1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <functional> 20 #include <memory> 21 #include <string> 22 23 #include <EngineInterface.h> 24 #include <android/media/audio/common/AudioHalEngineConfig.h> 25 26 namespace android { 27 28 using EngineInstance = std::unique_ptr<EngineInterface, std::function<void (EngineInterface*)>>; 29 30 EngineInstance loadApmEngineLibraryAndCreateEngine(const std::string& librarySuffix, 31 const std::string& configXmlFilePath = ""); 32 EngineInstance loadApmEngineLibraryAndCreateEngine(const std::string& librarySuffix, 33 const media::audio::common::AudioHalEngineConfig& config); 34 35 class EngineLibrary : public std::enable_shared_from_this<EngineLibrary> { 36 public: 37 static std::shared_ptr<EngineLibrary> load(const std::string& librarySuffix); 38 ~EngineLibrary(); 39 40 EngineLibrary(const EngineLibrary&) = delete; 41 EngineLibrary(EngineLibrary&&) = delete; 42 EngineLibrary& operator=(const EngineLibrary&) = delete; 43 EngineLibrary& operator=(EngineLibrary&&) = delete; 44 45 EngineInstance createEngineUsingXmlConfig(const std::string& xmlFilePath); 46 EngineInstance createEngineUsingHalConfig( 47 const media::audio::common::AudioHalEngineConfig& config); 48 49 private: 50 EngineLibrary() = default; 51 bool init(std::string libraryPath); 52 EngineInstance createEngine(); 53 void close(); 54 55 void *mLibraryHandle = nullptr; 56 EngineInterface* (*mCreateEngineInstance)() = nullptr; 57 void (*mDestroyEngineInstance)(EngineInterface*) = nullptr; 58 }; 59 60 } // namespace android 61