Changeset 281 for pjproject/trunk
- Timestamp:
- Mar 5, 2006 11:50:53 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-codec/gsm.c
r205 r281 98 98 99 99 /* GSM codec private data. */ 100 struct gsm_private 101 { 102 int dummy; 100 struct gsm_data 101 { 102 void *encoder; 103 void *decoder; 103 104 }; 104 105 … … 267 268 { 268 269 pjmedia_codec *codec; 270 struct gsm_data *gsm_data; 269 271 270 272 PJ_ASSERT_RETURN(factory && id && p_codec, PJ_EINVAL); … … 284 286 codec->op = &gsm_op; 285 287 codec->factory = factory; 288 289 gsm_data = pj_pool_zalloc(gsm_codec_factory.pool, 290 sizeof(struct gsm_data)); 291 codec->codec_data = gsm_data; 286 292 } 287 293 288 294 pj_mutex_unlock(gsm_codec_factory.mutex); 289 290 pj_assert(codec->codec_data == NULL);291 295 292 296 *p_codec = codec; … … 300 304 pjmedia_codec *codec ) 301 305 { 306 struct gsm_data *gsm_data; 307 302 308 PJ_ASSERT_RETURN(factory && codec, PJ_EINVAL); 303 309 PJ_ASSERT_RETURN(factory == &gsm_codec_factory.base, PJ_EINVAL); 304 310 311 gsm_data = codec->codec_data; 312 305 313 /* Close codec, if it's not closed. */ 306 if (codec->codec_data != NULL) { 307 gsm_destroy(codec->codec_data); 308 codec->codec_data = NULL; 309 } 314 gsm_codec_close(codec); 310 315 311 316 /* Put in the free list. */ … … 343 348 pjmedia_codec_param *attr ) 344 349 { 345 pj_assert(codec->codec_data == NULL); 350 struct gsm_data *gsm_data = codec->codec_data; 351 352 pj_assert(gsm_data != NULL); 353 pj_assert(gsm_data->encoder == NULL && gsm_data->decoder == NULL); 346 354 347 355 PJ_UNUSED_ARG(attr); 348 356 349 codec->codec_data= gsm_create();350 if (! codec->codec_data)357 gsm_data->encoder = gsm_create(); 358 if (!gsm_data->encoder) 351 359 return PJMEDIA_CODEC_EFAILED; 352 360 361 gsm_data->decoder = gsm_create(); 362 if (!gsm_data->decoder) 363 return PJMEDIA_CODEC_EFAILED; 364 353 365 return PJ_SUCCESS; 354 366 } … … 359 371 static pj_status_t gsm_codec_close( pjmedia_codec *codec ) 360 372 { 361 pj_assert(codec->codec_data != NULL); 362 363 if (codec->codec_data) { 364 gsm_destroy(codec->codec_data); 365 codec->codec_data = NULL; 373 struct gsm_data *gsm_data = codec->codec_data; 374 375 pj_assert(gsm_data != NULL); 376 377 if (gsm_data->encoder) { 378 gsm_destroy(gsm_data->encoder); 379 gsm_data->encoder = NULL; 380 } 381 if (gsm_data->decoder) { 382 gsm_destroy(gsm_data->decoder); 383 gsm_data->decoder = NULL; 366 384 } 367 385 … … 408 426 struct pjmedia_frame *output) 409 427 { 410 PJ_ASSERT_RETURN(codec && codec->codec_data && input && output, 411 PJ_EINVAL); 428 struct gsm_data *gsm_data = codec->codec_data; 429 430 pj_assert(gsm_data != NULL); 431 PJ_ASSERT_RETURN(input && output, PJ_EINVAL); 412 432 413 433 if (output_buf_len < 33) … … 417 437 return PJMEDIA_CODEC_EPCMTOOSHORT; 418 438 419 gsm_encode( codec->codec_data, (short*)input->buf,439 gsm_encode(gsm_data->encoder, (short*)input->buf, 420 440 (unsigned char*)output->buf); 421 441 … … 434 454 struct pjmedia_frame *output) 435 455 { 436 PJ_ASSERT_RETURN(codec && codec->codec_data && input && output, 437 PJ_EINVAL); 456 struct gsm_data *gsm_data = codec->codec_data; 457 458 pj_assert(gsm_data != NULL); 459 PJ_ASSERT_RETURN(input && output, PJ_EINVAL); 438 460 439 461 if (output_buf_len < 320) … … 443 465 return PJMEDIA_CODEC_EFRMTOOSHORT; 444 466 445 gsm_decode( codec->codec_data,467 gsm_decode(gsm_data->decoder, 446 468 (unsigned char*)input->buf, 447 469 (short*)output->buf);
Note: See TracChangeset
for help on using the changeset viewer.