OPAL  Version 3.10.10
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: 28134 $
27  * $Author: rjongbloed $
28  * $Date: 2012-08-01 19:48:35 -0500 (Wed, 01 Aug 2012) $
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 
62 {
63  public:
64  virtual ~H323StaticPluginCodec() { }
66  virtual PluginCodec_GetCodecFunction Get_GetCodecFn() = 0;
67 };
68 
69 typedef PFactory<H323StaticPluginCodec> H323StaticPluginCodecFactory;
70 
71 
73 
75 
77 
78 class OpalPluginCodecHandler : public PObject
79 {
80  PCLASSINFO(OpalPluginCodecHandler, PObject);
81  public:
83 
84  static int GetChannelCount(const PluginCodec_Definition * codeDefn);
85 
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
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);
121 
122  PFACTORY_GET_SINGLETON(PFactory<PPluginModuleManager>, OpalPluginCodecManager);
123 
124  void RegisterStaticCodec(const H323StaticPluginCodecFactory::Key_T & name,
126  PluginCodec_GetCodecFunction getCodecFn);
127 
128  void OnLoadPlugin(PDynaLink & dll, INT code);
129 
130  virtual void OnShutdown();
131 
132 #if OPAL_H323
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 
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:
181  const char * fnName;
183 };
184 
185 
187 
189 {
190  public:
192 
193  bool AdjustOptions(OpalMediaFormatInternal & fmt, OpalPluginControl & control) const;
195  void SetOldStyleOption(OpalMediaFormatInternal & format, const PString & _key, const PString & _val, const PString & type);
196  bool IsValidForProtocol(const PString & _protocol) const;
197 
204 };
205 
206 
208 {
209  public:
211  : OpalMediaFormat(info)
212  {
213  }
214 
216 };
217 
218 
220 {
221  public:
222  OpalPluginTranscoder(const PluginCodec_Definition * defn, bool isEnc);
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:
235  bool isEncoder;
236  void * context;
237 
240 };
241 
242 
244 
246 {
247  public:
249 
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 
266 {
268  public:
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:
277 };
278 
279 
281 {
283  public:
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:
291 };
292 
293 
295 
296 #if OPAL_VIDEO
297 
299 {
300  public:
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 
315 {
317  public:
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 
332  DWORD m_lastDecodedTimestamp; // For missing marker bit detection
333  DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
336 
337 #if PTRACING
338  unsigned m_consecutiveIntraFrames;
339 #endif
340 };
341 
342 #endif
343 
345 
346 #if OPAL_FAX
347 
349 {
350  public:
352  const PluginCodec_Definition * codec,
353  const char * fmtName,
354  const char * rtpEncodingName,
355  unsigned frameTime,
356  unsigned /*timeUnits*/,
357  time_t timeStamp
358  );
359  virtual PObject * Clone() const;
360  virtual bool IsValidForProtocol(const PString & protocol) const;
361 };
362 
363 #endif // OPAL_FAX
364 
365 
367 //
368 // this is the base class for codecs accessible via the abstract factory functions
369 //
370 
378 class OpalFactoryCodec : public PObject {
379  PCLASSINFO(OpalFactoryCodec, PObject)
380  public:
382  virtual const struct PluginCodec_Definition * GetDefinition()
383  { return NULL; }
384 
386  virtual PString GetInputFormat() const = 0;
387 
389  virtual PString GetOutputFormat() const = 0;
390 
392  virtual int Encode(const void * from,
393  unsigned * fromLen,
394  void * to,
395  unsigned * toLen,
396  unsigned int * flag
397  ) = 0;
398 
400  virtual unsigned int GetSampleRate() const = 0;
401 
403  virtual unsigned int GetBitsPerSec() const = 0;
404 
406  virtual unsigned int GetFrameTime() const = 0;
407 
409  virtual unsigned int GetSamplesPerFrame() const = 0;
410 
412  virtual unsigned int GetBytesPerFrame() const = 0;
413 
415  virtual unsigned int GetRecommendedFramesPerPacket() const = 0;
416 
418  virtual unsigned int GetMaxFramesPerPacket() const = 0;
419 
421  virtual BYTE GetRTPPayload() const = 0;
422 
424  virtual PString GetSDPFormat() const = 0;
425 };
426 
428 
429 template<class TranscoderClass>
431 {
432  public:
433  class Worker : public OpalTranscoderFactory::WorkerBase
434  {
435  public:
436  Worker(const OpalTranscoderKey & key, const PluginCodec_Definition * codec, bool enc)
437  : OpalTranscoderFactory::WorkerBase(), codecDefn(codec), isEncoder(enc)
438  { OpalTranscoderFactory::Register(key, this); }
439 
440  protected:
441  virtual OpalTranscoder * Create(const OpalTranscoderKey &) const
442  { return new TranscoderClass(codecDefn, isEncoder); }
443 
445  bool isEncoder;
446  };
447 };
448 
450 //
451 // Helper class for handling plugin capabilities
452 //
453 
455 {
456  public:
457  H323PluginCapabilityInfo(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
458 
459  //H323PluginCapabilityInfo(const PString & _baseName);
460 
461  const PString & GetFormatName() const
462  { return m_capabilityFormatName; }
463 
464  protected:
467 };
468 
469 #if OPAL_H323
470 
472 //
473 // Class for handling most audio plugin capabilities
474 //
475 
478 {
480  public:
482  const OpalMediaFormat & mediaFormat,
483  unsigned pluginSubType);
484 
485  virtual PObject * Clone() const;
486 
487  virtual PString GetFormatName() const;
488 
489  virtual unsigned GetSubType() const;
490 
491  protected:
492  unsigned pluginSubType;
493 };
494 
495 #define OPAL_DECLARE_EMPTY_AUDIO_CAPABILITY(fmt, type) \
496 class fmt##_CapabilityRegisterer { \
497  public: \
498  fmt##_CapabilityRegisterer() \
499  { H323CapabilityFactory::Register(fmt, new H323AudioPluginCapability(fmt, fmt, type)); } \
500 }; \
501 
502 #define OPAL_DEFINE_EMPTY_AUDIO_CAPABILITY(fmt) \
503 static fmt##_CapabilityRegisterer fmt##_CapabilityRegisterer_instance; \
504 
505 
506 //
507 // Class for handling G.723.1 codecs
508 //
509 
511 {
513  public:
515  const OpalMediaFormat & mediaFormat);
516 
517  virtual PObject * Clone() const;
518  virtual PBoolean OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
519  virtual PBoolean OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize);
520 };
521 
522 #define OPAL_DECLARE_EMPTY_G7231_CAPABILITY(fmt, annex) \
523 class fmt##_CapabilityRegisterer { \
524  public: \
525  fmt##_CapabilityRegisterer() \
526  { H323CapabilityFactory::Register(fmt, new H323PluginG7231Capability(fmt, annex)); } \
527 }; \
528 
529 #define OPAL_DEFINE_EMPTY_G7231_CAPABILITY(fmt) \
530 static fmt##_CapabilityRegisterer fmt##_CapabilityRegisterer_instance; \
531 
532 
533 //
534 // Class for handling non standard audio capabilities
535 //
536 
539 {
541  public:
543  const OpalMediaFormat & mediaFormat,
545  const unsigned char * data, unsigned dataLen);
546 
548  const OpalMediaFormat & mediaFormat,
549  const unsigned char * data, unsigned dataLen);
550 
551  virtual PObject * Clone() const;
552 
553  virtual PString GetFormatName() const;
554 };
555 
557 //
558 // Class for handling generic audio capabilities
559 //
560 
563 {
565  public:
567  const OpalMediaFormat & mediaFormat,
568  const PluginCodec_H323GenericCodecData * data);
569 
570  virtual PObject * Clone() const;
571  virtual PString GetFormatName() const;
572 };
573 
574 
575 #if OPAL_VIDEO
576 
578 //
579 // Class for handling non standard video capabilities
580 //
581 
584 {
586  public:
588  const OpalMediaFormat & mediaFormat,
590  const unsigned char * data, unsigned dataLen);
591 
593  const OpalMediaFormat & mediaFormat,
594  const unsigned char * data, unsigned dataLen);
595 
596  virtual PObject * Clone() const;
597 
598  virtual PString GetFormatName() const;
599 };
600 
602 //
603 // Class for handling generic video capabilities
604 //
605 
608 {
610  public:
612  const OpalMediaFormat & mediaFormat,
613  const PluginCodec_H323GenericCodecData * data);
614 
615  virtual PObject * Clone() const;
616 
617  virtual PString GetFormatName() const;
618 };
619 
621 //
622 // Class for handling H.261 plugin capabilities
623 //
624 
627 {
629  public:
630  H323H261PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
631 
632  Comparison Compare(const PObject & obj) const;
633 
634  virtual PObject * Clone() const;
635 
636  virtual PString GetFormatName() const;
637  virtual unsigned GetSubType() const;
638 
639  virtual PBoolean OnSendingPDU(
640  H245_VideoCapability & pdu
641  ) const;
642 
643  virtual PBoolean OnSendingPDU(
644  H245_VideoMode & pdu
645  ) const;
646 
647  virtual PBoolean OnReceivedPDU(
648  const H245_VideoCapability & pdu
649  );
650 };
651 
653 //
654 // Class for handling H.263 plugin capabilities
655 //
656 
659 {
661  public:
662  H323H263PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
663 
664  Comparison Compare(const PObject & obj) const;
665 
666  virtual PObject * Clone() const;
667 
668  virtual PString GetFormatName() const;
669  virtual unsigned GetSubType() const;
670 
671  virtual PBoolean OnSendingPDU(
672  H245_VideoCapability & pdu
673  ) const;
674 
675  virtual PBoolean OnSendingPDU(
676  H245_VideoMode & pdu
677  ) const;
678 
679  virtual PBoolean OnReceivedPDU(
680  const H245_VideoCapability & pdu
681  );
682  virtual PBoolean IsMatch(
683  const PASN_Choice & subTypePDU,
684  const PString & mediaPacketization
685  ) const;
686 };
687 
688 #endif // OPAL_VIDEO
689 #endif // OPAL_H323
690 
691 #endif // OPAL_CODEC_OPALPLUGINMGR_H