Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
2171d2e9
Commit
2171d2e9
authored
Sep 08, 2003
by
Laurent Aimar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* all: clean up.
parent
e40e6065
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
451 deletions
+151
-451
modules/demux/mp4/libmp4.c
modules/demux/mp4/libmp4.c
+57
-211
modules/demux/mp4/libmp4.h
modules/demux/mp4/libmp4.h
+58
-194
modules/demux/mp4/mp4.c
modules/demux/mp4/mp4.c
+32
-44
modules/demux/mp4/mp4.h
modules/demux/mp4/mp4.h
+4
-2
No files found.
modules/demux/mp4/libmp4.c
View file @
2171d2e9
...
...
@@ -2,7 +2,7 @@
* libmp4.c : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: libmp4.c,v 1.3
2 2003/09/07 22:48:29
fenrir Exp $
* $Id: libmp4.c,v 1.3
3 2003/09/08 00:35:16
fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -20,10 +20,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <stdlib.h>
/* malloc(), free() */
#include <stdarg.h>
#include <string.h>
/* strdup() */
#include <errno.h>
#include <sys/types.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
...
...
@@ -38,8 +34,6 @@
* Here are defined some macro to make life simpler but before using it
* *look* at the code.
*
* XXX: All macro are written in capital letters
*
*****************************************************************************/
#define MP4_BOX_HEADERSIZE( p_box ) \
( 8 + ( p_box->i_shortsize == 1 ? 8 : 0 ) \
...
...
@@ -122,16 +116,14 @@
*/
static
uint32_t
Get24bBE
(
uint8_t
*
p
_buff
)
static
uint32_t
Get24bBE
(
uint8_t
*
p
)
{
return
(
(
p
_buff
[
0
]
<<
16
)
+
(
p_buff
[
1
]
<<
8
)
+
p_buff
[
2
]
);
return
(
(
p
[
0
]
<<
16
)
+
(
p
[
1
]
<<
8
)
+
p
[
2
]
);
}
static
void
GetUUID
(
UUID_t
*
p_uuid
,
uint8_t
*
p_buff
)
{
memcpy
(
p_uuid
,
p_buff
,
16
);
memcpy
(
p_uuid
,
p_buff
,
16
);
}
static
void
CreateUUID
(
UUID_t
*
p_uuid
,
uint32_t
i_fourcc
)
...
...
@@ -143,39 +135,28 @@ static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc )
/* some functions for mp4 encoding of variables */
void
MP4_ConvertDate2Str
(
char
*
psz
,
uint64_t
i_date
)
static
void
MP4_ConvertDate2Str
(
char
*
psz
,
uint64_t
i_date
)
{
int
i_day
;
int
i_hour
;
int
i_min
;
int
i_sec
;
/* date begin at 1 jan 1904 */
i_date
+=
((
1904ULL
*
365
)
+
17
)
*
24
*
60
*
60
;
i_day
=
i_date
/
(
60
*
60
*
24
);
i_hour
=
(
i_date
/
(
60
*
60
)
)
%
60
;
i_min
=
(
i_date
/
60
)
%
60
;
i_sec
=
i_date
%
60
;
/* FIXME do it correctly, date begin at 1 jan 1904 */
sprintf
(
psz
,
"%dd-%2.2dh:%2.2dm:%2.2ds"
,
i_day
,
i_hour
,
i_min
,
i_sec
);
}
#if 0
static void DataDump( uint8_t *p_data, int i_data )
{
int i;
fprintf( stderr, "\nDumping %d bytes\n", i_data );
for( i = 0; i < i_data; i++ )
{
int c;
c = p_data[i];
if( c < 32 || c > 127 ) c = '.';
fprintf( stderr, "%c", c );
if( i % 60 == 59 ) fprintf( stderr, "\n" );
}
fprintf( stderr, "\n" );
}
#endif
/*****************************************************************************
* Some prototypes.
*****************************************************************************/
static
MP4_Box_t
*
MP4_ReadBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_father
);
/*****************************************************************************
* Some basic functions to manipulate stream more easily in vlc
...
...
@@ -187,7 +168,7 @@ static void DataDump( uint8_t *p_data, int i_data )
* MP4_ReadData read data from the file in a buffer
*
*****************************************************************************/
off_t
MP4_TellAbsolute
(
input_thread_t
*
p_input
)
static
off_t
MP4_TellAbsolute
(
input_thread_t
*
p_input
)
{
off_t
i_pos
;
...
...
@@ -200,8 +181,7 @@ off_t MP4_TellAbsolute( input_thread_t *p_input )
return
(
i_pos
);
}
int
MP4_SeekAbsolute
(
input_thread_t
*
p_input
,
off_t
i_pos
)
static
int
MP4_SeekAbsolute
(
input_thread_t
*
p_input
,
off_t
i_pos
)
{
off_t
i_filepos
;
...
...
@@ -267,7 +247,7 @@ int MP4_SeekAbsolute( input_thread_t *p_input,
}
/* return 1 if success, 0 if fail */
int
MP4_ReadData
(
input_thread_t
*
p_input
,
uint8_t
*
p_buff
,
int
i_size
)
static
int
MP4_ReadData
(
input_thread_t
*
p_input
,
uint8_t
*
p_buff
,
int
i_size
)
{
data_packet_t
*
p_data
;
...
...
@@ -462,7 +442,7 @@ int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos)
*
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int
MP4_ReadBoxCommon
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
static
int
MP4_ReadBoxCommon
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
{
int
i_read
;
uint8_t
*
p_peek
;
...
...
@@ -523,7 +503,7 @@ int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
*****************************************************************************
* if p_box == NULL, go to the next box in witch we are( at the begining ).
*****************************************************************************/
int
MP4_NextBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
static
int
MP4_NextBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
{
MP4_Box_t
box
;
...
...
@@ -549,16 +529,6 @@ int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
}
return
(
MP4_SeekStream
(
p_stream
,
p_box
->
i_size
+
p_box
->
i_pos
)
?
0
:
1
);
}
/*****************************************************************************
* MP4_MP4_GotoBox : Go to this particular box
*****************************************************************************
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int
MP4_GotoBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
{
return
(
MP4_SeekStream
(
p_stream
,
p_box
->
i_pos
)
?
0
:
1
);
}
/*****************************************************************************
* For all known box a loader is given,
...
...
@@ -579,29 +549,21 @@ static int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_contain
do
{
p_box
=
malloc
(
sizeof
(
MP4_Box_t
)
);
if
(
MP4_ReadBox
(
p_stream
,
p_box
,
p_container
)
)
if
(
(
p_box
=
MP4_ReadBox
(
p_stream
,
p_container
)
)
==
NULL
)
{
/* chain this box with the father and the other at same level */
if
(
!
p_container
->
p_first
)
{
p_container
->
p_first
=
p_box
;
}
else
{
p_container
->
p_last
->
p_next
=
p_box
;
}
p_container
->
p_last
=
p_box
;
break
;
}
/* chain this box with the father and the other at same level */
if
(
!
p_container
->
p_first
)
{
p_container
->
p_first
=
p_box
;
}
else
{
/* free memory */
free
(
p_box
);
break
;
p_container
->
p_last
->
p_next
=
p_box
;
}
}
while
(
MP4_NextBox
(
p_stream
,
p_box
)
==
1
);
p_container
->
p_last
=
p_box
;
}
while
(
MP4_NextBox
(
p_stream
,
p_box
)
==
1
);
return
(
1
);
}
...
...
@@ -1804,7 +1766,6 @@ static void MP4_FreeBox_cmvd( MP4_Box_t *p_box )
static
int
MP4_ReadBox_cmov
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
)
{
MP4_Stream_t
*
p_stream_memory
;
MP4_Box_t
*
p_umov
;
MP4_Box_t
*
p_dcom
;
MP4_Box_t
*
p_cmvd
;
...
...
@@ -1834,9 +1795,9 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
return
(
0
);
}
if
(
!
(
p_dcom
=
MP4_FindBox
(
p_box
,
FOURCC_dcom
)
)
||
!
(
p_cmvd
=
MP4_FindBox
(
p_box
,
FOURCC_cmvd
)
)
||
!
(
p_cmvd
->
data
.
p_cmvd
->
p_data
)
)
if
(
(
p_dcom
=
MP4_BoxGet
(
p_box
,
"dcom"
)
)
==
NULL
||
(
p_cmvd
=
MP4_BoxGet
(
p_box
,
"cmvd"
)
)
==
NULL
||
p_cmvd
->
data
.
p_cmvd
->
p_data
==
NULL
)
{
msg_Warn
(
p_stream
->
p_input
,
"Read Box:
\"
cmov
\"
incomplete"
);
return
(
1
);
...
...
@@ -1913,27 +1874,21 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
msg_Dbg
(
p_stream
->
p_input
,
"Read Box:
\"
cmov
\"
box succesfully uncompressed"
);
//DataDump( p_data, p_cmvd->data.p_cmvd->i_uncompressed_size );
/* now create a memory stream */
p_stream_memory
=
MP4_MemoryStream
(
p_stream
->
p_input
,
p_cmvd
->
data
.
p_cmvd
->
i_uncompressed_size
,
p_cmvd
->
data
.
p_cmvd
->
p_data
);
//DataDump( p_stream_memory->p_buffer, p_stream_memory->i_stop );
/* and read uncompressd moov */
p_umov
=
malloc
(
sizeof
(
MP4_Box_t
)
);
i_result
=
MP4_ReadBox
(
p_stream_memory
,
p_umov
,
NULL
);
p_box
->
data
.
p_cmov
->
p_moov
=
MP4_ReadBox
(
p_stream_memory
,
NULL
);
p_box
->
data
.
p_cmov
->
p_moov
=
p_umov
;
free
(
p_stream_memory
);
#ifdef MP4_VERBOSE
msg_Dbg
(
p_stream
->
p_input
,
"Read Box:
\"
cmov
\"
compressed movie header completed"
);
#endif
return
(
i_result
);
return
(
p_box
->
data
.
p_cmov
->
p_moov
?
1
:
0
);
#endif
/* HAVE_ZLIB_H */
}
...
...
@@ -2171,20 +2126,22 @@ static struct
* MP4_ReadBox : parse the actual box and the children
* XXX : Do not go to the next box
*****************************************************************************/
int
MP4_ReadBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
,
MP4_Box_t
*
p_father
)
static
MP4_Box_t
*
MP4_ReadBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_father
)
{
int
i_result
;
MP4_Box_t
*
p_box
=
malloc
(
sizeof
(
MP4_Box_t
)
)
;
unsigned
int
i_index
;
if
(
!
MP4_ReadBoxCommon
(
p_stream
,
p_box
)
)
{
msg_Warn
(
p_stream
->
p_input
,
"Cannot read one box"
);
return
(
0
);
free
(
p_box
);
return
NULL
;
}
if
(
!
p_box
->
i_size
)
{
msg_Dbg
(
p_stream
->
p_input
,
"Found an empty box (null size)"
);
return
(
0
);
free
(
p_box
);
return
NULL
;
}
p_box
->
p_father
=
p_father
;
...
...
@@ -2202,124 +2159,16 @@ int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father )
msg_Warn
(
p_stream
->
p_input
,
"Unknown box type %4.4s (uncompletetly loaded)"
,
(
char
*
)
&
p_box
->
i_type
);
return
(
1
);
}
else
else
if
(
!
(
MP4_Box_Function
[
i_index
].
MP4_ReadBox_function
)(
p_stream
,
p_box
)
)
{
i_result
=
(
MP4_Box_Function
[
i_index
].
MP4_ReadBox_function
)(
p_stream
,
p_box
)
;
free
(
p_box
);
return
NULL
;
}
return
(
i_result
)
;
return
p_box
;
}
#if 0
/*****************************************************************************
* MP4_CountBox: given a box, count how many child have the requested type
* FIXME : support GUUID
*****************************************************************************/
int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type )
{
unsigned int i_count;
MP4_Box_t *p_child;
if( !p_box )
{
return( 0 );
}
i_count = 0;
p_child = p_box->p_first;
while( p_child )
{
if( p_child->i_type == i_type )
{
i_count++;
}
p_child = p_child->p_next;
}
return( i_count );
}
#endif
/*****************************************************************************
* MP4_FindBox: find first box with i_type child of p_box
* return NULL if not found
*****************************************************************************/
MP4_Box_t
*
MP4_FindBox
(
MP4_Box_t
*
p_box
,
uint32_t
i_type
)
{
MP4_Box_t
*
p_child
;
if
(
!
p_box
)
{
return
(
NULL
);
}
p_child
=
p_box
->
p_first
;
while
(
p_child
)
{
if
(
p_child
->
i_type
==
i_type
)
{
return
(
p_child
);
}
p_child
=
p_child
->
p_next
;
}
return
(
NULL
);
}
#if 0
/*****************************************************************************
* MP4_FindNextBox: find next box with thesame type and at the same level
* than p_box
*****************************************************************************/
MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box )
{
MP4_Box_t *p_next;
if( !p_box )
{
return( NULL );
}
p_next = p_box->p_next;
while( p_next )
{
if( p_next->i_type == p_box->i_type )
{
return( p_next );
}
p_next = p_next->p_next;
}
return( NULL );
}
/*****************************************************************************
* MP4_FindNbBox: find the box i_number
*****************************************************************************/
MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number )
{
MP4_Box_t *p_child = p_box->p_first;
if( !p_child )
{
return( NULL );
}
while( i_number )
{
if( !( p_child = p_child->p_next ) )
{
return( NULL );
}
i_number--;
}
return( p_child );
}
#endif
/*****************************************************************************
* MP4_FreeBox : free memory after read with MP4_ReadBox and all
* the children
...
...
@@ -2327,21 +2176,19 @@ MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number )
void
MP4_BoxFree
(
input_thread_t
*
p_input
,
MP4_Box_t
*
p_box
)
{
unsigned
int
i_index
;
MP4_Box_t
*
p_child
;
MP4_Box_t
*
p_next
;
MP4_Box_t
*
p_child
;
if
(
!
p_box
)
{
return
;
/* hehe */
}
p_child
=
p_box
->
p_first
;
while
(
p_child
)
for
(
p_child
=
p_box
->
p_first
;
p_child
!=
NULL
;
)
{
MP4_Box_t
*
p_next
;
p_next
=
p_child
->
p_next
;
MP4_BoxFree
(
p_input
,
p_child
);
/* MP4_FreeBoxChildren have free all data expect p_child itself */
free
(
p_child
);
p_child
=
p_next
;
}
...
...
@@ -2369,12 +2216,9 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
}
free
(
p_box
->
data
.
p_data
);
p_box
->
data
.
p_data
=
NULL
;
}
p_box
->
p_first
=
NULL
;
p_box
->
p_last
=
NULL
;
free
(
p_box
);
}
/*****************************************************************************
...
...
@@ -2383,12 +2227,13 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
* The first box is a virtual box "root" and is the father for all first
* level boxes for the file, a sort of virtual contener
*****************************************************************************/
int
MP4_BoxGetRoot
(
input_thread_t
*
p_input
,
MP4_Box_t
*
p_roo
t
)
MP4_Box_t
*
MP4_BoxGetRoot
(
input_thread_t
*
p_inpu
t
)
{
MP4_Box_t
*
p_root
;
MP4_Stream_t
*
p_stream
;
int
i_result
;
MP4_SeekAbsolute
(
p_input
,
0
);
/* Go to the begining */
p_root
=
malloc
(
sizeof
(
MP4_Box_t
)
);
p_root
->
i_pos
=
0
;
p_root
->
i_type
=
VLC_FOURCC
(
'r'
,
'o'
,
'o'
,
't'
);
p_root
->
i_shortsize
=
1
;
...
...
@@ -2415,10 +2260,10 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
/* check if there is a cmov, if so replace
compressed moov by uncompressed one */
if
(
(
(
p_moov
=
MP4_
FindBox
(
p_root
,
FOURCC_moov
)
)
&&
(
p_cmov
=
MP4_
FindBox
(
p_moov
,
FOURCC_cmov
)
)
)
||
(
(
p_moov
=
MP4_
FindBox
(
p_root
,
FOURCC_foov
)
)
&&
(
p_cmov
=
MP4_
FindBox
(
p_moov
,
FOURCC_cmov
)
)
)
)
if
(
(
(
p_moov
=
MP4_
BoxGet
(
p_root
,
"moov"
)
)
&&
(
p_cmov
=
MP4_
BoxGet
(
p_root
,
"moov/cmov"
)
)
)
||
(
(
p_moov
=
MP4_
BoxGet
(
p_root
,
"foov"
)
)
&&
(
p_cmov
=
MP4_
BoxGet
(
p_root
,
"foov/cmov"
)
)
)
)
{
/* rename the compressed moov as a box to skip */
p_moov
->
i_type
=
FOURCC_skip
;
...
...
@@ -2435,7 +2280,8 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
p_root
->
p_first
=
p_moov
;
}
}
return
(
i_result
);
return
p_root
;
}
...
...
modules/demux/mp4/libmp4.h
View file @
2171d2e9
...
...
@@ -2,14 +2,14 @@
* libmp4.h : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: libmp4.h,v 1.1
5 2003/08/17 20:45:50
fenrir Exp $
* $Id: libmp4.h,v 1.1
6 2003/09/08 00:35:16
fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
...
...
@@ -28,7 +28,7 @@
#define FOURCC_cmov VLC_FOURCC( 'c', 'm', 'o', 'v' )
#define FOURCC_dcom VLC_FOURCC( 'd', 'c', 'o', 'm' )
#define FOURCC_cmvd VLC_FOURCC( 'c', 'm', 'v', 'd' )
#define FOURCC_moof VLC_FOURCC( 'm', 'o', 'o', 'f' )
#define FOURCC_mdat VLC_FOURCC( 'm', 'd', 'a', 't' )
#define FOURCC_skip VLC_FOURCC( 's', 'k', 'i', 'p' )
...
...
@@ -163,18 +163,18 @@ typedef struct MP4_Stream_s
int
b_memory
;
/* do we uses a memory buffer */
input_thread_t
*
p_input
;
off_t
i_start
;
/* in the buffer position for memory stream */
off_t
i_stop
;
uint8_t
*
p_buffer
;
}
MP4_Stream_t
;
struct
MP4_Box_s
;
/* uuid Universal Unique IDentifiers */
typedef
struct
UUID_s
typedef
struct
UUID_s
{
uint8_t
b
[
16
];
}
UUID_t
;
...
...
@@ -195,7 +195,7 @@ typedef struct MP4_Box_data_mvhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint64_t
i_creation_time
;
uint64_t
i_modification_time
;
uint32_t
i_timescale
;
...
...
@@ -218,30 +218,30 @@ typedef struct MP4_Box_data_tkhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint64_t
i_creation_time
;
uint64_t
i_modification_time
;
uint32_t
i_track_ID
;
uint32_t
i_reserved
;
uint64_t
i_duration
;
uint32_t
i_reserved2
[
2
];
int16_t
i_layer
;
int16_t
i_predefined
;
int16_t
i_volume
;
uint16_t
i_reserved3
;
int32_t
i_matrix
[
9
];
int32_t
i_width
;
int32_t
i_height
;
}
MP4_Box_data_tkhd_t
;
typedef
struct
MP4_Box_data_mdhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint64_t
i_creation_time
;
uint64_t
i_modification_time
;
uint32_t
i_timescale
;
...
...
@@ -249,7 +249,7 @@ typedef struct MP4_Box_data_mdhd_s
/* one bit for pad */
/* unsigned int(5)[3] language difference with 0x60*/
unsigned
char
i_language
[
3
];
unsigned
char
i_language
[
3
];
uint16_t
i_predefined
;
}
MP4_Box_data_mdhd_t
;
...
...
@@ -258,12 +258,12 @@ typedef struct MP4_Box_data_hdlr_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint32_t
i_predefined
;
uint32_t
i_handler_type
;
/* "vide" "soun" "hint" "odsm"
"crsm" "sdsm" "m7sm" "ocsm"
uint32_t
i_handler_type
;
/* "vide" "soun" "hint" "odsm"
"crsm" "sdsm" "m7sm" "ocsm"
"ipsm" "mjsm" */
unsigned
char
*
psz_name
;
/* in UTF-8 */
}
MP4_Box_data_hdlr_t
;
...
...
@@ -272,9 +272,9 @@ typedef struct MP4_Box_data_vmhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
int16_t
i_graphics_mode
;
int16_t
i_opcolor
[
3
];
int16_t
i_opcolor
[
3
];
}
MP4_Box_data_vmhd_t
;
...
...
@@ -282,7 +282,7 @@ typedef struct MP4_Box_data_smhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
int16_t
i_balance
;
int16_t
i_reserved
;
...
...
@@ -292,7 +292,7 @@ typedef struct MP4_Box_data_hmhd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint16_t
i_max_PDU_size
;
uint16_t
i_avg_PDU_size
;
uint32_t
i_max_bitrate
;
...
...
@@ -305,9 +305,9 @@ typedef struct MP4_Box_data_url_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
unsigned
char
*
psz_location
;
}
MP4_Box_data_url_t
;
typedef
struct
MP4_Box_data_urn_s
...
...
@@ -317,7 +317,7 @@ typedef struct MP4_Box_data_urn_s
unsigned
char
*
psz_name
;
unsigned
char
*
psz_location
;
}
MP4_Box_data_urn_t
;
typedef
struct
MP4_Box_data_dref_s
...
...
@@ -344,7 +344,7 @@ typedef struct MP4_Box_data_ctts_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint32_t
i_entry_count
;
uint32_t
*
i_sample_count
;
/* these are array */
...
...
@@ -436,11 +436,11 @@ typedef struct MP4_Box_data_stsd_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint32_t
i_entry_count
;
/* it contains SampleEntry handled as if it was Box */
}
MP4_Box_data_stsd_t
;
...
...
@@ -451,7 +451,7 @@ typedef struct MP4_Box_data_stsz_s
uint32_t
i_sample_size
;
uint32_t
i_sample_count
;
uint32_t
*
i_entry_size
;
/* array , empty if i_sample_size != 0 */
}
MP4_Box_data_stsz_t
;
...
...
@@ -479,7 +479,7 @@ typedef struct MP4_Box_data_stsc_s
uint32_t
*
i_first_chunk
;
/* theses are arrays */
uint32_t
*
i_samples_per_chunk
;
uint32_t
*
i_sample_description_index
;
}
MP4_Box_data_stsc_t
;
...
...
@@ -489,7 +489,7 @@ typedef struct MP4_Box_data_co64_s
uint32_t
i_flags
;
uint32_t
i_entry_count
;
uint64_t
*
i_chunk_offset
;
}
MP4_Box_data_co64_t
;
...
...
@@ -499,11 +499,11 @@ typedef struct MP4_Box_data_stss_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
uint32_t
i_entry_count
;
uint32_t
*
i_sample_number
;
}
MP4_Box_data_stss_t
;
typedef
struct
MP4_Box_data_stsh_s
...
...
@@ -512,7 +512,7 @@ typedef struct MP4_Box_data_stsh_s
uint32_t
i_flags
;
uint32_t
i_entry_count
;
uint32_t
*
i_shadowed_sample_number
;
uint32_t
*
i_sync_sample_number
;
...
...
@@ -538,7 +538,7 @@ typedef struct MP4_Box_data_padb_s
uint16_t
*
i_pad2
;
/* 3bits */
uint16_t
*
i_reserved2
;
/* 1bit */
uint16_t
*
i_pad1
;
/* 3bits */
}
MP4_Box_data_padb_t
;
...
...
@@ -555,7 +555,7 @@ typedef struct MP4_Box_data_elst_s
uint16_t
*
i_media_rate_integer
;
uint16_t
*
i_media_rate_fraction
;
}
MP4_Box_data_elst_t
;
typedef
struct
MP4_Box_data_cprt_s
...
...
@@ -564,7 +564,7 @@ typedef struct MP4_Box_data_cprt_s
uint32_t
i_flags
;
/* 1 pad bit */
unsigned
char
i_language
[
3
];
unsigned
char
*
psz_notice
;
}
MP4_Box_data_cprt_t
;
...
...
@@ -578,18 +578,18 @@ typedef struct MP4_descriptor_decoder_config_s
int
i_buffer_sizeDB
;
int
i_max_bitrate
;
int
i_avg_bitrate
;
int
i_decoder_specific_info_len
;
uint8_t
*
p_decoder_specific_info
;
/* some other stuff */
}
MP4_descriptor_decoder_config_t
;
typedef
struct
MP4_descriptor_SL_config_s
{
int
i_dummy
;
/* ANSI C forbids empty structures */
}
MP4_descriptor_SL_config_t
;
...
...
@@ -607,7 +607,7 @@ typedef struct MP4_descriptor_ES_s
uint16_t
i_OCR_ES_ID
;
/* if b_OCRstream */
MP4_descriptor_decoder_config_t
*
p_decConfigDescr
;
MP4_descriptor_SL_config_t
*
p_slConfigDescr
;
/* some other stuff ... */
...
...
@@ -619,16 +619,16 @@ typedef struct MP4_Box_data_esds_s
{
uint8_t
i_version
;
uint32_t
i_flags
;
MP4_descriptor_ES_t
es_descriptor
;
}
MP4_Box_data_esds_t
;
typedef
struct
MP4_Box_data_dcom_s
{
uint32_t
i_algorithm
;
/* fourcc */
}
MP4_Box_data_dcom_t
;
typedef
struct
MP4_Box_data_cmvd_s
...
...
@@ -756,15 +756,15 @@ typedef union MP4_Box_data_s
typedef
struct
MP4_Box_s
{
off_t
i_pos
;
/* absolute position */
uint32_t
i_type
;
uint32_t
i_shortsize
;
UUID_t
i_uuid
;
/* Set if i_type == "uuid" */
uint64_t
i_size
;
/* always set so use it */
MP4_Box_data_t
data
;
/* union of pointers on extended data depending
MP4_Box_data_t
data
;
/* union of pointers on extended data depending
on i_type (or i_usertype) */
struct
MP4_Box_s
*
p_father
;
/* pointer on the father Box */
...
...
@@ -776,35 +776,21 @@ typedef struct MP4_Box_s
}
MP4_Box_t
;
/*---------------------------------------------------------------------------*/
/* */
/****----------------------- High level functions ------------------------****/
/* */
/*---------------------------------------------------------------------------*/
/*****************************************************************************
* Function for manipulate stream easily
*****************************************************************************/
off_t
MP4_TellAbsolute
(
input_thread_t
*
p_input
);
int
MP4_SeekAbsolute
(
input_thread_t
*
p_input
,
off_t
i_pos
);
int
MP4_ReadData
(
input_thread_t
*
p_input
,
uint8_t
*
p_buff
,
int
i_size
);
/*****************************************************************************
* MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
*****************************************************************************
* The first box is a virtual box "root" and is the father for all first
* level boxes
*
* RETURN : 1 if succes and 0 if it failed
* The first box is a virtual box "root" and is the father for all first
* level boxes
*****************************************************************************/
int
MP4_BoxGetRoot
(
input_thread_t
*
p_input
,
MP4_Box_t
*
p_roo
t
);
MP4_Box_t
*
MP4_BoxGetRoot
(
input_thread_t
*
p_inpu
t
);
/*****************************************************************************
* MP4_FreeBox : free memory allocated after read with MP4_ReadBox
* or MP4_BoxGetRoot, this means also children boxes
* XXX : all children have to be allocated by a malloc !! and
* p_box is
n't freeing
* XXX : all children have to be allocated by a malloc !! and
* p_box is
freed
*****************************************************************************/
void
MP4_BoxFree
(
input_thread_t
*
p_input
,
MP4_Box_t
*
p_box
);
...
...
@@ -821,142 +807,20 @@ void MP4_BoxDumpStructure( input_thread_t *p_input, MP4_Box_t *p_box );
*****************************************************************************
* Path Format: . .. / as usual
* [number] to specifie box number ex: trak[12]
*
*
* ex: /moov/trak[12]
* ../mdia
* ../mdia
*****************************************************************************/
MP4_Box_t
*
MP4_BoxGet
(
MP4_Box_t
*
p_box
,
char
*
psz_fmt
,
...
);
/*****************************************************************************
* MP4_BoxCount: find number of box given a path relative to p_box
*****************************************************************************
* Path Format: . .. / as usual
* [number] to specifie box number ex: trak[12]
*
*
* ex: /moov/trak
* ../mdia
* ../mdia
*****************************************************************************/
int
MP4_BoxCount
(
MP4_Box_t
*
p_box
,
char
*
psz_fmt
,
...
);
/*---------------------------------------------------------------------------*/
/* */
/****---------------------- Medium level functions -----------------------****/
/* */
/*---------------------------------------------------------------------------*/
#if 0
/*****************************************************************************
* MP4_CountBox: given a box, count how many child have the requested type
* FIXME : support GUUID
*****************************************************************************/
int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type );
#endif
/*****************************************************************************
* MP4_FindBox: find first box with i_type child of p_box
* return NULL if not found
*****************************************************************************/
MP4_Box_t
*
MP4_FindBox
(
MP4_Box_t
*
p_box
,
uint32_t
i_type
);
#if 0
/*****************************************************************************
* MP4_FindNextBox: find next box with thesame type and at the same level
* than p_box
*****************************************************************************/
MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box );
/*****************************************************************************
* MP4_FindNbBox: find the box i_number
*****************************************************************************/
MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number );
#endif
/*---------------------------------------------------------------------------*/
/****----------------------- Lower level functions -----------------------****/
/**** ****/
/****------Use them only when you known what they really do and need------****/
/**** ****/
/****---------------------------------------------------------------------****/
/*---------------------------------------------------------------------------*/
/**** ------- First some function to make abstract from input -------- */
/****************************************************************************
* MP4_InputStream create an stram with an input
*
****************************************************************************/
MP4_Stream_t
*
MP4_InputStream
(
input_thread_t
*
p_input
);
/****************************************************************************
* MP4_MemoryStream create a memory stream
* if p_buffer == NULL, will allocate a buffer of i_size, else
* it uses p_buffer XXX you have to unallocate yourself !
*
****************************************************************************/
MP4_Stream_t
*
MP4_MemoryStream
(
input_thread_t
*
p_input
,
int
i_size
,
uint8_t
*
p_buffer
);
/****************************************************************************
* MP4_ReadStream read from a MP4_Stream_t
*
****************************************************************************/
int
MP4_ReadStream
(
MP4_Stream_t
*
p_stream
,
uint8_t
*
p_buff
,
int
i_size
);
/****************************************************************************
* MP4_PeekStream guess it ;)
*
****************************************************************************/
int
MP4_PeekStream
(
MP4_Stream_t
*
p_stream
,
uint8_t
**
pp_peek
,
int
i_size
);
/****************************************************************************
* MP4_TellStream give absolute position in the stream
* XXX for a memory stream give position from begining of the buffer
****************************************************************************/
off_t
MP4_TellStream
(
MP4_Stream_t
*
p_stream
);
/****************************************************************************
* MP4_SeekStream seek in a MP4_Stream_t
*
****************************************************************************/
int
MP4_SeekStream
(
MP4_Stream_t
*
p_stream
,
off_t
i_pos
);
/*****************************************************************************
* MP4_ReadBox : parse the actual box and the children if they exist
*
* RETURN : 1 if succes and 0 if it failed
*****************************************************************************/
int
MP4_ReadBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
,
MP4_Box_t
*
p_father
);
/*****************************************************************************
* MP4_ReadBoxCommon : Load only common parameters for all boxes
*****************************************************************************
* p_box need to be an already allocated MP4_Box_t, and all data
* will only be peek not read
*
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int
MP4_ReadBoxCommon
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
);
/*****************************************************************************
* MP4_MP4_GotoBox : Go to this particular box
*****************************************************************************
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int
MP4_GotoBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
);
/*****************************************************************************
* MP4_MP4_NextBox : Go to the next box wiithin p_box->p_father
*****************************************************************************
* if p_box == NULL, go to the next box in witch we are( at the begining ).
*****************************************************************************/
int
MP4_NextBox
(
MP4_Stream_t
*
p_stream
,
MP4_Box_t
*
p_box
);
modules/demux/mp4/mp4.c
View file @
2171d2e9
...
...
@@ -2,7 +2,7 @@
* mp4.c : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mp4.c,v 1.3
5 2003/09/07 22:48:29
fenrir Exp $
* $Id: mp4.c,v 1.3
6 2003/09/08 00:35:16
fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -138,21 +138,28 @@ static int Open( vlc_object_t * p_this )
p_input
->
pf_demux
=
Demux
;
p_input
->
pf_demux_control
=
Control
;
/* create our structure that will contains all data */
p_input
->
p_demux_data
=
p_demux
=
malloc
(
sizeof
(
demux_sys_t
)
);
memset
(
p_demux
,
0
,
sizeof
(
demux_sys_t
)
);
/* Create stream facilities */
if
(
(
p_demux
->
s
=
stream_OpenInput
(
p_input
)
)
==
NULL
)
{
msg_Err
(
p_input
,
"cannot create stream_t"
);
free
(
p_demux
);
return
VLC_EGENERIC
;
}
/* Now load all boxes ( except raw data ) */
if
(
!
MP4_BoxGetRoot
(
p_input
,
&
p_demux
->
box_root
)
)
if
(
(
p_demux
->
p_root
=
MP4_BoxGetRoot
(
p_input
)
)
==
NULL
)
{
msg_Warn
(
p_input
,
"MP4 plugin discarded (not a valid file)"
);
return
VLC_EGENERIC
;
goto
error
;
}
MP4_BoxDumpStructure
(
p_input
,
&
p_demux
->
box
_root
);
MP4_BoxDumpStructure
(
p_input
,
p_demux
->
p
_root
);
if
(
(
p_ftyp
=
MP4_BoxGet
(
&
p_demux
->
box
_root
,
"/ftyp"
)
)
)
if
(
(
p_ftyp
=
MP4_BoxGet
(
p_demux
->
p
_root
,
"/ftyp"
)
)
)
{
switch
(
p_ftyp
->
data
.
p_ftyp
->
i_major_brand
)
{
...
...
@@ -174,9 +181,9 @@ static int Open( vlc_object_t * p_this )
}
/* the file need to have one moov box */
if
(
MP4_BoxCount
(
&
p_demux
->
box
_root
,
"/moov"
)
<=
0
)
if
(
MP4_BoxCount
(
p_demux
->
p
_root
,
"/moov"
)
<=
0
)
{
MP4_Box_t
*
p_foov
=
MP4_BoxGet
(
&
p_demux
->
box
_root
,
"/foov"
);
MP4_Box_t
*
p_foov
=
MP4_BoxGet
(
p_demux
->
p
_root
,
"/foov"
);
if
(
!
p_foov
)
{
...
...
@@ -187,7 +194,7 @@ static int Open( vlc_object_t * p_this )
p_foov
->
i_type
=
FOURCC_moov
;
}
if
(
(
p_rmra
=
MP4_BoxGet
(
&
p_demux
->
box
_root
,
"/moov/rmra"
)
)
)
if
(
(
p_rmra
=
MP4_BoxGet
(
p_demux
->
p
_root
,
"/moov/rmra"
)
)
)
{
playlist_t
*
p_playlist
;
int
i_count
=
MP4_BoxCount
(
p_rmra
,
"rmda"
);
...
...
@@ -267,7 +274,7 @@ static int Open( vlc_object_t * p_this )
}
}
if
(
!
(
p_mvhd
=
MP4_BoxGet
(
&
p_demux
->
box
_root
,
"/moov/mvhd"
)
)
)
if
(
!
(
p_mvhd
=
MP4_BoxGet
(
p_demux
->
p
_root
,
"/moov/mvhd"
)
)
)
{
if
(
!
p_rmra
)
{
...
...
@@ -288,7 +295,7 @@ static int Open( vlc_object_t * p_this )
}
if
(
!
(
p_demux
->
i_tracks
=
MP4_BoxCount
(
&
p_demux
->
box
_root
,
"/moov/trak"
)
)
)
MP4_BoxCount
(
p_demux
->
p
_root
,
"/moov/trak"
)
)
)
{
msg_Err
(
p_input
,
"cannot find any /moov/trak"
);
goto
error
;
...
...
@@ -332,7 +339,7 @@ static int Open( vlc_object_t * p_this )
/* now process each track and extract all usefull informations */
for
(
i
=
0
;
i
<
p_demux
->
i_tracks
;
i
++
)
{
p_trak
=
MP4_BoxGet
(
&
p_demux
->
box
_root
,
"/moov/trak[%d]"
,
i
);
p_trak
=
MP4_BoxGet
(
p_demux
->
p
_root
,
"/moov/trak[%d]"
,
i
);
MP4_TrackCreate
(
p_input
,
&
p_demux
->
track
[
i
],
p_trak
);
if
(
p_demux
->
track
[
i
].
b_ok
)
...
...
@@ -391,7 +398,12 @@ static int Open( vlc_object_t * p_this )
return
VLC_SUCCESS
;
error:
Close
(
VLC_OBJECT
(
p_input
)
);
stream_Release
(
p_demux
->
s
);
if
(
p_demux
->
p_root
)
{
MP4_BoxFree
(
p_input
,
p_demux
->
p_root
);
}
free
(
p_demux
);
return
VLC_EGENERIC
;
}
...
...
@@ -491,7 +503,6 @@ static int Demux( input_thread_t *p_input )
size_t
i_size
;
off_t
i_pos
;
data_packet_t
*
p_data
;
pes_packet_t
*
p_pes
;
/* caculate size and position for this sample */
...
...
@@ -502,44 +513,20 @@ static int Demux( input_thread_t *p_input )
//msg_Dbg( p_input, "stream %d size=%6d pos=%8lld", i_track, i_size, i_pos );
/* go,go go ! */
if
(
MP4_SeekAbsolute
(
p_input
,
i_pos
)
)
if
(
stream_Seek
(
p_demux
->
s
,
i_pos
)
)
{
msg_Warn
(
p_input
,
"track[0x%x] will be disabled (eof?)"
,
track
.
i_track_ID
);
MP4_TrackUnselect
(
p_input
,
&
track
);
break
;
}
/* now create a pes */
if
(
!
(
p_pes
=
input_NewPES
(
p_input
->
p_method_data
)
)
)
{
break
;
}
/* and a data packet for the data */
if
(
!
(
p_data
=
input_NewPacket
(
p_input
->
p_method_data
,
i_size
)
)
)
/* now read pes */
if
(
(
p_pes
=
stream_PesPacket
(
p_demux
->
s
,
i_size
)
)
==
NULL
)
{
input_DeletePES
(
p_input
->
p_method_data
,
p_pes
);
msg_Warn
(
p_input
,
"track[0x%x] will be disabled (eof?)"
,
track
.
i_track_ID
);
MP4_TrackUnselect
(
p_input
,
&
track
);
break
;
}
p_data
->
p_payload_end
=
p_data
->
p_payload_start
+
i_size
;
/* initialisation of all the field */
p_pes
->
i_dts
=
p_pes
->
i_pts
=
0
;
p_pes
->
p_first
=
p_pes
->
p_last
=
p_data
;
p_pes
->
i_nb_data
=
1
;
p_pes
->
i_pes_size
=
i_size
;
if
(
i_size
>
0
)
{
if
(
MP4_ReadData
(
p_input
,
p_data
->
p_payload_start
,
i_size
)
)
{
input_DeletePES
(
p_input
->
p_method_data
,
p_pes
);
msg_Warn
(
p_input
,
"track[0x%x] will be disabled (eof?)"
,
track
.
i_track_ID
);
MP4_TrackUnselect
(
p_input
,
&
track
);
break
;
}
}
p_pes
->
i_dts
=
p_pes
->
i_pts
=
input_ClockGetTS
(
p_input
,
p_input
->
stream
.
p_selected_program
,
...
...
@@ -657,7 +644,8 @@ static void Close ( vlc_object_t * p_this )
demux_sys_t
*
p_demux
=
p_input
->
p_demux_data
;
msg_Dbg
(
p_input
,
"freeing all memory"
);
MP4_BoxFree
(
p_input
,
&
p_demux
->
box_root
);
MP4_BoxFree
(
p_input
,
p_demux
->
p_root
);
for
(
i_track
=
0
;
i_track
<
p_demux
->
i_tracks
;
i_track
++
)
{
MP4_TrackDestroy
(
p_input
,
&
p_demux
->
track
[
i_track
]
);
...
...
modules/demux/mp4/mp4.h
View file @
2171d2e9
...
...
@@ -2,7 +2,7 @@
* mp4.h : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: mp4.h,v 1.
6 2003/03/11 18:57:51
fenrir Exp $
* $Id: mp4.h,v 1.
7 2003/09/08 00:35:16
fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
...
...
@@ -127,7 +127,9 @@ typedef struct track_data_mp4_s
*****************************************************************************/
struct
demux_sys_t
{
MP4_Box_t
box_root
;
/* container for the whole file */
stream_t
*
s
;
MP4_Box_t
*
p_root
;
/* container for the whole file */
mtime_t
i_pcr
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment