OPAL Version 3.10.2
|
00001 /* 00002 * transcoders.h 00003 * 00004 * Abstractions for converting media from one format to another. 00005 * 00006 * Open Phone Abstraction Library (OPAL) 00007 * Formally known as the Open H323 project. 00008 * 00009 * Copyright (c) 2001 Equivalence Pty. Ltd. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Open Phone Abstraction Library. 00022 * 00023 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00024 * 00025 * Contributor(s): ______________________________________. 00026 * 00027 * $Revision: 25780 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2011-05-16 21:05:05 -0500 (Mon, 16 May 2011) $ 00030 */ 00031 00032 #ifndef OPAL_OPAL_TRANSCODERS_H 00033 #define OPAL_OPAL_TRANSCODERS_H 00034 00035 #ifdef P_USE_PRAGMA 00036 #pragma interface 00037 #endif 00038 00039 #include <opal/buildopts.h> 00040 00041 #include <opal/mediafmt.h> 00042 #include <opal/mediacmd.h> 00043 00044 #include <rtp/rtp.h> 00045 00046 class RTP_DataFrame; 00047 class OpalTranscoder; 00048 00049 00051 00055 class OpalMediaFormatPair : public PObject 00056 { 00057 PCLASSINFO(OpalMediaFormatPair, PObject); 00058 public: 00063 OpalMediaFormatPair( 00064 const OpalMediaFormat & inputMediaFormat, 00065 const OpalMediaFormat & outputMediaFormat 00066 ); 00068 00075 void PrintOn( 00076 ostream & strm 00077 ) const; 00078 00090 virtual Comparison Compare( 00091 const PObject & obj 00092 ) const; 00094 00099 const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; } 00100 00103 const OpalMediaFormat & GetOutputFormat() const { return outputMediaFormat; } 00105 00106 protected: 00107 OpalMediaFormat inputMediaFormat; 00108 OpalMediaFormat outputMediaFormat; 00109 }; 00110 00111 00112 typedef std::pair<PString, PString> OpalTranscoderKey; 00113 typedef PFactory<OpalTranscoder, OpalTranscoderKey> OpalTranscoderFactory; 00114 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T OpalTranscoderList; 00115 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T::iterator OpalTranscoderIterator; 00116 00117 __inline OpalTranscoderKey MakeOpalTranscoderKey(const OpalMediaFormat & from, const OpalMediaFormat & to) 00118 { 00119 return OpalTranscoderKey(from.GetName(), to.GetName()); 00120 } 00121 00122 __inline OpalTranscoderKey MakeOpalTranscoderKey(const char * from, const char * to) 00123 { 00124 return OpalTranscoderKey(from, to); 00125 } 00126 00127 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \ 00128 PFACTORY_CREATE(OpalTranscoderFactory, cls, MakeOpalTranscoderKey(input, output), false) 00129 00130 00137 class OpalTranscoder : public OpalMediaFormatPair 00138 { 00139 PCLASSINFO(OpalTranscoder, OpalMediaFormatPair); 00140 public: 00145 OpalTranscoder( 00146 const OpalMediaFormat & inputMediaFormat, 00147 const OpalMediaFormat & outputMediaFormat 00148 ); 00150 00166 virtual bool UpdateMediaFormats( 00167 const OpalMediaFormat & inputMediaFormat, 00168 const OpalMediaFormat & outputMediaFormat 00169 ); 00170 00177 virtual PBoolean ExecuteCommand( 00178 const OpalMediaCommand & command 00179 ); 00180 00187 virtual PINDEX GetOptimalDataFrameSize( 00188 PBoolean input 00189 ) const = 0; 00190 00201 virtual PBoolean ConvertFrames( 00202 const RTP_DataFrame & input, 00203 RTP_DataFrameList & output 00204 ); 00205 00212 virtual PBoolean Convert( 00213 const RTP_DataFrame & input, 00214 RTP_DataFrame & output 00215 ) = 0; 00216 00221 static OpalTranscoder * Create( 00222 const OpalMediaFormat & srcFormat, 00223 const OpalMediaFormat & dstFormat, 00224 const BYTE * instance = NULL, 00225 unsigned instanceLen = 0 00226 ); 00227 00242 static bool SelectFormats( 00243 const OpalMediaType & mediaType, 00244 const OpalMediaFormatList & srcFormats, 00245 const OpalMediaFormatList & dstFormats, 00246 const OpalMediaFormatList & allFormats, 00247 OpalMediaFormat & srcFormat, 00248 OpalMediaFormat & dstFormat 00249 ); 00250 00263 static bool FindIntermediateFormat( 00264 const OpalMediaFormat & srcFormat, 00265 const OpalMediaFormat & dstFormat, 00266 OpalMediaFormat & intermediateFormat 00267 ); 00268 00271 static OpalMediaFormatList GetDestinationFormats( 00272 const OpalMediaFormat & srcFormat 00273 ); 00274 00277 static OpalMediaFormatList GetSourceFormats( 00278 const OpalMediaFormat & dstFormat 00279 ); 00280 00283 static OpalMediaFormatList GetPossibleFormats( 00284 const OpalMediaFormatList & formats 00285 ); 00287 00292 PINDEX GetMaxOutputSize() const { return maxOutputSize; } 00293 00296 void SetMaxOutputSize( 00297 PINDEX size 00298 ) { maxOutputSize = size; } 00299 00304 void SetCommandNotifier( 00305 const PNotifier & notifier 00306 ) { commandNotifier = notifier; } 00307 00312 const PNotifier & GetCommandNotifier() const { return commandNotifier; } 00313 00315 void NotifyCommand( 00316 const OpalMediaCommand & command 00317 ) const; 00318 00320 unsigned GetSessionID() const { return m_sessionID; } 00321 00323 void SetSessionID(unsigned id) { m_sessionID = id; } 00324 00327 virtual void SetInstanceID( 00328 const BYTE * instance, 00329 unsigned instanceLen 00330 ); 00331 00332 RTP_DataFrame::PayloadTypes GetPayloadType( 00333 PBoolean input 00334 ) const; 00335 00336 virtual bool AcceptComfortNoise() const { return false; } 00337 virtual bool AcceptEmptyPayload() const { return acceptEmptyPayload; } 00338 virtual bool AcceptOtherPayloads() const { return acceptOtherPayloads; } 00339 00340 #if OPAL_STATISTICS 00341 virtual void GetStatistics(OpalMediaStatistics & statistics) const; 00342 #endif 00343 00344 void CopyTimestamp(RTP_DataFrame & dst, const RTP_DataFrame & src, bool inToOut) const; 00346 00347 protected: 00348 PINDEX maxOutputSize; 00349 PNotifier commandNotifier; 00350 PMutex updateMutex; 00351 00352 unsigned m_sessionID; 00353 bool outputIsRTP, inputIsRTP; 00354 bool acceptEmptyPayload; 00355 bool acceptOtherPayloads; 00356 unsigned m_inClockRate; 00357 unsigned m_outClockRate; 00358 }; 00359 00360 00368 class OpalFramedTranscoder : public OpalTranscoder 00369 { 00370 PCLASSINFO(OpalFramedTranscoder, OpalTranscoder); 00371 public: 00376 OpalFramedTranscoder( 00377 const OpalMediaFormat & inputMediaFormat, 00378 const OpalMediaFormat & outputMediaFormat 00379 ); 00381 00397 virtual bool UpdateMediaFormats( 00398 const OpalMediaFormat & inputMediaFormat, 00399 const OpalMediaFormat & outputMediaFormat 00400 ); 00401 00408 virtual PINDEX GetOptimalDataFrameSize( 00409 PBoolean input 00410 ) const; 00411 00418 virtual PBoolean Convert( 00419 const RTP_DataFrame & input, 00420 RTP_DataFrame & output 00421 ); 00422 00426 virtual PBoolean ConvertFrame( 00427 const BYTE * input, 00428 BYTE * output 00429 ); 00430 virtual PBoolean ConvertFrame( 00431 const BYTE * input, 00432 PINDEX & consumed, 00433 BYTE * output, 00434 PINDEX & created 00435 ); 00436 virtual PBoolean ConvertSilentFrame( 00437 BYTE * output 00438 ); 00440 00441 protected: 00442 void CalculateSizes(); 00443 00444 PINDEX inputBytesPerFrame; 00445 PINDEX outputBytesPerFrame; 00446 PINDEX maxOutputDataSize; 00447 }; 00448 00449 00457 class OpalStreamedTranscoder : public OpalTranscoder 00458 { 00459 PCLASSINFO(OpalStreamedTranscoder, OpalTranscoder); 00460 public: 00465 OpalStreamedTranscoder( 00466 const OpalMediaFormat & inputMediaFormat, 00467 const OpalMediaFormat & outputMediaFormat, 00468 unsigned inputBits, 00469 unsigned outputBits 00470 ); 00472 00481 virtual PINDEX GetOptimalDataFrameSize( 00482 PBoolean input 00483 ) const; 00484 00491 virtual PBoolean Convert( 00492 const RTP_DataFrame & input, 00493 RTP_DataFrame & output 00494 ); 00495 00502 virtual int ConvertOne(int sample) const = 0; 00504 00505 protected: 00506 unsigned inputBitsPerSample; 00507 unsigned outputBitsPerSample; 00508 }; 00509 00510 00512 00513 class Opal_Linear16Mono_PCM : public OpalStreamedTranscoder { 00514 public: 00515 Opal_Linear16Mono_PCM(); 00516 virtual int ConvertOne(int sample) const; 00517 }; 00518 00519 00521 00522 class Opal_PCM_Linear16Mono : public OpalStreamedTranscoder { 00523 public: 00524 Opal_PCM_Linear16Mono(); 00525 virtual int ConvertOne(int sample) const; 00526 }; 00527 00528 00530 00531 #define OPAL_REGISTER_L16_MONO() \ 00532 OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \ 00533 OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ) 00534 00535 00536 class OpalEmptyFramedAudioTranscoder : public OpalFramedTranscoder 00537 { 00538 PCLASSINFO(OpalEmptyFramedAudioTranscoder, OpalFramedTranscoder); 00539 public: 00540 OpalEmptyFramedAudioTranscoder(const char * inFormat, const char * outFormat) 00541 : OpalFramedTranscoder(inFormat, outFormat) 00542 { } 00543 00544 PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &) 00545 { return false; } 00546 }; 00547 00548 #define OPAL_DECLARE_EMPTY_TRANSCODER(fmt) \ 00549 class Opal_Empty_##fmt##_Encoder : public OpalEmptyFramedAudioTranscoder \ 00550 { \ 00551 public: \ 00552 Opal_Empty_##fmt##_Encoder() \ 00553 : OpalEmptyFramedAudioTranscoder(OpalPCM16, fmt) \ 00554 { } \ 00555 }; \ 00556 class Opal_Empty_##fmt##_Decoder : public OpalEmptyFramedAudioTranscoder \ 00557 { \ 00558 public: \ 00559 Opal_Empty_##fmt##_Decoder() \ 00560 : OpalEmptyFramedAudioTranscoder(fmt, OpalPCM16) \ 00561 { } \ 00562 }; \ 00563 00564 #define OPAL_DEFINE_EMPTY_TRANSCODER(fmt) \ 00565 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Encoder, OpalPCM16, fmt); \ 00566 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Decoder, fmt, OpalPCM16); \ 00567 00568 #endif // OPAL_OPAL_TRANSCODERS_H 00569 00570 00571 // End of File ///////////////////////////////////////////////////////////////