0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

demux: get rid of demux_packet.new_segment field

The new_segment field was used to track the decoder data flow handler of
timeline boundaries, which are used for ordered chapters etc. (anything
that sets demuxer_desc.load_timeline). This broke seeking with the
demuxer cache enabled. The demuxer is expected to set the new_segment
field after every seek or segment boundary switch, so the cached packets
basically contained incorrect values for this, and the decoders were not
initialized correctly.

Fix this by getting rid of the flag completely. Let the decoders instead
compare the segment information by content, which is hopefully enough.
(In theory, two segments with same information could perhaps appear in
broken-ish corner cases, or in an attempt to simulate looping, and such.
I preferred the simple solution over others, such as generating unique
and stable segment IDs.)

We still add a "segmented" field to make it explicit whether segments
are used, instead of doing something silly like testing arbitrary other
segment fields for validity.

Cached seeking with timeline stuff is still slightly broken even with
this commit: the seek logic is not aware of the overlap that segments
can have, and the timestamp clamping that needs to be performed in
theory to account for the fact that a packet might contain a frame that
is always clipped off by segment handling. This can be fixed later.
This commit is contained in:
wm4 2017-10-24 19:33:01 +02:00
parent bb9679d9a3
commit a5b51f75dc
6 changed files with 21 additions and 17 deletions

View File

@ -196,6 +196,12 @@ static void fix_audio_pts(struct dec_audio *da)
da->pts += mp_aframe_duration(da->current_frame); da->pts += mp_aframe_duration(da->current_frame);
} }
static bool is_new_segment(struct dec_audio *da, struct demux_packet *p)
{
return p->segmented &&
(p->start != da->start || p->end != da->end || p->codec != da->codec);
}
void audio_work(struct dec_audio *da) void audio_work(struct dec_audio *da)
{ {
if (da->current_frame || !da->ad_driver) if (da->current_frame || !da->ad_driver)
@ -208,7 +214,7 @@ void audio_work(struct dec_audio *da)
return; return;
} }
if (da->packet && da->packet->new_segment) { if (da->packet && is_new_segment(da, da->packet)) {
assert(!da->new_segment); assert(!da->new_segment);
da->new_segment = da->packet; da->new_segment = da->packet;
da->packet = NULL; da->packet = NULL;
@ -260,8 +266,6 @@ void audio_work(struct dec_audio *da)
da->start = new_segment->start; da->start = new_segment->start;
da->end = new_segment->end; da->end = new_segment->end;
new_segment->new_segment = false;
da->packet = new_segment; da->packet = new_segment;
da->current_state = DATA_AGAIN; da->current_state = DATA_AGAIN;
} }

View File

@ -46,7 +46,6 @@ struct segment {
struct virtual_stream { struct virtual_stream {
struct sh_stream *sh; // stream exported by demux_timeline struct sh_stream *sh; // stream exported by demux_timeline
bool selected; // ==demux_stream_is_selected(sh) bool selected; // ==demux_stream_is_selected(sh)
bool new_segment; // whether a new segment needs to be signaled
int eos_packets; // deal with b-frame delay int eos_packets; // deal with b-frame delay
}; };
@ -196,7 +195,6 @@ static void switch_segment(struct demuxer *demuxer, struct segment *new,
for (int n = 0; n < p->num_streams; n++) { for (int n = 0; n < p->num_streams; n++) {
struct virtual_stream *vs = p->streams[n]; struct virtual_stream *vs = p->streams[n];
vs->new_segment = true;
vs->eos_packets = 0; vs->eos_packets = 0;
} }
@ -307,10 +305,7 @@ static int d_fill_buffer(struct demuxer *demuxer)
} }
} }
if (!p->dash) pkt->segmented = true;
pkt->new_segment |= vs->new_segment;
vs->new_segment = false;
demux_add_packet(vs->sh, pkt); demux_add_packet(vs->sh, pkt);
return 1; return 1;

View File

@ -109,9 +109,9 @@ void demux_packet_copy_attribs(struct demux_packet *dst, struct demux_packet *sr
dst->dts = src->dts; dst->dts = src->dts;
dst->duration = src->duration; dst->duration = src->duration;
dst->pos = src->pos; dst->pos = src->pos;
dst->segmented = src->segmented;
dst->start = src->start; dst->start = src->start;
dst->end = src->end; dst->end = src->end;
dst->new_segment = src->new_segment;
dst->codec = src->codec; dst->codec = src->codec;
dst->keyframe = src->keyframe; dst->keyframe = src->keyframe;
dst->stream = src->stream; dst->stream = src->stream;

View File

@ -36,9 +36,9 @@ typedef struct demux_packet {
int stream; // source stream index int stream; // source stream index
// segmentation (ordered chapters, EDL) // segmentation (ordered chapters, EDL)
struct mp_codec_params *codec; bool segmented;
double start, end; struct mp_codec_params *codec; // set to non-NULL iff segmented is set
bool new_segment; double start, end; // set to non-NOPTS iff segmented is set
// private // private
struct demux_packet *next; struct demux_packet *next;

View File

@ -203,7 +203,7 @@ void sub_preload(struct dec_sub *sub)
static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p) static bool is_new_segment(struct dec_sub *sub, struct demux_packet *p)
{ {
return p->new_segment && return p->segmented &&
(p->start != sub->start || p->end != sub->end || p->codec != sub->codec); (p->start != sub->start || p->end != sub->end || p->codec != sub->codec);
} }

View File

@ -390,6 +390,13 @@ void video_set_start(struct dec_video *d_video, double start_pts)
d_video->start_pts = start_pts; d_video->start_pts = start_pts;
} }
static bool is_new_segment(struct dec_video *d_video, struct demux_packet *p)
{
return p->segmented &&
(p->start != d_video->start || p->end != d_video->end ||
p->codec != d_video->codec);
}
void video_work(struct dec_video *d_video) void video_work(struct dec_video *d_video)
{ {
if (d_video->current_mpi || !d_video->vd_driver) if (d_video->current_mpi || !d_video->vd_driver)
@ -402,7 +409,7 @@ void video_work(struct dec_video *d_video)
return; return;
} }
if (d_video->packet && d_video->packet->new_segment) { if (d_video->packet && is_new_segment(d_video, d_video->packet)) {
assert(!d_video->new_segment); assert(!d_video->new_segment);
d_video->new_segment = d_video->packet; d_video->new_segment = d_video->packet;
d_video->packet = NULL; d_video->packet = NULL;
@ -472,8 +479,6 @@ void video_work(struct dec_video *d_video)
d_video->start = new_segment->start; d_video->start = new_segment->start;
d_video->end = new_segment->end; d_video->end = new_segment->end;
new_segment->new_segment = false;
d_video->packet = new_segment; d_video->packet = new_segment;
d_video->current_state = DATA_AGAIN; d_video->current_state = DATA_AGAIN;
} }