Revision e9b78eeb

View differences:

libavformat/avformat.h
138 138
                                      raw picture data */
139 139
#define AVFMT_GLOBALHEADER  0x0040 /* format wants global header */
140 140
#define AVFMT_NOTIMESTAMPS  0x0080 /* format doesnt need / has any timestamps */
141
#define AVFMT_GENERIC_INDEX 0x0100 /* use generic index building code */
141 142

  
142 143
typedef struct AVOutputFormat {
143 144
    const char *name;
libavformat/mp3.c
393 393
    mp3_read_header,
394 394
    mp3_read_packet,
395 395
    mp3_read_close,
396
    .flags= AVFMT_GENERIC_INDEX,
396 397
    .extensions = "mp2,mp3,m2a", /* XXX: use probe */
397 398
};
398 399
#endif
libavformat/raw.c
414 414
    shorten_read_header,
415 415
    raw_read_partial_packet,
416 416
    raw_read_close,
417
    .flags= AVFMT_GENERIC_INDEX,
417 418
    .extensions = "shn",
418 419
};
419 420

  
......
425 426
    flac_read_header,
426 427
    raw_read_partial_packet,
427 428
    raw_read_close,
429
    .flags= AVFMT_GENERIC_INDEX,
428 430
    .extensions = "flac",
429 431
};
430 432

  
......
452 454
    ac3_read_header,
453 455
    raw_read_partial_packet,
454 456
    raw_read_close,
457
    .flags= AVFMT_GENERIC_INDEX,
455 458
    .extensions = "ac3",
456 459
};
457 460

  
......
479 482
    dts_read_header,
480 483
    raw_read_partial_packet,
481 484
    raw_read_close,
485
    .flags= AVFMT_GENERIC_INDEX,
482 486
    .extensions = "dts",
483 487
};
484 488

  
......
490 494
    aac_read_header,
491 495
    raw_read_partial_packet,
492 496
    raw_read_close,
497
    .flags= AVFMT_GENERIC_INDEX,
493 498
    .extensions = "aac",
494 499
};
495 500

  
......
501 506
    video_read_header,
502 507
    raw_read_partial_packet,
503 508
    raw_read_close,
509
    .flags= AVFMT_GENERIC_INDEX,
504 510
    .extensions = "h261",
505 511
    .value = CODEC_ID_H261,
506 512
};
......
529 535
    video_read_header,
530 536
    raw_read_partial_packet,
531 537
    raw_read_close,
538
    .flags= AVFMT_GENERIC_INDEX,
532 539
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
533 540
    .value = CODEC_ID_H263,
534 541
};
......
557 564
    video_read_header,
558 565
    raw_read_partial_packet,
559 566
    raw_read_close,
567
    .flags= AVFMT_GENERIC_INDEX,
560 568
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
561 569
    .value = CODEC_ID_MPEG4,
562 570
};
......
585 593
    video_read_header,
586 594
    raw_read_partial_packet,
587 595
    raw_read_close,
596
    .flags= AVFMT_GENERIC_INDEX,
588 597
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
589 598
    .value = CODEC_ID_H264,
590 599
};
......
613 622
    video_read_header,
614 623
    raw_read_partial_packet,
615 624
    raw_read_close,
625
    .flags= AVFMT_GENERIC_INDEX,
616 626
    .value = CODEC_ID_MPEG1VIDEO,
617 627
};
618 628

  
......
656 666
    video_read_header,
657 667
    raw_read_partial_packet,
658 668
    raw_read_close,
669
    .flags= AVFMT_GENERIC_INDEX,
659 670
    .extensions = "mjpg,mjpeg",
660 671
    .value = CODEC_ID_MJPEG,
661 672
};
......
668 679
    video_read_header,
669 680
    ingenient_read_packet,
670 681
    raw_read_close,
682
    .flags= AVFMT_GENERIC_INDEX,
671 683
    .extensions = "cgi", // FIXME
672 684
    .value = CODEC_ID_MJPEG,
673 685
};
......
700 712
    raw_read_packet,\
701 713
    raw_read_close,\
702 714
    pcm_read_seek,\
715
    .flags= AVFMT_GENERIC_INDEX,\
703 716
    .extensions = ext,\
704 717
    .value = codec,\
