mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +00:00 
			
		
		
		
	 312a41fddf
			
		
	
	
		312a41fddf
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			70 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2021, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibAudio/FlacLoader.h>
 | |
| #include <LibAudio/Loader.h>
 | |
| #include <LibAudio/MP3Loader.h>
 | |
| #include <LibAudio/WavLoader.h>
 | |
| 
 | |
| namespace Audio {
 | |
| 
 | |
| LoaderPlugin::LoaderPlugin(NonnullOwnPtr<Core::Stream::SeekableStream> stream)
 | |
|     : m_stream(move(stream))
 | |
| {
 | |
| }
 | |
| 
 | |
| Loader::Loader(NonnullOwnPtr<LoaderPlugin> plugin)
 | |
|     : m_plugin(move(plugin))
 | |
| {
 | |
| }
 | |
| 
 | |
| Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(StringView path)
 | |
| {
 | |
|     {
 | |
|         auto plugin = WavLoaderPlugin::try_create(path);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     {
 | |
|         auto plugin = FlacLoaderPlugin::try_create(path);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     {
 | |
|         auto plugin = MP3LoaderPlugin::try_create(path);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     return LoaderError { "No loader plugin available" };
 | |
| }
 | |
| 
 | |
| Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(Bytes buffer)
 | |
| {
 | |
|     {
 | |
|         auto plugin = WavLoaderPlugin::try_create(buffer);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     {
 | |
|         auto plugin = FlacLoaderPlugin::try_create(buffer);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     {
 | |
|         auto plugin = MP3LoaderPlugin::try_create(buffer);
 | |
|         if (!plugin.is_error())
 | |
|             return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
 | |
|     }
 | |
| 
 | |
|     return LoaderError { "No loader plugin available" };
 | |
| }
 | |
| 
 | |
| }
 |