From 5177b24b25931b83adea9de6f9c578654640346c Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Thu, 10 Feb 2011 12:15:21 +0200 Subject: cleanup: demuxer.[ch]: remove unused code, make functions static Remove some unused lines from demuxer.h. Make some demuxer.c functions static. Move new_ds_stream() declaration from demuxer.h to stream.h (the function is defined in stream.c). Clean up some code in mplayer.c that had commented-out free_demuxer_stream() calls. --- mplayer.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 743a364065..b0fcc82633 100644 --- a/mplayer.c +++ b/mplayer.c @@ -4371,14 +4371,9 @@ if (edl_output_filename) { mpctx->stream=NULL; mpctx->demuxer=NULL; - if (mpctx->d_audio) { - //free_demuxer_stream(mpctx->d_audio); - mpctx->d_audio=NULL; - } - if (mpctx->d_video) { - //free_demuxer_stream(d_video); - mpctx->d_video=NULL; - } + mpctx->d_audio=NULL; + mpctx->d_video=NULL; + mpctx->d_sub = NULL; mpctx->sh_audio=NULL; mpctx->sh_video=NULL; -- cgit v1.2.3 From e8af22db818f839f5ac25a309e8838ea53e831b2 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 14 Feb 2011 09:34:39 +0200 Subject: core: ordered chapters: move timeline creation to timeline/ Add new file timeline/tl_matroska.c. Move the code that parses ordered chapter information from Matroska files and creates the timeline structure based on that to the new file. Initialize the format parameter given to open_stream() in the moved code. The previous uninitialized value shouldn't have caused any visible effects. --- mplayer.c | 207 -------------------------------------------------------------- 1 file changed, 207 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index b0fcc82633..161f1c9a2c 100644 --- a/mplayer.c +++ b/mplayer.c @@ -100,7 +100,6 @@ #include "osdep/getch2.h" #include "osdep/timer.h" -#include "osdep/findfiles.h" #include "input/input.h" @@ -3608,212 +3607,6 @@ static void run_playloop(struct MPContext *mpctx) } -static int find_ordered_chapter_sources(struct MPContext *mpctx, - struct content_source *sources, - int num_sources, - unsigned char uid_map[][16]) -{ - int num_filenames = 0; - char **filenames = NULL; - if (num_sources > 1) { - mp_msg(MSGT_CPLAYER, MSGL_INFO, "This file references data from " - "other sources.\n"); - if (mpctx->stream->type != STREAMTYPE_FILE) { - mp_msg(MSGT_CPLAYER, MSGL_WARN, "Playback source is not a " - "normal disk file. Will not search for related files.\n"); - } else { - mp_msg(MSGT_CPLAYER, MSGL_INFO, "Will scan other files in the " - "same directory to find referenced sources.\n"); - filenames = find_files(mpctx->demuxer->filename, ".mkv", - &num_filenames); - } - } - - int num_left = num_sources - 1; - for (int i = 0; i < num_filenames && num_left > 0; i++) { - mp_msg(MSGT_CPLAYER, MSGL_INFO, "Checking file %s\n", - filename_recode(filenames[i])); - int format; - struct stream *s = open_stream(filenames[i], &mpctx->opts, &format); - if (!s) - continue; - struct demuxer *d = demux_open(&mpctx->opts, s, DEMUXER_TYPE_MATROSKA, - mpctx->opts.audio_id, - mpctx->opts.video_id, - mpctx->opts.sub_id, filenames[i]); - if (!d) { - free_stream(s); - continue; - } - if (d->file_format == DEMUXER_TYPE_MATROSKA) { - for (int i = 1; i < num_sources; i++) { - if (sources[i].demuxer) - continue; - if (!memcmp(uid_map[i], d->matroska_data.segment_uid, 16)) { - mp_msg(MSGT_CPLAYER, MSGL_INFO,"Match for source %d: %s\n", - i, filename_recode(d->filename)); - sources[i].stream = s; - sources[i].demuxer = d; - num_left--; - goto match; - } - } - } - free_demuxer(d); - free_stream(s); - continue; - match: - ; - } - talloc_free(filenames); - if (num_left) { - mp_msg(MSGT_CPLAYER, MSGL_ERR, "Failed to find ordered chapter part!\n" - "There will be parts MISSING from the video!\n"); - for (int i = 1, j = 1; i < num_sources; i++) - if (sources[i].demuxer) { - sources[j] = sources[i]; - memcpy(uid_map[j], uid_map[i], 16); - j++; - } - } - return num_sources - num_left; -} - -static void build_ordered_chapter_timeline(struct MPContext *mpctx) -{ - struct MPOpts *opts = &mpctx->opts; - - if (!opts->ordered_chapters) { - mp_msg(MSGT_CPLAYER, MSGL_INFO, "File uses ordered chapters, but " - "you have disabled support for them. Ignoring.\n"); - return; - } - - mp_msg(MSGT_CPLAYER, MSGL_INFO, "File uses ordered chapters, will build " - "edit timeline.\n"); - - struct demuxer *demuxer = mpctx->demuxer; - struct matroska_data *m = &demuxer->matroska_data; - - // +1 because sources/uid_map[0] is original file even if all chapters - // actually use other sources and need separate entries - struct content_source *sources = talloc_array_ptrtype(NULL, sources, - m->num_ordered_chapters+1); - sources[0].stream = mpctx->stream; - sources[0].demuxer = mpctx->demuxer; - unsigned char uid_map[m->num_ordered_chapters+1][16]; - int num_sources = 1; - memcpy(uid_map[0], m->segment_uid, 16); - - for (int i = 0; i < m->num_ordered_chapters; i++) { - struct matroska_chapter *c = m->ordered_chapters + i; - if (!c->has_segment_uid) - memcpy(c->segment_uid, m->segment_uid, 16); - - for (int j = 0; j < num_sources; j++) - if (!memcmp(c->segment_uid, uid_map[j], 16)) - goto found1; - memcpy(uid_map[num_sources], c->segment_uid, 16); - sources[num_sources] = (struct content_source){}; - num_sources++; - found1: - ; - } - - num_sources = find_ordered_chapter_sources(mpctx, sources, num_sources, - uid_map); - - - // +1 for terminating chapter with start time marking end of last real one - struct timeline_part *timeline = talloc_array_ptrtype(NULL, timeline, - m->num_ordered_chapters + 1); - struct chapter *chapters = talloc_array_ptrtype(NULL, chapters, - m->num_ordered_chapters); - uint64_t starttime = 0; - uint64_t missing_time = 0; - int part_count = 0; - int num_chapters = 0; - uint64_t prev_part_offset = 0; - for (int i = 0; i < m->num_ordered_chapters; i++) { - struct matroska_chapter *c = m->ordered_chapters + i; - - int j; - for (j = 0; j < num_sources; j++) { - if (!memcmp(c->segment_uid, uid_map[j], 16)) - goto found2; - } - missing_time += c->end - c->start; - continue; - found2:; - /* Only add a separate part if the time or file actually changes. - * Matroska files have chapter divisions that are redundant from - * timeline point of view because the same chapter structure is used - * both to specify the timeline and for normal chapter information. - * Removing a missing inserted external chapter can also cause this. - * We allow for a configurable fudge factor because of files which - * specify chapter end times that are one frame too early; - * we don't want to try seeking over a one frame gap. */ - int64_t join_diff = c->start - starttime - prev_part_offset; - if (part_count == 0 - || FFABS(join_diff) > opts->chapter_merge_threshold * 1000000 - || sources + j != timeline[part_count - 1].source) { - timeline[part_count].source = sources + j; - timeline[part_count].start = starttime / 1e9; - timeline[part_count].source_start = c->start / 1e9; - prev_part_offset = c->start - starttime; - part_count++; - } else if (part_count > 0 && join_diff) { - /* Chapter was merged at an inexact boundary; - * adjust timestamps to match. */ - mp_msg(MSGT_CPLAYER, MSGL_V, "Merging timeline part %d with " - "offset %d ms.\n", i, (int) join_diff); - starttime += join_diff; - } - chapters[num_chapters].start = starttime / 1e9; - chapters[num_chapters].name = talloc_strdup(chapters, c->name); - starttime += c->end - c->start; - num_chapters++; - } - timeline[part_count].start = starttime / 1e9; - - if (!part_count) { - // None of the parts come from the file itself??? - talloc_free(sources); - talloc_free(timeline); - talloc_free(chapters); - return; - } - - mp_msg(MSGT_CPLAYER, MSGL_V, "Timeline contains %d parts from %d " - "sources. Total length %.3f seconds.\n", part_count, num_sources, - timeline[part_count].start); - if (missing_time) - mp_msg(MSGT_CPLAYER, MSGL_ERR, "There are %.3f seconds missing " - "from the timeline!\n", missing_time / 1e9); - mp_msg(MSGT_CPLAYER, MSGL_V, "Source files:\n"); - for (int i = 0; i < num_sources; i++) - mp_msg(MSGT_CPLAYER, MSGL_V, "%d: %s\n", i, - filename_recode(sources[i].demuxer->filename)); - mp_msg(MSGT_CPLAYER, MSGL_V, "Timeline parts: (number, start, " - "source_start, source):\n"); - for (int i = 0; i < part_count; i++) { - struct timeline_part *p = timeline + i; - mp_msg(MSGT_CPLAYER, MSGL_V, "%3d %9.3f %9.3f %3td\n", i, p->start, - p->source_start, p->source - sources); - } - mp_msg(MSGT_CPLAYER, MSGL_V, "END %9.3f\n", timeline[part_count].start); - mpctx->sources = sources; - mpctx->num_sources = num_sources; - mpctx->timeline = timeline; - mpctx->num_timeline_parts = part_count; - mpctx->num_chapters = num_chapters; - mpctx->chapters = chapters; - - mpctx->timeline_part = 0; - mpctx->demuxer = timeline[0].source->demuxer; -} - - static int read_keys(void *ctx, int fd) { getch2(ctx); -- cgit v1.2.3 From 968154ba77f8e8974d6dd36d1109a473b3ff5b6c Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Mon, 14 Feb 2011 13:05:35 +0200 Subject: EDL: add support for new EDL file format The timeline code previously added to support Matroska ordered chapters allows constructing a playback timeline from segments picked from multiple source files. Add support for a new EDL format to make this machinery available for use with file formats other than Matroska and in a manner easier to use than creating files with ordered chapters. Unlike the old -edl option which specifies an additional file with edits to apply to the video file given as the main argument, the new EDL format is used by giving only the EDL file as the file to play; that file then contains the filename(s) to use as source files where actual video segments come from. Filename paths in the EDL file are ignored. Currently the source files are only searched for in the directory of the EDL file; support for a search path option will likely be added in the future. Format of the EDL files The first line in the file must be "mplayer EDL file, version 2". The rest of the lines belong to one of these classes: 1) lines specifying source files 2) empty lines 3) lines specifying timeline segments. Lines beginning with '<' specify source files. These lines first contain an identifier used to refer to the source file later, then the filename separated by whitespace. The identifier must start with a letter. Filenames that start or end with whitespace or contain newlines are not supported. On other lines '#' characters delimit comments. Lines that contain only whitespace after comments have been removed are ignored. Timeline segments must appear in the file in chronological order. Each segment has the following information associated with it: - duration - output start time - output end time (= output start time + duration) - source id (specifies the file the content of the segment comes from) - source start time (timestamp in the source file) - source end time (= source start time + duration) The output timestamps must form a continuous timeline from 0 to the end of the last segment, such that each new segment starts from the time the previous one ends at. Source files and times may change arbitrarily between segments. The general format for lines specifying timeline segments is [output time info] source_id [source time info] source_id must be an identifier defined on a '<' line. Both the time info parts consists of zero or more of the following elements: 1) timestamp 2) -timestamp 3) +duration 4) * 5) -* , where "timestamp" and "duration" are decimal numbers (computations are done with nanosecond precision). Whitespace around "+" and "-" is optional. 1) and 2) specify start and end time of the segment on output or source side. 3) specifies duration; the semantics are the same whether this appears on output or source side. 4) and 5) are ignored on the output side (they're always implicitly assumed). On the source side 4) specifies that the segment starts where the previous segment _using this source_ ended; if there was no previous segment time 0 is used. 5) specifies that the segment ends where the next segment using this source starts. Redundant information may be omitted. It will be filled in using the following rules: - output start for first segment is 0 - two of [output start, output end, duration] imply third - two of [source start, source end, duration] imply third - output start = output end of previous segment - output end = output start of next segment - if "*", source start = source end of earlier segment - if "-*", source end = source start of a later segment As a special rule, a last zero-duration segment without a source specification may appear. This will produce no corresponding segment in the resulting timeline, but can be used as syntax to specify the end time of the timeline (with effect equal to adding -time on the previous line). Examples: ----- begin ----- mplayer EDL file, version 2 < id1 filename 0 id1 123 100 id1 456 200 id1 789 300 ----- end ----- All segments come from the source file "filename". First segment (output time 0-100) comes from time 123-223, second 456-556, third 789-889. ----- begin ----- mplayer EDL file, version 2 < f filename f 60-120 f 600-660 f 30- 90 ----- end ----- Play first seconds 60-120 from the file, then 600-660, then 30-90. ----- begin ----- mplayer EDL file, version 2 < id1 filename1 < id2 filename2 +10 id1 * +10 id2 * +10 id1 * +10 id2 * +10 id1 * +10 id2 * ----- end ----- This plays time 0-10 from filename1, then 0-10 from filename1, then 10-20 from filename1, then 10-20 from filename2, then 20-30 from filename1, then 20-30 from filename2. ----- begin ----- mplayer EDL file, version 2 < t1 filename1 < t2 filename2 t1 * +2 # segment 1 +2 t2 100 # segment 2 t1 * # segment 3 t2 *-* # segment 4 t1 3 -* # segment 5 +0.111111 t2 102.5 # segment 6 7.37 t1 5 +1 # segment 7 ----- end ----- This rather pathological example illustrates the rules for filling in implied data. All the values can be determined by recursively applying the rules given above, and the full end result is this: +2 0-2 t1 0-2 # segment 1 +2 2-4 t2 100-102 # segment 2 +0.758889 4-4.758889 t1 2-2.758889 # segment 3 +0.5 4.4758889-5.258889 t2 102-102.5 # segment 4 +2 5.258889-7.258889 t1 3-5 # segment 5 +0.111111 7.258889-7.37 t2 102.5-102.611111 # segment 6 +1 7.37-8.37 t1 5-6 # segment 7 --- mplayer.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 161f1c9a2c..2afbbbb821 100644 --- a/mplayer.c +++ b/mplayer.c @@ -4349,6 +4349,32 @@ if (mpctx->demuxer && mpctx->demuxer->type==DEMUXER_TYPE_PLAYLIST) if (mpctx->demuxer->matroska_data.ordered_chapters) build_ordered_chapter_timeline(mpctx); + if (mpctx->demuxer->type == DEMUXER_TYPE_EDL) + build_edl_timeline(mpctx); + + if (mpctx->timeline) { + mpctx->timeline_part = 0; + mpctx->demuxer = mpctx->timeline[0].source->demuxer; + + int part_count = mpctx->num_timeline_parts; + mp_msg(MSGT_CPLAYER, MSGL_V, "Timeline contains %d parts from %d " + "sources. Total length %.3f seconds.\n", part_count, + mpctx->num_sources, mpctx->timeline[part_count].start); + mp_msg(MSGT_CPLAYER, MSGL_V, "Source files:\n"); + for (int i = 0; i < mpctx->num_sources; i++) + mp_msg(MSGT_CPLAYER, MSGL_V, "%d: %s\n", i, + filename_recode(mpctx->sources[i].demuxer->filename)); + mp_msg(MSGT_CPLAYER, MSGL_V, "Timeline parts: (number, start, " + "source_start, source):\n"); + for (int i = 0; i < part_count; i++) { + struct timeline_part *p = mpctx->timeline + i; + mp_msg(MSGT_CPLAYER, MSGL_V, "%3d %9.3f %9.3f %3td\n", i, p->start, + p->source_start, p->source - mpctx->sources); + } + mp_msg(MSGT_CPLAYER, MSGL_V, "END %9.3f\n", + mpctx->timeline[part_count].start); + } + if (!mpctx->sources) { mpctx->sources = talloc_ptrtype(NULL, mpctx->sources); *mpctx->sources = (struct content_source){.stream = mpctx->stream, -- cgit v1.2.3 From 52f11f73b1b645290679a460329585ded512d8ca Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Thu, 7 Apr 2011 21:17:51 +0300 Subject: core: audio: cut audio writes at end of timeline part Cut audio data written to AO at the point where current timeline part ends (before, AO buffers were always completely filled, but playback of the "extra" audio was then cut short by resetting the AO when switching timeline parts). This doesn't make much difference for current playback behavior, but will be used by timeline support for audio-only files and is necessary for future encoding support where "playback" of written audio cannot be aborted later. --- mplayer.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 2afbbbb821..ec42de4548 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2378,9 +2378,12 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) double tt; int playsize; int playflags=0; - int audio_eof=0; + bool audio_eof = false; + bool partial_fill = false; bool format_change = false; sh_audio_t * const sh_audio = mpctx->sh_audio; + bool modifiable_audio_format = !(ao_data.format & AF_FORMAT_SPECIAL_MASK); + int unitsize = ao_data.channels * af_fmt2bits(ao_data.format) / 8; current_module="play_audio"; @@ -2406,7 +2409,7 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) current_module="decode_audio"; t = GetTimer(); - if (!opts->initial_audio_sync || (ao_data.format & AF_FORMAT_SPECIAL_MASK)) + if (!opts->initial_audio_sync || !modifiable_audio_format) mpctx->syncing_audio = false; int res; @@ -2418,23 +2421,33 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) if (res == -2) format_change = true; else if (res == ASYNC_PLAY_DONE) - return 1; - else if (mpctx->d_audio->eof) { - audio_eof = 1; - int unitsize = ao_data.channels * af_fmt2bits(ao_data.format) / 8; - if (sh_audio->a_out_buffer_len < unitsize) - return 0; - } + return 0; + else if (mpctx->d_audio->eof) + audio_eof = true; } t = GetTimer() - t; tt = t*0.000001f; audio_time_usage+=tt; + if (mpctx->timeline && modifiable_audio_format) { + double endpts = mpctx->timeline[mpctx->timeline_part + 1].start; + double bytes = (endpts - written_audio_pts(mpctx) + audio_delay) + * ao_data.bps / opts->playback_speed; + if (playsize > bytes) { + playsize = FFMAX(bytes, 0); + playflags |= AOPLAY_FINAL_CHUNK; + audio_eof = true; + partial_fill = true; + } + } + if (playsize > sh_audio->a_out_buffer_len) { + partial_fill = true; playsize = sh_audio->a_out_buffer_len; if (audio_eof) playflags |= AOPLAY_FINAL_CHUNK; } + playsize -= playsize % unitsize; if (!playsize) - return 1; + return partial_fill && audio_eof ? -2 : -partial_fill; // play audio: current_module="play_audio"; @@ -2464,13 +2477,14 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) if (format_change) { uninit_player(mpctx, INITIALIZED_AO); reinit_audio_chain(mpctx); + return -1; } - return 1; + return -partial_fill; } static int sleep_until_near_frame(struct MPContext *mpctx, float *time_frame, - float *aq_sleep_time) + bool sync_to_audio, float *aq_sleep_time) { struct MPOpts *opts = &mpctx->opts; double audio_limit = 2; @@ -2481,7 +2495,7 @@ static int sleep_until_near_frame(struct MPContext *mpctx, float *time_frame, *time_frame -= get_relative_time(mpctx); // reset timer - if (mpctx->sh_audio && !mpctx->d_audio->eof) { + if (sync_to_audio) { float delay = mpctx->audio_out->get_delay(); mp_dbg(MSGT_AVSYNC, MSGL_DBG2, "delay=%f\n", delay); @@ -3310,6 +3324,7 @@ static void run_playloop(struct MPContext *mpctx) { struct MPOpts *opts = &mpctx->opts; float aq_sleep_time = 0; + bool full_audio_buffers = false; if (opts->chapterrange[1] > 0) { int cur_chapter = get_current_chapter(mpctx); @@ -3326,11 +3341,14 @@ static void run_playloop(struct MPContext *mpctx) /*========================== PLAY AUDIO ============================*/ if (mpctx->sh_audio && !mpctx->paused - && (!mpctx->restart_playback || !mpctx->sh_video)) - if (!fill_audio_out_buffers(mpctx)) + && (!mpctx->restart_playback || !mpctx->sh_video)) { + int status = fill_audio_out_buffers(mpctx); + full_audio_buffers = status >= 0; + if (status == -2) // at eof, all audio at least written to ao if (!mpctx->sh_video) mpctx->stop_play = AT_END_OF_FILE; + } if (!mpctx->sh_video) { @@ -3413,6 +3431,7 @@ static void run_playloop(struct MPContext *mpctx) bool frame_time_remaining = sleep_until_near_frame(mpctx, &mpctx->time_frame, + full_audio_buffers, &aq_sleep_time); //====================== FLIP PAGE (VIDEO BLT): ========================= -- cgit v1.2.3 From cbeed30ae8346520ca5561dbd3689bae2b5d9add Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Thu, 7 Apr 2011 23:05:16 +0300 Subject: core: wake up a bit less often for audio-only files Sleep 100 ms between filling audio output buffers. Also do the sleeping in input read functions to enable immediate wakeups on new input. --- mplayer.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index ec42de4548..072d4152bb 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2387,23 +2387,11 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) current_module="play_audio"; - while (1) { - int sleep_time; - // all the current uses of ao_data.pts seem to be in aos that handle - // sync completely wrong; there should be no need to use ao_data.pts - // in get_space() - ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0; - playsize = mpctx->audio_out->get_space(); - if (mpctx->sh_video || playsize >= ao_data.outburst) - break; - - // handle audio-only case: - // this is where mplayer sleeps during audio-only playback - // to avoid 100% CPU use - sleep_time = (ao_data.outburst - playsize) * 1000 / ao_data.bps; - if (sleep_time < 10) sleep_time = 10; // limit to 100 wakeups per second - usec_sleep(sleep_time * 1000); - } + // all the current uses of ao_data.pts seem to be in aos that handle + // sync completely wrong; there should be no need to use ao_data.pts + // in get_space() + ao_data.pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0; + playsize = mpctx->audio_out->get_space(); // Fill buffer if needed: current_module="decode_audio"; @@ -3366,10 +3354,14 @@ static void run_playloop(struct MPContext *mpctx) print_status(mpctx, a_pos, false); - if (end_at.type == END_AT_TIME && end_at.pos < a_pos) - mpctx->stop_play = PT_NEXT_ENTRY; update_subtitles(mpctx, a_pos, mpctx->video_offset, false); update_osd_msg(mpctx); + if (end_at.type == END_AT_TIME && end_at.pos < a_pos) { + mpctx->stop_play = AT_END_OF_FILE; + } else if (!mpctx->stop_play) { + int sleep_time = full_audio_buffers || !mpctx->sh_audio ? 100 : 20; + mp_input_get_cmd(mpctx->input, sleep_time, true); + } } else { /*========================== PLAY VIDEO ============================*/ -- cgit v1.2.3 From dc3471780d755e897538c315b86241a43616e81b Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Fri, 8 Apr 2011 05:15:43 +0300 Subject: core: support timeline with audio-only files --- mplayer.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'mplayer.c') diff --git a/mplayer.c b/mplayer.c index 072d4152bb..d583f8b85f 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2534,6 +2534,8 @@ int reinit_video_chain(struct MPContext *mpctx) { struct MPOpts *opts = &mpctx->opts; sh_video_t * const sh_video = mpctx->sh_video; + if (!sh_video) + return 0; double ar=-1.0; //================== Init VIDEO (codec & libvo) ========================== if (!opts->fixed_vo || !(mpctx->initialized_flags & INITIALIZED_VO)) { @@ -2983,7 +2985,7 @@ static void reinit_decoders(struct MPContext *mpctx) mp_property_do("sub", M_PROPERTY_SET, &(int){mpctx->global_sub_pos}, mpctx); } -static void seek_reset(struct MPContext *mpctx) +static void seek_reset(struct MPContext *mpctx, bool reset_ao) { if (mpctx->sh_video) { current_module = "seek_video_reset"; @@ -3009,7 +3011,9 @@ static void seek_reset(struct MPContext *mpctx) if (mpctx->sh_audio) { current_module = "seek_audio_reset"; resync_audio_stream(mpctx->sh_audio); - mpctx->audio_out->reset(); // stop audio, throwing away buffered data + if (reset_ao) + // stop audio, throwing away buffered data + mpctx->audio_out->reset(); mpctx->sh_audio->a_buffer_len = 0; mpctx->sh_audio->a_out_buffer_len = 0; if (!mpctx->sh_video) @@ -3041,7 +3045,11 @@ static bool timeline_set_part(struct MPContext *mpctx, int i) mpctx->video_offset = n->start - n->source_start; if (n->source == p->source) return false; - uninit_player(mpctx, INITIALIZED_VCODEC | (mpctx->opts.fixed_vo && mpctx->opts.video_id != -2 ? 0 : INITIALIZED_VO) | INITIALIZED_AO | INITIALIZED_ACODEC | INITIALIZED_SUB); + enum stop_play_reason orig_stop_play = mpctx->stop_play; + if (!mpctx->sh_video && mpctx->stop_play == KEEP_PLAYING) + mpctx->stop_play = AT_END_OF_FILE; // let audio uninit drain data + uninit_player(mpctx, INITIALIZED_VCODEC | (mpctx->opts.fixed_vo ? 0 : INITIALIZED_VO) | (mpctx->opts.gapless_audio ? 0 : INITIALIZED_AO) | INITIALIZED_ACODEC | INITIALIZED_SUB); + mpctx->stop_play = orig_stop_play; mpctx->demuxer = n->source->demuxer; mpctx->d_video = mpctx->demuxer->video; mpctx->d_audio = mpctx->demuxer->audio; @@ -3070,7 +3078,8 @@ static double timeline_set_from_time(struct MPContext *mpctx, double pts, // return -1 if seek failed (non-seekable stream?), 0 otherwise -static int seek(MPContext *mpctx, struct seek_params seek) +static int seek(MPContext *mpctx, struct seek_params seek, + bool timeline_fallthrough) { struct MPOpts *opts = &mpctx->opts; @@ -3135,7 +3144,7 @@ static int seek(MPContext *mpctx, struct seek_params seek) if (seekresult == 0) return -1; - seek_reset(mpctx); + seek_reset(mpctx, !timeline_fallthrough); /* Use the target time as "current position" for further relative * seeks etc until a new video frame has been decoded */ @@ -3286,7 +3295,7 @@ int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts, chapter_name); if (res >= 0) { if (*seek_pts == -1) - seek_reset(mpctx); + seek_reset(mpctx, true); else { mpctx->last_chapter_seek = res; mpctx->last_chapter_pts = *seek_pts; @@ -3358,6 +3367,20 @@ static void run_playloop(struct MPContext *mpctx) update_osd_msg(mpctx); if (end_at.type == END_AT_TIME && end_at.pos < a_pos) { mpctx->stop_play = AT_END_OF_FILE; + } else if (mpctx->timeline && mpctx->stop_play == AT_END_OF_FILE + && mpctx->timeline_part + 1 < mpctx->num_timeline_parts + && mpctx->sh_audio) { + struct timeline_part *p = mpctx->timeline + mpctx->timeline_part; + double delay = mpctx->audio_out->get_delay(); + if (!opts->gapless_audio && p->source != (p+1)->source + && delay > 0.05) { + mpctx->stop_play = KEEP_PLAYING; + mp_input_get_cmd(mpctx->input, (delay-.05) * 1000, true); + } else { + seek(mpctx, (struct seek_params){ .type = MPSEEK_ABSOLUTE, + .amount = (p+1)->start }, + true); + } } else if (!mpctx->stop_play) { int sleep_time = full_audio_buffers || !mpctx->sh_audio ? 100 : 20; mp_input_get_cmd(mpctx->input, sleep_time, true); @@ -3396,7 +3419,8 @@ static void run_playloop(struct MPContext *mpctx) || mpctx->stop_play == AT_END_OF_FILE && mpctx->timeline_part + 1 < mpctx->num_timeline_parts) { seek(mpctx, (struct seek_params){ .type = MPSEEK_ABSOLUTE, - .amount = next->start }); + .amount = next->start }, + true); return; } } @@ -3612,7 +3636,7 @@ static void run_playloop(struct MPContext *mpctx) } if (mpctx->seek.type) { - seek(mpctx, mpctx->seek); + seek(mpctx, mpctx->seek, false); mpctx->seek = (struct seek_params){0}; } } @@ -4565,8 +4589,7 @@ if (select_subtitle(mpctx)) { print_file_properties(mpctx, mpctx->filename); - if (mpctx->sh_video) - reinit_video_chain(mpctx); + reinit_video_chain(mpctx); if (mpctx->sh_video) { if(mpctx->sh_video->output_flags & VFCAP_SPU && vo_spudec) spudec_set_hw_spu(vo_spudec,mpctx->video_out); @@ -4679,7 +4702,7 @@ if(play_n_frames==0){ // If there's a timeline force an absolute seek to initialize state if (seek_to_sec || mpctx->timeline) { queue_seek(mpctx, MPSEEK_ABSOLUTE, seek_to_sec, 0); - seek(mpctx, mpctx->seek); + seek(mpctx, mpctx->seek, false); end_at.pos += seek_to_sec; } if (opts->chapterrange[0] > 0) { @@ -4687,7 +4710,7 @@ if (opts->chapterrange[0] > 0) { if (seek_chapter(mpctx, opts->chapterrange[0]-1, &pts, NULL) >= 0 && pts > -1.0) { queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, 0); - seek(mpctx, mpctx->seek); + seek(mpctx, mpctx->seek, false); } } -- cgit v1.2.3