• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_STREAM_MONITOR
17 #define AUDIO_STREAM_MONITOR
18 #include <vector>
19 #include <utility>
20 #include <mutex>
21 #include <map>
22 #include "audio_info.h"
23 #include "audio_stream_checker.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 class DataTransferStateChangeCallbackForMonitor {
28 public:
29     virtual ~DataTransferStateChangeCallbackForMonitor() = default;
30     virtual void OnDataTransferStateChange(const int32_t &pid, const int32_t & callbackId,
31         const AudioRendererDataTransferStateChangeInfo& info) = 0;
32     virtual void OnMuteStateChange(const int32_t &pid, const int32_t &callbackId,
33         const int32_t &uid, const uint32_t &sessionId, const bool &isMuted) = 0;
34 };
35 
36 class AudioStreamMonitor {
37 public:
38     static AudioStreamMonitor& GetInstance();
39     int32_t RegisterAudioRendererDataTransferStateListener(const DataTransferMonitorParam &param,
40         const int32_t pid, const int32_t callbackId);
41     int32_t UnregisterAudioRendererDataTransferStateListener(const int32_t pid, const int32_t callbackId);
42     void OnCallback(int32_t pid, int32_t callbackId, const AudioRendererDataTransferStateChangeInfo &info);
43     void OnMuteCallback(const int32_t &pid, const int32_t &callbackId,
44         const int32_t &uid, const uint32_t &sessionId, const bool &isMuted);
45     void ReportStreamFreezen(int64_t intervalTime);
46     void AddCheckForMonitor(uint32_t sessionId, std::shared_ptr<AudioStreamChecker> &checker);
47     void DeleteCheckForMonitor(uint32_t sessionId);
48     void SetAudioServerPtr(DataTransferStateChangeCallbackForMonitor *ptr);
49     void OnCallbackAppDied(const int32_t pid);
50     void NotifyAppStateChange(const int32_t uid, bool isBackground);
51     void UpdateMonitorVolume(const uint32_t &sessionId, const float &volume);
52 private:
AudioStreamMonitor()53     AudioStreamMonitor() {}
~AudioStreamMonitor()54     ~AudioStreamMonitor() {}
55     bool HasRegistered(const int32_t pid, const int32_t callbackId);
56     std::map<std::pair<int32_t, int32_t>, DataTransferMonitorParam> registerInfo_;
57     std::map<uint32_t, std::shared_ptr<AudioStreamChecker>> audioStreamCheckers_;
58     std::mutex regStatusMutex_;
59     DataTransferStateChangeCallbackForMonitor *audioServer_ = nullptr;
60 };
61 }
62 }
63 #endif