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.
This commit is contained in:
wm4 2013-07-07 23:54:11 +02:00
parent 8781e5a55c
commit af0c41e162
37 changed files with 38 additions and 10597 deletions

View File

@ -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

View File

@ -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``.

View File

@ -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 \

View File

@ -21,6 +21,8 @@
#include <unistd.h>
#include <assert.h>
#include <libavutil/mem.h>
#include "demux/codec_tags.h"
#include "config.h"

View File

@ -25,6 +25,7 @@
#include <stddef.h>
#include <sys/types.h>
#include <limits.h>
#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,

View File

@ -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;

View File

@ -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 <sys/types.h>
#include <inttypes.h>
#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 */

View File

@ -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 <inttypes.h>
#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 */

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libavutil/intreadwrite.h>
#include <libavutil/common.h>
#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<stnamect; i++) {
int stream_name_len;
buf_max_index+=4;
if (buf_max_index > 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<payct; i++) {
int payload_len;
buf_max_index+=22;
if (buf_max_index > 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((len<sizeof(*sh_video->bih))?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 ; i<stream_count ; i++ ) {
stream_id = AV_RL16(ptr);
ptr += sizeof(uint16_t);
max_bitrate = AV_RL32(ptr);
ptr += sizeof(uint32_t);
mp_msg(MSGT_HEADER,MSGL_V," stream id=[0x%x][%u]\n", stream_id, stream_id );
mp_msg(MSGT_HEADER,MSGL_V," max bitrate=[0x%x][%u]\n", max_bitrate, max_bitrate );
streams[2*i] = stream_id;
streams[2*i+1] = max_bitrate;
}
mp_msg(MSGT_HEADER,MSGL_V,"============ ASF Stream group == END ===\n");
}
free(hdr);
hdr = NULL;
start = stream_tell(demuxer->stream); // 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;
}

View File

@ -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 */

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <libavutil/common.h>
#include <libavutil/intreadwrite.h>
#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; i<s->nEntriesInUse; 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 = chunksize<sizeof(*sh_audio->wf)?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; i<vprp->nbFieldPerFrame; 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=%"PRId64").\n",
priv->idx_size,avih.dwTotalFrames, (int64_t)stream_tell(demuxer->stream));
priv->idx=malloc(priv->idx_size<<4);
// printf("\nindex to %p !!!!! (priv=%p)\n",priv->idx,priv);
read = stream_read(demuxer->stream,(char*)priv->idx,priv->idx_size<<4);
priv->idx_size = FFMAX(read, 0) >> 4;
for (i = 0; i < priv->idx_size; i++) { // swap index to machine endian
AVIINDEXENTRY *entry=(AVIINDEXENTRY*)priv->idx + i;
le2me_AVIINDEXENTRY(entry);
/*
* We (ab)use the upper word for bits 32-47 of the offset, so
* we'll clear them here.
* FIXME: AFAIK no codec uses them, but if one does it will break
*/
entry->dwFlags&=0xffff;
}
chunksize-=priv->idx_size<<4;
if( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx,priv->idx_size,MSGL_DBG2);
}
break;
/* added May 2002 */
case mmioFOURCC('R','I','F','F'): {
char riff_type[4];
mp_tmsg(MSGT_HEADER, MSGL_V, "Additional RIFF header...\n");
stream_read(demuxer->stream, riff_type, sizeof riff_type);
if (strncmp(riff_type, "AVIX", sizeof riff_type))
mp_tmsg(MSGT_HEADER, MSGL_WARN, "** Warning: this is no extended AVI header..\n");
else {
/*
* We got an extended AVI header, so we need to switch to
* ODML to get seeking to work, provided we got indx chunks
* in the header (suidx_size > 0).
*/
if (priv->suidx_size > 0)
priv->isodml = 1;
}
chunksize = 0;
list_end = 0; /* a new list will follow */
break; }
case ckidAVIPADDING:
stream_skip(demuxer->stream, chunksize);
chunksize = 0;
break;
}
if(hdr){
mp_msg(MSGT_HEADER,MSGL_V,"hdr=%s size=%u\n",hdr,size2);
if(size2==3)
chunksize=1; // empty
else {
char buf[256];
int len=(size2<250)?size2:250;
stream_read(demuxer->stream,buf,len);
chunksize-=len;
buf[len]=0;
mp_msg(MSGT_HEADER,MSGL_V,"%-10s: %s\n",hdr,buf);
demux_info_add(demuxer, hdr, buf);
}
}
mp_msg(MSGT_HEADER,MSGL_DBG2,"list_end=0x%"PRIX64" pos=0x%"PRIX64" chunksize=0x%"PRIX64" next=0x%"PRIX64"\n",
(int64_t)list_end, (int64_t)stream_tell(demuxer->stream),
(int64_t)chunksize, (int64_t)chunksize+(int64_t)stream_tell(demuxer->stream));
if(list_end>0 &&
chunksize+stream_tell(demuxer->stream) == list_end) list_end=0;
if(list_end>0 && chunksize+stream_tell(demuxer->stream)>list_end){
mp_tmsg(MSGT_HEADER,MSGL_V,"Broken chunk? chunksize=%d (id=%.4s)\n",chunksize,(char *) &id);
stream_seek(demuxer->stream,list_end);
list_end=0;
} else
if(chunksize>0) stream_skip(demuxer->stream,chunksize); else
if((int)chunksize<0) mp_msg(MSGT_HEADER,MSGL_WARN,"chunksize=%u (id=%.4s)\n",chunksize,(char *) &id);
}
if (priv->suidx_size > 0 && priv->idx_size == 0) {
/*
* No NEWAVIINDEX, but we got an OpenDML index.
*/
priv->isodml = 1;
}
if (priv->isodml && (index_mode==-1 || index_mode==0 || index_mode==1)) {
int i, j, k;
avisuperindex_chunk *cx;
AVIINDEXENTRY *idx;
if (priv->idx_size) free(priv->idx);
priv->idx_size = 0;
priv->idx_offset = 0;
priv->idx = NULL;
mp_tmsg(MSGT_HEADER, MSGL_INFO, "AVI: ODML: Building ODML index (%d superindexchunks).\n", priv->suidx_size);
// read the standard indices
for (cx = &priv->suidx[0], i=0; i<priv->suidx_size; cx++, i++) {
for (j=0; j<cx->nEntriesInUse; j++) {
int ret1, ret2;
memset(&cx->stdidx[j], 0, 32);
ret1 = stream_seek(demuxer->stream, (int64_t)cx->aIndex[j].qwOffset);
ret2 = stream_read(demuxer->stream, (char *)&cx->stdidx[j], 32);
if (ret1 != 1 || ret2 != 32 || cx->stdidx[j].nEntriesInUse==0) {
// this is a broken file (probably incomplete) let the standard
// gen_index routine handle this
priv->isodml = 0;
priv->idx_size = 0;
mp_tmsg(MSGT_HEADER, MSGL_WARN, "AVI: ODML: Broken (incomplete?) file detected. Will use traditional index.\n");
goto freeout;
}
le2me_AVISTDIDXCHUNK(&cx->stdidx[j]);
print_avistdindex_chunk(&cx->stdidx[j],MSGL_V);
priv->idx_size += cx->stdidx[j].nEntriesInUse;
cx->stdidx[j].aIndex = malloc(cx->stdidx[j].nEntriesInUse*sizeof(avistdindex_entry));
stream_read(demuxer->stream, (char *)cx->stdidx[j].aIndex,
cx->stdidx[j].nEntriesInUse*sizeof(avistdindex_entry));
for (k=0;k<cx->stdidx[j].nEntriesInUse; k++)
le2me_AVISTDIDXENTRY(&cx->stdidx[j].aIndex[k]);
cx->stdidx[j].dwReserved3 = 0;
}
}
/*
* We convert the index by translating all entries into AVIINDEXENTRYs
* and sorting them by offset. The result should be the same index
* we would get with -forceidx.
*/
idx = priv->idx = malloc(priv->idx_size * sizeof (AVIINDEXENTRY));
for (cx = priv->suidx; cx != &priv->suidx[priv->suidx_size]; cx++) {
avistdindex_chunk *sic;
for (sic = cx->stdidx; sic != &cx->stdidx[cx->nEntriesInUse]; sic++) {
avistdindex_entry *sie;
for (sie = sic->aIndex; sie != &sic->aIndex[sic->nEntriesInUse]; sie++) {
uint64_t off = sic->qwBaseOffset + sie->dwOffset - 8;
memcpy(&idx->ckid, sic->dwChunkId, 4);
idx->dwChunkOffset = off;
idx->dwFlags = (off >> 32) << 16;
idx->dwChunkLength = sie->dwSize & 0x7fffffff;
idx->dwFlags |= (sie->dwSize&0x80000000)?0x0:AVIIF_KEYFRAME; // bit 31 denotes !keyframe
idx++;
}
}
}
qsort(priv->idx, priv->idx_size, sizeof(AVIINDEXENTRY), avi_idx_cmp);
/*
Hack to work around a "wrong" index in some divx odml files
(processor_burning.avi as an example)
They have ##dc on non keyframes but the ix00 tells us they are ##db.
Read the fcc of a non-keyframe vid frame and check it.
*/
{
uint32_t id;
uint32_t db = 0;
// find out the video stream id. I have seen files with 01db.
for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
unsigned char res[2];
if (odml_get_vstream_id(idx->ckid, res)) {
db = mmioFOURCC(res[0], res[1], 'd', 'b');
break;
}
}
// find first non keyframe
for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
if (!(idx->dwFlags & AVIIF_KEYFRAME) && idx->ckid == db) break;
}
if (i<priv->idx_size && db) {
stream_seek(demuxer->stream, AVI_IDX_OFFSET(idx));
id = stream_read_dword_le(demuxer->stream);
if (id && id != db) // index fcc and real fcc differ? fix it.
for (idx = &((AVIINDEXENTRY *)priv->idx)[0], i=0; i<priv->idx_size; i++, idx++){
if (!(idx->dwFlags & AVIIF_KEYFRAME) && idx->ckid == db)
idx->ckid = id;
}
}
}
if ( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx, priv->idx_size,MSGL_DBG2);
demuxer->movi_end=demuxer->stream->end_pos;
freeout:
// free unneeded stuff
cx = &priv->suidx[0];
do {
for (j=0;j<cx->nEntriesInUse;j++)
if (cx->stdidx[j].nEntriesInUse) free(cx->stdidx[j].aIndex);
free(cx->stdidx);
} while (cx++ != &priv->suidx[priv->suidx_size-1]);
free(priv->suidx);
}
if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){
int idx_pos = 0;
// build index for file:
stream_seek(demuxer->stream,demuxer->movi_start);
priv->idx_size=0;
priv->idx=NULL;
while(1){
int id;
unsigned len;
int64_t skip;
AVIINDEXENTRY* idx;
unsigned int c;
demuxer->filepos=stream_tell(demuxer->stream);
if(demuxer->filepos>=demuxer->movi_end && demuxer->movi_start<demuxer->movi_end) break;
id=stream_read_dword_le(demuxer->stream);
len=stream_read_dword_le(demuxer->stream);
if(id==mmioFOURCC('L','I','S','T') || id==mmioFOURCC('R', 'I', 'F', 'F')){
id=stream_read_dword_le(demuxer->stream); // list or RIFF type
continue;
}
if(stream_eof(demuxer->stream)) break;
if(!id || avi_stream_id(id)==100) goto skip_chunk; // bad ID (or padding?)
if(idx_pos>=priv->idx_size){
// priv->idx_size+=32;
priv->idx_size+=1024; // +16kB
priv->idx=realloc(priv->idx,priv->idx_size*sizeof(AVIINDEXENTRY));
if(!priv->idx){idx_pos=0; break;} // error!
}
idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos++];
idx->ckid=id;
idx->dwFlags=AVIIF_KEYFRAME; // FIXME
idx->dwFlags|=(demuxer->filepos>>16)&0xffff0000U;
idx->dwChunkOffset=(unsigned long)demuxer->filepos;
idx->dwChunkLength=len;
c=stream_read_dword(demuxer->stream);
if(!len) idx->dwFlags&=~AVIIF_KEYFRAME;
// Fix keyframes for DivX files:
if(idxfix_divx)
if(avi_stream_id(id)==idxfix_videostream){
switch(idxfix_divx){
case 3: c=stream_read_dword(demuxer->stream)<<5; //skip 32+5 bits for m$mpeg4v1
case 1: if(c&0x40000000) idx->dwFlags&=~AVIIF_KEYFRAME;break; // divx 3
case 2: if(c==0x1B6) idx->dwFlags&=~AVIIF_KEYFRAME;break; // divx 4
}
}
// update status line:
{ static int64_t lastpos;
int64_t pos;
int64_t len=demuxer->movi_end-demuxer->movi_start;
if(len){
pos=100*(demuxer->filepos-demuxer->movi_start)/len; // %
} else {
pos=(demuxer->filepos-demuxer->movi_start)>>20; // MB
}
if(pos!=lastpos){
lastpos=pos;
mp_tmsg(MSGT_HEADER,MSGL_STATUS, "Generating Index: %3lu %s \r",
(unsigned long)pos, len?"%":"MB");
}
}
mp_dbg(MSGT_HEADER,MSGL_DBG2,"%08X %08X %.4s %08X %X\n",(unsigned int)demuxer->filepos,id,(char *) &id,(int)c,(unsigned int) idx->dwFlags);
#if 0
{ unsigned char tmp[64];
int i;
stream_read(demuxer->stream,tmp,64);
printf("%.4s",&id);
for(i=0;i<64;i++) printf(" %02X",tmp[i]);
printf("\n");
}
#endif
skip_chunk:
skip=(len+1)&(~1UL); // total bytes in this chunk
stream_seek(demuxer->stream,8+demuxer->filepos+skip);
}
priv->idx_size=idx_pos;
mp_tmsg(MSGT_HEADER,MSGL_INFO,"AVI: Generated index table for %d chunks!\n",priv->idx_size);
if( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx,priv->idx_size,MSGL_DBG2);
}
}

View File

