Ticket #3045: jerky_video.patch
File jerky_video.patch, 10.9 KB (added by , 19 years ago) |
---|
-
libs/libmythtv/nuppeldecoder.cpp
547 547 if (usingextradata && extradata.video_fourcc == MKTAG('D', 'I', 'V', 'X')) 548 548 setreadahead = true; 549 549 550 ringBuffer->UpdateRawBitrate(0); 550 bitrate = 0; 551 ringBuffer->UpdateRawBitrate(GetRawBitrate()); 551 552 552 553 videosizetotal = 0; 553 554 videoframesread = 0; … … 1099 1100 { 1100 1101 videosizetotal /= videoframesread; 1101 1102 1102 float bps = videosizetotal * 8.0 / 1024 * video_frame_rate; 1103 bps = bps * 3 / 2; 1103 float bps = (videosizetotal * 8.0f / 1024.0f * 1104 video_frame_rate); 1105 bitrate = (uint) (bps * 1.5f); 1104 1106 1105 ringBuffer->UpdateRawBitrate( (uint) bps);1107 ringBuffer->UpdateRawBitrate(GetRawBitrate()); 1106 1108 setreadahead = true; 1107 1109 } 1108 1110 } -
libs/libmythtv/NuppelVideoPlayer.cpp
2844 2844 return; 2845 2845 } 2846 2846 2847 // the bitrate is reset by ringBuffer->OpenFile()... 2848 ringBuffer->UpdateRawBitrate(GetDecoder()->GetRawBitrate()); 2849 2847 2850 ringBuffer->Unpause(); 2848 2851 2849 2852 if (discontinuity || newtype) … … 2949 2952 return; 2950 2953 } 2951 2954 2955 // the bitrate is reset by ringBuffer->OpenFile()... 2956 ringBuffer->UpdateRawBitrate(GetDecoder()->GetRawBitrate()); 2957 2952 2958 ringBuffer->Unpause(); 2953 2959 ringBuffer->IgnoreLiveEOF(false); 2954 2960 … … 3464 3470 3465 3471 timecode += tc_wrap[tc_type]; 3466 3472 3473 #define DOTCWRAP 0 3474 #if DOTCWRAP 3467 3475 // wrapped 3468 3476 if (timecode < tc_lastval[tc_type] - 10000) 3469 3477 { … … 3500 3508 tc_avcheck_framecounter = 0; 3501 3509 } 3502 3510 } 3511 #endif 3503 3512 } 3504 3513 3505 3514 /** \fn NuppelVideoPlayer::AddAudioData(char*,int,long long) -
libs/libmythtv/avformatdecoder.cpp
266 266 ic(NULL), 267 267 frame_decoded(0), decoded_video_frame(NULL), 268 268 directrendering(false), drawband(false), 269 bitrate(0),270 269 gopset(false), seen_gop(false), 271 270 seq_count(0), firstgoppos(0), 272 271 prevgoppos(0), gotvideo(false), -
libs/libmythtv/decoderbase.h
79 79 80 80 virtual QString GetEncodingType(void) const = 0; 81 81 virtual double GetFPS(void) const { return fps; } 82 /// Returns the estimated bitrate if the video were played at normal speed. 83 uint GetRawBitrate(void) const { return bitrate; } 82 84 83 85 virtual void UpdateFramesPlayed(void); 84 86 long long GetFramesRead(void) const { return framesRead; }; … … 163 165 int current_height; 164 166 float current_aspect; 165 167 double fps; 168 uint bitrate; 166 169 167 170 long long framesPlayed; 168 171 long long framesRead; -
libs/libmythtv/RingBuffer.cpp
7 7 // POSIX C headers 8 8 #include <sys/types.h> 9 9 #include <sys/stat.h> 10 #include <sys/time.h> 10 11 #include <unistd.h> 11 12 #include <fcntl.h> 12 13 #include <pthread.h> … … 39 40 #define O_LARGEFILE 0 40 41 #endif 41 42 42 const uint RingBuffer::kBufferSize = 10 * 256* 1024;43 const uint RingBuffer::kBufferSize = 3 * 1024 * 1024; 43 44 45 #define CHUNK 32768 /* readblocksize increments */ 46 44 47 #define PNG_MIN_SIZE 20 /* header plus one empty chunk */ 45 48 #define NUV_MIN_SIZE 204 /* header size? */ 46 49 #define MPEG_MIN_SIZE 376 /* 2 TS packets */ … … 92 95 internalreadpos(0), ateof(false), 93 96 readsallowed(false), wantseek(false), setswitchtonext(false), 94 97 rawbitrate(4000), playspeed(1.0f), 95 fill_threshold( -1),fill_min(-1),96 readblocksize( 128000),wanttoread(0),98 fill_threshold(65536), fill_min(-1), 99 readblocksize(CHUNK), wanttoread(0), 97 100 numfailures(0), commserror(false), 98 101 dvdPriv(NULL), oldfile(false), 99 102 livetvchain(NULL), ignoreliveeof(false), … … 534 537 */ 535 538 void RingBuffer::CalcReadAheadThresh(void) 536 539 { 537 const uint KB32 = 32*1024;538 const uint KB64 = 64*1024;539 const uint KB128 = 128*1024;540 const uint KB256 = 256*1024;541 const uint KB512 = 512*1024;542 540 uint estbitrate; 543 541 544 wantseek = true;545 542 pthread_rwlock_wrlock(&rwlock); 546 547 estbitrate = (uint) max(abs(rawbitrate * playspeed), 0.5f * rawbitrate);548 estbitrate = min(rawbitrate * 3, estbitrate);549 543 wantseek = false; 550 544 readsallowed = false; 545 readblocksize = CHUNK; 546 547 // loop without sleeping if the buffered data is less than this 548 fill_threshold = CHUNK * 2; 551 549 fill_min = 1; 552 readblocksize = (estbitrate > 2500) ? KB64 : KB32;553 readblocksize = (estbitrate > 5000) ? KB128 : readblocksize;554 readblocksize = (estbitrate > 9000) ? KB256 : readblocksize;555 readblocksize = (estbitrate > 18000) ? KB512 : readblocksize;556 550 557 uint secs_thr = 300; // seconds of buffering desired 558 float secs_min = 0.1; // minumum seconds of buffering before allowing read 551 #ifdef USING_FRONTEND 552 if (dvdPriv) 553 { 554 const uint KB32 = 32*1024; 555 const uint KB64 = 64*1024; 556 const uint KB128 = 128*1024; 557 const uint KB256 = 256*1024; 558 const uint KB512 = 512*1024; 559 559 560 // set basic fill_threshold based on bitrate 561 fill_threshold = (estbitrate * secs_thr) >> 3; // >>3 => bits -> bytes 562 // extra buffering for remote files 563 fill_threshold = fill_threshold + ((remotefile) ? KB256 : 0); 564 // make the fill_threshold at least one block 565 fill_threshold = max(readblocksize, fill_threshold); 560 estbitrate = (uint) max(abs(rawbitrate * playspeed), 561 0.5f * rawbitrate); 562 estbitrate = min(rawbitrate * 3, estbitrate); 563 readblocksize = (estbitrate > 2500) ? KB64 : KB32; 564 readblocksize = (estbitrate > 5000) ? KB128 : readblocksize; 565 readblocksize = (estbitrate > 9000) ? KB256 : readblocksize; 566 readblocksize = (estbitrate > 18000) ? KB512 : readblocksize; 566 567 567 // set the minimum buffering before allowing ffmpeg read 568 fill_min = (uint) ((estbitrate * secs_min) * 0.125f); 569 // make this a multiple of ffmpeg block size.. 570 fill_min = ((fill_min / KB32) + 1) * KB32; 568 // minumum seconds of buffering before allowing read 569 float secs_min = 0.1; 571 570 571 // set the minimum buffering before allowing ffmpeg read 572 fill_min = (uint) ((estbitrate * secs_min) * 0.125f); 573 // make this a multiple of ffmpeg block size.. 574 fill_min = ((fill_min / KB32) + 1) * KB32; 575 } 576 #endif // USING_FRONTEND 577 578 pthread_rwlock_unlock(&rwlock); 579 572 580 VERBOSE(VB_PLAYBACK, LOC + 573 581 QString("CalcReadAheadThresh(%1 KB)\n\t\t\t -> " 574 582 "threshhold(%2 KB) min read(%3 KB) blk size(%4 KB)") 575 583 .arg(estbitrate).arg(fill_threshold/1024) 576 584 .arg(fill_min/1024).arg(readblocksize/1024)); 577 578 pthread_rwlock_unlock(&rwlock);579 585 } 580 586 581 587 /** \fn RingBuffer::ReadBufFree(void) const … … 611 617 void RingBuffer::ResetReadAhead(long long newinternal) 612 618 { 613 619 readAheadLock.lock(); 620 readblocksize = CHUNK; 614 621 rbrpos = 0; 615 622 rbwpos = 0; 616 623 internalreadpos = newinternal; … … 722 729 int used = 0; 723 730 int loops = 0; 724 731 732 struct timeval lastread, now; 733 gettimeofday(&lastread, NULL); 734 const int KB640 = 640*1024; 735 int readtimeavg = 300; 736 int readinterval; 737 725 738 pausereadthread = false; 726 739 727 readAheadBuffer = new char[kBufferSize + 256000];740 readAheadBuffer = new char[kBufferSize + KB640]; 728 741 729 742 ResetReadAhead(0); 730 743 totfree = ReadBufFree(); … … 768 781 // limit the read size 769 782 totfree = readblocksize; 770 783 784 // adapt blocksize 785 gettimeofday(&now, NULL); 786 readinterval = (now.tv_sec - lastread.tv_sec ) * 1000 + 787 (now.tv_usec - lastread.tv_usec) / 1000; 788 789 readtimeavg = (readtimeavg * 9 + readinterval) / 10; 790 791 if (readtimeavg < 200 && readblocksize < KB640) 792 { 793 readblocksize += CHUNK; 794 VERBOSE(VB_PLAYBACK, 795 QString("Avg read interval was %1 msec. %2K block size") 796 .arg(readtimeavg).arg(readblocksize/1024)); 797 readtimeavg = 300; 798 } 799 else if (readtimeavg > 400 && readblocksize > CHUNK) 800 { 801 readblocksize -= CHUNK; 802 VERBOSE(VB_PLAYBACK, 803 QString("Avg read interval was %1 msec. %2K block size") 804 .arg(readtimeavg).arg(readblocksize/1024)); 805 readtimeavg = 300; 806 } 807 lastread = now; 808 771 809 if (rbwpos + totfree > kBufferSize) 772 810 totfree = kBufferSize - rbwpos; 773 811 -
libs/libmythtv/decoderbase.cpp
23 23 24 24 current_width(640), current_height(480), 25 25 current_aspect(1.33333), fps(29.97), 26 bitrate(4000), 26 27 27 28 framesPlayed(0), framesRead(0), lastKey(0), keyframedist(-1), 28 29 indexOffset(0), -
libs/libmythtv/avformatdecoder.h
204 204 bool directrendering; 205 205 bool drawband; 206 206 207 int bitrate;208 209 207 bool gopset; 210 208 /// A flag to indicate that we've seen a GOP frame. Used in junction with seq_count. 211 209 bool seen_gop; -
libs/libmythtv/ivtvdecoder.cpp
49 49 { 50 50 lastResetTime.start(); 51 51 fps = 29.97f; 52 bitrate = 8000; 52 53 lastKey = 0; 53 54 } 54 55 … … 277 278 278 279 fps = (ntsc) ? 29.97f : 25.0f; // save for later length calculations 279 280 280 ringBuffer->UpdateRawBitrate( 8000);281 ringBuffer->UpdateRawBitrate(GetRawBitrate()); 281 282 282 283 if (m_playbackinfo || livetv || watchingrecording) 283 284 {