sipxmedialib  Version 3.3
MpCodecFactory.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2008 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2008 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _MpCodecFactory_h_
16 #define _MpCodecFactory_h_
17 
18 // SYSTEM INCLUDES
19 
20 // APPLICATION INCLUDES
21 #include "mp/MpEncoderBase.h"
22 #include "mp/MpDecoderBase.h"
23 #include "mp/codecs/PlgDefsV1.h"
24 #include "mp/MpPlgStaffV1.h"
25 #include "mp/MpMisc.h"
26 #include "sdp/SdpCodecList.h"
27 #include "utl/UtlHashBag.h"
28 #include "utl/UtlHashBagIterator.h"
29 #include "os/OsSharedLibMgr.h"
30 #include "os/OsStatus.h"
31 #include "os/OsBSem.h"
32 
33 // DEFINES
35 #ifdef __pingtel_on_posix__ // [
36 # define CODEC_PLUGINS_FILTER "^codec_.*\\.so$"
37 #elif defined(WIN32) // __pingtel_on_posix__ ] [
38 # define CODEC_PLUGINS_FILTER "^codec_.*\\.dll$"
39 #else // WIN32 ] [
40 # error Unknown platform! Please specify correct codec plugins file filter.
41 #endif // ]
42 
43 
44 // MACROS
45 // EXTERNAL FUNCTIONS
46 // EXTERNAL VARIABLES
47 // CONSTANTS
48 // STRUCTS
49 // TYPEDEFS
50 // FORWARD DECLARATIONS
51 class MpFlowGraphBase;
52 class MpCodecSubInfo;
53 
54 
59 {
60 /* //////////////////////////// PUBLIC //////////////////////////////////// */
61 public:
62 
63 /* ============================ CREATORS ================================== */
65 
66 
68  static
75  static
77  void freeSingletonHandle();
78 
80 
81 /* ============================ MANIPULATORS ============================== */
83 
84 
86  OsStatus loadDynCodec(const char* name);
87 
89  OsStatus loadAllDynCodecs(const char* path, const char* regexFilter);
98  static
101 
103 
104 /* ============================ ACCESSORS ================================= */
106 
107 
109  OsStatus createDecoder(const UtlString &mime,
110  const UtlString &fmtp,
111  int sampleRate,
112  int numChannels,
113  int payloadType,
114  MpDecoderBase*& rpDecoder) const;
124  OsStatus createEncoder(const UtlString &mime,
126  const UtlString &fmtp,
127  int sampleRate,
128  int numChannels,
129  int payloadType,
130  MpEncoderBase*& rpEncoder) const;
140  void getCodecInfoArray(unsigned &count,
142  const MppCodecInfoV1_1 **&codecInfoArray) const;
148  void addCodecsToList(SdpCodecList &codecList) const;
156 
157 /* ============================ INQUIRY =================================== */
159 
160 
162 
163 /* //////////////////////////// PROTECTED ///////////////////////////////// */
164 protected:
165 
167  MpCodecFactory();
174  ~MpCodecFactory();
176 
178  MpCodecSubInfo* searchByMIME(const UtlString& mime,
179  int sampleRate,
180  int numChannels) const;
181 
184 
186  void initializeStaticCodecs();
192  static
194  void freeStaticCodecs();
195 
196 /* //////////////////////////// PRIVATE /////////////////////////////////// */
197 private:
198 
199  UtlHashBag mCodecsInfo;
200  mutable UtlBoolean mCodecInfoCacheValid;
201  mutable unsigned mCachedCodecInfoNum;
203 
205  // Static data members used to enforce Singleton behavior
207  static OsBSem sLock;
210 
213  OsStatus addCodecWrapperV1(MpCodecCallInfoV1* wrapper);
214 
216  void updateCodecInfoCache() const;
217 
219  MpCodecFactory(const MpCodecFactory& rMpCodecFactory);
220 
223 };
224 
225 /* ============================ INLINE METHODS ============================ */
226 
227 #endif // _MpCodecFactory_h_
static void freeStaticCodecs()
Freeing internal data of static codecs. Should be called only from global .dtor.
Definition: MpCodecFactory.cpp:532
void getCodecInfoArray(unsigned &count, const MppCodecInfoV1_1 **&codecInfoArray) const
Get list of all codecs' info.
Definition: MpCodecFactory.cpp:385
static MpCodecFactory * spInstance
Pointer to the singleton instance.
Definition: MpCodecFactory.h:206
Definition: MpCodecFactory.h:58
MpCodecSubInfo * searchByMIME(const UtlString &mime, int sampleRate, int numChannels) const
Search codec by given MIME-subtype, sample rate and channels number.
Definition: MpCodecFactory.cpp:455
static MpCodecCallInfoV1 * sStaticCodecsV1
Filled by global magic .ctor.
Definition: MpCodecFactory.h:209
Base class for all media processing decoders.
Definition: MpDecoderBase.h:37
OsStatus createEncoder(const UtlString &mime, const UtlString &fmtp, int sampleRate, int numChannels, int payloadType, MpEncoderBase *&rpEncoder) const
Returns a new instance of an encoder of the indicated type.
Definition: MpCodecFactory.cpp:351
Object-oriented wrapper for codec.
Definition: MpPlgStaffV1.h:94
OsStatus loadDynCodec(const char *name)
Load specified codec plugin.
Definition: MpCodecFactory.cpp:133
Base class for all media processing encoders.
Definition: MpEncoderBase.h:35
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
Definition: MpCodecFactory.cpp:34
unsigned mCachedCodecInfoNum
Number of elements in mpMimeTypesCache.
Definition: MpCodecFactory.h:201
OsStatus createDecoder(const UtlString &mime, const UtlString &fmtp, int sampleRate, int numChannels, int payloadType, MpDecoderBase *&rpDecoder) const
Returns a new instance of a decoder of the indicated type.
Definition: MpCodecFactory.cpp:315
void updateCodecInfoCache() const
Update cached array of MIME-types of loaded codecs.
Definition: MpCodecFactory.cpp:548
static MpCodecFactory * getMpCodecFactory(void)
Get/create singleton factory.
Definition: MpCodecFactory.cpp:75
OsStatus addCodecWrapperV1(MpCodecCallInfoV1 *wrapper)
Add new codec wrapper to codec list.
Definition: MpCodecFactory.cpp:569
static OsBSem sLock
Definition: MpCodecFactory.h:207
void freeAllLoadedLibsAndCodec()
Deinitialize all dynamic codecs. Should be called only from mpShutdown()
Definition: MpCodecFactory.cpp:487
static MpCodecCallInfoV1 * addStaticCodec(MpCodecCallInfoV1 *sStaticCode)
Add static codec to factory.
Definition: MpCodecFactory.cpp:294
UtlHashBag mCodecsInfo
List of all known and workable codecs.
Definition: MpCodecFactory.h:199
UtlBoolean mCodecInfoCacheValid
Should we rebuild MIME-subtypes cache?
Definition: MpCodecFactory.h:200
MpCodecFactory & operator=(const MpCodecFactory &rhs)
Assignment operator (not supported)
static void freeSingletonHandle()
Deinitialize all static codecs and freeing handle. Should be called only mpShutdown() ...
Definition: MpCodecFactory.cpp:92
~MpCodecFactory()
Destructor.
Definition: MpCodecFactory.cpp:112
const MppCodecInfoV1_1 ** mpCodecInfoCache
This is used as return value of getMimeTypes().
Definition: MpCodecFactory.h:202
void addCodecsToList(SdpCodecList &codecList) const
Add all supported codecs to SDP descriptions list.
Definition: MpCodecFactory.cpp:397
OsStatus loadAllDynCodecs(const char *path, const char *regexFilter)
Load all codec plugins within specified path and filter.
Definition: MpCodecFactory.cpp:267
void initializeStaticCodecs()
Initialize all static codecs.
Definition: MpCodecFactory.cpp:523
Generic information about codec.
Definition: PlgDefsV1.h:169
MpCodecFactory()
Constructor (called only indirectly via getMpCodecFactory())
Definition: MpCodecFactory.cpp:104