# opalplugin.h

Go to the documentation of this file.

    00001 /*
    00002  * opalplugins.h
    00003  *
    00004  * OPAL codec plugins handler
    00005  *
    00006  * Open Phone Abstraction Library (OPAL)
    00007  * Formally known as the Open H323 project.
    00008  *
    00009  * Copyright (C) 2004-2011 Post Increment
    00010  *
    00011  * Redistribution and use in source and binary forms, with or without
    00012  * modification, are permitted provided that the following conditions
    00013  * are met:
    00014  *
    00015  * - Redistributions of source code must retain the above copyright
    00016  *   notice, this list of conditions and the following disclaimer.
    00017
    00018  * - Redistributions in binary form must reproduce the above copyright
    00019  *   notice, this list of conditions and the following disclaimer in the
    00020  *   documentation and/or other materials provided with the distribution.
    00021  *
    00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    00025  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    00026  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00028  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00029  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00030  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00031  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00032  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00033  *
    00034  * $Revision: 28048 $
    00035  * $Author: rjongbloed $
    00036  * $Date: 2012-07-17 22:41:57 -0500 (Tue, 17 Jul 2012) $
    00037  */
    00038
    00039 #ifndef OPAL_CODEC_OPALPLUGIN_H
    00040 #define OPAL_CODEC_OPALPLUGIN_H
    00041
    00042 #ifdef __cplusplus
    00043 extern "C" {
    00044 #endif
    00045
    00046 #ifndef _CRT_NONSTDC_NO_DEPRECATE
    00047 #define _CRT_NONSTDC_NO_DEPRECATE 1
    00048 #endif
    00049
    00050 #ifndef _CRT_SECURE_NO_WARNINGS
    00051 #define _CRT_SECURE_NO_WARNINGS 1
    00052 #endif
    00053
    00054 #include <time.h>
    00055
    00056 #ifdef _MSC_VER
    00057 #pragma warning(disable:4201)
    00058 #endif
    00059
    00060 #ifdef _WIN32
    00061 #  ifdef PLUGIN_CODEC_DLL_EXPORTS
    00062 #    define PLUGIN_CODEC_DLL_API __declspec(dllexport)
    00063 #  else
    00064 #    define PLUGIN_CODEC_DLL_API __declspec(dllimport)
    00065 #  endif
    00066
    00067 #if !defined(strcasecmp) && !defined(_WIN32_WCE)
    00068 #define strcasecmp stricmp
    00069 #endif
    00070
    00071 #else
    00072
    00073 #define PLUGIN_CODEC_DLL_API
    00074
    00075 #endif
    00076
    00077 #ifdef PWLIB_PLUGIN_API_VERSION
    00078 #undef PWLIB_PLUGIN_API_VERSION
    00079 #endif
    00080 #define PWLIB_PLUGIN_API_VERSION 1
    00081
    00082 #define  PLUGIN_CODEC_VERSION_FIRST     1    // initial version
    00083 #define  PLUGIN_CODEC_VERSION_WIDEBAND  2    // added wideband
    00084 #define  PLUGIN_CODEC_VERSION_VIDEO     3    // added video
    00085 #define  PLUGIN_CODEC_VERSION_FAX       4    // added fax
    00086 #define  PLUGIN_CODEC_VERSION_OPTIONS   5    // added options handling
    00087 #define  PLUGIN_CODEC_VERSION_INTERSECT 6    // added media option intersection merge functionality
    00088 #define  PLUGIN_CODEC_VERSION_H245_DEF_GEN_PARAM 7 // added suppression of H.245 generic parameters via default
    00089
    00090 #define  PLUGIN_CODEC_VERSION PLUGIN_CODEC_VERSION_INTERSECT // Always latest version
    00091
    00092 #define PLUGIN_CODEC_API_VER_FN       PWLibPlugin_GetAPIVersion
    00093 #define PLUGIN_CODEC_API_VER_FN_STR   "PWLibPlugin_GetAPIVersion"
    00094
    00095 #define PLUGIN_CODEC_GET_CODEC_FN     OpalCodecPlugin_GetCodecs
    00096 #define PLUGIN_CODEC_GET_CODEC_FN_STR "OpalCodecPlugin_GetCodecs"
    00097
    00098 #define PLUGIN_CODEC_API_VER_FN_DECLARE \
    00099 PLUGIN_CODEC_DLL_API unsigned int PLUGIN_CODEC_API_VER_FN() \
    00100 { return PWLIB_PLUGIN_API_VERSION; }
    00101
    00102 enum {
    00103   PluginCodec_License_None                           = 0,
    00104   PluginCodec_Licence_None = PluginCodec_License_None,        // allow for old code with misspelled constant
    00105   PluginCodec_License_GPL                            = 1,
    00106   PluginCodec_License_MPL                            = 2,
    00107   PluginCodec_License_Freeware                       = 3,
    00108   PluginCodec_License_ResearchAndDevelopmentUseOnly  = 4,
    00109   PluginCodec_License_BSD                            = 5,
    00110   PluginCodec_License_LGPL                           = 6,
    00111
    00112   PluginCodec_License_NoRoyalties                    = 0x7f,
    00113
    00114   // any license codes above here require royalty payments
    00115   PluginCodec_License_RoyaltiesRequired              = 0x80
    00116 };
    00117
    00118 struct PluginCodec_information {
    00119   // start of version 1 fields
    00120   time_t timestamp;                     // codec creation time and date - obtain with command: date -u "+%c = %s"
    00121
    00122   const char * sourceAuthor;            // source code author
    00123   const char * sourceVersion;           // source code version
    00124   const char * sourceEmail;             // source code email contact information
    00125   const char * sourceURL;               // source code web site
    00126   const char * sourceCopyright;         // source code copyright
    00127   const char * sourceLicense;           // source code license
    00128   unsigned char sourceLicenseCode;      // source code license
    00129
    00130   const char * codecDescription;        // codec description
    00131   const char * codecAuthor;             // codec author
    00132   const char * codecVersion;            // codec version
    00133   const char * codecEmail;              // codec email contact information
    00134   const char * codecURL;                // codec web site
    00135   const char * codecCopyright;          // codec copyright information
    00136   const char * codecLicense;            // codec license
    00137   unsigned short codecLicenseCode;      // codec license code
    00138   // end of version 1 fields
    00139
    00140 };
    00141
    00142 enum PluginCodec_Flags {
    00143   PluginCodec_MediaTypeMask          = 0x000f,
    00144   PluginCodec_MediaTypeAudio         = 0x0000,
    00145   PluginCodec_MediaTypeVideo         = 0x0001,
    00146   PluginCodec_MediaTypeAudioStreamed = 0x0002,
    00147   PluginCodec_MediaTypeFax           = 0x0003,
    00148
    00149   PluginCodec_InputTypeMask          = 0x0010,
    00150   PluginCodec_InputTypeRaw           = 0x0000, // Note video is always RTP
    00151   PluginCodec_InputTypeRTP           = 0x0010,
    00152
    00153   PluginCodec_OutputTypeMask         = 0x0020,
    00154   PluginCodec_OutputTypeRaw          = 0x0000, // Note video is always RTP
    00155   PluginCodec_OutputTypeRTP          = 0x0020,
    00156
    00157   PluginCodec_RTPTypeMask            = 0x0040,
    00158   PluginCodec_RTPTypeDynamic         = 0x0000,
    00159   PluginCodec_RTPTypeExplicit        = 0x0040,
    00160
    00161   PluginCodec_RTPSharedMask          = 0x0080,
    00162   PluginCodec_RTPTypeNotShared       = 0x0000,
    00163   PluginCodec_RTPTypeShared          = 0x0080,
    00164
    00165   PluginCodec_DecodeSilenceMask      = 0x0100,
    00166   PluginCodec_NoDecodeSilence        = 0x0000,
    00167   PluginCodec_DecodeSilence          = 0x0100,
    00168
    00169   PluginCodec_EncodeSilenceMask      = 0x0200,
    00170   PluginCodec_NoEncodeSilence        = 0x0000,
    00171   PluginCodec_EncodeSilence          = 0x0200,
    00172
    00173   PluginCodec_MediaExtensionMask     = 0x0400,
    00174   PluginCodec_MediaTypeExtVideo      = 0x0400,
    00175
    00176   PluginCodec_ComfortNoiseMask       = 0x0800,
    00177   PluginCodec_ComfortNoise           = 0x0800,
    00178
    00179   PluginCodec_EmptyPayloadMask       = 0x1000,
    00180   PluginCodec_EmptyPayload           = 0x1000,
    00181
    00182   PluginCodec_OtherPayloadMask       = 0x2000,
    00183   PluginCodec_OtherPayload           = 0x2000,
    00184
    00185   PluginCodec_BitsPerSamplePos       = 12,
    00186   PluginCodec_BitsPerSampleMask      = 0xf000,
    00187
    00188   PluginCodec_ChannelsPos            = 16,
    00189   PluginCodec_ChannelsMask           = 0x003f0000
    00190 };
    00191
    00192 #define PluginCodec_SetChannels(n) (((n-1)<<PluginCodec_ChannelsPos)&PluginCodec_ChannelsMask)
    00193
    00194
    00195 enum PluginCodec_CoderFlags {
    00196   PluginCodec_CoderSilenceFrame      = 1,    // request audio codec to create silence frame
    00197   PluginCodec_CoderForceIFrame       = 2     // request video codec to force I frame
    00198 };
    00199
    00200 enum PluginCodec_ReturnCoderFlags {
    00201   PluginCodec_ReturnCoderLastFrame      = 1,    // indicates when video codec returns last data for frame
    00202   PluginCodec_ReturnCoderIFrame         = 2,    // indicates when video returns I frame
    00203   PluginCodec_ReturnCoderRequestIFrame  = 4,    // indicates when video decoder request I frame for resync
    00204   PluginCodec_ReturnCoderBufferTooSmall = 8     // indicates when output buffer is not large enough to receive
    00205                                                 // the data, another call to get_output_data_size is required
    00206 };
    00207
    00208 struct PluginCodec_Definition;
    00209
    00210 // Control function names
    00211
    00212 #define PLUGINCODEC_CONTROL_VALID_FOR_PROTOCOL    "valid_for_protocol"
    00213 #define PLUGINCODEC_CONTROL_GET_CODEC_OPTIONS     "get_codec_options"
    00214 #define PLUGINCODEC_CONTROL_FREE_CODEC_OPTIONS    "free_codec_options"
    00215 #define PLUGINCODEC_CONTROL_GET_OUTPUT_DATA_SIZE  "get_output_data_size"
    00216 #define PLUGINCODEC_CONTROL_SET_CODEC_OPTIONS     "set_codec_options"
    00217 #define PLUGINCODEC_CONTROL_TO_NORMALISED_OPTIONS "to_normalised_options"
    00218 #define PLUGINCODEC_CONTROL_TO_CUSTOMISED_OPTIONS "to_customised_options"
    00219 #define PLUGINCODEC_CONTROL_SET_INSTANCE_ID       "set_instance_id"
    00220 #define PLUGINCODEC_CONTROL_SET_LOG_FUNCTION      "set_log_function"
    00221 #define PLUGINCODEC_CONTROL_GET_STATISTICS        "get_statistics"
    00222 #define PLUGINCODEC_CONTROL_TERMINATE_CODEC       "terminate_codec"
    00223
    00224
    00225 /* Log function, plug in gets a pointer to this function which allows
    00226    it to use the standard OPAL logging system. The function returns 0 if
    00227    no logging was performed due to the log level. Note if log == NULL
    00228    then this return state is all that happens, so this may be executed
    00229    first to prevent lengthy logs that would not result in any output. */
    00230 typedef int (*PluginCodec_LogFunction)(unsigned level,
    00231                                        const char * file,
    00232                                        unsigned line,
    00233                                        const char * section,
    00234                                        const char * log);
    00235
    00236
    00237 struct PluginCodec_ControlDefn {
    00238   const char * name;
    00239   int (*control)(const struct PluginCodec_Definition * codec, void * context,
    00240                  const char * name, void * parm, unsigned * parmLen);
    00241
    00242 };
    00243
    00244 enum PluginCodec_OptionTypes {
    00245   PluginCodec_StringOption,
    00246   PluginCodec_BoolOption,
    00247   PluginCodec_IntegerOption,
    00248   PluginCodec_RealOption,
    00249   PluginCodec_EnumOption,
    00250   PluginCodec_OctetsOption,
    00251   PluginCodec_NumOptionTypes,
    00252 };
    00253
    00254 enum PluginCodec_OptionMerge {
    00255   PluginCodec_NoMerge,
    00256   PluginCodec_MinMerge,
    00257   PluginCodec_MaxMerge,
    00258   PluginCodec_EqualMerge,
    00259   PluginCodec_NotEqualMerge,
    00260   PluginCodec_AlwaysMerge,
    00261   PluginCodec_CustomMerge,
    00262   PluginCodec_IntersectionMerge,
    00263
    00264   PluginCodec_AndMerge = PluginCodec_MinMerge,
    00265   PluginCodec_OrMerge  = PluginCodec_MaxMerge
    00266 };
    00267
    00268 #define PluginCodec_H245_Collapsing    0x40000000
    00269 #define PluginCodec_H245_NonCollapsing 0x20000000
    00270 #define PluginCodec_H245_Unsigned32    0x10000000
    00271 #define PluginCodec_H245_BooleanArray  0x08000000
    00272 #define PluginCodec_H245_TCS           0x04000000
    00273 #define PluginCodec_H245_OLC           0x02000000
    00274 #define PluginCodec_H245_ReqMode       0x01000000
    00275 #define PluginCodec_H245_OrdinalMask   0x0000ffff
    00276 #define PluginCodec_H245_PositionMask  0x00ff0000
    00277 #define PluginCodec_H245_PositionShift 16
    00278
    00279 typedef int (*PluginCodec_MergeFunction)(char ** result, const char * dest, const char * src);
    00280 typedef void (*PluginCodec_FreeFunction)(char * string);
    00281
    00282 struct PluginCodec_Option {
    00283   // start of version 4 fields
    00284   enum PluginCodec_OptionTypes m_type;
    00285   const char *                 m_name;
    00286   unsigned                     m_readOnly;
    00287   enum PluginCodec_OptionMerge m_merge;
    00288   const char *                 m_value;
    00289   const char *                 m_FMTPName;
    00290   const char *                 m_FMTPDefault;
    00291   int                          m_H245Generic;
    00292   const char *                 m_minimum;
    00293   const char *                 m_maximum;
    00294   PluginCodec_MergeFunction    m_mergeFunction; // Used if m_merge==PluginCodec_CustomMerge
    00295   PluginCodec_FreeFunction     m_freeFunction;
    00296   const char *                 m_H245Default;
    00297 };
    00298
    00299
    00300 // Normalised option names
    00301 #define PLUGINCODEC_OPTION_NEEDS_JITTER               "Needs Jitter"
    00302 #define PLUGINCODEC_OPTION_CLOCK_RATE                 "Clock Rate"
    00303 #define PLUGINCODEC_OPTION_CHANNELS                   "Channels"
    00304 #define PLUGINCODEC_OPTION_FRAME_TIME                 "Frame Time"
    00305 #define PLUGINCODEC_OPTION_MAX_FRAME_SIZE             "Max Frame Size"
    00306 #define PLUGINCODEC_OPTION_MAX_TX_PACKET_SIZE         "Max Tx Packet Size"   /* Really max PAYLOAD size */
    00307 #define PLUGINCODEC_OPTION_MAX_BIT_RATE               "Max Bit Rate"
    00308 #define PLUGINCODEC_OPTION_TARGET_BIT_RATE            "Target Bit Rate"
    00309 #define PLUGINCODEC_OPTION_RATE_CONTROL_PERIOD        "Rate Control Period"
    00310 #define PLUGINCODEC_OPTION_RX_FRAMES_PER_PACKET       "Rx Frames Per Packet"
    00311 #define PLUGINCODEC_OPTION_TX_FRAMES_PER_PACKET       "Tx Frames Per Packet"
    00312 #define PLUGINCODEC_OPTION_FRAME_WIDTH                "Frame Width"
    00313 #define PLUGINCODEC_OPTION_FRAME_HEIGHT               "Frame Height"
    00314 #define PLUGINCODEC_OPTION_MIN_RX_FRAME_WIDTH         "Min Rx Frame Width"
    00315 #define PLUGINCODEC_OPTION_MIN_RX_FRAME_HEIGHT        "Min Rx Frame Height"
    00316 #define PLUGINCODEC_OPTION_MAX_RX_FRAME_WIDTH         "Max Rx Frame Width"
    00317 #define PLUGINCODEC_OPTION_MAX_RX_FRAME_HEIGHT        "Max Rx Frame Height"
    00318 #define PLUGINCODEC_OPTION_TEMPORAL_SPATIAL_TRADE_OFF "Temporal Spatial Trade Off"
    00319 #define PLUGINCODEC_OPTION_TX_KEY_FRAME_PERIOD        "Tx Key Frame Period"
    00320
    00321 #define PLUGINCODEC_OPTION_PROTOCOL      "Protocol"
    00322 #define PLUGINCODEC_OPTION_PROTOCOL_H323 "H.323"
    00323 #define PLUGINCODEC_OPTION_PROTOCOL_SIP  "SIP"
    00324
    00325
    00326 // Full definition of the codec
    00327
    00328 struct PluginCodec_Definition {
    00329   unsigned int version;                     // codec structure version
    00330
    00331   // start of version 1 fields
    00332   struct PluginCodec_information * info;   // license information
    00333
    00334   unsigned int flags;                      // b0-3: 0 = audio,        1 = video
    00335                                            // b4:   0 = raw input,    1 = RTP input
    00336                                            // b5:   0 = raw output,   1 = RTP output
    00337                                            // b6:   0 = dynamic RTP,  1 = explicit RTP
    00338                                            // b7:   0 = no share RTP, 1 = share RTP
    00339
    00340   const char * descr;                       // text decription
    00341
    00342   const char * sourceFormat;               // source format
    00343   const char * destFormat;                 // destination format
    00344
    00345   const void * userData;                   // user data value
    00346
    00347   unsigned int sampleRate;                 // samples per second
    00348   unsigned int bitsPerSec;                // raw bits per second
    00349   unsigned int usPerFrame;                 // microseconds per frame
    00350
    00351   union _parm {
    00352     struct _audio {
    00353       unsigned int samplesPerFrame;            // audio: samples per frame
    00354       unsigned int bytesPerFrame;              // audio: max bytes per frame
    00355       unsigned int recommendedFramesPerPacket; // audio: recommended number of frames per packet
    00356       unsigned int maxFramesPerPacket;         // audio: maximum number of frames per packet
    00357     } audio;
    00358     struct _video {
    00359       unsigned int maxFrameWidth;              // video: frame width
    00360       unsigned int maxFrameHeight;             // video: frame height
    00361       unsigned int recommendedFrameRate;       // video: recommended frame rate
    00362       unsigned int maxFrameRate;               // video: max frame rate
    00363     } video;
    00364   } parm;
    00365
    00366   unsigned char rtpPayload;                 // IANA RTP payload code (if defined)
    00367   const char * sdpFormat;                  // SDP format string (or NULL, if no SDP format)
    00368
    00369   void * (*createCodec)(const struct PluginCodec_Definition * codec);                    // create codec
    00370   void (*destroyCodec) (const struct PluginCodec_Definition * codec,  void * context);   // destroy codec
    00371   int (*codecFunction) (const struct PluginCodec_Definition * codec,  void * context,   // do codec function
    00372                                   const void * from, unsigned * fromLen,
    00373                                         void * to,   unsigned * toLen,
    00374                                         unsigned int * flag);
    00375   struct PluginCodec_ControlDefn * codecControls;
    00376
    00377   // H323 specific fields
    00378   unsigned char h323CapabilityType;
    00379   const void  * h323CapabilityData;
    00380
    00381   // end of version 1 fields
    00382
    00383   // NOTE!!!!! Due to an error in judgement, you cannot add ANY more fields
    00384   // to this structure without an API version change!!!!
    00385 };
    00386
    00387 typedef struct PluginCodec_Definition * (* PluginCodec_GetCodecFunction)(unsigned int *, unsigned int);
    00388 typedef unsigned (* PluginCodec_GetAPIVersionFunction)();
    00389
    00390
    00392
    00393 #define PLUGINCODEC_RAW_AUDIO "L16"
    00394 #define PLUGINCODEC_RAW_VIDEO "YUV420P"
    00395
    00397 #define PLUGINCODEC_CODEC_PAIR(MediaFormat,     \
    00398                                PayloadName,     \
    00399                                Description,     \
    00400                                SampleRate,      \
    00401                                BitsPerSecond,   \
    00402                                FrameTime,       \
    00403                                p1,p2,p3,p4, \
    00404                                PayloadType,     \
    00405                                H323type,        \
    00406                                H323data,        \
    00407                                CreateEncoder,   \
    00408                                DestroyEncoder,  \
    00409                                EncodeMedia,     \
    00410                                CreateDecoder,   \
    00411                                DestroyDecoder,  \
    00412                                DecodeMedia,     \
    00413                                ControlsTable,   \
    00414                                Flags,           \
    00415                                RawFormat        \
    00416                                ) \
    00417   { \
    00418     PLUGIN_CODEC_VERSION, &MyLicenseInfo, Flags, Description, RawFormat, MediaFormat, NULL, \
    00419     SampleRate, BitsPerSecond, FrameTime, {{ p1,p2,p3,p4 }}, PayloadType, PayloadName, \
    00420     CreateEncoder, DestroyEncoder, EncodeMedia, ControlsTable, H323type, H323data \
    00421   }, \
    00422   { \
    00423     PLUGIN_CODEC_VERSION, &MyLicenseInfo, Flags, Description, MediaFormat, RawFormat, NULL, \
    00424     SampleRate, BitsPerSecond, FrameTime, {{ p1,p2,p3,p4 }}, PayloadType, PayloadName, \
    00425     CreateDecoder, DestroyDecoder, DecodeMedia, ControlsTable, H323type, H323data \
    00426   }
    00427
    00428 #define PLUGINCODEC_AUDIO_CODEC(MediaFormat,      \
    00429                                 PayloadName,      \
    00430                                 Description,      \
    00431                                 SampleRate,       \
    00432                                 BitsPerSecond,    \
    00433                                 FrameTime,        \
    00434                                 SamplesPerFrame,  \
    00435                                 BytesPerFrame,    \
    00436                                 RecFramesPerPacket,  \
    00437                                 MaxFramesPerPacket,  \
    00438                                 RtpFlags,          \
    00439                                 PayloadType,       \
    00440                                 H323type,          \
    00441                                 H323data,          \
    00442                                 CreateEncoder,     \
    00443                                 DestroyEncoder,    \
    00444                                 EncodeAudio,       \
    00445                                 CreateDecoder,     \
    00446                                 DestroyDecoder,    \
    00447                                 DecodeAudio,       \
    00448                                 ControlsTable      \
    00449                                 ) \
    00450          PLUGINCODEC_CODEC_PAIR(MediaFormat, \
    00451                                 PayloadName, \
    00452                                 Description, \
    00453                                 SampleRate, \
    00454                                 BitsPerSecond, \
    00455                                 FrameTime, \
    00456                                 SamplesPerFrame, \
    00457                                 BytesPerFrame, \
    00458                                 RecFramesPerPacket, \
    00459                                 MaxFramesPerPacket, \
    00460                                 PayloadType, \
    00461                                 H323type, \
    00462                                 H323data, \
    00463                                 CreateEncoder, \
    00464                                 DestroyEncoder, \
    00465                                 EncodeAudio, \
    00466                                 CreateDecoder, \
    00467                                 DestroyDecoder, \
    00468                                 DecodeAudio, \
    00469                                 ControlsTable, \
    00470                                 PluginCodec_MediaTypeAudio | /* audio codec */ \
    00471                                 PluginCodec_InputTypeRaw |   /* raw input data */ \
    00472                                 PluginCodec_OutputTypeRaw |  /* raw output data */ \
    00473                                 (RtpFlags), \
    00474                                 PLUGINCODEC_RAW_AUDIO)
    00475
    00476 #define PLUGINCODEC_ONE_AUDIO_CODEC(MediaFormat,      \
    00477                                     PayloadName,      \
    00478                                     Description,      \
    00479                                     SampleRate,       \
    00480                                     BitsPerSecond,    \
    00481                                     FrameTime,        \
    00482                                     SamplesPerFrame,  \
    00483                                     BytesPerFrame,    \
    00484                                     RecFramesPerPacket,  \
    00485                                     MaxFramesPerPacket,  \
    00486                                     RtpFlags,          \
    00487                                     PayloadType,       \
    00488                                     H323type,          \
    00489                                     H323data           \
    00490                                 ) \
    00491     static struct PluginCodec_Definition CodecDefinitionTable[] = { \
    00492             PLUGINCODEC_AUDIO_CODEC(MediaFormat, \
    00493                                     PayloadName, \
    00494                                     Description, \
    00495                                     SampleRate, \
    00496                                     BitsPerSecond, \
    00497                                     FrameTime, \
    00498                                     SamplesPerFrame, \
    00499                                     BytesPerFrame, \
    00500                                     RecFramesPerPacket, \
    00501                                     MaxFramesPerPacket, \
    00502                                     RtpFlags, \
    00503                                     PayloadType, \
    00504                                     H323type, \
    00505                                     H323data, \
    00506                                     MyCreateEncoder, \
    00507                                     MyDestroyEncoder, \
    00508                                     MyEncodeAudio, \
    00509                                     MyCreateDecoder, \
    00510                                     MyDestroyDecoder, \
    00511                                     MyDecodeAudio, \
    00512                                     MyControlsTable \
    00513                                     ) \
    00514     }
    00515
    00516 #define PLUGINCODEC_VIDEO_CODEC(MediaFormat,      \
    00517                                 PayloadName,      \
    00518                                 Description,      \
    00519                                 BitsPerSecond,    \
    00520                                 MaxWidth,         \
    00521                                 MaxHeight,        \
    00522                                 RtpFlags,         \
    00523                                 PayloadType,      \
    00524                                 H323type,         \
    00525                                 H323data,         \
    00526                                 CreateEncoder,    \
    00527                                 DestroyEncoder,   \
    00528                                 EncodeVideo,      \
    00529                                 CreateDecoder,    \
    00530                                 DestroyDecoder,   \
    00531                                 DecodeVideo,      \
    00532                                 ControlsTable     \
    00533                                 ) \
    00534          PLUGINCODEC_CODEC_PAIR(MediaFormat, \
    00535                                 PayloadName, \
    00536                                 Description, \
    00537                                 SampleRate, \
    00538                                 BitsPerSecond, \
    00539                                 90000, \
    00540                                 BitsPerSecond, \
    00541                                 100000, \
    00542                                 MaxWidth, \
    00543                                 MaxHeight, \
    00544                                 0,30, \
    00545                                 PayloadType, \
    00546                                 H323type, \
    00547                                 H323data, \
    00548                                 CreateEncoder, \
    00549                                 DestroyEncoder, \
    00550                                 EncodeVideo, \
    00551                                 CreateDecoder, \
    00552                                 DestroyDecoder, \
    00553                                 DecodeVideo, \
    00554                                 ControlsTable, \
    00555                                 PluginCodec_MediaTypeVideo | /* video codec */ \
    00556                                 PluginCodec_InputTypeRRP |   /* RTP input data */ \
    00557                                 PluginCodec_OutputTypeRRP |  /* RTP output data */ \
    00558                                 (RtpFlags), \
    00559                                 PLUGINCODEC_RAW_VIDEO)
    00560
    00561 #define PLUGINCODEC_ONE_VIDEO_CODEC(MediaFormat,      \
    00562                                     PayloadName,      \
    00563                                     Description,      \
    00564                                     BitsPerSecond,    \
    00565                                     MaxWidth,         \
    00566                                     MaxHeight,        \
    00567                                     RtpFlags,         \
    00568                                     PayloadType,      \
    00569                                     H323type,         \
    00570                                     H323data          \
    00571                                 ) \
    00572     static struct PluginCodec_Definition CodecDefinitionTable[] = { \
    00573             PLUGINCODEC_VIDEO_CODEC(MediaFormat, \
    00574                                     PayloadName, \
    00575                                     Description, \
    00576                                     BitsPerSecond, \
    00577                                     MaxWidth, \
    00578                                     MaxHeight, \
    00579                                     RtpFlags, \
    00580                                     PayloadType, \
    00581                                     H323type, \
    00582                                     H323data, \
    00583                                     CreateEncoder, \
    00584                                     DestroyEncoder, \
    00585                                     EncodeAudio, \
    00586                                     CreateDecoder, \
    00587                                     DestroyDecoder, \
    00588                                     DecodeAudio, \
    00589                                     ControlsTable \
    00590                                     ) \
    00591     }
    00592
    00593
    00595 //
    00596 //  H.323 specific values
    00597 //
    00598
    00599
    00600 struct PluginCodec_H323CapabilityExtension {
    00601   unsigned int index;
    00602   void * data;
    00603   unsigned dataLength;
    00604 };
    00605
    00606 struct PluginCodec_H323NonStandardCodecData {
    00607   const char * objectId;
    00608   unsigned char  t35CountryCode;
    00609   unsigned char  t35Extension;
    00610   unsigned short manufacturerCode;
    00611   const unsigned char * data;
    00612   unsigned int dataLength;
    00613   int (*capabilityMatchFunction)(struct PluginCodec_H323NonStandardCodecData *);
    00614 };
    00615
    00616
    00617 struct PluginCodec_H323GenericParameterDefinition
    00618 {
    00619   /* The following used to be a simple integer for the collapsing flag in
    00620      version 3 and earlier. We hope that all those implementations just used
    00621      zero and one (a good bet) and thus the below bit fields will be backward
    00622      compatible, putting the parameter in all three PDU types.
    00623    */
    00624 #ifndef SOLARIS
    00625   struct {
    00626 #endif
    00627     int collapsing:1; /* boolean */
    00628     int excludeTCS:1;
    00629     int excludeOLC:1;
    00630     int excludeReqMode:1;
    00631     int readOnly:1;
    00632 #ifndef SOLARIS
    00633   };
    00634 #endif
    00635
    00636   unsigned int id;
    00637
    00638   enum PluginCodec_H323GenericParameterType {
    00639     /* these need to be in the same order as the choices in
    00640       H245_ParameterValue::Choices, as the value is just cast to that type
    00641     */
    00642     PluginCodec_GenericParameter_Logical = 0,
    00643     PluginCodec_GenericParameter_BooleanArray,
    00644     PluginCodec_GenericParameter_UnsignedMin,
    00645     PluginCodec_GenericParameter_UnsignedMax,
    00646     PluginCodec_GenericParameter_Unsigned32Min,
    00647     PluginCodec_GenericParameter_Unsigned32Max,
    00648     PluginCodec_GenericParameter_OctetString,
    00649     PluginCodec_GenericParameter_GenericParameter,
    00650
    00651     PluginCodec_GenericParameter_logical = 0,
    00652     PluginCodec_GenericParameter_booleanArray,
    00653     PluginCodec_GenericParameter_unsignedMin,
    00654     PluginCodec_GenericParameter_unsignedMax,
    00655     PluginCodec_GenericParameter_unsigned32Min,
    00656     PluginCodec_GenericParameter_unsigned32Max,
    00657     PluginCodec_GenericParameter_octetString,
    00658     PluginCodec_GenericParameter_genericParameter
    00659   } type;
    00660
    00661   union {
    00662     unsigned long integer;
    00663     const char * octetstring;
    00664     struct PluginCodec_H323GenericParameterDefinition *genericparameter;
    00665   } value;
    00666 };
    00667
    00668 struct PluginCodec_H323GenericCodecData
    00669 {
    00670   // some cunning structures & lists, and associated logic in
    00671   // H323CodecPluginGenericAudioCapability::H323CodecPluginGenericAudioCapability()
    00672   const char * standardIdentifier;
    00673   unsigned int maxBitRate; // Zero means use value from OpalMediaFormat
    00674
    00675   /* parameters; these are the parameters which are set in the
    00676      'TerminalCapabilitySet' and 'OpenLogicalChannel' requests */
    00677   unsigned int nParameters;
    00678   /* an array of nParameters parameter definitions */
    00679   const struct PluginCodec_H323GenericParameterDefinition *params;
    00680 };
    00681
    00682
    00683 struct PluginCodec_H323AudioGSMData {
    00684   int comfortNoise:1;
    00685   int scrambled:1;
    00686 };
    00687
    00688 struct  PluginCodec_H323AudioG7231AnnexC {
    00689   unsigned char maxAl_sduAudioFrames;
    00690   int silenceSuppression:1;
    00691   int highRateMode0:6;          // INTEGER (27..78),  -- units octets
    00692   int  highRateMode1:6;          // INTEGER (27..78),  -- units octets
    00693   int  lowRateMode0:6;            // INTEGER (23..66),  -- units octets
    00694   int  lowRateMode1:6;            // INTEGER (23..66),  -- units octets
    00695   int  sidMode0:4;                // INTEGER (6..17),  -- units octets
    00696   int  sidMode1:4;                // INTEGER (6..17),  -- units octets
    00697 };
    00698
    00699
    00700 enum {
    00701   PluginCodec_H323Codec_undefined,      // must be zero, so empty struct is undefined
    00702   PluginCodec_H323Codec_programmed,      // H323ProgrammedCapability
    00703   PluginCodec_H323Codec_nonStandard,    // H323NonStandardData
    00704   PluginCodec_H323Codec_generic,            // H323GenericCodecData
    00705
    00706   // audio codecs
    00707   PluginCodec_H323AudioCodec_g711Alaw_64k,        // int
    00708   PluginCodec_H323AudioCodec_g711Alaw_56k,        // int
    00709   PluginCodec_H323AudioCodec_g711Ulaw_64k,        // int
    00710   PluginCodec_H323AudioCodec_g711Ulaw_56k,        // int
    00711   PluginCodec_H323AudioCodec_g722_64k,            // int
    00712   PluginCodec_H323AudioCodec_g722_56k,            // int
    00713   PluginCodec_H323AudioCodec_g722_48k,            // int
    00714   PluginCodec_H323AudioCodec_g7231,                // H323AudioG7231Data
    00715   PluginCodec_H323AudioCodec_g728,                // int
    00716   PluginCodec_H323AudioCodec_g729,                // int
    00717   PluginCodec_H323AudioCodec_g729AnnexA,          // int
    00718   PluginCodec_H323AudioCodec_is11172,             // not yet implemented
    00719   PluginCodec_H323AudioCodec_is13818Audio,        // not yet implemented
    00720   PluginCodec_H323AudioCodec_g729wAnnexB,          // int
    00721   PluginCodec_H323AudioCodec_g729AnnexAwAnnexB,    // int
    00722   PluginCodec_H323AudioCodec_g7231AnnexC,         // H323AudioG7231AnnexC
    00723   PluginCodec_H323AudioCodec_gsmFullRate,          // H323AudioGSMData
    00724   PluginCodec_H323AudioCodec_gsmHalfRate,          // H323AudioGSMData
    00725   PluginCodec_H323AudioCodec_gsmEnhancedFullRate,  // H323AudioGSMData
    00726   PluginCodec_H323AudioCodec_g729Extensions,      // not yet implemented
    00727
    00728   // video codecs
    00729   PluginCodec_H323VideoCodec_h261,                // implemented
    00730   PluginCodec_H323VideoCodec_h262,                // not yet implemented
    00731   PluginCodec_H323VideoCodec_h263,                // implemented
    00732   PluginCodec_H323VideoCodec_is11172,             // not yet implemented
    00733
    00734   // other capabilities
    00735   PluginCodec_H323VideoCodec_Extended,            // implemented (for use with H.239)
    00736   PluginCodec_H323T38Codec,                       // not yet implemented
    00737
    00738   // special codes
    00739   PluginCodec_H323Codec_NoH323 = 0xff,            // used for SIP-only codecs
    00740 };
    00741
    00743 //
    00744 // Generic Codec Standard Identifiers
    00745 //
    00746
    00747 // Audio Capabilities
    00748 // AMR (as defined in H.245v13 Annex I)
    00749 #define OpalPluginCodec_Identifer_AMR             "0.0.8.245.1.1.1"
    00750
    00751 // AMR-NB\WB  (as defined in H.245v13 Annex R)
    00752 #define OpalPluginCodec_Identifer_AMR_NB          "0.0.8.245.1.1.9"
    00753 #define OpalPluginCodec_Identifer_AMR_WB          "0.0.8.245.1.1.10"
    00754
    00755 // G.722.1
    00756 #define OpalPluginCodec_Identifer_G7221           "0.0.7.7221.1.0"
    00757 #define OpalPluginCodec_Identifer_G7221ext        "0.0.7.7221.1.1.0"
    00758
    00759 // G.722.2 (aka AMR-WB)
    00760 #define OpalPluginCodec_Identifer_G7222           "0.0.7.7222.1.0"
    00761
    00762 // iLBC (as defined in H.245v13 Annex S)
    00763 #define OpalPluginCodec_Identifer_iLBC            "0.0.8.245.1.1.11"
    00764
    00765
    00766 // Video Capabilities
    00767
    00768 // H264 (as defined in H.241)
    00769 #define OpalPluginCodec_Identifer_H264_Aligned        "0.0.8.241.0.0.0.0"
    00770 #define OpalPluginCodec_Identifer_H264_NonInterleaved "0.0.8.241.0.0.0.1"
    00771 #define OpalPluginCodec_Identifer_H264_Interleaved    "0.0.8.241.0.0.0.2"
    00772 #define OpalPluginCodec_Identifer_H264_Generic        "0.0.8.241.0.0.1"
    00773
    00774 // ISO/IEC 14496-2 MPEG4 part 2 (as defined in H.245v13 Annex E)
    00775 #define OpalPluginCodec_Identifer_MPEG4           "0.0.8.245.1.0.0"
    00776
    00777
    00779 //
    00780 // Predefined options for H.323 codecs
    00781 //
    00782
    00783 #define PLUGINCODEC_SQCIF_MPI   "SQCIF MPI"
    00784 #define PLUGINCODEC_QCIF_MPI     "QCIF MPI"
    00785 #define PLUGINCODEC_CIF_MPI       "CIF MPI"
    00786 #define PLUGINCODEC_CIF4_MPI     "CIF4 MPI"
    00787 #define PLUGINCODEC_CIF16_MPI   "CIF16 MPI"
    00788 #define PLUGINCODEC_CUSTOM_MPI "Custom MPI"
    00789
    00790 #define PLUGINCODEC_MPI_DISABLED 33
    00791
    00792 #define PLUGINCODEC_MEDIA_PACKETIZATION  "Media Packetization"
    00793 #define PLUGINCODEC_MEDIA_PACKETIZATIONS "Media Packetizations"
    00794
    00795 #define H261_ANNEX_D "Annex D - Still Image Transmit"
    00796 #define H263_ANNEX_D "Annex D - Unrestricted Motion Vector"
    00797 #define H263_ANNEX_F "Annex F - Advanced Prediction"
    00798 #define H263_ANNEX_I "Annex I - Advanced INTRA Coding"
    00799 #define H263_ANNEX_J "Annex J - Deblocking Filter"
    00800 #define H263_ANNEX_K "Annex K - Slice Structure"
    00801 #define H263_ANNEX_N "Annex N - Reference Picture Selection"
    00802 #define H263_ANNEX_S "Annex S - Alternative INTER VLC"
    00803 #define H263_ANNEX_T "Annex T - Modified Quantization"
    00804
    00805 #ifndef STRINGIZE
    00806 #define __INTERNAL_STRINGIZE__(v) #v
    00807 #define STRINGIZE(v) __INTERNAL_STRINGIZE__(v)
    00808 #endif
    00809
    00810
    00812 //
    00813 // RTP specific definitions
    00814 //
    00815
    00816 #define PluginCodec_RTP_MaxPacketSize  (1518-14-4-8-20-16)  // Max Ethernet packet (1518 bytes) minus 802.3/CRC, 802.3, IP, UDP headers
    00817 #define PluginCodec_RTP_MinHeaderSize  (12)
    00818 #define PluginCodec_RTP_MaxPayloadSize (PluginCodec_RTP_MaxPacketSize - PluginCodec_RTP_MinHeaderSize)
    00819
    00820 #define PluginCodec_RTP_GetWORD(ptr, off)       ((((unsigned char*)(ptr))[off] << 8) | ((unsigned char*)(ptr))[off+1])
    00821
    00822 #define PluginCodec_RTP_GetDWORD(ptr, off)      ((((unsigned char*)(ptr))[off  ] << 24)|\
    00823                                                  (((unsigned char*)(ptr))[off+1] << 16)|\
    00824                                                  (((unsigned char*)(ptr))[off+2] << 8 )|\
    00825                                                   ((unsigned char*)(ptr))[off+3])
    00826
    00827 #define PluginCodec_RTP_SetWORD(ptr, off, val)  ((((unsigned char*)(ptr))[off  ] = (unsigned char)((val) >> 8 )),\
    00828                                                  (((unsigned char*)(ptr))[off+1] = (unsigned char) (val)      ))
    00829
    00830 #define PluginCodec_RTP_SetDWORD(ptr, off, val) ((((unsigned char*)(ptr))[off  ] = (unsigned char)((val) >> 24)),\
    00831                                                  (((unsigned char*)(ptr))[off+1] = (unsigned char)((val) >> 16)),\
    00832                                                  (((unsigned char*)(ptr))[off+2] = (unsigned char)((val) >> 8 )),\
    00833                                                  (((unsigned char*)(ptr))[off+3] = (unsigned char) (val)      ))
    00834
    00835 #define PluginCodec_RTP_GetCSRCHdrLength(ptr)      ((((unsigned char*)(ptr))[0] & 0x0f)*4 + PluginCodec_RTP_MinHeaderSize)
    00836 #define PluginCodec_RTP_GetExtHdrLength(ptr)       ((((unsigned char*)(ptr))[0] & 0x10) ? (PluginCodec_RTP_GetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr)+2)*4+4) : 0)
    00837
    00838 #define PluginCodec_RTP_GetHeaderLength(ptr)       (PluginCodec_RTP_GetCSRCHdrLength(ptr) + PluginCodec_RTP_GetExtHdrLength(ptr))
    00839 #define PluginCodec_RTP_GetPayloadPtr(ptr)          ((unsigned char*)(ptr) + PluginCodec_RTP_GetHeaderLength(ptr))
    00840 #define PluginCodec_RTP_GetPayloadType(ptr)        (((unsigned char*)(ptr))[1] & 0x7f)
    00841 #define PluginCodec_RTP_SetPayloadType(ptr, type)   (((unsigned char*)(ptr))[1] = (unsigned char)((((unsigned char*)(ptr))[1] & 0x80) | (type & 0x7f)))
    00842 #define PluginCodec_RTP_GetMarker(ptr)            ((((unsigned char*)(ptr))[1] & 0x80) != 0)
    00843 #define PluginCodec_RTP_SetMarker(ptr, mark)        (((unsigned char*)(ptr))[1] = (unsigned char)((((unsigned char*)(ptr))[1] & 0x7f) | (mark != 0 ? 0x80 : 0)))
    00844 #define PluginCodec_RTP_GetTimestamp(ptr)          PluginCodec_RTP_GetDWORD(ptr, 4)
    00845 #define PluginCodec_RTP_SetTimestamp(ptr, ts)      PluginCodec_RTP_SetDWORD(ptr, 4, ts)
    00846 #define PluginCodec_RTP_GetSequenceNumber(ptr)     PluginCodec_RTP_GetWORD(ptr, 2)
    00847 #define PluginCodec_RTP_SetSequenceNumber(ptr, sn) PluginCodec_RTP_SetWORD(ptr, 2, sn)
    00848 #define PluginCodec_RTP_GetSSRC(ptr)               PluginCodec_RTP_GetDWORD(ptr, 8)
    00849 #define PluginCodec_RTP_SetSSRC(ptr, ssrc)         PluginCodec_RTP_SetDWORD(ptr, 8, ssrc)
    00850
    00851 #define PluginCodec_RTP_SetExtended(ptr, type, sz) ((((unsigned char*)(ptr))[0] |= 0x10), \
    00852                                                     PluginCodec_RTP_SetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr), type), \
    00853                                                     PluginCodec_RTP_SetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr)+2, sz))
    00854
    00855
    00857 //
    00858 // video specific definitions
    00859 //
    00860
    00861 struct PluginCodec_Video_FrameHeader {
    00862   unsigned int  x;
    00863   unsigned int  y;
    00864   unsigned int  width;
    00865   unsigned int  height;
    00866 };
    00867
    00868 #ifdef __cplusplus
    00869 };
    00870
    00871 inline unsigned char * OPAL_VIDEO_FRAME_DATA_PTR(struct PluginCodec_Video_FrameHeader * base)
    00872 { return (((unsigned char *)base) + sizeof(PluginCodec_Video_FrameHeader)); }
    00873
    00874 inline unsigned char * OPAL_VIDEO_FRAME_DATA_PTR(const PluginCodec_Video_FrameHeader * base)
    00875 { return (((unsigned char *)base) + sizeof(PluginCodec_Video_FrameHeader)); }
    00876
    00877 extern "C" {
    00878 #endif
    00879
    00880 #define PLUGIN_CODEC_VIDEO_SET_FRAME_SIZE_FN    "set_frame_size"    // argument is struct PluginCodec_VideoSetFrameInfo
    00881 struct PluginCodec_Video_SetFrameInfo {
    00882   int width;
    00883   int height;
    00884 };
    00885
    00886
    00888 //
    00889 // experimental definitions for statically linking codecs
    00890 //
    00891
    00892 #ifdef OPAL_STATIC_CODEC
    00893
    00894 #  undef PLUGIN_CODEC_DLL_API
    00895 #  define PLUGIN_CODEC_DLL_API static
    00896 #  define PLUGIN_CODEC_IMPLEMENT(name) \
    00897 unsigned int Opal_StaticCodec_##name##_GetAPIVersion() \
    00898 { return PWLIB_PLUGIN_API_VERSION; } \
    00899 static struct PluginCodec_Definition * PLUGIN_CODEC_GET_CODEC_FN(unsigned * count, unsigned /*version*/); \
    00900 struct PluginCodec_Definition * Opal_StaticCodec_##name##_GetCodecs(unsigned * p1, unsigned p2) \
    00901 { return PLUGIN_CODEC_GET_CODEC_FN(p1,p2); } \
    00902
    00903 #  define PLUGIN_CODEC_IMPLEMENT_ALL(name, table, ver) \
    00904 unsigned int Opal_StaticCodec_##name##_GetAPIVersion() \
    00905 { return PWLIB_PLUGIN_API_VERSION; } \
    00906 PLUGIN_CODEC_DLL_API struct PluginCodec_Definition * Opal_StaticCodec_##name##_GetCodecs(unsigned * count, unsigned version) \
    00907 { *count = sizeof(table)/sizeof(struct PluginCodec_Definition); return version < ver ? NULL : table; }
    00908
    00909
    00910 #else
    00911
    00912 #  define PLUGIN_CODEC_IMPLEMENT(name) \
    00913 PLUGIN_CODEC_DLL_API unsigned int PLUGIN_CODEC_API_VER_FN() \
    00914 { return PWLIB_PLUGIN_API_VERSION; } \
    00915
    00916 #  define PLUGIN_CODEC_IMPLEMENT_ALL(name, table, ver) \
    00917 PLUGIN_CODEC_IMPLEMENT(name) \
    00918 PLUGIN_CODEC_DLL_API struct PluginCodec_Definition * PLUGIN_CODEC_GET_CODEC_FN(unsigned * count, unsigned version) \
    00919 { *count = sizeof(table)/sizeof(struct PluginCodec_Definition); return version < ver ? NULL : table; }
    00920
    00921
    00922 #endif
    00923
    00924 #ifdef __cplusplus
    00925 };
    00926 #endif
    00927
    00928
    00929 #ifdef _MSC_VER
    00930 #pragma warning(default:4201)
    00931 #endif
    00932
    00933 #endif // OPAL_CODEC_OPALPLUGIN_H