Commit Graph

911 Commits

Author SHA1 Message Date
James Almer 3b4e9a31ea avformat/matroskadec: don't rescale mastering display values
Simplifies code.

Signed-off-by: James Almer <jamrial@gmail.com>
2019-10-05 22:37:41 -03:00
Andreas Rheinhardt 581419ea39 avformat/matroskadec: Fix demuxing ProRes
The structure of a ProRes frame in mov/mp4 is that of a typical atom:
First a 32 bit BE size field, then a tag detailling the content. Said
size field includes the eight bytes of the atom header.

This header is actually redundant, as the size of the atom is already
known from the containing atom. It is therefore stripped away when muxed
into Matroska and so the Matroska demuxer has to recreate upon demuxing.
But it did not account for the fact that the size field includes the
size of the header and this can lead to problems when a decoder uses the
in-band size field.

Fixes ticket #8210.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-10-04 00:06:30 -03:00
Michael Niedermayer fccc37ca85 repeat an even number of characters in occured
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-16 00:04:18 +02:00
James Almer 3b3150c45f avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays
Speeds up the process considerably.

Fixes ticket #8109.

Suggested-by: nevcairiel
Suggested-by: cehoyos
Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-04 10:08:17 -03:00
James Almer f34aabfbae avformat/matroskadec: use proper types for some EbmlSyntax fields
Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-04 10:07:13 -03:00
Andreas Rheinhardt c294f38c91 avformat/matroskadec: Fix seeking
matroska_reset_status (a function that is used during seeking (among
other things)) used an int for the return value of avio_seek which
returns an int64_t. Checking the return value then indicated an error
even though the seek was successfull for targets in the range of
2GB-4GB, 6GB-8GB, ... This error implied that the status hasn't been
reset and in particular, the old level was still considered to be in
force, so that ebml_parse returned errors because the newly parsed
elements were of course not contained in the previously active and still
wrongly considered active master element any more.

Addresses ticket #8084.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-08-16 21:33:54 -03:00
Andreas Rheinhardt 9869e21776 matroskadec: Remove redundant const
The typedef used to define EbmlSyntax already includes a const qualifier
so that it is unnecessary to include another const qualifier in future
definitions and declarations. Given that MSVC warns about this, this
commit removes these redundant const qualifiers.

Suggested-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-18 22:26:00 +02:00
Andreas Rheinhardt ab4795a085 matroskadec: Add sizes to forward declarations
Unknown-length elements end when an element not allowed in them, but
allowed at a higher level is encountered. In order to check for this,
c1abd95a added a pointer to every syntax level's parent to each
EbmlSyntax. Given that the parent must of course also reference the
child in order to be able to enter said child level, one needs to use
forward declarations.
These forward declarations constitute tentative definitions and tentative
definitions with internal linkage (like our syntaxes) must not be an
incomplete type. Yet they were an incomplete type and while GCC and
Clang did not even warn about this (on default warning levels), it
broke compilation with MSVC. Therefore this commit adds the sizes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-18 09:38:10 +02:00
Andreas Rheinhardt 806ac7da69 avformat/matroskadec: Improve check for level 1 duplicates
If a file uses unknown-length level 1 elements besides clusters and such
elements are after the first cluster, then these elements will usually
be parsed twice: Once during parsing of the file header and once when
reading the file reaches the position where these elements are located.
The second time the element is parsed leads to a "Duplicate element"
error message. Known-length elements are not affected by this as they
are skipped except during parsing the header.

This commit fixes this by explicitly adding a check for whether the
position of the element to be parsed is the same as the position of the
already known level 1 element.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:18:10 -03:00
Andreas Rheinhardt 730ac1ae80 avformat/matroskadec: Use file offsets for level 1 elements
This commit converts the MatroskaLevel1Element struct to use file-based
offsets, as opposed to the current practice of using offsets relative to
the beginning of the segment in it. This also includes a change from
uint64_t to int64_t.

This is in preparation to another patch that improves the check for
duplicate level 1 elements.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:18:10 -03:00
Andreas Rheinhardt 6854127a76 avformat/matroskadec: Reindent after previous commit
Also use the smallest scope possible for a loop variable.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:18:10 -03:00
Andreas Rheinhardt 71c908817e avformat/matroskadec: Accept more unknown-length elements II
Up until now, one last kind of unknown-length element hasn't been
properly handled: Unknown-length elements that are supposed to be
skipped, i.e. the level 1 elements that might reside after the
clusters.

