~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/asf.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include "mpegaudio.h"
24
24
#include "asf.h"
25
25
#include "common.h"
 
26
#include "asfcrypt.h"
 
27
 
 
28
extern void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format);
26
29
 
27
30
#undef NDEBUG
28
31
#include <assert.h>
84
87
static void get_guid(ByteIOContext *s, GUID *g)
85
88
{
86
89
    assert(sizeof(*g) == 16);
87
 
    get_buffer(s, g, sizeof(*g));
 
90
    get_buffer(s, *g, sizeof(*g));
88
91
}
89
92
 
90
93
#if 0
119
122
static int asf_probe(AVProbeData *pd)
120
123
{
121
124
    /* check file header */
122
 
    if (pd->buf_size <= 32)
123
 
        return 0;
124
 
 
125
125
    if (!memcmp(pd->buf, &asf_header, sizeof(GUID)))
126
126
        return AVPROBE_SCORE_MAX;
127
127
    else
142
142
{
143
143
    ASFContext *asf = s->priv_data;
144
144
    GUID g;
145
 
    ByteIOContext *pb = &s->pb;
 
145
    ByteIOContext *pb = s->pb;
146
146
    AVStream *st;
147
147
    ASFStream *asf_st;
148
148
    int size, i;
149
149
    int64_t gsize;
150
150
    AVRational dar[128];
 
151
    uint32_t bitrate[128];
151
152
 
152
153
    memset(dar, 0, sizeof(dar));
 
154
    memset(bitrate, 0, sizeof(bitrate));
153
155
 
154
156
    get_guid(pb, &g);
155
157
    if (memcmp(&g, &asf_header, sizeof(GUID)))
167
169
        print_guid(&g);
168
170
        printf("  size=0x%"PRIx64"\n", gsize);
169
171
#endif
 
172
        if (!memcmp(&g, &data_header, sizeof(GUID))) {
 
173
            asf->data_object_offset = url_ftell(pb);
 
174
            // if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
 
175
            if (!(asf->hdr.flags & 0x01) && gsize >= 100) {
 
176
                asf->data_object_size = gsize - 24;
 
177
            } else {
 
178
                asf->data_object_size = (uint64_t)-1;
 
179
            }
 
180
            break;
 
181
        }
170
182
        if (gsize < 24)
171
183
            goto fail;
172
184
        if (!memcmp(&g, &file_header, sizeof(GUID))) {
174
186
            asf->hdr.file_size          = get_le64(pb);
175
187
            asf->hdr.create_time        = get_le64(pb);
176
188
            asf->nb_packets             = get_le64(pb);
 
189
            asf->hdr.play_time          = get_le64(pb);
177
190
            asf->hdr.send_time          = get_le64(pb);
178
 
            asf->hdr.play_time          = get_le64(pb);
179
191
            asf->hdr.preroll            = get_le32(pb);
180
192
            asf->hdr.ignore             = get_le32(pb);
181
193
            asf->hdr.flags              = get_le32(pb);
187
199
            int type, type_specific_size, sizeX;
188
200
            uint64_t total_size;
189
201
            unsigned int tag1;
190
 
            int64_t pos1, pos2;
191
 
            int test_for_ext_stream_audio;
 
202
            int64_t pos1, pos2, start_time;
 
203
            int test_for_ext_stream_audio, is_dvr_ms_audio=0;
192
204
 
193
205
            pos1 = url_ftell(pb);
194
206
 
200
212
            if (!asf_st)
201
213
                goto fail;
202
214
            st->priv_data = asf_st;
203
 
            st->start_time = asf->hdr.preroll;
 
215
            start_time = asf->hdr.preroll;
 
216
 
204
217
            if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming...
205
218
                st->duration = asf->hdr.send_time /
206
 
                    (10000000 / 1000) - st->start_time;
 
219
                    (10000000 / 1000) - start_time;
207
220
            }
208
221
            get_guid(pb, &g);
209
222
 
234
247
                get_guid(pb, &g);
235
248
                if (!memcmp(&g, &ext_stream_audio_stream, sizeof(GUID))) {
236
249
                    type = CODEC_TYPE_AUDIO;
 
250
                    is_dvr_ms_audio=1;
237
251
                    get_guid(pb, &g);
238
252
                    get_le32(pb);
239
253
                    get_le32(pb);
246
260
            st->codec->codec_type = type;
247
261
            if (type == CODEC_TYPE_AUDIO) {
248
262
                get_wav_header(pb, st->codec, type_specific_size);
249
 
                st->need_parsing = 1;
 
263
                if (is_dvr_ms_audio) {
 
264
                    // codec_id and codec_tag are unreliable in dvr_ms
 
265
                    // files. Set them later by probing stream.
 
266
                    st->codec->codec_id = CODEC_ID_NONE;
 
267
                    st->codec->codec_tag = 0;
 
268
                }
 
269
                st->need_parsing = AVSTREAM_PARSE_FULL;
250
270
                /* We have to init the frame size at some point .... */
251
271
                pos2 = url_ftell(pb);
252
 
                if (gsize > (pos2 + 8 - pos1 + 24)) {
 
272
                if (gsize >= (pos2 + 8 - pos1 + 24)) {
253
273
                    asf_st->ds_span = get_byte(pb);
254
274
                    asf_st->ds_packet_size = get_le16(pb);
255
275
                    asf_st->ds_chunk_size = get_le16(pb);
323
343
                st->codec->codec_tag = tag1;
324
344
                st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
325
345
                if(tag1 == MKTAG('D', 'V', 'R', ' '))
326
 
                    st->need_parsing = 1;
 
346
                    st->need_parsing = AVSTREAM_PARSE_FULL;
327
347
            }
328
348
            pos2 = url_ftell(pb);
329
349
            url_fskip(pb, gsize - (pos2 - pos1 + 24));
330
 
        } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
331
 
            asf->data_object_offset = url_ftell(pb);
332
 
            // if not streaming, gsize is not unlimited (how?), and there is enough space in the file..
333
 
            if (!(asf->hdr.flags & 0x01) && gsize != (uint64_t)-1 && gsize >= 24) {
334
 
                asf->data_object_size = gsize - 24;
335
 
            } else {
336
 
                asf->data_object_size = (uint64_t)-1;
337
 
            }
338
 
            break;
339
350
        } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
340
351
            int len1, len2, len3, len4, len5;
341
352
 
362
373
                bitrate= get_le32(pb);
363
374
                stream_id= (flags & 0x7f);
364
375
//                av_log(NULL, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate);
365
 
                asf->stream_bitrates[stream_id-1]= bitrate;
 
376
                asf->stream_bitrates[stream_id]= bitrate;
366
377
            }
367
378
       } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) {
368
379
                int desc_count, i;
378
389
                        get_str16_nolen(pb, name_len, name, sizeof(name));
379
390
                        value_type = get_le16(pb);
380
391
                        value_len = get_le16(pb);
381
 
                        if ((value_type == 0) || (value_type == 1)) // unicode or byte
 
392
                        if (value_type <= 1) // unicode or byte
382
393
                        {
383
394
                                if     (!strcmp(name,"WM/AlbumTitle")) get_str16_nolen(pb, value_len, s->album, sizeof(s->album));
384
395
                                else if(!strcmp(name,"WM/Genre"     )) get_str16_nolen(pb, value_len, s->genre, sizeof(s->genre));
 
396
                                else if(!strcmp(name,"WM/Year"      )) {
 
397
                                    char year[8];
 
398
                                    get_str16_nolen(pb, value_len, year, sizeof(year));
 
399
                                    s->year = atoi(year);
 
400
                                }
 
401
                                else if(!strcmp(name,"WM/Track") && s->track == 0) {
 
402
                                    char track[8];
 
403
                                    get_str16_nolen(pb, value_len, track, sizeof(track));
 
404
                                    s->track = strtol(track, NULL, 10) + 1;
 
405
                                }
 
406
                                else if(!strcmp(name,"WM/TrackNumber")) {
 
407
                                    char track[8];
 
408
                                    get_str16_nolen(pb, value_len, track, sizeof(track));
 
409
                                    s->track = strtol(track, NULL, 10);
 
410
                                }
385
411
                                else url_fskip(pb, value_len);
386
412
                        }
387
 
                        if ((value_type >= 2) && (value_type <= 5)) // boolean or DWORD or QWORD or WORD
 
413
                        else if (value_type <= 5) // boolean or DWORD or QWORD or WORD
388
414
                        {
389
415
                                value_num= get_value(pb, value_type);
390
 
                                if (!strcmp(name,"WM/Track"      )) s->track = value_num + 1;
 
416
                                if (!strcmp(name,"WM/Track"      ) && s->track == 0) s->track = value_num + 1;
391
417
                                if (!strcmp(name,"WM/TrackNumber")) s->track = value_num;
392
 
                        }
 
418
                        }else
 
