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. --- DOCS/man/en/changes.rst | 1 - DOCS/man/en/options.rst | 10 - Makefile | 10 - audio/decode/dec_audio.c | 2 + core/options.c | 13 +- core/options.h | 1 + demux/asf.h | 251 ---- demux/asfguid.h | 89 -- demux/asfheader.c | 721 ---------- demux/asfheader.h | 28 - demux/aviheader.c | 674 --------- demux/aviheader.h | 382 ----- demux/aviprint.c | 197 --- demux/aviprint.h | 35 - demux/demux.c | 140 +- demux/demux.h | 71 - demux/demux_asf.c | 691 --------- demux/demux_avi.c | 899 ------------ demux/demux_lavf.c | 2 +- demux/demux_mkv.c | 3 +- demux/demux_mpg.c | 1306 ----------------- demux/demux_ts.c | 3532 ---------------------------------------------- demux/demux_ts.h | 24 - demux/extension.c | 25 +- demux/mp3_hdr.c | 144 -- demux/mp3_hdr.h | 36 - demux/mpeg_hdr.c | 539 ------- demux/mpeg_hdr.h | 55 - demux/ms_hdr.h | 8 + demux/parse_es.c | 158 --- demux/parse_es.h | 45 - demux/stheader.h | 6 - demux/video.c | 527 +------ stream/stream_dvb.c | 2 +- stream/stream_vcd.c | 2 +- sub/dec_sub.c | 1 + video/decode/vd_lavc.c | 5 +- 37 files changed, 38 insertions(+), 10597 deletions(-) delete mode 100644 demux/asf.h delete mode 100644 demux/asfguid.h delete mode 100644 demux/asfheader.c delete mode 100644 demux/asfheader.h delete mode 100644 demux/aviheader.c delete mode 100644 demux/aviheader.h delete mode 100644 demux/aviprint.c delete mode 100644 demux/aviprint.h delete mode 100644 demux/demux_asf.c delete mode 100644 demux/demux_avi.c delete mode 100644 demux/demux_mpg.c delete mode 100644 demux/demux_ts.c delete mode 100644 demux/demux_ts.h delete mode 100644 demux/mp3_hdr.c delete mode 100644 demux/mp3_hdr.h delete mode 100644 demux/mpeg_hdr.c delete mode 100644 demux/mpeg_hdr.h delete mode 100644 demux/parse_es.c delete mode 100644 demux/parse_es.h diff --git a/DOCS/man/en/changes.rst b/DOCS/man/en/changes.rst index e6a20b6ddf..494c46e186 100644 --- a/DOCS/man/en/changes.rst +++ b/DOCS/man/en/changes.rst @@ -106,7 +106,6 @@ Command Line Switches -subdelay --sub-delay -subpos --sub-pos -forcedsubsonly --sub-forced-only - -ni --avi-ni -benchmark --untimed (no stats) -xineramascreen --screen (different values) -ss --start diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 938e5d54ed..9c7aac61ce 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1198,20 +1198,10 @@ depends on the VO backend and how it handles keyboard input. Does not apply to terminal input.) ---avi-ni - (Internal AVI demuxer which is not used by default only) - Force usage of non-interleaved AVI parser (fixes playback of some bad AVI - files). - --no-aspect Ignore aspect ratio information from video file and assume the video has square pixels. See also ``--aspect``. ---no-bps - (Internal AVI demuxer which is not used by default only) - Do not use average byte/second value for A-V sync. Helps with some AVI - files with broken header. - --no-cache Turn off input stream caching. See ``--cache``. diff --git a/Makefile b/Makefile index 7dc01f7a3d..55ea165e1c 100644 --- a/Makefile +++ b/Makefile @@ -185,24 +185,14 @@ SOURCES = talloc.c \ core/timeline/tl_edl.c \ core/timeline/tl_matroska.c \ core/timeline/tl_cue.c \ - demux/asfheader.c \ - demux/aviheader.c \ - demux/aviprint.c \ demux/codec_tags.c \ demux/demux.c \ - demux/demux_asf.c \ - demux/demux_avi.c \ demux/demux_edl.c \ demux/demux_cue.c \ demux/demux_lavf.c \ demux/demux_mf.c \ demux/demux_mkv.c \ - demux/demux_mpg.c \ demux/demux_subreader.c \ - demux/demux_ts.c \ - demux/mp3_hdr.c \ - demux/parse_es.c \ - demux/mpeg_hdr.c \ demux/demux_rawaudio.c \ demux/demux_rawvideo.c \ demux/ebml.c \ diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index 4f2f462b92..3275bae705 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -21,6 +21,8 @@ #include #include +#include + #include "demux/codec_tags.h" #include "config.h" diff --git a/core/options.c b/core/options.c index b00f79c003..c0e64b0dcd 100644 --- a/core/options.c +++ b/core/options.c @@ -25,6 +25,7 @@ #include #include +#include #include "core/options.h" #include "config.h" @@ -369,12 +370,9 @@ const m_option_t mp_opts[] = { OPT_FLAG("pause", pause, 0), OPT_FLAG("keep-open", keep_open, 0), - // AVI specific: force non-interleaved mode - {"avi-ni", &force_ni, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - // AVI and Ogg only: (re)build index at startup - {"idx", &index_mode, CONF_TYPE_FLAG, 0, -1, 1, NULL}, - {"forceidx", &index_mode, CONF_TYPE_FLAG, 0, -1, 2, NULL}, + OPT_FLAG_CONSTANTS("idx", index_mode, 0, -1, 1), + OPT_FLAG_STORE("forceidx", index_mode, 0, 2), // select audio/video/subtitle stream OPT_TRACKCHOICE("aid", audio_id), @@ -419,9 +417,6 @@ const m_option_t mp_opts[] = { // ------------------------- a-v sync options -------------------- - // AVI specific: A-V sync mode (bps vs. interleaving) - {"bps", &pts_from_bps, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - // set A-V sync correction speed (0=disables it): OPT_FLOATRANGE("mc", default_max_pts_correction, 0, 0, 100), @@ -804,6 +799,8 @@ const struct MPOpts mp_default_opts = { .hwdec_codecs = "all", + .index_mode = -1, + .ad_lavc_param = { .ac3drc = 1., .downmix = 1, diff --git a/core/options.h b/core/options.h index 1eb111e33e..f7be4adb02 100644 --- a/core/options.h +++ b/core/options.h @@ -160,6 +160,7 @@ typedef struct MPOpts { char *screenshot_template; double force_fps; + int index_mode; // -1=untouched 0=don't use index 1=use (generate) index struct mp_chmap audio_output_channels; int audio_output_format; diff --git a/demux/asf.h b/demux/asf.h deleted file mode 100644 index db48f72edb..0000000000 --- a/demux/asf.h +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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. - */ - -#ifndef MPLAYER_ASF_H -#define MPLAYER_ASF_H - -#include -#include -#include "libavutil/common.h" -#include "compat/mpbswap.h" - -/////////////////////// -// ASF Object Header -/////////////////////// -typedef struct __attribute__((packed)) { - uint8_t guid[16]; - uint64_t size; -} ASF_obj_header_t; - -//////////////// -// ASF Header -//////////////// -typedef struct __attribute__((packed)) { - ASF_obj_header_t objh; - uint32_t cno; // number of subchunks - uint8_t v1; // unknown (0x01) - uint8_t v2; // unknown (0x02) -} ASF_header_t; - -///////////////////// -// ASF File Header -///////////////////// -typedef struct __attribute__((packed)) { - uint8_t stream_id[16]; // stream GUID - uint64_t file_size; - uint64_t creation_time; //File creation time FILETIME 8 - uint64_t num_packets; //Number of packets UINT64 8 - uint64_t play_duration; //Timestamp of the end position UINT64 8 - uint64_t send_duration; //Duration of the playback UINT64 8 - uint64_t preroll; //Time to bufferize before playing UINT64 8 - uint32_t flags; //Unknown, maybe flags ( usually contains 2 ) UINT32 4 - uint32_t min_packet_size; //Min size of the packet, in bytes UINT32 4 - uint32_t max_packet_size; //Max size of the packet UINT32 4 - uint32_t max_bitrate; //Maximum bitrate of the media (sum of all the stream) -} ASF_file_header_t; - -/////////////////////// -// ASF Stream Header -/////////////////////// -typedef struct __attribute__((packed)) { - uint8_t type[16]; // Stream type (audio/video) GUID 16 - uint8_t concealment[16]; // Audio error concealment type GUID 16 - uint64_t unk1; // Unknown, maybe reserved ( usually contains 0 ) UINT64 8 - uint32_t type_size; //Total size of type-specific data UINT32 4 - uint32_t stream_size; //Size of stream-specific data UINT32 4 - uint16_t stream_no; //Stream number UINT16 2 - uint32_t unk2; //Unknown UINT32 4 -} ASF_stream_header_t; - -/////////////////////////// -// ASF Content Description -/////////////////////////// -typedef struct __attribute__((packed)) { - uint16_t title_size; - uint16_t author_size; - uint16_t copyright_size; - uint16_t comment_size; - uint16_t rating_size; -} ASF_content_description_t; - -//////////////////////// -// ASF Segment Header -//////////////////////// -typedef struct __attribute__((packed)) { - uint8_t streamno; - uint8_t seq; - uint32_t x; - uint8_t flag; -} ASF_segmhdr_t; - -////////////////////// -// ASF Stream Chunck -////////////////////// -typedef struct __attribute__((packed)) { - uint16_t type; - uint16_t size; - uint32_t sequence_number; - uint16_t unknown; - uint16_t size_confirm; -} ASF_stream_chunck_t; - -// Definition of the stream type -#if BYTE_ORDER == BIG_ENDIAN - #define ASF_STREAMING_CLEAR 0x2443 // $C - #define ASF_STREAMING_DATA 0x2444 // $D - #define ASF_STREAMING_END_TRANS 0x2445 // $E - #define ASF_STREAMING_HEADER 0x2448 // $H -#else - #define ASF_STREAMING_CLEAR 0x4324 // $C - #define ASF_STREAMING_DATA 0x4424 // $D - #define ASF_STREAMING_END_TRANS 0x4524 // $E - #define ASF_STREAMING_HEADER 0x4824 // $H -#endif - -// Definition of the differents type of ASF streaming -typedef enum { - ASF_Unknown_e, - ASF_Live_e, - ASF_Prerecorded_e, - ASF_Redirector_e, - ASF_PlainText_e, - ASF_Authenticate_e -} ASF_StreamType_e; - -typedef struct { - ASF_StreamType_e streaming_type; - int request; - int packet_size; - int *audio_streams,n_audio,*video_streams,n_video; - int audio_id, video_id; -} asf_http_streaming_ctrl_t; - - -/* - * Some macros to swap little endian structures read from an ASF file - * into machine endian format - */ -#if BYTE_ORDER == BIG_ENDIAN -#define le2me_ASF_obj_header_t(h) { \ - (h)->size = le2me_64((h)->size); \ -} -#define le2me_ASF_header_t(h) { \ - le2me_ASF_obj_header_t(&(h)->objh); \ - (h)->cno = le2me_32((h)->cno); \ -} -#define le2me_ASF_stream_header_t(h) { \ - (h)->unk1 = le2me_64((h)->unk1); \ - (h)->type_size = le2me_32((h)->type_size); \ - (h)->stream_size = le2me_32((h)->stream_size); \ - (h)->stream_no = le2me_16((h)->stream_no); \ - (h)->unk2 = le2me_32((h)->unk2); \ -} -#define le2me_ASF_file_header_t(h) { \ - (h)->file_size = le2me_64((h)->file_size); \ - (h)->creation_time = le2me_64((h)->creation_time); \ - (h)->num_packets = le2me_64((h)->num_packets); \ - (h)->play_duration = le2me_64((h)->play_duration); \ - (h)->send_duration = le2me_64((h)->send_duration); \ - (h)->preroll = le2me_64((h)->preroll); \ - (h)->flags = le2me_32((h)->flags); \ - (h)->min_packet_size = le2me_32((h)->min_packet_size); \ - (h)->max_packet_size = le2me_32((h)->max_packet_size); \ - (h)->max_bitrate = le2me_32((h)->max_bitrate); \ -} -#define le2me_ASF_content_description_t(h) { \ - (h)->title_size = le2me_16((h)->title_size); \ - (h)->author_size = le2me_16((h)->author_size); \ - (h)->copyright_size = le2me_16((h)->copyright_size); \ - (h)->comment_size = le2me_16((h)->comment_size); \ - (h)->rating_size = le2me_16((h)->rating_size); \ -} -#define le2me_BITMAPINFOHEADER(h) { \ - (h)->biSize = le2me_32((h)->biSize); \ - (h)->biWidth = le2me_32((h)->biWidth); \ - (h)->biHeight = le2me_32((h)->biHeight); \ - (h)->biPlanes = le2me_16((h)->biPlanes); \ - (h)->biBitCount = le2me_16((h)->biBitCount); \ - (h)->biCompression = le2me_32((h)->biCompression); \ - (h)->biSizeImage = le2me_32((h)->biSizeImage); \ - (h)->biXPelsPerMeter = le2me_32((h)->biXPelsPerMeter); \ - (h)->biYPelsPerMeter = le2me_32((h)->biYPelsPerMeter); \ - (h)->biClrUsed = le2me_32((h)->biClrUsed); \ - (h)->biClrImportant = le2me_32((h)->biClrImportant); \ -} -#define le2me_WAVEFORMATEX(h) { \ - (h)->wFormatTag = le2me_16((h)->wFormatTag); \ - (h)->nChannels = le2me_16((h)->nChannels); \ - (h)->nSamplesPerSec = le2me_32((h)->nSamplesPerSec); \ - (h)->nAvgBytesPerSec = le2me_32((h)->nAvgBytesPerSec); \ - (h)->nBlockAlign = le2me_16((h)->nBlockAlign); \ - (h)->wBitsPerSample = le2me_16((h)->wBitsPerSample); \ - (h)->cbSize = le2me_16((h)->cbSize); \ -} -#define le2me_ASF_stream_chunck_t(h) { \ - (h)->size = le2me_16((h)->size); \ - (h)->sequence_number = le2me_32((h)->sequence_number); \ - (h)->unknown = le2me_16((h)->unknown); \ - (h)->size_confirm = le2me_16((h)->size_confirm); \ -} -#else -#define le2me_ASF_obj_header_t(h) /**/ -#define le2me_ASF_header_t(h) /**/ -#define le2me_ASF_stream_header_t(h) /**/ -#define le2me_ASF_file_header_t(h) /**/ -#define le2me_ASF_content_description_t(h) /**/ -#define le2me_BITMAPINFOHEADER(h) /**/ -#define le2me_WAVEFORMATEX(h) /**/ -#define le2me_ASF_stream_chunck_t(h) /**/ -#endif - -// priv struct for the demuxer -struct asf_priv { - ASF_header_t header; - unsigned char* packet; - int scrambling_h; - int scrambling_w; - int scrambling_b; - unsigned packetsize; - double packetrate; - double movielength; - int asf_is_dvr_ms; - uint32_t asf_frame_state; - int asf_frame_start_found; - double dvr_last_vid_pts; - uint64_t vid_frame_ct; - uint64_t play_duration; - uint64_t num_packets; - int new_vid_frame_seg; - int *vid_repdata_sizes; - int *aud_repdata_sizes; - int vid_repdata_count; - int aud_repdata_count; - uint64_t avg_vid_frame_time; - uint64_t last_key_payload_time; - uint64_t last_aud_pts; - uint64_t last_aud_diff; - int found_first_key_frame; - uint32_t last_vid_seq; - int vid_ext_timing_index; - int aud_ext_timing_index; - int vid_ext_frame_index; - int know_frame_time; - unsigned bps; -}; - -#endif /* MPLAYER_ASF_H */ diff --git a/demux/asfguid.h b/demux/asfguid.h deleted file mode 100644 index e1dfed87d1..0000000000 --- a/demux/asfguid.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2001 Reimar Döffinger - * - * 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. - */ - -#ifndef MPLAYER_ASFGUID_H -#define MPLAYER_ASFGUID_H - -#include -#include "libavutil/common.h" -#include "compat/mpbswap.h" - - -#define ASF_LOAD_GUID_PREFIX(guid) AV_RL32(guid) - -#define ASF_GUID_PREFIX_audio_stream 0xF8699E40 -#define ASF_GUID_PREFIX_video_stream 0xBC19EFC0 -#define ASF_GUID_PREFIX_audio_conceal_none 0x49f1a440 -#define ASF_GUID_PREFIX_audio_conceal_interleave 0xbfc3cd50 -#define ASF_GUID_PREFIX_header 0x75B22630 -#define ASF_GUID_PREFIX_data_chunk 0x75b22636 -#define ASF_GUID_PREFIX_index_chunk 0x33000890 -#define ASF_GUID_PREFIX_stream_header 0xB7DC0791 -#define ASF_GUID_PREFIX_header_2_0 0xD6E229D1 -#define ASF_GUID_PREFIX_file_header 0x8CABDCA1 -#define ASF_GUID_PREFIX_content_desc 0x75b22633 -#define ASF_GUID_PREFIX_stream_group 0x7bf875ce -#define ASF_GUID_PREFIX_ext_audio_stream 0x31178C9D -#define ASF_GUID_PREFIX_ext_stream_embed_stream_header 0x3AFB65E2 -#define ASF_GUID_PREFIX_dvr_ms_timing_rep_data 0xFD3CC02A -#define ASF_GUID_PREFIX_dvr_ms_vid_frame_rep_data 0xDD6432CC - -/* -const char asf_audio_stream_guid[16] = {0x40, 0x9e, 0x69, 0xf8, - 0x4d, 0x5b, 0xcf, 0x11, 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}; -const char asf_video_stream_guid[16] = {0xc0, 0xef, 0x19, 0xbc, - 0x4d, 0x5b, 0xcf, 0x11, 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b}; -*/ -static const char asf_stream_header_guid[16] = {0x91, 0x07, 0xdc, 0xb7, - 0xb7, 0xa9, 0xcf, 0x11, 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}; -static const char asf_file_header_guid[16] = {0xa1, 0xdc, 0xab, 0x8c, - 0x47, 0xa9, 0xcf, 0x11, 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65}; -static const char asf_content_desc_guid[16] = {0x33, 0x26, 0xb2, 0x75, - 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}; -static const char asf_stream_group_guid[16] = {0xce, 0x75, 0xf8, 0x7b, - 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2}; -static const char asf_data_chunk_guid[16] = {0x36, 0x26, 0xb2, 0x75, - 0x8e, 0x66, 0xcf, 0x11, 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c}; -static const char asf_ext_stream_embed_stream_header[16] = {0xe2, 0x65, 0xfb, 0x3a, - 0xef, 0x47, 0xf2, 0x40, 0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43}; -static const char asf_ext_stream_audio[16] = {0x9d, 0x8c, 0x17, 0x31, - 0xe1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03}; -static const char asf_ext_stream_header[16] = {0xCB, 0xA5, 0xE6, 0x14, - 0x72, 0xC6, 0x32, 0x43, 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A}; -static const char asf_metadata_header[16] = {0xea, 0xcb, 0xf8, 0xc5, - 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca}; -static const char asf_content_encryption[16] = {0xfb, 0xb3, 0x11, 0x22, - 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e}; -static const char asf_dvr_ms_timing_rep_data[16] = {0x2a, 0xc0, 0x3c,0xfd, - 0xdb, 0x06, 0xfa, 0x4c, 0x80, 0x1c, 0x72, 0x12, 0xd3, 0x87, 0x45, 0xe4}; -static const char asf_dvr_ms_vid_frame_rep_data[16] = {0xcc, 0x32, 0x64, 0xdd, - 0x29, 0xe2, 0xdb, 0x40, 0x80, 0xf6, 0xd2, 0x63, 0x28, 0xd2, 0x76, 0x1f}; - -static int find_asf_guid(char *buf, const char *guid, int cur_pos, int buf_len) -{ - int i; - for (i = cur_pos; i < buf_len - 19; i++) { - if (memcmp(&buf[i], guid, 16) == 0) - return i + 16 + 8; // point after guid + length - } - return -1; -} - -#endif /* MPLAYER_ASFGUID_H */ diff --git a/demux/asfheader.c b/demux/asfheader.c deleted file mode 100644 index e3f19840cd..0000000000 --- a/demux/asfheader.c +++ /dev/null @@ -1,721 +0,0 @@ -/* - * 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. - */ - -// .asf fileformat docs from http://divx.euro.ru - -#include -#include -#include - -#include -#include - -#include "config.h" -#include "core/mp_msg.h" - -#include "stream/stream.h" -#include "aviprint.h" -#include "demux.h" -#include "stheader.h" - -#include "asf.h" -#include "asfguid.h" -#include "asfheader.h" - -typedef struct { - // must be 0 for metadata record, might be non-zero for metadata lib record - uint16_t lang_list_index; - uint16_t stream_num; - uint16_t name_length; - uint16_t data_type; - uint32_t data_length; - uint16_t* name; - void* data; -} ASF_meta_record_t; - -static char* get_ucs2str(const uint16_t* inbuf, uint16_t inlen) -{ - char* outbuf = calloc(inlen, 2); - char* q; - int i; - - if (!outbuf) { - mp_tmsg(MSGT_HEADER, MSGL_ERR, "Memory allocation failed.\n"); - return NULL; - } - q = outbuf; - for (i = 0; i < inlen / 2; i++) { - uint8_t tmp; - PUT_UTF8(AV_RL16(&inbuf[i]), tmp, *q++ = tmp;) - } - return outbuf; -} - -static const char* asf_chunk_type(unsigned char* guid) { - static char tmp[60]; - char *p; - int i; - - switch(ASF_LOAD_GUID_PREFIX(guid)){ - case ASF_GUID_PREFIX_audio_stream: - return "guid_audio_stream"; - case ASF_GUID_PREFIX_ext_audio_stream: - return "guid_ext_audio_stream"; - case ASF_GUID_PREFIX_ext_stream_embed_stream_header: - return "guid_ext_stream_embed_stream_header"; - case ASF_GUID_PREFIX_video_stream: - return "guid_video_stream"; - case ASF_GUID_PREFIX_audio_conceal_none: - return "guid_audio_conceal_none"; - case ASF_GUID_PREFIX_audio_conceal_interleave: - return "guid_audio_conceal_interleave"; - case ASF_GUID_PREFIX_header: - return "guid_header"; - case ASF_GUID_PREFIX_data_chunk: - return "guid_data_chunk"; - case ASF_GUID_PREFIX_index_chunk: - return "guid_index_chunk"; - case ASF_GUID_PREFIX_stream_header: - return "guid_stream_header"; - case ASF_GUID_PREFIX_header_2_0: - return "guid_header_2_0"; - case ASF_GUID_PREFIX_file_header: - return "guid_file_header"; - case ASF_GUID_PREFIX_content_desc: - return "guid_content_desc"; - case ASF_GUID_PREFIX_dvr_ms_timing_rep_data: - return "guid_dvr_ms_timing_rep_data"; - case ASF_GUID_PREFIX_dvr_ms_vid_frame_rep_data: - return "guid_dvr_ms_vid_frame_rep_data"; - default: - strcpy(tmp, "unknown guid "); - p = tmp + strlen(tmp); - for (i = 0; i < 16; i++) { - if ((1 << i) & ((1<<4) | (1<<6) | (1<<8))) *p++ = '-'; - sprintf(p, "%02x", guid[i]); - p += 2; - } - return tmp; - } -} - -int asf_check_header(demuxer_t *demuxer){ - unsigned char asfhdrguid[16]={0x30,0x26,0xB2,0x75,0x8E,0x66,0xCF,0x11,0xA6,0xD9,0x00,0xAA,0x00,0x62,0xCE,0x6C}; - struct asf_priv* asf = calloc(1,sizeof(*asf)); - asf->scrambling_h=asf->scrambling_w=asf->scrambling_b=1; - stream_read(demuxer->stream,(char*) &asf->header,sizeof(asf->header)); // header obj - le2me_ASF_header_t(&asf->header); // swap to machine endian -// for(i=0;i<16;i++) printf(" %02X",temp[i]);printf("\n"); -// for(i=0;i<16;i++) printf(" %02X",asfhdrguid[i]);printf("\n"); - if(memcmp(asfhdrguid,asf->header.objh.guid,16)){ - mp_msg(MSGT_HEADER,MSGL_V,"ASF_check: not ASF guid!\n"); - free(asf); - return 0; // not ASF guid - } - if(asf->header.cno>256){ - mp_msg(MSGT_HEADER,MSGL_V,"ASF_check: invalid subchunks_no %d\n",(int) asf->header.cno); - free(asf); - return 0; // invalid header??? - } - demuxer->priv = asf; - return DEMUXER_TYPE_ASF; -} - -static int get_ext_stream_properties(char *buf, int buf_len, int stream_num, struct asf_priv* asf, int is_video) -{ - int pos=0; - uint8_t *buffer = &buf[0]; - uint64_t avg_ft av_unused; - unsigned bitrate; - - while ((pos = find_asf_guid(buf, asf_ext_stream_header, pos, buf_len)) >= 0) { - int this_stream_num, stnamect, payct, i; - int buf_max_index=pos+50; - if (buf_max_index > buf_len) return 0; - buffer = &buf[pos]; - - // the following info is available - // some of it may be useful but we're skipping it for now - // starttime(8 bytes), endtime(8), - // leak-datarate(4), bucket-datasize(4), init-bucket-fullness(4), - // alt-leak-datarate(4), alt-bucket-datasize(4), alt-init-bucket-fullness(4), - // max-object-size(4), - // flags(4) (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved) - - buffer += 8+8; - bitrate = AV_RL32(buffer); - buffer += 8*4; - this_stream_num=AV_RL16(buffer);buffer+=2; - - if (this_stream_num == stream_num) { - buf_max_index+=14; - if (buf_max_index > buf_len) return 0; - buffer+=2; //skip stream-language-id-index - avg_ft = AV_RL64(buffer); // provided in 100ns units - buffer+=8; - asf->bps = bitrate / 8; - - // after this are values for stream-name-count and - // payload-extension-system-count - // followed by associated info for each - stnamect = AV_RL16(buffer);buffer+=2; - payct = AV_RL16(buffer);buffer+=2; - - // need to read stream names if present in order - // to get lengths - values are ignored for now - for (i=0; i buf_len) return 0; - buffer+=2; //language_id_index - stream_name_len = AV_RL16(buffer);buffer+=2; - buffer+=stream_name_len; //stream_name - buf_max_index+=stream_name_len; - if (buf_max_index > buf_len) return 0; - } - - if (is_video) { - asf->vid_repdata_count = payct; - asf->vid_repdata_sizes = malloc(payct*sizeof(int)); - } else { - asf->aud_repdata_count = payct; - asf->aud_repdata_sizes = malloc(payct*sizeof(int)); - } - - for (i=0; i buf_len) return 0; - // Each payload extension definition starts with a GUID. - // In dvr-ms files one of these indicates the presence an - // extension that contains pts values and this is always present - // in the video and audio streams. - // Another GUID indicates the presence of an extension - // that contains useful video frame demuxing information. - // Note that the extension data in each packet does not contain - // these GUIDs and that this header section defines the order the data - // will appear in. - if (memcmp(buffer, asf_dvr_ms_timing_rep_data, 16) == 0) { - if (is_video) - asf->vid_ext_timing_index = i; - else - asf->aud_ext_timing_index = i; - } else if (is_video && memcmp(buffer, asf_dvr_ms_vid_frame_rep_data, 16) == 0) - asf->vid_ext_frame_index = i; - buffer+=16; - - payload_len = AV_RL16(buffer);buffer+=2; - - if (is_video) - asf->vid_repdata_sizes[i] = payload_len; - else - asf->aud_repdata_sizes[i] = payload_len; - buffer+=4;//sys_len - } - - return 1; - } - } - return 1; -} - -#define CHECKDEC(l, n) if (((l) -= (n)) < 0) return 0 -static char* read_meta_record(ASF_meta_record_t* dest, char* buf, - int* buf_len) -{ - CHECKDEC(*buf_len, 2 + 2 + 2 + 2 + 4); - dest->lang_list_index = AV_RL16(buf); - dest->stream_num = AV_RL16(&buf[2]); - dest->name_length = AV_RL16(&buf[4]); - dest->data_type = AV_RL16(&buf[6]); - dest->data_length = AV_RL32(&buf[8]); - buf += 2 + 2 + 2 + 2 + 4; - CHECKDEC(*buf_len, dest->name_length); - dest->name = (uint16_t*)buf; - buf += dest->name_length; - CHECKDEC(*buf_len, dest->data_length); - dest->data = buf; - buf += dest->data_length; - return buf; -} - -static int get_meta(char *buf, int buf_len, int this_stream_num, - float* asp_ratio) -{ - int pos = 0; - uint16_t records_count; - uint16_t x = 0, y = 0; - - if ((pos = find_asf_guid(buf, asf_metadata_header, pos, buf_len)) < 0) - return 0; - - CHECKDEC(buf_len, pos); - buf += pos; - CHECKDEC(buf_len, 2); - records_count = AV_RL16(buf); - buf += 2; - - while (records_count--) { - ASF_meta_record_t record_entry; - char* name; - - if (!(buf = read_meta_record(&record_entry, buf, &buf_len))) - return 0; - /* reserved, must be zero */ - if (record_entry.lang_list_index) - continue; - /* match stream number: 0 to match all */ - if (record_entry.stream_num && record_entry.stream_num != this_stream_num) - continue; - if (!(name = get_ucs2str(record_entry.name, record_entry.name_length))) { - mp_tmsg(MSGT_HEADER, MSGL_ERR, "Memory allocation failed.\n"); - continue; - } - if (strcmp(name, "AspectRatioX") == 0) - x = AV_RL16(record_entry.data); - else if (strcmp(name, "AspectRatioY") == 0) - y = AV_RL16(record_entry.data); - free(name); - } - if (x && y) { - *asp_ratio = (float)x / (float)y; - return 1; - } - return 0; -} - -static int is_drm(char* buf, int buf_len) -{ - uint32_t data_len, type_len, key_len, url_len; - int pos = find_asf_guid(buf, asf_content_encryption, 0, buf_len); - - if (pos < 0) - return 0; - - CHECKDEC(buf_len, pos + 4); - buf += pos; - data_len = AV_RL32(buf); - buf += 4; - CHECKDEC(buf_len, data_len); - buf += data_len; - type_len = AV_RL32(buf); - if (type_len < 4) - return 0; - CHECKDEC(buf_len, 4 + type_len + 4); - buf += 4; - - if (buf[0] != 'D' || buf[1] != 'R' || buf[2] != 'M' || buf[3] != '\0') - return 0; - - buf += type_len; - key_len = AV_RL32(buf); - CHECKDEC(buf_len, key_len + 4); - buf += 4; - - buf[key_len - 1] = '\0'; - mp_msg(MSGT_HEADER, MSGL_V, "DRM Key ID: %s\n", buf); - - buf += key_len; - url_len = AV_RL32(buf); - CHECKDEC(buf_len, url_len); - buf += 4; - - buf[url_len - 1] = '\0'; - mp_tmsg(MSGT_HEADER, MSGL_INFO, "DRM License URL: %s\n", buf); - return 1; -} - -static int asf_init_audio_stream(demuxer_t *demuxer,struct asf_priv* asf, sh_audio_t* sh_audio, ASF_stream_header_t *streamh, int *ppos, uint8_t** buf, char *hdr, unsigned int hdr_len) -{ - uint8_t *buffer = *buf; - int pos = *ppos; - - sh_audio->wf=calloc(FFMAX(streamh->type_size, sizeof(*sh_audio->wf)), 1); - memcpy(sh_audio->wf,buffer,streamh->type_size); - le2me_WAVEFORMATEX(sh_audio->wf); - sh_audio->format=sh_audio->wf->wFormatTag; - mp_set_audio_codec_from_tag(sh_audio); - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf,MSGL_V); - if(ASF_LOAD_GUID_PREFIX(streamh->concealment)==ASF_GUID_PREFIX_audio_conceal_interleave){ - buffer = &hdr[pos]; - pos += streamh->stream_size; - if (pos > hdr_len) return 0; - asf->scrambling_h=buffer[0]; - asf->scrambling_w=(buffer[2]<<8)|buffer[1]; - asf->scrambling_b=(buffer[4]<<8)|buffer[3]; - if(asf->scrambling_b>0){ - asf->scrambling_w/=asf->scrambling_b; - } - } else { - asf->scrambling_b=asf->scrambling_h=asf->scrambling_w=1; - } - mp_msg(MSGT_HEADER,MSGL_V,"ASF: audio scrambling: %d x %d x %d\n",asf->scrambling_h,asf->scrambling_w,asf->scrambling_b); - return 1; -} - -static int find_backwards_asf_guid(char *buf, const char *guid, int cur_pos) -{ - int i; - for (i=cur_pos-16; i>0; i--) { - if (memcmp(&buf[i], guid, 16) == 0) - return i + 16 + 8; // point after guid + length - } - return -1; -} - -int read_asf_header(demuxer_t *demuxer,struct asf_priv* asf){ - int hdr_len = asf->header.objh.size - sizeof(asf->header); - int hdr_skip = 0; - char *hdr = NULL; - char guid_buffer[16]; - int pos, start = stream_tell(demuxer->stream); - uint32_t* streams = NULL; - int audio_streams=0; - int video_streams=0; - uint16_t stream_count=0; - int best_video = -1; - int best_audio = -1; - uint64_t data_len; - ASF_stream_header_t *streamh; - uint8_t *buffer; - int audio_pos=0; - - if(hdr_len < 0) { - mp_msg(MSGT_HEADER, MSGL_FATAL, "Header size is too small.\n"); - return 0; - } - - if (hdr_len > 1024 * 1024) { - mp_tmsg(MSGT_HEADER, MSGL_ERR, "FATAL: header size bigger than 1 MB (%d)!\nPlease contact MPlayer authors, and upload/send this file.\n", - hdr_len); - hdr_skip = hdr_len - 1024 * 1024; - hdr_len = 1024 * 1024; - } - hdr = malloc(hdr_len); - if (!hdr) { - mp_tmsg(MSGT_HEADER, MSGL_FATAL, "Could not allocate %d bytes for header.\n", - hdr_len); - return 0; - } - stream_read(demuxer->stream, hdr, hdr_len); - if (hdr_skip) - stream_skip(demuxer->stream, hdr_skip); - if (stream_eof(demuxer->stream)) { - mp_tmsg(MSGT_HEADER, MSGL_FATAL, "EOF while reading ASF header, broken/incomplete file?\n"); - goto err_out; - } - - if (is_drm(hdr, hdr_len)) - mp_tmsg(MSGT_HEADER, MSGL_FATAL, "This file has been encumbered with DRM encryption, it will not play in MPlayer!\n"); - - if ((pos = find_asf_guid(hdr, asf_ext_stream_audio, 0, hdr_len)) >= 0) - { - // Special case: found GUID for dvr-ms audio. - // Now skip back to associated stream header. - int sh_pos=0; - - sh_pos = find_backwards_asf_guid(hdr, asf_stream_header_guid, pos); - - if (sh_pos > 0) { - sh_audio_t *sh_audio; - - mp_msg(MSGT_HEADER, MSGL_V, "read_asf_header found dvr-ms audio stream header pos=%d\n", sh_pos); - // found audio stream header - following code reads header and - // initializes audio stream. - audio_pos = pos - 16 - 8; - streamh = (ASF_stream_header_t *)&hdr[sh_pos]; - le2me_ASF_stream_header_t(streamh); - audio_pos += 64; //16+16+4+4+4+16+4; - buffer = &hdr[audio_pos]; - sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F); - sh_audio->needs_parsing = 1; - mp_tmsg(MSGT_DEMUX, MSGL_INFO, "[%s] Audio stream found, -aid %d\n", "asfheader", streamh->stream_no & 0x7F); - ++audio_streams; - if (!asf_init_audio_stream(demuxer, asf, sh_audio, streamh, &audio_pos, &buffer, hdr, hdr_len)) - goto len_err_out; - if (!get_ext_stream_properties(hdr, hdr_len, streamh->stream_no, asf, 0)) - goto len_err_out; - } - } - // find stream headers - // only reset pos if we didnt find dvr_ms audio stream - // if we did find it then we want to avoid reading its header twice - if (audio_pos == 0) - pos = 0; - - while ((pos = find_asf_guid(hdr, asf_stream_header_guid, pos, hdr_len)) >= 0) - { - streamh = (ASF_stream_header_t *)&hdr[pos]; - pos += sizeof(ASF_stream_header_t); - if (pos > hdr_len) goto len_err_out; - le2me_ASF_stream_header_t(streamh); - mp_msg(MSGT_HEADER, MSGL_V, "stream type: %s\n", - asf_chunk_type(streamh->type)); - mp_msg(MSGT_HEADER, MSGL_V, "stream concealment: %s\n", - asf_chunk_type(streamh->concealment)); - mp_msg(MSGT_HEADER, MSGL_V, "type: %d bytes, stream: %d bytes ID: %d\n", - (int)streamh->type_size, (int)streamh->stream_size, - (int)streamh->stream_no); - mp_msg(MSGT_HEADER, MSGL_V, "unk1: %lX unk2: %X\n", - (unsigned long)streamh->unk1, (unsigned int)streamh->unk2); - mp_msg(MSGT_HEADER, MSGL_V, "FILEPOS=0x%X\n", pos + start); - // type-specific data: - buffer = &hdr[pos]; - pos += streamh->type_size; - if (pos > hdr_len) goto len_err_out; - switch(ASF_LOAD_GUID_PREFIX(streamh->type)){ - case ASF_GUID_PREFIX_audio_stream: { - sh_audio_t* sh_audio=new_sh_audio(demuxer,streamh->stream_no & 0x7F); - mp_tmsg(MSGT_DEMUX, MSGL_INFO, "[%s] Audio stream found, -aid %d\n", "asfheader", streamh->stream_no & 0x7F); - ++audio_streams; - if (!asf_init_audio_stream(demuxer, asf, sh_audio, streamh, &pos, &buffer, hdr, hdr_len)) - goto len_err_out; - //if(demuxer->audio->id==-1) demuxer->audio->id=streamh.stream_no & 0x7F; - break; - } - case ASF_GUID_PREFIX_video_stream: { - unsigned int len; - float asp_ratio; - sh_video_t* sh_video=new_sh_video(demuxer,streamh->stream_no & 0x7F); - mp_tmsg(MSGT_DEMUX, MSGL_INFO, "[%s] Video stream found, -vid %d\n", "asfheader", streamh->stream_no & 0x7F); - len=streamh->type_size-(4+4+1+2); - ++video_streams; -// sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize); - sh_video->bih=calloc((lenbih))?sizeof(*sh_video->bih):len,1); - memcpy(sh_video->bih,&buffer[4+4+1+2],len); - le2me_BITMAPINFOHEADER(sh_video->bih); - if (sh_video->bih->biSize > len && sh_video->bih->biSize > sizeof(*sh_video->bih)) - sh_video->bih->biSize = len; - if (sh_video->bih->biCompression == mmioFOURCC('D', 'V', 'R', ' ')) { - //mp_tmsg(MSGT_DEMUXER, MSGL_WARN, "DVR will probably only work with libavformat, try -demuxer 35 if you have problems\n"); - //sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; - //sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; - asf->asf_frame_state=-1; - asf->asf_frame_start_found=0; - asf->asf_is_dvr_ms=1; - asf->dvr_last_vid_pts=0.0; - } else asf->asf_is_dvr_ms=0; - if (!get_ext_stream_properties(hdr, hdr_len, streamh->stream_no, asf, 1)) - goto len_err_out; - if (get_meta(hdr, hdr_len, streamh->stream_no, &asp_ratio)) { - sh_video->aspect = asp_ratio * sh_video->bih->biWidth / - sh_video->bih->biHeight; - } - sh_video->i_bps = asf->bps; - sh_video->format = sh_video->bih->biCompression; - mp_set_video_codec_from_tag(sh_video); - sh_video->format = mp_video_fourcc_alias(sh_video->format); - - if( mp_msg_test(MSGT_DEMUX,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V); - //asf_video_id=streamh.stream_no & 0x7F; - //if(demuxer->video->id==-1) demuxer->video->id=streamh.stream_no & 0x7F; - break; - } - } - // stream-specific data: - // stream_read(demuxer->stream,(char*) buffer,streamh.stream_size); - } - - // find file header - pos = find_asf_guid(hdr, asf_file_header_guid, 0, hdr_len); - if (pos >= 0) { - ASF_file_header_t *fileh = (ASF_file_header_t *)&hdr[pos]; - pos += sizeof(ASF_file_header_t); - if (pos > hdr_len) goto len_err_out; - le2me_ASF_file_header_t(fileh); - mp_msg(MSGT_HEADER, MSGL_V, "ASF: packets: %d flags: %d " - "max_packet_size: %d min_packet_size: %d max_bitrate: %d " - "preroll: %d\n", - (int)fileh->num_packets, (int)fileh->flags, - (int)fileh->min_packet_size, (int)fileh->max_packet_size, - (int)fileh->max_bitrate, (int)fileh->preroll); - asf->packetsize=fileh->max_packet_size; - asf->packet=malloc(asf->packetsize); // !!! - asf->packetrate=fileh->max_bitrate/8.0/(double)asf->packetsize; - asf->movielength=FFMAX(0.0, (fileh->play_duration / 10000.0 - fileh->preroll) / 1000.0); - } - - // find content header - pos = find_asf_guid(hdr, asf_content_desc_guid, 0, hdr_len); - if (pos >= 0) { - ASF_content_description_t *contenth = (ASF_content_description_t *)&hdr[pos]; - char *string=NULL; - uint16_t* wstring = NULL; - uint16_t len; - pos += sizeof(ASF_content_description_t); - if (pos > hdr_len) goto len_err_out; - le2me_ASF_content_description_t(contenth); - mp_msg(MSGT_HEADER,MSGL_V,"\n"); - // extract the title - if((len = contenth->title_size) != 0) { - wstring = (uint16_t*)&hdr[pos]; - pos += len; - if (pos > hdr_len) goto len_err_out; - if ((string = get_ucs2str(wstring, len))) { - mp_msg(MSGT_HEADER,MSGL_V," Title: %s\n", string); - demux_info_add(demuxer, "title", string); - free(string); - } - } - // extract the author - if((len = contenth->author_size) != 0) { - wstring = (uint16_t*)&hdr[pos]; - pos += len; - if (pos > hdr_len) goto len_err_out; - if ((string = get_ucs2str(wstring, len))) { - mp_msg(MSGT_HEADER,MSGL_V," Author: %s\n", string); - demux_info_add(demuxer, "author", string); - free(string); - } - } - // extract the copyright - if((len = contenth->copyright_size) != 0) { - wstring = (uint16_t*)&hdr[pos]; - pos += len; - if (pos > hdr_len) goto len_err_out; - if ((string = get_ucs2str(wstring, len))) { - mp_msg(MSGT_HEADER,MSGL_V," Copyright: %s\n", string); - demux_info_add(demuxer, "copyright", string); - free(string); - } - } - // extract the comment - if((len = contenth->comment_size) != 0) { - wstring = (uint16_t*)&hdr[pos]; - pos += len; - if (pos > hdr_len) goto len_err_out; - if ((string = get_ucs2str(wstring, len))) { - mp_msg(MSGT_HEADER,MSGL_V," Comment: %s\n", string); - demux_info_add(demuxer, "comments", string); - free(string); - } - } - // extract the rating - if((len = contenth->rating_size) != 0) { - wstring = (uint16_t*)&hdr[pos]; - pos += len; - if (pos > hdr_len) goto len_err_out; - if ((string = get_ucs2str(wstring, len))) { - mp_msg(MSGT_HEADER,MSGL_V," Rating: %s\n", string); - free(string); - } - } - mp_msg(MSGT_HEADER,MSGL_V,"\n"); - } - - // find content header - pos = find_asf_guid(hdr, asf_stream_group_guid, 0, hdr_len); - if (pos >= 0) { - int max_streams = (hdr_len - pos - 2) / 6; - uint16_t stream_id, i; - uint32_t max_bitrate; - char *ptr = &hdr[pos]; - mp_msg(MSGT_HEADER,MSGL_V,"============ ASF Stream group == START ===\n"); - if(max_streams <= 0) goto len_err_out; - stream_count = AV_RL16(ptr); - ptr += sizeof(uint16_t); - if(stream_count > max_streams) stream_count = max_streams; - if(stream_count > 0) - streams = malloc(2*stream_count*sizeof(uint32_t)); - mp_msg(MSGT_HEADER,MSGL_V," stream count=[0x%x][%u]\n", stream_count, stream_count ); - for( i=0 ; istream); // start of first data chunk - stream_read(demuxer->stream, guid_buffer, 16); - if (memcmp(guid_buffer, asf_data_chunk_guid, 16) != 0) { - mp_tmsg(MSGT_HEADER, MSGL_FATAL, "No data chunk following header!\n"); - free(streams); - streams = NULL; - return 0; - } - // read length of chunk - data_len = stream_read_qword_le(demuxer->stream); - demuxer->movi_start = stream_tell(demuxer->stream) + 26; - demuxer->movi_end = start + data_len; - mp_msg(MSGT_HEADER, MSGL_V, "Found movie at 0x%X - 0x%X\n", - (int)demuxer->movi_start, (int)demuxer->movi_end); - -if(streams) { - // stream selection is done in the network code, it shouldn't be done here - // as the servers often do not care about what we requested. -#if 0 - uint32_t vr = 0, ar = 0,i; -#ifdef CONFIG_NETWORKING - if( demuxer->stream->streaming_ctrl!=NULL ) { - if( demuxer->stream->streaming_ctrl->bandwidth!=0 && demuxer->stream->streaming_ctrl->data!=NULL ) { - best_audio = ((asf_http_streaming_ctrl_t*)demuxer->stream->streaming_ctrl->data)->audio_id; - best_video = ((asf_http_streaming_ctrl_t*)demuxer->stream->streaming_ctrl->data)->video_id; - } - } else -#endif - for(i = 0; i < stream_count; i++) { - uint32_t id = streams[2*i]; - uint32_t rate = streams[2*i+1]; - if(demuxer->v_streams[id] && rate > vr) { - vr = rate; - best_video = id; - } else if(demuxer->a_streams[id] && rate > ar) { - ar = rate; - best_audio = id; - } - } -#endif - free(streams); - streams = NULL; -} - -mp_msg(MSGT_HEADER,MSGL_V,"ASF: %d audio and %d video streams found\n",audio_streams,video_streams); -if(!audio_streams) demuxer->audio->id=-2; // nosound -else if(best_audio > 0 && demuxer->audio->id == -1) demuxer->audio->id=best_audio; -if(!video_streams){ - if(!audio_streams){ - mp_tmsg(MSGT_HEADER,MSGL_ERR,"ASF: no audio or video headers found - broken file?\n"); - return 0; - } - demuxer->video->id=-2; // audio-only -} else if (best_video > 0 && demuxer->video->id == -1) demuxer->video->id = best_video; - -#if 0 -if( mp_msg_test(MSGT_HEADER,MSGL_V) ){ - printf("ASF duration: %d\n",(int)fileh.duration); - printf("ASF start pts: %d\n",(int)fileh.start_timestamp); - printf("ASF end pts: %d\n",(int)fileh.end_timestamp); -} -#endif - -return 1; - -len_err_out: - mp_tmsg(MSGT_HEADER, MSGL_FATAL, "Invalid length in ASF header!\n"); -err_out: - free(hdr); - free(streams); - return 0; -} diff --git a/demux/asfheader.h b/demux/asfheader.h deleted file mode 100644 index 3741f22cd6..0000000000 --- a/demux/asfheader.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ - -#ifndef MPLAYER_ASFHEADER_H -#define MPLAYER_ASFHEADER_H - -#include "asf.h" -#include "demux.h" - -int asf_check_header(demuxer_t *demuxer); -int read_asf_header(demuxer_t *demuxer, struct asf_priv *asf); - -#endif /* MPLAYER_ASFHEADER_H */ diff --git a/demux/aviheader.c b/demux/aviheader.c deleted file mode 100644 index c1b9c59692..0000000000 --- a/demux/aviheader.c +++ /dev/null @@ -1,674 +0,0 @@ -/* - * 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. - */ - -#include -#include -#include -#include - -#include -#include - -#include "config.h" -#include "core/mp_msg.h" - -#include "stream/stream.h" -#include "demux.h" -#include "stheader.h" -#include "aviprint.h" -#include "aviheader.h" - -static MainAVIHeader avih; - -static int odml_get_vstream_id(int id, unsigned char res[]) -{ - if ((char)(id >> 16) == 'd') { - if (res) { - res[0] = id; - res[1] = id >> 8; - } - return 1; - } - return 0; -} - -static int avi_idx_cmp(const void *elem1, const void *elem2) -{ - register int64_t a = AVI_IDX_OFFSET((AVIINDEXENTRY *)elem1); - register int64_t b = AVI_IDX_OFFSET((AVIINDEXENTRY *)elem2); - return (a > b) - (b > a); -} - -void read_avi_header(demuxer_t *demuxer,int index_mode){ -sh_audio_t *sh_audio=NULL; -sh_video_t *sh_video=NULL; -int stream_id=-1; -int idxfix_videostream=0; -int idxfix_divx=0; -avi_priv_t* priv=demuxer->priv; -int64_t list_end=0; - -//---- AVI header: -priv->idx_size=0; -priv->audio_streams=0; -while(1){ - int id=stream_read_dword_le(demuxer->stream); - unsigned chunksize,size2; - static int last_fccType=0; - static int last_fccHandler=0; - char* hdr=NULL; - // - if(stream_eof(demuxer->stream)) break; - // - if(id==mmioFOURCC('L','I','S','T')){ - unsigned len=stream_read_dword_le(demuxer->stream); // list size - id=stream_read_dword_le(demuxer->stream); // list type - mp_msg(MSGT_HEADER,MSGL_DBG2,"LIST %.4s len=%u\n",(char *) &id,len); - if(len >= 4) { - len -= 4; - list_end=stream_tell(demuxer->stream)+((len+1)&(~1)); - } else { - mp_tmsg(MSGT_HEADER,MSGL_WARN,"** empty list?!\n"); - list_end = 0; - } - mp_msg(MSGT_HEADER,MSGL_V,"list_end=0x%X\n",(int)list_end); - if(id==listtypeAVIMOVIE){ - // found MOVI header - if(!demuxer->movi_start) demuxer->movi_start=stream_tell(demuxer->stream); - demuxer->movi_end=stream_tell(demuxer->stream)+len; - mp_tmsg(MSGT_HEADER,MSGL_V,"Found movie at 0x%X - 0x%X\n",(int)demuxer->movi_start,(int)demuxer->movi_end); - if(demuxer->stream->end_pos>demuxer->movi_end) demuxer->movi_end=demuxer->stream->end_pos; - if(index_mode==-2 || index_mode==2 || index_mode==0) - break; // reading from non-seekable source (stdin) or forced index or no index forced - if(list_end>0) stream_seek(demuxer->stream,list_end); // skip movi - list_end=0; - } - continue; - } - size2=stream_read_dword_le(demuxer->stream); - mp_msg(MSGT_HEADER,MSGL_DBG2,"CHUNK %.4s len=%u\n",(char *) &id,size2); - chunksize=(size2+1)&(~1); - switch(id){ - - // Indicates where the subject of the file is archived - case mmioFOURCC('I','A','R','L'): hdr="Archival Location";break; - // Lists the artist of the original subject of the file; - // for example, "Michaelangelo." - case mmioFOURCC('I','A','R','T'): hdr="Artist";break; - // Lists the name of the person or organization that commissioned - // the subject of the file; for example "Pope Julian II." - case mmioFOURCC('I','C','M','S'): hdr="Commissioned";break; - // Provides general comments about the file or the subject - // of the file. If the comment is several sentences long, end each - // sentence with a period. Do not include new-line characters. - case mmioFOURCC('I','C','M','T'): hdr="Comments";break; - // Records the copyright information for the file; for example, - // "Copyright Encyclopedia International 1991." If there are multiple - // copyrights, separate them by semicolon followed by a space. - case mmioFOURCC('I','C','O','P'): hdr="Copyright";break; - // Describes whether an image has been cropped and, if so, how it - // was cropped; for example, "lower-right corner." - case mmioFOURCC('I','C','R','D'): hdr="Creation Date";break; - // Describes whether an image has been cropped and, if so, how it - // was cropped; for example, "lower-right corner." - case mmioFOURCC('I','C','R','P'): hdr="Cropped";break; - // Specifies the size of the original subject of the file; for - // example, "8.5 in h, 11 in w." - case mmioFOURCC('I','D','I','M'): hdr="Dimensions";break; - // Stores dots per inch setting of the digitizer used to - // produce the file, such as "300." - case mmioFOURCC('I','D','P','I'): hdr="Dots Per Inch";break; - // Stores the of the engineer who worked on the file. If there are - // multiple engineers, separate the names by a semicolon and a blank; - // for example, "Smith, John; Adams, Joe." - case mmioFOURCC('I','E','N','G'): hdr="Engineer";break; - // Describes the original work, such as "landscape,", "portrait," - // "still liefe," etc. - case mmioFOURCC('I','G','N','R'): hdr="Genre";break; - // Provides a list of keywords that refer to the file or subject of the - // file. Separate multiple keywords with a semicolon and a blank; - // for example, "Seattle, aerial view; scenery." - case mmioFOURCC('I','K','E','Y'): hdr="Keywords";break; - // ILGT - Describes the changes in the lightness settings on the digitizer - // required to produce the file. Note that the format of this information - // depends on the hardware used. - case mmioFOURCC('I','L','G','T'): hdr="Lightness";break; - // IMED - Decribes the original subject of the file, such as - // "computer image," "drawing," "lithograph," and so on. - case mmioFOURCC('I','M','E','D'): hdr="Medium";break; - // INAM - Stores the title of the subject of the file, such as - // "Seattle from Above." - case mmioFOURCC('I','N','A','M'): hdr="Title";break; - // IPLT - Specifies the number of colors requested when digitizing - // an image, such as "256." - case mmioFOURCC('I','P','L','T'): hdr="Palette Setting";break; - // IPRD - Specifies the name of title the file was originally intended - // for, such as "Encyclopedia of Pacific Northwest Geography." - case mmioFOURCC('I','P','R','D'): hdr="Product";break; - // ISBJ - Decsribes the contents of the file, such as - // "Aerial view of Seattle." - case mmioFOURCC('I','S','B','J'): hdr="Subject";break; - // ISFT - Identifies the name of the software packages used to create the - // file, such as "Microsoft WaveEdit" - case mmioFOURCC('I','S','F','T'): hdr="Software";break; - // ISHP - Identifies the change in sharpness for the digitizer - // required to produce the file (the format depends on the hardware used). - case mmioFOURCC('I','S','H','P'): hdr="Sharpness";break; - // ISRC - Identifies the name of the person or organization who - // supplied the original subject of the file; for example, "Try Research." - case mmioFOURCC('I','S','R','C'): hdr="Source";break; - // ISRF - Identifies the original form of the material that was digitized, - // such as "slide," "paper," "map," and so on. This is not necessarily - // the same as IMED - case mmioFOURCC('I','S','R','F'): hdr="Source Form";break; - // ITCH - Identifies the technician who digitized the subject file; - // for example, "Smith, John." - case mmioFOURCC('I','T','C','H'): hdr="Technician";break; - case mmioFOURCC('I','S','M','P'): hdr="Time Code";break; - case mmioFOURCC('I','D','I','T'): hdr="Digitization Time";break; - - case ckidAVIMAINHDR: // read 'avih' - stream_read(demuxer->stream,(char*) &avih,FFMIN(size2,sizeof(avih))); - le2me_MainAVIHeader(&avih); // swap to machine endian - chunksize-=FFMIN(size2,sizeof(avih)); - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_avih(&avih,MSGL_V); // else print_avih_flags(&avih,MSGL_V); - break; - case ckidSTREAMHEADER: { // read 'strh' - AVIStreamHeader h; - stream_read(demuxer->stream,(char*) &h,FFMIN(size2,sizeof(h))); - le2me_AVIStreamHeader(&h); // swap to machine endian - chunksize-=FFMIN(size2,sizeof(h)); - ++stream_id; - if(h.fccType==streamtypeVIDEO){ - sh_video=new_sh_video(demuxer,stream_id); - mp_tmsg(MSGT_DEMUX, MSGL_INFO, "[%s] Video stream found, -vid %d\n", "aviheader", stream_id); - memcpy(&sh_video->video,&h,sizeof(h)); - sh_video->stream_delay = (float)sh_video->video.dwStart * sh_video->video.dwScale/sh_video->video.dwRate; - } else - if(h.fccType==streamtypeAUDIO){ - sh_audio=new_sh_audio(demuxer,stream_id); - mp_tmsg(MSGT_DEMUX, MSGL_INFO, "[%s] Audio stream found, -aid %d\n", "aviheader", stream_id); - memcpy(&sh_audio->audio,&h,sizeof(h)); - sh_audio->stream_delay = (float)sh_audio->audio.dwStart * sh_audio->audio.dwScale/sh_audio->audio.dwRate; - sh_audio->needs_parsing = 1; - } - last_fccType=h.fccType; - last_fccHandler=h.fccHandler; - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_strh(&h,MSGL_V); - break; } - case mmioFOURCC('i', 'n', 'd', 'x'): { - uint32_t i; - avisuperindex_chunk *s; - - if(!index_mode) break; - - if(chunksize<=24){ - break; - } - priv->suidx_size++; - priv->suidx = realloc_struct(priv->suidx, priv->suidx_size, sizeof (avisuperindex_chunk)); - s = &priv->suidx[priv->suidx_size-1]; - - chunksize-=24; - memcpy(s->fcc, "indx", 4); - s->dwSize = size2; - s->wLongsPerEntry = stream_read_word_le(demuxer->stream); - s->bIndexSubType = stream_read_char(demuxer->stream); - s->bIndexType = stream_read_char(demuxer->stream); - s->nEntriesInUse = stream_read_dword_le(demuxer->stream); - AV_WN32(s->dwChunkId, stream_read_dword_le(demuxer->stream)); - stream_read(demuxer->stream, (char *)s->dwReserved, 3*4); - memset(s->dwReserved, 0, 3*4); - - print_avisuperindex_chunk(s,MSGL_V); - - // Check and fix this useless crap - if(s->wLongsPerEntry != sizeof (avisuperindex_entry)/4) { - mp_msg (MSGT_HEADER, MSGL_WARN, "Broken super index chunk size: %u\n",s->wLongsPerEntry); - s->wLongsPerEntry = sizeof(avisuperindex_entry)/4; - } - if( ((chunksize/4)/s->wLongsPerEntry) < s->nEntriesInUse){ - mp_msg (MSGT_HEADER, MSGL_WARN, "Broken super index chunk\n"); - s->nEntriesInUse = (chunksize/4)/s->wLongsPerEntry; - } - - s->aIndex = calloc(s->nEntriesInUse, sizeof (avisuperindex_entry)); - s->stdidx = calloc(s->nEntriesInUse, sizeof (avistdindex_chunk)); - - // now the real index of indices - for (i=0; inEntriesInUse; i++) { - chunksize-=16; - s->aIndex[i].qwOffset = stream_read_qword_le(demuxer->stream); - s->aIndex[i].dwSize = stream_read_dword_le(demuxer->stream); - s->aIndex[i].dwDuration = stream_read_dword_le(demuxer->stream); - mp_msg (MSGT_HEADER, MSGL_V, "ODML (%.4s): [%d] 0x%016"PRIx64" 0x%04x %u\n", - s->dwChunkId, i, - (uint64_t)s->aIndex[i].qwOffset, s->aIndex[i].dwSize, s->aIndex[i].dwDuration); - } - - break; } - case ckidSTREAMFORMAT: { // read 'strf' - if(last_fccType==streamtypeVIDEO){ - sh_video->bih=calloc(FFMAX(chunksize, sizeof(*sh_video->bih)), 1); -// sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize); - mp_tmsg(MSGT_HEADER,MSGL_V,"Found 'bih', %u bytes of %zu\n",chunksize,sizeof(*sh_video->bih)); - stream_read(demuxer->stream,(char*) sh_video->bih,chunksize); - le2me_BITMAPINFOHEADER(sh_video->bih); // swap to machine endian - if (sh_video->bih->biSize > chunksize && sh_video->bih->biSize > sizeof(*sh_video->bih)) - sh_video->bih->biSize = chunksize; - // fixup MS-RLE header (seems to be broken for <256 color files) - if(sh_video->bih->biCompression<=1 && sh_video->bih->biSize==40) - sh_video->bih->biSize=chunksize; - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih,MSGL_V); - chunksize=0; - sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; - sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; - sh_video->format = sh_video->bih->biCompression; - mp_set_video_codec_from_tag(sh_video); - sh_video->format = mp_video_fourcc_alias(sh_video->format); -// if(demuxer->video->id==-1) demuxer->video->id=stream_id; - // IdxFix: - idxfix_videostream=stream_id; - switch(sh_video->bih->biCompression){ - case mmioFOURCC('M', 'P', 'G', '4'): - case mmioFOURCC('m', 'p', 'g', '4'): - case mmioFOURCC('D', 'I', 'V', '1'): - idxfix_divx=3; // set index recovery mpeg4 flavour: msmpeg4v1 - mp_tmsg(MSGT_HEADER,MSGL_V,"Regenerating keyframe table for M$ mpg4v1 video.\n"); - break; - case mmioFOURCC('D', 'I', 'V', '3'): - case mmioFOURCC('d', 'i', 'v', '3'): - case mmioFOURCC('D', 'I', 'V', '4'): - case mmioFOURCC('d', 'i', 'v', '4'): - case mmioFOURCC('D', 'I', 'V', '5'): - case mmioFOURCC('d', 'i', 'v', '5'): - case mmioFOURCC('D', 'I', 'V', '6'): - case mmioFOURCC('d', 'i', 'v', '6'): - case mmioFOURCC('M', 'P', '4', '3'): - case mmioFOURCC('m', 'p', '4', '3'): - case mmioFOURCC('M', 'P', '4', '2'): - case mmioFOURCC('m', 'p', '4', '2'): - case mmioFOURCC('D', 'I', 'V', '2'): - case mmioFOURCC('A', 'P', '4', '1'): - idxfix_divx=1; // set index recovery mpeg4 flavour: msmpeg4v3 - mp_tmsg(MSGT_HEADER,MSGL_V,"Regenerating keyframe table for DIVX3 video.\n"); - break; - case mmioFOURCC('D', 'I', 'V', 'X'): - case mmioFOURCC('d', 'i', 'v', 'x'): - case mmioFOURCC('D', 'X', '5', '0'): - case mmioFOURCC('X', 'V', 'I', 'D'): - case mmioFOURCC('x', 'v', 'i', 'd'): - case mmioFOURCC('F', 'M', 'P', '4'): - case mmioFOURCC('f', 'm', 'p', '4'): - idxfix_divx=2; // set index recovery mpeg4 flavour: generic mpeg4 - mp_tmsg(MSGT_HEADER,MSGL_V,"Regenerating keyframe table for MPEG-4 video.\n"); - break; - } - } else - if(last_fccType==streamtypeAUDIO){ - unsigned wf_size = chunksizewf)?sizeof(*sh_audio->wf):chunksize; - sh_audio->wf=calloc(wf_size,1); -// sh_audio->wf=malloc(chunksize); memset(sh_audio->wf,0,chunksize); - mp_tmsg(MSGT_HEADER,MSGL_V,"Found 'wf', %d bytes of %zu\n",chunksize,sizeof(*sh_audio->wf)); - stream_read(demuxer->stream,(char*) sh_audio->wf,chunksize); - le2me_WAVEFORMATEX(sh_audio->wf); - if (sh_audio->wf->cbSize != 0 && - wf_size < sizeof(*sh_audio->wf)+sh_audio->wf->cbSize) { - sh_audio->wf=realloc(sh_audio->wf, sizeof(*sh_audio->wf)+sh_audio->wf->cbSize); - } - sh_audio->format=sh_audio->wf->wFormatTag; - if (sh_audio->wf->wFormatTag == 0xfffe && sh_audio->wf->cbSize >= 22) - sh_audio->format = le2me_16(((WAVEFORMATEXTENSIBLE *)sh_audio->wf)->SubFormat); - if (sh_audio->format == 1 && - last_fccHandler == mmioFOURCC('A', 'x', 'a', 'n')) - sh_audio->format = last_fccHandler; - mp_set_audio_codec_from_tag(sh_audio); - sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; - chunksize=0; - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf,MSGL_V); - ++priv->audio_streams; -// if(demuxer->audio->id==-1) demuxer->audio->id=stream_id; - } - break; - } - case mmioFOURCC('v', 'p', 'r', 'p'): { - VideoPropHeader *vprp = malloc(chunksize); - unsigned int i; - stream_read(demuxer->stream, (void*)vprp, chunksize); - le2me_VideoPropHeader(vprp); - chunksize -= sizeof(*vprp)-sizeof(vprp->FieldInfo); - chunksize /= sizeof(VIDEO_FIELD_DESC); - if (vprp->nbFieldPerFrame > chunksize) { - vprp->nbFieldPerFrame = chunksize; - } - chunksize = 0; - for (i=0; inbFieldPerFrame; i++) { - le2me_VIDEO_FIELD_DESC(&vprp->FieldInfo[i]); - } - if (sh_video) { - sh_video->aspect = GET_AVI_ASPECT(vprp->dwFrameAspectRatio); - } - if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_vprp(vprp,MSGL_V); - free(vprp); - break; - } - case mmioFOURCC('d', 'm', 'l', 'h'): { - // dmlh 00 00 00 04 frms - unsigned int total_frames = stream_read_dword_le(demuxer->stream); - mp_tmsg(MSGT_HEADER,MSGL_V,"AVI: dmlh found (size=%d) (total_frames=%d)\n", chunksize, total_frames); - stream_skip(demuxer->stream, chunksize-4); - chunksize = 0; - } - break; - case ckidAVINEWINDEX: - if(demuxer->movi_end>stream_tell(demuxer->stream)) - demuxer->movi_end=stream_tell(demuxer->stream); // fixup movi-end - if(index_mode && !priv->isodml){ - int read; - int i; - priv->idx_size=size2>>4; - mp_tmsg(MSGT_HEADER,MSGL_V,"Reading INDEX block, %d chunks for %d frames (fpos