This commit changes this. To do this, ebml_parse got a mode that
essentially tries to skip everything except when parsing is needed
(namely for unknown-length elements for which parsing is necessary
as they can't be skipped). This mode is selected by using a NULL
as destination where the parsed data should be written to.
It is used to parse the level 1 elements in matroska_parse_cluster.

The syntax list used for parsing must of course include links to
the syntax of all the master elements that might need to be parsed.
In other words: Instead of matroska_clusters (which contained every
level 1 element except clusters as EBML_NONE elements designated to
be skipped) matroska_segment is needed and used; matroska_clusters has
been removed.

Furthermore, matroska_segment has been reordered so that clusters are at
the front as this is now the most common case for this list.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:18:09 -03:00
Andreas Rheinhardt 9c6d14ab84 avformat/matroskadec: Fix probing of unknown-length headers
matroska_probe did not support the case of an unknown-length EBML header
at all; given that libavformat's Matroska muxer used to produce such
files in the streaming case, support for them has been added.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:17:00 -03:00
Andreas Rheinhardt 3c70b941d5 avformat/matroskadec: Accept more unknown-length elements
The current Matroska specifications mandate that only two elements may
use an unknown-length length: Segments and clusters. But this was not
always so: For the greater part of Matroska's existence, all master
elements were allowed to make use of the unknown-length feature.

And there were muxers creating such files: For several years
libavformat's Matroska muxer used unknown-length for all master
elements when the output wasn't seekable. This only stopped in March
2010 with 2529bb30. And even afterwards it was possible (albeit
unlikely) for libavformat to create unknown-length master elements
that are in violation of today's specifications, namely if the master
element was so big that the seek backwards to update the size could
no longer be performed inside the AVIOContext's write buffer. This
has only been fixed in October 2016 (with the patches that introduced
support for writing CRC-32 elements).

Libavformat's Matroska demuxer meanwhile has never really supported
unknown-length elements besides segments and clusters. Support for the
latter was hardcoded. This commit changes this: Now all master elements
for which a syntax to parse them is available are supported. This
includes the files produced by old versions of libavformat's muxer.

More precisely, master elements that have unknown length and are about
to be parsed (not skipped) are supported; only a warning is emitted for
them. For normal files, this means that level 1 elements after the
clusters that are encountered after the clusters have been parsed (i.e.
not because they are referenced by the seekhead at the beginning of the
file) are still unsupported (they would be skipped at this point if
their length were known).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:17:00 -03:00
Andreas Rheinhardt 04b62bd7ce avformat/matroskadec: Improve invalid length error handling
1. Up until now, the error message for EBML numbers whose length exceeds
the limits imposed upon them because of the element's type did not
distinguish between known-length and unknown-length elements. As a
consequence, the numerical value of the define constant
EBML_UNKNOWN_LENGTH was emitted as part of the error message which is
of course not appropriate. This commit changes this by adding error
messages designed for unknown-length elements.

2. We impose some (arbitrary) sanity checks on the lengths of certain
element types; these checks were conducted before the checks depending
on whether the element exceeds its containing master element. Now the
order has been reversed, because a failure at the (formerly) latter
check implies that the file is truly erroneous and not only fails our
arbitrary length limit. Moreover, this increases the informativeness of
the error messages.

3. Furthermore, the error message in general has been changed by replacing
the type of the element (something internal to this demuxer and
therefore suitable as debug output at best, not as an error message
intended for ordinary users) with the element ID. The element's position
has been added, too.

4. Finally, the length limit for EBML_NONE elements has been changed so
that all unknown-length elements of EBML_NONE-type trigger an error.
This is done because unknown-length elements can't be skipped and need
to be parsed, but there is no syntax to parse available for EBML_NONE
elements. This is done in preparation for a further patch which allows
more unknown-length elements than just clusters and segments.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:17:00 -03:00
Andreas Rheinhardt 5120305137 avformat/matroskadec: Don't skip too much when unseekable
The Matroska (and WebM) file format achieves forward-compability by
insisting that demuxers ignore and skip elements they don't know about.
Unfortunately, this complicates the detection of errors as errors
resulting from loosing sync can't be reliably distinguished from
unknown elements that are part of a future version of the standard.

Up until now, the strategy to deal with this situation was to skip all
unknown elements that are not obviously erroneous; if an error happened,
it was tried to seek to the last known good position to resync from (and
resync to level 1 elements). This is working fine if the input is
seekable, but if it is not, then the skipped data can usually not be
rechecked lateron. This is particularly acute if unknown-length clusters
are in use, as the check for whether a child element exceeds the
containing master element is ineffective in this situation.

To remedy this, a new heuristic has been introduced: If an unknown
element is encountered in non-seekable mode, an error is presumed to
have happened based upon a combination of the length of the row of the
already encountered unknown elements and of how far away skipping this
element would take us.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:17:00 -03:00
Andreas Rheinhardt 60f75c9976 avformat/matroskadec: Typos, nits and cosmetics
Cosmetics include reordering EbmlType so that EBML_SINT is adjacent to
the other numbers (and matches the order in the switch in ebml_parse)
and also reordering the switch for assignment of default values so that
it matches the order in EbmlType.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:17:00 -03:00
Andreas Rheinhardt 7087fc95b2 avformat/matroskadec: Reuse positions
Up until now, avio_tell was used multiple times in ebml_parse and its
subroutines, although the result of these calls can usually be simply
derived from the result of earlier calls to avio_tell. This has been
changed. Unnecessary calls to avio_tell in ebml_parse are avoided now.

Furthermore, there has been a slight change in the output of some error
messages relating to elements exceeding their containing master element:
The reported position of the element now points to the first byte of the
element ID and no longer to the first byte of the element's payload.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:59 -03:00
Andreas Rheinhardt 3ed2755baa avformat/matroskadec: Redo EOF handling
This commit closes the last hole in the system of checks for a
known-length file ending too early: Now an error message is emitted
in case the file ends directly after an EBML element.

Furthermore, this commit adds a check and a corresponding warning
whether there is data beyond the Matroska segment (only reasonable for
known-length segments). If everything looks alright, then parsing is
stopped as soon as EOF is reached (in contrast, the earlier code would
always call matroska_resync at the end).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:59 -03:00
Andreas Rheinhardt 38255cdcf8 avformat/matroskadec: Combine arrays
By including SimpleBlocks and BlockGroups twice in the same EbmlSyntax
array (with different semantics), one can reduce the duplication of the
other values.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:59 -03:00
Andreas Rheinhardt a9f051519e avformat/matroskadec: Don't reset cluster position
The new code does not rely on whether the cluster's position is set or
not to infer whether a cluster needs to be closed or not (instead, this
is done in ebml_parse), so there is no need to reset the cluster's
position at all any more. It will be automatically set to the correct
value when a cluster is entered.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:59 -03:00
Andreas Rheinhardt 865c537007 avformat/matroskadec: Make cluster parsing level compatible
Before this commit, the parsing of clusters mixed EBML levels by
allowing elements from different levels in a EbmlSyntax (namely
matroska_cluster_parsing). This has been changed. And the level
is now explicitly used to determine how to parse.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:59 -03:00
Andreas Rheinhardt b31c9b72e5 avformat/matroskadec: Redo level handling
This commit changes how levels are handled: If the level used for
ebml_parse ends directly after an element that has been consumed, then
ebml_parse ends the level itself (and any known-length levels that end
there as well) and informs the caller via the return value; if the
current level is of unknown-length, then the level is ended as soon as
an element that is not valid on the current level, but on a higher
level is encountered (or if EOF has been encountered).

This is designed for situations where one wants to parse master elements
incrementally, i.e. not in one go via ebml_parse_nest.

The (incremental) parsing of clusters still mixes levels by using a
syntax list that contains elements from different levels and the level
is still ended manually via a call to ebml_level_end if the last cluster
was an unknown-length cluster (known-length clusters are already ended
when their last element is read), but only if the next element is a
cluster, too. A  different level 1 element following an unknown-length
cluster will currently simply be presumed to be part of the earlier
cluster. Fixing this will be done in a future patch. The modifications
to matroska_parse_cluster contained in this patch are only intended not
to cause regressions.

Nevertheless, the fact that known-length levels are automatically ended
in ebml_parse when their last element has been read already fixes a bogus
error message introduced in 9326117b that was emitted when a known-length
cluster is followed by another level 1 element other than a cluster in
which case the cluster's level was not ended (which only happened when
a new cluster has been encountered) so that the length check (introduced
in 9326117b) failed for the level 1 element as it is of course not
contained in the previous cluster. Most Matroska files were affected by
this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:58 -03:00
Andreas Rheinhardt c1abd95ad0 avformat/matroskadec: Link to parents in syntax tables
By linking to the syntax of the parent (i.e. the containing master
element) one can check whether an element is actually part of a higher
level in the EBML hierarchy. Knowing this is important for
unknown-length levels, because they end when an element that doesn't
belong to this, but to a higher hierarchy level is encountered.

Sometimes there are different syntaxes dealing with the same elements.
In this case it is important to use a parent that contains all the
elements at the parent level; whether this is the syntax actually used
to enter the child's level is irrelevant. This affects the list of level
1 elements (which has been used as parent for matroska_cluster, too) and
it affects recursive elements (currently only the SimpleTag), where the
non-recursive parent has to be choosen.

This is in preparation for a patch that redoes level handling.

Finally, the segment id has been added to ebml_syntax. This will enable
handling of unknown-length EBML headers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:58 -03:00
Andreas Rheinhardt a3db9f62a4 avformat/matroskadec: Introduce a "last known good" position
Currently, resyncing during reading packets works as follows:
The current position is recorded, then a call to matroska_parse_cluster
is made and if said call fails, the demuxer tries to resync from the
earlier position. If the call doesn't fail, but also doesn't deliver a
packet, then this is looped.

There are two problems with this approach:
1. The Matroska file format aims to be forward-compatible; to achieve
this, a demuxer should simply ignore and skip elements it doesn't
know about. But it is not possible to reliably distinguish unknown
elements from junk. If matroska_parse_cluster encounters an unknown
element, it can therefore not simply error out; instead it returns zero
and the loop is iterated which includes an update of the position that
is intended to be used in case of errors, i.e. the element that is
skipped is not searched for level 1 element ids to resync to at all if
later calls to matroska_parse_cluster return an error.
Notice that in case that sync has been lost there can be a chain of
several unknown/possibly junk elements before an error is detected.

2. Even if a call to matroska_parse_cluster delivers a packet, this does
not mean that everything is fine. E.g. it might be that some of the
block's data is missing and that the data that was presumed to be from
the block just read actually contains the beginning of the next element.
This will only be apparent at the next call of matroska_read_packet,
which uses the (false) end of the earlier block as resync position so
that in the (not unlikely) case that the call to matroska_parse_cluster
fails, the data believed to be part of the earlier block is not searched
for a level 1 element to resync to.

To counter this, a "last known good" position is introduced. When an
element id that is known to be allowed at this position in the hierarchy
(according to the syntax currently in use for parsing) is read and some
further checks (regarding the length of the element and its containing
master element) are passed, then the beginning of the current element is
treated as a "good" position and recorded as such in the
MatroskaDemuxContext. Because of 2., only the start of the element is
treated as a "good" position, not the whole element. If an error occurs
later during parsing of clusters, the resync process starts at the last
known good position.

Given that when the header is damaged the subsequent resync never skips over
data and is therefore unaffected by both issues, the "last known good"
concept is not used there.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:58 -03:00
Andreas Rheinhardt 559e3422c7 avformat/matroskadec: Refactor some functions
Since the changes to the parsing of SimpleBlocks, both ebml_parse_id and
ebml_parse_elem are only called from one place, so that it is possible
to inline these two function calls. This is done, but not completely:
ebml_parse_id still exists in a modified form. This is done in
preparation for a further patch regarding the handling of
unknown-length elements.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:58 -03:00
Andreas Rheinhardt 8a286e745d avformat/matroskadec: Use proper levels after discontínuity
The earlier code set the level to zero upon seeking and after a
discontinuity although in both cases parsing (re)starts at a level 1
element.

