OPAL  Version 3.18.8
transcoders.h
Go to the documentation of this file.
1 /*
2  * transcoders.h
3  *
4  * Abstractions for converting media from one format to another.
5  *
6  * Open Phone Abstraction Library (OPAL)
7  * Formally known as the Open H323 project.
8  *
9  * Copyright (c) 2001 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  */
27 
28 #ifndef OPAL_OPAL_TRANSCODERS_H
29 #define OPAL_OPAL_TRANSCODERS_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <opal_config.h>
36 
37 #include <opal/mediafmt.h>
38 #include <opal/mediacmd.h>
39 #include <opal/mediasession.h>
40 
41 #include <rtp/rtp.h>
42 
43 class RTP_DataFrame;
44 class OpalTranscoder;
45 
46 
48 
52 class OpalMediaFormatPair : public PObject
53 {
54  PCLASSINFO(OpalMediaFormatPair, PObject);
55  public:
63  );
65 
72  void PrintOn(
73  ostream & strm
74  ) const;
75 
87  virtual Comparison Compare(
88  const PObject & obj
89  ) const;
91 
96  const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
97 
102 
103  protected:
106 };
107 
108 
109 typedef std::pair<PString, PString> OpalTranscoderKey;
110 typedef PFactory<OpalTranscoder, OpalTranscoderKey> OpalTranscoderFactory;
111 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T OpalTranscoderList;
112 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T::iterator OpalTranscoderIterator;
113 
115 {
116  return OpalTranscoderKey(from.GetName(), to.GetName());
117 }
118 
119 __inline OpalTranscoderKey MakeOpalTranscoderKey(const char * from, const char * to)
120 {
121  return OpalTranscoderKey(from, to);
122 }
123 
124 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \
125  PFACTORY_CREATE(OpalTranscoderFactory, cls, MakeOpalTranscoderKey(input, output), false)
126 
127 
135 {
136  PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
137  public:
145  );
147 
163  virtual bool UpdateMediaFormats(
164  const OpalMediaFormat & inputMediaFormat,
165  const OpalMediaFormat & outputMediaFormat
166  );
167 
176  virtual PBoolean ExecuteCommand(
177  const OpalMediaCommand & command
178  );
179 
186  virtual PINDEX GetOptimalDataFrameSize(
187  PBoolean input
188  ) const = 0;
189 
200  virtual PBoolean ConvertFrames(
201  const RTP_DataFrame & input,
202  RTP_DataFrameList & output
203  );
204 
211  virtual PBoolean Convert(
212  const RTP_DataFrame & input,
213  RTP_DataFrame & output
214  ) = 0;
215 
220  static OpalTranscoder * Create(
221  const OpalMediaFormat & srcFormat,
222  const OpalMediaFormat & dstFormat,
223  const BYTE * instance = NULL,
224  unsigned instanceLen = 0
225  );
226 
241  static bool SelectFormats(
242  const OpalMediaType & mediaType,
243  const OpalMediaFormatList & srcFormats,
244  const OpalMediaFormatList & dstFormats,
245  const OpalMediaFormatList & masterFormats,
246  OpalMediaFormat & srcFormat,
247  OpalMediaFormat & dstFormat
248  );
249 
262  static bool FindIntermediateFormat(
263  const OpalMediaFormat & srcFormat,
264  const OpalMediaFormat & dstFormat,
265  OpalMediaFormat & intermediateFormat
266  );
267 
271  const OpalMediaFormat & srcFormat
272  );
273 
277  const OpalMediaFormat & dstFormat
278  );
279 
283  const OpalMediaFormatList & formats
284  );
286 
291  PINDEX GetMaxOutputSize() const { return maxOutputSize; }
292 
295  void SetMaxOutputSize(
296  PINDEX size
297  );
298 
304  const PNotifier & notifier
305  ) { commandNotifier = notifier; }
306 
311  const PNotifier & GetCommandNotifier() const { return commandNotifier; }
312 
314  void NotifyCommand(
315  const OpalMediaCommand & command
316  ) const;
317 
319  unsigned GetSessionID() const { return m_sessionID; }
320 
322  void SetSessionID(unsigned id) { m_sessionID = id; }
323 
325  PBoolean input
326  ) const;
327 
328  virtual bool AcceptComfortNoise() const { return false; }
329  virtual bool AcceptEmptyPayload() const { return acceptEmptyPayload; }
330  virtual bool AcceptOtherPayloads() const { return acceptOtherPayloads; }
331 
332 #if OPAL_STATISTICS
333  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
334 #endif
335 
336  void CopyTimestamp(RTP_DataFrame & dst, const RTP_DataFrame & src, bool inToOut) const;
338 
339  protected:
342  virtual bool OnCreated(
343  const OpalMediaFormat & srcFormat,
344  const OpalMediaFormat & destFormat,
345  const BYTE * instance,
346  unsigned instanceLen
347  );
348 
350  PNotifier commandNotifier;
351  PDECLARE_MUTEX(updateMutex);
352 
353  unsigned m_sessionID;
357  unsigned m_inClockRate;
358  unsigned m_outClockRate;
359 
362 };
363 
364 
373 {
375  public:
383  );
385 
401  virtual bool UpdateMediaFormats(
402  const OpalMediaFormat & inputMediaFormat,
403  const OpalMediaFormat & outputMediaFormat
404  );
405 
412  virtual PINDEX GetOptimalDataFrameSize(
413  PBoolean input
414  ) const;
415 
422  virtual PBoolean Convert(
423  const RTP_DataFrame & input,
424  RTP_DataFrame & output
425  );
426 
430  virtual PBoolean ConvertFrame(
431  const BYTE * input,
432  BYTE * output
433  );
434  virtual PBoolean ConvertFrame(
435  const BYTE * input,
436  PINDEX & consumed,
437  BYTE * output,
438  PINDEX & created
439  );
440  virtual PBoolean ConvertSilentFrame(
441  BYTE * output,
442  PINDEX & created
443  );
445 
446  protected:
447  void CalculateSizes();
448 
452  enum
453  {
459 };
460 
461 
470 {
472  public:
480  unsigned inputBits,
481  unsigned outputBits
482  );
484 
493  virtual PINDEX GetOptimalDataFrameSize(
494  PBoolean input
495  ) const;
496 
503  virtual PBoolean Convert(
504  const RTP_DataFrame & input,
505  RTP_DataFrame & output
506  );
507 
514  virtual int ConvertOne(int sample) const = 0;
516 
517  protected:
520 };
521 
522 
524 
526  public:
528  virtual int ConvertOne(int sample) const;
529 };
530 
531 
533 
535  public:
537  virtual int ConvertOne(int sample) const;
538 };
539 
540 
542 
543 #define OPAL_REGISTER_L16_MONO() \
544  OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
545  OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ)
546 
547 
549 {
551  public:
552  OpalEmptyFramedAudioTranscoder(const char * inFormat, const char * outFormat)
553  : OpalFramedTranscoder(inFormat, outFormat)
554  { }
555 
556  PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
557  { return false; }
558 };
559 
560 #define OPAL_DECLARE_EMPTY_TRANSCODER(fmt) \
561 class Opal_Empty_##fmt##_Encoder : public OpalEmptyFramedAudioTranscoder \
562 { \
563  public: \
564  Opal_Empty_##fmt##_Encoder() \
565  : OpalEmptyFramedAudioTranscoder(OpalPCM16, fmt) \
566  { } \
567 }; \
568 class Opal_Empty_##fmt##_Decoder : public OpalEmptyFramedAudioTranscoder \
569 { \
570  public: \
571  Opal_Empty_##fmt##_Decoder() \
572  : OpalEmptyFramedAudioTranscoder(fmt, OpalPCM16) \
573  { } \
574 }; \
575 
576 #define OPAL_DEFINE_EMPTY_TRANSCODER(fmt) \
577 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Encoder, OpalPCM16, fmt); \
578 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Decoder, fmt, OpalPCM16); \
579 
580 #endif // OPAL_OPAL_TRANSCODERS_H
581 
582 
583 // End of File ///////////////////////////////////////////////////////////////
PFactory< OpalTranscoder, OpalTranscoderKey >::KeyList_T OpalTranscoderList
Definition: transcoders.h:111
bool inputIsRTP
Definition: transcoders.h:354
virtual PBoolean ConvertSilentFrame(BYTE *output, PINDEX &created)
PINDEX outputBytesPerFrame
Definition: transcoders.h:450
RTP_DataFrame::PayloadTypes GetPayloadType(PBoolean input) const
bool acceptOtherPayloads
Definition: transcoders.h:356
Definition: transcoders.h:534
unsigned m_outClockRate
Definition: transcoders.h:358
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const =0
virtual int ConvertOne(int sample) const
Definition: mediacmd.h:43
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)
Definition: transcoders.h:525
void CopyTimestamp(RTP_DataFrame &dst, const RTP_DataFrame &src, bool inToOut) const
virtual PBoolean ExecuteCommand(const OpalMediaCommand &command)
bool outputIsRTP
Definition: transcoders.h:354
PINDEX maxOutputDataSize
Definition: transcoders.h:451
RTP_Timestamp m_lastEmptyPayloadTimestamp
Definition: transcoders.h:458
Definition: transcoders.h:469
Definition: mediatype.h:66
bool acceptEmptyPayload
Definition: transcoders.h:355
OpalStreamedTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat, unsigned inputBits, unsigned outputBits)
static OpalMediaFormatList GetSourceFormats(const OpalMediaFormat &dstFormat)
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const
OpalTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
PayloadTypes
Definition: rtp.h:556
Definition: transcoders.h:52
virtual bool AcceptComfortNoise() const
Definition: transcoders.h:328
Definition: mediafmt.h:112
unsigned m_sessionID
Definition: transcoders.h:353
virtual bool AcceptOtherPayloads() const
Definition: transcoders.h:330
std::pair< PString, PString > OpalTranscoderKey
Definition: transcoders.h:109
unsigned m_consecutivePayloadTypeMismatches
Definition: transcoders.h:361
OpalFramedTranscoder(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
void NotifyCommand(const OpalMediaCommand &command) const
Notify command notifier of command.
Definition: rtp.h:540
enum OpalFramedTranscoder::@36 m_emptyPayloadState
const OpalMediaFormat & GetInputFormat() const
Definition: transcoders.h:96
unsigned GetSessionID() const
Get session ID for the transcoder (from OpalMediaStream)
Definition: transcoders.h:319
Definition: transcoders.h:548
__inline OpalTranscoderKey MakeOpalTranscoderKey(const OpalMediaFormat &from, const OpalMediaFormat &to)
Definition: transcoders.h:114
Definition: mediafmt.h:806
static OpalMediaFormatList GetPossibleFormats(const OpalMediaFormatList &formats)
static bool SelectFormats(const OpalMediaType &mediaType, const OpalMediaFormatList &srcFormats, const OpalMediaFormatList &dstFormats, const OpalMediaFormatList &masterFormats, OpalMediaFormat &srcFormat, OpalMediaFormat &dstFormat)
Definition: transcoders.h:134
virtual bool UpdateMediaFormats(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
virtual PBoolean ConvertFrames(const RTP_DataFrame &input, RTP_DataFrameList &output)
OpalMediaFormat inputMediaFormat
Definition: transcoders.h:104
PINDEX GetMaxOutputSize() const
Definition: transcoders.h:291
PINDEX maxOutputSize
Definition: transcoders.h:349
PString GetName() const
Definition: mediafmt.h:983
void SetCommandNotifier(const PNotifier &notifier)
Definition: transcoders.h:303
void SetMaxOutputSize(PINDEX size)
virtual Comparison Compare(const PObject &obj) const
virtual bool OnCreated(const OpalMediaFormat &srcFormat, const OpalMediaFormat &destFormat, const BYTE *instance, unsigned instanceLen)
PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
Definition: transcoders.h:556
static OpalTranscoder * Create(const OpalMediaFormat &srcFormat, const OpalMediaFormat &dstFormat, const BYTE *instance=NULL, unsigned instanceLen=0)
Definition: transcoders.h:372
unsigned outputBitsPerSample
Definition: transcoders.h:519
uint32_t RTP_Timestamp
Definition: rtp.h:44
OpalEmptyFramedAudioTranscoder(const char *inFormat, const char *outFormat)
Definition: transcoders.h:552
void SetSessionID(unsigned id)
Set session ID for the transcoder (from OpalMediaStream)
Definition: transcoders.h:322
PNotifier commandNotifier
Definition: transcoders.h:350
PFactory< OpalTranscoder, OpalTranscoderKey > OpalTranscoderFactory
Definition: transcoders.h:110
void PrintOn(ostream &strm) const
virtual int ConvertOne(int sample) const
static OpalMediaFormatList GetDestinationFormats(const OpalMediaFormat &srcFormat)
PFactory< OpalTranscoder, OpalTranscoderKey >::KeyList_T::iterator OpalTranscoderIterator
Definition: transcoders.h:112
virtual bool AcceptEmptyPayload() const
Definition: transcoders.h:329
virtual PBoolean ConvertFrame(const BYTE *input, BYTE *output)
virtual PINDEX GetOptimalDataFrameSize(PBoolean input) const
static bool FindIntermediateFormat(const OpalMediaFormat &srcFormat, const OpalMediaFormat &dstFormat, OpalMediaFormat &intermediateFormat)
const OpalMediaFormat & GetOutputFormat() const
Definition: transcoders.h:100
virtual bool UpdateMediaFormats(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
Definition: mediasession.h:210
PINDEX inputBytesPerFrame
Definition: transcoders.h:449
unsigned m_inClockRate
Definition: transcoders.h:357
OpalMediaFormat outputMediaFormat
Definition: transcoders.h:105
Definition: transcoders.h:455
PDECLARE_MUTEX(updateMutex)
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)
virtual void GetStatistics(OpalMediaStatistics &statistics) const
virtual int ConvertOne(int sample) const =0
virtual PBoolean Convert(const RTP_DataFrame &input, RTP_DataFrame &output)=0
OpalMediaFormatPair(const OpalMediaFormat &inputMediaFormat, const OpalMediaFormat &outputMediaFormat)
RTP_DataFrame::PayloadTypes m_lastPayloadType
Definition: transcoders.h:360
unsigned inputBitsPerSample
Definition: transcoders.h:518
const PNotifier & GetCommandNotifier() const
Definition: transcoders.h:311