@ -1,382 +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_AVIHEADER_H
#define MPLAYER_AVIHEADER_H
#include <sys/types.h>
#include <stdint.h>
#include "config.h"
#include "libavutil/common.h"
#include "compat/mpbswap.h"
#ifndef mmioFOURCC
#define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
#endif
/* Macro to make a TWOCC out of two characters */
#ifndef aviTWOCC
#define aviTWOCC(ch0, ch1) ((uint16_t)(uint8_t)(ch0) | ((uint16_t)(uint8_t)(ch1) << 8))
#endif
//typedef uint16_t TWOCC;
//typedef uint32_t FOURCC;
/* form types, list types, and chunk types */
#define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ')
#define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l')
#define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h')
#define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l')
#define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h')
#define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f')
#define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd')
#define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n')
#define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i')
#define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ')
#define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1')
/*
** Stream types for the <fccType> field of the stream header.
*/
#define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's')
#define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's')
#define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's')
#define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's')
/* Basic chunk types */
#define cktypeDIBbits aviTWOCC('d', 'b')
#define cktypeDIBcompressed aviTWOCC('d', 'c')
#define cktypePALchange aviTWOCC('p', 'c')
#define cktypeWAVEbytes aviTWOCC('w', 'b')
/* Chunk id to use for extra chunks for padding. */
#define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K')
/* flags for use in <dwFlags> in AVIFileHdr */
#define AVIF_HASINDEX 0x00000010 // Index at end of file?
#define AVIF_MUSTUSEINDEX 0x00000020
#define AVIF_ISINTERLEAVED 0x00000100
#define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
#define AVIF_WASCAPTUREFILE 0x00010000
#define AVIF_COPYRIGHTED 0x00020000
typedef struct
{
uint32_t dwMicroSecPerFrame; // frame display rate (or 0L)
uint32_t dwMaxBytesPerSec; // max. transfer rate
uint32_t dwPaddingGranularity; // pad to multiples of this
// size; normally 2K.
uint32_t dwFlags; // the ever-present flags
uint32_t dwTotalFrames; // # frames in file
uint32_t dwInitialFrames;
uint32_t dwStreams;
uint32_t dwSuggestedBufferSize;
uint32_t dwWidth;
uint32_t dwHeight;
uint32_t dwReserved[4];
} MainAVIHeader;
typedef struct rectangle_t {
short left;
short top;
short right;
short bottom;
} rectangle_t;
typedef struct {
uint32_t fccType;
uint32_t fccHandler;
uint32_t dwFlags; /* Contains AVITF_* flags */
uint16_t wPriority;
uint16_t wLanguage;
uint32_t dwInitialFrames;
uint32_t dwScale;
uint32_t dwRate; /* dwRate / dwScale == samples/second */
uint32_t dwStart;
uint32_t dwLength; /* In units above... */
uint32_t dwSuggestedBufferSize;
uint32_t dwQuality;
uint32_t dwSampleSize;
rectangle_t rcFrame;
} AVIStreamHeader;
/* Flags for index */
#define AVIIF_LIST 0x00000001L // chunk is a 'LIST'
#define AVIIF_KEYFRAME 0x00000010L // this frame is a key frame.
#define AVIIF_NOTIME 0x00000100L // this frame doesn't take any time
#define AVIIF_COMPUSE 0x0FFF0000L // these bits are for compressor use
#ifndef FOURCC_RIFF
#define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F')
#define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T')
#endif
typedef struct
{
uint32_t ckid;
uint32_t dwFlags;
uint32_t dwChunkOffset; // Position of chunk
uint32_t dwChunkLength; // Length of chunk
} AVIINDEXENTRY;
typedef struct avisuperindex_entry {
uint64_t qwOffset; // absolute file offset
uint32_t dwSize; // size of index chunk at this offset
uint32_t dwDuration; // time span in stream ticks
} avisuperindex_entry;
typedef struct avistdindex_entry {
uint32_t dwOffset; // qwBaseOffset + this is absolute file offset
uint32_t dwSize; // bit 31 is set if this is NOT a keyframe
} avistdindex_entry;
// Standard index
typedef struct __attribute__((packed)) avistdindex_chunk {
char fcc[4]; // ix##
uint32_t dwSize; // size of this chunk
uint16_t wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD)
uint8_t bIndexSubType; // must be 0
uint8_t bIndexType; // must be AVI_INDEX_OF_CHUNKS
uint32_t nEntriesInUse; // first unused entry
char dwChunkId[4]; // '##dc' or '##db' or '##wb' etc..
uint64_t qwBaseOffset; // all dwOffsets in aIndex array are relative to this
uint32_t dwReserved3; // must be 0
avistdindex_entry *aIndex; // the actual frames
} avistdindex_chunk;
// Base Index Form 'indx'
typedef struct avisuperindex_chunk {
char fcc[4];
uint32_t dwSize; // size of this chunk
uint16_t wLongsPerEntry; // size of each entry in aIndex array (must be 4*4 for us)
uint8_t bIndexSubType; // future use. must be 0
uint8_t bIndexType; // one of AVI_INDEX_* codes
uint32_t nEntriesInUse; // index of first unused member in aIndex array
char dwChunkId[4]; // fcc of what is indexed
uint32_t dwReserved[3]; // meaning differs for each index type/subtype.
// 0 if unused
avisuperindex_entry *aIndex; // position of ix## chunks
avistdindex_chunk *stdidx; // the actual std indices
} avisuperindex_chunk;
typedef struct {
uint32_t CompressedBMHeight;
uint32_t CompressedBMWidth;
uint32_t ValidBMHeight;
uint32_t ValidBMWidth;
uint32_t ValidBMXOffset;
uint32_t ValidBMYOffset;
uint32_t VideoXOffsetInT;
uint32_t VideoYValidStartLine;
} VIDEO_FIELD_DESC;
typedef struct {
uint32_t VideoFormatToken;
uint32_t VideoStandard;
uint32_t dwVerticalRefreshRate;
uint32_t dwHTotalInT;
uint32_t dwVTotalInLines;
uint32_t dwFrameAspectRatio;
uint32_t dwFrameWidthInPixels;
uint32_t dwFrameHeightInLines;
uint32_t nbFieldPerFrame;
VIDEO_FIELD_DESC FieldInfo[2];
} VideoPropHeader;
typedef enum {
FORMAT_UNKNOWN,
FORMAT_PAL_SQUARE,
FORMAT_PAL_CCIR_601,
FORMAT_NTSC_SQUARE,
FORMAT_NTSC_CCIR_601,
} VIDEO_FORMAT;
typedef enum {
STANDARD_UNKNOWN,
STANDARD_PAL,
STANDARD_NTSC,
STANDARD_SECAM
} VIDEO_STANDARD;
#define MAKE_AVI_ASPECT(a, b) (((a)<<16)|(b))
#define GET_AVI_ASPECT(a) ((float)((a)>>16)/(float)((a)&0xffff))
/*
* Some macros to swap little endian structures read from an AVI file
* into machine endian format
*/
#if BYTE_ORDER == BIG_ENDIAN
#define le2me_MainAVIHeader(h) { \
(h)->dwMicroSecPerFrame = le2me_32((h)->dwMicroSecPerFrame); \
(h)->dwMaxBytesPerSec = le2me_32((h)->dwMaxBytesPerSec); \
(h)->dwPaddingGranularity = le2me_32((h)->dwPaddingGranularity); \
(h)->dwFlags = le2me_32((h)->dwFlags); \
(h)->dwTotalFrames = le2me_32((h)->dwTotalFrames); \
(h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
(h)->dwStreams = le2me_32((h)->dwStreams); \
(h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
(h)->dwWidth = le2me_32((h)->dwWidth); \
(h)->dwHeight = le2me_32((h)->dwHeight); \
}
#define le2me_AVIStreamHeader(h) { \
(h)->fccType = le2me_32((h)->fccType); \
(h)->fccHandler = le2me_32((h)->fccHandler); \
(h)->dwFlags = le2me_32((h)->dwFlags); \
(h)->wPriority = le2me_16((h)->wPriority); \
(h)->wLanguage = le2me_16((h)->wLanguage); \
(h)->dwInitialFrames = le2me_32((h)->dwInitialFrames); \
(h)->dwScale = le2me_32((h)->dwScale); \
(h)->dwRate = le2me_32((h)->dwRate); \
(h)->dwStart = le2me_32((h)->dwStart); \
(h)->dwLength = le2me_32((h)->dwLength); \
(h)->dwSuggestedBufferSize = le2me_32((h)->dwSuggestedBufferSize); \
(h)->dwQuality = le2me_32((h)->dwQuality); \
(h)->dwSampleSize = le2me_32((h)->dwSampleSize); \
le2me_RECT(&(h)->rcFrame); \
}
#define le2me_RECT(h) { \
(h)->left = le2me_16((h)->left); \
(h)->top = le2me_16((h)->top); \
(h)->right = le2me_16((h)->right); \
(h)->bottom = le2me_16((h)->bottom); \
}
#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_AVIINDEXENTRY(h) { \
(h)->ckid = le2me_32((h)->ckid); \
(h)->dwFlags = le2me_32((h)->dwFlags); \
(h)->dwChunkOffset = le2me_32((h)->dwChunkOffset); \
(h)->dwChunkLength = le2me_32((h)->dwChunkLength); \
}
#define le2me_AVISTDIDXCHUNK(h) {\
char c; \
c = (h)->fcc[0]; (h)->fcc[0] = (h)->fcc[3]; (h)->fcc[3] = c; \
c = (h)->fcc[1]; (h)->fcc[1] = (h)->fcc[2]; (h)->fcc[2] = c; \
(h)->dwSize = le2me_32((h)->dwSize); \
(h)->wLongsPerEntry = le2me_16((h)->wLongsPerEntry); \
(h)->nEntriesInUse = le2me_32((h)->nEntriesInUse); \
c = (h)->dwChunkId[0]; (h)->dwChunkId[0] = (h)->dwChunkId[3]; (h)->dwChunkId[3] = c; \
c = (h)->dwChunkId[1]; (h)->dwChunkId[1] = (h)->dwChunkId[2]; (h)->dwChunkId[2] = c; \
(h)->qwBaseOffset = le2me_64((h)->qwBaseOffset); \
(h)->dwReserved3 = le2me_32((h)->dwReserved3); \
}
#define le2me_AVISTDIDXENTRY(h) {\
(h)->dwOffset = le2me_32((h)->dwOffset); \
(h)->dwSize = le2me_32((h)->dwSize); \
}
#define le2me_VideoPropHeader(h) { \
(h)->VideoFormatToken = le2me_32((h)->VideoFormatToken); \
(h)->VideoStandard = le2me_32((h)->VideoStandard); \
(h)->dwVerticalRefreshRate = le2me_32((h)->dwVerticalRefreshRate); \
(h)->dwHTotalInT = le2me_32((h)->dwHTotalInT); \
(h)->dwVTotalInLines = le2me_32((h)->dwVTotalInLines); \
(h)->dwFrameAspectRatio = le2me_32((h)->dwFrameAspectRatio); \
(h)->dwFrameWidthInPixels = le2me_32((h)->dwFrameWidthInPixels); \
(h)->dwFrameHeightInLines = le2me_32((h)->dwFrameHeightInLines); \
(h)->nbFieldPerFrame = le2me_32((h)->nbFieldPerFrame); \
}
#define le2me_VIDEO_FIELD_DESC(h) { \
(h)->CompressedBMHeight = le2me_32((h)->CompressedBMHeight); \
(h)->CompressedBMWidth = le2me_32((h)->CompressedBMWidth); \
(h)->ValidBMHeight = le2me_32((h)->ValidBMHeight); \
(h)->ValidBMWidth = le2me_32((h)->ValidBMWidth); \
(h)->ValidBMXOffset = le2me_32((h)->ValidBMXOffset); \
(h)->ValidBMYOffset = le2me_32((h)->ValidBMYOffset); \
(h)->VideoXOffsetInT = le2me_32((h)->VideoXOffsetInT); \
(h)->VideoYValidStartLine = le2me_32((h)->VideoYValidStartLine); \
}
#else
#define le2me_MainAVIHeader(h) /**/
#define le2me_AVIStreamHeader(h) /**/
#define le2me_RECT(h) /**/
#define le2me_BITMAPINFOHEADER(h) /**/
#define le2me_WAVEFORMATEX(h) /**/
#define le2me_AVIINDEXENTRY(h) /**/
#define le2me_AVISTDIDXCHUNK(h) /**/
#define le2me_AVISTDIDXENTRY(h) /**/
#define le2me_VideoPropHeader(h) /**/
#define le2me_VIDEO_FIELD_DESC(h) /**/
#endif
typedef struct {
// index stuff:
void* idx;
int idx_size;
int64_t idx_pos;
int64_t idx_pos_a;
int64_t idx_pos_v;
int64_t idx_offset; // ennyit kell hozzaadni az index offset ertekekhez
// bps-based PTS stuff:
int video_pack_no;
int audio_block_size;
int64_t audio_block_no;
// interleaved PTS stuff:
int skip_video_frames;
int audio_streams;
float avi_audio_pts;
float avi_video_pts;
float pts_correction;
unsigned int pts_corr_bytes;
unsigned char pts_corrected;
unsigned char pts_has_video;
unsigned int numberofframes;
avisuperindex_chunk *suidx;
int suidx_size;
int isodml;
int warned_unaligned;
} avi_priv_t;
#define AVI_PRIV ((avi_priv_t*)(demuxer->priv))
#define AVI_IDX_OFFSET(x) ((((uint64_t)(x)->dwFlags&0xffff0000)<<16)+(x)->dwChunkOffset)
struct demuxer;
void read_avi_header(struct demuxer *demuxer, int index_mode);
#endif /* MPLAYER_AVIHEADER_H */

View File

@ -1,197 +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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include "config.h"
// for avi_stream_id():
#include "stream/stream.h"
#include "demux.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "aviprint.h"
//#include "codec-cfg.h"
//#include "stheader.h"
void print_avih_flags(MainAVIHeader *h, int verbose_level){
mp_msg(MSGT_HEADER, verbose_level, "MainAVIHeader.dwFlags: (%"PRId32")%s%s%s%s%s%s\n",h->dwFlags,
(h->dwFlags&AVIF_HASINDEX)?" HAS_INDEX":"",
(h->dwFlags&AVIF_MUSTUSEINDEX)?" MUST_USE_INDEX":"",
(h->dwFlags&AVIF_ISINTERLEAVED)?" IS_INTERLEAVED":"",
(h->dwFlags&AVIF_TRUSTCKTYPE)?" TRUST_CKTYPE":"",
(h->dwFlags&AVIF_WASCAPTUREFILE)?" WAS_CAPTUREFILE":"",
(h->dwFlags&AVIF_COPYRIGHTED)?" COPYRIGHTED":""
);
}
void print_avih(MainAVIHeader *h, int verbose_level){
mp_msg(MSGT_HEADER, verbose_level, "======= AVI Header =======\n");
mp_msg(MSGT_HEADER, verbose_level, "us/frame: %"PRId32" (fps=%5.3f)\n",h->dwMicroSecPerFrame,1000000.0f/(float)h->dwMicroSecPerFrame);
mp_msg(MSGT_HEADER, verbose_level, "max bytes/sec: %"PRId32"\n",h->dwMaxBytesPerSec);
mp_msg(MSGT_HEADER, verbose_level, "padding: %"PRId32"\n",h->dwPaddingGranularity);
print_avih_flags(h, verbose_level);
mp_msg(MSGT_HEADER, verbose_level, "frames total: %"PRId32" initial: %"PRId32"\n",h->dwTotalFrames,h->dwInitialFrames);
mp_msg(MSGT_HEADER, verbose_level, "streams: %"PRId32"\n",h->dwStreams);
mp_msg(MSGT_HEADER, verbose_level, "Suggested BufferSize: %"PRId32"\n",h->dwSuggestedBufferSize);
mp_msg(MSGT_HEADER, verbose_level, "Size: %"PRId32" x %"PRId32"\n",h->dwWidth,h->dwHeight);
mp_msg(MSGT_HEADER, verbose_level, "==========================\n");
}
void print_strh(AVIStreamHeader *h, int verbose_level){
mp_msg(MSGT_HEADER, verbose_level, "====== STREAM Header =====\n");
mp_msg(MSGT_HEADER, verbose_level, "Type: %.4s FCC: %.4s (%X)\n",(char *)&h->fccType,(char *)&h->fccHandler,(unsigned int)h->fccHandler);
mp_msg(MSGT_HEADER, verbose_level, "Flags: %"PRId32"\n",h->dwFlags);
mp_msg(MSGT_HEADER, verbose_level, "Priority: %d Language: %d\n",h->wPriority,h->wLanguage);
mp_msg(MSGT_HEADER, verbose_level, "InitialFrames: %"PRId32"\n",h->dwInitialFrames);
mp_msg(MSGT_HEADER, verbose_level, "Rate: %"PRId32"/%"PRId32" = %5.3f\n",h->dwRate,h->dwScale,(float)h->dwRate/(float)h->dwScale);
mp_msg(MSGT_HEADER, verbose_level, "Start: %"PRId32" Len: %"PRId32"\n",h->dwStart,h->dwLength);
mp_msg(MSGT_HEADER, verbose_level, "Suggested BufferSize: %"PRId32"\n",h->dwSuggestedBufferSize);
mp_msg(MSGT_HEADER, verbose_level, "Quality %"PRId32"\n",h->dwQuality);
mp_msg(MSGT_HEADER, verbose_level, "Sample size: %"PRId32"\n",h->dwSampleSize);
mp_msg(MSGT_HEADER, verbose_level, "==========================\n");
}
void print_wave_header(WAVEFORMATEX *h, int verbose_level){
mp_msg(MSGT_HEADER, verbose_level, "======= WAVE Format =======\n");
mp_msg(MSGT_HEADER, verbose_level, "Format Tag: %d (0x%X)\n",h->wFormatTag,h->wFormatTag);
mp_msg(MSGT_HEADER, verbose_level, "Channels: %d\n",h->nChannels);
mp_msg(MSGT_HEADER, verbose_level, "Samplerate: %"PRId32"\n",h->nSamplesPerSec);
mp_msg(MSGT_HEADER, verbose_level, "avg byte/sec: %"PRId32"\n",h->nAvgBytesPerSec);
mp_msg(MSGT_HEADER, verbose_level, "Block align: %d\n",h->nBlockAlign);
mp_msg(MSGT_HEADER, verbose_level, "bits/sample: %d\n",h->wBitsPerSample);
mp_msg(MSGT_HEADER, verbose_level, "cbSize: %d\n",h->cbSize);
if(h->wFormatTag==0x55 && h->cbSize>=12){
MPEGLAYER3WAVEFORMAT* h2=(MPEGLAYER3WAVEFORMAT *)h;
mp_msg(MSGT_HEADER, verbose_level, "mp3.wID=%d\n",h2->wID);
mp_msg(MSGT_HEADER, verbose_level, "mp3.fdwFlags=0x%"PRIX32"\n",h2->fdwFlags);
mp_msg(MSGT_HEADER, verbose_level, "mp3.nBlockSize=%d\n",h2->nBlockSize);
mp_msg(MSGT_HEADER, verbose_level, "mp3.nFramesPerBlock=%d\n",h2->nFramesPerBlock);
mp_msg(MSGT_HEADER, verbose_level, "mp3.nCodecDelay=%d\n",h2->nCodecDelay);
}
else if (h->wFormatTag == 0xfffe && h->cbSize >= 22) {
WAVEFORMATEXTENSIBLE *h2 = (WAVEFORMATEXTENSIBLE *)h;
mp_msg(MSGT_HEADER, verbose_level, "ex.wValidBitsPerSample=%d\n", h2->wValidBitsPerSample);
mp_msg(MSGT_HEADER, verbose_level, "ex.dwChannelMask=0x%X\n", h2->dwChannelMask);
mp_msg(MSGT_HEADER, verbose_level, "ex.SubFormat=%d (0x%X)\n", h2->SubFormat, h2->SubFormat);
}
else if (h->cbSize > 0)
{
int i;
uint8_t* p = (uint8_t*)(h + 1);
mp_msg(MSGT_HEADER, verbose_level, "Unknown extra header dump: ");
for (i = 0; i < h->cbSize; i++)
mp_msg(MSGT_HEADER, verbose_level, "[%x] ", p[i]);
mp_msg(MSGT_HEADER, verbose_level, "\n");
}
mp_msg(MSGT_HEADER, verbose_level, "==========================================================================\n");
}
void print_video_header(BITMAPINFOHEADER *h, int verbose_level){
mp_msg(MSGT_HEADER, verbose_level, "======= VIDEO Format ======\n");
mp_msg(MSGT_HEADER, verbose_level, " biSize %d\n", h->biSize);
mp_msg(MSGT_HEADER, verbose_level, " biWidth %d\n", h->biWidth);
mp_msg(MSGT_HEADER, verbose_level, " biHeight %d\n", h->biHeight);
mp_msg(MSGT_HEADER, verbose_level, " biPlanes %d\n", h->biPlanes);
mp_msg(MSGT_HEADER, verbose_level, " biBitCount %d\n", h->biBitCount);
mp_msg(MSGT_HEADER, verbose_level, " biCompression %d='%.4s'\n", h->biCompression, (char *)&h->biCompression);
mp_msg(MSGT_HEADER, verbose_level, " biSizeImage %d\n", h->biSizeImage);
if (h->biSize > sizeof(*h))
{
int i;
uint8_t* p = (uint8_t*)(h + 1);
mp_msg(MSGT_HEADER, verbose_level, "Unknown extra header dump: ");
for (i = 0; i < h->biSize-sizeof(*h); i++)
mp_msg(MSGT_HEADER, verbose_level, "[%x] ", *(p+i));
mp_msg(MSGT_HEADER, verbose_level, "\n");
}
mp_msg(MSGT_HEADER, verbose_level, "===========================\n");
}
void print_vprp(VideoPropHeader *vprp, int verbose_level){
int i;
mp_msg(MSGT_HEADER, verbose_level, "======= Video Properties Header =======\n");
mp_msg(MSGT_HEADER, verbose_level, "Format: %d VideoStandard: %d\n",
vprp->VideoFormatToken,vprp->VideoStandard);
mp_msg(MSGT_HEADER, verbose_level, "VRefresh: %d HTotal: %d VTotal: %d\n",
vprp->dwVerticalRefreshRate, vprp->dwHTotalInT, vprp->dwVTotalInLines);
mp_msg(MSGT_HEADER, verbose_level, "FrameAspect: %d:%d Framewidth: %d Frameheight: %d\n",
vprp->dwFrameAspectRatio >> 16, vprp->dwFrameAspectRatio & 0xffff,
vprp->dwFrameWidthInPixels, vprp->dwFrameHeightInLines);
mp_msg(MSGT_HEADER, verbose_level, "Fields: %d\n", vprp->nbFieldPerFrame);
for (i=0; i<vprp->nbFieldPerFrame; i++) {
VIDEO_FIELD_DESC *vfd = &vprp->FieldInfo[i];
mp_msg(MSGT_HEADER, verbose_level, " == Field %d description ==\n", i);
mp_msg(MSGT_HEADER, verbose_level, " CompressedBMHeight: %d CompressedBMWidth: %d\n",
vfd->CompressedBMHeight, vfd->CompressedBMWidth);
mp_msg(MSGT_HEADER, verbose_level, " ValidBMHeight: %d ValidBMWidth: %d\n",
vfd->ValidBMHeight, vfd->ValidBMWidth);
mp_msg(MSGT_HEADER, verbose_level, " ValidBMXOffset: %d ValidBMYOffset: %d\n",
vfd->ValidBMXOffset, vfd->ValidBMYOffset);
mp_msg(MSGT_HEADER, verbose_level, " VideoXOffsetInT: %d VideoYValidStartLine: %d\n",
vfd->VideoXOffsetInT, vfd->VideoYValidStartLine);
}
mp_msg(MSGT_HEADER, verbose_level, "=======================================\n");
}
void print_index(AVIINDEXENTRY *idx, int idx_size, int verbose_level){
int i;
unsigned int pos[256];
unsigned int num[256];
memset(pos, 0, sizeof(pos));
memset(num, 0, sizeof(num));
for(i=0;i<idx_size;i++){
int id=avi_stream_id(idx[i].ckid);
if(id<0 || id>255) id=255;
mp_msg(MSGT_HEADER, verbose_level, "%5d: %.4s %4X %016"PRIX64" len:%6"PRId32" pos:%7d->%7.3f %7d->%7.3f\n",i,
(char *)&idx[i].ckid,
(unsigned int)idx[i].dwFlags&0xffff,
(uint64_t)AVI_IDX_OFFSET(&idx[i]),
// idx[i].dwChunkOffset+demuxer->movi_start,
idx[i].dwChunkLength,
pos[id],(float)pos[id]/18747.0f,
num[id],(float)num[id]/23.976f
);
pos[id]+=idx[i].dwChunkLength;
++num[id];
}
}
void print_avistdindex_chunk(avistdindex_chunk *h, int verbose_level){
mp_msg (MSGT_HEADER, verbose_level, "====== AVI Standard Index Header ========\n");
mp_msg (MSGT_HEADER, verbose_level, " FCC (%.4s) dwSize (%d) wLongsPerEntry(%d)\n", h->fcc, h->dwSize, h->wLongsPerEntry);
mp_msg (MSGT_HEADER, verbose_level, " bIndexSubType (%d) bIndexType (%d)\n", h->bIndexSubType, h->bIndexType);
mp_msg (MSGT_HEADER, verbose_level, " nEntriesInUse (%d) dwChunkId (%.4s)\n", h->nEntriesInUse, h->dwChunkId);
mp_msg (MSGT_HEADER, verbose_level, " qwBaseOffset (0x%"PRIX64") dwReserved3 (%d)\n", h->qwBaseOffset, h->dwReserved3);
mp_msg (MSGT_HEADER, verbose_level, "===========================\n");
}
void print_avisuperindex_chunk(avisuperindex_chunk *h, int verbose_level){
mp_msg (MSGT_HEADER, verbose_level, "====== AVI Super Index Header ========\n");
mp_msg (MSGT_HEADER, verbose_level, " FCC (%.4s) dwSize (%d) wLongsPerEntry(%d)\n", h->fcc, h->dwSize, h->wLongsPerEntry);
mp_msg (MSGT_HEADER, verbose_level, " bIndexSubType (%d) bIndexType (%d)\n", h->bIndexSubType, h->bIndexType);
mp_msg (MSGT_HEADER, verbose_level, " nEntriesInUse (%d) dwChunkId (%.4s)\n", h->nEntriesInUse, h->dwChunkId);
mp_msg (MSGT_HEADER, verbose_level, " dwReserved[0] (%d) dwReserved[1] (%d) dwReserved[2] (%d)\n",
h->dwReserved[0], h->dwReserved[1], h->dwReserved[2]);
mp_msg (MSGT_HEADER, verbose_level, "===========================\n");
}

