/*****************************************************************************
- * libasf.c :
+ * libasf.c :
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: libasf.c,v 1.7 2002/11/25 15:08:34 fenrir Exp $
+ * $Id: libasf.c,v 1.14 2003/08/17 23:42:37 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
*****************************************************************************/
#include <stdlib.h> /* malloc(), free() */
-#include <string.h> /* strdup() */
-#include <errno.h>
-#include <sys/types.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
+#include "codecs.h" /* BITMAPINFOHEADER, WAVEFORMATEX */
#include "libasf.h"
#define ASF_DEBUG 1
#define FREE( p ) \
if( p ) {free( p ); p = NULL; }
-
+
#define GUID_FMT "0x%x-0x%x-0x%x-0x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x"
#define GUID_PRINT( guid ) \
(guid).v1, \
(guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \
(guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7]
-/* Some functions to manipulate memory */
-static uint16_t GetWLE( uint8_t *p_buff )
-{
- return( (p_buff[0]) + ( p_buff[1] <<8 ) );
-}
-
-static uint32_t GetDWLE( uint8_t *p_buff )
-{
- return( p_buff[0] + ( p_buff[1] <<8 ) +
- ( p_buff[2] <<16 ) + ( p_buff[3] <<24 ) );
-}
-
-static uint64_t GetQWLE( uint8_t *p_buff )
-{
- return( ( (uint64_t)GetDWLE( p_buff ) )|
- ( (uint64_t)GetDWLE( p_buff + 4 ) << 32) );
-}
-
-void GetGUID( guid_t *p_guid, uint8_t *p_data )
+void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data )
{
p_guid->v1 = GetDWLE( p_data );
p_guid->v2 = GetWLE( p_data + 4);
memcpy( p_guid->v4, p_data + 8, 8 );
}
-int CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
+int ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 )
{
if( (p_guid1->v1 != p_guid2->v1 )||(p_guid1->v2 != p_guid2->v2 )||
(p_guid1->v3 != p_guid2->v3 )||
* Some basic functions to manipulate stream more easily in vlc
*
* ASF_TellAbsolute get file position
- *
+ *
* ASF_SeekAbsolute seek in the file
*
* ASF_ReadData read data from the file in a buffer
off_t ASF_TellAbsolute( input_thread_t *p_input )
{
off_t i_pos;
-
+
vlc_mutex_lock( &p_input->stream.stream_lock );
-
+
i_pos= p_input->stream.p_selected_area->i_tell;
// - ( p_input->p_last_data - p_input->p_current_data );
return( i_pos );
}
-
+
int ASF_SeekAbsolute( input_thread_t *p_input,
off_t i_pos)
{
}
if( p_input->stream.b_seekable &&
- ( p_input->stream.i_method == INPUT_METHOD_FILE ||
- i_pos < i_filepos ||
+ ( p_input->stream.i_method == INPUT_METHOD_FILE ||
+ i_pos < i_filepos ||
i_pos - i_filepos > 10000 ) )
{
- p_input->pf_seek( p_input, i_pos );
input_AccessReinit( p_input );
+ p_input->pf_seek( p_input, i_pos );
return( 1 );
}
else if( i_pos > i_filepos )
data_packet_t *p_data;
int i_read;
- i_read =
+ i_read =
input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
if( i_read <= 0 )
{
}
input_DeletePacket( p_input->p_method_data, p_data );
i_size -= i_read;
-
+
} while( i_size > 0 );
}
return( 1 );
int i_read;
-
+
if( !i_size )
{
return( 1 );
}
memcpy( p_buff, p_data->p_payload_start, i_read );
input_DeletePacket( p_input->p_method_data, p_data );
-
+
p_buff += i_read;
i_size -= i_read;
-
+
} while( i_size );
-
+
return( 1 );
}
int ASF_SkipBytes( input_thread_t *p_input, int i_count )
{
- return( ASF_SeekAbsolute( p_input,
+ return( ASF_SeekAbsolute( p_input,
ASF_TellAbsolute( p_input ) + i_count ) );
}
/****************************************************************************/
-int ASF_ReadObjectCommon( input_thread_t *p_input,
+int ASF_ReadObjectCommon( input_thread_t *p_input,
asf_object_t *p_obj )
{
asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
{
return( 0 );
}
- GetGUID( &p_common->i_object_id, p_peek );
+ ASF_GetGUID( &p_common->i_object_id, p_peek );
p_common->i_object_size = GetQWLE( p_peek + 16 );
p_common->i_object_pos = ASF_TellAbsolute( p_input );
p_common->p_next = NULL;
GUID_PRINT( p_common->i_object_id ),
p_common->i_object_size );
#endif
-
- return( 1 );
+
+ return( 1 );
}
int ASF_NextObject( input_thread_t *p_input,
if( p_obj->common.p_father && p_obj->common.p_father->common.i_object_size != 0 )
{
if( p_obj->common.p_father->common.i_object_pos + p_obj->common.p_father->common.i_object_size <
- p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
+ p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 )
/* 24 is min size of an object */
{
return( 0 );
}
}
- return( ASF_SeekAbsolute( p_input,
+ return( ASF_SeekAbsolute( p_input,
p_obj->common.i_object_pos + p_obj->common.i_object_size ) );
}
asf_object_t *p_subobj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, 30 ) ) < 30 )
{
return( 0 );
if( !( ASF_ReadObject( p_input, p_subobj, (asf_object_t*)p_hdr ) ) )
{
- break;
+ break;
}
if( !ASF_NextObject( p_input, p_subobj ) ) /* Go to the next object */
{
asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, 50 ) ) < 50 )
{
return( 0 );
}
- GetGUID( &p_data->i_file_id, p_peek + 24 );
+ ASF_GetGUID( &p_data->i_file_id, p_peek + 24 );
p_data->i_total_data_packets = GetQWLE( p_peek + 40 );
p_data->i_reserved = GetWLE( p_peek + 48 );
#ifdef ASF_DEBUG
asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, 56 ) ) < 56 )
{
return( 0 );
}
- GetGUID( &p_index->i_file_id, p_peek + 24 );
+ ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
msg_Dbg( p_input,
"Read \"Index Object\" file_id:" GUID_FMT
" index_entry_time_interval:"I64Fd" max_packet_count:%d "
- "index_entry_count:%d",
+ "index_entry_count:%ld",
GUID_PRINT( p_index->i_file_id ),
+ p_index->i_index_entry_time_interval,
p_index->i_max_packet_count,
- p_index->i_index_entry_count );
+ (long int)p_index->i_index_entry_count );
#endif
return( 1 );
}
asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, 92) ) < 92 )
{
return( 0 );
}
- GetGUID( &p_fp->i_file_id, p_peek + 24 );
+ ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 );
p_fp->i_file_size = GetQWLE( p_peek + 40 );
p_fp->i_creation_date = GetQWLE( p_peek + 48 );
p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
p_fp->i_max_bitrate = GetDWLE( p_peek + 100 );
-
+
#ifdef ASF_DEBUG
msg_Dbg( p_input,
"Read \"File Properties Object\" file_id:" GUID_FMT
asf_object_header_extention_t *p_he = (asf_object_header_extention_t*)p_obj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, p_he->i_object_size ) ) < 46)
{
return( 0 );
}
- GetGUID( &p_he->i_reserved1, p_peek + 24 );
+ ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 );
p_he->i_reserved2 = GetWLE( p_peek + 40 );
p_he->i_header_extention_size = GetDWLE( p_peek + 42 );
if( p_he->i_header_extention_size )
GUID_PRINT( p_he->i_reserved1 ),
p_he->i_reserved2,
p_he->i_header_extention_size );
-#endif
+#endif
return( 1 );
}
void ASF_FreeObject_header_extention( input_thread_t *p_input,
int ASF_ReadObject_stream_properties( input_thread_t *p_input,
asf_object_t *p_obj )
{
- asf_object_stream_properties_t *p_sp =
+ asf_object_stream_properties_t *p_sp =
(asf_object_stream_properties_t*)p_obj;
int i_peek;
uint8_t *p_peek;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, p_sp->i_object_size ) ) < 74 )
{
return( 0 );
}
- GetGUID( &p_sp->i_stream_type, p_peek + 24 );
- GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
+ ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
+ ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
p_sp->i_time_offset = GetQWLE( p_peek + 56 );
p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 );
p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 );
void ASF_FreeObject_stream_properties( input_thread_t *p_input,
asf_object_t *p_obj )
{
- asf_object_stream_properties_t *p_sp =
+ asf_object_stream_properties_t *p_sp =
(asf_object_stream_properties_t*)p_obj;
FREE( p_sp->p_type_specific_data );
int i_peek;
uint8_t *p_peek, *p_data;
- int i_codec;
-
+ unsigned int i_codec;
+
if( ( i_peek = input_Peek( p_input, &p_peek, p_cl->i_object_size ) ) < 44 )
{
return( 0 );
}
- GetGUID( &p_cl->i_reserved, p_peek + 24 );
+ ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
if( p_cl->i_codec_entries_count > 0 )
{
}
codec.psz_description[i_len] = '\0';
p_data += 2 * i_len;
-
+
/* opaque information */
codec.i_information_length = GetWLE( p_data ); p_data += 2;
if( codec.i_information_length > 0 )
p_cl->i_codec_entries_count );
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
{
+ char psz_cat[sizeof("Stream ")+10];
+ input_info_category_t *p_cat;
+ sprintf( psz_cat, "Stream %d", i_codec );
+ p_cat = input_InfoCategory( p_input, psz_cat);
+
#define codec p_cl->codec[i_codec]
- msg_Dbg( p_input,
+ input_AddInfo( p_cat, _("Codec name"), codec.psz_name );
+ input_AddInfo( p_cat, _("Codec description"), codec.psz_description );
+ msg_Dbg( p_input,
"Read \"Codec List Object\" codec[%d] %s name:\"%s\" description:\"%s\" information_length:%d",
i_codec,
( codec.i_type == ASF_CODEC_TYPE_VIDEO ) ? "video" : ( ( codec.i_type == ASF_CODEC_TYPE_AUDIO ) ? "audio" : "unknown" ),
- codec.psz_name,
- codec.psz_description,
+ codec.psz_name,
+ codec.psz_description,
codec.i_information_length );
-
+
#undef codec
}
#endif
asf_object_t *p_obj )
{
asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
- int i_codec;
+ unsigned int i_codec;
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
{
int ASF_ReadObject_content_description( input_thread_t *p_input,
asf_object_t *p_obj )
{
- asf_object_content_description_t *p_cd =
+ asf_object_content_description_t *p_cd =
(asf_object_content_description_t*)p_obj;
int i_peek;
uint8_t *p_peek, *p_data;
int i_copyright;
int i_description;
int i_rating;
-
+
#define GETSTRINGW( psz_str, i_size ) \
psz_str = calloc( i_size/2 + 1, sizeof( char ) ); \
for( i_len = 0; i_len < i_size/2; i_len++ ) \
} \
psz_str[i_size/2] = '\0'; \
p_data += i_size;
-
+
if( ( i_peek = input_Peek( p_input, &p_peek, p_cd->i_object_size ) ) < 34 )
{
return( 0 );
#undef GETSTRINGW
#ifdef ASF_DEBUG
+ {
+ input_info_category_t *p_cat = input_InfoCategory( p_input, _("Asf") );
+ input_AddInfo( p_cat, _("Title"), p_cd->psz_title );
+ input_AddInfo( p_cat, _("Author"), p_cd->psz_author );
+ input_AddInfo( p_cat, _("Copyright"), p_cd->psz_copyright );
+ input_AddInfo( p_cat, _("Description"), p_cd->psz_description );
+ input_AddInfo( p_cat, _("Rating"), p_cd->psz_rating );
+ }
msg_Dbg( p_input,
"Read \"Content Description Object\" title:\"%s\" author:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
p_cd->psz_title,
p_cd->psz_copyright,
p_cd->psz_description,
p_cd->psz_rating );
-#endif
+#endif
return( 1 );
}
asf_object_t *p_obj )
{
asf_object_content_description_t *p_cd = (asf_object_content_description_t*)p_obj;
-
+
FREE( p_cd->psz_title );
FREE( p_cd->psz_author );
FREE( p_cd->psz_copyright );
{
const guid_t *p_id;
int i_type;
- int (*ASF_ReadObject_function)( input_thread_t *p_input,
+ int (*ASF_ReadObject_function)( input_thread_t *p_input,
asf_object_t *p_obj );
void (*ASF_FreeObject_function)( input_thread_t *p_input,
asf_object_t *p_obj );
p_obj->common.p_first = NULL;
p_obj->common.p_next = NULL;
p_obj->common.p_last = NULL;
-
+
if( p_obj->common.i_object_size < 24 )
{
/* find this object */
for( i_index = 0; ; i_index++ )
{
- if( CmpGUID( ASF_Object_Function[i_index].p_id,
+ if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
&p_obj->common.i_object_id )||
- CmpGUID( ASF_Object_Function[i_index].p_id,
+ ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
&asf_object_null_guid ) )
{
break;
else
{
/* XXX ASF_ReadObject_function realloc *pp_obj XXX */
- i_result =
+ i_result =
(ASF_Object_Function[i_index].ASF_ReadObject_function)( p_input,
p_obj );
}
-
+
/* link this object with father */
if( p_father )
{
{
int i_index;
asf_object_t *p_child;
-
+
if( !p_obj )
{
return;
}
-
+
/* Free all child object */
p_child = p_obj->common.p_first;
while( p_child )
/* find this object */
for( i_index = 0; ; i_index++ )
{
- if( CmpGUID( ASF_Object_Function[i_index].p_id,
+ if( ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
&p_obj->common.i_object_id )||
- CmpGUID( ASF_Object_Function[i_index].p_id,
+ ASF_CmpGUID( ASF_Object_Function[i_index].p_id,
&asf_object_null_guid ) )
{
break;
/* Now free this object */
if( ASF_Object_Function[i_index].ASF_FreeObject_function == NULL )
{
- msg_Warn( p_input,
+ msg_Warn( p_input,
"Unknown asf object " GUID_FMT,
GUID_PRINT( p_obj->common.i_object_id ) );
}
else
{
#ifdef ASF_DEBUG
- msg_Dbg( p_input,
+ msg_Dbg( p_input,
"Free asf object " GUID_FMT,
GUID_PRINT( p_obj->common.i_object_id ) );
#endif
p_root->p_hdr = NULL;
p_root->p_data = NULL;
p_root->p_index = NULL;
-
+
for( ; ; )
{
p_obj = malloc( sizeof( asf_object_t ) );
asf_object_root_t *p_root )
{
asf_object_t *p_obj;
-
+
p_obj = p_root->p_first;
while( p_obj )
{
p_root->p_hdr = NULL;
p_root->p_data = NULL;
p_root->p_index = NULL;
-
+
}
int __ASF_CountObject( asf_object_t *p_obj, const guid_t *p_guid )
p_child = p_obj->common.p_first;
while( p_child )
{
- if( CmpGUID( &p_child->common.i_object_id, p_guid ) )
+ if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
{
i_count++;
}
while( p_child )
{
- if( CmpGUID( &p_child->common.i_object_id, p_guid ) )
+ if( ASF_CmpGUID( &p_child->common.i_object_id, p_guid ) )
{
if( i_number == 0 )
{