From af0c41e162725b0edcd6c3d066a2dbef05a3b896 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 7 Jul 2013 23:54:11 +0200 Subject: Remove old demuxers Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does better than them (except in rare corner cases), and the demuxers have a bad influence on the rest of the code. Often they don't output proper packets, and require additional audio and video parsing. Most work only in --no-correct-pts mode. Remove them to facilitate further cleanups. --- demux/demux.h | 71 ----------------------------------------------------------- 1 file changed, 71 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 20e6ba7a66..df73ddd4ee 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -32,42 +32,17 @@ struct MPOpts; -#if (__GNUC__ >= 3) -#define likely(x) __builtin_expect((x) != 0, 1) -#define unlikely(x) __builtin_expect((x) != 0, 0) -#else -#define likely(x) (x) -#define unlikely(x) (x) -#endif - #define MAX_PACKS 4096 #define MAX_PACK_BYTES 0x8000000 // 128 MiB enum demuxer_type { DEMUXER_TYPE_UNKNOWN = 0, - DEMUXER_TYPE_MPEG_PS, - DEMUXER_TYPE_AVI, - DEMUXER_TYPE_AVI_NI, - DEMUXER_TYPE_AVI_NINI, - DEMUXER_TYPE_ASF, DEMUXER_TYPE_TV, - DEMUXER_TYPE_Y4M, DEMUXER_TYPE_MF, DEMUXER_TYPE_RAWAUDIO, DEMUXER_TYPE_RAWVIDEO, - DEMUXER_TYPE_MPEG_ES, - DEMUXER_TYPE_MPEG4_ES, - DEMUXER_TYPE_H264_ES, - DEMUXER_TYPE_MPEG_PES, - DEMUXER_TYPE_MPEG_GXF, - DEMUXER_TYPE_GIF, - DEMUXER_TYPE_MPEG_TS, DEMUXER_TYPE_MATROSKA, DEMUXER_TYPE_LAVF, - DEMUXER_TYPE_NSV, - DEMUXER_TYPE_AVS, - DEMUXER_TYPE_AAC, - DEMUXER_TYPE_MPC, DEMUXER_TYPE_MNG, DEMUXER_TYPE_EDL, DEMUXER_TYPE_CUE, @@ -134,21 +109,10 @@ typedef struct demux_stream { 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) -// ---- asf ----- - struct demux_packet *asf_packet; // read asf fragments here - int asf_seq; // ---- stream header ---- void *sh; // points to sh_audio or sh_video } demux_stream_t; -typedef struct demuxer_info { - char *name; - char *author; - char *encoder; - char *comments; - char *copyright; -} demuxer_info_t; - #define MAX_SH_STREAMS 256 #define MAX_A_STREAMS MAX_SH_STREAMS #define MAX_V_STREAMS MAX_SH_STREAMS @@ -300,15 +264,6 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp); #define SIZE_MAX ((size_t)-1) #endif -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); -} - void free_demuxer(struct demuxer *demuxer); int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream, @@ -330,17 +285,6 @@ static inline int ds_tell_pts(struct demux_stream *ds) return (ds->pts_bytes - ds->buffer_size) + ds->buffer_pos; } -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, - int *read, uint32_t pattern); - -#define demux_peekc(ds) ( \ - (likely(ds->buffer_posbuffer_size)) ? ds->buffer[ds->buffer_pos] \ - : ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos])) -#define demux_getc(ds) ( \ - (likely(ds->buffer_posbuffer_size)) ? ds->buffer[ds->buffer_pos++] \ - : ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos++])) - 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, @@ -352,16 +296,6 @@ int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts, int64_t pos); void ds_clear_parser(struct demux_stream *sh); -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; -} - struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, int file_format, int aid, int vid, int sid, char *filename); @@ -376,11 +310,6 @@ void demux_flush(struct demuxer *demuxer); int demux_seek(struct demuxer *demuxer, float rel_seek_secs, float audio_delay, int flags); -// AVI demuxer params: -extern int index_mode; // -1=untouched 0=don't use index 1=use (generate) index -extern int force_ni; -extern int pts_from_bps; - 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); -- cgit v1.2.3 From aac5d758c5a60f13162bc2b500618389bfd92602 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 00:13:53 +0200 Subject: demux: remove audio parser The audio parser was needed only by the "old" demuxers, and demux_rawaudio. All other demuxers output already parsed packets. demux_rawaudio is usually for raw audio, so using a parser with it doesn't usually make sense. But you can also force it to read compressed formats with fixed packet sizes, in which case the parser would have been used. This use case is probably broken now, but you will be able to do the same thing with libavformat demuxers. --- demux/demux.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index df73ddd4ee..a478e58409 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -292,9 +292,6 @@ int ds_get_packet_pts(struct demux_stream *ds, unsigned char **start, struct demux_packet *ds_get_packet_sub(demux_stream_t *ds); struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last); double ds_get_next_pts(struct demux_stream *ds); -int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts, - int64_t pos); -void ds_clear_parser(struct demux_stream *sh); struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, int file_format, int aid, int vid, int sid, -- cgit v1.2.3 From 8a46d4c49f0f06cae4ccd027816b5fff915a9c44 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 00:50:59 +0200 Subject: demux: remove unused function --- demux/demux.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index a478e58409..3d632a92c6 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -275,11 +275,6 @@ void ds_read_packet(struct demux_stream *ds, struct stream *stream, int len, int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds); int ds_fill_buffer(struct demux_stream *ds); -static inline int64_t ds_tell(struct demux_stream *ds) -{ - return (ds->dpos - ds->buffer_size) + ds->buffer_pos; -} - static inline int ds_tell_pts(struct demux_stream *ds) { return (ds->pts_bytes - ds->buffer_size) + ds->buffer_pos; -- cgit v1.2.3 From 05ae5afd6249af9770eb1e55104fbd4f510c2342 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 01:26:13 +0200 Subject: demux: remove separate arrays for audio/video/sub streams, simplify These separate arrays were used by the old demuxers and are not needed anymore. We can simplify track switching as well. One interesting thing is that stream/tv.c (which is a demuxer) won't respect --no-audio anymore. It will probably work as expected, but it will still open an audio device etc. - this is because track selection is now always done with the runtime track switching mechanism. Maybe the TV code could be updated to do proper runtime switching, but I can't test this stuff. --- demux/demux.h | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 3d632a92c6..93cf680bae 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -107,16 +107,12 @@ typedef struct demux_stream { 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) // ---- stream header ---- - void *sh; // points to sh_audio or sh_video + struct sh_stream *gsh; } demux_stream_t; #define MAX_SH_STREAMS 256 -#define MAX_A_STREAMS MAX_SH_STREAMS -#define MAX_V_STREAMS MAX_SH_STREAMS -#define MAX_S_STREAMS MAX_SH_STREAMS struct demuxer; @@ -220,11 +216,6 @@ typedef struct demuxer { struct demux_stream *video; // video buffer/demuxer struct demux_stream *sub; // dvd subtitle buffer/demuxer - // stream headers: - struct sh_audio *a_streams[MAX_SH_STREAMS]; - struct sh_video *v_streams[MAX_SH_STREAMS]; - struct sh_sub *s_streams[MAX_SH_STREAMS]; - struct sh_stream **streams; int num_streams; -- cgit v1.2.3 From 73c76de91edbf8a55eb725196ff54583e3428510 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 01:37:30 +0200 Subject: demux: simplify demux_open() calls The demux_open as well as demux_open_withparams calls don't use the stream selection parameters anymore, so remove them everywhere. Completes the previous commit. --- demux/demux.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 93cf680bae..aa36d2f224 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -280,13 +280,11 @@ struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last); double ds_get_next_pts(struct demux_stream *ds); struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, - int file_format, int aid, int vid, int sid, - char *filename); + int file_format, char *filename); struct demuxer *demux_open_withparams(struct MPOpts *opts, struct stream *stream, int file_format, - char *force_format, int audio_id, - int video_id, int sub_id, char *filename, + char *force_format, char *filename, struct demuxer_params *params); void demux_flush(struct demuxer *demuxer); -- cgit v1.2.3 From 32ad3138445dbf4ac16199ced2ad239a1a8c4e3f Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 8 Jul 2013 23:18:31 +0200 Subject: demux: remove some more minor unused things --- demux/demux.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index aa36d2f224..84ed95ceb2 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -96,10 +96,6 @@ typedef struct demux_stream { 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) - int64_t pos; // position in the input stream (file) - int64_t dpos; // position in the demuxed stream - int pack_no; // serial number of packet - bool keyframe; // keyframe flag of current packet //--------------- int fill_count; // number of unsuccessful tries to get a packet int packs; // number of packets in buffer @@ -189,9 +185,7 @@ typedef struct demuxer { int64_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) enum demuxer_type type; /* 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 -- cgit v1.2.3 From b096269af5649124ead4dfe060cccf56a56876b3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 9 Jul 2013 00:03:14 +0200 Subject: demux: remove ds_read_packet() --- demux/demux.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 84ed95ceb2..eb5de265b3 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -254,8 +254,6 @@ void free_demuxer(struct demuxer *demuxer); int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream, demux_packet_t *dp); 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, int64_t pos, bool keyframe); int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds); int ds_fill_buffer(struct demux_stream *ds); -- cgit v1.2.3 From a5224836293ac02bd13f688cfc848aae6818e963 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:10:33 +0200 Subject: demux: remove facility for partial packet reads Partial packet reads were needed because the video/audio parsers were working on top of them. So it could happen that a parser read a part of a packet, and returned that to the decoder. With libavformat/libavcodec, packets are already parsed, and everything is much simpler. Most of the simplifications in ad_spdif could have been done earlier. Remove some other stuff as well, like the questionable slave mode start time reporting (could be replaced by proper code, but we don't bother). Remove the unused skip_audio_frame() functionality as well (it was used by old demuxers). Some functions become private to demux.c, like demux_fill_buffer(). Introduce new packet read functions, which have simpler semantics. Packets returned from them are owned by the caller, and all packets in the demux.c packet queue are considered unread. Remove special code that dropped subtitle packets with size 0. This used to be needed because it caused special cases in the old code. --- demux/demux.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index eb5de265b3..fade7533e9 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -90,19 +90,15 @@ enum timestamp_type { typedef struct demux_stream { enum stream_type stream_type; - 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 + double last_pts; // pts of the last packet that was read + int last_pts_bytes; // number of bytes read after last pts stamp int eof; // end of demuxed stream? (true if all buffer empty) //--------------- int fill_count; // number of unsuccessful tries to get a packet 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 + struct demux_packet *head; + struct demux_packet *tail; struct demuxer *demuxer; // parent demuxer structure (stream handler) // ---- stream header ---- struct sh_stream *gsh; @@ -256,20 +252,12 @@ int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream, void ds_add_packet(struct demux_stream *ds, struct demux_packet *dp); int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds); -int ds_fill_buffer(struct demux_stream *ds); - -static inline int ds_tell_pts(struct demux_stream *ds) -{ - return (ds->pts_bytes - ds->buffer_size) + ds->buffer_pos; -} 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); -struct demux_packet *ds_get_packet_sub(demux_stream_t *ds); -struct demux_packet *ds_get_packet2(struct demux_stream *ds, bool repeat_last); -double ds_get_next_pts(struct demux_stream *ds); + +struct demux_packet *demux_read_packet(struct sh_stream *sh); +double demux_get_next_pts(struct sh_stream *sh); +bool demux_has_packet(struct sh_stream *sh); struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, int file_format, char *filename); -- cgit v1.2.3 From fa74be880c27b350615f62dd4a0d6a32be56c60e Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:17:05 +0200 Subject: tv: add hack in preparation of demux_stream removal Currently, all demuxer fill_buffer functions have a demux_stream parameter. We want to remove that, but the TV code still depends on it. Add a hack to remove that dependency. The problem with the TV code is that reading video and audio frames blocks, so in order to avoid a deadlock, you should read either of them only if the decoder actually requests new data. --- demux/demux.h | 1 + 1 file changed, 1 insertion(+) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index fade7533e9..4d4d861b7d 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -317,6 +317,7 @@ struct sh_stream *demuxer_stream_by_demuxer_id(struct demuxer *d, enum stream_type t, int id); bool demuxer_stream_is_selected(struct demuxer *d, struct sh_stream *stream); +bool demuxer_stream_has_packets_queued(struct demuxer *d, struct sh_stream *stream); void demux_packet_list_sort(struct demux_packet **pkts, int num_pkts); void demux_packet_list_seek(struct demux_packet **pkts, int num_pkts, -- cgit v1.2.3 From 6ede485e4b2ea1093e84d8589a1c321fe8a8462a Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:17:51 +0200 Subject: core: don't access demux_stream outside of demux.c, make it private Generally remove all accesses to demux_stream from all the code, except inside of demux.c. Make it completely private to demux.c. This simplifies the code because it removes an extra concept. In demux.c it is reduced to a simple packet queue. There were other uses of demux_stream, but they were removed or are removed with this commit. Remove the extra "ds" argument to demux fill_buffer callback. It was used by demux_avi and the TV pseudo-demuxer only. Remove usage of d_video->last_pts from the no-correct-pts code. This field contains the last PTS retrieved after a packet that is not NOPTS. We can easily get this value manually because we read the packets ourselves. Reuse sh_video->last_pts to store the packet PTS values. It was used only by the correct-pts code before, and like d_video->last_pts, it is reset on seek. The behavior should be exactly the same. --- demux/demux.h | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 4d4d861b7d..a3e48a24f3 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -88,22 +88,6 @@ enum timestamp_type { // demux_lavf can pass lavf buffers using FF_INPUT_BUFFER_PADDING_SIZE instead #define MP_INPUT_BUFFER_PADDING_SIZE 16 -typedef struct demux_stream { - enum stream_type stream_type; - double last_pts; // pts of the last packet that was read - int last_pts_bytes; // number of bytes read after last pts stamp - int eof; // end of demuxed stream? (true if all buffer empty) -//--------------- - int fill_count; // number of unsuccessful tries to get a packet - int packs; // number of packets in buffer - int bytes; // total bytes of packets in buffer - struct demux_packet *head; - struct demux_packet *tail; - struct demuxer *demuxer; // parent demuxer structure (stream handler) -// ---- stream header ---- - struct sh_stream *gsh; -} demux_stream_t; - #define MAX_SH_STREAMS 256 struct demuxer; @@ -126,7 +110,7 @@ typedef struct demuxer_desc { // 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); + int (*fill_buffer)(struct demuxer *demuxer); /// Open the demuxer, return demuxer on success, NULL on failure struct demuxer *(*open)(struct demuxer *demuxer); // Optional /// Close the demuxer @@ -249,15 +233,11 @@ void free_demuxer(struct demuxer *demuxer); int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream, demux_packet_t *dp); -void ds_add_packet(struct demux_stream *ds, struct demux_packet *dp); - -int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds); - -void ds_free_packs(struct demux_stream *ds); struct demux_packet *demux_read_packet(struct sh_stream *sh); double demux_get_next_pts(struct sh_stream *sh); bool demux_has_packet(struct sh_stream *sh); +bool demux_stream_eof(struct sh_stream *sh); struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, int file_format, char *filename); -- cgit v1.2.3 From 06281848de53153266d8d4639bbc98e12505994b Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:20:25 +0200 Subject: demux: refactor --- demux/demux.h | 7 ------- 1 file changed, 7 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index a3e48a24f3..2b3a998289 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -183,13 +183,6 @@ typedef struct demuxer { enum timestamp_type timestamp_type; bool warned_queue_overflow; - struct demux_stream *ds[STREAM_TYPE_COUNT]; // video/audio/sub buffers - - // These correspond to ds[], e.g.: audio == ds[STREAM_AUDIO] - struct demux_stream *audio; // audio buffer/demuxer - struct demux_stream *video; // video buffer/demuxer - struct demux_stream *sub; // dvd subtitle buffer/demuxer - struct sh_stream **streams; int num_streams; -- cgit v1.2.3 From e5544e2da38522674edb1eb5d4cfdf179c4328db Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:22:24 +0200 Subject: demux: improve DVD sub auto-selection hack The code touched by this commit makes sure that DVD subtitle tracks known by libdvdread but not known by demux_lavf can be selected and displayed properly. These subtitle tracks have the first packet some time late in the packet stream, so that libavformat won't immediately recognize them, and will add the track as soon as the first packet is seen during normal demuxing. demux_mpg used to handle this elegantly: you just set the MPEG ID of the stream you wanted. demux_lavf couldn't do this, so it was emulated with a DEMUXER_CTRL. This commit changes it so that new streams are selected by default (if autoselect is enabled), and the playloop simply can take appropriate action before the lower layer throws away the first packet. This also changes the demux_lavf behavior that subtitle packets are always demuxed, even if not needed. (They were immediately thrown away, so there was no advantage to this.) Further, this adds the ability to demux.c to deal with demuxing more than one stream of a kind at once. (Though currently it's not useful.) --- demux/demux.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 2b3a998289..d75c8f0d12 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -77,7 +77,6 @@ enum timestamp_type { #define DEMUXER_CTRL_SWITCH_VIDEO 14 #define DEMUXER_CTRL_IDENTIFY_PROGRAM 15 #define DEMUXER_CTRL_CORRECT_PTS 16 -#define DEMUXER_CTRL_AUTOSELECT_SUBTITLE 17 #define SEEK_ABSOLUTE (1 << 0) #define SEEK_FACTOR (1 << 1) @@ -185,6 +184,7 @@ typedef struct demuxer { struct sh_stream **streams; int num_streams; + bool stream_autoselect; int num_editions; int edition; @@ -255,6 +255,9 @@ int demux_control(struct demuxer *demuxer, int cmd, void *arg); void demuxer_switch_track(struct demuxer *demuxer, enum stream_type type, struct sh_stream *stream); +void demuxer_select_track(struct demuxer *demuxer, struct sh_stream *stream, + bool selected); +void demuxer_enable_autoselect(struct demuxer *demuxer); int demuxer_type_by_filename(char *filename); -- cgit v1.2.3 From ac080c77fb9835db3c5a8c42e0ea18fdf209ea09 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 19:35:09 +0200 Subject: stheader: minor cleanup Move codec_tags.h include to demux_mkv.c, because this is the only file which still uses it. Move new_sh_stream() to demux.h, because this is more proper. --- demux/demux.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index d75c8f0d12..3b0d6d5956 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -232,6 +232,8 @@ double demux_get_next_pts(struct sh_stream *sh); bool demux_has_packet(struct sh_stream *sh); bool demux_stream_eof(struct sh_stream *sh); +struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type); + struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, int file_format, char *filename); -- cgit v1.2.3 From d17d2fdc7c536821b3fea8c4a37c0ad09fc487db Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 20:08:12 +0200 Subject: demux: change signature of open functions, cleanups Preparation for redoing the open functions. --- demux/demux.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 3b0d6d5956..c43f0282fb 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -105,19 +105,15 @@ typedef struct demuxer_desc { // 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 + // Return 0 on success, otherwise -1 int (*check_file)(struct demuxer *demuxer); - /// Get packets from file, return 0 on eof. Mandatory - int (*fill_buffer)(struct demuxer *demuxer); - /// 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 + // Open the demuxer, return 0 on success, otherwise -1 + int (*open)(struct demuxer *demuxer); + // The following functions are all optional + int (*fill_buffer)(struct demuxer *demuxer); // 0 on EOF, otherwise 1 + void (*close)(struct demuxer *demuxer); 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); } demuxer_desc_t; -- cgit v1.2.3 From 52c3eb69765a0d1070bf240353095c8ff546765b Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 11 Jul 2013 21:10:42 +0200 Subject: core: change open_stream and demux_open signature This removes the dependency on DEMUXER_TYPE_* and the file_format parameter from the stream open functions. Remove some of the playlist handling code. It looks like this was needed only for loading linked mov files with demux_mov (which was removed long ago). Delete a minor bit of dead network-related code from stream.c as well. --- demux/demux.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index c43f0282fb..f64a02dce1 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -230,13 +230,8 @@ bool demux_stream_eof(struct sh_stream *sh); struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type); -struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream, - int file_format, char *filename); - -struct demuxer *demux_open_withparams(struct MPOpts *opts, - struct stream *stream, int file_format, - char *force_format, char *filename, - struct demuxer_params *params); +struct demuxer *demux_open(struct stream *stream, char *force_format, + struct demuxer_params *params, struct MPOpts *opts); void demux_flush(struct demuxer *demuxer); int demux_seek(struct demuxer *demuxer, float rel_seek_secs, float audio_delay, -- cgit v1.2.3 From 3269bd178020c5d821e8b2d1fd807a38d63e93ce Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 21:58:11 +0200 Subject: demux: rewrite probing and demuxer initialization Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants. Instead of having two open functions for the demuxer callbacks (which somehow are both optional, but you can also decide to implement both...), just have one function. This function takes a parameter that tells the demuxer how strictly it should check for the file headers. This is a nice simplification and allows more flexibility. Remove the file extension code. This literally did nothing (anymore). Change demux_lavf so that we check our other builtin demuxers first before libavformat tries to guess by file extension. --- demux/demux.h | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index f64a02dce1..34ff9fd596 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -36,24 +36,11 @@ struct MPOpts; #define MAX_PACK_BYTES 0x8000000 // 128 MiB enum demuxer_type { - DEMUXER_TYPE_UNKNOWN = 0, + DEMUXER_TYPE_GENERIC = 0, DEMUXER_TYPE_TV, - DEMUXER_TYPE_MF, - DEMUXER_TYPE_RAWAUDIO, - DEMUXER_TYPE_RAWVIDEO, DEMUXER_TYPE_MATROSKA, - DEMUXER_TYPE_LAVF, - DEMUXER_TYPE_MNG, DEMUXER_TYPE_EDL, DEMUXER_TYPE_CUE, - DEMUXER_TYPE_SUBREADER, - DEMUXER_TYPE_LIBASS, - - /* Values after this are for internal use and can not be selected - * as demuxer type by the user (-demuxer option). */ - DEMUXER_TYPE_END, - - DEMUXER_TYPE_PLAYLIST, }; enum timestamp_type { @@ -84,6 +71,22 @@ enum timestamp_type { #define SEEK_BACKWARD (1 << 3) #define SEEK_SUBPREROLL (1 << 4) +// Strictness of the demuxer open format check. +// demux.c will try by default: NORMAL, UNSAFE (in this order) +// Using "-demuxer format" will try REQUEST +// Using "-demuxer +format" will try FORCE +// REQUEST can be used as special value for raw demuxers which have no file +// header check; then they should fail if check!=FORCE && check!=REQUEST. +// +// In general, the list is sorted from weakest check to normal check. +// You can use relation operators to compare the check level. +enum demux_check { + DEMUX_CHECK_FORCE, // force format if possible + DEMUX_CHECK_UNSAFE, // risky/fuzzy detection + DEMUX_CHECK_REQUEST,// requested by user or stream implementation + DEMUX_CHECK_NORMAL, // normal, safe detection +}; + // demux_lavf can pass lavf buffers using FF_INPUT_BUFFER_PADDING_SIZE instead #define MP_INPUT_BUFFER_PADDING_SIZE 16 @@ -101,14 +104,10 @@ typedef struct demuxer_desc { const char *author; // Demuxer author(s) const char *comment; // Comment, printed with -demuxer help - enum demuxer_type type; - // If 1 detection is safe and fast, do it before file extension check - int safe_check; + enum demuxer_type type; // optional // Return 0 on success, otherwise -1 - int (*check_file)(struct demuxer *demuxer); - // Open the demuxer, return 0 on success, otherwise -1 - int (*open)(struct demuxer *demuxer); + int (*open)(struct demuxer *demuxer, enum demux_check check); // The following functions are all optional int (*fill_buffer)(struct demuxer *demuxer); // 0 on EOF, otherwise 1 void (*close)(struct demuxer *demuxer); @@ -160,15 +159,8 @@ typedef struct demuxer { int64_t movi_end; struct stream *stream; double stream_pts; // current stream pts, if applicable (e.g. dvd) - char *filename; // Needed by avs_check_file + char *filename; // same as stream->url enum demuxer_type type; - /* 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). */ - enum demuxer_type file_format; int seekable; // flag /* Set if using absolute seeks for small movements is OK (no pts resets * that would make pts ambigious, preferably supports back/forward flags */ @@ -252,8 +244,6 @@ void demuxer_select_track(struct demuxer *demuxer, struct sh_stream *stream, bool selected); void demuxer_enable_autoselect(struct demuxer *demuxer); -int demuxer_type_by_filename(char *filename); - void demuxer_help(void); int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name, -- cgit v1.2.3 From 6c414f8c7a66ce3bb0c2446cb7fb0fb802a9e98b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:12:02 +0200 Subject: demux: remove useless author/comment fields Same deal as with previous commit. --- demux/demux.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 34ff9fd596..3f193fa72e 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -98,11 +98,8 @@ struct demuxer; * Demuxer description structure */ typedef struct demuxer_desc { - 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 + const char *desc; // Displayed to user enum demuxer_type type; // optional -- cgit v1.2.3 From 879c7a101b36674a952791d2f97cc38782052435 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 12 Jul 2013 22:12:31 +0200 Subject: demux: assume correct-pts mode by default All demuxers make a reasonable effort to set packet timestamps, and thus support correct-pts mode. This commit also implicitly switches demux_rawvideo to correct-pts mode. We still allow demuxers to disable correct-pts mode in theory. --- demux/demux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'demux/demux.h') diff --git a/demux/demux.h b/demux/demux.h index 3f193fa72e..85ee738137 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -63,7 +63,7 @@ enum timestamp_type { #define DEMUXER_CTRL_RESYNC 13 #define DEMUXER_CTRL_SWITCH_VIDEO 14 #define DEMUXER_CTRL_IDENTIFY_PROGRAM 15 -#define DEMUXER_CTRL_CORRECT_PTS 16 +#define DEMUXER_CTRL_CORRECT_PTS 16 // int* (write 1 for ok, 0 for no) #define SEEK_ABSOLUTE (1 << 0) #define SEEK_FACTOR (1 << 1) -- cgit v1.2.3