View File

@ -1,35 +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_AVIPRINT_H
#define MPLAYER_AVIPRINT_H
#include "ms_hdr.h"
#include "aviheader.h"
void print_avih_flags(MainAVIHeader *h, int verbose_level);
void print_avih(MainAVIHeader *h, int verbose_level);
void print_strh(AVIStreamHeader *h, int verbose_level);
void print_wave_header(WAVEFORMATEX *h, int verbose_level);
void print_video_header(BITMAPINFOHEADER *h, int verbose_level);
void print_vprp(VideoPropHeader *vprp, int verbose_level);
void print_index(AVIINDEXENTRY *idx, int idx_size, int verbose_level);
void print_avistdindex_chunk(avistdindex_chunk *h, int verbose_level);
void print_avisuperindex_chunk(avisuperindex_chunk *h, int verbose_level);
#endif /* MPLAYER_AVIPRINT_H */

View File

@ -55,18 +55,9 @@ extern const demuxer_desc_t demuxer_desc_rawaudio;
extern const demuxer_desc_t demuxer_desc_rawvideo;
extern const demuxer_desc_t demuxer_desc_tv;
extern const demuxer_desc_t demuxer_desc_mf;
extern const demuxer_desc_t demuxer_desc_avi;
extern const demuxer_desc_t demuxer_desc_asf;
extern const demuxer_desc_t demuxer_desc_matroska;
extern const demuxer_desc_t demuxer_desc_lavf;
extern const demuxer_desc_t demuxer_desc_mng;
extern const demuxer_desc_t demuxer_desc_mpeg_ps;
extern const demuxer_desc_t demuxer_desc_mpeg_pes;
extern const demuxer_desc_t demuxer_desc_mpeg_gxf;
extern const demuxer_desc_t demuxer_desc_mpeg_es;
extern const demuxer_desc_t demuxer_desc_mpeg4_es;
extern const demuxer_desc_t demuxer_desc_h264_es;
extern const demuxer_desc_t demuxer_desc_mpeg_ts;
extern const demuxer_desc_t demuxer_desc_libass;
extern const demuxer_desc_t demuxer_desc_subreader;
@ -86,18 +77,9 @@ const demuxer_desc_t *const demuxer_list[] = {
&demuxer_desc_matroska,
&demuxer_desc_lavf,
&demuxer_desc_subreader,
&demuxer_desc_avi,
&demuxer_desc_asf,
#ifdef CONFIG_MNG
&demuxer_desc_mng,
#endif
&demuxer_desc_mpeg_ps,
&demuxer_desc_mpeg_pes,
&demuxer_desc_mpeg_gxf,
&demuxer_desc_mpeg_es,
&demuxer_desc_mpeg4_es,
&demuxer_desc_h264_es,
&demuxer_desc_mpeg_ts,
// auto-probe last, because it checks file-extensions only
&demuxer_desc_mf,
/* Please do not add any new demuxers here. If you want to implement a new
@ -234,7 +216,6 @@ static struct demux_stream *new_demuxer_stream(struct demuxer *demuxer,
.stream_type = type,
.id = id,
.demuxer = demuxer,
.asf_seq = -1,
};
return ds;
}
@ -357,34 +338,6 @@ static void free_sh_stream(struct sh_stream *sh)
{
}
sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)
{
if (id > MAX_S_STREAMS - 1 || id < 0) {
mp_msg(MSGT_DEMUXER, MSGL_WARN,
"Requested sub stream id overflow (%d > %d)\n", id,
MAX_S_STREAMS);
return NULL;
}
if (demuxer->s_streams[id])
mp_msg(MSGT_DEMUXER, MSGL_WARN, "Sub stream %i redefined\n", id);
else {
new_sh_stream_id(demuxer, STREAM_SUB, id, sid);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SUBTITLE_ID=%d\n", sid);
}
return demuxer->s_streams[id];
}
struct sh_sub *new_sh_sub_sid_lang(struct demuxer *demuxer, int id, int sid,
const char *lang)
{
struct sh_sub *sh = new_sh_sub_sid(demuxer, id, sid);
if (lang && lang[0] && strcmp(lang, "und")) {
sh->gsh->lang = talloc_strdup(sh, lang);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_SID_%d_LANG=%s\n", sid, lang);
}
return sh;
}
static void free_sh_sub(sh_sub_t *sh)
{
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
@ -610,9 +563,7 @@ static bool demux_check_queue_full(demuxer_t *demux)
"packet queue (video: %d packets in %d bytes, audio: %d "
"packets in %d bytes).\n", vpacks, vbytes, apacks, abytes);
mp_tmsg(MSGT_DEMUXER, MSGL_HINT, "Maybe you are playing a non-"
"interleaved stream/file or the codec failed?\nFor AVI files, "
"try to force non-interleaved mode with the "
"--demuxer=avi --avi-ni options.\n");
"interleaved stream/file or the codec failed?\n");
}
demux->warned_queue_overflow = true;
@ -716,65 +667,6 @@ int ds_fill_buffer(demux_stream_t *ds)
return 0;
}
int demux_read_data(demux_stream_t *ds, unsigned char *mem, int len)
{
int x;
int bytes = 0;
while (len > 0) {
x = ds->buffer_size - ds->buffer_pos;
if (x == 0) {
if (!ds_fill_buffer(ds))
return bytes;
} else {
if (x > len)
x = len;
if (mem)
memcpy(mem + bytes, &ds->buffer[ds->buffer_pos], x);
bytes += x;
len -= x;
ds->buffer_pos += x;
}
}
return bytes;
}
/**
* \brief read data until the given 3-byte pattern is encountered, up to maxlen
* \param mem memory to read data into, may be NULL to discard data
* \param maxlen maximum number of bytes to read
* \param read number of bytes actually read
* \param pattern pattern to search for (lowest 8 bits are ignored)
* \return whether pattern was found
*/
int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
int *read, uint32_t pattern)
{
register uint32_t head = 0xffffff00;
register uint32_t pat = pattern & 0xffffff00;
int total_len = 0;
do {
register unsigned char *ds_buf = &ds->buffer[ds->buffer_size];
int len = ds->buffer_size - ds->buffer_pos;
register long pos = -len;
if (unlikely(pos >= 0)) { // buffer is empty
ds_fill_buffer(ds);
continue;
}
do {
head |= ds_buf[pos];
head <<= 8;
} while (++pos && head != pat);
len += pos;
if (total_len + len > maxlen)
len = maxlen - total_len;
len = demux_read_data(ds, mem ? &mem[total_len] : NULL, len);
total_len += len;
} while ((head != pat || total_len < 3) && total_len < maxlen && !ds->eof);
if (read)
*read = total_len;
return total_len >= 3 && head == pat;
}
void ds_free_packs(demux_stream_t *ds)
{
demux_packet_t *dp = ds->first;
@ -783,11 +675,6 @@ void ds_free_packs(demux_stream_t *ds)
free_demux_packet(dp);
dp = dn;
}
if (ds->asf_packet) {
// free unfinished .asf fragments:
free_demux_packet(ds->asf_packet);
ds->asf_packet = NULL;
}
ds->first = ds->last = NULL;
ds->packs = 0; // !!!!!
ds->bytes = 0;
@ -1019,22 +906,6 @@ struct demuxer *demux_open_withparams(struct MPOpts *opts,
if (demuxer_type)
file_format = demuxer_type;
// Some code (e.g. dvd stuff, network code, or extension.c) explicitly
// request certain file formats. The list of formats are always handled by
// libavformat.
// Maybe attempts should be made to convert the mplayer format to the libav
// format, instead of reyling on libav to auto-detect the stream's format
// correctly.
switch (file_format) {
//case DEMUXER_TYPE_MPEG_PS:
//case DEMUXER_TYPE_MPEG_TS:
case DEMUXER_TYPE_Y4M:
case DEMUXER_TYPE_NSV:
case DEMUXER_TYPE_AAC:
case DEMUXER_TYPE_MPC:
file_format = DEMUXER_TYPE_LAVF;
}
// If somebody requested a demuxer check it
if (file_format) {
desc = get_demuxer_desc_from_type(file_format);
@ -1099,14 +970,7 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
int flags)
{
if (!demuxer->seekable) {
if (demuxer->file_format == DEMUXER_TYPE_AVI)
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n");
#ifdef CONFIG_TV
else if (demuxer->file_format == DEMUXER_TYPE_TV)
mp_tmsg(MSGT_SEEK, MSGL_WARN, "TV input is not seekable! (Seeking will probably be for changing channels ;)\n");
#endif
else
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in this file.\n");
mp_tmsg(MSGT_SEEK, MSGL_WARN, "Cannot seek in this file.\n");
return 0;
}

View File

@ -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_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos] \
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos]))
#define demux_getc(ds) ( \
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos++] \
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos++]))
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);

View File

