transcoders.h
Go to the documentation of this file.
/*
* transcoders.h
*
* Abstractions for converting media from one format to another.
*
* 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: 26728 $
* $Author: rjongbloed $
* $Date: 2011-12-01 22:59:14 -0600 (Thu, 01 Dec 2011) $
*/
#ifndef OPAL_OPAL_TRANSCODERS_H
#define OPAL_OPAL_TRANSCODERS_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#include <opal/mediafmt.h>
#include <opal/mediacmd.h>
#include <rtp/rtp.h>
class RTP_DataFrame;
class OpalTranscoder;
class OpalMediaFormatPair : public PObject
{
PCLASSINFO(OpalMediaFormatPair, PObject);
public:
OpalMediaFormatPair(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat
);
void PrintOn(
ostream & strm
) const;
virtual Comparison Compare(
const PObject & obj
) const;
const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
const OpalMediaFormat & GetOutputFormat() const { return outputMediaFormat; }
protected:
OpalMediaFormat inputMediaFormat;
OpalMediaFormat outputMediaFormat;
};
typedef std::pair<PString, PString> OpalTranscoderKey;
typedef PFactory<OpalTranscoder, OpalTranscoderKey> OpalTranscoderFactory;
typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T OpalTranscoderList;
typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T::iterator OpalTranscoderIterator;
__inline OpalTranscoderKey MakeOpalTranscoderKey(const OpalMediaFormat & from, const OpalMediaFormat & to)
{
return OpalTranscoderKey(from.GetName(), to.GetName());
}
__inline OpalTranscoderKey MakeOpalTranscoderKey(const char * from, const char * to)
{
return OpalTranscoderKey(from, to);
}
#define OPAL_REGISTER_TRANSCODER(cls, input, output) \
PFACTORY_CREATE(OpalTranscoderFactory, cls, MakeOpalTranscoderKey(input, output), false)
class OpalTranscoder : public OpalMediaFormatPair
{
PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
public:
OpalTranscoder(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat
);
virtual bool UpdateMediaFormats(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat
);
virtual PBoolean ExecuteCommand(
const OpalMediaCommand & command
);
virtual PINDEX GetOptimalDataFrameSize(
PBoolean input
) const = 0;
virtual PBoolean ConvertFrames(
const RTP_DataFrame & input,
RTP_DataFrameList & output
);
virtual PBoolean Convert(
const RTP_DataFrame & input,
RTP_DataFrame & output
) = 0;
static OpalTranscoder * Create(
const OpalMediaFormat & srcFormat,
const OpalMediaFormat & dstFormat,
const BYTE * instance = NULL,
unsigned instanceLen = 0
);
static bool SelectFormats(
const OpalMediaType & mediaType,
const OpalMediaFormatList & srcFormats,
const OpalMediaFormatList & dstFormats,
const OpalMediaFormatList & allFormats,
OpalMediaFormat & srcFormat,
OpalMediaFormat & dstFormat
);
static bool FindIntermediateFormat(
const OpalMediaFormat & srcFormat,
const OpalMediaFormat & dstFormat,
OpalMediaFormat & intermediateFormat
);
static OpalMediaFormatList GetDestinationFormats(
const OpalMediaFormat & srcFormat
);
static OpalMediaFormatList GetSourceFormats(
const OpalMediaFormat & dstFormat
);
static OpalMediaFormatList GetPossibleFormats(
const OpalMediaFormatList & formats
);
PINDEX GetMaxOutputSize() const { return maxOutputSize; }
void SetMaxOutputSize(
PINDEX size
) { maxOutputSize = size; }
void SetCommandNotifier(
const PNotifier & notifier
) { commandNotifier = notifier; }
const PNotifier & GetCommandNotifier() const { return commandNotifier; }
void NotifyCommand(
const OpalMediaCommand & command
) const;
unsigned GetSessionID() const { return m_sessionID; }
void SetSessionID(unsigned id) { m_sessionID = id; }
virtual void SetInstanceID(
const BYTE * instance,
unsigned instanceLen
);
RTP_DataFrame::PayloadTypes GetPayloadType(
PBoolean input
) const;
virtual bool AcceptComfortNoise() const { return false; }
virtual bool AcceptEmptyPayload() const { return acceptEmptyPayload; }
virtual bool AcceptOtherPayloads() const { return acceptOtherPayloads; }
#if OPAL_STATISTICS
virtual void GetStatistics(OpalMediaStatistics & statistics) const;
#endif
void CopyTimestamp(RTP_DataFrame & dst, const RTP_DataFrame & src, bool inToOut) const;
protected:
PINDEX maxOutputSize;
PNotifier commandNotifier;
PMutex updateMutex;
unsigned m_sessionID;
bool outputIsRTP, inputIsRTP;
bool acceptEmptyPayload;
bool acceptOtherPayloads;
unsigned m_inClockRate;
unsigned m_outClockRate;
};
class OpalFramedTranscoder : public OpalTranscoder
{
PCLASSINFO(OpalFramedTranscoder, OpalTranscoder);
public:
OpalFramedTranscoder(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat
);
virtual bool UpdateMediaFormats(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat
);
virtual PINDEX GetOptimalDataFrameSize(
PBoolean input
) const;
virtual PBoolean Convert(
const RTP_DataFrame & input,
RTP_DataFrame & output
);
virtual PBoolean ConvertFrame(
const BYTE * input,
BYTE * output
);
virtual PBoolean ConvertFrame(
const BYTE * input,
PINDEX & consumed,
BYTE * output,
PINDEX & created
);
virtual PBoolean ConvertSilentFrame(
BYTE * output
);
protected:
void CalculateSizes();
PINDEX inputBytesPerFrame;
PINDEX outputBytesPerFrame;
PINDEX maxOutputDataSize;
};
class OpalStreamedTranscoder : public OpalTranscoder
{
PCLASSINFO(OpalStreamedTranscoder, OpalTranscoder);
public:
OpalStreamedTranscoder(
const OpalMediaFormat & inputMediaFormat,
const OpalMediaFormat & outputMediaFormat,
unsigned inputBits,
unsigned outputBits
);
virtual PINDEX GetOptimalDataFrameSize(
PBoolean input
) const;
virtual PBoolean Convert(
const RTP_DataFrame & input,
RTP_DataFrame & output
);
virtual int ConvertOne(int sample) const = 0;
protected:
unsigned inputBitsPerSample;
unsigned outputBitsPerSample;
};
class Opal_Linear16Mono_PCM : public OpalStreamedTranscoder {
public:
Opal_Linear16Mono_PCM();
virtual int ConvertOne(int sample) const;
};
class Opal_PCM_Linear16Mono : public OpalStreamedTranscoder {
public:
Opal_PCM_Linear16Mono();
virtual int ConvertOne(int sample) const;
};
#define OPAL_REGISTER_L16_MONO() \
OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ)
class OpalEmptyFramedAudioTranscoder : public OpalFramedTranscoder
{
PCLASSINFO(OpalEmptyFramedAudioTranscoder, OpalFramedTranscoder);
public:
OpalEmptyFramedAudioTranscoder(const char * inFormat, const char * outFormat)
: OpalFramedTranscoder(inFormat, outFormat)
{ }
PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
{ return false; }
};
#define OPAL_DECLARE_EMPTY_TRANSCODER(fmt) \
class Opal_Empty_##fmt##_Encoder : public OpalEmptyFramedAudioTranscoder \
{ \
public: \
Opal_Empty_##fmt##_Encoder() \
: OpalEmptyFramedAudioTranscoder(OpalPCM16, fmt) \
{ } \
}; \
class Opal_Empty_##fmt##_Decoder : public OpalEmptyFramedAudioTranscoder \
{ \
public: \
Opal_Empty_##fmt##_Decoder() \
: OpalEmptyFramedAudioTranscoder(fmt, OpalPCM16) \
{ } \
}; \
#define OPAL_DEFINE_EMPTY_TRANSCODER(fmt) \
OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Encoder, OpalPCM16, fmt); \
OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Decoder, fmt, OpalPCM16); \
#endif // OPAL_OPAL_TRANSCODERS_H
// End of File ///////////////////////////////////////////////////////////////
OpalTranscoderList
PFactory< OpalTranscoder, OpalTranscoderKey >::KeyList_T OpalTranscoderList
Definition: transcoders.h:114
OpalTranscoder::inputIsRTP
bool inputIsRTP
Definition: transcoders.h:355
OpalFramedTranscoder::outputBytesPerFrame
PINDEX outputBytesPerFrame
Definition: transcoders.h:447
OpalTranscoder::GetPayloadType
RTP_DataFrame::PayloadTypes GetPayloadType(PBoolean input) const
OpalTranscoder::acceptOtherPayloads
bool acceptOtherPayloads
Definition: transcoders.h:357
mediacmd.h
Opal_PCM_Linear16Mono
Definition: transcoders.h:524
OpalTranscoder::m_outClockRate
unsigned m_outClockRate
Definition: transcoders.h:359
OpalTranscoder::GetOptimalDataFrameSize
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const =0
Opal_PCM_Linear16Mono::ConvertOne
virtual int ConvertOne(int sample) const
OpalMediaCommand
Definition: mediacmd.h:43
OpalStreamedTranscoder::Convert
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)
OpalFramedTranscoder::ConvertSilentFrame
virtual PBoolean ConvertSilentFrame(BYTE *output)
buildopts.h
Opal_Linear16Mono_PCM
Definition: transcoders.h:515
OpalTranscoder::CopyTimestamp
void CopyTimestamp(RTP_DataFrame &dst, const RTP_DataFrame &src, bool inToOut) const
OpalTranscoder::ExecuteCommand
virtual PBoolean ExecuteCommand(const OpalMediaCommand &command)
OpalTranscoder::outputIsRTP
bool outputIsRTP
Definition: transcoders.h:355
OpalFramedTranscoder::maxOutputDataSize
PINDEX maxOutputDataSize
Definition: transcoders.h:448
OpalStreamedTranscoder
Definition: transcoders.h:459
OpalMediaType
Definition: mediatype.h:57
Opal_Linear16Mono_PCM::Opal_Linear16Mono_PCM
Opal_Linear16Mono_PCM()
OpalTranscoder::acceptEmptyPayload
bool acceptEmptyPayload
Definition: transcoders.h:356
OpalStreamedTranscoder::OpalStreamedTranscoder
OpalStreamedTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat, unsigned inputBits, unsigned outputBits)
OpalTranscoder::GetSourceFormats
static OpalMediaFormatList GetSourceFormats(const OpalMediaFormat &dstFormat)
OpalFramedTranscoder::CalculateSizes
void CalculateSizes()
OpalFramedTranscoder::GetOptimalDataFrameSize
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const
OpalTranscoder::OpalTranscoder
OpalTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
RTP_DataFrame::PayloadTypes
PayloadTypes
Definition: rtp.h:86
OpalMediaFormatPair
Definition: transcoders.h:55
OpalTranscoder::AcceptComfortNoise
virtual bool AcceptComfortNoise() const
Definition: transcoders.h:338
OpalMediaFormatList
Definition: mediafmt.h:72
OpalTranscoder::m_sessionID
unsigned m_sessionID
Definition: transcoders.h:354
OpalTranscoder::AcceptOtherPayloads
virtual bool AcceptOtherPayloads() const
Definition: transcoders.h:340
OpalTranscoderKey
std::pair< PString, PString > OpalTranscoderKey
Definition: transcoders.h:112
OpalFramedTranscoder::OpalFramedTranscoder
OpalFramedTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
OpalTranscoder::NotifyCommand
void NotifyCommand(const OpalMediaCommand &command) const
Notify command notifier of command.
RTP_DataFrame
Definition: rtp.h:71
OpalMediaFormatPair::GetInputFormat
const OpalMediaFormat & GetInputFormat() const
Definition: transcoders.h:99
OpalTranscoder::GetSessionID
unsigned GetSessionID() const
Get session ID for the transcoder (from OpalMediaStream)
Definition: transcoders.h:322
OpalEmptyFramedAudioTranscoder
Definition: transcoders.h:538
MakeOpalTranscoderKey
__inline OpalTranscoderKey MakeOpalTranscoderKey(const OpalMediaFormat &from, const OpalMediaFormat &to)
Definition: transcoders.h:117
OpalMediaFormat
Definition: mediafmt.h:724
OpalTranscoder::GetPossibleFormats
static OpalMediaFormatList GetPossibleFormats(const OpalMediaFormatList &formats)
OpalTranscoder
Definition: transcoders.h:137
OpalTranscoder::UpdateMediaFormats
virtual bool UpdateMediaFormats(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
OpalTranscoder::updateMutex
PMutex updateMutex
Definition: transcoders.h:352
OpalTranscoder::ConvertFrames
virtual PBoolean ConvertFrames(const RTP_DataFrame &input, RTP_DataFrameList &output)
OpalMediaFormatPair::inputMediaFormat
OpalMediaFormat inputMediaFormat
Definition: transcoders.h:107
OpalTranscoder::GetMaxOutputSize
PINDEX GetMaxOutputSize() const
Definition: transcoders.h:294
OpalTranscoder::maxOutputSize
PINDEX maxOutputSize
Definition: transcoders.h:350
OpalMediaFormat::GetName
PString GetName() const
Definition: mediafmt.h:896
OpalTranscoder::SetCommandNotifier
void SetCommandNotifier(const PNotifier &notifier)
Definition: transcoders.h:306
OpalTranscoder::SetMaxOutputSize
void SetMaxOutputSize(PINDEX size)
Definition: transcoders.h:298
Opal_PCM_Linear16Mono::Opal_PCM_Linear16Mono
Opal_PCM_Linear16Mono()
OpalMediaFormatPair::Compare
virtual Comparison Compare(const PObject &obj) const
OpalEmptyFramedAudioTranscoder::ConvertFrame
PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
Definition: transcoders.h:546
OpalTranscoder::Create
static OpalTranscoder * Create(const OpalMediaFormat &srcFormat, const OpalMediaFormat &dstFormat, const BYTE *instance=NULL, unsigned instanceLen=0)
OpalFramedTranscoder
Definition: transcoders.h:370
mediafmt.h
OpalStreamedTranscoder::outputBitsPerSample
unsigned outputBitsPerSample
Definition: transcoders.h:509
OpalEmptyFramedAudioTranscoder::OpalEmptyFramedAudioTranscoder
OpalEmptyFramedAudioTranscoder(const char *inFormat, const char *outFormat)
Definition: transcoders.h:542
OpalTranscoder::SetSessionID
void SetSessionID(unsigned id)
Set session ID for the transcoder (from OpalMediaStream)
Definition: transcoders.h:325
OpalTranscoder::commandNotifier
PNotifier commandNotifier
Definition: transcoders.h:351
OpalTranscoderFactory
PFactory< OpalTranscoder, OpalTranscoderKey > OpalTranscoderFactory
Definition: transcoders.h:113
OpalMediaFormatPair::PrintOn
void PrintOn(ostream &strm) const
Opal_Linear16Mono_PCM::ConvertOne
virtual int ConvertOne(int sample) const
OpalTranscoder::GetDestinationFormats
static OpalMediaFormatList GetDestinationFormats(const OpalMediaFormat &srcFormat)
OpalTranscoderIterator
PFactory< OpalTranscoder, OpalTranscoderKey >::KeyList_T::iterator OpalTranscoderIterator
Definition: transcoders.h:115
OpalTranscoder::AcceptEmptyPayload
virtual bool AcceptEmptyPayload() const
Definition: transcoders.h:339
OpalFramedTranscoder::ConvertFrame
virtual PBoolean ConvertFrame(const BYTE *input, BYTE *output)
OpalStreamedTranscoder::GetOptimalDataFrameSize
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const
OpalTranscoder::SetInstanceID
virtual void SetInstanceID(const BYTE *instance, unsigned instanceLen)
OpalTranscoder::FindIntermediateFormat
static bool FindIntermediateFormat(const OpalMediaFormat &srcFormat, const OpalMediaFormat &dstFormat, OpalMediaFormat &intermediateFormat)
OpalMediaFormatPair::GetOutputFormat
const OpalMediaFormat & GetOutputFormat() const
Definition: transcoders.h:103
OpalFramedTranscoder::UpdateMediaFormats
virtual bool UpdateMediaFormats(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
OpalMediaStatistics
Definition: rtp.h:370
rtp.h
OpalFramedTranscoder::inputBytesPerFrame
PINDEX inputBytesPerFrame
Definition: transcoders.h:446
OpalTranscoder::SelectFormats
static bool SelectFormats(const OpalMediaType &mediaType, const OpalMediaFormatList &srcFormats, const OpalMediaFormatList &dstFormats, const OpalMediaFormatList &allFormats, OpalMediaFormat &srcFormat, OpalMediaFormat &dstFormat)
OpalTranscoder::m_inClockRate
unsigned m_inClockRate
Definition: transcoders.h:358
OpalMediaFormatPair::outputMediaFormat
OpalMediaFormat outputMediaFormat
Definition: transcoders.h:108
OpalFramedTranscoder::Convert
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)
OpalTranscoder::GetStatistics
virtual void GetStatistics(OpalMediaStatistics &statistics) const
OpalStreamedTranscoder::ConvertOne
virtual int ConvertOne(int sample) const =0
OpalTranscoder::Convert
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)=0
OpalMediaFormatPair::OpalMediaFormatPair
OpalMediaFormatPair(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
OpalStreamedTranscoder::inputBitsPerSample
unsigned inputBitsPerSample
Definition: transcoders.h:508
OpalTranscoder::GetCommandNotifier
const PNotifier & GetCommandNotifier() const
Definition: transcoders.h:314