• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_AUDIO_OBSERVER_H
17 #define RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_AUDIO_OBSERVER_H
18 #ifdef RESSCHED_AUDIO_FRAMEWORK_ENABLE
19 #include <string>
20 #include <unordered_map>
21 
22 #include "nlohmann/json.hpp"
23 #include "audio_stream_manager.h"
24 #include "audio_system_manager.h"
25 #include "audio_routing_manager.h"
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
29 class AudioObserver :
30     public AudioStandard::AudioRendererStateChangeCallback,
31     public AudioStandard::AudioRingerModeCallback,
32     public AudioStandard::VolumeKeyEventCallback,
33     public AudioStandard::AudioManagerAudioSceneChangedCallback,
34     public AudioStandard::AudioPreferredOutputDeviceChangeCallback {
35 public:
36     void OnRendererStateChange(
37         const std::vector<std::shared_ptr<AudioStandard::AudioRendererChangeInfo>> &audioRendererChangeInfos) override;
38     void OnRingerModeUpdated(const AudioStandard::AudioRingerMode &ringerMode) override;
39     void OnVolumeKeyEvent(AudioStandard::VolumeEvent volumeEvent) override;
40     void OnAudioSceneChange(const AudioStandard::AudioScene audioScene) override;
41     void OnPreferredOutputDeviceUpdated(
42         const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &descs)  override;
43 private:
44     int32_t mode_ = -1;
45     void MarshallingAudioRendererChangeInfo(
46         const std::shared_ptr<AudioStandard::AudioRendererChangeInfo> &audioRendererChangeInfo,
47         nlohmann::json &payload);
48     bool IsRenderStateChange(const std::shared_ptr<AudioStandard::AudioRendererChangeInfo>& info);
49     std::unordered_map<int32_t, AudioStandard::RendererState> renderState_;
50     std::unordered_map<int32_t, int32_t> volumeState_;
51 };
52 } // namespace ResourceSchedule
53 } // namespace OHOS
54 #endif
55 #endif // RESSCHED_SCHED_CONTROLLER_OBSERVER_INCLUDE_AUDIO_OBSERVER_H
56