2009-05-08 21:51:13 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_DEMUXER_H
|
|
|
|
#define MPLAYER_DEMUXER_H
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2008-06-17 09:09:36 +00:00
|
|
|
#include <sys/types.h>
|
2008-03-05 23:32:01 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-16 21:30:48 +00:00
|
|
|
#include <stdbool.h>
|
2008-03-05 23:32:01 +00:00
|
|
|
|
2014-08-29 10:09:04 +00:00
|
|
|
#include "misc/bstr.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
2014-04-13 12:01:55 +00:00
|
|
|
#include "common/tags.h"
|
2013-11-18 17:46:44 +00:00
|
|
|
#include "packet.h"
|
2012-08-19 16:01:30 +00:00
|
|
|
#include "stheader.h"
|
2006-07-07 18:26:51 +00:00
|
|
|
|
2014-07-16 20:40:21 +00:00
|
|
|
// Maximum total size of packets queued - if larger, no new packets are read,
|
|
|
|
// and the demuxer pretends EOF was reached.
|
|
|
|
#define MAX_PACKS 16000
|
|
|
|
#define MAX_PACK_BYTES (400 * 1024 * 1024)
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2002-11-16 03:42:14 +00:00
|
|
|
// DEMUXER control commands/answers
|
|
|
|
#define DEMUXER_CTRL_NOTIMPL -1
|
|
|
|
#define DEMUXER_CTRL_DONTKNOW 0
|
|
|
|
#define DEMUXER_CTRL_OK 1
|
2013-04-14 04:20:31 +00:00
|
|
|
|
2013-10-02 19:19:16 +00:00
|
|
|
enum demux_ctrl {
|
2014-02-06 12:41:20 +00:00
|
|
|
DEMUXER_CTRL_SWITCHED_TRACKS = 1,
|
2013-10-02 19:19:16 +00:00
|
|
|
DEMUXER_CTRL_GET_TIME_LENGTH,
|
|
|
|
DEMUXER_CTRL_RESYNC,
|
|
|
|
DEMUXER_CTRL_IDENTIFY_PROGRAM,
|
2014-07-16 20:40:21 +00:00
|
|
|
DEMUXER_CTRL_STREAM_CTRL,
|
player: redo how stream caching and pausing on low cache works
Add the --cache-secs option, which literally overrides the value of
--demuxer-readahead-secs if the stream cache is active. The default
value is very high (10 seconds), which means it can act as network
cache.
Remove the old behavior of trying to pause once the byte cache runs
low. Instead, do something similar wit the demuxer cache. The nice
thing is that we can guess how many seconds of video it has cached,
and we can make better decisions. But for now, apply a relatively
naive heuristic: if the cache is below 0.5 secs, pause, and wait
until at least 2 secs are available.
Note that due to timestamp reordering, the estimated cached duration
of video might be inaccurate, depending on the file format. If the
file format has DTS, it's easy, otherwise the duration will seemingly
jump back and forth.
2014-08-26 23:13:20 +00:00
|
|
|
DEMUXER_CTRL_GET_READER_STATE,
|
2014-12-04 20:06:18 +00:00
|
|
|
DEMUXER_CTRL_GET_NAV_EVENT,
|
2014-12-12 00:00:58 +00:00
|
|
|
DEMUXER_CTRL_GET_BITRATE_STATS, // double[STREAM_TYPE_COUNT]
|
player: redo how stream caching and pausing on low cache works
Add the --cache-secs option, which literally overrides the value of
--demuxer-readahead-secs if the stream cache is active. The default
value is very high (10 seconds), which means it can act as network
cache.
Remove the old behavior of trying to pause once the byte cache runs
low. Instead, do something similar wit the demuxer cache. The nice
thing is that we can guess how many seconds of video it has cached,
and we can make better decisions. But for now, apply a relatively
naive heuristic: if the cache is below 0.5 secs, pause, and wait
until at least 2 secs are available.
Note that due to timestamp reordering, the estimated cached duration
of video might be inaccurate, depending on the file format. If the
file format has DTS, it's easy, otherwise the duration will seemingly
jump back and forth.
2014-08-26 23:13:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct demux_ctrl_reader_state {
|
|
|
|
bool eof, underrun, idle;
|
|
|
|
double ts_range[2]; // start, end
|
2014-08-27 20:42:28 +00:00
|
|
|
double ts_duration;
|
command: redo ancient TV/DVB/PVR commands
Convert all these commands to properties. (Except tv_last_channel, not
sure what to do with this.) Also, internally, don't access stream
details directly, but dispatch commands with stream ctrls.
Many of the new properties are a bit strange, because they're write-
only. Also remove some OSD output these commands produced, because I
couldn't be bothered to port these.
In general, this makes everything much cleaner, and will also make it
easier to e.g. move the demuxer to its own thread.
Don't bother updating input.conf, but changes.rst documents how old
commands map to the new ones.
Mostly untested, due to lack of hardware.
2014-06-09 21:38:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct demux_ctrl_stream_ctrl {
|
|
|
|
int ctrl;
|
|
|
|
void *arg;
|
|
|
|
int res;
|
2013-10-02 19:19:16 +00:00
|
|
|
};
|
2002-11-16 03:42:14 +00:00
|
|
|
|
2015-01-19 19:45:31 +00:00
|
|
|
#define SEEK_ABSOLUTE (1 << 0) // argument is a timestamp
|
|
|
|
#define SEEK_FACTOR (1 << 1) // argument is in range [0,1]
|
|
|
|
#define SEEK_FORWARD (1 << 2) // prefer later time if not exact
|
|
|
|
#define SEEK_BACKWARD (1 << 3) // prefer earlier time if not exact
|
|
|
|
#define SEEK_SUBPREROLL (1 << 4) // try to get more subtitle packets
|
|
|
|
#define SEEK_HR (1 << 5) // hr-seek (this is a weak hint only)
|
2008-01-29 15:11:38 +00:00
|
|
|
|
2013-07-12 19:58:11 +00:00
|
|
|
// Strictness of the demuxer open format check.
|
|
|
|
// demux.c will try by default: NORMAL, UNSAFE (in this order)
|
|
|
|
// Using "-demuxer format" will try REQUEST
|
|
|
|
// Using "-demuxer +format" will try FORCE
|
|
|
|
// REQUEST can be used as special value for raw demuxers which have no file
|
|
|
|
// header check; then they should fail if check!=FORCE && check!=REQUEST.
|
|
|
|
//
|
|
|
|
// In general, the list is sorted from weakest check to normal check.
|
|
|
|
// You can use relation operators to compare the check level.
|
|
|
|
enum demux_check {
|
|
|
|
DEMUX_CHECK_FORCE, // force format if possible
|
|
|
|
DEMUX_CHECK_UNSAFE, // risky/fuzzy detection
|
|
|
|
DEMUX_CHECK_REQUEST,// requested by user or stream implementation
|
|
|
|
DEMUX_CHECK_NORMAL, // normal, safe detection
|
|
|
|
};
|
|
|
|
|
2014-07-05 14:45:56 +00:00
|
|
|
enum demux_event {
|
2014-07-16 20:40:21 +00:00
|
|
|
DEMUX_EVENT_INIT = 1 << 0, // complete (re-)initialization
|
|
|
|
DEMUX_EVENT_STREAMS = 1 << 1, // a stream was added
|
|
|
|
DEMUX_EVENT_METADATA = 1 << 2, // metadata or stream_metadata changed
|
|
|
|
DEMUX_EVENT_ALL = 0xFFFF,
|
2014-07-05 14:45:56 +00:00
|
|
|
};
|
|
|
|
|
2012-08-03 10:24:55 +00:00
|
|
|
#define MAX_SH_STREAMS 256
|
2002-02-10 18:09:20 +00:00
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
struct demuxer;
|
2015-02-17 22:46:12 +00:00
|
|
|
struct timeline;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Demuxer description structure
|
|
|
|
*/
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct demuxer_desc {
|
2011-02-10 10:05:26 +00:00
|
|
|
const char *name; // Demuxer name, used with -demuxer switch
|
2013-07-12 20:12:02 +00:00
|
|
|
const char *desc; // Displayed to user
|
2011-02-10 10:05:26 +00:00
|
|
|
|
2013-07-11 18:08:12 +00:00
|
|
|
// Return 0 on success, otherwise -1
|
2013-07-12 19:58:11 +00:00
|
|
|
int (*open)(struct demuxer *demuxer, enum demux_check check);
|
2013-07-11 18:08:12 +00:00
|
|
|
// The following functions are all optional
|
|
|
|
int (*fill_buffer)(struct demuxer *demuxer); // 0 on EOF, otherwise 1
|
|
|
|
void (*close)(struct demuxer *demuxer);
|
2014-07-21 17:28:18 +00:00
|
|
|
void (*seek)(struct demuxer *demuxer, double rel_seek_secs, int flags);
|
2011-02-10 10:05:26 +00:00
|
|
|
int (*control)(struct demuxer *demuxer, int cmd, void *arg);
|
2015-02-17 22:46:12 +00:00
|
|
|
// See timeline.c
|
|
|
|
void (*load_timeline)(struct timeline *tl);
|
2005-08-05 19:57:47 +00:00
|
|
|
} demuxer_desc_t;
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct demux_chapter
|
2006-08-06 18:55:34 +00:00
|
|
|
{
|
2013-04-12 11:20:37 +00:00
|
|
|
int original_index;
|
2014-11-02 16:20:04 +00:00
|
|
|
double pts;
|
2011-02-10 10:05:26 +00:00
|
|
|
char *name;
|
2013-09-08 05:42:05 +00:00
|
|
|
struct mp_tags *metadata;
|
|
|
|
uint64_t demuxer_id; // for mapping to internal demuxer data structures
|
2006-08-06 18:55:34 +00:00
|
|
|
} demux_chapter_t;
|
|
|
|
|
2014-01-22 23:54:08 +00:00
|
|
|
struct demux_edition {
|
|
|
|
uint64_t demuxer_id;
|
|
|
|
bool default_edition;
|
|
|
|
struct mp_tags *metadata;
|
|
|
|
};
|
|
|
|
|
2013-10-07 00:49:12 +00:00
|
|
|
struct matroska_segment_uid {
|
|
|
|
unsigned char segment[16];
|
|
|
|
uint64_t edition;
|
|
|
|
};
|
|
|
|
|
2009-03-16 21:30:48 +00:00
|
|
|
struct matroska_data {
|
2013-10-07 00:49:12 +00:00
|
|
|
struct matroska_segment_uid uid;
|
2009-03-16 21:30:48 +00:00
|
|
|
// Ordered chapter information if any
|
|
|
|
struct matroska_chapter {
|
|
|
|
uint64_t start;
|
|
|
|
uint64_t end;
|
|
|
|
bool has_segment_uid;
|
2013-10-07 00:49:12 +00:00
|
|
|
struct matroska_segment_uid uid;
|
2009-04-02 02:00:22 +00:00
|
|
|
char *name;
|
2009-03-16 21:30:48 +00:00
|
|
|
} *ordered_chapters;
|
|
|
|
int num_ordered_chapters;
|
|
|
|
};
|
|
|
|
|
2014-03-25 10:46:10 +00:00
|
|
|
struct replaygain_data {
|
|
|
|
float track_gain;
|
|
|
|
float track_peak;
|
|
|
|
float album_gain;
|
|
|
|
float album_peak;
|
|
|
|
};
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct demux_attachment
|
2008-01-12 01:12:36 +00:00
|
|
|
{
|
2011-02-10 10:05:26 +00:00
|
|
|
char *name;
|
|
|
|
char *type;
|
|
|
|
void *data;
|
|
|
|
unsigned int data_size;
|
2008-01-12 01:12:36 +00:00
|
|
|
} demux_attachment_t;
|
|
|
|
|
2011-08-04 05:38:39 +00:00
|
|
|
struct demuxer_params {
|
2015-02-20 20:21:14 +00:00
|
|
|
char *force_format;
|
2013-09-26 06:22:06 +00:00
|
|
|
int matroska_num_wanted_uids;
|
2013-10-07 00:49:12 +00:00
|
|
|
struct matroska_segment_uid *matroska_wanted_uids;
|
2013-04-14 00:49:07 +00:00
|
|
|
int matroska_wanted_segment;
|
|
|
|
bool *matroska_was_valid;
|
2014-01-04 18:00:01 +00:00
|
|
|
bool expect_subtitle;
|
2015-02-20 20:56:55 +00:00
|
|
|
bool disable_cache; // demux_open_url() only
|
2011-08-04 05:38:39 +00:00
|
|
|
};
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct demuxer {
|
2011-02-10 10:05:26 +00:00
|
|
|
const demuxer_desc_t *desc; ///< Demuxer description structure
|
2011-05-04 20:12:55 +00:00
|
|
|
const char *filetype; // format name when not identified by demuxer (libavformat)
|
2012-11-18 19:46:12 +00:00
|
|
|
int64_t filepos; // input stream current pos.
|
2013-07-12 19:58:11 +00:00
|
|
|
char *filename; // same as stream->url
|
2015-01-26 12:46:33 +00:00
|
|
|
bool seekable;
|
|
|
|
bool partially_seekable; // implies seekable=true
|
2014-07-05 14:54:49 +00:00
|
|
|
double start_time;
|
2013-03-01 12:20:33 +00:00
|
|
|
// File format allows PTS resets (even if the current file is without)
|
|
|
|
bool ts_resets_possible;
|
2015-01-19 19:45:31 +00:00
|
|
|
// Send relative seek requests, instead of SEEK_ABSOLUTE or SEEK_FACTOR.
|
|
|
|
// This is only done if the user explicitly uses a relative seek.
|
|
|
|
bool rel_seeks;
|
demux: hack for instant stream switching
This removes the delay when switching audio tracks in mkv or mp4 files.
Other formats are not enabled, because it's not clear whether the
demuxers fulfill the requirements listed in demux.h. (Many formats
definitely do not with libavformat.)
Background:
The demuxer packet cache buffers a certain amount of packets. This
includes only packets from selected streams. We discard packets from
other streams for various reasons. This introduces a problem: switching
to a different audio track introduces a delay. The delay is as big as
the demuxer packet cache buffer, because while the file was read ahead
to fill the packet buffer, the process of reading packets also discarded
all packets from the previously not selected audio stream. Once the
remaining packet buffer has been played, new audio packets are available
and you hear audio again.
We could probably just not discard packets from unselected streams. But
this would require additional memory and CPU resources, and also it's
hard to tell when packets from unused streams should be discarded (we
don't want to keep them forever; it'd be a memory leak).
We could also issue a player hr-seek to the current playback position,
which would solve the problem in 1 line of code or so. But this can be
rather slow.
So what we do in this commit instead is: we just seek back to the
position where our current packet buffer starts, and start demuxing from
this position again. This way we can get the "past" packets for the
newly selected stream. For streams which were already selected the
packets are simply discarded until the previous position is reached
again.
That latter part is the hard part. We really want to skip packets
exactly until the position where we left off previously, or we will skip
packets or feed packets to the decoder twice. If we assume that the
demuxer is deterministic (returns exactly the same packets after a seek
to a previous position), then we can try to check whether it's the same
packet as the one at the end of the packet buffer. If it is, we know
that the packet after it is where we left off last time.
Unfortunately, this is not very robust, and maybe it can't be made
robust. Currently we use the demux_packet.pos field as unique packet
ID - which works fine in some scenarios, but will break in arbitrary
ways if the basic requirement to the demuxer (as listed in the demux.h
additions) are broken. Thus, this is enabled only for the internal mkv
demuxer and the libavformat mp4 demuxer.
(libavformat mkv does not work, because the packet positions are not
unique. Probably could be fixed upstream, but it's not clear whether
it's a bug or a feature.)
2015-02-13 20:17:17 +00:00
|
|
|
// Enable fast track switching hacks. This requires from the demuxer:
|
|
|
|
// - seeking is somewhat reliable; packet contents must not change
|
2015-02-14 13:29:21 +00:00
|
|
|
// - packet position (demux_packet.pos) is set, not negative, unique, and
|
|
|
|
// monotonically increasing
|
demux: hack for instant stream switching
This removes the delay when switching audio tracks in mkv or mp4 files.
Other formats are not enabled, because it's not clear whether the
demuxers fulfill the requirements listed in demux.h. (Many formats
definitely do not with libavformat.)
Background:
The demuxer packet cache buffers a certain amount of packets. This
includes only packets from selected streams. We discard packets from
other streams for various reasons. This introduces a problem: switching
to a different audio track introduces a delay. The delay is as big as
the demuxer packet cache buffer, because while the file was read ahead
to fill the packet buffer, the process of reading packets also discarded
all packets from the previously not selected audio stream. Once the
remaining packet buffer has been played, new audio packets are available
and you hear audio again.
We could probably just not discard packets from unselected streams. But
this would require additional memory and CPU resources, and also it's
hard to tell when packets from unused streams should be discarded (we
don't want to keep them forever; it'd be a memory leak).
We could also issue a player hr-seek to the current playback position,
which would solve the problem in 1 line of code or so. But this can be
rather slow.
So what we do in this commit instead is: we just seek back to the
position where our current packet buffer starts, and start demuxing from
this position again. This way we can get the "past" packets for the
newly selected stream. For streams which were already selected the
packets are simply discarded until the previous position is reached
again.
That latter part is the hard part. We really want to skip packets
exactly until the position where we left off previously, or we will skip
packets or feed packets to the decoder twice. If we assume that the
demuxer is deterministic (returns exactly the same packets after a seek
to a previous position), then we can try to check whether it's the same
packet as the one at the end of the packet buffer. If it is, we know
that the packet after it is where we left off last time.
Unfortunately, this is not very robust, and maybe it can't be made
robust. Currently we use the demux_packet.pos field as unique packet
ID - which works fine in some scenarios, but will break in arbitrary
ways if the basic requirement to the demuxer (as listed in the demux.h
additions) are broken. Thus, this is enabled only for the internal mkv
demuxer and the libavformat mp4 demuxer.
(libavformat mkv does not work, because the packet positions are not
unique. Probably could be fixed upstream, but it's not clear whether
it's a bug or a feature.)
2015-02-13 20:17:17 +00:00
|
|
|
// - seeking leaves packet positions invariant
|
|
|
|
bool allow_refresh_seeks;
|
2015-02-18 20:10:43 +00:00
|
|
|
// The file data was fully read, and there is no need to keep the stream
|
|
|
|
// open, keep the cache active, or to run the demuxer thread. Generating
|
|
|
|
// packets is not slow either (unlike e.g. libavdevice pseudo-demuxers).
|
|
|
|
// Typical examples: text subtitles, playlists
|
|
|
|
bool fully_read;
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2014-07-05 14:45:56 +00:00
|
|
|
// Bitmask of DEMUX_EVENT_*
|
|
|
|
int events;
|
|
|
|
|
2012-08-03 10:24:55 +00:00
|
|
|
struct sh_stream **streams;
|
|
|
|
int num_streams;
|
2009-11-07 12:31:05 +00:00
|
|
|
|
2014-01-22 23:54:08 +00:00
|
|
|
struct demux_edition *editions;
|
2012-08-25 23:19:42 +00:00
|
|
|
int num_editions;
|
|
|
|
int edition;
|
2011-12-31 12:20:08 +00:00
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
struct demux_chapter *chapters;
|
|
|
|
int num_chapters;
|
|
|
|
|
|
|
|
struct demux_attachment *attachments;
|
|
|
|
int num_attachments;
|
2008-01-12 01:12:36 +00:00
|
|
|
|
2009-03-16 21:30:48 +00:00
|
|
|
struct matroska_data matroska_data;
|
|
|
|
|
2013-08-25 18:40:21 +00:00
|
|
|
// If the file is a playlist file
|
|
|
|
struct playlist *playlist;
|
|
|
|
|
2013-09-08 04:32:48 +00:00
|
|
|
struct mp_tags *metadata;
|
2014-07-05 14:45:56 +00:00
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
void *priv; // demuxer-specific internal data
|
|
|
|
struct MPOpts *opts;
|
2013-12-21 19:24:20 +00:00
|
|
|
struct mpv_global *global;
|
2013-12-21 20:55:41 +00:00
|
|
|
struct mp_log *log, *glog;
|
2011-08-04 05:38:39 +00:00
|
|
|
struct demuxer_params *params;
|
2014-07-16 20:40:21 +00:00
|
|
|
|
|
|
|
struct demux_internal *in; // internal to demux.c
|
|
|
|
|
|
|
|
// Since the demuxer can run in its own thread, and the stream is not
|
|
|
|
// thread-safe, only the demuxer is allowed to access the stream directly.
|
|
|
|
// You can freely use demux_stream_control() to send STREAM_CTRLs, or use
|
|
|
|
// demux_pause() to get exclusive access to the stream.
|
|
|
|
struct stream *stream;
|
2001-04-23 16:12:21 +00:00
|
|
|
} demuxer_t;
|
|
|
|
|
2006-11-18 14:31:31 +00:00
|
|
|
typedef struct {
|
2011-02-10 10:05:26 +00:00
|
|
|
int progid; //program id
|
|
|
|
int aid, vid, sid; //audio, video and subtitle id
|
2006-11-18 14:31:31 +00:00
|
|
|
} demux_program_t;
|
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
void free_demuxer(struct demuxer *demuxer);
|
2015-02-20 20:08:10 +00:00
|
|
|
void free_demuxer_and_stream(struct demuxer *demuxer);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2014-07-05 14:59:44 +00:00
|
|
|
int demux_add_packet(struct sh_stream *stream, demux_packet_t *dp);
|
2013-07-11 17:10:33 +00:00
|
|
|
|
|
|
|
struct demux_packet *demux_read_packet(struct sh_stream *sh);
|
2014-07-18 13:08:05 +00:00
|
|
|
int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt);
|
2014-07-06 17:02:21 +00:00
|
|
|
bool demux_stream_is_selected(struct sh_stream *stream);
|
2013-07-11 17:10:33 +00:00
|
|
|
double demux_get_next_pts(struct sh_stream *sh);
|
|
|
|
bool demux_has_packet(struct sh_stream *sh);
|
2014-07-05 14:57:56 +00:00
|
|
|
struct demux_packet *demux_read_any_packet(struct demuxer *demuxer);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2013-07-11 17:35:09 +00:00
|
|
|
struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type);
|
|
|
|
|
2015-02-20 20:21:14 +00:00
|
|
|
struct demuxer *demux_open(struct stream *stream, struct demuxer_params *params,
|
2013-12-21 19:24:20 +00:00
|
|
|
struct mpv_global *global);
|
2011-08-04 05:38:39 +00:00
|
|
|
|
2015-02-20 20:56:55 +00:00
|
|
|
struct mp_cancel;
|
|
|
|
struct demuxer *demux_open_url(const char *url,
|
|
|
|
struct demuxer_params *params,
|
|
|
|
struct mp_cancel *cancel,
|
|
|
|
struct mpv_global *global);
|
|
|
|
|
2014-07-16 20:40:21 +00:00
|
|
|
void demux_start_thread(struct demuxer *demuxer);
|
|
|
|
void demux_stop_thread(struct demuxer *demuxer);
|
|
|
|
void demux_set_wakeup_cb(struct demuxer *demuxer, void (*cb)(void *ctx), void *ctx);
|
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
void demux_flush(struct demuxer *demuxer);
|
2014-10-29 21:47:25 +00:00
|
|
|
int demux_seek(struct demuxer *demuxer, double rel_seek_secs, int flags);
|
demux: hack for instant stream switching
This removes the delay when switching audio tracks in mkv or mp4 files.
Other formats are not enabled, because it's not clear whether the
demuxers fulfill the requirements listed in demux.h. (Many formats
definitely do not with libavformat.)
Background:
The demuxer packet cache buffers a certain amount of packets. This
includes only packets from selected streams. We discard packets from
other streams for various reasons. This introduces a problem: switching
to a different audio track introduces a delay. The delay is as big as
the demuxer packet cache buffer, because while the file was read ahead
to fill the packet buffer, the process of reading packets also discarded
all packets from the previously not selected audio stream. Once the
remaining packet buffer has been played, new audio packets are available
and you hear audio again.
We could probably just not discard packets from unselected streams. But
this would require additional memory and CPU resources, and also it's
hard to tell when packets from unused streams should be discarded (we
don't want to keep them forever; it'd be a memory leak).
We could also issue a player hr-seek to the current playback position,
which would solve the problem in 1 line of code or so. But this can be
rather slow.
So what we do in this commit instead is: we just seek back to the
position where our current packet buffer starts, and start demuxing from
this position again. This way we can get the "past" packets for the
newly selected stream. For streams which were already selected the
packets are simply discarded until the previous position is reached
again.
That latter part is the hard part. We really want to skip packets
exactly until the position where we left off previously, or we will skip
packets or feed packets to the decoder twice. If we assume that the
demuxer is deterministic (returns exactly the same packets after a seek
to a previous position), then we can try to check whether it's the same
packet as the one at the end of the packet buffer. If it is, we know
that the packet after it is where we left off last time.
Unfortunately, this is not very robust, and maybe it can't be made
robust. Currently we use the demux_packet.pos field as unique packet
ID - which works fine in some scenarios, but will break in arbitrary
ways if the basic requirement to the demuxer (as listed in the demux.h
additions) are broken. Thus, this is enabled only for the internal mkv
demuxer and the libavformat mp4 demuxer.
(libavformat mkv does not work, because the packet positions are not
unique. Probably could be fixed upstream, but it's not clear whether
it's a bug or a feature.)
2015-02-13 20:17:17 +00:00
|
|
|
void demux_set_enable_refresh_seeks(struct demuxer *demuxer, bool enabled);
|
2001-04-23 16:12:21 +00:00
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
int demux_control(struct demuxer *demuxer, int cmd, void *arg);
|
2002-03-03 18:47:29 +00:00
|
|
|
|
2012-08-19 16:01:30 +00:00
|
|
|
void demuxer_switch_track(struct demuxer *demuxer, enum stream_type type,
|
|
|
|
struct sh_stream *stream);
|
2013-07-11 17:22:24 +00:00
|
|
|
void demuxer_select_track(struct demuxer *demuxer, struct sh_stream *stream,
|
|
|
|
bool selected);
|
2014-07-16 20:40:21 +00:00
|
|
|
void demux_set_stream_autoselect(struct demuxer *demuxer, bool autoselect);
|
2003-01-19 00:21:54 +00:00
|
|
|
|
2013-12-21 19:24:20 +00:00
|
|
|
void demuxer_help(struct mp_log *log);
|
2006-08-06 18:55:34 +00:00
|
|
|
|
2011-02-10 10:05:26 +00:00
|
|
|
int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name,
|
2010-05-19 10:44:37 +00:00
|
|
|
struct bstr type, struct bstr data);
|
2014-11-02 16:20:04 +00:00
|
|
|
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
|
|
|
|
double pts, uint64_t demuxer_id);
|
2006-08-06 18:55:34 +00:00
|
|
|
|
2013-05-03 18:07:04 +00:00
|
|
|
double demuxer_get_time_length(struct demuxer *demuxer);
|
|
|
|
|
2014-07-16 20:40:21 +00:00
|
|
|
int demux_stream_control(demuxer_t *demuxer, int ctrl, void *arg);
|
|
|
|
|
|
|
|
void demux_pause(demuxer_t *demuxer);
|
|
|
|
void demux_unpause(demuxer_t *demuxer);
|
|
|
|
|
|
|
|
void demux_changed(demuxer_t *demuxer, int events);
|
|
|
|
void demux_update(demuxer_t *demuxer);
|
|
|
|
|
2012-08-19 16:01:30 +00:00
|
|
|
struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d,
|
|
|
|
enum stream_type t, int id);
|
2008-03-30 16:55:46 +00:00
|
|
|
|
2014-11-02 16:20:04 +00:00
|
|
|
struct demux_chapter *demux_copy_chapter_data(struct demux_chapter *c, int num);
|
|
|
|
|
2013-10-07 00:49:12 +00:00
|
|
|
bool demux_matroska_uid_cmp(struct matroska_segment_uid *a,
|
|
|
|
struct matroska_segment_uid *b);
|
|
|
|
|
2014-02-15 15:48:56 +00:00
|
|
|
const char *stream_type_name(enum stream_type type);
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_DEMUXER_H */
|