summaryrefslogtreecommitdiffstats
path: root/sub/dec_sub.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-18 00:51:57 +0100
committerwm4 <wm4@nowhere>2015-12-18 03:52:57 +0100
commit2c7db48195b03e93ee3cbf382ccabcedb96a6830 (patch)
tree165c6d52549991bf6c03cd47e495a558f14ac4ce /sub/dec_sub.c
parent7137afeb2c466135ab0e01ee0f9cbd2abd000563 (diff)
downloadmpv-2c7db48195b03e93ee3cbf382ccabcedb96a6830.tar.bz2
mpv-2c7db48195b03e93ee3cbf382ccabcedb96a6830.tar.xz
sub: do not clear subtitle list on seeking
This affects non-ASS text subtitles (those which go through libavcodec's subtitle converter), which are muxed with video/audio. (Typically srt subs in mkv.) The problem is that seeking in the file can send a subtitle packet to the decoder multiple times. These packets are interlaved with video, and thus can't be all read when opening the file. Rather, subtitle packets can essentially be randomly skipped or repeated (by seeking). Until recently, this was solved by scanning the libass event list for duplicates. Then our builtin srt-to-ass converter was removed, and the problem was handled by fully clearing the subtitle list on each seek. This resulted in sub-seek not working properly for this type of file. Since the subtitle list was cleared on seek, it was not possible to do e.g. sub-seeks to subtitles before the current playback position. Fix this by not clearing the list, and intead explicitly rejecting duplicate packets. We use the packet file position was unique ID for subtitles; this is confirmed working for most file formats (although it is slightly risky - new demuxers may not necessarily set the file position to something unique, or at all). The list of seen packets is sorted, and the lookup uses binary search. This is to avoid quadratic complexity when subtitles are added in bulks, such as when opening a text subtitle file. In some places, the code has to be adjusted to pass through the packet file position correctly.
Diffstat (limited to 'sub/dec_sub.c')
-rw-r--r--sub/dec_sub.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index 451a5cab38..e7362e1f69 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -273,6 +273,7 @@ static struct demux_packet *recode_packet(struct mp_log *log,
.buffer = conv.start,
.len = conv.len,
.pts = in->pts,
+ .pos = in->pos,
.duration = in->duration,
.avpacket = in->avpacket, // questionable, but gives us sidedata
};
@@ -305,13 +306,6 @@ static void add_sub_list(struct dec_sub *sub, struct packet_list *subs)
for (int n = 0; n < subs->num_packets; n++)
decode_chain_recode(sub, subs->packets[n]);
-
- // Hack for broken FFmpeg packet format: make sd_ass keep the subtitle
- // events on reset(), even if broken FFmpeg ASS packets were received
- // (from sd_lavc_conv.c). Normally, these events are removed on seek/reset,
- // but this is obviously unwanted in this case.
- if (sd->driver->fix_events)
- sd->driver->fix_events(sd);
}
static void add_packet(struct packet_list *subs, struct demux_packet *pkt)
@@ -446,7 +440,7 @@ struct sd_conv_buffer {
};
void sd_conv_add_packet(struct sd *sd, void *data, int data_len, double pts,
- double duration)
+ double duration, int64_t pos)
{
if (!sd->sd_conv_buffer)
sd->sd_conv_buffer = talloc_zero(sd, struct sd_conv_buffer);
@@ -462,6 +456,7 @@ void sd_conv_add_packet(struct sd *sd, void *data, int data_len, double pts,
.len = data_len,
.pts = pts,
.duration = duration,
+ .pos = pos,
};
memcpy(pkt->buffer, data, data_len);
pkt->buffer[data_len] = 0;