- Timestamp:
- Jul 12, 2011 9:08:56 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_stream.c
r3534 r3622 19 19 #include <pjmedia/vid_stream.h> 20 20 #include <pjmedia/errno.h> 21 #include <pjmedia/event.h> 21 22 #include <pjmedia/rtp.h> 22 23 #include <pjmedia/rtcp.h> … … 135 136 pj_uint32_t last_dec_ts; /**< Last decoded timestamp. */ 136 137 int last_dec_seq; /**< Last decoded sequence. */ 138 139 pjmedia_event_subscription esub_codec; /**< To subscribe codec events */ 140 pjmedia_event_publisher epub; /**< To publish events */ 137 141 }; 138 142 … … 301 305 #endif /* TRACE_JB */ 302 306 307 static void dump_port_info(const pjmedia_vid_channel *chan, 308 const char *event_name) 309 { 310 const pjmedia_port_info *pi = &chan->port.info; 311 312 PJ_LOG(5, (pi->name.ptr, 313 " %s format %s: %dx%d %c%c%c%c%s %d/%d(~%d)fps", 314 (chan->dir==PJMEDIA_DIR_DECODING? "Decoding":"Encoding"), 315 event_name, 316 pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h, 317 ((pi->fmt.id & 0x000000FF) >> 0), 318 ((pi->fmt.id & 0x0000FF00) >> 8), 319 ((pi->fmt.id & 0x00FF0000) >> 16), 320 ((pi->fmt.id & 0xFF000000) >> 24), 321 (chan->dir==PJMEDIA_DIR_ENCODING?"->":"<-"), 322 pi->fmt.det.vid.fps.num, pi->fmt.det.vid.fps.denum, 323 pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum)); 324 } 325 326 /* 327 * Handle events from stream components. 328 */ 329 static pj_status_t stream_event_cb(pjmedia_event_subscription *esub, 330 pjmedia_event *event) 331 { 332 pjmedia_vid_stream *stream = (pjmedia_vid_stream*)esub->user_data; 333 334 if (esub == &stream->esub_codec) { 335 /* This is codec event */ 336 switch (event->type) { 337 case PJMEDIA_EVENT_FMT_CHANGED: 338 /* Update param from codec */ 339 stream->codec->op->get_param(stream->codec, stream->info.codec_param); 340 341 /* Update decoding channel port info */ 342 pjmedia_format_copy(&stream->dec->port.info.fmt, 343 &stream->info.codec_param->dec_fmt); 344 345 /* we process the event */ 346 ++event->proc_cnt; 347 348 dump_port_info(event->data.fmt_changed.dir==PJMEDIA_DIR_DECODING ? 349 stream->dec : stream->enc, 350 "changed"); 351 break; 352 default: 353 break; 354 } 355 } 356 357 return pjmedia_event_publish(&stream->epub, event); 358 } 359 360 static pjmedia_event_publisher *port_get_epub(pjmedia_port *port) 361 { 362 pjmedia_vid_stream *stream = (pjmedia_vid_stream*) port->port_data.pdata; 363 return &stream->epub; 364 } 303 365 304 366 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA != 0 … … 795 857 return PJ_SUCCESS; 796 858 } 797 798 859 799 860 static pj_status_t get_frame(pjmedia_port *port, … … 915 976 } 916 977 917 /* Check if the decoder format is changed */918 if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) {919 /* Update param from codec */920 stream->codec->op->get_param(stream->codec, stream->info.codec_param);921 922 /* Update decoding channel port info */923 pjmedia_format_copy(&channel->port.info.fmt,924 &stream->info.codec_param->dec_fmt);925 }926 927 978 /* Learn remote frame rate after successful decoding */ 928 979 if (0 && frame->type == PJMEDIA_FRAME_TYPE_VIDEO && frame->size) … … 950 1001 stream->info.codec_param->dec_fmt.det.vid.fps = vfd->fps; 951 1002 952 /* Set bit_info */ 953 frame->bit_info |= PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED; 954 955 PJ_LOG(5, (channel->port.info.name.ptr, "Frame rate changed to %.2ffps", 956 (1.0 * vfd->fps.num / vfd->fps.denum))); 1003 PJ_LOG(5, (channel->port.info.name.ptr, 1004 "Frame rate changed to %d/%d(~%d)fps", 1005 vfd->fps.num, vfd->fps.denum, 1006 vfd->fps.num / vfd->fps.denum)); 1007 1008 /* Publish PJMEDIA_EVENT_FMT_CHANGED event */ 1009 if (pjmedia_event_publisher_has_sub(&stream->epub)) { 1010 pjmedia_event event; 1011 1012 dump_port_info(stream->dec, "changed"); 1013 1014 pjmedia_event_init(&event, PJMEDIA_EVENT_FMT_CHANGED, 1015 &frame_in.timestamp, &stream->epub); 1016 event.data.fmt_changed.dir = PJMEDIA_DIR_DECODING; 1017 pj_memcpy(&event.data.fmt_changed.new_fmt, 1018 &stream->info.codec_param->dec_fmt, 1019 sizeof(pjmedia_format)); 1020 pjmedia_event_publish(&stream->epub, &event); 1021 } 957 1022 } 958 1023 } … … 962 1027 stream->last_dec_ts = last_ts; 963 1028 } 964 965 #if PJ_LOG_MAX_LEVEL >= 5966 if (frame->bit_info & PJMEDIA_VID_CODEC_EVENT_FMT_CHANGED) {967 pjmedia_port_info *pi = &channel->port.info;968 969 PJ_LOG(5, (channel->port.info.name.ptr,970 "Decoding format changed to %dx%d %c%c%c%c %.2ffps",971 pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h,972 ((pi->fmt.id & 0x000000FF) >> 0),973 ((pi->fmt.id & 0x0000FF00) >> 8),974 ((pi->fmt.id & 0x00FF0000) >> 16),975 ((pi->fmt.id & 0xFF000000) >> 24),976 (1.0*pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum)));977 }978 #endif979 1029 980 1030 return PJ_SUCCESS; … … 1070 1120 /* Init port. */ 1071 1121 channel->port.port_data.pdata = stream; 1072 1073 PJ_LOG(5, (name.ptr, "%s channel created %dx%d %c%c%c%c%s%.*s %.2ffps", 1122 channel->port.get_event_pub = &port_get_epub; 1123 1124 PJ_LOG(5, (name.ptr, 1125 "%s channel created %dx%d %c%c%c%c%s%.*s %d/%d(~%d)fps", 1074 1126 (dir==PJMEDIA_DIR_ENCODING?"Encoding":"Decoding"), 1075 1127 pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h, … … 1081 1133 info->codec_info.encoding_name.slen, 1082 1134 info->codec_info.encoding_name.ptr, 1083 (1.0*pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum))); 1135 pi->fmt.det.vid.fps.num, pi->fmt.det.vid.fps.denum, 1136 pi->fmt.det.vid.fps.num/pi->fmt.det.vid.fps.denum)); 1084 1137 1085 1138 /* Done. */ … … 1198 1251 if (status != PJ_SUCCESS) 1199 1252 return status; 1253 1254 /* Init event publisher and subscribe to codec events */ 1255 pjmedia_event_publisher_init(&stream->epub); 1256 pjmedia_event_subscription_init(&stream->esub_codec, &stream_event_cb, 1257 stream); 1258 pjmedia_event_subscribe(&stream->codec->epub, &stream->esub_codec); 1200 1259 1201 1260 /* Estimate the maximum frame size */
Note: See TracChangeset
for help on using the changeset viewer.