419
                            url_fskip(pb, value_len);
393
420
                }
394
421
        } else if (!memcmp(&g, &metadata_header, sizeof(GUID))) {
395
422
            int n, stream_num, name_len, value_len, value_type, value_num;
406
433
 
407
434
                get_str16_nolen(pb, name_len, name, sizeof(name));
408
435
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
409
 
                value_num= get_le16(pb);//we should use get_value() here but it doesnt work 2 is le16 here but le32 elsewhere
 
436
                value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
410
437
                url_fskip(pb, value_len - 2);
411
438
 
412
439
                if(stream_num<128){
416
443
            }
417
444
        } else if (!memcmp(&g, &ext_stream_header, sizeof(GUID))) {
418
445
            int ext_len, payload_ext_ct, stream_ct;
419
 
            uint32_t ext_d;
 
446
            uint32_t ext_d, leak_rate, stream_num;
420
447
            int64_t pos_ex_st;
421
448
            pos_ex_st = url_ftell(pb);
422
449
 
423
450
            get_le64(pb); // starttime
424
451
            get_le64(pb); // endtime
425
 
            get_le32(pb); // leak-datarate
 
452
            leak_rate = get_le32(pb); // leak-datarate
426
453
            get_le32(pb); // bucket-datasize
427
454
            get_le32(pb); // init-bucket-fullness
428
455
            get_le32(pb); // alt-leak-datarate
430
457
            get_le32(pb); // alt-init-bucket-fullness
431
458
            get_le32(pb); // max-object-size
432
459
            get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
433
 
            get_le16(pb); // stream-num
 
460
            stream_num = get_le16(pb); // stream-num
434
461
            get_le16(pb); // stream-language-id-index
435
462
            get_le64(pb); // avg frametime in 100ns units
436
463
            stream_ct = get_le16(pb); //stream-name-count
437
464
            payload_ext_ct = get_le16(pb); //payload-extension-system-count
438
465
 
 
466
            if (stream_num < 128)
 
467
                bitrate[stream_num] = leak_rate;
 
468
 
439
469
            for (i=0; i<stream_ct; i++){
440
470
                get_le16(pb);
441
471
                ext_len = get_le16(pb);
499
529
 
500
530
    for(i=0; i<128; i++){
501
531
        int stream_num= asf->asfid2avid[i];
502
 
        if(stream_num>=0 && dar[i].num>0 && dar[i].den>0){
 
532
        if(stream_num>=0){
503
533
            AVCodecContext *codec= s->streams[stream_num]->codec;
504
 
            av_reduce(&codec->sample_aspect_ratio.num,
505
 
                    &codec->sample_aspect_ratio.den,
506
 
                    dar[i].num, dar[i].den, INT_MAX);
 
534
            if (!codec->bit_rate)
 
535
                codec->bit_rate = bitrate[i];
 
536
            if (dar[i].num > 0 && dar[i].den > 0)
 
537
                av_reduce(&codec->sample_aspect_ratio.num,
 
538
                          &codec->sample_aspect_ratio.den,
 
539
                          dar[i].num, dar[i].den, INT_MAX);
507
540
//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);
508
541
        }
509
542
    }
538
571
static int asf_get_packet(AVFormatContext *s)
539
572
{
540
573
    ASFContext *asf = s->priv_data;
541
 
    ByteIOContext *pb = &s->pb;
 
574
    ByteIOContext *pb = s->pb;
542
575
    uint32_t packet_length, padsize;
543
 
    int rsize = 9;
 
576
    int rsize = 8;
544
577
    int c, d, e, off;
545
578
 
546
 
    off= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size + 3;
 
579
    off= (url_ftell(s->pb) - s->data_offset) % asf->packet_size + 3;
547
580
 
548
581
    c=d=e=-1;
549
582
    while(off-- > 0){
557
590
        if (!url_feof(pb))
558
591
            av_log(s, AV_LOG_ERROR, "ff asf bad header %x  at:%"PRId64"\n", c, url_ftell(pb));
559
592
    }
560
 
    if ((c & 0x0f) == 2) { // always true for now
 
593
    if ((c & 0x8f) == 0x82) {
561
594
        if (d || e) {
562
595
            if (!url_feof(pb))
563
596
                av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
564
597
            return -1;
565
598
        }
 
599
        c= get_byte(pb);
566
600
        d= get_byte(pb);
567
 
        e= get_byte(pb);
568
 
        rsize+=2;
569
 
/*    }else{
570
 
        if (!url_feof(pb))
571
 
            printf("ff asf bad header %x  at:%"PRId64"\n", c, url_ftell(pb));
572
 
        return AVERROR_IO;*/
 
601
        rsize+=3;
 
602
    }else{
 
603
        url_fseek(pb, -1, SEEK_CUR); //FIXME
573
604
    }
574
605
 
575
 
    asf->packet_flags = d;
576
 
    asf->packet_property = e;
 
606
    asf->packet_flags    = c;
 
607
    asf->packet_property = d;
577
608
 
578
609
    DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
579
610
    DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
616
647
 */
617
648
static int asf_read_frame_header(AVFormatContext *s){
618
649
    ASFContext *asf = s->priv_data;
619
 
    ByteIOContext *pb = &s->pb;
 
650
    ByteIOContext *pb = s->pb;
620
651
    int rsize = 1;
621
652
    int num = get_byte(pb);
622
653
    int64_t ts0, ts1;
652
683
            url_fskip(pb, asf->packet_replic_size - 8);
653
684
        rsize += asf->packet_replic_size; // FIXME - check validity
654
685
    } else if (asf->packet_replic_size==1){
655
 
        // multipacket - frag_offset is begining timestamp
 
686
        // multipacket - frag_offset is beginning timestamp
656
687
        asf->packet_time_start = asf->packet_frag_offset;
657
688
        asf->packet_frag_offset = 0;
658
689
        asf->packet_frag_timestamp = asf->packet_timestamp;
689
720
{
690
721
    ASFContext *asf = s->priv_data;
691
722
    ASFStream *asf_st = 0;
692
 
    ByteIOContext *pb = &s->pb;
 
723
    ByteIOContext *pb = s->pb;
693
724
    //static int pc = 0;
694
725
    for (;;) {
695
726
        if(url_feof(pb))
696
 
            return AVERROR_IO;
 
727
            return AVERROR(EIO);
697
728
        if (asf->packet_size_left < FRAME_HEADER_SIZE
698
729
            || asf->packet_segments < 1) {
699
730
            //asf->packet_size_left <= asf->packet_padsize) {
703
734
            /* fail safe */
704
735
            url_fskip(pb, ret);
705
736
 
706
 
            asf->packet_pos= url_ftell(&s->pb);
 
737
            asf->packet_pos= url_ftell(s->pb);
707
738
            if (asf->data_object_size != (uint64_t)-1 &&
708
739
                (asf->packet_pos - asf->data_object_offset >= asf->data_object_size))
709
 
                return AVERROR_IO; /* Do not exceed the size of the data object */
 
740
                return AVERROR(EIO); /* Do not exceed the size of the data object */
710
741
            ret = asf_get_packet(s);
711
742
            //printf("READ ASF PACKET  %d   r:%d   c:%d\n", ret, asf->packet_size_left, pc++);
712
743
            if (ret < 0)
736
767
        asf_st = asf->asf_st;
737
768
 
738
769
        if (asf->packet_replic_size == 1) {
739
 
            // frag_offset is here used as the begining timestamp
 
770
            // frag_offset is here used as the beginning timestamp
740
771
            asf->packet_frag_timestamp = asf->packet_time_start;
741
772
            asf->packet_time_start += asf->packet_time_delta;
742
773
            asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
752
783
            asf->packet_multi_size -= asf->packet_obj_size;
753
784
            //printf("COMPRESS size  %d  %d  %d   ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
754
785
        }
 
786
        if(   /*asf->packet_frag_size == asf->packet_obj_size*/
 
787
              asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size
 
788
           && asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size){
 
789
            av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
 
790
                asf_st->frag_offset, asf->packet_frag_size,
 
791
                asf->packet_obj_size, asf_st->pkt.size);
 
792
            asf->packet_obj_size= asf_st->pkt.size;
 
793
        }
 
794
 
755
795
        if (   asf_st->pkt.size != asf->packet_obj_size
756
796
            || asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient?
757
797
            if(asf_st->pkt.data){
792
832
 
793
833
        get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
794
834
                   asf->packet_frag_size);
 
835
        if (s->key && s->keylen == 20)
 
836
            ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
 
837
                            asf->packet_frag_size);
795
838
        asf_st->frag_offset += asf->packet_frag_size;
796
839
        /* test if whole packet is read */
797
840
        if (asf_st->frag_offset == asf_st->pkt.size) {
 
841
            //workaround for macroshit radio DVR-MS files
 
842
            if(   s->streams[asf->stream_index]->codec->codec_id == CODEC_ID_MPEG2VIDEO
 
843
               && asf_st->pkt.size > 100){
 
844
                int i;
 
845
                for(i=0; i<asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
 
846
                if(i == asf_st->pkt.size){
 
847
                    av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
 
848
                    asf_st->frag_offset = 0;
 
849
                    av_free_packet(&asf_st->pkt);
 
850
                    continue;
 
851
                }
 
852
            }
 
853
 
798
854
            /* return packet */
799
855
            if (asf_st->ds_span > 1) {
800
856
              if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span){
801
 
                    av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span\n");
 
857
                    av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span (%d %d %d)\n", asf_st->pkt.size, asf_st->ds_packet_size, asf_st->ds_span);
802
858
              }else{
803
859
                /* packet descrambling */
804
860
                uint8_t *newdata = av_malloc(asf_st->pkt.size);
834
890
    return 0;
835
891
}
836
892
 
837
 
static int asf_read_close(AVFormatContext *s)
838
 
{
839
 
    int i;
840
 
 
841
 
    for(i=0;i<s->nb_streams;i++) {
842
 
        AVStream *st = s->streams[i];
843
 
        av_free(st->priv_data);
844
 
        av_free(st->codec->palctrl);
845
 
    }
846
 
    return 0;
847
 
}
848
 
 
849
893
// Added to support seeking after packets have been read
850
894
// If information is not reset, read_packet fails due to
851
895
// leftover information from previous reads
884
928
    asf->asf_st= NULL;
885
929
}
886
930
 
 
931
static int asf_read_close(AVFormatContext *s)
 
932
{
 
933
    int i;
 
934
 
 
935
    asf_reset_header(s);
 
936
    for(i=0;i<s->nb_streams;i++) {
 
937
        AVStream *st = s->streams[i];
 
938
        av_free(st->priv_data);
 
939
        av_free(st->codec->palctrl);
 
940
    }
 
941
    return 0;
 
942
}
 
943
 
887
944
static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
888
945
{
889
946
    ASFContext *asf = s->priv_data;
900
957
 
901
958
    pos= (pos+asf->packet_size-1-s->data_offset)/asf->packet_size*asf->packet_size+ s->data_offset;
902
959
    *ppos= pos;
903
 
    url_fseek(&s->pb, pos, SEEK_SET);
 
960
    url_fseek(s->pb, pos, SEEK_SET);
904
961
 
905
962
//printf("asf_read_pts\n");
906
963
    asf_reset_header(s);
944
1001
    int i;
945
1002
    int pct,ict;
946
1003
 
947
 
    current_pos = url_ftell(&s->pb);
 
1004
    current_pos = url_ftell(s->pb);
948
1005
 
949
 
    url_fseek(&s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
950
 
    get_guid(&s->pb, &g);
 
1006
    url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET);
 
1007
    get_guid(s->pb, &g);
951
1008
    if (!memcmp(&g, &index_guid, sizeof(GUID))) {
952
 
        gsize = get_le64(&s->pb);
953
 
        get_guid(&s->pb, &g);
954
 
        itime=get_le64(&s->pb);
955
 
        pct=get_le32(&s->pb);
956
 
        ict=get_le32(&s->pb);
 
1009
        gsize = get_le64(s->pb);
 
1010
        get_guid(s->pb, &g);
 
1011
        itime=get_le64(s->pb);
 
1012
        pct=get_le32(s->pb);
 
1013
        ict=get_le32(s->pb);
957
1014
        av_log(NULL, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
958
1015
 
959
1016
        for (i=0;i<ict;i++){
960
 
            int pktnum=get_le32(&s->pb);
961
 
            int pktct =get_le16(&s->pb);
 
1017
            int pktnum=get_le32(s->pb);
 
1018
            int pktct =get_le16(s->pb);
962
1019
            av_log(NULL, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
963
1020
 
964
1021
            pos=s->data_offset + asf->packet_size*(int64_t)pktnum;
968
1025
        }
969
1026
        asf->index_read= 1;
970
1027
    }
971
 
    url_fseek(&s->pb, current_pos, SEEK_SET);
 
1028
    url_fseek(s->pb, current_pos, SEEK_SET);
972
1029
}
973
1030
 
974
1031
static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
981
1038
    if (asf->packet_size <= 0)
982
1039
        return -1;
983
1040
 
 
1041
    /* Try using the protocol's read_seek if available */
 
1042
    if(s->pb) {
 
1043
        int ret = av_url_read_fseek(s->pb, stream_index, pts, flags);
 
1044
        if(ret >= 0)
 
1045
            asf_reset_header(s);
 
1046
        if (ret != AVERROR(ENOSYS))
 
1047
            return ret;
 
1048
    }
 
1049
 
984
1050
    if (!asf->index_read)
985
1051
        asf_build_simple_index(s, stream_index);
986
1052
 
998
1064
 
999
1065
    // various attempts to find key frame have failed so far
1000
1066
    //    asf_reset_header(s);
1001
 
    //    url_fseek(&s->pb, pos, SEEK_SET);
 
1067
    //    url_fseek(s->pb, pos, SEEK_SET);
1002
1068
    //    key_pos = pos;
1003
1069
    //     for(i=0;i<16;i++){
1004
 
    //         pos = url_ftell(&s->pb);
 
1070
    //         pos = url_ftell(s->pb);
1005
1071
    //         if (av_read_frame(s, &pkt) < 0){
1006
1072
    //             av_log(s, AV_LOG_INFO, "seek failed\n");
1007
1073
    //             return -1;
1019
1085
 
1020
1086
        /* do the seek */
1021
1087
        av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
1022
 
        url_fseek(&s->pb, pos, SEEK_SET);
 
1088
        url_fseek(s->pb, pos, SEEK_SET);
1023
1089
    }
1024
1090
    asf_reset_header(s);
1025
1091
    return 0;