2026-02-06 17:59:14 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2026, Gregory Bertilson <gregory@ladybird.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibCore/EventLoop.h>
|
|
|
|
|
#include <LibCore/File.h>
|
|
|
|
|
#include <LibCore/System.h>
|
2026-02-07 05:43:15 -03:00
|
|
|
#include <LibMedia/Audio/ChannelMap.h>
|
2026-02-06 17:59:14 -03:00
|
|
|
#include <LibMedia/Containers/Matroska/MatroskaDemuxer.h>
|
|
|
|
|
#include <LibMedia/FFmpeg/FFmpegDemuxer.h>
|
|
|
|
|
#include <LibMedia/IncrementallyPopulatedStream.h>
|
2026-04-25 22:51:09 -03:00
|
|
|
#include <LibMedia/MediaTimeProvider.h>
|
2026-04-26 07:49:40 -03:00
|
|
|
#include <LibMedia/PipelineStatus.h>
|
2026-04-25 22:51:09 -03:00
|
|
|
#include <LibMedia/Producers/DecodedAudioProducer.h>
|
|
|
|
|
#include <LibMedia/Producers/DecodedVideoProducer.h>
|
2026-02-06 17:59:14 -03:00
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
|
|
|
|
|
static NonnullRefPtr<Media::IncrementallyPopulatedStream> load_test_file(StringView path)
|
|
|
|
|
{
|
|
|
|
|
auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read));
|
|
|
|
|
return Media::IncrementallyPopulatedStream::create_from_buffer(MUST(file->read_until_eof()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NonnullRefPtr<Media::Demuxer> create_demuxer(NonnullRefPtr<Media::IncrementallyPopulatedStream> const& stream)
|
|
|
|
|
{
|
|
|
|
|
auto matroska_result = Media::Matroska::MatroskaDemuxer::from_stream(stream);
|
|
|
|
|
if (!matroska_result.is_error())
|
|
|
|
|
return matroska_result.release_value();
|
|
|
|
|
return MUST(Media::FFmpeg::FFmpegDemuxer::from_stream(stream));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-25 22:51:09 -03:00
|
|
|
TEST_CASE(audio_producer_underspecified_5_1_channel_map)
|
2026-02-07 05:43:15 -03:00
|
|
|
{
|
|
|
|
|
Core::EventLoop loop;
|
|
|
|
|
|
|
|
|
|
auto stream = load_test_file("WAV/tone_44100_5_1_underspecified.wav"sv);
|
|
|
|
|
auto demuxer = create_demuxer(stream);
|
2026-03-27 18:27:18 -03:00
|
|
|
auto tracks = TRY_OR_FAIL(demuxer->get_tracks_for_type(Media::TrackType::Audio));
|
|
|
|
|
VERIFY(!tracks.is_empty());
|
2026-02-07 05:43:15 -03:00
|
|
|
|
2026-06-04 15:00:52 -03:00
|
|
|
auto producer = TRY_OR_FAIL(Media::DecodedAudioProducer::try_create(loop, demuxer, tracks[0]));
|
2026-02-07 05:43:15 -03:00
|
|
|
|
2026-04-25 22:51:09 -03:00
|
|
|
producer->start();
|
2026-02-07 05:43:15 -03:00
|
|
|
|
|
|
|
|
auto time_limit = AK::Duration::from_seconds(1);
|
|
|
|
|
auto start_time = MonotonicTime::now_coarse();
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2026-04-26 07:49:40 -03:00
|
|
|
Media::AudioBlock block;
|
2026-05-19 00:41:00 -03:00
|
|
|
auto status = producer->status();
|
|
|
|
|
if (status == Media::PipelineStatus::HaveData)
|
|
|
|
|
producer->pull(block);
|
2026-04-26 07:49:40 -03:00
|
|
|
if (status == Media::PipelineStatus::HaveData) {
|
|
|
|
|
EXPECT(!block.is_empty());
|
2026-02-07 05:43:15 -03:00
|
|
|
EXPECT_EQ(block.channel_count(), 6);
|
|
|
|
|
EXPECT_EQ(block.sample_specification().channel_map(), Audio::ChannelMap::surround_5_1());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MonotonicTime::now_coarse() - start_time >= time_limit)
|
|
|
|
|
break;
|
|
|
|
|
loop.pump(Core::EventLoop::WaitMode::PollForEvents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FAIL("Decoding timed out.");
|
|
|
|
|
}
|