2009-05-08 21:51:13 +00: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 20:28:24 +00:00
|
|
|
|
2001-04-23 03:42:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-11-27 00:42:39 +00:00
|
|
|
#include <string.h>
|
2001-08-01 09:14:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
#include "config.h"
|
2008-04-16 01:23:38 +00:00
|
|
|
#include "options.h"
|
2009-03-16 03:11:22 +00:00
|
|
|
#include "talloc.h"
|
2001-08-17 00:40:25 +00:00
|
|
|
#include "mp_msg.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "m_config.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2005-12-17 10:46:48 +00:00
|
|
|
#include "libvo/fastmemcpy.h"
|
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2001-04-23 03:42:17 +00:00
|
|
|
#include "demuxer.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
#include "stheader.h"
|
2002-02-06 20:16:35 +00:00
|
|
|
#include "mf.h"
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libaf/af_format.h"
|
2009-11-10 11:26:03 +00:00
|
|
|
#include "libmpcodecs/dec_teletext.h"
|
2002-03-15 15:53:11 +00:00
|
|
|
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2008-07-17 17:14:12 +00: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
|
|
|
|
#endif
|
|
|
|
|
2010-01-24 15:19:14 +00:00
|
|
|
static void clear_parser(sh_common_t *sh);
|
2005-08-05 19:57:47 +00: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 11:05:35 +00:00
|
|
|
extern const struct demuxer_desc demuxer_desc_edl;
|
2008-01-13 16:00:39 +00: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_y4m;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_asf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_real;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_smjpeg;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_matroska;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_realaudio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_vqf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mov;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_vivo;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_fli;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_film;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_roq;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_gif;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_ogg;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_avs;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_pva;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_nsv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ts;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lmlm4;
|
|
|
|
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_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_gxf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg4_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_h264_es;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rawdv;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpc;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_audio;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_xmms;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_mpeg_ty;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rtp;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_rtp_nemesi;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lavf;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_lavf_preferred;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_aac;
|
|
|
|
extern const demuxer_desc_t demuxer_desc_nut;
|
2008-11-30 13:22:34 +00:00
|
|
|
extern const demuxer_desc_t demuxer_desc_mng;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-01-28 16:03:22 +00:00
|
|
|
/* Please do not add any new demuxers here. If you want to implement a new
|
2008-01-28 22:09:21 +00:00
|
|
|
* demuxer, add it to libavformat, except for wrappers around external
|
|
|
|
* libraries and demuxers requiring binary support. */
|
2008-01-28 16:03:22 +00:00
|
|
|
|
2008-04-12 15:51:08 +00: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 11:05:35 +00:00
|
|
|
&demuxer_desc_edl,
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rawaudio,
|
|
|
|
&demuxer_desc_rawvideo,
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_TV
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_tv,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_mf,
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_lavf_preferred,
|
2007-04-22 20:32:15 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_avi,
|
|
|
|
&demuxer_desc_y4m,
|
|
|
|
&demuxer_desc_asf,
|
|
|
|
&demuxer_desc_nsv,
|
|
|
|
&demuxer_desc_real,
|
|
|
|
&demuxer_desc_smjpeg,
|
|
|
|
&demuxer_desc_matroska,
|
|
|
|
&demuxer_desc_realaudio,
|
|
|
|
&demuxer_desc_vqf,
|
|
|
|
&demuxer_desc_mov,
|
|
|
|
&demuxer_desc_vivo,
|
|
|
|
&demuxer_desc_fli,
|
|
|
|
&demuxer_desc_film,
|
|
|
|
&demuxer_desc_roq,
|
2008-08-05 08:47:51 +00:00
|
|
|
#ifdef CONFIG_GIF
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_gif,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-08-02 16:30:32 +00:00
|
|
|
#ifdef CONFIG_OGGVORBIS
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_ogg,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_WIN32DLL
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_avs,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_pva,
|
|
|
|
&demuxer_desc_mpeg_ts,
|
|
|
|
&demuxer_desc_lmlm4,
|
|
|
|
&demuxer_desc_mpeg_ps,
|
|
|
|
&demuxer_desc_mpeg_pes,
|
|
|
|
&demuxer_desc_mpeg_es,
|
|
|
|
&demuxer_desc_mpeg_gxf,
|
|
|
|
&demuxer_desc_mpeg4_es,
|
|
|
|
&demuxer_desc_h264_es,
|
|
|
|
&demuxer_desc_audio,
|
|
|
|
&demuxer_desc_mpeg_ty,
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_LIVE555
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rtp,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-08-07 12:20:50 +00:00
|
|
|
#ifdef CONFIG_LIBNEMESI
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rtp_nemesi,
|
2007-12-04 13:05:25 +00:00
|
|
|
#endif
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_lavf,
|
2006-07-04 21:26:41 +00:00
|
|
|
#endif
|
2008-08-07 11:19:54 +00:00
|
|
|
#ifdef CONFIG_MUSEPACK
|
2008-06-16 12:11:14 +00:00
|
|
|
&demuxer_desc_mpc,
|
2008-05-27 17:27:06 +00:00
|
|
|
#endif
|
2008-08-02 16:30:32 +00:00
|
|
|
#ifdef CONFIG_LIBDV095
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_rawdv,
|
2005-08-05 19:57:47 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_aac,
|
2008-08-02 16:30:32 +00:00
|
|
|
#ifdef CONFIG_LIBNUT
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_nut,
|
2006-09-17 09:32:28 +00:00
|
|
|
#endif
|
2008-08-07 08:58:07 +00:00
|
|
|
#ifdef CONFIG_XMMS
|
2008-04-12 15:51:08 +00:00
|
|
|
&demuxer_desc_xmms,
|
2008-11-30 13:22:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MNG
|
|
|
|
&demuxer_desc_mng,
|
2006-07-04 21:26:41 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00: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 19:57:47 +00:00
|
|
|
};
|
|
|
|
|
2011-01-17 14:16:39 +00:00
|
|
|
struct demux_packet *new_demux_packet(size_t len)
|
2011-01-17 13:47:57 +00:00
|
|
|
{
|
2011-01-17 14:16:39 +00:00
|
|
|
if (len > 1000000000) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to allocate demux packet "
|
|
|
|
"over 1 GB!\n");
|
|
|
|
abort();
|
|
|
|
}
|
2011-01-17 13:47:57 +00:00
|
|
|
struct demux_packet *dp = malloc(sizeof(struct demux_packet));
|
|
|
|
dp->len = len;
|
|
|
|
dp->next = NULL;
|
|
|
|
dp->pts = MP_NOPTS_VALUE;
|
2011-01-26 18:42:15 +00:00
|
|
|
dp->duration = -1;
|
2011-01-17 13:47:57 +00:00
|
|
|
dp->stream_pts = MP_NOPTS_VALUE;
|
|
|
|
dp->pos = 0;
|
|
|
|
dp->flags = 0;
|
|
|
|
dp->refcount = 1;
|
|
|
|
dp->master = NULL;
|
|
|
|
dp->buffer = NULL;
|
2011-06-18 16:55:13 +00: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 14:16:39 +00:00
|
|
|
}
|
2011-06-18 16:55:13 +00:00
|
|
|
memset(dp->buffer + len, 0, 8);
|
2011-01-17 13:47:57 +00:00
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:16:39 +00:00
|
|
|
void resize_demux_packet(struct demux_packet *dp, size_t len)
|
2011-01-17 13:47:57 +00:00
|
|
|
{
|
2011-01-17 14:16:39 +00:00
|
|
|
if (len > 1000000000) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_FATAL, "Attempt to realloc demux packet "
|
|
|
|
"over 1 GB!\n");
|
|
|
|
abort();
|
|
|
|
}
|
2011-06-18 16:55:13 +00: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 13:47:57 +00:00
|
|
|
}
|
2011-06-18 16:55:13 +00:00
|
|
|
memset(dp->buffer + len, 0, 8);
|
2011-01-17 13:47:57 +00:00
|
|
|
dp->len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct demux_packet *clone_demux_packet(struct demux_packet *pack)
|
|
|
|
{
|
|
|
|
struct demux_packet *dp = malloc(sizeof(struct demux_packet));
|
|
|
|
while (pack->master)
|
|
|
|
pack = pack->master; // find the master
|
|
|
|
memcpy(dp, pack, sizeof(struct demux_packet));
|
|
|
|
dp->next = NULL;
|
|
|
|
dp->refcount = 0;
|
|
|
|
dp->master = pack;
|
|
|
|
pack->refcount++;
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_demux_packet(struct demux_packet *dp)
|
|
|
|
{
|
|
|
|
if (dp->master == NULL) { //dp is a master packet
|
|
|
|
dp->refcount--;
|
|
|
|
if (dp->refcount == 0) {
|
|
|
|
free(dp->buffer);
|
|
|
|
free(dp);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// dp is a clone:
|
|
|
|
free_demux_packet(dp->master);
|
|
|
|
free(dp);
|
|
|
|
}
|
|
|
|
|
2011-02-10 10:15:21 +00:00
|
|
|
static void free_demuxer_stream(struct demux_stream *ds)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2001-08-22 23:54:57 +00:00
|
|
|
ds_free_packs(ds);
|
|
|
|
free(ds);
|
|
|
|
}
|
|
|
|
|
2011-02-10 10:15:21 +00:00
|
|
|
static struct demux_stream *new_demuxer_stream(struct demuxer *demuxer, int id)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
|
|
|
demux_stream_t *ds = malloc(sizeof(demux_stream_t));
|
2009-11-02 01:40:09 +00:00
|
|
|
*ds = (demux_stream_t){
|
|
|
|
.id = id,
|
|
|
|
.demuxer = demuxer,
|
|
|
|
.asf_seq = -1,
|
|
|
|
};
|
2008-04-12 15:51:08 +00:00
|
|
|
return ds;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00: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 15:51:08 +00:00
|
|
|
static const demuxer_desc_t *get_demuxer_desc_from_type(int file_format)
|
2005-08-05 19:57:47 +00:00
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
int i;
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; demuxer_list[i]; i++)
|
|
|
|
if (file_format == demuxer_list[i]->type)
|
|
|
|
return demuxer_list[i];
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
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 15:51:08 +00:00
|
|
|
{
|
2009-03-16 03:11:22 +00:00
|
|
|
struct demuxer *d = talloc_zero(NULL, struct demuxer);
|
2008-04-12 15:51:08 +00: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 05:55:40 +00:00
|
|
|
d->filepos = -1;
|
2008-04-12 15:51:08 +00:00
|
|
|
d->audio = new_demuxer_stream(d, a_id);
|
|
|
|
d->video = new_demuxer_stream(d, v_id);
|
|
|
|
d->sub = new_demuxer_stream(d, s_id);
|
|
|
|
d->type = type;
|
2008-04-16 01:23:38 +00:00
|
|
|
d->opts = opts;
|
2008-04-12 15:51:08 +00: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(), "
|
|
|
|
"big troubles ahead.");
|
|
|
|
if (filename) // Filename hack for avs_check_file
|
|
|
|
d->filename = strdup(filename);
|
|
|
|
stream_seek(stream, stream->start_pos);
|
|
|
|
return d;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 16:04:18 +00:00
|
|
|
const char *sh_sub_type2str(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case 't': return "text";
|
|
|
|
case 'm': return "movtext";
|
|
|
|
case 'a': return "ass";
|
|
|
|
case 'v': return "vobsub";
|
|
|
|
case 'x': return "xsub";
|
|
|
|
case 'b': return "dvb";
|
|
|
|
case 'd': return "dvb-teletext";
|
|
|
|
case 'p': return "hdmv pgs";
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00: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 {
|
2011-07-03 11:48:00 +00:00
|
|
|
struct sh_sub *sh = talloc_zero(demuxer, struct sh_sub);
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->s_streams[id] = sh;
|
|
|
|
sh->sid = sid;
|
2008-04-16 01:23:38 +00:00
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
|
|
|
|
}
|
|
|
|
return demuxer->s_streams[id];
|
2006-11-13 16:15:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 16:23:17 +00: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")) {
|
2011-07-03 11:48:00 +00:00
|
|
|
sh->lang = talloc_strdup(sh, lang);
|
2010-10-29 16:23:17 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, lang);
|
|
|
|
}
|
|
|
|
return sh;
|
|
|
|
}
|
|
|
|
|
2008-08-12 10:58:29 +00:00
|
|
|
static void free_sh_sub(sh_sub_t *sh)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2007-06-23 17:39:27 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->extradata);
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2010-01-24 15:19:14 +00:00
|
|
|
clear_parser((sh_common_t *)sh);
|
2009-12-27 15:28:01 +00:00
|
|
|
#endif
|
2011-07-03 11:48:00 +00:00
|
|
|
talloc_free(sh);
|
2007-06-23 17:39:27 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00: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 18:09:20 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->a_streams[id]) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "WARNING: Audio stream header %d redefined.\n", id);
|
2001-07-21 22:37:55 +00:00
|
|
|
} else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_V, "==> Found audio stream: %d\n", id);
|
2011-07-03 11:48:00 +00:00
|
|
|
struct sh_audio *sh = talloc_zero(demuxer, struct sh_audio);
|
2008-05-27 17:30:20 +00:00
|
|
|
demuxer->a_streams[id] = sh;
|
2008-05-27 17:33:13 +00:00
|
|
|
sh->aid = aid;
|
2008-05-27 17:35:38 +00:00
|
|
|
sh->ds = demuxer->audio;
|
2004-09-16 19:51:13 +00:00
|
|
|
// set some defaults
|
2008-04-12 15:51:08 +00:00
|
|
|
sh->samplesize = 2;
|
|
|
|
sh->sample_format = AF_FORMAT_S16_NE;
|
2008-04-16 01:23:38 +00:00
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", aid);
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
|
|
|
return demuxer->a_streams[id];
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_sh_audio(demuxer_t *demuxer, int id)
|
|
|
|
{
|
2006-06-14 14:05:59 +00:00
|
|
|
sh_audio_t *sh = demuxer->a_streams[id];
|
|
|
|
demuxer->a_streams[id] = NULL;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_audio at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->wf);
|
|
|
|
free(sh->codecdata);
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2010-01-24 15:19:14 +00:00
|
|
|
clear_parser((sh_common_t *)sh);
|
2009-12-27 15:28:01 +00:00
|
|
|
#endif
|
2011-07-03 11:48:00 +00:00
|
|
|
talloc_free(sh);
|
2001-08-22 23:54:57 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00: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 18:09:20 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->v_streams[id])
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "WARNING: Video stream header %d redefined.\n", id);
|
2008-04-12 15:51:08 +00:00
|
|
|
else {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_V, "==> Found video stream: %d\n", id);
|
2011-07-03 11:48:00 +00:00
|
|
|
struct sh_video *sh = talloc_zero(demuxer, struct sh_video);
|
2008-04-16 01:23:38 +00:00
|
|
|
demuxer->v_streams[id] = sh;
|
2008-05-27 17:33:13 +00:00
|
|
|
sh->vid = vid;
|
2008-05-27 17:35:38 +00:00
|
|
|
sh->ds = demuxer->video;
|
2008-04-16 01:23:38 +00:00
|
|
|
sh->opts = demuxer->opts;
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_VIDEO_ID=%d\n", vid);
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
|
|
|
return demuxer->v_streams[id];
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_sh_video(sh_video_t *sh)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh);
|
2008-02-29 17:25:41 +00:00
|
|
|
free(sh->bih);
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2010-01-24 15:19:14 +00:00
|
|
|
clear_parser((sh_common_t *)sh);
|
2009-12-27 15:28:01 +00:00
|
|
|
#endif
|
2011-07-03 11:48:00 +00:00
|
|
|
talloc_free(sh);
|
2001-08-22 23:54:57 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void free_demuxer(demuxer_t *demuxer)
|
|
|
|
{
|
2001-08-22 23:54:57 +00:00
|
|
|
int i;
|
2010-02-20 17:50:56 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing %s demuxer at %p\n",
|
|
|
|
demuxer->desc->shortdesc, demuxer);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demuxer->desc->close)
|
|
|
|
demuxer->desc->close(demuxer);
|
2005-08-05 19:57:47 +00:00
|
|
|
// Very ugly hack to make it behave like old implementation
|
|
|
|
if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS)
|
2008-04-12 15:51:08 +00:00
|
|
|
goto skip_streamfree;
|
2001-08-22 23:54:57 +00:00
|
|
|
// free streams:
|
2008-04-12 15:51:08 +00: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-22 23:54:57 +00:00
|
|
|
// free demuxers:
|
|
|
|
free_demuxer_stream(demuxer->audio);
|
|
|
|
free_demuxer_stream(demuxer->video);
|
2002-03-31 02:45:14 +00:00
|
|
|
free_demuxer_stream(demuxer->sub);
|
2008-04-12 15:51:08 +00:00
|
|
|
skip_streamfree:
|
2008-02-29 17:25:41 +00:00
|
|
|
free(demuxer->filename);
|
2009-11-10 11:26:03 +00:00
|
|
|
if (demuxer->teletext)
|
|
|
|
teletext_control(demuxer->teletext, TV_VBI_CONTROL_STOP, NULL);
|
2009-03-16 03:11:22 +00:00
|
|
|
talloc_free(demuxer);
|
2001-08-22 23:54:57 +00:00
|
|
|
}
|
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
|
2010-12-20 04:42:04 +00:00
|
|
|
void ds_add_packet(demux_stream_t *ds, demux_packet_t *dp)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2001-02-24 20:28:24 +00:00
|
|
|
// append packet to DS stream:
|
|
|
|
++ds->packs;
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->bytes += dp->len;
|
|
|
|
if (ds->last) {
|
|
|
|
// next packet in stream
|
|
|
|
ds->last->next = dp;
|
|
|
|
ds->last = dp;
|
2001-02-24 20:28:24 +00:00
|
|
|
} else {
|
2008-04-12 15:51:08 +00:00
|
|
|
// first packet in stream
|
|
|
|
ds->first = ds->last = dp;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00: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 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 00:19:56 +00:00
|
|
|
#ifdef CONFIG_FFMPEG
|
2009-12-27 15:28:01 +00:00
|
|
|
static void allocate_parser(AVCodecContext **avctx, AVCodecParserContext **parser, unsigned format)
|
|
|
|
{
|
|
|
|
enum CodecID codec_id = CODEC_ID_NONE;
|
2010-09-04 08:11:31 +00:00
|
|
|
|
2009-12-27 15:28:01 +00:00
|
|
|
switch (format) {
|
2010-11-06 15:41:44 +00:00
|
|
|
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 0)
|
|
|
|
case MKTAG('M', 'P', '4', 'L'):
|
|
|
|
codec_id = CODEC_ID_AAC_LATM;
|
|
|
|
break;
|
|
|
|
#endif
|
2009-12-27 15:28:01 +00:00
|
|
|
case 0x2000:
|
|
|
|
case 0x332D6361:
|
|
|
|
case 0x332D4341:
|
2010-11-07 11:00:00 +00:00
|
|
|
case 0x20736D:
|
2009-12-27 15:28:01 +00:00
|
|
|
case MKTAG('s', 'a', 'c', '3'):
|
|
|
|
codec_id = CODEC_ID_AC3;
|
|
|
|
break;
|
2011-03-05 12:03:03 +00:00
|
|
|
case MKTAG('d', 'n', 'e', 't'):
|
|
|
|
// DNET/byte-swapped AC-3 - there is no parser for that yet
|
|
|
|
//codec_id = CODEC_ID_DNET;
|
|
|
|
break;
|
2009-12-27 15:28:01 +00:00
|
|
|
case MKTAG('E', 'A', 'C', '3'):
|
|
|
|
codec_id = CODEC_ID_EAC3;
|
|
|
|
break;
|
|
|
|
case 0x2001:
|
|
|
|
case 0x86:
|
|
|
|
codec_id = CODEC_ID_DTS;
|
|
|
|
break;
|
2010-12-09 00:50:17 +00:00
|
|
|
case MKTAG('f', 'L', 'a', 'C'):
|
|
|
|
codec_id = CODEC_ID_FLAC;
|
|
|
|
break;
|
2010-01-24 20:05:28 +00:00
|
|
|
case MKTAG('M', 'L', 'P', ' '):
|
|
|
|
codec_id = CODEC_ID_MLP;
|
|
|
|
break;
|
2009-12-27 15:28:01 +00:00
|
|
|
case 0x55:
|
|
|
|
case 0x5500736d:
|
2010-11-07 11:00:00 +00:00
|
|
|
case 0x55005354:
|
2009-12-27 15:28:01 +00:00
|
|
|
case MKTAG('.', 'm', 'p', '3'):
|
2010-11-07 10:55:01 +00:00
|
|
|
case MKTAG('M', 'P', '3', ' '):
|
2009-12-27 15:28:01 +00:00
|
|
|
case MKTAG('L', 'A', 'M', 'E'):
|
|
|
|
codec_id = CODEC_ID_MP3;
|
|
|
|
break;
|
|
|
|
case 0x50:
|
2010-11-07 11:00:00 +00:00
|
|
|
case 0x5000736d:
|
2009-12-27 15:28:01 +00:00
|
|
|
case MKTAG('.', 'm', 'p', '2'):
|
|
|
|
case MKTAG('.', 'm', 'p', '1'):
|
|
|
|
codec_id = CODEC_ID_MP2;
|
|
|
|
break;
|
2010-01-24 20:05:28 +00:00
|
|
|
case MKTAG('T', 'R', 'H', 'D'):
|
|
|
|
codec_id = CODEC_ID_TRUEHD;
|
|
|
|
break;
|
2009-12-27 15:28:01 +00:00
|
|
|
}
|
|
|
|
if (codec_id != CODEC_ID_NONE) {
|
|
|
|
*avctx = avcodec_alloc_context();
|
|
|
|
if (!*avctx)
|
|
|
|
return;
|
|
|
|
*parser = av_parser_init(codec_id);
|
|
|
|
if (!*parser)
|
|
|
|
av_freep(avctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_parser(sh_common_t *sh, AVCodecContext **avctx, AVCodecParserContext **parser)
|
|
|
|
{
|
|
|
|
*avctx = NULL;
|
|
|
|
*parser = NULL;
|
|
|
|
|
|
|
|
if (!sh || !sh->needs_parsing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*avctx = sh->avctx;
|
|
|
|
*parser = sh->parser;
|
|
|
|
if (*parser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
allocate_parser(avctx, parser, sh->format);
|
|
|
|
sh->avctx = *avctx;
|
|
|
|
sh->parser = *parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ds_parse(demux_stream_t *ds, uint8_t **buffer, int *len, double pts, off_t pos)
|
|
|
|
{
|
|
|
|
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 15:19:14 +00:00
|
|
|
|
|
|
|
static void clear_parser(sh_common_t *sh)
|
|
|
|
{
|
|
|
|
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 15:28:01 +00:00
|
|
|
#endif
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len,
|
|
|
|
double pts, off_t pos, int flags)
|
|
|
|
{
|
|
|
|
demux_packet_t *dp = new_demux_packet(len);
|
|
|
|
len = stream_read(stream, dp->buffer, len);
|
2003-09-20 12:50:25 +00:00
|
|
|
resize_demux_packet(dp, len);
|
2008-04-12 15:51:08 +00:00
|
|
|
dp->pts = pts;
|
|
|
|
dp->pos = pos;
|
|
|
|
dp->flags = flags;
|
2001-02-24 20:28:24 +00:00
|
|
|
// append packet to DS stream:
|
2008-04-12 15:51:08 +00:00
|
|
|
ds_add_packet(ds, dp);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF or no stream found or invalid type
|
|
|
|
// 1 = successfully read a packet
|
|
|
|
|
2008-04-12 15:51:08 +00: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 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return value:
|
|
|
|
// 0 = EOF
|
2007-12-01 13:35:25 +00:00
|
|
|
// 1 = successful
|
2008-04-12 15:51:08 +00: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 20:05:50 +00: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 15:51:08 +00:00
|
|
|
while (1) {
|
|
|
|
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;
|
|
|
|
ds->flags = p->flags;
|
|
|
|
// unlink packet:
|
|
|
|
ds->bytes -= p->len;
|
|
|
|
ds->current = p;
|
|
|
|
ds->first = p->next;
|
|
|
|
if (!ds->first)
|
|
|
|
ds->last = NULL;
|
|
|
|
--ds->packs;
|
2008-10-04 04:21:21 +00: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;
|
2008-04-12 15:51:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-06 22:15:02 +00:00
|
|
|
|
|
|
|
#define MaybeNI _("Maybe you are playing a non-interleaved stream/file or the codec failed?\n" \
|
|
|
|
"For AVI files, try to force non-interleaved mode with the -ni option.\n")
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demux->audio->packs >= MAX_PACKS
|
|
|
|
|| demux->audio->bytes >= MAX_PACK_BYTES) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "\nToo many audio packets in the buffer: (%d in %d bytes).\n",
|
2008-04-12 15:51:08 +00:00
|
|
|
demux->audio->packs, demux->audio->bytes);
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, MaybeNI);
|
2008-04-12 15:51:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (demux->video->packs >= MAX_PACKS
|
|
|
|
|| demux->video->bytes >= MAX_PACK_BYTES) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "\nToo many video packets in the buffer: (%d in %d bytes).\n",
|
2008-04-12 15:51:08 +00:00
|
|
|
demux->video->packs, demux->video->bytes);
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, MaybeNI);
|
2008-04-12 15:51:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!demux_fill_buffer(demux, ds)) {
|
|
|
|
mp_dbg(MSGT_DEMUXER, MSGL_DBG2,
|
|
|
|
"ds_fill_buffer()->demux_fill_buffer() failed\n");
|
|
|
|
break; // EOF
|
|
|
|
}
|
2001-07-29 21:07:34 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00: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 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00: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)
|
|
|
|
fast_memcpy(mem + bytes, &ds->buffer[ds->buffer_pos], x);
|
|
|
|
bytes += x;
|
|
|
|
len -= x;
|
|
|
|
ds->buffer_pos += x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bytes;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2006-01-17 20:04:49 +00: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,
|
2008-04-12 15:51:08 +00:00
|
|
|
int *read, uint32_t pattern)
|
|
|
|
{
|
|
|
|
register uint32_t head = 0xffffff00;
|
|
|
|
register uint32_t pat = pattern & 0xffffff00;
|
|
|
|
int total_len = 0;
|
2006-01-17 20:04:49 +00:00
|
|
|
do {
|
2008-04-12 15:51:08 +00:00
|
|
|
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;
|
2006-01-17 20:04:49 +00:00
|
|
|
}
|
2001-05-10 03:39:54 +00:00
|
|
|
|
2008-04-12 15:51:08 +00: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:
|
|
|
|
free(ds->asf_packet->buffer);
|
|
|
|
free(ds->asf_packet);
|
|
|
|
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 18:05:59 +00:00
|
|
|
ds->pts = MP_NOPTS_VALUE;
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->pts_bytes = 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet(demux_stream_t *ds, unsigned char **start)
|
|
|
|
{
|
2007-10-25 19:21:24 +00:00
|
|
|
int len;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
if (!ds_fill_buffer(ds)) {
|
2001-02-24 20:28:24 +00:00
|
|
|
// EOF
|
|
|
|
*start = NULL;
|
|
|
|
return -1;
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2007-10-25 19:21:24 +00:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos += len;
|
2007-10-25 19:21:24 +00:00
|
|
|
return len;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2001-04-20 23:00:11 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts)
|
2006-04-24 10:58:40 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
*pts = MP_NOPTS_VALUE;
|
2009-08-23 15:32:42 +00:00
|
|
|
len = ds_get_packet(ds, start);
|
|
|
|
if (len < 0)
|
|
|
|
return len;
|
2006-07-06 06:58:17 +00:00
|
|
|
// Return pts unless this read starts from the middle of a packet
|
2009-08-23 15:32:42 +00:00
|
|
|
if (len == ds->buffer_pos)
|
2008-04-12 15:51:08 +00:00
|
|
|
*pts = ds->current->pts;
|
2006-04-24 10:58:40 +00:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start)
|
|
|
|
{
|
2007-10-25 19:21:24 +00:00
|
|
|
int len;
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ds->buffer_pos >= ds->buffer_size) {
|
|
|
|
*start = NULL;
|
|
|
|
if (!ds->packs)
|
|
|
|
return -1; // no sub
|
|
|
|
if (!ds_fill_buffer(ds))
|
|
|
|
return -1; // EOF
|
2001-04-20 23:00:11 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
len = ds->buffer_size - ds->buffer_pos;
|
2007-10-25 19:21:24 +00:00
|
|
|
*start = &ds->buffer[ds->buffer_pos];
|
2008-04-12 15:51:08 +00:00
|
|
|
ds->buffer_pos += len;
|
2007-10-25 19:21:24 +00:00
|
|
|
return len;
|
2001-04-20 23:00:11 +00:00
|
|
|
}
|
|
|
|
|
2006-04-27 11:13:21 +00:00
|
|
|
double ds_get_next_pts(demux_stream_t *ds)
|
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer_t *demux = ds->demuxer;
|
2010-06-06 13:59:44 +00: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)) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (demux->audio->packs >= MAX_PACKS
|
|
|
|
|| demux->audio->bytes >= MAX_PACK_BYTES) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "\nToo many audio packets in the buffer: (%d in %d bytes).\n",
|
2008-04-12 15:51:08 +00:00
|
|
|
demux->audio->packs, demux->audio->bytes);
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, MaybeNI);
|
2008-04-12 15:51:08 +00:00
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
}
|
|
|
|
if (demux->video->packs >= MAX_PACKS
|
|
|
|
|| demux->video->bytes >= MAX_PACK_BYTES) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "\nToo many video packets in the buffer: (%d in %d bytes).\n",
|
2008-04-12 15:51:08 +00:00
|
|
|
demux->video->packs, demux->video->bytes);
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, MaybeNI);
|
2008-04-12 15:51:08 +00:00
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
}
|
|
|
|
if (!demux_fill_buffer(demux, ds))
|
|
|
|
return MP_NOPTS_VALUE;
|
2002-05-02 10:25:48 +00:00
|
|
|
}
|
2010-06-06 13:59:44 +00:00
|
|
|
// take pts from "current" if we never read from it.
|
|
|
|
if (ds->current && !ds->buffer_pos)
|
|
|
|
return ds->current->pts;
|
2008-04-12 15:51:08 +00:00
|
|
|
return ds->first->pts;
|
2002-05-02 10:25:48 +00:00
|
|
|
}
|
|
|
|
|
2001-07-21 22:37:55 +00:00
|
|
|
// ====================================================================
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
void demuxer_help(void)
|
|
|
|
{
|
2008-04-12 15:51:08 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "Available demuxers:\n");
|
2011-02-11 17:52:44 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, " demuxer: info: (comment)\n");
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXERS\n");
|
|
|
|
for (i = 0; demuxer_list[i]; i++) {
|
2011-02-11 17:52:44 +00:00
|
|
|
if (demuxer_list[i]->type >= DEMUXER_TYPE_END) // internal type
|
2008-04-12 15:51:08 +00:00
|
|
|
continue;
|
|
|
|
if (demuxer_list[i]->comment && strlen(demuxer_list[i]->comment))
|
2011-02-11 17:52:44 +00: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 15:51:08 +00:00
|
|
|
else
|
2011-02-11 17:52:44 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %s\n",
|
|
|
|
demuxer_list[i]->name, demuxer_list[i]->info);
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
2005-02-13 13:39:19 +00:00
|
|
|
|
2002-03-16 14:32:03 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
/**
|
|
|
|
* Get demuxer type for a given demuxer name
|
|
|
|
*
|
|
|
|
* @param demuxer_name string with demuxer name of demuxer number
|
2005-08-30 23:56:24 +00:00
|
|
|
* @param force will be set if demuxer should be forced.
|
|
|
|
* May be NULL.
|
2005-08-05 19:57:47 +00:00
|
|
|
* @return DEMUXER_TYPE_xxx, -1 if error or not found
|
|
|
|
*/
|
2011-02-10 10:15:21 +00:00
|
|
|
static int get_demuxer_type_from_name(char *demuxer_name, int *force)
|
2005-08-05 19:57:47 +00:00
|
|
|
{
|
2008-04-12 15:51:08 +00: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 17:52:44 +00: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 15:51:08 +00:00
|
|
|
continue;
|
|
|
|
if (strcmp(demuxer_name, demuxer_list[i]->name) == 0)
|
|
|
|
return demuxer_list[i]->type;
|
|
|
|
}
|
2005-08-05 19:57:47 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return -1;
|
2005-08-05 19:57:47 +00:00
|
|
|
}
|
2001-12-27 21:24:56 +00:00
|
|
|
|
2010-11-10 12:37:15 +00: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 05:38:39 +00:00
|
|
|
char *filename,
|
|
|
|
struct demuxer_params *params)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2010-11-10 12:37:15 +00:00
|
|
|
struct demuxer *demuxer;
|
|
|
|
int fformat;
|
|
|
|
demuxer = new_demuxer(opts, stream, desc->type, audio_id,
|
|
|
|
video_id, sub_id, filename);
|
2011-08-04 05:38:39 +00:00
|
|
|
demuxer->params = params;
|
2010-11-10 12:37:15 +00: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 13:38:36 +00: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 12:37:15 +00: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;
|
|
|
|
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 05:38:39 +00:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 12:37:15 +00:00
|
|
|
}
|
|
|
|
fail:
|
|
|
|
free_demuxer(demuxer);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
|
2010-11-10 12:37:15 +00:00
|
|
|
static struct demuxer *demux_open_stream(struct MPOpts *opts,
|
|
|
|
struct stream *stream,
|
|
|
|
int file_format, bool force,
|
|
|
|
int audio_id, int video_id, int sub_id,
|
2011-08-04 05:38:39 +00:00
|
|
|
char *filename,
|
|
|
|
struct demuxer_params *params)
|
2010-11-10 12:37:15 +00:00
|
|
|
{
|
|
|
|
struct demuxer *demuxer = NULL;
|
|
|
|
const struct demuxer_desc *desc;
|
2008-04-12 15:51:08 +00:00
|
|
|
|
|
|
|
// If somebody requested a demuxer check it
|
|
|
|
if (file_format) {
|
2010-11-10 12:37:15 +00:00
|
|
|
desc = get_demuxer_desc_from_type(file_format);
|
|
|
|
if (!desc)
|
|
|
|
// should only happen with obsolete -demuxer 99 numeric format
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2010-11-10 12:37:15 +00:00
|
|
|
demuxer = open_given_type(opts, desc, stream, force, audio_id,
|
2011-08-04 05:38:39 +00:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 12:37:15 +00:00
|
|
|
if (demuxer)
|
|
|
|
goto dmx_open;
|
|
|
|
return NULL;
|
2006-10-20 19:36:59 +00:00
|
|
|
}
|
2010-11-10 12:37:15 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
// Test demuxers with safe file checks
|
2010-11-10 12:37:15 +00: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 05:38:39 +00:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 12:37:15 +00:00
|
|
|
if (demuxer)
|
|
|
|
goto dmx_open;
|
2006-10-19 18:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-19 00:21:54 +00:00
|
|
|
|
2008-04-12 15:51:08 +00: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 14:24:17 +00:00
|
|
|
if (filename && opts->extension_parsing == 1) {
|
2010-11-10 12:37:15 +00: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 05:38:39 +00:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 12:37:15 +00:00
|
|
|
if (demuxer)
|
|
|
|
goto dmx_open;
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
2010-11-10 12:37:15 +00: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 05:38:39 +00:00
|
|
|
video_id, sub_id, filename, params);
|
2010-11-10 12:37:15 +00:00
|
|
|
if (demuxer)
|
|
|
|
goto dmx_open;
|
2006-10-19 18:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
2001-12-26 16:34:06 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2010-11-10 12:37:15 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
dmx_open:
|
|
|
|
|
2010-11-10 12:37:15 +00:00
|
|
|
if (demuxer->type == DEMUXER_TYPE_PLAYLIST)
|
|
|
|
return demuxer;
|
2008-04-12 15:51:08 +00:00
|
|
|
|
2010-11-10 12:37:15 +00:00
|
|
|
struct sh_video *sh_video = demuxer->video->sh;
|
|
|
|
if (sh_video && sh_video->bih) {
|
2008-04-12 15:51:08 +00:00
|
|
|
int biComp = le2me_32(sh_video->bih->biCompression);
|
|
|
|
mp_msg(MSGT_DEMUX, MSGL_INFO,
|
|
|
|
"VIDEO: [%.4s] %dx%d %dbpp %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
|
|
|
|
(char *) &biComp, sh_video->bih->biWidth,
|
|
|
|
sh_video->bih->biHeight, sh_video->bih->biBitCount,
|
|
|
|
sh_video->fps, sh_video->i_bps * 0.008f,
|
|
|
|
sh_video->i_bps / 1024.0f);
|
|
|
|
}
|
|
|
|
return demuxer;
|
2001-07-21 22:37:55 +00:00
|
|
|
}
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2011-08-04 05:38:39 +00: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)
|
|
|
|
{
|
|
|
|
return demux_open_withparams(opts, vs, file_format, audio_id, video_id,
|
|
|
|
sub_id, filename, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct demuxer *demux_open_withparams(struct MPOpts *opts, stream_t *vs,
|
|
|
|
int file_format, int audio_id, int video_id, int dvdsub_id,
|
|
|
|
char *filename, struct demuxer_params *params)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
|
|
|
stream_t *as = NULL, *ss = NULL;
|
|
|
|
demuxer_t *vd, *ad = NULL, *sd = NULL;
|
|
|
|
demuxer_t *res;
|
|
|
|
int afmt = DEMUXER_TYPE_UNKNOWN, sfmt = DEMUXER_TYPE_UNKNOWN;
|
|
|
|
int demuxer_type;
|
|
|
|
int audio_demuxer_type = 0, sub_demuxer_type = 0;
|
|
|
|
int demuxer_force = 0, audio_demuxer_force = 0, sub_demuxer_force = 0;
|
|
|
|
|
|
|
|
if ((demuxer_type =
|
2010-11-11 14:24:17 +00:00
|
|
|
get_demuxer_type_from_name(opts->demuxer_name, &demuxer_force)) < 0) {
|
2008-04-12 15:51:08 +00:00
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-demuxer %s does not exist.\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->demuxer_name);
|
2010-11-10 07:49:39 +00:00
|
|
|
return NULL;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((audio_demuxer_type =
|
2010-11-11 14:24:17 +00:00
|
|
|
get_demuxer_type_from_name(opts->audio_demuxer_name,
|
2008-04-12 15:51:08 +00:00
|
|
|
&audio_demuxer_force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-audio-demuxer %s does not exist.\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->audio_demuxer_name);
|
|
|
|
if (opts->audio_stream)
|
2010-11-10 07:49:39 +00:00
|
|
|
return NULL;
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((sub_demuxer_type =
|
2010-11-11 14:24:17 +00:00
|
|
|
get_demuxer_type_from_name(opts->sub_demuxer_name,
|
2008-04-12 15:51:08 +00:00
|
|
|
&sub_demuxer_force)) < 0) {
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR, "-sub-demuxer %s does not exist.\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->sub_demuxer_name);
|
|
|
|
if (opts->sub_stream)
|
2010-11-10 07:49:39 +00:00
|
|
|
return NULL;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
|
2010-11-11 14:24:17 +00:00
|
|
|
if (opts->audio_stream) {
|
|
|
|
as = open_stream(opts->audio_stream, 0, &afmt);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!as) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "Cannot open audio stream: %s\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->audio_stream);
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-11 14:24:17 +00:00
|
|
|
if (opts->audio_stream_cache) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!stream_enable_cache
|
2010-11-11 14:24:17 +00:00
|
|
|
(as, opts->audio_stream_cache * 1024,
|
|
|
|
opts->audio_stream_cache * 1024 *
|
2010-11-11 15:36:09 +00:00
|
|
|
(opts->stream_cache_min_percent / 100.0),
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->audio_stream_cache * 1024 *
|
2010-11-11 15:36:09 +00:00
|
|
|
(opts->stream_cache_seek_min_percent / 100.0))) {
|
2008-04-12 15:51:08 +00:00
|
|
|
free_stream(as);
|
|
|
|
mp_msg(MSGT_DEMUXER, MSGL_ERR,
|
|
|
|
"Can't enable audio stream cache\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2010-11-11 14:24:17 +00:00
|
|
|
if (opts->sub_stream) {
|
|
|
|
ss = open_stream(opts->sub_stream, 0, &sfmt);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!ss) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_ERR, "Cannot open subtitle stream: %s\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->sub_stream);
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 01:23:38 +00:00
|
|
|
vd = demux_open_stream(opts, vs, demuxer_type ? demuxer_type : file_format,
|
2010-11-11 14:24:17 +00:00
|
|
|
demuxer_force, opts->audio_stream ? -2 : audio_id,
|
2011-08-04 05:38:39 +00:00
|
|
|
video_id, opts->sub_stream ? -2 : dvdsub_id,
|
|
|
|
filename, params);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!vd) {
|
|
|
|
if (as)
|
|
|
|
free_stream(as);
|
|
|
|
if (ss)
|
|
|
|
free_stream(ss);
|
|
|
|
return NULL;
|
2003-03-27 20:38:14 +00:00
|
|
|
}
|
2008-04-12 15:51:08 +00:00
|
|
|
if (as) {
|
2008-04-16 01:23:38 +00:00
|
|
|
ad = demux_open_stream(opts, as,
|
2008-04-12 15:51:08 +00:00
|
|
|
audio_demuxer_type ? audio_demuxer_type : afmt,
|
|
|
|
audio_demuxer_force, audio_id, -2, -2,
|
2011-08-04 05:38:39 +00:00
|
|
|
opts->audio_stream, params);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!ad) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "Failed to open audio demuxer: %s\n",
|
2010-11-11 14:24:17 +00:00
|
|
|
opts->audio_stream);
|
2008-04-12 15:51:08 +00:00
|
|
|
free_stream(as);
|
|
|
|
} else if (ad->audio->sh
|
|
|
|
&& ((sh_audio_t *) ad->audio->sh)->format == 0x55) // MP3
|
2010-11-11 15:34:53 +00:00
|
|
|
opts->hr_mp3_seek = 1; // Enable high res seeking
|
2008-04-12 15:51:08 +00:00
|
|
|
}
|
|
|
|
if (ss) {
|
2008-04-16 01:23:38 +00:00
|
|
|
sd = demux_open_stream(opts, ss,
|
|
|
|
sub_demuxer_type ? sub_demuxer_type : sfmt,
|
2008-04-12 15:51:08 +00:00
|
|
|
sub_demuxer_force, -2, -2, dvdsub_id,
|
2011-08-04 05:38:39 +00:00
|
|
|
opts->sub_stream, params);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!sd) {
|
2009-07-05 23:41:23 +00:00
|
|
|
mp_tmsg(MSGT_DEMUXER, MSGL_WARN,
|
2010-11-11 14:24:17 +00:00
|
|
|
"Failed to open subtitle demuxer: %s\n", opts->sub_stream);
|
2008-04-12 15:51:08 +00:00
|
|
|
free_stream(ss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ad && sd)
|
|
|
|
res = new_demuxers_demuxer(vd, ad, sd);
|
|
|
|
else if (ad)
|
|
|
|
res = new_demuxers_demuxer(vd, ad, vd);
|
|
|
|
else if (sd)
|
|
|
|
res = new_demuxers_demuxer(vd, vd, sd);
|
|
|
|
else
|
|
|
|
res = vd;
|
|
|
|
|
2008-04-16 04:11:12 +00:00
|
|
|
opts->correct_pts = opts->user_correct_pts;
|
|
|
|
if (opts->correct_pts < 0)
|
|
|
|
opts->correct_pts =
|
2010-11-07 20:49:50 +00:00
|
|
|
demux_control(vd ? vd : res, DEMUXER_CTRL_CORRECT_PTS,
|
2008-04-12 15:51:08 +00:00
|
|
|
NULL) == DEMUXER_CTRL_OK;
|
|
|
|
return res;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-06-04 05:10:48 +00:00
|
|
|
void demux_flush(demuxer_t *demuxer)
|
|
|
|
{
|
2008-06-02 10:17:48 +00:00
|
|
|
ds_free_packs(demuxer->video);
|
|
|
|
ds_free_packs(demuxer->audio);
|
|
|
|
ds_free_packs(demuxer->sub);
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00: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-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n");
|
2008-07-30 12:01:30 +00:00
|
|
|
#ifdef CONFIG_TV
|
2008-04-12 15:51:08 +00:00
|
|
|
else if (demuxer->file_format == DEMUXER_TYPE_TV)
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "TV input is not seekable! (Seeking will probably be for changing channels ;)\n");
|
2001-11-09 23:46:06 +00:00
|
|
|
#endif
|
2008-04-12 15:51:08 +00:00
|
|
|
else
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in this file.\n");
|
2008-04-12 15:51:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-12 17:28:16 +00:00
|
|
|
// clear demux buffers:
|
2008-06-04 05:10:48 +00:00
|
|
|
demux_flush(demuxer);
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->video->eof = 0;
|
|
|
|
demuxer->audio->eof = 0;
|
2010-08-29 06:46:06 +00:00
|
|
|
demuxer->sub->eof = 0;
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2010-04-23 18:01:21 +00: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;
|
|
|
|
if (stream->type == STREAMTYPE_DVD || stream->type == STREAMTYPE_DVDNAV) {
|
|
|
|
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 22:54:28 +00:00
|
|
|
|
2010-04-23 18:01:21 +00: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 22:54:28 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
dmx_seek:
|
|
|
|
if (demuxer->desc->seek)
|
|
|
|
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
|
2001-08-12 17:28:16 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return 1;
|
2001-08-12 17:28:16 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 05:03:43 +00:00
|
|
|
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
|
2010-05-19 10:32:32 +00:00
|
|
|
{
|
2011-07-27 05:38:12 +00:00
|
|
|
return demux_info_add_bstr(demuxer, bstr(opt), bstr(param));
|
2010-05-19 10:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
|
2001-11-21 16:14:14 +00:00
|
|
|
{
|
2002-02-14 13:04:35 +00:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n = 0;
|
2001-11-21 16:14:14 +00:00
|
|
|
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (n = 0; info && info[2 * n] != NULL; n++) {
|
2011-07-27 05:38:12 +00:00
|
|
|
if (!bstrcasecmp(opt, bstr(info[2*n]))) {
|
|
|
|
if (!bstrcmp(param, bstr(info[2*n + 1]))) {
|
2010-05-19 10:32:32 +00: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 08:29:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-19 10:32:32 +00: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 15:51:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 10:32:32 +00: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 15:51:08 +00:00
|
|
|
memset(&info[2 * (n + 1)], 0, 2 * sizeof(char *));
|
2001-11-22 15:43:24 +00:00
|
|
|
|
2002-02-14 13:04:35 +00:00
|
|
|
return 1;
|
2001-11-21 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int demux_info_print(demuxer_t *demuxer)
|
|
|
|
{
|
2002-02-14 13:04:35 +00:00
|
|
|
char **info = demuxer->info;
|
|
|
|
int n;
|
2001-11-21 16:14:14 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (!info)
|
|
|
|
return 0;
|
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_DEMUX, MSGL_INFO, "Clip info:\n");
|
2008-04-12 15:51:08 +00: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-20 23:07:35 +00:00
|
|
|
}
|
2006-04-24 07:20:34 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n);
|
2002-01-16 03:25:07 +00:00
|
|
|
|
|
|
|
return 0;
|
2001-11-21 16:14:14 +00:00
|
|
|
}
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demux_info_get(demuxer_t *demuxer, const char *opt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char **info = demuxer->info;
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
for (i = 0; info && info[2 * i] != NULL; i++) {
|
|
|
|
if (!strcasecmp(opt, info[2 * i]))
|
|
|
|
return info[2 * i + 1];
|
|
|
|
}
|
2002-02-20 16:59:25 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return NULL;
|
2002-02-20 16:59:25 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demux_control(demuxer_t *demuxer, int cmd, void *arg)
|
|
|
|
{
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
if (demuxer->desc->control)
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->desc->control(demuxer, cmd, arg);
|
2005-08-05 19:57:47 +00:00
|
|
|
|
|
|
|
return DEMUXER_CTRL_NOTIMPL;
|
2002-11-16 03:42:14 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_switch_audio(demuxer_t *demuxer, int index)
|
|
|
|
{
|
2005-04-28 14:43:19 +00:00
|
|
|
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_AUDIO, &index);
|
2010-05-22 05:19:23 +00:00
|
|
|
if (res == DEMUXER_CTRL_NOTIMPL) {
|
|
|
|
struct sh_audio *sh_audio = demuxer->audio->sh;
|
|
|
|
return sh_audio ? sh_audio->aid : -2;
|
|
|
|
}
|
|
|
|
if (demuxer->audio->id >= 0) {
|
|
|
|
struct sh_audio *sh_audio = demuxer->a_streams[demuxer->audio->id];
|
|
|
|
demuxer->audio->sh = sh_audio;
|
|
|
|
index = sh_audio->aid; // internal MPEG demuxers don't set it right
|
|
|
|
}
|
2008-02-29 17:25:48 +00:00
|
|
|
else
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->audio->sh = NULL;
|
2005-04-28 14:43:19 +00:00
|
|
|
return index;
|
2005-04-03 14:08:28 +00:00
|
|
|
}
|
2006-08-06 18:55:34 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_switch_video(demuxer_t *demuxer, int index)
|
|
|
|
{
|
2006-11-16 21:23:06 +00:00
|
|
|
int res = demux_control(demuxer, DEMUXER_CTRL_SWITCH_VIDEO, &index);
|
2011-03-30 20:22:45 +00:00
|
|
|
if (res == DEMUXER_CTRL_NOTIMPL) {
|
|
|
|
struct sh_video *sh_video = demuxer->video->sh;
|
|
|
|
return sh_video ? sh_video->vid : -2;
|
|
|
|
}
|
|
|
|
if (demuxer->video->id >= 0) {
|
|
|
|
struct sh_video *sh_video = demuxer->v_streams[demuxer->video->id];
|
|
|
|
demuxer->video->sh = sh_video;
|
|
|
|
index = sh_video->vid; // internal MPEG demuxers don't set it right
|
|
|
|
} else
|
2008-04-12 15:51:08 +00:00
|
|
|
demuxer->video->sh = NULL;
|
2006-11-16 21:23:06 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2010-05-19 10:44:37 +00:00
|
|
|
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
|
|
|
|
struct bstr type, struct bstr data)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2010-01-26 01:31:31 +00: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 10:44:37 +00: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 01:12:36 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->num_attachments++;
|
2008-01-12 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 10:44:37 +00:00
|
|
|
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
|
2010-01-26 01:31:31 +00:00
|
|
|
uint64_t start, uint64_t end)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2010-01-26 01:31:31 +00:00
|
|
|
if (!(demuxer->num_chapters % 32))
|
|
|
|
demuxer->chapters = talloc_realloc(demuxer, demuxer->chapters,
|
|
|
|
struct demux_chapter,
|
|
|
|
demuxer->num_chapters + 32);
|
2006-08-06 18:55:34 +00:00
|
|
|
|
|
|
|
demuxer->chapters[demuxer->num_chapters].start = start;
|
|
|
|
demuxer->chapters[demuxer->num_chapters].end = end;
|
2010-05-19 10:44:37 +00:00
|
|
|
demuxer->chapters[demuxer->num_chapters].name = name.len ?
|
|
|
|
talloc_strndup(demuxer->chapters, name.start, name.len) :
|
2010-01-26 01:31:31 +00:00
|
|
|
talloc_strdup(demuxer->chapters, mp_gtext("unknown"));
|
2006-08-06 18:55:34 +00:00
|
|
|
|
2009-06-28 13:19:26 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_ID=%d\n", demuxer->num_chapters);
|
2011-01-23 22:29:01 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_START=%"PRIu64"\n", demuxer->num_chapters, start / 1000000);
|
2009-06-28 13:19:26 +00:00
|
|
|
if (end)
|
2011-01-23 22:29:01 +00:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_END=%"PRIu64"\n", demuxer->num_chapters, end / 1000000);
|
2010-05-19 10:44:37 +00:00
|
|
|
if (name.start)
|
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CHAPTER_%d_NAME=%.*s\n", demuxer->num_chapters, BSTR_P(name));
|
2009-06-28 13:19:26 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return demuxer->num_chapters++;
|
2006-08-06 18:55:34 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 16:48:22 +00:00
|
|
|
/**
|
2008-04-12 15:51:08 +00:00
|
|
|
* \brief demuxer_seek_chapter() seeks to a chapter in two possible ways:
|
2006-08-18 16:48:22 +00:00
|
|
|
* either using the demuxer->chapters structure set by the demuxer
|
|
|
|
* or asking help to the stream layer (e.g. dvd)
|
2006-08-18 19:03:59 +00:00
|
|
|
* \param chapter - chapter number wished - 0-based
|
2006-08-18 16:48:22 +00:00
|
|
|
* \param seek_pts set by the function to the pts to seek to (if demuxer->chapters is set)
|
2006-08-21 19:19:00 +00:00
|
|
|
* \param chapter_name name of chapter found (set by this function is param is not null)
|
2006-08-18 16:48:22 +00:00
|
|
|
* \return -1 on error, current chapter if successful
|
|
|
|
*/
|
|
|
|
|
2009-04-01 16:55:26 +00:00
|
|
|
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
|
2008-04-12 15:51:08 +00:00
|
|
|
char **chapter_name)
|
|
|
|
{
|
2006-08-18 16:48:22 +00:00
|
|
|
int ris;
|
|
|
|
|
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
2008-06-02 10:17:48 +00:00
|
|
|
demux_flush(demuxer);
|
2006-08-18 16:48:22 +00:00
|
|
|
|
2008-06-16 12:54:28 +00:00
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER,
|
|
|
|
&chapter);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris != STREAM_UNSUPPORTED)
|
2006-11-11 11:53:32 +00:00
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
2006-08-18 16:48:22 +00:00
|
|
|
|
2008-06-16 12:54:28 +00:00
|
|
|
// exit status may be ok, but main() doesn't have to seek itself
|
2008-04-12 15:51:08 +00:00
|
|
|
// (because e.g. dvds depend on sectors, not on pts)
|
2006-08-18 16:48:22 +00:00
|
|
|
*seek_pts = -1.0;
|
2006-08-21 19:19:00 +00:00
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
if (chapter_name) {
|
2006-08-21 19:19:00 +00:00
|
|
|
*chapter_name = NULL;
|
2009-04-01 16:55:26 +00:00
|
|
|
int num_chapters;
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_CHAPTERS,
|
|
|
|
&num_chapters) == STREAM_UNSUPPORTED)
|
|
|
|
num_chapters = 0;
|
|
|
|
if (num_chapters) {
|
|
|
|
*chapter_name = talloc_size(NULL, 16);
|
|
|
|
sprintf(*chapter_name, " of %3d", num_chapters);
|
2006-08-21 19:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
return ris != STREAM_UNSUPPORTED ? chapter : -1;
|
|
|
|
} else { // chapters structure is set in the demuxer
|
2009-04-01 16:55:26 +00:00
|
|
|
if (chapter >= demuxer->num_chapters)
|
2008-04-12 15:51:08 +00:00
|
|
|
return -1;
|
2009-04-01 16:55:26 +00:00
|
|
|
if (chapter < 0)
|
|
|
|
chapter = 0;
|
2006-08-18 16:48:22 +00:00
|
|
|
|
2011-01-23 22:29:01 +00:00
|
|
|
*seek_pts = demuxer->chapters[chapter].start / 1e9;
|
2006-08-18 16:48:22 +00:00
|
|
|
|
2009-04-01 16:55:26 +00:00
|
|
|
if (chapter_name)
|
|
|
|
*chapter_name = talloc_strdup(NULL, demuxer->chapters[chapter].name);
|
2006-08-21 19:19:00 +00:00
|
|
|
|
2009-04-01 16:55:26 +00:00
|
|
|
return chapter;
|
2006-08-18 16:48:22 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-13 12:51:05 +00:00
|
|
|
|
2010-11-13 13:48:26 +00:00
|
|
|
int demuxer_get_current_chapter(demuxer_t *demuxer, double time_now)
|
2008-04-12 15:51:08 +00:00
|
|
|
{
|
2010-04-24 17:46:54 +00:00
|
|
|
int chapter = -2;
|
2007-12-13 12:51:05 +00:00
|
|
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
|
|
|
if (stream_control(demuxer->stream, STREAM_CTRL_GET_CURRENT_CHAPTER,
|
|
|
|
&chapter) == STREAM_UNSUPPORTED)
|
2010-04-24 17:46:54 +00:00
|
|
|
chapter = -2;
|
2008-04-12 15:51:08 +00:00
|
|
|
} else {
|
2011-01-23 22:29:01 +00:00
|
|
|
uint64_t now = time_now * 1e9 + 0.5;
|
2007-12-13 12:51:05 +00:00
|
|
|
for (chapter = demuxer->num_chapters - 1; chapter >= 0; --chapter) {
|
|
|
|
if (demuxer->chapters[chapter].start <= now)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chapter;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demuxer_chapter_name(demuxer_t *demuxer, int chapter)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters) {
|
2008-04-12 15:51:08 +00:00
|
|
|
if (chapter >= 0 && chapter < demuxer->num_chapters
|
|
|
|
&& demuxer->chapters[chapter].name)
|
2007-12-13 12:51:05 +00:00
|
|
|
return strdup(demuxer->chapters[chapter].name);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
char *chapter_name = demuxer_chapter_name(demuxer, chapter);
|
|
|
|
if (chapter_name) {
|
2011-07-03 17:04:21 +00:00
|
|
|
char *tmp = talloc_asprintf(NULL, "(%d) %s", chapter + 1, chapter_name);
|
2008-04-12 15:51:08 +00:00
|
|
|
free(chapter_name);
|
2007-12-13 12:51:05 +00:00
|
|
|
return tmp;
|
2008-04-12 15:51:08 +00:00
|
|
|
} else {
|
2007-12-13 12:51:05 +00:00
|
|
|
int chapter_num = demuxer_chapter_count(demuxer);
|
|
|
|
if (chapter_num <= 0)
|
2011-07-03 17:04:21 +00:00
|
|
|
return talloc_asprintf(NULL, "(%d)", chapter + 1);
|
2007-12-13 12:51:05 +00:00
|
|
|
else
|
2011-07-03 17:04:21 +00:00
|
|
|
return talloc_asprintf(NULL, "(%d) of %d", chapter + 1,
|
|
|
|
chapter_num);
|
2007-12-13 12:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end)
|
|
|
|
{
|
2007-12-13 12:51:05 +00:00
|
|
|
if (demuxer->num_chapters && demuxer->chapters && chapter >= 0
|
2008-04-12 15:51:08 +00:00
|
|
|
&& chapter < demuxer->num_chapters) {
|
2007-12-13 12:51:05 +00:00
|
|
|
if (end)
|
2011-01-23 22:29:01 +00:00
|
|
|
*end = demuxer->chapters[chapter].end / 1e9;
|
|
|
|
return demuxer->chapters[chapter].start / 1e9;
|
2007-12-13 12:51:05 +00:00
|
|
|
}
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_chapter_count(demuxer_t *demuxer)
|
|
|
|
{
|
2007-12-13 12:51:05 +00: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 15:51:08 +00:00
|
|
|
} else
|
2007-12-13 12:51:05 +00:00
|
|
|
return demuxer->num_chapters;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_angles_count(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_NUM_ANGLES, &angles);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
return angles;
|
|
|
|
}
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_get_current_angle(demuxer_t *demuxer)
|
|
|
|
{
|
|
|
|
int ris, curr_angle = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_GET_ANGLE, &curr_angle);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
return curr_angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-12 15:51:08 +00:00
|
|
|
int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
|
|
|
{
|
|
|
|
int ris, angles = -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
angles = demuxer_angles_count(demuxer);
|
2008-04-12 15:51:08 +00:00
|
|
|
if ((angles < 1) || (angle > angles))
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
2008-06-02 10:17:48 +00:00
|
|
|
demux_flush(demuxer);
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
ris = stream_control(demuxer->stream, STREAM_CTRL_SET_ANGLE, &angle);
|
2008-04-12 15:51:08 +00:00
|
|
|
if (ris == STREAM_UNSUPPORTED)
|
|
|
|
return -1;
|
2008-01-05 14:28:57 +00:00
|
|
|
|
|
|
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
2008-02-29 17:25:43 +00:00
|
|
|
|
2011-02-18 14:32:40 +00:00
|
|
|
int demuxer_audio_track_by_lang_and_default(struct demuxer *d, char **langt)
|
2008-02-29 17:25:43 +00:00
|
|
|
{
|
2011-02-18 14:32:40 +00:00
|
|
|
int n = 0;
|
2010-11-08 11:05:49 +00:00
|
|
|
while (1) {
|
2011-02-18 14:32:40 +00:00
|
|
|
char *lang = langt ? langt[n++] : NULL;
|
2010-11-08 11:05:49 +00:00
|
|
|
int id = -1;
|
|
|
|
for (int i = 0; i < MAX_A_STREAMS; i++) {
|
|
|
|
struct sh_audio *sh = d->a_streams[i];
|
2011-02-18 14:32:40 +00:00
|
|
|
if (sh && (!lang || sh->lang && !strcmp(lang, sh->lang))) {
|
2010-11-08 11:05:49 +00:00
|
|
|
if (sh->default_track)
|
|
|
|
return sh->aid;
|
|
|
|
if (id < 0)
|
|
|
|
id = sh->aid;
|
|
|
|
}
|
2008-02-29 17:25:43 +00:00
|
|
|
}
|
2010-11-08 11:05:49 +00:00
|
|
|
if (id >= 0)
|
|
|
|
return id;
|
2011-02-18 14:32:40 +00:00
|
|
|
if (!lang)
|
2010-11-08 11:05:49 +00:00
|
|
|
return -1;
|
2008-02-29 17:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-18 14:32:40 +00:00
|
|
|
int demuxer_sub_track_by_lang_and_default(struct demuxer *d, char **langt)
|
2008-02-29 17:25:43 +00:00
|
|
|
{
|
2011-02-18 14:32:40 +00:00
|
|
|
int n = 0;
|
2010-11-08 11:05:49 +00:00
|
|
|
while (1) {
|
2011-02-18 14:32:40 +00:00
|
|
|
char *lang = langt ? langt[n++] : NULL;
|
2010-11-08 11:05:49 +00:00
|
|
|
int id = -1;
|
2010-11-16 08:41:16 +00:00
|
|
|
for (int i = 0; i < MAX_S_STREAMS; i++) {
|
|
|
|
struct sh_sub *sh = d->s_streams[i];
|
2011-02-18 14:32:40 +00:00
|
|
|
if (sh && (!lang || sh->lang && !strcmp(lang, sh->lang))) {
|
2010-11-08 11:05:49 +00:00
|
|
|
if (sh->default_track)
|
2010-11-16 08:41:16 +00:00
|
|
|
return sh->sid;
|
2010-11-08 11:05:49 +00:00
|
|
|
if (id < 0)
|
2010-11-16 08:41:16 +00:00
|
|
|
id = sh->sid;
|
2010-11-08 11:05:49 +00:00
|
|
|
}
|
2008-02-29 17:25:43 +00:00
|
|
|
}
|
2011-02-18 14:32:40 +00:00
|
|
|
if (!lang)
|
2010-11-08 11:05:49 +00:00
|
|
|
return -1;
|
|
|
|
if (id >= 0)
|
|
|
|
return id;
|
2008-03-30 16:55:46 +00:00
|
|
|
}
|
|
|
|
}
|