Commit 960df9a9 authored by Laurent Aimar's avatar Laurent Aimar

* all : preliminary mp4 (and some mov) demux plugin. I've not enabled

it ( add by hand to Makefile ... and link it with zlib -lz ) as I will
probably break it too many times. It work for some mp4(but without
audio, need aac decoder) and mov with sorenson v1(ffmpeg :).
parent 7d5c3cfd
mp4_SOURCES = mp4.c libmp4.c
This diff is collapsed.
/*****************************************************************************
* libmp4.h : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: libmp4.h,v 1.1 2002/07/17 21:37:27 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/* XXX It's not the same than VLC_FOURCC */
#define MP4_FOURCC( a, b, c, d ) \
( ((u32)d) | ( ((u32)c) << 8 ) | ( ((u32)b) << 16 ) | ( ((u32)a) << 24 ) )
#define FOURCC_uuid MP4_FOURCC( 'u', 'u', 'i', 'd' )
#define FOURCC_ftyp MP4_FOURCC( 'f', 't', 'y', 'p' )
#define FOURCC_moov MP4_FOURCC( 'm', 'o', 'o', 'v' )
#define FOURCC_cmov MP4_FOURCC( 'c', 'm', 'o', 'v' )
#define FOURCC_dcom MP4_FOURCC( 'd', 'c', 'o', 'm' )
#define FOURCC_cmvd MP4_FOURCC( 'c', 'm', 'v', 'd' )
#define FOURCC_moof MP4_FOURCC( 'm', 'o', 'o', 'f' )
#define FOURCC_mdat MP4_FOURCC( 'm', 'd', 'a', 't' )
#define FOURCC_skip MP4_FOURCC( 's', 'k', 'i', 'p' )
#define FOURCC_free MP4_FOURCC( 'f', 'r', 'e', 'e' )
#define FOURCC_udta MP4_FOURCC( 'u', 'd', 't', 'a' )
#define FOURCC_wide MP4_FOURCC( 'w', 'i', 'd', 'e' )
#define FOURCC_trak MP4_FOURCC( 't', 'r', 'a', 'k' )
#define FOURCC_mvhd MP4_FOURCC( 'm', 'v', 'h', 'd' )
#define FOURCC_tkhd MP4_FOURCC( 't', 'k', 'h', 'd' )
#define FOURCC_tref MP4_FOURCC( 't', 'r', 'e', 'f' )
#define FOURCC_mdia MP4_FOURCC( 'm', 'd', 'i', 'a' )
#define FOURCC_mdhd MP4_FOURCC( 'm', 'd', 'h', 'd' )
#define FOURCC_hdlr MP4_FOURCC( 'h', 'd', 'l', 'r' )
#define FOURCC_minf MP4_FOURCC( 'm', 'i', 'n', 'f' )
#define FOURCC_vmhd MP4_FOURCC( 'v', 'm', 'h', 'd' )
#define FOURCC_smhd MP4_FOURCC( 's', 'm', 'h', 'd' )
#define FOURCC_hmhd MP4_FOURCC( 'h', 'm', 'h', 'd' )
#define FOURCC_dinf MP4_FOURCC( 'd', 'i', 'n', 'f' )
#define FOURCC_url MP4_FOURCC( 'u', 'r', 'l', ' ' )
#define FOURCC_urn MP4_FOURCC( 'u', 'r', 'n', ' ' )
#define FOURCC_dref MP4_FOURCC( 'd', 'r', 'e', 'f' )
#define FOURCC_stbl MP4_FOURCC( 's', 't', 'b', 'l' )
#define FOURCC_stts MP4_FOURCC( 's', 't', 't', 's' )
#define FOURCC_ctts MP4_FOURCC( 'c', 't', 't', 's' )
#define FOURCC_stsd MP4_FOURCC( 's', 't', 's', 'd' )
#define FOURCC_stsz MP4_FOURCC( 's', 't', 's', 'z' )
#define FOURCC_stz2 MP4_FOURCC( 's', 't', 'z', '2' )
#define FOURCC_stsc MP4_FOURCC( 's', 't', 's', 'c' )
#define FOURCC_stco MP4_FOURCC( 's', 't', 'c', 'o' )
#define FOURCC_co64 MP4_FOURCC( 'c', 'o', '6', '4' )
#define FOURCC_stss MP4_FOURCC( 's', 't', 's', 's' )
#define FOURCC_stsh MP4_FOURCC( 's', 't', 's', 'h' )
#define FOURCC_stdp MP4_FOURCC( 's', 't', 'd', 'p' )
#define FOURCC_padb MP4_FOURCC( 'p', 'a', 'd', 'b' )
#define FOURCC_edts MP4_FOURCC( 'e', 'd', 't', 's' )
#define FOURCC_elst MP4_FOURCC( 'e', 'l', 's', 't' )
#define FOURCC_udta MP4_FOURCC( 'u', 'd', 't', 'a' )
#define FOURCC_mvex MP4_FOURCC( 'm', 'v', 'e', 'x' )
#define FOURCC_trex MP4_FOURCC( 't', 'r', 'e', 'x' )
#define FOURCC_mfhd MP4_FOURCC( 'm', 'f', 'h', 'd' )
#define FOURCC_traf MP4_FOURCC( 't', 'r', 'a', 'f' )
#define FOURCC_tfhd MP4_FOURCC( 't', 'f', 'h', 'd' )
#define FOURCC_trun MP4_FOURCC( 't', 'r', 'u', 'n' )
#define FOURCC_cprt MP4_FOURCC( 'c', 'p', 'r', 't' )
#define FOURCC_iods MP4_FOURCC( 'i', 'o', 'd', 's' )
#define FOURCC_nmhd MP4_FOURCC( 'n', 'm', 'h', 'd' )
#define FOURCC_mp4v MP4_FOURCC( 'm', 'p', '4', 'v' )
#define FOURCC_mp4a MP4_FOURCC( 'm', 'p', '4', 'a' )
#define FOURCC_mp4s MP4_FOURCC( 'm', 'p', '4', 's' )
#define FOURCC_vide MP4_FOURCC( 'v', 'i', 'd', 'e' )
#define FOURCC_soun MP4_FOURCC( 's', 'o', 'u', 'n' )
#define FOURCC_hint MP4_FOURCC( 'h', 'i', 'n', 't' )
#define FOURCC_dpnd MP4_FOURCC( 'd', 'p', 'n', 'd' )
#define FOURCC_ipir MP4_FOURCC( 'i', 'p', 'i', 'r' )
#define FOURCC_mpod MP4_FOURCC( 'm', 'p', 'o', 'd' )
#define FOURCC_hnti MP4_FOURCC( 'h', 'n', 't', 'i' )
#define FOURCC_rtp MP4_FOURCC( 'r', 't', 'p', ' ' )
#define FOURCC_isom MP4_FOURCC( 'i', 's', 'o', 'm' )
#define FOURCC_esds MP4_FOURCC( 'e', 's', 'd', 's' )
#define FOURCC_zlib MP4_FOURCC( 'z', 'l', 'i', 'b' )
#define FOURCC_SVQ1 MP4_FOURCC( 'S', 'V', 'Q', '1' )
#define FOURCC__mp3 MP4_FOURCC( '.', 'm', 'p', '3' )
#define FOURCC_3IV1 MP4_FOURCC( '3', 'I', 'V', '1' )
#define FOURCC_h263 MP4_FOURCC( 'h', '2', '6', '3' )
#define FOURCC_DIVX MP4_FOURCC( 'D', 'I', 'V', 'X' )
/*
#define FOURCC_ MP4_FOURCC( '', '', '', '' )
*/
/* Do you want some debug information on all read boxes ? */
#define MP4_VERBOSE 1
/* memory stream and file stream object */
typedef struct MP4_Stream_s
{
int b_memory; /* do we uses a memory buffer */
input_thread_t *p_input;
off_t i_start; /* in the buffer position for memory stream */
off_t i_stop;
u8 *p_buffer;
} MP4_Stream_t;
struct MP4_Box_s;
/* uuid Universal Unique IDentifiers */
typedef struct UUID_s
{
u8 b[16];
} UUID_t;
/* specific structure for all boxes */
typedef struct MP4_Box_data_ftyp_s
{
u32 i_major_brand;
u32 i_minor_version;
u32 i_compatible_brands_count;
u32 *i_compatible_brands;
} MP4_Box_data_ftyp_t;
typedef struct MP4_Box_data_mvhd_s
{
u8 i_version;
u32 i_flags;
u64 i_creation_time;
u64 i_modification_time;
u32 i_timescale;
u64 i_duration;
s32 i_rate;
s16 i_volume;
s16 i_reserved1;
u32 i_reserved2[2];
s32 i_matrix[9];
u32 i_predefined[6];
u32 i_next_track_id;
} MP4_Box_data_mvhd_t;
#define MP4_TRACK_ENABLED 0x000001
#define MP4_TRACK_IN_MOVIE 0x000002
#define MP4_TRACK_IN_PREVIEW 0x000004
typedef struct MP4_Box_data_tkhd_s
{
u8 i_version;
u32 i_flags;
u64 i_creation_time;
u64 i_modification_time;
u32 i_track_ID;
u32 i_reserved;
u64 i_duration;
u32 i_reserved2[2];
s16 i_layer;
s16 i_predefined;
s16 i_volume;
u16 i_reserved3;
s32 i_matrix[9];
s32 i_width;
s32 i_height;
} MP4_Box_data_tkhd_t;
typedef struct MP4_Box_data_mdhd_s
{
u8 i_version;
u32 i_flags;
u64 i_creation_time;
u64 i_modification_time;
u32 i_timescale;
u64 i_duration;
/* one bit for pad */
/* unsigned int(5)[3] language difference with 0x60*/
unsigned char i_language[3];
u16 i_predefined;
} MP4_Box_data_mdhd_t;
typedef struct MP4_Box_data_hdlr_s
{
u8 i_version;
u32 i_flags;
u32 i_predefined;
u32 i_handler_type; /* "vide" "soun" "hint" "odsm"
"crsm" "sdsm" "m7sm" "ocsm"
"ipsm" "mjsm" */
unsigned char *psz_name; /* in UTF-8 */
} MP4_Box_data_hdlr_t;
typedef struct MP4_Box_data_vmhd_s
{
u8 i_version;
u32 i_flags;
s16 i_graphics_mode;
s16 i_opcolor[3];
} MP4_Box_data_vmhd_t;
typedef struct MP4_Box_data_smhd_s
{
u8 i_version;
u32 i_flags;
s16 i_balance;
s16 i_reserved;
} MP4_Box_data_smhd_t;
typedef struct MP4_Box_data_hmhd_s
{
u8 i_version;
u32 i_flags;
u16 i_max_PDU_size;
u16 i_avg_PDU_size;
u32 i_max_bitrate;
u32 i_avg_bitrate;
u32 i_reserved;
} MP4_Box_data_hmhd_t;
typedef struct MP4_Box_data_url_s
{
u8 i_version;
u32 i_flags;
unsigned char *psz_location;
} MP4_Box_data_url_t;
typedef struct MP4_Box_data_urn_s
{
u8 i_version;
u32 i_flags;
unsigned char *psz_name;
unsigned char *psz_location;
} MP4_Box_data_urn_t;
typedef struct MP4_Box_data_dref_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
/* XXX it's also a container with i_entry_count entry */
} MP4_Box_data_dref_t;
typedef struct MP4_Box_data_stts_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u32 *i_sample_count; /* these are array */
s32 *i_sample_delta;
} MP4_Box_data_stts_t;
typedef struct MP4_Box_data_ctts_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u32 *i_sample_count; /* these are array */
s32 *i_sample_offset;
} MP4_Box_data_ctts_t;
typedef struct MP4_Box_data_sample_soun_s
{
u8 i_reserved1[6];
u16 i_data_reference_index;
u32 i_reserved2[2];
u16 i_channelcount;
u16 i_samplesize;
u16 i_predefined;
u16 i_reserved3;
u16 i_sampleratehi; /* timescale of track */
u16 i_sampleratelo;
} MP4_Box_data_sample_soun_t;
typedef struct MP4_Box_data_sample_mp4a_s
{
u8 i_reserved1[6];
u16 i_data_reference_index;
u32 i_reserved2[2];
u16 i_channelcount;
u16 i_samplesize;
u16 i_predefined;
u16 i_reserved3;
u16 i_sampleratehi; /* timescale of track */
u16 i_sampleratelo;
} MP4_Box_data_sample_mp4a_t;
typedef struct MP4_Box_data_sample_vide_s
{
u8 i_reserved1[6];
u16 i_data_reference_index;
u16 i_predefined1;
u16 i_reserved2;
u32 i_predefined2[3];
s16 i_width;
s16 i_height;
u32 i_horizresolution;
u32 i_vertresolution;
u32 i_reserved3;
u16 i_predefined3;
u8 i_compressorname[32];
s16 i_depth;
s16 i_predefined4;
} MP4_Box_data_sample_vide_t;
typedef struct MP4_Box_data_sample_mp4v_s
{
u8 i_reserved1[6];
u16 i_data_reference_index;
u16 i_predefined1;
u16 i_reserved2;
u32 i_predefined2[3];
s16 i_width;
s16 i_height;
u32 i_horizresolution;
u32 i_vertresolution;
u32 i_reserved3;
u16 i_predefined3;
u8 i_compressorname[32];
s16 i_depth;
s16 i_predefined4;
} MP4_Box_data_sample_mp4v_t;
typedef struct MP4_Box_data_sample_hint_s
{
u8 i_reserved1[6];
u16 i_data_reference_index;
u8 *p_data;
} MP4_Box_data_sample_hint_t;
typedef struct MP4_Box_data_moviehintinformation_rtp_s
{
u32 i_description_format;
unsigned char *psz_text;
} MP4_Box_data_moviehintinformation_rtp_t;
typedef struct MP4_Box_data_stsd_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
/* it contains SampleEntry handled as if it was Box */
} MP4_Box_data_stsd_t;
typedef struct MP4_Box_data_stsz_s
{
u8 i_version;
u32 i_flags;
u32 i_sample_size;
u32 i_sample_count;
u32 *i_entry_size; /* array , empty if i_sample_size != 0 */
} MP4_Box_data_stsz_t;
typedef struct MP4_Box_data_stz2_s
{
u8 i_version;
u32 i_flags;
u32 i_sample_size; /* 24 bits */
u8 i_field_size;
u32 i_sample_count;
u32 *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
} MP4_Box_data_stz2_t;
typedef struct MP4_Box_data_stsc_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u32 *i_first_chunk; /* theses are arrays */
u32 *i_samples_per_chunk;
u32 *i_sample_description_index;
} MP4_Box_data_stsc_t;
typedef struct MP4_Box_data_co64_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u64 *i_chunk_offset;
} MP4_Box_data_co64_t;
typedef struct MP4_Box_data_stss_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u32 *i_sample_number;
} MP4_Box_data_stss_t;
typedef struct MP4_Box_data_stsh_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u32 *i_shadowed_sample_number;
u32 *i_sync_sample_number;
} MP4_Box_data_stsh_t;
typedef struct MP4_Box_data_stdp_s
{
u8 i_version;
u32 i_flags;
u16 *i_priority;
} MP4_Box_data_stdp_t;
typedef struct MP4_Box_data_padb_s
{
u8 i_version;
u32 i_flags;
u32 i_sample_count;
u16 *i_reserved1; /* 1bit */
u16 *i_pad2; /* 3bits */
u16 *i_reserved2; /* 1bit */
u16 *i_pad1; /* 3bits */
} MP4_Box_data_padb_t;
typedef struct MP4_Box_data_elst_s
{
u8 i_version;
u32 i_flags;
u32 i_entry_count;
u64 *i_segment_duration;
s64 *i_media_time;
u16 *i_media_rate_integer;
u16 *i_media_rate_fraction;
} MP4_Box_data_elst_t;
typedef struct MP4_Box_data_cprt_s
{
u8 i_version;
u32 i_flags;
/* 1 pad bit */
unsigned char i_language[3];
unsigned char *psz_notice;
} MP4_Box_data_cprt_t;
/* DecoderConfigDescriptor */
typedef struct MP4_descriptor_decoder_config_s
{
u8 i_objectTypeIndication;
u8 i_streamType;
int b_upStream;
int i_buffer_sizeDB;
int i_max_bitrate;
int i_avg_bitrate;
int i_decoder_specific_info_len;
u8 *p_decoder_specific_info;
/* some other stuff */
} MP4_descriptor_decoder_config_t;
typedef struct MP4_descriptor_SL_config_s
{
} MP4_descriptor_SL_config_t;
typedef struct MP4_descriptor_ES_s
{
u16 i_ES_ID;
int b_stream_dependence;
int b_url;
int b_OCRstream;
int i_stream_priority;
int i_depend_on_ES_ID; /* if b_stream_dependence set */
unsigned char *psz_URL;
u16 i_OCR_ES_ID; /* if b_OCRstream */
MP4_descriptor_decoder_config_t *p_decConfigDescr;
MP4_descriptor_SL_config_t *p_slConfigDescr;
/* some other stuff ... */
} MP4_descriptor_ES_t;
/* ES descriptor */
typedef struct MP4_Box_data_esds_s
{
u8 i_version;
u32 i_flags;
MP4_descriptor_ES_t es_descriptor;
} MP4_Box_data_esds_t;
typedef struct MP4_Box_data_dcom_s
{
u32 i_algorithm; /* fourcc */
} MP4_Box_data_dcom_t;
typedef struct MP4_Box_data_cmvd_s
{
u32 i_uncompressed_size;
u32 i_compressed_size;
int b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
u8 *p_data;
} MP4_Box_data_cmvd_t;
typedef struct MP4_Box_data_cmov_s
{
struct MP4_Box_s *p_moov; /* uncompressed moov */
} MP4_Box_data_cmov_t;
/*
typedef struct MP4_Box_data_cmov_s
{
u8 i_version;
u32 i_flags;
} MP4_Box_data__t;
*/
typedef union MP4_Box_data_s
{
MP4_Box_data_ftyp_t *p_ftyp;
MP4_Box_data_mvhd_t *p_mvhd;
MP4_Box_data_tkhd_t *p_tkhd;
MP4_Box_data_mdhd_t *p_mdhd;
MP4_Box_data_hdlr_t *p_hdlr;