/*****************************************************************************
* libasf.c : asf stream demux module for vlc
*****************************************************************************
- * Copyright (C) 2001-2003 VideoLAN
+ * Copyright (C) 2001-2003 the VideoLAN team
* $Id$
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#include <vlc/vlc.h>
+
+#include <stdio.h>
#include <stdlib.h> /* malloc(), free() */
-#include <vlc/vlc.h>
#include <vlc/input.h>
#include "codecs.h" /* BITMAPINFOHEADER, WAVEFORMATEX */
#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, \
{
asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
- FREE( p_index->index_entry );
+ FREENULL( p_index->index_entry );
}
static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
int i_peek, i_entries, i;
uint8_t *p_peek;
+#ifdef ASF_DEBUG
+ unsigned int j;
+#endif
p_meta->i_record_entries_count = 0;
p_meta->record = 0;
msg_Dbg( s,
"read \"metadata object\" %d entries",
p_meta->i_record_entries_count );
- for( i = 0; i < p_meta->i_record_entries_count; i++ )
+ for( j = 0; j < p_meta->i_record_entries_count; j++ )
{
- asf_metadata_record_t *p_rec = &p_meta->record[i];
-
+ asf_metadata_record_t *p_rec = &p_meta->record[j];
+
if( p_rec->i_type == ASF_METADATA_TYPE_STRING )
msg_Dbg( s, " - %s=%s",
p_rec->psz_name, p_rec->p_data );
asf_object_header_extension_t *p_he =
(asf_object_header_extension_t *)p_obj;
- FREE( p_he->p_header_extension_data );
+ FREENULL( p_he->p_header_extension_data );
}
static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
asf_object_stream_properties_t *p_sp =
(asf_object_stream_properties_t*)p_obj;
- FREE( p_sp->p_type_specific_data );
- FREE( p_sp->p_error_correction_data );
+ FREENULL( p_sp->p_type_specific_data );
+ FREENULL( p_sp->p_error_correction_data );
}
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
{
#define codec p_cl->codec[i_codec]
- FREE( codec.psz_name );
- FREE( codec.psz_description );
- FREE( codec.p_information );
+ FREENULL( codec.psz_name );
+ FREENULL( codec.psz_description );
+ FREENULL( codec.p_information );
#undef codec
}
- FREE( p_cl->codec );
+ FREENULL( p_cl->codec );
}
/* Microsoft should go to hell. This time the length give number of bytes
asf_object_content_description_t *p_cd =
(asf_object_content_description_t *)p_obj;
uint8_t *p_peek, *p_data;
- int i_peek;
- int i_len, i_title, i_author, i_copyright, i_description, i_rating;
+ int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
+ vlc_iconv_t cd = (vlc_iconv_t)-1;
+ const char *ib = NULL;
+ char *ob = NULL;
+ size_t i_ibl, i_obl, i_len;
+
+ cd = vlc_iconv_open("UTF-8", "UTF-16LE");
+ if ( cd == (vlc_iconv_t)-1 ) {
+ msg_Err( s, "vlc_iconv_open failed" );
+ return VLC_EGENERIC;
+ }
+/* FIXME i_size*3 is the worst case. */
#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_len] = GetWLE( p_data + 2*i_len ); \
- } \
- psz_str[i_size/2] = '\0'; \
- p_data += i_size;
+ psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
+ ib = (const char *)p_data; \
+ ob = psz_str; \
+ i_ibl = i_size; \
+ i_obl = i_size*3; \
+ i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
+ p_data += i_size;
if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 )
{
p_data = p_peek + 24;
i_title = GetWLE( p_data ); p_data += 2;
- i_author= GetWLE( p_data ); p_data += 2;
+ i_artist= GetWLE( p_data ); p_data += 2;
i_copyright = GetWLE( p_data ); p_data += 2;
i_description = GetWLE( p_data ); p_data += 2;
i_rating = GetWLE( p_data ); p_data += 2;
GETSTRINGW( p_cd->psz_title, i_title );
- GETSTRINGW( p_cd->psz_author, i_author );
+ GETSTRINGW( p_cd->psz_artist, i_artist );
GETSTRINGW( p_cd->psz_copyright, i_copyright );
GETSTRINGW( p_cd->psz_description, i_description );
GETSTRINGW( p_cd->psz_rating, i_rating );
#ifdef ASF_DEBUG
msg_Dbg( s,
- "Read \"content description object\" title:\"%s\" author:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
+ "read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"",
p_cd->psz_title,
- p_cd->psz_author,
+ p_cd->psz_artist,
p_cd->psz_copyright,
p_cd->psz_description,
p_cd->psz_rating );
#endif
+
+ vlc_iconv_close(cd);
return VLC_SUCCESS;
}
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 );
- FREE( p_cd->psz_description );
- FREE( p_cd->psz_rating );
+ FREENULL( p_cd->psz_title );
+ FREENULL( p_cd->psz_artist );
+ FREENULL( p_cd->psz_copyright );
+ FREENULL( p_cd->psz_description );
+ FREENULL( p_cd->psz_rating );
}
/* Language list: */
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "Read \"language list object\" %d entries",
+ msg_Dbg( s, "read \"language list object\" %d entries",
p_ll->i_language );
for( i = 0; i < p_ll->i_language; i++ )
msg_Dbg( s, " - '%s'",
int i;
for( i = 0; i < p_ll->i_language; i++ )
- FREE( p_ll->ppsz_language[i] );
- FREE( p_ll->ppsz_language );
+ FREENULL( p_ll->ppsz_language[i] );
+ FREENULL( p_ll->ppsz_language );
}
/* Stream bitrate properties */
{
p_sb->bitrate[i].i_stream_number = GetWLE( &p_data[0] )& 0x7f;
p_sb->bitrate[i].i_avg_bitrate = GetDWLE( &p_data[2] );
-
+
p_data += 2+4;
}
#ifdef ASF_DEBUG
- msg_Dbg( s,"Read \"stream bitrate properties object\"" );
+ msg_Dbg( s,"read \"stream bitrate properties object\"" );
for( i = 0; i < p_sb->i_bitrate; i++ )
{
msg_Dbg( s," - stream=%d bitrate=%d",
p_esp->i_language_index = GetWLE( &p_data[50] );
p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] );
p_esp->i_stream_name_count = GetWLE( &p_data[60] );
- p_esp->i_payload_extention_system_count = GetWLE( &p_data[62] );
+ p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] );
p_data += 64;
p_esp->pi_stream_name_language[i] = GetWLE( &p_data[0] );
i_size = GetWLE( &p_data[2] );
p_data += 2;
-
+
psz = calloc( i_size/2 + 1, sizeof( char ) );
for( i_len = 0; i_len < i_size/2; i_len++ )
{
p_esp->ppsz_stream_name[i] = psz;
}
- for( i = 0; i < p_esp->i_payload_extention_system_count; i++ )
+ for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
{
/* Skip them */
int i_size = GetDWLE( &p_data[16 + 2] );
p_data += 16+2+4+i_size;
}
+ p_esp->p_sp = NULL;
if( p_data < &p_peek[i_peek] )
{
asf_object_t *p_sp;
else
{
/* This p_sp will be inserted by ReadRoot later */
- p_esp->p_sp = p_sp;
+ p_esp->p_sp = (asf_object_stream_properties_t*)p_sp;
}
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "Read \"extended stream properties object\":" );
+ msg_Dbg( s, "read \"extended stream properties object\":" );
msg_Dbg( s, " - start="I64Fd" end="I64Fd,
p_esp->i_start_time, p_esp->i_end_time );
msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
msg_Dbg( s, " - lang id=%d name=%s",
p_esp->pi_stream_name_language[i],
p_esp->ppsz_stream_name[i] );
- msg_Dbg( s, " - payload extention system count=%d",
- p_esp->i_payload_extention_system_count );
+ msg_Dbg( s, " - payload extension system count=%d",
+ p_esp->i_payload_extension_system_count );
#endif
return VLC_SUCCESS;
}
int i;
for( i = 0; i < p_esp->i_stream_name_count; i++ )
- FREE( p_esp->ppsz_stream_name[i] );
- FREE( p_esp->pi_stream_name_language );
- FREE( p_esp->ppsz_stream_name );
+ FREENULL( p_esp->ppsz_stream_name[i] );
+ FREENULL( p_esp->pi_stream_name_language );
+ FREENULL( p_esp->ppsz_stream_name );
}
- guid_t type;
- int16_t i_stream_number_count;
- int16_t *pi_stream_number;
-
static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
asf_object_t *p_obj)
{
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "Read \"advanced mutual exclusion object\"" );
+ msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
for( i = 0; i < p_ae->i_stream_number_count; i++ )
msg_Dbg( s, " - stream=%d", p_ae->pi_stream_number[i] );
#endif
asf_object_advanced_mutual_exclusion_t *p_ae =
(asf_object_advanced_mutual_exclusion_t *)p_obj;
- FREE( p_ae->pi_stream_number );
+ FREENULL( p_ae->pi_stream_number );
}
p_sp->pi_priority_flag[i] = GetWLE( p_data ); p_data += 2;
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "Read \"stream prioritization object\"" );
+ msg_Dbg( s, "read \"stream prioritization object\"" );
for( i = 0; i < p_sp->i_priority_count; i++ )
msg_Dbg( s, " - Stream:%d flags=0x%x",
p_sp->pi_priority_stream_number[i],
asf_object_stream_prioritization_t *p_sp =
(asf_object_stream_prioritization_t *)p_obj;
- FREE( p_sp->pi_priority_stream_number );
- FREE( p_sp->pi_priority_flag );
+ FREENULL( p_sp->pi_priority_stream_number );
+ FREENULL( p_sp->pi_priority_flag );
}
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "Read \"extended content description object\"" );
+ msg_Dbg( s, "read \"extended content description object\"" );
for( i = 0; i < p_ec->i_count; i++ )
msg_Dbg( s, " - '%s' = '%s'",
p_ec->ppsz_name[i],
for( i = 0; i < p_ec->i_count; i++ )
{
- FREE( p_ec->ppsz_name[i] );
- FREE( p_ec->ppsz_value[i] );
+ FREENULL( p_ec->ppsz_name[i] );
+ FREENULL( p_ec->ppsz_value[i] );
}
}
int i_result;
int i_index;
- if( !p_obj ) return( 0 );
+ if( !p_obj )
+ return( 0 );
+
+ memset( p_obj, 0, sizeof( p_obj ) );
if( ASF_ReadObjectCommon( s, p_obj ) )
{
{ &asf_object_file_properties_guid, "File Properties" },
{ &asf_object_stream_properties_guid, "Stream Properties" },
{ &asf_object_content_description_guid, "Content Description" },
- { &asf_object_header_extension_guid, "Header Extention" },
+ { &asf_object_header_extension_guid, "Header Extension" },
{ &asf_object_metadata_guid, "Metadata" },
{ &asf_object_codec_list_guid, "Codec List" },
{ &asf_object_marker_guid, "Marker" },