@ -1,691 +0,0 @@
/*
* ASF file parser for DEMUXER v0.3
* copyright (c) 2001 A'rpi/ESP-team
*
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <libavutil/intreadwrite.h>
#include "config.h"
#include "core/mp_msg.h"
#include "stream/stream.h"
#include "asf.h"
#include "asfheader.h"
#include "demux.h"
#include "audio/decode/dec_audio.h"
// based on asf file-format doc by Eugene [http://divx.euro.ru]
/**
* \brief reads int stored in number of bytes given by len
* \param ptr pointer to read from, is incremented appropriately
* \param len lowest 2 bits indicate number of bytes to read
* \param def default value to return if len is invalid
*/
static inline unsigned read_varlen(uint8_t **ptr, int len, int def) {
const uint8_t *p = *ptr;
len &= 3;
switch (len) {
case 1: *ptr += 1; return *p;
case 2: *ptr += 2; return AV_RL16(p);
case 3: *ptr += 4; return AV_RL32(p);
}
return def;
}
/**
* \brief checks if there is enough data to read the bytes given by len
* \param ptr pointer to read from
* \param endptr pointer to the end of the buffer
* \param len lowest 2 bits indicate number of bytes to read
*/
static inline int check_varlen(uint8_t *ptr, uint8_t *endptr, int len) {
return len&3 ? ptr + (1<<((len&3) - 1)) <= endptr : 1;
}
static void asf_descrambling(unsigned char **src,unsigned len, struct asf_priv* asf){
unsigned char *dst;
unsigned char *s2=*src;
unsigned i=0,x,y;
if (len > UINT_MAX - MP_INPUT_BUFFER_PADDING_SIZE)
return;
dst = malloc(len + MP_INPUT_BUFFER_PADDING_SIZE);
while(len>=asf->scrambling_h*asf->scrambling_w*asf->scrambling_b+i){
// mp_msg(MSGT_DEMUX,MSGL_DBG4,"descrambling! (w=%d b=%d)\n",w,asf_scrambling_b);
//i+=asf_scrambling_h*asf_scrambling_w;
for(x=0;x<asf->scrambling_w;x++)
for(y=0;y<asf->scrambling_h;y++){
memcpy(dst+i,s2+(y*asf->scrambling_w+x)*asf->scrambling_b,asf->scrambling_b);
i+=asf->scrambling_b;
}
s2+=asf->scrambling_h*asf->scrambling_w*asf->scrambling_b;
}
//if(i<len) memcpy(dst+i,src+i,len-i);
free(*src);
*src = dst;
}
/*****************************************************************
* \brief initializes asf private data
*
*/
static void init_priv (struct asf_priv* asf){
asf->last_vid_seq=-1;
asf->vid_ext_timing_index=-1;
asf->aud_ext_timing_index=-1;
asf->vid_ext_frame_index=-1;
}
static void demux_asf_append_to_packet(demux_packet_t* dp,unsigned char *data,int len,int offs)
{
if(dp->len!=offs && offs!=-1) mp_msg(MSGT_DEMUX,MSGL_V,"warning! fragment.len=%d BUT next fragment offset=%d \n",dp->len,offs);
size_t old_len = dp->len;
resize_demux_packet(dp, dp->len + len);
memcpy(dp->buffer + old_len, data, len);
}
static int demux_asf_read_packet(demuxer_t *demux,unsigned char *data,int len,int id,int seq,uint64_t time,unsigned short dur,int offs,int keyframe){
struct asf_priv* asf = demux->priv;
demux_stream_t *ds=NULL;
int close_seg=0;
mp_dbg(MSGT_DEMUX,MSGL_DBG4,"demux_asf.read_packet: id=%d seq=%d len=%d\n",id,seq,len);
if(demux->video->id==-1)
if(demux->v_streams[id])
demux->video->id=id;
if(demux->audio->id==-1)
if(demux->a_streams[id])
demux->audio->id=id;
if(id==demux->audio->id){
// audio
ds=demux->audio;
if(!ds->sh){
ds->sh=demux->a_streams[id];
mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected ASF audio ID = %d\n",ds->id);
}
} else
if(id==demux->video->id){
// video
ds=demux->video;
if(!ds->sh){
ds->sh=demux->v_streams[id];
mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected ASF video ID = %d\n",ds->id);
}
}
if(ds){
if(ds->asf_packet){
demux_packet_t* dp=ds->asf_packet;
if (ds==demux->video && asf->asf_is_dvr_ms) {
if (asf->new_vid_frame_seg) {
dp->pos=demux->filepos;
close_seg = 1;
} else seq = ds->asf_seq;
} else close_seg = ds->asf_seq!=seq;
if(close_seg){
// closed segment, finalize packet:
if(ds==demux->audio)
if(asf->scrambling_h>1 && asf->scrambling_w>1 && asf->scrambling_b>0)
asf_descrambling(&ds->asf_packet->buffer,ds->asf_packet->len,asf);
ds_add_packet(ds,ds->asf_packet);
ds->asf_packet=NULL;
} else {
// append data to it!
demux_asf_append_to_packet(dp,data,len,offs);
// we are ready now.
return 1;
}
}
// create new packet:
{ demux_packet_t* dp;
if(offs>0){
mp_msg(MSGT_DEMUX,MSGL_V,"warning! broken fragment, %d bytes missing \n",offs);
return 0;
}
dp=new_demux_packet(len);
memcpy(dp->buffer,data,len);
if (asf->asf_is_dvr_ms)
dp->pts=time*0.0000001;
else
dp->pts=time*0.001;
dp->keyframe = keyframe;
// if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur);
dp->pos=demux->filepos;
ds->asf_packet=dp;
ds->asf_seq=seq;
// we are ready now.
return 1;
}
}
return 0;
}
/*****************************************************************
* \brief read the replicated data associated with each segment
* \parameter pp reference to replicated data
* \parameter id stream number
* \parameter seq media object number
* \parameter keyframe key frame indicator - set to zero if keyframe, non-zero otherwise
* \parameter seg_time set to payload time when valid, if audio or new video frame payload, zero otherwise
*
*/
static void get_payload_extension_data(demuxer_t *demux, unsigned char** pp, unsigned char id, unsigned int seq, int *keyframe, uint64_t *seg_time){
struct asf_priv* asf = demux->priv;
uint64_t payload_time = -1; //100ns units
int i, ext_max, ext_timing_index;
uint8_t *pi = *pp+4;
if(demux->video->id==-1)
if(demux->v_streams[id])
demux->video->id=id;
if(demux->audio->id==-1)
if(demux->a_streams[id])
demux->audio->id=id;
if (id!=demux->video->id && id!=demux->audio->id) return;
if (id==demux->video->id) {
ext_max = asf->vid_repdata_count;
ext_timing_index = asf->vid_ext_timing_index;
} else {
ext_max = asf->aud_repdata_count;
ext_timing_index = asf->aud_ext_timing_index;
}
*seg_time=0.0;
asf->new_vid_frame_seg = 0;
for (i=0; i<ext_max; i++) {
uint16_t payextsize;
uint8_t segment_marker;
if (id==demux->video->id)
payextsize = asf->vid_repdata_sizes[i];
else
payextsize = asf->aud_repdata_sizes[i];
if (payextsize == 65535) {
payextsize = AV_RL16(pi);
pi+=2;
}
// if this is the timing info extension then read the payload time
if (i == ext_timing_index)
payload_time = AV_RL64(pi+8);
// if this is the video frame info extension then
// set the keyframe indicator, the 'new frame segment' indicator
// and (initially) the 'frame time'
if (i == asf->vid_ext_frame_index && id==demux->video->id) {
segment_marker = pi[0];
// Known video stream segment_marker values that
// contain useful information:
//
// NTSC/ATSC (29.97fps): 0X4A 01001010
// 0X4B 01001011
// 0X49 01001001
//
// PAL/ATSC (25fps): 0X3A 00111010
// 0X3B 00111011
// 0X39 00111001
//
// ATSC progressive (29.97fps): 0X7A 01111010
// 0X7B 01111011
// 0X79 01111001
// 11111111
// ^ this is new video frame marker
//
// ^^^^ these bits indicate the framerate
// 0X4 is 29.97i, 0X3 is 25i, 0X7 is 29.97p, ???=25p
//
// ^^^ these bits indicate the frame type:
// 001 means I-frame
// 010 and 011 probably mean P and B
asf->new_vid_frame_seg = (0X08 & segment_marker) && seq != asf->last_vid_seq;
if (asf->new_vid_frame_seg) asf->last_vid_seq = seq;
if (asf->avg_vid_frame_time == 0) {
// set the average frame time initially (in 100ns units).
// This is based on what works for known samples.
// It can be extended if more samples of different types can be obtained.
if (((segment_marker & 0XF0) >> 4) == 4) {
asf->avg_vid_frame_time = (uint64_t)((1.001 / 30.0) * 10000000.0);
asf->know_frame_time=1;
} else if (((segment_marker & 0XF0) >> 4) == 3) {
asf->avg_vid_frame_time = (uint64_t)(0.04 * 10000000.0);
asf->know_frame_time=1;
} else if (((segment_marker & 0XF0) >> 4) == 6) {
asf->avg_vid_frame_time = (uint64_t)(0.02 * 10000000.0);
asf->know_frame_time=1;
} else if (((segment_marker & 0XF0) >> 4) == 7) {
asf->avg_vid_frame_time = (uint64_t)((1.001 / 60.0) * 10000000.0);
asf->know_frame_time=1;
} else {
// we dont know the frame time initially so
// make a guess and then recalculate as we go.
asf->avg_vid_frame_time = (uint64_t)((1.001 / 60.0) * 10000000.0);
asf->know_frame_time=0;
}
}
*keyframe = (asf->new_vid_frame_seg && (segment_marker & 0X07) == 1);
}
pi +=payextsize;
}
if (id==demux->video->id && asf->new_vid_frame_seg) {
asf->vid_frame_ct++;
// Some samples only have timings on key frames and
// the rest contain non-cronological timestamps. Interpolating
// the values between key frames works for all samples.
if (*keyframe) {
asf->found_first_key_frame=1;
if (!asf->know_frame_time && asf->last_key_payload_time > 0) {
// We dont know average frametime so recalculate.
// Giving precedence to the 'weight' of the existing
// average limits damage done to new value when there is
// a sudden time jump which happens occasionally.
asf->avg_vid_frame_time =
(0.9 * asf->avg_vid_frame_time) +
(0.1 * ((payload_time - asf->last_key_payload_time) / asf->vid_frame_ct));
}
asf->last_key_payload_time = payload_time;
asf->vid_frame_ct = 1;
*seg_time = payload_time;
} else
*seg_time = (asf->last_key_payload_time + (asf->avg_vid_frame_time * (asf->vid_frame_ct-1)));
}
if (id==demux->audio->id) {
if (payload_time != -1)
asf->last_aud_diff = payload_time - asf->last_aud_pts;
asf->last_aud_pts += asf->last_aud_diff;
*seg_time = asf->last_aud_pts;
}
}
//static int num_elementary_packets100=0;
//static int num_elementary_packets101=0;
// return value:
// 0 = EOF or no stream found
// 1 = successfully read a packet
static int demux_asf_fill_buffer(demuxer_t *demux, demux_stream_t *ds){
struct asf_priv* asf = demux->priv;
demux->filepos=stream_tell(demux->stream);
// Brodcast stream have movi_start==movi_end
// Better test ?
if((demux->movi_start < demux->movi_end) && (demux->filepos>=demux->movi_end)){
demux->stream->eof=1;
return 0;
}
stream_read(demux->stream,asf->packet,asf->packetsize);
if(demux->stream->eof) return 0; // EOF
if(asf->packetsize < 2) return 0; // Packet too short
{
unsigned char* p=asf->packet;
unsigned char* p_end=asf->packet+asf->packetsize;
unsigned char flags=p[0];
unsigned char segtype=p[1];
unsigned padding;
unsigned plen;
unsigned sequence av_unused;
unsigned long time av_unused = 0;
unsigned short duration=0;
int segs=1;
unsigned char segsizetype=0x80;
int seg=-1;
if( mp_msg_test(MSGT_DEMUX,MSGL_DBG2) ){
int i;
for(i=0;i<FFMIN(16, asf->packetsize);i++) printf(" %02X",asf->packet[i]);
printf("\n");
}
// skip ECC data if present by testing bit 7 of flags
// 1xxxbbbb -> ecc data present, skip bbbb byte(s)
// 0xxxxxxx -> payload parsing info starts
if (flags & 0x80)
{
p += (flags & 0x0f)+1;
if (p+1 >= p_end) return 0; // Packet too short
flags = p[0];
segtype = p[1];
}
//if(segtype!=0x5d) printf("Warning! packet[4] != 0x5d \n");
p+=2; // skip flags & segtype
// Read packet size (plen):
if(!check_varlen(p, p_end, flags>> 5)) return 0; // Not enough data
plen = read_varlen(&p, flags >> 5, 0);
// Read sequence:
if(!check_varlen(p, p_end, flags>> 1)) return 0; // Not enough data
sequence = read_varlen(&p, flags >> 1, 0);
// Read padding size (padding):
if(!check_varlen(p, p_end, flags>> 3)) return 0; // Not enough data
padding = read_varlen(&p, flags >> 3, 0);
if(((flags>>5)&3)!=0){
// Explicit (absoulte) packet size
mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Explicit packet size specified: %d \n",plen);
if(plen>asf->packetsize) mp_msg(MSGT_DEMUX,MSGL_V,"Warning! plen>packetsize! (%d>%d) \n",plen,asf->packetsize);
} else {
// Padding (relative) size
plen=asf->packetsize-padding;
}
// Read time & duration:
if (p+5 >= p_end) return 0; // Packet too short
time = AV_RL32(p); p+=4;
duration = AV_RL16(p); p+=2;
// Read payload flags:
if(flags&1){
// multiple sub-packets
if (p >= p_end) return 0; // Packet too short
segsizetype=p[0]>>6;
segs=p[0] & 0x3F;
++p;
}
mp_dbg(MSGT_DEMUX,MSGL_DBG4,"%08"PRIu64": flag=%02X segs=%d seq=%u plen=%u pad=%u time=%ld dur=%d\n",
(uint64_t)demux->filepos,flags,segs,sequence,plen,padding,time,duration);
for(seg=0;seg<segs;seg++){
//ASF_segmhdr_t* sh;
unsigned char streamno;
unsigned int seq;
unsigned int x; // offset or timestamp
unsigned int rlen;
//
int len;
uint64_t time2=0;
int keyframe=0;
if(p>=p_end) {
mp_msg(MSGT_DEMUX,MSGL_V,"Warning! invalid packet 1, aborting parsing...\n");
break;
}
if( mp_msg_test(MSGT_DEMUX,MSGL_DBG2) ){
int i;
printf("seg %d:",seg);
for(i=0;i<FFMIN(16, p_end - p);i++) printf(" %02X",p[i]);
printf("\n");
}
streamno=p[0]&0x7F;
if(p[0]&0x80) keyframe=1;
p++;
// Read media object number (seq):
if(!check_varlen(p, p_end, segtype >> 4)) break; // Not enough data
seq = read_varlen(&p, segtype >> 4, 0);
// Read offset or timestamp:
if(!check_varlen(p, p_end, segtype >> 2)) break; // Not enough data
x = read_varlen(&p, segtype >> 2, 0);
// Read replic.data len:
if(!check_varlen(p, p_end, segtype)) break; // Not enough data
rlen = read_varlen(&p, segtype, 0);
// printf("### rlen=%d \n",rlen);
if (rlen > p_end - p) {
mp_msg(MSGT_DEMUX, MSGL_V, "invalid rlen=%u\n", rlen);
break;
}
switch(rlen){
case 0x01: // 1 = special, means grouping
//printf("grouping: %02X \n",p[0]);
++p; // skip PTS delta
break;
default:
if(rlen>=8){
p+=4; // skip object size
if (p+3 >= p_end) break; // Packet too short
time2=AV_RL32(p); // read PTS
if (asf->asf_is_dvr_ms)
get_payload_extension_data(demux, &p, streamno, seq, &keyframe, &time2);
p+=rlen-4;
} else {
mp_msg(MSGT_DEMUX,MSGL_V,"unknown segment type (rlen): 0x%02X \n",rlen);
time2=0; // unknown
p+=rlen;
}
}
if(flags&1){
// multiple segments
if(!check_varlen(p, p_end, segsizetype)) break; // Not enough data
len = read_varlen(&p, segsizetype, plen-(p-asf->packet));
} else {
// single segment
len=plen-(p-asf->packet);
}
if(len<0 || (p+len)>p_end){
mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! segment len=%d\n",len);
len = p_end - p;
}
mp_dbg(MSGT_DEMUX,MSGL_DBG4," seg #%d: streamno=%d seq=%d type=%02X len=%d\n",seg,streamno,seq,rlen,len);
switch(rlen){
case 0x01:
// GROUPING:
//printf("ASF_parser: warning! grouping (flag=1) not yet supported!\n",len);
//printf(" total: %d \n",len);
while(len>0){
int len2=p[0];
p++;
//printf(" group part: %d bytes\n",len2);
if(len2 > len - 1 || len2 < 0) break; // Not enough data
len2 = FFMIN(len2, asf->packetsize);
demux_asf_read_packet(demux,p,len2,streamno,seq,x,duration,-1,keyframe);
p+=len2;
len-=len2+1;
++seq;
}
if(len!=0){
mp_msg(MSGT_DEMUX,MSGL_V,"ASF_parser: warning! groups total != len\n");
}
break;
default:
// NO GROUPING:
//printf("fragment offset: %d \n",sh->x);
if (len <= 0) break;
if (!asf->asf_is_dvr_ms || asf->found_first_key_frame) {
len = FFMIN(len, asf->packetsize);
demux_asf_read_packet(demux,p,len,streamno,seq,time2,duration,x,keyframe);
}
p+=len;
break;
}
} // for segs
return 1; // success
}
mp_msg(MSGT_DEMUX,MSGL_V,"%08"PRIX64": UNKNOWN TYPE %02X %02X %02X %02X %02X...\n",(int64_t)demux->filepos,asf->packet[0],asf->packet[1],asf->packet[2],asf->packet[3],asf->packet[4]);
return 0;
}
#include "stheader.h"
static void demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
struct asf_priv* asf = demuxer->priv;
demux_stream_t *d_audio=demuxer->audio;
demux_stream_t *d_video=demuxer->video;
sh_audio_t *sh_audio=d_audio->sh;
// sh_video_t *sh_video=d_video->sh;
//FIXME: OFF_T - didn't test ASF case yet (don't have a large asf...)
//FIXME: reports good or bad to steve@daviesfam.org please
//================= seek in ASF ==========================
float p_rate=asf->packetrate; // packets / sec
int64_t rel_seek_packs=(flags&SEEK_FACTOR)? // FIXME: int may be enough?
(rel_seek_secs*(demuxer->movi_end-demuxer->movi_start)/asf->packetsize):
(rel_seek_secs*p_rate);
int64_t rel_seek_bytes=rel_seek_packs*asf->packetsize;
int64_t newpos;
//printf("ASF: packs: %d duration: %d \n",(int)fileh.packets,*((int*)&fileh.duration));
// printf("ASF_seek: %d secs -> %d packs -> %d bytes \n",
// rel_seek_secs,rel_seek_packs,rel_seek_bytes);
newpos=((flags&SEEK_ABSOLUTE)?demuxer->movi_start:demuxer->filepos)+rel_seek_bytes;
if(newpos<0 || newpos<demuxer->movi_start) newpos=demuxer->movi_start;
// printf("\r -- asf: newpos=%d -- \n",newpos);
stream_seek(demuxer->stream,newpos);
if (asf->asf_is_dvr_ms) asf->dvr_last_vid_pts = 0.0f;
if (d_video->id >= 0)
ds_fill_buffer(d_video);
if(sh_audio){
ds_fill_buffer(d_audio);
}
if (d_video->id >= 0)
while(1){
if(sh_audio && !d_audio->eof){
float a_pts=d_audio->pts;
a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
// sync audio:
if (d_video->pts > a_pts){
skip_audio_frame(sh_audio);
// if(!ds_fill_buffer(d_audio)) sh_audio=NULL; // skip audio. EOF?
continue;
}
}
if (d_video->keyframe)
break;
if(!ds_fill_buffer(d_video)) break; // skip frame. EOF?
}
}
static int demux_asf_control(demuxer_t *demuxer,int cmd, void *arg){
struct asf_priv* asf = demuxer->priv;
/* demux_stream_t *d_audio=demuxer->audio;
demux_stream_t *d_video=demuxer->video;
sh_audio_t *sh_audio=d_audio->sh;
sh_video_t *sh_video=d_video->sh;
*/
switch(cmd) {
case DEMUXER_CTRL_GET_TIME_LENGTH:
*((double *)arg)=asf->movielength;
return DEMUXER_CTRL_OK;
default:
return DEMUXER_CTRL_NOTIMPL;
}
}
static demuxer_t* demux_open_asf(demuxer_t* demuxer)
{
struct asf_priv* asf = demuxer->priv;
sh_video_t *sh_video=NULL;
//---- ASF header:
if(!asf) return NULL;
init_priv(asf);
if (!read_asf_header(demuxer,asf))
return NULL;
stream_seek(demuxer->stream,demuxer->movi_start);
// demuxer->idx_pos=0;
// demuxer->endpos=avi_header.movi_end;
if(demuxer->video->id != -2) {
if(!ds_fill_buffer(demuxer->video)){
mp_msg(MSGT_DEMUXER, MSGL_WARN, "ASF: %s",
mp_gtext("No video stream found.\n"));
demuxer->video->sh=NULL;
//printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
} else {
sh_video=demuxer->video->sh;
sh_video->fps=1000.0f; sh_video->frametime=0.001f;
if (asf->asf_is_dvr_ms) {
sh_video->bih->biWidth = 0;
sh_video->bih->biHeight = 0;
}
}
}
if(demuxer->audio->id!=-2){
mp_tmsg(MSGT_DEMUXER,MSGL_V,"ASF: Searching for audio stream (id:%d).\n",demuxer->audio->id);
if(!ds_fill_buffer(demuxer->audio)){
mp_msg(MSGT_DEMUXER, MSGL_INFO, "ASF: %s",
mp_gtext("No audio stream found -> no sound.\n"));
demuxer->audio->sh=NULL;
}
}
if(!demuxer->stream->seek)
demuxer->seekable=0;
return demuxer;
}
static void demux_close_asf(demuxer_t *demuxer) {
struct asf_priv* asf = demuxer->priv;
if (!asf) return;
free(asf->aud_repdata_sizes);
free(asf->vid_repdata_sizes);
free(asf->packet);
free(asf);
}
const demuxer_desc_t demuxer_desc_asf = {
"ASF demuxer",
"asf",
"ASF",
"A'rpi",
"ASF, WMV, WMA",
DEMUXER_TYPE_ASF,
1, // safe autodetect
asf_check_header,
demux_asf_fill_buffer,
demux_open_asf,
demux_close_asf,
demux_seek_asf,
demux_asf_control
};

View File

