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: 27367 $
00035  * $Author: rjongbloed $
00036  * $Date: 2012-03-29 02:32:25 -0500 (Thu, 29 Mar 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"
00307 #define PLUGINCODEC_OPTION_MAX_BIT_RATE               "Max Bit Rate"
00308 #define PLUGINCODEC_OPTION_TARGET_BIT_RATE            "Target Bit Rate"
00309 #define PLUGINCODEC_OPTION_RX_FRAMES_PER_PACKET       "Rx Frames Per Packet"
00310 #define PLUGINCODEC_OPTION_TX_FRAMES_PER_PACKET       "Tx Frames Per Packet"
00311 #define PLUGINCODEC_OPTION_FRAME_WIDTH                "Frame Width"
00312 #define PLUGINCODEC_OPTION_FRAME_HEIGHT               "Frame Height"
00313 #define PLUGINCODEC_OPTION_MIN_RX_FRAME_WIDTH         "Min Rx Frame Width"
00314 #define PLUGINCODEC_OPTION_MIN_RX_FRAME_HEIGHT        "Min Rx Frame Height"
00315 #define PLUGINCODEC_OPTION_MAX_RX_FRAME_WIDTH         "Max Rx Frame Width"
00316 #define PLUGINCODEC_OPTION_MAX_RX_FRAME_HEIGHT        "Max Rx Frame Height"
00317 #define PLUGINCODEC_OPTION_TEMPORAL_SPATIAL_TRADE_OFF "Temporal Spatial Trade Off"
00318 #define PLUGINCODEC_OPTION_TX_KEY_FRAME_PERIOD        "Tx Key Frame Period"
00319 
00320 
00321 
00322 // Full definition of the codec
00323 
00324 struct PluginCodec_Definition {
00325   unsigned int version;                     // codec structure version
00326 
00327   // start of version 1 fields
00328   struct PluginCodec_information * info;   // license information
00329 
00330   unsigned int flags;                      // b0-3: 0 = audio,        1 = video
00331                                            // b4:   0 = raw input,    1 = RTP input
00332                                            // b5:   0 = raw output,   1 = RTP output
00333                                            // b6:   0 = dynamic RTP,  1 = explicit RTP
00334                                            // b7:   0 = no share RTP, 1 = share RTP
00335 
00336   const char * descr;                       // text decription
00337 
00338   const char * sourceFormat;               // source format
00339   const char * destFormat;                 // destination format
00340 
00341   const void * userData;                   // user data value
00342 
00343   unsigned int sampleRate;                 // samples per second
00344   unsigned int bitsPerSec;                // raw bits per second
00345   unsigned int usPerFrame;                 // microseconds per frame
00346 
00347   union _parm {
00348     struct _audio {
00349       unsigned int samplesPerFrame;            // audio: samples per frame
00350       unsigned int bytesPerFrame;              // audio: max bytes per frame
00351       unsigned int recommendedFramesPerPacket; // audio: recommended number of frames per packet
00352       unsigned int maxFramesPerPacket;         // audio: maximum number of frames per packet
00353     } audio;
00354     struct _video {
00355       unsigned int maxFrameWidth;              // video: frame width
00356       unsigned int maxFrameHeight;             // video: frame height
00357       unsigned int recommendedFrameRate;       // video: recommended frame rate
00358       unsigned int maxFrameRate;               // video: max frame rate
00359     } video;
00360   } parm;
00361 
00362   unsigned char rtpPayload;                 // IANA RTP payload code (if defined)
00363   const char * sdpFormat;                  // SDP format string (or NULL, if no SDP format)
00364 
00365   void * (*createCodec)(const struct PluginCodec_Definition * codec);                    // create codec
00366   void (*destroyCodec) (const struct PluginCodec_Definition * codec,  void * context);   // destroy codec
00367   int (*codecFunction) (const struct PluginCodec_Definition * codec,  void * context,   // do codec function
00368                                   const void * from, unsigned * fromLen,
00369                                         void * to,   unsigned * toLen,
00370                                         unsigned int * flag);
00371   struct PluginCodec_ControlDefn * codecControls;
00372 
00373   // H323 specific fields
00374   unsigned char h323CapabilityType;
00375   const void  * h323CapabilityData;
00376 
00377   // end of version 1 fields
00378 
00379   // NOTE!!!!! Due to an error in judgement, you cannot add ANY more fields
00380   // to this structure without an API version change!!!!
00381 };
00382 
00383 typedef struct PluginCodec_Definition * (* PluginCodec_GetCodecFunction)(unsigned int *, unsigned int);
00384 typedef unsigned (* PluginCodec_GetAPIVersionFunction)();
00385 
00386 
00388 
00389 #define PLUGINCODEC_RAW_AUDIO "L16"
00390 #define PLUGINCODEC_RAW_VIDEO "YUV420P"
00391 
00393 #define PLUGINCODEC_CODEC_PAIR(MediaFormat,     \
00394                                PayloadName,     \
00395                                Description,     \
00396                                SampleRate,      \
00397                                BitsPerSecond,   \
00398                                FrameTime,       \
00399                                p1,p2,p3,p4, \
00400                                PayloadType,     \
00401                                H323type,        \
00402                                H323data,        \
00403                                CreateEncoder,   \
00404                                DestroyEncoder,  \
00405                                EncodeMedia,     \
00406                                CreateDecoder,   \
00407                                DestroyDecoder,  \
00408                                DecodeMedia,     \
00409                                ControlsTable,   \
00410                                Flags,           \
00411                                RawFormat        \
00412                                ) \
00413   { \
00414     PLUGIN_CODEC_VERSION, &MyLicenseInfo, Flags, Description, RawFormat, MediaFormat, NULL, \
00415     SampleRate, BitsPerSecond, FrameTime, {{ p1,p2,p3,p4 }}, PayloadType, PayloadName, \
00416     CreateEncoder, DestroyEncoder, EncodeMedia, ControlsTable, H323type, H323data \
00417   }, \
00418   { \
00419     PLUGIN_CODEC_VERSION, &MyLicenseInfo, Flags, Description, MediaFormat, RawFormat, NULL, \
00420     SampleRate, BitsPerSecond, FrameTime, {{ p1,p2,p3,p4 }}, PayloadType, PayloadName, \
00421     CreateDecoder, DestroyDecoder, DecodeMedia, ControlsTable, H323type, H323data \
00422   }
00423 
00424 #define PLUGINCODEC_AUDIO_CODEC(MediaFormat,      \
00425                                 PayloadName,      \
00426                                 Description,      \
00427                                 SampleRate,       \
00428                                 BitsPerSecond,    \
00429                                 FrameTime,        \
00430                                 SamplesPerFrame,  \
00431                                 BytesPerFrame,    \
00432                                 RecFramesPerPacket,  \
00433                                 MaxFramesPerPacket,  \
00434                                 RtpFlags,          \
00435                                 PayloadType,       \
00436                                 H323type,          \
00437                                 H323data,          \
00438                                 CreateEncoder,     \
00439                                 DestroyEncoder,    \
00440                                 EncodeAudio,       \
00441                                 CreateDecoder,     \
00442                                 DestroyDecoder,    \
00443                                 DecodeAudio,       \
00444                                 ControlsTable      \
00445                                 ) \
00446          PLUGINCODEC_CODEC_PAIR(MediaFormat, \
00447                                 PayloadName, \
00448                                 Description, \
00449                                 SampleRate, \
00450                                 BitsPerSecond, \
00451                                 FrameTime, \
00452                                 SamplesPerFrame, \
00453                                 BytesPerFrame, \
00454                                 RecFramesPerPacket, \
00455                                 MaxFramesPerPacket, \
00456                                 PayloadType, \
00457                                 H323type, \
00458                                 H323data, \
00459                                 CreateEncoder, \
00460                                 DestroyEncoder, \
00461                                 EncodeAudio, \
00462                                 CreateDecoder, \
00463                                 DestroyDecoder, \
00464                                 DecodeAudio, \
00465                                 ControlsTable, \
00466                                 PluginCodec_MediaTypeAudio | /* audio codec */ \
00467                                 PluginCodec_InputTypeRaw |   /* raw input data */ \
00468                                 PluginCodec_OutputTypeRaw |  /* raw output data */ \
00469                                 (RtpFlags), \
00470                                 PLUGINCODEC_RAW_AUDIO)
00471 
00472 #define PLUGINCODEC_ONE_AUDIO_CODEC(MediaFormat,      \
00473                                     PayloadName,      \
00474                                     Description,      \
00475                                     SampleRate,       \
00476                                     BitsPerSecond,    \
00477                                     FrameTime,        \
00478                                     SamplesPerFrame,  \
00479                                     BytesPerFrame,    \
00480                                     RecFramesPerPacket,  \
00481                                     MaxFramesPerPacket,  \
00482                                     RtpFlags,          \
00483                                     PayloadType,       \
00484                                     H323type,          \
00485                                     H323data           \
00486                                 ) \
00487     static struct PluginCodec_Definition CodecDefinitionTable[] = { \
00488             PLUGINCODEC_AUDIO_CODEC(MediaFormat, \
00489                                     PayloadName, \
00490                                     Description, \
00491                                     SampleRate, \
00492                                     BitsPerSecond, \
00493                                     FrameTime, \
00494                                     SamplesPerFrame, \
00495                                     BytesPerFrame, \
00496                                     RecFramesPerPacket, \
00497                                     MaxFramesPerPacket, \
00498                                     RtpFlags, \
00499                                     PayloadType, \
00500                                     H323type, \
00501                                     H323data, \
00502                                     MyCreateEncoder, \
00503                                     MyDestroyEncoder, \
00504                                     MyEncodeAudio, \
00505                                     MyCreateDecoder, \
00506                                     MyDestroyDecoder, \
00507                                     MyDecodeAudio, \
00508                                     MyControlsTable \
00509                                     ) \
00510     }
00511 
00512 #define PLUGINCODEC_VIDEO_CODEC(MediaFormat,      \
00513                                 PayloadName,      \
00514                                 Description,      \
00515                                 BitsPerSecond,    \
00516                                 MaxWidth,         \
00517                                 MaxHeight,        \
00518                                 RtpFlags,         \
00519                                 PayloadType,      \
00520                                 H323type,         \
00521                                 H323data,         \
00522                                 CreateEncoder,    \
00523                                 DestroyEncoder,   \
00524                                 EncodeVideo,      \
00525                                 CreateDecoder,    \
00526                                 DestroyDecoder,   \
00527                                 DecodeVideo,      \
00528                                 ControlsTable     \
00529                                 ) \
00530          PLUGINCODEC_CODEC_PAIR(MediaFormat, \
00531                                 PayloadName, \
00532                                 Description, \
00533                                 SampleRate, \
00534                                 BitsPerSecond, \
00535                                 90000, \
00536                                 BitsPerSecond, \
00537                                 100000, \
00538                                 MaxWidth, \
00539                                 MaxHeight, \
00540                                 0,30, \
00541                                 PayloadType, \
00542                                 H323type, \
00543                                 H323data, \
00544                                 CreateEncoder, \
00545                                 DestroyEncoder, \
00546                                 EncodeVideo, \
00547                                 CreateDecoder, \
00548                                 DestroyDecoder, \
00549                                 DecodeVideo, \
00550                                 ControlsTable, \
00551                                 PluginCodec_MediaTypeVideo | /* video codec */ \
00552                                 PluginCodec_InputTypeRRP |   /* RTP input data */ \
00553                                 PluginCodec_OutputTypeRRP |  /* RTP output data */ \
00554                                 (RtpFlags), \
00555                                 PLUGINCODEC_RAW_VIDEO)
00556 
00557 #define PLUGINCODEC_ONE_VIDEO_CODEC(MediaFormat,      \
00558                                     PayloadName,      \
00559                                     Description,      \
00560                                     BitsPerSecond,    \
00561                                     MaxWidth,         \
00562                                     MaxHeight,        \
00563                                     RtpFlags,         \
00564                                     PayloadType,      \
00565                                     H323type,         \
00566                                     H323data          \
00567                                 ) \
00568     static struct PluginCodec_Definition CodecDefinitionTable[] = { \
00569             PLUGINCODEC_VIDEO_CODEC(MediaFormat, \
00570                                     PayloadName, \
00571                                     Description, \
00572                                     BitsPerSecond, \
00573                                     MaxWidth, \
00574                                     MaxHeight, \
00575                                     RtpFlags, \
00576                                     PayloadType, \
00577                                     H323type, \
00578                                     H323data, \
00579                                     CreateEncoder, \
00580                                     DestroyEncoder, \
00581                                     EncodeAudio, \
00582                                     CreateDecoder, \
00583                                     DestroyDecoder, \
00584                                     DecodeAudio, \
00585                                     ControlsTable \
00586                                     ) \
00587     }
00588 
00589 
00591 //
00592 //  H.323 specific values
00593 //
00594 
00595 
00596 struct PluginCodec_H323CapabilityExtension {
00597   unsigned int index;
00598   void * data;
00599   unsigned dataLength;
00600 };
00601 
00602 struct PluginCodec_H323NonStandardCodecData {
00603   const char * objectId;
00604   unsigned char  t35CountryCode;
00605   unsigned char  t35Extension;
00606   unsigned short manufacturerCode;
00607   const unsigned char * data;
00608   unsigned int dataLength;
00609   int (*capabilityMatchFunction)(struct PluginCodec_H323NonStandardCodecData *);
00610 };
00611 
00612 
00613 struct PluginCodec_H323GenericParameterDefinition
00614 {
00615   /* The following used to be a simple integer for the collapsing flag in
00616      version 3 and earlier. We hope that all those implementations just used
00617      zero and one (a good bet) and thus the below bit fields will be backward
00618      compatible, putting the parameter in all three PDU types.
00619    */ 
00620 #ifndef SOLARIS   
00621   struct {
00622 #endif  
00623     int collapsing:1; /* boolean */
00624     int excludeTCS:1;
00625     int excludeOLC:1;
00626     int excludeReqMode:1;
00627     int readOnly:1;
00628 #ifndef SOLARIS    
00629   };
00630 #endif  
00631 
00632   unsigned int id;
00633 
00634   enum PluginCodec_H323GenericParameterType {
00635     /* these need to be in the same order as the choices in
00636       H245_ParameterValue::Choices, as the value is just cast to that type
00637     */
00638     PluginCodec_GenericParameter_Logical = 0,
00639     PluginCodec_GenericParameter_BooleanArray,
00640     PluginCodec_GenericParameter_UnsignedMin,
00641     PluginCodec_GenericParameter_UnsignedMax,
00642     PluginCodec_GenericParameter_Unsigned32Min,
00643     PluginCodec_GenericParameter_Unsigned32Max,
00644     PluginCodec_GenericParameter_OctetString,
00645     PluginCodec_GenericParameter_GenericParameter,
00646 
00647     PluginCodec_GenericParameter_logical = 0,
00648     PluginCodec_GenericParameter_booleanArray,
00649     PluginCodec_GenericParameter_unsignedMin,
00650     PluginCodec_GenericParameter_unsignedMax,
00651     PluginCodec_GenericParameter_unsigned32Min,
00652     PluginCodec_GenericParameter_unsigned32Max,
00653     PluginCodec_GenericParameter_octetString,
00654     PluginCodec_GenericParameter_genericParameter
00655   } type;
00656 
00657   union {
00658     unsigned long integer;
00659     const char * octetstring;
00660     struct PluginCodec_H323GenericParameterDefinition *genericparameter;
00661   } value;
00662 };
00663 
00664 struct PluginCodec_H323GenericCodecData
00665 {
00666   // some cunning structures & lists, and associated logic in
00667   // H323CodecPluginGenericAudioCapability::H323CodecPluginGenericAudioCapability()
00668   const char * standardIdentifier;
00669   unsigned int maxBitRate; // Zero means use value from OpalMediaFormat
00670 
00671   /* parameters; these are the parameters which are set in the
00672      'TerminalCapabilitySet' and 'OpenLogicalChannel' requests */
00673   unsigned int nParameters;
00674   /* an array of nParameters parameter definitions */
00675   const struct PluginCodec_H323GenericParameterDefinition *params;
00676 };
00677 
00678 
00679 struct PluginCodec_H323AudioGSMData {
00680   int comfortNoise:1;
00681   int scrambled:1;
00682 };
00683 
00684 struct  PluginCodec_H323AudioG7231AnnexC {
00685   unsigned char maxAl_sduAudioFrames;
00686   int silenceSuppression:1;
00687   int highRateMode0:6;          // INTEGER (27..78),  -- units octets
00688   int  highRateMode1:6;          // INTEGER (27..78),  -- units octets
00689   int  lowRateMode0:6;            // INTEGER (23..66),  -- units octets
00690   int  lowRateMode1:6;            // INTEGER (23..66),  -- units octets
00691   int  sidMode0:4;                // INTEGER (6..17),  -- units octets
00692   int  sidMode1:4;                // INTEGER (6..17),  -- units octets
00693 };
00694 
00695 
00696 enum {
00697   PluginCodec_H323Codec_undefined,      // must be zero, so empty struct is undefined
00698   PluginCodec_H323Codec_programmed,      // H323ProgrammedCapability
00699   PluginCodec_H323Codec_nonStandard,    // H323NonStandardData
00700   PluginCodec_H323Codec_generic,            // H323GenericCodecData
00701 
00702   // audio codecs
00703   PluginCodec_H323AudioCodec_g711Alaw_64k,        // int
00704   PluginCodec_H323AudioCodec_g711Alaw_56k,        // int
00705   PluginCodec_H323AudioCodec_g711Ulaw_64k,        // int
00706   PluginCodec_H323AudioCodec_g711Ulaw_56k,        // int
00707   PluginCodec_H323AudioCodec_g722_64k,            // int
00708   PluginCodec_H323AudioCodec_g722_56k,            // int
00709   PluginCodec_H323AudioCodec_g722_48k,            // int
00710   PluginCodec_H323AudioCodec_g7231,                // H323AudioG7231Data
00711   PluginCodec_H323AudioCodec_g728,                // int
00712   PluginCodec_H323AudioCodec_g729,                // int
00713   PluginCodec_H323AudioCodec_g729AnnexA,          // int
00714   PluginCodec_H323AudioCodec_is11172,             // not yet implemented
00715   PluginCodec_H323AudioCodec_is13818Audio,        // not yet implemented
00716   PluginCodec_H323AudioCodec_g729wAnnexB,          // int
00717   PluginCodec_H323AudioCodec_g729AnnexAwAnnexB,    // int
00718   PluginCodec_H323AudioCodec_g7231AnnexC,         // H323AudioG7231AnnexC
00719   PluginCodec_H323AudioCodec_gsmFullRate,          // H323AudioGSMData
00720   PluginCodec_H323AudioCodec_gsmHalfRate,          // H323AudioGSMData
00721   PluginCodec_H323AudioCodec_gsmEnhancedFullRate,  // H323AudioGSMData
00722   PluginCodec_H323AudioCodec_g729Extensions,      // not yet implemented
00723 
00724   // video codecs
00725   PluginCodec_H323VideoCodec_h261,                // implemented
00726   PluginCodec_H323VideoCodec_h262,                // not yet implemented
00727   PluginCodec_H323VideoCodec_h263,                // implemented
00728   PluginCodec_H323VideoCodec_is11172,             // not yet implemented
00729 
00730   // other capabilities
00731   PluginCodec_H323VideoCodec_Extended,            // implemented (for use with H.239)
00732   PluginCodec_H323T38Codec,                       // not yet implemented
00733 
00734   // special codes
00735   PluginCodec_H323Codec_NoH323 = 0xff,            // used for SIP-only codecs
00736 };
00737 
00739 //
00740 // Generic Codec Standard Identifiers
00741 //
00742 
00743 // Audio Capabilities
00744 // AMR (as defined in H.245v13 Annex I)
00745 #define OpalPluginCodec_Identifer_AMR             "0.0.8.245.1.1.1"
00746 
00747 // AMR-NB\WB  (as defined in H.245v13 Annex R)
00748 #define OpalPluginCodec_Identifer_AMR_NB          "0.0.8.245.1.1.9"
00749 #define OpalPluginCodec_Identifer_AMR_WB          "0.0.8.245.1.1.10"
00750 
00751 // G.722.1
00752 #define OpalPluginCodec_Identifer_G7221           "0.0.7.7221.1.0"
00753 #define OpalPluginCodec_Identifer_G7221ext        "0.0.7.7221.1.1.0"
00754 
00755 // G.722.2 (aka AMR-WB)
00756 #define OpalPluginCodec_Identifer_G7222           "0.0.7.7222.1.0"
00757 
00758 // iLBC (as defined in H.245v13 Annex S)
00759 #define OpalPluginCodec_Identifer_iLBC            "0.0.8.245.1.1.11"
00760 
00761 
00762 // Video Capabilities
00763 
00764 // H264 (as defined in H.241)
00765 #define OpalPluginCodec_Identifer_H264_Aligned        "0.0.8.241.0.0.0.0"
00766 #define OpalPluginCodec_Identifer_H264_NonInterleaved "0.0.8.241.0.0.0.1"
00767 #define OpalPluginCodec_Identifer_H264_Interleaved    "0.0.8.241.0.0.0.2"
00768 #define OpalPluginCodec_Identifer_H264_Generic        "0.0.8.241.0.0.1"
00769 
00770 // ISO/IEC 14496-2 MPEG4 part 2 (as defined in H.245v13 Annex E)
00771 #define OpalPluginCodec_Identifer_MPEG4           "0.0.8.245.1.0.0"
00772 
00773 
00775 //
00776 // Predefined options for H.323 codecs
00777 //
00778 
00779 #define PLUGINCODEC_SQCIF_MPI   "SQCIF MPI"
00780 #define PLUGINCODEC_QCIF_MPI     "QCIF MPI"
00781 #define PLUGINCODEC_CIF_MPI       "CIF MPI"
00782 #define PLUGINCODEC_CIF4_MPI     "CIF4 MPI"
00783 #define PLUGINCODEC_CIF16_MPI   "CIF16 MPI"
00784 #define PLUGINCODEC_CUSTOM_MPI "Custom MPI"
00785 
00786 #define PLUGINCODEC_MPI_DISABLED 33
00787 
00788 #define PLUGINCODEC_MEDIA_PACKETIZATION  "Media Packetization"
00789 #define PLUGINCODEC_MEDIA_PACKETIZATIONS "Media Packetizations"
00790 
00791 #define H261_ANNEX_D "Annex D - Still Image Transmit"
00792 #define H263_ANNEX_D "Annex D - Unrestricted Motion Vector"
00793 #define H263_ANNEX_F "Annex F - Advanced Prediction"
00794 #define H263_ANNEX_I "Annex I - Advanced INTRA Coding"
00795 #define H263_ANNEX_J "Annex J - Deblocking Filter"
00796 #define H263_ANNEX_K "Annex K - Slice Structure"
00797 #define H263_ANNEX_N "Annex N - Reference Picture Selection"
00798 #define H263_ANNEX_S "Annex S - Alternative INTER VLC"
00799 #define H263_ANNEX_T "Annex T - Modified Quantization"
00800 
00801 #ifndef STRINGIZE
00802 #define __INTERNAL_STRINGIZE__(v) #v
00803 #define STRINGIZE(v) __INTERNAL_STRINGIZE__(v)
00804 #endif
00805 
00806 
00808 //
00809 // RTP specific definitions
00810 //
00811 
00812 #define PluginCodec_RTP_MaxPacketSize  (1518-14-4-8-20-16)  // Max Ethernet packet (1518 bytes) minus 802.3/CRC, 802.3, IP, UDP headers
00813 #define PluginCodec_RTP_MinHeaderSize  (12)
00814 #define PluginCodec_RTP_MaxPayloadSize (PluginCodec_RTP_MaxPacketSize - PluginCodec_RTP_MinHeaderSize)
00815 
00816 #define PluginCodec_RTP_GetWORD(ptr, off)       ((((unsigned char*)(ptr))[off] << 8) | ((unsigned char*)(ptr))[off+1])
00817 
00818 #define PluginCodec_RTP_GetDWORD(ptr, off)      ((((unsigned char*)(ptr))[off  ] << 24)|\
00819                                                  (((unsigned char*)(ptr))[off+1] << 16)|\
00820                                                  (((unsigned char*)(ptr))[off+2] << 8 )|\
00821                                                   ((unsigned char*)(ptr))[off+3])
00822 
00823 #define PluginCodec_RTP_SetWORD(ptr, off, val)  ((((unsigned char*)(ptr))[off  ] = (unsigned char)((val) >> 8 )),\
00824                                                  (((unsigned char*)(ptr))[off+1] = (unsigned char) (val)      ))
00825 
00826 #define PluginCodec_RTP_SetDWORD(ptr, off, val) ((((unsigned char*)(ptr))[off  ] = (unsigned char)((val) >> 24)),\
00827                                                  (((unsigned char*)(ptr))[off+1] = (unsigned char)((val) >> 16)),\
00828                                                  (((unsigned char*)(ptr))[off+2] = (unsigned char)((val) >> 8 )),\
00829                                                  (((unsigned char*)(ptr))[off+3] = (unsigned char) (val)      ))
00830 
00831 #define PluginCodec_RTP_GetCSRCHdrLength(ptr)      ((((unsigned char*)(ptr))[0] & 0x0f)*4 + PluginCodec_RTP_MinHeaderSize)
00832 #define PluginCodec_RTP_GetExtHdrLength(ptr)       ((((unsigned char*)(ptr))[0] & 0x10) ? (PluginCodec_RTP_GetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr)+2)*4+4) : 0)
00833 
00834 #define PluginCodec_RTP_GetHeaderLength(ptr)       (PluginCodec_RTP_GetCSRCHdrLength(ptr) + PluginCodec_RTP_GetExtHdrLength(ptr))
00835 #define PluginCodec_RTP_GetPayloadPtr(ptr)          ((unsigned char*)(ptr) + PluginCodec_RTP_GetHeaderLength(ptr))
00836 #define PluginCodec_RTP_GetPayloadType(ptr)        (((unsigned char*)(ptr))[1] & 0x7f)
00837 #define PluginCodec_RTP_SetPayloadType(ptr, type)   (((unsigned char*)(ptr))[1] = (unsigned char)((((unsigned char*)(ptr))[1] & 0x80) | (type & 0x7f)))
00838 #define PluginCodec_RTP_GetMarker(ptr)            ((((unsigned char*)(ptr))[1] & 0x80) != 0)
00839 #define PluginCodec_RTP_SetMarker(ptr, mark)        (((unsigned char*)(ptr))[1] = (unsigned char)((((unsigned char*)(ptr))[1] & 0x7f) | (mark != 0 ? 0x80 : 0)))
00840 #define PluginCodec_RTP_GetTimestamp(ptr)          PluginCodec_RTP_GetDWORD(ptr, 4)
00841 #define PluginCodec_RTP_SetTimestamp(ptr, ts)      PluginCodec_RTP_SetDWORD(ptr, 4, ts)
00842 #define PluginCodec_RTP_GetSequenceNumber(ptr)     PluginCodec_RTP_GetWORD(ptr, 2)
00843 #define PluginCodec_RTP_SetSequenceNumber(ptr, sn) PluginCodec_RTP_SetWORD(ptr, 2, sn)
00844 #define PluginCodec_RTP_GetSSRC(ptr)               PluginCodec_RTP_GetDWORD(ptr, 8)
00845 #define PluginCodec_RTP_SetSSRC(ptr, ssrc)         PluginCodec_RTP_SetDWORD(ptr, 8, ssrc)
00846 
00847 #define PluginCodec_RTP_SetExtended(ptr, type, sz) ((((unsigned char*)(ptr))[0] |= 0x10), \
00848                                                     PluginCodec_RTP_SetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr), type), \
00849                                                     PluginCodec_RTP_SetWORD(ptr, PluginCodec_RTP_GetCSRCHdrLength(ptr)+2, sz))
00850 
00851 
00853 //
00854 // video specific definitions
00855 //
00856 
00857 struct PluginCodec_Video_FrameHeader {
00858   unsigned int  x;
00859   unsigned int  y;
00860   unsigned int  width;
00861   unsigned int  height;
00862 };
00863 
00864 #ifdef __cplusplus
00865 };
00866 
00867 inline unsigned char * OPAL_VIDEO_FRAME_DATA_PTR(struct PluginCodec_Video_FrameHeader * base)
00868 { return (((unsigned char *)base) + sizeof(PluginCodec_Video_FrameHeader)); }
00869 
00870 inline unsigned char * OPAL_VIDEO_FRAME_DATA_PTR(const PluginCodec_Video_FrameHeader * base)
00871 { return (((unsigned char *)base) + sizeof(PluginCodec_Video_FrameHeader)); }
00872 
00873 extern "C" {
00874 #endif
00875 
00876 #define PLUGIN_CODEC_VIDEO_SET_FRAME_SIZE_FN    "set_frame_size"    // argument is struct PluginCodec_VideoSetFrameInfo
00877 struct PluginCodec_Video_SetFrameInfo {
00878   int width;
00879   int height;
00880 };
00881 
00882 
00884 //
00885 // experimental definitions for statically linking codecs
00886 //
00887 
00888 #ifdef OPAL_STATIC_CODEC
00889 
00890 #  undef PLUGIN_CODEC_DLL_API
00891 #  define PLUGIN_CODEC_DLL_API static
00892 #  define PLUGIN_CODEC_IMPLEMENT(name) \
00893 unsigned int Opal_StaticCodec_##name##_GetAPIVersion() \
00894 { return PWLIB_PLUGIN_API_VERSION; } \
00895 static struct PluginCodec_Definition * PLUGIN_CODEC_GET_CODEC_FN(unsigned * count, unsigned /*version*/); \
00896 struct PluginCodec_Definition * Opal_StaticCodec_##name##_GetCodecs(unsigned * p1, unsigned p2) \
00897 { return PLUGIN_CODEC_GET_CODEC_FN(p1,p2); } \
00898 
00899 #  define PLUGIN_CODEC_IMPLEMENT_ALL(name, table, ver) \
00900 unsigned int Opal_StaticCodec_##name##_GetAPIVersion() \
00901 { return PWLIB_PLUGIN_API_VERSION; } \
00902 PLUGIN_CODEC_DLL_API struct PluginCodec_Definition * Opal_StaticCodec_##name##_GetCodecs(unsigned * count, unsigned version) \
00903 { *count = sizeof(table)/sizeof(struct PluginCodec_Definition); return version < ver ? NULL : table; }
00904 
00905 
00906 #else
00907 
00908 #  define PLUGIN_CODEC_IMPLEMENT(name) \
00909 PLUGIN_CODEC_DLL_API unsigned int PLUGIN_CODEC_API_VER_FN() \
00910 { return PWLIB_PLUGIN_API_VERSION; } \
00911 
00912 #  define PLUGIN_CODEC_IMPLEMENT_ALL(name, table, ver) \
00913 PLUGIN_CODEC_IMPLEMENT(name) \
00914 PLUGIN_CODEC_DLL_API struct PluginCodec_Definition * PLUGIN_CODEC_GET_CODEC_FN(unsigned * count, unsigned version) \
00915 { *count = sizeof(table)/sizeof(struct PluginCodec_Definition); return version < ver ? NULL : table; }
00916 
00917 
00918 #endif
00919 
00920 #ifdef __cplusplus
00921 };
00922 #endif
00923 
00924 
00925 #ifdef _MSC_VER
00926 #pragma warning(default:4201)
00927 #endif
00928 
00929 #endif // OPAL_CODEC_OPALPLUGIN_H

Generated on 5 Jun 2012 for OPAL by  doxygen 1.6.1