OPAL  Version 3.10.4
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 
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 
331  DWORD m_lastDecodedTimestamp; // For missing marker bit detection
332  DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
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>
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 
444  bool isEncoder;
445  };
446 };
447 
449 //
450 // Helper class for handling plugin capabilities
451 //
452 
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:
466 };
467 
468 #if OPAL_H323
469 
471 //
472 // Class for handling most audio plugin capabilities
473 //
474 
477 {
479  public:
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 
510 {
512  public:
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 
538 {
540  public:
542  const OpalMediaFormat & mediaFormat,
544  const unsigned char * data, unsigned dataLen);
545 
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 
562 {
564  public:
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 
583 {
585  public:
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 
610 {
612  public:
614  const OpalMediaFormat & mediaFormat,
616  const unsigned char * data, unsigned dataLen);
617 
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 
634 {
636  public:
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 
652 {
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 
680 {
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