mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 04:55:15 +00:00
LibAudio: Use NonnullOwnPtr
to keep track of LoaderPlugin streams
This doesn't have any immediate uses, but this adapts the code a bit more to `Core::Stream` conventions (as most functions there use NonnullOwnPtr to handle streams) and it makes it a bit clearer that this pointer isn't actually supposed to be null. In fact, MP3LoaderPlugin and FlacLoaderPlugin apparently forgot to check for that completely before starting to decode data.
This commit is contained in:
parent
c57be0f474
commit
312a41fddf
Notes:
sideshowbarker
2024-07-17 21:16:31 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/312a41fddf Pull-request: https://github.com/SerenityOS/serenity/pull/16316 Reviewed-by: https://github.com/kleinesfilmroellchen ✅
8 changed files with 9 additions and 15 deletions
|
@ -25,7 +25,7 @@
|
|||
|
||||
namespace Audio {
|
||||
|
||||
FlacLoaderPlugin::FlacLoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
|
||||
FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
|
||||
: LoaderPlugin(move(stream))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ ALWAYS_INLINE ErrorOr<i32> decode_unsigned_exp_golomb(u8 order, BigEndianInputBi
|
|||
// https://datatracker.ietf.org/doc/html/draft-ietf-cellar-flac-03 (newer IETF draft that uses incompatible numberings and names)
|
||||
class FlacLoaderPlugin : public LoaderPlugin {
|
||||
public:
|
||||
explicit FlacLoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream);
|
||||
explicit FlacLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream);
|
||||
virtual ~FlacLoaderPlugin() override = default;
|
||||
|
||||
static Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> try_create(StringView path);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Audio {
|
||||
|
||||
LoaderPlugin::LoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
|
||||
LoaderPlugin::LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
|
||||
: m_stream(move(stream))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ using MaybeLoaderError = Result<void, LoaderError>;
|
|||
|
||||
class LoaderPlugin {
|
||||
public:
|
||||
explicit LoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream);
|
||||
explicit LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream);
|
||||
virtual ~LoaderPlugin() = default;
|
||||
|
||||
virtual LoaderSamples get_more_samples(size_t max_bytes_to_read_from_input = 128 * KiB) = 0;
|
||||
|
@ -58,7 +58,7 @@ public:
|
|||
Vector<PictureData> const& pictures() const { return m_pictures; };
|
||||
|
||||
protected:
|
||||
OwnPtr<Core::Stream::SeekableStream> m_stream;
|
||||
NonnullOwnPtr<Core::Stream::SeekableStream> m_stream;
|
||||
|
||||
Vector<PictureData> m_pictures;
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Audio {
|
|||
DSP::MDCT<12> MP3LoaderPlugin::s_mdct_12;
|
||||
DSP::MDCT<36> MP3LoaderPlugin::s_mdct_36;
|
||||
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
|
||||
MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
|
||||
: LoaderPlugin(move(stream))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ struct ScaleFactorBand;
|
|||
|
||||
class MP3LoaderPlugin : public LoaderPlugin {
|
||||
public:
|
||||
explicit MP3LoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream);
|
||||
explicit MP3LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream);
|
||||
virtual ~MP3LoaderPlugin() = default;
|
||||
|
||||
static Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> try_create(StringView path);
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Audio {
|
|||
|
||||
static constexpr size_t const maximum_wav_size = 1 * GiB; // FIXME: is there a more appropriate size limit?
|
||||
|
||||
WavLoaderPlugin::WavLoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream)
|
||||
WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
|
||||
: LoaderPlugin(move(stream))
|
||||
{
|
||||
}
|
||||
|
@ -142,9 +142,6 @@ LoaderSamples WavLoaderPlugin::samples_from_pcm_data(Bytes const& data, size_t s
|
|||
|
||||
LoaderSamples WavLoaderPlugin::get_more_samples(size_t max_samples_to_read_from_input)
|
||||
{
|
||||
if (!m_stream)
|
||||
return LoaderError { LoaderError::Category::Internal, static_cast<size_t>(m_loaded_samples), "No stream; initialization failed" };
|
||||
|
||||
auto remaining_samples = m_total_samples - m_loaded_samples;
|
||||
if (remaining_samples <= 0)
|
||||
return FixedArray<Sample> {};
|
||||
|
@ -189,9 +186,6 @@ MaybeLoaderError WavLoaderPlugin::seek(int sample_index)
|
|||
// Specification reference: http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
|
||||
MaybeLoaderError WavLoaderPlugin::parse_header()
|
||||
{
|
||||
if (!m_stream)
|
||||
return LoaderError { LoaderError::Category::Internal, 0, "No stream" };
|
||||
|
||||
bool ok = true;
|
||||
size_t bytes_read = 0;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ static constexpr unsigned const WAVE_FORMAT_EXTENSIBLE = 0xFFFE; // Determined b
|
|||
// Parses and reads audio data from a WAV file.
|
||||
class WavLoaderPlugin : public LoaderPlugin {
|
||||
public:
|
||||
explicit WavLoaderPlugin(OwnPtr<Core::Stream::SeekableStream> stream);
|
||||
explicit WavLoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream);
|
||||
static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> try_create(StringView path);
|
||||
static Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> try_create(Bytes buffer);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue