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.
This commit is contained in:
Zaggy1024 2025-09-17 14:42:43 -05:00 committed by Gregory Bertilson
parent 2a288f6d53
commit 8d77e8b09d
9 changed files with 19 additions and 19 deletions

View File

@ -8,18 +8,17 @@
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/Time.h> #include <AK/Time.h>
#include <LibMedia/CodedVideoFrameData.h>
#include "VideoSampleData.h"
namespace Media { namespace Media {
class Sample final { class CodedFrame final {
public: public:
using AuxiliaryData = Variant<VideoSampleData>; using AuxiliaryData = Variant<CodedVideoFrameData>;
Sample(AK::Duration timestamp, ByteBuffer data, AuxiliaryData auxiliary_data) CodedFrame(AK::Duration timestamp, ByteBuffer&& data, AuxiliaryData auxiliary_data)
: m_timestamp(timestamp) : m_timestamp(timestamp)
, m_data(data) , m_data(move(data))
, m_auxiliary_data(auxiliary_data) , m_auxiliary_data(auxiliary_data)
{ {
} }

View File

@ -10,9 +10,9 @@
namespace Media { namespace Media {
class VideoSampleData { class CodedVideoFrameData {
public: public:
VideoSampleData(CodingIndependentCodePoints container_cicp) CodedVideoFrameData(CodingIndependentCodePoints container_cicp)
: m_container_cicp(container_cicp) : m_container_cicp(container_cicp)
{ {
} }

View File

@ -6,6 +6,7 @@
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Debug.h> #include <AK/Debug.h>
#include <LibMedia/CodedFrame.h>
#include <LibMedia/DecoderError.h> #include <LibMedia/DecoderError.h>
#include "MatroskaDemuxer.h" #include "MatroskaDemuxer.h"
@ -179,7 +180,7 @@ DecoderErrorOr<Optional<AK::Duration>> MatroskaDemuxer::seek_to_most_recent_keyf
return track_status.iterator.last_timestamp(); return track_status.iterator.last_timestamp();
} }
DecoderErrorOr<Sample> MatroskaDemuxer::get_next_sample_for_track(Track track) DecoderErrorOr<CodedFrame> MatroskaDemuxer::get_next_sample_for_track(Track track)
{ {
// FIXME: This makes a copy of the sample, which shouldn't be necessary. // FIXME: This makes a copy of the sample, which shouldn't be necessary.
// Matroska should make a RefPtr<ByteBuffer>, probably. // Matroska should make a RefPtr<ByteBuffer>, probably.
@ -191,7 +192,7 @@ DecoderErrorOr<Sample> MatroskaDemuxer::get_next_sample_for_track(Track track)
} }
auto cicp = TRY(m_reader.track_for_track_number(track.identifier()))->video_track()->color_format.to_cicp(); auto cicp = TRY(m_reader.track_for_track_number(track.identifier()))->video_track()->color_format.to_cicp();
auto sample_data = DECODER_TRY_ALLOC(ByteBuffer::copy(status.block->frame(status.frame_index++))); auto sample_data = DECODER_TRY_ALLOC(ByteBuffer::copy(status.block->frame(status.frame_index++)));
return Sample(status.block->timestamp(), move(sample_data), VideoSampleData(cicp)); return CodedFrame(status.block->timestamp(), move(sample_data), CodedVideoFrameData(cicp));
} }
DecoderErrorOr<AK::Duration> MatroskaDemuxer::total_duration() DecoderErrorOr<AK::Duration> MatroskaDemuxer::total_duration()

View File

@ -39,7 +39,7 @@ public:
DecoderErrorOr<ReadonlyBytes> get_codec_initialization_data_for_track(Track track) override; DecoderErrorOr<ReadonlyBytes> get_codec_initialization_data_for_track(Track track) override;
DecoderErrorOr<Sample> get_next_sample_for_track(Track track) override; DecoderErrorOr<CodedFrame> get_next_sample_for_track(Track track) override;
private: private:
struct TrackStatus { struct TrackStatus {

View File

@ -10,8 +10,8 @@
#include <LibCore/EventReceiver.h> #include <LibCore/EventReceiver.h>
#include "CodecID.h" #include "CodecID.h"
#include "CodedFrame.h"
#include "DecoderError.h" #include "DecoderError.h"
#include "Sample.h"
#include "Track.h" #include "Track.h"
namespace Media { namespace Media {
@ -25,7 +25,7 @@ public:
// given type is present. // given type is present.
virtual DecoderErrorOr<Optional<Track>> get_preferred_track_for_type(TrackType type) = 0; virtual DecoderErrorOr<Optional<Track>> get_preferred_track_for_type(TrackType type) = 0;
virtual DecoderErrorOr<Sample> get_next_sample_for_track(Track track) = 0; virtual DecoderErrorOr<CodedFrame> get_next_sample_for_track(Track track) = 0;
virtual DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) = 0; virtual DecoderErrorOr<CodecID> get_codec_id_for_track(Track track) = 0;

View File

@ -163,7 +163,7 @@ DecoderErrorOr<ReadonlyBytes> FFmpegDemuxer::get_codec_initialization_data_for_t
return ReadonlyBytes { stream->codecpar->extradata, static_cast<size_t>(stream->codecpar->extradata_size) }; return ReadonlyBytes { stream->codecpar->extradata, static_cast<size_t>(stream->codecpar->extradata_size) };
} }
DecoderErrorOr<Sample> FFmpegDemuxer::get_next_sample_for_track(Track track) DecoderErrorOr<CodedFrame> FFmpegDemuxer::get_next_sample_for_track(Track track)
{ {
VERIFY(track.identifier() < m_format_context->nb_streams); VERIFY(track.identifier() < m_format_context->nb_streams);
auto* stream = m_format_context->streams[track.identifier()]; auto* stream = m_format_context->streams[track.identifier()];
@ -199,10 +199,10 @@ DecoderErrorOr<Sample> FFmpegDemuxer::get_next_sample_for_track(Track track)
// to wipe the packet afterwards. // to wipe the packet afterwards.
auto packet_data = DECODER_TRY_ALLOC(ByteBuffer::copy(m_packet->data, m_packet->size)); auto packet_data = DECODER_TRY_ALLOC(ByteBuffer::copy(m_packet->data, m_packet->size));
auto sample = Sample( auto sample = CodedFrame(
time_units_to_duration(m_packet->pts, stream->time_base), time_units_to_duration(m_packet->pts, stream->time_base),
move(packet_data), move(packet_data),
VideoSampleData(CodingIndependentCodePoints(color_primaries, transfer_characteristics, matrix_coefficients, color_range))); CodedVideoFrameData(CodingIndependentCodePoints(color_primaries, transfer_characteristics, matrix_coefficients, color_range)));
// Wipe the packet now that the data is safe. // Wipe the packet now that the data is safe.
av_packet_unref(m_packet); av_packet_unref(m_packet);

View File

@ -37,7 +37,7 @@ public:
virtual DecoderErrorOr<ReadonlyBytes> get_codec_initialization_data_for_track(Track track) override; virtual DecoderErrorOr<ReadonlyBytes> get_codec_initialization_data_for_track(Track track) override;
virtual DecoderErrorOr<Sample> get_next_sample_for_track(Track track) override; virtual DecoderErrorOr<CodedFrame> get_next_sample_for_track(Track track) override;
private: private:
DecoderErrorOr<Track> get_track_for_stream_index(u32 stream_index); DecoderErrorOr<Track> get_track_for_stream_index(u32 stream_index);

View File

@ -8,10 +8,10 @@
namespace Media { namespace Media {
class CodedFrame;
class DecoderError; class DecoderError;
class FrameQueueItem; class FrameQueueItem;
class PlaybackManager; class PlaybackManager;
class Sample;
class Track; class Track;
class VideoDecoder; class VideoDecoder;
class VideoFrame; class VideoFrame;

View File

@ -215,7 +215,7 @@ void PlaybackManager::decode_and_queue_one_sample()
break; break;
} }
auto sample = sample_result.release_value(); auto sample = sample_result.release_value();
container_cicp = sample.auxiliary_data().get<VideoSampleData>().container_cicp(); container_cicp = sample.auxiliary_data().get<CodedVideoFrameData>().container_cicp();
// Submit the sample to the decoder. // Submit the sample to the decoder.
auto decode_result = m_decoder->receive_sample(sample.timestamp(), sample.data()); auto decode_result = m_decoder->receive_sample(sample.timestamp(), sample.data());