+
+ return VLC_SUCCESS;
+}
+
+static void ASF_FreeObject_content_description( asf_object_t *p_obj)
+{
+ asf_object_content_description_t *p_cd = &p_obj->content_description;
+
+ 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: */
+static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
+{
+ asf_object_language_list_t *p_ll = &p_obj->language_list;
+ const uint8_t *p_peek, *p_data;
+ int i_peek;
+ int i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ p_ll->i_language = ASF_READ2();
+ if( p_ll->i_language > 0 )
+ {
+ p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
+ if( !p_ll->ppsz_language )
+ return VLC_ENOMEM;
+
+ for( i = 0; i < p_ll->i_language; i++ )
+ {
+ if( !ASF_HAVE(1) )
+ break;
+ p_ll->ppsz_language[i] = ASF_READS( ASF_READ1() );
+ }
+ p_ll->i_language = i;
+ }
+
+#ifdef ASF_DEBUG
+ 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'",
+ p_ll->ppsz_language[i] );
+#endif
+ return VLC_SUCCESS;
+}
+
+static void ASF_FreeObject_language_list( asf_object_t *p_obj)
+{
+ asf_object_language_list_t *p_ll = &p_obj->language_list;
+ int i;
+
+ for( i = 0; i < p_ll->i_language; i++ )
+ FREENULL( p_ll->ppsz_language[i] );
+ FREENULL( p_ll->ppsz_language );
+}
+
+/* Stream bitrate properties */
+static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
+ asf_object_t *p_obj)
+{
+ asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate;
+ const uint8_t *p_peek, *p_data;
+ int i_peek;
+ int i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ p_sb->i_bitrate = ASF_READ2();
+ if( p_sb->i_bitrate > 127 )
+ p_sb->i_bitrate = 127; /* Buggy ? */
+ for( i = 0; i < p_sb->i_bitrate; i++ )
+ {
+ if( !ASF_HAVE(2 + 4) )
+ break;
+ p_sb->bitrate[i].i_stream_number = ASF_READ2()& 0x7f;
+ p_sb->bitrate[i].i_avg_bitrate = ASF_READ4();
+ }
+ p_sb->i_bitrate = i;
+
+#ifdef ASF_DEBUG
+ 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_sb->bitrate[i].i_stream_number,
+ p_sb->bitrate[i].i_avg_bitrate );
+ }
+#endif
+ return VLC_SUCCESS;
+}
+static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj)
+{
+ VLC_UNUSED(p_obj);
+}
+
+static int ASF_ReadObject_extended_stream_properties( stream_t *s,
+ asf_object_t *p_obj)
+{
+ asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
+ const uint8_t *p_peek, *p_data;
+ int i_peek, i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ p_esp->i_start_time = GetQWLE( &p_data[0] );
+ p_esp->i_end_time = GetQWLE( &p_data[8] );
+ p_esp->i_data_bitrate = GetDWLE( &p_data[16] );
+ p_esp->i_buffer_size = GetDWLE( &p_data[20] );
+ p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] );
+ p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] );
+ p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] );
+ p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] );
+ p_esp->i_maximum_object_size = GetDWLE( &p_data[40] );
+ p_esp->i_flags = GetDWLE( &p_data[44] );
+ p_esp->i_stream_number = GetWLE( &p_data[48] );
+ 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_extension_system_count = GetWLE( &p_data[62] );
+
+ p_data += 64;
+
+ p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count,
+ sizeof(int) );
+ p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
+ sizeof(char*) );
+ if( !p_esp->pi_stream_name_language ||
+ !p_esp->ppsz_stream_name )
+ {
+ free( p_esp->pi_stream_name_language );
+ free( p_esp->ppsz_stream_name );
+ return VLC_ENOMEM;
+ }
+ for( i = 0; i < p_esp->i_stream_name_count; i++ )
+ {
+ if( !ASF_HAVE( 2+2 ) )
+ break;
+ p_esp->pi_stream_name_language[i] = ASF_READ2();
+ p_esp->ppsz_stream_name[i] = ASF_READS( ASF_READ2() );
+ }
+ p_esp->i_stream_name_count = i;
+
+ for( i = 0; i < p_esp->i_payload_extension_system_count; i++ )
+ {
+ ASF_SKIP( 16 ); // GUID
+ ASF_SKIP( 2 );
+ ASF_SKIP( ASF_READ4() );
+ }
+
+ p_esp->p_sp = NULL;
+ if( p_data < &p_peek[i_peek] )
+ {
+ asf_object_t *p_sp;
+ /* Cannot fail as peek succeed */
+ stream_Read( s, NULL, p_data - p_peek );
+
+ p_sp = malloc( sizeof( asf_object_t ) );
+
+ if( !p_sp || ASF_ReadObject( s, p_sp, NULL ) )
+ {
+ free( p_sp );
+ }
+ else
+ {
+ /* This p_sp will be inserted by ReadRoot later */
+ 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, " - start=%"PRId64" end=%"PRId64,
+ p_esp->i_start_time, p_esp->i_end_time );
+ msg_Dbg( s, " - data bitrate=%d buffer=%d initial fullness=%d",
+ p_esp->i_data_bitrate,
+ p_esp->i_buffer_size,
+ p_esp->i_initial_buffer_fullness );
+ msg_Dbg( s, " - alternate data bitrate=%d buffer=%d initial fullness=%d",
+ p_esp->i_alternate_data_bitrate,
+ p_esp->i_alternate_buffer_size,
+ p_esp->i_alternate_initial_buffer_fullness );
+ msg_Dbg( s, " - maximum object size=%d", p_esp->i_maximum_object_size );
+ msg_Dbg( s, " - flags=0x%x", p_esp->i_flags );
+ msg_Dbg( s, " - stream number=%d language=%d",
+ p_esp->i_stream_number, p_esp->i_language_index );
+ msg_Dbg( s, " - average time per frame=%"PRId64,
+ p_esp->i_average_time_per_frame );
+ msg_Dbg( s, " - stream name count=%d", p_esp->i_stream_name_count );
+ for( i = 0; i < p_esp->i_stream_name_count; i++ )
+ 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 extension system count=%d",
+ p_esp->i_payload_extension_system_count );
+#endif
+ return VLC_SUCCESS;
+}
+static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
+{
+ asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
+ int i;
+
+ for( i = 0; i < p_esp->i_stream_name_count; i++ )
+ FREENULL( p_esp->ppsz_stream_name[i] );
+ FREENULL( p_esp->pi_stream_name_language );
+ FREENULL( p_esp->ppsz_stream_name );
+}
+
+
+static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
+ asf_object_t *p_obj)
+{
+ asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
+ const uint8_t *p_peek, *p_data;
+ int i_peek;
+ int i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_ae->i_object_size ) ) < 42 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ ASF_GetGUID( &p_ae->type, &p_data[0] );
+ ASF_SKIP( 16 );
+ p_ae->i_stream_number_count = ASF_READ2();
+ p_ae->pi_stream_number = calloc( p_ae->i_stream_number_count, sizeof(int) );
+
+ for( i = 0; i < p_ae->i_stream_number_count; i++ )
+ {
+ if( !ASF_HAVE(2) )
+ break;
+ p_ae->pi_stream_number[i] = ASF_READ2();
+ }
+ p_ae->i_stream_number_count = i;
+
+#ifdef ASF_DEBUG
+ 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
+ return VLC_SUCCESS;
+}
+static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
+{
+ asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
+
+ FREENULL( p_ae->pi_stream_number );
+}
+
+
+static int ASF_ReadObject_stream_prioritization( stream_t *s,
+ asf_object_t *p_obj)
+{
+ asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
+ const uint8_t *p_peek, *p_data;
+ int i_peek;
+ int i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 26 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ p_sp->i_priority_count = ASF_READ2();
+
+ p_sp->pi_priority_flag = calloc( p_sp->i_priority_count, sizeof(int) );
+ p_sp->pi_priority_stream_number =
+ calloc( p_sp->i_priority_count, sizeof(int) );
+
+ if( !p_sp->pi_priority_flag || !p_sp->pi_priority_stream_number )
+ {
+ free( p_sp->pi_priority_flag );
+ free( p_sp->pi_priority_stream_number );
+ return VLC_ENOMEM;
+ }
+
+ for( i = 0; i < p_sp->i_priority_count; i++ )
+ {
+ if( !ASF_HAVE(2+2) )
+ break;
+ p_sp->pi_priority_stream_number[i] = ASF_READ2();
+ p_sp->pi_priority_flag[i] = ASF_READ2();
+ }
+ p_sp->i_priority_count = i;
+
+#ifdef ASF_DEBUG
+ 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],
+ p_sp->pi_priority_flag[i] );
+#endif
+ return VLC_SUCCESS;
+}
+static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
+{
+ asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
+
+ FREENULL( p_sp->pi_priority_stream_number );
+ FREENULL( p_sp->pi_priority_flag );
+}
+
+
+static int ASF_ReadObject_extended_content_description( stream_t *s,
+ asf_object_t *p_obj)
+{
+ asf_object_extended_content_description_t *p_ec =
+ &p_obj->extended_content_description;
+ const uint8_t *p_peek, *p_data;
+ int i_peek;
+ int i;
+
+ if( ( i_peek = stream_Peek( s, &p_peek, p_ec->i_object_size ) ) < 26 )
+ return VLC_EGENERIC;
+
+ p_data = &p_peek[24];
+
+ p_ec->i_count = ASF_READ2();
+ p_ec->ppsz_name = calloc( p_ec->i_count, sizeof(char*) );
+ p_ec->ppsz_value = calloc( p_ec->i_count, sizeof(char*) );
+ if( !p_ec->ppsz_name || !p_ec->ppsz_value )
+ {
+ free( p_ec->ppsz_name );
+ free( p_ec->ppsz_value );
+ return VLC_ENOMEM;
+ }
+ for( i = 0; i < p_ec->i_count; i++ )
+ {
+ int i_size;
+ int i_type;
+
+ if( !ASF_HAVE(2 + 2+2) )
+ break;
+
+ p_ec->ppsz_name[i] = ASF_READS( ASF_READ2() );
+
+ /* Grrr */
+ i_type = ASF_READ2();
+ i_size = ASF_READ2();
+
+ if( i_type == 0 )
+ {
+ p_ec->ppsz_value[i] = ASF_READS( i_size );
+ }
+ else if( i_type == 1 )
+ {
+ /* Byte array */
+ static const char hex[16] = "0123456789ABCDEF";
+ int j;
+
+ p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
+ if( p_ec->ppsz_value[i] )
+ {
+ char *psz_value = p_ec->ppsz_value[i];
+ for( j = 0; j < i_size; j++ )
+ {
+ const uint8_t v = ASF_READ1();
+ psz_value[2*j+0] = hex[v>>4];
+ psz_value[2*j+1] = hex[v&0xf];
+ }
+ psz_value[2*i_size] = '\0';
+ }
+ }
+ else if( i_type == 2 )
+ {
+ /* Bool */
+ p_ec->ppsz_value[i] = strdup( ASF_READ1() ? "true" : "false" );
+ ASF_SKIP(i_size-1);
+ }
+ else if( i_type == 3 )
+ {
+ /* DWord */
+ if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
+ }
+ else if( i_type == 4 )
+ {
+ /* QWord */
+ if( asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
+ }
+ else if( i_type == 5 )
+ {
+ /* Word */
+ if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
+ }
+ else
+ {
+ p_ec->ppsz_value[i] = NULL;
+ ASF_SKIP(i_size);
+ }
+ }
+ p_ec->i_count = i;
+
+#ifdef ASF_DEBUG
+ 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],
+ p_ec->ppsz_value[i] );
+#endif
+ return VLC_SUCCESS;
+}
+static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
+{
+ asf_object_extended_content_description_t *p_ec =
+ &p_obj->extended_content_description;
+ int i;
+
+ for( i = 0; i < p_ec->i_count; i++ )
+ {
+ FREENULL( p_ec->ppsz_name[i] );
+ FREENULL( p_ec->ppsz_value[i] );
+ }
+ FREENULL( p_ec->ppsz_name );
+ FREENULL( p_ec->ppsz_value );