@ -1,899 +0,0 @@
/*
* AVI file parser for DEMUXER v2.9
* Copyright (c) 2001 A'rpi/ESP-team
*
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "config.h"
#include "core/mp_msg.h"
#include "stream/stream.h"
#include "demux.h"
#include "stheader.h"
#include "aviheader.h"
extern const demuxer_desc_t demuxer_desc_avi_ni;
extern const demuxer_desc_t demuxer_desc_avi_nini;
// PTS: 0=interleaved 1=BPS-based
int pts_from_bps=1;
static void update_audio_block_size(demuxer_t *demux)
{
avi_priv_t *priv = demux->priv;
sh_audio_t *sh = demux->audio->sh;
if (!sh)
return;
priv->audio_block_size = sh->audio.dwSampleSize;
if (sh->wf) {
priv->audio_block_size = sh->wf->nBlockAlign;
if (!priv->audio_block_size) {
// for PCM audio we can calculate the blocksize:
if (sh->format == 1)
priv->audio_block_size = sh->wf->nChannels*(sh->wf->wBitsPerSample/8);
else
priv->audio_block_size = 1; // hope the best...
} else {
// workaround old mencoder bug:
if (sh->audio.dwSampleSize == 1 && sh->audio.dwScale == 1 &&
(sh->wf->nBlockAlign == 1152 || sh->wf->nBlockAlign == 576)) {
mp_tmsg(MSGT_DEMUX,MSGL_WARN,"AVI: Working around CBR-MP3 nBlockAlign header bug!\n");
priv->audio_block_size = 1;
}
}
}
}
// Select ds from ID
static demux_stream_t *demux_avi_select_stream(demuxer_t *demux,
unsigned int id)
{
int stream_id=avi_stream_id(id);
if(demux->video->id==-1)
if(demux->v_streams[stream_id])
demux->video->id=stream_id;
if(demux->audio->id==-1)
if(demux->a_streams[stream_id])
demux->audio->id=stream_id;
if(stream_id==demux->audio->id){
if(!demux->audio->sh){
demux->audio->sh=demux->a_streams[stream_id];
mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI audio ID = %d\n",demux->audio->id);
update_audio_block_size(demux);
}
return demux->audio;
}
if(stream_id==demux->video->id){
if(!demux->video->sh){
demux->video->sh=demux->v_streams[stream_id];
mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI video ID = %d\n",demux->video->id);
}
return demux->video;
}
if(id!=mmioFOURCC('J','U','N','K')){
// unknown
mp_msg(MSGT_DEMUX,MSGL_DBG2,"Unknown chunk: %.4s (%X)\n",(char *) &id,id);
//abort();
}
return NULL;
}
static int valid_fourcc(unsigned int id){
static const char valid[] = "0123456789abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
unsigned char* fcc=(unsigned char*)(&id);
return strchr(valid, fcc[0]) && strchr(valid, fcc[1]) &&
strchr(valid, fcc[2]) && strchr(valid, fcc[3]);
}
static int valid_stream_id(unsigned int id) {
unsigned char* fcc=(unsigned char*)(&id);
return fcc[0] >= '0' && fcc[0] <= '9' && fcc[1] >= '0' && fcc[1] <= '9' &&
((fcc[2] == 'w' && fcc[3] == 'b') || (fcc[2] == 'd' && fcc[3] == 'c'));
}
static int choose_chunk_len(unsigned int len1,unsigned int len2){
// len1 has a bit more priority than len2. len1!=len2
// Note: this is a first-idea-logic, may be wrong. comments welcomed.
// prefer small frames rather than 0
if(!len1) return (len2>0x80000) ? len1 : len2;
if(!len2) return (len1>0x100000) ? len2 : len1;
// choose the smaller value:
return (len1<len2)? len1 : len2;
}
static int demux_avi_read_packet(demuxer_t *demux,demux_stream_t *ds,unsigned int id,unsigned int len,int idxpos,int flags){
avi_priv_t *priv=demux->priv;
int skip;
float pts=0;
mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_avi.read_packet: %X\n",id);
if(ds==demux->audio){
if(priv->pts_corrected==0){
if(priv->pts_has_video){
// we have video pts now
float delay=0;
if(((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec)
delay=(float)priv->pts_corr_bytes/((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec;
mp_msg(MSGT_DEMUX,MSGL_V,"XXX initial v_pts=%5.3f a_pos=%d (%5.3f) \n",priv->avi_audio_pts,priv->pts_corr_bytes,delay);
//priv->pts_correction=-priv->avi_audio_pts+delay;
priv->pts_correction=delay-priv->avi_audio_pts;
priv->avi_audio_pts+=priv->pts_correction;
priv->pts_corrected=1;
} else
priv->pts_corr_bytes+=len;
}
if(pts_from_bps){
pts = priv->audio_block_no *
(float)((sh_audio_t*)demux->audio->sh)->audio.dwScale /
(float)((sh_audio_t*)demux->audio->sh)->audio.dwRate;
} else
pts=priv->avi_audio_pts; //+priv->pts_correction;
priv->avi_audio_pts=0;
// update blockcount:
priv->audio_block_no+=
(len+priv->audio_block_size-1)/priv->audio_block_size;
} else
if(ds==demux->video){
// video
if(priv->skip_video_frames>0){
// drop frame (seeking)
--priv->skip_video_frames;
ds=NULL;
}
pts = priv->avi_video_pts = priv->video_pack_no *
(float)((sh_video_t*)demux->video->sh)->video.dwScale /
(float)((sh_video_t*)demux->video->sh)->video.dwRate;
priv->avi_audio_pts=priv->avi_video_pts+priv->pts_correction;
priv->pts_has_video=1;
if(ds) ++priv->video_pack_no;
}
skip=(len+1)&(~1); // total bytes in this chunk
if(ds){
mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id);
ds_read_packet(ds,demux->stream,len,pts,idxpos,flags);
skip-=len;
}
skip = FFMAX(skip, 0);
if (avi_stream_id(id) > 99 && id != mmioFOURCC('J','U','N','K'))
skip = FFMIN(skip, 65536);
if(skip){
mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id);
stream_skip(demux->stream,skip);
}
return ds?1:0;
}
static uint32_t avi_find_id(stream_t *stream) {
uint32_t id = stream_read_dword_le(stream);
if (!id) {
mp_msg(MSGT_DEMUX, MSGL_WARN, "Incomplete stream? Trying resync.\n");
do {
id = stream_read_dword_le(stream);
if (stream_eof(stream)) return 0;
} while (avi_stream_id(id) > 99);
}
return id;
}
// return value:
// 0 = EOF or no stream found
// 1 = successfully read a packet
static int demux_avi_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){
avi_priv_t *priv=demux->priv;
unsigned int id=0;
unsigned int len;
int ret=0;
demux_stream_t *ds;
do{
int flags=1;
AVIINDEXENTRY *idx=NULL;
if(priv->idx_size>0 && priv->idx_pos<priv->idx_size){
int64_t pos;
idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++];
if(idx->dwFlags&AVIIF_LIST){
if (!valid_stream_id(idx->ckid))
// LIST
continue;
if (!priv->warned_unaligned)
mp_msg(MSGT_DEMUX, MSGL_WARN, "Looks like unaligned chunk in index, broken AVI file!\n");
priv->warned_unaligned = 1;
}
if(!demux_avi_select_stream(demux,idx->ckid)){
mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid);
continue; // skip this chunk
}
pos = (int64_t)priv->idx_offset+AVI_IDX_OFFSET(idx);
if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start) && (demux->stream->flags & MP_STREAM_SEEK)){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! idx=0x%"PRIX64" \n",(int64_t)pos);
continue;
}
stream_seek(demux->stream,pos);
demux->filepos=stream_tell(demux->stream);
id=stream_read_dword_le(demux->stream);
if(stream_eof(demux->stream)) return 0; // EOF!
if(id!=idx->ckid){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid);
if(valid_fourcc(idx->ckid))
id=idx->ckid; // use index if valid
else
if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
}
len=stream_read_dword_le(demux->stream);
if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :(
len=choose_chunk_len(idx->dwChunkLength,len);
}
if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0;
} else {
demux->filepos=stream_tell(demux->stream);
if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start && (demux->stream->flags & MP_STREAM_SEEK)){
demux->stream->eof=1;
return 0;
}
id=avi_find_id(demux->stream);
len=stream_read_dword_le(demux->stream);
if(stream_eof(demux->stream)) return 0; // EOF!
if(id==mmioFOURCC('L','I','S','T') || id==mmioFOURCC('R', 'I', 'F', 'F')){
id=stream_read_dword_le(demux->stream); // list or RIFF type
continue;
}
}
ds=demux_avi_select_stream(demux,id);
if(ds)
if(ds->packs+1>=MAX_PACKS || ds->bytes+len>=MAX_PACK_BYTES){
// this packet will cause a buffer overflow, switch to -ni mode!!!
mp_tmsg(MSGT_DEMUX,MSGL_WARN,"\nBadly interleaved AVI file detected - switching to --avi-ni mode...\n");
if(priv->idx_size>0){
// has index
demux->type=DEMUXER_TYPE_AVI_NI;
demux->desc=&demuxer_desc_avi_ni;
--priv->idx_pos; // hack
} else {
// no index
demux->type=DEMUXER_TYPE_AVI_NINI;
demux->desc=&demuxer_desc_avi_nini;
priv->idx_pos=demux->filepos; // hack
}
priv->idx_pos_v=priv->idx_pos_a=priv->idx_pos;
// quit now, we can't even (no enough buffer memory) read this packet :(
return -1;
}
ret=demux_avi_read_packet(demux,ds,id,len,priv->idx_pos-1,flags);
} while(ret!=1);
return 1;
}
// return value:
// 0 = EOF or no stream found
// 1 = successfully read a packet
static int demux_avi_fill_buffer_ni(demuxer_t *demux, demux_stream_t *ds)
{
avi_priv_t *priv=demux->priv;
unsigned int id=0;
unsigned int len;
int ret=0;
do{
int flags=1;
AVIINDEXENTRY *idx=NULL;
int idx_pos=0;
demux->filepos=stream_tell(demux->stream);
if(ds==demux->video) idx_pos=priv->idx_pos_v++; else
if(ds==demux->audio) idx_pos=priv->idx_pos_a++; else
idx_pos=priv->idx_pos++;
if(priv->idx_size>0 && idx_pos<priv->idx_size){
int64_t pos;
idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos];
if(idx->dwFlags&AVIIF_LIST){
if (!valid_stream_id(idx->ckid))
// LIST
continue;
if (!priv->warned_unaligned)
mp_msg(MSGT_DEMUX, MSGL_WARN, "Looks like unaligned chunk in index, broken AVI file!\n");
priv->warned_unaligned = 1;
}
if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){
mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid);
continue; // skip this chunk
}
pos = priv->idx_offset+AVI_IDX_OFFSET(idx);
if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start)){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! current=0x%"PRIX64" idx=0x%"PRIX64" \n",(int64_t)demux->filepos,(int64_t)pos);
continue;
}
stream_seek(demux->stream,pos);
id=stream_read_dword_le(demux->stream);
if(stream_eof(demux->stream)) return 0;
if(id!=idx->ckid){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid);
if(valid_fourcc(idx->ckid))
id=idx->ckid; // use index if valid
else
if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
}
len=stream_read_dword_le(demux->stream);
if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :(
len=choose_chunk_len(idx->dwChunkLength,len);
}
if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0;
} else return 0;
ret=demux_avi_read_packet(demux,demux_avi_select_stream(demux,id),id,len,idx_pos,flags);
} while(ret!=1);
return 1;
}
// return value:
// 0 = EOF or no stream found
// 1 = successfully read a packet
static int demux_avi_fill_buffer_nini(demuxer_t *demux, demux_stream_t *ds)
{
avi_priv_t *priv=demux->priv;
unsigned int id=0;
unsigned int len;
int ret=0;
int64_t *fpos=NULL;
if(ds==demux->video) fpos=&priv->idx_pos_v; else
if(ds==demux->audio) fpos=&priv->idx_pos_a; else
return 0;
stream_seek(demux->stream,fpos[0]);
do{
demux->filepos=stream_tell(demux->stream);
if(demux->filepos>=demux->movi_end && (demux->movi_end>demux->movi_start)){
ds->eof=1;
return 0;
}
id=avi_find_id(demux->stream);
len=stream_read_dword_le(demux->stream);
if(stream_eof(demux->stream)) return 0;
if(id==mmioFOURCC('L','I','S','T')){
id=stream_read_dword_le(demux->stream); // list type
continue;
}
if(id==mmioFOURCC('R','I','F','F')){
mp_msg(MSGT_DEMUX,MSGL_V,"additional RIFF header...\n");
id=stream_read_dword_le(demux->stream); // "AVIX"
continue;
}
if(ds==demux_avi_select_stream(demux,id)){
// read it!
ret=demux_avi_read_packet(demux,ds,id,len,priv->idx_pos-1,0);
} else {
// skip it!
int skip=(len+1)&(~1); // total bytes in this chunk
stream_skip(demux->stream,skip);
}
} while(ret!=1);
fpos[0]=stream_tell(demux->stream);
return 1;
}
// AVI demuxer parameters:
int index_mode=-1; // -1=untouched 0=don't use index 1=use (generate) index
int force_ni=0; // force non-interleaved AVI parsing
static demuxer_t* demux_open_avi(demuxer_t* demuxer){
demux_stream_t *d_audio=demuxer->audio;
demux_stream_t *d_video=demuxer->video;
sh_audio_t *sh_audio=NULL;
sh_video_t *sh_video=NULL;
avi_priv_t* priv=calloc(1, sizeof(avi_priv_t));
demuxer->priv=(void*)priv;
//---- AVI header:
read_avi_header(demuxer,(demuxer->stream->flags & MP_STREAM_SEEK_BW)?index_mode:-2);
update_audio_block_size(demuxer);
if(demuxer->audio->id>=0 && !demuxer->a_streams[demuxer->audio->id]){
mp_tmsg(MSGT_DEMUX,MSGL_WARN,"AVI: invalid audio stream ID: %d - ignoring (nosound)\n",demuxer->audio->id);
demuxer->audio->id=-2; // disabled
}
if(demuxer->video->id>=0 && !demuxer->v_streams[demuxer->video->id]){
mp_tmsg(MSGT_DEMUX,MSGL_WARN,"AVI: invalid video stream ID: %d - ignoring (using default)\n",demuxer->video->id);
demuxer->video->id=-1; // autodetect
}
stream_seek(demuxer->stream,demuxer->movi_start);
if(priv->idx_size>1){
// decide index format:
#if 1
if((AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start ||
AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[1])<demuxer->movi_start )&& !priv->isodml)
priv->idx_offset=demuxer->movi_start-4;
#else
if(AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start)
priv->idx_offset=demuxer->movi_start-4;
#endif
mp_msg(MSGT_DEMUX,MSGL_V,"AVI index offset: 0x%X (movi=0x%X idx0=0x%X idx1=0x%X)\n",
(int)priv->idx_offset,(int)demuxer->movi_start,
(int)((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset,
(int)((AVIINDEXENTRY *)priv->idx)[1].dwChunkOffset);
}
if(priv->idx_size>0){
// check that file is non-interleaved:
int i;
int64_t a_pos=-1;
int64_t v_pos=-1;
for(i=0;i<priv->idx_size;i++){
AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i];
demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
int64_t pos = priv->idx_offset + AVI_IDX_OFFSET(idx);
if(a_pos==-1 && ds==demuxer->audio){
a_pos=pos;
if(v_pos!=-1) break;
}
if(v_pos==-1 && ds==demuxer->video){
v_pos=pos;
if(a_pos!=-1) break;
}
}
if(v_pos==-1){
mp_msg(MSGT_DEMUX, MSGL_ERR, "AVI_NI: %s",
mp_gtext("No video stream found.\n"));
return NULL;
}
if(a_pos==-1){
d_audio->sh=sh_audio=NULL;
} else {
if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB
mp_tmsg(MSGT_DEMUX,MSGL_INFO,"%s NON-INTERLEAVED AVI file format.\n",force_ni?"Forced":"Detected");
demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!!
demuxer->desc=&demuxer_desc_avi_ni; // HACK!!!!
pts_from_bps=1; // force BPS sync!
}
}
} else {
// no index
if(force_ni){
mp_tmsg(MSGT_DEMUX,MSGL_INFO,"Using NON-INTERLEAVED broken AVI file format.\n");
demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!!
demuxer->desc=&demuxer_desc_avi_nini; // HACK!!!!
priv->idx_pos_a=
priv->idx_pos_v=demuxer->movi_start;
pts_from_bps=1; // force BPS sync!
}
demuxer->seekable=0;
}
if(!ds_fill_buffer(d_video)){
mp_msg(MSGT_DEMUX, MSGL_ERR, "AVI: %s",
mp_gtext("Missing video stream!? Contact the author, "
"it may be a bug :(\n"));
return NULL;
}
sh_video=d_video->sh;sh_video->ds=d_video;
if(d_audio->id!=-2){
mp_msg(MSGT_DEMUX,MSGL_V,"AVI: Searching for audio stream (id:%d)\n",d_audio->id);
if(!priv->audio_streams || !ds_fill_buffer(d_audio)){
mp_msg(MSGT_DEMUX, MSGL_INFO, "AVI: %s",
mp_gtext("No audio stream found -> no sound.\n"));
d_audio->sh=sh_audio=NULL;
} else {
sh_audio=d_audio->sh;sh_audio->ds=d_audio;
}
}
// calculating audio/video bitrate:
if(priv->idx_size>0){
// we have index, let's count 'em!
AVIINDEXENTRY *idx = priv->idx;
int64_t vsize=0;
int64_t asize=0;
size_t vsamples=0;
size_t asamples=0;
int i;
for(i=0;i<priv->idx_size;i++){
int id=avi_stream_id(idx[i].ckid);
unsigned len=idx[i].dwChunkLength;
if(sh_video->ds->id == id) {
vsize+=len;
++vsamples;
}
else if(sh_audio && sh_audio->ds->id == id) {
asize+=len;
asamples+=(len+priv->audio_block_size-1)/priv->audio_block_size;
}
}
mp_msg(MSGT_DEMUX, MSGL_V,
"AVI video size=%"PRId64" (%zu) audio size=%"PRId64" (%zu)\n",
vsize, vsamples, asize, asamples);
priv->numberofframes=vsamples;
sh_video->i_bps=((float)vsize/(float)vsamples)*(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
if(sh_audio) sh_audio->i_bps=((float)asize/(float)asamples)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
} else {
// guessing, results may be inaccurate:
int64_t vsize;
int64_t asize=0;
if((priv->numberofframes=sh_video->video.dwLength)<=1)
// bad video header, try to get number of frames from audio
if(sh_audio && sh_audio->wf->nAvgBytesPerSec) priv->numberofframes=sh_video->fps*sh_audio->audio.dwLength/sh_audio->audio.dwRate*sh_audio->audio.dwScale;
if(priv->numberofframes<=1){
mp_tmsg(MSGT_SEEK,MSGL_WARN,"Could not determine number of frames (for absolute seek).\n");
priv->numberofframes=0;
}
if(sh_audio){
if(sh_audio->wf->nAvgBytesPerSec && sh_audio->audio.dwSampleSize!=1){
asize=(float)sh_audio->wf->nAvgBytesPerSec*sh_audio->audio.dwLength*sh_audio->audio.dwScale/sh_audio->audio.dwRate;
} else {
asize=sh_audio->audio.dwLength;
sh_audio->i_bps=(float)asize/(sh_video->frametime*priv->numberofframes);
}
}
vsize=demuxer->movi_end-demuxer->movi_start-asize-8*priv->numberofframes;
mp_msg(MSGT_DEMUX,MSGL_V,"AVI video size=%"PRId64" (%u) audio size=%"PRId64"\n",vsize,priv->numberofframes,asize);
sh_video->i_bps=(float)vsize/(sh_video->frametime*priv->numberofframes);
}
return demuxer;
}
static void demux_seek_avi(demuxer_t *demuxer, float rel_seek_secs,
float audio_delay, int flags)
{
avi_priv_t *priv=demuxer->priv;
demux_stream_t *d_audio=demuxer->audio;
demux_stream_t *d_video=demuxer->video;
sh_audio_t *sh_audio=d_audio->sh;
sh_video_t *sh_video=d_video->sh;
float skip_audio_secs=0;
//FIXME: OFF_T - Didn't check AVI case yet (avi files can't be >2G anyway?)
//================= seek in AVI ==========================
int rel_seek_frames=rel_seek_secs*sh_video->fps;
int video_chunk_pos=d_video->pos;
int i;
if(flags&SEEK_ABSOLUTE){
// seek absolute
video_chunk_pos=0;
}
if(flags&SEEK_FACTOR){
rel_seek_frames=rel_seek_secs*priv->numberofframes;
}
priv->skip_video_frames=0;
priv->avi_audio_pts=0;
// ------------ STEP 1: find nearest video keyframe chunk ------------
// find nearest video keyframe chunk pos:
if(rel_seek_frames>0){
// seek forward
while(video_chunk_pos<priv->idx_size-1){
int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
if(avi_stream_id(id)==d_video->id){ // video frame
if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
}
++video_chunk_pos;
}
} else {
// seek backward
while(video_chunk_pos>0){
int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
if(avi_stream_id(id)==d_video->id){ // video frame
if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
}
--video_chunk_pos;
}
}
priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=video_chunk_pos;
// re-calc video pts:
d_video->pack_no=0;
for(i=0;i<video_chunk_pos;i++){
int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
if(avi_stream_id(id)==d_video->id) ++d_video->pack_no;
}
priv->video_pack_no=d_video->pack_no;
priv->avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
d_video->pos=video_chunk_pos;
mp_msg(MSGT_SEEK,MSGL_DBG2,"V_SEEK: pack=%d pts=%5.3f chunk=%d \n",d_video->pack_no,priv->avi_video_pts,video_chunk_pos);
// ------------ STEP 2: seek audio, find the right chunk & pos ------------
d_audio->pack_no=0;
priv->audio_block_no=0;
d_audio->dpos=0;
if(sh_audio){
int i;
int len=0;
int skip_audio_bytes=0;
int curr_audio_pos=-1;
int audio_chunk_pos=-1;
int chunk_max=(demuxer->type==DEMUXER_TYPE_AVI)?video_chunk_pos:priv->idx_size;
if(sh_audio->audio.dwSampleSize){
// constant rate audio stream
/* immediate seeking to audio position, including when streams are delayed */
curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
curr_audio_pos*=sh_audio->audio.dwSampleSize;
// find audio chunk pos:
for(i=0;i<chunk_max;i++){
int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
if(avi_stream_id(id)==d_audio->id){
len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){
break;
}
++d_audio->pack_no;
priv->audio_block_no+=
(len+priv->audio_block_size-1)/priv->audio_block_size;
d_audio->dpos+=len;
}
}
audio_chunk_pos=i;
skip_audio_bytes=curr_audio_pos-d_audio->dpos;
mp_msg(MSGT_SEEK,MSGL_V,"SEEK: i=%d (max:%d) dpos=%d (wanted:%d) \n",
i,chunk_max,(int)d_audio->dpos,curr_audio_pos);
} else {
// VBR audio
/* immediate seeking to audio position, including when streams are delayed */
int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
audio_chunk_pos=0;
// find audio chunk pos:
for(i=0;i<priv->idx_size && chunks>0;i++){
int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
if(avi_stream_id(id)==d_audio->id){
len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
if(i>chunk_max){
skip_audio_bytes+=len;
} else {
++d_audio->pack_no;
priv->audio_block_no+=
(len+priv->audio_block_size-1)/priv->audio_block_size;
d_audio->dpos+=len;
audio_chunk_pos=i;
}
chunks-=(len+priv->audio_block_size-1)/priv->audio_block_size;
}
}
}
// Now we have:
// audio_chunk_pos = chunk no in index table (it's <=chunk_max)
// skip_audio_bytes = bytes to be skipped after chunk seek
// d-audio->pack_no = chunk_no in stream at audio_chunk_pos
// d_audio->dpos = bytepos in stream at audio_chunk_pos
// let's seek!
// update stream position:
d_audio->pos=audio_chunk_pos;
if(demuxer->type==DEMUXER_TYPE_AVI){
// interleaved stream:
if(audio_chunk_pos<video_chunk_pos){
// calc priv->skip_video_frames & adjust video pts counter:
for(i=audio_chunk_pos;i<video_chunk_pos;i++){
int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
if(avi_stream_id(id)==d_video->id) ++priv->skip_video_frames;
}
// requires for correct audio pts calculation (demuxer):
priv->avi_video_pts-=priv->skip_video_frames*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
priv->avi_audio_pts=priv->avi_video_pts;
// set index position:
priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=audio_chunk_pos;
}
} else {
// non-interleaved stream:
priv->idx_pos_a=audio_chunk_pos;
priv->idx_pos_v=video_chunk_pos;
priv->idx_pos=(audio_chunk_pos<video_chunk_pos)?audio_chunk_pos:video_chunk_pos;
}
mp_msg(MSGT_SEEK,MSGL_V,"SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n",
(int)priv->idx_pos,audio_chunk_pos,video_chunk_pos,
(int)priv->skip_video_frames,skip_audio_bytes,skip_audio_secs);
if(skip_audio_bytes){
demux_read_data(d_audio,NULL,skip_audio_bytes);
}
}
d_video->pts=priv->avi_video_pts; // OSD
}
static void demux_close_avi(demuxer_t *demuxer)
{
avi_priv_t* priv=demuxer->priv;
if(!priv)
return;
if(priv->idx_size > 0)
free(priv->idx);
free(priv);
}
static int demux_avi_control(demuxer_t *demuxer,int cmd, void *arg){
avi_priv_t *priv=demuxer->priv;
demux_stream_t *d_video=demuxer->video;
sh_video_t *sh_video=d_video->sh;
switch(cmd) {
case DEMUXER_CTRL_GET_TIME_LENGTH:
if (!priv->numberofframes || !sh_video) return DEMUXER_CTRL_DONTKNOW;
*((double *)arg)=(double)priv->numberofframes/sh_video->fps;
if (sh_video->video.dwLength<=1) return DEMUXER_CTRL_GUESS;
return DEMUXER_CTRL_OK;
case DEMUXER_CTRL_SWITCH_AUDIO:
case DEMUXER_CTRL_SWITCH_VIDEO: {
int audio = (cmd == DEMUXER_CTRL_SWITCH_AUDIO);
demux_stream_t *ds = audio ? demuxer->audio : demuxer->video;
void **streams = audio ? (void **)demuxer->a_streams : (void **)demuxer->v_streams;
int maxid = FFMIN(100, audio ? MAX_A_STREAMS : MAX_V_STREAMS);
int chunkid;
if (ds->id < -1)
ds->id = -1;
if (*(int *)arg >= 0)
ds->id = *(int *)arg;
else {
int i;
for (i = 0; i < maxid; i++) {
if (++ds->id >= maxid) ds->id = 0;
if (streams[ds->id]) break;
}
}
chunkid = (ds->id / 10 + '0') | (ds->id % 10 + '0') << 8;
ds->sh = NULL;
if (!streams[ds->id]) // stream not available
ds->id = -1;
else
demux_avi_select_stream(demuxer, chunkid);
*(int *)arg = ds->id;
return DEMUXER_CTRL_OK;
}
default:
return DEMUXER_CTRL_NOTIMPL;
}
}
static int avi_check_file(demuxer_t *demuxer)
{
int id=stream_read_dword_le(demuxer->stream); // "RIFF"
if((id==mmioFOURCC('R','I','F','F')) || (id==mmioFOURCC('O','N','2',' '))) {
stream_read_dword_le(demuxer->stream); //filesize
id=stream_read_dword_le(demuxer->stream); // "AVI "
if(id==formtypeAVI)
return DEMUXER_TYPE_AVI;
// "Samsung Digimax i6 PMP" crap according to bug 742
if(id==mmioFOURCC('A','V','I',0x19))
return DEMUXER_TYPE_AVI;
if(id==mmioFOURCC('O','N','2','f')){
mp_tmsg(MSGT_DEMUXER,MSGL_INFO,"ON2 AVI format");
return DEMUXER_TYPE_AVI;
}
}
return 0;
}
const demuxer_desc_t demuxer_desc_avi = {
"AVI demuxer",
"avi",
"AVI",
"Arpi?",
"AVI files, including non interleaved files",
DEMUXER_TYPE_AVI,
1, // safe autodetect
avi_check_file,
demux_avi_fill_buffer,
demux_open_avi,
demux_close_avi,
demux_seek_avi,
demux_avi_control
};
const demuxer_desc_t demuxer_desc_avi_ni = {
"AVI demuxer, non-interleaved",
"avini",
"AVI",
"Arpi?",
"AVI files, including non interleaved files",
DEMUXER_TYPE_AVI,
1, // safe autodetect
avi_check_file,
demux_avi_fill_buffer_ni,
demux_open_avi,
demux_close_avi,
demux_seek_avi,
demux_avi_control
};
const demuxer_desc_t demuxer_desc_avi_nini = {
"AVI demuxer, non-interleaved and no index",
"avinini",
"AVI",
"Arpi?",
"AVI files, including non interleaved files",
DEMUXER_TYPE_AVI,
1, // safe autodetect
avi_check_file,
demux_avi_fill_buffer_nini,
demux_open_avi,
demux_close_avi,
demux_seek_avi,
demux_avi_control
};

