OPAL Version 3.10.4

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

- File List
- Globals

opalpluginmgr.h
Go to the documentation of this file.
1 /*
2 * opalpluginmgr.h
3 *
4 * OPAL codec plugins handler
5 *
6 * OPAL Library
7 *
8 * Copyright (C) 2005-2006 Post Increment
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Open Phone Abstraction Library.
21 *
22 * The Initial Developer of the Original Code is Post Increment
23 *
24 * Contributor(s): ______________________________________.
25 *
26 * $Revision: 26521 $
27 * $Author: rjongbloed $
28 * $Date: 2011-10-04 23:57:06 -0500 (Tue, 04 Oct 2011) $
29 */
30
31 #ifndef OPAL_CODEC_OPALPLUGINMGR_H
32 #define OPAL_CODEC_OPALPLUGINMGR_H
33
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37
38 #include <ptlib/object.h>
39
40 #include <opal/buildopts.h>
41
42 #include <ptlib/pluginmgr.h>
43 #include <ptlib/pfactory.h>
44 #include <codec/opalplugin.h>
45 #include <opal/mediafmt.h>
46 #include <opal/transcoders.h>
47
48 #if OPAL_H323
49 #include <h323/h323caps.h>
50 #endif
51
52 #if OPAL_VIDEO
53 #include <codec/vidcodec.h>
54 #endif
55
56
58
59 class H323Capability;
60
61 class H323StaticPluginCodec
62 {
63 public:
64 virtual ~H323StaticPluginCodec() { }
65 virtual PluginCodec_GetAPIVersionFunction Get_GetAPIFn() = 0;
66 virtual PluginCodec_GetCodecFunction Get_GetCodecFn() = 0;
67 };
68
69 typedef PFactory<H323StaticPluginCodec> H323StaticPluginCodecFactory;
70
71
73
74 class OpalPluginCodecManager;
75
76 PFACTORY_LOAD(OpalPluginCodecManager);
77
78 class OpalPluginCodecHandler : public PObject
79 {
80 PCLASSINFO(OpalPluginCodecHandler, PObject);
81 public:
82 OpalPluginCodecHandler();
83
84 static int GetChannelCount(const PluginCodec_Definition * codeDefn);
85
86 virtual OpalMediaFormatInternal * OnCreateAudioFormat(OpalPluginCodecManager & mgr,
87 const PluginCodec_Definition * codecDefn,
88 const char * fmtName,
89 const char * rtpEncodingName,
90 unsigned frameTime,
91 unsigned timeUnits,
92 time_t timeStamp);
93
94 #if OPAL_VIDEO
95 virtual OpalMediaFormatInternal * OnCreateVideoFormat(OpalPluginCodecManager & mgr,
96 const PluginCodec_Definition * codecDefn,
97 const char * fmtName,
98 const char * rtpEncodingName,
99 time_t timeStamp);
100 virtual void RegisterVideoTranscoder(const PString & src, const PString & dst, const PluginCodec_Definition * codec, bool v);
101 #endif
102
103 #if OPAL_T38_CAPABILITY
104 virtual OpalMediaFormatInternal * OnCreateFaxFormat(OpalPluginCodecManager & mgr,
105 const PluginCodec_Definition * codecDefn,
106 const char * fmtName,
107 const char * rtpEncodingName,
108 unsigned frameTime,
109 unsigned timeUnits,
110 time_t timeStamp);
111 #endif
112 };
113
114
115 class OpalPluginCodecManager : public PPluginModuleManager
116 {
117 PCLASSINFO(OpalPluginCodecManager, PPluginModuleManager);
118 public:
119 OpalPluginCodecManager(PPluginManager * pluginMgr = NULL);
120 ~OpalPluginCodecManager();
121
122 PFACTORY_GET_SINGLETON(PFactory<PPluginModuleManager>, OpalPluginCodecManager);
123
124 void RegisterStaticCodec(const H323StaticPluginCodecFactory::Key_T & name,
125 PluginCodec_GetAPIVersionFunction getApiVerFn,
126 PluginCodec_GetCodecFunction getCodecFn);
127
128 void OnLoadPlugin(PDynaLink & dll, INT code);
129
130 virtual void OnShutdown();
131
132 #if OPAL_H323
133 H323Capability * CreateCapability(
134 const PString & _mediaFormat,
135 const PString & _baseName,
136 unsigned maxFramesPerPacket,
137 unsigned recommendedFramesPerPacket,
138 unsigned _pluginSubType);
139 #endif
140
141 protected:
142 // Note the below MUST NOT be an OpalMediaFormatList
143 PList<OpalMediaFormat> mediaFormatsOnHeap;
144
145 void RegisterCodecPlugins (unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
146 void UnregisterCodecPlugins(unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
147
148 bool AddMediaFormat(OpalPluginCodecHandler * handler, const PTime & timeNow, const PluginCodec_Definition * codecDefn, const char * fmtName);
149 #if OPAL_H323
150 void RegisterCapability(const PluginCodec_Definition * codecDefn);
151 #endif
152 };
153
154
156
157 class OpalPluginControl
158 {
159 public:
160 OpalPluginControl(const PluginCodec_Definition * def, const char * name);
161
162 bool Exists() const
163 {
164 return controlDef != NULL;
165 }
166
167 int Call(void * parm, unsigned * parmLen, void * context = NULL) const
168 {
169 return controlDef != NULL ? (*controlDef->control)(codecDef, context, fnName, parm, parmLen) : -1;
170 }
171
172 int Call(void * parm, unsigned parmLen, void * context = NULL) const
173 {
174 return Call(parm, &parmLen, context);
175 }
176
177 const char * GetName() const { return fnName; }
178
179 protected:
180 const PluginCodec_Definition * codecDef;
181 const char * fnName;
182 const PluginCodec_ControlDefn * controlDef;
183 };
184
185
187
188 class OpalPluginMediaFormatInternal
189 {
190 public:
191 OpalPluginMediaFormatInternal(const PluginCodec_Definition * defn);
192
193 bool AdjustOptions(OpalMediaFormatInternal & fmt, OpalPluginControl & control) const;
194 void PopulateOptions(OpalMediaFormatInternal & format);
195 void SetOldStyleOption(OpalMediaFormatInternal & format, const PString & _key, const PString & _val, const PString & type);
196 bool IsValidForProtocol(const PString & _protocol) const;
197
198 const PluginCodec_Definition * codecDef;
199 OpalPluginControl getOptionsControl;
200 OpalPluginControl freeOptionsControl;
201 OpalPluginControl validForProtocolControl;
202 OpalPluginControl toNormalisedControl;
203 OpalPluginControl toCustomisedControl;
204 };
205
206
207 class OpalPluginMediaFormat : public OpalMediaFormat
208 {
209 public:
210 OpalPluginMediaFormat(OpalMediaFormatInternal * info)
211 : OpalMediaFormat(info)
212 {
213 }
214
215 OpalPluginMediaFormatInternal * GetInfo() const { return dynamic_cast<OpalPluginMediaFormatInternal *>(m_info); }
216 };
217
218
219 class OpalPluginTranscoder
220 {
221 public:
222 OpalPluginTranscoder(const PluginCodec_Definition * defn, bool isEnc);
223 ~OpalPluginTranscoder();
224
225 bool UpdateOptions(const OpalMediaFormat & fmt);
226 bool ExecuteCommand(const OpalMediaCommand & command);
227 bool Transcode(const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned * flags) const
228 {
229 return codecDef != NULL && codecDef->codecFunction != NULL &&
230 (codecDef->codecFunction)(codecDef, context, from, fromLen, to, toLen, flags) != 0;
231 }
232
233 protected:
234 const PluginCodec_Definition * codecDef;
235 bool isEncoder;
236 void * context;
237
238 OpalPluginControl setCodecOptions;
239 OpalPluginControl getOutputDataSizeControl;
240 };
241
242
244
245 class OpalPluginAudioFormatInternal : public OpalAudioFormatInternal, public OpalPluginMediaFormatInternal
246 {
247 public:
248 friend class OpalPluginCodecManager;
249
250 OpalPluginAudioFormatInternal(
251 const PluginCodec_Definition * codecDefn,
252 const char * fmtName,
253 const char * rtpEncodingName,
254 unsigned frameTime,
255 unsigned timeUnits,
256 time_t timeStamp
257 );
258 virtual PObject * Clone() const;
259 virtual bool IsValidForProtocol(const PString & protocol) const;
260 virtual bool ToNormalisedOptions();
261 virtual bool ToCustomisedOptions();
262 };
263
264
265 class OpalPluginFramedAudioTranscoder : public OpalFramedTranscoder, public OpalPluginTranscoder
266 {
267 PCLASSINFO(OpalPluginFramedAudioTranscoder, OpalFramedTranscoder);
268 public:
269 OpalPluginFramedAudioTranscoder(const PluginCodec_Definition * codecDefn, bool isEncoder);
270 bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
271 PBoolean ExecuteCommand(const OpalMediaCommand & command);
272 PBoolean ConvertFrame(const BYTE * input, PINDEX & consumed, BYTE * output, PINDEX & created);
273 virtual PBoolean ConvertSilentFrame(BYTE * buffer);
274 virtual bool AcceptComfortNoise() const { return comfortNoise; }
275 protected:
276 bool comfortNoise;
277 };
278
279
280 class OpalPluginStreamedAudioTranscoder : public OpalStreamedTranscoder, public OpalPluginTranscoder
281 {
282 PCLASSINFO(OpalPluginStreamedAudioTranscoder, OpalStreamedTranscoder);
283 public:
284 OpalPluginStreamedAudioTranscoder(const PluginCodec_Definition * codec, bool isEncoder);
285 bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
286 PBoolean ExecuteCommand(const OpalMediaCommand & command);
287 virtual bool AcceptComfortNoise() const { return comfortNoise; }
288 virtual int ConvertOne(int from) const;
289 protected:
290 bool comfortNoise;
291 };
292
293
295
296 #if OPAL_VIDEO
297
298 class OpalPluginVideoFormatInternal : public OpalVideoFormatInternal, public OpalPluginMediaFormatInternal
299 {
300 public:
301 OpalPluginVideoFormatInternal(
302 const PluginCodec_Definition * codec,
303 const char * fmtName,
304 const char * rtpEncodingName,
305 time_t timeStamp
306 );
307 virtual PObject * Clone() const;
308 virtual bool IsValidForProtocol(const PString & protocol) const;
309 virtual bool ToNormalisedOptions();
310 virtual bool ToCustomisedOptions();
311 };
312
313
314 class OpalPluginVideoTranscoder : public OpalVideoTranscoder, public OpalPluginTranscoder
315 {
316 PCLASSINFO(OpalPluginVideoTranscoder, OpalVideoTranscoder);
317 public:
318 OpalPluginVideoTranscoder(const PluginCodec_Definition * codec, bool isEncoder);
319 ~OpalPluginVideoTranscoder();
320
321 PBoolean ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
322 bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
323 PBoolean ExecuteCommand(const OpalMediaCommand & command);
324
325 protected:
326 bool EncodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
327 bool DecodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
328 bool DecodeFrame(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
329
330 RTP_DataFrame * m_bufferRTP;
331 DWORD m_lastDecodedTimestamp; // For missing marker bit detection
332 DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
333 bool m_badMarkers;
334 PSimpleTimer m_videoPictureLossTimer;
335
336 #if PTRACING
337 unsigned m_consecutiveIntraFrames;
338 #endif
339 };
340
341 #endif
342
344
345 #if OPAL_T38_CAPABILITY
346
347 class OpalPluginFaxFormatInternal : public OpalMediaFormatInternal, public OpalPluginMediaFormatInternal
348 {
349 public:
350 OpalPluginFaxFormatInternal(
351 const PluginCodec_Definition * codec,
352 const char * fmtName,
353 const char * rtpEncodingName,
354 unsigned frameTime,
355 unsigned /*timeUnits*/,
356 time_t timeStamp
357 );
358 virtual PObject * Clone() const;
359 virtual bool IsValidForProtocol(const PString & protocol) const;
360 };
361
362 #endif // OPAL_T38_CAPABILITY
363
364
366 //
367 // this is the base class for codecs accessible via the abstract factory functions
368 //
369
377 class OpalFactoryCodec : public PObject {
378 PCLASSINFO(OpalFactoryCodec, PObject)
379 public:
381 virtual const struct PluginCodec_Definition * GetDefinition()
382 { return NULL; }
383
385 virtual PString GetInputFormat() const = 0;
386
388 virtual PString GetOutputFormat() const = 0;
389
391 virtual int Encode(const void * from,
392 unsigned * fromLen,
393 void * to,
394 unsigned * toLen,
395 unsigned int * flag
396 ) = 0;
397
399 virtual unsigned int GetSampleRate() const = 0;
400
402 virtual unsigned int GetBitsPerSec() const = 0;
403
405 virtual unsigned int GetFrameTime() const = 0;
406
408 virtual unsigned int GetSamplesPerFrame() const = 0;
409
411 virtual unsigned int GetBytesPerFrame() const = 0;
412
414 virtual unsigned int GetRecommendedFramesPerPacket() const = 0;
415
417 virtual unsigned int GetMaxFramesPerPacket() const = 0;
418
420 virtual BYTE GetRTPPayload() const = 0;
421
423 virtual PString GetSDPFormat() const = 0;
424 };
425
427
428 template<class TranscoderClass>
429 class OpalPluginTranscoderFactory : public OpalTranscoderFactory
430 {
431 public:
432 class Worker : public OpalTranscoderFactory::WorkerBase
433 {
434 public:
435 Worker(const OpalTranscoderKey & key, const PluginCodec_Definition * codec, bool enc)
436 : OpalTranscoderFactory::WorkerBase(), codecDefn(codec), isEncoder(enc)
437 { OpalTranscoderFactory::Register(key, this); }
438
439 protected:
440 virtual OpalTranscoder * Create(const OpalTranscoderKey &) const
441 { return new TranscoderClass(codecDefn, isEncoder); }
442
443 const PluginCodec_Definition * codecDefn;
444 bool isEncoder;
445 };
446 };
447
449 //
450 // Helper class for handling plugin capabilities
451 //
452
453 class H323PluginCapabilityInfo
454 {
455 public:
456 H323PluginCapabilityInfo(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
457
458 //H323PluginCapabilityInfo(const PString & _baseName);
459
460 const PString & GetFormatName() const
461 { return m_capabilityFormatName; }
462
463 protected:
464 const PluginCodec_Definition * m_codecDefn;
465 PString m_capabilityFormatName;
466 };
467
468 #if OPAL_H323
469
471 //
472 // Class for handling most audio plugin capabilities
473 //
474
475 class H323AudioPluginCapability : public H323AudioCapability,
476 public H323PluginCapabilityInfo
477 {
478 PCLASSINFO(H323AudioPluginCapability, H323AudioCapability);
479 public:
480 H323AudioPluginCapability(const PluginCodec_Definition * codecDefn,
481 const OpalMediaFormat & mediaFormat,
482 unsigned pluginSubType);
483
484 virtual PObject * Clone() const;
485
486 virtual PString GetFormatName() const;
487
488 virtual unsigned GetSubType() const;
489
490 protected:
491 unsigned pluginSubType;
492 };
493
494 #define OPAL_DECLARE_EMPTY_AUDIO_CAPABILITY(fmt, type) \
495 class fmt##_CapabilityRegisterer { \
496 public: \
497 fmt##_CapabilityRegisterer() \
498 { H323CapabilityFactory::Register(fmt, new H323AudioPluginCapability(fmt, fmt, type)); } \
499 }; \
500
501 #define OPAL_DEFINE_EMPTY_AUDIO_CAPABILITY(fmt) \
502 static fmt##_CapabilityRegisterer fmt##_CapabilityRegisterer_instance; \
503
504
505 //
506 // Class for handling G.723.1 codecs
507 //
508
509 class H323PluginG7231Capability : public H323AudioPluginCapability
510 {
511 PCLASSINFO(H323PluginG7231Capability, H323AudioPluginCapability);
512 public:
513 H323PluginG7231Capability(const PluginCodec_Definition * codecDefn,
514 const OpalMediaFormat & mediaFormat);
515
516 virtual PObject * Clone() const;
517 virtual PBoolean OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
518 virtual PBoolean OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize);
519 };
520
521 #define OPAL_DECLARE_EMPTY_G7231_CAPABILITY(fmt, annex) \
522 class fmt##_CapabilityRegisterer { \
523 public: \
524 fmt##_CapabilityRegisterer() \
525 { H323CapabilityFactory::Register(fmt, new H323PluginG7231Capability(fmt, annex)); } \
526 }; \
527
528 #define OPAL_DEFINE_EMPTY_G7231_CAPABILITY(fmt) \
529 static fmt##_CapabilityRegisterer fmt##_CapabilityRegisterer_instance; \
530
531
532 //
533 // Class for handling non standard audio capabilities
534 //
535
536 class H323CodecPluginNonStandardAudioCapability : public H323NonStandardAudioCapability,
537 public H323PluginCapabilityInfo
538 {
539 PCLASSINFO(H323CodecPluginNonStandardAudioCapability, H323NonStandardAudioCapability);
540 public:
541 H323CodecPluginNonStandardAudioCapability(const PluginCodec_Definition * codecDefn,
542 const OpalMediaFormat & mediaFormat,
543 H323NonStandardCapabilityInfo::CompareFuncType compareFunc,
544 const unsigned char * data, unsigned dataLen);
545
546 H323CodecPluginNonStandardAudioCapability(const PluginCodec_Definition * codecDefn,
547 const OpalMediaFormat & mediaFormat,
548 const unsigned char * data, unsigned dataLen);
549
550 virtual PObject * Clone() const;
551
552 virtual PString GetFormatName() const;
553 };
554
556 //
557 // Class for handling generic audio capabilities
558 //
559
560 class H323CodecPluginGenericAudioCapability : public H323GenericAudioCapability,
561 public H323PluginCapabilityInfo
562 {
563 PCLASSINFO(H323CodecPluginGenericAudioCapability, H323GenericAudioCapability);
564 public:
565 H323CodecPluginGenericAudioCapability(const PluginCodec_Definition * codecDefn,
566 const OpalMediaFormat & mediaFormat,
567 const PluginCodec_H323GenericCodecData * data);
568
569 virtual PObject * Clone() const;
570 virtual PString GetFormatName() const;
571 };
572
573
574 #if OPAL_VIDEO
575
577 //
578 // Class for handling most audio plugin capabilities
579 //
580
581 class H323VideoPluginCapability : public H323VideoCapability,
582 public H323PluginCapabilityInfo
583 {
584 PCLASSINFO(H323VideoPluginCapability, H323VideoCapability);
585 public:
586 H323VideoPluginCapability(const PluginCodec_Definition * codecDefn,
587 const OpalMediaFormat & mediaFormat,
588 unsigned _pluginSubType);
589
590 virtual PString GetFormatName() const;
591
592 virtual unsigned GetSubType() const;
593
594 static bool SetOptionsFromMPI(OpalMediaFormat & mediaFormat, int frameWidth, int frameHeight, int frameRate);
595
596 virtual void PrintOn(std::ostream & strm) const;
597
598 protected:
599 unsigned pluginSubType;
600 unsigned h323subType; // only set if using capability without codec
601 };
602
604 //
605 // Class for handling non standard video capabilities
606 //
607
608 class H323CodecPluginNonStandardVideoCapability : public H323NonStandardVideoCapability,
609 public H323PluginCapabilityInfo
610 {
611 PCLASSINFO(H323CodecPluginNonStandardVideoCapability, H323NonStandardVideoCapability);
612 public:
613 H323CodecPluginNonStandardVideoCapability(const PluginCodec_Definition * codecDefn,
614 const OpalMediaFormat & mediaFormat,
615 H323NonStandardCapabilityInfo::CompareFuncType compareFunc,
616 const unsigned char * data, unsigned dataLen);
617
618 H323CodecPluginNonStandardVideoCapability(const PluginCodec_Definition * codecDefn,
619 const OpalMediaFormat & mediaFormat,
620 const unsigned char * data, unsigned dataLen);
621
622 virtual PObject * Clone() const;
623
624 virtual PString GetFormatName() const;
625 };
626
628 //
629 // Class for handling generic video capabilities
630 //
631
632 class H323CodecPluginGenericVideoCapability : public H323GenericVideoCapability,
633 public H323PluginCapabilityInfo
634 {
635 PCLASSINFO(H323CodecPluginGenericVideoCapability, H323GenericVideoCapability);
636 public:
637 H323CodecPluginGenericVideoCapability(const PluginCodec_Definition * codecDefn,
638 const OpalMediaFormat & mediaFormat,
639 const PluginCodec_H323GenericCodecData * data);
640
641 virtual PObject * Clone() const;
642
643 virtual PString GetFormatName() const;
644 };
645
647 //
648 // Class for handling H.261 plugin capabilities
649 //
650
651 class H323H261PluginCapability : public H323VideoPluginCapability
652 {
653 PCLASSINFO(H323H261PluginCapability, H323VideoPluginCapability);
654 public:
655 H323H261PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
656
657 Comparison Compare(const PObject & obj) const;
658
659 virtual PObject * Clone() const;
660
661 virtual PBoolean OnSendingPDU(
662 H245_VideoCapability & pdu
663 ) const;
664
665 virtual PBoolean OnSendingPDU(
666 H245_VideoMode & pdu
667 ) const;
668
669 virtual PBoolean OnReceivedPDU(
670 const H245_VideoCapability & pdu
671 );
672 };
673
675 //
676 // Class for handling H.263 plugin capabilities
677 //
678
679 class H323H263PluginCapability : public H323VideoPluginCapability
680 {
681 PCLASSINFO(H323H263PluginCapability, H323VideoPluginCapability);
682 public:
683 H323H263PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
684
685 Comparison Compare(const PObject & obj) const;
686
687 virtual PObject * Clone() const;
688
689 virtual PBoolean OnSendingPDU(
690 H245_VideoCapability & pdu
691 ) const;
692
693 virtual PBoolean OnSendingPDU(
694 H245_VideoMode & pdu
695 ) const;
696
697 virtual PBoolean OnReceivedPDU(
698 const H245_VideoCapability & pdu
699 );
700 virtual PBoolean IsMatch(const PASN_Choice & subTypePDU) const;
701 };
702
703 #endif // OPAL_VIDEO
704 #endif // OPAL_H323
705
706 #endif // OPAL_CODEC_OPALPLUGINMGR_H