Mercurial > libavformat.hg
comparison mp3.c @ 1308:866d43ed0a67 libavformat
allow ffmpeg to read mp3s beginning with partial frames
Patch by Andreas Oman andreas A olebyn P nu
Original thread:
Date: Sep 10, 2006 7:26 AM
Subject: Re: [Ffmpeg-devel] [PATCH] allow ffmpeg to read mp3s beginning with partial frames
| author | gpoirier |
|---|---|
| date | Sun, 10 Sep 2006 20:31:58 +0000 |
| parents | d18cc9a1fd02 |
| children | 24f1d6a50117 |
comparison
equal
deleted
inserted
replaced
| 1307:59dbb78518d4 | 1308:866d43ed0a67 |
|---|---|
| 15 * You should have received a copy of the GNU Lesser General Public | 15 * You should have received a copy of the GNU Lesser General Public |
| 16 * License along with this library; if not, write to the Free Software | 16 * License along with this library; if not, write to the Free Software |
| 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 */ | 18 */ |
| 19 #include "avformat.h" | 19 #include "avformat.h" |
| 20 #include "mpegaudio.h" | |
| 20 | 21 |
| 21 #define ID3_HEADER_SIZE 10 | 22 #define ID3_HEADER_SIZE 10 |
| 22 #define ID3_TAG_SIZE 128 | 23 #define ID3_TAG_SIZE 128 |
| 23 | 24 |
| 24 #define ID3_GENRE_MAX 125 | 25 #define ID3_GENRE_MAX 125 |
| 241 | 242 |
| 242 /* mp3 read */ | 243 /* mp3 read */ |
| 243 | 244 |
| 244 static int mp3_read_probe(AVProbeData *p) | 245 static int mp3_read_probe(AVProbeData *p) |
| 245 { | 246 { |
| 246 int d; | 247 int max_frames; |
| 247 | 248 int fsize, frames; |
| 248 if(p->buf_size < 4) | 249 uint32_t header; |
| 250 uint8_t *buf, *buf2, *end; | |
| 251 AVCodecContext avctx; | |
| 252 | |
| 253 if(p->buf_size < ID3_HEADER_SIZE) | |
| 249 return 0; | 254 return 0; |
| 250 | 255 |
| 251 if(p->buf[0] == 'I' && p->buf[1] == 'D' && p->buf[2] == '3' && | 256 if(id3_match(p->buf)) |
| 252 p->buf[3] < 5) | |
| 253 return AVPROBE_SCORE_MAX; | 257 return AVPROBE_SCORE_MAX; |
| 254 | 258 |
| 255 if(p->buf[0] != 0xff) | 259 max_frames = 0; |
| 256 return 0; | 260 buf = p->buf; |
| 257 | 261 end = buf + FFMIN(4096, p->buf_size - sizeof(uint32_t)); |
| 258 d = p->buf[1]; | 262 |
| 259 if((d & 0xe0) != 0xe0 || ((d & 0x18) == 0x08 || (d & 0x06) == 0)) | 263 for(; buf < end; buf++) { |
| 260 return 0; | 264 buf2 = buf; |
| 261 | 265 |
| 262 d = p->buf[2]; | 266 for(frames = 0; buf < end; frames++) { |
| 263 if((d & 0xf0) == 0xf0 || (d & 0x0c) == 0x0c) | 267 header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3]; |
| 264 return 0; | 268 fsize = mpa_decode_header(&avctx, header); |
| 265 | 269 if(fsize < 0) |
| 266 return AVPROBE_SCORE_MAX; | 270 break; |
| 271 buf2 += fsize; | |
| 272 } | |
| 273 max_frames = FFMAX(max_frames, frames); | |
| 274 } | |
| 275 if (max_frames>=3) return AVPROBE_SCORE_MAX/2+1; | |
| 276 else if(max_frames==2) return AVPROBE_SCORE_MAX/4; | |
| 277 else if(max_frames==1) return 1; | |
| 278 else return 0; | |
| 267 } | 279 } |
| 268 | 280 |
| 269 static int mp3_read_header(AVFormatContext *s, | 281 static int mp3_read_header(AVFormatContext *s, |
| 270 AVFormatParameters *ap) | 282 AVFormatParameters *ap) |
| 271 { | 283 { |
