OPAL  Version 3.12.5
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: 30188 $
27  * $Author: rjongbloed $
28  * $Date: 2013-07-28 23:37:22 -0500 (Sun, 28 Jul 2013) $
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_FAX
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, P_INT_PTR code);
129 
130  virtual void OnStartup();
131  virtual void OnShutdown();
132 
133 #if OPAL_H323
135  const PString & _mediaFormat,
136  const PString & _baseName,
137  unsigned maxFramesPerPacket,
138  unsigned recommendedFramesPerPacket,
139  unsigned _pluginSubType);
140 #endif
141 
142  protected:
143  // Note the below MUST NOT be an OpalMediaFormatList
144  PList<OpalMediaFormat> mediaFormatsOnHeap;
145 
146  void RegisterCodecPlugins (unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
147  void UnregisterCodecPlugins(unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
148 
149  bool AddMediaFormat(OpalPluginCodecHandler * handler, const PTime & timeNow, const PluginCodec_Definition * codecDefn, const char * fmtName);
150 #if OPAL_H323
151  void RegisterCapability(const PluginCodec_Definition * codecDefn);
152 #endif
153 };
154 
155 
157 
159 {
160  public:
161  OpalPluginControl(const PluginCodec_Definition * def, const char * name);
162 
163  bool Exists() const
164  {
165  return controlDef != NULL;
166  }
167 
168  int Call(void * parm, unsigned * parmLen, void * context = NULL) const
169  {
170  return controlDef != NULL ? (*controlDef->control)(codecDef, context, fnName, parm, parmLen) : -1;
171  }
172 
173  int Call(void * parm, unsigned parmLen, void * context = NULL) const
174  {
175  return Call(parm, &parmLen, context);
176  }
177 
178  const char * GetName() const { return fnName; }
179 
180  protected:
182  const char * fnName;
184 };
185 
186 
188 
190 {
191  public:
193 
194  bool AdjustOptions(OpalMediaFormatInternal & fmt, OpalPluginControl & control) const;
196  void SetOldStyleOption(OpalMediaFormatInternal & format, const PString & _key, const PString & _val, const PString & type);
197  bool IsValidForProtocol(const PString & _protocol) const;
198 
205 };
206 
207 
209 {
210  public:
212  : OpalMediaFormat(info)
213  {
214  }
215 
217 };
218 
219 
221 {
222  public:
223  OpalPluginTranscoder(const PluginCodec_Definition * defn, bool isEnc);
225 
226  bool UpdateOptions(OpalMediaFormat & fmt);
227  bool ExecuteCommand(const OpalMediaCommand & command);
228  bool Transcode(const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned * flags) const
229  {
230  return codecDef != NULL && codecDef->codecFunction != NULL &&
231  (codecDef->codecFunction)(codecDef, context, from, fromLen, to, toLen, flags) != 0;
232  }
233 
234  protected:
236  bool isEncoder;
237  void * context;
238 
244 };
245 
246 
248 
250 {
251  public:
253 
255  const PluginCodec_Definition * codecDefn,
256  const char * fmtName,
257  const char * rtpEncodingName,
258  unsigned frameTime,
259  unsigned timeUnits,
260  time_t timeStamp
261  );
262  virtual PObject * Clone() const;
263  virtual bool IsValidForProtocol(const PString & protocol) const;
264  virtual bool ToNormalisedOptions();
265  virtual bool ToCustomisedOptions();
266 };
267 
268 
270 {
272  public:
274  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
275  PBoolean ExecuteCommand(const OpalMediaCommand & command);
276  PBoolean ConvertFrame(const BYTE * input, PINDEX & consumed, BYTE * output, PINDEX & created);
277  virtual PBoolean ConvertSilentFrame(BYTE * buffer);
278  virtual bool AcceptComfortNoise() const { return comfortNoise; }
279  protected:
281 };
282 
283 
285 {
287  public:
289  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
290  PBoolean ExecuteCommand(const OpalMediaCommand & command);
291  virtual bool AcceptComfortNoise() const { return comfortNoise; }
292  virtual int ConvertOne(int from) const;
293  protected:
295 };
296 
297 
299 
300 #if OPAL_VIDEO
301 
303 {
304  public:
306  const PluginCodec_Definition * codec,
307  const char * fmtName,
308  const char * rtpEncodingName,
309  time_t timeStamp
310  );
311  virtual PObject * Clone() const;
312  virtual bool IsValidForProtocol(const PString & protocol) const;
313  virtual bool ToNormalisedOptions();
314  virtual bool ToCustomisedOptions();
315 };
316 
317 
319 {
321  public:
324 
325 #if OPAL_STATISTICS
326  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
327 #endif
328 
329  PBoolean ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
330  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
331  PBoolean ExecuteCommand(const OpalMediaCommand & command);
332 
333  protected:
334  bool EncodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
335  bool DecodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
336  bool DecodeFrame(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
337 
340  DWORD m_lastDecodedTimestamp; // For missing marker bit detection
341  DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
344 
345 #if PTRACING
346  unsigned m_consecutiveIntraFrames;
347 #endif
348 };
349 
350 #endif
351 
353 
354 #if OPAL_FAX
355 
357 {
358  public:
360  const PluginCodec_Definition * codec,
361  const char * fmtName,
362  const char * rtpEncodingName,
363  unsigned frameTime,
364  unsigned /*timeUnits*/,
365  time_t timeStamp
366  );
367  virtual PObject * Clone() const;
368  virtual bool IsValidForProtocol(const PString & protocol) const;
369 };
370 
371 #endif // OPAL_FAX
372 
373 
375 //
376 // this is the base class for codecs accessible via the abstract factory functions
377 //
378 
386 class OpalFactoryCodec : public PObject {
387  PCLASSINFO(OpalFactoryCodec, PObject)
388  public:
390  virtual const struct PluginCodec_Definition * GetDefinition()
391  { return NULL; }
392 
394  virtual PString GetInputFormat() const = 0;
395 
397  virtual PString GetOutputFormat() const = 0;
398 
400  virtual int Encode(const void * from,
401  unsigned * fromLen,
402  void * to,
403  unsigned * toLen,
404  unsigned int * flag
405  ) = 0;
406 
408  virtual unsigned int GetSampleRate() const = 0;
409 
411  virtual unsigned int GetBitsPerSec() const = 0;
412 
414  virtual unsigned int GetFrameTime() const = 0;
415 
417  virtual unsigned int GetSamplesPerFrame() const = 0;
418 
420  virtual unsigned int GetBytesPerFrame() const = 0;
421 
423  virtual unsigned int GetRecommendedFramesPerPacket() const = 0;
424 
426  virtual unsigned int GetMaxFramesPerPacket() const = 0;
427 
429  virtual BYTE GetRTPPayload() const = 0;
430 
432  virtual PString GetSDPFormat() const = 0;
433 };
434 
436 
437 template<class TranscoderClass>
439 {
440  public:
441  class Worker : public OpalTranscoderFactory::WorkerBase
442  {
443  public:
444  Worker(const OpalTranscoderKey & key, const PluginCodec_Definition * codec, bool enc)
445  : OpalTranscoderFactory::WorkerBase(), codecDefn(codec), isEncoder(enc)
446  { OpalTranscoderFactory::Register(key, this); }
447 
448  protected:
449  virtual OpalTranscoder * Create(const OpalTranscoderKey &) const
450  { return new TranscoderClass(codecDefn, isEncoder); }
451 
453  bool isEncoder;
454  };
455 };
456 
458 //
459 // Helper class for handling plugin capabilities
460 //
461 
463 {
464  public:
465  H323PluginCapabilityInfo(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
466 
467  //H323PluginCapabilityInfo(const PString & _baseName);
468 
469  const PString & GetFormatName() const
470  { return m_capabilityFormatName; }
471 
472  protected:
475 };
476 
477 #if OPAL_H323
478 
480 //
481 // Class for handling most audio plugin capabilities
482 //
483 
486 {
488  public:
490  const OpalMediaFormat & mediaFormat,
491  unsigned pluginSubType);
492 
493  virtual PObject * Clone() const;
494 
495  virtual PString GetFormatName() const;
496 
497  virtual unsigned GetSubType() const;
498 
499  protected:
500  unsigned pluginSubType;
501 };
502 
503 
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 
523 //
524 // Class for handling non standard audio capabilities
525 //
526 
529 {
531  public:
533  const OpalMediaFormat & mediaFormat,
535  const unsigned char * data, unsigned dataLen);
536 
538  const OpalMediaFormat & mediaFormat,
539  const unsigned char * data, unsigned dataLen);
540 
541  virtual PObject * Clone() const;
542 
543  virtual PString GetFormatName() const;
544 };
545 
547 //
548 // Class for handling generic audio capabilities
549 //
550 
553 {
555  public:
557  const OpalMediaFormat & mediaFormat,
558  const PluginCodec_H323GenericCodecData * data);
559 
560  virtual PObject * Clone() const;
561  virtual PString GetFormatName() const;
562 };
563 
564 
565 #if OPAL_VIDEO
566 
568 //
569 // Class for handling non standard video capabilities
570 //
571 
574 {
576  public:
578  const OpalMediaFormat & mediaFormat,
580  const unsigned char * data, unsigned dataLen);
581 
583  const OpalMediaFormat & mediaFormat,
584  const unsigned char * data, unsigned dataLen);
585 
586  virtual PObject * Clone() const;
587 
588  virtual PString GetFormatName() const;
589 };
590 
592 //
593 // Class for handling generic video capabilities
594 //
595 
598 {
600  public:
602  const OpalMediaFormat & mediaFormat,
603  const PluginCodec_H323GenericCodecData * data);
604 
605  virtual PObject * Clone() const;
606 
607  virtual PString GetFormatName() const;
608 };
609 
611 //
612 // Class for handling H.261 plugin capabilities
613 //
614 
616 {
618  public:
620 
621  Comparison Compare(const PObject & obj) const;
622 
623  virtual PObject * Clone() const;
624 
625  virtual PString GetFormatName() const;
626  virtual unsigned GetSubType() const;
627 
628  virtual PBoolean OnSendingPDU(
629  H245_VideoCapability & pdu
630  ) const;
631 
632  virtual PBoolean OnSendingPDU(
633  H245_VideoMode & pdu
634  ) const;
635 
636  virtual PBoolean OnReceivedPDU(
637  const H245_VideoCapability & pdu
638  );
639 };
640 
641 
644 {
646  public:
647  H323H261PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
648 
649  virtual PObject * Clone() const;
650 };
651 
652 
654 //
655 // Class for handling H.263 plugin capabilities
656 //
657 
659 {
660  public:
661  H323H263Capability(const PString & variant);
662 
663  Comparison Compare(const PObject & obj) const;
664 
665  virtual PObject * Clone() const;
666 
667  virtual PString GetFormatName() const;
668  virtual unsigned GetSubType() const;
669 
670  virtual PBoolean OnSendingPDU(
671  H245_VideoCapability & pdu
672  ) const;
673 
674  virtual PBoolean OnSendingPDU(
675  H245_VideoMode & pdu
676  ) const;
677 
678  virtual PBoolean OnReceivedPDU(
679  const H245_VideoCapability & pdu
680  );
681  virtual PBoolean IsMatch(
682  const PASN_Choice & subTypePDU,
683  const PString & mediaPacketization
684  ) const;
685 
686  protected:
687  PString m_variant;
688 };
689 
692 {
694  public:
695  H323H263PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat)
696  : H323H263Capability(mediaFormat)
697  , H323PluginCapabilityInfo(codecDefn, mediaFormat)
698  {
699  }
700 };
701 
702 #endif // OPAL_VIDEO
703 #endif // OPAL_H323
704 
705 #endif // OPAL_CODEC_OPALPLUGINMGR_H