Mercurial > libavformat.hg
comparison flvdec.c @ 821:92dfb26763e4 libavformat
extract duration if available
author | michael |
---|---|
date | Tue, 19 Jul 2005 14:26:41 +0000 |
parents | feca73904e67 |
children | 2614d3c1f415 |
comparison
equal
deleted
inserted
replaced
820:feca73904e67 | 821:92dfb26763e4 |
---|---|
56 return 0; | 56 return 0; |
57 } | 57 } |
58 | 58 |
59 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) | 59 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) |
60 { | 60 { |
61 int ret, i, type, size, pts, flags, is_audio; | 61 int ret, i, type, size, pts, flags, is_audio, next; |
62 AVStream *st = NULL; | 62 AVStream *st = NULL; |
63 | 63 |
64 for(;;){ | 64 for(;;){ |
65 url_fskip(&s->pb, 4); /* size of previous packet */ | 65 url_fskip(&s->pb, 4); /* size of previous packet */ |
66 type = get_byte(&s->pb); | 66 type = get_byte(&s->pb); |
72 url_fskip(&s->pb, 4); /* reserved */ | 72 url_fskip(&s->pb, 4); /* reserved */ |
73 flags = 0; | 73 flags = 0; |
74 | 74 |
75 if(size == 0) | 75 if(size == 0) |
76 continue; | 76 continue; |
77 | 77 |
78 next= size + url_ftell(&s->pb); | |
79 | |
78 if (type == 8) { | 80 if (type == 8) { |
79 is_audio=1; | 81 is_audio=1; |
80 flags = get_byte(&s->pb); | 82 flags = get_byte(&s->pb); |
81 size--; | |
82 } else if (type == 9) { | 83 } else if (type == 9) { |
83 is_audio=0; | 84 is_audio=0; |
84 flags = get_byte(&s->pb); | 85 flags = get_byte(&s->pb); |
85 size--; | 86 } else if (type == 18 && size > 13+1+4) { |
87 url_fskip(&s->pb, 13); //onMetaData blah | |
88 if(get_byte(&s->pb) == 8){ | |
89 url_fskip(&s->pb, 4); | |
90 } | |
91 while(url_ftell(&s->pb) + 5 < next){ | |
92 char tmp[128]; | |
93 int type, len; | |
94 double d= 0; | |
95 | |
96 len= get_be16(&s->pb); | |
97 if(len >= sizeof(tmp) || !len) | |
98 break; | |
99 get_buffer(&s->pb, tmp, len); | |
100 tmp[len]=0; | |
101 | |
102 type= get_byte(&s->pb); | |
103 if(type==0){ | |
104 d= av_int2dbl(get_be64(&s->pb)); | |
105 }else if(type==2){ | |
106 len= get_be16(&s->pb); | |
107 if(len >= sizeof(tmp)) | |
108 break; | |
109 url_fskip(&s->pb, len); | |
110 }else if(type==8){ | |
111 //array | |
112 break; | |
113 }else if(type==11){ | |
114 d= av_int2dbl(get_be64(&s->pb)); | |
115 get_be16(&s->pb); | |
116 } | |
117 | |
118 if(!strcmp(tmp, "duration")){ | |
119 s->duration = d*AV_TIME_BASE; | |
120 }else if(!strcmp(tmp, "videodatarate")){ | |
121 }else if(!strcmp(tmp, "audiodatarate")){ | |
122 } | |
123 } | |
124 url_fseek(&s->pb, next, SEEK_SET); | |
125 continue; | |
86 } else { | 126 } else { |
87 /* skip packet */ | 127 /* skip packet */ |
88 av_log(s, AV_LOG_ERROR, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); | 128 av_log(s, AV_LOG_ERROR, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); |
89 url_fskip(&s->pb, size); | 129 url_fseek(&s->pb, next, SEEK_SET); |
90 continue; | 130 continue; |
91 } | 131 } |
92 | 132 |
93 /* now find stream */ | 133 /* now find stream */ |
94 for(i=0;i<s->nb_streams;i++) { | 134 for(i=0;i<s->nb_streams;i++) { |
107 // av_log(NULL, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard); | 147 // av_log(NULL, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard); |
108 if( (st->discard >= AVDISCARD_NONKEY && !((flags >> 4)==1 || is_audio)) | 148 if( (st->discard >= AVDISCARD_NONKEY && !((flags >> 4)==1 || is_audio)) |
109 ||(st->discard >= AVDISCARD_BIDIR && ((flags >> 4)==3 && !is_audio)) | 149 ||(st->discard >= AVDISCARD_BIDIR && ((flags >> 4)==3 && !is_audio)) |
110 || st->discard >= AVDISCARD_ALL | 150 || st->discard >= AVDISCARD_ALL |
111 ){ | 151 ){ |
112 url_fskip(&s->pb, size); | 152 url_fseek(&s->pb, next, SEEK_SET); |
113 continue; | 153 continue; |
114 } | 154 } |
115 break; | 155 break; |
116 } | 156 } |
117 | 157 |
145 av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flags & 0xf); | 185 av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flags & 0xf); |
146 st->codec->codec_tag= flags & 0xF; | 186 st->codec->codec_tag= flags & 0xF; |
147 } | 187 } |
148 } | 188 } |
149 | 189 |
150 ret= av_get_packet(&s->pb, pkt, size); | 190 ret= av_get_packet(&s->pb, pkt, size - 1); |
151 if (ret <= 0) { | 191 if (ret <= 0) { |
152 return AVERROR_IO; | 192 return AVERROR_IO; |
153 } | 193 } |
154 /* note: we need to modify the packet size here to handle the last | 194 /* note: we need to modify the packet size here to handle the last |
155 packet */ | 195 packet */ |