00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 #ifndef __OPAL_TRANSCODERS_H
00118 #define __OPAL_TRANSCODERS_H
00119
00120 #ifdef P_USE_PRAGMA
00121 #pragma interface
00122 #endif
00123
00124 #include <opal/buildopts.h>
00125
00126 #include <opal/mediafmt.h>
00127 #include <opal/mediacmd.h>
00128
00129 #include <rtp/rtp.h>
00130
00131 class RTP_DataFrame;
00132 class OpalTranscoder;
00133
00134
00136
00140 class OpalMediaFormatPair : public PObject
00141 {
00142 PCLASSINFO(OpalMediaFormatPair, PObject);
00143 public:
00148 OpalMediaFormatPair(
00149 const OpalMediaFormat & inputMediaFormat,
00150 const OpalMediaFormat & outputMediaFormat
00151 );
00153
00160 void PrintOn(
00161 ostream & strm
00162 ) const;
00163
00175 virtual Comparison Compare(
00176 const PObject & obj
00177 ) const;
00179
00184 const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
00185
00188 const OpalMediaFormat & GetOutputFormat() const { return outputMediaFormat; }
00190
00191 protected:
00192 OpalMediaFormat inputMediaFormat;
00193 OpalMediaFormat outputMediaFormat;
00194 };
00195
00196
00197 typedef PFactory<OpalTranscoder, OpalMediaFormatPair> OpalTranscoderFactory;
00198 typedef PFactory<OpalTranscoder, OpalMediaFormatPair>::KeyList_T OpalTranscoderList;
00199 typedef PFactory<OpalTranscoder, OpalMediaFormatPair>::KeyList_T::iterator OpalTranscoderIterator;
00200
00201 inline OpalMediaFormatPair OpalCreateMediaFormatPair(const OpalMediaFormat & from, const OpalMediaFormat & to)
00202 { return OpalMediaFormatPair(from, to); }
00203
00204 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \
00205 OpalTranscoderFactory::Worker<cls> OpalTranscoder_##cls(OpalCreateMediaFormatPair(input, output))
00206
00207
00214 class OpalTranscoder : public OpalMediaFormatPair
00215 {
00216 PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
00217 public:
00222 OpalTranscoder(
00223 const OpalMediaFormat & inputMediaFormat,
00224 const OpalMediaFormat & outputMediaFormat
00225 );
00227
00238 virtual BOOL UpdateOutputMediaFormat(
00239 const OpalMediaFormat & mediaFormat
00240 );
00241
00248 virtual BOOL ExecuteCommand(
00249 const OpalMediaCommand & command
00250 );
00251
00258 virtual PINDEX GetOptimalDataFrameSize(
00259 BOOL input
00260 ) const = 0;
00261
00272 virtual BOOL ConvertFrames(
00273 const RTP_DataFrame & input,
00274 RTP_DataFrameList & output
00275 );
00276
00283 virtual BOOL Convert(
00284 const RTP_DataFrame & input,
00285 RTP_DataFrame & output
00286 ) = 0;
00287
00292 static OpalTranscoder * Create(
00293 const OpalMediaFormat & srcFormat,
00294 const OpalMediaFormat & dstFormat
00295 );
00296
00308 static BOOL SelectFormats(
00309 unsigned sessionID,
00310 const OpalMediaFormatList & srcFormats,
00311 const OpalMediaFormatList & dstFormats,
00312 OpalMediaFormat & srcFormat,
00313 OpalMediaFormat & dstFormat
00314 );
00315
00324 static BOOL FindIntermediateFormat(
00325 const OpalMediaFormat & srcFormat,
00326 const OpalMediaFormat & dstFormat,
00327 OpalMediaFormat & intermediateFormat
00328 );
00329
00332 static OpalMediaFormatList GetDestinationFormats(
00333 const OpalMediaFormat & srcFormat
00334 );
00335
00338 static OpalMediaFormatList GetSourceFormats(
00339 const OpalMediaFormat & dstFormat
00340 );
00341
00344 static OpalMediaFormatList GetPossibleFormats(
00345 const OpalMediaFormatList & formats
00346 );
00348
00353 PINDEX GetMaxOutputSize() const { return maxOutputSize; }
00354
00357 void SetMaxOutputSize(
00358 PINDEX size
00359 ) { maxOutputSize = size; }
00360
00365 void SetCommandNotifier(
00366 const PNotifier & notifier
00367 ) { commandNotifier = notifier; }
00368
00373 const PNotifier & GetCommandNotifier() const { return commandNotifier; }
00375
00376 protected:
00377 PINDEX maxOutputSize;
00378 bool outputMediaFormatUpdated;
00379 PNotifier commandNotifier;
00380 PMutex updateMutex;
00381
00382 RTP_DataFrame::PayloadMapType payloadTypeMap;
00383
00384 public:
00385 void SetRTPPayloadMap(const RTP_DataFrame::PayloadMapType & v)
00386 { payloadTypeMap = v; }
00387
00388 void AddRTPPayloadMapping(RTP_DataFrame::PayloadTypes from, RTP_DataFrame::PayloadTypes to)
00389 { payloadTypeMap.insert(RTP_DataFrame::PayloadMapType::value_type(from, to)); }
00390 };
00391
00392
00400 class OpalFramedTranscoder : public OpalTranscoder
00401 {
00402 PCLASSINFO(OpalFramedTranscoder, OpalTranscoder);
00403 public:
00408 OpalFramedTranscoder(
00409 const OpalMediaFormat & inputMediaFormat,
00410 const OpalMediaFormat & outputMediaFormat,
00411 PINDEX inputBytesPerFrame,
00412 PINDEX outputBytesPerFrame
00413 );
00415
00424 virtual PINDEX GetOptimalDataFrameSize(
00425 BOOL input
00426 ) const;
00427
00434 virtual BOOL Convert(
00435 const RTP_DataFrame & input,
00436 RTP_DataFrame & output
00437 );
00438
00442 virtual BOOL ConvertFrame(
00443 const BYTE * input,
00444 BYTE * output
00445 );
00446 virtual BOOL ConvertFrame(
00447 const BYTE * input,
00448 PINDEX & consumed,
00449 BYTE * output,
00450 PINDEX & created
00451 );
00452 virtual BOOL ConvertSilentFrame(
00453 BYTE * output
00454 );
00456
00457 protected:
00458 PINDEX inputBytesPerFrame;
00459 PINDEX outputBytesPerFrame;
00460
00461
00462 };
00463
00464
00472 class OpalStreamedTranscoder : public OpalTranscoder
00473 {
00474 PCLASSINFO(OpalStreamedTranscoder, OpalTranscoder);
00475 public:
00480 OpalStreamedTranscoder(
00481 const OpalMediaFormat & inputMediaFormat,
00482 const OpalMediaFormat & outputMediaFormat,
00483 unsigned inputBits,
00484 unsigned outputBits,
00485 PINDEX optimalSamples
00486 );
00488
00497 virtual PINDEX GetOptimalDataFrameSize(
00498 BOOL input
00499 ) const;
00500
00507 virtual BOOL Convert(
00508 const RTP_DataFrame & input,
00509 RTP_DataFrame & output
00510 );
00511
00518 virtual int ConvertOne(int sample) const = 0;
00520
00521 protected:
00522 unsigned inputBitsPerSample;
00523 unsigned outputBitsPerSample;
00524 PINDEX optimalSamples;
00525 };
00526
00527
00529
00530 class Opal_Linear16Mono_PCM : public OpalStreamedTranscoder {
00531 public:
00532 Opal_Linear16Mono_PCM();
00533 virtual int ConvertOne(int sample) const;
00534 };
00535
00536
00538
00539 class Opal_PCM_Linear16Mono : public OpalStreamedTranscoder {
00540 public:
00541 Opal_PCM_Linear16Mono();
00542 virtual int ConvertOne(int sample) const;
00543 };
00544
00545
00547
00548 #define OPAL_REGISTER_L16_MONO() \
00549 OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
00550 OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ)
00551
00552
00553
00554 #endif // __OPAL_TRANSCODERS_H
00555
00556
00557