mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-22 10:57:18 +00:00
LibMedia: Store whether a CodedFrame is a keyframe
This commit is contained in:
committed by
Jelle Raaijmakers
parent
d52ceec1bf
commit
0a03cc1cf7
Notes:
github-actions[bot]
2025-10-28 00:33:49 +00:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/LadybirdBrowser/ladybird/commit/0a03cc1cf76 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6410 Reviewed-by: https://github.com/R-Goc Reviewed-by: https://github.com/gmta ✅
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022, Gregory Bertilson <zaggy1024@gmail.com>
|
||||
* Copyright (c) 2022-2025, Gregory Bertilson <gregory@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <AK/Time.h>
|
||||
#include <LibMedia/CodedAudioFrameData.h>
|
||||
#include <LibMedia/CodedVideoFrameData.h>
|
||||
#include <LibMedia/FrameFlags.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
@@ -17,19 +18,23 @@ class CodedFrame final {
|
||||
public:
|
||||
using AuxiliaryData = Variant<CodedVideoFrameData, CodedAudioFrameData>;
|
||||
|
||||
CodedFrame(AK::Duration timestamp, ByteBuffer&& data, AuxiliaryData auxiliary_data)
|
||||
CodedFrame(AK::Duration timestamp, FrameFlags flags, ByteBuffer&& data, AuxiliaryData auxiliary_data)
|
||||
: m_timestamp(timestamp)
|
||||
, m_flags(flags)
|
||||
, m_data(move(data))
|
||||
, m_auxiliary_data(auxiliary_data)
|
||||
{
|
||||
}
|
||||
|
||||
AK::Duration timestamp() const { return m_timestamp; }
|
||||
FrameFlags flags() const { return m_flags; }
|
||||
bool is_keyframe() const { return has_flag(m_flags, FrameFlags::Keyframe); }
|
||||
ByteBuffer const& data() const { return m_data; }
|
||||
AuxiliaryData const& auxiliary_data() const { return m_auxiliary_data; }
|
||||
|
||||
private:
|
||||
AK::Duration m_timestamp;
|
||||
FrameFlags m_flags;
|
||||
ByteBuffer m_data;
|
||||
AuxiliaryData m_auxiliary_data;
|
||||
};
|
||||
|
||||
@@ -207,6 +207,8 @@ DecoderErrorOr<CodedFrame> MatroskaDemuxer::get_next_sample_for_track(Track cons
|
||||
status.block = TRY(status.iterator.next_block());
|
||||
status.frame_index = 0;
|
||||
}
|
||||
|
||||
auto flags = status.block->only_keyframes() ? FrameFlags::Keyframe : FrameFlags::None;
|
||||
auto aux_data = [&] -> CodedFrame::AuxiliaryData {
|
||||
if (track.type() == TrackType::Video) {
|
||||
auto cicp = MUST(m_reader.track_for_track_number(track.identifier()))->video_track()->color_format.to_cicp();
|
||||
@@ -218,7 +220,7 @@ DecoderErrorOr<CodedFrame> MatroskaDemuxer::get_next_sample_for_track(Track cons
|
||||
VERIFY_NOT_REACHED();
|
||||
}();
|
||||
auto sample_data = DECODER_TRY_ALLOC(ByteBuffer::copy(status.block->frame(status.frame_index++)));
|
||||
return CodedFrame(status.block->timestamp(), move(sample_data), aux_data);
|
||||
return CodedFrame(status.block->timestamp(), flags, move(sample_data), aux_data);
|
||||
}
|
||||
|
||||
DecoderErrorOr<AK::Duration> MatroskaDemuxer::total_duration()
|
||||
|
||||
@@ -217,8 +217,10 @@ DecoderErrorOr<CodedFrame> FFmpegDemuxer::get_next_sample_for_track(Track const&
|
||||
// to wipe the packet afterwards.
|
||||
auto packet_data = DECODER_TRY_ALLOC(ByteBuffer::copy(m_packet->data, m_packet->size));
|
||||
|
||||
auto flags = (m_packet->flags & AV_PKT_FLAG_KEY) != 0 ? FrameFlags::Keyframe : FrameFlags::None;
|
||||
auto sample = CodedFrame(
|
||||
time_units_to_duration(m_packet->pts, stream->time_base),
|
||||
flags,
|
||||
move(packet_data),
|
||||
auxiliary_data);
|
||||
|
||||
|
||||
21
Libraries/LibMedia/FrameFlags.h
Normal file
21
Libraries/LibMedia/FrameFlags.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2025, Gregory Bertilson <gregory@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/EnumBits.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace Media {
|
||||
|
||||
enum class FrameFlags : u8 {
|
||||
None = 0,
|
||||
Keyframe = 1 << 0,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
AK_ENUM_BITWISE_OPERATORS(Media::FrameFlags);
|
||||
Reference in New Issue
Block a user