Commit graph

933 commits

Author SHA1 Message Date
Mart Raudsepp
67958ccce8 matroska: Provide audio lead-in for some lossy formats
Various audio formats require an audio lead-in to decode it properly.
Most parsers would take care of it, but when a container like matroska is
involved, the demuxer handles the seeking and without its own lead-in
handling would never even pass the lead-in data to the parser.
This commit provides an initial implementation of that for audio/mpeg,
audio/x-ac3 and audio/x-eac3 by calculating the worst case lead-in time
needed from known samplerate, potential lead-in frames need and the
maximum blocksize possible for the format (as we don't parse that out
exactly in matroskademux) and seeking that much earlier in case of
accurate seeks. This is especially important for NLE use-cases with GES.

If accurate seeking to a position that happens to have a video keyframe,
it'll go back to the previous keyframe than needed, but with typical
video files that's the best we can do anyway without falling back to
scanning the clusters, as typically only keyframes are indexed in
Cueing Data.
If the media doesn't have a CUE, then we bisect for the cluster to seek
to with the same modified time as well in case of accurate seeking,
ensuring sufficient lead-in. This code path is typically hit only with
(suboptimal) audio-only matroska files, e.g. when created with ffmpeg,
which doesn't add a CUE for audio-only mkv muxing.
2019-08-07 18:51:57 -04:00
Doug Nazar
b0534c65d1 matroska: Handle interlaced field order 2019-08-07 14:12:32 +00:00
Doug Nazar
5451e4e900 matroskademux: Ignore crc32 element while peeking at cluster. 2019-07-27 14:21:34 -04:00
Seungha Yang
aa0544ab8f matroska: Port to color_{primaries,transfer,matrix}_to_iso
... and remove duplicated code.
2019-07-15 23:25:53 +09:00
Seungha Yang
67b8ce3167 matroskademux: Fix mismatched transfer characteristic
TransferCharacteristics(18) should be ARIB STD-B67 (HLG)
See https://www.webmproject.org/docs/container/#TransferCharacteristics

Also map more color primaries indexes which have been handled by matroska-mux.
2019-07-09 23:11:45 +09:00
Jan Schmidt
2479ccac7d matroska: Initialise a video_context field to satisfy valgrind
Clear the mastering_display_info_present field explicitly
after reallocating the track context into a video context
to avoid uninitialised warnings in valgrind
2019-06-16 11:10:41 +10:00
Aaron Boxer
7bd1909f4f matroskamux: fix typo in property description 2019-06-05 07:37:17 +01:00
Sebastian Dröge
cced65ee21 matroskamux: Add new property to offset all streams to start at zero
This takes the timestamp of the earliest stream and offsets it so that
it starts at 0. Some software (VLC, ffmpeg-based) does not properly
handle Matroska files that start at timestamps much bigger than zero.

Closes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/449
2019-05-29 11:53:02 +00:00
Seungha Yang
1ae4814a74 matroska: Add BT2020_10, PQ and HLG transfer functions
The direct use of newly added transfer functions
2019-05-24 16:32:38 +09:00
Thibault Saunier
af01988534 doc: Port documentation to hotdoc 2019-05-13 11:34:56 -04:00
Thibault Saunier
0a6a62aa76 docs: Port all docstring to gtk-doc markdown 2019-05-13 10:24:40 -04:00
Seungha Yang
74e409590a matroskamux: Write MasteringMetadata and Max{CLL,FALL}
Enable muxing with HDR meta data if upstream provided it
2019-05-01 14:28:36 +00:00
Seungha Yang
61f9a2a415 matroskademux: Add support parsing HDR metadata
Set SMPTE ST 2086 mastering-display-metadata and
content-light-level to caps, if any
2019-05-01 14:28:36 +00:00
Seungha Yang
53fedc43ae matroska: Remove white space 2019-05-01 14:28:36 +00:00
Sebastian Dröge
0c7c31d197 matroskamux: Fix typo in error message 2019-04-25 21:52:42 +03:00
Seungha Yang
7fb8abf8bb meson: matroska: Ensure header dependency not only library
Library existence does not guarantee header.
2019-04-22 20:40:50 +09:00
Guillaume Desmottes
fcd568dd56 matroskamux: add support for new color primaries 2019-03-12 16:52:45 +01:00
Tim-Philipp Müller
899d0c4b3b matroskademux: fix AV1 caps when there's no codec_data
There is no "byte-stream" format for AV1 in Matroska, this
was probably cargo-culted from H.264. codec_data / CodecPrivate
is now mandatory for AV1 in Matroska[*], but there are sample
files out there which don't have it (e.g. some Elecard ones).

