Skip to content

Commit

Permalink
Some minor enhancements to the libavformat decoder class. Lemme know …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Isaac Richards committed Jun 28, 2003
1 parent a5c6596 commit 439a71e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 20 deletions.
3 changes: 3 additions & 0 deletions mythtv/libs/libavformat/mov.c
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
Expand Up @@ -53,6 +53,7 @@ NuppelVideoPlayer::NuppelVideoPlayer(QSqlDatabase *ldb,
video_width = 0;
video_size = 0;
text_size = 0;
video_aspect = 1.33333;

decoder = NULL;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/NuppelVideoPlayer.h
Expand Up @@ -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);
Expand Down Expand Up @@ -226,6 +226,7 @@ class NuppelVideoPlayer
int video_height;
int video_size;
double video_frame_rate;
float video_aspect;

int filesize;
int startpos;
Expand Down
30 changes: 19 additions & 11 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/avformatdecoder.h
Expand Up @@ -99,6 +99,8 @@ class AvFormatDecoder : public DecoderBase

double fps;
bool validvpts;

double ptsmultiplier;
};

#endif
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -138,6 +138,7 @@ void TV::Init(bool createWindow)
myWindow->installEventFilter(this);
myWindow->setNoErase();
myWindow->show();
myWindow->setBackgroundColor(Qt::black);
qApp->processEvents();
}

Expand Down
14 changes: 11 additions & 3 deletions mythtv/libs/libmythtv/videoout_xv.cpp
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
6 changes: 4 additions & 2 deletions mythtv/libs/libmythtv/videoout_xv.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -61,6 +61,8 @@ class XvVideoOutput
unsigned char *scratchspace;

pthread_mutex_t lock;

float XJ_aspect;
};

#endif

0 comments on commit 439a71e

Please sign in to comment.