* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
-#include <stdio.h>
-#include <stdlib.h> /* malloc(), free() */
#include <vlc_demux.h>
p_str = NULL; \
}
-
#define MP4_READBOX_ENTER( MP4_Box_data_TYPE_t ) \
int64_t i_read = p_box->i_size; \
uint8_t *p_peek, *p_buff; \
*/
-static uint32_t Get24bBE( uint8_t *p )
+/* This macro is used when we want to printf the box type
+ * APPLE annotation box is :
+ * either 0xA9 + 24-bit ASCII text string (and 0xA9 isn't printable)
+ * either 32-bit ASCII text string
+ */
+#define MP4_BOX_TYPE_ASCII() ( ((char*)&p_box->i_type)[0] != (char)0xA9 )
+
+static uint32_t Get24bBE( const uint8_t *p )
{
return( ( p[0] <<16 ) + ( p[1] <<8 ) + p[2] );
}
-static void GetUUID( UUID_t *p_uuid, uint8_t *p_buff )
+static void GetUUID( UUID_t *p_uuid, const uint8_t *p_buff )
{
memcpy( p_uuid, p_buff, 16 );
}
/* made by 0xXXXXXXXX-0011-0010-8000-00aa00389b71
where XXXXXXXX is the fourcc */
/* FIXME implement this */
+ (void)p_uuid;
+ (void)i_fourcc;
}
/* some functions for mp4 encoding of variables */
int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box )
{
int i_read;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( ( ( i_read = stream_Peek( p_stream, &p_peek, 32 ) ) < 8 ) )
{
#ifdef MP4_VERBOSE
if( p_box->i_size )
{
- msg_Dbg( p_stream, "found Box: %4.4s size "I64Fd,
- (char*)&p_box->i_type, p_box->i_size );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Dbg( p_stream, "found Box: %4.4s size "I64Fd,
+ (char*)&p_box->i_type, p_box->i_size );
+ else
+ msg_Dbg( p_stream, "found Box: c%3.3s size "I64Fd,
+ (char*)&p_box->i_type+1, p_box->i_size );
}
#endif
if( p_box->p_father )
{
+ const int i_box_end = p_box->i_size + p_box->i_pos;
+ const int i_father_end = p_box->p_father->i_size + p_box->p_father->i_pos;
+
/* check if it's within p-father */
- if( p_box->i_size + p_box->i_pos >=
- p_box->p_father->i_size + p_box->p_father->i_pos )
+ if( i_box_end >= i_father_end )
{
- msg_Dbg( p_stream, "out of bound child" );
+ if( i_box_end > i_father_end )
+ msg_Dbg( p_stream, "out of bound child" );
return 0; /* out of bound */
}
}
static void MP4_FreeBox_Common( MP4_Box_t *p_box )
{
/* Up to now do nothing */
+ (void)p_box;
}
static int MP4_ReadBoxSkip( stream_t *p_stream, MP4_Box_t *p_box )
p_box->p_father->i_type == VLC_FOURCC( 'r', 'o', 'o', 't' ) &&
p_box->i_type == FOURCC_free )
{
- uint8_t *p_peek;
+ const uint8_t *p_peek;
int i_read;
vlc_fourcc_t i_fcc;
/* Nothing to do */
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream, "skip box: \"%4.4s\"", (char*)&p_box->i_type );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Dbg( p_stream, "skip box: \"%4.4s\"", (char*)&p_box->i_type );
+ else
+ msg_Dbg( p_stream, "skip box: \"c%3.3s\"", (char*)&p_box->i_type+1 );
#endif
return 1;
}
}
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream, "read box: \"hdlr\" handler type %4.4s name %s",
- (char*)&p_box->data.p_hdlr->i_handler_type,
- p_box->data.p_hdlr->psz_name );
+ msg_Dbg( p_stream, "read box: \"hdlr\" handler type %4.4s name %s",
+ (char*)&p_box->data.p_hdlr->i_handler_type,
+ p_box->data.p_hdlr->psz_name );
#endif
MP4_READBOX_EXIT( 1 );
static void MP4_FreeBox_url( MP4_Box_t *p_box )
{
- FREENULL( p_box->data.p_url->psz_location )
+ FREENULL( p_box->data.p_url->psz_location );
}
static int MP4_ReadBox_urn( stream_t *p_stream, MP4_Box_t *p_box )
{
/* SoundDescriptionV2 */
double f_sample_rate;
- int64_t dummy;
+ int64_t dummy;
uint32_t i_channel;
MP4_GET4BYTES( p_box->data.p_sample_soun->i_sample_per_packet );
MP4_GET8BYTES( dummy );
- memcpy( &f_sample_rate, &dummy, 8 );
+ memcpy( &f_sample_rate, &dummy, 8 );
msg_Dbg( p_stream, "read box: %f Hz", f_sample_rate );
p_box->data.p_sample_soun->i_sampleratehi = (int)f_sample_rate % 65536;
static void MP4_FreeBox_stss( MP4_Box_t *p_box )
{
- FREENULL( p_box->data.p_stss->i_sample_number )
+ FREENULL( p_box->data.p_stss->i_sample_number );
}
static int MP4_ReadBox_stsh( stream_t *p_stream, MP4_Box_t *p_box )
static void MP4_FreeBox_stsh( MP4_Box_t *p_box )
{
- FREENULL( p_box->data.p_stsh->i_shadowed_sample_number )
- FREENULL( p_box->data.p_stsh->i_sync_sample_number )
+ FREENULL( p_box->data.p_stsh->i_shadowed_sample_number );
+ FREENULL( p_box->data.p_stsh->i_sync_sample_number );
}
static void MP4_FreeBox_stdp( MP4_Box_t *p_box )
{
- FREENULL( p_box->data.p_stdp->i_priority )
+ FREENULL( p_box->data.p_stdp->i_priority );
}
static int MP4_ReadBox_padb( stream_t *p_stream, MP4_Box_t *p_box )
}
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream, "read box: \"elst\" entry-count "I64Fd, p_box->data.p_elst->i_entry_count );
+ msg_Dbg( p_stream, "read box: \"elst\" entry-count %lu",
+ (unsigned long)p_box->data.p_elst->i_entry_count );
#endif
MP4_READBOX_EXIT( 1 );
}
#ifdef MP4_VERBOSE
msg_Dbg( p_stream,
- "read box: \"rdrf\" type:%4.4s ref %s",
- (char*)&p_box->data.p_rdrf->i_ref_type,
- p_box->data.p_rdrf->psz_ref );
-
+ "read box: \"rdrf\" type:%4.4s ref %s",
+ (char*)&p_box->data.p_rdrf->i_ref_type,
+ p_box->data.p_rdrf->psz_ref );
#endif
MP4_READBOX_EXIT( 1 );
}
static void MP4_FreeBox_rdrf( MP4_Box_t *p_box )
{
- FREENULL( p_box->data.p_rdrf->psz_ref )
+ FREENULL( p_box->data.p_rdrf->psz_ref );
}
if( p_drms_box && p_drms_box->data.p_sample_soun->p_drms )
{
- int i_ret;
- if( config_GetInt( p_stream, "france" ) )
- {
- i_ret = -7;
- }
- else
- {
- i_ret= drms_init( p_drms_box->data.p_sample_soun->p_drms,
+ int i_ret = drms_init( p_drms_box->data.p_sample_soun->p_drms,
p_box->i_type, p_peek, i_read );
- }
if( i_ret )
{
const char *psz_error;
case -4: psz_error = "could not get SCI data"; break;
case -5: psz_error = "no user key found in SCI data"; break;
case -6: psz_error = "invalid user key"; break;
- case -7: psz_error = "you live in France"; break;
default: psz_error = "unknown error"; break;
}
-
- msg_Err( p_stream, "drms_init(%4.4s) failed (%s)",
- (char *)&p_box->i_type, psz_error );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Err( p_stream, "drms_init(%4.4s) failed (%s)",
+ (char *)&p_box->i_type, psz_error );
+ else
+ msg_Err( p_stream, "drms_init(c%3.3s) failed (%s)",
+ (char *)&p_box->i_type+1, psz_error );
drms_free( p_drms_box->data.p_sample_soun->p_drms );
p_drms_box->data.p_sample_soun->p_drms = NULL;
#ifdef MP4_VERBOSE
msg_Dbg( p_stream,
- "read box: \"%4.4s\" text=`%s'",
- (char*)&p_box->i_type,
+ "read box: \"c%3.3s\" text=`%s'",
+ ((char*)&p_box->i_type + 1),
p_box->data.p_0xa9xxx->psz_text );
#endif
}
p_box->data.p_0xa9xxx->psz_text[i_data_len] = '\0';
#ifdef MP4_VERBOSE
msg_Dbg( p_stream,
- "read box: \"%4.4s\" text=`%s'",
- (char*)&p_box->i_type,
+ "read box: \"c%3.3s\" text=`%s'",
+ ((char*)&p_box->i_type+1),
p_box->data.p_0xa9xxx->psz_text );
#endif
}
free( p_chpl->chapter[i].psz_name );
}
+static int MP4_ReadBox_tref_generic( stream_t *p_stream, MP4_Box_t *p_box )
+{
+ unsigned int i;
+ MP4_READBOX_ENTER( MP4_Box_data_tref_generic_t );
+
+ p_box->data.p_tref_generic->i_track_ID = NULL;
+ p_box->data.p_tref_generic->i_entry_count = i_read / sizeof(uint32_t);
+ if( p_box->data.p_tref_generic->i_entry_count > 0 )
+ p_box->data.p_tref_generic->i_track_ID = malloc( p_box->data.p_tref_generic->i_entry_count * sizeof(uint32_t) );
+
+ for( i = 0; i < p_box->data.p_tref_generic->i_entry_count; i++ )
+ {
+ MP4_GET4BYTES( p_box->data.p_tref_generic->i_track_ID[i] );
+ }
+#ifdef MP4_VERBOSE
+ msg_Dbg( p_stream, "read box: \"chap\" %d references",
+ p_box->data.p_tref_generic->i_entry_count );
+#endif
+
+ MP4_READBOX_EXIT( 1 );
+}
+static void MP4_FreeBox_tref_generic( MP4_Box_t *p_box )
+{
+ FREENULL( p_box->data.p_tref_generic->i_track_ID );
+}
+
static int MP4_ReadBox_meta( stream_t *p_stream, MP4_Box_t *p_box )
{
uint8_t meta_data[8];
return MP4_ReadBox_sample_tx3g( p_stream, p_box );
default:
msg_Warn( p_stream,
- "unknown handler type in stsd (uncompletetly loaded)" );
+ "unknown handler type in stsd (incompletely loaded)" );
return 1;
}
}
unknown:
- msg_Warn( p_stream,
- "unknown box type %4.4s (uncompletetly loaded)",
- (char*)&p_box->i_type );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Warn( p_stream,
+ "unknown box type %4.4s (incompletely loaded)",
+ (char*)&p_box->i_type );
+ else
+ msg_Warn( p_stream,
+ "unknown box type c%3.3s (incompletely loaded)",
+ (char*)&p_box->i_type+1 );
return 1;
}
/**** "Higher level" Functions ****/
/**** ------------------------------------------------------------------- ****/
-static struct
+static const struct
{
uint32_t i_type;
int (*MP4_ReadBox_function )( stream_t *p_stream, MP4_Box_t *p_box );
{ FOURCC_dpnd, MP4_ReadBox_default, NULL },
{ FOURCC_ipir, MP4_ReadBox_default, NULL },
{ FOURCC_mpod, MP4_ReadBox_default, NULL },
+ { FOURCC_chap, MP4_ReadBox_tref_generic, MP4_FreeBox_tref_generic },
/* found in hnti */
{ FOURCC_rtp, MP4_ReadBox_default, NULL },
if( MP4_Box_Function[i_index].MP4_FreeBox_function == NULL )
{
/* Should not happen */
- msg_Warn( s,
- "cannot free box %4.4s, type unknown",
- (char*)&p_box->i_type );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Warn( s,
+ "cannot free box %4.4s, type unknown",
+ (char*)&p_box->i_type );
+ else
+ msg_Warn( s,
+ "cannot free box c%3.3s, type unknown",
+ (char*)&p_box->i_type+1 );
}
else
{
if( !i_level )
{
- msg_Dbg( s, "dumping root Box \"%4.4s\"",
- (char*)&p_box->i_type );
+ if MP4_BOX_TYPE_ASCII()
+ msg_Dbg( s, "dumping root Box \"%4.4s\"",
+ (char*)&p_box->i_type );
+ else
+ msg_Dbg( s, "dumping root Box \"c%3.3s\"",
+ (char*)&p_box->i_type+1 );
}
else
{
{
str[i*5] = '|';
}
- sprintf( str + i_level * 5, "+ %4.4s size %d",
- (char*)&p_box->i_type,
- (uint32_t)p_box->i_size );
-
+ if MP4_BOX_TYPE_ASCII()
+ sprintf( str + i_level * 5, "+ %4.4s size %d",
+ (char*)&p_box->i_type, (uint32_t)p_box->i_size );
+ else
+ sprintf( str + i_level * 5, "+ c%3.3s size %d",
+ (char*)&p_box->i_type+1, (uint32_t)p_box->i_size );
msg_Dbg( s, "%s", str );
}
p_child = p_box->p_first;
return;
}
- vasprintf( &psz_path, psz_fmt, args );
+ if( vasprintf( &psz_path, psz_fmt, args ) == -1 )
+ psz_path = NULL;
if( !psz_path || !psz_path[0] )
{