Commit graph

536 commits

Author SHA1 Message Date
Jan Schmidt
78eaa7c6ed matroska: Check the return value of gst_segment_do_seek()
gst_segment_do_seek() can fail.
2020-04-02 05:23:17 +00:00
Sebastian Dröge
5d0657d4ae matroska-demux: Send instant-rate-change event if requested in the SEEK event
Short-circuit instant rate change events by generating
a downstream instant-rate-change event and doing no further
seek processing.
2020-04-02 05:23:17 +00:00
Seungha Yang
cb8c83e799 matroska: Update for video-hdr struct change
See the change of -base https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/594
2020-04-01 05:19:24 +00:00
Aaron Boxer
46989dca96 documentation: fix a number of typos 2019-10-05 22:38:11 +00:00
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
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
0a6a62aa76 docs: Port all docstring to gtk-doc markdown 2019-05-13 10:24:40 -04: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
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
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
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
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
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
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
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
Sean DuBois
de8f080a5c Add AV1 to matroska plugin
https://bugzilla.gnome.org/show_bug.cgi?id=784160
2017-12-15 18:00:31 +01:00
Edward Hervey
f89d672eb7 matroskademux: Remove bogus error message
It's just informational
2017-11-13 13:51:20 +01:00
Seungha Yang
5dd39d8946 matroskademux: Add parsing Colour element
... and forward colorimetry to downstream. The Colour element describes
various color information (similar to 'colr' box in isobmff).
Note that, due to the comparatively limited syntax for color information
in vpx codecs, the color information in mkv/wemb container level
should be used for sophisticated color handling (e.g., HDR video).

https://bugzilla.gnome.org/show_bug.cgi?id=790023
2017-11-08 11:01:55 +02:00
Mark Nauwelaerts
cf3f195012 matroskademux: search_cluster should find preceding cluster before target
... since failing this constraint takes search_pos by surprise which might
then end up in an infinite loop.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=787538
2017-09-11 20:39:22 +02:00
Mark Nauwelaerts
286df32e03 matroskademux: segment seek position is expressed in buffer time
... so it need not be corrected again for stream start
2017-07-09 10:55:00 +02:00
Mark Nauwelaerts
04fd953713 matroskademux: track highest known cluster position and time
... to use as a fallback initial duration estimate and to provide for
interpolation when scanning for position.
2017-06-24 17:36:54 +02:00
Mark Nauwelaerts
84c6aaf45b matroskademux: improve and simplify searching for cluster and position
... avoiding inefficiency proportional to file size
2017-06-24 17:36:54 +02:00
Mark Nauwelaerts
d7b736fa11 matroskademux: increase chunk size when scanning for cluster 2017-06-24 17:36:54 +02:00
Mark Nauwelaerts
b19ef0df30 matroskademux: maintain variable state when searching for position
... so skipping to next cluster happens efficiently
2017-06-24 17:36:54 +02:00
Jan Schmidt
d76bd1913f qtdemux: matroskademux: Ignore repeated seek events
Similar to what was done in adaptivedemux, ignore seek
events we've already handled - such as when they are received
on every srcpad of files with lots of streams.
2017-03-22 00:40:01 +11:00
Mark Nauwelaerts
e6a251e9c0 matroskademux: adjust segment stop for KEY_UNIT negative rate seeking 2016-12-29 12:48:56 +01:00
Sebastian Dröge
5d4c71d76e matroskademux: Fix cluster searching if we search multiple times in one chunk
After finding a cluster id in the byte reader, we skip ahead the reader
position by one further byte to be able to continue searching from there
inside the same chunk if the cluster candidate was a false positive.

We have to accomodate for that additional byte when resuming the search,
otherwise all following pulls are off-by-one for every resume and we run
into an assertion.
2016-11-22 20:24:59 +02:00
Nicola Murino
0ef3a71b89 matroskademux: add support for skipping invalid data in push mode
https://bugzilla.gnome.org/show_bug.cgi?id=774566
2016-11-21 13:38:08 +02:00