OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

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: 26728 $
28 * $Author: rjongbloed $
29 * $Date: 2011-12-01 22:59:14 -0600 (Thu, 01 Dec 2011) $
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/buildopts.h>
40
41 #include <opal/mediafmt.h>
42 #include <opal/mediacmd.h>
43
44 #include <rtp/rtp.h>
45
46 class RTP_DataFrame;
47 class OpalTranscoder;
48
49
51
55 class OpalMediaFormatPair : public PObject
56 {
57 PCLASSINFO(OpalMediaFormatPair, PObject);
58 public:
63 OpalMediaFormatPair(
64 const OpalMediaFormat & inputMediaFormat,
65 const OpalMediaFormat & outputMediaFormat
66 );
68
75 void PrintOn(
76 ostream & strm
77 ) const;
78
90 virtual Comparison Compare(
91 const PObject & obj
92 ) const;
94
99 const OpalMediaFormat & GetInputFormat() const { return inputMediaFormat; }
100
103 const OpalMediaFormat & GetOutputFormat() const { return outputMediaFormat; }
105
106 protected:
107 OpalMediaFormat inputMediaFormat;
108 OpalMediaFormat outputMediaFormat;
109 };
110
111
112 typedef std::pair<PString, PString> OpalTranscoderKey;
113 typedef PFactory<OpalTranscoder, OpalTranscoderKey> OpalTranscoderFactory;
114 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T OpalTranscoderList;
115 typedef PFactory<OpalTranscoder, OpalTranscoderKey>::KeyList_T::iterator OpalTranscoderIterator;
116
117 __inline OpalTranscoderKey MakeOpalTranscoderKey(const OpalMediaFormat & from, const OpalMediaFormat & to)
118 {
119 return OpalTranscoderKey(from.GetName(), to.GetName());
120 }
121
122 __inline OpalTranscoderKey MakeOpalTranscoderKey(const char * from, const char * to)
123 {
124 return OpalTranscoderKey(from, to);
125 }
126
127 #define OPAL_REGISTER_TRANSCODER(cls, input, output) \
128 PFACTORY_CREATE(OpalTranscoderFactory, cls, MakeOpalTranscoderKey(input, output), false)
129
130
137 class OpalTranscoder : public OpalMediaFormatPair
138 {
139 PCLASSINFO(OpalTranscoder, OpalMediaFormatPair);
140 public:
145 OpalTranscoder(
146 const OpalMediaFormat & inputMediaFormat,
147 const OpalMediaFormat & outputMediaFormat
148 );
150
166 virtual bool UpdateMediaFormats(
167 const OpalMediaFormat & inputMediaFormat,
168 const OpalMediaFormat & outputMediaFormat
169 );
170
179 virtual PBoolean ExecuteCommand(
180 const OpalMediaCommand & command
181 );
182
189 virtual PINDEX GetOptimalDataFrameSize(
190 PBoolean input
191 ) const = 0;
192
203 virtual PBoolean ConvertFrames(
204 const RTP_DataFrame & input,
205 RTP_DataFrameList & output
206 );
207
214 virtual PBoolean Convert(
215 const RTP_DataFrame & input,
216 RTP_DataFrame & output
217 ) = 0;
218
223 static OpalTranscoder * Create(
224 const OpalMediaFormat & srcFormat,
225 const OpalMediaFormat & dstFormat,
226 const BYTE * instance = NULL,
227 unsigned instanceLen = 0
228 );
229
244 static bool SelectFormats(
245 const OpalMediaType & mediaType,
246 const OpalMediaFormatList & srcFormats,
247 const OpalMediaFormatList & dstFormats,
248 const OpalMediaFormatList & allFormats,
249 OpalMediaFormat & srcFormat,
250 OpalMediaFormat & dstFormat
251 );
252
265 static bool FindIntermediateFormat(
266 const OpalMediaFormat & srcFormat,
267 const OpalMediaFormat & dstFormat,
268 OpalMediaFormat & intermediateFormat
269 );
270
273 static OpalMediaFormatList GetDestinationFormats(
274 const OpalMediaFormat & srcFormat
275 );
276
279 static OpalMediaFormatList GetSourceFormats(
280 const OpalMediaFormat & dstFormat
281 );
282
285 static OpalMediaFormatList GetPossibleFormats(
286 const OpalMediaFormatList & formats
287 );
289
294 PINDEX GetMaxOutputSize() const { return maxOutputSize; }
295
298 void SetMaxOutputSize(
299 PINDEX size
300 ) { maxOutputSize = size; }
301
306 void SetCommandNotifier(
307 const PNotifier & notifier
308 ) { commandNotifier = notifier; }
309
314 const PNotifier & GetCommandNotifier() const { return commandNotifier; }
315
317 void NotifyCommand(
318 const OpalMediaCommand & command
319 ) const;
320
322 unsigned GetSessionID() const { return m_sessionID; }
323
325 void SetSessionID(unsigned id) { m_sessionID = id; }
326
329 virtual void SetInstanceID(
330 const BYTE * instance,
331 unsigned instanceLen
332 );
333
334 RTP_DataFrame::PayloadTypes GetPayloadType(
335 PBoolean input
336 ) const;
337
338 virtual bool AcceptComfortNoise() const { return false; }
339 virtual bool AcceptEmptyPayload() const { return acceptEmptyPayload; }
340 virtual bool AcceptOtherPayloads() const { return acceptOtherPayloads; }
341
342 #if OPAL_STATISTICS
343 virtual void GetStatistics(OpalMediaStatistics & statistics) const;
344 #endif
345
346 void CopyTimestamp(RTP_DataFrame & dst, const RTP_DataFrame & src, bool inToOut) const;
348
349 protected:
350 PINDEX maxOutputSize;
351 PNotifier commandNotifier;
352 PMutex updateMutex;
353
354 unsigned m_sessionID;
355 bool outputIsRTP, inputIsRTP;
356 bool acceptEmptyPayload;
357 bool acceptOtherPayloads;
358 unsigned m_inClockRate;
359 unsigned m_outClockRate;
360 };
361
362
370 class OpalFramedTranscoder : public OpalTranscoder
371 {
372 PCLASSINFO(OpalFramedTranscoder, OpalTranscoder);
373 public:
378 OpalFramedTranscoder(
379 const OpalMediaFormat & inputMediaFormat,
380 const OpalMediaFormat & outputMediaFormat
381 );
383
399 virtual bool UpdateMediaFormats(
400 const OpalMediaFormat & inputMediaFormat,
401 const OpalMediaFormat & outputMediaFormat
402 );
403
410 virtual PINDEX GetOptimalDataFrameSize(
411 PBoolean input
412 ) const;
413
420 virtual PBoolean Convert(
421 const RTP_DataFrame & input,
422 RTP_DataFrame & output
423 );
424
428 virtual PBoolean ConvertFrame(
429 const BYTE * input,
430 BYTE * output
431 );
432 virtual PBoolean ConvertFrame(
433 const BYTE * input,
434 PINDEX & consumed,
435 BYTE * output,
436 PINDEX & created
437 );
438 virtual PBoolean ConvertSilentFrame(
439 BYTE * output
440 );
442
443 protected:
444 void CalculateSizes();
445
446 PINDEX inputBytesPerFrame;
447 PINDEX outputBytesPerFrame;
448 PINDEX maxOutputDataSize;
449 };
450
451
459 class OpalStreamedTranscoder : public OpalTranscoder
460 {
461 PCLASSINFO(OpalStreamedTranscoder, OpalTranscoder);
462 public:
467 OpalStreamedTranscoder(
468 const OpalMediaFormat & inputMediaFormat,
469 const OpalMediaFormat & outputMediaFormat,
470 unsigned inputBits,
471 unsigned outputBits
472 );
474
483 virtual PINDEX GetOptimalDataFrameSize(
484 PBoolean input
485 ) const;
486
493 virtual PBoolean Convert(
494 const RTP_DataFrame & input,
495 RTP_DataFrame & output
496 );
497
504 virtual int ConvertOne(int sample) const = 0;
506
507 protected:
508 unsigned inputBitsPerSample;
509 unsigned outputBitsPerSample;
510 };
511
512
514
515 class Opal_Linear16Mono_PCM : public OpalStreamedTranscoder {
516 public:
517 Opal_Linear16Mono_PCM();
518 virtual int ConvertOne(int sample) const;
519 };
520
521
523
524 class Opal_PCM_Linear16Mono : public OpalStreamedTranscoder {
525 public:
526 Opal_PCM_Linear16Mono();
527 virtual int ConvertOne(int sample) const;
528 };
529
530
532
533 #define OPAL_REGISTER_L16_MONO() \
534 OPAL_REGISTER_TRANSCODER(Opal_Linear16Mono_PCM, OpalL16_MONO_8KHZ, OpalPCM16); \
535 OPAL_REGISTER_TRANSCODER(Opal_PCM_Linear16Mono, OpalPCM16, OpalL16_MONO_8KHZ)
536
537
538 class OpalEmptyFramedAudioTranscoder : public OpalFramedTranscoder
539 {
540 PCLASSINFO(OpalEmptyFramedAudioTranscoder, OpalFramedTranscoder);
541 public:
542 OpalEmptyFramedAudioTranscoder(const char * inFormat, const char * outFormat)
543 : OpalFramedTranscoder(inFormat, outFormat)
544 { }
545
546 PBoolean ConvertFrame(const BYTE *, PINDEX &, BYTE *, PINDEX &)
547 { return false; }
548 };
549
550 #define OPAL_DECLARE_EMPTY_TRANSCODER(fmt) \
551 class Opal_Empty_##fmt##_Encoder : public OpalEmptyFramedAudioTranscoder \
552 { \
553 public: \
554 Opal_Empty_##fmt##_Encoder() \
555 : OpalEmptyFramedAudioTranscoder(OpalPCM16, fmt) \
556 { } \
557 }; \
558 class Opal_Empty_##fmt##_Decoder : public OpalEmptyFramedAudioTranscoder \
559 { \
560 public: \
561 Opal_Empty_##fmt##_Decoder() \
562 : OpalEmptyFramedAudioTranscoder(fmt, OpalPCM16) \
563 { } \
564 }; \
565
566 #define OPAL_DEFINE_EMPTY_TRANSCODER(fmt) \
567 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Encoder, OpalPCM16, fmt); \
568 OPAL_REGISTER_TRANSCODER(Opal_Empty_##fmt##_Decoder, fmt, OpalPCM16); \
569
570 #endif // OPAL_OPAL_TRANSCODERS_H
571
572
573 // End of File ///////////////////////////////////////////////////////////////