mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:12:43 +00:00 
			
		
		
		
	 8a92573732
			
		
	
	
		8a92573732
		
	
	
	
	
		
			
			For this change to work "easily", Loader can't take const ByteBuffer's anymore, which is fine for now.
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			1.2 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/WavLoader.h>
 | |
| 
 | |
| namespace Audio {
 | |
| 
 | |
| Loader::Loader(NonnullOwnPtr<LoaderPlugin> plugin)
 | |
|     : m_plugin(move(plugin))
 | |
| {
 | |
| }
 | |
| 
 | |
| Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(StringView path)
 | |
| {
 | |
|     NonnullOwnPtr<LoaderPlugin> plugin = adopt_own(*new WavLoaderPlugin(path));
 | |
|     auto initstate0 = plugin->initialize();
 | |
|     if (!initstate0.is_error())
 | |
|         return plugin;
 | |
| 
 | |
|     plugin = adopt_own(*new FlacLoaderPlugin(path));
 | |
|     auto initstate1 = plugin->initialize();
 | |
|     if (!initstate1.is_error())
 | |
|         return plugin;
 | |
| 
 | |
|     return LoaderError { "No loader plugin available" };
 | |
| }
 | |
| 
 | |
| Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::try_create(Bytes& buffer)
 | |
| {
 | |
|     NonnullOwnPtr<LoaderPlugin> plugin = adopt_own(*new WavLoaderPlugin(buffer));
 | |
|     if (auto initstate = plugin->initialize(); !initstate.is_error())
 | |
|         return plugin;
 | |
|     plugin = adopt_own(*new FlacLoaderPlugin(buffer));
 | |
|     if (auto initstate = plugin->initialize(); !initstate.is_error())
 | |
|         return plugin;
 | |
|     return LoaderError { "No loader plugin available" };
 | |
| }
 | |
| 
 | |
| }
 |