- Timestamp:
- Mar 2, 2011 8:37:31 AM (14 years ago)
- Location:
- pjproject/branches/projects/2.0-dev
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/include/pjmedia/jbuf.h
r3420 r3435 327 327 328 328 329 /** 330 * Get a frame from the jitter buffer. The jitter buffer will return the 331 * oldest frame from it's buffer, when it is available. 332 * 333 * @param jb The jitter buffer. 334 * @param frame Buffer to receive the payload from the jitter buffer. 335 * @see pjmedia_jbuf_get_frame(). 336 * @param size Pointer to receive frame size. 337 * @param p_frm_type Pointer to receive frame type. 338 * @see pjmedia_jbuf_get_frame(). 339 * @param bit_info Bit precise info of the frame, e.g: a frame may not 340 * exactly start and end at the octet boundary, so this 341 * field may be used for specifying start & end bit offset. 342 * @param ts Frame timestamp. 343 * @param seq Frame sequence number. 344 */ 329 345 PJ_DECL(void) pjmedia_jbuf_get_frame3(pjmedia_jbuf *jb, 330 346 void *frame, … … 332 348 char *p_frm_type, 333 349 pj_uint32_t *bit_info, 334 pj_uint32_t *ts); 335 350 pj_uint32_t *ts, 351 int *seq); 352 353 354 /** 355 * Peek a frame from the jitter buffer. The jitter buffer state will not be 356 * modified. 357 * 358 * @param jb The jitter buffer. 359 * @param offset Offset from the oldest frame to be peeked. 360 * @param frame Buffer to receive the payload from the jitter buffer. 361 * @see pjmedia_jbuf_get_frame(). 362 * @param size Pointer to receive frame size. 363 * @param p_frm_type Pointer to receive frame type. 364 * @see pjmedia_jbuf_get_frame(). 365 * @param bit_info Bit precise info of the frame, e.g: a frame may not 366 * exactly start and end at the octet boundary, so this 367 * field may be used for specifying start & end bit offset. 368 * @param ts Frame timestamp. 369 * @param seq Frame sequence number. 370 */ 336 371 PJ_DECL(void) pjmedia_jbuf_peek_frame(pjmedia_jbuf *jb, 337 unsigned idx,372 unsigned offset, 338 373 const void **frame, 339 374 pj_size_t *size, 340 375 char *p_frm_type, 341 376 pj_uint32_t *bit_info, 342 pj_uint32_t *ts); 343 377 pj_uint32_t *ts, 378 int *seq); 379 380 381 /** 382 * Remove frames from the jitter buffer. 383 * 384 * @param jb The jitter buffer. 385 * @param frame_cnt Number of frames to be removed. 386 * 387 * @return The number of frame successfully removed. 388 */ 344 389 PJ_DECL(unsigned) pjmedia_jbuf_remove_frame(pjmedia_jbuf *jb, 345 390 unsigned frame_cnt); -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-codec/ffmpeg_codecs.c
r3432 r3435 182 182 /**< expected output format of 183 183 ffmpeg decoder */ 184 struct SwsContext *sws_ctx; /**< the format converter for185 post decoding */186 187 184 } ffmpeg_private; 188 185 … … 207 204 pjmedia_vid_codec_info info; 208 205 pjmedia_format_id base_fmt_id; 206 pj_uint32_t avg_bps; 207 pj_uint32_t max_bps; 209 208 func_packetize packetize; 210 209 func_unpacketize unpacketize; … … 248 247 { 249 248 {PJMEDIA_FORMAT_H263P, {"H263-1998",9}, PJMEDIA_RTP_PT_H263}, 250 PJMEDIA_FORMAT_H263, 249 PJMEDIA_FORMAT_H263, 1000000, 2000000, 251 250 &h263_packetize, &h263_unpacketize, &h263_parse_fmtp, 252 251 {2, { {{"CIF",3}, {"2",1}}, {{"QCIF",4}, {"1",1}}, } }, … … 254 253 { 255 254 {PJMEDIA_FORMAT_H263, {"H263",4}, PJMEDIA_RTP_PT_H263}, 256 0, 255 0, 1000000, 2000000, 257 256 &h263_packetize, &h263_unpacketize, &h263_parse_fmtp, 258 257 {2, { {{"CIF",3}, {"2",1}}, {{"QCIF",4}, {"1",1}}, } }, … … 802 801 attr->dec_fmtp = desc->dec_fmtp; 803 802 803 /* Bitrate */ 804 attr->enc_fmt.det.vid.avg_bps = desc->avg_bps; 805 attr->enc_fmt.det.vid.max_bps = desc->max_bps; 806 804 807 return PJ_SUCCESS; 805 808 } … … 989 992 ctx->time_base.num = vfd->fps.denum; 990 993 ctx->time_base.den = vfd->fps.num; 991 if (vfd->avg_bps) 994 if (vfd->avg_bps) { 992 995 ctx->bit_rate = vfd->avg_bps; 993 if (vfd->max_bps) 994 ctx->rc_max_rate = vfd->max_bps; 996 if (vfd->max_bps) 997 ctx->bit_rate_tolerance = vfd->max_bps - vfd->avg_bps; 998 } 995 999 996 1000 /* For encoder, should be better to be strict to the standards */ … … 1124 1128 av_free(ff->dec_ctx); 1125 1129 } 1126 if (ff->sws_ctx) {1127 sws_freeContext(ff->sws_ctx);1128 }1129 1130 ff->enc_ctx = NULL; 1130 1131 ff->dec_ctx = NULL; 1131 ff->sws_ctx = NULL;1132 1132 pj_mutex_unlock(ff_mutex); 1133 1133 … … 1409 1409 #ifdef _MSC_VER 1410 1410 # pragma comment( lib, "avcodec.lib") 1411 # pragma comment( lib, "swscale.lib")1412 1411 #endif 1413 1412 -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia-videodev/sdl_dev.c
r3432 r3435 447 447 if (strm->overlay) 448 448 SDL_FreeYUVOverlay(strm->overlay); 449 450 /* Update SDL info for the new format */ 451 sdl_info = get_sdl_format_info(fmt->id); 449 452 450 453 if (vfi->color_model == PJMEDIA_COLOR_MODEL_RGB) { -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/jbuf.c
r3420 r3435 264 264 pjmedia_jb_frame_type *p_type, 265 265 pj_uint32_t *bit_info, 266 pj_uint32_t *ts) 266 pj_uint32_t *ts, 267 int *seq) 267 268 { 268 269 if (framelist->size) { … … 289 290 if (ts) 290 291 *ts = framelist->ts[framelist->head]; 292 if (seq) 293 *seq = framelist->origin; 291 294 292 295 //pj_bzero(framelist->content + … … 314 317 315 318 static pj_bool_t jb_framelist_peek(jb_framelist_t *framelist, 316 unsigned idx,319 unsigned offset, 317 320 const void **frame, 318 321 pj_size_t *size, 319 322 pjmedia_jb_frame_type *type, 320 323 pj_uint32_t *bit_info, 321 pj_uint32_t *ts) 322 { 323 unsigned pos; 324 325 if (idx >= jb_framelist_eff_size(framelist)) 324 pj_uint32_t *ts, 325 int *seq) 326 { 327 unsigned pos, idx; 328 329 if (offset >= jb_framelist_eff_size(framelist)) 326 330 return PJ_FALSE; 327 331 328 332 pos = framelist->head; 333 idx = offset; 329 334 330 335 /* Find actual peek position, note there may be discarded frames */ … … 351 356 if (ts) 352 357 *ts = framelist->ts[pos]; 358 if (seq) 359 *seq = framelist->origin + offset; 353 360 354 361 return PJ_TRUE; … … 932 939 char *p_frame_type) 933 940 { 934 pjmedia_jbuf_get_frame3(jb, frame, NULL, p_frame_type, NULL, NULL); 941 pjmedia_jbuf_get_frame3(jb, frame, NULL, p_frame_type, NULL, 942 NULL, NULL); 935 943 } 936 944 … … 944 952 pj_uint32_t *bit_info) 945 953 { 946 pjmedia_jbuf_get_frame3(jb, frame, size, p_frame_type, bit_info, NULL); 954 pjmedia_jbuf_get_frame3(jb, frame, size, p_frame_type, bit_info, 955 NULL, NULL); 947 956 } 948 957 … … 955 964 char *p_frame_type, 956 965 pj_uint32_t *bit_info, 957 pj_uint32_t *ts) 966 pj_uint32_t *ts, 967 int *seq) 958 968 { 959 969 if (jb->jb_status == JB_STATUS_PREFETCHING) { … … 980 990 /* Try to retrieve a frame from frame list */ 981 991 res = jb_framelist_get(&jb->jb_framelist, frame, size, &ftype, 982 bit_info, ts );992 bit_info, ts, seq); 983 993 if (res) { 984 994 /* We've successfully retrieved a frame from the frame list, but … … 1050 1060 1051 1061 PJ_DEF(void) pjmedia_jbuf_peek_frame( pjmedia_jbuf *jb, 1052 unsigned idx,1062 unsigned offset, 1053 1063 const void **frame, 1054 1064 pj_size_t *size, 1055 1065 char *p_frm_type, 1056 1066 pj_uint32_t *bit_info, 1057 pj_uint32_t *ts) 1067 pj_uint32_t *ts, 1068 int *seq) 1058 1069 { 1059 1070 pjmedia_jb_frame_type ftype; 1060 1071 pj_bool_t res; 1061 1072 1062 res = jb_framelist_peek(&jb->jb_framelist, idx, frame, size, &ftype, bit_info, ts); 1073 res = jb_framelist_peek(&jb->jb_framelist, offset, frame, size, &ftype, 1074 bit_info, ts, seq); 1063 1075 if (!res) 1064 1076 *p_frm_type = PJMEDIA_JB_ZERO_EMPTY_FRAME; -
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/stream.c
r3425 r3435 2742 2742 2743 2743 static const pj_str_t ID_AUDIO = { "audio", 5}; 2744 static const pj_str_t ID_VIDEO = { "video", 5};2745 static const pj_str_t ID_APPLICATION = { "application", 11};2746 2744 static const pj_str_t ID_IN = { "IN", 2 }; 2747 2745 static const pj_str_t ID_IP4 = { "IP4", 3}; -
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 }; -
pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c
r3425 r3435 548 548 dump_pool_usage(THIS_FILE, &cp); 549 549 550 /* Destroy stream */ 551 if (g_med_stream) 552 pjmedia_stream_destroy(g_med_stream); 553 if (g_med_vstream) 554 pjmedia_vid_stream_destroy(g_med_vstream); 555 556 /* Destroy audio ports */ 557 if (g_snd_player) 558 pjmedia_snd_port_destroy(g_snd_player); 559 if (g_snd_rec) 560 pjmedia_snd_port_destroy(g_snd_rec); 561 562 /* Destroy video ports */ 563 if (g_vid_capturer) 564 pjmedia_vid_port_destroy(g_vid_capturer); 565 if (g_vid_renderer) 566 pjmedia_vid_port_destroy(g_vid_renderer); 567 568 /* Destroy media transports */ 569 for (i = 0; i < MAX_MEDIA_CNT; ++i) { 570 if (g_med_transport[i]) 571 pjmedia_transport_close(g_med_transport[i]); 572 } 573 574 /* Deinit ffmpeg codec */ 575 pjmedia_codec_ffmpeg_deinit(); 576 577 /* Deinit pjmedia endpoint */ 578 if (g_med_endpt) 579 pjmedia_endpt_destroy(g_med_endpt); 580 581 /* Deinit pjsip endpoint */ 582 if (g_endpt) 583 pjsip_endpt_destroy(g_endpt); 584 585 /* Release pool */ 550 586 pj_pool_release(pool); 551 587 -
pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/vid_streamutil.c
r3432 r3435 126 126 } 127 127 128 /* 129 * Register all codecs. 130 */ 131 static void deinit_codecs() 132 { 133 #if defined(PJMEDIA_HAS_FFMPEG_CODEC) && PJMEDIA_HAS_FFMPEG_CODEC != 0 134 pjmedia_codec_ffmpeg_deinit(); 135 #endif 136 } 137 128 138 static pj_status_t create_file_player( pj_pool_t *pool, 129 139 const char *file_name, … … 616 626 file_vfd = pjmedia_format_get_video_format_detail(&play_port->info.fmt, 617 627 PJ_TRUE); 618 PJ_LOG(2, (THIS_FILE, "Reading video stream %dx%d %c%c%c%c @%.2 dfps",628 PJ_LOG(2, (THIS_FILE, "Reading video stream %dx%d %c%c%c%c @%.2ffps", 619 629 file_vfd->size.w, file_vfd->size.h, 620 630 ((play_port->info.fmt.id & 0x000000FF) >> 0), … … 622 632 ((play_port->info.fmt.id & 0x00FF0000) >> 16), 623 633 ((play_port->info.fmt.id & 0xFF000000) >> 24), 624 file_vfd->fps.num/file_vfd->fps.denum));634 (1.0*file_vfd->fps.num/file_vfd->fps.denum))); 625 635 626 636 /* Allocate file read buffer */ … … 658 668 goto on_exit; 659 669 670 codec_param2.dir = PJMEDIA_DIR_DECODING; 660 671 status = play_decoder->op->open(play_decoder, &codec_param2); 661 672 if (status != PJ_SUCCESS) … … 706 717 goto on_exit; 707 718 708 pjmedia_format_copy(&vpp.vidparam.fmt, &codec_param.dec_fmt); 719 pjmedia_format_copy(&vpp.vidparam.fmt, &codec_param.enc_fmt); 720 vpp.vidparam.fmt.id = codec_param.dec_fmt.id; 709 721 vpp.vidparam.dir = PJMEDIA_DIR_CAPTURE; 710 722 … … 836 848 837 849 if (dir & PJMEDIA_DIR_ENCODING) 838 PJ_LOG(2, (THIS_FILE, "Sending %dx%d %.*s @%.2 dfps",850 PJ_LOG(2, (THIS_FILE, "Sending %dx%d %.*s @%.2ffps", 839 851 codec_param.enc_fmt.det.vid.size.w, 840 852 codec_param.enc_fmt.det.vid.size.h, 841 853 codec_info->encoding_name.slen, 842 854 codec_info->encoding_name.ptr, 843 codec_param.enc_fmt.det.vid.fps.num/844 codec_param.enc_fmt.det.vid.fps.denum));855 (1.0*codec_param.enc_fmt.det.vid.fps.num/ 856 codec_param.enc_fmt.det.vid.fps.denum))); 845 857 846 858 for (;;) { … … 880 892 881 893 /* Destroy file decoder */ 882 if (play_decoder) 894 if (play_decoder) { 883 895 play_decoder->op->close(play_decoder); 896 pjmedia_vid_codec_mgr_dealloc_codec(NULL, play_decoder); 897 } 884 898 885 899 /* Destroy video devices */ … … 899 913 } 900 914 915 /* Deinit codecs */ 916 deinit_codecs(); 917 901 918 /* Shutdown video subsystem */ 902 919 pjmedia_vid_subsys_shutdown();
Note: See TracChangeset
for help on using the changeset viewer.