View File

@ -510,7 +510,7 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
if (opts->user_correct_pts != 0)
avfc->flags |= AVFMT_FLAG_GENPTS;
}
if (index_mode == 0)
if (opts->index_mode == 0)
avfc->flags |= AVFMT_FLAG_IGNIDX;
if (lavfdopts->probesize) {

View File

@ -722,10 +722,11 @@ static void add_block_position(demuxer_t *demuxer, struct mkv_track *track,
static int demux_mkv_read_cues(demuxer_t *demuxer)
{
struct MPOpts *opts = demuxer->opts;
mkv_demuxer_t *mkv_d = (mkv_demuxer_t *) demuxer->priv;
stream_t *s = demuxer->stream;
if (index_mode == 0 || index_mode == 2) {
if (opts->index_mode == 0 || opts->index_mode == 2) {
ebml_read_skip(s, NULL);
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +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_DEMUX_TS_H
#define MPLAYER_DEMUX_TS_H
#define TS_MAX_PROBE_SIZE 2000000
#endif /* MPLAYER_DEMUX_TS_H */

View File

@ -38,17 +38,17 @@ static struct {
const char *extension;
int demuxer_type;
} extensions_table[] = {
{ "vob", DEMUXER_TYPE_MPEG_PS },
{ "m2v", DEMUXER_TYPE_MPEG_PS },
{ "avi", DEMUXER_TYPE_AVI },
{ "asx", DEMUXER_TYPE_ASF },
{ "asf", DEMUXER_TYPE_ASF },
{ "wmv", DEMUXER_TYPE_ASF },
{ "wma", DEMUXER_TYPE_ASF },
{ "vob", DEMUXER_TYPE_LAVF },
{ "m2v", DEMUXER_TYPE_LAVF },
{ "avi", DEMUXER_TYPE_LAVF },
{ "asx", DEMUXER_TYPE_LAVF },
{ "asf", DEMUXER_TYPE_LAVF },
{ "wmv", DEMUXER_TYPE_LAVF },
{ "wma", DEMUXER_TYPE_LAVF },
{ "rm", DEMUXER_TYPE_LAVF },
{ "rmvb", DEMUXER_TYPE_LAVF },
{ "ra", DEMUXER_TYPE_LAVF },
{ "y4m", DEMUXER_TYPE_Y4M },
{ "y4m", DEMUXER_TYPE_LAVF },
{ "mp3", DEMUXER_TYPE_LAVF },
{ "wav", DEMUXER_TYPE_LAVF },
{ "flac", DEMUXER_TYPE_LAVF },
@ -63,12 +63,9 @@ static struct {
{ "it", DEMUXER_TYPE_LAVF },
{ "mid", DEMUXER_TYPE_LAVF },
{ "midi", DEMUXER_TYPE_LAVF },
{ "nsv", DEMUXER_TYPE_NSV },
{ "nsa", DEMUXER_TYPE_NSV },
{ "mpc", DEMUXER_TYPE_MPC },
#ifdef CONFIG_WIN32DLL
{ "avs", DEMUXER_TYPE_AVS },
#endif
{ "nsv", DEMUXER_TYPE_LAVF },
{ "nsa", DEMUXER_TYPE_LAVF },
{ "mpc", DEMUXER_TYPE_LAVF },
{ "302", DEMUXER_TYPE_LAVF },
{ "264", DEMUXER_TYPE_LAVF },
{ "26l", DEMUXER_TYPE_LAVF },

View File

@ -1,144 +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 <stdio.h>
#include "config.h"
#include "mp3_hdr.h"
#include "core/mp_msg.h"
//----------------------- mp3 audio frame header parser -----------------------
static int tabsel_123[2][3][16] = {
{ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0},
{0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0},
{0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0} },
{ {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,0},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,0} }
};
static long freqs[9] = { 44100, 48000, 32000, // MPEG 1.0
22050, 24000, 16000, // MPEG 2.0
11025, 12000, 8000}; // MPEG 2.5
/*
* return frame size or -1 (bad frame)
*/
int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* srate, int* spf, int* mpa_layer, int* br){
int stereo,ssize,lsf,framesize,padding,bitrate_index,sampling_frequency, divisor;
int bitrate;
int layer, mult[3] = { 12000, 144000, 144000 };
unsigned long newhead =
hbuf[0] << 24 |
hbuf[1] << 16 |
hbuf[2] << 8 |
hbuf[3];
// printf("head=0x%08X\n",newhead);
// head_check:
if( (newhead & 0xffe00000) != 0xffe00000 ){
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"head_check failed\n");
return -1;
}
layer = 4-((newhead>>17)&3);
if(layer==4){
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"not layer-1/2/3\n");
return -1;
}
sampling_frequency = ((newhead>>10)&0x3); // valid: 0..2
if(sampling_frequency==3){
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid sampling_frequency\n");
return -1;
}
if( newhead & ((long)1<<20) ) {
// MPEG 1.0 (lsf==0) or MPEG 2.0 (lsf==1)
lsf = (newhead & ((long)1<<19)) ? 0x0 : 0x1;
sampling_frequency += (lsf*3);
} else {
// MPEG 2.5
lsf = 1;
sampling_frequency += 6;
}
// crc = ((newhead>>16)&0x1)^0x1;
bitrate_index = ((newhead>>12)&0xf); // valid: 1..14
padding = ((newhead>>9)&0x1);
// fr->extension = ((newhead>>8)&0x1);
// fr->mode = ((newhead>>6)&0x3);
// fr->mode_ext = ((newhead>>4)&0x3);
// fr->copyright = ((newhead>>3)&0x1);
// fr->original = ((newhead>>2)&0x1);
// fr->emphasis = newhead & 0x3;
stereo = ( (((newhead>>6)&0x3)) == 3) ? 1 : 2;
// !checked later through tabsel_123[]!
// if(!bitrate_index || bitrate_index==15){
// mp_msg(MSGT_DEMUXER,MSGL_DBG2,"Free format not supported.\n");
// return -1;
// }
if(lsf)
ssize = (stereo == 1) ? 9 : 17;
else
ssize = (stereo == 1) ? 17 : 32;
if(!((newhead>>16)&0x1)) ssize += 2; // CRC
bitrate = tabsel_123[lsf][layer-1][bitrate_index];
framesize = bitrate * mult[layer-1];
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"FRAMESIZE: %d, layer: %d, bitrate: %d, mult: %d\n",
framesize, layer, tabsel_123[lsf][layer-1][bitrate_index], mult[layer-1]);
if(!framesize){
mp_msg(MSGT_DEMUXER,MSGL_DBG2,"invalid framesize/bitrate_index\n");
return -1;
}
divisor = (layer == 3 ? (freqs[sampling_frequency] << lsf) : freqs[sampling_frequency]);
framesize /= divisor;
if(layer==1)
framesize = (framesize+padding)*4;
else
framesize += padding;
// if(framesize<=0 || framesize>MAXFRAMESIZE) return FALSE;
if(srate) {
*srate = freqs[sampling_frequency];
if(spf) {
if(layer == 1)
*spf = 384;
else if(layer == 2)
*spf = 1152;
else if(*srate < 32000)
*spf = 576;
else
*spf = 1152;
}
}
if(mpa_layer) *mpa_layer = layer;
if(chans) *chans = stereo;
if(br) *br = bitrate;
return framesize;
}

View File

@ -1,36 +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_MP3_HDR_H
#define MPLAYER_MP3_HDR_H
#include <stddef.h>
int mp_get_mp3_header(unsigned char* hbuf,int* chans, int* freq, int* spf, int* mpa_layer, int* br);
#define mp_decode_mp3_header(hbuf) mp_get_mp3_header(hbuf,NULL,NULL,NULL,NULL,NULL)
static inline int mp_check_mp3_header(unsigned int head){
unsigned char tmp[4] = {head >> 24, head >> 16, head >> 8, head};
if( (head & 0xffe00000) != 0xffe00000 ||
(head & 0x00000c00) == 0x00000c00) return 0;
if(mp_decode_mp3_header(tmp)<=0) return 0;
return 1;
}
#endif /* MPLAYER_MP3_HDR_H */

View File

@ -1,539 +0,0 @@
/*
* based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
*
* 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 <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mpeg_hdr.h"
#include "libavutil/attributes.h"
#include "core/mp_msg.h"
static float frameratecode2framerate[16] = {
0,
// Official mpeg1/2 framerates: (1-8)
24000.0/1001, 24,25,
30000.0/1001, 30,50,
60000.0/1001, 60,
// Xing's 15fps: (9)
15,
// libmpeg3's "Unofficial economy rates": (10-13)
5,10,12,15,
// some invalid ones: (14-15)
0,0
};
int mp_header_process_sequence_header (mp_mpeg_header_t * picture, const unsigned char * buffer)
{
int height;
if ((buffer[6] & 0x20) != 0x20){
fprintf(stderr, "missing marker bit!\n");
return 1; /* missing marker_bit */
}
height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
picture->display_picture_width = height >> 12;
picture->display_picture_height = height & 0xfff;
picture->aspect_ratio_information = buffer[3] >> 4;
picture->frame_rate_code = buffer[3] & 15;
picture->fps=frameratecode2framerate[picture->frame_rate_code];
picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
picture->mpeg1 = 1;
picture->picture_structure = 3; //FRAME_PICTURE;
picture->display_time=100;
picture->frame_rate_extension_n = 1;
picture->frame_rate_extension_d = 1;
return 0;
}
static int header_process_sequence_extension (mp_mpeg_header_t * picture,
unsigned char * buffer)
{
/* check chroma format, size extensions, marker bit */
if ( ((buffer[1] & 0x06) == 0x00) ||
((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) ||
((buffer[3] & 0x01) != 0x01) )
return 1;
picture->progressive_sequence = (buffer[1] >> 3) & 1;
picture->frame_rate_extension_n = ((buffer[5] >> 5) & 3) + 1;
picture->frame_rate_extension_d = (buffer[5] & 0x1f) + 1;
picture->mpeg1 = 0;
return 0;
}
static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
{
picture->picture_structure = buffer[2] & 3;
picture->top_field_first = buffer[3] >> 7;
picture->repeat_first_field = (buffer[3] >> 1) & 1;
picture->progressive_frame = buffer[4] >> 7;
// repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
picture->display_time=100;
if(picture->repeat_first_field){
if(picture->progressive_sequence){
if(picture->top_field_first)
picture->display_time+=200;
else
picture->display_time+=100;
} else
if(picture->progressive_frame){
picture->display_time+=50;
}
}
//temopral hack. We calc time on every field, so if we have 2 fields
// interlaced we'll end with double time for 1 frame
if( picture->picture_structure!=3 ) picture->display_time/=2;
return 0;
}
int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
{
switch (buffer[0] & 0xf0) {
case 0x10: /* sequence extension */
return header_process_sequence_extension (picture, buffer);
case 0x80: /* picture coding extension */
return header_process_picture_coding_extension (picture, buffer);
}
return 0;
}
float mpeg12_aspect_info(mp_mpeg_header_t *picture)
{
float aspect = 0.0;
switch(picture->aspect_ratio_information) {
case 2: // PAL/NTSC SVCD/DVD 4:3
case 8: // PAL VCD 4:3
case 12: // NTSC VCD 4:3
aspect=4.0/3.0;
break;
case 3: // PAL/NTSC Widescreen SVCD/DVD 16:9
case 6: // (PAL?)/NTSC Widescreen SVCD 16:9
aspect=16.0/9.0;
break;
case 4: // according to ISO-138182-2 Table 6.3
aspect=2.21;
break;
case 1: // VGA 1:1 - do not prescale
case 9: // Movie Type ??? / 640x480
aspect=0.0;
break;
default:
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Detected unknown aspect_ratio_information in mpeg sequence header.\n"
"Please report the aspect value (%i) along with the movie type (VGA,PAL,NTSC,"
"SECAM) and the movie resolution (720x576,352x240,480x480,...) to the MPlayer"
" developers, so that we can add support for it!\nAssuming 1:1 aspect for now.\n",
picture->aspect_ratio_information);
}
return aspect;
}
//MPEG4 HEADERS
unsigned char mp_getbits(unsigned char *buffer, unsigned int from, unsigned char len)
{
unsigned int n;
unsigned char m, u, l, y;
n = from / 8;
m = from % 8;
u = 8 - m;
l = (len > u ? len - u : 0);
y = (buffer[n] << m);
if(8 > len)
y >>= (8-len);
if(l)
y |= (buffer[n+1] >> (8-l));
//fprintf(stderr, "GETBITS(%d -> %d): bytes=0x%x 0x%x, n=%d, m=%d, l=%d, u=%d, Y=%d\n",
// from, (int) len, (int) buffer[n],(int) buffer[n+1], n, (int) m, (int) l, (int) u, (int) y);
return y;
}
static inline unsigned int mp_getbits16(unsigned char *buffer, unsigned int from, unsigned char len)
{
if(len > 8)
return (mp_getbits(buffer, from, len - 8) << 8) | mp_getbits(buffer, from + len - 8, 8);
else
return mp_getbits(buffer, from, len);
}
#define getbits mp_getbits
#define getbits16 mp_getbits16
static int read_timeinc(mp_mpeg_header_t * picture, unsigned char * buffer, int n)
{
if(picture->timeinc_bits > 8) {
picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits - 8) << 8;
n += picture->timeinc_bits - 8;
picture->timeinc_unit |= getbits(buffer, n, 8);
n += 8;
} else {
picture->timeinc_unit = getbits(buffer, n, picture->timeinc_bits);
n += picture->timeinc_bits;
}
//fprintf(stderr, "TIMEINC2: %d, bits: %d\n", picture->timeinc_unit, picture->timeinc_bits);
return n;
}
int mp4_header_process_vol(mp_mpeg_header_t * picture, unsigned char * buffer)
{
unsigned int n, aspect=0, aspectw av_unused=0, aspecth av_unused=0, x=1, v;
//begins with 0x0000012x
picture->fps = 0;
picture->timeinc_bits = picture->timeinc_resolution = picture->timeinc_unit = 0;
n = 9;
if(getbits(buffer, n, 1))
n += 7;
n++;
aspect=getbits(buffer, n, 4);
n += 4;
if(aspect == 0x0f) {
aspectw = getbits(buffer, n, 8);
n += 8;
aspecth = getbits(buffer, n, 8);
n += 8;
}
if(getbits(buffer, n, 1)) {
n += 4;
if(getbits(buffer, n, 1))
n += 79;
n++;
} else n++;
n+=3;
picture->timeinc_resolution = getbits(buffer, n, 8) << 8;
n += 8;
picture->timeinc_resolution |= getbits(buffer, n, 8);
n += 8;
picture->timeinc_bits = 0;
v = picture->timeinc_resolution - 1;
while(v && (x<16)) {
v>>=1;
picture->timeinc_bits++;
}
picture->timeinc_bits = (picture->timeinc_bits > 1 ? picture->timeinc_bits : 1);
n++; //marker bit
if(getbits(buffer, n++, 1)) { //fixed_vop_timeinc
n += read_timeinc(picture, buffer, n);
if(picture->timeinc_unit)
picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit;
}
n++; //marker bit
picture->display_picture_width = getbits16(buffer, n, 13);
n += 13;
n++; //marker bit
picture->display_picture_height = getbits16(buffer, n, 13);
n += 13;
//fprintf(stderr, "ASPECT: %d, PARW=%d, PARH=%d, TIMEINCRESOLUTION: %d, FIXED_TIMEINC: %d (number of bits: %d), FPS: %u\n",
// aspect, aspectw, aspecth, picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_bits, picture->fps);
return 0;
}
void mp4_header_process_vop(mp_mpeg_header_t * picture, unsigned char * buffer)
{
int n;
n = 0;
picture->picture_type = getbits(buffer, n, 2);
n += 2;
while(getbits(buffer, n, 1))
n++;
n++;
getbits(buffer, n, 1);
n++;
n += read_timeinc(picture, buffer, n);
}
#define min(a, b) ((a) <= (b) ? (a) : (b))
static unsigned int read_golomb(unsigned char *buffer, unsigned int *init)
{
unsigned int x, v = 0, v2 = 0, m, len = 0, n = *init;
while(getbits(buffer, n++, 1) == 0)
len++;
x = len + n;
while(n < x)
{
m = min(x - n, 8);
v |= getbits(buffer, n, m);
n += m;
if(x - n > 8)
v <<= 8;
}
v2 = 1;
for(n = 0; n < len; n++)
v2 <<= 1;
v2 = (v2 - 1) + v;
//fprintf(stderr, "READ_GOLOMB(%u), V=2^%u + %u-1 = %u\n", *init, len, v, v2);
*init = x;
return v2;
}
inline static int read_golomb_s(unsigned char *buffer, unsigned int *init)
{
unsigned int v = read_golomb(buffer, init);
return (v & 1) ? ((v + 1) >> 1) : -(v >> 1);
}
static int h264_parse_vui(mp_mpeg_header_t * picture, unsigned char * buf, unsigned int n)
{
unsigned int overscan, vsp_color, chroma, timing, fixed_fps;
if(getbits(buf, n++, 1))
{
picture->aspect_ratio_information = getbits(buf, n, 8);
n += 8;
if(picture->aspect_ratio_information == 255)
{
picture->display_picture_width = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8);
n += 16;
picture->display_picture_height = (getbits(buf, n, 8) << 8) | getbits(buf, n + 8, 8);
n += 16;
}
}
if((overscan=getbits(buf, n++, 1)))
n++;
if((vsp_color=getbits(buf, n++, 1)))
{
n += 4;
if(getbits(buf, n++, 1))
n += 24;
}
if((chroma=getbits(buf, n++, 1)))
{
read_golomb(buf, &n);
read_golomb(buf, &n);
}
if((timing=getbits(buf, n++, 1)))
{
picture->timeinc_unit = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8);
n += 32;
picture->timeinc_resolution = (getbits(buf, n, 8) << 24) | (getbits(buf, n+8, 8) << 16) | (getbits(buf, n+16, 8) << 8) | getbits(buf, n+24, 8);
n += 32;
fixed_fps = getbits(buf, n, 1);
if(picture->timeinc_unit > 0 && picture->timeinc_resolution > 0)
picture->fps = (float) picture->timeinc_resolution / (float) picture->timeinc_unit;
if(fixed_fps)
picture->fps /= 2;
}
//fprintf(stderr, "H264_PARSE_VUI, OVESCAN=%u, VSP_COLOR=%u, CHROMA=%u, TIMING=%u, DISPW=%u, DISPH=%u, TIMERES=%u, TIMEINC=%u, FIXED_FPS=%u\n", overscan, vsp_color, chroma, timing, picture->display_picture_width, picture->display_picture_height,
// picture->timeinc_resolution, picture->timeinc_unit, picture->timeinc_unit, fixed_fps);
return n;
}
static int mp_unescape03(unsigned char *buf, int len)
{
unsigned char *dest;
int i, j, skip;
dest = malloc(len);
if(! dest)
return 0;
j = i = skip = 0;
while(i <= len-3)
{
if(buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 3)
{
dest[j] = dest[j+1] = 0;
j += 2;
i += 3;
skip++;
}
else
{
dest[j] = buf[i];
j++;
i++;
}
}
dest[j] = buf[len-2];
dest[j+1] = buf[len-1];
len -= skip;
memcpy(buf, dest, len);
free(dest);
return len;
}
int h264_parse_sps(mp_mpeg_header_t * picture, unsigned char * buf, int len)
{
unsigned int n = 0, v, i, k, mbh;
int frame_mbs_only;
len = mp_unescape03(buf, len);
picture->fps = picture->timeinc_unit = picture->timeinc_resolution = 0;
n = 24;
read_golomb(buf, &n);
if(buf[0] >= 100){
if(read_golomb(buf, &n) == 3)
n++;
read_golomb(buf, &n);
read_golomb(buf, &n);
n++;
if(getbits(buf, n++, 1)){
for(i = 0; i < 8; i++)
{ // scaling list is skipped for now
if(getbits(buf, n++, 1))
{
v = 8;
for(k = (i < 6 ? 16 : 64); k && v; k--)
v = (v + read_golomb_s(buf, &n)) & 255;
}
}
}
}
read_golomb(buf, &n);
v = read_golomb(buf, &n);
if(v == 0)
read_golomb(buf, &n);
else if(v == 1)
{
getbits(buf, n++, 1);
read_golomb(buf, &n);
read_golomb(buf, &n);
v = read_golomb(buf, &n);
for(i = 0; i < v; i++)
read_golomb(buf, &n);
}
read_golomb(buf, &n);
getbits(buf, n++, 1);
picture->display_picture_width = 16 *(read_golomb(buf, &n)+1);
mbh = read_golomb(buf, &n)+1;
frame_mbs_only = getbits(buf, n++, 1);
picture->display_picture_height = 16 * (2 - frame_mbs_only) * mbh;
if(!frame_mbs_only)
getbits(buf, n++, 1);
getbits(buf, n++, 1);
if(getbits(buf, n++, 1))
{
read_golomb(buf, &n);
read_golomb(buf, &n);
read_golomb(buf, &n);
read_golomb(buf, &n);
}
if(getbits(buf, n++, 1))
n = h264_parse_vui(picture, buf, n);
return n;
}
int mp_vc1_decode_sequence_header(mp_mpeg_header_t * picture, unsigned char * buf, int len)
{
int n, x;
len = mp_unescape03(buf, len);
picture->display_picture_width = picture->display_picture_height = 0;
picture->fps = 0;
n = 0;
x = getbits(buf, n, 2);
n += 2;
if(x != 3) //not advanced profile
return 0;
getbits16(buf, n, 14);
n += 14;
picture->display_picture_width = getbits16(buf, n, 12) * 2 + 2;
n += 12;
picture->display_picture_height = getbits16(buf, n, 12) * 2 + 2;
n += 12;
getbits(buf, n, 6);
n += 6;
x = getbits(buf, n, 1);
n += 1;
if(x) //display info
{
getbits16(buf, n, 14);
n += 14;
getbits16(buf, n, 14);
n += 14;
if(getbits(buf, n++, 1)) //aspect ratio
{
x = getbits(buf, n, 4);
n += 4;
if(x == 15)
{
getbits16(buf, n, 16);
n += 16;
}
}
if(getbits(buf, n++, 1)) //framerates
{
int frexp=0, frnum=0, frden=0;
if(getbits(buf, n++, 1))
{
frexp = getbits16(buf, n, 16);
n += 16;
picture->fps = (double) (frexp+1) / 32.0;
}
else
{
float frates[] = {0, 24000, 25000, 30000, 50000, 60000, 48000, 72000, 0};
float frdivs[] = {0, 1000, 1001, 0};
frnum = getbits(buf, n, 8);
n += 8;
frden = getbits(buf, n, 4);
n += 4;
if((frden == 1 || frden == 2) && (frnum < 8))
picture->fps = frates[frnum] / frdivs[frden];
}
}
}
//free(dest);
return 1;
}

