OPAL  Version 3.12.9
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: 30561 $
27  * $Author: rjongbloed $
28  * $Date: 2013-09-24 14:32:49 +1000 (Tue, 24 Sep 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:
211  OpalPluginTranscoder(const PluginCodec_Definition * defn, bool isEnc);
213 
214  bool UpdateOptions(OpalMediaFormat & fmt);
215  bool ExecuteCommand(const OpalMediaCommand & command);
216  bool Transcode(const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned * flags) const
217  {
218  return codecDef != NULL && codecDef->codecFunction != NULL &&
219  (codecDef->codecFunction)(codecDef, context, from, fromLen, to, toLen, flags) != 0;
220  }
221 
222  protected:
224  bool isEncoder;
225  void * context;
226 
232 };
233 
234 
236 
238 {
239  public:
241 
243  const PluginCodec_Definition * codecDefn,
244  const char * fmtName,
245  const char * rtpEncodingName,
246  unsigned frameTime,
247  unsigned timeUnits,
248  time_t timeStamp
249  );
250  virtual PObject * Clone() const;
251  virtual bool IsValidForProtocol(const PString & protocol) const;
252  virtual bool ToNormalisedOptions();
253  virtual bool ToCustomisedOptions();
254 };
255 
256 
258 {
260  public:
262  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
263  PBoolean ExecuteCommand(const OpalMediaCommand & command);
264  PBoolean ConvertFrame(const BYTE * input, PINDEX & consumed, BYTE * output, PINDEX & created);
265  virtual PBoolean ConvertSilentFrame(BYTE * buffer);
266  virtual bool AcceptComfortNoise() const { return comfortNoise; }
267  protected:
269 };
270 
271 
273 {
275  public:
277  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
278  PBoolean ExecuteCommand(const OpalMediaCommand & command);
279  virtual bool AcceptComfortNoise() const { return comfortNoise; }
280  virtual int ConvertOne(int from) const;
281  protected:
283 };
284 
285 
287 
288 #if OPAL_VIDEO
289 
291 {
292  public:
294  const PluginCodec_Definition * codec,
295  const char * fmtName,
296  const char * rtpEncodingName,
297  time_t timeStamp
298  );
299  virtual PObject * Clone() const;
300  virtual bool IsValidForProtocol(const PString & protocol) const;
301  virtual bool ToNormalisedOptions();
302  virtual bool ToCustomisedOptions();
303 };
304 
305 
307 {
309  public:
312 
313 #if OPAL_STATISTICS
314  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
315 #endif
316 
317  PBoolean ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
318  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
319  PBoolean ExecuteCommand(const OpalMediaCommand & command);
320 
321  protected:
322  bool EncodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
323  bool DecodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
324  bool DecodeFrame(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
325 
328  DWORD m_lastDecodedTimestamp; // For missing marker bit detection
329  DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
332 
333 #if PTRACING
334  unsigned m_consecutiveIntraFrames;
335 #endif
336 };
337 
338 #endif
339 
341 
342 #if OPAL_FAX
343 
345 {
346  public:
348  const PluginCodec_Definition * codec,
349  const char * fmtName,
350  const char * rtpEncodingName,
351  unsigned frameTime,
352  unsigned /*timeUnits*/,
353  time_t timeStamp
354  );
355  virtual PObject * Clone() const;
356  virtual bool IsValidForProtocol(const PString & protocol) const;
357 };
358 
359 #endif // OPAL_FAX
360 
361 
363 //
364 // this is the base class for codecs accessible via the abstract factory functions
365 //
366 
374 class OpalFactoryCodec : public PObject {
375  PCLASSINFO(OpalFactoryCodec, PObject)
376  public:
378  virtual const struct PluginCodec_Definition * GetDefinition()
379  { return NULL; }
380 
382  virtual PString GetInputFormat() const = 0;
383 
385  virtual PString GetOutputFormat() const = 0;
386 
388  virtual int Encode(const void * from,
389  unsigned * fromLen,
390  void * to,
391  unsigned * toLen,
392  unsigned int * flag
393  ) = 0;
394 
396  virtual unsigned int GetSampleRate() const = 0;
397 
399  virtual unsigned int GetBitsPerSec() const = 0;
400 
402  virtual unsigned int GetFrameTime() const = 0;
403 
405  virtual unsigned int GetSamplesPerFrame() const = 0;
406 
408  virtual unsigned int GetBytesPerFrame() const = 0;
409 
411  virtual unsigned int GetRecommendedFramesPerPacket() const = 0;
412 
414  virtual unsigned int GetMaxFramesPerPacket() const = 0;
415 
417  virtual BYTE GetRTPPayload() const = 0;
418 
420  virtual PString GetSDPFormat() const = 0;
421 };
422 
424 
425 template<class TranscoderClass>
427 {
428  public:
429  class Worker : public OpalTranscoderFactory::WorkerBase
430  {
431  public:
432  Worker(const OpalTranscoderKey & key, const PluginCodec_Definition * codec, bool enc)
433  : OpalTranscoderFactory::WorkerBase(), codecDefn(codec), isEncoder(enc)
434  { OpalTranscoderFactory::Register(key, this); }
435 
436  protected:
437  virtual OpalTranscoder * Create(const OpalTranscoderKey &) const
438  { return new TranscoderClass(codecDefn, isEncoder); }
439 
441  bool isEncoder;
442  };
443 };
444 
446 //
447 // Helper class for handling plugin capabilities
448 //
449 
451 {
452  public:
453  H323PluginCapabilityInfo(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
454 
455  //H323PluginCapabilityInfo(const PString & _baseName);
456 
457  const PString & GetFormatName() const
458  { return m_capabilityFormatName; }
459 
460  protected:
463 };
464 
465 #if OPAL_H323
466 
468 //
469 // Class for handling most audio plugin capabilities
470 //
471 
474 {
476  public:
478  const OpalMediaFormat & mediaFormat,
479  unsigned pluginSubType);
480 
481  virtual PObject * Clone() const;
482 
483  virtual PString GetFormatName() const;
484 
485  virtual unsigned GetSubType() const;
486 
487  protected:
488  unsigned pluginSubType;
489 };
490 
491 
493 //
494 // Class for handling G.723.1 codecs
495 //
496 
498 {
500  public:
502  const OpalMediaFormat & mediaFormat);
503 
504  virtual PObject * Clone() const;
505  virtual PBoolean OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
506  virtual PBoolean OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize);
507 };
508 
509 
511 //
512 // Class for handling non standard audio capabilities
513 //
514 
517 {
519  public:
521  const OpalMediaFormat & mediaFormat,
523  const unsigned char * data, unsigned dataLen);
524 
526  const OpalMediaFormat & mediaFormat,
527  const unsigned char * data, unsigned dataLen);
528 
529  virtual PObject * Clone() const;
530 
531  virtual PString GetFormatName() const;
532 };
533 
535 //
536 // Class for handling generic audio capabilities
537 //
538 
541 {
543  public:
545  const OpalMediaFormat & mediaFormat,
546  const PluginCodec_H323GenericCodecData * data);
547 
548  virtual PObject * Clone() const;
549  virtual PString GetFormatName() const;
550 };
551 
552 
553 #if OPAL_VIDEO
554 
556 //
557 // Class for handling non standard video capabilities
558 //
559 
562 {
564  public:
566  const OpalMediaFormat & mediaFormat,
568  const unsigned char * data, unsigned dataLen);
569 
571  const OpalMediaFormat & mediaFormat,
572  const unsigned char * data, unsigned dataLen);
573 
574  virtual PObject * Clone() const;
575 
576  virtual PString GetFormatName() const;
577 };
578 
580 //
581 // Class for handling generic video capabilities
582 //
583 
586 {
588  public:
590  const OpalMediaFormat & mediaFormat,
591  const PluginCodec_H323GenericCodecData * data);
592 
593  virtual PObject * Clone() const;
594 
595  virtual PString GetFormatName() const;
596 };
597 
599 //
600 // Class for handling H.261 plugin capabilities
601 //
602 
604 {
606  public:
608 
609  Comparison Compare(const PObject & obj) const;
610 
611  virtual PObject * Clone() const;
612 
613  virtual PString GetFormatName() const;
614  virtual unsigned GetSubType() const;
615 
616  virtual PBoolean OnSendingPDU(
617  H245_VideoCapability & pdu
618  ) const;
619 
620  virtual PBoolean OnSendingPDU(
621  H245_VideoMode & pdu
622  ) const;
623 
624  virtual PBoolean OnReceivedPDU(
625  const H245_VideoCapability & pdu
626  );
627 };
628 
629 
632 {
634  public:
635  H323H261PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
636 
637  virtual PObject * Clone() const;
638 };
639 
640 
642 //
643 // Class for handling H.263 plugin capabilities
644 //
645 
647 {
648  public:
649  H323H263Capability(const PString & variant);
650 
651  Comparison Compare(const PObject & obj) const;
652 
653  virtual PObject * Clone() const;
654 
655  virtual PString GetFormatName() const;
656  virtual unsigned GetSubType() const;
657 
658  virtual PBoolean OnSendingPDU(
659  H245_VideoCapability & pdu
660  ) const;
661 
662  virtual PBoolean OnSendingPDU(
663  H245_VideoMode & pdu
664  ) const;
665 
666  virtual PBoolean OnReceivedPDU(
667  const H245_VideoCapability & pdu
668  );
669  virtual PBoolean IsMatch(
670  const PASN_Choice & subTypePDU,
671  const PString & mediaPacketization
672  ) const;
673 
674  protected:
675  PString m_variant;
676 };
677 
680 {
682  public:
683  H323H263PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat)
684  : H323H263Capability(mediaFormat)
685  , H323PluginCapabilityInfo(codecDefn, mediaFormat)
686  {
687  }
688 };
689 
690 #endif // OPAL_VIDEO
691 #endif // OPAL_H323
692 
693 #endif // OPAL_CODEC_OPALPLUGINMGR_H