summaryrefslogtreecommitdiffstats
path: root/video/decode/dec_video.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-02-11 16:01:11 +0100
committerwm4 <wm4@nowhere>2016-02-11 16:14:30 +0100
commitd3f32cba32d0cd5a46af00b2c176b177de36e074 (patch)
treee49f5f691dab25426e976ffa92c614bf93b20014 /video/decode/dec_video.c
parenteff2e575f1d83f7fae2b4e2270ee20671e5d7107 (diff)
downloadmpv-d3f32cba32d0cd5a46af00b2c176b177de36e074.tar.bz2
mpv-d3f32cba32d0cd5a46af00b2c176b177de36e074.tar.xz
video: approximate AVI timestamps via DTS handling
Until now (and in mplayer traditionally), avi timestamps were handled with a timestamp FIFO. AVI timestamps are essentially just strictly increasing frame numbers and are not reordered like normal timestamps. Limiting the FIFO is required because frames can be dropped. To make it worse, frame dropping can't be distinguished from the decoder not returning output due to increasing the buffering required for B-frames. ("Measuring" the buffering at playback start seems like an interesting idea, but won't work as the buffering could be increased mid-playback.) Another problem are skipped frames (packets with data, but which do not contain a video frame). Besides dropped and skipped frames, there is the problem that we can't always know the delay. External decoders like MMAL are not going to tell us. (And later perhaps others, like direct VideoToolbox usage.) In general, this works not-well enough that I prefer the solution of passing through AVI timestamps as DTS. This is slightly incorrect, because most decoders treat DTS as mpeg-style timestamps, which already include a b-frame delay, and thus will be shifted by a few frames. This means there will be a problem with A/V sync in some situations. Note that the FFmpeg AVI demuxer shifts timestamps by an additional amount (which increases after the first seek!?!?), which makes the situation worse. It works well with VfW-muxed Matroska files, though. On RPI, the first X timestamps are broken until the MMAL decoder "locks on".
Diffstat (limited to 'video/decode/dec_video.c')
-rw-r--r--video/decode/dec_video.c52
1 files changed, 9 insertions, 43 deletions
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c
index d20d10304e..2b01b544cc 100644
--- a/video/decode/dec_video.c
+++ b/video/decode/dec_video.c
@@ -59,7 +59,6 @@ const vd_functions_t * const mpcodecs_vd_drivers[] = {
void video_reset(struct dec_video *d_video)
{
video_vd_control(d_video, VDCTRL_RESET, NULL);
- d_video->num_buffered_pts = 0;
d_video->first_packet_pdts = MP_NOPTS_VALUE;
d_video->start_pts = MP_NOPTS_VALUE;
d_video->decoded_pts = MP_NOPTS_VALUE;
@@ -235,34 +234,6 @@ static void fix_image_params(struct dec_video *d_video,
d_video->fixed_format = p;
}
-static void add_avi_pts(struct dec_video *d_video, double pts)
-{
- if (pts != MP_NOPTS_VALUE) {
- int delay = -1;
- video_vd_control(d_video, VDCTRL_QUERY_UNSEEN_FRAMES, &delay);
- if (delay >= 0 && delay < d_video->num_buffered_pts)
- d_video->num_buffered_pts = delay;
- if (d_video->num_buffered_pts == MP_ARRAY_SIZE(d_video->buffered_pts)) {
- MP_ERR(d_video, "Too many buffered pts\n");
- } else {
- for (int i = d_video->num_buffered_pts; i > 0; i--)
- d_video->buffered_pts[i] = d_video->buffered_pts[i - 1];
- d_video->buffered_pts[0] = pts;
- d_video->num_buffered_pts++;
- }
- }
-}
-
-static double retrieve_avi_pts(struct dec_video *d_video, double codec_pts)
-{
- if (d_video->num_buffered_pts) {
- d_video->num_buffered_pts--;
- return d_video->buffered_pts[d_video->num_buffered_pts];
- }
- MP_ERR(d_video, "No pts value from demuxer to use for frame!\n");
- return MP_NOPTS_VALUE;
-}
-
static struct mp_image *decode_packet(struct dec_video *d_video,
struct demux_packet *packet,
int drop_frame)
@@ -271,7 +242,7 @@ static struct mp_image *decode_packet(struct dec_video *d_video,
bool avi_pts = d_video->header->codec->avi_dts && opts->correct_pts;
struct demux_packet packet_copy;
- if (packet && packet->dts == MP_NOPTS_VALUE) {
+ if (packet && packet->dts == MP_NOPTS_VALUE && !avi_pts) {
packet_copy = *packet;
packet = &packet_copy;
packet->dts = packet->pts;
@@ -284,12 +255,6 @@ static struct mp_image *decode_packet(struct dec_video *d_video,
if (pkt_pdts != MP_NOPTS_VALUE && d_video->first_packet_pdts == MP_NOPTS_VALUE)
d_video->first_packet_pdts = pkt_pdts;
- if (avi_pts)
- add_avi_pts(d_video, pkt_pdts);
-
- if (d_video->header->codec->avi_dts)
- drop_frame = 0;
-
MP_STATS(d_video, "start decode video");
struct mp_image *mpi = d_video->vd_driver->decode(d_video, packet, drop_frame);
@@ -298,9 +263,6 @@ static struct mp_image *decode_packet(struct dec_video *d_video,
// Error, discarded frame, dropped frame, or initial codec delay.
if (!mpi || drop_frame) {
- // If we already had output, this must be a dropped frame.
- if (d_video->decoded_pts != MP_NOPTS_VALUE && d_video->num_buffered_pts)
- d_video->num_buffered_pts--;
talloc_free(mpi);
return NULL;
}
@@ -333,10 +295,6 @@ static struct mp_image *decode_packet(struct dec_video *d_video,
pts == MP_NOPTS_VALUE) && dts != MP_NOPTS_VALUE)
pts = dts;
- // Alternative PTS determination methods
- if (avi_pts)
- pts = retrieve_avi_pts(d_video, pts);
-
if (!opts->correct_pts || pts == MP_NOPTS_VALUE) {
if (opts->correct_pts && !d_video->header->missing_timestamps)
MP_WARN(d_video, "No video PTS! Making something up.\n");
@@ -363,6 +321,14 @@ static struct mp_image *decode_packet(struct dec_video *d_video,
mpi->pts = pts;
d_video->decoded_pts = pts;
+
+ // Compensate for incorrectly using mpeg-style DTS for avi timestamps.
+ if (avi_pts && mpi->pts != MP_NOPTS_VALUE && d_video->fps > 0) {
+ int delay = -1;
+ video_vd_control(d_video, VDCTRL_GET_BFRAMES, &delay);
+ mpi->pts -= MPMAX(delay, 0) / d_video->fps;
+ }
+
return mpi;
}