1 /* 2 * Copyright (c) 2022 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_SYSTEM_MANAGER_ADAPTER_IMPL_H 17 #define AUDIO_SYSTEM_MANAGER_ADAPTER_IMPL_H 18 19 #include "audio_system_manager_adapter.h" 20 21 #if defined(NWEB_AUDIO_ENABLE) 22 #include "audio_system_manager.h" 23 #endif 24 25 namespace OHOS::NWeb { 26 #if defined(NWEB_AUDIO_ENABLE) 27 using namespace OHOS::AudioStandard; 28 29 class AudioManagerCallbackAdapterImpl : public AudioManagerCallback { 30 public: 31 explicit AudioManagerCallbackAdapterImpl(std::shared_ptr<AudioManagerCallbackAdapter> cb); 32 33 ~AudioManagerCallbackAdapterImpl() override = default; 34 35 void OnInterrupt(const InterruptAction &interruptAction) override; 36 37 private: 38 std::shared_ptr<AudioManagerCallbackAdapter> cb_ = nullptr; 39 }; 40 41 class AudioManagerDeviceChangeCallbackAdapterImpl : public AudioManagerDeviceChangeCallback { 42 public: 43 explicit AudioManagerDeviceChangeCallbackAdapterImpl(std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter> cb); 44 45 ~AudioManagerDeviceChangeCallbackAdapterImpl() override = default; 46 47 void OnDeviceChange(const DeviceChangeAction& deviceChangeAction) override; 48 49 private: 50 std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter> cb_ = nullptr; 51 }; 52 #endif 53 54 class AudioSystemManagerAdapterImpl : public AudioSystemManagerAdapter { 55 public: 56 AudioSystemManagerAdapterImpl() = default; 57 58 static AudioSystemManagerAdapterImpl& GetInstance(); 59 60 ~AudioSystemManagerAdapterImpl() override = default; 61 62 bool HasAudioOutputDevices() const override; 63 64 bool HasAudioInputDevices() const override; 65 66 int32_t RequestAudioFocus(const AudioAdapterInterrupt &audioInterrupt) override; 67 68 int32_t AbandonAudioFocus(const AudioAdapterInterrupt &audioInterrupt) override; 69 70 int32_t SetAudioManagerInterruptCallback(const std::shared_ptr<AudioManagerCallbackAdapter> &callback) override; 71 72 int32_t UnsetAudioManagerInterruptCallback() override; 73 74 std::vector<AudioAdapterDeviceDesc> GetDevices(AdapterDeviceFlag flag) const override; 75 76 int32_t SelectAudioDevice(AudioAdapterDeviceDesc desc, bool isInput) const override; 77 78 AudioAdapterDeviceDesc GetDefaultOutputDevice() override; 79 80 int32_t SetDeviceChangeCallback(const std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter>& callback) override; 81 82 int32_t UnsetDeviceChangeCallback() override; 83 84 AudioAdapterDeviceDesc GetDefaultInputDevice() override; 85 86 #if defined(NWEB_AUDIO_ENABLE) 87 static AudioStreamType GetStreamType(AudioAdapterStreamType streamType); 88 89 private: 90 int32_t SelectAudioOutputDevice(bool isCallDevice, const std::vector<sptr<AudioDeviceDescriptor>>& device) const; 91 92 private: 93 std::shared_ptr<AudioManagerCallbackAdapterImpl> callback_; 94 std::shared_ptr<AudioManagerDeviceChangeCallbackAdapterImpl> deviceChangeCallback_ = nullptr; 95 #endif 96 }; 97 } // namespace OHOS::NWeb 98 99 #endif // AUDIO_SYSTEM_MANAGER_ADAPTER_IMPL_H