Changeset 159 for pjproject/trunk/pjmedia/include/pjmedia/codec.h
- Timestamp:
- Feb 8, 2006 10:43:39 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/codec.h
r121 r159 26 26 */ 27 27 28 #include <pjmedia/types.h> 28 29 #include <pj/list.h> 29 30 … … 37 38 */ 38 39 39 /** Top most media type. */ 40 typedef enum pj_media_type 41 { 42 /** No type. */ 43 PJ_MEDIA_TYPE_NONE = 0, 44 45 /** The media is audio */ 46 PJ_MEDIA_TYPE_AUDIO = 1, 47 48 /** The media is video. */ 49 PJ_MEDIA_TYPE_VIDEO = 2, 50 51 /** Unknown media type, in this case the name will be specified in 52 * encoding_name. 53 */ 54 PJ_MEDIA_TYPE_UNKNOWN = 3, 55 56 } pj_media_type; 57 58 59 /** Media direction. */ 60 typedef enum pj_media_dir_t 61 { 62 /** None */ 63 PJ_MEDIA_DIR_NONE = 0, 64 65 /** Encoding (outgoing to network) stream */ 66 PJ_MEDIA_DIR_ENCODING = 1, 67 68 /** Decoding (incoming from network) stream. */ 69 PJ_MEDIA_DIR_DECODING = 2, 70 71 /** Incoming and outgoing stream. */ 72 PJ_MEDIA_DIR_ENCODING_DECODING = 3, 73 74 } pj_media_dir_t; 75 76 77 /** Standard RTP paylist types. */ 78 typedef enum pj_rtp_pt 79 { 80 PJ_RTP_PT_PCMU = 0, /* audio PCMU */ 81 PJ_RTP_PT_GSM = 3, /* audio GSM */ 82 PJ_RTP_PT_G723 = 4, /* audio G723 */ 83 PJ_RTP_PT_DVI4_8K = 5, /* audio DVI4 8KHz */ 84 PJ_RTP_PT_DVI4_16K = 6, /* audio DVI4 16Khz */ 85 PJ_RTP_PT_LPC = 7, /* audio LPC */ 86 PJ_RTP_PT_PCMA = 8, /* audio PCMA */ 87 PJ_RTP_PT_G722 = 9, /* audio G722 */ 88 PJ_RTP_PT_L16_2 = 10, /* audio 16bit linear 44.1KHz stereo */ 89 PJ_RTP_PT_L16_1 = 11, /* audio 16bit linear 44.1KHz mono */ 90 PJ_RTP_PT_QCELP = 12, /* audio QCELP */ 91 PJ_RTP_PT_CN = 13, /* audio Comfort Noise */ 92 PJ_RTP_PT_MPA = 14, /* audio MPEG1 or MPEG2 as elementary streams */ 93 PJ_RTP_PT_G728 = 15, /* audio G728 */ 94 PJ_RTP_PT_DVI4_11K = 16, /* audio DVI4 11.025KHz mono */ 95 PJ_RTP_PT_DVI4_22K = 17, /* audio DVI4 22.050KHz mono */ 96 PJ_RTP_PT_G729 = 18, /* audio G729 */ 97 PJ_RTP_PT_CELB = 25, /* video/comb Cell-B by Sun Microsystems (RFC 2029) */ 98 PJ_RTP_PT_JPEG = 26, /* video JPEG */ 99 PJ_RTP_PT_NV = 28, /* video NV implemented by nv program by Xerox */ 100 PJ_RTP_PT_H261 = 31, /* video H261 */ 101 PJ_RTP_PT_MPV = 32, /* video MPEG1 or MPEG2 elementary streams */ 102 PJ_RTP_PT_MP2T = 33, /* video MPEG2 transport */ 103 PJ_RTP_PT_H263 = 34, /* video H263 */ 104 105 PJ_RTP_PT_DYNAMIC = 96, /* start of dynamic RTP payload */ 106 } pj_rtp_pt; 107 108 109 /** Identification used to search for codec factory that supports specific 110 * codec specification. 111 */ 112 typedef struct pj_codec_id 113 { 114 /** Media type. */ 115 pj_media_type type; 116 117 /** Payload type (can be dynamic). */ 118 unsigned pt; 119 120 /** Encoding name, must be present if the payload type is dynamic. */ 121 pj_str_t encoding_name; 122 123 /** Sampling rate. */ 124 unsigned sample_rate; 125 } pj_codec_id; 126 127 128 /** Detailed codec attributes used both to configure a codec and to query 129 * the capability of codec factories. 130 */ 131 typedef struct pj_codec_attr 132 { 133 pj_uint32_t sample_rate; /* Sampling rate in Hz */ 134 pj_uint32_t avg_bps; /* Average bandwidth in bits per second */ 135 136 pj_uint8_t pcm_bits_per_sample;/* Bits per sample in the PCM side */ 137 pj_uint16_t ptime; /* Packet time in miliseconds */ 138 139 unsigned pt:8; /* Payload type. */ 140 unsigned vad_enabled:1; /* Voice Activity Detector. */ 141 unsigned cng_enabled:1; /* Comfort Noise Generator. */ 142 unsigned lpf_enabled:1; /* Low pass filter */ 143 unsigned hpf_enabled:1; /* High pass filter */ 144 unsigned penh_enabled:1; /* Perceptual Enhancement */ 145 unsigned concl_enabled:1; /* Packet loss concealment */ 146 unsigned reserved_bit:1; 147 148 } pj_codec_attr; 149 150 /** Types of audio frame. */ 151 typedef enum pj_audio_frame_type 152 { 153 /** The frame is a silence audio frame. */ 154 PJ_AUDIO_FRAME_SILENCE, 155 156 /** The frame is a non-silence audio frame. */ 157 PJ_AUDIO_FRAME_AUDIO, 158 159 } pj_audio_frame_type; 160 161 typedef struct pj_codec pj_codec; 162 typedef struct pj_codec_factory pj_codec_factory; 163 164 165 /** This structure describes an audio frame. */ 166 struct pj_audio_frame 167 { 168 /** Type: silence or non-silence. */ 169 pj_audio_frame_type type; 170 171 /** Pointer to buffer. */ 172 void *buf; 173 174 /** Frame size in bytes. */ 175 unsigned size; 176 }; 177 178 /** 179 * Operations that must be supported by the codec. 180 */ 181 typedef struct pj_codec_op 182 { 183 /** Get default attributes. */ 184 pj_status_t (*default_attr) (pj_codec *codec, pj_codec_attr *attr); 185 186 /** Open and initialize codec using the specified attribute. 187 * @return zero on success. 188 */ 189 pj_status_t (*init)( pj_codec *codec, pj_pool_t *pool ); 190 191 /** Close and shutdown codec. 192 */ 193 pj_status_t (*open)( pj_codec *codec, pj_codec_attr *attr ); 194 195 /** Close and shutdown codec. 196 */ 197 pj_status_t (*close)( pj_codec *codec ); 198 199 /** Encode frame. 200 */ 201 pj_status_t (*encode)( pj_codec *codec, const struct pj_audio_frame *input, 202 unsigned output_buf_len, struct pj_audio_frame *output); 203 204 /** Decode frame. 205 */ 206 pj_status_t (*decode)( pj_codec *codec, const struct pj_audio_frame *input, 207 unsigned output_buf_len, struct pj_audio_frame *output); 208 209 } pj_codec_op; 210 211 /** 212 * A codec describes an instance to encode or decode media frames. 213 */ 214 struct pj_codec 40 41 /** 42 * Standard RTP static payload types, as defined by RFC 3551. 43 */ 44 enum pjmedia_rtp_pt 45 { 46 PJMEDIA_RTP_PT_PCMU = 0, /* audio PCMU */ 47 PJMEDIA_RTP_PT_GSM = 3, /* audio GSM */ 48 PJMEDIA_RTP_PT_G723 = 4, /* audio G723 */ 49 PJMEDIA_RTP_PT_DVI4_8K = 5, /* audio DVI4 8KHz */ 50 PJMEDIA_RTP_PT_DVI4_16K = 6, /* audio DVI4 16Khz */ 51 PJMEDIA_RTP_PT_LPC = 7, /* audio LPC */ 52 PJMEDIA_RTP_PT_PCMA = 8, /* audio PCMA */ 53 PJMEDIA_RTP_PT_G722 = 9, /* audio G722 */ 54 PJMEDIA_RTP_PT_L16_2 = 10, /* audio 16bit linear 44.1KHz stereo */ 55 PJMEDIA_RTP_PT_L16_1 = 11, /* audio 16bit linear 44.1KHz mono */ 56 PJMEDIA_RTP_PT_QCELP = 12, /* audio QCELP */ 57 PJMEDIA_RTP_PT_CN = 13, /* audio Comfort Noise */ 58 PJMEDIA_RTP_PT_MPA = 14, /* audio MPEG1/MPEG2 elementary streams */ 59 PJMEDIA_RTP_PT_G728 = 15, /* audio G728 */ 60 PJMEDIA_RTP_PT_DVI4_11K = 16, /* audio DVI4 11.025KHz mono */ 61 PJMEDIA_RTP_PT_DVI4_22K = 17, /* audio DVI4 22.050KHz mono */ 62 PJMEDIA_RTP_PT_G729 = 18, /* audio G729 */ 63 64 PJMEDIA_RTP_PT_CELB = 25, /* video/comb Cell-B by Sun (RFC 2029) */ 65 PJMEDIA_RTP_PT_JPEG = 26, /* video JPEG */ 66 PJMEDIA_RTP_PT_NV = 28, /* video NV by nv program by Xerox */ 67 PJMEDIA_RTP_PT_H261 = 31, /* video H261 */ 68 PJMEDIA_RTP_PT_MPV = 32, /* video MPEG1 or MPEG2 elementary */ 69 PJMEDIA_RTP_PT_MP2T = 33, /* video MPEG2 transport */ 70 PJMEDIA_RTP_PT_H263 = 34, /* video H263 */ 71 72 PJMEDIA_RTP_PT_DYNAMIC = 96, /* start of dynamic RTP payload */ 73 74 }; 75 76 77 /** 78 * Identification used to search for codec factory that supports specific 79 * codec specification. 80 */ 81 struct pjmedia_codec_info 82 { 83 pjmedia_type type; /**< Media type. */ 84 unsigned pt; /**< Payload type (can be dynamic). */ 85 pj_str_t encoding_name; /**< Encoding name. */ 86 unsigned sample_rate; /**< Sampling rate. */ 87 }; 88 89 90 /** 91 * Detailed codec attributes used both to configure a codec and to query 92 * the capability of codec factories. 93 */ 94 struct pjmedia_codec_param 95 { 96 pj_uint32_t sample_rate; /**< Sampling rate in Hz */ 97 pj_uint32_t avg_bps; /**< Average bandwidth in bits/sec */ 98 99 pj_uint8_t pcm_bits_per_sample;/**< Bits/sample in the PCM side */ 100 pj_uint16_t ptime; /**< Packet time in miliseconds */ 101 102 unsigned pt:8; /**< Payload type. */ 103 unsigned vad_enabled:1; /**< Voice Activity Detector. */ 104 unsigned cng_enabled:1; /**< Comfort Noise Generator. */ 105 unsigned lpf_enabled:1; /**< Low pass filter */ 106 unsigned hpf_enabled:1; /**< High pass filter */ 107 unsigned penh_enabled:1; /**< Perceptual Enhancement */ 108 unsigned concl_enabled:1; /**< Packet loss concealment */ 109 unsigned reserved_bit:1; /**< Reserved, must be NULL. */ 110 111 }; 112 113 114 /** 115 * Types of media frame. 116 */ 117 enum pjmedia_frame_type 118 { 119 PJMEDIA_FRAME_TYPE_SILENCE_AUDIO, /**< Silence audio frame. */ 120 PJMEDIA_FRAME_TYPE_AUDIO, /**< Normal audio frame. */ 121 122 }; 123 124 /** 125 * This structure describes a media frame. 126 */ 127 struct pjmedia_frame 128 { 129 pjmedia_frame_type type; /**< Frame type. */ 130 void *buf; /**< Pointer to buffer. */ 131 pj_size_t size; /**< Frame size in bytes. */ 132 }; 133 134 /** 135 * This structure describes codec operations. Each codec MUST implement 136 * all of these functions. 137 */ 138 struct pjmedia_codec_op 139 { 140 /** 141 * Get default attributes for this codec. 142 * 143 * @param codec The codec instance. 144 * @param attr Pointer to receive default codec attributes. 145 * 146 * @return PJ_SUCCESS on success. 147 */ 148 pj_status_t (*default_attr)(pjmedia_codec *codec, 149 pjmedia_codec_param *attr); 150 151 /** 152 * Initialize codec using the specified attribute. 153 * 154 * @param codec The codec instance. 155 * @param pool Pool to use when the codec needs to allocate 156 * some memory. 157 * 158 * @return PJ_SUCCESS on success. 159 */ 160 pj_status_t (*init)(pjmedia_codec *codec, 161 pj_pool_t *pool ); 162 163 /** 164 * Open the codec and initialize with the specified parameter.. 165 * 166 * @param codec The codec instance. 167 * @param param Codec initialization parameter. 168 * 169 * @return PJ_SUCCESS on success. 170 */ 171 pj_status_t (*open)(pjmedia_codec *codec, 172 pjmedia_codec_param *param ); 173 174 /** 175 * Close and shutdown codec, releasing all resources allocated by 176 * this codec, if any. 177 * 178 * @param codec The codec instance. 179 * 180 * @return PJ_SUCCESS on success. 181 */ 182 pj_status_t (*close)(pjmedia_codec *codec); 183 184 185 /** 186 * Instruct the codec to encode the specified input frame. 187 * 188 * @param codec The codec instance. 189 * @param input The input frame. 190 * @param out_size The length of buffer in the output frame. 191 * @param output The output frame. 192 * 193 * @return PJ_SUCCESS on success; 194 */ 195 pj_status_t (*encode)(pjmedia_codec *codec, 196 const struct pjmedia_frame *input, 197 unsigned out_size, 198 struct pjmedia_frame *output); 199 200 /** 201 * Instruct the codec to decode the specified input frame. 202 * 203 * @param codec The codec instance. 204 * @param input The input frame. 205 * @param out_size The length of buffer in the output frame. 206 * @param output The output frame. 207 * 208 * @return PJ_SUCCESS on success; 209 */ 210 pj_status_t (*decode)(pjmedia_codec *codec, 211 const struct pjmedia_frame *input, 212 unsigned out_size, 213 struct pjmedia_frame *output); 214 215 }; 216 217 218 /** 219 * This structure describes a codec instance. 220 */ 221 struct pjmedia_codec 215 222 { 216 223 /** Entries to put this codec instance in codec factory's list. */ 217 PJ_DECL_LIST_MEMBER(struct pj _codec);224 PJ_DECL_LIST_MEMBER(struct pjmedia_codec); 218 225 219 226 /** Codec's private data. */ … … 221 228 222 229 /** Codec factory where this codec was allocated. */ 223 pj _codec_factory *factory;230 pjmedia_codec_factory *factory; 224 231 225 232 /** Operations to codec. */ 226 pj_codec_op *op; 227 }; 228 229 /** 230 * This structure describes operations that must be supported by codec factories. 231 */ 232 typedef struct pj_codec_factory_op 233 { 234 /** Check whether the factory can create codec with the specified ID. 235 * @param factory The codec factory. 236 * @param id The codec ID. 237 * @return zero it matches. 238 */ 239 pj_status_t (*match_id)( pj_codec_factory *factory, const pj_codec_id *id ); 240 241 /** Create default attributes for the specified codec ID. This function can 242 * be called by application to get the capability of the codec. 243 * @param factory The codec factory. 244 * @param id The codec ID. 245 * @param attr The attribute to be initialized. 246 * @return zero if success. 247 */ 248 pj_status_t (*default_attr)( pj_codec_factory *factory, const pj_codec_id *id, 249 pj_codec_attr *attr ); 250 251 /** Enumerate supported codecs. 252 * @param factory The codec factory. 253 * @param count Number of entries in the array. 254 * @param codecs The codec array. 255 * @return the total number of supported codecs, which can be less or 256 * greater than requested. 257 */ 258 unsigned (*enum_codecs) (pj_codec_factory *factory, unsigned count, pj_codec_id codecs[]); 259 260 /** This function is called by codec manager to instantiate one codec 261 * instance. 262 * @param factory The codec factory. 263 * @param id The codec ID. 264 * @return the instance of the codec, or NULL if codec can not be created. 265 */ 266 pj_codec* (*alloc_codec)( pj_codec_factory *factory, const pj_codec_id *id); 267 268 /** This function is called by codec manager to return a particular instance 269 * of codec back to the codec factory. 270 * @param factory The codec factory. 271 * @param codec The codec instance to be returned. 272 */ 273 void (*dealloc_codec)( pj_codec_factory *factory, pj_codec *codec ); 274 275 } pj_codec_factory_op; 233 pjmedia_codec_op *op; 234 }; 235 236 237 /** 238 * This structure describes operations that must be supported by codec 239 * factories. 240 */ 241 struct pjmedia_codec_factory_op 242 { 243 /** 244 * Check whether the factory can create codec with the specified 245 * codec info. 246 * 247 * @param factory The codec factory. 248 * @param info The codec info. 249 * 250 * @return PJ_SUCCESS if this factory is able to create an 251 * instance of codec with the specified info. 252 */ 253 pj_status_t (*test_alloc)(pjmedia_codec_factory *factory, 254 const pjmedia_codec_info *info ); 255 256 /** 257 * Create default attributes for the specified codec ID. This function 258 * can be called by application to get the capability of the codec. 259 * 260 * @param factory The codec factory. 261 * @param info The codec info. 262 * @param attr The attribute to be initialized. 263 * 264 * @return PJ_SUCCESS if success. 265 */ 266 pj_status_t (*default_attr)(pjmedia_codec_factory *factory, 267 const pjmedia_codec_info *info, 268 pjmedia_codec_param *attr ); 269 270 /** 271 * Enumerate supported codecs that can be created using this factory. 272 * 273 * @param factory The codec factory. 274 * @param count On input, specifies the number of elements in 275 * the array. On output, the value will be set to 276 * the number of elements that have been initialized 277 * by this function. 278 * @param info The codec info array, which contents will be 279 * initialized upon return. 280 * 281 * @return PJ_SUCCESS on success. 282 */ 283 pj_status_t (*enum_info)(pjmedia_codec_factory *factory, 284 unsigned *count, 285 pjmedia_codec_info codecs[]); 286 287 /** 288 * Create one instance of the codec with the specified codec info. 289 * 290 * @param factory The codec factory. 291 * @param info The codec info. 292 * @param p_codec Pointer to receive the codec instance. 293 * 294 * @return PJ_SUCCESS on success. 295 */ 296 pj_status_t (*alloc_codec)(pjmedia_codec_factory *factory, 297 const pjmedia_codec_info *info, 298 pjmedia_codec **p_codec); 299 300 /** 301 * This function is called by codec manager to return a particular 302 * instance of codec back to the codec factory. 303 * 304 * @param factory The codec factory. 305 * @param codec The codec instance to be returned. 306 * 307 * @return PJ_SUCCESS on success. 308 */ 309 pj_status_t (*dealloc_codec)(pjmedia_codec_factory *factory, 310 pjmedia_codec *codec ); 311 312 }; 313 276 314 277 315 /** … … 280 318 * instances of codec. 281 319 */ 282 struct pj _codec_factory320 struct pjmedia_codec_factory 283 321 { 284 322 /** Entries to put this structure in the codec manager list. */ 285 PJ_DECL_LIST_MEMBER(struct pj _codec_factory);323 PJ_DECL_LIST_MEMBER(struct pjmedia_codec_factory); 286 324 287 325 /** The factory's private data. */ 288 void *factory_data;326 void *factory_data; 289 327 290 328 /** Operations to the factory. */ 291 pj _codec_factory_op *op;329 pjmedia_codec_factory_op *op; 292 330 293 331 }; … … 296 334 * Declare maximum codecs 297 335 */ 298 #define PJ _CODEC_MGR_MAX_CODECS 32336 #define PJMEDIA_CODEC_MGR_MAX_CODECS 32 299 337 300 338 /** 301 339 * Codec manager maintains codec factory etc. 302 340 */ 303 typedef struct pj_codec_mgr 304 { 305 pj_codec_factory factory_list; 306 unsigned codec_cnt; 307 pj_codec_id codecs[PJ_CODEC_MGR_MAX_CODECS]; 308 } pj_codec_mgr; 309 310 /** 311 * Init codec manager. 341 typedef struct pjmedia_codec_mgr 342 { 343 pjmedia_codec_factory factory_list; 344 unsigned codec_cnt; 345 pjmedia_codec_info codecs[PJMEDIA_CODEC_MGR_MAX_CODECS]; 346 } pjmedia_codec_mgr; 347 348 349 350 /** 351 * Initialize codec manager. 352 * 353 * @param mgr Codec manager instance. 354 * 355 * @return PJ_SUCCESS on success. 356 */ 357 PJ_DECL(pj_status_t) pjmedia_codec_mgr_init(pjmedia_codec_mgr *mgr); 358 359 360 /** 361 * Register codec factory to codec manager. 362 * 363 * @param mgr The codec manager. 364 * @param factory The codec factory to be registered. 365 * 366 * @return PJ_SUCCESS on success. 312 367 */ 313 368 PJ_DECL(pj_status_t) 314 pj_codec_mgr_init (pj_codec_mgr *mgr); 315 316 /** 317 * Register codec to codec manager. 369 pjmedia_codec_mgr_register_factory( pjmedia_codec_mgr *mgr, 370 pjmedia_codec_factory *factory); 371 372 /** 373 * Unregister codec factory from the codec manager. 374 * 375 * @param mgr The codec manager. 376 * @param factory The codec factory to be unregistered. 377 * 378 * @return PJ_SUCCESS on success. 318 379 */ 319 380 PJ_DECL(pj_status_t) 320 pj_codec_mgr_register_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); 321 322 /** 323 * Unregister codec. 324 */ 325 PJ_DECL(void) 326 pj_codec_mgr_unregister_factory (pj_codec_mgr *mgr, pj_codec_factory *factory); 327 328 /** 329 * Enumerate codecs. 330 */ 331 PJ_DECL(unsigned) 332 pj_codec_mgr_enum_codecs (pj_codec_mgr *mgr, unsigned count, const pj_codec_id *codecs[]); 333 334 /** 335 * Open codec. 336 */ 337 PJ_DECL(pj_codec*) 338 pj_codec_mgr_alloc_codec (pj_codec_mgr *mgr, const struct pj_codec_id *id); 339 340 /** 341 * Close codec. 342 */ 343 PJ_DECL(void) 344 pj_codec_mgr_dealloc_codec (pj_codec_mgr *mgr, pj_codec *codec); 381 pjmedia_codec_mgr_unregister_factory( pjmedia_codec_mgr *mgr, 382 pjmedia_codec_factory *factory); 383 384 /** 385 * Enumerate all supported codec. 386 * 387 * @param mgr The codec manager. 388 * @param count On input, specifies the number of elements in 389 * the array. On output, the value will be set to 390 * the number of elements that have been initialized 391 * by this function. 392 * @param info The codec info array, which contents will be 393 * initialized upon return. 394 * 395 * @return PJ_SUCCESS on success. 396 */ 397 PJ_DECL(pj_status_t) pjmedia_codec_mgr_enum_codecs( pjmedia_codec_mgr *mgr, 398 unsigned *count, 399 pjmedia_codec_info info[]); 400 401 /** 402 * Request the codec manager to allocate one instance of codec with the 403 * specified codec info. The codec will enumerate all codec factories 404 * until it finds factory that is able to create the specified codec. 405 * 406 * @param mgr The codec manager. 407 * @param info The information about the codec to be created. 408 * @param p_codec Pointer to receive the codec instance. 409 * 410 * @return PJ_SUCCESS on success. 411 */ 412 PJ_DECL(pj_status_t) pjmedia_codec_mgr_alloc_codec(pjmedia_codec_mgr *mgr, 413 const pjmedia_codec_info *info, 414 pjmedia_codec **p_codec); 415 416 /** 417 * Deallocate the specified codec instance. The codec manager will return 418 * the instance of the codec back to its factory. 419 * 420 * @param mgr The codec manager. 421 * @param codec The codec instance. 422 * 423 * @return PJ_SUCESS on success. 424 */ 425 PJ_DECL(pj_status_t) pjmedia_codec_mgr_dealloc_codec(pjmedia_codec_mgr *mgr, 426 pjmedia_codec *codec); 345 427 346 428 /**
Note: See TracChangeset
for help on using the changeset viewer.