summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-08-19 18:11:53 +0200
committerwm4 <wm4@nowhere>2012-09-18 21:04:45 +0200
commitcde59e913f2c1c2cca27d10daddb54b4de6cc90a (patch)
treeb1e97bb2977e50e6d0466c698fcc8b4530113dd8 /mplayer.c
parent0f155921b046c9e6cfed3fe601aa891c2d2a8b16 (diff)
downloadmpv-cde59e913f2c1c2cca27d10daddb54b4de6cc90a.tar.bz2
mpv-cde59e913f2c1c2cca27d10daddb54b4de6cc90a.tar.xz
core: move implementation for -audiofile to the frontend
This should behave as before, with the same set of caveats.
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/mplayer.c b/mplayer.c
index e7565adfc5..06a57b597f 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -2754,6 +2754,33 @@ static int seek(MPContext *mpctx, struct seek_params seek,
return -1;
}
+ // If audio or demuxer subs come from different files, seek them too:
+ bool have_external_tracks = false;
+ for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
+ struct track *track = mpctx->current_track[type];
+ have_external_tracks |= track && track->is_external && track->demuxer;
+ }
+ if (have_external_tracks) {
+ double main_new_pos = MP_NOPTS_VALUE;
+ if (seek.type == MPSEEK_ABSOLUTE)
+ main_new_pos = seek.amount - mpctx->video_offset;
+ for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
+ struct demux_stream *ds = mpctx->demuxer->ds[type];
+ if (ds->sh && main_new_pos == MP_NOPTS_VALUE) {
+ demux_fill_buffer(mpctx->demuxer, ds);
+ if (ds->first)
+ main_new_pos = ds->first->pts;
+ }
+ }
+ assert(main_new_pos != MP_NOPTS_VALUE);
+ for (int type = 0; type < STREAM_TYPE_COUNT; type++) {
+ struct track *track = mpctx->current_track[type];
+ if (track && track->is_external && track->demuxer)
+ demux_seek(track->demuxer, main_new_pos, audio_delay,
+ SEEK_ABSOLUTE);
+ }
+ }
+
if (need_reset)
reinit_audio_chain(mpctx);
/* If we just reinitialized audio it doesn't need to be reset,
@@ -3498,6 +3525,79 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
}
}
+static void open_external_file(struct MPContext *mpctx, char *filename,
+ char *demuxer_name, int stream_cache,
+ enum stream_type filter)
+{
+ if (!filename)
+ return;
+ int format = 0;
+ struct stream *stream = open_stream(filename, &mpctx->opts, &format);
+ if (!stream)
+ goto err_out;
+ if (stream_cache) {
+ if (!stream_enable_cache(stream, stream_cache * 1024,
+ stream_cache * 1024 *
+ (mpctx->opts.stream_cache_min_percent / 100.0),
+ stream_cache * 1024 *
+ (mpctx->opts.stream_cache_seek_min_percent / 100.0)))
+ {
+ free_stream(stream);
+ mp_msg(MSGT_CPLAYER, MSGL_ERR,
+ "Can't enable external file stream cache\n");
+ return;
+ }
+ }
+ // deal with broken demuxers: preselect streams
+ int vs = -2, as = -2, ss = -2;
+ switch (filter) {
+ case STREAM_VIDEO: vs = -1; break;
+ case STREAM_AUDIO: as = -1; break;
+ case STREAM_SUB: ss = -1; break;
+ }
+ vs = -1; // avi can't go without video
+ struct demuxer *demuxer =
+ demux_open_withparams(&mpctx->opts, stream, format, demuxer_name,
+ as, vs, ss, filename, NULL);
+ if (!demuxer) {
+ free_stream(stream);
+ goto err_out;
+ }
+ int num_added = 0;
+ for (int n = 0; n < demuxer->num_streams; n++) {
+ struct sh_stream *stream = demuxer->streams[n];
+ if (stream->type == filter) {
+ struct track *t = add_stream_track(mpctx, stream, false);
+ t->is_external = true;
+ }
+ }
+ if (num_added == 0) {
+ mp_msg(MSGT_CPLAYER, MSGL_WARN, "No streams added from file %s.\n",
+ filename);
+ }
+ MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, demuxer);
+ return;
+
+err_out:
+ mp_msg(MSGT_CPLAYER, MSGL_ERR, "Can not open external file %s.\n",
+ filename);
+}
+
+static void open_audiofiles_from_options(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = &mpctx->opts;
+ open_external_file(mpctx, opts->audio_stream, opts->audio_demuxer_name,
+ opts->audio_stream_cache, STREAM_AUDIO);
+}
+
+// Just for -subfile. open_subtitles_from_options handles -sub text sub files.
+static void open_subfiles_from_options(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = &mpctx->opts;
+ open_external_file(mpctx, opts->sub_stream, opts->sub_demuxer_name,
+ 0, STREAM_SUB);
+}
+
static void print_timeline(struct MPContext *mpctx)
{
if (mpctx->timeline) {
@@ -3714,6 +3814,8 @@ goto_enable_cache:
open_subtitles_from_options(mpctx);
open_vobsubs_from_options(mpctx);
+ open_audiofiles_from_options(mpctx);
+ open_subfiles_from_options(mpctx);
mpctx->current_track[STREAM_VIDEO] =
select_track(mpctx, STREAM_VIDEO, mpctx->opts.video_id, NULL, true);