2009-05-08 23:51:13 +02:00
|
|
|
/*
|
|
|
|
* DEMUXER v2.5
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-02-24 21:28:24 +01:00
|
|
|
|
2001-04-23 05:42:17 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-11-27 01:42:39 +01:00
|
|
|
#include <string.h>
|
2011-08-20 19:25:43 +02:00
|
|
|
#include <assert.h>
|
2001-08-01 11:14:02 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-24 21:28:24 +01:00
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
#include "config.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/options.h"
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 15:15:19 +01:00
|
|
|
#include "core/av_common.h"
|
2009-03-16 04:11:22 +01:00
|
|
|
#include "talloc.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/mp_msg.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2007-03-15 19:36:36 +01:00
|
|
|
#include "stream/stream.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "demux.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
#include "stheader.h"
|
2002-02-06 21:16:35 +01:00
|
|
|
#include "mf.h"
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "audio/format.h"
|
2002-03-15 16:53:11 +01:00
|
|
|
|
2008-07-17 19:14:12 +02:00
|
|
|
#include "libavcodec/avcodec.h"
|
|
|
|
#if MP_INPUT_BUFFER_PADDING_SIZE < FF_INPUT_BUFFER_PADDING_SIZE
|
|
|
|
#error MP_INPUT_BUFFER_PADDING_SIZE is too small!
|
|
|
|
#endif
|
|
|
|
|
2013-04-15 21:26:22 +02:00
|
|
|
static void clear_parser(sh_audio_t *sh);
|
2005-08-05 21:57:47 +02:00
|
|
|
|
|
|
|
// Demuxer list
|
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
2011-02-14 12:05:35 +01:00
|
|
|
extern const struct demuxer_desc demuxer_desc_edl;
|
2012-01-01 17:45:24 +01:00
|
|
|
extern const struct demuxer_desc demuxer_desc_cue;
|
2008-01-13 17:00:39 +01:00
|
|
|
extern const demuxer_desc_t demuxer_desc_rawaudio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rawvideo;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_tv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_avi;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_asf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_matroska;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lavf;
|
2008-11-30 14:22:34 +01:00
|
|
|
extern const demuxer_desc_t demuxer_desc_mng;
|
2012-09-07 14:26:02 +02:00
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ps;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_pes;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_gxf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg4_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_h264_es;
|
2012-09-07 14:42:25 +02:00
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ts;
|
2013-06-01 19:43:11 +02:00
|
|
|
extern const demuxer_desc_t demuxer_desc_sub;
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-01-28 17:03:22 +01:00
|
|
|
/* Please do not add any new demuxers here. If you want to implement a new
|
2008-01-28 23:09:21 +01:00
|
|
|
* demuxer, add it to libavformat, except for wrappers around external
|
|
|
|
* libraries and demuxers requiring binary support. */
|
2008-01-28 17:03:22 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
const demuxer_desc_t *const demuxer_list[] = {
|
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
2011-02-14 12:05:35 +01:00
|
|
|
&demuxer_desc_edl,
|
2012-01-01 17:45:24 +01:00
|
|
|
&demuxer_desc_cue,
|
2008-04-12 17:51:08 +02:00
|
|
|
&demuxer_desc_rawaudio,
|
|
|
|
&demuxer_desc_rawvideo,
|
2008-07-30 14:01:30 +02:00
|
|
|
#ifdef CONFIG_TV
|
2008-04-12 17:51:08 +02:00
|
|
|
&demuxer_desc_tv,
|
2005-08-05 21:57:47 +02:00
|
|
|
#endif
|
2008-04-12 17:51:08 +02:00
|
|
|
&demuxer_desc_matroska,
|
|
|
|
&demuxer_desc_lavf,
|
2012-12-08 20:14:13 +01:00
|
|
|
&demuxer_desc_avi,
|
|
|
|
&demuxer_desc_asf,
|
2008-11-30 14:22:34 +01:00
|
|
|
#ifdef CONFIG_MNG
|
|
|
|
&demuxer_desc_mng,
|
2006-07-04 23:26:41 +02:00
|
|
|
#endif
|
2012-09-07 14:26:02 +02:00
|
|
|
&demuxer_desc_mpeg_ps,
|
|
|
|
&demuxer_desc_mpeg_pes,
|
|
|
|
&demuxer_desc_mpeg_gxf,
|
|
|
|
&demuxer_desc_mpeg_es,
|
|
|
|
&demuxer_desc_mpeg4_es,
|
|
|
|
&demuxer_desc_h264_es,
|
2012-09-07 14:42:25 +02:00
|
|
|
&demuxer_desc_mpeg_ts,
|
2012-11-16 19:12:56 +01:00
|
|
|
// auto-probe last, because it checks file-extensions only
|
|
|
|
&demuxer_desc_mf,
|
2013-06-01 19:43:11 +02:00
|
|
|
// no auto-probe
|
|
|
|
&demuxer_desc_sub,
|
2008-04-12 17:51:08 +02:00
|
|
|
/* Please do not add any new demuxers here. If you want to implement a new
|
|
|
|
* demuxer, add it to libavformat, except for wrappers around external
|
|
|
|
* libraries and demuxers requiring binary support. */
|
|
|
|
NULL
|
2005-08-05 21:57:47 +02:00
|
|
|
};
|
|
|
|
|
stream: report chapter times, use time seeks for DVD chapters
Allow the stream layer to report chapter times. Extend stream_dvd to do
this. I'm not 100% sure whether the re-used code is bug-free (because it
was used for slave-mode and/or debugging only).
MAke the frontend do time-based seeks when switching DVD chapters. I'm
not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists
(maybe/hopefully not), but we will see.
Note that querying chapter times in demuxer_chapter_time() with the new
STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with
the cache enabled. The frontend likes to query chapter times very often.
Additionally, stream_dvd uses some sort of quadratic algorithm to list
times for all chapters. For this reason, we try to query all chapters on
start (after the demuxer is opened), and add the chapters to the demuxer
chapter list. demuxer_chapter_time() will get the time from that list,
instead of asking the stream layer over and over again.
This assumes stream_dvd knows the list of chapters at the start, and
also that the list of chapters never changes during playback. This
seems to be true, and the only exception, switching DVD titles, is not
supported at runtime (and doesn't need to be supported).
2013-05-04 01:20:39 +02:00
|
|
|
static void add_stream_chapters(struct demuxer *demuxer);
|
|
|
|
|
2013-05-03 23:24:09 +02:00
|
|
|
static int packet_destroy(void *ptr)
|
|
|
|
{
|
|
|
|
struct demux_packet *dp = ptr;
|
2013-05-21 22:03:35 +02:00
|
|
|
talloc_free(dp->avpacket);
|
|
|
|
free(dp->allocation);
|
2013-05-03 23:24:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-19 03:59:01 +02:00
|
|
|
static struct demux_packet *create_packet(size_t len)
|
2011-01-17 14:47:57 +01:00
|
|
|
{
|
2011-01-17 15:16:39 +01:00
|
|
|
if (len > 1000000000) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to allocate demux packet "
|
|
|
|
"over 1 GB!\n");
|
|
|
|
abort();
|
|
|
|
}
|
2013-05-03 23:24:09 +02:00
|
|
|
struct demux_packet *dp = talloc(NULL, struct demux_packet);
|
|
|
|
talloc_set_destructor(dp, packet_destroy);
|
|
|
|
*dp = (struct demux_packet) {
|
|
|
|
.len = len,
|
|
|
|
.pts = MP_NOPTS_VALUE,
|
|
|
|
.duration = -1,
|
|
|
|
.stream_pts = MP_NOPTS_VALUE,
|
|
|
|
};
|
2011-08-19 03:59:01 +02:00
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct demux_packet *new_demux_packet(size_t len)
|
|
|
|
{
|
|
|
|
struct demux_packet *dp = create_packet(len);
|
2011-06-18 18:55:13 +02:00
|
|
|
dp->buffer = malloc(len + MP_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!dp->buffer) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Memory allocation failure!\n");
|
|
|
|
abort();
|
2011-01-17 15:16:39 +01:00
|
|
|
}
|
2013-04-14 23:23:00 +02:00
|
|
|
memset(dp->buffer + len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2013-05-21 22:03:35 +02:00
|
|
|
dp->allocation = dp->buffer;
|
2011-01-17 14:47:57 +01:00
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2013-04-14 23:19:29 +02:00
|
|
|
// data must already have suitable padding, and does not copy the data
|
2011-08-19 03:59:01 +02:00
|
|
|
struct demux_packet *new_demux_packet_fromdata(void *data, size_t len)
|
|
|
|
{
|
|
|
|
struct demux_packet *dp = create_packet(len);
|
|
|
|
dp->buffer = data;
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2013-04-14 23:19:29 +02:00
|
|
|
struct demux_packet *new_demux_packet_from(void *data, size_t len)
|
|
|
|
{
|
|
|
|
struct demux_packet *dp = new_demux_packet(len);
|
|
|
|
memcpy(dp->buffer, data, len);
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:16:39 +01:00
|
|
|
void resize_demux_packet(struct demux_packet *dp, size_t len)
|
2011-01-17 14:47:57 +01:00
|
|
|
{
|
2011-01-17 15:16:39 +01:00
|
|
|
if (len > 1000000000) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to realloc demux packet "
|
|
|
|
"over 1 GB!\n");
|
|
|
|
abort();
|
|
|
|
}
|
2013-05-21 22:03:35 +02:00
|
|
|
assert(dp->allocation);
|
2011-06-18 18:55:13 +02:00
|
|
|
dp->buffer = realloc(dp->buffer, len + MP_INPUT_BUFFER_PADDING_SIZE);
|
|
|
|
if (!dp->buffer) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Memory allocation failure!\n");
|
|
|
|
abort();
|
2011-01-17 14:47:57 +01:00
|
|
|
}
|
2013-04-14 23:23:00 +02:00
|
|
|
memset(dp->buffer + len, 0, MP_INPUT_BUFFER_PADDING_SIZE);
|
2011-01-17 14:47:57 +01:00
|
|
|
dp->len = len;
|
2013-05-21 22:03:35 +02:00
|
|
|
dp->allocation = dp->buffer;
|
2011-01-17 14:47:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_demux_packet(struct demux_packet *dp)
|
|
|
|
{
|
2013-05-03 23:24:09 +02:00
|
|
|
talloc_free(dp);
|
2011-01-17 14:47:57 +01:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:15:21 +01:00
|
|
|
static void free_demuxer_stream(struct demux_stream *ds)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2001-08-23 01:54:57 +02:00
|
|
|
ds_free_packs(ds);
|
|
|
|
free(ds);
|
|
|
|
}
|
|
|
|
|
2012-08-19 18:01:30 +02:00
|
|
|
static struct demux_stream *new_demuxer_stream(struct demuxer *demuxer,
|
|
|
|
enum stream_type type, int id)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
|
|
|
demux_stream_t *ds = malloc(sizeof(demux_stream_t));
|
2012-08-19 18:01:30 +02:00
|
|
|
*ds = (demux_stream_t) {
|
|
|
|
.stream_type = type,
|
2009-11-02 02:40:09 +01:00
|
|
|
.id = id,
|
|
|
|
.demuxer = demuxer,
|
|
|
|
.asf_seq = -1,
|
|
|
|
};
|
2008-04-12 17:51:08 +02:00
|
|
|
return ds;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2005-08-05 21:57:47 +02:00
|
|
|
/**
|
|
|
|
* Get demuxer description structure for a given demuxer type
|
|
|
|
*
|
|
|
|
* @param file_format type of the demuxer
|
|
|
|
* @return structure for the demuxer, NULL if not found
|
|
|
|
*/
|
2008-04-12 17:51:08 +02:00
|
|
|
static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format)
|
2005-08-05 21:57:47 +02:00
|
|
|
{
|
2008-04-12 17:51:08 +02:00
|
|
|
int i;
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
for (i = 0; demuxer_list[i]; i++)
|
|
|
|
if (file_format == demuxer_list[i]->type)
|
|
|
|
return demuxer_list[i];
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return NULL;
|
2005-08-05 21:57:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-01 19:43:11 +02:00
|
|
|
static demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
|
|
|
|
int a_id, int v_id, int s_id, char *filename)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2009-03-16 04:11:22 +01:00
|
|
|
struct demuxer *d = talloc_zero(NULL, struct demuxer);
|
2008-04-12 17:51:08 +02:00
|
|
|
d->stream = stream;
|
|
|
|
d->stream_pts = MP_NOPTS_VALUE;
|
|
|
|
d->reference_clock = MP_NOPTS_VALUE;
|
|
|
|
d->movi_start = stream->start_pos;
|
|
|
|
d->movi_end = stream->end_pos;
|
|
|
|
d->seekable = 1;
|
|
|
|
d->synced = 0;
|
2009-08-17 07:55:40 +02:00
|
|
|
d->filepos = -1;
|
2013-05-21 22:03:35 +02:00
|
|
|
d->audio = new_demuxer_stream(d, STREAM_AUDIO, a_id);
|
|
|
|
d->video = new_demuxer_stream(d, STREAM_VIDEO, v_id);
|
2012-08-19 18:01:30 +02:00
|
|
|
d->sub = new_demuxer_stream(d, STREAM_SUB, s_id);
|
|
|
|
d->ds[STREAM_VIDEO] = d->video;
|
|
|
|
d->ds[STREAM_AUDIO] = d->audio;
|
|
|
|
d->ds[STREAM_SUB] = d->sub;
|
2008-04-12 17:51:08 +02:00
|
|
|
d->type = type;
|
2008-04-16 03:23:38 +02:00
|
|
|
d->opts = opts;
|
2008-04-12 17:51:08 +02:00
|
|
|
if (type)
|
|
|
|
if (!(d->desc = get_demuxer_desc_from_type(type)))
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR,
|
|
|
|
"BUG! Invalid demuxer type in new_demuxer(), "
|
2012-08-27 09:09:34 +02:00
|
|
|
"big troubles ahead.\n");
|
2008-04-12 17:51:08 +02:00
|
|
|
if (filename) // Filename hack for avs_check_file
|
|
|
|
d->filename = strdup(filename);
|
|
|
|
stream_seek(stream, stream->start_pos);
|
|
|
|
return d;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2013-06-01 19:43:11 +02:00
|
|
|
// for demux_sub.c
|
|
|
|
demuxer_t *new_sub_pseudo_demuxer(struct MPOpts *opts)
|
|
|
|
{
|
|
|
|
struct stream *s = open_stream("null://", NULL, NULL);
|
|
|
|
assert(s);
|
|
|
|
struct demuxer *d = new_demuxer(opts, s, DEMUXER_TYPE_SUB,
|
|
|
|
-1, -1, -1, NULL);
|
|
|
|
new_sh_stream(d, STREAM_SUB);
|
|
|
|
talloc_steal(d, s);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2013-04-14 19:19:35 +02:00
|
|
|
static struct sh_stream *new_sh_stream_id(demuxer_t *demuxer,
|
|
|
|
enum stream_type type,
|
|
|
|
int stream_index,
|
2013-04-29 22:34:36 +02:00
|
|
|
int demuxer_id)
|
2012-08-03 12:24:55 +02:00
|
|
|
{
|
2013-04-29 22:34:36 +02:00
|
|
|
if (demuxer->num_streams > MAX_SH_STREAMS || stream_index > MAX_SH_STREAMS) {
|
2013-04-14 19:19:35 +02:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, "Too many streams.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-03 12:24:55 +02:00
|
|
|
struct sh_stream *sh = talloc_struct(demuxer, struct sh_stream, {
|
|
|
|
.type = type,
|
2012-08-19 18:01:30 +02:00
|
|
|
.demuxer = demuxer,
|
2012-08-03 12:24:55 +02:00
|
|
|
.index = demuxer->num_streams,
|
2013-04-29 22:34:36 +02:00
|
|
|
.demuxer_id = demuxer_id, // may be overwritten by demuxer
|
2012-08-03 12:24:55 +02:00
|
|
|
.stream_index = stream_index,
|
|
|
|
.opts = demuxer->opts,
|
|
|
|
});
|
|
|
|
MP_TARRAY_APPEND(demuxer, demuxer->streams, demuxer->num_streams, sh);
|
|
|
|
switch (sh->type) {
|
|
|
|
case STREAM_VIDEO: {
|
|
|
|
struct sh_video *sht = talloc_zero(demuxer, struct sh_video);
|
2013-04-15 21:26:22 +02:00
|
|
|
sht->gsh = sh;
|
|
|
|
sht->opts = sh->opts;
|
2012-08-03 12:24:55 +02:00
|
|
|
sht->ds = demuxer->video;
|
|
|
|
sh->video = sht;
|
|
|
|
demuxer->v_streams[sh->stream_index] = sht;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_AUDIO: {
|
|
|
|
struct sh_audio *sht = talloc_zero(demuxer, struct sh_audio);
|
2013-04-15 21:26:22 +02:00
|
|
|
sht->gsh = sh;
|
|
|
|
sht->opts = sh->opts;
|
2012-08-03 12:24:55 +02:00
|
|
|
sht->ds = demuxer->audio;
|
|
|
|
sht->samplesize = 2;
|
|
|
|
sht->sample_format = AF_FORMAT_S16_NE;
|
|
|
|
sh->audio = sht;
|
|
|
|
demuxer->a_streams[sh->stream_index] = sht;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_SUB: {
|
|
|
|
struct sh_sub *sht = talloc_zero(demuxer, struct sh_sub);
|
2013-04-15 21:26:22 +02:00
|
|
|
sht->gsh = sh;
|
|
|
|
sht->opts = sh->opts;
|
2012-08-03 12:24:55 +02:00
|
|
|
sht->ds = demuxer->sub;
|
|
|
|
sh->sub = sht;
|
|
|
|
demuxer->s_streams[sh->stream_index] = sht;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: assert(false);
|
|
|
|
}
|
|
|
|
return sh;
|
|
|
|
}
|
|
|
|
|
2013-04-14 19:19:35 +02:00
|
|
|
// This is what "modern" demuxers are supposed to use.
|
|
|
|
struct sh_stream *new_sh_stream(demuxer_t *demuxer, enum stream_type type)
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
for (int n = 0; n < demuxer->num_streams; n++) {
|
|
|
|
if (demuxer->streams[n]->type == type)
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
return new_sh_stream_id(demuxer, type, demuxer->num_streams, num);
|
|
|
|
}
|
|
|
|
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 15:15:37 +01:00
|
|
|
static void free_sh_stream(struct sh_stream *sh)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)
|
|
|
|
{
|
|
|
|
if (id > MAX_S_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested sub stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_S_STREAMS);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (demuxer->s_streams[id])
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN, "Sub stream %i redefined\n", id);
|
|
|
|
else {
|
2013-04-14 19:19:35 +02:00
|
|
|
new_sh_stream_id(demuxer, STREAM_SUB, id, sid);
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
|
|
|
|
}
|
|
|
|
return demuxer->s_streams[id];
|
2006-11-13 17:15:23 +01:00
|
|
|
}
|
|
|
|
|
2012-09-07 14:42:25 +02:00
|
|
|
struct sh_sub *new_sh_sub_sid_lang(struct demuxer *demuxer, int id, int sid,
|
|
|
|
const char *lang)
|
|
|
|
{
|
|
|
|
struct sh_sub *sh = new_sh_sub_sid(demuxer, id, sid);
|
|
|
|
if (lang && lang[0] && strcmp(lang, "und")) {
|
2013-02-09 15:15:28 +01:00
|
|
|
sh->gsh->lang = talloc_strdup(sh, lang);
|
2012-09-07 14:42:25 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, lang);
|
|
|
|
}
|
|
|
|
return sh;
|
|
|
|
}
|
|
|
|
|
2008-08-12 12:58:29 +02:00
|
|
|
static void free_sh_sub(sh_sub_t *sh)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2007-06-23 19:39:27 +02:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
|
2008-02-29 18:25:41 +01:00
|
|
|
free(sh->extradata);
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 15:15:37 +01:00
|
|
|
free_sh_stream(sh->gsh);
|
2007-06-23 19:39:27 +02:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid)
|
|
|
|
{
|
|
|
|
if (id > MAX_A_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested audio stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_A_STREAMS);
|
|
|
|
return NULL;
|
2002-02-10 19:09:20 +01:00
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
if (demuxer->a_streams[id]) {
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "WARNING: Audio stream header %d redefined.\n", id);
|
2001-07-22 00:37:55 +02:00
|
|
|
} else {
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_V, "==> Found audio stream: %d\n", id);
|
2013-04-14 19:19:35 +02:00
|
|
|
new_sh_stream_id(demuxer, STREAM_AUDIO, id, aid);
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid);
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
|
|
|
return demuxer->a_streams[id];
|
|
|
|
}
|
|
|
|
|
2012-11-08 00:30:30 +01:00
|
|
|
static void free_sh_audio(demuxer_t *demuxer, int id)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2006-06-14 16:05:59 +02:00
|
|
|
sh_audio_t *sh = demuxer->a_streams[id];
|
|
|
|
demuxer->a_streams[id] = NULL;
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh);
|
2008-02-29 18:25:41 +01:00
|
|
|
free(sh->wf);
|
|
|
|
free(sh->codecdata);
|
2013-04-15 21:26:22 +02:00
|
|
|
clear_parser(sh);
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 15:15:37 +01:00
|
|
|
free_sh_stream(sh->gsh);
|
2001-08-23 01:54:57 +02:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
sh_video_t *new_sh_video_vid(demuxer_t *demuxer, int id, int vid)
|
|
|
|
{
|
|
|
|
if (id > MAX_V_STREAMS - 1 || id < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_WARN,
|
|
|
|
"Requested video stream id overflow (%d > %d)\n", id,
|
|
|
|
MAX_V_STREAMS);
|
|
|
|
return NULL;
|
2002-02-10 19:09:20 +01:00
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
if (demuxer->v_streams[id])
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "WARNING: Video stream header %d redefined.\n", id);
|
2008-04-12 17:51:08 +02:00
|
|
|
else {
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_V, "==> Found video stream: %d\n", id);
|
2013-04-14 19:19:35 +02:00
|
|
|
new_sh_stream_id(demuxer, STREAM_VIDEO, id, vid);
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid);
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
|
|
|
return demuxer->v_streams[id];
|
|
|
|
}
|
|
|
|
|
2012-11-08 00:30:30 +01:00
|
|
|
static void free_sh_video(sh_video_t *sh)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh);
|
2008-02-29 18:25:41 +01:00
|
|
|
free(sh->bih);
|
demux_lavf, ad_lavc, vd_lavc: pass codec header data directly
Instead of putting codec header data into WAVEFORMATEX and
BITMAPINFOHEADER, pass it directly via AVCodecContext. To do this, we
add mp_copy_lav_codec_headers(), which copies the codec header data
from one AVCodecContext to another (originally, the plan was to use
avcodec_copy_context() for this, but it looks like this would turn
decoder initialization into an even worse mess).
Get rid of the silly CodecID <-> codec_tag mapping. This was originally
needed for codecs.conf: codec tags were used to identify codecs, but
libavformat didn't always return useful codec tags (different file
formats can have different, overlapping tag numbers). Since we don't
go through WAVEFORMATEX etc. and pass all header data directly via
AVCodecContext, we can be absolutely sure that the codec tag mapping is
not needed anymore.
Note that this also destroys the "standard" MPlayer method of exporting
codec header data. WAVEFORMATEX and BITMAPINFOHEADER made sure that
other non-libavcodec decoders could be initialized. However, all these
decoders have been removed, so this is just cruft full of old hacks that
are not needed anymore. There's still ad_spdif and ad_mpg123, bu neither
of these need codec header data. Should we ever add non-libavcodec
decoders, better data structures without the past hacks could be added
to export the headers.
2013-02-09 15:15:37 +01:00
|
|
|
free_sh_stream(sh->gsh);
|
2001-08-23 01:54:57 +02:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
void free_demuxer(demuxer_t *demuxer)
|
|
|
|
{
|
2001-08-23 01:54:57 +02:00
|
|
|
int i;
|
2010-02-20 18:50:56 +01:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing %s demuxer at %p\n",
|
|
|
|
demuxer->desc->shortdesc, demuxer);
|
2008-04-12 17:51:08 +02:00
|
|
|
if (demuxer->desc->close)
|
|
|
|
demuxer->desc->close(demuxer);
|
2001-08-23 01:54:57 +02:00
|
|
|
// free streams:
|
2008-04-12 17:51:08 +02:00
|
|
|
for (i = 0; i < MAX_A_STREAMS; i++)
|
|
|
|
if (demuxer->a_streams[i])
|
|
|
|
free_sh_audio(demuxer, i);
|
|
|
|
for (i = 0; i < MAX_V_STREAMS; i++)
|
|
|
|
if (demuxer->v_streams[i])
|
|
|
|
free_sh_video(demuxer->v_streams[i]);
|
|
|
|
for (i = 0; i < MAX_S_STREAMS; i++)
|
|
|
|
if (demuxer->s_streams[i])
|
|
|
|
free_sh_sub(demuxer->s_streams[i]);
|
2001-08-23 01:54:57 +02:00
|
|
|
// free demuxers:
|
|
|
|
free_demuxer_stream(demuxer->audio);
|
|
|
|
free_demuxer_stream(demuxer->video);
|
2002-03-31 04:45:14 +02:00
|
|
|
free_demuxer_stream(demuxer->sub);
|
2008-02-29 18:25:41 +01:00
|
|
|
free(demuxer->filename);
|
2009-03-16 04:11:22 +01:00
|
|
|
talloc_free(demuxer);
|
2001-08-23 01:54:57 +02:00
|
|
|
}
|
|
|
|
|
2013-04-14 19:19:35 +02:00
|
|
|
void demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream,
|
|
|
|
demux_packet_t *dp)
|
|
|
|
{
|
|
|
|
if (!demuxer_stream_is_selected(demuxer, stream)) {
|
|
|
|
free_demux_packet(dp);
|
|
|
|
} else {
|
|
|
|
ds_add_packet(demuxer->ds[stream->type], dp);
|
|
|
|
}
|
|
|
|
}
|
2001-07-22 00:37:55 +02:00
|
|
|
|
2010-12-20 05:42:04 +01:00
|
|
|
void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2012-12-08 13:59:49 +01:00
|
|
|
// demux API can't handle 0-sized packets, but at least some vobsubs
|
|
|
|
// generate them. Skipping them seems to work fine. Not skipping them will
|
|
|
|
// stop demuxing with external vobsubs. See FATE sub/vobsub.{idx,sub} at
|
|
|
|
// pts=185.91.
|
|
|
|
if (dp->len == 0 && ds->stream_type == STREAM_SUB) {
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_INFO, "Discarding empty subtitle packet.\n");
|
|
|
|
free_demux_packet(dp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-24 21:28:24 +01:00
|
|
|
// append packet to DS stream:
|
|
|
|
++ds->packs;
|
2008-04-12 17:51:08 +02:00
|
|
|
ds->bytes += dp->len;
|
|
|
|
if (ds->last) {
|
|
|
|
// next packet in stream
|
|
|
|
ds->last->next = dp;
|
|
|
|
ds->last = dp;
|
2001-02-24 21:28:24 +01:00
|
|
|
} else {
|
2008-04-12 17:51:08 +02:00
|
|
|
// first packet in stream
|
|
|
|
ds->first = ds->last = dp;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
|
|
|
|
"DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%u [packs: A=%d V=%d]\n",
|
|
|
|
(ds == ds->demuxer->audio) ? "d_audio" : "d_video", dp->len,
|
|
|
|
dp->pts, (unsigned int) dp->pos, ds->demuxer->audio->packs,
|
|
|
|
ds->demuxer->video->packs);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 15:15:19 +01:00
|
|
|
static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, const char *format)
|
2009-12-27 16:28:01 +01:00
|
|
|
{
|
2013-03-09 08:49:56 +01:00
|
|
|
enum AVCodecID codec_id = mp_codec_to_av_codec_id(format);
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 15:15:19 +01:00
|
|
|
|
|
|
|
switch (codec_id) {
|
2013-03-09 08:49:56 +01:00
|
|
|
case AV_CODEC_ID_AAC_LATM:
|
|
|
|
case AV_CODEC_ID_AC3:
|
|
|
|
case AV_CODEC_ID_EAC3:
|
|
|
|
case AV_CODEC_ID_DTS:
|
|
|
|
case AV_CODEC_ID_FLAC:
|
|
|
|
case AV_CODEC_ID_MLP:
|
|
|
|
case AV_CODEC_ID_MP3:
|
|
|
|
case AV_CODEC_ID_MP2:
|
|
|
|
case AV_CODEC_ID_TRUEHD:
|
2012-01-28 12:41:36 +01:00
|
|
|
*avctx = avcodec_alloc_context3(NULL);
|
2009-12-27 16:28:01 +01:00
|
|
|
if (!*avctx)
|
|
|
|
return;
|
|
|
|
*parser = av_parser_init(codec_id);
|
|
|
|
if (!*parser)
|
|
|
|
av_freep(avctx);
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 15:15:19 +01:00
|
|
|
break;
|
|
|
|
default: ;
|
2009-12-27 16:28:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 21:26:22 +02:00
|
|
|
static void get_parser(sh_audio_t *sh, AVCodecContext **avctx, AVCodecParserContext **parser)
|
2009-12-27 16:28:01 +01:00
|
|
|
{
|
|
|
|
*avctx = NULL;
|
|
|
|
*parser = NULL;
|
|
|
|
|
|
|
|
if (!sh || !sh->needs_parsing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*avctx = sh->avctx;
|
|
|
|
*parser = sh->parser;
|
|
|
|
if (*parser)
|
|
|
|
return;
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 15:15:19 +01:00
|
|
|
allocate_parser(avctx, parser, sh->gsh->codec);
|
2009-12-27 16:28:01 +01:00
|
|
|
sh->avctx = *avctx;
|
|
|
|
sh->parser = *parser;
|
|
|
|
}
|
|
|
|
|
2012-11-18 20:46:12 +01:00
|
|
|
int ds_parse(demux_stream_t *ds, uint8_t **buffer, int *len, double pts, int64_t pos)
|
2009-12-27 16:28:01 +01:00
|
|
|
{
|
|
|
|
AVCodecContext *avctx;
|
|
|
|
AVCodecParserContext *parser;
|
|
|
|
get_parser(ds->sh, &avctx, &parser);
|
|
|
|
if (!parser)
|
|
|
|
return *len;
|
|
|
|
return av_parser_parse2(parser, avctx, buffer, len, *buffer, *len, pts, pts, pos);
|
|
|
|
}
|
2010-01-24 16:19:14 +01:00
|
|
|
|
2013-04-15 21:26:22 +02:00
|
|
|
static void clear_parser(sh_audio_t *sh)
|
2010-01-24 16:19:14 +01:00
|
|
|
{
|
|
|
|
av_parser_close(sh->parser);
|
|
|
|
sh->parser = NULL;
|
|
|
|
av_freep(&sh->avctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ds_clear_parser(demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
if (!ds->sh)
|
|
|
|
return;
|
|
|
|
clear_parser(ds->sh);
|
|
|
|
}
|
2009-12-27 16:28:01 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len,
|
2012-11-18 20:46:12 +01:00
|
|
|
double pts, int64_t pos, bool keyframe)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
|
|
|
demux_packet_t *dp = new_demux_packet(len);
|
|
|
|
len = stream_read(stream, dp->buffer, len);
|
2003-09-20 14:50:25 +02:00
|
|
|
resize_demux_packet(dp, len);
|
2008-04-12 17:51:08 +02:00
|
|
|
dp->pts = pts;
|
|
|
|
dp->pos = pos;
|
2012-07-24 23:23:27 +02:00
|
|
|
dp->keyframe = keyframe;
|
2001-02-24 21:28:24 +01:00
|
|
|
// append packet to DS stream:
|
2008-04-12 17:51:08 +02:00
|
|
|
ds_add_packet(ds, dp);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2013-02-14 14:49:50 +01:00
|
|
|
static bool demux_check_queue_full(demuxer_t *demux)
|
|
|
|
{
|
|
|
|
int apacks = demux->audio ? demux->audio->packs : 0;
|
|
|
|
int abytes = demux->audio ? demux->audio->bytes : 0;
|
|
|
|
int vpacks = demux->video ? demux->video->packs : 0;
|
|
|
|
int vbytes = demux->video ? demux->video->bytes : 0;
|
|
|
|
|
|
|
|
if (apacks < MAX_PACKS && abytes < MAX_PACK_BYTES &&
|
|
|
|
vpacks < MAX_PACKS && vbytes < MAX_PACK_BYTES)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!demux->warned_queue_overflow) {
|
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "\nToo many packets in the demuxer "
|
|
|
|
"packet queue (video: %d packets in %d bytes, audio: %d "
|
|
|
|
"packets in %d bytes).\n", vpacks, vbytes, apacks, abytes);
|
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, "Maybe you are playing a non-"
|
|
|
|
"interleaved stream/file or the codec failed?\nFor AVI files, "
|
|
|
|
"try to force non-interleaved mode with the "
|
|
|
|
"--demuxer=avi --avi-ni options.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
demux->warned_queue_overflow = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-02-24 21:28:24 +01:00
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found or invalid type
|
|
|
|
// 1 = successfully read a packet
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demux_fill_buffer(demuxer_t *demux, demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
// Note: parameter 'ds' can be NULL!
|
|
|
|
return demux->desc->fill_buffer(demux, ds);
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF
|
2007-12-01 14:35:25 +01:00
|
|
|
// 1 = successful
|
2008-04-12 17:51:08 +02:00
|
|
|
int ds_fill_buffer(demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
demuxer_t *demux = ds->demuxer;
|
|
|
|
if (ds->current)
|
|
|
|
free_demux_packet(ds->current);
|
|
|
|
ds->current = NULL;
|
2011-06-30 22:05:50 +02:00
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG3, "ds_fill_buffer (%s) called\n",
|
|
|
|
ds == demux->audio ? "d_audio" : ds == demux->video ? "d_video" :
|
|
|
|
ds == demux->sub ? "d_sub" : "unknown");
|
2008-04-12 17:51:08 +02:00
|
|
|
while (1) {
|
2011-01-27 21:37:51 +01:00
|
|
|
int apacks = demux->audio ? demux->audio->packs : 0;
|
|
|
|
int vpacks = demux->video ? demux->video->packs : 0;
|
2008-04-12 17:51:08 +02:00
|
|
|
if (ds->packs) {
|
|
|
|
demux_packet_t *p = ds->first;
|
|
|
|
// copy useful data:
|
|
|
|
ds->buffer = p->buffer;
|
|
|
|
ds->buffer_pos = 0;
|
|
|
|
ds->buffer_size = p->len;
|
|
|
|
ds->pos = p->pos;
|
|
|
|
ds->dpos += p->len; // !!!
|
|
|
|
++ds->pack_no;
|
|
|
|
if (p->pts != MP_NOPTS_VALUE) {
|
|
|
|
ds->pts = p->pts;
|
|
|
|
ds->pts_bytes = 0;
|
|
|
|
}
|
|
|
|
ds->pts_bytes += p->len; // !!!
|
|
|
|
if (p->stream_pts != MP_NOPTS_VALUE)
|
|
|
|
demux->stream_pts = p->stream_pts;
|
2012-07-24 23:23:27 +02:00
|
|
|
ds->keyframe = p->keyframe;
|
2008-04-12 17:51:08 +02:00
|
|
|
// unlink packet:
|
|
|
|
ds->bytes -= p->len;
|
|
|
|
ds->current = p;
|
|
|
|
ds->first = p->next;
|
|
|
|
if (!ds->first)
|
|
|
|
ds->last = NULL;
|
|
|
|
--ds->packs;
|
2008-10-04 06:21:21 +02:00
|
|
|
/* The code below can set ds->eof to 1 when another stream runs
|
|
|
|
* out of buffer space. That makes sense because in that situation
|
|
|
|
* the calling code should not count on being able to demux more
|
|
|
|
* packets from this stream.
|
|
|
|
* If however the situation improves and we're called again
|
|
|
|
* despite the eof flag then it's better to clear it to avoid
|
|
|
|
* weird behavior. */
|
|
|
|
ds->eof = 0;
|
2013-02-14 14:49:50 +01:00
|
|
|
ds->fill_count = 0;
|
2008-04-12 17:51:08 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2011-01-27 21:37:51 +01:00
|
|
|
// avoid buffering too far ahead in e.g. badly interleaved files
|
|
|
|
// or when one stream is shorter, without breaking large audio
|
|
|
|
// delay with well interleaved files.
|
|
|
|
// This needs to be enough for at least 1 second of packets
|
|
|
|
// since libavformat mov demuxer does not try to interleave
|
|
|
|
// with more than 1s precision.
|
|
|
|
if (ds->fill_count > 80)
|
|
|
|
break;
|
2009-07-07 00:15:02 +02:00
|
|
|
|
2013-02-14 14:49:50 +01:00
|
|
|
if (demux_check_queue_full(demux))
|
2008-04-12 17:51:08 +02:00
|
|
|
break;
|
2013-02-14 14:49:50 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
if (!demux_fill_buffer(demux, ds)) {
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
|
|
|
|
"ds_fill_buffer()->demux_fill_buffer() failed\n");
|
|
|
|
break; // EOF
|
|
|
|
}
|
2013-02-14 14:49:50 +01:00
|
|
|
|
2013-03-19 02:27:47 +01:00
|
|
|
struct sh_video *sh_video = demux->video->sh;
|
|
|
|
|
|
|
|
if (sh_video && sh_video->gsh->attached_picture) {
|
2013-02-14 15:11:42 +01:00
|
|
|
if (demux->audio)
|
|
|
|
ds->fill_count += demux->audio->packs - apacks;
|
|
|
|
if (demux->video && demux->video->packs > vpacks)
|
|
|
|
ds->fill_count++;
|
|
|
|
}
|
2001-07-29 23:07:34 +02:00
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
ds->buffer_pos = ds->buffer_size = 0;
|
|
|
|
ds->buffer = NULL;
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V,
|
|
|
|
"ds_fill_buffer: EOF reached (stream: %s) \n",
|
|
|
|
ds == demux->audio ? "audio" : "video");
|
|
|
|
ds->eof = 1;
|
|
|
|
return 0;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demux_read_data(demux_stream_t *ds, unsigned char *mem, int len)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int bytes = 0;
|
|
|
|
while (len > 0) {
|
|
|
|
x = ds->buffer_size - ds->buffer_pos;
|
|
|
|
if (x == 0) {
|
|
|
|
if (!ds_fill_buffer(ds))
|
|
|
|
return bytes;
|
|
|
|
} else {
|
|
|
|
if (x > len)
|
|
|
|
x = len;
|
|
|
|
if (mem)
|
2012-11-09 01:31:49 +01:00
|
|
|
memcpy(mem + bytes, &ds->buffer[ds->buffer_pos], x);
|
2008-04-12 17:51:08 +02:00
|
|
|
bytes += x;
|
|
|
|
len -= x;
|
|
|
|
ds->buffer_pos += x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2012-09-07 14:26:02 +02:00
|
|
|
/**
|
|
|
|
* \brief read data until the given 3-byte pattern is encountered, up to maxlen
|
|
|
|
* \param mem memory to read data into, may be NULL to discard data
|
|
|
|
* \param maxlen maximum number of bytes to read
|
|
|
|
* \param read number of bytes actually read
|
|
|
|
* \param pattern pattern to search for (lowest 8 bits are ignored)
|
|
|
|
* \return whether pattern was found
|
|
|
|
*/
|
|
|
|
int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
|
|
|
|
int *read, uint32_t pattern)
|
|
|
|
{
|
|
|
|
register uint32_t head = 0xffffff00;
|
|
|
|
register uint32_t pat = pattern & 0xffffff00;
|
|
|
|
int total_len = 0;
|
|
|
|
do {
|
|
|
|
register unsigned char *ds_buf = &ds->buffer[ds->buffer_size];
|
|
|
|
int len = ds->buffer_size - ds->buffer_pos;
|
|
|
|
register long pos = -len;
|
|
|
|
if (unlikely(pos >= 0)) { // buffer is empty
|
|
|
|
ds_fill_buffer(ds);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
head |= ds_buf[pos];
|
|
|
|
head <<= 8;
|
|
|
|
} while (++pos && head != pat);
|
|
|
|
len += pos;
|
|
|
|
if (total_len + len > maxlen)
|
|
|
|
len = maxlen - total_len;
|
|
|
|
len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len);
|
|
|
|
total_len += len;
|
|
|
|
} while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof);
|
|
|
|
if (read)
|
|
|
|
*read = total_len;
|
|
|
|
return total_len >= 3 && head == pat;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
void ds_free_packs(demux_stream_t *ds)
|
|
|
|
{
|
|
|
|
demux_packet_t *dp = ds->first;
|
|
|
|
while (dp) {
|
|
|
|
demux_packet_t *dn = dp->next;
|
|
|
|
free_demux_packet(dp);
|
|
|
|
dp = dn;
|
|
|
|
}
|
|
|
|
if (ds->asf_packet) {
|
|
|
|
// free unfinished .asf fragments:
|
2013-05-29 14:54:44 +02:00
|
|
|
free_demux_packet(ds->asf_packet);
|
2008-04-12 17:51:08 +02:00
|
|
|
ds->asf_packet = NULL;
|
|
|
|
}
|
|
|
|
ds->first = ds->last = NULL;
|
|
|
|
ds->packs = 0; // !!!!!
|
|
|
|
ds->bytes = 0;
|
|
|
|
if (ds->current)
|
|
|
|
free_demux_packet(ds->current);
|
|
|
|
ds->current = NULL;
|
|
|
|
ds->buffer = NULL;
|
|
|
|
ds->buffer_pos = ds->buffer_size;
|
2011-07-30 20:05:59 +02:00
|
|
|
ds->pts = MP_NOPTS_VALUE;
|
2008-04-12 17:51:08 +02:00
|
|
|
ds->pts_bytes = 0;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int ds_get_packet(demux_stream_t *ds, unsigned char **start)
|
|
|
|
{
|
2007-10-25 21:21:24 +02:00
|
|
|
int len;
|
2008-04-12 17:51:08 +02:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
if (!ds_fill_buffer(ds)) {
|
2001-02-24 21:28:24 +01:00
|
|
|
// EOF
|
|
|
|
*start = NULL;
|
|
|
|
return -1;
|
2008-04-12 17:51:08 +02:00
|
|
|
}
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2007-10-25 21:21:24 +02:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 17:51:08 +02:00
|
|
|
ds->buffer_pos += len;
|
2007-10-25 21:21:24 +02:00
|
|
|
return len;
|
2001-02-24 21:28:24 +01:00
|
|
|
}
|
2001-04-21 01:00:11 +02:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts)
|
2006-04-24 12:58:40 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
*pts = MP_NOPTS_VALUE;
|
2009-08-23 17:32:42 +02:00
|
|
|
len = ds_get_packet(ds, start);
|
|
|
|
if (len < 0)
|
|
|
|
return len;
|
2006-07-06 08:58:17 +02:00
|
|
|
// Return pts unless this read starts from the middle of a packet
|
2009-08-23 17:32:42 +02:00
|
|
|
if (len == ds->buffer_pos)
|
2008-04-12 17:51:08 +02:00
|
|
|
*pts = ds->current->pts;
|
2006-04-24 12:58:40 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2013-06-03 01:28:14 +02:00
|
|
|
struct demux_packet *ds_get_packet_sub(demux_stream_t *ds)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
if (!ds->packs)
|
2013-06-03 01:28:14 +02:00
|
|
|
return NULL; // no sub
|
2008-04-12 17:51:08 +02:00
|
|
|
if (!ds_fill_buffer(ds))
|
2013-06-03 01:28:14 +02:00
|
|
|
return NULL; // EOF
|
2001-04-21 01:00:11 +02:00
|
|
|
}
|
2013-06-03 01:28:14 +02:00
|
|
|
if (ds->buffer_pos < ds->buffer_size) {
|
|
|
|
ds->current->buffer += ds->buffer_pos;
|
|
|
|
ds->buffer_size -= ds->buffer_pos;
|
|
|
|
}
|
|
|
|
ds->buffer_pos = ds->buffer_size;
|
|
|
|
return ds->current;
|
2001-04-21 01:00:11 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 04:54:48 +01:00
|
|
|
struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last)
|
2011-08-20 19:25:43 +02:00
|
|
|
{
|
2011-12-22 04:54:48 +01:00
|
|
|
if (!repeat_last)
|
|
|
|
ds_fill_buffer(ds);
|
2013-05-21 22:03:35 +02:00
|
|
|
// This shouldn't get used together with partial reads
|
|
|
|
// However, some old demuxers return parsed packets with an offset in
|
|
|
|
// -correct-pts mode (at least mpegts).
|
|
|
|
// Not all old demuxers will actually work.
|
|
|
|
if (ds->buffer_pos < ds->buffer_size) {
|
|
|
|
ds->current->buffer += ds->buffer_pos;
|
|
|
|
ds->buffer_size -= ds->buffer_pos;
|
|
|
|
}
|
2011-08-20 19:25:43 +02:00
|
|
|
ds->buffer_pos = ds->buffer_size;
|
|
|
|
return ds->current;
|
|
|
|
}
|
|
|
|
|
2006-04-27 13:13:21 +02:00
|
|
|
double ds_get_next_pts(demux_stream_t *ds)
|
|
|
|
{
|
2008-04-12 17:51:08 +02:00
|
|
|
demuxer_t *demux = ds->demuxer;
|
2010-06-06 15:59:44 +02:00
|
|
|
// if we have not read from the "current" packet, consider it
|
|
|
|
// as the next, otherwise we never get the pts for the first packet.
|
|
|
|
while (!ds->first && (!ds->current || ds->buffer_pos)) {
|
2013-02-14 14:49:50 +01:00
|
|
|
if (demux_check_queue_full(demux))
|
2008-04-12 17:51:08 +02:00
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
if (!demux_fill_buffer(demux, ds))
|
|
|
|
return MP_NOPTS_VALUE;
|
2002-05-02 12:25:48 +02:00
|
|
|
}
|
2010-06-06 15:59:44 +02:00
|
|
|
// take pts from "current" if we never read from it.
|
|
|
|
if (ds->current && !ds->buffer_pos)
|
|
|
|
return ds->current->pts;
|
2008-04-12 17:51:08 +02:00
|
|
|
return ds->first->pts;
|
2002-05-02 12:25:48 +02:00
|
|
|
}
|
|
|
|
|
2001-07-22 00:37:55 +02:00
|
|
|
// ====================================================================
|
|
|
|
|
2005-08-05 21:57:47 +02:00
|
|
|
void demuxer_help(void)
|
|
|
|
{
|
2008-04-12 17:51:08 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "Available demuxers:\n");
|
2011-02-11 18:52:44 +01:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, " demuxer: info: (comment)\n");
|
2008-04-12 17:51:08 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXERS\n");
|
|
|
|
for (i = 0; demuxer_list[i]; i++) {
|
2011-02-11 18:52:44 +01:00
|
|
|
if (demuxer_list[i]->type >= DEMUXER_TYPE_END) // internal type
|
2008-04-12 17:51:08 +02:00
|
|
|
continue;
|
|
|
|
if (demuxer_list[i]->comment && strlen(demuxer_list[i]->comment))
|
2011-02-11 18:52:44 +01:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %s (%s)\n",
|
|
|
|
demuxer_list[i]->name, demuxer_list[i]->info,
|
|
|
|
demuxer_list[i]->comment);
|
2008-04-12 17:51:08 +02:00
|
|
|
else
|
2011-02-11 18:52:44 +01:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %s\n",
|
|
|
|
demuxer_list[i]->name, demuxer_list[i]->info);
|
2008-04-12 17:51:08 +02:00
|
|
|
}
|
2005-08-05 21:57:47 +02:00
|
|
|
}
|
2005-02-13 14:39:19 +01:00
|
|
|
|
2002-03-16 15:32:03 +01:00
|
|
|
|
2005-08-05 21:57:47 +02:00
|
|
|
/**
|
|
|
|
* Get demuxer type for a given demuxer name
|
|
|
|
*
|
|
|
|
* @param demuxer_name string with demuxer name of demuxer number
|
2005-08-31 01:56:24 +02:00
|
|
|
* @param force will be set if demuxer should be forced.
|
|
|
|
* May be NULL.
|
2005-08-05 21:57:47 +02:00
|
|
|
* @return DEMUXER_TYPE_xxx, -1 if error or not found
|
|
|
|
*/
|
2011-02-10 11:15:21 +01:00
|
|
|
static int get_demuxer_type_from_name(char *demuxer_name, int *force)
|
2005-08-05 21:57:47 +02:00
|
|
|
{
|
2008-04-12 17:51:08 +02:00
|
|
|
if (!demuxer_name || !demuxer_name[0])
|
|
|
|
return DEMUXER_TYPE_UNKNOWN;
|
|
|
|
if (force)
|
|
|
|
*force = demuxer_name[0] == '+';
|
|
|
|
if (demuxer_name[0] == '+')
|
|
|
|
demuxer_name = &demuxer_name[1];
|
2011-02-11 18:52:44 +01:00
|
|
|
for (int i = 0; demuxer_list[i]; i++) {
|
|
|
|
if (demuxer_list[i]->type >= DEMUXER_TYPE_END)
|
|
|
|
// Can't select special demuxers from commandline
|
2008-04-12 17:51:08 +02:00
|
|
|
continue;
|
|
|
|
if (strcmp(demuxer_name, demuxer_list[i]->name) == 0)
|
|
|
|
return demuxer_list[i]->type;
|
|
|
|
}
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return -1;
|
2005-08-05 21:57:47 +02:00
|
|
|
}
|
2001-12-27 22:24:56 +01:00
|
|
|
|
2010-11-10 13:37:15 +01:00
|
|
|
static struct demuxer *open_given_type(struct MPOpts *opts,
|
|
|
|
const struct demuxer_desc *desc,
|
|
|
|
struct stream *stream, bool force,
|
|
|
|
int audio_id, int video_id, int sub_id,
|
2011-08-04 07:38:39 +02:00
|
|
|
char *filename,
|
|
|
|
struct demuxer_params *params)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2010-11-10 13:37:15 +01:00
|
|
|
struct demuxer *demuxer;
|
|
|
|
int fformat;
|
2012-12-08 20:14:13 +01:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_V, "Trying demuxer: %s\n", desc->name);
|
2010-11-10 13:37:15 +01:00
|
|
|
demuxer = new_demuxer(opts, stream, desc->type, audio_id,
|
|
|
|
video_id, sub_id, filename);
|
2011-08-04 07:38:39 +02:00
|
|
|
demuxer->params = params;
|
2010-11-10 13:37:15 +01:00
|
|
|
if (desc->check_file)
|
|
|
|
fformat = desc->check_file(demuxer);
|
|
|
|
else
|
|
|
|
fformat = desc->type;
|
|
|
|
if (force)
|
|
|
|
fformat = desc->type;
|
|
|
|
if (fformat == 0)
|
|
|
|
goto fail;
|
|
|
|
if (fformat == desc->type) {
|
2010-11-10 14:38:36 +01:00
|
|
|
if (demuxer->filetype)
|
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_INFO, "Detected file format: %s (%s)\n",
|
|
|
|
demuxer->filetype, desc->shortdesc);
|
|
|
|
else
|
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_INFO, "Detected file format: %s\n",
|
|
|
|
desc->shortdesc);
|
2010-11-10 13:37:15 +01:00
|
|
|
if (demuxer->desc->open) {
|
|
|
|
struct demuxer *demux2 = demuxer->desc->open(demuxer);
|
|
|
|
if (!demux2) {
|
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "Opening as detected format "
|
|
|
|
"\"%s\" failed.\n", desc->shortdesc);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
/* At least demux_mov can return a demux_demuxers instance
|
|
|
|
* from open() instead of the original fed in. */
|
|
|
|
demuxer = demux2;
|
|
|
|
}
|
|
|
|
demuxer->file_format = fformat;
|
2012-08-19 18:11:53 +02:00
|
|
|
opts->correct_pts = opts->user_correct_pts;
|
|
|
|
if (opts->correct_pts < 0)
|
|
|
|
opts->correct_pts =
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_CORRECT_PTS,
|
|
|
|
NULL) == DEMUXER_CTRL_OK;
|
2013-05-03 19:52:28 +02:00
|
|
|
if (stream_manages_timeline(demuxer->stream)) {
|
|
|
|
// Incorrect, but fixes some behavior with DVD/BD
|
|
|
|
demuxer->ts_resets_possible = false;
|
2013-05-04 02:59:42 +02:00
|
|
|
// Doesn't work, because stream_pts is a "guess".
|
|
|
|
demuxer->accurate_seek = false;
|
2013-05-03 19:52:28 +02:00
|
|
|
}
|
stream: report chapter times, use time seeks for DVD chapters
Allow the stream layer to report chapter times. Extend stream_dvd to do
this. I'm not 100% sure whether the re-used code is bug-free (because it
was used for slave-mode and/or debugging only).
MAke the frontend do time-based seeks when switching DVD chapters. I'm
not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists
(maybe/hopefully not), but we will see.
Note that querying chapter times in demuxer_chapter_time() with the new
STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with
the cache enabled. The frontend likes to query chapter times very often.
Additionally, stream_dvd uses some sort of quadratic algorithm to list
times for all chapters. For this reason, we try to query all chapters on
start (after the demuxer is opened), and add the chapters to the demuxer
chapter list. demuxer_chapter_time() will get the time from that list,
instead of asking the stream layer over and over again.
This assumes stream_dvd knows the list of chapters at the start, and
also that the list of chapters never changes during playback. This
seems to be true, and the only exception, switching DVD titles, is not
supported at runtime (and doesn't need to be supported).
2013-05-04 01:20:39 +02:00
|
|
|
add_stream_chapters(demuxer);
|
2013-04-12 13:20:37 +02:00
|
|
|
demuxer_sort_chapters(demuxer);
|
2010-11-10 13:37:15 +01:00
|
|
|
return demuxer;
|
|
|
|
} else {
|
|
|
|
// demux_mov can return playlist instead of mov
|
|
|
|
if (fformat == DEMUXER_TYPE_PLAYLIST)
|
|
|
|
return demuxer; // handled in mplayer.c
|
|
|
|
/* Internal MPEG PS demuxer check can return other MPEG subtypes
|
|
|
|
* which don't have their own checks; recurse to try opening as
|
|
|
|
* the returned type instead. */
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
desc = get_demuxer_desc_from_type(fformat);
|
|
|
|
if (!desc) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR,
|
|
|
|
"BUG: recursion to nonexistent file format\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return open_given_type(opts, desc, stream, false, audio_id,
|
2011-08-04 07:38:39 +02:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 13:37:15 +01:00
|
|
|
}
|
|
|
|
fail:
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-12 17:51:08 +02:00
|
|
|
|
2012-08-19 18:11:53 +02:00
|
|
|
struct demuxer *demux_open_withparams(struct MPOpts *opts,
|
|
|
|
struct stream *stream, int file_format,
|
|
|
|
char *force_format, int audio_id,
|
|
|
|
int video_id, int sub_id, char *filename,
|
|
|
|
struct demuxer_params *params)
|
2010-11-10 13:37:15 +01:00
|
|
|
{
|
|
|
|
struct demuxer *demuxer = NULL;
|
|
|
|
const struct demuxer_desc *desc;
|
2008-04-12 17:51:08 +02:00
|
|
|
|
2012-08-19 18:11:53 +02:00
|
|
|
int force = 0;
|
|
|
|
int demuxer_type;
|
|
|
|
if ((demuxer_type = get_demuxer_type_from_name(force_format, &force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "Demuxer %s does not exist.\n",
|
|
|
|
force_format);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (demuxer_type)
|
|
|
|
file_format = demuxer_type;
|
|
|
|
|
2012-07-30 18:40:46 +02:00
|
|
|
// Some code (e.g. dvd stuff, network code, or extension.c) explicitly
|
|
|
|
// request certain file formats. The list of formats are always handled by
|
|
|
|
// libavformat.
|
|
|
|
// Maybe attempts should be made to convert the mplayer format to the libav
|
|
|
|
// format, instead of reyling on libav to auto-detect the stream's format
|
|
|
|
// correctly.
|
|
|
|
switch (file_format) {
|
2013-06-02 23:55:21 +02:00
|
|
|
//case DEMUXER_TYPE_MPEG_PS:
|
2012-09-07 14:42:25 +02:00
|
|
|
//case DEMUXER_TYPE_MPEG_TS:
|
2012-07-30 18:40:46 +02:00
|
|
|
case DEMUXER_TYPE_Y4M:
|
|
|
|
case DEMUXER_TYPE_NSV:
|
|
|
|
case DEMUXER_TYPE_AAC:
|
|
|
|
case DEMUXER_TYPE_MPC:
|
|
|
|
file_format = DEMUXER_TYPE_LAVF;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
// If somebody requested a demuxer check it
|
|
|
|
if (file_format) {
|
2010-11-10 13:37:15 +01:00
|
|
|
desc = get_demuxer_desc_from_type(file_format);
|
|
|
|
if (!desc)
|
|
|
|
// should only happen with obsolete -demuxer 99 numeric format
|
2008-04-12 17:51:08 +02:00
|
|
|
return NULL;
|
2012-07-24 08:01:47 +02:00
|
|
|
return open_given_type(opts, desc, stream, force, audio_id,
|
|
|
|
video_id, sub_id, filename, params);
|
2006-10-20 21:36:59 +02:00
|
|
|
}
|
2010-11-10 13:37:15 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
// Test demuxers with safe file checks
|
2010-11-10 13:37:15 +01:00
|
|
|
for (int i = 0; (desc = demuxer_list[i]); i++) {
|
|
|
|
if (desc->safe_check) {
|
|
|
|
demuxer = open_given_type(opts, desc, stream, false, audio_id,
|
2011-08-04 07:38:39 +02:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 13:37:15 +01:00
|
|
|
if (demuxer)
|
2012-07-24 08:01:47 +02:00
|
|
|
return demuxer;
|
2006-10-19 20:20:12 +02:00
|
|
|
}
|
|
|
|
}
|
2003-01-19 01:21:54 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
// Ok. We're over the stable detectable fileformats, the next ones are
|
|
|
|
// a bit fuzzy. So by default (extension_parsing==1) try extension-based
|
|
|
|
// detection first:
|
2010-11-11 15:24:17 +01:00
|
|
|
if (filename && opts->extension_parsing == 1) {
|
2010-11-10 13:37:15 +01:00
|
|
|
desc = get_demuxer_desc_from_type(demuxer_type_by_filename(filename));
|
|
|
|
if (desc)
|
|
|
|
demuxer = open_given_type(opts, desc, stream, false, audio_id,
|
2011-08-04 07:38:39 +02:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 13:37:15 +01:00
|
|
|
if (demuxer)
|
2012-07-24 08:01:47 +02:00
|
|
|
return demuxer;
|
2008-04-12 17:51:08 +02:00
|
|
|
}
|
2010-11-10 13:37:15 +01:00
|
|
|
|
|
|
|
// Finally try detection for demuxers with unsafe checks
|
|
|
|
for (int i = 0; (desc = demuxer_list[i]); i++) {
|
|
|
|
if (!desc->safe_check && desc->check_file) {
|
|
|
|
demuxer = open_given_type(opts, desc, stream, false, audio_id,
|
2011-08-04 07:38:39 +02:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 13:37:15 +01:00
|
|
|
if (demuxer)
|
2012-07-24 08:01:47 +02:00
|
|
|
return demuxer;
|
2006-10-19 20:20:12 +02:00
|
|
|
}
|
|
|
|
}
|
2001-12-26 17:34:06 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return NULL;
|
2001-07-22 00:37:55 +02:00
|
|
|
}
|
2001-08-12 19:28:16 +02:00
|
|
|
|
2011-08-04 07:38:39 +02:00
|
|
|
struct demuxer *demux_open(struct MPOpts *opts, stream_t *vs, int file_format,
|
|
|
|
int audio_id, int video_id, int sub_id,
|
|
|
|
char *filename)
|
|
|
|
{
|
2012-08-19 18:11:53 +02:00
|
|
|
return demux_open_withparams(opts, vs, file_format, opts->demuxer_name,
|
|
|
|
audio_id, video_id, sub_id, filename, NULL);
|
2011-08-04 07:38:39 +02:00
|
|
|
}
|
|
|
|
|
2008-06-04 07:10:48 +02:00
|
|
|
void demux_flush(demuxer_t *demuxer)
|
|
|
|
{
|
2008-06-02 12:17:48 +02:00
|
|
|
ds_free_packs(demuxer->video);
|
|
|
|
ds_free_packs(demuxer->audio);
|
|
|
|
ds_free_packs(demuxer->sub);
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
if (!demuxer->seekable) {
|
|
|
|
if (demuxer->file_format == DEMUXER_TYPE_AVI)
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n");
|
2008-07-30 14:01:30 +02:00
|
|
|
#ifdef CONFIG_TV
|
2008-04-12 17:51:08 +02:00
|
|
|
else if (demuxer->file_format == DEMUXER_TYPE_TV)
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "TV input is not seekable! (Seeking will probably be for changing channels ;)\n");
|
2001-11-10 00:46:06 +01:00
|
|
|
#endif
|
2008-04-12 17:51:08 +02:00
|
|
|
else
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in this file.\n");
|
2008-04-12 17:51:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2012-12-08 13:12:46 +01:00
|
|
|
|
|
|
|
if (rel_seek_secs == MP_NOPTS_VALUE && (flags & SEEK_ABSOLUTE))
|
|
|
|
return 0;
|
|
|
|
|
2001-08-12 19:28:16 +02:00
|
|
|
// clear demux buffers:
|
2008-06-04 07:10:48 +02:00
|
|
|
demux_flush(demuxer);
|
2008-04-12 17:51:08 +02:00
|
|
|
demuxer->video->eof = 0;
|
|
|
|
demuxer->audio->eof = 0;
|
2010-08-29 08:46:06 +02:00
|
|
|
demuxer->sub->eof = 0;
|
2013-02-14 14:49:50 +01:00
|
|
|
demuxer->warned_queue_overflow = false;
|
2001-08-12 19:28:16 +02:00
|
|
|
|
2010-04-23 20:01:21 +02:00
|
|
|
/* HACK: assume any demuxer used with these streams can cope with
|
|
|
|
* the stream layer suddenly seeking to a different position under it
|
|
|
|
* (nothing actually implements DEMUXER_CTRL_RESYNC now).
|
|
|
|
*/
|
|
|
|
struct stream *stream = demuxer->stream;
|
2013-05-03 19:52:28 +02:00
|
|
|
if (stream_manages_timeline(stream)) {
|
2010-04-23 20:01:21 +02:00
|
|
|
double pts;
|
|
|
|
|
|
|
|
if (flags & SEEK_ABSOLUTE)
|
|
|
|
pts = 0.0f;
|
|
|
|
else {
|
|
|
|
if (demuxer->stream_pts == MP_NOPTS_VALUE)
|
|
|
|
goto dmx_seek;
|
|
|
|
pts = demuxer->stream_pts;
|
|
|
|
}
|
2006-11-07 23:54:28 +01:00
|
|
|
|
2010-04-23 20:01:21 +02:00
|
|
|
if (flags & SEEK_FACTOR) {
|
|
|
|
double tmp = 0;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH,
|
|
|
|
&tmp) == STREAM_UNSUPPORTED)
|
|
|
|
goto dmx_seek;
|
|
|
|
pts += tmp * rel_seek_secs;
|
|
|
|
} else
|
|
|
|
pts += rel_seek_secs;
|
|
|
|
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts)
|
|
|
|
!= STREAM_UNSUPPORTED) {
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-11-07 23:54:28 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
dmx_seek:
|
|
|
|
if (demuxer->desc->seek)
|
|
|
|
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
|
2001-08-12 19:28:16 +02:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return 1;
|
2001-08-12 19:28:16 +02:00
|
|
|
}
|
|
|
|
|
2006-07-13 07:03:43 +02:00
|
|
|
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
|
2010-05-19 12:32:32 +02:00
|
|
|
{
|
2012-07-28 23:47:42 +02:00
|
|
|
return demux_info_add_bstr(demuxer, bstr0(opt), bstr0(param));
|
2010-05-19 12:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
|
2001-11-21 17:14:14 +01:00
|
|
|
{
|
2002-02-14 14:04:35 +01:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n = 0;
|
2001-11-21 17:14:14 +01:00
|
|
|
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
for (n = 0; info && info[2 * n] != NULL; n++) {
|
2012-07-28 23:47:42 +02:00
|
|
|
if (!bstrcasecmp(opt, bstr0(info[2*n]))) {
|
|
|
|
if (!bstrcmp(param, bstr0(info[2*n + 1]))) {
|
2010-05-19 12:32:32 +02:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "Demuxer info %.*s set to unchanged value %.*s\n",
|
|
|
|
BSTR_P(opt), BSTR_P(param));
|
2009-09-14 10:29:18 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-19 12:32:32 +02:00
|
|
|
mp_tmsg(MSGT_DEMUX, MSGL_INFO, "Demuxer info %.*s changed to %.*s\n",
|
|
|
|
BSTR_P(opt), BSTR_P(param));
|
|
|
|
talloc_free(info[2*n + 1]);
|
|
|
|
info[2*n + 1] = talloc_strndup(demuxer->info, param.start, param.len);
|
2008-04-12 17:51:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 12:32:32 +02:00
|
|
|
info = demuxer->info = talloc_realloc(demuxer, info, char *, 2 * (n + 2));
|
|
|
|
info[2*n] = talloc_strndup(demuxer->info, opt.start, opt.len);
|
|
|
|
info[2*n + 1] = talloc_strndup(demuxer->info, param.start, param.len);
|
2008-04-12 17:51:08 +02:00
|
|
|
memset(&info[2 * (n + 1)], 0, 2 * sizeof(char *));
|
2001-11-22 16:43:24 +01:00
|
|
|
|
2002-02-14 14:04:35 +01:00
|
|
|
return 1;
|
2001-11-21 17:14:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_print(demuxer_t *demuxer)
|
|
|
|
{
|
2002-02-14 14:04:35 +01:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n;
|
2001-11-21 17:14:14 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
|
2009-07-07 00:15:02 +02:00
|
|
|
mp_tmsg(MSGT_DEMUX, MSGL_INFO, "Clip info:\n");
|
2008-04-12 17:51:08 +02:00
|
|
|
for (n = 0; info[2 * n] != NULL; n++) {
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n", info[2 * n],
|
|
|
|
info[2 * n + 1]);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_NAME%d=%s\n", n,
|
|
|
|
info[2 * n]);
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_VALUE%d=%s\n", n,
|
|
|
|
info[2 * n + 1]);
|
2005-06-21 01:07:35 +02:00
|
|
|
}
|
2006-04-24 09:20:34 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n);
|
2002-01-16 04:25:07 +01:00
|
|
|
|
|
|
|
return 0;
|
2001-11-21 17:14:14 +01:00
|
|
|
}
|
2002-02-20 17:59:25 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
char *demux_info_get(demuxer_t *demuxer, const char *opt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char **info = demuxer->info;
|
2002-02-20 17:59:25 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
for (i = 0; info && info[2 * i] != NULL; i++) {
|
|
|
|
if (!strcasecmp(opt, info[2 * i]))
|
|
|
|
return info[2 * i + 1];
|
|
|
|
}
|
2002-02-20 17:59:25 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return NULL;
|
2002-02-20 17:59:25 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demux_control(demuxer_t *demuxer, int cmd, void *arg)
|
|
|
|
{
|
2005-08-05 21:57:47 +02:00
|
|
|
|
|
|
|
if (demuxer->desc->control)
|
2008-04-12 17:51:08 +02:00
|
|
|
return demuxer->desc->control(demuxer, cmd, arg);
|
2005-08-05 21:57:47 +02:00
|
|
|
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
2002-11-16 04:42:14 +01:00
|
|
|
}
|
|
|
|
|
2012-08-19 18:01:30 +02:00
|
|
|
struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d,
|
|
|
|
enum stream_type t, int id)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2012-08-19 18:01:30 +02:00
|
|
|
for (int n = 0; n < d->num_streams; n++) {
|
|
|
|
struct sh_stream *s = d->streams[n];
|
|
|
|
if (s->type == t && s->demuxer_id == id)
|
|
|
|
return d->streams[n];
|
2010-05-22 07:19:23 +02:00
|
|
|
}
|
2012-08-19 18:01:30 +02:00
|
|
|
return NULL;
|
2005-04-03 16:08:28 +02:00
|
|
|
}
|
2006-08-06 20:55:34 +02:00
|
|
|
|
2012-08-19 18:01:30 +02:00
|
|
|
void demuxer_switch_track(struct demuxer *demuxer, enum stream_type type,
|
|
|
|
struct sh_stream *stream)
|
|
|
|
{
|
|
|
|
assert(!stream || stream->type == type);
|
2013-04-14 06:20:31 +02:00
|
|
|
|
2013-05-29 14:54:51 +02:00
|
|
|
// don't flush buffers if stream is already selected
|
|
|
|
if (stream && demuxer_stream_is_selected(demuxer, stream))
|
|
|
|
return;
|
|
|
|
|
2013-04-14 06:20:31 +02:00
|
|
|
int old_id = demuxer->ds[type]->id;
|
|
|
|
|
|
|
|
// legacy
|
2013-04-29 22:34:36 +02:00
|
|
|
int index = stream ? stream->stream_index : -2;
|
2012-08-19 18:01:30 +02:00
|
|
|
if (type == STREAM_AUDIO) {
|
2012-09-23 14:59:36 +02:00
|
|
|
if (demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index)
|
|
|
|
== DEMUXER_CTRL_NOTIMPL)
|
|
|
|
demuxer->audio->id = index;
|
2012-08-19 18:01:30 +02:00
|
|
|
} else if (type == STREAM_VIDEO) {
|
2012-09-23 14:59:36 +02:00
|
|
|
if (demux_control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO, &index)
|
|
|
|
== DEMUXER_CTRL_NOTIMPL)
|
|
|
|
demuxer->video->id = index;
|
2012-08-19 18:01:30 +02:00
|
|
|
} else if (type == STREAM_SUB) {
|
2013-04-29 22:34:36 +02:00
|
|
|
demuxer->ds[type]->id = index;
|
2013-04-09 10:06:54 +02:00
|
|
|
} else {
|
|
|
|
abort();
|
2011-03-30 22:22:45 +02:00
|
|
|
}
|
2013-04-09 10:06:54 +02:00
|
|
|
|
2012-08-19 18:01:30 +02:00
|
|
|
int new_id = demuxer->ds[type]->id;
|
|
|
|
void *new = NULL;
|
|
|
|
if (new_id >= 0) {
|
|
|
|
switch (type) {
|
|
|
|
case STREAM_VIDEO: new = demuxer->v_streams[new_id]; break;
|
|
|
|
case STREAM_AUDIO: new = demuxer->a_streams[new_id]; break;
|
|
|
|
case STREAM_SUB: new = demuxer->s_streams[new_id]; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
demuxer->ds[type]->sh = new;
|
2013-04-14 06:20:31 +02:00
|
|
|
|
|
|
|
if (old_id != new_id) {
|
|
|
|
ds_free_packs(demuxer->ds[type]);
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_SWITCHED_TRACKS, NULL);
|
|
|
|
}
|
2006-11-16 22:23:06 +01:00
|
|
|
}
|
|
|
|
|
2013-04-14 19:19:35 +02:00
|
|
|
bool demuxer_stream_is_selected(struct demuxer *d, struct sh_stream *stream)
|
|
|
|
{
|
2013-04-29 22:34:36 +02:00
|
|
|
return stream && d->ds[stream->type]->id == stream->stream_index;
|
2013-04-14 19:19:35 +02:00
|
|
|
}
|
|
|
|
|
2010-05-19 12:44:37 +02:00
|
|
|
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
|
|
|
|
struct bstr type, struct bstr data)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2010-01-26 02:31:31 +01:00
|
|
|
if (!(demuxer->num_attachments % 32))
|
|
|
|
demuxer->attachments = talloc_realloc(demuxer, demuxer->attachments,
|
|
|
|
struct demux_attachment,
|
|
|
|
demuxer->num_attachments + 32);
|
|
|
|
|
|
|
|
struct demux_attachment *att =
|
|
|
|
demuxer->attachments + demuxer->num_attachments;
|
2010-05-19 12:44:37 +02:00
|
|
|
att->name = talloc_strndup(demuxer->attachments, name.start, name.len);
|
|
|
|
att->type = talloc_strndup(demuxer->attachments, type.start, type.len);
|
|
|
|
att->data = talloc_size(demuxer->attachments, data.len);
|
|
|
|
memcpy(att->data, data.start, data.len);
|
|
|
|
att->data_size = data.len;
|
2008-01-12 02:12:36 +01:00
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
return demuxer->num_attachments++;
|
2008-01-12 02:12:36 +01:00
|
|
|
}
|
|
|
|
|
2012-02-26 21:12:53 +01:00
|
|
|
static int chapter_compare(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
struct demux_chapter *c1 = (void *)p1;
|
|
|
|
struct demux_chapter *c2 = (void *)p2;
|
|
|
|
|
|
|
|
if (c1->start > c2->start)
|
|
|
|
return 1;
|
|
|
|
else if (c1->start < c2->start)
|
|
|
|
return -1;
|
2013-04-12 13:20:37 +02:00
|
|
|
return c1->original_index > c2->original_index ? 1 :-1; // never equal
|
2012-02-26 21:12:53 +01:00
|
|
|
}
|
|
|
|
|
2013-04-12 13:20:37 +02:00
|
|
|
void demuxer_sort_chapters(demuxer_t *demuxer)
|
2012-02-26 21:12:53 +01:00
|
|
|
{
|
|
|
|
qsort(demuxer->chapters, demuxer->num_chapters,
|
|
|
|
sizeof(struct demux_chapter), chapter_compare);
|
|
|
|
}
|
|
|
|
|
2010-05-19 12:44:37 +02:00
|
|
|
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
|
2010-01-26 02:31:31 +01:00
|
|
|
uint64_t start, uint64_t end)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2013-04-12 13:38:20 +02:00
|
|
|
struct demux_chapter new = {
|
|
|
|
.original_index = demuxer->num_chapters,
|
|
|
|
.start = start,
|
|
|
|
.end = end,
|
2013-05-06 23:33:38 +02:00
|
|
|
.name = name.len ? bstrdup0(demuxer, name) : NULL,
|
2013-04-12 13:38:20 +02:00
|
|
|
};
|
|
|
|
MP_TARRAY_APPEND(demuxer, demuxer->chapters, demuxer->num_chapters, new);
|
2012-02-26 21:12:53 +01:00
|
|
|
return 0;
|
2006-08-06 20:55:34 +02:00
|
|
|
}
|
|
|
|
|
stream: report chapter times, use time seeks for DVD chapters
Allow the stream layer to report chapter times. Extend stream_dvd to do
this. I'm not 100% sure whether the re-used code is bug-free (because it
was used for slave-mode and/or debugging only).
MAke the frontend do time-based seeks when switching DVD chapters. I'm
not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists
(maybe/hopefully not), but we will see.
Note that querying chapter times in demuxer_chapter_time() with the new
STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with
the cache enabled. The frontend likes to query chapter times very often.
Additionally, stream_dvd uses some sort of quadratic algorithm to list
times for all chapters. For this reason, we try to query all chapters on
start (after the demuxer is opened), and add the chapters to the demuxer
chapter list. demuxer_chapter_time() will get the time from that list,
instead of asking the stream layer over and over again.
This assumes stream_dvd knows the list of chapters at the start, and
also that the list of chapters never changes during playback. This
seems to be true, and the only exception, switching DVD titles, is not
supported at runtime (and doesn't need to be supported).
2013-05-04 01:20:39 +02:00
|
|
|
static void add_stream_chapters(struct demuxer *demuxer)
|
|
|
|
{
|
|
|
|
if (demuxer->num_chapters)
|
|
|
|
return;
|
|
|
|
int num_chapters = demuxer_chapter_count(demuxer);
|
|
|
|
for (int n = 0; n < num_chapters; n++) {
|
|
|
|
double p = n;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CHAPTER_TIME, &p)
|
|
|
|
!= STREAM_OK)
|
|
|
|
return;
|
|
|
|
demuxer_add_chapter(demuxer, bstr0(""), p * 1e9, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-18 18:48:22 +02:00
|
|
|
/**
|
2008-04-12 17:51:08 +02:00
|
|
|
* \brief demuxer_seek_chapter() seeks to a chapter in two possible ways:
|
2006-08-18 18:48:22 +02:00
|
|
|
* either using the demuxer->chapters structure set by the demuxer
|
|
|
|
* or asking help to the stream layer (e.g. dvd)
|
2006-08-18 21:03:59 +02:00
|
|
|
* \param chapter - chapter number wished - 0-based
|
2006-08-18 18:48:22 +02:00
|
|
|
* \param seek_pts set by the function to the pts to seek to (if demuxer->chapters is set)
|
|
|
|
* \return -1 on error, current chapter if successful
|
|
|
|
*/
|
|
|
|
|
2011-10-23 04:51:44 +02:00
|
|
|
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2013-05-09 01:09:08 +02:00
|
|
|
int ris = STREAM_UNSUPPORTED;
|
2006-08-18 18:48:22 +02:00
|
|
|
|
2013-05-09 01:09:08 +02:00
|
|
|
if (demuxer->num_chapters == 0)
|
2008-06-16 14:54:28 +02:00
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER,
|
|
|
|
&chapter);
|
2013-05-09 01:09:08 +02:00
|
|
|
|
|
|
|
if (ris != STREAM_UNSUPPORTED) {
|
|
|
|
demux_flush(demuxer);
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
2006-08-18 18:48:22 +02:00
|
|
|
|
2008-06-16 14:54:28 +02:00
|
|
|
// exit status may be ok, but main() doesn't have to seek itself
|
2008-04-12 17:51:08 +02:00
|
|
|
// (because e.g. dvds depend on sectors, not on pts)
|
2006-08-18 18:48:22 +02:00
|
|
|
*seek_pts = -1.0;
|
2006-08-21 21:19:00 +02:00
|
|
|
|
2013-05-09 01:09:08 +02:00
|
|
|
return chapter;
|
|
|
|
} else {
|
2009-04-01 18:55:26 +02:00
|
|
|
if (chapter >= demuxer->num_chapters)
|
2008-04-12 17:51:08 +02:00
|
|
|
return -1;
|
2009-04-01 18:55:26 +02:00
|
|
|
if (chapter < 0)
|
|
|
|
chapter = 0;
|
2006-08-18 18:48:22 +02:00
|
|
|
|
2011-01-23 23:29:01 +01:00
|
|
|
*seek_pts = demuxer->chapters[chapter].start / 1e9;
|
2006-08-18 18:48:22 +02:00
|
|
|
|
2009-04-01 18:55:26 +02:00
|
|
|
return chapter;
|
2006-08-18 18:48:22 +02:00
|
|
|
}
|
|
|
|
}
|
2007-12-13 13:51:05 +01:00
|
|
|
|
2010-11-13 14:48:26 +01:00
|
|
|
int demuxer_get_current_chapter(demuxer_t *demuxer, double time_now)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2010-04-24 19:46:54 +02:00
|
|
|
int chapter = -2;
|
2007-12-13 13:51:05 +01:00
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
|
|
|
&chapter) == STREAM_UNSUPPORTED)
|
2010-04-24 19:46:54 +02:00
|
|
|
chapter = -2;
|
2008-04-12 17:51:08 +02:00
|
|
|
} else {
|
2011-01-23 23:29:01 +01:00
|
|
|
uint64_t now = time_now * 1e9 + 0.5;
|
2007-12-13 13:51:05 +01:00
|
|
|
for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
|
|
|
|
if (demuxer->chapters[chapter].start <= now)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chapter;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
char *demuxer_chapter_name(demuxer_t *demuxer, int chapter)
|
|
|
|
{
|
2007-12-13 13:51:05 +01:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters) {
|
2008-04-12 17:51:08 +02:00
|
|
|
if (chapter >= 0 && chapter < demuxer->num_chapters
|
|
|
|
&& demuxer->chapters[chapter].name)
|
2011-10-23 04:51:44 +02:00
|
|
|
return talloc_strdup(NULL, demuxer->chapters[chapter].name);
|
2007-12-13 13:51:05 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-04 01:02:09 +02:00
|
|
|
double demuxer_chapter_time(demuxer_t *demuxer, int chapter)
|
2008-04-12 17:51:08 +02:00
|
|
|
{
|
2007-12-13 13:51:05 +01:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters && chapter >= 0
|
2008-04-12 17:51:08 +02:00
|
|
|
&& chapter < demuxer->num_chapters) {
|
2011-01-23 23:29:01 +01:00
|
|
|
return demuxer->chapters[chapter].start / 1e9;
|
2007-12-13 13:51:05 +01:00
|
|
|
}
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demuxer_chapter_count(demuxer_t *demuxer)
|
|
|
|
{
|
2007-12-13 13:51:05 +01:00
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
|
|
|
int num_chapters = 0;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
|
|
|
|
&num_chapters) == STREAM_UNSUPPORTED)
|
|
|
|
num_chapters = 0;
|
|
|
|
return num_chapters;
|
2008-04-12 17:51:08 +02:00
|
|
|
} else
|
2007-12-13 13:51:05 +01:00
|
|
|
return demuxer->num_chapters;
|
|
|
|
}
|
|
|
|
|
2013-05-03 20:07:04 +02:00
|
|
|
double demuxer_get_time_length(struct demuxer *demuxer)
|
|
|
|
{
|
2013-05-03 20:26:48 +02:00
|
|
|
double len;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, &len) > 0)
|
|
|
|
return len;
|
2013-05-03 20:07:04 +02:00
|
|
|
// <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
|
2013-05-03 20:26:48 +02:00
|
|
|
if (demux_control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH, &len) > 0)
|
|
|
|
return len;
|
2013-05-03 20:07:04 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double demuxer_get_start_time(struct demuxer *demuxer)
|
|
|
|
{
|
|
|
|
double time;
|
2013-05-03 20:26:48 +02:00
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_START_TIME, &time) > 0)
|
|
|
|
return time;
|
2013-05-03 20:07:04 +02:00
|
|
|
if (demux_control(demuxer, DEMUXER_CTRL_GET_START_TIME, &time) > 0)
|
|
|
|
return time;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demuxer_angles_count(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_ANGLES, &angles);
|
2008-04-12 17:51:08 +02:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
return angles;
|
|
|
|
}
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demuxer_get_current_angle(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, curr_angle = -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_ANGLE, &curr_angle);
|
2008-04-12 17:51:08 +02:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
return curr_angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-12 17:51:08 +02:00
|
|
|
int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
|
|
|
|
angles = demuxer_angles_count(demuxer);
|
2008-04-12 17:51:08 +02:00
|
|
|
if ((angles < 1) || (angle > angles))
|
|
|
|
return -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
|
2008-06-02 12:17:48 +02:00
|
|
|
demux_flush(demuxer);
|
2008-01-05 15:28:57 +01:00
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_SET_ANGLE, &angle);
|
2008-04-12 17:51:08 +02:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 15:28:57 +01:00
|
|
|
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|