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