Revision 30e88789

View differences:

libavformat/asf.c
67 67
    else PRINT_IF_GUID(g, extended_content_header);
68 68
    else PRINT_IF_GUID(g, ext_stream_embed_stream_header);
69 69
    else PRINT_IF_GUID(g, ext_stream_audio_stream);
70
    else PRINT_IF_GUID(g, metadata_header);
70 71
    else
71 72
        printf("(GUID: unknown) ");
72 73
    for(i=0;i<16;i++)
......
123 124
        return 0;
124 125
}
125 126

  
127
static int get_value(ByteIOContext *pb, int type){
128
    switch(type){
129
        case 2: return get_le32(pb);
130
        case 3: return get_le32(pb);
131
        case 4: return get_le64(pb);
132
        case 5: return get_le16(pb);
133
        default:return INT_MIN;
134
    }
135
}
136

  
126 137
static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
127 138
{
128 139
    ASFContext *asf = s->priv_data;
......
132 143
    ASFStream *asf_st;
133 144
    int size, i;
134 145
    int64_t gsize;
146
    AVRational dar[128];
147

  
148
    memset(dar, 0, sizeof(dar));
135 149

  
136 150
    get_guid(pb, &g);
137 151
    if (memcmp(&g, &asf_header, sizeof(GUID)))
......
353 367
                        }
354 368
                        if ((value_type >= 2) && (value_type <= 5)) // boolean or DWORD or QWORD or WORD
355 369
                        {
356
                                if (value_type==2) value_num = get_le32(pb);
357
                                if (value_type==3) value_num = get_le32(pb);
358
                                if (value_type==4) value_num = get_le64(pb);
359
                                if (value_type==5) value_num = get_le16(pb);
370
                                value_num= get_value(pb, value_type);
360 371
                                if (!strcmp(name,"WM/Track"      )) s->track = value_num + 1;
361 372
                                if (!strcmp(name,"WM/TrackNumber")) s->track = value_num;
362 373
                        }
363 374
                }
375
        } else if (!memcmp(&g, &metadata_header, sizeof(GUID))) {
376
            int n, stream_num, name_len, value_len, value_type, value_num;
377
            n = get_le16(pb);
378

  
379
            for(i=0;i<n;i++) {
380
                char name[1024];
381

  
382
                get_le16(pb); //lang_list_index
383
                stream_num= get_le16(pb);
384
                name_len=   get_le16(pb);
385
                value_type= get_le16(pb);
386
                value_len=  get_le32(pb);
387

  
388
                get_str16_nolen(pb, name_len, name, sizeof(name));
389
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
390
                value_num= get_le16(pb);//we should use get_value() here but it doesnt work 2 is le16 here but le32 elsewhere
391
                url_fskip(pb, value_len - 2);
392

  
393
                if(stream_num<128){
394
                    if     (!strcmp(name, "AspectRatioX")) dar[stream_num].num= value_num;
395
                    else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num;
396
                }
397
            }
364 398
        } else if (!memcmp(&g, &ext_stream_header, sizeof(GUID))) {
365 399
            int ext_len, payload_ext_ct, stream_ct;
366 400
            uint32_t ext_d;
......
443 477
    asf->data_offset = url_ftell(pb);
444 478
    asf->packet_size_left = 0;
445 479

  
480

  
481
    for(i=0; i<128; i++){
482
        int stream_num= asf->asfid2avid[i];
483
        if(stream_num>=0 && dar[i].num>0 && dar[i].den>0){
484
            AVCodecContext *codec= s->streams[stream_num]->codec;
485
            codec->sample_aspect_ratio=
486
                av_div_q(
487
                    dar[i],
488
                    (AVRational){codec->width, codec->height}
489
                );
490
//av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den);
491
        }
492
    }
493

  
446 494
    return 0;
447 495

  
448 496
 fail:
libavformat/asf.h
208 208
        0x9d, 0x8c, 0x17, 0x31, 0xE1, 0x03, 0x28, 0x45, 0xb5, 0x82, 0x3d, 0xf9, 0xdb, 0x22, 0xf5, 0x03
209 209
};
210 210

  
211
static const GUID metadata_header = {
212
        0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca
213
};
214

  
211 215
/* I am not a number !!! This GUID is the one found on the PC used to
212 216
   generate the stream */
213 217
static const GUID my_guid = {

Also available in: Unified diff