Mercurial > libavformat.hg
comparison mp3.c @ 4221:55f448c99135 libavformat
Factorise id3v2 header parsing from mp3.c to be shared
Patch by Alex Converse ( alex converse gmail com )
author | superdump |
---|---|
date | Thu, 15 Jan 2009 12:23:03 +0000 |
parents | c3102b189cb6 |
children | 77e0c7511d41 |
comparison
equal
deleted
inserted
replaced
4220:443927a154f1 | 4221:55f448c99135 |
---|---|
22 #include <strings.h> | 22 #include <strings.h> |
23 #include "libavutil/avstring.h" | 23 #include "libavutil/avstring.h" |
24 #include "libavcodec/mpegaudio.h" | 24 #include "libavcodec/mpegaudio.h" |
25 #include "libavcodec/mpegaudiodecheader.h" | 25 #include "libavcodec/mpegaudiodecheader.h" |
26 #include "avformat.h" | 26 #include "avformat.h" |
27 | 27 #include "id3v2.h" |
28 #define ID3v2_HEADER_SIZE 10 | 28 |
29 #define ID3v1_TAG_SIZE 128 | 29 #define ID3v1_TAG_SIZE 128 |
30 | 30 |
31 #define ID3v1_GENRE_MAX 125 | 31 #define ID3v1_GENRE_MAX 125 |
32 | 32 |
33 static const char * const id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { | 33 static const char * const id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { |
157 [123] = "A capella", | 157 [123] = "A capella", |
158 [124] = "Euro-House", | 158 [124] = "Euro-House", |
159 [125] = "Dance Hall", | 159 [125] = "Dance Hall", |
160 }; | 160 }; |
161 | 161 |
162 /* buf must be ID3v2_HEADER_SIZE byte long */ | |
163 static int id3v2_match(const uint8_t *buf) | |
164 { | |
165 return buf[0] == 'I' && | |
166 buf[1] == 'D' && | |
167 buf[2] == '3' && | |
168 buf[3] != 0xff && | |
169 buf[4] != 0xff && | |
170 (buf[6] & 0x80) == 0 && | |
171 (buf[7] & 0x80) == 0 && | |
172 (buf[8] & 0x80) == 0 && | |
173 (buf[9] & 0x80) == 0; | |
174 } | |
175 | |
176 static unsigned int id3v2_get_size(ByteIOContext *s, int len) | 162 static unsigned int id3v2_get_size(ByteIOContext *s, int len) |
177 { | 163 { |
178 int v=0; | 164 int v=0; |
179 while(len--) | 165 while(len--) |
180 v= (v<<7) + (get_byte(s)&0x7F); | 166 v= (v<<7) + (get_byte(s)&0x7F); |
369 int fsize, frames, sample_rate; | 355 int fsize, frames, sample_rate; |
370 uint32_t header; | 356 uint32_t header; |
371 uint8_t *buf, *buf2, *end; | 357 uint8_t *buf, *buf2, *end; |
372 AVCodecContext avctx; | 358 AVCodecContext avctx; |
373 | 359 |
374 if(id3v2_match(p->buf)) | 360 if(ff_id3v2_match(p->buf)) |
375 return AVPROBE_SCORE_MAX/2+1; // this must be less than mpeg-ps because some retards put id3v2 tags before mpeg-ps files | 361 return AVPROBE_SCORE_MAX/2+1; // this must be less than mpeg-ps because some retards put id3v2 tags before mpeg-ps files |
376 | 362 |
377 max_frames = 0; | 363 max_frames = 0; |
378 buf = p->buf; | 364 buf = p->buf; |
379 end = buf + p->buf_size - sizeof(uint32_t); | 365 end = buf + p->buf_size - sizeof(uint32_t); |
485 | 471 |
486 /* if ID3v2 header found, skip it */ | 472 /* if ID3v2 header found, skip it */ |
487 ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE); | 473 ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE); |
488 if (ret != ID3v2_HEADER_SIZE) | 474 if (ret != ID3v2_HEADER_SIZE) |
489 return -1; | 475 return -1; |
490 if (id3v2_match(buf)) { | 476 if (ff_id3v2_match(buf)) { |
491 /* parse ID3v2 header */ | 477 /* parse ID3v2 header */ |
492 len = ((buf[6] & 0x7f) << 21) | | 478 len = ((buf[6] & 0x7f) << 21) | |
493 ((buf[7] & 0x7f) << 14) | | 479 ((buf[7] & 0x7f) << 14) | |
494 ((buf[8] & 0x7f) << 7) | | 480 ((buf[8] & 0x7f) << 7) | |
495 (buf[9] & 0x7f); | 481 (buf[9] & 0x7f); |