Also set the segment's length to unkown if an error occured in order not
to drop any valid data that happens to be beyond the designated end of
the segment.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:58 -03:00
Andreas Rheinhardt 310f326b43 avformat/matroskadec: Add function to reset status
This function will be useful later to reset the status (e.g. current
level and the already parsed id).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:57 -03:00
Andreas Rheinhardt 27f40b1dcd avformat/matroskadec: Don't abort resyncing upon seek failure
When an error happens, the Matroska demuxer tries to resync to level 1
elements from an earlier position onwards. If the seek to said earlier
position fails, the demuxer currently treats this as an unrecoverable
error. And that behaviour is suboptimal as said failure is nothing
unrecoverable or unexpected (when the input isn't seekable).
It is preferable to simply resync from the earliest position available
(i.e. the start of the AVIOContext's buffer) onwards if the seek failed.

Here are some scenarios that might be treated as unrecoverable errors
by the current code if the input isn't seekable. They all have in
common that the current position is so far away from the desired
position that the seek can't be fulfilled from the AVIOContext's buffer:

1. Blocks (both SimpleBlocks as well as a Block in a BlockGroup) for
which reading them as binary EBML elements succeeds, but whose parsing
triggers an error (e.g. an invalid TrackNumber). In this case the
earlier position from which resyncing begins is at the start of the block
(or even earlier).
2. BlockGroups, whose parsing fails in one of the latter elements. Just
as in 1., the start of the BlockGroup (the target of the seek) might be
so far away from the current position that it is no longer in the
buffer.
3. At the beginning of parsing a cluster, the cluster is parsed until a
SimpleBlock or a BlockGroup is encountered. So if the input is damaged
between the beginning of the cluster and the first occurrence of a
SimpleBlock/BlockGroup and if said damage makes the demuxer read/skip so
much data that the beginning of the cluster is no longer in the buffer,
demuxing will currently fail completely.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-07-16 16:16:57 -03:00
Andreas Rheinhardt eb33be188d matroskadec: Fix overflow introduced in a569a7b3
This commit fixes an overflow introduced in a569a7b3 that affected EBML
elements that the Matroska demuxer doesn't want to parse like CRC-32
elements. The return value of avio_skip (the new position on success or
an AVERROR on failure) has been assigned to an integer which meant that
new positions in the range of 2GB to 4GB-1 etc. were considered errors.

Fixes ticket #8001.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-07-06 14:48:54 -03:00
Andreas Rheinhardt ff5ea59f7b avformat/matroskadec: Improve error/EOF checks III
Up until now, when an element was skipped, it was relied upon
ffio_limit to make sure that there is enough data available to skip.
ffio_limit itself relies upon the availability of the file's size. As
this needn't be available, the check has been refined: First one byte
less than intended is skipped, then another byte is read, followed by a
check of the error flags.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-24 22:19:03 -03:00
Andreas Rheinhardt a569a7b3bb avformat/matroskadec: Improve read error/EOF checks II
This commit fixes a number of bugs:

1. There was no check that no read error/EOF occured during
ebml_read_uint, ebml_read_sint and ebml_read_float.
2. ebml_read_ascii and ebml_read_binary did sometimes not forward
error codes; instead they simply returned AVERROR(EIO).
3. In particular, AVERROR_EOF hasn't been used and no dedicated error
message for it existed. This has been changed.

In order to reduce code duplication, the new error code NEEDS_CHECKING
has been introduced which makes ebml_parse check the AVIOContext's
status for errors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-24 22:19:03 -03:00
Andreas Rheinhardt 239c7369e0 avformat/matroskadec: Improve read error/EOF checks I
ebml_read_num had a number of flaws:

1. The check for read errors/EOF was totally wrong. E.g. an EBML number
beginning with the invalid 0x00 would be considered a read error,
although it is just invalid data.
2. The check for read errors/EOF was done just once, after reading the
first byte of the EBML number. But errors/EOF can happen inbetween, of
course, and this wasn't checked.
3. There was no way to distinguish when EOF should be an error (because
the data has to be there) for which an error message should be emitted
and when it is not necessarily an error (namely during parsing of EBML
IDs). Such a possibility has been added and used.

All this was fixed; furthermore, the error messages for invalid EBML
numbers were improved and useless initializations were removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-24 22:19:03 -03:00
Andreas Rheinhardt a27e5398e2 avformat/matroskadec: Properly check return values
Up until now, webm_dash_manifest_cues used the return values of
ebml_read_num and ebml_read_length without checking for errors,
i.e. return values < 0. This has been changed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-24 22:19:03 -03:00
Andreas Rheinhardt 1215b3a5f3 avformat/matroskadec: Don't zero unnecessarily
It is only necessary to zero the initial allocated memory used to store
the size of laced frames if the block used Xiph lacing. Otherwise no
unintialized data was ever used, so use av_malloc instead of av_mallocz.

Also use the correct type for the allocations.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-24 20:59:33 -03:00
Andreas Rheinhardt bc3306fd5b avformat/matroskadec: Treat SimpleBlock as EBML_BIN
Up until now, the SimpleBlock was treated specially: It basically had
its own EBML category and it was also included in the BlockGroup EBML
syntax (although a SimpleBlock must not exist in a BlockGroup according
to the Matroska specifications). The latter fact also meant that
a MatroskaBlock's buffer was always unreferenced twice.
This has been changed: The type of a SimpleBlock is now an EBML_BIN.
The only way in which SimpleBlocks are still different is that they
share their associated structure with another unit (namely BlockGroup).
This is also used to unref the block: It is always unreferenced via the
BlockGroup syntax.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-23 20:11:24 -03:00
Andreas Rheinhardt ffa64a4db8 avformat/matroskadec: Don't keep old blocks
Before this commit, the Matroska muxer would read a block when required
to do so, parse the block, create and return the necessary AVPackets and
yet keep the blocks (in a dynamically allocated list), although they
aren't used at all any more. This has been changed. There is no list any
more and the block is immediately discarded after parsing.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-23 00:47:50 -03:00
Andreas Rheinhardt f3ca3e7f19 avformat/matroskadec: Remove redundant initialization
Every new element of an EbmlList is zeroed initially in
ebml_parse_elem, so that in particular a SimpleBlock's duration is
initialized to zero. Therefore it is unnecessary to initialize this
field again (for SimpleBlocks) in matroska_parse_cluster_incremental.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-23 00:47:50 -03:00
Andreas Rheinhardt 43c3cebbd4 avformat/matroskadec: Set offset of first cluster
By default, the data_offset member of the AVFormatInternal of the
AVFormatContext associated with the MatroskaDemuxContext has not been
initialized explicitly by any Matroska-specific function, so that it was
initialized by default to the offset at the end of matroska_read_header,
i.e. usually to the offset of the length field of the first encountered
cluster. This meant that in case that the Matroska-specific seek-code
fails because there are no index entries for the target track a seek to
data_offset would be performed and ordinary parsing would start from
there which is nonsense: The length field would be treated as EBML ID and
(if the length field is not longer than four bytes (EBML numbers that
long are rejected as invalid EBML IDs)) whatever comes next would be
treated as its EBML size although it simply isn't.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-23 00:47:50 -03:00
Andreas Rheinhardt 36aceb6174 avformat/matroskadec: Get rid of cluster size field assumption
The earlier code relied on the length of clusters always being coded on
eight bytes as was the behaviour of libavformat's Matroska muxer until
recently. But given that our own Matroska muxer now (and mkvmerge from
time immemorial) creates files that don't conform to this assumption,
it is high time to get rid of this assumption.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-23 00:47:50 -03:00
Andreas Rheinhardt 70baf729b5 avformat/matroskadec: Remove non-incremental parsing of clusters
When the new incremental parser was introduced, the old parser was
kept, because the new parser was unable to handle the way SSA packets
are put into Matroska. But since 2014 (since c7d8dbad) this is no
longer needed, so that the old parser can be completely removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-22 23:45:41 -03:00
Andreas Rheinhardt e5ec131856 avformat/matroskadec: Use generic size check for signed integers
and drop the redundant checks contained in ebml_read_uint and
ebml_read_sint.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-22 23:43:38 -03:00
Andreas Rheinhardt 07d4056052 avformat/matroskadec: Don't copy attached pictures
This commit replaces copying attached pictures by using references to
the already existing buffers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2019-06-22 23:39:17 -03:00
Andreas Rheinhardt 410a0824f0 avformat/matroskadec: Compactify structure
Matroska EBML IDs can be only four bytes long maximally, so it is
natural to use uint32_t for them. By doing this and rearranging the
elements of the MatroskaLevel1Element structure, one can reduce the size
of said structure.

Notice that this field is not read via the generic reading process for
EBML_UINT, so one is not forced to use an uint64_t for it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-06-07 19:58:15 +02:00
Andreas Rheinhardt f767c68b34 avformat/matroskadec: Correct outdated error message
This error message is outdated since d31fb1a9.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-06-07 19:58:15 +02:00
Andreas Rheinhardt c6bb825e72 avformat/matroskadec: Remove unused variables
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-06-07 19:58:15 +02:00
Andreas Rheinhardt via ffmpeg-devel 18a851aca7 avformat/matroskadec: Improve length check
The earlier code had three flaws:

1. The case of an unknown-sized element inside a finite-sized element
(which is against the specifications) was not caught.

2. The error message wasn't helpful: It compared the length of the child
with the offset of the end of the parent and claimed that the first
exceeds the latter, although that is not necessarily true.

3. Unknown-sized elements that are not parsed can't be skipped. Given
that according to the Matroska specifications only the segment and the
clusters can be of unknown-size, this is handled by not allowing any
other units to have infinite size whereas the earlier code would seek
back by 1 byte upon encountering an infinite-size element that ought
to be skipped.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-04-05 12:05:47 +02:00
Carl Eugen Hoyos 4d8875ec23 lavf: Constify the probe function argument.
Reviewed-by: Lauri Kasanen
Reviewed-by: Tomas Härdin
2019-03-21 11:42:17 +01:00
Steve Lhomme a2c7702ccf avformat:matroskadec: use a define to mark the EBML length is unknown
Unifying the way the EBML unknown length is signaled, rather than using two
incompatible values. UINT64_MAX cannot be read as a valid EBML length with the
current code.

Co-authored-by: Steve Lhomme <robux4@ycbcr.xyz>
Co-authored-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-24 20:31:07 +01:00
Steve Lhomme 9326117bf6 avformat/matroskadec: Check parents remaining length
This was found through the Hacker One program on VLC but is not a security issue in libavformat
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-17 10:29:42 +01:00
Michael Niedermayer d1afa7284c avformat/matroskadec: Do not leak queued packets on sync errors
Fixes: memleak
Fixes: clusterfuzz-testcase-minimized-audio_decoder_fuzzer-5649187601121280

Reported-by: Chris Cunningham <chcunningham@google.com>
Tested-by: Chris Cunningham <chcunningham@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-17 09:12:06 +01:00
Carl Eugen Hoyos 73abde61bb lavf/matroskadec: Do not use strncat() to limit copying a one-char constant.
Instead add the character to the snprintf above as suggested by Mark.

Silences a warning:
libavformat/matroskadec.c: In function 'webm_dash_manifest_cues':
libavformat/matroskadec.c:3947:13: warning: 'strncat' specified bound 1 equals source length [-Wstringop-overflow=]
             strncat(buf, ",", 1);
             ^~~~~~~~~~~~~~~~~~~~
2018-12-11 00:40:26 +01:00
Carl Eugen Hoyos 6871c17173 lavf/matroskadec: Simplify string length calculation.
FFmpeg relies on sizeof(char) == 1.
2018-10-19 20:36:55 +02:00
James Almer 8d5604a69a avformat/av1: update ff_isom_write_av1c() to the latest revision of the spec
This will get ISOBMFF and Matroska up to date with the revised AV1 Codec
Configuration Box spec.
For now keep propagating raw OBUs as extradata until all libavcodec modules
are adapted to handle AV1CodecConfigurationRecord formatted extradata.

Tested-by: Thomas Daede <bztdlinux@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-08-17 15:09:02 -03:00
James Almer 9703b7d05f avformat/matroskadec: reference the existing data buffer when creating packets
Newly allocated data buffers (wavpack, prores, compressed buffers)
are padded to meet the requirements of AVPacket.

About 10x speed up in matroska_parse_frame().

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-06 21:14:50 -03:00
James Almer b8e75a2a08 avformat/matroskadec: factor the prores packet parsing code out
Simplifies code in matroska_parse_frame(). This is in preparation for
the following patch.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-06 21:14:50 -03:00
James Almer a61886650b avformat/matroskadec: use refcounted buffers in EbmlBin
Data in EbmlBin objects is never changed after being read from the
input file (save for two specific cases with encoded CodePrivate), so
using AVBufferRef we can prevent unnecessary copy of data by instead
creating new references to said constant data.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-06 21:14:49 -03:00
James Almer 4f55b94663 avformat/matroskadec: address some more missing AVPacket frees
Fixes memleaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 13:53:12 -03:00
James Almer 2f0e0deadc avformat/matroskadec: address a missing AVPacket free
Fixes memleaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 10:54:14 -03:00
James Almer 78b96be758 avformat/matroskadec: use AVPacketList to queue packets
It's more robust and efficient.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:15:38 -03:00
James Almer f4f39582e7 avformat/matroskadec: fix return value
err is already an AVERROR.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-20 10:26:21 -03:00
James Almer 88eb368f42 avformat/matroskadec: free the packet on webvtt side data allocation failure
Fixes potential memory leaks

Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-20 10:25:54 -03:00
James Almer acdea9e7c5 avformat/matroskadec: ignore CodecPrivate if the stream is VP9
Defined in a recent revision of https://www.webmproject.org/docs/container/

This prevents storing the contents of CodecPrivate into extradata for
a codec that doesn't need nor expect any. It will among other things
prevent matroska specific binary data from being dumped onto other
formats during remuxing.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-02-19 22:13:13 -03:00
James Almer 63b5d04e33 avformat/matroskadec: force full frame parsing of MLP/TrueHD streams
There's at least one known file with a TrueHD stream that hasn't
been correctly muxed, and requires full frame parsing and repack.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-01-29 23:09:08 -03:00
Marton Balint 18ac642359 avformat: migrate to AVFormatContext->url
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-01-28 23:06:43 +01:00
Nikolas Bowe e07649e618 avformat/matroskadec: Fix float-cast-overflow undefined behavior in matroska_parse_tracks()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-01-19 22:33:31 +01:00
James Almer f5c67c431e Merge commit '55fe72a841ba306370e68e86c88f34b4456aa4dd'
* commit '55fe72a841ba306370e68e86c88f34b4456aa4dd':
  matroskadec: don't warn about unknown spherical medata when none is present

Merged-by: James Almer <jamrial@gmail.com>
2017-11-12 00:46:52 -03:00
James Almer 55fe72a841 matroskadec: don't warn about unknown spherical medata when none is present
track->video.projection.type is set to 0 (a Matroska specific "No spherical
metadata present" value, with no related AVSphericalMapping) by default on
files without the element.

This removes bogus warnings on every single matroska file without Spherical
metadata.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-11-03 19:41:08 -03:00
James Almer 68727a1dc0 Merge commit '251849f06ce36ce8dc076e0fca2922119fa7e39e'
* commit '251849f06ce36ce8dc076e0fca2922119fa7e39e':
  mkv: Add support for Spherical Video elements

See 445204cd57

Merged-by: James Almer <jamrial@gmail.com>
2017-10-17 16:47:30 -03:00
Steven Liu cc25a887c5 avformat/matroskadec: fix resource leak
Fixes Coverity CID: 1405453

Reviewed-by: wm4 <nfxjfg@googlemail.com>
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2017-05-07 11:29:08 +08:00
James Almer 095147ae06 avformat/matroskadec: export Content Light Level metadata
Based on a patch by Hendrik Leppkes

Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-30 20:04:50 -03:00
Derek Buitenhuis 6ba1c9bf7e webm_dash_manifest_demuxer: Fix initialization range for files with cues at the front
The WebM DASH spec states:
    The Initialization Segment shall not contain Clusters or Cues.
    The Segment Index corresponds to the Cues.

Previously, it included the cues if they were at the front.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2017-04-23 17:52:58 +01:00
Derek Buitenhuis 8e6b9ef473 webm_dash_manifest_demuxer: Fix UB in cue timestamp string code and make it actually work
Output was apparently not tested for correctness. Passing overlapping
memory to snprintf causes undefined behavior, and usually resulted in
only the very last timestamp being written to metadata, and not a list
at all.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2017-04-23 17:51:41 +01:00
James Zern 20aeee4fc9 matroskadec,cosmetics: fix a couple typos
Signed-off-by: James Zern <jzern@google.com>
2017-04-17 10:59:31 -07:00
Vignesh Venkatasubramanian 62c27fdba4 webm_dash_manifest: Add option to specify bandwidth
Add an option to webm_dash_manifest demuxer to specify a value for
"bandwidth" field in the DASH manifest. The value is then used by
the muxer. Fixes an existing FIXME in the code.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: James Zern <jzern@google.com>
2017-04-17 10:46:51 -07:00
Clément Bœsch e3287077ec Merge commit '67deba8a416d818f3d95aef0aa916589090396e2'
* commit '67deba8a416d818f3d95aef0aa916589090396e2':
  Use avpriv_report_missing_feature() where appropriate

Merged-by: Clément Bœsch <cboesch@gopro.com>
2017-03-31 10:40:34 +02:00
Clément Bœsch cd4d6cba12 lavf: fix usages of av_get_codec_tag_string() 2017-03-29 14:49:29 +02:00
Vittorio Giovara 5f90ad99bb spherical: Change types of bounding and pad to uint32_t
These values are defined to be 32bit in the specification,
so it makes more sense to store them as fixed width.

Based on a patch by Micahel Niedermayer <michael@niedermayer.cc>.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-03-23 10:09:18 +01:00
James Almer 4de591e6fb Merge commit '83548fe894cdb455cc127f754d09905b6d23c173'
* commit '83548fe894cdb455cc127f754d09905b6d23c173':
  lavf: fix usage of AVIOContext.seekable

Merged-by: James Almer <jamrial@gmail.com>
2017-03-21 17:02:30 -03:00
Vittorio Giovara f20bcec4c2 spherical: Change types of bounding and pad to uint32_t
These values are defined to be 32bit in the specification,
so it makes more sense to store them as fixed width.

Based on a patch by Micahel Niedermayer <michael@niedermayer.cc>.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-03-17 13:12:25 -04:00
Vittorio Giovara 9ae3506696 matroskadec: cosmetics: Rearrange checks for projection-depedendent properties 2017-03-07 17:34:32 -05:00
Vittorio Giovara bde9642268 mkv: Export bounds and padding from spherical metadata
Update the fate test as needed.
2017-03-07 11:28:02 -05:00
James Almer 251849f06c mkv: Add support for Spherical Video elements
Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-03-07 11:07:03 -05:00
Vittorio Giovara 0429f01e47 mkv: Export bounds and padding from spherical metadata
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-03-07 11:07:03 -05:00
Carl Eugen Hoyos b8a7dcbde2 lavf/matroskadec: Fix demuxing sipr.
Regression since 2c8d876d
2017-02-28 21:51:26 +01:00
Chris Cunningham ac25840ee3 lavf/matroskadec: fix is_keyframe for early Blocks
Blocks are marked as key frames whenever the "reference" field is
zero. This breaks for non-keyframe Blocks with a reference timestamp
of zero.

The likelihood of reference timestamp being zero is increased by a
longstanding bug in muxing that encodes reference timestamp as the
absolute time of the referenced frame (rather than relative to the
current Block timestamp, as described in MKV spec).

Now using INT64_MIN to denote "no reference".

Reported to chromium at http://crbug.com/497889 (contains sample)
2017-02-06 09:33:28 +01:00
James Almer 1ae39429e4 avformat/matroskadec: ProjectionPrivate is optional on Equirectangular projections
This reflects a recent change to the spec draft.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-01-26 19:28:19 -03:00
Anton Khirnov 9026ec8aaf matroskadec: make sure not to leave EbmlBin in an inconsistent state
If a read fails, the current code will free the data but leave the size
non-zero. Make sure the size is zeroed in such a case.

CC: libav-stable@libav.org
Bug-Id: 1001
Found-By: Kamil Frankowicz
Signed-off-by: Sean McGovern <gseanmcg@gmail.com>
2017-01-04 20:05:44 -05:00
Michael Niedermayer b347ca9341 avformat/matroskadec: Fix OOM on long streams
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-12-27 02:48:19 +01:00
John Stebbins 0982152c3f matroskadec: fix SRT subtitle duration
The codec id for SRT was changed and conditionals were not updated.
2016-12-24 08:33:17 -08:00
James Almer edb4f5da81 avformat/matroskadec: remove the strict unofficial check for Colour elements
Signed-off-by: James Almer <jamrial@gmail.com>
2016-12-10 21:06:45 -03:00
James Almer 4e759072c2 avformat/matroskadec: allocate Colour related fields only if the file contains the relevant master
The demuxer doesn't fill the defaults if the master isn't present.
This results in codecpar->color_space being set with a value of
zero (RGB) on such files.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-12-10 21:05:21 -03:00
James Almer 120471da2d avformat/matroskadec: remove unused variable
Signed-off-by: James Almer <jamrial@gmail.com>
2016-12-08 01:23:24 -03:00
James Almer 8396d54d3c avformat/matroskadec: fix memleak on stream side data failure
Signed-off-by: James Almer <jamrial@gmail.com>
2016-12-08 01:21:11 -03:00
James Almer 445204cd57 avformat/matroskadec: add support for Spherical Video elements
Signed-off-by: James Almer <jamrial@gmail.com>
2016-12-07 22:40:59 -03:00
Rainer Hochecker 7a9db61da3 matroskadec: partly revert "demux relevant subtitle packets after a seek"
This reverts parts of c16582579b. The hard
coded 30 seconds are a lot, and finishing the seek can takes several
seconds when the source is on a network share. Remove this code
entirely, because it does more bad than good.

(Commit message provided by committer, based on the original messages
by the patch author.)

Signed-off-by: Rainer Hochecker <fernetmenta@online.de>
Signed-off-by: wm4 <nfxjfg@googlemail.com>
2016-12-02 13:59:17 +01:00
Michael Schenk 18b9466937 matroskadec: prevent access of elements after freeing
Using the decode interrupt feature of ffmpeg may cause crashes by
accessing previously freed pointers in matroska_read_close.

To prevent this reset nb_elem to zero after freeing the elements,
because ffmpeg normally tests for nb_elem.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-11-30 01:15:38 +01:00
Andreas Cadhalpun ff100c9dd9 matroskadec: fix NULL pointer dereference in webm_dash_manifest_read_header
The code assumes that s->streams[0] is valid.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-11-08 20:17:31 +01:00
Diego Biurrun 67deba8a41 Use avpriv_report_missing_feature() where appropriate 2016-11-08 17:54:34 +01:00
James Almer 70c6a1bcf0 avformat/matroskadec: fix DiscardPadding element parsing
If the value is negative then it means padding at the start of the packet
instead of at the end.

Based on a patch by Hendrik Leppkes.

Reviewed-by: James Zern <jzern-at-google.com@ffmpeg.org>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-08 13:43:53 -03:00
James Almer 0ad71ed6f9 avformat/matroskadec: fix BitsPerChannel element's default value
The element is currently ignored, so there's no effective functionality
change with this.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-18 23:55:32 -03:00
James Almer f5cfc0cc54 avformat/matroskadec: clarify some Colour element defaults using enum values
This way it's more clear what the default values refer to, as
Undetermined/Unspecified is 0 for some, 2 for others.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-18 23:55:05 -03:00
James Almer 47ee6f1a59 avformat/matroskadec: support parsing Chroma Location elements
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-18 20:39:07 -03:00
Andreas Cadhalpun eb751f06db matroskadec: fix NULL pointer dereference
The problem was introduced in commit 1273bc6.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-10-17 15:50:26 +02:00
James Almer 8b59ce0342 Partially revert "avformat/matroskadec: set aspect ratio only when DisplayWidth and DisplayHeight are in pixels"
The code works just fine regardless of unit, so only make sure DisplayUnit
is not "unknown".

Found-by: Nicolas George <george@nsup.org>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-16 14:19:05 -03:00
James Almer bad8bbc26a avformat/matroskadec: set aspect ratio only when DisplayWidth and DisplayHeight are in pixels
A missing DisplayUnit element or one with the default value of 0 means
DisplayWidth and DisplayHeight should be interpreted as pixels.

The current code setting st->sample_aspect_ratio is wrong when DisplayUnit
is anything else.

Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-15 20:42:07 -03:00
James Almer 1273bc6d26 avformat/matroskadec: workaround the field_order bug in the Matroska muxer
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-13 14:22:07 -03:00
James Almer a4044498f7 avformat/matroskadec: check for more reserved values on some Colour elements
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 13:49:29 -03:00
Anton Khirnov 83548fe894 lavf: fix usage of AVIOContext.seekable
It is supposed to be a flag. The only currently defined value is
AVIO_SEEKABLE_NORMAL, but other ones may be added in the future.
However all the current lavf code treats this field as a bool (mainly
for historical reasons).
Change all those cases to properly check for AVIO_SEEKABLE_NORMAL.
2016-09-30 16:54:33 +02:00
James Almer 29b6c2be29 avformat/matroskadec: set AVCodecParameters.field_order on progressive video
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-09-27 20:30:11 -03:00
Sophia Wang 8c83062acb avformat/matroskadec: retain error codes in matroska_resync() and matroska_read_packet()
Signed-off-by: Sophia Wang <skw@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-28 01:24:51 +02:00
Marton Balint 13b90ff2c1 avformat: fix decoded creation_time timestamps
Use proper ISO 8601 timestamps which also signal that they are in UTC.

This changes the format of creation_time and modification_date metadata values
from 2016-06-01 22:30:00 to 2016-01-01T22:30:00.000000Z

Fixes ticket #5673.

Signed-off-by: Marton Balint <cus@passwd.hu>
2016-08-28 15:55:32 +02:00
Chris Cunningham 52ec4cc09b libavformat/matroskadec: Add test for seeking with codec delay.
Also cleanup parens for the skip_to_timecode check.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-30 01:02:41 +02:00
Chris Cunningham d59820f6fe libavformat/matroskadec: fix unsigned overflow to improve seeking
When seeking a file where codec delay is greater than 0, the timecode
can become negative after offsetting by the codec delay. Failing to cast
to a signed int64 will cause the check against skip_to_timecode to evaluate
true for these negative values. This breaks the "skip_to" seek mechanism.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-23 10:32:28 +02:00
Anton Khirnov 40f74dc87a matroskadec: export CodecDelay 2016-07-03 09:13:29 +02:00
Michael Niedermayer f573acc424 avformat/matroskadec: Call matroska_read_close() on header parsing error
Fixes memleak
Fixes Ticket5169

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-24 18:39:53 +02:00
James Almer 49b0246635 avformat/matroskadec: force 48kHz sample rate when rescaling Opus inital padding
Mkvtoolnix stores the sample rate of the original stream as reported by the
"OpusHead" stream header instead of 48kHz, the actual sample rate of the Opus
stream.
Ignoring the stored sample rate and forcing 48kHz preserves the correct initial
padding when remuxing such files.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-06-07 20:32:25 -03:00
Michael Niedermayer b5bc436ebc avformat/matroskadec: Fix rounding error with codec_delay
Fixes Ticket5509

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-06 05:01:34 +02:00
Derek Buitenhuis f3972b3b7d Merge commit '5f0226668124aa7ae4db501ba7f4ace4c770f3d1'
* commit '5f0226668124aa7ae4db501ba7f4ace4c770f3d1':
  matroska: Support interlaced content correctly

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-05-08 22:58:18 +01:00
Diego Biurrun 5afb94c817 Mark read-only tables as static 2016-05-05 10:48:34 +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
Luca Barbato 5f02266681 matroska: Support interlaced content correctly
The matroska specification now has two elements for it.
2016-03-31 18:03:21 +02:00
Luca Barbato 8b4b1c1eea matroska: Support V_QUICKTIME as written in the specification
Check if the size is written the first 4 bytes and read the next 4
as fourcc candidate, fallback checking the initial for 4 bytes.

"The CodecPrivate contains all additional data that is stored in the
'stsd' (sample description) atom in the QuickTime file after the
mandatory video descriptor structure (starting with the size and FourCC
fields)"

CC: libav-stable@libav.org
2016-03-15 16:06:35 +01:00
Neil Birkbeck bbda13a771 lavf/matroskadec: Add early support for some of the new colour elements.
Adding early support for a subset of the proposed colour elements
according to the latest version of spec:
https://mailarchive.ietf.org/arch/search/?email_list=cellar&gbt=1&index=hIKLhMdgTMTEwUTeA4ct38h0tmE

I've left out elements for pix_fmt related things as there still
seems to be some discussion around these, and the max_cll/max_fall
are currently not propagated as there is not yet side data for them.

The new elements are exposed under strict experimental mode.

Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-03-04 23:11:51 +01:00
Mats Peterson 6aac43f180 lavf/matroskadec: Process QuickTime palette per track
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-02-27 02:03:02 +01: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
Luca Barbato f273f7fb25 mkv: Force the full parsing of mp3
Some muxer might or might not fit incomplete mp3 frames in
their packets.

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2016-02-19 17:35:33 +01:00
Mats Peterson 535d09a510 lavf/matroskadec: Get sample size from private data
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-16 11:44:46 +01:00
Mats Peterson adef8ee794 lavf/matroskadec: Use av_realloc() in get_qt_codec()
Use av_realloc() rather than av_malloc() when normalizing noncompliant
private data in get_qt_codec().

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-12 14:53:25 +01:00
Mats Peterson 71f73ee325 lavf/matroskadec: Normalize noncompliant A_QUICKTIME/V_QUICKTIME private data
This patch adds a new static function get_qt_codec() that takes care of
the initial retrieval of the fourcc and codec ID for A_QUICKTIME and
V_QUICKTIME. It also normalizes noncompliant private data found in some
older files that incorrectly starts with the fourcc by expanding/shifting
the data by 4 bytes, and storing the data size at the start. This is
necessary in order for the rest of the code in the A_QUICKTIME and
V_QUICKTIME blocks (and most likely other code as well) to correctly
parse the private data.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-11 01:35:34 +01:00
Mats Peterson 6f1466dc52 lavf/matroskadec: A_QUICKTIME and fourcc 0x00000000
In many older QuickTime files, the audio format, or "fourcc", is
0x00000000. The QuickTime File Format Specification states the following
regarding this situation:

"This format descriptor should not be used, but may be found in some
files. Samples are assumed to be stored in either 'raw ' or 'twos'
format, depending on the sample size field in the sound description."

MPlayer handles this logic by itself, but FFmpeg/FFplay currently does
not.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-08 14:52:53 +01:00
Mats Peterson 6a975cb07f lavf/matroskadec: correct codec_tag for "SMI" SVQ3 files
This corrects the codec_tag for some SVQ3 files

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-06 14:45:52 +01:00
Mats Peterson 7973603843 avformat/matroskadec: palettized QuickTime video in Matroska
Palettized QuickTime video in Matroska has hitherto not been recognized
whatsoever, and the "palette" used has been completely random.

The patch for matroskadec.c fixes this issue by adding a palette side
data packet in matroska_deliver_packet(), much in the same way as it's
done in mov.c.

Video samples for testing are available at
https://drive.google.com/open?id=0B3_pEBoLs0faWElmM2FnLTZYNlk.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-28 02:47:58 +01:00
Hendrik Leppkes 5242cc878a Merge commit 'febfb49a70e82f5ac46dc7ea34dabd4d56b19b31'
* commit 'febfb49a70e82f5ac46dc7ea34dabd4d56b19b31':
  matroskadec: Fix sample_aspect_ratio for stereo matroska content

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-12-18 14:49:56 +01:00
Carl Eugen Hoyos 7c1c453ce9 lavf/matroskadec: Set codec_tag also for audio codecs.
This was already done for "A_MS/ACM" mkv files and it is done
for mov files but was not done for A_QUICKTIME" mkv files.
2015-12-12 18:21:45 +01:00
Aaron Colwell febfb49a70 matroskadec: Fix sample_aspect_ratio for stereo matroska content
matroskaenc applies divisors to the display width/height when generating
stereo content. This patch adds the corresponding multipliers to matroskadec
so that the original sample aspect ratio can be recovered.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-12-07 11:27:42 -05:00
Hendrik Leppkes 0ecec7449c Merge commit 'a0fa6d06b848f26b16ba12f0a9a4a85b93ab8022'
* commit 'a0fa6d06b848f26b16ba12f0a9a4a85b93ab8022':
  matroska: Warn when metadata references a non-existent element

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-12-07 14:51:23 +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
Aaron Colwell ec83efd4d3 avformat/matroskadec: Fix sample_aspect_ratio for stereo matroska content
matroskaenc.c applies divisors to the display width/height when generating
stereo content. This patch adds the corresponding multipliers to matroskadec.c
so that the original sample aspect ratio can be recovered.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2015-12-02 11:09:07 +01:00
Luca Barbato a0fa6d06b8 matroska: Warn when metadata references a non-existent element
Avoid some confusion when the information is not present.

Bug-Id: 902
2015-11-28 17:02:15 +01:00
Michael Niedermayer a5034b324c avformat/matroskadec: Check subtitle stream before dereferencing
Unrecognized streams are not allocated
Fixes: flicker-1.color1.vp91447030769.08.webm

Found-by: Chris Cunningham <chcunningham@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-11-17 19:02:28 +01:00
Hendrik Leppkes c2f861ca42 Replace remaining occurances of av_free_packet with av_packet_unref 2015-10-27 14:35:30 +01:00
Hendrik Leppkes 7f5af80ba4 Merge commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457'
* commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457':
  avpacket: Replace av_free_packet with av_packet_unref

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-10-27 14:28:56 +01:00
Luca Barbato ce70f28a17 avpacket: Replace av_free_packet with av_packet_unref
`av_packet_unref` matches the AVFrame ref-counted API and can be used as
a drop in replacement.

Deprecate `av_free_packet`.
2015-10-26 18:00:55 +01:00
Rodger Combs 4f7d9b7706 lavf/matroskadec: drop indexes that appear broken
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-10-09 04:43:49 +02:00
Hendrik Leppkes b01891a9f0 Merge commit '948f3c19a8bd069768ca411212aaf8c1ed96b10d'
* commit '948f3c19a8bd069768ca411212aaf8c1ed96b10d':
  lavc: Make AVPacket.duration int64, and deprecate convergence_duration

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-09-29 15:22:52 +02:00
wm4 948f3c19a8 lavc: Make AVPacket.duration int64, and deprecate convergence_duration
Note that convergence_duration had another meaning, one which was in
practice never used. The only real use for it was a 64 bit replacement
for the duration field. It's better just to make duration 64 bits, and
to get rid of it.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-09-29 14:33:00 +02:00
Rodger Combs cf2719abee lavf/matroska: ignore ChapCountry ID for now
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-20 20:08:01 +02:00
Rodger Combs b4b2717ffe lavf/matroskadec: Fully parse and repack MP3 packets
Fixes https://trac.ffmpeg.org/ticket/4776

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-16 11:46:33 +02:00
Michael Niedermayer 29d147c94d Merge commit '059a934806d61f7af9ab3fd9f74994b838ea5eba'
* commit '059a934806d61f7af9ab3fd9f74994b838ea5eba':
  lavc: Consistently prefix input buffer defines

Conflicts:
	doc/examples/decoding_encoding.c
	libavcodec/4xm.c
	libavcodec/aac_adtstoasc_bsf.c
	libavcodec/aacdec.c
	libavcodec/aacenc.c
	libavcodec/ac3dec.h
	libavcodec/asvenc.c
	libavcodec/avcodec.h
	libavcodec/avpacket.c
	libavcodec/dvdec.c
	libavcodec/ffv1enc.c
	libavcodec/g2meet.c
	libavcodec/gif.c
	libavcodec/h264.c
	libavcodec/h264_mp4toannexb_bsf.c
	libavcodec/huffyuvdec.c
	libavcodec/huffyuvenc.c
	libavcodec/jpeglsenc.c
	libavcodec/libxvid.c
	libavcodec/mdec.c
	libavcodec/motionpixels.c
	libavcodec/mpeg4videodec.c
	libavcodec/mpegvideo.c
	libavcodec/noise_bsf.c
	libavcodec/nuv.c
	libavcodec/nvenc.c
	libavcodec/options.c
	libavcodec/parser.c
	libavcodec/pngenc.c
	libavcodec/proresenc_kostya.c
	libavcodec/qsvdec.c
	libavcodec/svq1enc.c
	libavcodec/tiffenc.c
	libavcodec/truemotion2.c
	libavcodec/utils.c
	libavcodec/utvideoenc.c
	libavcodec/vc1dec.c
	libavcodec/wmalosslessdec.c
	libavformat/adxdec.c
	libavformat/aiffdec.c
	libavformat/apc.c
	libavformat/apetag.c
	libavformat/avidec.c
	libavformat/bink.c
	libavformat/cafdec.c
	libavformat/flvdec.c
	libavformat/id3v2.c
	libavformat/isom.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/mpc.c
	libavformat/mpc8.c
	libavformat/mpegts.c
	libavformat/mvi.c
	libavformat/mxfdec.c
	libavformat/mxg.c
	libavformat/nutdec.c
	libavformat/oggdec.c
	libavformat/oggparsecelt.c
	libavformat/oggparseflac.c
	libavformat/oggparseopus.c
	libavformat/oggparsespeex.c
	libavformat/omadec.c
	libavformat/rawdec.c
	libavformat/riffdec.c
	libavformat/rl2.c
	libavformat/rmdec.c
	libavformat/rtpdec_latm.c
	libavformat/rtpdec_mpeg4.c
	libavformat/rtpdec_qdm2.c
	libavformat/rtpdec_svq3.c
	libavformat/sierravmd.c
	libavformat/smacker.c
	libavformat/smush.c
	libavformat/spdifenc.c
	libavformat/takdec.c
	libavformat/tta.c
	libavformat/utils.c
	libavformat/vqf.c
	libavformat/westwood_vqa.c
	libavformat/xmv.c
	libavformat/xwma.c
	libavformat/yop.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 23:15:19 +02:00
Vittorio Giovara 059a934806 lavc: Consistently prefix input buffer defines
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-07-27 15:24:59 +01:00
Michael Niedermayer ba77fb61f7 Merge commit 'd80811c94e068085aab797f9ba35790529126f85'
* commit 'd80811c94e068085aab797f9ba35790529126f85':
  riff: Use the correct logging context

Conflicts:
	libavformat/asfdec_o.c
	libavformat/avidec.c
	libavformat/dxa.c
	libavformat/matroskadec.c
	libavformat/mov.c
	libavformat/riff.h
	libavformat/riffdec.c
	libavformat/wavdec.c
	libavformat/wtvdec.c
	libavformat/xwma.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-12 15:22:37 +02:00
Luca Barbato d80811c94e riff: Use the correct logging context 2015-07-11 18:45:44 +02:00
Michael Niedermayer 2f8c81637c avformat/matroskadec: Fix undefined shift in read_sint()
Fixes: asan_heap-oob_17212bc_2243_cov_594210248_h264_TTA.mkv

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-07-01 12:00:43 +02:00
Andreas Cadhalpun 92e79a2f7b matroskadec: validate audio channels and bitdepth
In the TTA extradata re-construction the values are written with
avio_wl16 and if they don't fit into uint16_t, this triggers an
av_assert2 in avio_w8.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2015-06-16 21:46:04 +02:00
Andreas Cadhalpun 5b76c82fd7 matroskadec: check audio sample rate
And default to 8000 if it is invalid.

An invalid sample rate can trigger av_assert2 in av_rescale_rnd.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2015-06-16 21:45:45 +02:00
wm4 7e240f9581 matroskadec: verify seekhead IDs
Some files have SeekHead elements with broken IDs. They mismatch with
the ID of the destination element. These files are written by
"IDMmkvlib0.1" (as identified by the MuxingApp and WritingApp elements),
and the SeekHead IDs are actually endian-swapped.

This confuses the SeekHead logic of the demuxer. It will read some
elements twice, because the SeekHead ID is used to identify and remember
already read elements. With the file at hand, the stream list was
duplicated by reading the Tracks element twice.

Fix this by rejecting invalid EBML IDs in SeekHead entries. (This fix is
relatively specific to the broken file at hand, and doesn't protect
against some other cases of broken SeekHead, such as valid but
mismatching target element IDs.)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-06-12 19:30:11 +02:00
Michael Niedermayer e5397513b9 Merge commit '8fc11abe1fea4f211cc7dbd58a173d1221627d90'
* commit '8fc11abe1fea4f211cc7dbd58a173d1221627d90':
  mkv: Print unsupported mov tags when found

Conflicts:
	libavformat/matroskadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-13 22:04:02 +02:00
Michael Niedermayer 171af59d58 avformat/matroskadec: Cleanup error handling for bz2 & zlib
Fixes CID703652

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-12 18:34:26 +02:00
Vittorio Giovara 8fc11abe1f mkv: Print unsupported mov tags when found 2015-05-12 15:28:31 +01:00
Michael Niedermayer 17b26308a2 avformat/matroskadec: Use size_t for the variable holding a strlen() value.
Should make no difference but is more correct

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-11 04:05:20 +02:00
Michael Niedermayer 5d309d3091 avformat/matroskadec: Use tracks[k]->stream instead of s->streams[k]
The later is not correct

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-04 15:49:58 +02:00
Andreas Cadhalpun e54540655f matroskadec: check s->streams[k] before using it
This fixes a segmentation fault.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-04 15:48:55 +02:00
Andreas Cadhalpun eb9fb508b0 matroskadec: use uint64_t instead of int for index_scale
index_scale is set to matroska->time_scale of type uint64_t.

When index_scale is int, the assignment can overflow and e.g. result
in index_scale = 0. This causes a floating point exception due to the
division by index_scale.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-04 00:16:00 +02:00
Michael Niedermayer c187217287 avformat/matroskadec: Mark static tables as const
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-02 13:27:45 +02:00
Michael Niedermayer 0cab0931dc avformat/matroskadec: remove now duplicate doctype check
See: b8d7f3186e
See: d9fe6b926c
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-19 16:47:12 +02:00
Thomas Guillem b8d7f3186e matroskadec: fix crash when parsing invalid mkv
CC: libav-stable@libav.org

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2015-04-18 16:49:25 +02:00
Michael Niedermayer f98cad8759 Merge commit 'b8d7f3186e86234f6255f5e8ee9e98573b4d9a6e'
* commit 'b8d7f3186e86234f6255f5e8ee9e98573b4d9a6e':
  matroskadec: fix crash when parsing invalid mkv

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-18 21:13:25 +02:00
Michael Niedermayer 8e1717cf12 Merge commit 'c4d37cd9ef6e374bb888f6273259b10fac5bd909'
* commit 'c4d37cd9ef6e374bb888f6273259b10fac5bd909':
  matroskadec: export cover art correctly

Conflicts:
	libavformat/matroskadec.c

See: 511585ce7f
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-08 20:37:24 +02:00
wm4 c4d37cd9ef matroskadec: export cover art correctly
Generally, libavformat exports cover art pictures as video streams with
1 packet and AV_DISPOSITION_ATTACHED_PIC set. Only matroskadec exported
it as attachment with codec_id set to AV_CODEC_ID_MJPEG.

Obviously, this should be consistent, so change the Matroska demuxer to
export a AV_DISPOSITION_ATTACHED_PIC pseudo video stream.

Matroska muxing is probably incorrect too. I know that it can create
broken files with an audio track and just 1 video frame when e.g.
remuxing mp3 with APIC to mkv. But for now this commit does not change
anything about muxing, and also continues to write attachments with
AV_CODEC_ID_MJPEG should the muxer application have special knowledge
that the Matroska is broken in this way.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2015-04-08 12:36:53 +02:00
Vignesh Venkatasubramanian 2171b7c58e matroskadec: Add support for parsing live header files
This patch adds support for parsing live files (produced by
-f webm_chunk) which contains only the headers but no packets. This
is only used when using -f webm_dash_manifest. There will be a
follow up patch which adds live support to WebM DASH Manifest
muxer.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-05 00:39:29 +02:00
wm4 511585ce7f matroskadec: export cover art correctly
Generally, libavformat exports cover art pictures as video streams with
1 packet and AV_DISPOSITION_ATTACHED_PIC set. Only matroskadec exported
it as attachment with codec_id set to AV_CODEC_ID_MJPEG.

Obviously, this should be consistent, so change the Matroska demuxer to
export a AV_DISPOSITION_ATTACHED_PIC pseudo video stream.

Matroska muxing is probably incorrect too. I know that it can create
broken files with an audio track and just 1 video frame when e.g.
remuxing mp3 with APIC to mkv. But for now this commit does not change
anything about muxing, and also continues to write attachments with
AV_CODEC_ID_MJPEG should the muxer application have special knowledge
that the Matroska is broken in this way.

Fixes trac #4423.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-04-04 02:25:56 +02:00
Michael Niedermayer b0112019f9 Merge commit '6bdae41d3ef74a0865e8f87896e649f93b2f39bd'
* commit '6bdae41d3ef74a0865e8f87896e649f93b2f39bd':
  matroskadec: Check memory allocations

Conflicts:
	libavformat/matroskadec.c

See: 3e2a5b33f0
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-03-12 23:51:44 +01:00
Vittorio Giovara 6bdae41d3e matroskadec: Check memory allocations
CC: libav-stable@libav.org
2015-03-12 17:48:14 +00:00
Michael Niedermayer a0fe1a25fa Merge commit 'daf8cf358a098a903d59adb6c0d0cc3262a8c93e'
* commit 'daf8cf358a098a903d59adb6c0d0cc3262a8c93e':
  avformat: Don't anonymously typedef structs

Conflicts:
	libavformat/adtsenc.c
	libavformat/aiffenc.c
	libavformat/avidec.c
	libavformat/gif.c
	libavformat/iff.c
	libavformat/img2dec.c
	libavformat/jvdec.c
	libavformat/matroskadec.c
	libavformat/udp.c
	libavformat/wtvdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-14 21:07:40 +01:00
Diego Biurrun daf8cf358a avformat: Don't anonymously typedef structs 2015-02-14 10:13:47 -08:00
wm4 7862325f80 avformat/matroskadec: fix IGNIDX handling
Just because the user requested the seek index to be ignored, we can't
just skip essential headers. At least tags are often located at the end
of the file, and the old code simply ignored the seekhead for all
elements, not just the cue index. Also, it looks like it used the index
even if IGNIDX was set if the cue index was located in the beginning of
the file.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-12 17:08:51 +01:00
wm4 cac2295b21 matroska: redo seekhead handling
In particular, this reads chained seekheads. This makes seeking faster
in files which have the index indirectly linked through 2 seekheads.

As a side-effect, this warns when reading level-1 (toplevel) elements
multiple times (other than seekheads, clusters, and void/crc). Such
elements are not valid and likely break everything.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-12 13:51:41 +01:00
wm4 6938a095cb matroska: don't complain about unknown elements
Matroska is an extensible format - unknown elements must be expected. It
shouldn't complain about such elements to the user either; it'll just
generate noise. The "error_recognition & AV_EF_EXPLODE" is completely,
wrong why would it explode on valid files?

It's still useful for debugging, so the message is left in place with a
higher log level.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-09 21:33:33 +01:00
Michael Niedermayer fc3cdb00d0 avformat/matroskadec: Fix number suffixes
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-02-01 20:00:10 +01:00
Michael Niedermayer a1062e1437 avformat/matroskadec: Use av_malloc_array() for index_entries
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-25 00:26:53 +01:00
Michael Niedermayer c1cdce5dcb avformat/matroskadec: Check av_mallocz() return values
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-25 00:26:39 +01:00
Michael Niedermayer 6e70e4aca5 avformat/matroskadec: Use av_freep() to avoid leaving stale pointers in memory
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-01-06 15:07:50 +01:00
Thomas Volkert 00d7555f34 wavdec: RIFX file format support
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-18 00:10:35 +01:00
Xiaohan Wang 490a3ebf36 matroskadec: Fix read-after-free in matroska_read_seek()
In matroska_read_seek(), |tracks| is assigned at the begining of the
function. However, functions like matroska_parse_cues() could reallocate
the tracks and invalidate |tracks|.

This assigns |tracks| only before using it, so that it will not get
invalidated elsewhere.

Bug-Id: chromium/427266
2014-12-15 15:46:34 +01:00
Michael Niedermayer 72c984432e avformat/matroskadec: request a sample with recursive seek heads
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-07 22:45:34 +01:00
wm4 6551acab68 avformat/matroskadec: fix handling of recursive SeekHead elements
When matroska_execute_seekhead() is called, it goes through the list of
seekhead entries and attempts to read elements not read yet. When doing
this, the parser can find further SeekHead elements, and will extend the
matroska->seekhead list. This can lead to a (practically) infinite loop
with certain broken files. (Maybe it can happen even with valid files.
The demuxer doesn't seem to check correctly whether an element has
already been read.)

Fix this by ignoring elements that were added to the seekhead field
during executing seekhead entries.

This does not fix the possible situation when multiple SeekHead elements
after the file header (i.e. occur after the "before_pos" file position)
point to the same elements. These elements will probably be parsed
multiple times, likely leading to bugs.

Fixes ticket #4162.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-12-07 22:30:56 +01:00
Matthew Oliver 0167fa0060 msvc: Fix compilation errors due to header include order.
Ensures that the header include order is such that winsock2.h is always
included before windows.h or that windows.h does not include winsock.h.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-27 12:40:18 +01:00
Xiaohan Wang 33301f0017 Fix read-after-free in matroska_read_seek().
In matroska_read_seek(), |tracks| is assigned at the begining of the function.
However, functions like matroska_parse_cues() could reallocate the tracks so
that |tracks| can get invalidated.

This CL assigns |tracks| only before we use it so that it won't be invalidated.

BUG=427266
TEST=Test case in associated bug passes now.

Change-Id: I9c7065fe8f4311ca846076281df2282d190ed344

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-08 01:33:13 +01:00
Michael Niedermayer a52cb42ba6 avformat/matroskadec: use gmtime_r() for thread saftey
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-11-02 19:19:07 +01:00
Michael Niedermayer f0390638e0 avformat/matroskadec: Check the return code from strftime()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-26 17:07:29 +01:00
Michael Niedermayer 3ae818f6ab Merge commit 'e0caa1eb4e518111a81801db0d2ccdd2733ba94b'
* commit 'e0caa1eb4e518111a81801db0d2ccdd2733ba94b':
  matroskadec: check return values

Conflicts:
	libavformat/matroskadec.c

See: 1116491c53
Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-25 04:37:27 +02:00
Vittorio Giovara e0caa1eb4e matroskadec: check return values
CC: libav-stable@libav.org
Bug-Id: CID 733712
2014-10-24 23:48:51 +01:00
Vittorio Giovara 3c1199c3c4 matroskadec: fix leak on error
CC: libav-stable@libav.org
Bug-Id: CID 1026767
2014-10-24 23:43:25 +01:00
Michael Niedermayer a39201818f avformat/matroskadec: Fix cluster parsing loop which gathers seek information
Fixes Ticket2263
Fixes Ticket3934

Reviewed-by: Rodger Combs <rodger.combs@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-22 13:40:28 +02:00
Vignesh Venkatasubramanian 233f3ad869 lavf/webm_dash: Allow filenames without directories
Fix basename computation code to allow just file names without any
directories in the path.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-10 00:46:37 +02:00
Michael Niedermayer be695ee389 avformat/matroskadec: do not trust the default duration to be the real 1/timebase if its less than 5fps
Fixes Ticket3980

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-08 20:39:37 +02:00
Vignesh Venkatasubramanian b1071db3df lavf/webm_dash: Fix incorrect bandwidth computation
Fix incorrect bandwidth computation in some cases. When the cue end
descriptor is null (i.e.) start_time_ns == -1, existing bandwidth
computed (if any) should be returned rather than returning 0.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-01 20:47:18 +02:00
Vignesh Venkatasubramanian 8acb76567a lavf/webm_dash: fix hardcode in cues_end computation
Fix an incorrect hard code in cues_end computation. Updating the fate
test reference files related to the fix as well. The earlier computation
was clearly wrong as the cues_end field was greater than the file size
itself in some cases.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-10-01 20:47:11 +02:00
Clément Bœsch c7d8dbad14 avformat: remove FF_API_ASS_SSA dead code 2014-09-09 21:34:23 +02:00