OLD | NEW |
1 /* | 1 /* |
2 * MP3 muxer and demuxer | 2 * MP3 muxer and demuxer |
3 * Copyright (c) 2003 Fabrice Bellard | 3 * Copyright (c) 2003 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 27 matching lines...) Expand all Loading... |
38 int max_frames, first_frames = 0; | 38 int max_frames, first_frames = 0; |
39 int fsize, frames, sample_rate; | 39 int fsize, frames, sample_rate; |
40 uint32_t header; | 40 uint32_t header; |
41 uint8_t *buf, *buf0, *buf2, *end; | 41 uint8_t *buf, *buf0, *buf2, *end; |
42 AVCodecContext avctx; | 42 AVCodecContext avctx; |
43 | 43 |
44 buf0 = p->buf; | 44 buf0 = p->buf; |
45 if(ff_id3v2_match(buf0)) { | 45 if(ff_id3v2_match(buf0)) { |
46 buf0 += ff_id3v2_tag_len(buf0); | 46 buf0 += ff_id3v2_tag_len(buf0); |
47 } | 47 } |
| 48 end = p->buf + p->buf_size - sizeof(uint32_t); |
| 49 while(buf0 < end && !*buf0) |
| 50 buf0++; |
48 | 51 |
49 max_frames = 0; | 52 max_frames = 0; |
50 buf = buf0; | 53 buf = buf0; |
51 end = p->buf + p->buf_size - sizeof(uint32_t); | |
52 | 54 |
53 for(; buf < end; buf= buf2+1) { | 55 for(; buf < end; buf= buf2+1) { |
54 buf2 = buf; | 56 buf2 = buf; |
55 | 57 |
56 for(frames = 0; buf2 < end; frames++) { | 58 for(frames = 0; buf2 < end; frames++) { |
57 header = AV_RB32(buf2); | 59 header = AV_RB32(buf2); |
58 fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_r
ate, &sample_rate, &sample_rate); | 60 fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_r
ate, &sample_rate, &sample_rate); |
59 if(fsize < 0) | 61 if(fsize < 0) |
60 break; | 62 break; |
61 buf2 += fsize; | 63 buf2 += fsize; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 142 |
141 st->codec->codec_type = CODEC_TYPE_AUDIO; | 143 st->codec->codec_type = CODEC_TYPE_AUDIO; |
142 st->codec->codec_id = CODEC_ID_MP3; | 144 st->codec->codec_id = CODEC_ID_MP3; |
143 st->need_parsing = AVSTREAM_PARSE_FULL; | 145 st->need_parsing = AVSTREAM_PARSE_FULL; |
144 st->start_time = 0; | 146 st->start_time = 0; |
145 | 147 |
146 // lcm of all mp3 sample rates | 148 // lcm of all mp3 sample rates |
147 av_set_pts_info(st, 64, 1, 14112000); | 149 av_set_pts_info(st, 64, 1, 14112000); |
148 | 150 |
149 ff_id3v2_read(s); | 151 ff_id3v2_read(s); |
| 152 off = url_ftell(s->pb); |
| 153 |
150 if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) | 154 if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) |
151 ff_id3v1_read(s); | 155 ff_id3v1_read(s); |
152 | 156 |
153 off = url_ftell(s->pb); | |
154 if (mp3_parse_vbr_tags(s, st, off) < 0) | 157 if (mp3_parse_vbr_tags(s, st, off) < 0) |
155 url_fseek(s->pb, off, SEEK_SET); | 158 url_fseek(s->pb, off, SEEK_SET); |
156 | 159 |
157 /* the parameters will be extracted from the compressed bitstream */ | 160 /* the parameters will be extracted from the compressed bitstream */ |
158 return 0; | 161 return 0; |
159 } | 162 } |
160 | 163 |
161 #define MP3_PACKET_SIZE 1024 | 164 #define MP3_PACKET_SIZE 1024 |
162 | 165 |
163 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) | 166 static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 put_byte(s->pb, 0); | 308 put_byte(s->pb, 0); |
306 put_byte(s->pb, 0); /* flags */ | 309 put_byte(s->pb, 0); /* flags */ |
307 | 310 |
308 /* reserve space for size */ | 311 /* reserve space for size */ |
309 size_pos = url_ftell(s->pb); | 312 size_pos = url_ftell(s->pb); |
310 put_be32(s->pb, 0); | 313 put_be32(s->pb, 0); |
311 | 314 |
312 while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
{ | 315 while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
{ |
313 uint32_t tag = 0; | 316 uint32_t tag = 0; |
314 | 317 |
315 if (t->key[0] == 'T' && strcmp(t->key, "TSSE")) { | 318 if (t->key[0] == 'T' && strlen(t->key) == 4) { |
316 int i; | 319 int i; |
317 for (i = 0; *ff_id3v2_tags[i]; i++) | 320 for (i = 0; *ff_id3v2_tags[i]; i++) |
318 if (AV_RB32(t->key) == AV_RB32(ff_id3v2_tags[i])) { | 321 if (AV_RB32(t->key) == AV_RB32(ff_id3v2_tags[i])) { |
319 int len = strlen(t->value); | 322 int len = strlen(t->value); |
320 tag = AV_RB32(t->key); | 323 tag = AV_RB32(t->key); |
321 totlen += len + ID3v2_HEADER_SIZE + 2; | 324 totlen += len + ID3v2_HEADER_SIZE + 2; |
322 id3v2_put_ttag(s, t->value, len + 1, tag); | 325 id3v2_put_ttag(s, t->value, len + 1, tag); |
323 break; | 326 break; |
324 } | 327 } |
325 } | 328 } |
326 | 329 |
327 if (!tag) { /* unknown tag, write as TXXX frame */ | 330 if (!tag) { /* unknown tag, write as TXXX frame */ |
328 int len = strlen(t->key), len1 = strlen(t->value); | 331 int len = strlen(t->key), len1 = strlen(t->value); |
329 char *buf = av_malloc(len + len1 + 2); | 332 char *buf = av_malloc(len + len1 + 2); |
330 if (!buf) | 333 if (!buf) |
331 return AVERROR(ENOMEM); | 334 return AVERROR(ENOMEM); |
332 tag = MKBETAG('T', 'X', 'X', 'X'); | 335 tag = MKBETAG('T', 'X', 'X', 'X'); |
333 strcpy(buf, t->key); | 336 strcpy(buf, t->key); |
334 strcpy(buf + len + 1, t->value); | 337 strcpy(buf + len + 1, t->value); |
335 id3v2_put_ttag(s, buf, len + len1 + 2, tag); | 338 id3v2_put_ttag(s, buf, len + len1 + 2, tag); |
336 totlen += len + len1 + ID3v2_HEADER_SIZE + 3; | 339 totlen += len + len1 + ID3v2_HEADER_SIZE + 3; |
337 av_free(buf); | 340 av_free(buf); |
338 } | 341 } |
339 } | 342 } |
340 if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { | |
341 totlen += strlen(LIBAVFORMAT_IDENT) + ID3v2_HEADER_SIZE + 2; | |
342 id3v2_put_ttag(s, LIBAVFORMAT_IDENT, strlen(LIBAVFORMAT_IDENT) + 1, | |
343 MKBETAG('T', 'S', 'S', 'E')); | |
344 } | |
345 | 343 |
346 cur_pos = url_ftell(s->pb); | 344 cur_pos = url_ftell(s->pb); |
347 url_fseek(s->pb, size_pos, SEEK_SET); | 345 url_fseek(s->pb, size_pos, SEEK_SET); |
348 id3v2_put_size(s, totlen); | 346 id3v2_put_size(s, totlen); |
349 url_fseek(s->pb, cur_pos, SEEK_SET); | 347 url_fseek(s->pb, cur_pos, SEEK_SET); |
350 | 348 |
351 return 0; | 349 return 0; |
352 } | 350 } |
353 | 351 |
354 AVOutputFormat mp3_muxer = { | 352 AVOutputFormat mp3_muxer = { |
355 "mp3", | 353 "mp3", |
356 NULL_IF_CONFIG_SMALL("MPEG audio layer 3"), | 354 NULL_IF_CONFIG_SMALL("MPEG audio layer 3"), |
357 "audio/x-mpeg", | 355 "audio/x-mpeg", |
358 "mp3", | 356 "mp3", |
359 0, | 357 0, |
360 CODEC_ID_MP3, | 358 CODEC_ID_MP3, |
361 CODEC_ID_NONE, | 359 CODEC_ID_NONE, |
362 mp3_write_header, | 360 mp3_write_header, |
363 mp3_write_packet, | 361 mp3_write_packet, |
364 mp3_write_trailer, | 362 mp3_write_trailer, |
365 .metadata_conv = ff_id3v2_metadata_conv, | 363 .metadata_conv = ff_id3v2_metadata_conv, |
366 }; | 364 }; |
367 #endif | 365 #endif |
OLD | NEW |