- Timestamp:
- Mar 2, 2011 8:37:31 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_stream.c
r3425 r3435 69 69 void *buf; /**< Output buffer. */ 70 70 unsigned buf_size; /**< Size of output buffer. */ 71 unsigned buf_len; /**< Length of data in buffer. */71 unsigned buf_len; /**< Length of data in buffer. */ 72 72 pjmedia_rtp_session rtp; /**< RTP session. */ 73 73 } pjmedia_vid_channel; … … 135 135 136 136 pjmedia_vid_codec *codec; /**< Codec instance being used. */ 137 pj_uint32_t last_dec_ts; /**< Last decoded timestamp. */ 138 int last_dec_seq; /**< Last decoded sequence. */ 137 139 }; 138 140 … … 841 843 pjmedia_vid_channel *channel = stream->dec; 842 844 pjmedia_frame frame_in; 845 pj_bool_t fps_changed = PJ_FALSE; 846 pjmedia_ratio new_fps = {0}; 843 847 pj_status_t status; 844 848 … … 857 861 pj_size_t psize, data_len; 858 862 pj_uint32_t ts, last_ts; 859 pj_bool_t got_frame; 863 int seq; 864 pj_bool_t got_frame, check_fps; 860 865 unsigned i; 861 866 … … 863 868 last_ts = 0; 864 869 got_frame = PJ_FALSE; 870 check_fps = PJ_FALSE; 865 871 866 872 /* Lock jitter buffer mutex first */ … … 870 876 /* Get frame from jitter buffer. */ 871 877 pjmedia_jbuf_peek_frame(stream->jb, i, &p, &psize, &ptype, 872 NULL, &ts );878 NULL, &ts, &seq); 873 879 if (ptype == PJMEDIA_JB_NORMAL_FRAME) { 874 if (last_ts == 0) 880 if (last_ts == 0) { 875 881 last_ts = ts; 882 check_fps = stream->last_dec_ts && 883 (seq - stream->last_dec_seq == 1) && 884 (last_ts > stream->last_dec_ts); 885 } 876 886 877 887 if (ts != last_ts) { … … 880 890 break; 881 891 } 882 892 883 893 data = (pj_uint8_t*)channel->buf + channel->buf_len; 884 894 data_len = channel->buf_size - channel->buf_len; … … 901 911 return PJ_SUCCESS; 902 912 } 913 914 /* Learn remote frame rate */ 915 if (check_fps) { 916 pj_uint32_t ts_diff; 917 pjmedia_video_format_detail *vfd; 918 919 ts_diff = last_ts - stream->last_dec_ts; 920 vfd = pjmedia_format_get_video_format_detail( 921 &channel->port.info.fmt, PJ_TRUE); 922 if (ts_diff * vfd->fps.num != 923 stream->info.codec_info.clock_rate * vfd->fps.denum) 924 { 925 /* Frame rate changed */ 926 fps_changed = PJ_TRUE; 927 new_fps.num = stream->info.codec_info.clock_rate; 928 new_fps.denum = ts_diff; 929 } 930 } 931 932 /* Update last frame seq and timestamp */ 933 stream->last_dec_seq = seq - 1; 934 stream->last_dec_ts = last_ts; 903 935 } 904 936 … … 924 956 925 957 /* Update decoding channel port info */ 926 pjmedia_format_copy(& stream->dec->port.info.fmt,958 pjmedia_format_copy(&channel->port.info.fmt, 927 959 &stream->info.codec_param->dec_fmt); 928 960 } 929 961 962 if (fps_changed) { 963 pjmedia_video_format_detail *vfd; 964 965 /* Update decoding channel port info */ 966 vfd = pjmedia_format_get_video_format_detail( 967 &channel->port.info.fmt, PJ_TRUE); 968 vfd->fps = new_fps; 969 970 /* Update stream info */ 971 vfd = pjmedia_format_get_video_format_detail( 972 &stream->info.codec_param->dec_fmt, PJ_TRUE); 973 vfd->fps = new_fps; 974 975 /* Set bit_info */ 976 frame->bit_info |= PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED; 977 978 PJ_LOG(4, (channel->port.info.name.ptr, "Frame rate changed to %.2ffps", 979 (1.0 * new_fps.num / new_fps.denum))); 980 } 981 930 982 return PJ_SUCCESS; 931 983 } … … 1134 1186 return status; 1135 1187 1136 /* Get the frame size */ 1137 stream->frame_size = vfd_enc->max_bps * vfd_enc->fps.denum / 1188 /* Estimate the maximum frame size */ 1189 stream->frame_size = vfd_enc->size.w * vfd_enc->size.h * 4; 1190 1191 #if 0 1192 stream->frame_size = vfd_enc->max_bps/8 * vfd_enc->fps.denum / 1138 1193 vfd_enc->fps.num; 1139 1194 … … 1142 1197 * frame size value for safety. 1143 1198 */ 1144 stream->frame_size <<= 2; 1199 stream->frame_size <<= 4; 1200 #endif 1145 1201 1146 1202 /* Validate the frame size */ … … 1562 1618 1563 1619 1564 static const pj_str_t ID_AUDIO = { "audio", 5};1565 1620 static const pj_str_t ID_VIDEO = { "video", 5}; 1566 static const pj_str_t ID_APPLICATION = { "application", 11};1567 1621 static const pj_str_t ID_IN = { "IN", 2 }; 1568 1622 static const pj_str_t ID_IP4 = { "IP4", 3}; … … 1572 1626 //static const pj_str_t ID_SDP_NAME = { "pjmedia", 7 }; 1573 1627 static const pj_str_t ID_RTPMAP = { "rtpmap", 6 }; 1574 static const pj_str_t ID_TELEPHONE_EVENT = { "telephone-event", 15 };1575 1628 1576 1629 static const pj_str_t STR_INACTIVE = { "inactive", 8 };
Note: See TracChangeset
for help on using the changeset viewer.