Ignore:
Timestamp:
Mar 2, 2011 8:37:31 AM (13 years ago)
Author:
nanang
Message:

Re #1182:

  • Added remote frame-rate detection in to video stream.
  • Fixed bitrate settings in ffmpeg codec.
  • Fixed SDL dev to update internal SDL info when format changed.
  • Minor fixes/updates, e.g:
    • added cleanup steps, fixed logs, etc, in sample app simpleua.c and vid_streamutil.c
    • fixed/added docs of the new APIs in the jitter buffer.
File:
1 edited

Legend:

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

    r3425 r3435  
    6969    void                   *buf;            /**< Output buffer.             */ 
    7070    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.  */ 
    7272    pjmedia_rtp_session     rtp;            /**< RTP session.               */ 
    7373} pjmedia_vid_channel; 
     
    135135 
    136136    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.    */ 
    137139}; 
    138140 
     
    841843    pjmedia_vid_channel *channel = stream->dec; 
    842844    pjmedia_frame frame_in; 
     845    pj_bool_t fps_changed = PJ_FALSE; 
     846    pjmedia_ratio new_fps = {0}; 
    843847    pj_status_t status; 
    844848 
     
    857861        pj_size_t psize, data_len; 
    858862        pj_uint32_t ts, last_ts; 
    859         pj_bool_t got_frame; 
     863        int seq; 
     864        pj_bool_t got_frame, check_fps; 
    860865        unsigned i; 
    861866 
     
    863868        last_ts = 0; 
    864869        got_frame = PJ_FALSE; 
     870        check_fps = PJ_FALSE; 
    865871 
    866872        /* Lock jitter buffer mutex first */ 
     
    870876            /* Get frame from jitter buffer. */ 
    871877            pjmedia_jbuf_peek_frame(stream->jb, i, &p, &psize, &ptype, 
    872                                     NULL, &ts); 
     878                                    NULL, &ts, &seq); 
    873879            if (ptype == PJMEDIA_JB_NORMAL_FRAME) { 
    874                 if (last_ts == 0) 
     880                if (last_ts == 0) { 
    875881                    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                } 
    876886 
    877887                if (ts != last_ts) { 
     
    880890                    break; 
    881891                } 
    882                  
     892 
    883893                data = (pj_uint8_t*)channel->buf + channel->buf_len; 
    884894                data_len = channel->buf_size - channel->buf_len; 
     
    901911            return PJ_SUCCESS; 
    902912        } 
     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; 
    903935    } 
    904936 
     
    924956 
    925957        /* Update decoding channel port info */ 
    926         pjmedia_format_copy(&stream->dec->port.info.fmt, 
     958        pjmedia_format_copy(&channel->port.info.fmt, 
    927959                            &stream->info.codec_param->dec_fmt); 
    928960    } 
    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 
    930982    return PJ_SUCCESS; 
    931983} 
     
    11341186        return status; 
    11351187 
    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 / 
    11381193                         vfd_enc->fps.num; 
    11391194     
     
    11421197     * frame size value for safety. 
    11431198     */ 
    1144     stream->frame_size <<= 2; 
     1199    stream->frame_size <<= 4; 
     1200#endif 
    11451201 
    11461202    /* Validate the frame size */ 
     
    15621618 
    15631619 
    1564 static const pj_str_t ID_AUDIO = { "audio", 5}; 
    15651620static const pj_str_t ID_VIDEO = { "video", 5}; 
    1566 static const pj_str_t ID_APPLICATION = { "application", 11}; 
    15671621static const pj_str_t ID_IN = { "IN", 2 }; 
    15681622static const pj_str_t ID_IP4 = { "IP4", 3}; 
     
    15721626//static const pj_str_t ID_SDP_NAME = { "pjmedia", 7 }; 
    15731627static const pj_str_t ID_RTPMAP = { "rtpmap", 6 }; 
    1574 static const pj_str_t ID_TELEPHONE_EVENT = { "telephone-event", 15 }; 
    15751628 
    15761629static const pj_str_t STR_INACTIVE = { "inactive", 8 }; 
Note: See TracChangeset for help on using the changeset viewer.