summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohns <johns98@gmx.net>2015-02-06 09:50:54 +0100
committerJohns <johns98@gmx.net>2015-02-06 09:50:54 +0100
commit4f4d3044792bb5db441e0c648ad86ae082774abf (patch)
tree26c88a847920880c01bb90c9263a78e93d34459b
parent9f134c1b6d7e4a488db9933f489ea2a56ec057b7 (diff)
downloadvdr-plugin-softhddevice-4f4d3044792bb5db441e0c648ad86ae082774abf.tar.gz
vdr-plugin-softhddevice-4f4d3044792bb5db441e0c648ad86ae082774abf.tar.bz2
Use video stream frame rate for A/V sync.
Use the video stream frame rate and not the fixed 50Hz for A/V sync.
-rw-r--r--video.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/video.c b/video.c
index 7f47f5e..3ce1094 100644
--- a/video.c
+++ b/video.c
@@ -446,13 +446,27 @@ static void VideoThreadExit(void); ///< exit/kill video thread
///
/// @note frame->interlaced_frame can't be used for interlace detection
///
-static void VideoSetPts(int64_t * pts_p, int interlaced, const AVFrame * frame)
+static void VideoSetPts(int64_t * pts_p, int interlaced,
+ const AVCodecContext * video_ctx, const AVFrame * frame)
{
int64_t pts;
+ int duration;
+
+ //
+ // Get duration for this frame.
+ // FIXME: using framerate as workaround for av_frame_get_pkt_duration
+ //
+ if (video_ctx->framerate.num != 0 && video_ctx->framerate.den != 0) {
+ duration = 1000 * video_ctx->framerate.den / video_ctx->framerate.num;
+ } else {
+ duration = interlaced ? 40 : 20; // 50Hz -> 20ms default
+ }
+ Debug(4, "video: %d/%d %" PRIx64 " -> %d\n", video_ctx->framerate.den,
+ video_ctx->framerate.num, av_frame_get_pkt_duration(frame), duration);
// update video clock
if (*pts_p != (int64_t) AV_NOPTS_VALUE) {
- *pts_p += interlaced ? 40 * 90 : 20 * 90;
+ *pts_p += duration * 90;
//Info("video: %s +pts\n", Timestamp2String(*pts_p));
}
//av_opt_ptr(avcodec_get_frame_class(), frame, "best_effort_timestamp");
@@ -5257,7 +5271,7 @@ static void VaapiSyncRenderFrame(VaapiDecoder * decoder,
}
if (!decoder->Closing) {
- VideoSetPts(&decoder->PTS, decoder->Interlaced, frame);
+ VideoSetPts(&decoder->PTS, decoder->Interlaced, video_ctx, frame);
}
VaapiRenderFrame(decoder, video_ctx, frame);
#ifdef USE_AUTOCROP
@@ -8879,7 +8893,7 @@ static void VdpauSyncRenderFrame(VdpauDecoder * decoder,
if (VdpauPreemption) { // display preempted
if (!decoder->Closing) {
- VideoSetPts(&decoder->PTS, decoder->Interlaced, frame);
+ VideoSetPts(&decoder->PTS, decoder->Interlaced, video_ctx, frame);
}
return;
}
@@ -8929,7 +8943,7 @@ static void VdpauSyncRenderFrame(VdpauDecoder * decoder,
#endif
if (!decoder->Closing) {
- VideoSetPts(&decoder->PTS, decoder->Interlaced, frame);
+ VideoSetPts(&decoder->PTS, decoder->Interlaced, video_ctx, frame);
}
VdpauRenderFrame(decoder, video_ctx, frame);
}