Changeset 2506 for pjproject/trunk/pjmedia/include/pjmedia/types.h
- Timestamp:
- Mar 12, 2009 6:11:37 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk
-
Property
svn:mergeinfo
set to
False
/pjproject/branches/projects/aps-direct merged eligible
-
Property
svn:mergeinfo
set to
False
-
pjproject/trunk/pjmedia/include/pjmedia/types.h
r2394 r2506 48 48 */ 49 49 50 /** 51 * Top most media type. 50 /** 51 * Top most media type. 52 52 */ 53 53 typedef enum pjmedia_type … … 62 62 PJMEDIA_TYPE_VIDEO = 2, 63 63 64 /** Unknown media type, in this case the name will be specified in 64 /** Unknown media type, in this case the name will be specified in 65 65 * encoding_name. 66 66 */ … … 73 73 74 74 75 /** 76 * Media transport protocol. 75 /** 76 * Media transport protocol. 77 77 */ 78 78 typedef enum pjmedia_tp_proto … … 93 93 94 94 95 /** 96 * Media direction. 95 /** 96 * Media direction. 97 97 */ 98 98 typedef enum pjmedia_dir … … 139 139 140 140 141 /** 142 * Opa gue declaration of media endpoint.141 /** 142 * Opaque declaration of media endpoint. 143 143 */ 144 144 typedef struct pjmedia_endpt pjmedia_endpt; … … 151 151 152 152 153 /** 153 /** 154 154 * Media socket info is used to describe the underlying sockets 155 155 * to be used as media transport. … … 181 181 182 182 /** 183 * Macro for packing format. 184 */ 185 #define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 ) 186 187 /** 188 * This enumeration describes format ID. 189 */ 190 typedef enum pjmedia_format_id 191 { 192 /** 193 * 16bit linear 194 */ 195 PJMEDIA_FORMAT_L16 = 0, 196 197 /** 198 * Alias for PJMEDIA_FORMAT_L16 199 */ 200 PJMEDIA_FORMAT_PCM = PJMEDIA_FORMAT_L16, 201 202 /** 203 * G.711 ALAW 204 */ 205 PJMEDIA_FORMAT_PCMA = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'), 206 207 /** 208 * Alias for PJMEDIA_FORMAT_PCMA 209 */ 210 PJMEDIA_FORMAT_ALAW = PJMEDIA_FORMAT_PCMA, 211 212 /** 213 * G.711 ULAW 214 */ 215 PJMEDIA_FORMAT_PCMU = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'), 216 217 /** 218 * Aliaw for PJMEDIA_FORMAT_PCMU 219 */ 220 PJMEDIA_FORMAT_ULAW = PJMEDIA_FORMAT_PCMU, 221 222 /** 223 * AMR narrowband 224 */ 225 PJMEDIA_FORMAT_AMR = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'), 226 227 /** 228 * ITU G.729 229 */ 230 PJMEDIA_FORMAT_G729 = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'), 231 232 /** 233 * Internet Low Bit-Rate Codec (ILBC) 234 */ 235 PJMEDIA_FORMAT_ILBC = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C') 236 237 } pjmedia_format_id; 238 239 240 /** 241 * Media format information. 242 */ 243 typedef struct pjmedia_format 244 { 245 /** Format ID */ 246 pjmedia_format_id id; 247 248 /** Bitrate. */ 249 pj_uint32_t bitrate; 250 251 /** Flag to indicate whether VAD is enabled */ 252 pj_bool_t vad; 253 254 } pjmedia_format; 255 256 257 258 /** 183 259 * This is a general purpose function set PCM samples to zero. 184 * Since this function is needed by many parts of the library, 260 * Since this function is needed by many parts of the library, 185 261 * by putting this functionality in one place, it enables some. 186 262 * clever people to optimize this function. … … 206 282 /** 207 283 * This is a general purpose function to copy samples from/to buffers with 208 * equal size. Since this function is needed by many parts of the library, 284 * equal size. Since this function is needed by many parts of the library, 209 285 * by putting this functionality in one place, it enables some. 210 286 * clever people to optimize this function. … … 221 297 unsigned i; 222 298 count >>= 1; 223 for (i=0; i<count; ++i) 299 for (i=0; i<count; ++i) 224 300 ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 225 301 #endif … … 229 305 /** 230 306 * This is a general purpose function to copy samples from/to buffers with 231 * equal size. Since this function is needed by many parts of the library, 307 * equal size. Since this function is needed by many parts of the library, 232 308 * by putting this functionality in one place, it enables some. 233 309 * clever people to optimize this function. … … 244 320 unsigned i; 245 321 count >>= 1; 246 for (i=0; i<count; ++i) 322 for (i=0; i<count; ++i) 247 323 ((pj_int32_t*)dst)[i] = ((pj_int32_t*)src)[i]; 248 324 #endif 249 325 } 250 326 327 /** 328 * Types of media frame. 329 */ 330 typedef enum pjmedia_frame_type 331 { 332 PJMEDIA_FRAME_TYPE_NONE, /**< No frame. */ 333 PJMEDIA_FRAME_TYPE_AUDIO, /**< Normal audio frame. */ 334 PJMEDIA_FRAME_TYPE_EXTENDED /**< Extended audio frame. */ 335 336 } pjmedia_frame_type; 337 338 339 /** 340 * This structure describes a media frame. 341 */ 342 typedef struct pjmedia_frame 343 { 344 pjmedia_frame_type type; /**< Frame type. */ 345 void *buf; /**< Pointer to buffer. */ 346 pj_size_t size; /**< Frame size in bytes. */ 347 pj_timestamp timestamp; /**< Frame timestamp. */ 348 pj_uint32_t bit_info; /**< Bit info of the frame, sample case: 349 a frame may not exactly start and end 350 at the octet boundary, so this field 351 may be used for specifying start & 352 end bit offset. */ 353 } pjmedia_frame; 354 355 356 /** 357 * The pjmedia_frame_ext is used to carry a more complex audio frames than 358 * the typical PCM audio frames, and it is signaled by setting the "type" 359 * field of a pjmedia_frame to PJMEDIA_FRAME_TYPE_EXTENDED. With this set, 360 * application may typecast pjmedia_frame to pjmedia_frame_ext. 361 * 362 * This structure may contain more than one audio frames, which subsequently 363 * will be called subframes in this structure. The subframes section 364 * immediately follows the end of this structure, and each subframe is 365 * represented by pjmedia_frame_ext_subframe structure. Every next 366 * subframe immediately follows the previous subframe, and all subframes 367 * are byte-aligned although its payload may not be byte-aligned. 368 */ 369 370 #pragma pack(1) 371 typedef struct pjmedia_frame_ext { 372 pjmedia_frame base; /**< Base frame info */ 373 pj_uint16_t samples_cnt; /**< Number of samples in this frame */ 374 pj_uint16_t subframe_cnt; /**< Number of (sub)frames in this frame */ 375 376 /* Zero or more (sub)frames follows immediately after this, 377 * each will be represented by pjmedia_frame_ext_subframe 378 */ 379 } pjmedia_frame_ext; 380 #pragma pack() 381 382 /** 383 * This structure represents the individual subframes in the 384 * pjmedia_frame_ext structure. 385 */ 386 #pragma pack(1) 387 typedef struct pjmedia_frame_ext_subframe { 388 pj_uint16_t bitlen; /**< Number of bits in the data */ 389 pj_uint8_t data[1]; /**< Start of encoded data */ 390 } pjmedia_frame_ext_subframe; 391 392 #pragma pack() 393 394 395 /** 396 * Append one subframe to #pjmedia_frame_ext. 397 * 398 * @param frm The #pjmedia_frame_ext. 399 * @param src Subframe data. 400 * @param bitlen Lenght of subframe, in bits. 401 * @param samples_cnt Number of audio samples in subframe. 402 */ 403 PJ_INLINE(void) pjmedia_frame_ext_append_subframe(pjmedia_frame_ext *frm, 404 const void *src, 405 unsigned bitlen, 406 unsigned samples_cnt) 407 { 408 pjmedia_frame_ext_subframe *fsub; 409 pj_uint8_t *p; 410 unsigned i; 411 412 p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 413 for (i = 0; i < frm->subframe_cnt; ++i) { 414 fsub = (pjmedia_frame_ext_subframe*) p; 415 p += sizeof(fsub->bitlen) + ((fsub->bitlen+7) >> 3); 416 } 417 418 fsub = (pjmedia_frame_ext_subframe*) p; 419 fsub->bitlen = (pj_uint16_t)bitlen; 420 if (bitlen) 421 pj_memcpy(fsub->data, src, (bitlen+7) >> 3); 422 423 frm->subframe_cnt++; 424 frm->samples_cnt = (pj_uint16_t)(frm->samples_cnt + samples_cnt); 425 } 426 427 /** 428 * Get a subframe from #pjmedia_frame_ext. 429 * 430 * @param frm The #pjmedia_frame_ext. 431 * @param n Subframe index, zero based. 432 * 433 * @return The n-th subframe, or NULL if n is out-of-range. 434 */ 435 PJ_INLINE(pjmedia_frame_ext_subframe*) 436 pjmedia_frame_ext_get_subframe(const pjmedia_frame_ext *frm, unsigned n) 437 { 438 pjmedia_frame_ext_subframe *sf = NULL; 439 440 if (n < frm->subframe_cnt) { 441 pj_uint8_t *p; 442 unsigned i; 443 444 p = (pj_uint8_t*)frm + sizeof(pjmedia_frame_ext); 445 for (i = 0; i < n; ++i) { 446 sf = (pjmedia_frame_ext_subframe*) p; 447 p += sizeof(sf->bitlen) + ((sf->bitlen+7) >> 3); 448 } 449 450 sf = (pjmedia_frame_ext_subframe*) p; 451 } 452 453 return sf; 454 } 455 456 /** 457 * Extract all frame payload to the specified buffer. 458 * 459 * @param frm The frame. 460 * @param dst Destination buffer. 461 * @param maxsize Maximum size to copy (i.e. the size of the 462 * destination buffer). 463 * 464 * @return Total size of payload copied. 465 */ 466 PJ_INLINE(unsigned) 467 pjmedia_frame_ext_copy_payload(const pjmedia_frame_ext *frm, 468 void *dst, 469 unsigned maxlen) 470 { 471 unsigned i, copied=0; 472 for (i=0; i<frm->subframe_cnt; ++i) { 473 pjmedia_frame_ext_subframe *sf; 474 unsigned sz; 475 476 sf = pjmedia_frame_ext_get_subframe(frm, i); 477 if (!sf) 478 continue; 479 480 sz = ((sf->bitlen + 7) >> 3); 481 if (sz + copied > maxlen) 482 break; 483 484 pj_memcpy(((pj_uint8_t*)dst) + copied, sf->data, sz); 485 copied += sz; 486 } 487 return copied; 488 } 489 490 491 /** 492 * Pop out first n subframes from #pjmedia_frame_ext. 493 * 494 * @param frm The #pjmedia_frame_ext. 495 * @param n Number of first subframes to be popped out. 496 * 497 * @return PJ_SUCCESS when successful. 498 */ 499 PJ_INLINE(pj_status_t) 500 pjmedia_frame_ext_pop_subframes(pjmedia_frame_ext *frm, unsigned n) 501 { 502 pjmedia_frame_ext_subframe *sf; 503 pj_uint8_t *move_src; 504 unsigned move_len; 505 506 if (frm->subframe_cnt <= n) { 507 frm->subframe_cnt = 0; 508 frm->samples_cnt = 0; 509 return PJ_SUCCESS; 510 } 511 512 move_src = (pj_uint8_t*)pjmedia_frame_ext_get_subframe(frm, n); 513 sf = pjmedia_frame_ext_get_subframe(frm, frm->subframe_cnt-1); 514 move_len = (pj_uint8_t*)sf - move_src + sizeof(sf->bitlen) + 515 ((sf->bitlen+7) >> 3); 516 pj_memmove((pj_uint8_t*)frm+sizeof(pjmedia_frame_ext), 517 move_src, move_len); 518 519 frm->samples_cnt = (pj_uint16_t) 520 (frm->samples_cnt - n*frm->samples_cnt/frm->subframe_cnt); 521 frm->subframe_cnt = (pj_uint16_t) (frm->subframe_cnt - n); 522 523 return PJ_SUCCESS; 524 } 525 526 251 527 /** 252 528 * @}
Note: See TracChangeset
for help on using the changeset viewer.