1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AUDIO_SERVICE_H 17 #define AUDIO_SERVICE_H 18 19 #include <condition_variable> 20 #include <sstream> 21 #include <map> 22 #include <mutex> 23 #include <vector> 24 25 #include "audio_process_in_server.h" 26 #include "audio_endpoint.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 class AudioService : public ProcessReleaseCallback { 31 public: 32 static AudioService *GetInstance(); 33 ~AudioService(); 34 sptr<AudioProcessInServer> GetAudioProcess(const AudioProcessConfig &config); 35 // override for ProcessReleaseCallback, do release process work. 36 int32_t OnProcessRelease(IAudioProcessStream *process) override; 37 38 DeviceInfo GetDeviceInfoForProcess(const AudioProcessConfig &config); 39 std::shared_ptr<AudioEndpoint> GetAudioEndpointForDevice(DeviceInfo deviceInfo); 40 41 int32_t LinkProcessToEndpoint(sptr<AudioProcessInServer> process, std::shared_ptr<AudioEndpoint> endpoint); 42 int32_t UnlinkProcessToEndpoint(sptr<AudioProcessInServer> process, std::shared_ptr<AudioEndpoint> endpoint); 43 void Dump(std::stringstream &dumpString); 44 45 private: 46 AudioService(); 47 void DelayCallReleaseEndpoint(std::string endpointName, int32_t delayInMs); 48 49 private: 50 std::mutex processListMutex_; 51 52 std::string reusingEndpoint_; 53 std::mutex releaseEndpointMutex_; 54 std::condition_variable releaseEndpointCV_; 55 std::vector<std::pair<sptr<AudioProcessInServer>, std::shared_ptr<AudioEndpoint>>> linkedPairedList_; 56 std::map<std::string, std::shared_ptr<AudioEndpoint>> endpointList_; 57 }; 58 } // namespace AudioStandard 59 } // namespace OHOS 60 #endif // AUDIO_SERVICE_H 61