Changeset 3509
- Timestamp:
- Apr 8, 2011 4:04:25 AM (14 years ago)
- Location:
- pjproject/branches/projects/2.0-dev/pjmedia
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/frame.h
r3392 r3509 106 106 #pragma pack() 107 107 108 /** 109 * Copy one frame to another. If the destination frame's size is smaller than 110 * the source frame's, the destination buffer will be truncated. 111 * 112 * @param src Source frame. 113 * @param dst Destination frame. 114 */ 115 PJ_INLINE(void) pjmedia_frame_copy(pjmedia_frame *dst, 116 const pjmedia_frame *src) 117 { 118 dst->type = src->type; 119 dst->timestamp = src->timestamp; 120 dst->bit_info = src->bit_info; 121 dst->size = (dst->size < src->size? dst->size: src->size); 122 pj_memcpy(dst->buf, src->buf, dst->size); 123 } 108 124 109 125 /** … … 112 128 * @param frm The #pjmedia_frame_ext. 113 129 * @param src Subframe data. 114 * @param bitlen Leng htof subframe, in bits.130 * @param bitlen Length of subframe, in bits. 115 131 * @param samples_cnt Number of audio samples in subframe. 116 132 */ -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
r3499 r3509 734 734 } 735 735 736 if (frame->size==0 || frame->buf==NULL) 736 if (frame->size==0 || frame->buf==NULL || 737 frame->size < stream->vafp.framebytes) 737 738 goto on_return; 738 739 … … 746 747 } 747 748 748 pj_memcpy(stream->surf->pixels, frame->buf, frame->size); 749 pj_memcpy(stream->surf->pixels, frame->buf, 750 stream->vafp.framebytes); 749 751 750 752 if (SDL_MUSTLOCK(stream->surf)) { -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/videoport.c
r3489 r3509 136 136 unsigned ptime_usec; 137 137 pjmedia_vid_param vparam; 138 pjmedia_conversion_param conv_param; 138 139 139 140 PJ_ASSERT_RETURN(pool && prm && p_vid_port, PJ_EINVAL); … … 264 265 { 265 266 /* Yes, we need converter */ 266 pjmedia_conversion_param conv_param;267 267 const pjmedia_video_format_info *vfi; 268 268 pjmedia_video_apply_fmt_param vafp; … … 288 288 289 289 /* Allocate buffer for conversion */ 290 vfi = pjmedia_get_video_format_info(NULL, prm->vidparam.fmt.id);290 vfi = pjmedia_get_video_format_info(NULL, conv_param.dst.id); 291 291 if (!vfi) 292 292 return PJMEDIA_EBADFMT; 293 293 294 294 pj_bzero(&vafp, sizeof(vafp)); 295 vafp.size = prm->vidparam.fmt.det.vid.size;295 vafp.size = conv_param.dst.det.vid.size; 296 296 status = vfi->apply_fmt(vfi, &vafp); 297 297 if (status != PJ_SUCCESS) … … 353 353 pjmedia_video_apply_fmt_param vafp; 354 354 355 vfi = pjmedia_get_video_format_info(NULL, vparam.fmt.id); 355 vfi = pjmedia_get_video_format_info(NULL, vp->cap_conv? 356 conv_param.src.id: 357 vparam.fmt.id); 356 358 if (!vfi) { 357 359 status = PJ_ENOTFOUND; … … 360 362 361 363 pj_bzero(&vafp, sizeof(vafp)); 362 vafp.size = vparam.fmt.det.vid.size; 364 vafp.size = (vp->cap_conv? conv_param.src.det.vid.size: 365 vparam.fmt.det.vid.size); 363 366 status = vfi->apply_fmt(vfi, &vafp); 364 367 if (status != PJ_SUCCESS) … … 367 370 if (vp->dir & PJMEDIA_DIR_ENCODING) { 368 371 vp->enc_frm_buf = PJ_POOL_ZALLOC_T(pool, pjmedia_frame); 369 vp->enc_frm_buf_size = vafp.framebytes; 370 vp->enc_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes); 371 vp->enc_frm_buf->size = vafp.framebytes; 372 if (vp->stream_role == ROLE_ACTIVE && vp->cap_conv) { 373 vp->enc_frm_buf_size = vp->cap_conv_buf_size; 374 vp->enc_frm_buf->buf = vp->cap_conv_buf; 375 } else { 376 vp->enc_frm_buf_size = vafp.framebytes; 377 vp->enc_frm_buf->buf = pj_pool_alloc(pool, vafp.framebytes); 378 } 379 vp->enc_frm_buf->size = vp->enc_frm_buf_size; 372 380 vp->enc_frm_buf->type = PJMEDIA_FRAME_TYPE_NONE; 373 381 … … 674 682 //save_rgb_frame(vp->cap_size.w, vp->cap_size.h, vp->enc_frm_buf); 675 683 676 frame = *vp->enc_frm_buf;677 684 if (vp->cap_conv) { 678 685 frame.buf = vp->cap_conv_buf; … … 684 691 } 685 692 686 status = pjmedia_port_put_frame(vp->client_port, &frame); 693 status = pjmedia_port_put_frame(vp->client_port, (vp->cap_conv? 694 &frame: 695 vp->enc_frm_buf)); 687 696 } 688 697 … … 694 703 pjmedia_vid_port *vp = (pjmedia_vid_port*)user_data; 695 704 pj_status_t status; 705 pjmedia_frame frame; 696 706 unsigned frame_ts = vp->rend_clocksrc.clock_rate / 1000 * 697 707 vp->rend_clocksrc.ptime_usec / 1000; … … 815 825 return; 816 826 817 status = pjmedia_vid_dev_stream_put_frame(vp->strm, vp->dec_frm_buf); 818 } 819 820 static void copy_frame(pjmedia_frame *dst, const pjmedia_frame *src) 821 { 822 PJ_ASSERT_ON_FAIL(dst->size >= src->size, return); 823 824 pj_memcpy(dst, src, sizeof(*src)); 825 pj_memcpy(dst->buf, src->buf, src->size); 826 dst->size = src->size; 827 if (vp->cap_conv) { 828 frame.buf = vp->cap_conv_buf; 829 frame.size = vp->cap_conv_buf_size; 830 status = pjmedia_converter_convert(vp->cap_conv, 831 vp->dec_frm_buf, &frame); 832 if (status != PJ_SUCCESS) 833 return; 834 } 835 836 status = pjmedia_vid_dev_stream_put_frame(vp->strm, (vp->cap_conv? 837 &frame: 838 vp->dec_frm_buf)); 827 839 } 828 840 … … 834 846 pjmedia_frame frame_; 835 847 836 frame_ = *frame;837 848 if (vp->cap_conv) { 838 849 pj_status_t status; … … 844 855 if (status != PJ_SUCCESS) 845 856 return status; 857 frame = &frame_; 846 858 } 847 859 848 860 if (vp->role==ROLE_ACTIVE) { 849 861 if (vp->client_port) 850 return pjmedia_port_put_frame(vp->client_port, &frame_);862 return pjmedia_port_put_frame(vp->client_port, frame); 851 863 } else { 852 pj_mutex_lock(vp->enc_frm_mutex); 853 copy_frame(vp->enc_frm_buf, &frame_); 854 pj_mutex_unlock(vp->enc_frm_mutex); 864 if (!vp->cap_conv) { 865 pj_mutex_lock(vp->enc_frm_mutex); 866 pjmedia_frame_copy(vp->enc_frm_buf, frame); 867 pj_mutex_unlock(vp->enc_frm_mutex); 868 } 855 869 } 856 870 if (vp->strm_cb.capture_cb) 857 return (*vp->strm_cb.capture_cb)(stream, vp->strm_cb_data, &frame_);871 return (*vp->strm_cb.capture_cb)(stream, vp->strm_cb_data, frame); 858 872 return PJ_SUCCESS; 859 873 } … … 877 891 } else { 878 892 pj_mutex_lock(vp->dec_frm_mutex); 879 copy_frame(frame, vp->dec_frm_buf);893 pjmedia_frame_copy(frame, vp->dec_frm_buf); 880 894 pj_mutex_unlock(vp->dec_frm_mutex); 881 895 } … … 901 915 struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port; 902 916 pjmedia_vid_port *vp = vpp->vp; 917 pjmedia_frame frame_; 918 919 if (vp->cap_conv) { 920 pj_status_t status; 921 922 frame_.buf = vp->cap_conv_buf; 923 frame_.size = vp->cap_conv_buf_size; 924 status = pjmedia_converter_convert(vp->cap_conv, 925 frame, &frame_); 926 if (status != PJ_SUCCESS) 927 return status; 928 frame = &frame_; 929 } 903 930 904 931 if (vp->stream_role==ROLE_PASSIVE) { … … 906 933 } else { 907 934 pj_mutex_lock(vp->dec_frm_mutex); 908 copy_frame(vp->dec_frm_buf, frame);935 pjmedia_frame_copy(vp->dec_frm_buf, frame); 909 936 pj_mutex_unlock(vp->dec_frm_mutex); 910 937 } … … 918 945 struct vid_pasv_port *vpp = (struct vid_pasv_port*)this_port; 919 946 pjmedia_vid_port *vp = vpp->vp; 947 pj_status_t status; 920 948 921 949 if (vp->stream_role==ROLE_PASSIVE) { 950 if (vp->cap_conv) 951 vp->enc_frm_buf->size = vp->enc_frm_buf_size; 952 status = pjmedia_vid_dev_stream_get_frame(vp->strm, 953 (vp->cap_conv? 954 vp->enc_frm_buf: 955 frame)); 956 if (status != PJ_SUCCESS) 957 return status; 958 922 959 if (vp->cap_conv) { 923 pj_status_t status;924 925 vp->enc_frm_buf->size = vp->enc_frm_buf_size;926 status = pjmedia_vid_dev_stream_get_frame(vp->strm, vp->enc_frm_buf);927 if (status != PJ_SUCCESS)928 return status;929 930 960 status = pjmedia_converter_convert(vp->cap_conv, 931 961 vp->enc_frm_buf, frame); 932 962 if (status != PJ_SUCCESS) 933 963 return status; 934 } else { 935 return pjmedia_vid_dev_stream_get_frame(vp->strm, frame); 936 } 964 } 937 965 } else { 938 966 pj_mutex_lock(vp->enc_frm_mutex); 939 copy_frame(frame, vp->enc_frm_buf);967 pjmedia_frame_copy(frame, vp->enc_frm_buf); 940 968 pj_mutex_unlock(vp->enc_frm_mutex); 941 969 }
Note: See TracChangeset
for help on using the changeset viewer.