1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

131 Commits

Author SHA1 Message Date
Chris Cunningham
ab87df9a47 avformat/mp3dec: fix msan warning when verifying mpa header
MPEG Audio frame header must be 4 bytes. If we fail to read
4 bytes bail early to avoid Use-of-uninitialized-value msan error.
Reference https://crbug.com/666874.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-15 04:36:28 +01:00
Michael Niedermayer
5fd73948bb avformat/mp3dec: Increase probe score slightly when the whole data from begin to end is mp3
Improves score for 1000-frames-of-noise-encoded-with-lame.mp3 without file extension

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-11 02:58:00 +02:00
Derek Buitenhuis
6f69f7a8bf Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
  lavf: replace AVStream.codec with AVStream.codecpar

This has been a HUGE effort from:
    - Derek Buitenhuis <derek.buitenhuis@gmail.com>
    - Hendrik Leppkes <h.leppkes@gmail.com>
    - wm4 <nfxjfg@googlemail.com>
    - Clément Bœsch <clement@stupeflix.com>
    - James Almer <jamrial@gmail.com>
    - Michael Niedermayer <michael@niedermayer.cc>
    - Rostislav Pehlivanov <atomnuker@gmail.com>

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-10 20:59:55 +01:00
Moritz Barsnick
8a90e0fd21 lavf/mp3dec: avoid printing useless message in default log level
"Skipping 0 bytes of junk" is useless to the user, and essentially
indicates a NOP. At 0 bytes, this message is now pushed back to
the verbose log level.

Signed-off-by: Moritz Barsnick <barsnick@gmx.net>
2016-03-08 17:02:32 +01:00
Derek Buitenhuis
1c9215e580 lavf/mp3: Properly check return values of seeks and reads while reading the header
Fixes large amounts of seeking past EOF, which could be extremely
slow over a network.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-28 13:57:35 +00:00
Anton Khirnov
9200514ad8 lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.

In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.

