summaryrefslogtreecommitdiff
path: root/cmdutils.c
diff options
context:
space:
mode:
authorAlexander Strange <astrange@ithinksw.com>2010-09-28 02:05:12 +0000
committerAlexander Strange <astrange@ithinksw.com>2010-09-28 02:05:12 +0000
commit7a8bfa5d674922d4413d403b059fe183deb7ddbe (patch)
treeefaf3df8c3aa8f3d7eb47fdfa4828c86b2fcdcf1 /cmdutils.c
parent6d19fd5c26cc2971a9925376f52e57c286d2326b (diff)
downloadffmpeg-7a8bfa5d674922d4413d403b059fe183deb7ddbe.tar.gz
Extract timestamp correction code from ffplay.c to cmdutils.c
Originally committed as revision 25241 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'cmdutils.c')
-rw-r--r--cmdutils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/cmdutils.c b/cmdutils.c
index 762537aa75..864d772213 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -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;
+}