2001-10-10 01:07:50 +00:00
// QuickTime MOV file parser by A'rpi
2002-03-21 06:05:14 +00:00
// additional work by Atmos
// based on TOOLS/movinfo.c by A'rpi & Al3x
2001-10-10 01:07:50 +00:00
// compressed header support from moov.c of the openquicktime lib.
2001-10-22 22:49:09 +00:00
// References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/
2001-10-29 21:01:00 +00:00
// http://www.geocities.com/SiliconValley/Lakes/2160/fformats/files/mov.pdf
2002-03-21 16:42:58 +00:00
// (above url no longer works, file mirrored somewhere? ::atmos)
// The QuickTime File Format PDF from Apple:
// http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
// (Complete list of documentation at http://developer.apple.com/quicktime/)
2007-02-22 00:18:10 +00:00
// MP4-Lib sources from http://mpeg4ip.sf.net/ might be useful for .mp4
// as well as .mov specific stuff.
2002-03-21 22:26:52 +00:00
// All sort of Stuff about MPEG4:
// http://www.cmlab.csie.ntu.edu.tw/~pkhsiao/thesis.html
2002-03-22 00:54:10 +00:00
// I really recommend N4270-1.doc and N4270-2.doc which are exact specs
// of the MP4-File Format and the MPEG4 Specific extensions. ::atmos
2005-05-05 21:40:33 +00:00
// TSGS#15(02)0088
// http://www.3gpp.org/ftp/tsg_sa/TSG_SA/TSGS_15/Docs/pdf/SP-020088.pdf
// http://www.3gpp2.org/Public_html/specs/C.S0050-0_v1.0_121503.pdf
2001-08-12 01:58:05 +00:00
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
2006-11-28 23:53:07 +00:00
# include <inttypes.h>
# include "config.h"
2001-08-12 01:58:05 +00:00
2006-11-28 23:13:08 +00:00
# ifdef MACOSX
# include <QuickTime/QuickTime.h>
# include <QuickTime/ImageCompression.h>
# include <QuickTime/ImageCodec.h>
# else
# include "loader/qtx/qtxsdk/components.h"
# endif
2001-08-17 00:40:25 +00:00
# include "mp_msg.h"
2001-09-26 21:35:14 +00:00
# include "help_mp.h"
2001-08-12 01:58:05 +00:00
2007-03-15 18:36:36 +00:00
# include "stream/stream.h"
2001-08-12 01:58:05 +00:00
# include "demuxer.h"
# include "stheader.h"
2007-12-14 07:14:33 +00:00
# include "libmpcodecs/img_format.h"
2006-11-13 18:41:24 +00:00
# include "libvo/sub.h"
2002-01-24 05:20:19 +00:00
# include "qtpalette.h"
2002-06-30 00:37:02 +00:00
# include "parse_mp4.h" // .MP4 specific stuff
2002-01-24 05:20:19 +00:00
2001-10-10 01:07:50 +00:00
# ifdef HAVE_ZLIB
# include <zlib.h>
# endif
2003-04-20 23:15:27 +00:00
# ifndef _FCNTL_H
2001-11-09 17:00:12 +00:00
# include <fcntl.h>
2002-06-07 22:41:26 +00:00
# endif
2001-11-09 17:00:12 +00:00
2002-10-07 16:43:04 +00:00
# define BE_16(x) (((unsigned char *)(x))[0] << 8 | \
( ( unsigned char * ) ( x ) ) [ 1 ] )
# define BE_32(x) (((unsigned char *)(x))[0] << 24 | \
( ( unsigned char * ) ( x ) ) [ 1 ] < < 16 | \
( ( unsigned char * ) ( x ) ) [ 2 ] < < 8 | \
( ( unsigned char * ) ( x ) ) [ 3 ] )
# define char2short(x,y) BE_16(&(x)[(y)])
# define char2int(x,y) BE_32(&(x)[(y)])
2002-03-21 06:05:14 +00:00
2001-10-05 23:13:26 +00:00
typedef struct {
unsigned int pts ; // duration
unsigned int size ;
off_t pos ;
} mov_sample_t ;
typedef struct {
2001-10-29 22:40:25 +00:00
unsigned int sample ; // number of the first sample in the chunk
2001-10-07 00:22:43 +00:00
unsigned int size ; // number of samples in the chunk
int desc ; // for multiple codecs mode - not used
2001-10-05 23:13:26 +00:00
off_t pos ;
} mov_chunk_t ;
typedef struct {
unsigned int first ;
unsigned int spc ;
unsigned int sdid ;
} mov_chunkmap_t ;
2001-10-07 00:22:43 +00:00
typedef struct {
unsigned int num ;
unsigned int dur ;
} mov_durmap_t ;
2002-07-07 15:21:30 +00:00
typedef struct {
unsigned int dur ;
unsigned int pos ;
int speed ;
//
int frames ;
int start_sample ;
int start_frame ;
int pts_offset ;
} mov_editlist_t ;
2002-02-10 00:45:56 +00:00
# define MOV_TRAK_UNKNOWN 0
# define MOV_TRAK_VIDEO 1
# define MOV_TRAK_AUDIO 2
# define MOV_TRAK_FLASH 3
# define MOV_TRAK_GENERIC 4
# define MOV_TRAK_CODE 5
2001-08-12 01:58:05 +00:00
typedef struct {
int id ;
int type ;
2002-01-05 19:29:52 +00:00
off_t pos ;
2001-10-06 00:58:23 +00:00
//
2002-11-29 20:25:32 +00:00
unsigned int media_handler ;
unsigned int data_handler ;
//
2001-08-12 01:58:05 +00:00
int timescale ;
2001-10-05 23:13:26 +00:00
unsigned int length ;
2001-10-07 00:22:43 +00:00
int samplesize ; // 0 = variable
int duration ; // 0 = variable
2001-08-12 01:58:05 +00:00
int width , height ; // for video
unsigned int fourcc ;
2004-12-29 23:26:01 +00:00
unsigned int nchannels ;
unsigned int samplebytes ;
2001-10-07 00:22:43 +00:00
//
2001-10-06 00:58:23 +00:00
int tkdata_len ; // track data
unsigned char * tkdata ;
int stdata_len ; // stream data
unsigned char * stdata ;
2002-03-14 02:26:49 +00:00
//
2002-03-21 20:43:43 +00:00
unsigned char * stream_header ;
int stream_header_len ; // if >0, this header should be sent before the 1st frame
//
2001-10-05 23:13:26 +00:00
int samples_size ;
mov_sample_t * samples ;
int chunks_size ;
mov_chunk_t * chunks ;
int chunkmap_size ;
mov_chunkmap_t * chunkmap ;
2001-10-07 00:22:43 +00:00
int durmap_size ;
mov_durmap_t * durmap ;
2001-10-29 21:55:07 +00:00
int keyframes_size ;
unsigned int * keyframes ;
2002-07-07 15:21:30 +00:00
int editlist_size ;
mov_editlist_t * editlist ;
int editlist_pos ;
2002-03-27 21:27:38 +00:00
//
void * desc ; // image/sound/etc description (pointer to ImageDescription etc)
2001-08-12 01:58:05 +00:00
} mov_track_t ;
2002-09-18 19:09:11 +00:00
void mov_build_index ( mov_track_t * trak , int timescale ) {
2001-10-05 23:13:26 +00:00
int i , j , s ;
int last = trak - > chunks_size ;
2001-10-07 00:22:43 +00:00
unsigned int pts = 0 ;
2001-12-22 00:33:35 +00:00
#if 0
if ( trak - > chunks_size < = 0 )
{
mp_msg ( MSGT_DEMUX , MSGL_WARN , " No chunk offset table, trying to build one! \n " ) ;
2002-03-15 15:57:57 +00:00
trak - > chunks_size = trak - > samples_size ; /* XXX: FIXME ! */
2006-06-04 22:41:27 +00:00
// audit: this code will be vulnerable if it is reenabled (currently #if 0)
2001-12-22 00:33:35 +00:00
trak - > chunks = realloc ( trak - > chunks , sizeof ( mov_chunk_t ) * trak - > chunks_size ) ;
for ( i = 0 ; i < trak - > chunks_size ; i + + )
trak - > chunks [ i ] . pos = - 1 ;
}
# endif
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV track #%d: %d chunks, %d samples \n " , trak - > id , trak - > chunks_size , trak - > samples_size ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " pts=%d scale=%d time=%5.3f \n " , trak - > length , trak - > timescale , ( float ) trak - > length / ( float ) trak - > timescale ) ;
2001-10-29 22:40:25 +00:00
2001-10-05 23:13:26 +00:00
// process chunkmap:
i = trak - > chunkmap_size ;
while ( i > 0 ) {
- - i ;
for ( j = trak - > chunkmap [ i ] . first ; j < last ; j + + ) {
trak - > chunks [ j ] . desc = trak - > chunkmap [ i ] . sdid ;
trak - > chunks [ j ] . size = trak - > chunkmap [ i ] . spc ;
}
last = trak - > chunkmap [ i ] . first ;
}
2001-10-07 00:22:43 +00:00
2001-12-22 00:33:35 +00:00
#if 0
for ( i = 0 ; i < trak - > chunks_size ; i + + )
{
/* fixup position */
if ( trak - > chunks [ i ] . pos = = - 1 )
if ( i > 0 )
trak - > chunks [ i ] . pos = trak - > chunks [ i - 1 ] . pos + trak - > chunks [ i - 1 ] . size ;
else
trak - > chunks [ i ] . pos = 0 ; /* FIXME: set initial pos */
# endif
2001-10-07 00:22:43 +00:00
// calc pts of chunks:
s = 0 ;
for ( j = 0 ; j < trak - > chunks_size ; j + + ) {
trak - > chunks [ j ] . sample = s ;
s + = trak - > chunks [ j ] . size ;
}
2005-08-30 23:24:47 +00:00
i = 0 ;
for ( j = 0 ; j < trak - > durmap_size ; j + + )
i + = trak - > durmap [ j ] . num ;
if ( i ! = s ) {
mp_msg ( MSGT_DEMUX , MSGL_WARN ,
" MOV: durmap and chunkmap sample count differ (%i vs %i) \n " , i , s ) ;
if ( i > s ) s = i ;
}
2001-10-07 00:22:43 +00:00
2002-02-10 00:45:56 +00:00
// workaround for fixed-size video frames (dv and uncompressed)
2002-11-29 20:25:32 +00:00
if ( ! trak - > samples_size & & trak - > type ! = MOV_TRAK_AUDIO ) {
2002-02-10 00:45:56 +00:00
trak - > samples_size = s ;
2006-05-11 18:50:46 +00:00
trak - > samples = calloc ( s , sizeof ( mov_sample_t ) ) ;
2002-02-10 00:45:56 +00:00
for ( i = 0 ; i < s ; i + + )
trak - > samples [ i ] . size = trak - > samplesize ;
trak - > samplesize = 0 ;
}
2001-10-07 00:22:43 +00:00
if ( ! trak - > samples_size ) {
// constant sampesize
if ( trak - > durmap_size = = 1 | | ( trak - > durmap_size = = 2 & & trak - > durmap [ 1 ] . num = = 1 ) ) {
2001-10-16 22:41:46 +00:00
trak - > duration = trak - > durmap [ 0 ] . dur ;
2001-10-26 14:04:17 +00:00
} else mp_msg ( MSGT_DEMUX , MSGL_ERR , " *** constant samplesize & variable duration not yet supported! *** \n Contact the author if you have such sample file! \n " ) ;
2001-10-07 00:22:43 +00:00
return ;
}
2005-08-30 23:24:47 +00:00
if ( trak - > samples_size < s ) {
mp_msg ( MSGT_DEMUX , MSGL_WARN ,
" MOV: durmap or chunkmap bigger than sample count (%i vs %i) \n " ,
s , trak - > samples_size ) ;
trak - > samples_size = s ;
2006-05-11 18:50:46 +00:00
trak - > samples = realloc_struct ( trak - > samples , s , sizeof ( mov_sample_t ) ) ;
2005-08-30 23:24:47 +00:00
}
2001-10-07 00:22:43 +00:00
// calc pts:
s = 0 ;
for ( j = 0 ; j < trak - > durmap_size ; j + + ) {
for ( i = 0 ; i < trak - > durmap [ j ] . num ; i + + ) {
trak - > samples [ s ] . pts = pts ;
+ + s ;
pts + = trak - > durmap [ j ] . dur ;
}
}
2001-10-05 23:13:26 +00:00
// calc sample offsets
s = 0 ;
for ( j = 0 ; j < trak - > chunks_size ; j + + ) {
off_t pos = trak - > chunks [ j ] . pos ;
for ( i = 0 ; i < trak - > chunks [ j ] . size ; i + + ) {
trak - > samples [ s ] . pos = pos ;
2001-10-26 14:04:17 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG3 , " Sample %5d: pts=%8d off=0x%08X size=%d \n " , s ,
2001-10-05 23:13:26 +00:00
trak - > samples [ s ] . pts ,
( int ) trak - > samples [ s ] . pos ,
trak - > samples [ s ] . size ) ;
pos + = trak - > samples [ s ] . size ;
+ + s ;
}
}
2002-07-07 15:21:30 +00:00
// precalc editlist entries
if ( trak - > editlist_size > 0 ) {
int frame = 0 ;
int e_pts = 0 ;
for ( i = 0 ; i < trak - > editlist_size ; i + + ) {
mov_editlist_t * el = & trak - > editlist [ i ] ;
int sample = 0 ;
int pts = el - > pos ;
el - > start_frame = frame ;
if ( pts < 0 ) {
// skip!
el - > frames = 0 ; continue ;
}
// find start sample
for ( ; sample < trak - > samples_size ; sample + + ) {
if ( pts < = trak - > samples [ sample ] . pts ) break ;
}
el - > start_sample = sample ;
2002-09-18 19:09:11 +00:00
el - > pts_offset = ( ( long long ) e_pts * ( long long ) trak - > timescale ) / ( long long ) timescale - trak - > samples [ sample ] . pts ;
pts + = ( ( long long ) el - > dur * ( long long ) trak - > timescale ) / ( long long ) timescale ;
2002-07-07 15:21:30 +00:00
e_pts + = el - > dur ;
// find end sample
for ( ; sample < trak - > samples_size ; sample + + ) {
2005-09-16 11:05:29 +00:00
if ( pts < trak - > samples [ sample ] . pts ) break ;
2002-07-07 15:21:30 +00:00
}
el - > frames = sample - el - > start_sample ;
frame + = el - > frames ;
2002-09-27 20:33:09 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " EL#%d: pts=%d 1st_sample=%d frames=%d (%5.3fs) pts_offs=%d \n " , i ,
el - > pos , el - > start_sample , el - > frames ,
( float ) ( el - > dur ) / ( float ) timescale , el - > pts_offset ) ;
2002-07-07 15:21:30 +00:00
}
}
2001-10-05 23:13:26 +00:00
}
2001-08-12 01:58:05 +00:00
# define MOV_MAX_TRACKS 256
2006-11-13 18:41:24 +00:00
# define MOV_MAX_SUBLEN 1024
2001-08-12 01:58:05 +00:00
typedef struct {
off_t moov_start ;
off_t moov_end ;
off_t mdat_start ;
off_t mdat_end ;
int track_db ;
mov_track_t * tracks [ MOV_MAX_TRACKS ] ;
2002-09-18 19:09:11 +00:00
int timescale ; // movie timescale
int duration ; // movie duration (in movie timescale units)
2006-11-13 18:41:24 +00:00
subtitle subs ;
char subtext [ MOV_MAX_SUBLEN + 1 ] ;
int current_sub ;
2001-08-12 01:58:05 +00:00
} mov_priv_t ;
# define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
2005-08-05 19:57:47 +00:00
static int mov_check_file ( demuxer_t * demuxer ) {
2001-08-12 01:58:05 +00:00
int flags = 0 ;
2001-11-13 21:11:10 +00:00
int no = 0 ;
2001-08-12 01:58:05 +00:00
mov_priv_t * priv = malloc ( sizeof ( mov_priv_t ) ) ;
2001-08-17 00:40:25 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Checking for MOV \n " ) ;
2001-08-12 01:58:05 +00:00
memset ( priv , 0 , sizeof ( mov_priv_t ) ) ;
2006-11-13 18:41:24 +00:00
priv - > current_sub = - 1 ;
2001-08-12 01:58:05 +00:00
while ( 1 ) {
2002-11-29 21:06:13 +00:00
int i ;
2002-01-05 19:29:52 +00:00
int skipped = 8 ;
2001-08-12 01:58:05 +00:00
off_t len = stream_read_dword ( demuxer - > stream ) ;
unsigned int id = stream_read_dword ( demuxer - > stream ) ;
if ( stream_eof ( demuxer - > stream ) ) break ; // EOF
2002-01-05 19:29:52 +00:00
if ( len = = 1 ) /* real size is 64bits - cjb */
{
# ifndef _LARGEFILE_SOURCE
if ( stream_read_dword ( demuxer - > stream ) ! = 0 )
2002-03-21 06:05:14 +00:00
mp_msg ( MSGT_DEMUX , MSGL_WARN , " 64bit file, but you've compiled MPlayer without LARGEFILE support! \n " ) ;
2002-01-05 19:29:52 +00:00
len = stream_read_dword ( demuxer - > stream ) ;
# else
len = stream_read_qword ( demuxer - > stream ) ;
# endif
skipped + = 8 ;
}
2002-03-21 15:01:39 +00:00
#if 0
2002-03-15 15:57:57 +00:00
else if ( len = = 0 ) /* deleted chunk */
{
/* XXX: CJB! is this right? - alex */
2002-03-21 16:44:15 +00:00
goto skip_chunk ;
2002-03-15 15:57:57 +00:00
}
2002-03-21 15:01:39 +00:00
# endif
2002-01-05 19:29:52 +00:00
else if ( len < 8 ) break ; // invalid chunk
2001-08-12 01:58:05 +00:00
switch ( id ) {
2002-03-22 00:54:10 +00:00
case MOV_FOURCC ( ' f ' , ' t ' , ' y ' , ' p ' ) : {
unsigned int tmp ;
// File Type Box (ftyp):
// char[4] major_brand (eg. 'isom')
// int minor_version (eg. 0x00000000)
// char[4] compatible_brands[] (eg. 'mp41')
// compatible_brands list spans to the end of box
# if 1
tmp = stream_read_dword ( demuxer - > stream ) ;
switch ( tmp ) {
case MOV_FOURCC ( ' i ' , ' s ' , ' o ' , ' m ' ) :
2004-01-20 04:59:48 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " ISO: File Type Major Brand: ISO Base Media \n " ) ;
break ;
case MOV_FOURCC ( ' m ' , ' p ' , ' 4 ' , ' 1 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: ISO/IEC 14496-1 (MPEG-4 system) v1 \n " ) ;
break ;
case MOV_FOURCC ( ' m ' , ' p ' , ' 4 ' , ' 2 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: ISO/IEC 14496-1 (MPEG-4 system) v2 \n " ) ;
break ;
case MOV_FOURCC ( ' M ' , ' 4 ' , ' A ' , ' ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: Apple iTunes AAC-LC Audio \n " ) ;
break ;
case MOV_FOURCC ( ' M ' , ' 4 ' , ' P ' , ' ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: Apple iTunes AAC-LC Protected Audio \n " ) ;
break ;
case MOV_FOURCC ( ' q ' , ' t ' , ' ' , ' ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: Original QuickTime \n " ) ;
break ;
case MOV_FOURCC ( ' 3 ' , ' g ' , ' p ' , ' 1 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: 3GPP Profile 1 \n " ) ;
break ;
case MOV_FOURCC ( ' 3 ' , ' g ' , ' p ' , ' 2 ' ) :
2005-04-28 18:25:50 +00:00
case MOV_FOURCC ( ' 3 ' , ' g ' , ' 2 ' , ' a ' ) :
2004-01-20 04:59:48 +00:00
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: 3GPP Profile 2 \n " ) ;
break ;
case MOV_FOURCC ( ' 3 ' , ' g ' , ' p ' , ' 3 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: 3GPP Profile 3 \n " ) ;
break ;
case MOV_FOURCC ( ' 3 ' , ' g ' , ' p ' , ' 4 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: 3GPP Profile 4 \n " ) ;
break ;
case MOV_FOURCC ( ' 3 ' , ' g ' , ' p ' , ' 5 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: 3GPP Profile 5 \n " ) ;
break ;
case MOV_FOURCC ( ' m ' , ' m ' , ' p ' , ' 4 ' ) :
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ISO: File Type Major Brand: Mobile ISO/IEC 14496-1 (MPEG-4 system) \n " ) ;
2002-03-22 00:54:10 +00:00
break ;
default :
tmp = be2me_32 ( tmp ) ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_WARN , " ISO: Unknown File Type Major Brand: %.4s \n " , ( char * ) & tmp ) ;
2002-03-22 00:54:10 +00:00
}
2004-01-20 04:59:48 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " ISO: File Type Minor Version: %d \n " ,
2002-03-22 00:54:10 +00:00
stream_read_dword ( demuxer - > stream ) ) ;
skipped + = 8 ;
// List all compatible brands
for ( i = 0 ; i < ( ( len - 16 ) / 4 ) ; i + + ) {
tmp = be2me_32 ( stream_read_dword ( demuxer - > stream ) ) ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " ISO: File Type Compatible Brand #%d: %.4s \n " , i , ( char * ) & tmp ) ;
2002-03-22 00:54:10 +00:00
skipped + = 4 ;
}
# endif
} break ;
2001-08-12 01:58:05 +00:00
case MOV_FOURCC ( ' m ' , ' o ' , ' o ' , ' v ' ) :
2002-03-15 15:57:57 +00:00
// case MOV_FOURCC('c','m','o','v'):
2001-08-17 00:40:25 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Movie header found! \n " ) ;
2002-03-15 15:57:57 +00:00
priv - > moov_start = ( off_t ) stream_tell ( demuxer - > stream ) ;
priv - > moov_end = ( off_t ) priv - > moov_start + len - skipped ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " MOV: Movie header: start: % " PRIx64 " end: % " PRIx64 " \n " ,
( int64_t ) priv - > moov_start , ( int64_t ) priv - > moov_end ) ;
2002-11-29 21:06:13 +00:00
skipped + = 8 ;
i = stream_read_dword ( demuxer - > stream ) - 8 ;
if ( stream_read_dword ( demuxer - > stream ) = = MOV_FOURCC ( ' r ' , ' m ' , ' r ' , ' a ' ) ) {
skipped + = i ;
mp_msg ( MSGT_DEMUX , MSGL_INFO , " MOV: Reference Media file!!! \n " ) ;
2003-01-13 02:42:06 +00:00
//set demuxer type to playlist ...
demuxer - > type = DEMUXER_TYPE_PLAYLIST ;
2002-11-29 21:06:13 +00:00
while ( i > 0 ) {
int len = stream_read_dword ( demuxer - > stream ) - 8 ;
int fcc = stream_read_dword ( demuxer - > stream ) ;
if ( len < 0 ) break ; // EOF!?
i - = 8 ;
// printf("i=%d len=%d\n",i,len);
switch ( fcc ) {
case MOV_FOURCC ( ' r ' , ' m ' , ' d ' , ' a ' ) :
continue ;
case MOV_FOURCC ( ' r ' , ' d ' , ' r ' , ' f ' ) : {
2007-05-28 14:25:48 +00:00
int tmp = stream_read_dword ( demuxer - > stream ) ;
2002-11-29 21:06:13 +00:00
int type = stream_read_dword_le ( demuxer - > stream ) ;
int slen = stream_read_dword ( demuxer - > stream ) ;
2003-01-13 02:42:06 +00:00
//char* s=malloc(slen+1);
//stream_read(demuxer->stream,s,slen);
//FIXME: also store type & data_rate ?
ds_read_packet ( demuxer - > video ,
demuxer - > stream ,
slen ,
0 ,
stream_tell ( demuxer - > stream ) ,
0 // no flags
) ;
flags | = 4 ;
mp_msg ( MSGT_DEMUX , MSGL_V , " Added reference to playlist \n " ) ;
//s[slen]=0;
//mp_msg(MSGT_DEMUX,MSGL_INFO,"REF: [%.4s] %s\n",&type,s);
2002-11-29 21:06:13 +00:00
len - = 12 + slen ; i - = 12 + slen ; break ;
}
case MOV_FOURCC ( ' r ' , ' m ' , ' d ' , ' r ' ) : {
2007-05-28 14:25:48 +00:00
int flags = stream_read_dword ( demuxer - > stream ) ;
2002-11-29 21:06:13 +00:00
int rate = stream_read_dword ( demuxer - > stream ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " min. data rate: %d bits/sec \n " , rate ) ;
len - = 8 ; i - = 8 ; break ;
}
case MOV_FOURCC ( ' r ' , ' m ' , ' q ' , ' u ' ) : {
int q = stream_read_dword ( demuxer - > stream ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " quality index: %d \n " , q ) ;
len - = 4 ; i - = 4 ; break ;
}
}
i - = len ; stream_skip ( demuxer - > stream , len ) ;
}
}
2001-08-12 01:58:05 +00:00
flags | = 1 ;
break ;
2002-04-18 16:06:24 +00:00
case MOV_FOURCC ( ' w ' , ' i ' , ' d ' , ' e ' ) :
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: 'WIDE' chunk found! \n " ) ;
if ( flags & 2 ) break ;
2001-08-12 01:58:05 +00:00
case MOV_FOURCC ( ' m ' , ' d ' , ' a ' , ' t ' ) :
2001-08-17 00:40:25 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Movie DATA found! \n " ) ;
2001-08-12 01:58:05 +00:00
priv - > mdat_start = stream_tell ( demuxer - > stream ) ;
2002-01-05 19:29:52 +00:00
priv - > mdat_end = priv - > mdat_start + len - skipped ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " MOV: Movie data: start: % " PRIx64 " end: % " PRIx64 " \n " ,
( int64_t ) priv - > mdat_start , ( int64_t ) priv - > mdat_end ) ;
2001-08-12 01:58:05 +00:00
flags | = 2 ;
2003-01-12 20:11:20 +00:00
if ( flags = = 3 ) {
// if we're over the headers, then we can stop parsing here!
demuxer - > priv = priv ;
2005-08-05 19:57:47 +00:00
return DEMUXER_TYPE_MOV ;
2003-01-12 20:11:20 +00:00
}
2001-08-12 01:58:05 +00:00
break ;
2001-10-23 16:21:24 +00:00
case MOV_FOURCC ( ' f ' , ' r ' , ' e ' , ' e ' ) :
2001-11-17 01:10:46 +00:00
case MOV_FOURCC ( ' s ' , ' k ' , ' i ' , ' p ' ) :
2002-03-15 15:57:57 +00:00
case MOV_FOURCC ( ' j ' , ' u ' , ' n ' , ' k ' ) :
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " MOV: free space (len: % " PRId64 " ) \n " , ( int64_t ) len ) ;
2002-03-15 15:57:57 +00:00
/* unused, if you edit a mov, you can use space provided by free atoms (redefining it) */
2001-11-13 21:11:10 +00:00
break ;
2002-08-01 21:16:57 +00:00
case MOV_FOURCC ( ' p ' , ' n ' , ' o ' , ' t ' ) :
case MOV_FOURCC ( ' P ' , ' I ' , ' C ' , ' T ' ) :
/* dunno what, but we shoudl ignore it */
break ;
2001-08-12 01:58:05 +00:00
default :
2002-10-16 20:14:29 +00:00
if ( no = = 0 ) { free ( priv ) ; return 0 ; } // first chunk is bad!
2002-03-01 03:02:25 +00:00
id = be2me_32 ( id ) ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: unknown chunk: %.4s %d \n " , ( char * ) & id , ( int ) len ) ;
2001-08-12 01:58:05 +00:00
}
2007-09-09 09:54:57 +00:00
//skip_chunk:
2002-01-05 19:29:52 +00:00
if ( ! stream_skip ( demuxer - > stream , len - skipped ) ) break ;
2001-11-13 21:11:10 +00:00
+ + no ;
2001-08-12 01:58:05 +00:00
}
2002-10-16 20:14:29 +00:00
if ( flags = = 3 ) {
demuxer - > priv = priv ;
2005-08-05 19:57:47 +00:00
return DEMUXER_TYPE_MOV ;
2002-10-16 20:14:29 +00:00
}
free ( priv ) ;
2003-01-27 22:29:47 +00:00
if ( ( flags = = 5 ) | | ( flags = = 7 ) ) // reference & header sent
2005-08-31 13:04:22 +00:00
return DEMUXER_TYPE_PLAYLIST ;
2003-01-13 02:42:06 +00:00
2001-10-10 01:07:50 +00:00
if ( flags = = 1 )
mp_msg ( MSGT_DEMUX , MSGL_WARN , " MOV: missing data (mdat) chunk! Maybe broken file... \n " ) ;
else if ( flags = = 2 )
mp_msg ( MSGT_DEMUX , MSGL_WARN , " MOV: missing header (moov/cmov) chunk! Maybe broken file... \n " ) ;
2001-08-12 01:58:05 +00:00
2002-10-16 20:14:29 +00:00
return 0 ;
2001-08-12 01:58:05 +00:00
}
2005-08-05 19:57:47 +00:00
static void demux_close_mov ( demuxer_t * demuxer ) {
2005-06-20 14:16:59 +00:00
mov_priv_t * priv = demuxer - > priv ;
int i ;
if ( ! priv )
return ;
for ( i = 0 ; i < MOV_MAX_TRACKS ; i + + ) {
mov_track_t * track = priv - > tracks [ i ] ;
if ( track ) {
free ( track - > tkdata ) ;
free ( track - > stdata ) ;
free ( track - > stream_header ) ;
free ( track - > samples ) ;
free ( track - > chunks ) ;
free ( track - > chunkmap ) ;
free ( track - > durmap ) ;
free ( track - > keyframes ) ;
free ( track - > editlist ) ;
free ( track - > desc ) ;
free ( track ) ;
}
}
free ( priv ) ;
}
2006-08-04 21:19:06 +00:00
unsigned int store_ughvlc ( unsigned char * s , unsigned int v ) {
unsigned int n = 0 ;
while ( v > = 0xff ) {
* s + + = 0xff ;
v - = 0xff ;
n + + ;
}
* s = v ;
n + + ;
return n ;
}
2006-11-17 20:13:21 +00:00
static void init_vobsub ( sh_sub_t * sh , mov_track_t * trak ) {
int i ;
uint8_t * pal = trak - > stdata ;
sh - > type = ' v ' ;
if ( trak - > stdata_len < 106 )
return ;
sh - > has_palette = 1 ;
pal + = 42 ;
for ( i = 0 ; i < 16 ; i + + ) {
sh - > palette [ i ] = BE_32 ( pal ) ;
pal + = 4 ;
}
}
2005-07-10 08:57:31 +00:00
static int lschunks_intrak ( demuxer_t * demuxer , int level , unsigned int id ,
off_t pos , off_t len , mov_track_t * trak ) ;
2007-08-25 18:09:00 +00:00
static int gen_sh_audio ( sh_audio_t * sh , mov_track_t * trak , int timescale ) {
2002-03-19 21:48:55 +00:00
#if 0
struct {
int16_t version ; // 0 or 1 (version 1 is qt3.0+)
int16_t revision ; // 0
int32_t vendor_id ; // 0
int16_t channels ; // 1 or 2 (Mono/Stereo)
int16_t samplesize ; // 8 or 16 (8Bit/16Bit)
int16_t compression_id ; // if version 0 then 0
// if version 1 and vbr then -2 else 0
int16_t packet_size ; // 0
2002-03-21 06:05:14 +00:00
uint16_t sample_rate ; // samplerate (Hz)
2002-03-19 21:48:55 +00:00
// qt3.0+ (version == 1)
uint32_t samples_per_packet ; // 0 or num uncompressed samples in a packet
// if 0 below three values are also 0
uint32_t bytes_per_packet ; // 0 or num compressed bytes for one channel
uint32_t bytes_per_frame ; // 0 or num compressed bytes for all channels
// (channels * bytes_per_packet)
uint32_t bytes_per_sample ; // 0 or size of uncompressed sample
// if samples_per_packet and bytes_per_packet are constant (CBR)
// then bytes_per_frame and bytes_per_sample must be 0 (else is VBR)
// ---
// optional additional atom-based fields
// ([int32_t size,int32_t type,some data ],repeat)
} my_stdata ;
# endif
2006-01-02 06:56:22 +00:00
int version , adjust ;
2006-06-09 21:30:06 +00:00
int is_vorbis = 0 ;
2001-10-05 23:13:26 +00:00
sh - > format = trak - > fourcc ;
2002-03-14 02:26:49 +00:00
2006-07-23 22:34:02 +00:00
// crude audio delay from editlist0 hack ::atm
if ( trak - > editlist_size > = 1 ) {
if ( trak - > editlist [ 0 ] . pos = = - 1 ) {
2007-08-25 18:09:00 +00:00
sh - > stream_delay = ( float ) trak - > editlist [ 0 ] . dur / ( float ) timescale ;
2006-07-23 22:34:02 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Initial Audio-Delay: %.3f sec \n " , sh - > stream_delay ) ;
}
}
2004-12-29 23:26:01 +00:00
switch ( sh - > format ) {
case 0x726D6173 : /* samr */
/* amr narrowband */
trak - > samplebytes = sh - > samplesize = 1 ;
trak - > nchannels = sh - > channels = 1 ;
sh - > samplerate = 8000 ;
break ;
case 0x62776173 : /* sawb */
/* amr wideband */
trak - > samplebytes = sh - > samplesize = 1 ;
trak - > nchannels = sh - > channels = 1 ;
sh - > samplerate = 16000 ;
break ;
default :
2002-03-21 06:05:14 +00:00
// assumptions for below table: short is 16bit, int is 32bit, intfp is 16bit
// XXX: 32bit fixed point numbers (intfp) are only 2 Byte!
2002-03-19 21:48:55 +00:00
// short values are usually one byte leftpadded by zero
// int values are usually two byte leftpadded by zero
2002-03-14 02:26:49 +00:00
// stdata[]:
// 8 short version
// 10 short revision
// 12 int vendor_id
// 16 short channels
// 18 short samplesize
// 20 short compression_id
// 22 short packet_size (==0)
2002-03-21 06:05:14 +00:00
// 24 intfp sample_rate
// (26 short) unknown (==0)
2002-06-30 00:37:02 +00:00
// ---- qt3.0+ (version>=1)
2002-03-14 02:26:49 +00:00
// 28 int samples_per_packet
// 32 int bytes_per_packet
// 36 int bytes_per_frame
// 40 int bytes_per_sample
2002-03-21 06:05:14 +00:00
// there may be additional atoms following at 28 (version 0)
// or 44 (version 1), eg. esds atom of .MP4 files
2002-03-19 21:48:55 +00:00
// esds atom:
2002-03-21 06:05:14 +00:00
// 28 int atom size (bytes of int size, int type and data)
// 32 char[4] atom type (fourc charater code -> esds)
2002-03-24 14:47:28 +00:00
// 36 char[] atom data (len=size-8)
2002-03-19 21:48:55 +00:00
2005-09-27 11:21:13 +00:00
// TODO: fix parsing for files using version 2.
2006-01-02 06:56:22 +00:00
version = char2short ( trak - > stdata , 8 ) ;
if ( version > 1 )
mp_msg ( MSGT_DEMUX , MSGL_WARN , " MOV: version %d sound atom may not parse correctly! \n " , version ) ;
2004-12-29 23:26:01 +00:00
trak - > samplebytes = sh - > samplesize = char2short ( trak - > stdata , 18 ) / 8 ;
2006-01-02 06:56:22 +00:00
/* I can't find documentation, but so far this is the case. -Corey */
switch ( char2short ( trak - > stdata , 16 ) ) {
case 1 :
trak - > nchannels = 1 ; break ;
case 2 :
trak - > nchannels = 2 ; break ;
case 3 :
trak - > nchannels = 6 ; break ;
default :
mp_msg ( MSGT_DEMUX , MSGL_WARN ,
" MOV: unable to determine audio channels, assuming 2 (got %d) \n " ,
char2short ( trak - > stdata , 16 ) ) ;
trak - > nchannels = 2 ;
}
sh - > channels = trak - > nchannels ;
2002-03-20 04:22:14 +00:00
/*printf("MOV: timescale: %d samplerate: %d durmap: %d (%d) -> %d (%d)\n",
trak - > timescale , char2short ( trak - > stdata , 24 ) , trak - > durmap [ 0 ] . dur ,
trak - > durmap [ 0 ] . num , trak - > timescale / trak - > durmap [ 0 ] . dur ,
char2short ( trak - > stdata , 24 ) / trak - > durmap [ 0 ] . dur ) ; */
2002-03-19 21:48:55 +00:00
sh - > samplerate = char2short ( trak - > stdata , 24 ) ;
2007-03-07 01:23:37 +00:00
if ( ( sh - > samplerate < 7000 ) & & trak - > durmap & & trak - > durmap [ 0 ] . dur > 1 ) {
2002-03-20 04:22:14 +00:00
switch ( char2short ( trak - > stdata , 24 ) / trak - > durmap [ 0 ] . dur ) {
// TODO: add more cases.
case 31 :
sh - > samplerate = 32000 ; break ;
case 43 :
sh - > samplerate = 44100 ; break ;
case 47 :
sh - > samplerate = 48000 ; break ;
default :
mp_msg ( MSGT_DEMUX , MSGL_WARN ,
" MOV: unable to determine audio samplerate, "
" assuming 44.1kHz (got %d) \n " ,
char2short ( trak - > stdata , 24 ) / trak - > durmap [ 0 ] . dur ) ;
sh - > samplerate = 44100 ;
}
}
2004-12-29 23:26:01 +00:00
}
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Audio bits: %d chans: %d rate: %d \n " ,
2004-12-29 23:26:01 +00:00
sh - > samplesize * 8 , sh - > channels , sh - > samplerate ) ;
2002-06-30 00:37:02 +00:00
2002-10-31 19:35:20 +00:00
if ( trak - > stdata_len > = 44 & & trak - > stdata [ 9 ] > = 1 ) {
2002-06-30 00:37:02 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Audio header: samp/pack=%d bytes/pack=%d bytes/frame=%d bytes/samp=%d \n " ,
char2int ( trak - > stdata , 28 ) ,
char2int ( trak - > stdata , 32 ) ,
char2int ( trak - > stdata , 36 ) ,
char2int ( trak - > stdata , 40 ) ) ;
2002-10-31 19:35:20 +00:00
if ( trak - > stdata_len > = 44 + 8 ) {
int len = char2int ( trak - > stdata , 44 ) ;
int fcc = char2int ( trak - > stdata , 48 ) ;
// we have extra audio headers!!!
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Audio extra header: len=%d fcc=0x%X \n " , len , fcc ) ;
2005-03-30 22:10:07 +00:00
if ( ( len > = 4 ) & &
( char2int ( trak - > stdata , 52 ) > = 12 ) & &
2006-03-13 23:32:36 +00:00
( char2int ( trak - > stdata , 52 + 4 ) = = MOV_FOURCC ( ' f ' , ' r ' , ' m ' , ' a ' ) ) ) {
switch ( char2int ( trak - > stdata , 52 + 8 ) ) {
case MOV_FOURCC ( ' a ' , ' l ' , ' a ' , ' c ' ) :
if ( len > = 36 + char2int ( trak - > stdata , 52 ) ) {
2005-03-30 22:10:07 +00:00
sh - > codecdata_len = char2int ( trak - > stdata , 52 + char2int ( trak - > stdata , 52 ) ) ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found alac atom (%d)! \n " , sh - > codecdata_len ) ;
2006-07-13 16:41:13 +00:00
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
2005-03-30 22:10:07 +00:00
memcpy ( sh - > codecdata , & trak - > stdata [ 52 + char2int ( trak - > stdata , 52 ) ] , sh - > codecdata_len ) ;
2006-03-13 23:32:36 +00:00
}
break ;
case MOV_FOURCC ( ' i ' , ' n ' , ' 2 ' , ' 4 ' ) :
case MOV_FOURCC ( ' i ' , ' n ' , ' 3 ' , ' 2 ' ) :
case MOV_FOURCC ( ' f ' , ' l ' , ' 3 ' , ' 2 ' ) :
case MOV_FOURCC ( ' f ' , ' l ' , ' 6 ' , ' 4 ' ) :
if ( ( len > = 22 ) & &
( char2int ( trak - > stdata , 52 + 16 ) = = MOV_FOURCC ( ' e ' , ' n ' , ' d ' , ' a ' ) ) & &
( char2short ( trak - > stdata , 52 + 20 ) ) ) {
2006-03-14 00:02:42 +00:00
sh - > format = char2int ( trak - > stdata , 52 + 8 ) ;
2006-03-13 23:32:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found little endian PCM data, reversed fourcc:%04x \n " , sh - > format ) ;
}
break ;
2006-03-27 21:37:18 +00:00
default :
if ( len > 8 & & len + 44 < = trak - > stdata_len ) {
sh - > codecdata_len = len - 8 ;
2008-01-09 07:18:14 +00:00
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
memcpy ( sh - > codecdata , trak - > stdata + 44 + 8 , sh - > codecdata_len ) ;
2006-03-27 21:37:18 +00:00
}
2006-03-13 23:32:36 +00:00
}
2005-03-30 22:10:07 +00:00
} else {
2005-10-05 14:55:06 +00:00
if ( len > 8 & & len + 44 < = trak - > stdata_len ) {
2002-10-31 19:35:20 +00:00
sh - > codecdata_len = len - 8 ;
2008-01-09 07:18:14 +00:00
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
memcpy ( sh - > codecdata , trak - > stdata + 44 + 8 , sh - > codecdata_len ) ;
2005-09-27 11:21:13 +00:00
}
2005-03-30 22:10:07 +00:00
}
2002-10-31 19:35:20 +00:00
}
}
2002-06-30 00:37:02 +00:00
2006-01-02 06:56:22 +00:00
switch ( version ) {
case 0 :
adjust = 0 ; break ;
case 1 :
adjust = 48 ; break ;
case 2 :
adjust = 68 ; break ;
default :
mp_msg ( MSGT_DEMUX , MSGL_WARN , " MOV: unknown sound atom version (%d); may not work! \n " , version ) ;
adjust = 68 ;
}
if ( trak - > stdata_len > = 36 + adjust ) {
2003-03-15 10:52:30 +00:00
int atom_len = char2int ( trak - > stdata , 28 + adjust ) ;
switch ( char2int ( trak - > stdata , 32 + adjust ) ) { // atom type
2002-03-24 02:25:41 +00:00
case MOV_FOURCC ( ' e ' , ' s ' , ' d ' , ' s ' ) : {
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found MPEG4 audio Elementary Stream Descriptor atom (%d)! \n " , atom_len ) ;
2002-03-24 14:47:28 +00:00
if ( atom_len > 8 ) {
2002-03-24 06:10:13 +00:00
esds_t esds ;
2003-03-15 10:52:30 +00:00
if ( ! mp4_parse_esds ( & trak - > stdata [ 36 + adjust ] , atom_len - 8 , & esds ) ) {
2006-08-11 22:57:33 +00:00
/* 0xdd is a "user private" id, not an official allocated id (see http://www.mp4ra.org/object.html),
so perform some extra checks to be sure that this is really vorbis audio */
if ( esds . objectTypeId = = 0xdd & & esds . streamType = = 0x15 & & sh - > format = = 0x6134706D & & esds . decoderConfigLen > 8 )
2006-06-09 21:30:06 +00:00
{
//vorbis audio
unsigned char * buf [ 3 ] ;
unsigned short sizes [ 3 ] ;
int offset , len , k ;
unsigned char * ptr = esds . decoderConfig ;
if ( ptr [ 0 ] ! = 0 | | ptr [ 1 ] ! = 30 ) goto quit_vorbis_block ; //wrong extradata layout
offset = len = 0 ;
for ( k = 0 ; k < 3 ; k + + )
{
sizes [ k ] = ( ptr [ offset ] < < 8 ) | ptr [ offset + 1 ] ;
len + = sizes [ k ] ;
offset + = 2 ;
if ( offset + sizes [ k ] > esds . decoderConfigLen )
{
mp_msg ( MSGT_DEMUX , MSGL_FATAL , " MOV: ERROR!, not enough vorbis extradata to read: offset = %d, k=%d, size=%d, len: %d \n " , offset , k , sizes [ k ] , esds . decoderConfigLen ) ;
goto quit_vorbis_block ;
}
buf [ k ] = malloc ( sizes [ k ] ) ;
if ( ! buf [ k ] ) goto quit_vorbis_block ;
memcpy ( buf [ k ] , & ptr [ offset ] , sizes [ k ] ) ;
offset + = sizes [ k ] ;
}
sh - > codecdata_len = len + len / 255 + 64 ;
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
ptr = sh - > codecdata ;
ptr [ 0 ] = 2 ;
offset = 1 ;
offset + = store_ughvlc ( & ptr [ offset ] , sizes [ 0 ] ) ;
offset + = store_ughvlc ( & ptr [ offset ] , sizes [ 1 ] ) ;
for ( k = 0 ; k < 3 ; k + + )
{
memcpy ( & ptr [ offset ] , buf [ k ] , sizes [ k ] ) ;
offset + = sizes [ k ] ;
}
sh - > codecdata_len = offset ;
sh - > codecdata = realloc ( sh - > codecdata , offset ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " demux_mov, vorbis extradata size: %d \n " , offset ) ;
is_vorbis = 1 ;
quit_vorbis_block :
sh - > format = mmioFOURCC ( ' v ' , ' r ' , ' b ' , ' s ' ) ;
}
2002-03-24 06:10:13 +00:00
sh - > i_bps = esds . avgBitrate / 8 ;
2002-03-24 02:25:41 +00:00
2002-08-05 18:22:14 +00:00
// printf("######## audio format = %d ########\n",esds.objectTypeId);
2004-11-15 15:04:57 +00:00
if ( esds . objectTypeId = = MP4OTI_MPEG1Audio | | esds . objectTypeId = = MP4OTI_MPEG2AudioPart3 )
2002-08-05 18:22:14 +00:00
sh - > format = 0x55 ; // .mp3
2006-08-11 22:57:33 +00:00
if ( esds . objectTypeId = = MP4OTI_13kVoice ) { // 13K Voice, defined by 3GPP2
sh - > format = mmioFOURCC ( ' Q ' , ' c ' , ' l ' , ' p ' ) ;
trak - > nchannels = sh - > channels = 1 ;
trak - > samplebytes = sh - > samplesize = 1 ;
}
2002-03-24 02:25:41 +00:00
// dump away the codec specific configuration for the AAC decoder
2002-08-05 18:22:14 +00:00
if ( esds . decoderConfigLen ) {
2005-02-15 21:04:33 +00:00
if ( ( esds . decoderConfig [ 0 ] > > 3 ) = = 29 )
sh - > format = 0x1d61346d ; // request multi-channel mp3 decoder
2006-06-09 21:30:06 +00:00
if ( ! is_vorbis )
{
2002-03-24 06:10:13 +00:00
sh - > codecdata_len = esds . decoderConfigLen ;
2006-07-13 16:41:13 +00:00
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
2002-03-24 06:10:13 +00:00
memcpy ( sh - > codecdata , esds . decoderConfig , sh - > codecdata_len ) ;
2002-08-05 18:22:14 +00:00
}
2006-06-09 21:30:06 +00:00
}
2002-03-24 03:07:18 +00:00
}
2002-03-24 06:10:13 +00:00
mp4_free_esds ( & esds ) ; // freeup esds mem
2002-03-24 02:25:41 +00:00
#if 0
{ FILE * f = fopen ( " esds.dat " , " wb " ) ;
fwrite ( & trak - > stdata [ 36 ] , atom_len - 8 , 1 , f ) ;
fclose ( f ) ; }
# endif
}
} break ;
2005-03-06 17:55:31 +00:00
case MOV_FOURCC ( ' a ' , ' l ' , ' a ' , ' c ' ) : {
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found alac atom (%d)! \n " , atom_len ) ;
2005-03-06 17:55:31 +00:00
if ( atom_len > 8 ) {
// copy all the atom (not only payload) for lavc alac decoder
sh - > codecdata_len = atom_len ;
2006-07-13 16:41:13 +00:00
sh - > codecdata = malloc ( sh - > codecdata_len ) ;
2005-03-06 17:55:31 +00:00
memcpy ( sh - > codecdata , & trak - > stdata [ 28 ] , sh - > codecdata_len ) ;
}
} break ;
2005-05-05 21:40:33 +00:00
case MOV_FOURCC ( ' d ' , ' a ' , ' m ' , ' r ' ) :
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found AMR audio atom %c%c%c%c (%d)! \n " , trak - > stdata [ 32 + adjust ] , trak - > stdata [ 33 + adjust ] , trak - > stdata [ 34 + adjust ] , trak - > stdata [ 35 + adjust ] , atom_len ) ;
2005-05-05 21:40:33 +00:00
if ( atom_len > 14 ) {
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " mov: vendor: %c%c%c%c Version: %d \n " , trak - > stdata [ 36 + adjust ] , trak - > stdata [ 37 + adjust ] , trak - > stdata [ 38 + adjust ] , trak - > stdata [ 39 + adjust ] , trak - > stdata [ 40 + adjust ] ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Modes set: %02x%02x \n " , trak - > stdata [ 41 + adjust ] , trak - > stdata [ 42 + adjust ] ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Mode change period: %d Frames per sample: %d \n " , trak - > stdata [ 43 + adjust ] , trak - > stdata [ 44 + adjust ] ) ;
2005-05-05 21:40:33 +00:00
}
break ;
2002-03-19 21:48:55 +00:00
default :
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unknown audio atom %c%c%c%c (%d)! \n " ,
2003-03-15 10:52:30 +00:00
trak - > stdata [ 32 + adjust ] , trak - > stdata [ 33 + adjust ] , trak - > stdata [ 34 + adjust ] , trak - > stdata [ 35 + adjust ] ,
2002-03-19 21:48:55 +00:00
atom_len ) ;
}
}
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Fourcc: %.4s \n " , ( char * ) & trak - > fourcc ) ;
2001-10-29 21:25:10 +00:00
#if 0
{ FILE * f = fopen ( " stdata.dat " , " wb " ) ;
fwrite ( trak - > stdata , trak - > stdata_len , 1 , f ) ;
fclose ( f ) ; }
{ FILE * f = fopen ( " tkdata.dat " , " wb " ) ;
fwrite ( trak - > tkdata , trak - > tkdata_len , 1 , f ) ;
fclose ( f ) ; }
# endif
2001-10-06 00:58:23 +00:00
// Emulate WAVEFORMATEX struct:
2006-06-09 21:30:06 +00:00
sh - > wf = malloc ( sizeof ( WAVEFORMATEX ) + ( is_vorbis ? sh - > codecdata_len : 0 ) ) ;
2001-10-06 00:58:23 +00:00
memset ( sh - > wf , 0 , sizeof ( WAVEFORMATEX ) ) ;
2004-12-29 23:26:01 +00:00
sh - > wf - > nChannels = sh - > channels ;
2001-10-29 21:25:10 +00:00
sh - > wf - > wBitsPerSample = ( trak - > stdata [ 18 ] < < 8 ) + trak - > stdata [ 19 ] ;
// sh->wf->nSamplesPerSec=trak->timescale;
2005-05-06 22:26:36 +00:00
sh - > wf - > nSamplesPerSec = sh - > samplerate ;
2002-11-02 22:39:02 +00:00
if ( trak - > stdata_len > = 44 & & trak - > stdata [ 9 ] > = 1 & & char2int ( trak - > stdata , 28 ) > 0 ) {
2002-10-31 23:16:27 +00:00
//Audio header: samp/pack=4096 bytes/pack=743 bytes/frame=1486 bytes/samp=2
sh - > wf - > nAvgBytesPerSec = ( sh - > wf - > nChannels * sh - > wf - > nSamplesPerSec *
char2int ( trak - > stdata , 32 ) + char2int ( trak - > stdata , 28 ) / 2 )
/ char2int ( trak - > stdata , 28 ) ;
sh - > wf - > nBlockAlign = char2int ( trak - > stdata , 36 ) ;
} else {
sh - > wf - > nAvgBytesPerSec = sh - > wf - > nChannels * sh - > wf - > wBitsPerSample * sh - > wf - > nSamplesPerSec / 8 ;
2002-11-04 20:36:51 +00:00
// workaround for ms11 ima4
if ( sh - > format = = 0x1100736d & & trak - > stdata_len > = 36 )
sh - > wf - > nBlockAlign = char2int ( trak - > stdata , 36 ) ;
2002-10-31 23:16:27 +00:00
}
2006-06-09 21:30:06 +00:00
if ( is_vorbis & & sh - > codecdata_len )
{
memcpy ( sh - > wf + 1 , sh - > codecdata , sh - > codecdata_len ) ;
sh - > wf - > cbSize = sh - > codecdata_len ;
}
2001-10-06 00:58:23 +00:00
// Selection:
2002-12-07 01:01:25 +00:00
// if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){
// // (auto)selected audio track:
// demuxer->audio->id=priv->track_db;
// demuxer->audio->sh=sh; sh->ds=demuxer->audio;
// }
2007-08-25 18:09:00 +00:00
return 1 ;
}
static int gen_sh_video ( sh_video_t * sh , mov_track_t * trak , int timescale ) {
2007-04-25 00:03:27 +00:00
int depth , i , entry ;
2003-09-02 14:48:49 +00:00
int flag , start , count_flag , end , palette_count , gray ;
2002-03-14 02:26:49 +00:00
int hdr_ptr = 76 ; // the byte just after depth
2002-01-13 06:01:04 +00:00
unsigned char * palette_map ;
2007-12-14 07:14:33 +00:00
depth = trak - > stdata [ 75 ] | ( trak - > stdata [ 74 ] < < 8 ) ;
if ( trak - > fourcc = = mmioFOURCC ( ' r ' , ' a ' , ' w ' , ' ' ) ) {
sh - > format = IMGFMT_RGB | depth ;
} else
2007-12-14 07:15:13 +00:00
sh - > format = trak - > fourcc ;
2002-03-14 02:26:49 +00:00
2006-07-23 22:34:02 +00:00
// crude video delay from editlist0 hack ::atm
if ( trak - > editlist_size > = 1 ) {
if ( trak - > editlist [ 0 ] . pos = = - 1 ) {
2007-08-25 18:09:00 +00:00
sh - > stream_delay = ( float ) trak - > editlist [ 0 ] . dur / ( float ) timescale ;
2006-07-23 22:34:02 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Initial Video-Delay: %.3f sec \n " , sh - > stream_delay ) ;
}
}
2005-07-10 09:05:14 +00:00
if ( trak - > stdata_len < 78 ) {
mp_msg ( MSGT_DEMUXER , MSGL_WARN ,
" MOV: Invalid (%d bytes instead of >= 78) video trak desc \n " ,
trak - > stdata_len ) ;
2007-08-25 18:09:00 +00:00
return 0 ;
2005-07-10 09:05:14 +00:00
}
2002-03-14 02:26:49 +00:00
// stdata[]:
// 8 short version
// 10 short revision
// 12 int vendor_id
// 16 int temporal_quality
// 20 int spatial_quality
// 24 short width
// 26 short height
// 28 int h_dpi
// 32 int v_dpi
// 36 int 0
// 40 short frames_per_sample
2002-03-21 06:05:14 +00:00
// 42 char[4] compressor_name
2002-03-14 02:26:49 +00:00
// 74 short depth
// 76 short color_table_id
2002-03-21 06:05:14 +00:00
// additional atoms may follow,
// eg esds atom from .MP4 files
// 78 int atom size
// 82 char[4] atom type
// 86 ... atom data
2006-05-11 18:50:46 +00:00
{ ImageDescription * id = malloc ( 8 + trak - > stdata_len ) ; // safe
2002-03-27 21:27:38 +00:00
trak - > desc = id ;
id - > idSize = 8 + trak - > stdata_len ;
2003-05-10 09:32:02 +00:00
// id->cType=bswap_32(trak->fourcc);
id - > cType = le2me_32 ( trak - > fourcc ) ;
2002-03-27 21:27:38 +00:00
id - > version = char2short ( trak - > stdata , 8 ) ;
id - > revisionLevel = char2short ( trak - > stdata , 10 ) ;
id - > vendor = char2int ( trak - > stdata , 12 ) ;
id - > temporalQuality = char2int ( trak - > stdata , 16 ) ;
id - > spatialQuality = char2int ( trak - > stdata , 20 ) ;
id - > width = char2short ( trak - > stdata , 24 ) ;
id - > height = char2short ( trak - > stdata , 26 ) ;
id - > hRes = char2int ( trak - > stdata , 28 ) ;
id - > vRes = char2int ( trak - > stdata , 32 ) ;
id - > dataSize = char2int ( trak - > stdata , 36 ) ;
id - > frameCount = char2short ( trak - > stdata , 40 ) ;
memcpy ( & id - > name , trak - > stdata + 42 , 32 ) ;
id - > depth = char2short ( trak - > stdata , 74 ) ;
id - > clutID = char2short ( trak - > stdata , 76 ) ;
2002-11-29 20:25:32 +00:00
if ( trak - > stdata_len > 78 ) memcpy ( ( ( char * ) & id - > clutID ) + 2 , trak - > stdata + 78 , trak - > stdata_len - 78 ) ;
2002-11-11 23:46:27 +00:00
sh - > ImageDesc = id ;
#if 0
2002-03-27 21:27:38 +00:00
{ FILE * f = fopen ( " ImageDescription " , " wb " ) ;
fwrite ( id , id - > idSize , 1 , f ) ;
fclose ( f ) ;
}
2002-11-11 23:46:27 +00:00
# endif
2002-03-27 21:27:38 +00:00
}
2002-03-21 06:05:14 +00:00
if ( trak - > stdata_len > = 86 ) { // extra atoms found
2002-03-21 20:18:30 +00:00
int pos = 78 ;
2002-03-21 20:19:00 +00:00
int atom_len ;
2002-03-21 20:18:30 +00:00
while ( pos + 8 < = trak - > stdata_len & &
( pos + ( atom_len = char2int ( trak - > stdata , pos ) ) ) < = trak - > stdata_len ) {
switch ( char2int ( trak - > stdata , pos + 4 ) ) { // switch atom type
2002-03-21 06:05:14 +00:00
case MOV_FOURCC ( ' g ' , ' a ' , ' m ' , ' a ' ) :
// intfp with gamma value at which movie was captured
// can be used to gamma correct movie display
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unsupported Gamma-Correction movie atom (%d)! \n " ,
2002-03-21 06:05:14 +00:00
atom_len ) ;
break ;
case MOV_FOURCC ( ' f ' , ' i ' , ' e ' , ' l ' ) :
// 2 char-values (8bit int) that specify field handling
// see the Apple's QuickTime Fileformat PDF for more info
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unsupported Field-Handling movie atom (%d)! \n " ,
2002-03-21 06:05:14 +00:00
atom_len ) ;
break ;
case MOV_FOURCC ( ' m ' , ' j ' , ' q ' , ' t ' ) :
// Motion-JPEG default quantization table
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unsupported MJPEG-Quantization movie atom (%d)! \n " ,
2002-03-21 06:05:14 +00:00
atom_len ) ;
break ;
case MOV_FOURCC ( ' m ' , ' j ' , ' h ' , ' t ' ) :
// Motion-JPEG default huffman table
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unsupported MJPEG-Huffman movie atom (%d)! \n " ,
2002-03-21 06:05:14 +00:00
atom_len ) ;
break ;
case MOV_FOURCC ( ' e ' , ' s ' , ' d ' , ' s ' ) :
2002-03-21 16:42:58 +00:00
// MPEG4 Elementary Stream Descriptor header
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found MPEG4 movie Elementary Stream Descriptor atom (%d)! \n " , atom_len ) ;
2002-03-21 06:05:14 +00:00
// add code here to save esds header of length atom_len-8
// beginning at stdata[86] to some variable to pass it
// on to the decoder ::atmos
2002-03-24 14:47:28 +00:00
if ( atom_len > 8 ) {
esds_t esds ;
if ( ! mp4_parse_esds ( trak - > stdata + pos + 8 , atom_len - 8 , & esds ) ) {
2004-11-15 15:04:57 +00:00
if ( esds . objectTypeId = = MP4OTI_MPEG2VisualSimple | | esds . objectTypeId = = MP4OTI_MPEG2VisualMain | |
esds . objectTypeId = = MP4OTI_MPEG2VisualSNR | | esds . objectTypeId = = MP4OTI_MPEG2VisualSpatial | |
esds . objectTypeId = = MP4OTI_MPEG2VisualHigh | | esds . objectTypeId = = MP4OTI_MPEG2Visual422 )
sh - > format = mmioFOURCC ( ' m ' , ' p ' , ' g ' , ' 2 ' ) ;
else if ( esds . objectTypeId = = MP4OTI_MPEG1Visual )
sh - > format = mmioFOURCC ( ' m ' , ' p ' , ' g ' , ' 1 ' ) ;
2002-03-24 14:47:28 +00:00
// dump away the codec specific configuration for the AAC decoder
trak - > stream_header_len = esds . decoderConfigLen ;
2006-07-13 16:41:13 +00:00
trak - > stream_header = malloc ( trak - > stream_header_len ) ;
2002-03-24 14:47:28 +00:00
memcpy ( trak - > stream_header , esds . decoderConfig , trak - > stream_header_len ) ;
}
mp4_free_esds ( & esds ) ; // freeup esds mem
}
2002-03-21 06:05:14 +00:00
break ;
2004-08-29 13:52:19 +00:00
case MOV_FOURCC ( ' a ' , ' v ' , ' c ' , ' C ' ) :
// AVC decoder configuration record
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: AVC decoder configuration record atom (%d)! \n " , atom_len ) ;
2004-08-29 13:52:19 +00:00
if ( atom_len > 8 ) {
int i , poffs , cnt ;
// Parse some parts of avcC, just for fun :)
2004-09-13 21:21:48 +00:00
// real parsing is done by avc1 decoder
2004-08-29 13:52:19 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC version: %d \n " , * ( trak - > stdata + pos + 8 ) ) ;
if ( * ( trak - > stdata + pos + 8 ) ! = 1 )
mp_msg ( MSGT_DEMUX , MSGL_ERR , " MOV: unknown avcC version (%d). Expexct problems. \n " , * ( trak - > stdata + pos + 9 ) ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC profile: %d \n " , * ( trak - > stdata + pos + 9 ) ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC profile compatibility: %d \n " , * ( trak - > stdata + pos + 10 ) ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC level: %d \n " , * ( trak - > stdata + pos + 11 ) ) ;
2004-09-13 21:21:48 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC nal length size: %d \n " , ( ( * ( trak - > stdata + pos + 12 ) ) & 0x03 ) + 1 ) ;
2004-08-29 13:52:19 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC number of sequence param sets: %d \n " , cnt = ( * ( trak - > stdata + pos + 13 ) & 0x1f ) ) ;
poffs = pos + 14 ;
for ( i = 0 ; i < cnt ; i + + ) {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC sps %d have length %d \n " , i , BE_16 ( trak - > stdata + poffs ) ) ;
poffs + = BE_16 ( trak - > stdata + poffs ) + 2 ;
}
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC number of picture param sets: %d \n " , * ( trak - > stdata + poffs ) ) ;
poffs + + ;
for ( i = 0 ; i < cnt ; i + + ) {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: avcC pps %d have length %d \n " , i , BE_16 ( trak - > stdata + poffs ) ) ;
poffs + = BE_16 ( trak - > stdata + poffs ) + 2 ;
}
// Copy avcC for the AVC decoder
2004-09-13 21:21:48 +00:00
// This data will be put in extradata below, where BITMAPINFOHEADER is created
2004-08-29 13:52:19 +00:00
trak - > stream_header_len = atom_len - 8 ;
2006-07-13 16:41:13 +00:00
trak - > stream_header = malloc ( trak - > stream_header_len ) ;
2004-08-29 13:52:19 +00:00
memcpy ( trak - > stream_header , trak - > stdata + pos + 8 , trak - > stream_header_len ) ;
}
break ;
2005-05-05 21:40:33 +00:00
case MOV_FOURCC ( ' d ' , ' 2 ' , ' 6 ' , ' 3 ' ) :
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found H.263 decoder atom %c%c%c%c (%d)! \n " , trak - > stdata [ pos + 4 ] , trak - > stdata [ pos + 5 ] , trak - > stdata [ pos + 6 ] , trak - > stdata [ pos + 7 ] , atom_len ) ;
2005-05-05 21:40:33 +00:00
if ( atom_len > 10 )
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Vendor: %c%c%c%c H.263 level: %d H.263 profile: %d \n " , trak - > stdata [ pos + 8 ] , trak - > stdata [ pos + 9 ] , trak - > stdata [ pos + 10 ] , trak - > stdata [ pos + 11 ] , trak - > stdata [ pos + 12 ] , trak - > stdata [ pos + 13 ] ) ;
2005-05-05 21:40:33 +00:00
break ;
2002-07-06 15:14:32 +00:00
case 0 :
break ;
2002-03-21 06:05:14 +00:00
default :
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Found unknown movie atom %c%c%c%c (%d)! \n " ,
2002-03-21 20:18:30 +00:00
trak - > stdata [ pos + 4 ] , trak - > stdata [ pos + 5 ] , trak - > stdata [ pos + 6 ] , trak - > stdata [ pos + 7 ] ,
2002-03-21 06:05:14 +00:00
atom_len ) ;
2002-03-21 20:18:30 +00:00
}
2002-07-06 15:14:32 +00:00
if ( atom_len < 8 ) break ;
2002-03-21 20:18:30 +00:00
pos + = atom_len ;
2002-03-21 20:43:43 +00:00
// printf("pos=%d max=%d\n",pos,trak->stdata_len);
2002-03-21 06:05:14 +00:00
}
}
2002-04-15 02:48:11 +00:00
sh - > fps = trak - > timescale /
( ( trak - > durmap_size > = 1 ) ? ( float ) trak - > durmap [ 0 ] . dur : 1 ) ;
2001-10-05 23:13:26 +00:00
sh - > frametime = 1.0f / sh - > fps ;
2002-03-21 16:42:58 +00:00
2002-03-14 02:26:49 +00:00
sh - > disp_w = trak - > stdata [ 25 ] | ( trak - > stdata [ 24 ] < < 8 ) ;
sh - > disp_h = trak - > stdata [ 27 ] | ( trak - > stdata [ 26 ] < < 8 ) ;
2002-03-21 16:42:58 +00:00
// if image size is zero, fallback to display size
if ( ! sh - > disp_w & & ! sh - > disp_h ) {
sh - > disp_w = trak - > tkdata [ 77 ] | ( trak - > tkdata [ 76 ] < < 8 ) ;
sh - > disp_h = trak - > tkdata [ 81 ] | ( trak - > tkdata [ 80 ] < < 8 ) ;
2002-04-15 01:58:18 +00:00
} else if ( sh - > disp_w ! = ( trak - > tkdata [ 77 ] | ( trak - > tkdata [ 76 ] < < 8 ) ) ) {
// codec and display width differ... use display one for aspect
sh - > aspect = trak - > tkdata [ 77 ] | ( trak - > tkdata [ 76 ] < < 8 ) ;
sh - > aspect / = trak - > tkdata [ 81 ] | ( trak - > tkdata [ 80 ] < < 8 ) ;
}
2006-04-22 05:12:10 +00:00
if ( depth > 32 + 8 ) mp_msg ( MSGT_DEMUX , MSGL_INFO , " *** depth = 0x%X \n " , depth ) ;
2001-10-06 00:58:23 +00:00
2002-01-13 06:01:04 +00:00
// palettized?
2003-09-02 14:48:49 +00:00
gray = 0 ;
if ( depth > 32 ) { depth & = 31 ; gray = 1 ; } // depth > 32 means grayscale
2002-03-14 02:26:49 +00:00
if ( ( depth = = 2 ) | | ( depth = = 4 ) | | ( depth = = 8 ) )
palette_count = ( 1 < < depth ) ;
2002-01-13 06:01:04 +00:00
else
palette_count = 0 ;
2001-10-06 00:58:23 +00:00
// emulate BITMAPINFOHEADER:
2002-01-13 06:01:04 +00:00
if ( palette_count )
{
sh - > bih = malloc ( sizeof ( BITMAPINFOHEADER ) + palette_count * 4 ) ;
memset ( sh - > bih , 0 , sizeof ( BITMAPINFOHEADER ) + palette_count * 4 ) ;
sh - > bih - > biSize = 40 + palette_count * 4 ;
// fetch the relevant fields
flag = BE_16 ( & trak - > stdata [ hdr_ptr ] ) ;
hdr_ptr + = 2 ;
start = BE_32 ( & trak - > stdata [ hdr_ptr ] ) ;
hdr_ptr + = 4 ;
count_flag = BE_16 ( & trak - > stdata [ hdr_ptr ] ) ;
hdr_ptr + = 2 ;
end = BE_16 ( & trak - > stdata [ hdr_ptr ] ) ;
hdr_ptr + = 2 ;
palette_map = ( unsigned char * ) sh - > bih + 40 ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Allocated %d entries for palette \n " ,
2002-03-15 15:57:57 +00:00
palette_count ) ;
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " QT palette: start: %x, end: %x, count flag: %d, flags: %x \n " ,
start , end , count_flag , flag ) ;
/* XXX: problems with sample (statunit6.mov) with flag&0x4 set! - alex*/
2002-01-24 05:20:19 +00:00
// load default palette
2002-02-10 19:06:08 +00:00
if ( flag & 0x08 )
2002-01-24 05:20:19 +00:00
{
2003-09-02 14:48:49 +00:00
if ( gray )
{
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Using default QT grayscale palette \n " ) ;
2003-09-02 14:48:49 +00:00
if ( palette_count = = 16 )
memcpy ( palette_map , qt_default_grayscale_palette_16 , 16 * 4 ) ;
2004-06-27 19:53:30 +00:00
else if ( palette_count = = 256 ) {
2003-09-02 14:48:49 +00:00
memcpy ( palette_map , qt_default_grayscale_palette_256 , 256 * 4 ) ;
2004-06-27 19:53:30 +00:00
if ( trak - > fourcc = = mmioFOURCC ( ' c ' , ' v ' , ' i ' , ' d ' ) ) {
int i ;
// Hack for grayscale CVID, negative palette
// If you have samples where this is not required contact me (rxt)
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: greyscale cvid with default palette, "
2004-06-27 19:53:30 +00:00
" enabling negative palette hack. \n " ) ;
for ( i = 0 ; i < 256 * 4 ; i + + )
palette_map [ i ] = palette_map [ i ] ^ 0xff ;
}
}
2003-09-02 14:48:49 +00:00
}
else
{
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Using default QT colour palette \n " ) ;
2003-09-02 14:48:49 +00:00
if ( palette_count = = 4 )
memcpy ( palette_map , qt_default_palette_4 , 4 * 4 ) ;
else if ( palette_count = = 16 )
memcpy ( palette_map , qt_default_palette_16 , 16 * 4 ) ;
else if ( palette_count = = 256 )
memcpy ( palette_map , qt_default_palette_256 , 256 * 4 ) ;
}
2002-01-24 05:20:19 +00:00
}
// load palette from file
else
2002-01-13 06:01:04 +00:00
{
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Loading palette from file \n " ) ;
2002-01-24 05:20:19 +00:00
for ( i = start ; i < = end ; i + + )
{
entry = BE_16 ( & trak - > stdata [ hdr_ptr ] ) ;
hdr_ptr + = 2 ;
// apparently, if count_flag is set, entry is same as i
if ( count_flag & 0x8000 )
entry = i ;
// only care about top 8 bits of 16-bit R, G, or B value
2002-03-15 15:57:57 +00:00
if ( entry < = palette_count & & entry > = 0 )
{
palette_map [ entry * 4 + 2 ] = trak - > stdata [ hdr_ptr + 0 ] ;
palette_map [ entry * 4 + 1 ] = trak - > stdata [ hdr_ptr + 2 ] ;
palette_map [ entry * 4 + 0 ] = trak - > stdata [ hdr_ptr + 4 ] ;
mp_dbg ( MSGT_DEMUX , MSGL_DBG2 , " QT palette: added entry: %d of %d (colors: R:%x G:%x B:%x) \n " ,
entry , palette_count ,
palette_map [ entry * 4 + 2 ] ,
palette_map [ entry * 4 + 1 ] ,
palette_map [ entry * 4 + 0 ] ) ;
}
else
mp_msg ( MSGT_DEMUX , MSGL_V , " QT palette: skipped entry (out of count): %d of %d \n " ,
entry , palette_count ) ;
2002-01-24 05:20:19 +00:00
hdr_ptr + = 6 ;
}
2002-01-13 06:01:04 +00:00
}
}
else
{
2004-09-13 21:21:48 +00:00
if ( trak - > fourcc = = mmioFOURCC ( ' a ' , ' v ' , ' c ' , ' 1 ' ) ) {
2006-05-11 18:50:46 +00:00
if ( trak - > stream_header_len > 0xffffffff - sizeof ( BITMAPINFOHEADER ) ) {
2006-05-13 21:12:43 +00:00
mp_msg ( MSGT_DEMUXER , MSGL_ERR , " Invalid extradata size %d, skipping \n " , trak - > stream_header_len ) ;
2006-05-11 18:50:46 +00:00
trak - > stream_header_len = 0 ;
}
2004-09-13 21:21:48 +00:00
sh - > bih = malloc ( sizeof ( BITMAPINFOHEADER ) + trak - > stream_header_len ) ;
memset ( sh - > bih , 0 , sizeof ( BITMAPINFOHEADER ) + trak - > stream_header_len ) ;
sh - > bih - > biSize = 40 + trak - > stream_header_len ;
memcpy ( ( ( unsigned char * ) sh - > bih ) + 40 , trak - > stream_header , trak - > stream_header_len ) ;
free ( trak - > stream_header ) ;
trak - > stream_header_len = 0 ;
trak - > stream_header = NULL ;
} else {
2002-01-13 06:01:04 +00:00
sh - > bih = malloc ( sizeof ( BITMAPINFOHEADER ) ) ;
memset ( sh - > bih , 0 , sizeof ( BITMAPINFOHEADER ) ) ;
sh - > bih - > biSize = 40 ;
2004-09-13 21:21:48 +00:00
}
2002-01-13 06:01:04 +00:00
}
2001-10-06 00:58:23 +00:00
sh - > bih - > biWidth = sh - > disp_w ;
sh - > bih - > biHeight = sh - > disp_h ;
sh - > bih - > biPlanes = 0 ;
2001-12-22 00:33:35 +00:00
sh - > bih - > biBitCount = depth ;
2001-10-06 00:58:23 +00:00
sh - > bih - > biCompression = trak - > fourcc ;
sh - > bih - > biSizeImage = sh - > bih - > biWidth * sh - > bih - > biHeight ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Image size: %d x %d (%d bpp) \n " , sh - > disp_w , sh - > disp_h , sh - > bih - > biBitCount ) ;
2002-03-14 02:26:49 +00:00
if ( trak - > tkdata_len > 81 )
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Display size: %d x %d \n " ,
2002-03-14 02:26:49 +00:00
trak - > tkdata [ 77 ] | ( trak - > tkdata [ 76 ] < < 8 ) ,
trak - > tkdata [ 81 ] | ( trak - > tkdata [ 80 ] < < 8 ) ) ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Fourcc: %.4s Codec: '%.*s' \n " , ( char * ) & trak - > fourcc , trak - > stdata [ 42 ] & 31 , trak - > stdata + 43 ) ;
2001-10-07 00:22:43 +00:00
2002-12-07 01:01:25 +00:00
// if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){
// // (auto)selected video track:
// demuxer->video->id=priv->track_db;
// demuxer->video->sh=sh; sh->ds=demuxer->video;
// }
2007-08-25 18:09:00 +00:00
return 1 ;
}
static void lschunks ( demuxer_t * demuxer , int level , off_t endpos , mov_track_t * trak ) {
mov_priv_t * priv = demuxer - > priv ;
// printf("lschunks (level=%d,endpos=%x)\n", level, endpos);
while ( 1 ) {
off_t pos ;
off_t len ;
unsigned int id ;
//
pos = stream_tell ( demuxer - > stream ) ;
// printf("stream_tell==%d\n",pos);
if ( pos > = endpos ) return ; // END
len = stream_read_dword ( demuxer - > stream ) ;
// printf("len==%d\n",len);
if ( len < 8 ) return ; // error
len - = 8 ;
id = stream_read_dword ( demuxer - > stream ) ;
//
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " lschunks %.4s %d \n " , ( char * ) & id , ( int ) len ) ;
//
if ( trak ) {
if ( lschunks_intrak ( demuxer , level , id , pos , len , trak ) < 0 )
return ;
} else { /* not in track */
switch ( id ) {
case MOV_FOURCC ( ' m ' , ' v ' , ' h ' , ' d ' ) : {
int version = stream_read_char ( demuxer - > stream ) ;
stream_skip ( demuxer - > stream , ( version = = 1 ) ? 19 : 11 ) ;
priv - > timescale = stream_read_dword ( demuxer - > stream ) ;
if ( version = = 1 )
priv - > duration = stream_read_qword ( demuxer - > stream ) ;
else
priv - > duration = stream_read_dword ( demuxer - > stream ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sMovie header (%d bytes): tscale=%d dur=%d \n " , level , " " , ( int ) len ,
( int ) priv - > timescale , ( int ) priv - > duration ) ;
break ;
}
case MOV_FOURCC ( ' t ' , ' r ' , ' a ' , ' k ' ) : {
// if(trak) printf("MOV: Warning! trak in trak?\n");
if ( priv - > track_db > = MOV_MAX_TRACKS ) {
mp_msg ( MSGT_DEMUX , MSGL_WARN , MSGTR_MOVtooManyTrk ) ;
return ;
}
if ( ! priv - > track_db ) mp_msg ( MSGT_DEMUX , MSGL_V , " -------------- \n " ) ;
trak = malloc ( sizeof ( mov_track_t ) ) ;
memset ( trak , 0 , sizeof ( mov_track_t ) ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: Track #%d: \n " , priv - > track_db ) ;
trak - > id = priv - > track_db ;
priv - > tracks [ priv - > track_db ] = trak ;
lschunks ( demuxer , level + 1 , pos + len , trak ) ;
mov_build_index ( trak , priv - > timescale ) ;
switch ( trak - > type ) {
case MOV_TRAK_AUDIO : {
sh_audio_t * sh = new_sh_audio ( demuxer , priv - > track_db ) ;
mp_msg ( MSGT_DEMUX , MSGL_INFO , MSGTR_AudioID , " mov " , priv - > track_db ) ;
gen_sh_audio ( sh , trak , priv - > timescale ) ;
break ;
}
case MOV_TRAK_VIDEO : {
sh_video_t * sh = new_sh_video ( demuxer , priv - > track_db ) ;
mp_msg ( MSGT_DEMUX , MSGL_INFO , MSGTR_VideoID , " mov " , priv - > track_db ) ;
gen_sh_video ( sh , trak , priv - > timescale ) ;
2001-10-05 23:13:26 +00:00
break ;
}
2001-11-09 17:00:12 +00:00
case MOV_TRAK_GENERIC :
2006-11-13 18:41:24 +00:00
if ( trak - > fourcc = = mmioFOURCC ( ' m ' , ' p ' , ' 4 ' , ' s ' ) | |
2006-11-17 19:16:07 +00:00
trak - > fourcc = = mmioFOURCC ( ' t ' , ' x ' , ' 3 ' , ' g ' ) | |
2006-11-13 18:41:24 +00:00
trak - > fourcc = = mmioFOURCC ( ' t ' , ' e ' , ' x ' , ' t ' ) ) {
sh_sub_t * sh = new_sh_sub ( demuxer , priv - > track_db ) ;
2007-04-20 21:49:49 +00:00
mp_msg ( MSGT_DEMUX , MSGL_INFO , MSGTR_SubtitleID , " mov " , priv - > track_db ) ;
2006-11-17 20:13:21 +00:00
if ( trak - > fourcc = = mmioFOURCC ( ' m ' , ' p ' , ' 4 ' , ' s ' ) )
init_vobsub ( sh , trak ) ;
else
sh - > type = ' t ' ;
2006-11-13 18:41:24 +00:00
} else
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Generic track - not completely understood! (id: %d) \n " ,
2001-11-09 17:00:12 +00:00
trak - > id ) ;
2002-03-15 15:57:57 +00:00
/* XXX: Also this contains the FLASH data */
2002-11-29 20:25:32 +00:00
2001-11-09 17:00:12 +00:00
#if 0
{
int pos = stream_tell ( demuxer - > stream ) ;
int i ;
int fd ;
char name [ 20 ] ;
2002-11-29 20:25:32 +00:00
2001-11-09 17:00:12 +00:00
for ( i = 0 ; i < trak - > samples_size ; i + + )
{
char buf [ trak - > samples [ i ] . size ] ;
stream_seek ( demuxer - > stream , trak - > samples [ i ] . pos ) ;
snprintf ( ( char * ) & name [ 0 ] , 20 , " samp%d " , i ) ;
fd = open ( ( char * ) & name [ 0 ] , O_CREAT | O_WRONLY ) ;
stream_read ( demuxer - > stream , & buf [ 0 ] , trak - > samples [ i ] . size ) ;
write ( fd , & buf [ 0 ] , trak - > samples [ i ] . size ) ;
close ( fd ) ;
}
for ( i = 0 ; i < trak - > chunks_size ; i + + )
{
char buf [ trak - > length ] ;
stream_seek ( demuxer - > stream , trak - > chunks [ i ] . pos ) ;
snprintf ( ( char * ) & name [ 0 ] , 20 , " chunk%d " , i ) ;
fd = open ( ( char * ) & name [ 0 ] , O_CREAT | O_WRONLY ) ;
stream_read ( demuxer - > stream , & buf [ 0 ] , trak - > length ) ;
write ( fd , & buf [ 0 ] , trak - > length ) ;
close ( fd ) ;
}
if ( trak - > samplesize > 0 )
{
char * buf ;
buf = malloc ( trak - > samplesize ) ;
stream_seek ( demuxer - > stream , trak - > chunks [ 0 ] . pos ) ;
snprintf ( ( char * ) & name [ 0 ] , 20 , " trak%d " , trak - > id ) ;
fd = open ( ( char * ) & name [ 0 ] , O_CREAT | O_WRONLY ) ;
stream_read ( demuxer - > stream , buf , trak - > samplesize ) ;
write ( fd , buf , trak - > samplesize ) ;
close ( fd ) ;
}
stream_seek ( demuxer - > stream , pos ) ;
}
# endif
break ;
2001-10-29 16:15:04 +00:00
default :
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Unknown track type found (type: %d) \n " , trak - > type ) ;
2001-10-29 16:15:04 +00:00
break ;
2001-10-05 23:13:26 +00:00
}
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " -------------- \n " ) ;
2001-10-05 23:13:26 +00:00
priv - > track_db + + ;
2001-08-12 01:58:05 +00:00
trak = NULL ;
2001-10-29 16:15:04 +00:00
break ;
}
2001-10-10 01:07:50 +00:00
# ifndef HAVE_ZLIB
2001-10-29 16:15:04 +00:00
case MOV_FOURCC ( ' c ' , ' m ' , ' o ' , ' v ' ) : {
2001-09-26 21:35:14 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , MSGTR_MOVcomprhdr ) ;
2001-08-12 01:58:05 +00:00
return ;
}
2001-10-10 01:07:50 +00:00
# else
2002-03-15 15:57:57 +00:00
case MOV_FOURCC ( ' m ' , ' o ' , ' o ' , ' v ' ) :
2001-10-29 16:15:04 +00:00
case MOV_FOURCC ( ' c ' , ' m ' , ' o ' , ' v ' ) : {
2001-10-10 01:07:50 +00:00
// mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr);
lschunks ( demuxer , level + 1 , pos + len , NULL ) ;
2001-10-29 16:15:04 +00:00
break ;
}
case MOV_FOURCC ( ' d ' , ' c ' , ' o ' , ' m ' ) : {
2001-10-10 01:07:50 +00:00
// int temp=stream_read_dword(demuxer->stream);
2002-03-15 15:57:57 +00:00
unsigned int algo = be2me_32 ( stream_read_dword ( demuxer - > stream ) ) ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Compressed header uses %.4s algo! \n " , ( char * ) & algo ) ;
2001-10-29 16:15:04 +00:00
break ;
}
case MOV_FOURCC ( ' c ' , ' m ' , ' v ' , ' d ' ) : {
2001-10-10 01:07:50 +00:00
// int temp=stream_read_dword(demuxer->stream);
unsigned int moov_sz = stream_read_dword ( demuxer - > stream ) ;
unsigned int cmov_sz = len - 4 ;
2006-05-11 18:50:46 +00:00
unsigned char * cmov_buf ;
unsigned char * moov_buf ;
2001-10-10 01:07:50 +00:00
int zret ;
z_stream zstrm ;
stream_t * backup ;
2006-06-04 22:41:27 +00:00
if ( moov_sz > SIZE_MAX - 16 ) {
2006-05-11 18:50:46 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , " Invalid cmvd atom size %d \n " , moov_sz ) ;
break ;
}
cmov_buf = malloc ( cmov_sz ) ;
moov_buf = malloc ( moov_sz + 16 ) ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Compressed header size: %d / %d \n " , cmov_sz , moov_sz ) ;
2001-10-10 01:07:50 +00:00
stream_read ( demuxer - > stream , cmov_buf , cmov_sz ) ;
zstrm . zalloc = ( alloc_func ) 0 ;
zstrm . zfree = ( free_func ) 0 ;
zstrm . opaque = ( voidpf ) 0 ;
zstrm . next_in = cmov_buf ;
zstrm . avail_in = cmov_sz ;
zstrm . next_out = moov_buf ;
zstrm . avail_out = moov_sz ;
zret = inflateInit ( & zstrm ) ;
if ( zret ! = Z_OK )
2001-10-26 14:04:17 +00:00
{ mp_msg ( MSGT_DEMUX , MSGL_ERR , " QT cmov: inflateInit err %d \n " , zret ) ;
2001-10-10 01:07:50 +00:00
return ;
}
zret = inflate ( & zstrm , Z_NO_FLUSH ) ;
if ( ( zret ! = Z_OK ) & & ( zret ! = Z_STREAM_END ) )
2001-10-26 14:04:17 +00:00
{ mp_msg ( MSGT_DEMUX , MSGL_ERR , " QT cmov inflate: ERR %d \n " , zret ) ;
2001-10-10 01:07:50 +00:00
return ;
}
#if 0
else {
FILE * DecOut ;
DecOut = fopen ( " Out.bin " , " w " ) ;
fwrite ( moov_buf , 1 , moov_sz , DecOut ) ;
fclose ( DecOut ) ;
}
# endif
2001-10-26 14:04:17 +00:00
if ( moov_sz ! = zstrm . total_out )
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_WARN , " Warning! moov size differs cmov: %d zlib: %ld \n " , moov_sz , zstrm . total_out ) ;
2001-10-10 01:07:50 +00:00
zret = inflateEnd ( & zstrm ) ;
backup = demuxer - > stream ;
demuxer - > stream = new_memory_stream ( moov_buf , moov_sz ) ;
stream_skip ( demuxer - > stream , 8 ) ;
lschunks ( demuxer , level + 1 , moov_sz , NULL ) ; // parse uncompr. 'moov'
//free_stream(demuxer->stream);
demuxer - > stream = backup ;
2001-10-26 14:04:17 +00:00
free ( cmov_buf ) ;
free ( moov_buf ) ;
2001-10-29 16:15:04 +00:00
break ;
2001-10-10 01:07:50 +00:00
}
# endif
2001-10-29 16:15:04 +00:00
case MOV_FOURCC ( ' u ' , ' d ' , ' t ' , ' a ' ) :
2001-10-23 16:21:24 +00:00
{
unsigned int udta_id ;
off_t udta_len ;
off_t udta_size = len ;
2001-08-12 01:58:05 +00:00
2001-10-23 16:21:24 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " mov: user data record found \n " ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Quicktime Clip Info: \n " ) ;
2001-10-23 16:21:24 +00:00
while ( ( len > 8 ) & & ( udta_size > 8 ) )
{
udta_len = stream_read_dword ( demuxer - > stream ) ;
udta_id = stream_read_dword ( demuxer - > stream ) ;
udta_size - = 8 ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " udta_id: %.4s (len: % " PRId64 " ) \n " , ( char * ) & udta_id , ( int64_t ) udta_len ) ;
2001-10-23 16:21:24 +00:00
switch ( udta_id )
{
case MOV_FOURCC ( 0xa9 , ' c ' , ' p ' , ' y ' ) :
2001-10-29 21:01:00 +00:00
case MOV_FOURCC ( 0xa9 , ' d ' , ' a ' , ' y ' ) :
case MOV_FOURCC ( 0xa9 , ' d ' , ' i ' , ' r ' ) :
/* 0xa9,'e','d','1' - '9' : edit timestamps */
case MOV_FOURCC ( 0xa9 , ' f ' , ' m ' , ' t ' ) :
2001-10-23 16:21:24 +00:00
case MOV_FOURCC ( 0xa9 , ' i ' , ' n ' , ' f ' ) :
2001-10-29 21:01:00 +00:00
case MOV_FOURCC ( 0xa9 , ' p ' , ' r ' , ' d ' ) :
case MOV_FOURCC ( 0xa9 , ' p ' , ' r ' , ' f ' ) :
case MOV_FOURCC ( 0xa9 , ' r ' , ' e ' , ' q ' ) :
case MOV_FOURCC ( 0xa9 , ' s ' , ' r ' , ' c ' ) :
case MOV_FOURCC ( ' n ' , ' a ' , ' m ' , ' e ' ) :
2001-10-23 16:21:24 +00:00
case MOV_FOURCC ( 0xa9 , ' n ' , ' a ' , ' m ' ) :
case MOV_FOURCC ( 0xa9 , ' A ' , ' R ' , ' T ' ) :
case MOV_FOURCC ( 0xa9 , ' c ' , ' m ' , ' t ' ) :
2001-10-26 14:04:17 +00:00
case MOV_FOURCC ( 0xa9 , ' a ' , ' u ' , ' t ' ) :
case MOV_FOURCC ( 0xa9 , ' s ' , ' w ' , ' r ' ) :
2001-10-23 16:21:24 +00:00
{
off_t text_len = stream_read_word ( demuxer - > stream ) ;
char text [ text_len + 2 + 1 ] ;
stream_read ( demuxer - > stream , ( char * ) & text , text_len + 2 ) ;
text [ text_len + 2 ] = 0x0 ;
switch ( udta_id )
{
2001-10-26 14:04:17 +00:00
case MOV_FOURCC ( 0xa9 , ' a ' , ' u ' , ' t ' ) :
2001-11-22 15:43:24 +00:00
demux_info_add ( demuxer , " author " , & text [ 2 ] ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Author: %s \n " , & text [ 2 ] ) ;
2001-10-26 14:04:17 +00:00
break ;
2001-10-23 16:21:24 +00:00
case MOV_FOURCC ( 0xa9 , ' c ' , ' p ' , ' y ' ) :
2001-11-22 15:43:24 +00:00
demux_info_add ( demuxer , " copyright " , & text [ 2 ] ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Copyright: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' i ' , ' n ' , ' f ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Info: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
2001-10-29 21:01:00 +00:00
case MOV_FOURCC ( ' n ' , ' a ' , ' m ' , ' e ' ) :
2001-10-23 16:21:24 +00:00
case MOV_FOURCC ( 0xa9 , ' n ' , ' a ' , ' m ' ) :
2001-11-22 15:43:24 +00:00
demux_info_add ( demuxer , " name " , & text [ 2 ] ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Name: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' A ' , ' R ' , ' T ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Artist: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' d ' , ' i ' , ' r ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Director: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' c ' , ' m ' , ' t ' ) :
2001-11-22 15:43:24 +00:00
demux_info_add ( demuxer , " comments " , & text [ 2 ] ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Comment: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' r ' , ' e ' , ' q ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Requirements: %s \n " , & text [ 2 ] ) ;
2001-10-23 16:21:24 +00:00
break ;
2001-10-26 14:04:17 +00:00
case MOV_FOURCC ( 0xa9 , ' s ' , ' w ' , ' r ' ) :
2001-11-22 15:43:24 +00:00
demux_info_add ( demuxer , " encoder " , & text [ 2 ] ) ;
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Software: %s \n " , & text [ 2 ] ) ;
2001-10-26 14:04:17 +00:00
break ;
2001-10-29 21:01:00 +00:00
case MOV_FOURCC ( 0xa9 , ' d ' , ' a ' , ' y ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Creation timestamp: %s \n " , & text [ 2 ] ) ;
2001-10-29 21:01:00 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' f ' , ' m ' , ' t ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Format: %s \n " , & text [ 2 ] ) ;
2001-10-29 21:01:00 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' p ' , ' r ' , ' d ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Producer: %s \n " , & text [ 2 ] ) ;
2001-10-29 21:01:00 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' p ' , ' r ' , ' f ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Performer(s): %s \n " , & text [ 2 ] ) ;
2001-10-29 21:01:00 +00:00
break ;
case MOV_FOURCC ( 0xa9 , ' s ' , ' r ' , ' c ' ) :
2002-05-20 03:51:58 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " Source providers: %s \n " , & text [ 2 ] ) ;
2001-10-29 21:01:00 +00:00
break ;
2001-10-23 16:21:24 +00:00
}
udta_size - = 4 + text_len ;
break ;
}
2001-10-29 21:01:00 +00:00
/* some other shits: WLOC - window location,
LOOP - looping style ,
SelO - play only selected frames
AllF - play all frames
*/
case MOV_FOURCC ( ' W ' , ' L ' , ' O ' , ' C ' ) :
case MOV_FOURCC ( ' L ' , ' O ' , ' O ' , ' P ' ) :
case MOV_FOURCC ( ' S ' , ' e ' , ' l ' , ' O ' ) :
case MOV_FOURCC ( ' A ' , ' l ' , ' l ' , ' F ' ) :
2001-10-23 16:21:24 +00:00
default :
{
2003-09-20 10:10:11 +00:00
if ( udta_len > udta_size )
udta_len = udta_size ;
{
2001-10-23 16:21:24 +00:00
char dump [ udta_len - 4 ] ;
stream_read ( demuxer - > stream , ( char * ) & dump , udta_len - 4 - 4 ) ;
udta_size - = udta_len ;
2003-09-20 10:10:11 +00:00
}
2001-10-23 16:21:24 +00:00
}
}
}
2001-10-29 16:15:04 +00:00
break ;
2001-10-23 16:21:24 +00:00
} /* eof udta */
2001-10-29 16:15:04 +00:00
default :
2002-03-01 03:02:25 +00:00
id = be2me_32 ( id ) ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: unknown chunk: %.4s %d \n " , ( char * ) & id , ( int ) len ) ;
2001-10-29 16:15:04 +00:00
} /* endof switch */
} /* endof else */
2001-10-23 16:21:24 +00:00
2001-08-12 01:58:05 +00:00
pos + = len + 8 ;
if ( pos > = endpos ) break ;
if ( ! stream_seek ( demuxer - > stream , pos ) ) break ;
}
}
2005-07-10 08:57:31 +00:00
static int lschunks_intrak ( demuxer_t * demuxer , int level , unsigned int id ,
off_t pos , off_t len , mov_track_t * trak )
{
switch ( id ) {
case MOV_FOURCC ( ' m ' , ' d ' , ' a ' , ' t ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_WARN , " Hmm, strange MOV, parsing mdat in lschunks? \n " ) ;
return - 1 ;
}
case MOV_FOURCC ( ' f ' , ' r ' , ' e ' , ' e ' ) :
case MOV_FOURCC ( ' u ' , ' d ' , ' t ' , ' a ' ) :
/* here not supported :p */
break ;
case MOV_FOURCC ( ' t ' , ' k ' , ' h ' , ' d ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sTrack header! \n " , level , " " ) ;
// read codec data
trak - > tkdata_len = len ;
trak - > tkdata = malloc ( trak - > tkdata_len ) ;
stream_read ( demuxer - > stream , trak - > tkdata , trak - > tkdata_len ) ;
/*
0 1 Version
1 3 Flags
4 4 Creation time
8 4 Modification time
12 4 Track ID
16 4 Reserved
20 4 Duration
24 8 Reserved
32 2 Layer
34 2 Alternate group
36 2 Volume
38 2 Reserved
40 36 Matrix structure
76 4 Track width
80 4 Track height
*/
mp_msg ( MSGT_DEMUX , MSGL_V ,
" tkhd len=%d ver=%d flags=0x%X id=%d dur=%d lay=%d vol=%d \n " ,
trak - > tkdata_len , trak - > tkdata [ 0 ] , trak - > tkdata [ 1 ] ,
char2int ( trak - > tkdata , 12 ) , // id
char2int ( trak - > tkdata , 20 ) , // duration
char2short ( trak - > tkdata , 32 ) , // layer
char2short ( trak - > tkdata , 36 ) ) ; // volume
break ;
}
case MOV_FOURCC ( ' m ' , ' d ' , ' h ' , ' d ' ) : {
2006-08-06 19:26:17 +00:00
int version = stream_read_char ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sMedia header! \n " , level , " " ) ;
2006-08-06 19:26:17 +00:00
stream_skip ( demuxer - > stream , ( version = = 1 ) ? 19 : 11 ) ;
2005-07-10 08:57:31 +00:00
// read timescale
trak - > timescale = stream_read_dword ( demuxer - > stream ) ;
// read length
2006-08-06 19:26:17 +00:00
if ( version = = 1 )
trak - > length = stream_read_qword ( demuxer - > stream ) ;
else
trak - > length = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
break ;
}
case MOV_FOURCC ( ' h ' , ' d ' , ' l ' , ' r ' ) : {
2007-05-28 14:25:48 +00:00
unsigned int tmp = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
unsigned int type = stream_read_dword_le ( demuxer - > stream ) ;
unsigned int subtype = stream_read_dword_le ( demuxer - > stream ) ;
unsigned int manufact = stream_read_dword_le ( demuxer - > stream ) ;
2007-05-28 14:25:48 +00:00
unsigned int comp_flags = stream_read_dword ( demuxer - > stream ) ;
unsigned int comp_mask = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
int len = stream_read_char ( demuxer - > stream ) ;
char * str = malloc ( len + 1 ) ;
stream_read ( demuxer - > stream , str , len ) ;
str [ len ] = 0 ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: %*sHandler header: %.4s/%.4s (%.4s) %s \n " , level , " " ,
2006-01-12 20:04:36 +00:00
( char * ) & type , ( char * ) & subtype , ( char * ) & manufact , str ) ;
2005-07-10 08:57:31 +00:00
free ( str ) ;
switch ( bswap_32 ( type ) ) {
case MOV_FOURCC ( ' m ' , ' h ' , ' l ' , ' r ' ) :
trak - > media_handler = bswap_32 ( subtype ) ;
break ;
case MOV_FOURCC ( ' d ' , ' h ' , ' l ' , ' r ' ) :
trak - > data_handler = bswap_32 ( subtype ) ;
break ;
default :
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: unknown handler class: 0x%X (%.4s) \n " ,
2006-01-12 20:04:36 +00:00
bswap_32 ( type ) , ( char * ) & type ) ;
2005-07-10 08:57:31 +00:00
}
break ;
}
case MOV_FOURCC ( ' v ' , ' m ' , ' h ' , ' d ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sVideo header! \n " , level , " " ) ;
trak - > type = MOV_TRAK_VIDEO ;
// read video data
break ;
}
case MOV_FOURCC ( ' s ' , ' m ' , ' h ' , ' d ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sSound header! \n " , level , " " ) ;
trak - > type = MOV_TRAK_AUDIO ;
// read audio data
break ;
}
case MOV_FOURCC ( ' g ' , ' m ' , ' h ' , ' d ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sGeneric header! \n " , level , " " ) ;
trak - > type = MOV_TRAK_GENERIC ;
break ;
}
case MOV_FOURCC ( ' n ' , ' m ' , ' h ' , ' d ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sGeneric header! \n " , level , " " ) ;
trak - > type = MOV_TRAK_GENERIC ;
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' s ' , ' d ' ) : {
int i = stream_read_dword ( demuxer - > stream ) ; // temp!
int count = stream_read_dword ( demuxer - > stream ) ;
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sDescription list! (cnt:%d) \n " ,
level , " " , count ) ;
for ( i = 0 ; i < count ; i + + ) {
off_t pos = stream_tell ( demuxer - > stream ) ;
off_t len = stream_read_dword ( demuxer - > stream ) ;
unsigned int fourcc = stream_read_dword_le ( demuxer - > stream ) ;
/* some files created with Broadcast 2000 (e.g. ilacetest.mov)
contain raw I420 video but have a yv12 fourcc */
if ( fourcc = = mmioFOURCC ( ' y ' , ' v ' , ' 1 ' , ' 2 ' ) )
fourcc = mmioFOURCC ( ' I ' , ' 4 ' , ' 2 ' , ' 0 ' ) ;
if ( len < 8 )
break ; // error
mp_msg ( MSGT_DEMUX , MSGL_V ,
2006-01-12 20:04:36 +00:00
" MOV: %*s desc #%d: %.4s (% " PRId64 " bytes) \n " , level , " " ,
i , ( char * ) & fourcc , ( int64_t ) len - 16 ) ;
2005-07-10 08:57:31 +00:00
if ( fourcc ! = trak - > fourcc & & i )
mp_msg ( MSGT_DEMUX , MSGL_WARN , MSGTR_MOVvariableFourCC ) ;
// if(!i)
{
trak - > fourcc = fourcc ;
// read type specific (audio/video/time/text etc) header
// NOTE: trak type is not yet known at this point :(((
trak - > stdata_len = len - 8 ;
trak - > stdata = malloc ( trak - > stdata_len ) ;
stream_read ( demuxer - > stream , trak - > stdata , trak - > stdata_len ) ;
}
if ( ! stream_seek ( demuxer - > stream , pos + len ) )
break ;
}
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' t ' , ' s ' ) : {
2007-05-28 14:25:48 +00:00
int temp = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
int len = stream_read_dword ( demuxer - > stream ) ;
int i ;
unsigned int pts = 0 ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: %*sSample duration table! (%d blocks) \n " , level , " " ,
len ) ;
2006-05-11 18:50:46 +00:00
trak - > durmap = calloc ( len , sizeof ( mov_durmap_t ) ) ;
2005-07-10 08:57:31 +00:00
trak - > durmap_size = len ;
for ( i = 0 ; i < len ; i + + ) {
trak - > durmap [ i ] . num = stream_read_dword ( demuxer - > stream ) ;
trak - > durmap [ i ] . dur = stream_read_dword ( demuxer - > stream ) ;
pts + = trak - > durmap [ i ] . num * trak - > durmap [ i ] . dur ;
}
if ( trak - > length ! = pts )
mp_msg ( MSGT_DEMUX , MSGL_WARN , " Warning! pts=%d length=%d \n " ,
pts , trak - > length ) ;
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' s ' , ' c ' ) : {
int temp = stream_read_dword ( demuxer - > stream ) ;
int len = stream_read_dword ( demuxer - > stream ) ;
int ver = ( temp < < 24 ) ;
int flags = ( temp < < 16 ) | ( temp < < 8 ) | temp ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
2006-01-12 20:04:36 +00:00
" MOV: %*sSample->Chunk mapping table! (%d blocks) (ver:%d,flags:%d) \n " , level , " " ,
2005-07-10 08:57:31 +00:00
len , ver , flags ) ;
// read data:
trak - > chunkmap_size = len ;
2006-05-11 18:50:46 +00:00
trak - > chunkmap = calloc ( len , sizeof ( mov_chunkmap_t ) ) ;
2005-07-10 08:57:31 +00:00
for ( i = 0 ; i < len ; i + + ) {
trak - > chunkmap [ i ] . first = stream_read_dword ( demuxer - > stream ) - 1 ;
trak - > chunkmap [ i ] . spc = stream_read_dword ( demuxer - > stream ) ;
trak - > chunkmap [ i ] . sdid = stream_read_dword ( demuxer - > stream ) ;
}
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' s ' , ' z ' ) : {
int temp = stream_read_dword ( demuxer - > stream ) ;
int ss = stream_read_dword ( demuxer - > stream ) ;
int ver = ( temp < < 24 ) ;
int flags = ( temp < < 16 ) | ( temp < < 8 ) | temp ;
int entries = stream_read_dword ( demuxer - > stream ) ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
2006-01-12 20:04:36 +00:00
" MOV: %*sSample size table! (entries=%d ss=%d) (ver:%d,flags:%d) \n " , level , " " ,
2005-07-10 08:57:31 +00:00
entries , ss , ver , flags ) ;
trak - > samplesize = ss ;
if ( ! ss ) {
// variable samplesize
2006-05-11 18:50:46 +00:00
trak - > samples = realloc_struct ( trak - > samples , entries , sizeof ( mov_sample_t ) ) ;
2005-07-10 08:57:31 +00:00
trak - > samples_size = entries ;
for ( i = 0 ; i < entries ; i + + )
trak - > samples [ i ] . size = stream_read_dword ( demuxer - > stream ) ;
}
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' c ' , ' o ' ) : {
2007-05-28 14:25:48 +00:00
int temp = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
int len = stream_read_dword ( demuxer - > stream ) ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: %*sChunk offset table! (%d chunks) \n " , level , " " ,
len ) ;
// extend array if needed:
if ( len > trak - > chunks_size ) {
2006-05-11 18:50:46 +00:00
trak - > chunks = realloc_struct ( trak - > chunks , len , sizeof ( mov_chunk_t ) ) ;
2005-07-10 08:57:31 +00:00
trak - > chunks_size = len ;
}
// read elements:
for ( i = 0 ; i < len ; i + + )
trak - > chunks [ i ] . pos = stream_read_dword ( demuxer - > stream ) ;
break ;
}
case MOV_FOURCC ( ' c ' , ' o ' , ' 6 ' , ' 4 ' ) : {
2007-05-28 14:25:48 +00:00
int temp = stream_read_dword ( demuxer - > stream ) ;
2005-07-10 08:57:31 +00:00
int len = stream_read_dword ( demuxer - > stream ) ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: %*s64bit chunk offset table! (%d chunks) \n " , level , " " ,
len ) ;
// extend array if needed:
if ( len > trak - > chunks_size ) {
2006-05-11 18:50:46 +00:00
trak - > chunks = realloc_struct ( trak - > chunks , len , sizeof ( mov_chunk_t ) ) ;
2005-07-10 08:57:31 +00:00
trak - > chunks_size = len ;
}
// read elements:
for ( i = 0 ; i < len ; i + + ) {
# ifndef _LARGEFILE_SOURCE
if ( stream_read_dword ( demuxer - > stream ) ! = 0 )
mp_msg ( MSGT_DEMUX , MSGL_WARN , " Chunk %d has got 64bit address, but you've MPlayer compiled without LARGEFILE support! \n " , i ) ;
trak - > chunks [ i ] . pos = stream_read_dword ( demuxer - > stream ) ;
# else
trak - > chunks [ i ] . pos = stream_read_qword ( demuxer - > stream ) ;
# endif
}
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' s ' , ' s ' ) : {
int temp = stream_read_dword ( demuxer - > stream ) ;
int entries = stream_read_dword ( demuxer - > stream ) ;
int ver = ( temp < < 24 ) ;
int flags = ( temp < < 16 ) | ( temp < < 8 ) | temp ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
2006-01-12 20:04:36 +00:00
" MOV: %*sSyncing samples (keyframes) table! (%d entries) (ver:%d,flags:%d) \n " , level , " " ,
2005-07-10 08:57:31 +00:00
entries , ver , flags ) ;
trak - > keyframes_size = entries ;
2006-05-11 18:50:46 +00:00
trak - > keyframes = calloc ( entries , sizeof ( unsigned int ) ) ;
2005-07-10 08:57:31 +00:00
for ( i = 0 ; i < entries ; i + + )
trak - > keyframes [ i ] = stream_read_dword ( demuxer - > stream ) - 1 ;
break ;
}
case MOV_FOURCC ( ' m ' , ' d ' , ' i ' , ' a ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sMedia stream! \n " , level , " " ) ;
lschunks ( demuxer , level + 1 , pos + len , trak ) ;
break ;
}
case MOV_FOURCC ( ' m ' , ' i ' , ' n ' , ' f ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sMedia info! \n " , level , " " ) ;
lschunks ( demuxer , level + 1 , pos + len , trak ) ;
break ;
}
case MOV_FOURCC ( ' s ' , ' t ' , ' b ' , ' l ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sSample info! \n " , level , " " ) ;
lschunks ( demuxer , level + 1 , pos + len , trak ) ;
break ;
}
case MOV_FOURCC ( ' e ' , ' d ' , ' t ' , ' s ' ) : {
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: %*sEdit atom! \n " , level , " " ) ;
lschunks ( demuxer , level + 1 , pos + len , trak ) ;
break ;
}
case MOV_FOURCC ( ' e ' , ' l ' , ' s ' , ' t ' ) : {
int temp = stream_read_dword ( demuxer - > stream ) ;
int entries = stream_read_dword ( demuxer - > stream ) ;
int ver = ( temp < < 24 ) ;
int flags = ( temp < < 16 ) | ( temp < < 8 ) | temp ;
int i ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
2006-01-12 20:04:36 +00:00
" MOV: %*sEdit list table (%d entries) (ver:%d,flags:%d) \n " , level , " " ,
2005-07-10 08:57:31 +00:00
entries , ver , flags ) ;
# if 1
trak - > editlist_size = entries ;
2006-05-11 18:50:46 +00:00
trak - > editlist = calloc ( trak - > editlist_size , sizeof ( mov_editlist_t ) ) ;
2005-07-10 08:57:31 +00:00
for ( i = 0 ; i < entries ; i + + ) {
int dur = stream_read_dword ( demuxer - > stream ) ;
int mt = stream_read_dword ( demuxer - > stream ) ;
int mr = stream_read_dword ( demuxer - > stream ) ; // 16.16fp
trak - > editlist [ i ] . dur = dur ;
trak - > editlist [ i ] . pos = mt ;
trak - > editlist [ i ] . speed = mr ;
mp_msg ( MSGT_DEMUX , MSGL_V ,
" MOV: %*s entry#%d: duration: %d start time: %d speed: %3.1fx \n " , level , " " ,
i , dur , mt , ( float ) mr / 65536.0f ) ;
}
# endif
break ;
}
case MOV_FOURCC ( ' c ' , ' o ' , ' d ' , ' e ' ) : {
/* XXX: Implement atom 'code' for FLASH support */
break ;
}
default :
id = be2me_32 ( id ) ;
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: unknown chunk: %.4s %d \n " , ( char * ) & id , ( int ) len ) ;
2005-07-10 08:57:31 +00:00
break ;
} //switch(id)
return 0 ;
}
2005-08-05 19:57:47 +00:00
static demuxer_t * mov_read_header ( demuxer_t * demuxer ) {
2001-08-12 01:58:05 +00:00
mov_priv_t * priv = demuxer - > priv ;
2002-12-07 01:01:25 +00:00
int t_no ;
int best_a_id = - 1 , best_a_len = 0 ;
int best_v_id = - 1 , best_v_len = 0 ;
2001-08-12 01:58:05 +00:00
2001-10-26 14:04:17 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG3 , " mov_read_header! \n " ) ;
2001-08-12 01:58:05 +00:00
// Parse header:
2001-10-05 23:13:26 +00:00
stream_reset ( demuxer - > stream ) ;
2002-03-15 15:57:57 +00:00
if ( ! stream_seek ( demuxer - > stream , priv - > moov_start ) )
{
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , " MOV: Cannot seek to the beginning of the Movie header (0x% " PRIx64 " ) \n " ,
( int64_t ) priv - > moov_start ) ;
2002-03-15 15:57:57 +00:00
return 0 ;
}
2001-08-12 01:58:05 +00:00
lschunks ( demuxer , 0 , priv - > moov_end , NULL ) ;
2005-01-23 21:39:51 +00:00
// just in case we have hit eof while parsing...
demuxer - > stream - > eof = 0 ;
2002-05-20 03:51:58 +00:00
// mp_msg(MSGT_DEMUX, MSGL_INFO, "--------------\n");
2001-08-12 01:58:05 +00:00
2002-12-07 01:01:25 +00:00
// find the best (longest) streams:
for ( t_no = 0 ; t_no < priv - > track_db ; t_no + + ) {
mov_track_t * trak = priv - > tracks [ t_no ] ;
int len = ( trak - > samplesize ) ? trak - > chunks_size : trak - > samples_size ;
2003-01-06 21:58:39 +00:00
if ( demuxer - > a_streams [ t_no ] ) { // need audio
2002-12-07 01:01:25 +00:00
if ( len > best_a_len ) { best_a_len = len ; best_a_id = t_no ; }
}
2003-01-06 21:58:39 +00:00
if ( demuxer - > v_streams [ t_no ] ) { // need video
2002-12-07 01:01:25 +00:00
if ( len > best_v_len ) { best_v_len = len ; best_v_id = t_no ; }
}
}
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_V , " MOV: longest streams: A: #%d (%d samples) V: #%d (%d samples) \n " ,
2002-12-07 01:01:25 +00:00
best_a_id , best_a_len , best_v_id , best_v_len ) ;
2003-01-06 21:58:39 +00:00
if ( demuxer - > audio - > id = = - 1 & & best_a_id > = 0 ) demuxer - > audio - > id = best_a_id ;
if ( demuxer - > video - > id = = - 1 & & best_v_id > = 0 ) demuxer - > video - > id = best_v_id ;
2002-12-07 01:01:25 +00:00
// setup sh pointers:
if ( demuxer - > audio - > id > = 0 ) {
sh_audio_t * sh = demuxer - > a_streams [ demuxer - > audio - > id ] ;
2003-01-06 21:58:39 +00:00
if ( sh ) {
demuxer - > audio - > sh = sh ; sh - > ds = demuxer - > audio ;
} else {
2007-02-14 19:17:39 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , " MOV: selected audio stream (%d) does not exist \n " , demuxer - > audio - > id ) ;
2003-01-06 21:58:39 +00:00
demuxer - > audio - > id = - 2 ;
}
2002-12-07 01:01:25 +00:00
}
if ( demuxer - > video - > id > = 0 ) {
sh_video_t * sh = demuxer - > v_streams [ demuxer - > video - > id ] ;
2003-01-06 21:58:39 +00:00
if ( sh ) {
demuxer - > video - > sh = sh ; sh - > ds = demuxer - > video ;
} else {
2007-02-14 19:17:39 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , " MOV: selected video stream (%d) does not exist \n " , demuxer - > video - > id ) ;
2003-01-06 21:58:39 +00:00
demuxer - > video - > id = - 2 ;
}
2002-12-07 01:01:25 +00:00
}
2006-11-13 18:41:24 +00:00
if ( demuxer - > sub - > id > = 0 ) {
2006-11-14 15:02:15 +00:00
sh_sub_t * sh = demuxer - > s_streams [ demuxer - > sub - > id ] ;
2006-11-13 18:41:24 +00:00
if ( sh ) {
2006-11-14 15:02:15 +00:00
demuxer - > sub - > sh = sh ;
2006-11-13 18:41:24 +00:00
} else {
2007-02-14 19:17:39 +00:00
mp_msg ( MSGT_DEMUX , MSGL_ERR , " MOV: selected subtitle stream (%d) does not exist \n " , demuxer - > sub - > id ) ;
2006-11-13 18:41:24 +00:00
demuxer - > sub - > id = - 2 ;
}
}
2002-12-07 01:01:25 +00:00
2006-08-04 20:18:21 +00:00
if ( demuxer - > video - > id < 0 & & demuxer - > audio - > id < 0 ) {
/* No AV streams found. Try to find an MPEG stream. */
for ( t_no = 0 ; t_no < priv - > track_db ; t_no + + ) {
mov_track_t * trak = priv - > tracks [ t_no ] ;
if ( trak - > media_handler = = MOV_FOURCC ( ' M ' , ' P ' , ' E ' , ' G ' ) ) {
stream_t * s ;
demuxer_t * od ;
demuxer - > video - > id = t_no ;
s = new_ds_stream ( demuxer - > video ) ;
od = demux_open ( s , DEMUXER_TYPE_MPEG_PS , - 1 , - 1 , - 1 , NULL ) ;
if ( od ) return new_demuxers_demuxer ( od , od , od ) ;
demuxer - > video - > id = - 2 ; //new linked demuxer couldn't be allocated
break ;
}
}
}
2006-06-05 19:00:23 +00:00
#if 0
2006-03-24 08:12:03 +00:00
if ( mp_msg_test ( MSGT_DEMUX , MSGL_DBG3 ) ) {
2002-11-29 20:25:32 +00:00
for ( t_no = 0 ; t_no < priv - > track_db ; t_no + + ) {
mov_track_t * trak = priv - > tracks [ t_no ] ;
if ( trak - > type = = MOV_TRAK_GENERIC ) {
int i ;
int fd ;
char name [ 20 ] ;
mp_msg ( MSGT_DEMUX , MSGL_INFO , " MOV: Track #%d: Extracting %d data chunks to files \n " , t_no , trak - > samples_size ) ;
for ( i = 0 ; i < trak - > samples_size ; i + + )
{
int len = trak - > samples [ i ] . size ;
char buf [ len ] ;
stream_seek ( demuxer - > stream , trak - > samples [ i ] . pos ) ;
snprintf ( name , 20 , " t%02d-s%03d.%s " , t_no , i ,
( trak - > media_handler = = MOV_FOURCC ( ' f ' , ' l ' , ' s ' , ' h ' ) ) ?
" swf " : " dump " ) ;
fd = open ( name , O_CREAT | O_WRONLY ) ;
// { int j;
// for(j=0;j<trak->stdata_len-3; j++)
// printf("stdata[%d]=0x%X ize=0x%X\n",j,char2int(trak->stdata,j),MOV_FOURCC('z','l','i','b'));
// }
if ( //trak->media_handler==MOV_FOURCC('s','p','r','t') &&
trak - > stdata_len > = 16 & &
char2int ( trak - > stdata , 12 ) = = MOV_FOURCC ( ' z ' , ' l ' , ' i ' , ' b ' )
) {
int newlen = stream_read_dword ( demuxer - > stream ) ;
# ifdef HAVE_ZLIB
// unzip:
z_stream zstrm ;
int zret ;
char buf2 [ newlen ] ;
len - = 4 ;
stream_read ( demuxer - > stream , buf , len ) ;
zstrm . zalloc = ( alloc_func ) 0 ;
zstrm . zfree = ( free_func ) 0 ;
zstrm . opaque = ( voidpf ) 0 ;
zstrm . next_in = buf ;
zstrm . avail_in = len ;
zstrm . next_out = buf2 ;
zstrm . avail_out = newlen ;
zret = inflateInit ( & zstrm ) ;
zret = inflate ( & zstrm , Z_NO_FLUSH ) ;
if ( newlen ! = zstrm . total_out )
2006-01-12 20:04:36 +00:00
mp_msg ( MSGT_DEMUX , MSGL_WARN , " Warning! unzipped frame size differs hdr: %d zlib: %ld \n " , newlen , zstrm . total_out ) ;
2002-11-29 20:25:32 +00:00
write ( fd , buf2 , newlen ) ;
} else {
# else
len - = 4 ;
2006-03-06 08:26:07 +00:00
mp_msg ( MSGT_DEMUX , MSGL_INFO , " ******* ZLIB COMPRESSED SAMPLE!!!!! (%d->%d bytes) ******* \n " , len , newlen ) ;
2002-11-29 20:25:32 +00:00
}
{
# endif
stream_read ( demuxer - > stream , buf , len ) ;
write ( fd , buf , len ) ;
}
close ( fd ) ;
}
}
}
}
2005-01-23 21:39:51 +00:00
demuxer - > stream - > eof = 0 ;
2002-11-29 20:25:32 +00:00
# endif
2005-08-05 19:57:47 +00:00
return demuxer ;
2001-08-12 01:58:05 +00:00
}
2001-10-06 00:58:23 +00:00
2004-12-21 12:27:38 +00:00
/**
* \ brief return the mov track that belongs to a demuxer stream
* \ param ds the demuxer stream , may be NULL
* \ return the mov track info structure belonging to the stream ,
* NULL if not found
*/
static mov_track_t * stream_track ( mov_priv_t * priv , demux_stream_t * ds ) {
if ( ds & & ( ds - > id > = 0 ) & & ( ds - > id < priv - > track_db ) )
return priv - > tracks [ ds - > id ] ;
return NULL ;
}
2001-10-06 00:58:23 +00:00
// return value:
// 0 = EOF or no stream found
// 1 = successfully read a packet
2005-08-05 19:57:47 +00:00
static int demux_mov_fill_buffer ( demuxer_t * demuxer , demux_stream_t * ds ) {
2001-10-06 00:58:23 +00:00
mov_priv_t * priv = demuxer - > priv ;
mov_track_t * trak = NULL ;
float pts ;
2002-03-21 20:43:43 +00:00
int x ;
off_t pos ;
2001-10-06 00:58:23 +00:00
2005-09-28 15:37:30 +00:00
if ( ds - > eof ) return 0 ;
2004-12-21 12:27:38 +00:00
trak = stream_track ( priv , ds ) ;
if ( ! trak ) return 0 ;
2001-10-06 00:58:23 +00:00
2001-10-07 00:22:43 +00:00
if ( trak - > samplesize ) {
// read chunk:
if ( trak - > pos > = trak - > chunks_size ) return 0 ; // EOF
stream_seek ( demuxer - > stream , trak - > chunks [ trak - > pos ] . pos ) ;
pts = ( float ) ( trak - > chunks [ trak - > pos ] . sample * trak - > duration ) / ( float ) trak - > timescale ;
2001-11-22 15:43:24 +00:00
if ( trak - > samplesize ! = 1 )
{
2002-02-10 18:31:12 +00:00
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " WARNING! Samplesize(%d) != 1 \n " ,
2001-11-22 15:43:24 +00:00
trak - > samplesize ) ;
2006-04-23 11:38:06 +00:00
if ( ( trak - > fourcc ! = MOV_FOURCC ( ' t ' , ' w ' , ' o ' , ' s ' ) ) & & ( trak - > fourcc ! = MOV_FOURCC ( ' s ' , ' o ' , ' w ' , ' t ' ) ) )
x = trak - > chunks [ trak - > pos ] . size * trak - > samplesize ;
else
x = trak - > chunks [ trak - > pos ] . size ;
2001-11-22 15:43:24 +00:00
}
2006-04-23 11:38:06 +00:00
else
2001-11-22 15:43:24 +00:00
x = trak - > chunks [ trak - > pos ] . size ;
2001-12-22 00:33:35 +00:00
// printf("X = %d\n", x);
2002-02-10 18:31:12 +00:00
/* the following stuff is audio related */
2002-06-30 00:37:02 +00:00
if ( trak - > type = = MOV_TRAK_AUDIO ) {
2002-07-12 13:50:35 +00:00
if ( trak - > stdata_len > = 44 & & trak - > stdata [ 9 ] > = 1 & & char2int ( trak - > stdata , 28 ) > 0 ) {
2002-06-30 00:37:02 +00:00
// stsd version 1 - we have audio compression ratio info:
x / = char2int ( trak - > stdata , 28 ) ; // samples/packet
2002-07-06 15:14:32 +00:00
// x*=char2int(trak->stdata,32); // bytes/packet
x * = char2int ( trak - > stdata , 36 ) ; // bytes/frame
2002-06-30 00:37:02 +00:00
} else {
2002-10-16 16:51:03 +00:00
if ( ds - > ss_div & & ds - > ss_mul ) {
2002-06-30 00:37:02 +00:00
// workaround for buggy files like 7up-high-traffic-areas.mov,
// with missing stsd v1 header containing compression rate
2001-10-29 22:41:54 +00:00
x / = ds - > ss_div ; x * = ds - > ss_mul ; // compression ratio fix ! HACK !
} else {
2004-12-29 23:26:01 +00:00
x * = trak - > nchannels ;
x * = trak - > samplebytes ;
2001-10-29 22:41:54 +00:00
}
2002-06-30 00:37:02 +00:00
}
mp_msg ( MSGT_DEMUX , MSGL_DBG2 , " Audio sample %d bytes pts %5.3f \n " , trak - > chunks [ trak - > pos ] . size * trak - > samplesize , pts ) ;
2002-02-10 18:31:12 +00:00
} /* MOV_TRAK_AUDIO */
2002-03-21 20:43:43 +00:00
pos = trak - > chunks [ trak - > pos ] . pos ;
2001-10-07 00:22:43 +00:00
} else {
2002-07-07 15:21:30 +00:00
int frame = trak - > pos ;
// editlist support:
if ( trak - > type = = MOV_TRAK_VIDEO & & trak - > editlist_size > = 1 ) {
// find the right editlist entry:
if ( frame < trak - > editlist [ trak - > editlist_pos ] . start_frame )
trak - > editlist_pos = 0 ;
while ( trak - > editlist_pos < trak - > editlist_size - 1 & &
frame > = trak - > editlist [ trak - > editlist_pos + 1 ] . start_frame )
+ + trak - > editlist_pos ;
if ( frame > = trak - > editlist [ trak - > editlist_pos ] . start_frame +
trak - > editlist [ trak - > editlist_pos ] . frames ) return 0 ; // EOF
// calc real frame index:
frame - = trak - > editlist [ trak - > editlist_pos ] . start_frame ;
frame + = trak - > editlist [ trak - > editlist_pos ] . start_sample ;
// calc pts:
pts = ( float ) ( trak - > samples [ frame ] . pts +
trak - > editlist [ trak - > editlist_pos ] . pts_offset ) / ( float ) trak - > timescale ;
} else {
if ( frame > = trak - > samples_size ) return 0 ; // EOF
pts = ( float ) trak - > samples [ frame ] . pts / ( float ) trak - > timescale ;
}
2001-10-06 00:58:23 +00:00
// read sample:
2002-07-07 15:21:30 +00:00
stream_seek ( demuxer - > stream , trak - > samples [ frame ] . pos ) ;
x = trak - > samples [ frame ] . size ;
pos = trak - > samples [ frame ] . pos ;
2001-10-07 00:22:43 +00:00
}
2002-03-21 20:43:43 +00:00
if ( trak - > pos = = 0 & & trak - > stream_header_len > 0 ) {
// we have to append the stream header...
demux_packet_t * dp = new_demux_packet ( x + trak - > stream_header_len ) ;
memcpy ( dp - > buffer , trak - > stream_header , trak - > stream_header_len ) ;
stream_read ( demuxer - > stream , dp - > buffer + trak - > stream_header_len , x ) ;
2002-03-24 14:47:28 +00:00
free ( trak - > stream_header ) ;
trak - > stream_header = NULL ;
2003-09-11 09:05:54 +00:00
trak - > stream_header_len = 0 ;
2002-03-21 20:43:43 +00:00
dp - > pts = pts ;
dp - > flags = 0 ;
dp - > pos = pos ; // FIXME?
ds_add_packet ( ds , dp ) ;
} else
ds_read_packet ( ds , demuxer - > stream , x , pts , pos , 0 ) ;
2001-10-06 00:58:23 +00:00
+ + trak - > pos ;
2001-10-07 00:22:43 +00:00
2007-02-24 10:19:41 +00:00
trak = NULL ;
if ( demuxer - > sub - > id > = 0 & & demuxer - > sub - > id < priv - > track_db )
2006-11-13 18:41:24 +00:00
trak = priv - > tracks [ demuxer - > sub - > id ] ;
2007-02-24 10:19:41 +00:00
if ( trak ) {
int samplenr = 0 ;
2006-11-13 18:41:24 +00:00
while ( samplenr < trak - > samples_size ) {
double subpts = ( double ) trak - > samples [ samplenr ] . pts / ( double ) trak - > timescale ;
if ( subpts > = pts ) break ;
samplenr + + ;
}
samplenr - - ;
if ( samplenr < 0 )
vo_sub = NULL ;
else if ( samplenr ! = priv - > current_sub ) {
sh_sub_t * sh = demuxer - > sub - > sh ;
off_t pos = trak - > samples [ samplenr ] . pos ;
int len = trak - > samples [ samplenr ] . size ;
double subpts = ( double ) trak - > samples [ samplenr ] . pts / ( double ) trak - > timescale ;
stream_seek ( demuxer - > stream , pos ) ;
2007-01-06 19:07:58 +00:00
if ( sh - > type ! = ' v ' ) {
2006-11-13 18:41:24 +00:00
stream_skip ( demuxer - > stream , 2 ) ; // size
len - = 2 ;
if ( len < 0 ) len = 0 ;
if ( len > MOV_MAX_SUBLEN ) len = MOV_MAX_SUBLEN ;
2007-02-05 18:12:56 +00:00
sub_utf8 = 1 ;
2006-11-13 18:41:24 +00:00
}
2007-01-06 19:07:58 +00:00
ds_read_packet ( demuxer - > sub , demuxer - > stream , len , subpts , pos , 0 ) ;
2006-11-13 18:41:24 +00:00
priv - > current_sub = samplenr ;
}
}
2001-10-06 00:58:23 +00:00
return 1 ;
}
2001-10-16 22:41:46 +00:00
static float mov_seek_track ( mov_track_t * trak , float pts , int flags ) {
// printf("MOV track seek called %5.3f \n",pts);
if ( flags & 2 ) pts * = trak - > length ; else pts * = ( float ) trak - > timescale ;
if ( trak - > samplesize ) {
int sample = pts / trak - > duration ;
// printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration);
if ( ! ( flags & 1 ) ) sample + = trak - > chunks [ trak - > pos ] . sample ; // relative
trak - > pos = 0 ;
while ( trak - > pos < trak - > chunks_size & & trak - > chunks [ trak - > pos ] . sample < sample ) + + trak - > pos ;
2005-09-28 15:37:30 +00:00
if ( trak - > pos = = trak - > chunks_size ) return - 1 ;
2001-10-16 22:41:46 +00:00
pts = ( float ) ( trak - > chunks [ trak - > pos ] . sample * trak - > duration ) / ( float ) trak - > timescale ;
} else {
2001-10-29 22:11:40 +00:00
unsigned int ipts ;
if ( ! ( flags & 1 ) ) pts + = trak - > samples [ trak - > pos ] . pts ;
if ( pts < 0 ) pts = 0 ;
ipts = pts ;
//printf("MOV track seek - sample: %d \n",ipts);
2001-10-29 21:55:07 +00:00
for ( trak - > pos = 0 ; trak - > pos < trak - > samples_size ; + + trak - > pos ) {
if ( trak - > samples [ trak - > pos ] . pts > = ipts ) break ; // found it!
}
2005-09-28 15:37:30 +00:00
if ( trak - > pos = = trak - > samples_size ) return - 1 ;
2001-10-29 21:55:07 +00:00
if ( trak - > keyframes_size ) {
// find nearest keyframe
int i ;
for ( i = 0 ; i < trak - > keyframes_size ; i + + ) {
if ( trak - > keyframes [ i ] > = trak - > pos ) break ;
}
2005-09-28 15:37:30 +00:00
if ( i = = trak - > keyframes_size ) return - 1 ;
2001-10-29 22:40:25 +00:00
if ( i > 0 & & ( trak - > keyframes [ i ] - trak - > pos ) > ( trak - > pos - trak - > keyframes [ i - 1 ] ) )
- - i ;
2001-10-29 21:55:07 +00:00
trak - > pos = trak - > keyframes [ i ] ;
// printf("nearest keyframe: %d \n",trak->pos);
}
2001-10-16 22:41:46 +00:00
pts = ( float ) trak - > samples [ trak - > pos ] . pts / ( float ) trak - > timescale ;
}
// printf("MOV track seek done: %5.3f \n",pts);
return pts ;
}
2006-02-17 01:57:41 +00:00
static void demux_seek_mov ( demuxer_t * demuxer , float pts , float audio_delay , int flags ) {
2001-10-16 22:41:46 +00:00
mov_priv_t * priv = demuxer - > priv ;
demux_stream_t * ds ;
2004-12-21 12:27:38 +00:00
mov_track_t * trak ;
2001-10-16 22:41:46 +00:00
// printf("MOV seek called %5.3f flag=%d \n",pts,flags);
ds = demuxer - > video ;
2004-12-21 12:27:38 +00:00
trak = stream_track ( priv , ds ) ;
if ( trak ) {
2001-10-16 22:41:46 +00:00
//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
//if(!(flags&1)) pts+=ds->pts;
2005-09-28 15:37:30 +00:00
ds - > pts = mov_seek_track ( trak , pts , flags ) ;
if ( ds - > pts < 0 ) ds - > eof = 1 ;
else pts = ds - > pts ;
2001-10-16 22:41:46 +00:00
flags = 1 ; // absolute seconds
}
ds = demuxer - > audio ;
2004-12-21 12:27:38 +00:00
trak = stream_track ( priv , ds ) ;
if ( trak ) {
2001-10-16 22:41:46 +00:00
//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
//if(!(flags&1)) pts+=ds->pts;
ds - > pts = mov_seek_track ( trak , pts , flags ) ;
2005-09-28 15:37:30 +00:00
if ( ds - > pts < 0 ) ds - > eof = 1 ;
2001-10-16 22:41:46 +00:00
}
}
2005-08-05 19:57:47 +00:00
static int demux_mov_control ( demuxer_t * demuxer , int cmd , void * arg ) {
2004-12-21 12:27:38 +00:00
mov_track_t * track ;
// try the video track
track = stream_track ( demuxer - > priv , demuxer - > video ) ;
if ( ! track | | ! track - > length )
// otherwise try to get the info from the audio track
track = stream_track ( demuxer - > priv , demuxer - > audio ) ;
if ( ! track | | ! track - > length )
return DEMUXER_CTRL_DONTKNOW ;
switch ( cmd ) {
case DEMUXER_CTRL_GET_TIME_LENGTH :
if ( ! track - > timescale )
return DEMUXER_CTRL_DONTKNOW ;
2005-09-02 08:32:32 +00:00
* ( ( double * ) arg ) = ( double ) track - > length / track - > timescale ;
2004-12-21 12:27:38 +00:00
return DEMUXER_CTRL_OK ;
case DEMUXER_CTRL_GET_PERCENT_POS :
{
off_t pos = track - > pos ;
if ( track - > durmap_size > = 1 )
pos * = track - > durmap [ 0 ] . dur ;
* ( ( int * ) arg ) = ( int ) ( 100 * pos / track - > length ) ;
return DEMUXER_CTRL_OK ;
}
}
return DEMUXER_CTRL_NOTIMPL ;
}
2005-08-05 19:57:47 +00:00
2008-01-13 16:00:39 +00:00
const demuxer_desc_t demuxer_desc_mov = {
2005-08-05 19:57:47 +00:00
" Quicktime/MP4 demuxer " ,
" mov " ,
" Quicktime/MOV " ,
" Arpi, Al3x, Atmos, others " ,
" Handles Quicktime, MP4, 3GP " ,
DEMUXER_TYPE_MOV ,
0 , // slow autodetect
mov_check_file ,
demux_mov_fill_buffer ,
mov_read_header ,
demux_close_mov ,
demux_seek_mov ,
demux_mov_control
} ;