2013-10-29 21:38:29 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2013-10-29 21:38:29 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2013-10-29 21:38:29 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-10-29 21:38:29 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-10-29 21:38:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
2014-07-10 06:28:03 +00:00
|
|
|
#include <strings.h>
|
2013-10-29 21:38:29 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
#include "osdep/io.h"
|
2013-12-19 20:31:27 +00:00
|
|
|
#include "osdep/terminal.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "osdep/timer.h"
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-10-06 19:20:38 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/path.h"
|
|
|
|
#include "options/m_config.h"
|
|
|
|
#include "options/parse_configfile.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/playlist.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
|
|
|
#include "options/m_property.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/encode.h"
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2013-11-10 22:38:18 +00:00
|
|
|
#include "audio/audio.h"
|
|
|
|
#include "audio/audio_buffer.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "audio/decode/dec_audio.h"
|
|
|
|
#include "audio/out/ao.h"
|
|
|
|
#include "demux/demux.h"
|
|
|
|
#include "stream/stream.h"
|
|
|
|
#include "sub/dec_sub.h"
|
2015-09-20 16:05:06 +00:00
|
|
|
#include "external_files.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "video/decode/dec_video.h"
|
|
|
|
#include "video/out/vo.h"
|
|
|
|
|
2013-12-17 00:08:53 +00:00
|
|
|
#include "core.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "command.h"
|
2014-02-10 20:01:35 +00:00
|
|
|
#include "libmpv/client.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-10-03 17:57:49 +00:00
|
|
|
static void uninit_demuxer(struct MPContext *mpctx)
|
2013-12-24 16:46:14 +00:00
|
|
|
{
|
2014-10-03 17:57:49 +00:00
|
|
|
for (int r = 0; r < NUM_PTRACKS; r++) {
|
|
|
|
for (int t = 0; t < STREAM_TYPE_COUNT; t++)
|
|
|
|
mpctx->current_track[r][t] = NULL;
|
|
|
|
}
|
2015-02-22 18:06:21 +00:00
|
|
|
talloc_free(mpctx->chapters);
|
|
|
|
mpctx->chapters = NULL;
|
|
|
|
mpctx->num_chapters = 0;
|
|
|
|
|
|
|
|
// close demuxers for external tracks
|
|
|
|
for (int n = mpctx->num_tracks - 1; n >= 0; n--) {
|
|
|
|
mpctx->tracks[n]->selected = false;
|
|
|
|
mp_remove_track(mpctx, mpctx->tracks[n]);
|
2015-02-17 22:46:12 +00:00
|
|
|
}
|
2015-12-26 17:32:27 +00:00
|
|
|
for (int i = 0; i < mpctx->num_tracks; i++) {
|
2016-01-17 15:56:32 +00:00
|
|
|
sub_destroy(mpctx->tracks[i]->d_sub);
|
2015-02-22 18:06:21 +00:00
|
|
|
talloc_free(mpctx->tracks[i]);
|
2015-12-26 17:32:27 +00:00
|
|
|
}
|
2015-02-22 18:06:21 +00:00
|
|
|
mpctx->num_tracks = 0;
|
|
|
|
|
2016-02-15 20:03:51 +00:00
|
|
|
free_demuxer_and_stream(mpctx->demuxer);
|
|
|
|
mpctx->demuxer = NULL;
|
2013-12-24 16:46:14 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 18:12:13 +00:00
|
|
|
#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
static void print_stream(struct MPContext *mpctx, struct track *t)
|
|
|
|
{
|
|
|
|
struct sh_stream *s = t->stream;
|
|
|
|
const char *tname = "?";
|
|
|
|
const char *selopt = "?";
|
|
|
|
const char *langopt = "?";
|
|
|
|
switch (t->type) {
|
|
|
|
case STREAM_VIDEO:
|
2014-07-13 18:12:13 +00:00
|
|
|
tname = "Video"; selopt = "vid"; langopt = NULL;
|
2013-10-29 21:38:29 +00:00
|
|
|
break;
|
|
|
|
case STREAM_AUDIO:
|
2014-07-13 18:12:13 +00:00
|
|
|
tname = "Audio"; selopt = "aid"; langopt = "alang";
|
2013-10-29 21:38:29 +00:00
|
|
|
break;
|
|
|
|
case STREAM_SUB:
|
2014-07-13 18:12:13 +00:00
|
|
|
tname = "Subs"; selopt = "sid"; langopt = "slang";
|
2013-10-29 21:38:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-07-13 18:12:13 +00:00
|
|
|
char b[2048] = {0};
|
2015-01-09 22:56:49 +00:00
|
|
|
APPEND(b, " %3s %-5s", t->selected ? "(+)" : "", tname);
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " --%s=%d", selopt, t->user_tid);
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t->lang && langopt)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " --%s=%s", langopt, t->lang);
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t->default_track)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " (*)");
|
2015-06-27 20:02:24 +00:00
|
|
|
if (t->forced_track)
|
|
|
|
APPEND(b, " (f)");
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t->attached_picture)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " [P]");
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t->title)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " '%s'", t->title);
|
2016-01-12 22:48:19 +00:00
|
|
|
const char *codec = s ? s->codec->codec : NULL;
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " (%s)", codec ? codec : "<unknown>");
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t->is_external)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " (external)");
|
|
|
|
MP_INFO(mpctx, "%s\n", b);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 19:50:37 +00:00
|
|
|
void print_track_list(struct MPContext *mpctx, const char *msg)
|
2015-04-28 20:04:37 +00:00
|
|
|
{
|
2015-06-03 19:50:37 +00:00
|
|
|
if (msg)
|
|
|
|
MP_INFO(mpctx, "%s\n", msg);
|
2015-04-28 20:04:37 +00:00
|
|
|
for (int t = 0; t < STREAM_TYPE_COUNT; t++) {
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++)
|
|
|
|
if (mpctx->tracks[n]->type == t)
|
|
|
|
print_stream(mpctx, mpctx->tracks[n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:40:21 +00:00
|
|
|
void update_demuxer_properties(struct MPContext *mpctx)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2016-02-15 20:03:51 +00:00
|
|
|
struct demuxer *demuxer = mpctx->demuxer;
|
2014-07-16 20:40:21 +00:00
|
|
|
if (!demuxer)
|
|
|
|
return;
|
|
|
|
demux_update(demuxer);
|
|
|
|
int events = demuxer->events;
|
|
|
|
if ((events & DEMUX_EVENT_INIT) && demuxer->num_editions > 1) {
|
2014-01-22 23:54:08 +00:00
|
|
|
for (int n = 0; n < demuxer->num_editions; n++) {
|
|
|
|
struct demux_edition *edition = &demuxer->editions[n];
|
2014-07-13 18:12:13 +00:00
|
|
|
char b[128] = {0};
|
2015-01-09 22:56:49 +00:00
|
|
|
APPEND(b, " %3s --edition=%d",
|
2014-07-13 18:12:13 +00:00
|
|
|
n == demuxer->edition ? "(+)" : "", n);
|
2014-01-22 23:54:08 +00:00
|
|
|
char *name = mp_tags_get_str(edition->metadata, "title");
|
|
|
|
if (name)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " '%s'", name);
|
2014-01-22 23:54:08 +00:00
|
|
|
if (edition->default_edition)
|
2014-07-13 18:12:13 +00:00
|
|
|
APPEND(b, " (*)");
|
|
|
|
MP_INFO(mpctx, "%s\n", b);
|
2014-01-22 23:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-15 20:03:51 +00:00
|
|
|
struct demuxer *tracks = mpctx->demuxer;
|
2014-07-20 18:02:58 +00:00
|
|
|
if (tracks->events & DEMUX_EVENT_STREAMS) {
|
|
|
|
add_demuxer_tracks(mpctx, tracks);
|
2015-06-03 19:50:37 +00:00
|
|
|
print_track_list(mpctx, NULL);
|
2014-07-20 18:02:58 +00:00
|
|
|
tracks->events &= ~DEMUX_EVENT_STREAMS;
|
2014-07-16 20:40:21 +00:00
|
|
|
}
|
2014-12-19 22:54:21 +00:00
|
|
|
if (events & DEMUX_EVENT_METADATA) {
|
2014-12-29 21:51:18 +00:00
|
|
|
struct mp_tags *info =
|
|
|
|
mp_tags_filtered(mpctx, demuxer->metadata, mpctx->opts->display_tags);
|
2014-12-19 22:54:21 +00:00
|
|
|
// prev is used to attempt to print changed tags only (to some degree)
|
2014-12-29 21:51:18 +00:00
|
|
|
struct mp_tags *prev = mpctx->filtered_tags;
|
2014-12-19 22:54:21 +00:00
|
|
|
int n_prev = 0;
|
|
|
|
bool had_output = false;
|
|
|
|
for (int n = 0; n < info->num_keys; n++) {
|
|
|
|
if (prev && n_prev < prev->num_keys) {
|
|
|
|
if (strcmp(prev->keys[n_prev], info->keys[n]) == 0) {
|
|
|
|
n_prev++;
|
|
|
|
if (strcmp(prev->values[n_prev - 1], info->values[n]) == 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 19:10:59 +00:00
|
|
|
struct mp_log *log = mp_log_new(NULL, mpctx->log, "!display-tags");
|
2014-12-19 22:54:21 +00:00
|
|
|
if (!had_output)
|
2015-10-01 19:10:59 +00:00
|
|
|
mp_info(log, "File tags:\n");
|
|
|
|
mp_info(log, " %s: %s\n", info->keys[n], info->values[n]);
|
2014-12-19 22:54:21 +00:00
|
|
|
had_output = true;
|
2015-10-01 19:10:59 +00:00
|
|
|
talloc_free(log);
|
2014-12-19 22:54:21 +00:00
|
|
|
}
|
2014-12-29 21:51:18 +00:00
|
|
|
talloc_free(mpctx->filtered_tags);
|
|
|
|
mpctx->filtered_tags = info;
|
2014-07-16 20:40:21 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_METADATA_UPDATE, NULL);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
2014-07-20 18:02:58 +00:00
|
|
|
demuxer->events = 0;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 21:44:50 +00:00
|
|
|
// Enables or disables the stream for the given track, according to
|
|
|
|
// track->selected.
|
|
|
|
void reselect_demux_stream(struct MPContext *mpctx, struct track *track)
|
2014-07-29 15:55:28 +00:00
|
|
|
{
|
2016-02-25 21:44:50 +00:00
|
|
|
if (!track->stream)
|
|
|
|
return;
|
player: improve instant track switching
When switching tracks, we normally have the problem that data gets lost
due to readahead buffering. (Which in turn is because we're stubborn and
instruct the demuxers to discard data on unselected streams.) The
demuxer layer has a hack that re-reads discarded buffered data if a
stream is enabled mid-stream, so track switching will seem instant.
A somewhat similar problem is when all tracks of an external files were
disabled - when enabling the first track, we have to seek to the target
position.
Handle these with the same mechanism. Pass the "current time" to the
demuxer's stream switch function, and let the demuxer figure out what to
do. The demuxer will issue a refresh seek (if possible) to update the
new stream, or will issue a "normal" seek if there was no active stream
yet.
One case that changes is when a video/audio stream is enabled on an
external file with only a subtitle stream active, and the demuxer does
not support rrefresh seeks. This is a fuzzy case, because subtitles are
sparse, and the demuxer might have skipped large amounts of data. We
used to seek (and send the subtitle decoder some subtitle packets
twice). This case is sort of obscure and insane, and the fix would be
questionable, so we simply don't care.
Should mostly fix #3392.
2016-08-06 13:47:04 +00:00
|
|
|
double pts = get_current_time(mpctx);
|
|
|
|
if (pts != MP_NOPTS_VALUE)
|
|
|
|
pts += get_track_seek_offset(mpctx, track);
|
|
|
|
demuxer_select_track(track->demuxer, track->stream, pts, track->selected);
|
2013-12-24 10:30:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 13:10:28 +00:00
|
|
|
// Called from the demuxer thread if a new packet is available.
|
|
|
|
static void wakeup_demux(void *pctx)
|
|
|
|
{
|
|
|
|
struct MPContext *mpctx = pctx;
|
|
|
|
mp_input_wakeup(mpctx->input);
|
|
|
|
}
|
|
|
|
|
2016-02-23 21:51:18 +00:00
|
|
|
static void enable_demux_thread(struct MPContext *mpctx, struct demuxer *demux)
|
2014-07-18 13:10:28 +00:00
|
|
|
{
|
2016-02-23 21:51:18 +00:00
|
|
|
if (mpctx->opts->demuxer_thread && !demux->fully_read) {
|
|
|
|
demux_set_wakeup_cb(demux, wakeup_demux, mpctx);
|
|
|
|
demux_start_thread(demux);
|
2014-07-18 13:10:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
static int find_new_tid(struct MPContext *mpctx, enum stream_type t)
|
|
|
|
{
|
|
|
|
int new_id = 0;
|
|
|
|
for (int i = 0; i < mpctx->num_tracks; i++) {
|
|
|
|
struct track *track = mpctx->tracks[i];
|
|
|
|
if (track->type == t)
|
|
|
|
new_id = MPMAX(new_id, track->user_tid);
|
|
|
|
}
|
|
|
|
return new_id + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct track *add_stream_track(struct MPContext *mpctx,
|
2014-07-16 20:40:21 +00:00
|
|
|
struct demuxer *demuxer,
|
2016-02-15 20:03:51 +00:00
|
|
|
struct sh_stream *stream)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < mpctx->num_tracks; i++) {
|
|
|
|
struct track *track = mpctx->tracks[i];
|
2016-02-15 20:03:51 +00:00
|
|
|
if (track->stream == stream)
|
2013-10-29 21:38:29 +00:00
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct track *track = talloc_ptrtype(NULL, track);
|
|
|
|
*track = (struct track) {
|
|
|
|
.type = stream->type,
|
|
|
|
.user_tid = find_new_tid(mpctx, stream->type),
|
|
|
|
.demuxer_id = stream->demuxer_id,
|
2014-10-21 11:16:48 +00:00
|
|
|
.ff_index = stream->ff_index,
|
2013-10-29 21:38:29 +00:00
|
|
|
.title = stream->title,
|
|
|
|
.default_track = stream->default_track,
|
2015-06-27 20:02:24 +00:00
|
|
|
.forced_track = stream->forced_track,
|
2013-10-29 21:38:29 +00:00
|
|
|
.attached_picture = stream->attached_picture != NULL,
|
|
|
|
.lang = stream->lang,
|
2014-07-16 20:40:21 +00:00
|
|
|
.demuxer = demuxer,
|
2013-10-29 21:38:29 +00:00
|
|
|
.stream = stream,
|
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(mpctx, mpctx->tracks, mpctx->num_tracks, track);
|
|
|
|
|
player: improve instant track switching
When switching tracks, we normally have the problem that data gets lost
due to readahead buffering. (Which in turn is because we're stubborn and
instruct the demuxers to discard data on unselected streams.) The
demuxer layer has a hack that re-reads discarded buffered data if a
stream is enabled mid-stream, so track switching will seem instant.
A somewhat similar problem is when all tracks of an external files were
disabled - when enabling the first track, we have to seek to the target
position.
Handle these with the same mechanism. Pass the "current time" to the
demuxer's stream switch function, and let the demuxer figure out what to
do. The demuxer will issue a refresh seek (if possible) to update the
new stream, or will issue a "normal" seek if there was no active stream
yet.
One case that changes is when a video/audio stream is enabled on an
external file with only a subtitle stream active, and the demuxer does
not support rrefresh seeks. This is a fuzzy case, because subtitles are
sparse, and the demuxer might have skipped large amounts of data. We
used to seek (and send the subtitle decoder some subtitle packets
twice). This case is sort of obscure and insane, and the fix would be
questionable, so we simply don't care.
Should mostly fix #3392.
2016-08-06 13:47:04 +00:00
|
|
|
demuxer_select_track(track->demuxer, stream, MP_NOPTS_VALUE, false);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer)
|
|
|
|
{
|
2016-02-15 20:03:51 +00:00
|
|
|
for (int n = 0; n < demux_get_num_stream(demuxer); n++)
|
|
|
|
add_stream_track(mpctx, demuxer, demux_get_stream(demuxer, n));
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Result numerically higher => better match. 0 == no match.
|
|
|
|
static int match_lang(char **langs, char *lang)
|
|
|
|
{
|
|
|
|
for (int idx = 0; langs && langs[idx]; idx++) {
|
|
|
|
if (lang && strcmp(langs[idx], lang) == 0)
|
|
|
|
return INT_MAX - idx;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the track wanted by the user.
|
|
|
|
* tid is the track ID requested by the user (-2: deselect, -1: default)
|
|
|
|
* lang is a string list, NULL is same as empty list
|
|
|
|
* Sort tracks based on the following criteria, and pick the first:
|
2014-10-21 11:16:48 +00:00
|
|
|
* 0a) track matches ff-index (always wins)
|
|
|
|
* 0b) track matches tid (almost always wins)
|
2014-01-05 15:15:30 +00:00
|
|
|
* 1) track is external (no_default cancels this)
|
2013-10-29 21:38:29 +00:00
|
|
|
* 1b) track was passed explicitly (is not an auto-loaded subtitle)
|
|
|
|
* 2) earlier match in lang list
|
2015-06-27 20:02:24 +00:00
|
|
|
* 3a) track is marked forced
|
|
|
|
* 3b) track is marked default
|
2014-09-01 21:47:27 +00:00
|
|
|
* 4) attached picture, HLS bitrate
|
|
|
|
* 5) lower track number
|
|
|
|
* If select_fallback is not set, 5) is only used to determine whether a
|
2013-10-29 21:38:29 +00:00
|
|
|
* matching track is preferred over another track. Otherwise, always pick a
|
|
|
|
* track (if nothing else matches, return the track with lowest ID).
|
|
|
|
*/
|
|
|
|
// Return whether t1 is preferred over t2
|
2014-09-01 21:47:27 +00:00
|
|
|
static bool compare_track(struct track *t1, struct track *t2, char **langs,
|
|
|
|
struct MPOpts *opts)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2016-08-10 20:22:50 +00:00
|
|
|
if (!opts->autoload_files && t1->is_external != t2->is_external)
|
|
|
|
return !t1->is_external;
|
2014-01-05 15:15:30 +00:00
|
|
|
bool ext1 = t1->is_external && !t1->no_default;
|
|
|
|
bool ext2 = t2->is_external && !t2->no_default;
|
|
|
|
if (ext1 != ext2)
|
|
|
|
return ext1;
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t1->auto_loaded != t2->auto_loaded)
|
|
|
|
return !t1->auto_loaded;
|
|
|
|
int l1 = match_lang(langs, t1->lang), l2 = match_lang(langs, t2->lang);
|
|
|
|
if (l1 != l2)
|
|
|
|
return l1 > l2;
|
2015-06-27 20:02:24 +00:00
|
|
|
if (t1->forced_track != t2->forced_track)
|
|
|
|
return t1->forced_track;
|
2013-10-29 21:38:29 +00:00
|
|
|
if (t1->default_track != t2->default_track)
|
|
|
|
return t1->default_track;
|
|
|
|
if (t1->attached_picture != t2->attached_picture)
|
|
|
|
return !t1->attached_picture;
|
2015-07-13 11:34:58 +00:00
|
|
|
if (t1->stream && t2->stream && opts->hls_bitrate >= 0 &&
|
|
|
|
t1->stream->hls_bitrate != t2->stream->hls_bitrate)
|
|
|
|
{
|
|
|
|
bool t1_ok = t1->stream->hls_bitrate <= opts->hls_bitrate;
|
|
|
|
bool t2_ok = t2->stream->hls_bitrate <= opts->hls_bitrate;
|
|
|
|
if (t1_ok != t2_ok)
|
|
|
|
return t1_ok;
|
|
|
|
if (t1_ok && t2_ok)
|
|
|
|
return t1->stream->hls_bitrate > t2->stream->hls_bitrate;
|
|
|
|
return t1->stream->hls_bitrate < t2->stream->hls_bitrate;
|
2014-09-01 21:47:27 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
return t1->user_tid <= t2->user_tid;
|
|
|
|
}
|
2015-05-22 19:00:24 +00:00
|
|
|
struct track *select_default_track(struct MPContext *mpctx, int order,
|
|
|
|
enum stream_type type)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2015-05-22 19:00:24 +00:00
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
int tid = opts->stream_id[order][type];
|
|
|
|
int ffid = order == 0 ? opts->stream_id_ff[type] : -1;
|
|
|
|
char **langs = order == 0 ? opts->stream_lang[type] : NULL;
|
2014-10-21 11:16:48 +00:00
|
|
|
if (ffid != -1)
|
|
|
|
tid = -1; // prefer selecting ffid
|
|
|
|
if (tid == -2 || ffid == -2)
|
2013-10-29 21:38:29 +00:00
|
|
|
return NULL;
|
|
|
|
bool select_fallback = type == STREAM_VIDEO || type == STREAM_AUDIO;
|
|
|
|
struct track *pick = NULL;
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
if (track->type != type)
|
|
|
|
continue;
|
|
|
|
if (track->user_tid == tid)
|
|
|
|
return track;
|
2014-10-21 11:16:48 +00:00
|
|
|
if (track->ff_index == ffid)
|
|
|
|
return track;
|
2014-09-01 21:47:27 +00:00
|
|
|
if (!pick || compare_track(track, pick, langs, mpctx->opts))
|
2013-10-29 21:38:29 +00:00
|
|
|
pick = track;
|
|
|
|
}
|
2014-01-05 15:15:30 +00:00
|
|
|
if (pick && !select_fallback && !(pick->is_external && !pick->no_default)
|
2015-06-27 20:02:24 +00:00
|
|
|
&& !match_lang(langs, pick->lang) && !pick->default_track
|
|
|
|
&& !pick->forced_track)
|
2013-10-29 21:38:29 +00:00
|
|
|
pick = NULL;
|
|
|
|
if (pick && pick->attached_picture && !mpctx->opts->audio_display)
|
|
|
|
pick = NULL;
|
2016-08-10 20:22:50 +00:00
|
|
|
if (pick && !opts->autoload_files && pick->is_external)
|
|
|
|
pick = NULL;
|
2013-10-29 21:38:29 +00:00
|
|
|
return pick;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *track_layout_hash(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
char *h = talloc_strdup(NULL, "");
|
|
|
|
for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
if (track->type != type)
|
|
|
|
continue;
|
|
|
|
h = talloc_asprintf_append_buffer(h, "%d-%d-%d-%d-%s\n", type,
|
|
|
|
track->user_tid, track->default_track, track->is_external,
|
|
|
|
track->lang ? track->lang : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normally, video/audio/sub track selection is persistent across files. This
|
|
|
|
// code resets track selection if the new file has a different track layout.
|
|
|
|
static void check_previous_track_selection(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
|
|
|
|
if (!mpctx->track_layout_hash)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *h = track_layout_hash(mpctx);
|
|
|
|
if (strcmp(h, mpctx->track_layout_hash) != 0) {
|
2015-05-22 19:00:24 +00:00
|
|
|
// Reset selection, but only if they're not "auto" or "off". The
|
|
|
|
// defaults are -1 (default selection), or -2 (off) for secondary tracks.
|
|
|
|
for (int t = 0; t < STREAM_TYPE_COUNT; t++) {
|
|
|
|
for (int i = 0; i < NUM_PTRACKS; i++) {
|
|
|
|
if (opts->stream_id[i][t] >= 0)
|
|
|
|
opts->stream_id[i][t] = i == 0 ? -1 : -2;
|
|
|
|
}
|
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(mpctx->track_layout_hash);
|
|
|
|
mpctx->track_layout_hash = NULL;
|
|
|
|
}
|
|
|
|
talloc_free(h);
|
|
|
|
}
|
|
|
|
|
2013-12-24 16:46:08 +00:00
|
|
|
void mp_switch_track_n(struct MPContext *mpctx, int order, enum stream_type type,
|
2015-05-26 12:01:23 +00:00
|
|
|
struct track *track, int flags)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
|
|
|
assert(!track || track->type == type);
|
2013-12-24 16:46:08 +00:00
|
|
|
assert(order >= 0 && order < NUM_PTRACKS);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-05-26 12:01:23 +00:00
|
|
|
// Mark the current track selection as explicitly user-requested. (This is
|
|
|
|
// different from auto-selection or disabling a track due to errors.)
|
|
|
|
if (flags & FLAG_MARK_SELECTION)
|
|
|
|
mpctx->opts->stream_id[order][type] = track ? track->user_tid : -2;
|
|
|
|
|
|
|
|
// No decoder should be initialized yet.
|
|
|
|
if (!mpctx->demuxer)
|
|
|
|
return;
|
|
|
|
|
2013-12-24 16:46:08 +00:00
|
|
|
struct track *current = mpctx->current_track[order][type];
|
2013-10-29 21:38:29 +00:00
|
|
|
if (track == current)
|
|
|
|
return;
|
|
|
|
|
2016-02-05 22:19:56 +00:00
|
|
|
if (current && current->sink) {
|
|
|
|
MP_ERR(mpctx, "Can't disable input to complex filter.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((type == STREAM_VIDEO && mpctx->vo_chain && !mpctx->vo_chain->track) ||
|
|
|
|
(type == STREAM_AUDIO && mpctx->ao_chain && !mpctx->ao_chain->track))
|
|
|
|
{
|
|
|
|
MP_ERR(mpctx, "Can't switch away from complex filter output.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-25 10:24:37 +00:00
|
|
|
if (track && track->selected) {
|
|
|
|
// Track has been selected in a different order parameter.
|
|
|
|
MP_ERR(mpctx, "Track %d is already selected.\n", track->user_tid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-24 16:46:08 +00:00
|
|
|
if (order == 0) {
|
|
|
|
if (type == STREAM_VIDEO) {
|
2014-10-03 17:57:49 +00:00
|
|
|
uninit_video_chain(mpctx);
|
2015-02-03 22:09:02 +00:00
|
|
|
if (!track)
|
2016-04-23 15:24:03 +00:00
|
|
|
handle_force_window(mpctx, true);
|
2013-12-24 16:46:08 +00:00
|
|
|
} else if (type == STREAM_AUDIO) {
|
2014-07-13 18:07:14 +00:00
|
|
|
clear_audio_output_buffers(mpctx);
|
2014-10-03 17:57:49 +00:00
|
|
|
uninit_audio_chain(mpctx);
|
|
|
|
uninit_audio_out(mpctx);
|
2013-12-24 16:46:08 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
2016-01-17 15:56:32 +00:00
|
|
|
if (type == STREAM_SUB)
|
|
|
|
uninit_sub(mpctx, current);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-02-25 21:44:50 +00:00
|
|
|
if (current) {
|
2013-12-23 19:14:54 +00:00
|
|
|
current->selected = false;
|
2016-02-25 21:44:50 +00:00
|
|
|
reselect_demux_stream(mpctx, current);
|
|
|
|
}
|
2013-12-23 19:14:54 +00:00
|
|
|
|
2013-12-24 16:46:08 +00:00
|
|
|
mpctx->current_track[order][type] = track;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-02-25 21:44:50 +00:00
|
|
|
if (track) {
|
2013-12-23 19:14:54 +00:00
|
|
|
track->selected = true;
|
2016-02-25 21:44:50 +00:00
|
|
|
reselect_demux_stream(mpctx, track);
|
|
|
|
}
|
2013-12-23 19:14:54 +00:00
|
|
|
|
2014-03-03 22:58:19 +00:00
|
|
|
if (type == STREAM_VIDEO && order == 0) {
|
|
|
|
reinit_video_chain(mpctx);
|
|
|
|
} else if (type == STREAM_AUDIO && order == 0) {
|
|
|
|
reinit_audio_chain(mpctx);
|
|
|
|
} else if (type == STREAM_SUB && order >= 0 && order <= 2) {
|
2016-01-17 15:56:32 +00:00
|
|
|
reinit_sub(mpctx, track);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_TRACK_SWITCHED, NULL);
|
2014-02-03 21:00:59 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(mpctx->track_layout_hash);
|
|
|
|
mpctx->track_layout_hash = talloc_steal(mpctx, track_layout_hash(mpctx));
|
|
|
|
}
|
|
|
|
|
2013-12-24 16:46:08 +00:00
|
|
|
void mp_switch_track(struct MPContext *mpctx, enum stream_type type,
|
2015-05-26 12:01:23 +00:00
|
|
|
struct track *track, int flags)
|
2013-12-24 16:46:08 +00:00
|
|
|
{
|
2015-05-26 12:01:23 +00:00
|
|
|
mp_switch_track_n(mpctx, 0, type, track, flags);
|
2013-12-24 16:46:08 +00:00
|
|
|
}
|
|
|
|
|
2013-12-23 19:14:54 +00:00
|
|
|
void mp_deselect_track(struct MPContext *mpctx, struct track *track)
|
|
|
|
{
|
2013-12-24 16:46:08 +00:00
|
|
|
if (track && track->selected) {
|
|
|
|
for (int t = 0; t < NUM_PTRACKS; t++)
|
2015-05-26 12:01:23 +00:00
|
|
|
mp_switch_track_n(mpctx, t, track->type, NULL, 0);
|
2013-12-24 16:46:08 +00:00
|
|
|
}
|
2013-12-23 19:14:54 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
|
|
|
|
int tid)
|
|
|
|
{
|
|
|
|
if (tid == -1)
|
2013-12-24 16:46:08 +00:00
|
|
|
return mpctx->current_track[0][type];
|
2013-10-29 21:38:29 +00:00
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
if (track->type == type && track->user_tid == tid)
|
|
|
|
return track;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mp_remove_track(struct MPContext *mpctx, struct track *track)
|
|
|
|
{
|
|
|
|
if (!track->is_external)
|
|
|
|
return false;
|
|
|
|
|
2013-12-23 19:14:54 +00:00
|
|
|
mp_deselect_track(mpctx, track);
|
|
|
|
if (track->selected)
|
|
|
|
return false;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-02-22 18:06:21 +00:00
|
|
|
struct demuxer *d = track->demuxer;
|
|
|
|
|
2016-01-17 15:56:32 +00:00
|
|
|
sub_destroy(track->d_sub);
|
2015-12-26 17:32:27 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
int index = 0;
|
|
|
|
while (index < mpctx->num_tracks && mpctx->tracks[index] != track)
|
|
|
|
index++;
|
2015-02-17 22:43:43 +00:00
|
|
|
MP_TARRAY_REMOVE_AT(mpctx->tracks, mpctx->num_tracks, index);
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(track);
|
|
|
|
|
2015-02-22 18:06:21 +00:00
|
|
|
// Close the demuxer, unless there is still a track using it. These are
|
2016-02-15 20:03:51 +00:00
|
|
|
// all external tracks.
|
2015-02-22 18:06:21 +00:00
|
|
|
bool in_use = false;
|
|
|
|
for (int n = mpctx->num_tracks - 1; n >= 0 && !in_use; n--)
|
|
|
|
in_use |= mpctx->tracks[n]->demuxer == d;
|
|
|
|
|
2016-02-23 21:12:11 +00:00
|
|
|
if (!in_use)
|
2015-02-22 18:06:21 +00:00
|
|
|
free_demuxer_and_stream(d);
|
2015-02-17 22:43:13 +00:00
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:18:35 +00:00
|
|
|
// Add the given file as additional track. Only tracks of type "filter" are
|
|
|
|
// included; pass STREAM_TYPE_COUNT to disable filtering.
|
2015-02-03 08:15:14 +00:00
|
|
|
struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
|
|
|
|
enum stream_type filter)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
if (!filename)
|
|
|
|
return NULL;
|
2015-02-02 20:23:12 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
char *disp_filename = filename;
|
|
|
|
if (strncmp(disp_filename, "memory://", 9) == 0)
|
|
|
|
disp_filename = "memory://"; // avoid noise
|
2015-02-02 20:23:12 +00:00
|
|
|
|
2016-01-18 16:42:34 +00:00
|
|
|
struct demuxer_params params = {0};
|
2015-02-20 20:21:14 +00:00
|
|
|
|
2015-02-02 20:23:12 +00:00
|
|
|
switch (filter) {
|
|
|
|
case STREAM_SUB:
|
2015-02-20 20:21:14 +00:00
|
|
|
params.force_format = opts->sub_demuxer_name;
|
2015-02-02 20:23:12 +00:00
|
|
|
break;
|
|
|
|
case STREAM_AUDIO:
|
2015-02-20 20:21:14 +00:00
|
|
|
params.force_format = opts->audio_demuxer_name;
|
2015-02-02 20:23:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-20 20:56:55 +00:00
|
|
|
struct demuxer *demuxer =
|
|
|
|
demux_open_url(filename, ¶ms, mpctx->playback_abort, mpctx->global);
|
|
|
|
if (!demuxer)
|
2013-10-29 21:38:29 +00:00
|
|
|
goto err_out;
|
2016-02-23 21:51:18 +00:00
|
|
|
enable_demux_thread(mpctx, demuxer);
|
2015-02-02 20:23:12 +00:00
|
|
|
|
2015-11-16 21:47:17 +00:00
|
|
|
if (filter != STREAM_SUB && opts->rebase_start_time)
|
|
|
|
demux_set_ts_offset(demuxer, -demuxer->start_time);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
struct track *first = NULL;
|
demux: remove weird tripple-buffering for the sh_stream list
The demuxer infrastructure was originally single-threaded. To make it
suitable for multithreading (specifically, demuxing and decoding on
separate threads), some sort of tripple-buffering was introduced. There
are separate "struct demuxer" allocations. The demuxer thread sets the
state on d_thread. If anything changes, the state is copied to d_buffer
(the copy is protected by a lock), and the decoder thread is notified.
Then the decoder thread copies the state from d_buffer to d_user (again
while holding a lock). This avoids the need for locking in the
demuxer/decoder code itself (only demux.c needs an internal, "invisible"
lock.)
Remove the streams/num_streams fields from this tripple-buffering
schema. Move them to the internal struct, and protect them with the
internal lock. Use accessors for read access outside of demux.c.
Other than replacing all field accesses with accessors, this separates
allocating and adding sh_streams. This is needed to avoid race
conditions. Before this change, this was awkwardly handled by first
initializing the sh_stream, and then sending a stream change event. Now
the stream is allocated, then initialized, and then declared as
immutable and added (at which point it becomes visible to the decoder
thread immediately).
This change is useful for PR #2626. And eventually, we should probably
get entirely of the tripple buffering, and this makes a nice first step.
2015-12-23 20:44:53 +00:00
|
|
|
for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
|
|
|
|
struct sh_stream *sh = demux_get_stream(demuxer, n);
|
2016-02-08 20:18:35 +00:00
|
|
|
if (filter == STREAM_TYPE_COUNT || sh->type == filter) {
|
2016-02-15 20:03:51 +00:00
|
|
|
struct track *t = add_stream_track(mpctx, demuxer, sh);
|
2013-10-29 21:38:29 +00:00
|
|
|
t->is_external = true;
|
2014-08-02 00:08:49 +00:00
|
|
|
t->title = talloc_strdup(t, mp_basename(disp_filename));
|
2013-10-29 21:38:29 +00:00
|
|
|
t->external_filename = talloc_strdup(t, filename);
|
|
|
|
first = t;
|
2016-02-08 20:18:35 +00:00
|
|
|
// --external-file special semantics
|
|
|
|
t->no_default = filter == STREAM_TYPE_COUNT;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!first) {
|
2015-02-20 20:08:10 +00:00
|
|
|
free_demuxer_and_stream(demuxer);
|
|
|
|
MP_WARN(mpctx, "No streams added from file %s.\n", disp_filename);
|
2013-10-29 21:38:29 +00:00
|
|
|
goto err_out;
|
|
|
|
}
|
2015-02-02 20:23:12 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
return first;
|
|
|
|
|
|
|
|
err_out:
|
2015-02-20 20:08:10 +00:00
|
|
|
MP_ERR(mpctx, "Can not open external file %s.\n", disp_filename);
|
2013-10-29 21:38:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-08 20:18:35 +00:00
|
|
|
static void open_external_files(struct MPContext *mpctx, char **files,
|
|
|
|
enum stream_type filter)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2016-02-08 20:18:35 +00:00
|
|
|
for (int n = 0; files && files[n]; n++)
|
|
|
|
mp_add_external_file(mpctx, files[n], filter);
|
2015-02-02 20:23:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 21:06:41 +00:00
|
|
|
void autoload_external_files(struct MPContext *mpctx)
|
2015-02-02 20:23:12 +00:00
|
|
|
{
|
|
|
|
if (mpctx->opts->sub_auto < 0 && mpctx->opts->audiofile_auto < 0)
|
|
|
|
return;
|
2016-08-10 20:22:50 +00:00
|
|
|
if (!mpctx->opts->autoload_files)
|
|
|
|
return;
|
2015-02-02 20:23:12 +00:00
|
|
|
|
|
|
|
void *tmp = talloc_new(NULL);
|
|
|
|
char *base_filename = mpctx->filename;
|
|
|
|
char *stream_filename = NULL;
|
|
|
|
if (mpctx->demuxer) {
|
|
|
|
if (demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_BASE_FILENAME,
|
|
|
|
&stream_filename) > 0)
|
|
|
|
base_filename = talloc_steal(tmp, stream_filename);
|
|
|
|
}
|
|
|
|
struct subfn *list = find_external_files(mpctx->global, base_filename);
|
|
|
|
talloc_steal(tmp, list);
|
2015-02-05 21:14:17 +00:00
|
|
|
|
|
|
|
int sc[STREAM_TYPE_COUNT] = {0};
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
if (!mpctx->tracks[n]->attached_picture)
|
|
|
|
sc[mpctx->tracks[n]->type]++;
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:23:12 +00:00
|
|
|
for (int i = 0; list && list[i].fname; i++) {
|
|
|
|
char *filename = list[i].fname;
|
|
|
|
char *lang = list[i].lang;
|
2016-02-23 21:12:11 +00:00
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *t = mpctx->tracks[n];
|
2016-08-26 10:31:09 +00:00
|
|
|
if (t->demuxer && strcmp(t->demuxer->filename, filename) == 0)
|
2015-02-02 20:23:12 +00:00
|
|
|
goto skip;
|
|
|
|
}
|
2015-02-05 21:14:17 +00:00
|
|
|
if (list[i].type == STREAM_SUB && !sc[STREAM_VIDEO] && !sc[STREAM_AUDIO])
|
|
|
|
goto skip;
|
|
|
|
if (list[i].type == STREAM_AUDIO && !sc[STREAM_VIDEO])
|
|
|
|
goto skip;
|
2015-02-03 08:15:14 +00:00
|
|
|
struct track *track = mp_add_external_file(mpctx, filename, list[i].type);
|
2015-02-02 20:23:12 +00:00
|
|
|
if (track) {
|
|
|
|
track->auto_loaded = true;
|
|
|
|
if (!track->lang)
|
|
|
|
track->lang = talloc_strdup(track, lang);
|
|
|
|
}
|
|
|
|
skip:;
|
|
|
|
}
|
2015-02-05 21:14:17 +00:00
|
|
|
|
2015-02-02 20:23:12 +00:00
|
|
|
talloc_free(tmp);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 21:08:22 +00:00
|
|
|
// Do stuff to a newly loaded playlist. This includes any processing that may
|
|
|
|
// be required after loading a playlist.
|
|
|
|
void prepare_playlist(struct MPContext *mpctx, struct playlist *pl)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
|
2015-08-22 20:08:17 +00:00
|
|
|
pl->current = NULL;
|
|
|
|
|
|
|
|
if (opts->playlist_pos >= 0)
|
|
|
|
pl->current = playlist_entry_from_index(pl, opts->playlist_pos);
|
|
|
|
|
2014-12-29 21:08:22 +00:00
|
|
|
if (opts->shuffle)
|
|
|
|
playlist_shuffle(pl);
|
|
|
|
|
|
|
|
if (opts->merge_files)
|
|
|
|
merge_playlist_files(pl);
|
|
|
|
|
2015-08-22 20:08:17 +00:00
|
|
|
if (!pl->current)
|
|
|
|
pl->current = mp_check_playlist_resume(mpctx, pl);
|
|
|
|
|
2014-12-29 21:08:22 +00:00
|
|
|
if (!pl->current)
|
|
|
|
pl->current = pl->first;
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// Replace the current playlist entry with playlist contents. Moves the entries
|
|
|
|
// from the given playlist pl, so the entries don't actually need to be copied.
|
|
|
|
static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl)
|
|
|
|
{
|
2013-11-03 18:22:13 +00:00
|
|
|
if (pl->first) {
|
2014-12-29 21:08:22 +00:00
|
|
|
prepare_playlist(mpctx, pl);
|
|
|
|
struct playlist_entry *new = pl->current;
|
2016-01-06 21:40:55 +00:00
|
|
|
if (mpctx->playlist->current)
|
|
|
|
playlist_add_redirect(pl, mpctx->playlist->current->filename);
|
2013-11-03 18:22:13 +00:00
|
|
|
playlist_transfer_entries(mpctx->playlist, pl);
|
|
|
|
// current entry is replaced
|
2013-10-29 21:38:29 +00:00
|
|
|
if (mpctx->playlist->current)
|
|
|
|
playlist_remove(mpctx->playlist, mpctx->playlist->current);
|
2014-09-02 20:16:20 +00:00
|
|
|
if (new)
|
|
|
|
mpctx->playlist->current = new;
|
2013-10-29 21:38:29 +00:00
|
|
|
} else {
|
|
|
|
MP_WARN(mpctx, "Empty playlist!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
command: add a mechanism to allow scripts to intercept file loads
A vague idea to get something similar what libquvi did.
Undocumented because it might change a lot, or even be removed. To give
an idea what it does, a Lua script could do the following:
-- type ID priority
mp.commandv("hook_add", "on_load", 0, 0)
mp.register_script_message("hook_run", function(param, param2)
-- param is "0", the user-chosen ID from the hook_add command
-- param2 is the magic value that has to be passed to finish
-- the hook
mp.resume_all()
-- do something, maybe set options that are reset on end:
mp.set_property("file-local-options/name", "value")
-- or change the URL that's being opened:
local url = mp.get_property("stream-open-filename")
mp.set_property("stream-open-filename", url .. ".png")
-- let the player (or the next script) continue
mp.commandv("hook_ack", param2)
end)
2014-10-15 21:09:53 +00:00
|
|
|
static int process_open_hooks(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
|
|
|
|
mp_hook_run(mpctx, NULL, "on_load");
|
|
|
|
|
|
|
|
while (!mp_hook_test_completion(mpctx, "on_load")) {
|
|
|
|
mp_idle(mpctx);
|
|
|
|
if (mpctx->stop_play) {
|
|
|
|
// Can't exit immediately, the script would interfere with the
|
|
|
|
// next file being loaded.
|
2014-10-20 21:43:10 +00:00
|
|
|
if (mpctx->stop_play == PT_QUIT)
|
|
|
|
return -1;
|
command: add a mechanism to allow scripts to intercept file loads
A vague idea to get something similar what libquvi did.
Undocumented because it might change a lot, or even be removed. To give
an idea what it does, a Lua script could do the following:
-- type ID priority
mp.commandv("hook_add", "on_load", 0, 0)
mp.register_script_message("hook_run", function(param, param2)
-- param is "0", the user-chosen ID from the hook_add command
-- param2 is the magic value that has to be passed to finish
-- the hook
mp.resume_all()
-- do something, maybe set options that are reset on end:
mp.set_property("file-local-options/name", "value")
-- or change the URL that's being opened:
local url = mp.get_property("stream-open-filename")
mp.set_property("stream-open-filename", url .. ".png")
-- let the player (or the next script) continue
mp.commandv("hook_ack", param2)
end)
2014-10-15 21:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-15 15:19:19 +00:00
|
|
|
static int process_preloaded_hooks(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
mp_hook_run(mpctx, NULL, "on_preloaded");
|
|
|
|
|
|
|
|
while (!mp_hook_test_completion(mpctx, "on_preloaded")) {
|
|
|
|
mp_idle(mpctx);
|
|
|
|
if (mpctx->stop_play)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-04 17:25:40 +00:00
|
|
|
static void process_unload_hooks(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
mp_hook_run(mpctx, NULL, "on_unload");
|
|
|
|
|
|
|
|
while (!mp_hook_test_completion(mpctx, "on_unload"))
|
|
|
|
mp_idle(mpctx);
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:05:48 +00:00
|
|
|
static void load_chapters(struct MPContext *mpctx)
|
|
|
|
{
|
2016-02-15 20:03:51 +00:00
|
|
|
struct demuxer *src = mpctx->demuxer;
|
2014-11-02 15:47:23 +00:00
|
|
|
bool free_src = false;
|
|
|
|
char *chapter_file = mpctx->opts->chapter_file;
|
|
|
|
if (chapter_file && chapter_file[0]) {
|
2015-06-24 19:26:06 +00:00
|
|
|
struct demuxer *demux = demux_open_url(chapter_file, NULL,
|
2014-11-02 15:47:23 +00:00
|
|
|
mpctx->playback_abort, mpctx->global);
|
2015-06-24 19:26:06 +00:00
|
|
|
if (demux) {
|
|
|
|
src = demux;
|
|
|
|
free_src = true;
|
2014-11-02 15:47:23 +00:00
|
|
|
}
|
|
|
|
talloc_free(mpctx->chapters);
|
|
|
|
mpctx->chapters = NULL;
|
|
|
|
}
|
|
|
|
if (src && !mpctx->chapters) {
|
|
|
|
talloc_free(mpctx->chapters);
|
2014-11-02 16:20:04 +00:00
|
|
|
mpctx->num_chapters = src->num_chapters;
|
|
|
|
mpctx->chapters = demux_copy_chapter_data(src->chapters, src->num_chapters);
|
2015-11-16 21:47:17 +00:00
|
|
|
if (mpctx->opts->rebase_start_time) {
|
|
|
|
for (int n = 0; n < mpctx->num_chapters; n++)
|
|
|
|
mpctx->chapters[n].pts -= src->start_time;
|
|
|
|
}
|
2014-03-25 01:05:48 +00:00
|
|
|
}
|
2015-06-24 19:26:06 +00:00
|
|
|
if (free_src)
|
|
|
|
free_demuxer_and_stream(src);
|
2014-03-25 01:05:48 +00:00
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
static void load_per_file_options(m_config_t *conf,
|
|
|
|
struct playlist_param *params,
|
|
|
|
int params_count)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < params_count; n++) {
|
|
|
|
m_config_set_option_ext(conf, params[n].name, params[n].value,
|
|
|
|
M_SETOPT_BACKUP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 19:20:38 +00:00
|
|
|
struct demux_open_args {
|
2015-08-03 23:01:09 +00:00
|
|
|
int stream_flags;
|
|
|
|
char *url;
|
2014-10-28 14:30:27 +00:00
|
|
|
struct mpv_global *global;
|
2015-08-03 23:01:09 +00:00
|
|
|
struct mp_cancel *cancel;
|
2015-02-20 19:28:23 +00:00
|
|
|
struct mp_log *log;
|
|
|
|
// results
|
|
|
|
struct demuxer *demux;
|
2015-08-03 23:01:09 +00:00
|
|
|
int err;
|
2014-10-06 19:20:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void open_demux_thread(void *pctx)
|
|
|
|
{
|
|
|
|
struct demux_open_args *args = pctx;
|
2014-10-28 14:30:27 +00:00
|
|
|
struct mpv_global *global = args->global;
|
2015-08-03 23:01:09 +00:00
|
|
|
struct demuxer_params p = {
|
|
|
|
.force_format = global->opts->demuxer_name,
|
|
|
|
.allow_capture = true,
|
|
|
|
.stream_flags = args->stream_flags,
|
|
|
|
};
|
|
|
|
args->demux = demux_open_url(args->url, &p, args->cancel, global);
|
2015-08-28 18:51:29 +00:00
|
|
|
if (!args->demux) {
|
|
|
|
if (p.demuxer_failed) {
|
|
|
|
args->err = MPV_ERROR_UNKNOWN_FORMAT;
|
|
|
|
} else {
|
|
|
|
args->err = MPV_ERROR_LOADING_FAILED;
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 20:03:51 +00:00
|
|
|
if (args->demux && global->opts->rebase_start_time)
|
|
|
|
demux_set_ts_offset(args->demux, -args->demux->start_time);
|
2014-10-06 19:20:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 19:28:23 +00:00
|
|
|
static void open_demux_reentrant(struct MPContext *mpctx)
|
2014-10-06 19:20:38 +00:00
|
|
|
{
|
2015-02-20 19:28:23 +00:00
|
|
|
struct demux_open_args args = {
|
2016-09-09 15:44:02 +00:00
|
|
|
.global = mpctx->global,
|
2015-08-03 23:01:09 +00:00
|
|
|
.cancel = mpctx->playback_abort,
|
2015-02-20 19:28:23 +00:00
|
|
|
.log = mpctx->log,
|
2015-08-03 23:01:09 +00:00
|
|
|
.stream_flags = mpctx->playing->stream_flags,
|
|
|
|
.url = talloc_strdup(NULL, mpctx->stream_open_filename),
|
2015-02-20 19:28:23 +00:00
|
|
|
};
|
2015-08-03 23:01:09 +00:00
|
|
|
if (mpctx->opts->load_unsafe_playlists)
|
|
|
|
args.stream_flags = 0;
|
2015-02-20 19:06:43 +00:00
|
|
|
mpctx_run_reentrant(mpctx, open_demux_thread, &args);
|
2014-10-28 14:30:27 +00:00
|
|
|
if (args.demux) {
|
2016-02-15 20:03:51 +00:00
|
|
|
mpctx->demuxer = args.demux;
|
2016-02-23 21:51:18 +00:00
|
|
|
enable_demux_thread(mpctx, mpctx->demuxer);
|
2014-10-28 14:30:27 +00:00
|
|
|
} else {
|
2015-08-03 23:01:09 +00:00
|
|
|
mpctx->error_playing = args.err;
|
2014-10-28 14:30:27 +00:00
|
|
|
}
|
2015-08-03 23:01:09 +00:00
|
|
|
talloc_free(args.url);
|
2014-10-06 19:20:38 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 21:08:47 +00:00
|
|
|
static bool init_complex_filters(struct MPContext *mpctx)
|
2016-02-05 22:19:56 +00:00
|
|
|
{
|
|
|
|
assert(!mpctx->lavfi);
|
|
|
|
|
|
|
|
char *graph = mpctx->opts->lavfi_complex;
|
|
|
|
|
|
|
|
if (!graph || !graph[0])
|
2016-02-10 21:08:47 +00:00
|
|
|
return true;
|
2016-02-05 22:19:56 +00:00
|
|
|
|
|
|
|
mpctx->lavfi = lavfi_create(mpctx->log, graph);
|
|
|
|
if (!mpctx->lavfi)
|
2016-02-10 21:08:47 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (lavfi_has_failed(mpctx->lavfi))
|
|
|
|
return false;
|
2016-02-05 22:19:56 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
|
|
|
|
char label[32];
|
|
|
|
char prefix;
|
|
|
|
switch (track->type) {
|
|
|
|
case STREAM_VIDEO: prefix = 'v'; break;
|
|
|
|
case STREAM_AUDIO: prefix = 'a'; break;
|
|
|
|
default: continue;
|
|
|
|
}
|
|
|
|
snprintf(label, sizeof(label), "%cid%d", prefix, track->user_tid);
|
|
|
|
|
|
|
|
struct lavfi_pad *pad = lavfi_find_pad(mpctx->lavfi, label);
|
|
|
|
if (!pad)
|
|
|
|
continue;
|
|
|
|
if (lavfi_pad_type(pad) != track->type)
|
|
|
|
continue;
|
|
|
|
if (lavfi_pad_direction(pad) != LAVFI_IN)
|
|
|
|
continue;
|
|
|
|
if (lavfi_get_connected(pad))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
track->sink = pad;
|
|
|
|
lavfi_set_connected(pad, true);
|
|
|
|
track->selected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct lavfi_pad *pad = lavfi_find_pad(mpctx->lavfi, "vo");
|
|
|
|
if (pad && lavfi_pad_type(pad) == STREAM_VIDEO &&
|
|
|
|
lavfi_pad_direction(pad) == LAVFI_OUT)
|
|
|
|
{
|
|
|
|
lavfi_set_connected(pad, true);
|
|
|
|
reinit_video_chain_src(mpctx, pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
pad = lavfi_find_pad(mpctx->lavfi, "ao");
|
|
|
|
if (pad && lavfi_pad_type(pad) == STREAM_AUDIO &&
|
|
|
|
lavfi_pad_direction(pad) == LAVFI_OUT)
|
|
|
|
{
|
|
|
|
lavfi_set_connected(pad, true);
|
|
|
|
reinit_audio_chain_src(mpctx, pad);
|
|
|
|
}
|
2016-02-10 21:08:47 +00:00
|
|
|
|
|
|
|
return true;
|
2016-02-05 22:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool init_complex_filter_decoders(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
if (!mpctx->lavfi)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
if (track->sink && track->type == STREAM_VIDEO) {
|
|
|
|
if (!init_video_decoder(mpctx, track))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (track->sink && track->type == STREAM_AUDIO) {
|
|
|
|
if (!init_audio_decoder(mpctx, track))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit_complex_filters(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
if (!mpctx->lavfi)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
|
|
|
struct track *track = mpctx->tracks[n];
|
|
|
|
|
|
|
|
if (track->d_video && !track->vo_c) {
|
|
|
|
video_uninit(track->d_video);
|
|
|
|
track->d_video = NULL;
|
|
|
|
}
|
|
|
|
if (track->d_audio && !track->ao_c) {
|
|
|
|
audio_uninit(track->d_audio);
|
|
|
|
track->d_audio = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpctx->vo_chain && mpctx->vo_chain->filter_src)
|
|
|
|
uninit_video_chain(mpctx);
|
|
|
|
if (mpctx->ao_chain && mpctx->ao_chain->filter_src)
|
|
|
|
uninit_audio_chain(mpctx);
|
|
|
|
|
|
|
|
lavfi_destroy(mpctx->lavfi);
|
|
|
|
mpctx->lavfi = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// Start playing the current playlist entry.
|
|
|
|
// Handle initialization and deinitialization.
|
|
|
|
static void play_current_file(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
double playback_start = -1e100;
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_START_FILE, NULL);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
mp_cancel_reset(mpctx->playback_abort);
|
|
|
|
|
2014-10-28 15:19:07 +00:00
|
|
|
mpctx->error_playing = MPV_ERROR_LOADING_FAILED;
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->stop_play = 0;
|
|
|
|
mpctx->filename = NULL;
|
|
|
|
mpctx->shown_aframes = 0;
|
|
|
|
mpctx->shown_vframes = 0;
|
2014-09-01 19:02:43 +00:00
|
|
|
mpctx->last_vo_pts = MP_NOPTS_VALUE;
|
|
|
|
mpctx->last_chapter_seek = -2;
|
|
|
|
mpctx->last_chapter_pts = MP_NOPTS_VALUE;
|
|
|
|
mpctx->last_chapter = -2;
|
|
|
|
mpctx->paused = false;
|
|
|
|
mpctx->paused_for_cache = false;
|
2016-04-19 20:01:30 +00:00
|
|
|
mpctx->cache_buffer = -1;
|
2014-09-01 19:02:43 +00:00
|
|
|
mpctx->playing_msg_shown = false;
|
|
|
|
mpctx->max_frames = -1;
|
2015-08-10 16:40:16 +00:00
|
|
|
mpctx->video_speed = mpctx->audio_speed = opts->playback_speed;
|
|
|
|
mpctx->speed_factor_a = mpctx->speed_factor_v = 1.0;
|
2015-08-10 16:43:25 +00:00
|
|
|
mpctx->display_sync_error = 0.0;
|
|
|
|
mpctx->display_sync_active = false;
|
2014-09-01 19:02:43 +00:00
|
|
|
mpctx->seek = (struct seek_params){ 0 };
|
|
|
|
|
|
|
|
reset_playback_state(mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-09-08 22:38:38 +00:00
|
|
|
mpctx->playing = mpctx->playlist->current;
|
|
|
|
if (!mpctx->playing || !mpctx->playing->filename)
|
2013-10-29 21:38:29 +00:00
|
|
|
goto terminate_playback;
|
2014-09-08 22:38:38 +00:00
|
|
|
mpctx->playing->reserved += 1;
|
|
|
|
|
2015-12-23 14:49:20 +00:00
|
|
|
mpctx->filename = talloc_strdup(NULL, mpctx->playing->filename);
|
command: add a mechanism to allow scripts to intercept file loads
A vague idea to get something similar what libquvi did.
Undocumented because it might change a lot, or even be removed. To give
an idea what it does, a Lua script could do the following:
-- type ID priority
mp.commandv("hook_add", "on_load", 0, 0)
mp.register_script_message("hook_run", function(param, param2)
-- param is "0", the user-chosen ID from the hook_add command
-- param2 is the magic value that has to be passed to finish
-- the hook
mp.resume_all()
-- do something, maybe set options that are reset on end:
mp.set_property("file-local-options/name", "value")
-- or change the URL that's being opened:
local url = mp.get_property("stream-open-filename")
mp.set_property("stream-open-filename", url .. ".png")
-- let the player (or the next script) continue
mp.commandv("hook_ack", param2)
end)
2014-10-15 21:09:53 +00:00
|
|
|
mpctx->stream_open_filename = mpctx->filename;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-11-11 21:07:16 +00:00
|
|
|
mpctx->add_osd_seek_info &= OSD_SEEK_INFO_EDITION | OSD_SEEK_INFO_CURRENT_FILE;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
if (opts->reset_options) {
|
|
|
|
for (int n = 0; opts->reset_options[n]; n++) {
|
|
|
|
const char *opt = opts->reset_options[n];
|
|
|
|
if (opt[0]) {
|
|
|
|
if (strcmp(opt, "all") == 0) {
|
|
|
|
m_config_backup_all_opts(mpctx->mconfig);
|
|
|
|
} else {
|
|
|
|
m_config_backup_opt(mpctx->mconfig, opt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-21 19:45:19 +00:00
|
|
|
mp_load_auto_profiles(mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-05-09 14:21:44 +00:00
|
|
|
mp_load_playback_resume(mpctx, mpctx->filename);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-09-08 22:38:38 +00:00
|
|
|
load_per_file_options(mpctx->mconfig, mpctx->playing->params,
|
|
|
|
mpctx->playing->num_params);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-09-01 19:02:43 +00:00
|
|
|
mpctx->max_frames = opts->play_frames;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-09-20 15:58:02 +00:00
|
|
|
handle_force_window(mpctx, false);
|
2015-09-20 15:05:14 +00:00
|
|
|
|
2014-09-01 19:02:43 +00:00
|
|
|
MP_INFO(mpctx, "Playing: %s\n", mpctx->filename);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-07-02 12:38:03 +00:00
|
|
|
reopen_file:
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
assert(mpctx->demuxer == NULL);
|
|
|
|
|
2014-10-25 18:07:44 +00:00
|
|
|
if (process_open_hooks(mpctx) < 0)
|
|
|
|
goto terminate_playback;
|
command: add a mechanism to allow scripts to intercept file loads
A vague idea to get something similar what libquvi did.
Undocumented because it might change a lot, or even be removed. To give
an idea what it does, a Lua script could do the following:
-- type ID priority
mp.commandv("hook_add", "on_load", 0, 0)
mp.register_script_message("hook_run", function(param, param2)
-- param is "0", the user-chosen ID from the hook_add command
-- param2 is the magic value that has to be passed to finish
-- the hook
mp.resume_all()
-- do something, maybe set options that are reset on end:
mp.set_property("file-local-options/name", "value")
-- or change the URL that's being opened:
local url = mp.get_property("stream-open-filename")
mp.set_property("stream-open-filename", url .. ".png")
-- let the player (or the next script) continue
mp.commandv("hook_ack", param2)
end)
2014-10-15 21:09:53 +00:00
|
|
|
|
2015-07-02 12:02:32 +00:00
|
|
|
if (opts->stream_dump && opts->stream_dump[0]) {
|
2016-03-26 19:14:02 +00:00
|
|
|
if (stream_dump(mpctx, mpctx->stream_open_filename) >= 0)
|
2015-07-02 12:02:32 +00:00
|
|
|
mpctx->error_playing = 1;
|
|
|
|
goto terminate_playback;
|
|
|
|
}
|
|
|
|
|
2015-02-20 19:28:23 +00:00
|
|
|
open_demux_reentrant(mpctx);
|
2016-02-15 20:03:51 +00:00
|
|
|
if (!mpctx->demuxer || mpctx->stop_play)
|
2013-10-29 21:38:29 +00:00
|
|
|
goto terminate_playback;
|
|
|
|
|
|
|
|
if (mpctx->demuxer->playlist) {
|
2014-08-31 17:49:39 +00:00
|
|
|
struct playlist *pl = mpctx->demuxer->playlist;
|
2015-03-02 18:09:36 +00:00
|
|
|
int entry_stream_flags = 0;
|
|
|
|
if (!pl->disable_safety) {
|
|
|
|
entry_stream_flags = STREAM_SAFE_ONLY;
|
2016-08-26 10:31:09 +00:00
|
|
|
if (mpctx->demuxer->is_network)
|
2015-03-02 18:09:36 +00:00
|
|
|
entry_stream_flags |= STREAM_NETWORK_ONLY;
|
|
|
|
}
|
2014-08-31 17:49:39 +00:00
|
|
|
for (struct playlist_entry *e = pl->first; e; e = e->next)
|
2014-08-31 22:12:47 +00:00
|
|
|
e->stream_flags |= entry_stream_flags;
|
2014-08-31 17:49:39 +00:00
|
|
|
transfer_playlist(mpctx, pl);
|
2014-11-08 22:03:04 +00:00
|
|
|
mp_notify_property(mpctx, "playlist");
|
2015-06-11 19:39:48 +00:00
|
|
|
mpctx->error_playing = 2;
|
2013-10-29 21:38:29 +00:00
|
|
|
goto terminate_playback;
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:05:48 +00:00
|
|
|
load_chapters(mpctx);
|
2016-02-15 20:03:51 +00:00
|
|
|
add_demuxer_tracks(mpctx, mpctx->demuxer);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-02-08 20:18:35 +00:00
|
|
|
open_external_files(mpctx, opts->audio_files, STREAM_AUDIO);
|
|
|
|
open_external_files(mpctx, opts->sub_name, STREAM_SUB);
|
|
|
|
open_external_files(mpctx, opts->external_files, STREAM_TYPE_COUNT);
|
2015-02-02 20:23:12 +00:00
|
|
|
autoload_external_files(mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
check_previous_track_selection(mpctx);
|
|
|
|
|
2016-02-15 15:19:19 +00:00
|
|
|
if (process_preloaded_hooks(mpctx))
|
|
|
|
goto terminate_playback;
|
|
|
|
|
2016-02-10 21:08:47 +00:00
|
|
|
if (!init_complex_filters(mpctx))
|
|
|
|
goto terminate_playback;
|
2016-02-05 22:19:56 +00:00
|
|
|
|
2015-05-22 19:00:24 +00:00
|
|
|
assert(NUM_PTRACKS == 2); // opts->stream_id is hardcoded to 2
|
|
|
|
for (int t = 0; t < STREAM_TYPE_COUNT; t++) {
|
2016-02-05 22:19:56 +00:00
|
|
|
for (int i = 0; i < NUM_PTRACKS; i++) {
|
|
|
|
struct track *sel = NULL;
|
|
|
|
bool taken = (t == STREAM_VIDEO && mpctx->vo_chain) ||
|
|
|
|
(t == STREAM_AUDIO && mpctx->ao_chain);
|
|
|
|
if (!taken)
|
|
|
|
sel = select_default_track(mpctx, i, t);
|
|
|
|
mpctx->current_track[i][t] = sel;
|
|
|
|
}
|
2015-05-22 19:00:24 +00:00
|
|
|
}
|
2013-12-25 10:24:37 +00:00
|
|
|
for (int t = 0; t < STREAM_TYPE_COUNT; t++) {
|
|
|
|
for (int i = 0; i < NUM_PTRACKS; i++) {
|
|
|
|
struct track *track = mpctx->current_track[i][t];
|
|
|
|
if (track) {
|
|
|
|
if (track->selected) {
|
|
|
|
MP_ERR(mpctx, "Track %d can't be selected twice.\n",
|
|
|
|
track->user_tid);
|
|
|
|
mpctx->current_track[i][t] = NULL;
|
|
|
|
} else {
|
|
|
|
track->selected = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-23 19:14:54 +00:00
|
|
|
}
|
2016-02-25 21:44:50 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < mpctx->num_tracks; n++)
|
|
|
|
reselect_demux_stream(mpctx, mpctx->tracks[n]);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-07-16 20:40:21 +00:00
|
|
|
update_demuxer_properties(mpctx);
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ENCODING
|
2013-12-24 16:46:08 +00:00
|
|
|
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_VIDEO])
|
2013-10-29 21:38:29 +00:00
|
|
|
encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_VIDEO);
|
2013-12-24 16:46:08 +00:00
|
|
|
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_AUDIO])
|
2013-10-29 21:38:29 +00:00
|
|
|
encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_AUDIO);
|
2014-03-30 17:05:59 +00:00
|
|
|
if (mpctx->encode_lavc_ctx) {
|
|
|
|
encode_lavc_set_metadata(mpctx->encode_lavc_ctx,
|
|
|
|
mpctx->demuxer->metadata);
|
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-10 16:22:20 +00:00
|
|
|
update_playback_speed(mpctx);
|
|
|
|
|
2016-02-05 22:19:56 +00:00
|
|
|
if (!init_complex_filter_decoders(mpctx))
|
|
|
|
goto terminate_playback;
|
|
|
|
|
2015-01-12 12:04:21 +00:00
|
|
|
reinit_video_chain(mpctx);
|
|
|
|
reinit_audio_chain(mpctx);
|
2016-01-17 15:56:32 +00:00
|
|
|
reinit_sub_all(mpctx);
|
2015-01-12 12:04:21 +00:00
|
|
|
|
2016-02-01 21:28:47 +00:00
|
|
|
if (!mpctx->vo_chain && !mpctx->ao_chain) {
|
|
|
|
MP_FATAL(mpctx, "No video or audio streams selected.\n");
|
|
|
|
mpctx->error_playing = MPV_ERROR_NOTHING_TO_PLAY;
|
|
|
|
goto terminate_playback;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpctx->vo_chain && mpctx->vo_chain->is_coverart) {
|
|
|
|
MP_INFO(mpctx,
|
|
|
|
"Displaying attached picture. Use --no-audio-display to prevent this.\n");
|
|
|
|
}
|
|
|
|
|
2016-02-15 14:14:11 +00:00
|
|
|
if (!mpctx->vo_chain)
|
|
|
|
handle_force_window(mpctx, true);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
MP_VERBOSE(mpctx, "Starting playback...\n");
|
|
|
|
|
2016-01-03 14:48:47 +00:00
|
|
|
mpctx->playback_initialized = true;
|
|
|
|
mp_notify(mpctx, MPV_EVENT_FILE_LOADED, NULL);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
if (mpctx->max_frames == 0) {
|
2015-07-08 19:31:31 +00:00
|
|
|
if (!mpctx->stop_play)
|
|
|
|
mpctx->stop_play = PT_NEXT_ENTRY;
|
2014-10-28 15:19:07 +00:00
|
|
|
mpctx->error_playing = 0;
|
2013-10-29 21:38:29 +00:00
|
|
|
goto terminate_playback;
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:32:24 +00:00
|
|
|
double startpos = rel_time_to_abs(mpctx, opts->play_start);
|
|
|
|
if (startpos == MP_NOPTS_VALUE && opts->chapterrange[0] > 0) {
|
2014-03-25 01:27:22 +00:00
|
|
|
double start = chapter_start_time(mpctx, opts->chapterrange[0] - 1);
|
|
|
|
if (start != MP_NOPTS_VALUE)
|
|
|
|
startpos = start;
|
|
|
|
}
|
2014-03-25 01:32:24 +00:00
|
|
|
if (startpos != MP_NOPTS_VALUE) {
|
2016-08-15 19:07:32 +00:00
|
|
|
queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, MPSEEK_DEFAULT, 0);
|
2013-10-29 21:38:29 +00:00
|
|
|
execute_queued_seek(mpctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mpctx->opts->pause)
|
2014-04-14 20:33:41 +00:00
|
|
|
pause_player(mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
playback_start = mp_time_sec();
|
2014-10-28 15:19:07 +00:00
|
|
|
mpctx->error_playing = 0;
|
2013-10-29 21:38:29 +00:00
|
|
|
while (!mpctx->stop_play)
|
|
|
|
run_playloop(mpctx);
|
|
|
|
|
|
|
|
MP_VERBOSE(mpctx, "EOF code: %d \n", mpctx->stop_play);
|
|
|
|
|
2014-10-28 18:48:56 +00:00
|
|
|
terminate_playback:
|
|
|
|
|
2015-02-04 17:25:40 +00:00
|
|
|
process_unload_hooks(mpctx);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
if (mpctx->stop_play == KEEP_PLAYING)
|
|
|
|
mpctx->stop_play = AT_END_OF_FILE;
|
|
|
|
|
2013-11-08 19:02:09 +00:00
|
|
|
if (mpctx->stop_play != AT_END_OF_FILE)
|
|
|
|
clear_audio_output_buffers(mpctx);
|
audio: don't let ao_lavc access frontend internals, change gapless audio
ao_lavc.c accesses ao->buffer, which I consider internal. The access was
done in ao_lavc.c/uninit(), which tried to get the left-over audio in
order to write the last (possibly partial) audio frame. The play()
function didn't accept partial frames, because the AOPLAY_FINAL_CHUNK
flag was not correctly set, and handling it otherwise would require an
internal FIFO.
Fix this by making sure that with gapless audio (used with encoding),
the AOPLAY_FINAL_CHUNK is set only once, instead when each file ends.
Basically, move the hack in ao_lavc's uninit to uninit_player.
One thing can not be entirely correctly handled: if gapless audio is
active, we don't know really whether the AO is closed because the file
ended playing (i.e. we want to send the buffered remainder of the audio
to the AO), or whether the user is quitting the player. (The stop_play
flag is overwritten, fixing that is perhaps not worth it.) Handle this
by adding additional code to drain the AO and the buffers when playback
is quit (see play_current_file() change).
Test case: mpv avdevice://lavfi:sine=441 avdevice://lavfi:sine=441 -length 0.2267 -gapless-audio
2013-11-08 19:00:58 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
if (mpctx->step_frames)
|
|
|
|
opts->pause = 1;
|
|
|
|
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
mp_cancel_trigger(mpctx->playback_abort);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// time to uninit all, except global stuff:
|
2016-02-05 22:19:56 +00:00
|
|
|
uninit_complex_filters(mpctx);
|
2014-10-03 17:57:49 +00:00
|
|
|
uninit_audio_chain(mpctx);
|
|
|
|
uninit_video_chain(mpctx);
|
|
|
|
uninit_sub_all(mpctx);
|
|
|
|
uninit_demuxer(mpctx);
|
2014-10-10 12:49:18 +00:00
|
|
|
if (!opts->gapless_audio && !mpctx->encode_lavc_ctx)
|
2014-10-03 17:57:49 +00:00
|
|
|
uninit_audio_out(mpctx);
|
|
|
|
|
2015-07-02 12:38:03 +00:00
|
|
|
mpctx->playback_initialized = false;
|
|
|
|
|
|
|
|
if (mpctx->stop_play == PT_RELOAD_FILE) {
|
|
|
|
mpctx->stop_play = KEEP_PLAYING;
|
2016-01-07 08:11:15 +00:00
|
|
|
mp_cancel_reset(mpctx->playback_abort);
|
2015-07-02 12:38:03 +00:00
|
|
|
goto reopen_file;
|
|
|
|
}
|
|
|
|
|
2014-10-28 14:30:27 +00:00
|
|
|
m_config_restore_backups(mpctx->mconfig);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-12-29 21:51:18 +00:00
|
|
|
talloc_free(mpctx->filtered_tags);
|
|
|
|
mpctx->filtered_tags = NULL;
|
2014-12-19 22:54:21 +00:00
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_notify(mpctx, MPV_EVENT_TRACKS_CHANGED, NULL);
|
2014-10-30 22:54:06 +00:00
|
|
|
|
|
|
|
bool nothing_played = !mpctx->shown_aframes && !mpctx->shown_vframes &&
|
|
|
|
mpctx->error_playing <= 0;
|
2014-04-10 23:23:32 +00:00
|
|
|
struct mpv_event_end_file end_event = {0};
|
|
|
|
switch (mpctx->stop_play) {
|
2014-10-28 15:19:07 +00:00
|
|
|
case PT_ERROR:
|
|
|
|
case AT_END_OF_FILE:
|
|
|
|
{
|
2015-06-11 19:39:48 +00:00
|
|
|
if (mpctx->error_playing == 0 && nothing_played)
|
2014-10-28 15:19:07 +00:00
|
|
|
mpctx->error_playing = MPV_ERROR_NOTHING_TO_PLAY;
|
2015-06-11 19:30:02 +00:00
|
|
|
if (mpctx->error_playing < 0) {
|
|
|
|
end_event.error = mpctx->error_playing;
|
2014-10-28 15:19:07 +00:00
|
|
|
end_event.reason = MPV_END_FILE_REASON_ERROR;
|
2015-06-11 19:39:48 +00:00
|
|
|
} else if (mpctx->error_playing == 2) {
|
|
|
|
end_event.reason = MPV_END_FILE_REASON_REDIRECT;
|
2014-10-28 15:19:07 +00:00
|
|
|
} else {
|
|
|
|
end_event.reason = MPV_END_FILE_REASON_EOF;
|
|
|
|
}
|
|
|
|
if (mpctx->playing) {
|
|
|
|
// Played/paused for longer than 1 second -> ok
|
|
|
|
mpctx->playing->playback_short =
|
|
|
|
playback_start < 0 || mp_time_sec() - playback_start < 1.0;
|
2014-10-30 22:54:06 +00:00
|
|
|
mpctx->playing->init_failed = nothing_played;
|
2014-10-28 15:19:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Note that error_playing is meaningless in these cases.
|
2014-04-10 23:23:32 +00:00
|
|
|
case PT_NEXT_ENTRY:
|
|
|
|
case PT_CURRENT_ENTRY:
|
2014-10-28 14:44:25 +00:00
|
|
|
case PT_STOP: end_event.reason = MPV_END_FILE_REASON_STOP; break;
|
|
|
|
case PT_QUIT: end_event.reason = MPV_END_FILE_REASON_QUIT; break;
|
2014-04-10 23:23:32 +00:00
|
|
|
};
|
|
|
|
mp_notify(mpctx, MPV_EVENT_END_FILE, &end_event);
|
2014-09-08 22:38:38 +00:00
|
|
|
|
2015-09-03 12:45:32 +00:00
|
|
|
MP_VERBOSE(mpctx, "finished playback, %s (reason %d)\n",
|
|
|
|
mpv_error_string(end_event.error), end_event.reason);
|
2015-08-03 23:01:09 +00:00
|
|
|
if (mpctx->error_playing == MPV_ERROR_UNKNOWN_FORMAT)
|
|
|
|
MP_ERR(mpctx, "Failed to recognize file format.\n");
|
|
|
|
MP_INFO(mpctx, "\n");
|
|
|
|
|
2014-09-08 22:38:38 +00:00
|
|
|
if (mpctx->playing)
|
|
|
|
playlist_entry_unref(mpctx->playing);
|
|
|
|
mpctx->playing = NULL;
|
2015-12-23 14:49:20 +00:00
|
|
|
talloc_free(mpctx->filename);
|
2014-09-08 22:38:38 +00:00
|
|
|
mpctx->filename = NULL;
|
command: add a mechanism to allow scripts to intercept file loads
A vague idea to get something similar what libquvi did.
Undocumented because it might change a lot, or even be removed. To give
an idea what it does, a Lua script could do the following:
-- type ID priority
mp.commandv("hook_add", "on_load", 0, 0)
mp.register_script_message("hook_run", function(param, param2)
-- param is "0", the user-chosen ID from the hook_add command
-- param2 is the magic value that has to be passed to finish
-- the hook
mp.resume_all()
-- do something, maybe set options that are reset on end:
mp.set_property("file-local-options/name", "value")
-- or change the URL that's being opened:
local url = mp.get_property("stream-open-filename")
mp.set_property("stream-open-filename", url .. ".png")
-- let the player (or the next script) continue
mp.commandv("hook_ack", param2)
end)
2014-10-15 21:09:53 +00:00
|
|
|
mpctx->stream_open_filename = NULL;
|
2014-09-08 22:38:38 +00:00
|
|
|
|
2014-10-30 22:54:06 +00:00
|
|
|
if (end_event.error < 0 && nothing_played) {
|
|
|
|
mpctx->files_broken++;
|
|
|
|
} else if (end_event.error < 0) {
|
|
|
|
mpctx->files_errored++;
|
|
|
|
} else {
|
|
|
|
mpctx->files_played++;
|
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the next file to play. Note that if this function returns non-NULL,
|
|
|
|
// it can have side-effects and mutate mpctx.
|
|
|
|
// direction: -1 (previous) or +1 (next)
|
|
|
|
// force: if true, don't skip playlist entries marked as failed
|
|
|
|
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction,
|
|
|
|
bool force)
|
|
|
|
{
|
|
|
|
struct playlist_entry *next = playlist_get_next(mpctx->playlist, direction);
|
|
|
|
if (next && direction < 0 && !force) {
|
|
|
|
// Don't jump to files that would immediately go to next file anyway
|
|
|
|
while (next && next->playback_short)
|
|
|
|
next = next->prev;
|
|
|
|
// Always allow jumping to first file
|
2015-02-12 21:41:45 +00:00
|
|
|
if (!next && mpctx->opts->loop_times == 1)
|
2013-10-29 21:38:29 +00:00
|
|
|
next = mpctx->playlist->first;
|
|
|
|
}
|
2015-02-12 21:41:45 +00:00
|
|
|
if (!next && mpctx->opts->loop_times != 1) {
|
2013-10-29 21:38:29 +00:00
|
|
|
if (direction > 0) {
|
|
|
|
if (mpctx->opts->shuffle)
|
|
|
|
playlist_shuffle(mpctx->playlist);
|
|
|
|
next = mpctx->playlist->first;
|
2015-02-12 21:41:45 +00:00
|
|
|
if (next && mpctx->opts->loop_times > 1)
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->opts->loop_times--;
|
|
|
|
} else {
|
|
|
|
next = mpctx->playlist->last;
|
|
|
|
// Don't jump to files that would immediately go to next file anyway
|
|
|
|
while (next && next->playback_short)
|
|
|
|
next = next->prev;
|
|
|
|
}
|
2015-02-12 21:41:45 +00:00
|
|
|
bool ignore_failures = mpctx->opts->loop_times == -2;
|
|
|
|
if (!force && next && next->init_failed && !ignore_failures) {
|
2013-10-29 21:38:29 +00:00
|
|
|
// Don't endless loop if no file in playlist is playable
|
|
|
|
bool all_failed = true;
|
|
|
|
struct playlist_entry *cur;
|
|
|
|
for (cur = mpctx->playlist->first; cur; cur = cur->next) {
|
|
|
|
all_failed &= cur->init_failed;
|
|
|
|
if (!all_failed)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (all_failed)
|
|
|
|
next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Play all entries on the playlist, starting from the current entry.
|
|
|
|
// Return if all done.
|
|
|
|
void mp_play_files(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
idle_loop(mpctx);
|
|
|
|
if (mpctx->stop_play == PT_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
play_current_file(mpctx);
|
|
|
|
if (mpctx->stop_play == PT_QUIT)
|
|
|
|
break;
|
|
|
|
|
2014-10-28 15:19:07 +00:00
|
|
|
struct playlist_entry *new_entry = mpctx->playlist->current;
|
|
|
|
if (mpctx->stop_play == PT_NEXT_ENTRY || mpctx->stop_play == PT_ERROR ||
|
|
|
|
mpctx->stop_play == AT_END_OF_FILE || !mpctx->stop_play)
|
|
|
|
{
|
2013-10-29 21:38:29 +00:00
|
|
|
new_entry = mp_next_file(mpctx, +1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
mpctx->playlist->current = new_entry;
|
|
|
|
mpctx->playlist->current_was_replaced = false;
|
|
|
|
mpctx->stop_play = 0;
|
|
|
|
|
2014-12-07 11:49:07 +00:00
|
|
|
if (!mpctx->playlist->current && mpctx->opts->player_idle_mode < 2)
|
2013-10-29 21:38:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Abort current playback and set the given entry to play next.
|
|
|
|
// e must be on the mpctx->playlist.
|
|
|
|
void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e)
|
|
|
|
{
|
2015-03-23 03:50:51 +00:00
|
|
|
assert(!e || playlist_entry_to_index(mpctx->playlist, e) >= 0);
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->playlist->current = e;
|
|
|
|
mpctx->playlist->current_was_replaced = false;
|
2015-07-08 19:31:31 +00:00
|
|
|
if (!mpctx->stop_play)
|
|
|
|
mpctx->stop_play = PT_CURRENT_ENTRY;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|