[*] https://github.com/Matroska-Org/matroska-specification/blob/master/codec/av1.md#codecprivate-1
2019-03-01 17:37:55 +00:00
Christopher Snowhill
818428ce9c webmmux: allow resolutions above 4096
Modify the caps string to allow width and height greater than 4096.
There is no need to restrict it since the matroska format allows the
width and height values to be up to eight bytes long, and this also
applies to the webm subset of the format.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/550
2019-02-02 15:40:53 +00:00
Seungha Yang
022fbe9a46 matroskademux: Don't leak allocated index memory
Don't forget to free returned memory from _search_pos()
2018-12-26 20:31:10 +09:00
Matej Knopp
e9495c55f4 matroskademux: fix handling of MS ACM audio
Pass riff codec-data as strf, not strd, which is where
gst_riff_create_audio_caps() expects the WAVEFORMATEXTENSIBLE
data.

https://bugzilla.gnome.org/show_bug.cgi?id=757583
Fixes #234
2018-11-28 11:55:14 +00:00
Jordan Petridis
515ada7e22
Run gst-indent through the files
This is required before we enabled an indent test in the CI.

https://gitlab.freedesktop.org/gstreamer/gstreamer-project/issues/33
2018-11-28 05:52:16 +02:00
Alicia Boya García
753b7c17f3 matroskademux: Defer seeks received before GST_MATROSKA_READ_STATE_DATA
This patch enables matroskademux to receive seeks before it reaches
GST_MATROSKA_READ_STATE_DATA.

Closes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/514

This also enables receiving seeks in the element READY state.

When such a seek is received, it is stored to be later handled when
GST_MATROSKA_READ_STATE_DATA is reached.
2018-11-15 08:01:29 +00:00
Matthew Waters
40fc8aea8f matroska: implement preliminary support for the bitrate query
Return the size / total duration as a ballpark estimate.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/60
2018-11-07 15:07:18 +00:00
Johan Bjäreholt
e736f29376 matroska-demux: Fix caps memleak
https://bugzilla.gnome.org/show_bug.cgi?id=797326
2018-10-27 10:48:38 +01:00
Johan Bjäreholt
abfc7da345 matroska-ids: Fix uninitialized memory in contexts
https://bugzilla.gnome.org/show_bug.cgi?id=797327
2018-10-24 09:54:20 +01:00
Thibault Saunier
defae35035 matroskdemux: do not use MapInfo.data after unmapping
And minor gst-indenting
2018-10-03 17:39:33 +02:00
Yacine Bandou
0432826950 matroska: Add the WebM encrypted content support in matroskademux
This commit:

1. Reads the WebM and Matroska ContentEncryption subelements.

2. Creates a GST_PROTECTION event for each ContentEncryption, which
   will be sent before pushing the first source buffer.
   The DRM system id field in this event is set to GST_PROTECTION_UNSPECIFIED_SYSTEM_ID,
   because it isn't specified neither by Matroska nor by the WebM spec.

3. Reads the protection information of encrypted Block/SimpleBlock and
   extracts the IV and the partitioning format (subsamples).

4. Creates the metadata protection for each encrypted Block/SimpleBlock,
   with those informations: KeyID (extracted from ContentEncryption element),
   IV and partitioning format.

5. Adds a new caps for WebM encrypted content named "application/x-webm-enc",
   with the following new fields:

   "encryption-algorithm": The encryption algorithm used.
                           values: "None", "DES", "3DES", "Twofish", "Blowfish", "AES".

   "encoding-scope": The field that describes which Elements have been modified.
                     Values: "frame", "codec-data", "next-content".

   "cipher-mode": The cipher mode used in the encryption.
                  Values: "None", "CTR".

