Ticket #971: rb-switch-dbg.patch
File rb-switch-dbg.patch, 9.9 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/NuppelVideoPlayer.h
141 141 bool IsPlaying(void) const { return playing; } 142 142 bool AtNormalSpeed(void) const { return next_normal_speed; } 143 143 bool IsDecoderThreadAlive(void) const { return decoder_thread_alive; } 144 bool IsReallyNearEnd(void) const; 144 145 bool IsNearEnd(long long framesRemaining = -1) const; 145 146 bool PlayingSlowForPrebuffer(void) const { return m_playing_slower; } 146 147 bool HasAudioIn(void) const { return !no_audio_in; } -
libs/libmythtv/nuppeldecoder.cpp
541 541 if (usingextradata && extradata.video_fourcc == MKTAG('D', 'I', 'V', 'X')) 542 542 setreadahead = true; 543 543 544 ringBuffer-> CalcReadAheadThresh(0);544 ringBuffer->UpdateRawBitrate(0); 545 545 546 546 videosizetotal = 0; 547 547 videoframesread = 0; … … 1083 1083 float bps = videosizetotal * 8.0 / 1024 * video_frame_rate; 1084 1084 bps = bps * 3 / 2; 1085 1085 1086 ringBuffer-> CalcReadAheadThresh((int)bps);1086 ringBuffer->UpdateRawBitrate((uint) bps); 1087 1087 setreadahead = true; 1088 1088 } 1089 1089 } -
libs/libmythtv/NuppelVideoPlayer.cpp
2145 2145 2146 2146 void NuppelVideoPlayer::SwitchToProgram(void) 2147 2147 { 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)"); 2155 2151 2156 2152 bool discontinuity = false, newtype = false; 2157 2153 ProgramInfo *pginfo = livetvchain->GetSwitchProgram(discontinuity, newtype); … … 2242 2238 2243 2239 void NuppelVideoPlayer::JumpToProgram(void) 2244 2240 { 2241 VERBOSE(VB_IMPORTANT, "JumpToProgram(void)"); 2245 2242 bool discontinuity = false, newtype = false; 2246 2243 ProgramInfo *pginfo = livetvchain->GetSwitchProgram(discontinuity, newtype); 2247 2244 if (!pginfo) … … 2487 2484 decoderThreadPaused.wakeAll(); 2488 2485 } 2489 2486 else 2487 { 2488 ringBuffer->UpdatePlaySpeed(play_speed); 2490 2489 DoPlay(); 2490 } 2491 2491 2492 2492 decoder_lock.unlock(); 2493 2493 continue; … … 3162 3162 return ret; 3163 3163 } 3164 3164 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 */ 3171 bool 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 3165 3198 /** \fn NuppelVideoPlayer::IsNearEnd(long long) const 3166 3199 * \brief Returns true iff near end of recording. 3167 3200 * \param margin minimum number of frames we want before being near end, -
libs/libmythtv/RingBuffer.cpp
86 86 rbrpos(0), rbwpos(0), 87 87 internalreadpos(0), ateof(false), 88 88 readsallowed(false), wantseek(false), 89 last_rawbitrate(8000), last_playspeed(1.0f), 89 90 fill_threshold(-1), fill_min(-1), 90 91 readblocksize(128000), wanttoread(0), 91 92 numfailures(0), commserror(false), … … 443 444 return ret; 444 445 } 445 446 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) 449 448 * \param estbitrate Streams average number of kilobits per second. 450 449 */ 451 void RingBuffer:: CalcReadAheadThresh(uint estbitrate)450 void RingBuffer::UpdateRawBitrate(uint rawbitrate) 452 451 { 452 pthread_rwlock_wrlock(&rwlock); 453 last_rawbitrate = rawbitrate; 454 pthread_rwlock_unlock(&rwlock); 455 CalcReadAheadThresh(); 456 } 457 458 uint 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 */ 470 void 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 */ 482 void RingBuffer::CalcReadAheadThresh(void) 483 { 484 const uint KB128 = 128*1024; 485 const uint KB256 = 256*1024; 486 const uint KB512 = 512*1024; 487 453 488 wantseek = true; 454 489 pthread_rwlock_wrlock(&rwlock); 455 490 491 uint estbitrate = GetBitrate(); 492 456 493 wantseek = false; 457 494 readsallowed = false; 458 495 fill_min = 1; 459 readblocksize = (estbitrate > 12000) ? 256000 : 128000;496 readblocksize = (estbitrate > 12000) ? KB256 : KB128; 460 497 461 498 #if 1 462 499 fill_threshold = 0; 463 500 464 501 if (remotefile) 465 fill_threshold += 256000;502 fill_threshold += KB256; 466 503 467 504 if (estbitrate > 6000) 468 fill_threshold += 256000;505 fill_threshold += KB256; 469 506 470 507 if (estbitrate > 10000) 471 fill_threshold += 256000;508 fill_threshold += KB256; 472 509 473 510 if (estbitrate > 12000) 474 fill_threshold += 256000;511 fill_threshold += KB256; 475 512 476 513 fill_threshold = (fill_threshold) ? fill_threshold : -1; 477 514 #else 478 fill_threshold = (remotefile) ? 256000: 0;515 fill_threshold = (remotefile) ? KB256 : 0; 479 516 fill_threshold = max(0, estbitrate) * 60*10; 480 517 fill_threshold = (fill_threshold) ? fill_threshold : -1; 481 518 #endif -
libs/libmythtv/avformatdecoder.cpp
1172 1172 1173 1173 if (bitrate > 0) 1174 1174 { 1175 bitrate /=1000;1175 bitrate = (bitrate + 999) / 1000; 1176 1176 if (ringBuffer) 1177 ringBuffer-> CalcReadAheadThresh(bitrate);1177 ringBuffer->UpdateRawBitrate(bitrate); 1178 1178 } 1179 1179 1180 1180 // Select a new track at the next opportunity. -
libs/libmythtv/decoderbase.h
52 52 virtual long UpdateStoredFrameNum(long frame) = 0; 53 53 54 54 virtual QString GetEncodingType(void) const = 0; 55 virtual double GetFPS(void) const { return fps; } 55 56 56 57 virtual void UpdateFramesPlayed(void); 57 58 long long GetFramesRead(void) const { return framesRead; }; -
libs/libmythtv/RingBuffer.h
22 22 // Sets 23 23 void SetWriteBufferSize(int newSize); 24 24 void SetWriteBufferMinWriteSize(int newMinSize); 25 void CalcReadAheadThresh(uint estbitrate); 25 void UpdateRawBitrate(uint rawbitrate); 26 void UpdatePlaySpeed(float playspeed); 26 27 27 28 // Gets 28 29 /// Returns name of file used by this RingBuffer … … 39 40 long long GetReadPosition(void) const; 40 41 long long GetWritePosition(void) const; 41 42 long long GetRealFileSize(void) const; 43 uint GetBitrate(void) const; 42 44 bool IsOpen(void) const; 43 45 44 46 // General Commands … … 90 92 void ReadAheadThread(void); 91 93 92 94 private: 95 void CalcReadAheadThresh(void); 93 96 int safe_read_dvd(void *data, uint sz); 94 97 int safe_read(int fd, void *data, uint sz); 95 98 int safe_read(RemoteFile *rf, void *data, uint sz); … … 136 139 bool ateof; 137 140 bool readsallowed; 138 141 bool wantseek; 139 int fill_threshold;140 int fill_min;141 142 142 int readblocksize; 143 uint last_rawbitrate; 144 float last_playspeed; 145 int fill_threshold; 146 int fill_min; 147 int readblocksize; 143 148 144 149 QWaitCondition pauseWait; 145 150 -
libs/libmythtv/ivtvdecoder.cpp
268 268 GetNVP()->SetVideoParams(720 /*width*/, (ntsc) ? 480 : 576 /*height*/, 269 269 (ntsc) ? 29.97f : 25.0f, keyframedist, 1.33); 270 270 271 ringBuffer-> CalcReadAheadThresh(8000);271 ringBuffer->UpdateRawBitrate(8000); 272 272 273 273 if (m_playbackinfo || livetv || watchingrecording) 274 274 {