comparison flvdec.c @ 1318:defa841523a9 libavformat

FLV seeking patch by Nazo. lovesyao at aol com.
author banan
date Sun, 17 Sep 2006 09:39:49 +0000
parents 541f4aa12efc
children 0899bfe4105c
comparison
equal deleted inserted replaced
1317:132206560fe6 1318:defa841523a9
53 } 53 }
54 } 54 }
55 55
56 url_fseek(&s->pb, offset, SEEK_SET); 56 url_fseek(&s->pb, offset, SEEK_SET);
57 57
58 s->start_time = 0;
59
58 return 0; 60 return 0;
59 } 61 }
60 62
61 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) 63 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
62 { 64 {
63 int ret, i, type, size, pts, flags, is_audio, next; 65 int ret, i, type, size, pts, flags, is_audio, next, pos;
64 AVStream *st = NULL; 66 AVStream *st = NULL;
65 67
66 for(;;){ 68 for(;;){
69 pos = url_ftell(&s->pb);
67 url_fskip(&s->pb, 4); /* size of previous packet */ 70 url_fskip(&s->pb, 4); /* size of previous packet */
68 type = get_byte(&s->pb); 71 type = get_byte(&s->pb);
69 size = get_be24(&s->pb); 72 size = get_be24(&s->pb);
70 pts = get_be24(&s->pb); 73 pts = get_be24(&s->pb);
71 // av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, pts:%d\n", type, size, pts); 74 // av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, pts:%d\n", type, size, pts);
152 || st->discard >= AVDISCARD_ALL 155 || st->discard >= AVDISCARD_ALL
153 ){ 156 ){
154 url_fseek(&s->pb, next, SEEK_SET); 157 url_fseek(&s->pb, next, SEEK_SET);
155 continue; 158 continue;
156 } 159 }
160 if ((flags >> 4)==1)
161 av_add_index_entry(st, pos, pts, size, 0, AVINDEX_KEYFRAME);
157 break; 162 break;
158 } 163 }
159 164
160 if(is_audio){ 165 if(is_audio){
161 if(st->codec->sample_rate == 0){ 166 if(st->codec->sample_rate == 0){
214 static int flv_read_close(AVFormatContext *s) 219 static int flv_read_close(AVFormatContext *s)
215 { 220 {
216 return 0; 221 return 0;
217 } 222 }
218 223
224 static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
225 {
226 AVStream *st = s->streams[stream_index];
227 int index = av_index_search_timestamp(st, timestamp, flags);
228 if (index < 0)
229 return -1;
230 url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET);
231
232 return 0;
233 }
234
219 AVInputFormat flv_demuxer = { 235 AVInputFormat flv_demuxer = {
220 "flv", 236 "flv",
221 "flv format", 237 "flv format",
222 0, 238 0,
223 flv_probe, 239 flv_probe,
224 flv_read_header, 240 flv_read_header,
225 flv_read_packet, 241 flv_read_packet,
226 flv_read_close, 242 flv_read_close,
243 flv_read_seek,
227 .extensions = "flv", 244 .extensions = "flv",
228 .value = CODEC_ID_FLV1, 245 .value = CODEC_ID_FLV1,
229 }; 246 };