mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
LibVideo: Add the concept of codec identifiers
This is required for detecting which decoder should be used. Only a small subset of codecs identifiers is added for now
This commit is contained in:
parent
ff48b7333c
commit
1f55cc942d
5 changed files with 135 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibCore/EventReceiver.h>
|
||||
#include <LibVideo/CodecID.h>
|
||||
#include <LibVideo/DecoderError.h>
|
||||
#include <LibVideo/Sample.h>
|
||||
#include <LibVideo/Track.h>
|
||||
|
@ -28,6 +29,8 @@ public:
|
|||
return sample.release_nonnull<VideoSample>();
|
||||
}
|
||||
|
||||
virtual DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) = 0;
|
||||
|
||||
// Returns the timestamp of the keyframe that was seeked to.
|
||||
// The value is `Optional` to allow the demuxer to decide not to seek so that it can keep its position
|
||||
// in the case that the timestamp is closer to the current time than the nearest keyframe.
|
||||
|
|
|
@ -71,6 +71,32 @@ DecoderErrorOr<MatroskaDemuxer::TrackStatus*> MatroskaDemuxer::get_track_status(
|
|||
return &m_track_statuses.get(track).release_value();
|
||||
}
|
||||
|
||||
CodecID MatroskaDemuxer::get_codec_id_for_string(DeprecatedFlyString const& codec_id)
|
||||
{
|
||||
dbgln_if(MATROSKA_DEBUG, "Codec ID: {}", codec_id);
|
||||
if (codec_id == "V_VP8")
|
||||
return CodecID::VP8;
|
||||
if (codec_id == "V_VP9")
|
||||
return CodecID::VP9;
|
||||
if (codec_id == "V_MPEG1")
|
||||
return CodecID::MPEG1;
|
||||
if (codec_id == "V_MPEG2")
|
||||
return CodecID::H262;
|
||||
if (codec_id == "V_MPEG4/ISO/AVC")
|
||||
return CodecID::H264;
|
||||
if (codec_id == "V_MPEGH/ISO/HEVC")
|
||||
return CodecID::H265;
|
||||
if (codec_id == "V_AV1")
|
||||
return CodecID::AV1;
|
||||
if (codec_id == "V_THEORA")
|
||||
return CodecID::Theora;
|
||||
if (codec_id == "A_VORBIS")
|
||||
return CodecID::Vorbis;
|
||||
if (codec_id == "A_OPUS")
|
||||
return CodecID::Opus;
|
||||
return CodecID::Unknown;
|
||||
}
|
||||
|
||||
DecoderErrorOr<Optional<Duration>> MatroskaDemuxer::seek_to_most_recent_keyframe(Track track, Duration timestamp, Optional<Duration> earliest_available_sample)
|
||||
{
|
||||
// Removing the track status will cause us to start from the beginning.
|
||||
|
@ -119,4 +145,10 @@ DecoderErrorOr<Duration> MatroskaDemuxer::duration()
|
|||
return duration.value_or(Duration::zero());
|
||||
}
|
||||
|
||||
DecoderErrorOr<CodecID> MatroskaDemuxer::get_codec_id_for_track(Track track)
|
||||
{
|
||||
auto codec_id = TRY(m_reader.track_for_track_number(track.identifier())).codec_id();
|
||||
return get_codec_id_for_string(codec_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
|
||||
DecoderErrorOr<Duration> duration() override;
|
||||
|
||||
DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) override;
|
||||
|
||||
protected:
|
||||
DecoderErrorOr<NonnullOwnPtr<Sample>> get_next_sample_for_track(Track track) override;
|
||||
|
||||
|
@ -44,6 +46,7 @@ private:
|
|||
};
|
||||
|
||||
DecoderErrorOr<TrackStatus*> get_track_status(Track track);
|
||||
CodecID get_codec_id_for_string(DeprecatedFlyString const& codec_id);
|
||||
|
||||
Reader m_reader;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue