patch.h
Go to the documentation of this file.
/*
* patch.h
*
* Media stream patch thread.
*
* Open Phone Abstraction Library (OPAL)
* Formally known as the Open H323 project.
*
* Copyright (c) 2001 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open Phone Abstraction Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 27949 $
* $Author: rjongbloed $
* $Date: 2012-06-30 22:55:05 -0500 (Sat, 30 Jun 2012) $
*/
#ifndef OPAL_OPAL_PATCH_H
#define OPAL_OPAL_PATCH_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#include <opal/mediastrm.h>
#include <opal/mediacmd.h>
#include <codec/ratectl.h>
#include <list>
class OpalTranscoder;
class OpalMediaPatch : public PSafeObject
{
PCLASSINFO(OpalMediaPatch, PObject);
public:
OpalMediaPatch(
OpalMediaStream & source
);
~OpalMediaPatch();
void PrintOn(
ostream & strm
) const;
virtual void Start();
virtual bool OnStartMediaPatch();
virtual void Close();
PBoolean AddSink(
const OpalMediaStreamPtr & stream
);
void RemoveSink(
const OpalMediaStreamPtr & stream
);
OpalMediaStream & GetSource() const { return source; }
OpalMediaStreamPtr GetSink(PINDEX i = 0) const;
OpalMediaFormat GetSinkFormat(PINDEX i = 0) const;
void AddFilter(
const PNotifier & filter,
const OpalMediaFormat & stage = OpalMediaFormat()
);
bool RemoveFilter(
const PNotifier & filter,
const OpalMediaFormat & stage = OpalMediaFormat()
);
virtual void FilterFrame(
RTP_DataFrame & frame,
const OpalMediaFormat & mediaFormat
);
virtual bool UpdateMediaFormat(
const OpalMediaFormat & mediaFormat
);
virtual PBoolean ExecuteCommand(
const OpalMediaCommand & command,
PBoolean fromSink
);
virtual bool SetPaused(
bool pause
);
virtual PBoolean PushFrame(
RTP_DataFrame & frame
);
bool SetBypassPatch(
OpalMediaPatch * patch
);
virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i = 0) const;
virtual void UnLockSinkTranscoder() const;
#if OPAL_STATISTICS
virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromSink) const;
#endif
PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, OnMediaCommand);
protected:
virtual void Main();
void StopThread();
bool DispatchFrame(RTP_DataFrame & frame);
bool EnableJitterBuffer();
OpalMediaStream & source;
class Sink : public PObject {
PCLASSINFO(Sink, PObject);
public:
Sink(OpalMediaPatch & p, const OpalMediaStreamPtr & s);
~Sink();
bool UpdateMediaFormat(const OpalMediaFormat & mediaFormat);
bool ExecuteCommand(const OpalMediaCommand & command);
bool WriteFrame(RTP_DataFrame & sourceFrame);
#if OPAL_STATISTICS
void GetStatistics(OpalMediaStatistics & statistics, bool fromSource) const;
#endif
OpalMediaPatch & patch;
OpalMediaStreamPtr stream;
OpalTranscoder * primaryCodec;
OpalTranscoder * secondaryCodec;
RTP_DataFrameList intermediateFrames;
RTP_DataFrameList finalFrames;
bool writeSuccessful;
RTP_DataFrame::PayloadTypes m_lastPayloadType;
unsigned m_consecutivePayloadTypeMismatches;
bool CannotTranscodeFrame(OpalTranscoder & codec, RTP_DataFrame & frame);
#if OPAL_VIDEO
void SetRateControlParameters(const OpalMediaFormat & mediaFormat);
bool RateControlExceeded(bool & forceIFrame);
OpalVideoRateController * rateController;
#endif
};
PList<Sink> sinks;
class Filter : public PObject {
PCLASSINFO(Filter, PObject);
public:
Filter(const PNotifier & n, const OpalMediaFormat & s) : notifier(n), stage(s) { }
PNotifier notifier;
OpalMediaFormat stage;
};
PList<Filter> filters;
OpalMediaPatch * m_bypassToPatch;
OpalMediaPatch * m_bypassFromPatch;
PSyncPoint m_bypassEnded;
class Thread : public PThread {
PCLASSINFO(Thread, PThread);
public:
Thread(OpalMediaPatch & p);
virtual void Main() { patch.Main(); };
OpalMediaPatch & patch;
};
Thread * patchThread;
PMutex patchThreadMutex;
private:
P_REMOVE_VIRTUAL(bool, OnPatchStart(), false);
};
class OpalPassiveMediaPatch : public OpalMediaPatch
{
PCLASSINFO(OpalPassiveMediaPatch, OpalMediaPatch);
public:
OpalPassiveMediaPatch(
OpalMediaStream & source
);
virtual void Start();
protected:
bool m_started;
};
#endif // OPAL_OPAL_PATCH_H
// End of File ///////////////////////////////////////////////////////////////
OpalMediaPatch::UpdateMediaFormat
virtual bool UpdateMediaFormat(const OpalMediaFormat &mediaFormat)
OpalMediaPatch::Sink::secondaryCodec
OpalTranscoder * secondaryCodec
Definition: patch.h:263
OpalMediaPatch::ExecuteCommand
virtual PBoolean ExecuteCommand(const OpalMediaCommand &command, PBoolean fromSink)
OpalMediaPatch::Sink::m_consecutivePayloadTypeMismatches
unsigned m_consecutivePayloadTypeMismatches
Definition: patch.h:269
OpalMediaPatch::Filter::Filter
Filter(const PNotifier &n, const OpalMediaFormat &s)
Definition: patch.h:283
OpalMediaPatch::Thread::Thread
Thread(OpalMediaPatch &p)
mediacmd.h
OpalMediaPatch::Sink::primaryCodec
OpalTranscoder * primaryCodec
Definition: patch.h:262
OpalMediaPatch::Thread::patch
OpalMediaPatch & patch
Definition: patch.h:297
OpalMediaPatch::Sink::writeSuccessful
bool writeSuccessful
Definition: patch.h:266
OpalMediaPatch::Sink::~Sink
~Sink()
OpalMediaPatch::m_bypassFromPatch
OpalMediaPatch * m_bypassFromPatch
Definition: patch.h:290
OpalMediaPatch::AddFilter
void AddFilter(const PNotifier &filter, const OpalMediaFormat &stage=OpalMediaFormat())
OpalMediaCommand
Definition: mediacmd.h:43
OpalMediaPatch::Sink::rateController
OpalVideoRateController * rateController
Definition: patch.h:275
buildopts.h
OpalPassiveMediaPatch
Definition: patch.h:315
OpalMediaPatch::Filter
Definition: patch.h:280
OpalMediaPatch::RemoveSink
void RemoveSink(const OpalMediaStreamPtr &stream)
OpalMediaStreamPtr
PSafePtr< OpalMediaStream > OpalMediaStreamPtr
Definition: mediastrm.h:442
OpalMediaPatch::GetSource
OpalMediaStream & GetSource() const
Definition: patch.h:131
OpalMediaPatch::Sink::ExecuteCommand
bool ExecuteCommand(const OpalMediaCommand &command)
OpalMediaPatch::OpalMediaPatch
OpalMediaPatch(OpalMediaStream &source)
OpalMediaPatch::~OpalMediaPatch
~OpalMediaPatch()
OpalMediaPatch::GetSinkFormat
OpalMediaFormat GetSinkFormat(PINDEX i=0) const
OpalMediaPatch::Sink::CannotTranscodeFrame
bool CannotTranscodeFrame(OpalTranscoder &codec, RTP_DataFrame &frame)
OpalMediaPatch::Sink::UpdateMediaFormat
bool UpdateMediaFormat(const OpalMediaFormat &mediaFormat)
OpalMediaPatch::StopThread
void StopThread()
RTP_DataFrame::PayloadTypes
PayloadTypes
Definition: rtp.h:86
ratectl.h
OpalMediaPatch::UnLockSinkTranscoder
virtual void UnLockSinkTranscoder() const
OpalMediaPatch::AddSink
PBoolean AddSink(const OpalMediaStreamPtr &stream)
OpalMediaPatch::m_bypassEnded
PSyncPoint m_bypassEnded
Definition: patch.h:291
OpalMediaPatch::Thread::Main
virtual void Main()
Definition: patch.h:297
OpalMediaPatch::OnStartMediaPatch
virtual bool OnStartMediaPatch()
OpalMediaPatch::Thread
Definition: patch.h:293
OpalMediaPatch::GetStatistics
virtual void GetStatistics(OpalMediaStatistics &statistics, bool fromSink) const
OpalMediaPatch::GetAndLockSinkTranscoder
virtual OpalTranscoder * GetAndLockSinkTranscoder(PINDEX i=0) const
RTP_DataFrame
Definition: rtp.h:71
OpalMediaPatch
Definition: patch.h:60
OpalMediaFormat
Definition: mediafmt.h:724
OpalMediaPatch::PushFrame
virtual PBoolean PushFrame(RTP_DataFrame &frame)
OpalMediaPatch::Sink::stream
OpalMediaStreamPtr stream
Definition: patch.h:261
OpalPassiveMediaPatch::Start
virtual void Start()
OpalMediaPatch::Sink::patch
OpalMediaPatch & patch
Definition: patch.h:260
OpalMediaPatch::FilterFrame
virtual void FilterFrame(RTP_DataFrame &frame, const OpalMediaFormat &mediaFormat)
OpalTranscoder
Definition: transcoders.h:137
OpalMediaPatch::RemoveFilter
bool RemoveFilter(const PNotifier &filter, const OpalMediaFormat &stage=OpalMediaFormat())
OpalMediaPatch::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(OpalMediaCommand, OpalMediaPatch, OnMediaCommand)
OpalMediaPatch::Sink::intermediateFrames
RTP_DataFrameList intermediateFrames
Definition: patch.h:264
OpalMediaPatch::Start
virtual void Start()
OpalMediaPatch::Sink::m_lastPayloadType
RTP_DataFrame::PayloadTypes m_lastPayloadType
Definition: patch.h:268
OpalMediaPatch::Main
virtual void Main()
OpalMediaPatch::PrintOn
void PrintOn(ostream &strm) const
OpalMediaPatch::Sink::finalFrames
RTP_DataFrameList finalFrames
Definition: patch.h:265
OpalMediaPatch::m_bypassToPatch
OpalMediaPatch * m_bypassToPatch
Definition: patch.h:289
OpalMediaPatch::Close
virtual void Close()
OpalMediaPatch::patchThread
Thread * patchThread
Definition: patch.h:301
OpalPassiveMediaPatch::m_started
bool m_started
Definition: patch.h:327
OpalMediaPatch::Sink::GetStatistics
void GetStatistics(OpalMediaStatistics &statistics, bool fromSource) const
OpalMediaPatch::DispatchFrame
bool DispatchFrame(RTP_DataFrame &frame)
OpalMediaStream
Definition: mediastrm.h:111
OpalPassiveMediaPatch::OpalPassiveMediaPatch
OpalPassiveMediaPatch(OpalMediaStream &source)
OpalMediaPatch::sinks
PList< Sink > sinks
Definition: patch.h:278
OpalMediaPatch::Sink
Definition: patch.h:248
OpalMediaPatch::EnableJitterBuffer
bool EnableJitterBuffer()
OpalMediaPatch::Filter::notifier
PNotifier notifier
Definition: patch.h:284
mediastrm.h
OpalMediaPatch::Sink::RateControlExceeded
bool RateControlExceeded(bool &forceIFrame)
OpalMediaStatistics
Definition: rtp.h:370
OpalMediaPatch::patchThreadMutex
PMutex patchThreadMutex
Definition: patch.h:302
OpalMediaPatch::filters
PList< Filter > filters
Definition: patch.h:287
OpalMediaPatch::GetSink
OpalMediaStreamPtr GetSink(PINDEX i=0) const
OpalMediaPatch::SetPaused
virtual bool SetPaused(bool pause)
OpalMediaPatch::Sink::WriteFrame
bool WriteFrame(RTP_DataFrame &sourceFrame)
OpalMediaPatch::SetBypassPatch
bool SetBypassPatch(OpalMediaPatch *patch)
OpalMediaPatch::Filter::stage
OpalMediaFormat stage
Definition: patch.h:285
OpalMediaPatch::Sink::SetRateControlParameters
void SetRateControlParameters(const OpalMediaFormat &mediaFormat)
OpalMediaPatch::Sink::Sink
Sink(OpalMediaPatch &p, const OpalMediaStreamPtr &s)
OpalMediaPatch::source
OpalMediaStream & source
Definition: patch.h:246
OpalVideoRateController
Definition: ratectl.h:169