There are multiple important problems with this approach:
    - the fields in AVCodecContext are in general one of
        * stream parameters
        * codec options
        * codec state
      However, it's not clear which ones are which. It is consequently
      unclear which fields are a demuxer allowed to set or a muxer allowed to
      read. This leads to erratic behaviour depending on whether decoding or
      encoding is being performed or not (and whether it uses the AVStream
      embedded codec context).
    - various synchronization issues arising from the fact that the same
      context is used by several different APIs (muxers/demuxers,
      parsers, bitstream filters and encoders/decoders) simultaneously, with
      there being no clear rules for who can modify what and the different
      processes being typically delayed with respect to each other.
    - avformat_find_stream_info() making it necessary to support opening
      and closing a single codec context multiple times, thus
      complicating the semantics of freeing various allocated objects in the
      codec context.

Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2016-02-23 17:01:58 +01:00
Michael Niedermayer
dbfb2c1abf avformat/mp3dec: Remove unused variable
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-01 21:21:10 +01:00
Hendrik Leppkes
a78d9abee0 Merge commit '72d658766e6ccf198317dffd6499c5e288847a1c'
* commit '72d658766e6ccf198317dffd6499c5e288847a1c':
  mp3dec: replace avpriv_mpa_decode_header with avpriv_mpegaudio_decode_header

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-01 16:57:40 +01:00
Hendrik Leppkes
1e96b151fa Merge commit '955aec3c7c7be39b659197e1ec379a09f2b7c41c'
* commit '955aec3c7c7be39b659197e1ec379a09f2b7c41c':
  mpegaudiodecheader: check the header in avpriv_mpegaudio_decode_header

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-01 16:47:27 +01:00
Anton Khirnov
72d658766e mp3dec: replace avpriv_mpa_decode_header with avpriv_mpegaudio_decode_header
The latter does not require a full AVCodecContext and still provides all
the functionality needed here.
2015-12-12 21:26:00 +01:00
Anton Khirnov
955aec3c7c mpegaudiodecheader: check the header in avpriv_mpegaudio_decode_header
Almost all the places from which this function is called already check
the header manually and in the two that don't (the mp3 muxer) the check
should not cause any problems.
2015-12-12 21:25:42 +01:00
Clément Bœsch
43ecec0f03 avformat: use AV_OPT_TYPE_BOOL in a bunch of places 2015-12-04 15:43:33 +01:00
Chris Cunningham
5e6ce28dab avformat/mp3dec: prefer "fast_seek" to TOC seek for CBR files.
"Fast seek" uses linear interpolation to find the position of the
requested seek time. For CBR this is more direct than using the
mp3 TOC and bypassing the TOC avoids problems with TOC precision.
(see https://crbug.com/545914#c13)

For VBR, fast seek is not precise, so continue to prefer the TOC
when available (the lesser of two evils).

Also, some re-ordering of the logic in mp3_seek to simplify and
give usetoc=1 precedence over fastseek flag.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2015-12-02 11:02:27 +01:00
wm4
de1b1a7da9 avformat/mp3dec: improve junk skipping heuristic
Commit 2b3e9bbfb5 caused problems for a
certain API user:

https://code.google.com/p/chromium/issues/detail?id=537725
https://code.google.com/p/chromium/issues/detail?id=542032

The problem seems rather arbitrary, because if there's junk, anything
can happen. In this case, the imperfect junk skipping just caused it to
read different junk, from what I can see.

We can improve the accuracy of junk detection by a lot by checking if 2
consecutive frames use the same configuration. While in theory it might
be completely fine for the 1st frame to have a different format than the
2nd frame, it's exceedingly unlikely, and I can't think of a legitimate
use-case.

This is approximately the same mpg123 does for junk skipping. The
set of compared header bits is the same as the libavcodec mp3 parser
uses for similar purposes.
2015-10-20 12:17:21 +02:00
Andy Wu
c43bd08f8b avformat/mp3dec: Make MP3 seek fast
When AVFMT_FLAG_FAST_SEEK is specified, make MP3 seek operation as
fast as possible.

When no "-usetoc" is specified, the default operation is using TOC
if available; otherwise, uses linear interpolation. This is useful
when seeking a large MP3 file with no TOC available. One example is
Podcast, many MP3 files are large, but no CBR/VBR tags. Most of
them are actually CBR. Even in VBR cases, this option sacrifices the
accuracy of playback time in exchange for responsiveness.
2015-09-05 18:32:58 +02:00
Michael Niedermayer
cb53db144c avformat/mp3dec: Rename sync() function to avoid build failure on android
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-20 02:41:44 +02:00
James Almer
2db8c42ddc avformat/mp3dec: remove unused variable
Signed-off-by: James Almer <jamrial@gmail.com>
2015-07-19 17:47:28 -03:00
Michael Niedermayer
4df66c7cd6 avformat/mp3dec: split position sync code out
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-19 19:31:08 +02:00
Ganesh Ajjanagadde
f6870495e1 avformat: increase first_frames threshold for mp3,ac3
Fixes Ticket4723

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-18 04:52:49 +02:00
Luca Barbato
a5a6a786bf mp3: Forward seeking errors
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2015-07-13 21:59:53 +02:00
Michael Niedermayer
7da1f00e79 Merge commit 'c1d647b15afa69fa70f999a9ddcb98346409fb4d'
* commit 'c1d647b15afa69fa70f999a9ddcb98346409fb4d':
  mp3: Make the seek more robust

Conflicts:
	libavformat/mp3dec.c

Mostly not merged

See: b6267901c4 and various later commits

The bug is also not reproducable in FFmpeg

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-12 16:01:31 +02:00
Luca Barbato
c1d647b15a mp3: Make the seek more robust
Try to parse up to 4 packets to find the closest packet.

Reported-By: jan.schlueter@ofai.at
2015-07-11 18:45:45 +02:00
Michael Niedermayer
041aa800f2 avformat/mp3dec: Remove the ID3v1 tag removial code
The code is simply broken, the read packets are not aligned to
the mp3 frames, the file end or the id3 tag thus this simply
cannot reliably find the ID3v1 tag to remove it

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-24 02:52:11 +02:00
Carl Eugen Hoyos
3323c5f353 Remove a few occurences of "long long" from the libraries. 2015-06-13 09:28:41 +02:00
Michael Niedermayer
f722009ad9 avformat/mp3dec: Ensure the buffer is large enough to avoid seeks from the first frame search
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-27 17:06:24 +02:00
wm4
2b3e9bbfb5 avformat/mp3: skip junk at the beginning of mp3 files
Apparently it can happen that a mp3 file has junk data between id3 tag
and actual mp3 data. Skip this to avoid outputting nonsense timestamps.
(Two packets had the same timestamps, because the mp3 parser failed to
compute a frame duration.)

In this case, the junk consisted of 1044 bytes of zero, which
incidentally is the same size as normal mp3 frames in this stream. I
suspect the mp3 was edited with some tool which wiped the Xing/LAME
headers. Data near the end of the file suggests it was encoded with
"LAME3.97", but the normal Xing/LAME headers are missing. So this could
be "normal". mpg123 also attempts to skip at least 64KB of junk data by
scanning for headers.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-27 15:50:04 +02:00
wm4
537ab68053 avformat/mp3: large id3 tags break concatenated file detection
If the file size is much larger than what is indicated in the XING
header, the demuxer assumes it's a concatenated file, and throws away
the (presumably) incorrect duration information. Unfortunately, this
also triggers if the id3 tags are very large (embedded pictures and
such). Then the half-baked heuristic not only breaks the duration
display, but also gapless audio.

Fix it by subtracting the size of the headers (the check is off by some
bytes, but that doesn't matter at all). Note that there could be an
arbitrary amount of tags _after_ the mp3 data, but hopefully these are
not too large to trigger the heuristic in practice.

Also add a warning when this happens.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-24 15:06:54 +02:00
wm4
748d4816d9 avformat: add AVFMT_FLAG_FASTSEEK, use it for mp3
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-22 22:27:05 +02:00
wm4
58fade2c68 avformat/mp3dec: make generic index mode the default
It's the most useful mode, because it seeks accurately, and does not
break features like gapless audio.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-22 14:41:57 +02:00
wm4
c3a73666ad avformat/mp3dec: allow enabling generic seek mode
"-usetoc 2" now invokes the generic seek and indexing mode. This mode
skips data until the seek target is reached, and this is exact. It also
makes gapless audio actually work if a seek past the start of the file
is involved.

Change the fate-gapless-mp3 test to use the new mode, and move the old
one to fate-gapless-mp3-toc (since the test forces use of the Xing TOC).
The new mode has a different result for the seek - this result is
actually correct.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-22 14:33:02 +02:00
wm4
066b92e91d avformat/mp3dec: use the common mechanism for skipping samples
The mp2 seek test results change. Whether to skip samples if the file
had no LAME gapless tags was inconsistent. When seeking to the start
of the file, 529 samples were skipped, but when playing from start,
nothing was skipped. This commit changes the behavior on seek to skip
nothing.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-22 14:16:35 +02:00
Michael Niedermayer
ecf34e8fc2 avformat/mp3dec: Adjust returned timestamp in the CBR seeking case
With this the returned timestamp should match the packet instead of
the requested timestamp, which may lay between  packets

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-21 01:31:28 +02:00
wm4
92eef26e67 avformat/mp3dec: fix gapless audio when seeking in CBR mode
Removing a bunch of questionable hacks makes it work. These hacks
apparently try to make concatenated mp3s with Lame headers seekable,
which doesn't make too much sense anyway. The main change is that we
trust the Xing header file size field now (the same field is used for
seeking with Xing TOC). Note that a mp3 might contain an unknown number
of unsupported additional tags, so we can't reliably compute this size
manually.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-17 17:48:22 +02:00
wm4
3163083f7b avformat/mp3dec: offset seek index to end of vbr headers
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-15 13:25:08 +02:00
wm4
ddd429fab6 Revert "avformat/mp3dec: offset seek index to end of id3v2 tag"
This reverts commit 8b76c0eb56.

It was slightly incorrect; the next commit fixes it.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-15 13:25:07 +02:00
Michael Niedermayer
a742a0536d avformat/mp3dec: Allow forcing the use of the xing TOC for CBR files
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-15 13:25:07 +02:00
wm4
8b76c0eb56 avformat/mp3dec: offset seek index to end of id3v2 tag
The Xing index won't account for the id3 tag - it's relative to the
headers.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-03-31 23:22:07 +02:00
Michael Niedermayer
2d37c57f3e Merge commit 'fe99c52fa99e44961a09cd1324aefd492b797fc8'
* commit 'fe99c52fa99e44961a09cd1324aefd492b797fc8':
  mp3: Properly use AVCodecContext API

Conflicts:
	libavformat/mp3dec.c

See: 6ad42b3e15
See: b851bc20c6
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-03-11 20:21:16 +01:00
Vittorio Giovara
fe99c52fa9 mp3: Properly use AVCodecContext API
Rather than having an unitialized context on the stack, allocate it with
defaults and free it when unneeded.

CC: libav-stable@libav.org
2015-03-11 17:57:56 +00:00
Michael Niedermayer
b851bc20c6 avformat/mp3dec: Check for avcodec_alloc_context3() failure
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-26 20:11:19 +01:00
Michael Niedermayer
6ad42b3e15 avformat/mp3dec: properly allocate dummy AVCodecContext
Fixes (harmless) use of uninitialized variable

Found-by: jamrial
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-26 20:02:23 +01:00
Michael Niedermayer
2924514721 Merge commit '9deaec782810d098bca11c9332fab2d2f4c5fb78'
* commit '9deaec782810d098bca11c9332fab2d2f4c5fb78':
  lavf: move internal fields from public to internal context

Conflicts:
	libavformat/avformat.h
	libavformat/internal.h
	libavformat/mux.c
	libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-11 02:47:54 +01:00
Michael Niedermayer
8ddfc00ab7 avformat/mp3dec: Name the dummy variable as what it is, to avoid confusion
Found-by: nattyzs <nattyzs@163.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-14 20:08:13 +01:00
Luca Barbato
4fd7e63c87 mp3: Tweak the probe scores
Having more than 10 consecutive frames decoded as mp3 should be
considered a clear signal that the sample is mp3 and not mpegps.

Reported-By: Florian Iragne <florian@iragne.fr>
CC: libav-stable@libav.org
2014-12-07 21:50:47 +01:00
Michael Niedermayer
0b75b6c3cd avformat/mp3dec: avoid seeking to negative positions
Fixes Ticket4038

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-18 04:04:37 +01:00
Michael Niedermayer
279b2a4deb avformat/mp3dec: also accept Lavc as shortname to read delays
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-24 18:06:26 +02:00
Michael Niedermayer
899d3706d8 Merge commit '99143140dea12363af680d02e23cb42cfe191679'
* commit '99143140dea12363af680d02e23cb42cfe191679':
  mp3dec: fix reading the Xing tag

Conflicts:
	libavformat/mp3dec.c

See: 19ff479f69
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-24 12:49:53 +02:00
Anton Khirnov
99143140de mp3dec: fix reading the Xing tag
The quality scale field is only supposed to be present if the fourth bit
is set. In practice, lame always sets it, but other tools might not.

CC:libav-stable@libav.org
2014-10-24 09:03:16 +02:00
wm4
6c7f1155bb avformat/mp3dec: avoid early EOF with concatenated gapless mp3s
Consider a file created with something like:

    cat file1.mp3 file2.mp3 > result.mp3

Then if file2.mp3 has gapless information, result.mp3 would stop playing
something in the middle. This happens because the gapless info directs
the decoder to discard all samples after a certain position. To make
matters worse, the gapless info of file2.mp3 will be used when playing
the file1.mp3 part, because the gapless info is located at the end of
the file.

While handling concatenated gapless files correctly would be insane and
a lot of effort (especially without scanning the whole file on opening),
it's easy to prevent at least early EOF. Playback will happen to work,
even if it's slightly broken.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-21 14:57:12 +02:00
wm4
d87fe2687f avformat/mp3dec: fix gapless audio support
The code already had skipping of initial padding, but discarding
trailing frame padding was missing.

This is somewhat questionable, because it will make the decoder discard
any data after the declared file size in the LAME header. But note that
skipping full frames at the end of the stream is required. Encoders
actually create such files.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-09-20 19:46:25 +02:00