1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 10:02:17 +00:00

player: eliminate demux_get_next_pts()

This slightly changes behavior when seeking with external audio/subtitle
tracks if transport streams and mpeg files are played, as well as
behavior when seeking with such external tracks.

get_main_demux_pts() is evil because it always blocks on the demuxer (if
there isn't already a packet queued). Thus it could lock up the player,
which is a shame because all other possible causes have been removed.

The reduced "precision" when seeking in the ts/mpeg cases (where
SEEK_FACTOR is used, resulting in byte seeks instead of timestamp seeks)
might lead to issues. We should probably drop this heuristic. (It was
introduced because there is no other way to seek in files with PTS
resets with libavformat, but its value is still questionable.)
This commit is contained in:
wm4 2016-01-11 20:36:23 +01:00
parent f54ae2031e
commit 8135838018
6 changed files with 6 additions and 37 deletions

View File

@ -738,22 +738,6 @@ int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt)
return r; return r;
} }
// Return the pts of the next packet that demux_read_packet() would return.
// Might block. Sometimes used to force a packet read, without removing any
// packets from the queue.
double demux_get_next_pts(struct sh_stream *sh)
{
double res = MP_NOPTS_VALUE;
if (sh) {
pthread_mutex_lock(&sh->ds->in->lock);
ds_get_packets(sh->ds);
if (sh->ds->head)
res = MP_ADD_PTS(sh->ds->head->pts, sh->ds->in->ts_offset);
pthread_mutex_unlock(&sh->ds->in->lock);
}
return res;
}
// Return whether a packet is queued. Never blocks, never forces any reads. // Return whether a packet is queued. Never blocks, never forces any reads.
bool demux_has_packet(struct sh_stream *sh) bool demux_has_packet(struct sh_stream *sh)
{ {

View File

@ -242,7 +242,6 @@ void demux_add_packet(struct sh_stream *stream, demux_packet_t *dp);
struct demux_packet *demux_read_packet(struct sh_stream *sh); struct demux_packet *demux_read_packet(struct sh_stream *sh);
int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt); int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt);
bool demux_stream_is_selected(struct sh_stream *stream); bool demux_stream_is_selected(struct sh_stream *stream);
double demux_get_next_pts(struct sh_stream *sh);
bool demux_has_packet(struct sh_stream *sh); bool demux_has_packet(struct sh_stream *sh);
struct demux_packet *demux_read_any_packet(struct demuxer *demuxer); struct demux_packet *demux_read_any_packet(struct demuxer *demuxer);

View File

@ -449,7 +449,6 @@ void mp_print_version(struct mp_log *log, int always);
void wakeup_playloop(void *ctx); void wakeup_playloop(void *ctx);
// misc.c // misc.c
double get_main_demux_pts(struct MPContext *mpctx);
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t); double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
double get_play_end_pts(struct MPContext *mpctx); double get_play_end_pts(struct MPContext *mpctx);
double get_relative_time(struct MPContext *mpctx); double get_relative_time(struct MPContext *mpctx);

View File

@ -235,9 +235,10 @@ void reselect_demux_streams(struct MPContext *mpctx)
need_init_seek(track->demuxer); need_init_seek(track->demuxer);
demuxer_select_track(track->demuxer, track->stream, track->selected); demuxer_select_track(track->demuxer, track->stream, track->selected);
if (need_init) { if (need_init) {
double pts = get_main_demux_pts(mpctx); double pts = get_current_time(mpctx);
if (pts != MP_NOPTS_VALUE) if (pts == MP_NOPTS_VALUE)
demux_seek(track->demuxer, pts, SEEK_ABSOLUTE); pts = 0;
demux_seek(track->demuxer, pts, SEEK_ABSOLUTE);
} }
} }
} }

View File

@ -101,20 +101,6 @@ double get_play_end_pts(struct MPContext *mpctx)
return end; return end;
} }
// Time used to seek external tracks to.
double get_main_demux_pts(struct MPContext *mpctx)
{
double main_new_pos = MP_NOPTS_VALUE;
if (mpctx->demuxer) {
for (int n = 0; n < demux_get_num_stream(mpctx->demuxer); n++) {
struct sh_stream *stream = demux_get_stream(mpctx->demuxer, n);
if (main_new_pos == MP_NOPTS_VALUE && stream->type != STREAM_SUB)
main_new_pos = demux_get_next_pts(stream);
}
}
return main_new_pos;
}
float mp_get_cache_percent(struct MPContext *mpctx) float mp_get_cache_percent(struct MPContext *mpctx)
{ {
if (mpctx->demuxer) { if (mpctx->demuxer) {

View File

@ -260,9 +260,9 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
for (int t = 0; t < mpctx->num_tracks; t++) { for (int t = 0; t < mpctx->num_tracks; t++) {
struct track *track = mpctx->tracks[t]; struct track *track = mpctx->tracks[t];
if (track->selected && track->is_external && track->demuxer) { if (track->selected && track->is_external && track->demuxer) {
double main_new_pos = seek.amount; double main_new_pos = demuxer_amount;
if (seek.type != MPSEEK_ABSOLUTE) if (seek.type != MPSEEK_ABSOLUTE)
main_new_pos = get_main_demux_pts(mpctx); main_new_pos = target_time;
demux_seek(track->demuxer, main_new_pos, SEEK_ABSOLUTE | SEEK_BACKWARD); demux_seek(track->demuxer, main_new_pos, SEEK_ABSOLUTE | SEEK_BACKWARD);
} }
} }