| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
#ifdef HAVE_CONFIG_H |
|---|
| 26 |
# include "config.h" |
|---|
| 27 |
#endif |
|---|
| 28 |
|
|---|
| 29 |
#include <vlc_common.h> |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_demux.h> |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_codecs.h> |
|---|
| 35 |
#include "libasf.h" |
|---|
| 36 |
|
|---|
| 37 |
#define ASF_DEBUG 1 |
|---|
| 38 |
|
|---|
| 39 |
#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" |
|---|
| 40 |
#define GUID_PRINT( guid ) \ |
|---|
| 41 |
(guid).v1, \ |
|---|
| 42 |
(guid).v2, \ |
|---|
| 43 |
(guid).v3, \ |
|---|
| 44 |
(guid).v4[0],(guid).v4[1],(guid).v4[2],(guid).v4[3], \ |
|---|
| 45 |
(guid).v4[4],(guid).v4[5],(guid).v4[6],(guid).v4[7] |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
static inline bool AsfObjectHelperHave( const uint8_t *p_peek, int i_peek, const uint8_t *p_current, int i_wanted ) |
|---|
| 58 |
{ |
|---|
| 59 |
if( i_wanted < 0 || i_wanted > i_peek ) |
|---|
| 60 |
return false; |
|---|
| 61 |
return &p_current[i_wanted] <= &p_peek[i_peek]; |
|---|
| 62 |
} |
|---|
| 63 |
#define ASF_HAVE(n) AsfObjectHelperHave( p_peek, i_peek, p_data, n ) |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
static inline void AsfObjectHelperSkip( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_wanted ) |
|---|
| 68 |
{ |
|---|
| 69 |
if( AsfObjectHelperHave( p_peek, i_peek, *pp_data, i_wanted ) ) |
|---|
| 70 |
*pp_data += i_wanted; |
|---|
| 71 |
else |
|---|
| 72 |
*pp_data = (uint8_t*)&p_peek[i_peek]; |
|---|
| 73 |
} |
|---|
| 74 |
#define ASF_SKIP(n) AsfObjectHelperSkip( p_peek, i_peek, (uint8_t**)&p_data, n ) |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
#define ASF_FUNCTION_READ_X(type, x, cmd ) \ |
|---|
| 79 |
static inline type AsfObjectHelperRead##x( const uint8_t *p_peek, int i_peek, uint8_t **pp_data ) { \ |
|---|
| 80 |
uint8_t *p_data = *pp_data; \ |
|---|
| 81 |
type i_ret = 0; \ |
|---|
| 82 |
if( ASF_HAVE(x) ) \ |
|---|
| 83 |
i_ret = cmd; \ |
|---|
| 84 |
ASF_SKIP(x); \ |
|---|
| 85 |
*pp_data = p_data; \ |
|---|
| 86 |
return i_ret; } |
|---|
| 87 |
ASF_FUNCTION_READ_X( uint8_t, 1, *p_data ) |
|---|
| 88 |
ASF_FUNCTION_READ_X( uint16_t, 2, GetWLE(p_data) ) |
|---|
| 89 |
ASF_FUNCTION_READ_X( uint32_t, 4, GetDWLE(p_data) ) |
|---|
| 90 |
ASF_FUNCTION_READ_X( uint64_t, 8, GetQWLE(p_data) ) |
|---|
| 91 |
#define ASF_READ1() AsfObjectHelperRead1( p_peek, i_peek, (uint8_t**)&p_data ) |
|---|
| 92 |
#define ASF_READ2() AsfObjectHelperRead2( p_peek, i_peek, (uint8_t**)&p_data ) |
|---|
| 93 |
#define ASF_READ4() AsfObjectHelperRead4( p_peek, i_peek, (uint8_t**)&p_data ) |
|---|
| 94 |
#define ASF_READ8() AsfObjectHelperRead8( p_peek, i_peek, (uint8_t**)&p_data ) |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
static char *AsfObjectHelperReadString( const uint8_t *p_peek, int i_peek, uint8_t **pp_data, int i_size ) |
|---|
| 100 |
{ |
|---|
| 101 |
uint8_t *p_data = *pp_data; |
|---|
| 102 |
char *psz_string; |
|---|
| 103 |
if( ASF_HAVE(i_size) ) |
|---|
| 104 |
{ |
|---|
| 105 |
psz_string = calloc( i_size/2 + 1, sizeof( char ) ); |
|---|
| 106 |
if( psz_string ) |
|---|
| 107 |
{ |
|---|
| 108 |
int i; |
|---|
| 109 |
for( i = 0; i < i_size/2; i++ ) |
|---|
| 110 |
psz_string[i] = GetWLE( &p_data[2*i] ); |
|---|
| 111 |
psz_string[i_size/2] = '\0'; \ |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
else |
|---|
| 115 |
{ |
|---|
| 116 |
psz_string = strdup(""); |
|---|
| 117 |
} |
|---|
| 118 |
ASF_SKIP(i_size); |
|---|
| 119 |
*pp_data = p_data; |
|---|
| 120 |
return psz_string; |
|---|
| 121 |
} |
|---|
| 122 |
#define ASF_READS(n) AsfObjectHelperReadString( p_peek, i_peek, (uint8_t**)&p_data, n ) |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
static int ASF_ReadObject( stream_t *, asf_object_t *, asf_object_t * ); |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data ) |
|---|
| 133 |
{ |
|---|
| 134 |
p_guid->v1 = GetDWLE( p_data ); |
|---|
| 135 |
p_guid->v2 = GetWLE( p_data + 4); |
|---|
| 136 |
p_guid->v3 = GetWLE( p_data + 6); |
|---|
| 137 |
memcpy( p_guid->v4, p_data + 8, 8 ); |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
bool ASF_CmpGUID( const guid_t *p_guid1, const guid_t *p_guid2 ) |
|---|
| 141 |
{ |
|---|
| 142 |
if( (p_guid1->v1 != p_guid2->v1 )|| |
|---|
| 143 |
(p_guid1->v2 != p_guid2->v2 )|| |
|---|
| 144 |
(p_guid1->v3 != p_guid2->v3 )|| |
|---|
| 145 |
( memcmp( p_guid1->v4, p_guid2->v4,8 )) ) |
|---|
| 146 |
{ |
|---|
| 147 |
return false; |
|---|
| 148 |
} |
|---|
| 149 |
return true; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj ) |
|---|
| 156 |
{ |
|---|
| 157 |
asf_object_common_t *p_common = &p_obj->common; |
|---|
| 158 |
const uint8_t *p_peek; |
|---|
| 159 |
|
|---|
| 160 |
if( stream_Peek( s, &p_peek, 24 ) < 24 ) |
|---|
| 161 |
return VLC_EGENERIC; |
|---|
| 162 |
|
|---|
| 163 |
ASF_GetGUID( &p_common->i_object_id, p_peek ); |
|---|
| 164 |
p_common->i_object_size = GetQWLE( p_peek + 16 ); |
|---|
| 165 |
p_common->i_object_pos = stream_Tell( s ); |
|---|
| 166 |
p_common->p_next = NULL; |
|---|
| 167 |
|
|---|
| 168 |
#ifdef ASF_DEBUG |
|---|
| 169 |
msg_Dbg( s, |
|---|
| 170 |
"found object guid: " GUID_FMT " size:%"PRId64, |
|---|
| 171 |
GUID_PRINT( p_common->i_object_id ), |
|---|
| 172 |
p_common->i_object_size ); |
|---|
| 173 |
#endif |
|---|
| 174 |
|
|---|
| 175 |
return VLC_SUCCESS; |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
static int ASF_NextObject( stream_t *s, asf_object_t *p_obj ) |
|---|
| 179 |
{ |
|---|
| 180 |
asf_object_t obj; |
|---|
| 181 |
if( p_obj == NULL ) |
|---|
| 182 |
{ |
|---|
| 183 |
if( ASF_ReadObjectCommon( s, &obj ) ) |
|---|
| 184 |
return VLC_EGENERIC; |
|---|
| 185 |
|
|---|
| 186 |
p_obj = &obj; |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
if( p_obj->common.i_object_size <= 0 ) |
|---|
| 190 |
return VLC_EGENERIC; |
|---|
| 191 |
|
|---|
| 192 |
if( p_obj->common.p_father && |
|---|
| 193 |
p_obj->common.p_father->common.i_object_size != 0 ) |
|---|
| 194 |
{ |
|---|
| 195 |
if( p_obj->common.p_father->common.i_object_pos + |
|---|
| 196 |
p_obj->common.p_father->common.i_object_size < |
|---|
| 197 |
p_obj->common.i_object_pos + p_obj->common.i_object_size + 24 ) |
|---|
| 198 |
|
|---|
| 199 |
{ |
|---|
| 200 |
return VLC_EGENERIC; |
|---|
| 201 |
} |
|---|
| 202 |
|
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
return stream_Seek( s, p_obj->common.i_object_pos + |
|---|
| 206 |
p_obj->common.i_object_size ); |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
static void ASF_FreeObject_Null( asf_object_t *pp_obj ) |
|---|
| 210 |
{ |
|---|
| 211 |
VLC_UNUSED(pp_obj); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj ) |
|---|
| 215 |
{ |
|---|
| 216 |
asf_object_header_t *p_hdr = &p_obj->header; |
|---|
| 217 |
asf_object_t *p_subobj; |
|---|
| 218 |
int i_peek; |
|---|
| 219 |
const uint8_t *p_peek; |
|---|
| 220 |
|
|---|
| 221 |
if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 ) |
|---|
| 222 |
return VLC_EGENERIC; |
|---|
| 223 |
|
|---|
| 224 |
p_hdr->i_sub_object_count = GetDWLE( p_peek + 24 ); |
|---|
| 225 |
p_hdr->i_reserved1 = p_peek[28]; |
|---|
| 226 |
p_hdr->i_reserved2 = p_peek[29]; |
|---|
| 227 |
p_hdr->p_first = NULL; |
|---|
| 228 |
p_hdr->p_last = NULL; |
|---|
| 229 |
|
|---|
| 230 |
#ifdef ASF_DEBUG |
|---|
| 231 |
msg_Dbg( s, |
|---|
| 232 |
"read \"header object\" subobj:%d, reserved1:%d, reserved2:%d", |
|---|
| 233 |
p_hdr->i_sub_object_count, |
|---|
| 234 |
p_hdr->i_reserved1, |
|---|
| 235 |
p_hdr->i_reserved2 ); |
|---|
| 236 |
#endif |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
stream_Read( s, NULL, 30 ); |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
for( ; ; ) |
|---|
| 243 |
{ |
|---|
| 244 |
p_subobj = malloc( sizeof( asf_object_t ) ); |
|---|
| 245 |
|
|---|
| 246 |
if( !p_subobj || ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) ) |
|---|
| 247 |
{ |
|---|
| 248 |
free( p_subobj ); |
|---|
| 249 |
break; |
|---|
| 250 |
} |
|---|
| 251 |
if( ASF_NextObject( s, p_subobj ) ) |
|---|
| 252 |
break; |
|---|
| 253 |
} |
|---|
| 254 |
return VLC_SUCCESS; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj ) |
|---|
| 258 |
{ |
|---|
| 259 |
asf_object_data_t *p_data = &p_obj->data; |
|---|
| 260 |
int i_peek; |
|---|
| 261 |
const uint8_t *p_peek; |
|---|
| 262 |
|
|---|
| 263 |
if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 ) |
|---|
| 264 |
return VLC_EGENERIC; |
|---|
| 265 |
|
|---|
| 266 |
ASF_GetGUID( &p_data->i_file_id, p_peek + 24 ); |
|---|
| 267 |
p_data->i_total_data_packets = GetQWLE( p_peek + 40 ); |
|---|
| 268 |
p_data->i_reserved = GetWLE( p_peek + 48 ); |
|---|
| 269 |
|
|---|
| 270 |
#ifdef ASF_DEBUG |
|---|
| 271 |
msg_Dbg( s, |
|---|
| 272 |
"read \"data object\" file_id:" GUID_FMT " total data packet:" |
|---|
| 273 |
"%"PRId64" reserved:%d", |
|---|
| 274 |
GUID_PRINT( p_data->i_file_id ), |
|---|
| 275 |
p_data->i_total_data_packets, |
|---|
| 276 |
p_data->i_reserved ); |
|---|
| 277 |
#endif |
|---|
| 278 |
|
|---|
| 279 |
return VLC_SUCCESS; |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj ) |
|---|
| 283 |
{ |
|---|
| 284 |
asf_object_index_t *p_index = &p_obj->index; |
|---|
| 285 |
const uint8_t *p_peek; |
|---|
| 286 |
unsigned int i; |
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
if( stream_Peek( s, &p_peek, p_index->i_object_size ) < |
|---|
| 290 |
__MAX( (int64_t)p_index->i_object_size, 56 ) ) |
|---|
| 291 |
return VLC_SUCCESS; |
|---|
| 292 |
|
|---|
| 293 |
ASF_GetGUID( &p_index->i_file_id, p_peek + 24 ); |
|---|
| 294 |
p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 ); |
|---|
| 295 |
p_index->i_max_packet_count = GetDWLE( p_peek + 48 ); |
|---|
| 296 |
p_index->i_index_entry_count = GetDWLE( p_peek + 52 ); |
|---|
| 297 |
p_index->index_entry = NULL; |
|---|
| 298 |
|
|---|
| 299 |
#ifdef ASF_DEBUG |
|---|
| 300 |
msg_Dbg( s, |
|---|
| 301 |
"read \"index object\" file_id:" GUID_FMT |
|---|
| 302 |
" index_entry_time_interval:%"PRId64" max_packet_count:%d " |
|---|
| 303 |
"index_entry_count:%ld", |
|---|
| 304 |
GUID_PRINT( p_index->i_file_id ), |
|---|
| 305 |
p_index->i_index_entry_time_interval, |
|---|
| 306 |
p_index->i_max_packet_count, |
|---|
| 307 |
(long int)p_index->i_index_entry_count ); |
|---|
| 308 |
#endif |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 ) |
|---|
| 312 |
p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6; |
|---|
| 313 |
|
|---|
| 314 |
p_index->index_entry = calloc( p_index->i_index_entry_count, |
|---|
| 315 |
sizeof(asf_index_entry_t) ); |
|---|
| 316 |
if( !p_index->index_entry ) |
|---|
| 317 |
return VLC_ENOMEM; |
|---|
| 318 |
|
|---|
| 319 |
for( i = 0, p_peek += 56; i < p_index->i_index_entry_count; i++, p_peek += 6 ) |
|---|
| 320 |
{ |
|---|
| 321 |
p_index->index_entry[i].i_packet_number = GetDWLE( p_peek ); |
|---|
| 322 |
p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 ); |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
return VLC_SUCCESS; |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
static void ASF_FreeObject_Index( asf_object_t *p_obj ) |
|---|
| 329 |
{ |
|---|
| 330 |
asf_object_index_t *p_index = &p_obj->index; |
|---|
| 331 |
|
|---|
| 332 |
FREENULL( p_index->index_entry ); |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj ) |
|---|
| 336 |
{ |
|---|
| 337 |
asf_object_file_properties_t *p_fp = &p_obj->file_properties; |
|---|
| 338 |
int i_peek; |
|---|
| 339 |
const uint8_t *p_peek; |
|---|
| 340 |
|
|---|
| 341 |
if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 ) |
|---|
| 342 |
return VLC_EGENERIC; |
|---|
| 343 |
|
|---|
| 344 |
ASF_GetGUID( &p_fp->i_file_id, p_peek + 24 ); |
|---|
| 345 |
p_fp->i_file_size = GetQWLE( p_peek + 40 ); |
|---|
| 346 |
p_fp->i_creation_date = GetQWLE( p_peek + 48 ); |
|---|
| 347 |
p_fp->i_data_packets_count = GetQWLE( p_peek + 56 ); |
|---|
| 348 |
p_fp->i_play_duration = GetQWLE( p_peek + 64 ); |
|---|
| 349 |
p_fp->i_send_duration = GetQWLE( p_peek + 72 ); |
|---|
| 350 |
p_fp->i_preroll = GetQWLE( p_peek + 80 ); |
|---|
| 351 |
p_fp->i_flags = GetDWLE( p_peek + 88 ); |
|---|
| 352 |
p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 ); |
|---|
| 353 |
p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 ); |
|---|
| 354 |
p_fp->i_max_bitrate = GetDWLE( p_peek + 100 ); |
|---|
| 355 |
|
|---|
| 356 |
#ifdef ASF_DEBUG |
|---|
| 357 |
msg_Dbg( s, |
|---|
| 358 |
"read \"file properties object\" file_id:" GUID_FMT |
|---|
| 359 |
" file_size:%"PRId64" creation_date:%"PRId64" data_packets_count:" |
|---|
| 360 |
"%"PRId64" play_duration:%"PRId64" send_duration:%"PRId64" preroll:%"PRId64 |
|---|
| 361 |
" flags:%d min_data_packet_size:%d " |
|---|
| 362 |
" max_data_packet_size:%d max_bitrate:%d", |
|---|
| 363 |
GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size, |
|---|
| 364 |
p_fp->i_creation_date, p_fp->i_data_packets_count, |
|---|
| 365 |
p_fp->i_play_duration, p_fp->i_send_duration, |
|---|
| 366 |
p_fp->i_preroll, p_fp->i_flags, |
|---|
| 367 |
p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size, |
|---|
| 368 |
p_fp->i_max_bitrate ); |
|---|
| 369 |
#endif |
|---|
| 370 |
|
|---|
| 371 |
return VLC_SUCCESS; |
|---|
| 372 |
} |
|---|
| 373 |
|
|---|
| 374 |
static void ASF_FreeObject_metadata( asf_object_t *p_obj ) |
|---|
| 375 |
{ |
|---|
| 376 |
asf_object_metadata_t *p_meta = &p_obj->metadata; |
|---|
| 377 |
unsigned int i; |
|---|
| 378 |
|
|---|
| 379 |
for( i = 0; i < p_meta->i_record_entries_count; i++ ) |
|---|
| 380 |
{ |
|---|
| 381 |
free( p_meta->record[i].psz_name ); |
|---|
| 382 |
free( p_meta->record[i].p_data ); |
|---|
| 383 |
} |
|---|
| 384 |
free( p_meta->record ); |
|---|
| 385 |
} |
|---|
| 386 |
|
|---|
| 387 |
static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj ) |
|---|
| 388 |
{ |
|---|
| 389 |
asf_object_metadata_t *p_meta = &p_obj->metadata; |
|---|
| 390 |
|
|---|
| 391 |
int i_peek; |
|---|
| 392 |
unsigned int i; |
|---|
| 393 |
const uint8_t *p_peek, *p_data; |
|---|
| 394 |
#ifdef ASF_DEBUG |
|---|
| 395 |
unsigned int j; |
|---|
| 396 |
#endif |
|---|
| 397 |
|
|---|
| 398 |
if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) < |
|---|
| 399 |
__MAX( (int64_t)p_meta->i_object_size, 26 ) ) |
|---|
| 400 |
return VLC_EGENERIC; |
|---|
| 401 |
|
|---|
| 402 |
p_meta->i_record_entries_count = GetWLE( p_peek + 24 ); |
|---|
| 403 |
|
|---|
| 404 |
p_data = p_peek + 26; |
|---|
| 405 |
|
|---|
| 406 |
p_meta->record = calloc( p_meta->i_record_entries_count, |
|---|
| 407 |
sizeof(asf_metadata_record_t) ); |
|---|
| 408 |
if( !p_meta->record ) |
|---|
| 409 |
return VLC_ENOMEM; |
|---|
| 410 |
|
|---|
| 411 |
for( i = 0; i < p_meta->i_record_entries_count; i++ ) |
|---|
| 412 |
{ |
|---|
| 413 |
asf_metadata_record_t *p_record = &p_meta->record[i]; |
|---|
| 414 |
int i_name; |
|---|
| 415 |
int i_data; |
|---|
| 416 |
|
|---|
| 417 |
if( !ASF_HAVE( 2+2+2+2+4 ) ) |
|---|
| 418 |
break; |
|---|
| 419 |
|
|---|
| 420 |
if( ASF_READ2() != 0 ) |
|---|
| 421 |
break; |
|---|
| 422 |
|
|---|
| 423 |
p_record->i_stream = ASF_READ2(); |
|---|
| 424 |
i_name = ASF_READ2(); |
|---|
| 425 |
p_record->i_type = ASF_READ2(); |
|---|
| 426 |
i_data = ASF_READ4(); |
|---|
| 427 |
|
|---|
| 428 |
if( !ASF_HAVE( i_name + i_data ) ) |
|---|
| 429 |
break; |
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
p_record->psz_name = ASF_READS( i_name ); |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
if( p_record->i_type == ASF_METADATA_TYPE_STRING ) |
|---|
| 436 |
{ |
|---|
| 437 |
p_record->p_data = ASF_READS( i_data ); |
|---|
| 438 |
p_record->i_data = i_data/2; |
|---|
| 439 |
} |
|---|
| 440 |
else if( p_record->i_type == ASF_METADATA_TYPE_BYTE ) |
|---|
| 441 |
{ |
|---|
| 442 |
p_record->p_data = malloc( i_data ); |
|---|
| 443 |
p_record->i_data = i_data; |
|---|
| 444 |
if( p_record->p_data && i_data > 0 ) |
|---|
| 445 |
memcpy( p_record->p_data, p_data, i_data ); |
|---|
| 446 |
|
|---|
| 447 |
p_data += i_data; |
|---|
| 448 |
} |
|---|
| 449 |
else if( p_record->i_type == ASF_METADATA_TYPE_QWORD ) |
|---|
| 450 |
{ |
|---|
| 451 |
p_record->i_val = ASF_READ8(); |
|---|
| 452 |
} |
|---|
| 453 |
else if( p_record->i_type == ASF_METADATA_TYPE_DWORD ) |
|---|
| 454 |
{ |
|---|
| 455 |
p_record->i_val = ASF_READ4(); |
|---|
| 456 |
} |
|---|
| 457 |
else if( p_record->i_type == ASF_METADATA_TYPE_WORD ) |
|---|
| 458 |
{ |
|---|
| 459 |
p_record->i_val = ASF_READ2(); |
|---|
| 460 |
} |
|---|
| 461 |
else if( p_record->i_type == ASF_METADATA_TYPE_BOOL ) |
|---|
| 462 |
{ |
|---|
| 463 |
p_record->i_val = ASF_READ2(); |
|---|
| 464 |
} |
|---|
| 465 |
else |
|---|
| 466 |
{ |
|---|
| 467 |
|
|---|
| 468 |
p_data += i_data; |
|---|
| 469 |
} |
|---|
| 470 |
} |
|---|
| 471 |
p_meta->i_record_entries_count = i; |
|---|
| 472 |
|
|---|
| 473 |
#ifdef ASF_DEBUG |
|---|
| 474 |
msg_Dbg( s, |
|---|
| 475 |
"read \"metadata object\" %d entries", |
|---|
| 476 |
p_meta->i_record_entries_count ); |
|---|
| 477 |
for( j = 0; j < p_meta->i_record_entries_count; j++ ) |
|---|
| 478 |
{ |
|---|
| 479 |
asf_metadata_record_t *p_rec = &p_meta->record[j]; |
|---|
| 480 |
|
|---|
| 481 |
if( p_rec->i_type == ASF_METADATA_TYPE_STRING ) |
|---|
| 482 |
msg_Dbg( s, " - %s=%s", |
|---|
| 483 |
p_rec->psz_name, p_rec->p_data ); |
|---|
| 484 |
else if( p_rec->i_type == ASF_METADATA_TYPE_BYTE ) |
|---|
| 485 |
msg_Dbg( s, " - %s (%i bytes)", |
|---|
| 486 |
p_rec->psz_name, p_rec->i_data ); |
|---|
| 487 |
else |
|---|
| 488 |
msg_Dbg( s, " - %s=%"PRId64, |
|---|
| 489 |
p_rec->psz_name, p_rec->i_val ); |
|---|
| 490 |
} |
|---|
| 491 |
#endif |
|---|
| 492 |
|
|---|
| 493 |
return VLC_SUCCESS; |
|---|
| 494 |
} |
|---|
| 495 |
|
|---|
| 496 |
static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj ) |
|---|
| 497 |
{ |
|---|
| 498 |
asf_object_header_extension_t *p_he = &p_obj->header_extension; |
|---|
| 499 |
int i_peek; |
|---|
| 500 |
const uint8_t *p_peek; |
|---|
| 501 |
|
|---|
| 502 |
if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46) |
|---|
| 503 |
{ |
|---|
| 504 |
return VLC_EGENERIC; |
|---|
| 505 |
} |
|---|
| 506 |
ASF_GetGUID( &p_he->i_reserved1, p_peek + 24 ); |
|---|
| 507 |
p_he->i_reserved2 = GetWLE( p_peek + 40 ); |
|---|
| 508 |
p_he->i_header_extension_size = GetDWLE( p_peek + 42 ); |
|---|
| 509 |
if( p_he->i_header_extension_size ) |
|---|
| 510 |
{ |
|---|
| 511 |
if( (unsigned int)(i_peek-46) < p_he->i_header_extension_size ) |
|---|
| 512 |
return VLC_EGENERIC; |
|---|
| 513 |
|
|---|
| 514 |
p_he->p_header_extension_data = |
|---|
| 515 |
malloc( p_he->i_header_extension_size ); |
|---|
| 516 |
if( !p_he->p_header_extension_data ) |
|---|
| 517 |
return VLC_ENOMEM; |
|---|
| 518 |
|
|---|
| 519 |
memcpy( p_he->p_header_extension_data, p_peek + 46, |
|---|
| 520 |
p_he->i_header_extension_size ); |
|---|
| 521 |
} |
|---|
| 522 |
else |
|---|
| 523 |
{ |
|---|
| 524 |
p_he->p_header_extension_data = NULL; |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
#ifdef ASF_DEBUG |
|---|
| 528 |
msg_Dbg( s, |
|---|
| 529 |
"read \"header extension object\" reserved1:" GUID_FMT |
|---|
| 530 |
" reserved2:%d header_extension_size:%d", |
|---|
| 531 |
GUID_PRINT( p_he->i_reserved1 ), p_he->i_reserved2, |
|---|
| 532 |
p_he->i_header_extension_size ); |
|---|
| 533 |
#endif |
|---|
| 534 |
|
|---|
| 535 |
if( !p_he->i_header_extension_size ) return VLC_SUCCESS; |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
stream_Read( s, NULL, 46 ); |
|---|
| 539 |
for( ; ; ) |
|---|
| 540 |
{ |
|---|
| 541 |
asf_object_t *p_obj = malloc( sizeof( asf_object_t ) ); |
|---|
| 542 |
|
|---|
| 543 |
if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) ) |
|---|
| 544 |
{ |
|---|
| 545 |
free( p_obj ); |
|---|
| 546 |
break; |
|---|
| 547 |
} |
|---|
| 548 |
|
|---|
| 549 |
if( ASF_NextObject( s, p_obj ) ) |
|---|
| 550 |
{ |
|---|
| 551 |
break; |
|---|
| 552 |
} |
|---|
| 553 |
} |
|---|
| 554 |
|
|---|
| 555 |
return VLC_SUCCESS; |
|---|
| 556 |
} |
|---|
| 557 |
|
|---|
| 558 |
static void ASF_FreeObject_header_extension( asf_object_t *p_obj ) |
|---|
| 559 |
{ |
|---|
| 560 |
asf_object_header_extension_t *p_he = &p_obj->header_extension; |
|---|
| 561 |
|
|---|
| 562 |
FREENULL( p_he->p_header_extension_data ); |
|---|
| 563 |
} |
|---|
| 564 |
|
|---|
| 565 |
static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj ) |
|---|
| 566 |
{ |
|---|
| 567 |
asf_object_stream_properties_t *p_sp = &p_obj->stream_properties; |
|---|
| 568 |
size_t i_peek; |
|---|
| 569 |
const uint8_t *p_peek; |
|---|
| 570 |
|
|---|
| 571 |
if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 ) |
|---|
| 572 |
return VLC_EGENERIC; |
|---|
| 573 |
|
|---|
| 574 |
ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 ); |
|---|
| 575 |
ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 ); |
|---|
| 576 |
p_sp->i_time_offset = GetQWLE( p_peek + 56 ); |
|---|
| 577 |
p_sp->i_type_specific_data_length = GetDWLE( p_peek + 64 ); |
|---|
| 578 |
p_sp->i_error_correction_data_length = GetDWLE( p_peek + 68 ); |
|---|
| 579 |
p_sp->i_flags = GetWLE( p_peek + 72 ); |
|---|
| 580 |
p_sp->i_stream_number = p_sp->i_flags&0x07f; |
|---|
| 581 |
p_sp->i_reserved = GetDWLE( p_peek + 74 ); |
|---|
| 582 |
i_peek -= 78; |
|---|
| 583 |
|
|---|
| 584 |
if( p_sp->i_type_specific_data_length ) |
|---|
| 585 |
{ |
|---|
| 586 |
if( i_peek < p_sp->i_type_specific_data_length ) |
|---|
| 587 |
return VLC_EGENERIC; |
|---|
| 588 |
|
|---|
| 589 |
p_sp->p_type_specific_data = |
|---|
| 590 |
malloc( p_sp->i_type_specific_data_length ); |
|---|
| 591 |
if( !p_sp->p_type_specific_data ) |
|---|
| 592 |
return VLC_ENOMEM; |
|---|
| 593 |
|
|---|
| 594 |
memcpy( p_sp->p_type_specific_data, p_peek + 78, |
|---|
| 595 |
p_sp->i_type_specific_data_length ); |
|---|
| 596 |
i_peek -= p_sp->i_type_specific_data_length; |
|---|
| 597 |
} |
|---|
| 598 |
|
|---|
| 599 |
if( p_sp->i_error_correction_data_length ) |
|---|
| 600 |
{ |
|---|
| 601 |
if( i_peek < p_sp->i_error_correction_data_length ) |
|---|
| 602 |
{ |
|---|
| 603 |
free( p_sp->p_type_specific_data ); |
|---|
| 604 |
return VLC_EGENERIC; |
|---|
| 605 |
} |
|---|
| 606 |
|
|---|
| 607 |
p_sp->p_error_correction_data = |
|---|
| 608 |
malloc( p_sp->i_error_correction_data_length ); |
|---|
| 609 |
if( !p_sp->p_error_correction_data ) |
|---|
| 610 |
{ |
|---|
| 611 |
free( p_sp->p_type_specific_data ); |
|---|
| 612 |
return VLC_ENOMEM; |
|---|
| 613 |
} |
|---|
| 614 |
memcpy( p_sp->p_error_correction_data, |
|---|
| 615 |
p_peek + 78 + p_sp->i_type_specific_data_length, |
|---|
| 616 |
p_sp->i_error_correction_data_length ); |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
#ifdef ASF_DEBUG |
|---|
| 620 |
msg_Dbg( s, |
|---|
| 621 |
"read \"stream Properties object\" stream_type:" GUID_FMT |
|---|
| 622 |
" error_correction_type:" GUID_FMT " time_offset:%"PRId64 |
|---|
| 623 |
" type_specific_data_length:%d error_correction_data_length:%d" |
|---|
| 624 |
" flags:0x%x stream_number:%d", |
|---|
| 625 |
GUID_PRINT( p_sp->i_stream_type ), |
|---|
| 626 |
GUID_PRINT( p_sp->i_error_correction_type ), |
|---|
| 627 |
p_sp->i_time_offset, |
|---|
| 628 |
p_sp->i_type_specific_data_length, |
|---|
| 629 |
p_sp->i_error_correction_data_length, |
|---|
| 630 |
p_sp->i_flags, |
|---|
| 631 |
p_sp->i_stream_number ); |
|---|
| 632 |
|
|---|
| 633 |
#endif |
|---|
| 634 |
return VLC_SUCCESS; |
|---|
| 635 |
} |
|---|
| 636 |
|
|---|
| 637 |
static void ASF_FreeObject_stream_properties( asf_object_t *p_obj ) |
|---|
| 638 |
{ |
|---|
| 639 |
asf_object_stream_properties_t *p_sp = &p_obj->stream_properties; |
|---|
| 640 |
|
|---|
| 641 |
FREENULL( p_sp->p_type_specific_data ); |
|---|
| 642 |
FREENULL( p_sp->p_error_correction_data ); |
|---|
| 643 |
} |
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 |
static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj ) |
|---|
| 647 |
{ |
|---|
| 648 |
asf_object_codec_list_t *p_cl = &p_obj->codec_list; |
|---|
| 649 |
int i_peek; |
|---|
| 650 |
const uint8_t *p_peek, *p_data; |
|---|
| 651 |
|
|---|
| 652 |
unsigned int i_codec; |
|---|
| 653 |
|
|---|
| 654 |
if( ( i_peek = stream_Peek( s, &p_peek, p_cl->i_object_size ) ) < 44 ) |
|---|
| 655 |
return VLC_EGENERIC; |
|---|
| 656 |
|
|---|
| 657 |
ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 ); |
|---|
| 658 |
p_cl->i_codec_entries_count = GetWLE( p_peek + 40 ); |
|---|
| 659 |
|
|---|
| 660 |
p_data = p_peek + 44; |
|---|
| 661 |
|
|---|
| 662 |
if( p_cl->i_codec_entries_count > 0 ) |
|---|
| 663 |
{ |
|---|
| 664 |
p_cl->codec = calloc( p_cl->i_codec_entries_count, |
|---|
| 665 |
sizeof( asf_codec_entry_t ) ); |
|---|
| 666 |
if( !p_cl->codec ) |
|---|
| 667 |
return VLC_ENOMEM; |
|---|
| 668 |
|
|---|
| 669 |
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) |
|---|
| 670 |
{ |
|---|
| 671 |
asf_codec_entry_t *p_codec = &p_cl->codec[i_codec]; |
|---|
| 672 |
|
|---|
| 673 |
if( !ASF_HAVE( 2+2+2 ) ) |
|---|
| 674 |
break; |
|---|
| 675 |
|
|---|
| 676 |
|
|---|
| 677 |
p_codec->i_type = ASF_READ2(); |
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 |
|
|---|
| 683 |
p_codec->psz_name = ASF_READS( 2*ASF_READ2() ); |
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 |
p_codec->psz_description = ASF_READS( 2*ASF_READ2() ); |
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
p_codec->i_information_length = ASF_READ2(); |
|---|
| 690 |
if( p_codec->i_information_length > 0 && ASF_HAVE( p_codec->i_information_length ) ) |
|---|
| 691 |
{ |
|---|
| 692 |
p_codec->p_information = malloc( p_codec->i_information_length ); |
|---|
| 693 |
if( p_codec->p_information ) |
|---|
| 694 |
memcpy( p_codec->p_information, p_data, p_codec->i_information_length ); |
|---|
| 695 |
else |
|---|
| 696 |
p_codec->i_information_length = 0; |
|---|
| 697 |
p_data += p_codec->i_information_length; |
|---|
| 698 |
} |
|---|
| 699 |
} |
|---|
| 700 |
p_cl->i_codec_entries_count = i_codec; |
|---|
| 701 |
} |
|---|
| 702 |
|
|---|
| 703 |
#ifdef ASF_DEBUG |
|---|
| 704 |
msg_Dbg( s, "read \"codec list object\" reserved_guid:" GUID_FMT |
|---|
| 705 |
" codec_entries_count:%d", |
|---|
| 706 |
GUID_PRINT( p_cl->i_reserved ), p_cl->i_codec_entries_count ); |
|---|
| 707 |
|
|---|
| 708 |
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) |
|---|
| 709 |
{ |
|---|
| 710 |
const asf_codec_entry_t *p_codec = &p_cl->codec[i_codec]; |
|---|
| 711 |
|
|---|
| 712 |
msg_Dbg( s, " - codec[%d] %s name:\"%s\" " |
|---|
| 713 |
"description:\"%s\" information_length:%d", |
|---|
| 714 |
i_codec, ( p_codec->i_type == ASF_CODEC_TYPE_VIDEO ) ? |
|---|
| 715 |
"video" : ( ( p_codec->i_type == ASF_CODEC_TYPE_AUDIO ) ? |
|---|
| 716 |
"audio" : "unknown" ), |
|---|
| 717 |
p_codec->psz_name, p_codec->psz_description, |
|---|
| 718 |
p_codec->i_information_length ); |
|---|
| 719 |
} |
|---|
| 720 |
#endif |
|---|
| 721 |
|
|---|
| 722 |
return VLC_SUCCESS; |
|---|
| 723 |
} |
|---|
| 724 |
|
|---|
| 725 |
static void ASF_FreeObject_codec_list( asf_object_t *p_obj ) |
|---|
| 726 |
{ |
|---|
| 727 |
asf_object_codec_list_t *p_cl = &p_obj->codec_list; |
|---|
| 728 |
unsigned int i_codec; |
|---|
| 729 |
|
|---|
| 730 |
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) |
|---|
| 731 |
{ |
|---|
| 732 |
asf_codec_entry_t *p_codec = &p_cl->codec[i_codec]; |
|---|
| 733 |
|
|---|
| 734 |
FREENULL( p_codec->psz_name ); |
|---|
| 735 |
FREENULL( p_codec->psz_description ); |
|---|
| 736 |
FREENULL( p_codec->p_information ); |
|---|
| 737 |
} |
|---|
| 738 |
FREENULL( p_cl->codec ); |
|---|
| 739 |
} |
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj) |
|---|
| 744 |
{ |
|---|
| 745 |
asf_object_content_description_t *p_cd = &p_obj->content_description; |
|---|
| 746 |
const uint8_t *p_peek, *p_data; |
|---|
| 747 |
int i_peek, i_title, i_artist, i_copyright, i_description, i_rating; |
|---|
| 748 |
vlc_iconv_t cd = (vlc_iconv_t)-1; |
|---|
| 749 |
const char *ib = NULL; |
|---|
| 750 |
char *ob = NULL; |
|---|
| 751 |
size_t i_ibl, i_obl, i_len; |
|---|
| 752 |
|
|---|
| 753 |
if( ( i_peek = stream_Peek( s, &p_peek, p_cd->i_object_size ) ) < 34 ) |
|---|
| 754 |
return VLC_EGENERIC; |
|---|
| 755 |
|
|---|
| 756 |
cd = vlc_iconv_open("UTF-8", "UTF-16LE"); |
|---|
| 757 |
if( cd == (vlc_iconv_t)-1 ) |
|---|
| 758 |
{ |
|---|
| 759 |
msg_Err( s, "vlc_iconv_open failed" ); |
|---|
| 760 |
return VLC_EGENERIC; |
|---|
| 761 |
} |
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
#define GETSTRINGW( psz_str, i_size ) do { \ |
|---|
| 765 |
psz_str = calloc( i_size*3+1, sizeof(char) ); \ |
|---|
| 766 |
if( psz_str ) { \ |
|---|
| 767 |
ib = (const char *)p_data; \ |
|---|
| 768 |
ob = psz_str; \ |
|---|
| 769 |
i_ibl = i_size; \ |
|---|
| 770 |
i_obl = i_size*3; \ |
|---|
| 771 |
i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \ |
|---|
| 772 |
p_data += i_size; \ |
|---|
| 773 |
} } while(0) |
|---|
| 774 |
|
|---|
| 775 |
p_data = p_peek + 24; |
|---|
| 776 |
|
|---|
| 777 |
i_title = ASF_READ2(); |
|---|
| 778 |
i_artist = ASF_READ2(); |
|---|
| 779 |
i_copyright = ASF_READ2(); |
|---|
| 780 |
i_description = ASF_READ2(); |
|---|
| 781 |
i_rating = ASF_READ2(); |
|---|
| 782 |
|
|---|
| 783 |
if( !ASF_HAVE( i_title+i_artist+i_copyright+i_description+i_rating ) ) |
|---|
| 784 |
{ |
|---|
| 785 |
vlc_iconv_close( cd ); |
|---|
| 786 |
return VLC_EGENERIC; |
|---|
| 787 |
} |
|---|
| 788 |
|
|---|
| 789 |
GETSTRINGW( p_cd->psz_title, i_title ); |
|---|
| 790 |
GETSTRINGW( p_cd->psz_artist, i_artist ); |
|---|
| 791 |
GETSTRINGW( p_cd->psz_copyright, i_copyright ); |
|---|
| 792 |
GETSTRINGW( p_cd->psz_description, i_description ); |
|---|
| 793 |
GETSTRINGW( p_cd->psz_rating, i_rating ); |
|---|
| 794 |
|
|---|
| 795 |
#undef GETSTRINGW |
|---|
| 796 |
|
|---|
| 797 |
#ifdef ASF_DEBUG |
|---|
| 798 |
msg_Dbg( s, |
|---|
| 799 |
"read \"content description object\" title:\"%s\" artist:\"%s\" copyright:\"%s\" description:\"%s\" rating:\"%s\"", |
|---|
| 800 |
p_cd->psz_title, |
|---|
| 801 |
p_cd->psz_artist, |
|---|
| 802 |
p_cd->psz_copyright, |
|---|
| 803 |
p_cd->psz_description, |
|---|
| 804 |
p_cd->psz_rating ); |
|---|
| 805 |
#endif |
|---|
| 806 |
|
|---|
| 807 |
vlc_iconv_close(cd); |
|---|
| 808 |
return VLC_SUCCESS; |
|---|
| 809 |
} |
|---|
| 810 |
|
|---|
| 811 |
static void ASF_FreeObject_content_description( asf_object_t *p_obj) |
|---|
| 812 |
{ |
|---|
| 813 |
asf_object_content_description_t *p_cd = &p_obj->content_description; |
|---|
| 814 |
|
|---|
| 815 |
FREENULL( p_cd->psz_title ); |
|---|
| 816 |
FREENULL( p_cd->psz_artist ); |
|---|
| 817 |
FREENULL( p_cd->psz_copyright ); |
|---|
| 818 |
FREENULL( p_cd->psz_description ); |
|---|
| 819 |
FREENULL( p_cd->psz_rating ); |
|---|
| 820 |
} |
|---|
| 821 |
|
|---|
| 822 |
|
|---|
| 823 |
static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj) |
|---|
| 824 |
{ |
|---|
| 825 |
asf_object_language_list_t *p_ll = &p_obj->language_list; |
|---|
| 826 |
const uint8_t *p_peek, *p_data; |
|---|
| 827 |
int i_peek; |
|---|
| 828 |
int i; |
|---|
| 829 |
|
|---|
| 830 |
if( ( i_peek = stream_Peek( s, &p_peek, p_ll->i_object_size ) ) < 26 ) |
|---|
| 831 |
return VLC_EGENERIC; |
|---|
| 832 |
|
|---|
| 833 |
p_data = &p_peek[24]; |
|---|
| 834 |
|
|---|
| 835 |
p_ll->i_language = ASF_READ2(); |
|---|
| 836 |
if( p_ll->i_language > 0 ) |
|---|
| 837 |
{ |
|---|
| 838 |
p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) ); |
|---|
| 839 |
if( !p_ll->ppsz_language ) |
|---|
| 840 |
return VLC_ENOMEM; |
|---|
| 841 |
|
|---|
| 842 |
for( i = 0; i < p_ll->i_language; i++ ) |
|---|
| 843 |
{ |
|---|
| 844 |
if( !ASF_HAVE(1) ) |
|---|
| 845 |
break; |
|---|
| 846 |
p_ll->ppsz_language[i] = ASF_READS( ASF_READ1() ); |
|---|
| 847 |
} |
|---|
| 848 |
p_ll->i_language = i; |
|---|
| 849 |
} |
|---|
| 850 |
|
|---|
| 851 |
#ifdef ASF_DEBUG |
|---|
| 852 |
msg_Dbg( s, "read \"language list object\" %d entries", |
|---|
| 853 |
p_ll->i_language ); |
|---|
| 854 |
for( i = 0; i < p_ll->i_language; i++ ) |
|---|
| 855 |
msg_Dbg( s, " - '%s'", |
|---|
| 856 |
p_ll->ppsz_language[i] ); |
|---|
| 857 |
#endif |
|---|
| 858 |
return VLC_SUCCESS; |
|---|
| 859 |
} |
|---|
| 860 |
|
|---|
| 861 |
static void ASF_FreeObject_language_list( asf_object_t *p_obj) |
|---|
| 862 |
{ |
|---|
| 863 |
asf_object_language_list_t *p_ll = &p_obj->language_list; |
|---|
| 864 |
int i; |
|---|
| 865 |
|
|---|
| 866 |
for( i = 0; i < p_ll->i_language; i++ ) |
|---|
| 867 |
FREENULL( p_ll->ppsz_language[i] ); |
|---|
| 868 |
FREENULL( p_ll->ppsz_language ); |
|---|
| 869 |
} |
|---|
| 870 |
|
|---|
| 871 |
|
|---|
| 872 |
static int ASF_ReadObject_stream_bitrate_properties( stream_t *s, |
|---|
| 873 |
asf_object_t *p_obj) |
|---|
| 874 |
{ |
|---|
| 875 |
asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate; |
|---|
| 876 |
const uint8_t *p_peek, *p_data; |
|---|
| 877 |
int i_peek; |
|---|
| 878 |
int i; |
|---|
| 879 |
|
|---|
| 880 |
if( ( i_peek = stream_Peek( s, &p_peek, p_sb->i_object_size ) ) < 26 ) |
|---|
| 881 |
return VLC_EGENERIC; |
|---|
| 882 |
|
|---|
| 883 |
p_data = &p_peek[24]; |
|---|
| 884 |
|
|---|
| 885 |
p_sb->i_bitrate = ASF_READ2(); |
|---|
| 886 |
if( p_sb->i_bitrate > 127 ) |
|---|
| 887 |
p_sb->i_bitrate = 127; |
|---|
| 888 |
for( i = 0; i < p_sb->i_bitrate; i++ ) |
|---|
| 889 |
{ |
|---|
| 890 |
if( !ASF_HAVE(2 + 4) ) |
|---|
| 891 |
break; |
|---|
| 892 |
p_sb->bitrate[i].i_stream_number = ASF_READ2()& 0x7f; |
|---|
| 893 |
p_sb->bitrate[i].i_avg_bitrate = ASF_READ4(); |
|---|
| 894 |
} |
|---|
| 895 |
p_sb->i_bitrate = i; |
|---|
| 896 |
|
|---|
| 897 |
#ifdef ASF_DEBUG |
|---|
| 898 |
msg_Dbg( s,"read \"stream bitrate properties object\"" ); |
|---|
| 899 |
for( i = 0; i < p_sb->i_bitrate; i++ ) |
|---|
| 900 |
{ |
|---|
| 901 |
msg_Dbg( s," - stream=%d bitrate=%d", |
|---|
| 902 |
p_sb->bitrate[i].i_stream_number, |
|---|
| 903 |
p_sb->bitrate[i].i_avg_bitrate ); |
|---|
| 904 |
} |
|---|
| 905 |
#endif |
|---|
| 906 |
return VLC_SUCCESS; |
|---|
| 907 |
} |
|---|
| 908 |
static void ASF_FreeObject_stream_bitrate_properties( asf_object_t *p_obj) |
|---|
| 909 |
{ |
|---|
| 910 |
VLC_UNUSED(p_obj); |
|---|
| 911 |
} |
|---|
| 912 |
|
|---|
| 913 |
static int ASF_ReadObject_extended_stream_properties( stream_t *s, |
|---|
| 914 |
asf_object_t *p_obj) |
|---|
| 915 |
{ |
|---|
| 916 |
asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream; |
|---|
| 917 |
const uint8_t *p_peek, *p_data; |
|---|
| 918 |
int i_peek, i; |
|---|
| 919 |
|
|---|
| 920 |
if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 ) |
|---|
| 921 |
return VLC_EGENERIC; |
|---|
| 922 |
|
|---|
| 923 |
p_data = &p_peek[24]; |
|---|
| 924 |
|
|---|
| 925 |
p_esp->i_start_time = GetQWLE( &p_data[0] ); |
|---|
| 926 |
p_esp->i_end_time = GetQWLE( &p_data[8] ); |
|---|
| 927 |
p_esp->i_data_bitrate = GetDWLE( &p_data[16] ); |
|---|
| 928 |
p_esp->i_buffer_size = GetDWLE( &p_data[20] ); |
|---|
| 929 |
p_esp->i_initial_buffer_fullness = GetDWLE( &p_data[24] ); |
|---|
| 930 |
p_esp->i_alternate_data_bitrate = GetDWLE( &p_data[28] ); |
|---|
| 931 |
p_esp->i_alternate_buffer_size = GetDWLE( &p_data[32] ); |
|---|
| 932 |
p_esp->i_alternate_initial_buffer_fullness = GetDWLE( &p_data[36] ); |
|---|
| 933 |
p_esp->i_maximum_object_size = GetDWLE( &p_data[40] ); |
|---|
| 934 |
p_esp->i_flags = GetDWLE( &p_data[44] ); |
|---|
| 935 |
p_esp->i_stream_number = GetWLE( &p_data[48] ); |
|---|
| 936 |
p_esp->i_language_index = GetWLE( &p_data[50] ); |
|---|
| 937 |
p_esp->i_average_time_per_frame= GetQWLE( &p_data[52] ); |
|---|
| 938 |
p_esp->i_stream_name_count = GetWLE( &p_data[60] ); |
|---|
| 939 |
p_esp->i_payload_extension_system_count = GetWLE( &p_data[62] ); |
|---|
| 940 |
|
|---|
| 941 |
p_data += 64; |
|---|
| 942 |
|
|---|
| 943 |
p_esp->pi_stream_name_language = calloc( p_esp->i_stream_name_count, |
|---|
| 944 |
sizeof(int) ); |
|---|
| 945 |
p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count, |
|---|
| 946 |
sizeof(char*) ); |
|---|
| 947 |
if( !p_esp->pi_stream_name_language || |
|---|
| 948 |
!p_esp->ppsz_stream_name ) |
|---|
| 949 |
{ |
|---|
| 950 |
free( p_esp->pi_stream_name_language ); |
|---|
| 951 |
free( p_esp->ppsz_stream_name ); |
|---|
| 952 |
return VLC_ENOMEM; |
|---|
| 953 |
} |
|---|
| 954 |
for( i = 0; i < p_esp->i_stream_name_count; i++ ) |
|---|
| 955 |
{ |
|---|
| 956 |
if( !ASF_HAVE( 2+2 ) ) |
|---|
| 957 |
|
|---|