FFmpeg
mp3dec.c
Go to the documentation of this file.
1 /*
2  * MP3 demuxer
3  * Copyright (c) 2003 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/opt.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/dict.h"
25 #include "libavutil/mathematics.h"
26 #include "avformat.h"
27 #include "internal.h"
28 #include "avio_internal.h"
29 #include "demux.h"
30 #include "id3v2.h"
31 #include "id3v1.h"
32 #include "replaygain.h"
33 
34 #include "libavcodec/codec_id.h"
35 #include "libavcodec/mpegaudio.h"
37 
38 #define XING_FLAG_FRAMES 0x01
39 #define XING_FLAG_SIZE 0x02
40 #define XING_FLAG_TOC 0x04
41 #define XING_FLAC_QSCALE 0x08
42 
43 #define XING_TOC_COUNT 100
44 
45 
46 typedef struct {
47  AVClass *class;
49  int xing_toc;
50  int start_pad;
51  int end_pad;
52  int usetoc;
53  unsigned frames; /* Total number of frames in file */
54  unsigned header_filesize; /* Total number of bytes in the stream */
55  int is_cbr;
57 
58 enum CheckRet {
61 };
62 
63 static int check(AVIOContext *pb, int64_t pos, uint32_t *header);
64 
65 /* mp3 read */
66 
67 static int mp3_read_probe(const AVProbeData *p)
68 {
69  int max_frames, first_frames = 0;
70  int whole_used = 0;
71  int frames, ret;
72  int framesizes, max_framesizes;
73  uint32_t header;
74  const uint8_t *buf, *buf0, *buf2, *buf3, *end;
75 
76  buf0 = p->buf;
77  end = p->buf + p->buf_size - sizeof(uint32_t);
78  while (buf0 < end && !*buf0)
79  buf0++;
80 
81  max_frames = 0;
82  max_framesizes = 0;
83  buf = buf0;
84 
85  for (; buf < end; buf = buf2+1) {
86  buf2 = buf;
87  for (framesizes = frames = 0; buf2 < end; frames++) {
89  int header_emu = 0;
90  int available;
91 
92  header = AV_RB32(buf2);
94  if (ret != 0)
95  break;
96 
97  available = FFMIN(h.frame_size, end - buf2);
98  for (buf3 = buf2 + 4; buf3 < buf2 + available; buf3++) {
99  uint32_t next_sync = AV_RB32(buf3);
100  header_emu += (next_sync & MP3_MASK) == (header & MP3_MASK);
101  }
102  if (header_emu > 2)
103  break;
104  framesizes += h.frame_size;
105  if (available < h.frame_size) {
106  frames++;
107  break;
108  }
109  buf2 += h.frame_size;
110  }
111  max_frames = FFMAX(max_frames, frames);
112  max_framesizes = FFMAX(max_framesizes, framesizes);
113  if (buf == buf0) {
114  first_frames= frames;
115  if (buf2 == end + sizeof(uint32_t))
116  whole_used = 1;
117  }
118  }
119  // keep this in sync with ac3 probe, both need to avoid
120  // issues with MPEG-files!
121  if (first_frames>=7) return AVPROBE_SCORE_EXTENSION + 1;
122  else if (max_frames>200 && p->buf_size < 2*max_framesizes)return AVPROBE_SCORE_EXTENSION;
123  else if (max_frames>=4 && p->buf_size < 2*max_framesizes) return AVPROBE_SCORE_EXTENSION / 2;
124  else if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC) && 2*ff_id3v2_tag_len(buf0) >= p->buf_size)
126  else if (first_frames > 1 && whole_used) return 5;
127  else if (max_frames>=1 && p->buf_size < 10*max_framesizes) return 1;
128  else return 0;
129  //mpegps_mp3_unrecognized_format.mpg has max_frames=3
130 }
131 
133 {
134  int i;
135  MP3DecContext *mp3 = s->priv_data;
136  int fast_seek = s->flags & AVFMT_FLAG_FAST_SEEK;
137  int fill_index = (mp3->usetoc || fast_seek) && duration > 0;
138 
139  if (!filesize &&
140  (filesize = avio_size(s->pb)) <= 0) {
141  av_log(s, AV_LOG_WARNING, "Cannot determine file size, skipping TOC table.\n");
142  fill_index = 0;
143  filesize = 0;
144  }
145 
146  for (i = 0; i < XING_TOC_COUNT; i++) {
147  uint8_t b = avio_r8(s->pb);
148  if (fill_index)
149  av_add_index_entry(s->streams[0],
150  av_rescale(b, filesize, 256),
152  0, 0, AVINDEX_KEYFRAME);
153  }
154  if (fill_index)
155  mp3->xing_toc = 1;
156 }
157 
159  MPADecodeHeader *c, uint32_t spf)
160 {
161 #define LAST_BITS(k, n) ((k) & ((1 << (n)) - 1))
162 #define MIDDLE_BITS(k, m, n) LAST_BITS((k) >> (m), ((n) - (m) + 1))
163 
164  FFStream *const sti = ffstream(st);
165  uint16_t crc;
166  uint32_t v;
167 
168  char version[10];
169 
170  uint32_t peak = 0;
171  int32_t r_gain = INT32_MIN, a_gain = INT32_MIN;
172 
173  MP3DecContext *mp3 = s->priv_data;
174  static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
175  uint64_t fsize = avio_size(s->pb);
176  int64_t pos = avio_tell(s->pb);
177  fsize = fsize >= pos ? fsize - pos : 0;
178 
179  /* Check for Xing / Info tag */
180  avio_skip(s->pb, xing_offtbl[c->lsf == 1][c->nb_channels == 1]);
181  v = avio_rb32(s->pb);
182  mp3->is_cbr = v == MKBETAG('I', 'n', 'f', 'o');
183  if (v != MKBETAG('X', 'i', 'n', 'g') && !mp3->is_cbr)
184  return;
185 
186  v = avio_rb32(s->pb);
187  if (v & XING_FLAG_FRAMES)
188  mp3->frames = avio_rb32(s->pb);
189  if (v & XING_FLAG_SIZE)
190  mp3->header_filesize = avio_rb32(s->pb);
191  if (fsize && mp3->header_filesize) {
192  uint64_t min, delta;
193  min = FFMIN(fsize, mp3->header_filesize);
194  delta = FFMAX(fsize, mp3->header_filesize) - min;
195  if (fsize > mp3->header_filesize && delta > min >> 4) {
196  mp3->frames = 0;
198  "invalid concatenated file detected - using bitrate for duration\n");
199  } else if (delta > min >> 4) {
201  "filesize and duration do not match (growing file?)\n");
202  }
203  }
204  if (v & XING_FLAG_TOC)
206  (AVRational){spf, c->sample_rate},
207  st->time_base));
208  /* VBR quality */
209  if (v & XING_FLAC_QSCALE)
210  avio_rb32(s->pb);
211 
212  /* Encoder short version string */
213  memset(version, 0, sizeof(version));
214  avio_read(s->pb, version, 9);
215 
216  /* Info Tag revision + VBR method */
217  avio_r8(s->pb);
218 
219  /* Lowpass filter value */
220  avio_r8(s->pb);
221 
222  /* ReplayGain peak */
223  v = avio_rb32(s->pb);
224  peak = av_rescale(v, 100000, 1 << 23);
225 
226  /* Radio ReplayGain */
227  v = avio_rb16(s->pb);
228 
229  if (MIDDLE_BITS(v, 13, 15) == 1) {
230  r_gain = MIDDLE_BITS(v, 0, 8) * 10000;
231 
232  if (v & (1 << 9))
233  r_gain *= -1;
234  }
235 
236  /* Audiophile ReplayGain */
237  v = avio_rb16(s->pb);
238 
239  if (MIDDLE_BITS(v, 13, 15) == 2) {
240  a_gain = MIDDLE_BITS(v, 0, 8) * 10000;
241 
242  if (v & (1 << 9))
243  a_gain *= -1;
244  }
245 
246  /* Encoding flags + ATH Type */
247  avio_r8(s->pb);
248 
249  /* if ABR {specified bitrate} else {minimal bitrate} */
250  avio_r8(s->pb);
251 
252  /* Encoder delays */
253  v = avio_rb24(s->pb);
254  if (AV_RB32(version) == MKBETAG('L', 'A', 'M', 'E')
255  || AV_RB32(version) == MKBETAG('L', 'a', 'v', 'f')
256  || AV_RB32(version) == MKBETAG('L', 'a', 'v', 'c')
257  ) {
258 
259  mp3->start_pad = v>>12;
260  mp3-> end_pad = v&4095;
261  sti->start_skip_samples = mp3->start_pad + 528 + 1;
262  if (mp3->frames) {
263  sti->first_discard_sample = -mp3->end_pad + 528 + 1 + mp3->frames * (int64_t)spf;
264  sti->last_discard_sample = mp3->frames * (int64_t)spf;
265  }
266  if (!st->start_time)
268  (AVRational){1, c->sample_rate},
269  st->time_base);
270  av_log(s, AV_LOG_DEBUG, "pad %d %d\n", mp3->start_pad, mp3-> end_pad);
271  }
272 
273  /* Misc */
274  avio_r8(s->pb);
275 
276  /* MP3 gain */
277  avio_r8(s->pb);
278 
279  /* Preset and surround info */
280  avio_rb16(s->pb);
281 
282  /* Music length */
283  avio_rb32(s->pb);
284 
285  /* Music CRC */
286  avio_rb16(s->pb);
287 
288  /* Info Tag CRC */
289  crc = ffio_get_checksum(s->pb);
290  v = avio_rb16(s->pb);
291 
292  if (v == crc) {
293  ff_replaygain_export_raw(st, r_gain, peak, a_gain, 0);
294  av_dict_set(&st->metadata, "encoder", version, 0);
295  }
296 }
297 
299 {
300  uint32_t v;
301  MP3DecContext *mp3 = s->priv_data;
302 
303  /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
304  avio_seek(s->pb, base + 4 + 32, SEEK_SET);
305  v = avio_rb32(s->pb);
306  if (v == MKBETAG('V', 'B', 'R', 'I')) {
307  /* Check tag version */
308  if (avio_rb16(s->pb) == 1) {
309  /* skip delay and quality */
310  avio_skip(s->pb, 4);
311  mp3->header_filesize = avio_rb32(s->pb);
312  mp3->frames = avio_rb32(s->pb);
313  }
314  }
315 }
316 
317 /**
318  * Try to find Xing/Info/VBRI tags and compute duration from info therein
319  */
321 {
322  uint32_t v, spf;
324  int vbrtag_size = 0;
325  MP3DecContext *mp3 = s->priv_data;
326  int ret;
327 
329 
330  v = avio_rb32(s->pb);
331 
333  if (ret < 0)
334  return ret;
335  else if (ret == 0)
336  vbrtag_size = c.frame_size;
337  if (c.layer != 3)
338  return -1;
339 
340  spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */
341 
342  mp3->frames = 0;
343  mp3->header_filesize = 0;
344 
345  mp3_parse_info_tag(s, st, &c, spf);
346  mp3_parse_vbri_tag(s, st, base);
347 
348  if (!mp3->frames && !mp3->header_filesize)
349  return -1;
350 
351  /* Skip the vbr tag frame */
352  avio_seek(s->pb, base + vbrtag_size, SEEK_SET);
353 
354  if (mp3->frames)
355  st->duration = av_rescale_q(mp3->frames, (AVRational){spf, c.sample_rate},
356  st->time_base);
357  if (mp3->header_filesize && mp3->frames && !mp3->is_cbr)
358  st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf);
359 
360  return 0;
361 }
362 
364 {
365  FFFormatContext *const si = ffformatcontext(s);
366  MP3DecContext *mp3 = s->priv_data;
367  AVStream *st;
368  FFStream *sti;
369  int64_t off;
370  int ret;
371  int i;
372 
373  s->metadata = si->id3v2_meta;
374  si->id3v2_meta = NULL;
375 
376  st = avformat_new_stream(s, NULL);
377  if (!st)
378  return AVERROR(ENOMEM);
379  sti = ffstream(st);
380 
384  st->start_time = 0;
385 
386  // lcm of all mp3 sample rates
387  avpriv_set_pts_info(st, 64, 1, 14112000);
388 
389  ffiocontext(s->pb)->maxsize = -1;
390  off = avio_tell(s->pb);
391 
392  if (!av_dict_count(s->metadata))
393  ff_id3v1_read(s);
394 
395  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
396  mp3->filesize = avio_size(s->pb);
397 
398  if (mp3_parse_vbr_tags(s, st, off) < 0)
399  avio_seek(s->pb, off, SEEK_SET);
400 
401  ret = ff_replaygain_export(st, s->metadata);
402  if (ret < 0)
403  return ret;
404 
405  ret = ffio_ensure_seekback(s->pb, 64 * 1024 + MPA_MAX_CODED_FRAME_SIZE + 4);
406  if (ret < 0)
407  return ret;
408 
409  off = avio_tell(s->pb);
410  for (i = 0; i < 64 * 1024; i++) {
411  uint32_t header, header2;
412  int frame_size;
413  frame_size = check(s->pb, off + i, &header);
414  if (frame_size > 0) {
415  ret = check(s->pb, off + i + frame_size, &header2);
416  if (ret >= 0 && (header & MP3_MASK) == (header2 & MP3_MASK))
417  break;
418  } else if (frame_size == CHECK_SEEK_FAILED) {
419  av_log(s, AV_LOG_ERROR, "Failed to find two consecutive MPEG audio frames.\n");
420  return AVERROR_INVALIDDATA;
421  }
422  }
423  if (i == 64 * 1024) {
424  off = avio_seek(s->pb, off, SEEK_SET);
425  } else {
426  av_log(s, i > 0 ? AV_LOG_INFO : AV_LOG_VERBOSE, "Skipping %d bytes of junk at %"PRId64".\n", i, off);
427  off = avio_seek(s->pb, off + i, SEEK_SET);
428  }
429  if (off < 0)
430  return off;
431 
432  // the seek index is relative to the end of the xing vbr headers
433  for (int i = 0; i < sti->nb_index_entries; i++)
434  sti->index_entries[i].pos += off;
435 
436  /* the parameters will be extracted from the compressed bitstream */
437  return 0;
438 }
439 
440 #define MP3_PACKET_SIZE 1024
441 
443 {
444  MP3DecContext *mp3 = s->priv_data;
445  int ret, size;
446  int64_t pos;
447 
449  pos = avio_tell(s->pb);
450  if (mp3->filesize > ID3v1_TAG_SIZE && pos < mp3->filesize)
451  size= FFMIN(size, mp3->filesize - pos);
452 
453  ret = av_get_packet(s->pb, pkt, size);
454  if (ret <= 0) {
455  if(ret<0)
456  return ret;
457  return AVERROR_EOF;
458  }
459 
461  pkt->stream_index = 0;
462 
463  return ret;
464 }
465 
466 #define SEEK_WINDOW 4096
467 
468 static int check(AVIOContext *pb, int64_t pos, uint32_t *ret_header)
469 {
470  int64_t ret = avio_seek(pb, pos, SEEK_SET);
471  uint8_t header_buf[4];
472  unsigned header;
473  MPADecodeHeader sd;
474  if (ret < 0)
475  return CHECK_SEEK_FAILED;
476 
477  ret = avio_read(pb, &header_buf[0], 4);
478  /* We should always find four bytes for a valid mpa header. */
479  if (ret < 4)
480  return CHECK_SEEK_FAILED;
481 
482  header = AV_RB32(&header_buf[0]);
483  if (ff_mpa_check_header(header) < 0)
484  return CHECK_WRONG_HEADER;
485  if (avpriv_mpegaudio_decode_header(&sd, header) == 1)
486  return CHECK_WRONG_HEADER;
487 
488  if (ret_header)
489  *ret_header = header;
490  return sd.frame_size;
491 }
492 
493 static int64_t mp3_sync(AVFormatContext *s, int64_t target_pos, int flags)
494 {
495  int dir = (flags&AVSEEK_FLAG_BACKWARD) ? -1 : 1;
496  int64_t best_pos;
497  int best_score, i, j;
498  int64_t ret;
499 
500  avio_seek(s->pb, FFMAX(target_pos - SEEK_WINDOW, 0), SEEK_SET);
501  ret = avio_seek(s->pb, target_pos, SEEK_SET);
502  if (ret < 0)
503  return ret;
504 
505 #define MIN_VALID 3
506  best_pos = target_pos;
507  best_score = 999;
508  for (i = 0; i < SEEK_WINDOW; i++) {
509  int64_t pos = target_pos + (dir > 0 ? i - SEEK_WINDOW/4 : -i);
510  int64_t candidate = -1;
511  int score = 999;
512 
513  if (pos < 0)
514  continue;
515 
516  for (j = 0; j < MIN_VALID; j++) {
517  ret = check(s->pb, pos, NULL);
518  if (ret < 0) {
519  if (ret == CHECK_WRONG_HEADER) {
520  break;
521  } else if (ret == CHECK_SEEK_FAILED) {
522  av_log(s, AV_LOG_ERROR, "Could not seek to %"PRId64".\n", pos);
523  return AVERROR(EINVAL);
524  }
525  }
526  if ((target_pos - pos)*dir <= 0 && FFABS(MIN_VALID/2-j) < score) {
527  candidate = pos;
528  score = FFABS(MIN_VALID/2-j);
529  }
530  pos += ret;
531  }
532  if (best_score > score && j == MIN_VALID) {
533  best_pos = candidate;
534  best_score = score;
535  if(score == 0)
536  break;
537  }
538  }
539 
540  return avio_seek(s->pb, best_pos, SEEK_SET);
541 }
542 
543 static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
544  int flags)
545 {
546  FFFormatContext *const si = ffformatcontext(s);
547  MP3DecContext *mp3 = s->priv_data;
548  AVIndexEntry *ie, ie1;
549  AVStream *st = s->streams[0];
550  FFStream *const sti = ffstream(st);
551  int64_t best_pos;
552  int fast_seek = s->flags & AVFMT_FLAG_FAST_SEEK;
554 
555  if (filesize <= 0) {
556  int64_t size = avio_size(s->pb);
557  if (size > 0 && size > si->data_offset)
558  filesize = size - si->data_offset;
559  }
560 
561  if (mp3->xing_toc && (mp3->usetoc || (fast_seek && !mp3->is_cbr))) {
562  int64_t ret = av_index_search_timestamp(st, timestamp, flags);
563 
564  // NOTE: The MP3 TOC is not a precise lookup table. Accuracy is worse
565  // for bigger files.
566  av_log(s, AV_LOG_WARNING, "Using MP3 TOC to seek; may be imprecise.\n");
567 
568  if (ret < 0)
569  return ret;
570 
571  ie = &sti->index_entries[ret];
572  } else if (fast_seek && st->duration > 0 && filesize > 0) {
573  if (!mp3->is_cbr)
574  av_log(s, AV_LOG_WARNING, "Using scaling to seek VBR MP3; may be imprecise.\n");
575 
576  ie = &ie1;
577  timestamp = av_clip64(timestamp, 0, st->duration);
578  ie->timestamp = timestamp;
579  ie->pos = av_rescale(timestamp, filesize, st->duration) + si->data_offset;
580  } else {
581  return -1; // generic index code
582  }
583 
584  best_pos = mp3_sync(s, ie->pos, flags);
585  if (best_pos < 0)
586  return best_pos;
587 
588  if (mp3->is_cbr && ie == &ie1 && mp3->frames && mp3->header_filesize > 0) {
589  int frame_duration = av_rescale(st->duration, 1, mp3->frames);
590  ie1.timestamp = frame_duration * av_rescale(best_pos - si->data_offset, mp3->frames, mp3->header_filesize);
591  }
592 
594  return 0;
595 }
596 
597 static const AVOption options[] = {
598  { "usetoc", "use table of contents", offsetof(MP3DecContext, usetoc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM},
599  { NULL },
600 };
601 
602 static const AVClass demuxer_class = {
603  .class_name = "mp3",
604  .item_name = av_default_item_name,
605  .option = options,
606  .version = LIBAVUTIL_VERSION_INT,
607  .category = AV_CLASS_CATEGORY_DEMUXER,
608 };
609 
611  .p.name = "mp3",
612  .p.long_name = NULL_IF_CONFIG_SMALL("MP2/3 (MPEG audio layer 2/3)"),
613  .p.flags = AVFMT_GENERIC_INDEX,
614  .p.extensions = "mp2,mp3,m2a,mpa", /* XXX: use probe */
615  .p.priv_class = &demuxer_class,
616  .p.mime_type = "audio/mpeg",
617  .read_probe = mp3_read_probe,
618  .read_header = mp3_read_header,
619  .read_packet = mp3_read_packet,
620  .read_seek = mp3_seek,
621  .priv_data_size = sizeof(MP3DecContext),
622 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
ID3v1_TAG_SIZE
#define ID3v1_TAG_SIZE
Definition: id3v1.h:27
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
xing_offtbl
static const uint8_t xing_offtbl[2][2]
Definition: mp3enc.c:140
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
XING_FLAC_QSCALE
#define XING_FLAC_QSCALE
Definition: mp3dec.c:41
ffiocontext
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
Definition: avio_internal.h:81
demuxer_class
static const AVClass demuxer_class
Definition: mp3dec.c:602
mp3_read_packet
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: mp3dec.c:442
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:127
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
ff_replaygain_export
int ff_replaygain_export(AVStream *st, AVDictionary *metadata)
Parse replaygain tags and export them as per-stream side data.
Definition: replaygain.c:94
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
av_dict_count
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:39
MP3DecContext
Definition: mp3dec.c:46
int64_t
long long int64_t
Definition: coverity.c:34
id3v2.h
FFStream::first_discard_sample
int64_t first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
Definition: internal.h:229
ff_replaygain_export_raw
int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp, int32_t ag, uint32_t ap)
Export already decoded replaygain values as per-stream side data.
Definition: replaygain.c:69
mpegaudiodecheader.h
ff_mp3_demuxer
const FFInputFormat ff_mp3_demuxer
Definition: mp3dec.c:610
ff_id3v1_read
void ff_id3v1_read(AVFormatContext *s)
Read an ID3v1 tag.
Definition: id3v1.c:278
AVOption
AVOption.
Definition: opt.h:429
b
#define b
Definition: input.c:41
MPADecodeHeader
Definition: mpegaudiodecheader.h:47
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
base
uint8_t base
Definition: vp3data.h:128
mathematics.h
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
MP3_MASK
#define MP3_MASK
Definition: mpegaudiodecheader.h:33
id3v1.h
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:323
avpriv_update_cur_dts
void avpriv_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
Definition: seek.c:37
ffio_get_checksum
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:583
AVIndexEntry
Definition: avformat.h:602
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:610
MIDDLE_BITS
#define MIDDLE_BITS(k, m, n)
XING_FLAG_FRAMES
#define XING_FLAG_FRAMES
Definition: mp3dec.c:38
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:867
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: seek.c:122
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:480
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:447
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:807
read_xing_toc
static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration)
Definition: mp3dec.c:132
av_clip64
#define av_clip64
Definition: common.h:103
MP3DecContext::filesize
int64_t filesize
Definition: mp3dec.c:48
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:761
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
avpriv_mpegaudio_decode_header
int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
Definition: mpegaudiodecheader.c:34
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:595
SEEK_WINDOW
#define SEEK_WINDOW
Definition: mp3dec.c:466
codec_id.h
duration
int64_t duration
Definition: movenc.c:65
MP3_PACKET_SIZE
#define MP3_PACKET_SIZE
Definition: mp3dec.c:440
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
frame_size
int frame_size
Definition: mxfenc.c:2429
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVIndexEntry::timestamp
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
Definition: avformat.h:604
MP3DecContext::end_pad
int end_pad
Definition: mp3dec.c:51
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
FFFormatContext::data_offset
int64_t data_offset
offset of the first packet
Definition: internal.h:89
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
MP3DecContext::xing_toc
int xing_toc
Definition: mp3dec.c:49
XING_FLAG_TOC
#define XING_FLAG_TOC
Definition: mp3dec.c:40
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
AV_CLASS_CATEGORY_DEMUXER
@ AV_CLASS_CATEGORY_DEMUXER
Definition: log.h:33
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
FFFormatContext
Definition: internal.h:64
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:325
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVSEEK_FLAG_BACKWARD
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:2498
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:787
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:190
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
options
Definition: swscale.c:42
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:461
FFIOContext::maxsize
int64_t maxsize
max filesize, used to limit allocations
Definition: avio_internal.h:46
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:122
MP3DecContext::start_pad
int start_pad
Definition: mp3dec.c:50
mp3_parse_vbr_tags
static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
Try to find Xing/Info/VBRI tags and compute duration from info therein.
Definition: mp3dec.c:320
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:754
ff_mpa_check_header
static int ff_mpa_check_header(uint32_t header)
Definition: mpegaudiodecheader.h:62
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
FFStream
Definition: internal.h:132
FFStream::last_discard_sample
int64_t last_discard_sample
The sample after last sample that is intended to be discarded after first_discard_sample.
Definition: internal.h:236
mp3_read_header
static int mp3_read_header(AVFormatContext *s)
Definition: mp3dec.c:363
MP3DecContext::frames
unsigned frames
Definition: mp3dec.c:53
size
int size
Definition: twinvq_data.h:10344
CHECK_SEEK_FAILED
@ CHECK_SEEK_FAILED
Definition: mp3dec.c:60
ID3v2_DEFAULT_MAGIC
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition: id3v2.h:35
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
XING_FLAG_SIZE
#define XING_FLAG_SIZE
Definition: mp3dec.c:39
ffio_init_checksum
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:591
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
header
static const uint8_t header[24]
Definition: sdr2.c:68
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1023
XING_TOC_COUNT
#define XING_TOC_COUNT
Definition: mp3dec.c:43
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
FFStream::start_skip_samples
int64_t start_skip_samples
If not 0, the number of samples that should be skipped from the start of the stream (the samples are ...
Definition: internal.h:221
version
version
Definition: libkvazaar.c:321
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
MP3DecContext::is_cbr
int is_cbr
Definition: mp3dec.c:55
filesize
static int64_t filesize(AVIOContext *pb)
Definition: ffmpeg_mux.c:51
PROBE_BUF_MAX
#define PROBE_BUF_MAX
Definition: internal.h:34
AVFMT_FLAG_FAST_SEEK
#define AVFMT_FLAG_FAST_SEEK
Enable fast, but inaccurate seeks for some formats.
Definition: avformat.h:1470
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
avio_internal.h
available
if no frame is available
Definition: filter_design.txt:166
mp3_parse_info_tag
static void mp3_parse_info_tag(AVFormatContext *s, AVStream *st, MPADecodeHeader *c, uint32_t spf)
Definition: mp3dec.c:158
mp3_seek
static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: mp3dec.c:543
delta
float delta
Definition: vorbis_enc_data.h:430
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
mp3_sync
static int64_t mp3_sync(AVFormatContext *s, int64_t target_pos, int flags)
Definition: mp3dec.c:493
mp3_read_probe
static int mp3_read_probe(const AVProbeData *p)
Definition: mp3dec.c:67
demux.h
ff_crcA001_update
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:577
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
mpegaudio.h
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:91
ff_id3v2_tag_len
int ff_id3v2_tag_len(const uint8_t *buf)
Get the length of an ID3v2 tag.
Definition: id3v2.c:158
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:746
CheckRet
CheckRet
Definition: mp3dec.c:58
pos
unsigned int pos
Definition: spdifenc.c:414
avformat.h
dict.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
mp3_parse_vbri_tag
static void mp3_parse_vbri_tag(AVFormatContext *s, AVStream *st, int64_t base)
Definition: mp3dec.c:298
MP3DecContext::header_filesize
unsigned header_filesize
Definition: mp3dec.c:54
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:603
AVSTREAM_PARSE_FULL_RAW
@ AVSTREAM_PARSE_FULL_RAW
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition: avformat.h:597
AVPacket::stream_index
int stream_index
Definition: packet.h:541
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
MP3DecContext::usetoc
int usetoc
Definition: mp3dec.c:52
options
static const AVOption options[]
Definition: mp3dec.c:597
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:188
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:356
check
static int check(AVIOContext *pb, int64_t pos, uint32_t *header)
Definition: mp3dec.c:468
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
FFInputFormat
Definition: demux.h:42
int32_t
int32_t
Definition: audioconvert.c:56
replaygain.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2070
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:797
MPA_MAX_CODED_FRAME_SIZE
#define MPA_MAX_CODED_FRAME_SIZE
Definition: mpegaudio.h:40
MIN_VALID
#define MIN_VALID
ff_id3v2_match
int ff_id3v2_match(const uint8_t *buf, const char *magic)
Detect ID3v2 Header.
Definition: id3v2.c:145
av_index_search_timestamp
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: seek.c:245
CHECK_WRONG_HEADER
@ CHECK_WRONG_HEADER
Definition: mp3dec.c:59
min
float min
Definition: vorbis_enc_data.h:429