Mercurial > libavformat.hg
comparison asf.c @ 1265:613fdf995af0 libavformat
read and use index (based on a patch by John Donaghy on the 23-03-2006 '[Ffmpeg-devel] dvr-ms seek help request')
author | michael |
---|---|
date | Wed, 23 Aug 2006 17:07:01 +0000 |
parents | 3d00cb7b7426 |
children | 5b9729f5145c |
comparison
equal
deleted
inserted
replaced
1264:3d00cb7b7426 | 1265:613fdf995af0 |
---|---|
835 //printf("found keyframe at %Ld stream %d stamp:%Ld\n", *ppos, stream_index, pts); | 835 //printf("found keyframe at %Ld stream %d stamp:%Ld\n", *ppos, stream_index, pts); |
836 | 836 |
837 return pts; | 837 return pts; |
838 } | 838 } |
839 | 839 |
840 static void asf_build_simple_index(AVFormatContext *s, int stream_index) | |
841 { | |
842 GUID g; | |
843 ASFContext *asf = s->priv_data; | |
844 int64_t gsize, itime; | |
845 int64_t pos, current_pos, index_pts; | |
846 int i; | |
847 int pct,ict; | |
848 | |
849 current_pos = url_ftell(&s->pb); | |
850 | |
851 url_fseek(&s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET); | |
852 get_guid(&s->pb, &g); | |
853 if (!memcmp(&g, &index_guid, sizeof(GUID))) { | |
854 gsize = get_le64(&s->pb); | |
855 get_guid(&s->pb, &g); | |
856 itime=get_le64(&s->pb); | |
857 pct=get_le32(&s->pb); | |
858 ict=get_le32(&s->pb); | |
859 av_log(NULL, AV_LOG_DEBUG, "itime:0x%Lx, pct:%d, ict:%d\n",itime,pct,ict); | |
860 | |
861 for (i=0;i<ict;i++){ | |
862 int pktnum=get_le32(&s->pb); | |
863 int pktct =get_le16(&s->pb); | |
864 av_log(NULL, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct); | |
865 | |
866 pos=s->data_offset + asf->packet_size*(int64_t)pktnum; | |
867 index_pts=av_rescale(itime, i, 10000); | |
868 | |
869 av_add_index_entry(s->streams[stream_index], pos, index_pts, asf->packet_size, 0, AVINDEX_KEYFRAME); | |
870 } | |
871 } | |
872 url_fseek(&s->pb, current_pos, SEEK_SET); | |
873 } | |
874 | |
840 static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags) | 875 static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags) |
841 { | 876 { |
842 ASFContext *asf = s->priv_data; | 877 ASFContext *asf = s->priv_data; |
878 AVStream *st = s->streams[stream_index]; | |
879 int64_t pos; | |
880 int index; | |
843 | 881 |
844 if (asf->packet_size <= 0) | 882 if (asf->packet_size <= 0) |
845 return -1; | 883 return -1; |
846 | 884 |
847 if(av_seek_frame_binary(s, stream_index, pts, flags)<0) | 885 if (!st->index_entries) |
848 return -1; | 886 asf_build_simple_index(s, stream_index); |
849 | 887 |
888 if(!st->index_entries){ | |
889 if(av_seek_frame_binary(s, stream_index, pts, flags)<0) | |
890 return -1; | |
891 }else{ | |
892 index= av_index_search_timestamp(st, pts, flags); | |
893 if(index<0) | |
894 return -1; | |
895 | |
896 /* find the position */ | |
897 pos = st->index_entries[index].pos; | |
898 pts = st->index_entries[index].timestamp; | |
899 | |
900 // various attempts to find key frame have failed so far | |
901 // asf_reset_header(s); | |
902 // url_fseek(&s->pb, pos, SEEK_SET); | |
903 // key_pos = pos; | |
904 // for(i=0;i<16;i++){ | |
905 // pos = url_ftell(&s->pb); | |
906 // if (av_read_frame(s, &pkt) < 0){ | |
907 // av_log(s, AV_LOG_INFO, "seek failed\n"); | |
908 // return -1; | |
909 // } | |
910 // asf_st = s->streams[stream_index]->priv_data; | |
911 // pos += st->parser->frame_offset; | |
912 // | |
913 // if (pkt.size > b) { | |
914 // b = pkt.size; | |
915 // key_pos = pos; | |
916 // } | |
917 // | |
918 // av_free_packet(&pkt); | |
919 // } | |
920 | |
921 /* do the seek */ | |
922 av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %Ld\n", pos); | |
923 url_fseek(&s->pb, pos, SEEK_SET); | |
924 } | |
850 asf_reset_header(s); | 925 asf_reset_header(s); |
851 return 0; | 926 return 0; |
852 } | 927 } |
853 | 928 |
854 AVInputFormat asf_demuxer = { | 929 AVInputFormat asf_demuxer = { |