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 <set> 22 #include <map> 23 #include <mutex> 24 #include <vector> 25 26 #include "audio_process_in_server.h" 27 #include "audio_endpoint.h" 28 #include "ipc_stream_in_server.h" 29 30 namespace OHOS { 31 namespace AudioStandard { 32 class AudioService : public ProcessReleaseCallback { 33 public: 34 static AudioService *GetInstance(); 35 ~AudioService(); 36 37 sptr<IpcStreamInServer> GetIpcStream(const AudioProcessConfig &config, int32_t &ret); 38 39 sptr<AudioProcessInServer> GetAudioProcess(const AudioProcessConfig &config); 40 // override for ProcessReleaseCallback, do release process work. 41 int32_t OnProcessRelease(IAudioProcessStream *process) override; 42 43 DeviceInfo GetDeviceInfoForProcess(const AudioProcessConfig &config); 44 std::shared_ptr<AudioEndpoint> GetAudioEndpointForDevice(DeviceInfo &deviceInfo, AudioStreamType streamType); 45 int32_t NotifyStreamVolumeChanged(AudioStreamType streamType, float volume); 46 47 int32_t LinkProcessToEndpoint(sptr<AudioProcessInServer> process, std::shared_ptr<AudioEndpoint> endpoint); 48 int32_t UnlinkProcessToEndpoint(sptr<AudioProcessInServer> process, std::shared_ptr<AudioEndpoint> endpoint); 49 void Dump(std::stringstream &dumpString); 50 51 private: 52 AudioService(); 53 void DelayCallReleaseEndpoint(std::string endpointName, int32_t delayInMs); 54 55 private: 56 std::mutex processListMutex_; 57 std::vector<std::pair<sptr<AudioProcessInServer>, std::shared_ptr<AudioEndpoint>>> linkedPairedList_; 58 59 std::mutex releaseEndpointMutex_; 60 std::condition_variable releaseEndpointCV_; 61 std::set<std::string> releasingEndpointSet_; 62 std::map<std::string, std::shared_ptr<AudioEndpoint>> endpointList_; 63 }; 64 } // namespace AudioStandard 65 } // namespace OHOS 66 #endif // AUDIO_SERVICE_H 67