summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-01-30 11:05:43 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-08 17:44:32 +0000
commit220fbcaa7e6ed087fa266b98a454ce1c06ea8100 (patch)
treeb155b42e299728dc672d2b5ce33b520a428cfb14 /Userland/Libraries/LibAudio
parent8b2f23d0166ec9d21a70f10dadb2d7533a161079 (diff)
downloadserenity-220fbcaa7e6ed087fa266b98a454ce1c06ea8100.zip
AK: Remove the fallible constructor from `FixedMemoryStream`
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.cpp26
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp2
-rw-r--r--Userland/Libraries/LibAudio/WavLoader.cpp14
3 files changed, 21 insertions, 21 deletions
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp
index d2ba2ed2cb..26036610d4 100644
--- a/Userland/Libraries/LibAudio/FlacLoader.cpp
+++ b/Userland/Libraries/LibAudio/FlacLoader.cpp
@@ -42,7 +42,7 @@ Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(St
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<FlacLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@@ -78,8 +78,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// Receive the streaminfo block
auto streaminfo = TRY(next_meta_block(bit_input));
FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO");
- auto streaminfo_data_memory = LOADER_TRY(FixedMemoryStream::construct(streaminfo.data.bytes()));
- BigEndianInputBitStream streaminfo_data { MaybeOwned<AK::Stream>(*streaminfo_data_memory) };
+ FixedMemoryStream streaminfo_data_memory { streaminfo.data.bytes() };
+ BigEndianInputBitStream streaminfo_data { MaybeOwned<AK::Stream>(streaminfo_data_memory) };
// 11.10 METADATA_BLOCK_STREAMINFO
m_min_block_size = LOADER_TRY(streaminfo_data.read_bits<u16>(16));
@@ -149,8 +149,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// 11.19. METADATA_BLOCK_PICTURE
MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
{
- auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
- BigEndianInputBitStream picture_block_bytes { MaybeOwned<AK::Stream>(*memory_stream) };
+ FixedMemoryStream memory_stream { block.data.bytes() };
+ BigEndianInputBitStream picture_block_bytes { MaybeOwned<AK::Stream>(memory_stream) };
PictureData picture {};
@@ -158,13 +158,13 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
auto const mime_string_length = LOADER_TRY(picture_block_bytes.read_bits(32));
// Note: We are seeking before reading the value to ensure that we stayed inside buffer's size.
- auto offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(mime_string_length, SeekMode::FromCurrentPosition));
+ auto offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(mime_string_length, SeekMode::FromCurrentPosition));
picture.mime_string = { block.data.bytes().data() + offset_before_seeking, (size_t)mime_string_length };
auto const description_string_length = LOADER_TRY(picture_block_bytes.read_bits(32));
- offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(description_string_length, SeekMode::FromCurrentPosition));
+ offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(description_string_length, SeekMode::FromCurrentPosition));
picture.description_string = Vector<u32> { Span<u32> { reinterpret_cast<u32*>(block.data.bytes().data() + offset_before_seeking), (size_t)description_string_length } };
picture.width = LOADER_TRY(picture_block_bytes.read_bits(32));
@@ -174,8 +174,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
picture.colors = LOADER_TRY(picture_block_bytes.read_bits(32));
auto const picture_size = LOADER_TRY(picture_block_bytes.read_bits(32));
- offset_before_seeking = memory_stream->offset();
- LOADER_TRY(memory_stream->seek(picture_size, SeekMode::FromCurrentPosition));
+ offset_before_seeking = memory_stream.offset();
+ LOADER_TRY(memory_stream.seek(picture_size, SeekMode::FromCurrentPosition));
picture.data = Vector<u8> { Span<u8> { block.data.bytes().data() + offset_before_seeking, (size_t)picture_size } };
m_pictures.append(move(picture));
@@ -186,8 +186,8 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
// 11.13. METADATA_BLOCK_SEEKTABLE
MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block)
{
- auto memory_stream = LOADER_TRY(FixedMemoryStream::construct(block.data.bytes()));
- BigEndianInputBitStream seektable_bytes { MaybeOwned<AK::Stream>(*memory_stream) };
+ FixedMemoryStream memory_stream { block.data.bytes() };
+ BigEndianInputBitStream seektable_bytes { MaybeOwned<AK::Stream>(memory_stream) };
for (size_t i = 0; i < block.length / 18; ++i) {
// 11.14. SEEKPOINT
FlacSeekPoint seekpoint {
diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp
index 693f680527..59a90cf233 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.cpp
+++ b/Userland/Libraries/LibAudio/MP3Loader.cpp
@@ -31,7 +31,7 @@ Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Stri
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<MP3LoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
diff --git a/Userland/Libraries/LibAudio/WavLoader.cpp b/Userland/Libraries/LibAudio/WavLoader.cpp
index 4fcff2ae88..f222cd4cfc 100644
--- a/Userland/Libraries/LibAudio/WavLoader.cpp
+++ b/Userland/Libraries/LibAudio/WavLoader.cpp
@@ -35,7 +35,7 @@ Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Stri
Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(Bytes buffer)
{
- auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer));
+ auto stream = LOADER_TRY(try_make<FixedMemoryStream>(buffer));
auto loader = make<WavLoaderPlugin>(move(stream));
LOADER_TRY(loader->initialize());
@@ -115,23 +115,23 @@ static ErrorOr<double> read_sample(AK::Stream& stream)
LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const
{
FixedArray<Sample> samples = LOADER_TRY(FixedArray<Sample>::create(samples_to_read));
- auto stream = LOADER_TRY(FixedMemoryStream::construct(move(data)));
+ FixedMemoryStream stream { data };
switch (m_sample_format) {
case PcmSampleFormat::Uint8:
- TRY(read_samples_from_stream(*stream, read_sample<u8>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<u8>, samples));
break;
case PcmSampleFormat::Int16:
- TRY(read_samples_from_stream(*stream, read_sample<i16>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<i16>, samples));
break;
case PcmSampleFormat::Int24:
- TRY(read_samples_from_stream(*stream, read_sample_int24, samples));
+ TRY(read_samples_from_stream(stream, read_sample_int24, samples));
break;
case PcmSampleFormat::Float32:
- TRY(read_samples_from_stream(*stream, read_sample<float>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<float>, samples));
break;
case PcmSampleFormat::Float64:
- TRY(read_samples_from_stream(*stream, read_sample<double>, samples));
+ TRY(read_samples_from_stream(stream, read_sample<double>, samples));
break;
default:
VERIFY_NOT_REACHED();