View File

@ -1,55 +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_MPEG_HDR_H
#define MPLAYER_MPEG_HDR_H
typedef struct {
// video info:
int mpeg1; // 0=mpeg2 1=mpeg1
int display_picture_width;
int display_picture_height;
int aspect_ratio_information;
int frame_rate_code;
float fps;
int frame_rate_extension_n;
int frame_rate_extension_d;
int bitrate; // 0x3FFFF==VBR
// timing:
int picture_structure;
int progressive_sequence;
int repeat_first_field;
int progressive_frame;
int top_field_first;
int display_time; // secs*100
//the following are for mpeg4
unsigned int timeinc_resolution, timeinc_bits, timeinc_unit;
int picture_type;
} mp_mpeg_header_t;
int mp_header_process_sequence_header (mp_mpeg_header_t * picture, const unsigned char * buffer);
int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer);
float mpeg12_aspect_info(mp_mpeg_header_t *picture);
int mp4_header_process_vol(mp_mpeg_header_t * picture, unsigned char * buffer);
void mp4_header_process_vop(mp_mpeg_header_t * picture, unsigned char * buffer);
int h264_parse_sps(mp_mpeg_header_t * picture, unsigned char * buf, int len);
int mp_vc1_decode_sequence_header(mp_mpeg_header_t * picture, unsigned char * buf, int len);
unsigned char mp_getbits(unsigned char *buffer, unsigned int from, unsigned char len);
#endif /* MPLAYER_MPEG_HDR_H */

View File

@ -22,6 +22,14 @@
#include <sys/types.h>
#include "config.h"
#include "compat/mpbswap.h"
#ifndef mmioFOURCC
#define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
( (uint32_t)(uint8_t)(ch0) | ( (uint32_t)(uint8_t)(ch1) << 8 ) | \
( (uint32_t)(uint8_t)(ch2) << 16 ) | ( (uint32_t)(uint8_t)(ch3) << 24 ) )
#endif
#ifndef _WAVEFORMATEX_
#define _WAVEFORMATEX_
typedef struct __attribute__((__packed__)) _WAVEFORMATEX {

View File

@ -1,158 +0,0 @@
/*
* MPEG-ES video parser
*
* 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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "config.h"
#include "core/mp_msg.h"
#include "stream/stream.h"
#include "demux.h"
#include "parse_es.h"
//static unsigned char videobuffer[MAX_VIDEO_PACKET_SIZE];
unsigned char* videobuffer=NULL;
int videobuf_len=0;
int next_nal = -1;
///! legacy variable, 4 if stream is synced, 0 if not
int videobuf_code_len=0;
#define MAX_SYNCLEN (10 * 1024 * 1024)
// sync video stream, and returns next packet code
int sync_video_packet(demux_stream_t *ds){
if (!videobuf_code_len) {
int skipped=0;
if (!demux_pattern_3(ds, NULL, MAX_SYNCLEN, &skipped, 0x100)) {
if (skipped == MAX_SYNCLEN)
mp_msg(MSGT_DEMUXER, MSGL_ERR, "parse_es: could not sync video stream!\n");
goto eof_out;
}
next_nal = demux_getc(ds);
if (next_nal < 0)
goto eof_out;
videobuf_code_len = 4;
if(skipped) mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: %d bytes skipped (next: 0x1%02X)\n",skipped,next_nal);
}
return 0x100|next_nal;
eof_out:
next_nal = -1;
videobuf_code_len = 0;
return 0;
}
// return: packet length
int read_video_packet(demux_stream_t *ds){
int packet_start;
int res, read;
if (VIDEOBUFFER_SIZE - videobuf_len < 5)
return 0;
// SYNC STREAM
// if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
// COPY STARTCODE:
packet_start=videobuf_len;
videobuffer[videobuf_len+0]=0;
videobuffer[videobuf_len+1]=0;
videobuffer[videobuf_len+2]=1;
videobuffer[videobuf_len+3]=next_nal;
videobuf_len+=4;
// READ PACKET:
res = demux_pattern_3(ds, &videobuffer[videobuf_len],
VIDEOBUFFER_SIZE - videobuf_len, &read, 0x100);
videobuf_len += read;
if (!res)
goto eof_out;
videobuf_len-=3;
mp_dbg(MSGT_PARSEES,MSGL_DBG2,"videobuf: packet 0x1%02X len=%d (total=%d)\n",videobuffer[packet_start+3],videobuf_len-packet_start,videobuf_len);
// Save next packet code:
next_nal = demux_getc(ds);
if (next_nal < 0)
goto eof_out;
videobuf_code_len=4;
return videobuf_len-packet_start;
eof_out:
next_nal = -1;
videobuf_code_len = 0;
return videobuf_len - packet_start;
}
// return: next packet code
int skip_video_packet(demux_stream_t *ds){
// SYNC STREAM
// if(!sync_video_packet(ds)) return 0; // cannot sync (EOF)
videobuf_code_len=0; // force resync
// SYNC AGAIN:
return sync_video_packet(ds);
}
/* stripped down version of a52_syncinfo() from liba52
* copyright belongs to Michel Lespinasse <walken@zoy.org>
* and Aaron Holtzman <aholtzma@ess.engr.uvic.ca> */
int mp_a52_framesize(uint8_t * buf, int *srate)
{
int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
128, 160, 192, 224, 256, 320, 384, 448,
512, 576, 640
};
uint8_t halfrate[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 };
int frmsizecod, bitrate, half;
if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
return 0;
if (buf[5] >= 0x60) /* bsid >= 12 */
return 0;
half = halfrate[buf[5] >> 3];
frmsizecod = buf[4] & 63;
if (frmsizecod >= 38)
return 0;
bitrate = rate[frmsizecod >> 1];
switch (buf[4] & 0xc0) {
case 0: /* 48 KHz */
*srate = 48000 >> half;
return 4 * bitrate;
case 0x40: /* 44.1 KHz */
*srate = 44100 >> half;
return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
case 0x80: /* 32 KHz */
*srate = 32000 >> half;
return 6 * bitrate;
}
return 0;
}

View File

@ -1,45 +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_PARSE_ES_H
#define MPLAYER_PARSE_ES_H
#include <stdint.h>
#include "demux.h"
#define MAX_VIDEO_PACKET_SIZE (224*1024+4)
#define VIDEOBUFFER_SIZE 0x100000
extern unsigned char* videobuffer;
extern int videobuf_len;
extern unsigned char videobuf_code[4];
extern int videobuf_code_len;
// sync video stream, and returns next packet code
int sync_video_packet(demux_stream_t *ds);
// return: packet length
int read_video_packet(demux_stream_t *ds);
// return: next packet code
int skip_video_packet(demux_stream_t *ds);
int mp_a52_framesize(uint8_t *buf, int *srate);
#endif /* MPLAYER_PARSE_ES_H */

View File

@ -24,7 +24,6 @@
#include "codec_tags.h"
#include "audio/chmap.h"
#include "aviheader.h"
#include "ms_hdr.h"
struct MPOpts;
struct demuxer;
@ -113,7 +112,6 @@ typedef struct sh_audio {
struct af_stream *afilter; // the audio filter stream
const struct ad_functions *ad_driver;
// win32-compatible codec parameters:
AVIStreamHeader audio;
WAVEFORMATEX *wf;
// note codec extradata may be either under "wf" or "codecdata"
unsigned char *codecdata;
@ -153,7 +151,6 @@ typedef struct sh_video {
const struct vd_functions *vd_driver;
int vf_initialized; // -1 failed, 0 not done, 1 done
// win32-compatible codec parameters:
AVIStreamHeader video;
BITMAPINFOHEADER *bih;
} sh_video_t;
@ -173,9 +170,6 @@ struct sh_audio *new_sh_audio_aid(struct demuxer *demuxer, int id, int aid);
#define new_sh_video(d, i) new_sh_video_vid(d, i, i)
struct sh_video *new_sh_video_vid(struct demuxer *demuxer, int id, int vid);
#define new_sh_sub(d, i) new_sh_sub_sid(d, i, i)
struct sh_sub *new_sh_sub_sid(struct demuxer *demuxer, int id, int sid);
struct sh_sub *new_sh_sub_sid_lang(struct demuxer *demuxer, int id, int sid,
const char *lang);
struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type);
// video.c:

View File

