summaryrefslogtreecommitdiff
path: root/video.c
diff options
context:
space:
mode:
authorJohns <johns98@gmx.net>2011-12-19 17:03:40 +0100
committerJohns <johns98@gmx.net>2011-12-19 17:11:25 +0100
commit36b285b5f7351836f0ad6a364c3d4743549a99c7 (patch)
tree514d88c4eddc836b83cf7be4042f374ea08b910d /video.c
parent33460f1370b24bae464201e08bbc7bea26f98129 (diff)
downloadvdr-plugin-softhddevice-36b285b5f7351836f0ad6a364c3d4743549a99c7.tar.gz
vdr-plugin-softhddevice-36b285b5f7351836f0ad6a364c3d4743549a99c7.tar.bz2
Audio/video sync improvements.
Configurable audio delay. Use monotonic pts. Support old libav or ffmpeg libraries.
Diffstat (limited to 'video.c')
-rw-r--r--video.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/video.c b/video.c
index 0e437d8..b7930b8 100644
--- a/video.c
+++ b/video.c
@@ -181,6 +181,9 @@ static VideoDeinterlaceModes VideoDeinterlace;
/// Default scaling mode
static VideoScalingModes VideoScaling;
+ /// Default audio/video delay
+static int VideoAudioDelay;
+
//static char VideoSoftStartSync; ///< soft start sync audio/video
static char Video60HzMode; ///< handle 60hz displays
@@ -2520,7 +2523,7 @@ static void VaapiDisplayFrame(void)
// deinterlace and full frame rate
// VDPAU driver only display a frame, if a full frame is put
// INTEL driver does the same, but only with 1080i
- if (decoder->Interlaced
+ if (0 && decoder->Interlaced
// FIXME: buggy libva-driver-vdpau, buggy libva-driver-intel
&& (VaapiBuggyVdpau || (0 && VaapiBuggyIntel
&& decoder->InputHeight == 1080))
@@ -3136,10 +3139,11 @@ static void VaapiSyncDisplayFrame(VaapiDecoder * decoder)
if (abs(video_clock - audio_clock) > 5000 * 90) {
Debug(3, "video: pts difference too big\n");
- } else if (video_clock > audio_clock + 300 * 90) {
+ } else if (video_clock > audio_clock + VideoAudioDelay + 30 * 90) {
Debug(3, "video: slow down video\n");
decoder->DupNextFrame = 1;
- } else if (audio_clock > video_clock + 300 * 90) {
+ } else if (audio_clock + VideoAudioDelay > video_clock + 50 * 90
+ && filled > 1) {
Debug(3, "video: speed up video\n");
decoder->DropNextFrame = 1;
}
@@ -3502,19 +3506,30 @@ void VideoRenderFrame(VideoHwDecoder * decoder, AVCodecContext * video_ctx,
// FIXME: move into vaapi module
// update video clock
- decoder->Vaapi.PTS += decoder->Vaapi.Interlaced ? 40 * 90 : 20 * 90;
-
+ if ((uint64_t) decoder->Vaapi.PTS != AV_NOPTS_VALUE) {
+ decoder->Vaapi.PTS += decoder->Vaapi.Interlaced ? 40 * 90 : 20 * 90;
+ }
//pts = frame->best_effort_timestamp;
pts = frame->pkt_pts;
if ((uint64_t) pts == AV_NOPTS_VALUE || !pts) {
+ // libav: 0.8pre didn't set pts
pts = frame->pkt_dts;
}
- // libav: sets only pkt_dts
+ if (!pts) {
+ pts = AV_NOPTS_VALUE;
+ }
+ // build a monotonic pts
+ if ((uint64_t) decoder->Vaapi.PTS != AV_NOPTS_VALUE) {
+ if (pts - decoder->Vaapi.PTS < -10 * 90) {
+ pts = AV_NOPTS_VALUE;
+ }
+ }
+ // libav: sets only pkt_dts which can be 0
if ((uint64_t) pts != AV_NOPTS_VALUE) {
if (decoder->Vaapi.PTS != pts) {
- Debug(4,
+ Debug(3,
"video: %#012" PRIx64 "->%#012" PRIx64 " %4" PRId64 " pts\n",
- decoder->Vaapi.PTS, pts, decoder->Vaapi.PTS - pts);
+ decoder->Vaapi.PTS, pts, pts - decoder->Vaapi.PTS);
decoder->Vaapi.PTS = pts;
}
}
@@ -3557,6 +3572,10 @@ void VideoRenderFrame(VideoHwDecoder * decoder, AVCodecContext * video_ctx,
VaapiSyncDisplayFrame(&decoder->Vaapi);
}
+
+ if (frame->repeat_pict) {
+ Warning("video/vaapi: repeated pict found, but not handle\n");
+ }
#ifdef USE_VAAPI
if (VideoVaapiEnabled) {
VaapiRenderFrame(&decoder->Vaapi, video_ctx, frame);
@@ -3634,7 +3653,8 @@ void VideoDisplayHandler(void)
/**
** Get video clock.
**
-** @note this isn't monoton, decoding reorders frames.
+** @note this isn't monoton, decoding reorders frames,
+** setter keeps it monotonic
*/
int64_t VideoGetClock(void)
{
@@ -3777,6 +3797,16 @@ void VideoSetScaling(int mode)
}
/**
+** Set audio delay.
+**
+** @param ms delay in ms
+*/
+void VideoSetAudioDelay(int ms)
+{
+ VideoAudioDelay = ms * 90;
+}
+
+/**
** Initialize video output module.
**
** @param display_name X11 display name