OPAL  Version 3.14.3
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: 31437 $
27  * $Author: rjongbloed $
28  * $Date: 2014-02-11 16:42:40 +1100 (Tue, 11 Feb 2014) $
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_config.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  virtual void RegisterAudioTranscoder(const PString & src, const PString & dst, const PluginCodec_Definition * codec, bool isEnc);
94 
95 #if OPAL_VIDEO
97  const PluginCodec_Definition * codecDefn,
98  const char * fmtName,
99  const char * rtpEncodingName,
100  time_t timeStamp);
101  virtual void RegisterVideoTranscoder(const PString & src, const PString & dst, const PluginCodec_Definition * codec, bool isEnc);
102 #endif
103 
104 #if OPAL_FAX
106  const PluginCodec_Definition * codecDefn,
107  const char * fmtName,
108  const char * rtpEncodingName,
109  unsigned frameTime,
110  unsigned timeUnits,
111  time_t timeStamp);
112  virtual void RegisterFaxTranscoder(const PString & src, const PString & dst, const PluginCodec_Definition * codec, bool isEnc);
113 #endif
114 };
115 
116 
117 class OpalPluginCodecManager : public PPluginModuleManager
118 {
119  PCLASSINFO(OpalPluginCodecManager, PPluginModuleManager);
120  public:
121  OpalPluginCodecManager(PPluginManager * pluginMgr = NULL);
123 
124  PFACTORY_GET_SINGLETON(PFactory<PPluginModuleManager>, OpalPluginCodecManager);
125 
126  void RegisterStaticCodec(const H323StaticPluginCodecFactory::Key_T & name,
128  PluginCodec_GetCodecFunction getCodecFn);
129 
130  void OnLoadPlugin(PDynaLink & dll, P_INT_PTR code);
131 
132  virtual void OnStartup();
133  virtual void OnShutdown();
134 
135 #if OPAL_H323
137  const PString & _mediaFormat,
138  const PString & _baseName,
139  unsigned maxFramesPerPacket,
140  unsigned recommendedFramesPerPacket,
141  unsigned _pluginSubType);
142 #endif
143 
144  protected:
145  // Note the below MUST NOT be an OpalMediaFormatList
146  PList<OpalMediaFormat> mediaFormatsOnHeap;
147 
148  void RegisterCodecPlugins (unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
149  void UnregisterCodecPlugins(unsigned int count, const PluginCodec_Definition * codecList, OpalPluginCodecHandler * handler);
150 
151  bool AddMediaFormat(
152  OpalPluginCodecHandler * handler,
153  const PTime & timeNow,
154  const PluginCodec_Definition * codecDefn,
155  const char * fmtName,
156  OpalMediaFormat & mediaFormat
157  );
158 #if OPAL_H323
159  void RegisterCapability(const PluginCodec_Definition * codecDefn);
160 #endif
161 };
162 
163 
165 
167 {
168  public:
169  OpalPluginControl(const PluginCodec_Definition * def, const char * name);
170 
171  bool Exists() const
172  {
173  return controlDef != NULL;
174  }
175 
176  int Call(void * parm, unsigned * parmLen, void * context = NULL) const
177  {
178  return controlDef != NULL ? (*controlDef->control)(codecDef, context, fnName, parm, parmLen) : -1;
179  }
180 
181  int Call(void * parm, unsigned parmLen, void * context = NULL) const
182  {
183  return Call(parm, &parmLen, context);
184  }
185 
186  const char * GetName() const { return fnName; }
187 
188  protected:
190  const char * fnName;
192 };
193 
194 
196 
198 {
199  public:
201 
202  bool AdjustOptions(OpalMediaFormatInternal & fmt, OpalPluginControl & control) const;
204  void SetOldStyleOption(OpalMediaFormatInternal & format, const PString & _key, const PString & _val, const PString & type);
205  bool IsValidForProtocol(const PString & _protocol) const;
206 
213 };
214 
215 
217 {
218  public:
219  OpalPluginTranscoder(const PluginCodec_Definition * defn, bool isEnc);
221 
222  bool UpdateOptions(OpalMediaFormat & fmt);
223  bool ExecuteCommand(const OpalMediaCommand & command);
224  bool Transcode(const void * from, unsigned * fromLen, void * to, unsigned * toLen, unsigned * flags) const
225  {
226  return codecDef != NULL && codecDef->codecFunction != NULL &&
227  (codecDef->codecFunction)(codecDef, context, from, fromLen, to, toLen, flags) != 0;
228  }
229 
230  protected:
232  bool isEncoder;
233  void * context;
234 
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 #if OPAL_STATISTICS
322  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
323 #endif
324 
325  PBoolean ConvertFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
326  bool UpdateMediaFormats(const OpalMediaFormat & input, const OpalMediaFormat & output);
327  PBoolean ExecuteCommand(const OpalMediaCommand & command);
328 
329  protected:
330  bool EncodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
331  bool DecodeFrames(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
332  bool DecodeFrame(const RTP_DataFrame & src, RTP_DataFrameList & dstList);
333 
336  DWORD m_lastDecodedTimestamp; // For missing marker bit detection
337  DWORD m_lastMarkerTimestamp; // For continuous marker bit detection
340 
341 #if PTRACING
342  unsigned m_consecutiveIntraFrames;
343 #endif
344 };
345 
346 #endif
347 
349 
350 #if OPAL_FAX
351 
353 {
354  public:
356  const PluginCodec_Definition * codec,
357  const char * fmtName,
358  const char * rtpEncodingName,
359  unsigned frameTime,
360  unsigned /*timeUnits*/,
361  time_t timeStamp
362  );
363  virtual PObject * Clone() const;
364  virtual bool IsValidForProtocol(const PString & protocol) const;
365 };
366 
367 #endif // OPAL_FAX
368 
369 
371 //
372 // this is the base class for codecs accessible via the abstract factory functions
373 //
374 
382 class OpalFactoryCodec : public PObject {
383  PCLASSINFO(OpalFactoryCodec, PObject)
384  public:
386  virtual const struct PluginCodec_Definition * GetDefinition()
387  { return NULL; }
388 
390  virtual PString GetInputFormat() const = 0;
391 
393  virtual PString GetOutputFormat() const = 0;
394 
396  virtual int Encode(const void * from,
397  unsigned * fromLen,
398  void * to,
399  unsigned * toLen,
400  unsigned int * flag
401  ) = 0;
402 
404  virtual unsigned int GetSampleRate() const = 0;
405 
407  virtual unsigned int GetBitsPerSec() const = 0;
408 
410  virtual unsigned int GetFrameTime() const = 0;
411 
413  virtual unsigned int GetSamplesPerFrame() const = 0;
414 
416  virtual unsigned int GetBytesPerFrame() const = 0;
417 
419  virtual unsigned int GetRecommendedFramesPerPacket() const = 0;
420 
422  virtual unsigned int GetMaxFramesPerPacket() const = 0;
423 
425  virtual BYTE GetRTPPayload() const = 0;
426 
428  virtual PString GetSDPFormat() const = 0;
429 };
430 
432 
433 template<class TranscoderClass>
435 {
436  public:
437  class Worker : public OpalTranscoderFactory::WorkerBase
438  {
439  public:
440  Worker(const OpalTranscoderKey & key, const PluginCodec_Definition * codec, bool enc)
441  : OpalTranscoderFactory::WorkerBase()
442  , m_key(key)
443  , m_codecDefn(codec)
444  , m_isEncoder(enc)
445  {
446  OpalTranscoderFactory::Register(key, this);
447  }
448 
449  protected:
450  virtual OpalTranscoder * Create(const OpalTranscoderKey &) const
451  {
452  return new TranscoderClass(m_key, m_codecDefn, m_isEncoder);
453  }
454 
458  };
459 };
460 
462 //
463 // Helper class for handling plugin capabilities
464 //
465 
467 {
468  public:
469  H323PluginCapabilityInfo(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
470 
471  //H323PluginCapabilityInfo(const PString & _baseName);
472 
473  const PString & GetFormatName() const
474  { return m_capabilityFormatName; }
475 
476  protected:
479 };
480 
481 #if OPAL_H323
482 
484 //
485 // Class for handling most audio plugin capabilities
486 //
487 
490 {
492  public:
494  const OpalMediaFormat & mediaFormat,
495  unsigned pluginSubType);
496 
497  virtual PObject * Clone() const;
498 
499  virtual PString GetFormatName() const;
500 
501  virtual unsigned GetSubType() const;
502 
503  protected:
504  unsigned pluginSubType;
505 };
506 
507 
509 //
510 // Class for handling G.723.1 codecs
511 //
512 
514 {
516  public:
518  const OpalMediaFormat & mediaFormat);
519 
520  virtual PObject * Clone() const;
521  virtual PBoolean OnSendingPDU(H245_AudioCapability & cap, unsigned packetSize) const;
522  virtual PBoolean OnReceivedPDU(const H245_AudioCapability & cap, unsigned & packetSize);
523 };
524 
525 
527 //
528 // Class for handling non standard audio capabilities
529 //
530 
533 {
535  public:
537  const OpalMediaFormat & mediaFormat,
539  const unsigned char * data, unsigned dataLen);
540 
542  const OpalMediaFormat & mediaFormat,
543  const unsigned char * data, unsigned dataLen);
544 
545  virtual PObject * Clone() const;
546 
547  virtual PString GetFormatName() const;
548 };
549 
551 //
552 // Class for handling generic audio capabilities
553 //
554 
557 {
559  public:
561  const OpalMediaFormat & mediaFormat,
562  const PluginCodec_H323GenericCodecData * data);
563 
564  virtual PObject * Clone() const;
565  virtual PString GetFormatName() const;
566 };
567 
568 
569 #if OPAL_VIDEO
570 
572 //
573 // Class for handling non standard video capabilities
574 //
575 
578 {
580  public:
582  const OpalMediaFormat & mediaFormat,
584  const unsigned char * data, unsigned dataLen);
585 
587  const OpalMediaFormat & mediaFormat,
588  const unsigned char * data, unsigned dataLen);
589 
590  virtual PObject * Clone() const;
591 
592  virtual PString GetFormatName() const;
593 };
594 
596 //
597 // Class for handling generic video capabilities
598 //
599 
602 {
604  public:
606  const OpalMediaFormat & mediaFormat,
607  const PluginCodec_H323GenericCodecData * data);
608 
609  virtual PObject * Clone() const;
610 
611  virtual PString GetFormatName() const;
612 };
613 
615 //
616 // Class for handling H.261 plugin capabilities
617 //
618 
620 {
622  public:
624 
625  Comparison Compare(const PObject & obj) const;
626 
627  virtual PObject * Clone() const;
628 
629  virtual PString GetFormatName() const;
630  virtual unsigned GetSubType() const;
631 
632  virtual PBoolean OnSendingPDU(
633  H245_VideoCapability & pdu
634  ) const;
635 
636  virtual PBoolean OnSendingPDU(
637  H245_VideoMode & pdu
638  ) const;
639 
640  virtual PBoolean OnReceivedPDU(
641  const H245_VideoCapability & pdu
642  );
643 };
644 
645 
648 {
650  public:
651  H323H261PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat);
652 
653  virtual PObject * Clone() const;
654 };
655 
656 
658 //
659 // Class for handling H.263 plugin capabilities
660 //
661 
663 {
664  public:
665  H323H263Capability(const PString & variant);
666 
667  Comparison Compare(const PObject & obj) const;
668 
669  virtual PObject * Clone() const;
670 
671  virtual PString GetFormatName() const;
672  virtual unsigned GetSubType() const;
673 
674  virtual PBoolean OnSendingPDU(
675  H245_VideoCapability & pdu
676  ) const;
677 
678  virtual PBoolean OnSendingPDU(
679  H245_VideoMode & pdu
680  ) const;
681 
682  virtual PBoolean OnReceivedPDU(
683  const H245_VideoCapability & pdu
684  );
685  virtual PBoolean IsMatch(
686  const PASN_Object & subTypePDU,
687  const PString & mediaPacketization
688  ) const;
689 
690  protected:
691  PString m_variant;
692 };
693 
696 {
698  public:
699  H323H263PluginCapability(const PluginCodec_Definition * codecDefn, const OpalMediaFormat & mediaFormat)
700  : H323H263Capability(mediaFormat)
701  , H323PluginCapabilityInfo(codecDefn, mediaFormat)
702  {
703  }
704 };
705 
706 #endif // OPAL_VIDEO
707 #endif // OPAL_H323
708 
709 #endif // OPAL_CODEC_OPALPLUGINMGR_H