sipxmedialib  Version 3.3
PlgDefsV1.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2020 SIPez LLC. All rights reserved.
3 //
4 //
5 // $$
7 
8 // Author: Sergey Kostanbaev <Sergey DOT Kostanbaev AT sipez DOT com>
9 
10 #ifndef _PlgDefs_h_
11 #define _PlgDefs_h_
12 
13 #include <string.h>
14 #include <ctype.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #include "mp/RtpHeader.h"
21 
22 #ifndef CODEC_STATIC
23 #define CODEC_DYNAMIC
24 #endif
25 
26 #ifdef CODEC_DYNAMIC
27 # ifdef WIN32
28 # define CODEC_API __declspec(dllexport)
29 # else
30 # define CODEC_API
31 # endif
32 #else
33 # define CODEC_API
34 #endif
35 
36 #ifndef FALSE
37 #define FALSE (0!=0)
38 #endif
39 
40 #ifndef TRUE
41 #define TRUE (0==0)
42 #endif
43 
45 
46 # define CODEC_TYPE_FRAME_BASED 0
48 # define CODEC_TYPE_SAMPLE_BASED 1
50 
51 
53 
54 # define CODEC_FRAME_PACKING_NONE 0
56 # define CODEC_FRAME_PACKING_SPECIAL 1
59 
60 
62 
63 # define CODEC_PLC_NONE 0
65 # define CODEC_PLC_INTERNAL 1
67 
68 
70 
71 # define CODEC_CNG_NONE 0
73 # define CODEC_CNG_INTERNAL 1
75 
76 
78 
79 # define RPLG_SUCCESS 0
80 # define RPLG_INVALID_ARGUMENT (-1)
81 # define RPLG_FAILED (-2)
82 # define RPLG_NOT_SUPPORTED (-3)
83 # define RPLG_CORRUPTED_DATA (-4)
84 # define RPLG_BAD_HANDLE (-5)
85 # define RPLG_NO_MORE_DATA (-6)
86 # define RPLG_BUFFER_TOO_SMALL (-7)
87 
89 
90 
92 # define CODEC_DECODER 1
93 # define CODEC_ENCODER 0
94 
95 
96 /* c wrapper for OsSysLog::add(FAC_MP, PRI_ERR, const char* format, ...); */
97 void mppLogError(const char* format, ...);
98 
99 /* Parsing {param}={value} */
100 static inline int analizeParamEqValue(const char* parsingString, const char* paramName, int* value)
101 {
102  int tmp;
103  char c;
104  int eqFound = FALSE;
105  int digitFound = FALSE;
106  const char* res;
107  res =
108 #if defined(WIN32)
109  (const char*)
110 #endif
111  strstr(parsingString, paramName);
112  if (!res) {
113  return -1;
114  }
115  res += strlen(paramName); //Skip name of param world
116 
117  for (; (c = *res) != 0; res++)
118  {
119  if (isspace(c)) {
120  if (digitFound)
121  break;
122  continue;
123  }
124  if (c == '=') {
125  if (eqFound)
126  goto end_of_analize;
127  eqFound = TRUE;
128  continue;
129  }
130  if (isdigit(c)) {
131  if (!eqFound)
132  goto end_of_analize;
133  tmp = (c - '0');
134  for (res++; isdigit(c = *res); res++) {
135  tmp = tmp * 10 + (c - '0');
136  }
137  res--;
138  digitFound = TRUE;
139  continue;
140  }
141 
142  /* Unexpected character */
143  goto end_of_analize;
144  }
145  if (digitFound) {
146  *value = tmp;
147  return 0;
148  }
149 
150 end_of_analize:
151  return -1;
152 }
153 
154 /* fmtp parameter parser */
155 static inline int getFmtpValueRange(const char* fmtp, const char* paramName, int defaultValue, int minValue, int maxValue)
156 {
157  int value;
158  int res = (!fmtp) ? (-1) : analizeParamEqValue(fmtp, paramName, &value);
159  if ((res == 0) && (value >= minValue) && (value <= maxValue))
160  return value;
161  return defaultValue;
162 }
163 
164 
165 
170 {
171 // unsigned cbSize; ///< Size of struct for compatibility with future version
172 
174 
175 // const char* codecId; ///< Codec unique ID string. Should consist of alphanumeric
177  const char* codecManufacturer;
178  const char* codecName;
179  const char* codecVersion;
180  unsigned codecType;
181 
182 
184 
185  const char* mimeSubtype;
186  unsigned fmtpsNum;
187  const char** fmtps;
189  unsigned sampleRate;
191  unsigned numChannels;
194  unsigned framePacking;
196 
197 };
198 
203 {
204 // unsigned cbSize; ///< Size of struct for compatability with future version.
205 
206  unsigned signalingCodec;
207 
208  unsigned minBitrate;
209  unsigned maxBitrate;
211  unsigned minFrameBytes;
216  unsigned maxFrameBytes;
218  unsigned packetLossConcealment;
220  unsigned vadCng;
221  unsigned algorithmicDelay;
222  int mSetMarker;
226 };
228 
229 #define DECLARE_FUNCS_V1(x) \
230  CODEC_API int PLG_GET_INFO_V1_1(x)(const struct MppCodecInfoV1_1 **codecInfo); \
231  CODEC_API void* PLG_INIT_V1_2(x)(const char* fmtp, int isDecoder, \
232  struct MppCodecFmtpInfoV1_2* pCodecFmtpInfo); \
233  CODEC_API int PLG_FREE_V1(x)(void* handle, int isDecoder); \
234  CODEC_API int PLG_GET_PACKET_SAMPLES_V1_2(x)(void* handle, \
235  const uint8_t* pPacketData, \
236  unsigned packetSize, \
237  unsigned *pNumSamples, \
238  const struct RtpHeader* pRtpHeader);\
239  CODEC_API int PLG_DECODE_V1(x)(void* handle, const void* pCodedData, \
240  unsigned cbCodedPacketSize, void* pAudioBuffer, \
241  unsigned cbBufferSize, unsigned *pcbDecodedSize, \
242  const struct RtpHeader* pRtpHeader); \
243  CODEC_API int PLG_ENCODE_V1(x)(void* handle, const void* pAudioBuffer, \
244  unsigned cbAudioSamples, int* rSamplesConsumed, \
245  void* pCodedData, unsigned cbMaxCodedData, \
246  int* pcbCodedSize, unsigned* pbSendNow);
247 
248 #define CPP_DECLARE_FUNCS_V1(x) \
249 extern "C" DECLARE_FUNCS_V1(x)
250 
251 #define PLG_GET_CODEC_NAME get_codecs_v1
252 #define PLG_GET_INFO_V1_1(x) x##_get_info_v1_1
253 #define PLG_INIT_V1_2(x) x##_init_v1_2
254 #define PLG_GET_PACKET_SAMPLES_V1_2(x) x##_get_packet_samples_v1_2
255 #define PLG_DECODE_V1(x) x##_decode_v1
256 #define PLG_ENCODE_V1(x) x##_encode_v1
257 #define PLG_FREE_V1(x) x##_free_v1
258 #define PLG_SIGNALING_V1(x) x##_signaling_v1
259 
260 #define MSK_GET_CODEC_NAME_V1 "get_codecs_v1"
261 #define MSK_GET_INFO_V1_1 "_get_info_v1_1"
262 #define MSK_INIT_V1_2 "_init_v1_2"
263 #define MSK_GET_PACKET_SAMPLES_V1_2 "_get_packet_samples_v1_2"
264 #define MSK_DECODE_V1 "_decode_v1"
265 #define MSK_ENCODE_V1 "_encode_v1"
266 #define MSK_FREE_V1 "_free_v1"
267 #define MSK_SIGNALING_V1 "_signaling_v1"
268 
269 typedef int (*dlGetCodecsV1)(int iNum, const char** pCodecModuleName);
270 
271 typedef int (*dlPlgGetInfoV1_1)(const struct MppCodecInfoV1_1 **codecInfo);
272 typedef void* (*dlPlgInitV1_2)(const char* fmtp, int isDecoder, struct MppCodecFmtpInfoV1_2* pCodecFmtpInfo);
273 typedef int (*dlPlgGetSignalingDataV1)(void* handle, uint32_t* outEvent, uint32_t* outDuration,
274  uint32_t* startStatus, uint32_t *stopStatus);
275 typedef int (*dlPlgGetPacketSamplesV1_2)(void* handle,
276  const uint8_t* pPacketData,
277  unsigned packetSize,
278  unsigned *pNumSamples,
279  const struct RtpHeader* pRtpHeader);
280 typedef int (*dlPlgDecodeV1)(void* handle, const void* pCodedData, unsigned cbCodedPacketSize,
281  void* pAudioBuffer, unsigned cbBufferSize, unsigned *pcbDecodedSize,
282  const struct RtpHeader* pRtpHeader);
283 typedef int (*dlPlgEncodeV1)(void* handle, const void* pAudioBuffer, unsigned cbAudioSamples,
284  int* rSamplesConsumed, void* pCodedData, unsigned cbMaxCodedData,
285  int* pcbCodedSize, unsigned* pbSendNow);
286 typedef int (*dlPlgFreeV1)(void* handle, int isDecoder);
287 
288 
289 #define IPLG_ENUM_CODEC_NAME plugin_enum_codec
290 #define IPLG_ENUM_CODEC_START static const char* IPLG_ENUM_CODEC_NAME [] = {
291 #define IPLG_ENUM_CODEC(x) #x ,
292 #define IPLG_ENUM_CODEC_END NULL};
293 #define IPLG_ENUM_CODEC_FUNC \
294  CODEC_API int PLG_GET_CODEC_NAME (int iNum, const char** pCodecModuleName); /* prototype */ \
295  CODEC_API int PLG_GET_CODEC_NAME (int iNum, const char** pCodecModuleName) /* implementation */ \
296  { \
297  int i = (sizeof ( IPLG_ENUM_CODEC_NAME ) / sizeof ( IPLG_ENUM_CODEC_NAME[0] )) - 1; \
298  if ((iNum < 0) || (iNum > i)) return RPLG_FAILED; \
299  *pCodecModuleName = IPLG_ENUM_CODEC_NAME [iNum]; return RPLG_SUCCESS; \
300  }
301 
302 #define DEFINE_STATIC_REGISTRATOR \
303  void callbackRegisterStaticCodec(const char* moduleName, \
304  const char* codecModuleName, \
305  dlPlgInitV1_2 plgInit, \
306  dlPlgGetInfoV1_1 plgGetInfo, \
307  dlPlgDecodeV1 plgDecode, \
308  dlPlgEncodeV1 plgEncode, \
309  dlPlgFreeV1 plgFree, \
310  dlPlgGetPacketSamplesV1_2 plgGetPacketSamples, \
311  dlPlgGetSignalingDataV1 plgSignaling);
312 
313 #define REG_STATIC_NAME(y) registerStatic_##y
314 
315 #define REGISTER_STATIC_PLG(x) void REG_STATIC_NAME(x)(void); \
316  REG_STATIC_NAME(x)();
317 
318 #define SPLG_ENUM_CODEC_START(y) \
319  void REG_STATIC_NAME(y) (void) {
320 #define SPLG_ENUM_CODEC(x) \
321  callbackRegisterStaticCodec(__FILE__, #x, \
322  PLG_INIT_V1_2(x), \
323  PLG_GET_INFO_V1_1(x), \
324  PLG_DECODE_V1(x), \
325  PLG_ENCODE_V1(x), \
326  PLG_FREE_V1(x),
327 #define SPLG_ENUM_CODEC_SPECIAL_PACKING(x) \
328  PLG_GET_PACKET_SAMPLES_V1_2(x),
329 #define SPLG_ENUM_CODEC_NO_SPECIAL_PACKING(x) \
330  NULL,
331 #define SPLG_ENUM_CODEC_SIGNALING(x) \
332  PLG_SIGNALING_V1(x));
333 #define SPLG_ENUM_CODEC_NO_SIGNALING(x) \
334  NULL);
335 #define SPLG_ENUM_CODEC_END }
336 
337 #ifdef CODEC_DYNAMIC
338 # define PLG_ENUM_CODEC_START(y) IPLG_ENUM_CODEC_START
339 # define PLG_ENUM_CODEC(x) IPLG_ENUM_CODEC(x)
340 # define PLG_ENUM_CODEC_SPECIAL_PACKING(x)
341 # define PLG_ENUM_CODEC_NO_SPECIAL_PACKING(x)
342 # define PLG_ENUM_CODEC_SIGNALING(x)
343 # define PLG_ENUM_CODEC_NO_SIGNALING(x)
344 # define PLG_ENUM_CODEC_END IPLG_ENUM_CODEC_END \
345  IPLG_ENUM_CODEC_FUNC
346 #else
347 # define PLG_ENUM_CODEC_START(y) DEFINE_STATIC_REGISTRATOR \
348  SPLG_ENUM_CODEC_START(y)
349 # define PLG_ENUM_CODEC(x) SPLG_ENUM_CODEC(x)
350 # define PLG_ENUM_CODEC_SPECIAL_PACKING(x) SPLG_ENUM_CODEC_SPECIAL_PACKING(x)
351 # define PLG_ENUM_CODEC_NO_SPECIAL_PACKING(x) SPLG_ENUM_CODEC_NO_SPECIAL_PACKING(x)
352 # define PLG_ENUM_CODEC_SIGNALING(x) SPLG_ENUM_CODEC_SIGNALING(x)
353 # define PLG_ENUM_CODEC_NO_SIGNALING(x) SPLG_ENUM_CODEC_NO_SIGNALING(x)
354 # define PLG_ENUM_CODEC_END SPLG_ENUM_CODEC_END
355 #endif
356 
357 
358 #define PLG_SINGLE_CODEC_SIG(x) \
359  PLG_ENUM_CODEC_START(x) \
360  PLG_ENUM_CODEC_SIG(x) \
361  PLG_ENUM_CODEC_END
362 
363 #define PLG_SINGLE_CODEC(x) \
364  PLG_ENUM_CODEC_START(x) \
365  PLG_ENUM_CODEC(x) \
366  PLG_ENUM_CODEC_END
367 
368 #define PLG_DOUBLE_CODECS(x,y) \
369  PLG_ENUM_CODEC_START(x##y) \
370  PLG_ENUM_CODEC(x) \
371  PLG_ENUM_CODEC(y) \
372  PLG_ENUM_CODEC_END
373 
374 /* ABI format declarations */
375 /* Currently only signed, 16 bit, little-endian format supported */
376 #define SIZE_OF_SAMPLE 2
377 #define SIZE_OF_SAMPLE_BITS (SIZE_OF_SAMPLE * 8)
378 
379 typedef int16_t audio_sample_t;
380 
381 
382 #ifndef PLG_MAX
383 #define PLG_MAX(a, b) (((a) > (b)) ? (a) : (b))
384 #endif
385 
386 #ifndef PLG_MIN
387 #define PLG_MIN(a, b) (((a) < (b)) ? (a) : (b))
388 #endif
389 
390 #ifdef __cplusplus
391 };
392 #endif
393 
394 
395 #endif //_PlgDefs_h_
int(* dlPlgDecodeV1)(void *handle, const void *pCodedData, unsigned cbCodedPacketSize, void *pAudioBuffer, unsigned cbBufferSize, unsigned *pcbDecodedSize, const struct RtpHeader *pRtpHeader)
Definition: PlgDefsV1.h:280
int(* dlPlgEncodeV1)(void *handle, const void *pAudioBuffer, unsigned cbAudioSamples, int *rSamplesConsumed, void *pCodedData, unsigned cbMaxCodedData, int *pcbCodedSize, unsigned *pbSendNow)
Definition: PlgDefsV1.h:283
unsigned maxBitrate
Maximum bit rate for this codec (in bits per second).
Definition: PlgDefsV1.h:209
unsigned fmtpsNum
Definition: PlgDefsV1.h:186
unsigned minBitrate
Minimum bit rate for this codec (in bits per second).
Definition: PlgDefsV1.h:208
unsigned numChannels
Definition: PlgDefsV1.h:193
unsigned sampleRate
Definition: PlgDefsV1.h:190
unsigned numSamplesPerFrame
Definition: PlgDefsV1.h:210
int(* dlPlgGetInfoV1_1)(const struct MppCodecInfoV1_1 **codecInfo)
Definition: PlgDefsV1.h:271
unsigned algorithmicDelay
Definition: PlgDefsV1.h:221
unsigned vadCng
See CODEC_CNG_* for details.
Definition: PlgDefsV1.h:220
unsigned codecType
See CODEC_TYPE_* defines above.
Definition: PlgDefsV1.h:180
const char * codecManufacturer
< characters and underscores.
Definition: PlgDefsV1.h:177
const char * codecVersion
Codec version (human readable).
Definition: PlgDefsV1.h:179
int(* dlGetCodecsV1)(int iNum, const char **pCodecModuleName)
Definition: PlgDefsV1.h:269
const char * mimeSubtype
MIME subtype.
Definition: PlgDefsV1.h:185
RTP header as described in RFC 3550.
Definition: RtpHeader.h:43
const char * codecName
Codec name (human readable).
Definition: PlgDefsV1.h:178
const char ** fmtps
Definition: PlgDefsV1.h:188
int(* dlPlgFreeV1)(void *handle, int isDecoder)
Definition: PlgDefsV1.h:286
unsigned signalingCodec
TRUE if codec could carry DTMF tones, FALSE otherwise.
Definition: PlgDefsV1.h:206
Information about concrete codec instance (i.e. with selected fmtp).
Definition: PlgDefsV1.h:202
int(* dlPlgGetPacketSamplesV1_2)(void *handle, const uint8_t *pPacketData, unsigned packetSize, unsigned *pNumSamples, const struct RtpHeader *pRtpHeader)
Definition: PlgDefsV1.h:275
int16_t audio_sample_t
Definition: PlgDefsV1.h:379
unsigned framePacking
See CODEC_FRAME_PACKING_* for details.
Definition: PlgDefsV1.h:195
void mppLogError(const char *format,...)
Definition: MpPlgStaffV1.cpp:43
int(* dlPlgGetSignalingDataV1)(void *handle, uint32_t *outEvent, uint32_t *outDuration, uint32_t *startStatus, uint32_t *stopStatus)
Definition: PlgDefsV1.h:273
#define TRUE
Definition: PlgDefsV1.h:41
#define FALSE
Definition: PlgDefsV1.h:37
Generic information about codec.
Definition: PlgDefsV1.h:169