OPAL  Version 3.14.3
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  * $Revision: 32291 $
28  * $Author: rjongbloed $
29  * $Date: 2014-07-03 18:18:10 +1000 (Thu, 03 Jul 2014) $
30  */
31 
32 #ifndef OPAL_OPAL_TRANSCODERS_H
33 #define OPAL_OPAL_TRANSCODERS_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <opal_config.h>
40 
41 #include <opal/mediafmt.h>
42 #include <opal/mediacmd.h>
43 #include <opal/mediasession.h>
44 
45 #include <rtp/rtp.h>
46 
47 class RTP_DataFrame;
48 class OpalTranscoder;
49 
50 
52 
56 class OpalMediaFormatPair : public PObject
57 {
58  PCLASSINFO(OpalMediaFormatPair, PObject);
59  public:
67  );
69 
76  void PrintOn(
77  ostream & strm
78  ) const;
79 
91  virtual Comparison Compare(
92  const PObject & obj
93  ) const;
95 
100  const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
101 
106 
107  protected:
110 };
111 
112 
113 typedef std::pair<PString, PString> OpalTranscoderKey;
114 typedef PFactory<OpalTranscoder, OpalTranscoderKey> OpalTranscoderFactory;
115 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T OpalTranscoderList;
116 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T::iterator OpalTranscoderIterator;
117 
119 {
120  return OpalTranscoderKey(from.GetName(), to.GetName());
121 }
122 
123 __inline OpalTranscoderKey MakeOpalTranscoderKey(const char * from, const char * to)
124 {
125  return OpalTranscoderKey(from, to);
126 }
127 
128 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \
129  PFACTORY_CREATE(OpalTranscoderFactory, cls, MakeOpalTranscoderKey(input, output), false)
130 
131 
139 {
140  PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
141  public:
149  );
151 
167  virtual bool UpdateMediaFormats(
168  const OpalMediaFormat & inputMediaFormat,
169  const OpalMediaFormat & outputMediaFormat
170  );
171 
180  virtual PBoolean ExecuteCommand(
181  const OpalMediaCommand & command
182  );
183 
190  virtual PINDEX GetOptimalDataFrameSize(
191  PBoolean input
192  ) const = 0;
193 
204  virtual PBoolean ConvertFrames(
205  const RTP_DataFrame & input,
206  RTP_DataFrameList & output
207  );
208 
215  virtual PBoolean Convert(
216  const RTP_DataFrame & input,
217  RTP_DataFrame & output
218  ) = 0;
219 
224  static OpalTranscoder * Create(
225  const OpalMediaFormat & srcFormat,
226  const OpalMediaFormat & dstFormat,
227  const BYTE * instance = NULL,
228  unsigned instanceLen = 0
229  );
230 
245  static bool SelectFormats(
246  const OpalMediaType & mediaType,
247  const OpalMediaFormatList & srcFormats,
248  const OpalMediaFormatList & dstFormats,
249  const OpalMediaFormatList & allFormats,
250  OpalMediaFormat & srcFormat,
251  OpalMediaFormat & dstFormat
252  );
253 
266  static bool FindIntermediateFormat(
267  const OpalMediaFormat & srcFormat,
268  const OpalMediaFormat & dstFormat,
269  OpalMediaFormat & intermediateFormat
270  );
271 
275  const OpalMediaFormat & srcFormat
276  );
277 
281  const OpalMediaFormat & dstFormat
282  );
283 
287  const OpalMediaFormatList & formats
288  );
290 
295  PINDEX GetMaxOutputSize() const { return maxOutputSize; }
296 
299  void SetMaxOutputSize(
300  PINDEX size
301  );
302 
308  const PNotifier & notifier
309  ) { commandNotifier = notifier; }
310 
315  const PNotifier & GetCommandNotifier() const { return commandNotifier; }
316 
318  void NotifyCommand(
319  const OpalMediaCommand & command
320  ) const;
321 
323  unsigned GetSessionID() const { return m_sessionID; }
324 
326  void SetSessionID(unsigned id) { m_sessionID = id; }
327 
330  virtual void SetInstanceID(
331  const BYTE * instance,
332  unsigned instanceLen
333  );
334 
336  PBoolean input
337  ) const;
338 
339  virtual bool AcceptComfortNoise() const { return false; }
340  virtual bool AcceptEmptyPayload() const { return acceptEmptyPayload; }
341  virtual bool AcceptOtherPayloads() const { return acceptOtherPayloads; }
342 
343 #if OPAL_STATISTICS
344  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
345 #endif
346 
347  void CopyTimestamp(RTP_DataFrame & dst, const RTP_DataFrame & src, bool inToOut) const;
349 
350  protected:
352  PNotifier commandNotifier;
353  PMutex updateMutex;
354 
355  unsigned m_sessionID;
359  unsigned m_inClockRate;
360  unsigned m_outClockRate;
361 
364 };
365 
366 
375 {
377  public:
385  );
387 
403  virtual bool UpdateMediaFormats(
404  const OpalMediaFormat & inputMediaFormat,
405  const OpalMediaFormat & outputMediaFormat
406  );
407 
414  virtual PINDEX GetOptimalDataFrameSize(
415  PBoolean input
416  ) const;
417 
424  virtual PBoolean Convert(
425  const RTP_DataFrame & input,
426  RTP_DataFrame & output
427  );
428 
432  virtual PBoolean ConvertFrame(
433  const BYTE * input,
434  BYTE * output
435  );
436  virtual PBoolean ConvertFrame(
437  const BYTE * input,
438  PINDEX & consumed,
439  BYTE * output,
440  PINDEX & created
441  );
442  virtual PBoolean ConvertSilentFrame(
443  BYTE * output
444  );
446 
447  protected:
448  void CalculateSizes();
449 
453 };
454 
455 
464 {
466  public:
474  unsigned inputBits,
475  unsigned outputBits
476  );
478 
487  virtual PINDEX GetOptimalDataFrameSize(
488  PBoolean input
489  ) const;
490 
497  virtual PBoolean Convert(
498  const RTP_DataFrame & input,
499  RTP_DataFrame & output
500  );
501 
508  virtual int ConvertOne(int sample) const = 0;
510 
511  protected:
514 };
515 
516 
518 
520  public:
522  virtual int ConvertOne(int sample) const;
523 };
524 
525 
527 
529  public:
531  virtual int ConvertOne(int sample) const;
532 };
533 
534 
536 
537 #define OPAL_REGISTER_L16_MONO() \
538  OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
539  OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ)
540 
541 
543 {
545  public:
546  OpalEmptyFramedAudioTranscoder(const char * inFormat, const char * outFormat)
547  : OpalFramedTranscoder(inFormat, outFormat)
548  { }
549 
550  PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
551  { return false; }
552 };
553 
554 #define OPAL_DECLARE_EMPTY_TRANSCODER(fmt) \
555 class Opal_Empty_##fmt##_Encoder : public OpalEmptyFramedAudioTranscoder \
556 { \
557  public: \
558  Opal_Empty_##fmt##_Encoder() \
559  : OpalEmptyFramedAudioTranscoder(OpalPCM16, fmt) \
560  { } \
561 }; \
562 class Opal_Empty_##fmt##_Decoder : public OpalEmptyFramedAudioTranscoder \
563 { \
564  public: \
565  Opal_Empty_##fmt##_Decoder() \
566  : OpalEmptyFramedAudioTranscoder(fmt, OpalPCM16) \
567  { } \
568 }; \
569 
570 #define OPAL_DEFINE_EMPTY_TRANSCODER(fmt) \
571 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Encoder, OpalPCM16, fmt); \
572 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Decoder, fmt, OpalPCM16); \
573 
574 #endif // OPAL_OPAL_TRANSCODERS_H
575 
576 
577 // End of File ///////////////////////////////////////////////////////////////