@ -32,530 +32,23 @@
#include "stream/stream.h"
#include "demux.h"
#include "stheader.h"
#include "parse_es.h"
#include "mpeg_hdr.h"
/* sub_cc (closed captions)*/
//#include "sub/sub_cc.h"
/* biCompression constant */
#define BI_RGB 0L
static mp_mpeg_header_t picture;
static int telecine=0;
static float telecine_cnt=-2.5;
typedef enum {
VIDEO_MPEG12,
VIDEO_MPEG4,
VIDEO_H264,
VIDEO_VC1,
VIDEO_OTHER
} video_codec_t;
static video_codec_t find_video_codec(sh_video_t *sh_video)
{
demux_stream_t *d_video=sh_video->ds;
int fmt = d_video->demuxer->file_format;
if(
(fmt == DEMUXER_TYPE_MPEG_ES) ||
(fmt == DEMUXER_TYPE_MPEG_GXF) ||
(fmt == DEMUXER_TYPE_MPEG_PES) ||
(
(fmt == DEMUXER_TYPE_MPEG_PS || fmt == DEMUXER_TYPE_MPEG_TS) &&
((! sh_video->format) || (sh_video->format==0x10000001) || (sh_video->format==0x10000002))
)
)
return VIDEO_MPEG12;
else if((fmt == DEMUXER_TYPE_MPEG4_ES) ||
((fmt == DEMUXER_TYPE_MPEG_TS) && (sh_video->format==0x10000004)) ||
((fmt == DEMUXER_TYPE_MPEG_PS) && (sh_video->format==0x10000004))
)
return VIDEO_MPEG4;
else if((fmt == DEMUXER_TYPE_H264_ES) ||
((fmt == DEMUXER_TYPE_MPEG_TS) && (sh_video->format==0x10000005)) ||
((fmt == DEMUXER_TYPE_MPEG_PS) && (sh_video->format==0x10000005))
)
return VIDEO_H264;
else if((fmt == DEMUXER_TYPE_MPEG_PS || fmt == DEMUXER_TYPE_MPEG_TS) &&
(sh_video->format==mmioFOURCC('W', 'V', 'C', '1')))
return VIDEO_VC1;
else if (fmt == DEMUXER_TYPE_ASF && sh_video->bih && sh_video->bih->biCompression == mmioFOURCC('D', 'V', 'R', ' '))
return VIDEO_MPEG12;
else
return VIDEO_OTHER;
}
int video_read_properties(sh_video_t *sh_video){
demux_stream_t *d_video=sh_video->ds;
video_codec_t video_codec = find_video_codec(sh_video);
// Determine image properties:
switch(video_codec){
case VIDEO_OTHER: {
if((d_video->demuxer->file_format == DEMUXER_TYPE_ASF) || (d_video->demuxer->file_format == DEMUXER_TYPE_AVI)) {
// display info:
// in case no strf chunk has been seen in avi, we have no bitmap header
if(!sh_video->bih) return 0;
sh_video->format=sh_video->bih->biCompression;
mp_set_video_codec_from_tag(sh_video);
sh_video->disp_w=sh_video->bih->biWidth;
sh_video->disp_h=abs(sh_video->bih->biHeight);
}
break;
}
case VIDEO_MPEG4: {
int pos = 0, vop_cnt=0, units[3];
videobuf_len=0; videobuf_code_len=0;
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Start code... ");
while(1){
int i=sync_video_packet(d_video);
if(i<=0x11F) break; // found it!
if(!i || !skip_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
if(!videobuffer) {
videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
else {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for Video Object Layer Start code... ");
while(1){
int i=sync_video_packet(d_video);
mp_msg(MSGT_DECVIDEO,MSGL_V,"M4V: 0x%X\n",i);
if(i>=0x120 && i<=0x12F) break; // found it!
if(!i || !read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
pos = videobuf_len+4;
if(!read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read Video Object Layer Header\n");
return 0;
}
mp4_header_process_vol(&picture, &(videobuffer[pos]));
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK! FPS SEEMS TO BE %.3f\nSearching for Video Object Plane Start code... ", sh_video->fps);
mp4_init:
while(1){
int i=sync_video_packet(d_video);
if(i==0x1B6) break; // found it!
if(!i || !read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
pos = videobuf_len+4;
if(!read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read Video Object Plane Header\n");
return 0;
}
mp4_header_process_vop(&picture, &(videobuffer[pos]));
sh_video->disp_w = picture.display_picture_width;
sh_video->disp_h = picture.display_picture_height;
units[vop_cnt] = picture.timeinc_unit;
vop_cnt++;
//mp_msg(MSGT_DECVIDEO,MSGL_V, "TYPE: %d, unit: %d\n", picture.picture_type, picture.timeinc_unit);
if(!picture.fps) {
int i, mn, md, mx, diff;
if(vop_cnt < 3)
goto mp4_init;
i=0;
mn = mx = units[0];
for(i=0; i<3; i++) {
if(units[i] < mn)
mn = units[i];
if(units[i] > mx)
mx = units[i];
}
md = mn;
for(i=0; i<3; i++) {
if((units[i] > mn) && (units[i] < mx))
md = units[i];
}
mp_msg(MSGT_DECVIDEO,MSGL_V, "MIN: %d, mid: %d, max: %d\n", mn, md, mx);
if(mx - md > md - mn)
diff = md - mn;
else
diff = mx - md;
if(diff > 0){
picture.fps = ((float)picture.timeinc_resolution) / diff;
mp_msg(MSGT_DECVIDEO,MSGL_V, "FPS seems to be: %f, resolution: %d, delta_units: %d\n", picture.fps, picture.timeinc_resolution, diff);
}
}
if(picture.fps) {
sh_video->fps=picture.fps;
sh_video->frametime=1.0/picture.fps;
mp_msg(MSGT_DECVIDEO,MSGL_INFO, "FPS seems to be: %f\n", picture.fps);
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
sh_video->format=0x10000004;
break;
}
case VIDEO_H264: {
int pos = 0;
videobuf_len=0; videobuf_code_len=0;
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence parameter set... ");
while(1){
int i=sync_video_packet(d_video);
if((i&~0x60) == 0x107 && i != 0x107) break; // found it!
if(!i || !skip_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
if(!videobuffer) {
videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
else {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
return 0;
}
}
pos = videobuf_len+4;
if(!read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Can't read sequence parameter set\n");
return 0;
}
h264_parse_sps(&picture, &(videobuffer[pos]), videobuf_len - pos);
sh_video->disp_w=picture.display_picture_width;
sh_video->disp_h=picture.display_picture_height;
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for picture parameter set... ");
while(1){
int i=sync_video_packet(d_video);
mp_msg(MSGT_DECVIDEO,MSGL_V,"H264: 0x%X\n",i);
if((i&~0x60) == 0x108 && i != 0x108) break; // found it!
if(!i || !read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\nSearching for Slice... ");
while(1){
int i=sync_video_packet(d_video);
if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105) break; // found it!
if(!i || !read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
sh_video->format=0x10000005;
if(picture.fps) {
sh_video->fps=picture.fps;
sh_video->frametime=1.0/picture.fps;
mp_msg(MSGT_DECVIDEO,MSGL_INFO, "FPS seems to be: %f\n", picture.fps);
}
break;
}
case VIDEO_MPEG12: {
if (d_video->demuxer->file_format == DEMUXER_TYPE_ASF) { // DVR-MS
if(!sh_video->bih) return 0;
sh_video->format=sh_video->bih->biCompression;
}
mpeg_header_parser:
// Find sequence_header first:
videobuf_len=0; videobuf_code_len=0;
telecine=0; telecine_cnt=-2.5;
mp_msg(MSGT_DECVIDEO,MSGL_V,"Searching for sequence header... ");
while(1){
int i=sync_video_packet(d_video);
if(i==0x1B3) break; // found it!
if(!i || !skip_video_packet(d_video)){
if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: FATAL: EOF while searching for sequence header.\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_V,"OK!\n");
// ========= Read & process sequence header & extension ============
if(!videobuffer) {
videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
else {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
return 0;
}
}
if(!read_video_packet(d_video)){
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"FATAL: Cannot read sequence header.\n");
return 0;
}
if(mp_header_process_sequence_header (&picture, &videobuffer[4])) {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: bad sequence header\n");
goto mpeg_header_parser;
}
if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext.
int pos=videobuf_len;
if(!read_video_packet(d_video)){
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"FATAL: Cannot read sequence header extension.\n");
return 0;
}
if(mp_header_process_extension (&picture, &videobuffer[pos+4])) {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"MPEG: bad sequence header extension\n");
return 0;
}
}
// display info:
sh_video->format=picture.mpeg1?0x10000001:0x10000002; // mpeg video
sh_video->fps=picture.fps * picture.frame_rate_extension_n / picture.frame_rate_extension_d;
if(!sh_video->fps){
sh_video->frametime=0;
} else {
sh_video->frametime=1.0/sh_video->fps;
}
sh_video->disp_w=picture.display_picture_width;
sh_video->disp_h=picture.display_picture_height;
// bitrate:
if(picture.bitrate!=0x3FFFF) // unspecified/VBR ?
sh_video->i_bps=picture.bitrate * 400 / 8;
// info:
mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"mpeg bitrate: %d (%X)\n",picture.bitrate,picture.bitrate);
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: %s %dx%d (aspect %d) %5.3f fps %5.1f kbps (%4.1f kbyte/s)\n",
picture.mpeg1?"MPEG1":"MPEG2",
sh_video->disp_w,sh_video->disp_h,
picture.aspect_ratio_information,
sh_video->fps,
sh_video->i_bps * 8 / 1000.0,
sh_video->i_bps / 1000.0 );
break;
}
case VIDEO_VC1: {
// Find sequence_header:
videobuf_len=0;
videobuf_code_len=0;
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"Searching for VC1 sequence header... ");
while(1){
int i=sync_video_packet(d_video);
if(i==0x10F) break; // found it!
if(!i || !skip_video_packet(d_video)){
if( mp_msg_test(MSGT_DECVIDEO,MSGL_V) ) mp_msg(MSGT_DECVIDEO,MSGL_V,"NONE :(\n");
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Couldn't find VC-1 sequence header\n");
return 0;
}
}
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"found\n");
if(!videobuffer) {
videobuffer = av_malloc(VIDEOBUFFER_SIZE + MP_INPUT_BUFFER_PADDING_SIZE);
if (videobuffer) memset(videobuffer+VIDEOBUFFER_SIZE, 0, MP_INPUT_BUFFER_PADDING_SIZE);
else {
mp_tmsg(MSGT_DECVIDEO,MSGL_ERR,"Cannot allocate shared memory.\n");
return 0;
}
}
if(!read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Couldn't read VC-1 sequence header!\n");
return 0;
}
while(1) {
int i=sync_video_packet(d_video);
if(i==0x10E) break; // found it!
if(!i || !skip_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"Couldn't find VC-1 entry point sync-code:(\n");
return 0;
}
}
if(!read_video_packet(d_video)){
mp_msg(MSGT_DECVIDEO,MSGL_V,"Couldn't read VC-1 entry point sync-code:(\n");
return 0;
}
if(mp_vc1_decode_sequence_header(&picture, &videobuffer[4], videobuf_len-4)) {
sh_video->bih = calloc(1, sizeof(*sh_video->bih) + videobuf_len);
if(sh_video->bih == NULL) {
mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Couldn't alloc %zu bytes for VC-1 extradata!\n", sizeof(*sh_video->bih) + videobuf_len);
return 0;
}
sh_video->bih->biSize= sizeof(*sh_video->bih) + videobuf_len;
memcpy(sh_video->bih + 1, videobuffer, videobuf_len);
sh_video->bih->biCompression = sh_video->format;
sh_video->bih->biWidth = sh_video->disp_w = picture.display_picture_width;
sh_video->bih->biHeight = sh_video->disp_h = picture.display_picture_height;
if(picture.fps > 0) {
sh_video->frametime=1.0/picture.fps;
sh_video->fps = picture.fps;
}
mp_msg(MSGT_DECVIDEO,MSGL_INFO,"VIDEO: VC-1 %dx%d, %5.3f fps, header len: %d\n",
sh_video->disp_w, sh_video->disp_h, sh_video->fps, videobuf_len);
}
break;
}
} // switch(file_format)
if (d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_PS ||
d_video->demuxer->file_format == DEMUXER_TYPE_MPEG_TS)
mp_set_video_codec_from_tag(sh_video);
return 1;
}
static void process_userdata(const unsigned char* buf,int len){
int i;
/* if the user data starts with "CC", assume it is a CC info packet */
if(len>2 && buf[0]=='C' && buf[1]=='C'){
// mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"video.c: process_userdata() detected Closed Captions!\n");
//subcc_process_data(buf+2,len-2);
}
if(verbose<2) return;
fprintf(stderr, "user_data: len=%3d %02X %02X %02X %02X '",
len, buf[0], buf[1], buf[2], buf[3]);
for(i=0;i<len;i++)
// if(buf[i]>=32 && buf[i]<127) fputc(buf[i], stderr);
if(buf[i]&0x60) fputc(buf[i]&0x7F, stderr);
fprintf(stderr, "'\n");
}
int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){
demux_stream_t *d_video=sh_video->ds;
demuxer_t *demuxer=d_video->demuxer;
float frame_time=1;
float pts1=d_video->pts;
float pts=0;
float fps;
int picture_coding_type=0;
int in_size=0;
video_codec_t video_codec = find_video_codec(sh_video);
*start=NULL;
if(video_codec == VIDEO_MPEG12){
int in_frame=0;
//float newfps;
//videobuf_len=0;
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
int i=sync_video_packet(d_video);
//void* buffer=&videobuffer[videobuf_len+4];
int start=videobuf_len+4;
if(in_frame){
if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame
if(!i) return -1; // EOF
break;
}
} else {
if(i==0x100){
pts=d_video->pts;
d_video->pts=0;
}
if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
else if(!i) return -1; // EOF
}
if(!read_video_packet(d_video)) return -1; // EOF
// process headers:
switch(i){
case 0x1B3: mp_header_process_sequence_header (&picture, &videobuffer[start]);break;
case 0x1B5: mp_header_process_extension (&picture, &videobuffer[start]);break;
case 0x1B2: process_userdata (&videobuffer[start], videobuf_len-start);break;
case 0x100: picture_coding_type=(videobuffer[start+1] >> 3) & 7;break;
}
}
fps = picture.fps * picture.frame_rate_extension_n / picture.frame_rate_extension_d;
*start=videobuffer; in_size=videobuf_len;
// get mpeg fps:
if(sh_video->fps!=fps) if(!force_fps && !telecine){
mp_msg(MSGT_CPLAYER,MSGL_WARN,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,fps,sh_video->fps-fps,picture.frame_rate_code);
sh_video->fps=fps;
sh_video->frametime=1.0/fps;
}
// fix mpeg2 frametime:
frame_time=(picture.display_time)*0.01f;
picture.display_time=100;
videobuf_len=0;
telecine_cnt*=0.9; // drift out error
telecine_cnt+=frame_time-5.0/4.0;
mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"\r telecine = %3.1f %5.3f \n",frame_time,telecine_cnt);
if(telecine){
frame_time=1;
if(telecine_cnt<-1.5 || telecine_cnt>1.5){
mp_tmsg(MSGT_DECVIDEO,MSGL_INFO,"\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n");
telecine=0;
}
} else
if(telecine_cnt>-0.5 && telecine_cnt<0.5 && !force_fps){
sh_video->fps=sh_video->fps*4/5;
sh_video->frametime=sh_video->frametime*5/4;
mp_tmsg(MSGT_DECVIDEO,MSGL_INFO,"\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n");
telecine=1;
}
} else if(video_codec == VIDEO_MPEG4){
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
int i=sync_video_packet(d_video);
if(!i) return -1;
if(!read_video_packet(d_video)) return -1; // EOF
if(i==0x1B6) break;
}
*start=videobuffer; in_size=videobuf_len;
videobuf_len=0;
} else if(video_codec == VIDEO_H264){
int in_picture = 0;
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){
int i=sync_video_packet(d_video);
int pos = videobuf_len+4;
if(!i) return -1;
if(!read_video_packet(d_video)) return -1; // EOF
if((i&~0x60) == 0x107 && i != 0x107) {
h264_parse_sps(&picture, &(videobuffer[pos]), videobuf_len - pos);
if(picture.fps > 0) {
sh_video->fps=picture.fps;
sh_video->frametime=1.0/picture.fps;
}
i=sync_video_packet(d_video);
if(!i) return -1;
if(!read_video_packet(d_video)) return -1; // EOF
}
// here starts the access unit end detection code
// see the mail on MPlayer-dev-eng for details:
// Date: Sat, 17 Sep 2005 11:24:06 +0200
// Subject: Re: [MPlayer-dev-eng] [RFC] h264 ES parser problems
// Message-ID: <20050917092406.GA7699@rz.uni-karlsruhe.de>
if((i&~0x60) == 0x101 || (i&~0x60) == 0x102 || (i&~0x60) == 0x105)
// found VCL NAL with slice header i.e. start of current primary coded
// picture, so start scanning for the end now
in_picture = 1;
if (in_picture) {
i = sync_video_packet(d_video) & ~0x60; // code of next packet
if(i == 0x106 || i == 0x109) break; // SEI or access unit delim.
if(i == 0x101 || i == 0x102 || i == 0x105) {
// assuming arbitrary slice ordering is not allowed, the
// first_mb_in_slice (golomb encoded) value should be 0 then
// for the first VCL NAL in a picture
if (demux_peekc(d_video) & 0x80)
break;
}
}
}
*start=videobuffer; in_size=videobuf_len;
videobuf_len=0;
} else if(video_codec == VIDEO_VC1) {
while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE) {
int i=sync_video_packet(d_video);
if(!i) return -1;
if(!read_video_packet(d_video)) return -1; // EOF
if(i==0x10D) break;
}
*start=videobuffer;
in_size=videobuf_len;
videobuf_len=0;
} else {
// frame-based file formats: (AVI,ASF,MOV)
in_size=ds_get_packet(d_video,start);
if(in_size<0) return -1; // EOF
}
//------------------------ frame decoded. --------------------
@ -564,14 +57,12 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char**
// override frame_time for variable/unknown FPS formats:
if(!force_fps) switch(demuxer->file_format){
case DEMUXER_TYPE_GIF:
case DEMUXER_TYPE_MATROSKA:
case DEMUXER_TYPE_MNG:
if(d_video->pts>0 && pts1>0 && d_video->pts>pts1)
frame_time=d_video->pts-pts1;
break;
case DEMUXER_TYPE_TV:
case DEMUXER_TYPE_ASF: {
case DEMUXER_TYPE_TV: {
double next_pts = ds_get_next_pts(d_video);
double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1;
if(d>=0){
@ -599,21 +90,7 @@ int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char**
break;
}
if(video_codec == VIDEO_MPEG12){
sh_video->pts+=frame_time;
if(picture_coding_type==1)
d_video->keyframe = true;
if(picture_coding_type<=2 && sh_video->i_pts){
sh_video->pts=sh_video->i_pts;
sh_video->i_pts=pts;
} else {
if(pts){
if(picture_coding_type<=2) sh_video->i_pts=pts;
else sh_video->pts=pts;
}
}
} else
sh_video->pts=d_video->pts;
sh_video->pts=d_video->pts;
if(frame_time_ptr) *frame_time_ptr=frame_time;
return in_size;

View File

@ -739,7 +739,7 @@ static int dvb_open(stream_t *stream, int mode, void *opts, int *file_format)
stream->close = dvbin_close;
m_struct_free(&stream_opts, opts);
*file_format = DEMUXER_TYPE_MPEG_TS;
*file_format = DEMUXER_TYPE_LAVF; // TS
return STREAM_OK;
}

View File

@ -232,7 +232,7 @@ static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
stream->seek = seek;
stream->control = control;
stream->close = close_s;
*file_format = DEMUXER_TYPE_MPEG_PS;
*file_format = DEMUXER_TYPE_LAVF; // mpegps
m_struct_free(&stream_opts,opts);
return STREAM_OK;

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "config.h"

View File

@ -345,10 +345,7 @@ static void init_avctx(sh_video_t *sh, const char *decoder, struct hwdec *hwdec)
avctx->coded_width = sh->disp_w;
avctx->coded_height = sh->disp_h;
// demux_avi only
avctx->stream_codec_tag = sh->video.fccHandler;
// demux_mkv, demux_avi, demux_asf
// demux_mkv
if (sh->bih)
set_from_bih(avctx, sh->format, sh->bih);