LibMedia: Store a duration in CodedFrame
This commit is contained in:
parent
9e2b674da5
commit
42b19bdebf
3 changed files with 10 additions and 2 deletions
|
|
@ -18,8 +18,9 @@ class CodedFrame final {
|
|||
public:
|
||||
using AuxiliaryData = Variant<CodedVideoFrameData, CodedAudioFrameData>;
|
||||
|
||||
CodedFrame(AK::Duration timestamp, FrameFlags flags, ByteBuffer&& data, AuxiliaryData auxiliary_data)
|
||||
CodedFrame(AK::Duration timestamp, AK::Duration duration, FrameFlags flags, ByteBuffer&& data, AuxiliaryData auxiliary_data)
|
||||
: m_timestamp(timestamp)
|
||||
, m_duration(duration)
|
||||
, m_flags(flags)
|
||||
, m_data(move(data))
|
||||
, m_auxiliary_data(auxiliary_data)
|
||||
|
|
@ -27,6 +28,7 @@ public:
|
|||
}
|
||||
|
||||
AK::Duration timestamp() const { return m_timestamp; }
|
||||
AK::Duration duration() const { return m_duration; }
|
||||
FrameFlags flags() const { return m_flags; }
|
||||
bool is_keyframe() const { return has_flag(m_flags, FrameFlags::Keyframe); }
|
||||
ByteBuffer const& data() const { return m_data; }
|
||||
|
|
@ -34,6 +36,7 @@ public:
|
|||
|
||||
private:
|
||||
AK::Duration m_timestamp;
|
||||
AK::Duration m_duration;
|
||||
FrameFlags m_flags;
|
||||
ByteBuffer m_data;
|
||||
AuxiliaryData m_auxiliary_data;
|
||||
|
|
|
|||
|
|
@ -165,6 +165,10 @@ DecoderErrorOr<CodedFrame> MatroskaDemuxer::get_next_sample_for_track(Track cons
|
|||
status.frame_index = 0;
|
||||
}
|
||||
|
||||
VERIFY(status.block.has_value());
|
||||
|
||||
auto timestamp = status.block->timestamp();
|
||||
auto duration = status.block->duration().value_or(AK::Duration::zero());
|
||||
auto flags = status.block->only_keyframes() ? FrameFlags::Keyframe : FrameFlags::None;
|
||||
auto aux_data = [&] -> CodedFrame::AuxiliaryData {
|
||||
if (track.type() == TrackType::Video) {
|
||||
|
|
@ -176,7 +180,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(), flags, move(sample_data), aux_data);
|
||||
return CodedFrame(timestamp, duration, flags, move(sample_data), aux_data);
|
||||
}
|
||||
|
||||
DecoderErrorOr<AK::Duration> MatroskaDemuxer::total_duration()
|
||||
|
|
|
|||
|
|
@ -253,6 +253,7 @@ DecoderErrorOr<CodedFrame> FFmpegDemuxer::get_next_sample_for_track(Track const&
|
|||
auto flags = (packet.flags & AV_PKT_FLAG_KEY) != 0 ? FrameFlags::Keyframe : FrameFlags::None;
|
||||
auto sample = CodedFrame(
|
||||
time_units_to_duration(packet.pts, stream.time_base),
|
||||
time_units_to_duration(packet.duration, stream.time_base),
|
||||
flags,
|
||||
move(packet_data),
|
||||
auxiliary_data);
|
||||
|
|
|
|||
Loading…
Reference in a new issue