• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "audio_system_manager.h"
22 
23 namespace OHOS::NWeb {
24 using namespace OHOS::AudioStandard;
25 
26 class AudioManagerCallbackAdapterImpl : public AudioManagerCallback {
27 public:
28     explicit AudioManagerCallbackAdapterImpl(std::shared_ptr<AudioManagerCallbackAdapter> cb);
29 
30     ~AudioManagerCallbackAdapterImpl() override = default;
31 
32     void OnInterrupt(const InterruptAction &interruptAction) override;
33 
34 private:
35     std::shared_ptr<AudioManagerCallbackAdapter> cb_ = nullptr;
36 };
37 
38 class AudioManagerDeviceChangeCallbackAdapterImpl : public AudioManagerDeviceChangeCallback {
39 public:
40     explicit AudioManagerDeviceChangeCallbackAdapterImpl(std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter> cb);
41 
42     ~AudioManagerDeviceChangeCallbackAdapterImpl() override = default;
43 
44     void OnDeviceChange(const DeviceChangeAction& deviceChangeAction) override;
45 
46 private:
47     std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter> cb_ = nullptr;
48 };
49 
50 class AudioSystemManagerAdapterImpl : public AudioSystemManagerAdapter {
51 public:
52     AudioSystemManagerAdapterImpl() = default;
53 
54     static AudioSystemManagerAdapterImpl& GetInstance();
55 
56     ~AudioSystemManagerAdapterImpl() override = default;
57 
58     bool HasAudioOutputDevices() const override;
59 
60     bool HasAudioInputDevices() const override;
61 
62     int32_t RequestAudioFocus(const AudioAdapterInterrupt &audioInterrupt) override;
63 
64     int32_t AbandonAudioFocus(const AudioAdapterInterrupt &audioInterrupt) override;
65 
66     int32_t SetAudioManagerInterruptCallback(const std::shared_ptr<AudioManagerCallbackAdapter> &callback) override;
67 
68     int32_t UnsetAudioManagerInterruptCallback() override;
69 
70     std::vector<AudioAdapterDeviceDesc> GetDevices(AdapterDeviceFlag flag) const override;
71 
72     int32_t SelectAudioDevice(AudioAdapterDeviceDesc desc, bool isInput) const override;
73 
74     AudioAdapterDeviceDesc GetDefaultOutputDevice() override;
75 
76     int32_t SetDeviceChangeCallback(const std::shared_ptr<AudioManagerDeviceChangeCallbackAdapter>& callback) override;
77 
78     int32_t UnsetDeviceChangeCallback() override;
79 
80     static AudioStreamType GetStreamType(AudioAdapterStreamType streamType);
81 
82 private:
83     std::shared_ptr<AudioManagerCallbackAdapterImpl> callback_;
84     std::shared_ptr<AudioManagerDeviceChangeCallbackAdapterImpl> deviceChangeCallback_ = nullptr;
85 };
86 }  // namespace OHOS::NWeb
87 
88 #endif // AUDIO_SYSTEM_MANAGER_ADAPTER_IMPL_H