Extract timestamp correction code from ffplay.c to cmdutils.c

Originally committed as revision 25241 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Alexander Strange 2010-09-28 02:05:12 +00:00
parent 6d19fd5c26
commit 7a8bfa5d67
3 changed files with 63 additions and 23 deletions

View file

@ -677,3 +677,30 @@ int read_file(const char *filename, char **bufptr, size_t *size)
fclose(f);
return 0;
}
void init_pts_correction(PtsCorrectionContext *ctx)
{
ctx->num_faulty_pts = ctx->num_faulty_dts = 0;
ctx->last_pts = ctx->last_dts = INT64_MIN;
}
int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts)
{
int64_t pts = AV_NOPTS_VALUE;
if (dts != AV_NOPTS_VALUE) {
ctx->num_faulty_dts += dts <= ctx->last_dts;
ctx->last_dts = dts;
}
if (reordered_pts != AV_NOPTS_VALUE) {
ctx->num_faulty_pts += reordered_pts <= ctx->last_pts;
ctx->last_pts = reordered_pts;
}
if ((ctx->num_faulty_pts<ctx->num_faulty_dts || dts == AV_NOPTS_VALUE)
&& reordered_pts != AV_NOPTS_VALUE)
pts = reordered_pts;
else
pts = dts;
return pts;
}