https://bugzilla.gnome.org/show_bug.cgi?id=765275
2018-10-03 16:59:14 +02:00
Alicia Boya García
7ceefec714 matroskademux: Emit no-more-pads after parsing Tracks
Currently matroskademux does not emit no-more-pads until the first
Cluster is parsed, even though the Tracks have already been parsed and
from that point on there can be no more tracks.

This is important in MSE because the browser needs to know when the MSE
initialization segment has been completely parsed so that it can expose
the tracks to the user. Some applications depend on this been done
before they feed frames to the demuxer.

As a consequence, historically WebKit has relied on hacks such as
listening to the `pad-added` event, which made impossible to support
multiple tracks in the same file. Let's fix that.

https://bugzilla.gnome.org/show_bug.cgi?id=797187
2018-09-21 17:41:57 -03:00
Alicia Boya García
0e60076a39 matroskademux: Parse successive Tracks elements
This patch allows matroskademux to parse a second Tracks element,
erroring out if the tracks are not compatible (different number, type or
codec) and emitting new caps and tag events should they have changed.

https://bugzilla.gnome.org/show_bug.cgi?id=793333
2018-09-21 17:27:57 -03:00
Alicia Boya García
f279bc5336 matroskademux: Refactor track parsing out from adding tracks
This splits gst_matroska_demux_add_stream() into:

* gst_matroska_demux_parse_stream(): will read the Matroska bytestream
  and fill a GstMatroskaTrackContext.

* gst_matroska_demux_parse_tracks(): will check there are no repeated
  tracks.

* gst_matroska_demux_add_stream(): creates and sets up the pad for the
  track.

https://bugzilla.gnome.org/show_bug.cgi?id=793333
2018-09-21 17:27:57 -03:00
Alicia Boya García
9dc7859184 matroskademux: Allow Matroska headers to be read more than once
This is necessary for MSE, where a new MSE initialization segment may be
appended at any point. These MSE initialization segments consist of an
entire WebM file until the first Cluster element (not included). [1]

Note that track definitions are ignored on successive headers, they must
match, but this is not checked by matroskademux (look for
`(!demux->tracks_parsed)` in the code).

Source pads are not altered when the new headers are read.

This patch has been splitted from the original patch from eocanha in [2].

[1] https://www.w3.org/TR/mse-byte-stream-format-webm/
[2] https://bug334082.bugzilla-attachments.gnome.org/attachment.cgi?id=362212

https://bugzilla.gnome.org/show_bug.cgi?id=793333
2018-09-21 17:27:57 -03:00
Martin Kelly
be05515da7 matroskamux: don't store used UIDs
Currently, whenever we generate a 128-bit UID, we store it in a list and
return 0 if we ever encounter a collision. This is so mathematically
improbable that it's not worth checking for, so we can save memory and
time by not tracking the UID. Even if a collision happened, a list of
only 10 UIDs would be unlikely to detect it.

This article has a good description of how improbable a collision is:
https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions

https://bugzilla.gnome.org/show_bug.cgi?id=797086
2018-09-06 14:14:56 -04:00
Tim-Philipp Müller
9d6621a30d matroskademux: implement keyframe search also without cluster prev size
If we have cluster prev size (GStreamer muxer will write it by default),
we can go back to the previous cluster efficiently, but if we don't then
just search backwards until we find a cluster ebml identifier, like we
do when searching for clusters in the bisection loop.
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
2d6efbbae2 matroskademux: make max backtrack distance for keyframe search configurable
Add property instead of hardcoding it in the code.

In some scenarios such as CCTV variable fps and extra long GOPs are
used to minimise storage space, for example. In those cases there might
not be any keyframes for many minutes, so provide a property to override
the max allowed distance.

https://bugzilla.gnome.org/show_bug.cgi?id=790696
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
2990f0730a matroskademux: set limit how much to backtrack to find a keyframe
If we seek without an index and land on a cluster that starts
with a delta frame.

https://bugzilla.gnome.org/show_bug.cgi?id=790696
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
ffb4533137 matroskademux: no need to search for keyframes for intra-only streams
If the video streams are all I-frame only then we don't need to look
for a cluster with a keyframe, we can just assume there will be one.

