Changeset 4047 for pjproject/trunk
- Timestamp:
- Apr 13, 2012 4:59:05 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/avi_dev.c
r4034 r4047 47 47 pjmedia_port *vid; 48 48 avi_dev_strm *strm; 49 pjmedia_vid_codec *codec; 50 pj_uint8_t *enc_buf; 51 pj_size_t enc_buf_size; 49 52 }; 50 53 … … 70 73 pjmedia_vid_dev_cb vid_cb; /**< Stream callback. */ 71 74 void *user_data; /**< Application data. */ 72 pjmedia_vid_codec *codec;73 pj_uint8_t *enc_buf;74 pj_size_t enc_buf_size;75 75 }; 76 76 … … 273 273 } 274 274 275 if (adi->codec) { 276 pjmedia_vid_codec_close(adi->codec); 277 adi->codec = NULL; 278 } 279 275 280 if (adi->pool) 276 281 pj_pool_release(adi->pool); … … 361 366 unsigned local_idx; 362 367 struct avi_dev_info *adi = NULL; 368 pjmedia_format avi_fmt; 369 const pjmedia_video_format_info *vfi; 363 370 pj_status_t status; 364 371 … … 410 417 adi->fpath.ptr)); 411 418 goto on_error; 419 } 420 421 pjmedia_format_copy(&avi_fmt, &adi->vid->info.fmt); 422 vfi = pjmedia_get_video_format_info(NULL, avi_fmt.id); 423 /* Check whether the frame is encoded. */ 424 if (!vfi || vfi->bpp == 0) { 425 /* Yes, prepare codec */ 426 const pjmedia_vid_codec_info *codec_info; 427 pjmedia_vid_codec_param codec_param; 428 pjmedia_video_apply_fmt_param vafp; 429 430 /* Lookup codec */ 431 status = pjmedia_vid_codec_mgr_get_codec_info2(NULL, 432 avi_fmt.id, 433 &codec_info); 434 if (status != PJ_SUCCESS || !codec_info) 435 goto on_error; 436 437 status = pjmedia_vid_codec_mgr_get_default_param(NULL, codec_info, 438 &codec_param); 439 if (status != PJ_SUCCESS) 440 goto on_error; 441 442 /* Open codec */ 443 status = pjmedia_vid_codec_mgr_alloc_codec(NULL, codec_info, 444 &adi->codec); 445 if (status != PJ_SUCCESS) 446 goto on_error; 447 448 status = pjmedia_vid_codec_init(adi->codec, adi->pool); 449 if (status != PJ_SUCCESS) 450 goto on_error; 451 452 codec_param.dir = PJMEDIA_DIR_DECODING; 453 codec_param.packing = PJMEDIA_VID_PACKING_WHOLE; 454 status = pjmedia_vid_codec_open(adi->codec, &codec_param); 455 if (status != PJ_SUCCESS) 456 goto on_error; 457 458 /* Allocate buffer */ 459 avi_fmt.id = codec_info->dec_fmt_id[0]; 460 vfi = pjmedia_get_video_format_info(NULL, avi_fmt.id); 461 pj_bzero(&vafp, sizeof(vafp)); 462 vafp.size = avi_fmt.det.vid.size; 463 status = vfi->apply_fmt(vfi, &vafp); 464 if (status != PJ_SUCCESS) 465 goto on_error; 466 467 adi->enc_buf = pj_pool_alloc(adi->pool, vafp.framebytes); 468 adi->enc_buf_size = vafp.framebytes; 412 469 } 413 470 … … 437 494 adi->info.caps = PJMEDIA_VID_DEV_CAP_FORMAT; 438 495 adi->info.fmt_cnt = 1; 439 pjmedia_format_copy(&adi->info.fmt[0], &a di->vid->info.fmt);496 pjmedia_format_copy(&adi->info.fmt[0], &avi_fmt); 440 497 441 498 /* Set out vars */ … … 449 506 450 507 on_error: 508 if (adi->codec) { 509 pjmedia_vid_codec_close(adi->codec); 510 adi->codec = NULL; 511 } 451 512 if (adi->pool) { 452 513 pj_pool_release(adi->pool); … … 470 531 struct avi_dev_info *adi; 471 532 struct avi_dev_strm *strm; 472 pjmedia_format avi_fmt;473 const pjmedia_video_format_info *vfi;474 pj_status_t status = PJ_SUCCESS;475 533 476 534 PJ_ASSERT_RETURN(f && param && p_vid_strm, PJ_EINVAL); … … 498 556 strm->adi = adi; 499 557 500 pjmedia_format_copy(&avi_fmt, &adi->vid->info.fmt); 501 vfi = pjmedia_get_video_format_info(NULL, avi_fmt.id); 502 /* Check whether the frame is encoded. */ 503 if (!vfi || vfi->bpp == 0) { 504 /* Yes, prepare codec */ 505 const pjmedia_vid_codec_info *codec_info; 506 pjmedia_vid_codec_param codec_param; 507 pjmedia_video_apply_fmt_param vafp; 508 509 /* Lookup codec */ 510 status = pjmedia_vid_codec_mgr_get_codec_info2(NULL, 511 avi_fmt.id, 512 &codec_info); 513 if (status != PJ_SUCCESS || !codec_info) 514 goto on_error; 515 516 status = pjmedia_vid_codec_mgr_get_default_param(NULL, codec_info, 517 &codec_param); 518 if (status != PJ_SUCCESS) 519 goto on_error; 520 521 /* Open codec */ 522 status = pjmedia_vid_codec_mgr_alloc_codec(NULL, codec_info, 523 &strm->codec); 524 if (status != PJ_SUCCESS) 525 goto on_error; 526 527 status = pjmedia_vid_codec_init(strm->codec, strm->pool); 528 if (status != PJ_SUCCESS) 529 goto on_error; 530 531 codec_param.dir = PJMEDIA_DIR_DECODING; 532 codec_param.packing = PJMEDIA_VID_PACKING_WHOLE; 533 status = pjmedia_vid_codec_open(strm->codec, &codec_param); 534 if (status != PJ_SUCCESS) 535 goto on_error; 536 537 /* Allocate buffer */ 538 avi_fmt.id = codec_info->dec_fmt_id[0]; 539 vfi = pjmedia_get_video_format_info(NULL, avi_fmt.id); 540 pj_bzero(&vafp, sizeof(vafp)); 541 vafp.size = avi_fmt.det.vid.size; 542 status = vfi->apply_fmt(vfi, &vafp); 543 if (status != PJ_SUCCESS) 544 goto on_error; 545 546 strm->enc_buf = pj_pool_alloc(strm->pool, vafp.framebytes); 547 strm->enc_buf_size = vafp.framebytes; 548 } 549 pjmedia_format_copy(¶m->fmt, &avi_fmt); 558 pjmedia_format_copy(¶m->fmt, &adi->info.fmt[0]); 550 559 551 560 /* Done */ … … 555 564 556 565 return PJ_SUCCESS; 557 558 on_error:559 avi_dev_strm_destroy(&strm->base);560 return status;561 566 } 562 567 … … 612 617 struct avi_dev_strm *stream = (struct avi_dev_strm*)strm; 613 618 614 if (stream-> codec) {619 if (stream->adi->codec) { 615 620 pjmedia_frame enc_frame; 616 621 pj_status_t status; 617 622 618 enc_frame.buf = stream-> enc_buf;619 enc_frame.size = stream-> enc_buf_size;623 enc_frame.buf = stream->adi->enc_buf; 624 enc_frame.size = stream->adi->enc_buf_size; 620 625 status = pjmedia_port_get_frame(stream->adi->vid, &enc_frame); 621 626 if (status != PJ_SUCCESS) 622 627 return status; 623 628 624 return pjmedia_vid_codec_decode(stream-> codec, 1, &enc_frame,629 return pjmedia_vid_codec_decode(stream->adi->codec, 1, &enc_frame, 625 630 frame->size, frame); 626 631 } else { … … 663 668 avi_dev_strm_stop(strm); 664 669 665 if (stream->codec) {666 pjmedia_vid_codec_close(stream->codec);667 stream->codec = NULL;668 }669 670 670 stream->adi->strm = NULL; 671 671 stream->adi = NULL;
Note: See TracChangeset
for help on using the changeset viewer.