Commit Graph

42 Commits

Author SHA1 Message Date
Zaggy1024
c34b5a544e LibMedia: Set Matroska "complex" tracks' types based on the codec
The spec indicates that the codec defines how to interpret the data,
so use our CodecIDs to determine the track type.
2025-11-21 16:51:58 -06:00
Zaggy1024
eaf1564d1b LibMedia: Use u32 instead of uint to parse FFmpeg version numbers
This was breaking the build on Windows, apparently we don't have uint
there.
2025-11-21 09:32:54 -06:00
Zaggy1024
e72080b15f LibMedia: Adjust Matroska seeking based on SeekPreRoll
This is important for seeking Opus tracks, as Opus needs to decode a
certain amount of input data before its output converges. Without this,
audio after a seek can sound muffled briefly.
2025-11-21 11:02:44 +01:00
Zaggy1024
31c751ee92 LibMedia: Handle buggy FFmpeg WebM muxing in Matroska::Reader 2025-11-21 11:02:44 +01:00
Zaggy1024
653a3452df LibMedia: Move conversion of Matroska codecs to CodecID to a new file
This function is needed in Matroska::Reader to check for Opus in the
next commit.
2025-11-21 11:02:44 +01:00
Zaggy1024
dcc2359eac LibMedia: Clamp Matroska cluster timestamps when casting them 2025-11-21 11:02:44 +01:00
Zaggy1024
f899d49e18 LibMedia: Make Matroska's get_element_id_size function static
...to silence a warning.
2025-11-21 11:02:44 +01:00
Zaggy1024
180f2a07f1 LibMedia: Read the Matroska SamplingFrequency element 2025-11-21 11:02:44 +01:00
Zaggy1024
364b422ae0 LibMedia: Store Matroska audio and video track info more safely
We don't need to put these in a union, it's not gonna save us much
space. The reader also may find both audio and video elements, in which
case this code would produce undefined behavior.

