• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 MULTIMEDIA_AUDIO_RENDERER_CALLBACK_H
17 #define MULTIMEDIA_AUDIO_RENDERER_CALLBACK_H
18 #include "audio_renderer.h"
19 #include "multimedia_audio_ffi.h"
20 
21 namespace OHOS {
22 namespace AudioStandard {
23 class CjRendererPositionCallback : public RendererPositionCallback {
24 public:
25     CjRendererPositionCallback() = default;
26     virtual ~CjRendererPositionCallback() = default;
27     void RegisterFunc(std::function<void(int64_t)> cjCallback);
28 
29     void OnMarkReached(const int64_t& framePosition) override;
30 
31 private:
32     std::function<void(int64_t)> func_ {};
33     std::mutex cbMutex_;
34 };
35 
36 class CjRendererPeriodPositionCallback : public RendererPeriodPositionCallback {
37 public:
38     CjRendererPeriodPositionCallback() = default;
39     virtual ~CjRendererPeriodPositionCallback() = default;
40     void RegisterFunc(std::function<void(int64_t)> cjCallback);
41 
42     void OnPeriodReached(const int64_t& frameNumber) override;
43 
44 private:
45     std::function<void(int64_t)> func_ {};
46     std::mutex cbMutex_;
47 };
48 
49 class CjAudioRendererOutputDeviceChangeCallback : public AudioRendererOutputDeviceChangeCallback {
50 public:
51     CjAudioRendererOutputDeviceChangeCallback() = default;
52     virtual ~CjAudioRendererOutputDeviceChangeCallback() = default;
53     void RegisterFunc(std::function<void(CArrDeviceDescriptor)> cjCallback);
54 
55     void OnOutputDeviceChange(
56         const AudioDeviceDescriptor& deviceInfo, const AudioStreamDeviceChangeReason reason) override;
57 
58 private:
59     std::function<void(CArrDeviceDescriptor)> func_ {};
60     std::mutex cbMutex_;
61 };
62 
63 class CjAudioRendererOutputDeviceChangeWithInfoCallback : public AudioRendererOutputDeviceChangeCallback {
64 public:
65     CjAudioRendererOutputDeviceChangeWithInfoCallback() = default;
66     virtual ~CjAudioRendererOutputDeviceChangeWithInfoCallback() = default;
67     void RegisterFunc(std::function<void(CAudioStreamDeviceChangeInfo)> cjCallback);
68 
69     void OnOutputDeviceChange(
70         const AudioDeviceDescriptor& deviceInfo, const AudioStreamDeviceChangeReason reason) override;
71 
72 private:
73     std::function<void(CAudioStreamDeviceChangeInfo)> func_ {};
74     std::mutex cbMutex_;
75 };
76 
77 class CjAudioRendererWriteCallback : public AudioRendererWriteCallback {
78 public:
79     CjAudioRendererWriteCallback() = default;
80     virtual ~CjAudioRendererWriteCallback() = default;
81     void RegisterFunc(std::function<int32_t(CArrUI8)> cjCallback, std::shared_ptr<AudioRenderer> audioRenderer);
82 
83     void OnWriteData(size_t length) override;
84 
85 private:
86     std::function<int32_t(CArrUI8)> func_ {};
87     std::shared_ptr<AudioRenderer> audioRenderer_ {};
88     std::mutex cbMutex_;
89 };
90 
91 class CjAudioRendererCallback : public AudioRendererCallback {
92 public:
93     CjAudioRendererCallback() = default;
94     virtual ~CjAudioRendererCallback() = default;
95     void RegisterFunc(std::function<void(int32_t)> cjCallback);
96     void RegisterInterruptFunc(std::function<void(CInterruptEvent)> cjCallback);
97 
98     void OnInterrupt(const InterruptEvent& interruptEvent) override;
99     void OnStateChange(const RendererState state, const StateChangeCmdType __attribute__((unused)) cmdType) override;
100 
101 private:
102     std::function<void(CInterruptEvent)> interruptCallback_ {};
103     std::function<void(int32_t)> stateChangeCallback_ {};
104     std::mutex cbMutex_;
105 };
106 } // namespace AudioStandard
107 } // namespace OHOS
108 #endif // MULTIMEDIA_AUDIO_RENDERER_CALLBACK_H
109