From 220fbcaa7e6ed087fa266b98a454ce1c06ea8100 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Mon, 30 Jan 2023 11:05:43 +0100 Subject: AK: Remove the fallible constructor from `FixedMemoryStream` --- Userland/Libraries/LibAudio/FlacLoader.cpp | 26 +++++++++++++------------- Userland/Libraries/LibAudio/MP3Loader.cpp | 2 +- Userland/Libraries/LibAudio/WavLoader.cpp | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'Userland/Libraries/LibAudio') 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, LoaderError> FlacLoaderPlugin::create(St Result, LoaderError> FlacLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(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(*streaminfo_data_memory) }; + FixedMemoryStream streaminfo_data_memory { streaminfo.data.bytes() }; + BigEndianInputBitStream streaminfo_data { MaybeOwned(streaminfo_data_memory) }; // 11.10 METADATA_BLOCK_STREAMINFO m_min_block_size = LOADER_TRY(streaminfo_data.read_bits(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(*memory_stream) }; + FixedMemoryStream memory_stream { block.data.bytes() }; + BigEndianInputBitStream picture_block_bytes { MaybeOwned(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 { Span { reinterpret_cast(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 { Span { 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(*memory_stream) }; + FixedMemoryStream memory_stream { block.data.bytes() }; + BigEndianInputBitStream seektable_bytes { MaybeOwned(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, LoaderError> MP3LoaderPlugin::create(Stri Result, LoaderError> MP3LoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(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, LoaderError> WavLoaderPlugin::create(Stri Result, LoaderError> WavLoaderPlugin::create(Bytes buffer) { - auto stream = LOADER_TRY(FixedMemoryStream::construct(buffer)); + auto stream = LOADER_TRY(try_make(buffer)); auto loader = make(move(stream)); LOADER_TRY(loader->initialize()); @@ -115,23 +115,23 @@ static ErrorOr read_sample(AK::Stream& stream) LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t samples_to_read) const { FixedArray samples = LOADER_TRY(FixedArray::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, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; case PcmSampleFormat::Int16: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, 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, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; case PcmSampleFormat::Float64: - TRY(read_samples_from_stream(*stream, read_sample, samples)); + TRY(read_samples_from_stream(stream, read_sample, samples)); break; default: VERIFY_NOT_REACHED(); -- cgit v1.2.3