mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:42:43 +00:00 
			
		
		
		
	 bcd222cfae
			
		
	
	
		bcd222cfae
		
	
	
	
	
		
			
			It's currently possible to seek to the total sample count of an audio loader. We must limit seeking to one less than that count. This mistake was duplicated in both AudioCodecPluginSerenity/Ladybird, so the computation was moved to a helper in the base AudioCodecPlugin.
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 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 <LibAudio/Forward.h>
 | |
| 
 | |
| namespace Web::Platform {
 | |
| 
 | |
| class 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, size_t device_sample_rate);
 | |
|     static Duration set_loader_position(Audio::Loader&, double position, Duration duration, size_t device_sample_rate);
 | |
|     static Duration current_loader_position(Audio::Loader const&, size_t device_sample_rate);
 | |
| 
 | |
|     virtual void resume_playback() = 0;
 | |
|     virtual void pause_playback() = 0;
 | |
|     virtual void set_volume(double) = 0;
 | |
|     virtual void seek(double) = 0;
 | |
| 
 | |
|     virtual Duration duration() = 0;
 | |
| 
 | |
|     Function<void(Duration)> on_playback_position_updated;
 | |
| 
 | |
| protected:
 | |
|     AudioCodecPlugin();
 | |
| };
 | |
| 
 | |
| }
 |