705 718
};
......
797 810
    raw_read_header,
798 811
    rawvideo_read_packet,
799 812
    raw_read_close,
813
    .flags= AVFMT_GENERIC_INDEX,
800 814
    .extensions = "yuv,cif,qcif",
801 815
    .value = CODEC_ID_RAWVIDEO,
802 816
};
libavformat/utils.c
788 788
                    pkt->dts = st->parser->dts;
789 789
                    pkt->destruct = av_destruct_packet_nofree;
790 790
                    compute_pkt_fields(s, st, st->parser, pkt);
791

  
792
                    if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){
793
                        av_add_index_entry(st, st->parser->frame_offset, pkt->dts,
794
                                           0, 0, AVINDEX_KEYFRAME);
795
                    }
796

  
791 797
                    break;
792 798
                }
793 799
            } else {
......
836 842
                }else if(st->need_parsing == 2){
837 843
                    st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
838 844
                }
845
                if(st->parser && (s->iformat->flags & AVFMT_GENERIC_INDEX)){
846
                    st->parser->last_frame_offset=
847
                    st->parser->cur_offset= s->cur_pkt.pos;
848
                }
839 849
            }
840 850
        }
841 851
    }
......
1370 1380
    AVStream *st;
1371 1381
    AVIndexEntry *ie;
1372 1382

  
1373
    if (!s->index_built) {
1374
        if (is_raw_stream(s)) {
1375
            av_build_index_raw(s);
1376
        } else {
1377
            return -1;
1378
        }
1379
        s->index_built = 1;
1380
    }
1381

  
1382 1383
    st = s->streams[stream_index];
1384

  
1383 1385
    index = av_index_search_timestamp(st, timestamp, flags);
1386

  
1387
    if(index < 0){
1388
        int i;
1389
        AVPacket pkt;
1390

  
1391
        if(st->index_entries && st->nb_index_entries){
1392
            ie= &st->index_entries[st->nb_index_entries-1];
1393
            url_fseek(&s->pb, ie->pos, SEEK_SET);
1394
            av_update_cur_dts(s, st, ie->timestamp);
1395
        }else
1396
            url_fseek(&s->pb, 0, SEEK_SET);
1397

  
1398
        for(i=0;; i++) {
1399
            int ret = av_read_frame(s, &pkt);
1400
            if(ret<0)
1401
                break;
1402
            av_free_packet(&pkt);
1403
            if(stream_index == pkt.stream_index){
1404
                if((pkt.flags & PKT_FLAG_KEY) && pkt.dts > timestamp)
1405
                    break;
1406
            }
1407
        }
1408
        index = av_index_search_timestamp(st, timestamp, flags);
1409
    }
1384 1410
    if (index < 0)
1385 1411
        return -1;
1386 1412

  
1387
    /* now we have found the index, we can seek */
1388
    ie = &st->index_entries[index];
1389 1413
    av_read_frame_flush(s);
1414
    if (s->iformat->read_seek){
1415
        if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0)
1416
            return 0;
1417
    }
1418
    ie = &st->index_entries[index];
1390 1419
    url_fseek(&s->pb, ie->pos, SEEK_SET);
1391 1420

  
1392 1421
    av_update_cur_dts(s, st, ie->timestamp);
libavformat/wav.c
188 188
        size = (size / st->codec->block_align) * st->codec->block_align;
189 189
    }
190 190
    size= FFMIN(size, left);
191
    if (av_new_packet(pkt, size))
191
    ret= av_get_packet(&s->pb, pkt, size);
192
    if (ret <= 0)
192 193
        return AVERROR_IO;
193 194
    pkt->stream_index = 0;
194 195

  
195
    ret = get_buffer(&s->pb, pkt->data, pkt->size);
196
    if (ret < 0)
197
        av_free_packet(pkt);
198 196
    /* note: we need to modify the packet size here to handle the last
199 197
       packet */
200 198
    pkt->size = ret;
......
235 233
    wav_read_packet,
236 234
    wav_read_close,
237 235
    wav_read_seek,
236
    .flags= AVFMT_GENERIC_INDEX,
238 237
    .codec_tag= (const AVCodecTag*[]){codec_wav_tags, 0},
239 238
};
240 239
#endif

Also available in: Unified diff