Also, with this change, we can use the default values from the spec.
2025-11-21 11:02:44 +01:00
Zaggy1024
b59f0501b8 LibMedia: Use String instead of ByteString in Matroska::Document 2025-11-21 11:02:44 +01:00
Zaggy1024
0f6f5cd353 LibMedia+Tests: Clear the current block when seeking in MatroskaDemuxer
Otherwise, if the sample iterator resides in a block with multiple
frames before the seek, the demuxer will output all the remaining
frames from that block before moving on to the block at the seeked
position.
2025-11-13 13:48:17 +01:00
Zaggy1024
82586645dc LibMedia: Export MatroskaDemuxer for use in tests 2025-11-11 00:50:42 +01:00
Zaggy1024
5640541c44 LibMedia: Handle Xiph lacing in Matroska files 2025-11-11 00:50:42 +01:00
Zaggy1024
634e5ff491 LibMedia: Move CICP values from CodedFrame to Track
All our current demuxers have these constant for an entire track, so we
don't need to get them for every frame we output.
2025-11-05 18:40:02 +01:00
Zaggy1024
6bd7e338fd LibMedia: Remove redundant parameter names in Demuxer 2025-11-05 18:40:02 +01:00
Zaggy1024
8f666c6360 LibMedia: Support parsing Matroska BlockGroup elements
This allows us to read WebM files that have blocks with additional data
attached to each block for an alpha frame. For now, only the main coded
data is used, the additional data containing the alpha channel is
ignored.
2025-11-04 16:59:50 +01:00
Zaggy1024
b1c9a872bc LibMedia: Return whether a demuxer seek moved the stream position
We no longer need to return a timestamp from the seek function, which
makes it much easier to implement backend-agnostically.
2025-10-27 17:28:49 -07:00
Zaggy1024
e5a6b76a40 LibMedia: When reaching EOS, clear Matroska iterators' last timestamp
This ensures that if we're at EOS, we never skip a seek, so that
seeking to the end of a video always gets a frame.
2025-10-27 17:28:49 -07:00
Zaggy1024
86e236519d LibMedia: Give demuxer seeks an option to always seek to a keyframe
By default, MatroskaDemuxer chooses not to seek if the current frame
is closer to the seek target than the keyframe that precedes the seek
target. However, it can be desirable to seek to a keyframe anyway, so
let's allow that.
2025-10-27 17:28:49 -07:00
Zaggy1024
e94ab24e66 LibMedia: Don't assert when MatroskaDemuxer seeks near the start
Reader::seek_to_random_access_point() isn't actually guaranteed to
return a sample iterator that has already gotten a block timestamp.
This verify passes in almost every case, but if we happen to seek to a
timestamp before the second keyframe, we'd crash.
2025-10-27 17:28:49 -07:00
Zaggy1024
0a03cc1cf7 LibMedia: Store whether a CodedFrame is a keyframe 2025-10-27 17:28:49 -07:00
Zaggy1024
d52ceec1bf LibMedia: Take Track const& in Demuxer methods 2025-10-27 17:28:49 -07:00
Zaggy1024
d3941cd83d LibMedia: Support playing FLAC 2025-10-27 17:28:49 -07:00
Zaggy1024
29ab9c5fd5 LibMedia: Let the Matroska LanguageBCP47 element override Language
The Matroska spec indicates that this field should always override the
Language element when it is present.
2025-10-27 17:28:49 -07:00
Zaggy1024
e11da1f85f LibMedia: Store a name and language in Media::Track 2025-10-27 17:28:49 -07:00
Zaggy1024
e8238b4098 LibMedia: Replace FlyString with String for Matroska track attributes
The values stored by these are either going to be fairly unique or too
short to benefit from FlyString.
2025-10-27 17:28:49 -07:00
Zaggy1024
dd052832c1 LibMedia: Support the MP3 and AAC codecs in our demuxer 2025-10-27 17:28:49 -07:00
Zaggy1024
6b34003c2c LibMedia: Support coded audio frames in our demuxers
This adds a new variant of the metadata storage in CodedFrame for audio
frames, called CodedAudioFrameData.
2025-10-27 17:28:49 -07:00
Zaggy1024
523e7e2ffa LibMedia: Make Demuxer atomically ref-counted
We'll need to share the demuxer between multiple decoder providers, and
those will hold references to the demuxer from their own decoder
threads.
2025-10-27 17:28:49 -07:00
Zaggy1024
30d4810d70 LibMedia: Actually read Matroska tracks' CodecDelay elements 2025-10-02 11:03:26 +02:00
Zaggy1024
ce228663f1 LibMedia: Rename Matroska TRACK_CODEC_PRIVATE to TRACK_CODEC_PRIVATE_ID 2025-10-02 11:03:26 +02:00
Zaggy1024
8d77e8b09d LibMedia: Refer to demuxer outputs as coded frames
This should be a clearer name, as "sample" is most often used to refer
to the output of a decoder.
2025-09-22 12:04:29 -05:00
Zaggy1024
26a21f2070 LibMedia: Make MatroskaDemuxer::get_codec_id_for_string static 2025-09-12 11:23:47 +02:00
Zaggy1024
9077873803 LibMedia: Stop initializing an empty optional in MatroskaDemuxer
There was a warning for the Optional initializer having no effect, but
removing the initializer caused the call to add a track to the HashMap
to complain. A constructor looks a little nicer here anyway.
2025-09-12 11:23:47 +02:00
Zaggy1024
ae7f82591b LibMedia: Separate file duration from track duration in Demuxer
Most users will only care about the total file duration, and shouldn't
be required to determine the file duration from multiple track
durations. To facilitate that, add a total_duration() function that
returns the demuxer's duration not associated to any particular track.
2025-09-12 11:23:47 +02:00
Zaggy1024
6653b747ff LibMedia: Allow demuxers to specify a preferred track
...and return all tracks of a matching type from FFmpegDemuxer, rather
than only the single best one.
2025-09-12 11:23:47 +02:00
Zaggy1024
8d64e72655 LibMedia: Remove the duration field from Track::VideoData
Most demuxer users will only care about the whole file's duration
anyway, so this field doesn't really do us any good.
2025-09-12 11:23:47 +02:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
ayeteadoe
8150fb4cbb LibMedia: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
Luke Wilde
b789ba5e5f LibMedia: Demux videos with FFmpeg
This gives us access to container types other than Matroska, the
biggest one being MP4.
2025-03-13 19:33:44 +01:00
Pavel Shliak
b60cb699a9 LibMedia: Clean up #include directives
This change aims to improve the speed of incremental builds.
2024-11-21 14:08:33 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00