Ticket #971: rb-switch-dbg.patch

File rb-switch-dbg.patch, 9.9 KB (added by danielk, 15 years ago)

debugging patch

  • libs/libmythtv/NuppelVideoPlayer.h

     
    141141    bool    IsPlaying(void) const             { return playing; }
    142142    bool    AtNormalSpeed(void) const         { return next_normal_speed; }
    143143    bool    IsDecoderThreadAlive(void) const  { return decoder_thread_alive; }
     144    bool    IsReallyNearEnd(void) const;
    144145    bool    IsNearEnd(long long framesRemaining = -1) const;
    145146    bool    PlayingSlowForPrebuffer(void) const { return m_playing_slower; }
    146147    bool    HasAudioIn(void) const            { return !no_audio_in; }
  • libs/libmythtv/nuppeldecoder.cpp

     
    541541    if (usingextradata && extradata.video_fourcc == MKTAG('D', 'I', 'V', 'X'))
    542542        setreadahead = true;
    543543
    544     ringBuffer->CalcReadAheadThresh(0);
     544    ringBuffer->UpdateRawBitrate(0);
    545545
    546546    videosizetotal = 0;
    547547    videoframesread = 0;
     
    10831083                    float bps = videosizetotal * 8.0 / 1024 * video_frame_rate;
    10841084                    bps = bps * 3 / 2;
    10851085
    1086                     ringBuffer->CalcReadAheadThresh((int)bps);
     1086                    ringBuffer->UpdateRawBitrate((uint) bps);
    10871087                    setreadahead = true;
    10881088                }
    10891089            }
  • libs/libmythtv/NuppelVideoPlayer.cpp

     
    21452145
    21462146void NuppelVideoPlayer::SwitchToProgram(void)
    21472147{
    2148     if (videoOutput)
    2149     {
    2150         int  sz  = ringBuffer->DataInReadAhead();
    2151         uint vvf = videoOutput->ValidVideoFrames();
    2152         if ((vvf > 3 && sz > 128000) || (sz > 256000))
    2153             return;
    2154     }
     2148    if (!IsReallyNearEnd())
     2149        return;
     2150    VERBOSE(VB_IMPORTANT, "SwitchToProgram(void)");
    21552151
    21562152    bool discontinuity = false, newtype = false;
    21572153    ProgramInfo *pginfo = livetvchain->GetSwitchProgram(discontinuity, newtype);
     
    22422238
    22432239void NuppelVideoPlayer::JumpToProgram(void)
    22442240{
     2241    VERBOSE(VB_IMPORTANT, "JumpToProgram(void)");
    22452242    bool discontinuity = false, newtype = false;
    22462243    ProgramInfo *pginfo = livetvchain->GetSwitchProgram(discontinuity, newtype);
    22472244    if (!pginfo)
     
    24872484                decoderThreadPaused.wakeAll();
    24882485            }
    24892486            else
     2487            {
     2488                ringBuffer->UpdatePlaySpeed(play_speed);
    24902489                DoPlay();
     2490            }
    24912491
    24922492            decoder_lock.unlock();
    24932493            continue;
     
    31623162    return ret;
    31633163}
    31643164
     3165/** \fn NuppelVideoPlayer::IsReallyNearEnd(void) const
     3166 *  \brief Returns true iff really near end of recording.
     3167 *
     3168 *   This is used by SwitchToProgram() to determine if we are so
     3169 *   close to the end that we need to switch to the next program.
     3170 */
     3171bool NuppelVideoPlayer::IsReallyNearEnd(void) const
     3172{
     3173    if (!videoOutput)
     3174        return false;
     3175
     3176    int  sz  = ringBuffer->DataInReadAhead();
     3177    uint vvf = videoOutput->ValidVideoFrames();
     3178
     3179    uint kbytes_per_sec = ringBuffer->GetBitrate() / 8;
     3180    double inv_fps = 1.0 / GetDecoder()->GetFPS();
     3181    double bytes_per_frame = kbytes_per_sec * 1000 * inv_fps;
     3182    double rh_frames = sz / bytes_per_frame;
     3183
     3184    bool near_end = !((vvf > 3 && sz > 128000) || (sz > 256000));
     3185    //bool near_end = (vvf + rh_frames < 10);
     3186
     3187    VERBOSE(VB_IMPORTANT, LOC + "IsReallyNearEnd()"
     3188            <<" br("<<kbytes_per_sec<<"KB)"
     3189            <<" sz("<<(sz / 1000)<<"KB)"
     3190            <<" vfl("<<vvf<<")"
     3191            <<" fps("<<((uint)(1.0/inv_fps))<<")"
     3192            <<" frh("<<((uint)rh_frames)<<")"
     3193            <<" ne:"<<near_end);
     3194
     3195    return near_end;
     3196}
     3197
    31653198/** \fn NuppelVideoPlayer::IsNearEnd(long long) const
    31663199 *  \brief Returns true iff near end of recording.
    31673200 *  \param margin minimum number of frames we want before being near end,
  • libs/libmythtv/RingBuffer.cpp

     
    8686      rbrpos(0),                rbwpos(0),
    8787      internalreadpos(0),       ateof(false),
    8888      readsallowed(false),      wantseek(false),
     89      last_rawbitrate(8000),    last_playspeed(1.0f),
    8990      fill_threshold(-1),       fill_min(-1),
    9091      readblocksize(128000),    wanttoread(0),
    9192      numfailures(0),           commserror(false),
     
    443444    return ret;
    444445}
    445446
    446 /** \fn RingBuffer::CalcReadAheadThresh(uint)
    447  *  \brief Calculates fill_min, fill_threshold, and readblocksize from
    448  *         the estimated bitrate of the stream.
     447/** \fn RingBuffer::UpdateRawBitrate(uint)
    449448 *  \param estbitrate Streams average number of kilobits per second.
    450449 */
    451 void RingBuffer::CalcReadAheadThresh(uint estbitrate)
     450void RingBuffer::UpdateRawBitrate(uint rawbitrate)
    452451{
     452    pthread_rwlock_wrlock(&rwlock);
     453    last_rawbitrate = rawbitrate;
     454    pthread_rwlock_unlock(&rwlock);
     455    CalcReadAheadThresh();
     456}
     457
     458uint RingBuffer::GetBitrate(void) const
     459{
     460    //pthread_rwlock_wrlock(&rwlock);
     461    uint estrate = (uint) (last_rawbitrate * last_playspeed);
     462    //pthread_rwlock_unlock(&rwlock);
     463
     464    return estrate;
     465}
     466
     467/** \fn RingBuffer::UpdatePlaySpeed(float)
     468 *  \param estbitrate Streams average number of kilobits per second.
     469 */
     470void RingBuffer::UpdatePlaySpeed(float playspeed)
     471{
     472    pthread_rwlock_wrlock(&rwlock);
     473    last_playspeed = playspeed;
     474    pthread_rwlock_unlock(&rwlock);
     475    CalcReadAheadThresh();
     476}
     477
     478/** \fn RingBuffer::CalcReadAheadThresh(void)
     479 *  \brief Calculates fill_min, fill_threshold, and readblocksize
     480 *         from the estimated bitrate of the stream.
     481 */
     482void RingBuffer::CalcReadAheadThresh(void)
     483{
     484    const uint KB128 = 128*1024;
     485    const uint KB256 = 256*1024;
     486    const uint KB512 = 512*1024;
     487
    453488    wantseek = true;
    454489    pthread_rwlock_wrlock(&rwlock);
    455490
     491    uint estbitrate = GetBitrate();
     492
    456493    wantseek       = false;
    457494    readsallowed   = false;
    458495    fill_min       = 1;
    459     readblocksize  = (estbitrate > 12000) ? 256000 : 128000;
     496    readblocksize  = (estbitrate > 12000) ? KB256 : KB128;
    460497
    461498#if 1
    462499    fill_threshold = 0;
    463500
    464501    if (remotefile)
    465         fill_threshold += 256000;
     502        fill_threshold += KB256;
    466503
    467504    if (estbitrate > 6000)
    468         fill_threshold += 256000;
     505        fill_threshold += KB256;
    469506
    470507    if (estbitrate > 10000)
    471         fill_threshold += 256000;
     508        fill_threshold += KB256;
    472509
    473510    if (estbitrate > 12000)
    474         fill_threshold += 256000;
     511        fill_threshold += KB256;
    475512
    476513    fill_threshold = (fill_threshold) ? fill_threshold : -1;
    477514#else
    478     fill_threshold = (remotefile) ? 256000 : 0;
     515    fill_threshold = (remotefile) ? KB256 : 0;
    479516    fill_threshold = max(0, estbitrate) * 60*10;
    480517    fill_threshold = (fill_threshold) ? fill_threshold : -1;
    481518#endif
  • libs/libmythtv/avformatdecoder.cpp

     
    11721172
    11731173    if (bitrate > 0)
    11741174    {
    1175         bitrate /= 1000;
     1175        bitrate = (bitrate + 999) / 1000;
    11761176        if (ringBuffer)
    1177             ringBuffer->CalcReadAheadThresh(bitrate);
     1177            ringBuffer->UpdateRawBitrate(bitrate);
    11781178    }
    11791179
    11801180    // Select a new track at the next opportunity.
  • libs/libmythtv/decoderbase.h

     
    5252    virtual long UpdateStoredFrameNum(long frame) = 0;
    5353
    5454    virtual QString GetEncodingType(void) const = 0;
     55    virtual double  GetFPS(void) const { return fps; }
    5556
    5657    virtual void UpdateFramesPlayed(void);
    5758    long long GetFramesRead(void) const { return framesRead; };
  • libs/libmythtv/RingBuffer.h

     
    2222    // Sets
    2323    void SetWriteBufferSize(int newSize);
    2424    void SetWriteBufferMinWriteSize(int newMinSize);
    25     void CalcReadAheadThresh(uint estbitrate);
     25    void UpdateRawBitrate(uint rawbitrate);
     26    void UpdatePlaySpeed(float playspeed);
    2627
    2728    // Gets
    2829    /// Returns name of file used by this RingBuffer
     
    3940    long long GetReadPosition(void)  const;
    4041    long long GetWritePosition(void) const;
    4142    long long GetRealFileSize(void)  const;
     43    uint      GetBitrate(void)       const;
    4244    bool      IsOpen(void)           const;
    4345
    4446    // General Commands
     
    9092    void ReadAheadThread(void);
    9193
    9294  private:
     95    void CalcReadAheadThresh(void);
    9396    int safe_read_dvd(void *data, uint sz);
    9497    int safe_read(int fd, void *data, uint sz);
    9598    int safe_read(RemoteFile *rf, void *data, uint sz);
     
    136139    bool ateof;
    137140    bool readsallowed;
    138141    bool wantseek;
    139     int fill_threshold;
    140     int fill_min;
    141142
    142     int readblocksize;
     143    uint  last_rawbitrate;
     144    float last_playspeed;
     145    int   fill_threshold;
     146    int   fill_min;
     147    int   readblocksize;
    143148
    144149    QWaitCondition pauseWait;
    145150
  • libs/libmythtv/ivtvdecoder.cpp

     
    268268    GetNVP()->SetVideoParams(720 /*width*/, (ntsc) ? 480 : 576 /*height*/,
    269269                             (ntsc) ? 29.97f : 25.0f, keyframedist, 1.33);
    270270     
    271     ringBuffer->CalcReadAheadThresh(8000);
     271    ringBuffer->UpdateRawBitrate(8000);
    272272
    273273    if (m_playbackinfo || livetv || watchingrecording)
    274274    {