From 439a71eb8cb9c57462b3c5a5686a8c0d067213e7 Mon Sep 17 00:00:00 2001 From: Isaac Richards Date: Sat, 28 Jun 2003 04:44:30 +0000 Subject: [PATCH] Some minor enhancements to the libavformat decoder class. Lemme know if this hurts playback of pvr-250 produced mpeg2 files. git-svn-id: http://svn.mythtv.org/svn/trunk@1765 7dbf422c-18fa-0310-86e9-fd20926502f2 --- mythtv/libs/libavformat/mov.c | 3 +++ mythtv/libs/libmythtv/NuppelVideoPlayer.cpp | 10 ++++--- mythtv/libs/libmythtv/NuppelVideoPlayer.h | 3 ++- mythtv/libs/libmythtv/avformatdecoder.cpp | 30 +++++++++++++-------- mythtv/libs/libmythtv/avformatdecoder.h | 2 ++ mythtv/libs/libmythtv/tv_play.cpp | 1 + mythtv/libs/libmythtv/videoout_xv.cpp | 14 +++++++--- mythtv/libs/libmythtv/videoout_xv.h | 6 +++-- 8 files changed, 49 insertions(+), 20 deletions(-) diff --git a/mythtv/libs/libavformat/mov.c b/mythtv/libs/libavformat/mov.c index 176232bbe83..803facbff17 100644 --- a/mythtv/libs/libavformat/mov.c +++ b/mythtv/libs/libavformat/mov.c @@ -1442,6 +1442,9 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) else atom.size = 0x7FFFFFFFFFFFFFFFLL; + if (atom.size == 0) + atom.size = 0x7FFFFFFFFFFFFFFFLL; + #ifdef DEBUG printf("filesz=%Ld\n", atom.size); #endif diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp index 2a5d0a7cbd7..34c854eb231 100644 --- a/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp +++ b/mythtv/libs/libmythtv/NuppelVideoPlayer.cpp @@ -53,6 +53,7 @@ NuppelVideoPlayer::NuppelVideoPlayer(QSqlDatabase *ldb, video_width = 0; video_size = 0; text_size = 0; + video_aspect = 1.33333; decoder = NULL; @@ -282,8 +283,9 @@ void NuppelVideoPlayer::InitVideo(void) } videoOutput = new XvVideoOutput(); - videoOutput->Init(video_width, video_height, MAXVBUFFER + 1, vbuffer, - widget->winId(), 0, 0, widget->width(), widget->height(), + videoOutput->Init(video_width, video_height, video_aspect, + MAXVBUFFER + 1, vbuffer, widget->winId(), + 0, 0, widget->width(), widget->height(), embedid); if (embedid > 0) { @@ -292,7 +294,7 @@ void NuppelVideoPlayer::InitVideo(void) } void NuppelVideoPlayer::SetVideoParams(int width, int height, double fps, - int keyframedistance) + int keyframedistance, float aspect) { if (width > 0) video_width = width; @@ -303,6 +305,8 @@ void NuppelVideoPlayer::SetVideoParams(int width, int height, double fps, video_size = video_height * video_width * 3 / 2; keyframedist = keyframedistance; + + video_aspect = aspect; } void NuppelVideoPlayer::SetFileLength(int total, int frames) diff --git a/mythtv/libs/libmythtv/NuppelVideoPlayer.h b/mythtv/libs/libmythtv/NuppelVideoPlayer.h index a9fb2d82b30..1598df51fbf 100644 --- a/mythtv/libs/libmythtv/NuppelVideoPlayer.h +++ b/mythtv/libs/libmythtv/NuppelVideoPlayer.h @@ -132,7 +132,7 @@ class NuppelVideoPlayer // decoder stuff.. void SetVideoParams(int width, int height, double fps, - int keyframedistance); + int keyframedistance, float aspect = 1.33333); void SetAudioParams(int bps, int channels, int samplerate); void SetEffDsp(int dsprate); void SetFileLength(int total, int frames); @@ -226,6 +226,7 @@ class NuppelVideoPlayer int video_height; int video_size; double video_frame_rate; + float video_aspect; int filesize; int startpos; diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp index 75b1d59cb51..0b1af3b1a2c 100644 --- a/mythtv/libs/libmythtv/avformatdecoder.cpp +++ b/mythtv/libs/libmythtv/avformatdecoder.cpp @@ -260,8 +260,12 @@ int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo, if (fps < 26 && fps > 24) keyframedist = 12; + float aspect_ratio = enc->aspect_ratio; + if (aspect_ratio <= 0.0) + aspect_ratio = (float)enc->width / (float)enc->height; + m_parent->SetVideoParams(enc->width, enc->height, fps, - keyframedist); + keyframedist, aspect_ratio); enc->error_resilience = 2; enc->workaround_bugs = FF_BUG_AUTODETECT; @@ -319,6 +323,8 @@ int AvFormatDecoder::OpenFile(RingBuffer *rbuffer, bool novideo, } } + ptsmultiplier = ((double)ic->pts_num) / (ic->pts_den / 1000.0); + ringBuffer->CalcReadAheadThresh(bitrate); if (m_playbackinfo && m_db) @@ -432,6 +438,7 @@ void AvFormatDecoder::GetFrame(int onlyvideo) unsigned char *ptr; short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2]; int data_size = 0; + long long temppts; bool gotvideo = false; @@ -516,18 +523,19 @@ void AvFormatDecoder::GetFrame(int onlyvideo) continue; } - if (lastapts != pkt.pts && pkt.pts > 0 && validvpts) + temppts = (long long)((double)pkt.pts * ptsmultiplier); + + if (lastapts != temppts && temppts > 0 && validvpts) { - lastapts = pkt.pts; + lastapts = temppts; } else { - lastapts += (long long)((double)((data_size * 90.0) / - audio_sample_size / audio_sampling_rate) - * 1000); + lastapts += (long long)((double)(data_size * 1000) / + audio_sample_size / audio_sampling_rate); } m_parent->AddAudioData((char *)samples, data_size, - lastapts / 90); + lastapts); break; } case CODEC_TYPE_VIDEO: @@ -590,14 +598,14 @@ void AvFormatDecoder::GetFrame(int onlyvideo) if (pkt.pts > 0) { validvpts = true; - newvpts = (long long int)(pkt.pts * 1.0 * - ic->pts_num / (ic->pts_den / 1000)); + newvpts = (long long)((double)pkt.pts * + ptsmultiplier); } - else + else if (context->codec_id == CODEC_ID_MPEG1VIDEO) { // guess, based off of the audio timestamp and // the prebuffer size - newvpts = lastapts / 90 + (int)(1000.0 / fps) * 3; + newvpts = lastapts + (int)(1000.0 / fps) * 3; } if (newvpts <= lastvpts) diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h index 9b1453d7d4e..be1fda69147 100644 --- a/mythtv/libs/libmythtv/avformatdecoder.h +++ b/mythtv/libs/libmythtv/avformatdecoder.h @@ -99,6 +99,8 @@ class AvFormatDecoder : public DecoderBase double fps; bool validvpts; + + double ptsmultiplier; }; #endif diff --git a/mythtv/libs/libmythtv/tv_play.cpp b/mythtv/libs/libmythtv/tv_play.cpp index afcd7ed8888..708796549a0 100644 --- a/mythtv/libs/libmythtv/tv_play.cpp +++ b/mythtv/libs/libmythtv/tv_play.cpp @@ -138,6 +138,7 @@ void TV::Init(bool createWindow) myWindow->installEventFilter(this); myWindow->setNoErase(); myWindow->show(); + myWindow->setBackgroundColor(Qt::black); qApp->processEvents(); } diff --git a/mythtv/libs/libmythtv/videoout_xv.cpp b/mythtv/libs/libmythtv/videoout_xv.cpp index 2530a788744..fae2358ce90 100644 --- a/mythtv/libs/libmythtv/videoout_xv.cpp +++ b/mythtv/libs/libmythtv/videoout_xv.cpp @@ -100,7 +100,7 @@ int XvVideoOutput::GetRefreshRate(void) return (int)rate; } -bool XvVideoOutput::Init(int width, int height, int num_buffers, +bool XvVideoOutput::Init(int width, int height, float aspect, int num_buffers, unsigned char **out_buffers, unsigned int winid, int winx, int winy, int winw, int winh, unsigned int embedid) @@ -120,6 +120,8 @@ bool XvVideoOutput::Init(int width, int height, int num_buffers, XJ_width = width; XJ_height = height; + XJ_aspect = aspect; + XInitThreads(); data->XJ_disp = XOpenDisplay(NULL); @@ -154,7 +156,7 @@ bool XvVideoOutput::Init(int width, int height, int num_buffers, printf("Over/underscanning. V: %f, H: %f, XOff: %d, YOff: %d\n", img_vscanf, img_hscanf, img_xoff, img_yoff); - XJ_aspect = gContext->GetNumSetting("FixedAspectRatio", 0); + XJ_fixedaspect = gContext->GetNumSetting("FixedAspectRatio", 0); XJ_white = XWhitePixel(data->XJ_disp, XJ_screen_num); XJ_black = XBlackPixel(data->XJ_disp, XJ_screen_num); @@ -722,7 +724,7 @@ void XvVideoOutput::ResizeVideo(int x, int y, int w, int h) if (oldx == (x+1) && oldy == (y+1) && oldw == w && oldh == h) return; - if (XJ_aspect) + if (XJ_fixedaspect) { if (w * 3 / 4 > h) { @@ -854,4 +856,10 @@ void XvVideoOutput::MoveResize(void) } } + if (XJ_aspect >= 1.34) + { + int oldheight = disphoff; + disphoff = (int)(dispwoff / XJ_aspect); + dispyoff = (oldheight - disphoff) / 2; + } } diff --git a/mythtv/libs/libmythtv/videoout_xv.h b/mythtv/libs/libmythtv/videoout_xv.h index fe0e4c3ad10..899ddf102b6 100644 --- a/mythtv/libs/libmythtv/videoout_xv.h +++ b/mythtv/libs/libmythtv/videoout_xv.h @@ -9,7 +9,7 @@ class XvVideoOutput XvVideoOutput(); ~XvVideoOutput(); - bool Init(int width, int height, int num_buffers, + bool Init(int width, int height, float aspect, int num_buffers, unsigned char **out_buffers, unsigned int winid, int winx, int winy, int winw, int winh, unsigned int embedid = 0); void PrepareFrame(unsigned char *buffer, int width, int height); @@ -41,7 +41,7 @@ class XvVideoOutput int XJ_screenx, XJ_screeny; int XJ_screenwidth, XJ_screenheight; int XJ_fullscreen; - int XJ_aspect; + int XJ_fixedaspect; int oldx, oldy, oldw, oldh; int curx, cury, curw, curh; @@ -61,6 +61,8 @@ class XvVideoOutput unsigned char *scratchspace; pthread_mutex_t lock; + + float XJ_aspect; }; #endif