mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-22 10:57:18 +00:00
LibMedia: Store a SampleSpecification in Track
This allows FFmpegDemuxer to communicate the data necessary to convert WAV PCM to whatever our output format is.
This commit is contained in:
committed by
Gregory Bertilson
parent
0f5bd00e3a
commit
b4ca17fd29
Notes:
github-actions[bot]
2025-12-16 00:04:35 +00:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/LadybirdBrowser/ladybird/commit/b4ca17fd29f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7149
@@ -147,6 +147,22 @@ DecoderErrorOr<Track> FFmpegDemuxer::get_track_for_stream_index(u32 stream_index
|
||||
.pixel_height = static_cast<u64>(stream.codecpar->height),
|
||||
.cicp = CodingIndependentCodePoints(color_primaries, transfer_characteristics, matrix_coefficients, color_range),
|
||||
});
|
||||
} else if (type == TrackType::Audio) {
|
||||
auto channel_map = Audio::ChannelMap::invalid();
|
||||
|
||||
auto& channel_layout = stream.codecpar->ch_layout;
|
||||
if (channel_layout.nb_channels != 0) {
|
||||
auto channel_map_result = av_channel_layout_to_channel_map(channel_layout);
|
||||
if (channel_map_result.is_error())
|
||||
return DecoderError::with_description(DecoderErrorCategory::Invalid, channel_map_result.error().string_literal());
|
||||
channel_map = channel_map_result.release_value();
|
||||
}
|
||||
|
||||
auto sample_specification = Audio::SampleSpecification(stream.codecpar->sample_rate, channel_map);
|
||||
|
||||
track.set_audio_data({
|
||||
.sample_specification = sample_specification,
|
||||
});
|
||||
}
|
||||
|
||||
return track;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Utf16String.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibMedia/Audio/SampleSpecification.h>
|
||||
#include <LibMedia/Color/CodingIndependentCodePoints.h>
|
||||
#include <LibMedia/TrackType.h>
|
||||
|
||||
@@ -24,6 +25,10 @@ class Track {
|
||||
CodingIndependentCodePoints cicp;
|
||||
};
|
||||
|
||||
struct AudioData {
|
||||
Audio::SampleSpecification sample_specification;
|
||||
};
|
||||
|
||||
public:
|
||||
Track(TrackType type, size_t identifier, Utf16String const& name, Utf16String const& language)
|
||||
: m_type(type)
|
||||
@@ -35,6 +40,9 @@ public:
|
||||
case TrackType::Video:
|
||||
m_track_data = VideoData {};
|
||||
break;
|
||||
case TrackType::Audio:
|
||||
m_track_data = AudioData {};
|
||||
break;
|
||||
default:
|
||||
m_track_data = Empty {};
|
||||
break;
|
||||
@@ -58,6 +66,18 @@ public:
|
||||
return m_track_data.get<VideoData>();
|
||||
}
|
||||
|
||||
void set_audio_data(AudioData data)
|
||||
{
|
||||
VERIFY(m_type == TrackType::Audio);
|
||||
m_track_data = data;
|
||||
}
|
||||
|
||||
AudioData const& audio_data() const
|
||||
{
|
||||
VERIFY(m_type == TrackType::Audio);
|
||||
return m_track_data.get<AudioData>();
|
||||
}
|
||||
|
||||
bool operator==(Track const& other) const
|
||||
{
|
||||
return m_type == other.m_type && m_identifier == other.m_identifier;
|
||||
@@ -74,7 +94,7 @@ private:
|
||||
Utf16String m_name;
|
||||
Utf16String m_language;
|
||||
|
||||
Variant<Empty, VideoData> m_track_data;
|
||||
Variant<Empty, VideoData, AudioData> m_track_data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user