mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00

The plugin may go out of scope before the callbacks we've queued have fired. It is undefined behavior for these callbacks to access the plugin data after that has occurred. This patch protects these callbacks with weak pointers. Note that the plugin is not ref-counted, so we cannot use `strong_ref` here.
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FixedArray.h>
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/Weakable.h>
|
|
#include <LibMedia/Audio/Forward.h>
|
|
|
|
namespace Web::Platform {
|
|
|
|
class AudioCodecPlugin : public Weakable<AudioCodecPlugin> {
|
|
public:
|
|
using AudioCodecPluginCreator = Function<ErrorOr<NonnullOwnPtr<AudioCodecPlugin>>(NonnullRefPtr<Audio::Loader>)>;
|
|
|
|
static void install_creation_hook(AudioCodecPluginCreator);
|
|
static ErrorOr<NonnullOwnPtr<AudioCodecPlugin>> create(NonnullRefPtr<Audio::Loader>);
|
|
|
|
virtual ~AudioCodecPlugin();
|
|
|
|
static ErrorOr<FixedArray<Audio::Sample>> read_samples_from_loader(Audio::Loader&, size_t samples_to_load);
|
|
static AK::Duration set_loader_position(Audio::Loader&, double position, AK::Duration duration);
|
|
static AK::Duration current_loader_position(Audio::Loader const&);
|
|
|
|
virtual void resume_playback() = 0;
|
|
virtual void pause_playback() = 0;
|
|
virtual void set_volume(double) = 0;
|
|
virtual void seek(double) = 0;
|
|
|
|
virtual AK::Duration duration() = 0;
|
|
|
|
Function<void(AK::Duration)> on_playback_position_updated;
|
|
Function<void(String)> on_decoder_error;
|
|
|
|
protected:
|
|
AudioCodecPlugin();
|
|
};
|
|
|
|
}
|