2009-05-08 23:51:13 +02:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 10:09:46 +01:00
|
|
|
#ifndef MPLAYER_DEMUXER_H
|
|
|
|
#define MPLAYER_DEMUXER_H
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2008-06-17 11:09:36 +02:00
|
|
|
#include <sys/types.h>
|
2008-03-06 00:32:01 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-16 22:30:48 +01:00
|
|
|
#include <stdbool.h>
|
2008-03-06 00:32:01 +01:00
|
|
|
|
2010-05-19 12:32:32 +02:00
|
|
|
#include "bstr.h"
|
2011-01-12 14:29:31 +01:00
|
|
|
#include "mpcommon.h"
|
2006-07-07 20:26:51 +02:00
|
|
|
|
2008-04-16 03:23:38 +02:00
|
|
|
struct MPOpts;
|
|
|
|
|
2008-10-16 20:26:01 +02:00
|
|
|
#ifdef HAVE_BUILTIN_EXPECT
|
2011-02-10 11:05:26 +01:00
|
|
|
#define likely(x) __builtin_expect((x) != 0, 1)
|
|
|
|
#define unlikely(x) __builtin_expect((x) != 0, 0)
|
2008-10-16 20:26:01 +02:00
|
|
|
#else
|
|
|
|
#define likely(x) (x)
|
|
|
|
#define unlikely(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 22:43:12 +02:00
|
|
|
#define MAX_PACKS 4096
|
2008-10-04 06:52:27 +02:00
|
|
|
#define MAX_PACK_BYTES 0x8000000 // 128 MiB
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-11 18:52:44 +01:00
|
|
|
enum demuxer_type {
|
|
|
|
DEMUXER_TYPE_UNKNOWN = 0,
|
|
|
|
DEMUXER_TYPE_MPEG_ES,
|
|
|
|
DEMUXER_TYPE_MPEG_PS,
|
|
|
|
DEMUXER_TYPE_AVI,
|
|
|
|
DEMUXER_TYPE_AVI_NI,
|
|
|
|
DEMUXER_TYPE_AVI_NINI,
|
|
|
|
DEMUXER_TYPE_ASF,
|
|
|
|
DEMUXER_TYPE_MOV,
|
|
|
|
DEMUXER_TYPE_VIVO,
|
|
|
|
DEMUXER_TYPE_TV,
|
|
|
|
DEMUXER_TYPE_FLI,
|
|
|
|
DEMUXER_TYPE_REAL,
|
|
|
|
DEMUXER_TYPE_Y4M,
|
|
|
|
DEMUXER_TYPE_FILM,
|
|
|
|
DEMUXER_TYPE_ROQ,
|
|
|
|
DEMUXER_TYPE_MF,
|
|
|
|
DEMUXER_TYPE_AUDIO,
|
|
|
|
DEMUXER_TYPE_OGG,
|
|
|
|
DEMUXER_TYPE_RAWAUDIO,
|
|
|
|
DEMUXER_TYPE_RTP,
|
|
|
|
DEMUXER_TYPE_RAWDV,
|
|
|
|
DEMUXER_TYPE_PVA,
|
|
|
|
DEMUXER_TYPE_SMJPEG,
|
|
|
|
DEMUXER_TYPE_XMMS,
|
|
|
|
DEMUXER_TYPE_RAWVIDEO,
|
|
|
|
DEMUXER_TYPE_MPEG4_ES,
|
|
|
|
DEMUXER_TYPE_GIF,
|
|
|
|
DEMUXER_TYPE_MPEG_TS,
|
|
|
|
DEMUXER_TYPE_H264_ES,
|
|
|
|
DEMUXER_TYPE_MATROSKA,
|
|
|
|
DEMUXER_TYPE_REALAUDIO,
|
|
|
|
DEMUXER_TYPE_MPEG_TY,
|
|
|
|
DEMUXER_TYPE_LMLM4,
|
|
|
|
DEMUXER_TYPE_LAVF,
|
|
|
|
DEMUXER_TYPE_NSV,
|
|
|
|
DEMUXER_TYPE_VQF,
|
|
|
|
DEMUXER_TYPE_AVS,
|
|
|
|
DEMUXER_TYPE_AAC,
|
|
|
|
DEMUXER_TYPE_MPC,
|
|
|
|
DEMUXER_TYPE_MPEG_PES,
|
|
|
|
DEMUXER_TYPE_MPEG_GXF,
|
|
|
|
DEMUXER_TYPE_NUT,
|
|
|
|
DEMUXER_TYPE_LAVF_PREFERRED,
|
|
|
|
DEMUXER_TYPE_RTP_NEMESI,
|
|
|
|
DEMUXER_TYPE_MNG,
|
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_TYPE_EDL,
|
2002-09-13 20:58:14 +02:00
|
|
|
|
2011-02-11 18:52:44 +01:00
|
|
|
/* Values after this are for internal use and can not be selected
|
|
|
|
* as demuxer type by the user (-demuxer option). */
|
|
|
|
DEMUXER_TYPE_END,
|
2002-02-20 17:59:25 +01:00
|
|
|
|
2011-02-11 18:52:44 +01:00
|
|
|
DEMUXER_TYPE_DEMUXERS,
|
|
|
|
DEMUXER_TYPE_PLAYLIST,
|
|
|
|
};
|
2002-02-21 14:14:52 +01:00
|
|
|
|
2010-11-14 10:53:27 +01:00
|
|
|
enum timestamp_type {
|
|
|
|
TIMESTAMP_TYPE_PTS,
|
|
|
|
TIMESTAMP_TYPE_SORT,
|
|
|
|
};
|
|
|
|
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2002-11-16 04:42:14 +01:00
|
|
|
// DEMUXER control commands/answers
|
|
|
|
#define DEMUXER_CTRL_NOTIMPL -1
|
|
|
|
#define DEMUXER_CTRL_DONTKNOW 0
|
|
|
|
#define DEMUXER_CTRL_OK 1
|
|
|
|
#define DEMUXER_CTRL_GUESS 2
|
|
|
|
#define DEMUXER_CTRL_GET_TIME_LENGTH 10
|
|
|
|
#define DEMUXER_CTRL_GET_PERCENT_POS 11
|
2005-04-03 16:08:28 +02:00
|
|
|
#define DEMUXER_CTRL_SWITCH_AUDIO 12
|
2006-11-07 23:51:18 +01:00
|
|
|
#define DEMUXER_CTRL_RESYNC 13
|
2006-11-16 22:23:06 +01:00
|
|
|
#define DEMUXER_CTRL_SWITCH_VIDEO 14
|
2006-11-18 15:31:31 +01:00
|
|
|
#define DEMUXER_CTRL_IDENTIFY_PROGRAM 15
|
2008-02-03 13:14:29 +01:00
|
|
|
#define DEMUXER_CTRL_CORRECT_PTS 16
|
2002-11-16 04:42:14 +01:00
|
|
|
|
2008-01-29 16:11:38 +01:00
|
|
|
#define SEEK_ABSOLUTE (1 << 0)
|
|
|
|
#define SEEK_FACTOR (1 << 1)
|
2009-03-19 04:25:12 +01:00
|
|
|
#define SEEK_FORWARD (1 << 2)
|
|
|
|
#define SEEK_BACKWARD (1 << 3)
|
2008-01-29 16:11:38 +01:00
|
|
|
|
2011-08-19 03:59:01 +02:00
|
|
|
// demux_lavf can pass lavf buffers using FF_INPUT_BUFFER_PADDING_SIZE instead
|
|
|
|
#define MP_INPUT_BUFFER_PADDING_SIZE 8
|
2008-07-16 18:18:25 +02:00
|
|
|
|
2001-08-01 01:18:16 +02:00
|
|
|
// Holds one packet/frame/whatever
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demux_packet {
|
2011-02-10 11:05:26 +01:00
|
|
|
int len;
|
|
|
|
double pts;
|
|
|
|
double duration;
|
|
|
|
double stream_pts;
|
|
|
|
off_t pos; // position in index (AVI) or file (MPG)
|
|
|
|
unsigned char *buffer;
|
|
|
|
int flags; // keyframe, etc
|
|
|
|
int refcount; // counter for the master packet, if 0, buffer can be free()d
|
|
|
|
struct demux_packet *master; //in clones, pointer to the master packet
|
|
|
|
struct demux_packet *next;
|
2011-08-19 03:59:01 +02:00
|
|
|
struct AVPacket *avpacket; // original libavformat packet (demux_lavf)
|
2001-04-23 18:12:21 +02:00
|
|
|
} demux_packet_t;
|
|
|
|
|
2008-04-23 08:49:25 +02:00
|
|
|
typedef struct demux_stream {
|
2011-02-10 11:05:26 +01:00
|
|
|
int buffer_pos; // current buffer position
|
|
|
|
int buffer_size; // current buffer size
|
|
|
|
unsigned char *buffer; // current buffer, never free() it, always use free_demux_packet(buffer_ref);
|
|
|
|
double pts; // current buffer's pts
|
|
|
|
int pts_bytes; // number of bytes read after last pts stamp
|
|
|
|
int eof; // end of demuxed stream? (true if all buffer empty)
|
|
|
|
off_t pos; // position in the input stream (file)
|
|
|
|
off_t dpos; // position in the demuxed stream
|
|
|
|
int pack_no; // serial number of packet
|
|
|
|
int flags; // flags of current packet (keyframe etc)
|
|
|
|
int non_interleaved; // 1 if this stream is not properly interleaved,
|
2009-11-01 10:48:34 +01:00
|
|
|
// so e.g. subtitle handling must do explicit reads.
|
2001-04-23 18:12:21 +02:00
|
|
|
//---------------
|
2011-02-10 11:05:26 +01:00
|
|
|
int packs; // number of packets in buffer
|
|
|
|
int bytes; // total bytes of packets in buffer
|
|
|
|
demux_packet_t *first; // read to current buffer from here
|
|
|
|
demux_packet_t *last; // append new packets from input stream to here
|
|
|
|
demux_packet_t *current; // needed for refcounting of the buffer
|
|
|
|
int id; // stream ID (for multiple audio/video streams)
|
|
|
|
struct demuxer *demuxer; // parent demuxer structure (stream handler)
|
2001-04-23 18:12:21 +02:00
|
|
|
// ---- asf -----
|
2011-02-10 11:05:26 +01:00
|
|
|
struct demux_packet *asf_packet; // read asf fragments here
|
|
|
|
int asf_seq;
|
2001-10-23 15:55:49 +02:00
|
|
|
// ---- mov -----
|
2011-02-10 11:05:26 +01:00
|
|
|
unsigned int ss_mul, ss_div;
|
2001-04-23 18:12:21 +02:00
|
|
|
// ---- stream header ----
|
2011-02-10 11:05:26 +01:00
|
|
|
void *sh;
|
2001-04-23 18:12:21 +02:00
|
|
|
} demux_stream_t;
|
|
|
|
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demuxer_info {
|
2011-02-10 11:05:26 +01:00
|
|
|
char *name;
|
|
|
|
char *author;
|
|
|
|
char *encoder;
|
|
|
|
char *comments;
|
|
|
|
char *copyright;
|
2001-11-21 17:14:14 +01:00
|
|
|
} demuxer_info_t;
|
|
|
|
|
2002-02-10 19:09:20 +01:00
|
|
|
#define MAX_A_STREAMS 256
|
|
|
|
#define MAX_V_STREAMS 256
|
2009-01-28 01:44:48 +01:00
|
|
|
#define MAX_S_STREAMS 256
|
2002-02-10 19:09:20 +01:00
|
|
|
|
2008-04-24 04:49:44 +02:00
|
|
|
struct demuxer;
|
2005-08-05 21:57:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Demuxer description structure
|
|
|
|
*/
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demuxer_desc {
|
2011-02-10 11:05:26 +01:00
|
|
|
const char *info; // What is it (long name and/or description)
|
|
|
|
const char *name; // Demuxer name, used with -demuxer switch
|
|
|
|
const char *shortdesc; // Description printed at demuxer detection
|
|
|
|
const char *author; // Demuxer author(s)
|
|
|
|
const char *comment; // Comment, printed with -demuxer help
|
|
|
|
|
2011-02-11 18:52:44 +01:00
|
|
|
enum demuxer_type type;
|
2011-02-10 11:05:26 +01:00
|
|
|
// If 1 detection is safe and fast, do it before file extension check
|
|
|
|
int safe_check;
|
|
|
|
|
|
|
|
// Check if can demux the file, return DEMUXER_TYPE_xxx on success
|
|
|
|
// Mandatory if safe_check == 1, else optional
|
|
|
|
int (*check_file)(struct demuxer *demuxer);
|
|
|
|
/// Get packets from file, return 0 on eof. Mandatory
|
|
|
|
int (*fill_buffer)(struct demuxer *demuxer, struct demux_stream *ds);
|
|
|
|
/// Open the demuxer, return demuxer on success, NULL on failure
|
|
|
|
struct demuxer *(*open)(struct demuxer *demuxer); // Optional
|
|
|
|
/// Close the demuxer
|
|
|
|
void (*close)(struct demuxer *demuxer); // Optional
|
|
|
|
// Seek. Optional
|
|
|
|
void (*seek)(struct demuxer *demuxer, float rel_seek_secs,
|
|
|
|
float audio_delay, int flags);
|
|
|
|
// Various control functions. Optional
|
|
|
|
int (*control)(struct demuxer *demuxer, int cmd, void *arg);
|
2005-08-05 21:57:47 +02:00
|
|
|
} demuxer_desc_t;
|
|
|
|
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demux_chapter
|
2006-08-06 20:55:34 +02:00
|
|
|
{
|
2011-02-10 11:05:26 +01:00
|
|
|
uint64_t start, end;
|
|
|
|
char *name;
|
2006-08-06 20:55:34 +02:00
|
|
|
} demux_chapter_t;
|
|
|
|
|
2009-03-16 22:30:48 +01:00
|
|
|
struct matroska_data {
|
|
|
|
unsigned char segment_uid[16];
|
|
|
|
// Ordered chapter information if any
|
|
|
|
struct matroska_chapter {
|
|
|
|
uint64_t start;
|
|
|
|
uint64_t end;
|
|
|
|
bool has_segment_uid;
|
|
|
|
unsigned char segment_uid[16];
|
2009-04-02 04:00:22 +02:00
|
|
|
char *name;
|
2009-03-16 22:30:48 +01:00
|
|
|
} *ordered_chapters;
|
|
|
|
int num_ordered_chapters;
|
|
|
|
};
|
|
|
|
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demux_attachment
|
2008-01-12 02:12:36 +01:00
|
|
|
{
|
2011-02-10 11:05:26 +01:00
|
|
|
char *name;
|
|
|
|
char *type;
|
|
|
|
void *data;
|
|
|
|
unsigned int data_size;
|
2008-01-12 02:12:36 +01:00
|
|
|
} demux_attachment_t;
|
|
|
|
|
2011-08-04 07:38:39 +02:00
|
|
|
struct demuxer_params {
|
|
|
|
unsigned char (*matroska_wanted_uids)[16];
|
|
|
|
};
|
|
|
|
|
2008-04-24 04:49:44 +02:00
|
|
|
typedef struct demuxer {
|
2011-02-10 11:05:26 +01:00
|
|
|
const demuxer_desc_t *desc; ///< Demuxer description structure
|
2011-05-04 22:12:55 +02:00
|
|
|
const char *filetype; // format name when not identified by demuxer (libavformat)
|
2011-02-10 11:05:26 +01:00
|
|
|
off_t filepos; // input stream current pos.
|
|
|
|
off_t movi_start;
|
|
|
|
off_t movi_end;
|
|
|
|
struct stream *stream;
|
|
|
|
double stream_pts; // current stream pts, if applicable (e.g. dvd)
|
|
|
|
double reference_clock;
|
|
|
|
char *filename; // Needed by avs_check_file
|
|
|
|
int synced; // stream synced (used by mpeg)
|
2011-02-11 18:52:44 +01:00
|
|
|
enum demuxer_type type;
|
2011-02-10 11:05:26 +01:00
|
|
|
/* Normally the file_format field is just a copy of the type field above.
|
|
|
|
* There are 2 exceptions I noticed. Internal demux_avi may force
|
|
|
|
* ->type to DEMUXER_TYPE_AVI_[NI|NINI] while leaving ->file_format at
|
|
|
|
* DEMUXER_TYPE_AVI. Internal demux_mov may set ->type to
|
|
|
|
* DEMUXER_TYPE_PLAYLIST and also return that from the check function
|
|
|
|
* or not (looks potentially buggy). */
|
2011-02-11 18:52:44 +01:00
|
|
|
enum demuxer_type file_format;
|
2011-02-10 11:05:26 +01:00
|
|
|
int seekable; // flag
|
2009-03-19 04:25:12 +01:00
|
|
|
/* Set if using absolute seeks for small movements is OK (no pts resets
|
|
|
|
* that would make pts ambigious, preferably supports back/forward flags */
|
|
|
|
bool accurate_seek;
|
2010-11-14 10:53:27 +01:00
|
|
|
enum timestamp_type timestamp_type;
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
struct demux_stream *audio; // audio buffer/demuxer
|
|
|
|
struct demux_stream *video; // video buffer/demuxer
|
|
|
|
struct demux_stream *sub; // dvd subtitle buffer/demuxer
|
2006-08-06 20:55:34 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
// stream headers:
|
|
|
|
struct sh_audio *a_streams[MAX_A_STREAMS];
|
|
|
|
struct sh_video *v_streams[MAX_V_STREAMS];
|
|
|
|
struct sh_sub *s_streams[MAX_S_STREAMS];
|
2009-11-07 13:31:05 +01:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
// teletext decoder private data, if demuxer stream contains teletext
|
|
|
|
void *teletext;
|
2009-03-16 22:30:48 +01:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
struct demux_chapter *chapters;
|
|
|
|
int num_chapters;
|
|
|
|
|
|
|
|
struct demux_attachment *attachments;
|
|
|
|
int num_attachments;
|
2008-01-12 02:12:36 +01:00
|
|
|
|
2009-03-16 22:30:48 +01:00
|
|
|
struct matroska_data matroska_data;
|
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
|
|
|
// for trivial demuxers which just read the whole file for codec to use
|
|
|
|
struct bstr file_contents;
|
2009-03-16 22:30:48 +01:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
void *priv; // demuxer-specific internal data
|
|
|
|
char **info; // metadata
|
|
|
|
struct MPOpts *opts;
|
2011-08-04 07:38:39 +02:00
|
|
|
struct demuxer_params *params;
|
2001-04-23 18:12:21 +02:00
|
|
|
} demuxer_t;
|
|
|
|
|
2006-11-18 15:31:31 +01:00
|
|
|
typedef struct {
|
2011-02-10 11:05:26 +01:00
|
|
|
int progid; //program id
|
|
|
|
int aid, vid, sid; //audio, video and subtitle id
|
2006-11-18 15:31:31 +01:00
|
|
|
} demux_program_t;
|
|
|
|
|
2011-01-17 15:16:39 +01:00
|
|
|
struct demux_packet *new_demux_packet(size_t len);
|
2011-08-19 03:59:01 +02:00
|
|
|
// data must already have suitable padding
|
|
|
|
struct demux_packet *new_demux_packet_fromdata(void *data, size_t len);
|
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
|
|
|
struct demux_packet *clone_demux_packet(struct demux_packet *pack);
|
|
|
|
void free_demux_packet(struct demux_packet *dp);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2006-06-05 00:41:27 +02:00
|
|
|
#ifndef SIZE_MAX
|
|
|
|
#define SIZE_MAX ((size_t)-1)
|
|
|
|
#endif
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
static inline void *realloc_struct(void *ptr, size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
if (nmemb > SIZE_MAX / size) {
|
|
|
|
free(ptr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return realloc(ptr, nmemb * size);
|
2006-06-05 00:41:27 +02:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
struct demuxer *new_demuxer(struct MPOpts *opts, struct stream *stream,
|
|
|
|
int type, int a_id, int v_id, int s_id,
|
|
|
|
char *filename);
|
|
|
|
void free_demuxer(struct demuxer *demuxer);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
void ds_add_packet(struct demux_stream *ds, struct demux_packet *dp);
|
|
|
|
void ds_read_packet(struct demux_stream *ds, struct stream *stream, int len,
|
|
|
|
double pts, off_t pos, int flags);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds);
|
|
|
|
int ds_fill_buffer(struct demux_stream *ds);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
static inline off_t ds_tell(struct demux_stream *ds)
|
|
|
|
{
|
|
|
|
return (ds->dpos - ds->buffer_size) + ds->buffer_pos;
|
2001-04-23 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
static inline int ds_tell_pts(struct demux_stream *ds)
|
|
|
|
{
|
|
|
|
return (ds->pts_bytes - ds->buffer_size) + ds->buffer_pos;
|
2001-05-10 05:39:54 +02:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demux_read_data(struct demux_stream *ds, unsigned char *mem, int len);
|
|
|
|
int demux_pattern_3(struct demux_stream *ds, unsigned char *mem, int maxlen,
|
2006-01-17 21:04:49 +01:00
|
|
|
int *read, uint32_t pattern);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
#define demux_peekc(ds) ( \
|
|
|
|
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos] \
|
|
|
|
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos]))
|
|
|
|
#define demux_getc(ds) ( \
|
|
|
|
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos++] \
|
|
|
|
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos++]))
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
void ds_free_packs(struct demux_stream *ds);
|
|
|
|
int ds_get_packet(struct demux_stream *ds, unsigned char **start);
|
|
|
|
int ds_get_packet_pts(struct demux_stream *ds, unsigned char **start,
|
|
|
|
double *pts);
|
|
|
|
int ds_get_packet_sub(struct demux_stream *ds, unsigned char **start);
|
|
|
|
double ds_get_next_pts(struct demux_stream *ds);
|
|
|
|
int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts,
|
|
|
|
off_t pos);
|
|
|
|
void ds_clear_parser(struct demux_stream *sh);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
static inline int avi_stream_id(unsigned int id)
|
|
|
|
{
|
|
|
|
unsigned char a, b;
|
|
|
|
a = id - '0';
|
|
|
|
b = (id >> 8) - '0';
|
|
|
|
if (a>9 || b>9)
|
|
|
|
return 100; // invalid ID
|
|
|
|
return a * 10 + b;
|
2001-04-23 18:12:21 +02:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream,
|
|
|
|
int file_format, int aid, int vid, int sid,
|
|
|
|
char *filename);
|
2011-08-04 07:38:39 +02:00
|
|
|
|
|
|
|
struct demuxer *demux_open_withparams(struct MPOpts *opts,
|
|
|
|
struct stream *stream, int file_format, int aid, int vid, int sid,
|
|
|
|
char *filename, struct demuxer_params *params);
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
void demux_flush(struct demuxer *demuxer);
|
|
|
|
int demux_seek(struct demuxer *demuxer, float rel_seek_secs, float audio_delay,
|
|
|
|
int flags);
|
|
|
|
struct demuxer *new_demuxers_demuxer(struct demuxer *vd, struct demuxer *ad,
|
|
|
|
struct demuxer *sd);
|
2001-04-23 18:12:21 +02:00
|
|
|
|
2001-10-30 18:03:11 +01:00
|
|
|
// AVI demuxer params:
|
2011-06-10 10:31:00 +02:00
|
|
|
extern int index_mode; // -1=untouched 0=don't use index 1=use (generate) index
|
2003-10-22 21:01:37 +02:00
|
|
|
extern char *index_file_save, *index_file_load;
|
2001-10-30 18:03:11 +01:00
|
|
|
extern int force_ni;
|
|
|
|
extern int pts_from_bps;
|
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demux_info_add(struct demuxer *demuxer, const char *opt, const char *param);
|
|
|
|
int demux_info_add_bstr(struct demuxer *demuxer, struct bstr opt,
|
|
|
|
struct bstr param);
|
|
|
|
char *demux_info_get(struct demuxer *demuxer, const char *opt);
|
|
|
|
int demux_info_print(struct demuxer *demuxer);
|
|
|
|
int demux_control(struct demuxer *demuxer, int cmd, void *arg);
|
2002-03-03 19:47:29 +01:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_switch_audio(struct demuxer *demuxer, int index);
|
|
|
|
int demuxer_switch_video(struct demuxer *demuxer, int index);
|
2003-01-19 01:21:54 +01:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_type_by_filename(char *filename);
|
2005-08-05 21:57:47 +02:00
|
|
|
|
2008-12-04 00:01:03 +01:00
|
|
|
void demuxer_help(void);
|
2006-08-06 20:55:34 +02:00
|
|
|
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name,
|
2010-05-19 12:44:37 +02:00
|
|
|
struct bstr type, struct bstr data);
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
|
2010-01-26 02:31:31 +01:00
|
|
|
uint64_t start, uint64_t end);
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_seek_chapter(struct demuxer *demuxer, int chapter, double *seek_pts,
|
2009-04-01 18:55:26 +02:00
|
|
|
char **chapter_name);
|
2006-08-06 20:55:34 +02:00
|
|
|
|
2007-12-13 13:51:05 +01:00
|
|
|
/// Get current chapter index if available.
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_get_current_chapter(struct demuxer *demuxer, double time_now);
|
2007-12-13 13:51:05 +01:00
|
|
|
/// Get chapter name by index if available.
|
2011-02-10 11:05:26 +01:00
|
|
|
char *demuxer_chapter_name(struct demuxer *demuxer, int chapter);
|
2007-12-13 13:51:05 +01:00
|
|
|
/// Get chapter display name by index.
|
2011-02-10 11:05:26 +01:00
|
|
|
char *demuxer_chapter_display_name(struct demuxer *demuxer, int chapter);
|
2007-12-13 13:51:05 +01:00
|
|
|
/// Get chapter start time and end time by index if available.
|
2011-02-10 11:05:26 +01:00
|
|
|
float demuxer_chapter_time(struct demuxer *demuxer, int chapter, float *end);
|
2007-12-13 13:51:05 +01:00
|
|
|
/// Get total chapter number.
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_chapter_count(struct demuxer *demuxer);
|
2008-01-05 15:28:57 +01:00
|
|
|
/// Get current angle index.
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_get_current_angle(struct demuxer *demuxer);
|
2008-01-05 15:28:57 +01:00
|
|
|
/// Set angle.
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_set_angle(struct demuxer *demuxer, int angle);
|
2008-01-05 15:28:57 +01:00
|
|
|
/// Get number of angles.
|
2011-02-10 11:05:26 +01:00
|
|
|
int demuxer_angles_count(struct demuxer *demuxer);
|
2007-06-20 18:52:32 +02:00
|
|
|
|
2010-11-08 12:05:49 +01:00
|
|
|
/* Get the index of a track.
|
2011-02-18 15:32:40 +01:00
|
|
|
* lang is a string list, NULL is same as empty list
|
2010-11-08 12:05:49 +01:00
|
|
|
* Sort tracks based on the following criteria:
|
|
|
|
* 1) earlier match in lang list, or last no match
|
|
|
|
* 2) track is marked default (default wins)
|
|
|
|
* 3) track number (lower wins)
|
|
|
|
* For audio, select best track according to these criteria; only return -1
|
|
|
|
* if there are no tracks at all.
|
|
|
|
* For subs, select best track according to the same criteria, but return -1
|
|
|
|
* if all tracks are no-lang-match, not-default.
|
|
|
|
*/
|
2011-02-18 15:32:40 +01:00
|
|
|
int demuxer_audio_track_by_lang_and_default(struct demuxer *d, char **langt);
|
|
|
|
int demuxer_sub_track_by_lang_and_default(struct demuxer *d, char **langt);
|
2008-03-30 18:55:46 +02:00
|
|
|
|
2008-02-22 10:09:46 +01:00
|
|
|
#endif /* MPLAYER_DEMUXER_H */
|