https://bugzilla.gnome.org/show_bug.cgi?id=790696
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
694631520d matroskademux: figure out if we have prev_size when starting up
This is useful to know in case someone initiates a seek or
direction change before we reach the second cluster.
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
43ce85f794 matroskademux: try to ensure keyframe when seeking without index
When seeking in pull mode without an index (because there is no index
or the file is still being written to) we bisect to find the right
cluster to jump to. However, it's possible the cluster we found doesn't
start with a keyframe, which leads to decoding errors, so if we know
that the found cluster starts with a delta frame try to scan back to
previous clusters until we find one that starts with a keyframe or
we are back at the beginning. Theoretically it's possible that all
clusters but the first one do not start with a keyframe and the
keyframes are in the middle of clusters, but this is extremely
unusual, so we will cover this case with a basic sanity check.

This problem is especially problematic with content recorded with
dynamic GOP and FPS, where long GOP lengths and low FPS may cause a
large set of clusters to lack key frames. Playback would then be
started on a non-keyframe cluster, and the large number of such frames
would make the content impossible to decode fo a long stretch of time.

Based on patch by: Mats Lindestam <matslm@axis.com>

https://bugzilla.gnome.org/show_bug.cgi?id=790696
2018-08-27 23:01:21 +02:00
Tim-Philipp Müller
93ddea2a70 matroskademux: extract cluster prevsize if available
This is useful for reverse playback/trickmodes
without an index, and will also be useful in the
seek handler if we need to scan back to find a cluster
that starts with a keyframe.

https://bugzilla.gnome.org/show_bug.cgi?id=790696
2018-08-27 23:00:53 +02:00
Tim-Philipp Müller
fd0afe033b matroska: fix handling of FlagInterlaced
This is an enum not a boolean, and a value of 2 signals
that the video is progressive, but we would mistakenly set
interlace-mode=mixed on the output caps.

https://bugzilla.gnome.org/show_bug.cgi?id=787206
2018-08-23 23:32:06 +02:00
Nirbheek Chauhan
8f807477eb meson: Add feature options for all plugins
Checks for GL, Qt5, and C++ are still automagic. FIXMEs have been
added for these so they can be fixed later.

https://bugzilla.gnome.org/show_bug.cgi?id=795107
2018-07-27 18:42:54 +05:30
Olivier Crête
d641b37fcb matroskamux: Put codec_data as CodecPrivate for AV1 2018-07-26 14:14:53 -04:00
Olivier Crête
e3b14e345d matroskamux: Accept muxing AV1 2018-07-26 14:14:53 -04:00
Olivier Crête
415caf4b87 matroskademux: Extract codec_data for AV1
According to
https://github.com/Matroska-Org/matroska-specification/blob/av1-mappin/codec/av1.md
2018-07-26 14:14:53 -04:00
Philippe Normand
4c10a1ba27 matroskademux: Set subtitle tag title from TrackName field
GUI applications can then use the title tag to set menu items or labels
representing the track.

https://bugzilla.gnome.org/show_bug.cgi?id=796567
2018-06-29 17:11:28 +01:00
Mathieu Duponchelle
d9235404aa matroska-mux: write colorimetry
This is a straightforward translation of 5dd39d8, can be trivially
checked by running:

gst-launch-1.0 -v videotestsrc ! video/x-raw, colorimetry=2:4:7:1 ! \
matroskamux ! matroskademux ! fakesink

and verifying that the colorimetry is correctly preserved.

https://bugzilla.gnome.org/show_bug.cgi?id=796344
2018-05-23 15:14:23 +02:00
Tim-Philipp Müller
adc315978c matroskademux: tag disabled streams with FLAG_UNSELECT
So they're never picked as default, only by explicit
user action.

https://bugzilla.gnome.org/show_bug.cgi?id=690911
2018-05-15 10:25:35 +01:00
Xavier Claessens
edd9c8f6b8 Meson: Generate pc file for all plugins in good
https://bugzilla.gnome.org/show_bug.cgi?id=794568
2018-04-25 11:07:06 +01:00
Alicia Boya García
a5e93b7062 matroskademux: Add comment about Opus clipping
https://bugzilla.gnome.org/show_bug.cgi?id=793523
2018-04-13 09:50:35 +01:00