Changeset 5913


Ignore:
Timestamp:
Nov 22, 2018 3:33:42 AM (6 years ago)
Author:
nanang
Message:

Fix #2163:

  • Frame rate calculation is now done using temporary variable, instead of using stream decoding channel state directly.
  • Added condition for applying calculated frame rate: it must be greater than zero.
  • Fixed frame rate comparison to use float, was using integer which might get overflow on 32 bit integer platforms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/vid_stream.c

    r5894 r5913  
    12541254        { 
    12551255            pj_uint32_t ts_diff; 
    1256             pjmedia_video_format_detail *vfd; 
     1256            pjmedia_ratio new_fps; 
    12571257 
    12581258            ts_diff = frm_ts - stream->last_dec_ts; 
    1259             vfd = pjmedia_format_get_video_format_detail( 
    1260                                     &channel->port.info.fmt, PJ_TRUE); 
    1261             if (stream->info.codec_info.clock_rate * vfd->fps.denum != 
    1262                 vfd->fps.num * ts_diff) 
     1259             
     1260            /* Calculate new FPS based on RTP timestamp diff */ 
     1261            if (stream->info.codec_info.clock_rate % ts_diff == 0) { 
     1262                new_fps.num = stream->info.codec_info.clock_rate/ts_diff; 
     1263                new_fps.denum = 1; 
     1264            } else { 
     1265                new_fps.num = stream->info.codec_info.clock_rate; 
     1266                new_fps.denum = ts_diff; 
     1267            } 
     1268 
     1269            /* Only apply the new FPS when it is >0, <=100, and increasing */ 
     1270            if (new_fps.num/new_fps.denum <= 100 && 
     1271                new_fps.num/new_fps.denum > 0 && 
     1272                new_fps.num*1.0/new_fps.denum > 
     1273                stream->dec_max_fps.num*1.0/stream->dec_max_fps.denum) 
    12631274            { 
    1264                 /* Frame rate changed, update decoding port info */ 
    1265                 if (stream->info.codec_info.clock_rate % ts_diff == 0) { 
    1266                     vfd->fps.num = stream->info.codec_info.clock_rate/ts_diff; 
    1267                     vfd->fps.denum = 1; 
    1268                 } else { 
    1269                     vfd->fps.num = stream->info.codec_info.clock_rate; 
    1270                     vfd->fps.denum = ts_diff; 
    1271                 } 
    1272  
    1273                 /* Update stream info */ 
    1274                 stream->info.codec_param->dec_fmt.det.vid.fps = vfd->fps; 
    1275  
    1276                 /* Update the decoding delay as FPS updated */ 
     1275                pjmedia_video_format_detail *vfd; 
     1276                vfd = pjmedia_format_get_video_format_detail( 
     1277                                        &channel->port.info.fmt, PJ_TRUE); 
     1278 
     1279                /* Update FPS in channel & stream info */ 
     1280                vfd->fps = new_fps; 
     1281                stream->info.codec_param->dec_fmt.det.vid.fps = new_fps; 
     1282 
     1283                /* Update the decoding delay */ 
    12771284                { 
    12781285                    pjmedia_jb_state jb_state; 
     
    12901297                } 
    12911298 
    1292                 /* Publish PJMEDIA_EVENT_FMT_CHANGED event if frame rate 
    1293                  * increased and not exceeding 100fps. 
    1294                  */ 
    1295                 if (vfd->fps.num/vfd->fps.denum <= 100 && 
    1296                     vfd->fps.num * stream->dec_max_fps.denum > 
    1297                     stream->dec_max_fps.num * vfd->fps.denum) 
     1299                /* Publish PJMEDIA_EVENT_FMT_CHANGED event */ 
    12981300                { 
    12991301                    pjmedia_event *event = &stream->fmt_event; 
     
    21162118    if ((dir & PJMEDIA_DIR_ENCODING) && stream->enc) { 
    21172119        stream->enc->paused = 0; 
     2120        stream->force_keyframe = PJ_TRUE; 
    21182121        PJ_LOG(4,(stream->enc->port.info.name.ptr, "Encoder stream resumed")); 
    21192122    } 
     
    21212124    if ((dir & PJMEDIA_DIR_DECODING) && stream->dec) { 
    21222125        stream->dec->paused = 0; 
     2126        stream->last_dec_seq = 0; 
    21232127        PJ_LOG(4,(stream->dec->port.info.name.ptr, "Decoder stream resumed")); 
    21242128    } 
Note: See TracChangeset for help on using the changeset viewer.