Ignore:
Timestamp:
Jul 12, 2011 9:08:56 AM (13 years ago)
Author:
bennylp
Message:

More on re #1284:

  • Replaced bit_info mechanism to report format change in codec with event
  • Updated vid_port, vid_codec_test, etc.
  • Add event publisher to vid_codec
  • Add event publisher to pjmedia_port
  • Add event publisher to vid_stream
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjmedia/src/pjmedia/vid_stream.c

    r3534 r3622  
    1919#include <pjmedia/vid_stream.h> 
    2020#include <pjmedia/errno.h> 
     21#include <pjmedia/event.h> 
    2122#include <pjmedia/rtp.h> 
    2223#include <pjmedia/rtcp.h> 
     
    135136    pj_uint32_t              last_dec_ts;    /**< Last decoded timestamp.   */ 
    136137    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         */ 
    137141}; 
    138142 
     
    301305#endif /* TRACE_JB */ 
    302306 
     307static 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 */ 
     329static 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 
     360static 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} 
    303365 
    304366#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA != 0 
     
    795857    return PJ_SUCCESS; 
    796858} 
    797  
    798859 
    799860static pj_status_t get_frame(pjmedia_port *port, 
     
    915976    } 
    916977 
    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  
    927978    /* Learn remote frame rate after successful decoding */ 
    928979    if (0 && frame->type == PJMEDIA_FRAME_TYPE_VIDEO && frame->size) 
     
    9501001                stream->info.codec_param->dec_fmt.det.vid.fps = vfd->fps; 
    9511002 
    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                } 
    9571022            } 
    9581023        } 
     
    9621027        stream->last_dec_ts = last_ts; 
    9631028    } 
    964  
    965 #if PJ_LOG_MAX_LEVEL >= 5 
    966     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 #endif 
    9791029 
    9801030    return PJ_SUCCESS; 
     
    10701120    /* Init port. */ 
    10711121    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", 
    10741126               (dir==PJMEDIA_DIR_ENCODING?"Encoding":"Decoding"), 
    10751127               pi->fmt.det.vid.size.w, pi->fmt.det.vid.size.h, 
     
    10811133               info->codec_info.encoding_name.slen, 
    10821134               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)); 
    10841137 
    10851138    /* Done. */ 
     
    11981251    if (status != PJ_SUCCESS) 
    11991252        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); 
    12001259 
    12011260    /* Estimate the maximum frame size */ 
Note: See TracChangeset for help on using the changeset viewer.