Changeset 4026 for pjproject/trunk
- Timestamp:
- Apr 5, 2012 8:38:27 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/vid_port.c
r4013 r4026 57 57 pj_bool_t destroy_client_port; 58 58 59 pjmedia_converter *conv; 60 void *conv_buf; 61 pj_size_t conv_buf_size; 62 pjmedia_conversion_param conv_param; 59 struct { 60 pjmedia_converter *conv; 61 void *conv_buf; 62 pj_size_t conv_buf_size; 63 pjmedia_conversion_param conv_param; 64 unsigned usec_ctr; 65 unsigned usec_src, usec_dst; 66 } conv; 63 67 64 68 pjmedia_clock *clock; … … 126 130 static pj_status_t create_converter(pjmedia_vid_port *vp) 127 131 { 128 if (vp->conv ) {129 pjmedia_converter_destroy(vp->conv );130 vp->conv = NULL;132 if (vp->conv.conv) { 133 pjmedia_converter_destroy(vp->conv.conv); 134 vp->conv.conv = NULL; 131 135 } 132 136 133 137 /* Instantiate converter if necessary */ 134 if (vp->conv_param.src.id != vp->conv_param.dst.id || 135 vp->conv_param.src.det.vid.size.w != vp->conv_param.dst.det.vid.size.w || 136 vp->conv_param.src.det.vid.size.h != vp->conv_param.dst.det.vid.size.h) 138 if (vp->conv.conv_param.src.id != vp->conv.conv_param.dst.id || 139 (vp->conv.conv_param.src.det.vid.size.w != 140 vp->conv.conv_param.dst.det.vid.size.w) || 141 (vp->conv.conv_param.src.det.vid.size.h != 142 vp->conv.conv_param.dst.det.vid.size.h)) 137 143 { 138 144 pj_status_t status; 139 145 140 146 /* Yes, we need converter */ 141 const pjmedia_video_format_info *vfi; 142 pjmedia_video_apply_fmt_param vafp; 143 144 status = pjmedia_converter_create(NULL, vp->pool, &vp->conv_param, 145 &vp->conv); 147 status = pjmedia_converter_create(NULL, vp->pool, &vp->conv.conv_param, 148 &vp->conv.conv); 146 149 if (status != PJ_SUCCESS) { 147 150 PJ_PERROR(4,(THIS_FILE, status, "Error creating converter")); 148 151 return status; 149 152 } 153 } 154 155 if (vp->conv.conv || 156 (vp->role==ROLE_ACTIVE && (vp->dir & PJMEDIA_DIR_ENCODING))) 157 { 158 pj_status_t status; 159 const pjmedia_video_format_info *vfi; 160 pjmedia_video_apply_fmt_param vafp; 150 161 151 162 /* Allocate buffer for conversion */ 152 vfi = pjmedia_get_video_format_info(NULL, vp->conv _param.dst.id);163 vfi = pjmedia_get_video_format_info(NULL, vp->conv.conv_param.dst.id); 153 164 if (!vfi) 154 165 return PJMEDIA_EBADFMT; 155 166 156 167 pj_bzero(&vafp, sizeof(vafp)); 157 vafp.size = vp->conv _param.dst.det.vid.size;168 vafp.size = vp->conv.conv_param.dst.det.vid.size; 158 169 status = vfi->apply_fmt(vfi, &vafp); 159 170 if (status != PJ_SUCCESS) 160 171 return PJMEDIA_EBADFMT; 161 172 162 if (vafp.framebytes > vp->conv _buf_size) {163 vp->conv _buf = pj_pool_alloc(vp->pool, vafp.framebytes);164 vp->conv _buf_size = vafp.framebytes;173 if (vafp.framebytes > vp->conv.conv_buf_size) { 174 vp->conv.conv_buf = pj_pool_alloc(vp->pool, vafp.framebytes); 175 vp->conv.conv_buf_size = vafp.framebytes; 165 176 } 166 177 } 178 179 vp->conv.usec_ctr = 0; 180 vp->conv.usec_src = PJMEDIA_PTIME(&vp->conv.conv_param.src.det.vid.fps); 181 vp->conv.usec_dst = PJMEDIA_PTIME(&vp->conv.conv_param.dst.det.vid.fps); 167 182 168 183 return PJ_SUCCESS; … … 273 288 274 289 if (vp->dir & PJMEDIA_DIR_CAPTURE) { 275 pjmedia_format_copy(&vp->conv _param.src, &vparam.fmt);276 pjmedia_format_copy(&vp->conv _param.dst, &prm->vidparam.fmt);290 pjmedia_format_copy(&vp->conv.conv_param.src, &vparam.fmt); 291 pjmedia_format_copy(&vp->conv.conv_param.dst, &prm->vidparam.fmt); 277 292 } else { 278 pjmedia_format_copy(&vp->conv _param.src, &prm->vidparam.fmt);279 pjmedia_format_copy(&vp->conv _param.dst, &vparam.fmt);293 pjmedia_format_copy(&vp->conv.conv_param.src, &prm->vidparam.fmt); 294 pjmedia_format_copy(&vp->conv.conv_param.dst, &vparam.fmt); 280 295 } 281 296 … … 511 526 vp->frm_mutex = NULL; 512 527 } 513 if (vp->conv ) {514 pjmedia_converter_destroy(vp->conv );515 vp->conv = NULL;528 if (vp->conv.conv) { 529 pjmedia_converter_destroy(vp->conv.conv); 530 vp->conv.conv = NULL; 516 531 } 517 532 pj_pool_release(vp->pool); … … 577 592 578 593 /* Change the destination format to the new format */ 579 pjmedia_format_copy(&vp->conv _param.src,594 pjmedia_format_copy(&vp->conv.conv_param.src, 580 595 &event->data.fmt_changed.new_fmt); 581 596 /* Only copy the size here */ 582 vp->conv _param.dst.det.vid.size =597 vp->conv.conv_param.dst.det.vid.size = 583 598 event->data.fmt_changed.new_fmt.det.vid.size; 584 599 … … 590 605 591 606 pjmedia_vid_dev_stream_get_param(vp->strm, &vid_param); 592 if (vid_param.fmt.id != vp->conv _param.dst.id ||607 if (vid_param.fmt.id != vp->conv.conv_param.dst.id || 593 608 (vid_param.fmt.det.vid.size.h != 594 vp->conv _param.dst.det.vid.size.h) ||609 vp->conv.conv_param.dst.det.vid.size.h) || 595 610 (vid_param.fmt.det.vid.size.w != 596 vp->conv _param.dst.det.vid.size.w))611 vp->conv.conv_param.dst.det.vid.size.w)) 597 612 { 598 613 status = pjmedia_vid_dev_stream_set_cap(vp->strm, 599 614 PJMEDIA_VID_DEV_CAP_FORMAT, 600 &vp->conv _param.dst);615 &vp->conv.conv_param.dst); 601 616 if (status != PJ_SUCCESS) { 602 617 PJ_LOG(3, (THIS_FILE, "failure in changing the format of the " … … 639 654 pj_status_t status = PJ_SUCCESS; 640 655 641 if (vp->conv ) {642 dst_frame->buf = vp->conv _buf;643 dst_frame->size = vp->conv _buf_size;644 status = pjmedia_converter_convert(vp->conv ,656 if (vp->conv.conv) { 657 dst_frame->buf = vp->conv.conv_buf; 658 dst_frame->size = vp->conv.conv_buf_size; 659 status = pjmedia_converter_convert(vp->conv.conv, 645 660 src_frame, dst_frame); 646 661 } … … 651 666 /* Copy frame to buffer. */ 652 667 static void copy_frame_to_buffer(pjmedia_vid_port *vp, 653 668 pjmedia_frame *frame) 654 669 { 655 670 pj_mutex_lock(vp->frm_mutex); … … 665 680 666 681 pj_mutex_lock(vp->frm_mutex); 667 if (vp->conv )682 if (vp->conv.conv) 668 683 status = convert_frame(vp, vp->frm_buf, frame); 669 684 else … … 691 706 692 707 if (vp->stream_role == ROLE_PASSIVE) { 693 vp->frm_buf->size = vp->frm_buf_size; 694 status = pjmedia_vid_dev_stream_get_frame(vp->strm, vp->frm_buf); 708 while (vp->conv.usec_ctr < vp->conv.usec_src) { 709 vp->frm_buf->size = vp->frm_buf_size; 710 status = pjmedia_vid_dev_stream_get_frame(vp->strm, vp->frm_buf); 711 vp->conv.usec_ctr += vp->conv.usec_dst; 712 } 713 vp->conv.usec_ctr -= vp->conv.usec_src; 695 714 if (status != PJ_SUCCESS) 696 715 return; … … 699 718 //save_rgb_frame(vp->cap_size.w, vp->cap_size.h, vp->frm_buf); 700 719 701 status = convert_frame(vp, vp->frm_buf, &frame_); 720 frame_.buf = vp->conv.conv_buf; 721 frame_.size = vp->conv.conv_buf_size; 722 status = get_frame_from_buffer(vp, &frame_); 702 723 if (status != PJ_SUCCESS) 703 724 return; 704 725 705 status = pjmedia_port_put_frame(vp->client_port, 706 (vp->conv? &frame_: vp->frm_buf)); 726 status = pjmedia_port_put_frame(vp->client_port, &frame_); 707 727 if (status != PJ_SUCCESS) 708 728 return; … … 876 896 return status; 877 897 878 if (!vp->conv )898 if (!vp->conv.conv) 879 899 pj_memcpy(frame, vp->frm_buf, sizeof(*frame)); 880 900 } else { … … 907 927 return status; 908 928 909 return pjmedia_vid_dev_stream_put_frame(vp->strm, 910 (vp->conv?&frame_: frame));929 return pjmedia_vid_dev_stream_put_frame(vp->strm, (vp->conv.conv? 930 &frame_: frame)); 911 931 } else { 912 932 /* We are passive while the stream is active so we just store the … … 931 951 * The decoding counterpart is in vid_pasv_port_put_frame(). 932 952 */ 933 status = pjmedia_vid_dev_stream_get_frame(vp->strm, 934 (vp->conv? vp->frm_buf: 935 frame)); 953 status = pjmedia_vid_dev_stream_get_frame(vp->strm, (vp->conv.conv? 954 vp->frm_buf: frame)); 936 955 if (status != PJ_SUCCESS) 937 956 return status;
Note: See TracChangeset
for help on using the changeset viewer.