• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 I_RENDERER_STREAM_H
17 #define I_RENDERER_STREAM_H
18 
19 #include "i_stream.h"
20 #include "audio_stream_info.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
24 class IWriteCallback {
25 public:
26     virtual int32_t OnWriteData(size_t length) = 0;
27     virtual int32_t OnWriteData(int8_t *inputData, size_t requestDataLen) = 0;
28     virtual int32_t GetAvailableSize(size_t &length) = 0;
29 };
30 
31 class IStreamCallback {
32 public:
33     virtual int32_t OnStreamData(AudioCallBackStreamInfo& callBackStremInfo) = 0;
34 };
35 
36 class IRendererStream : public IStream {
37 public:
38     virtual ~IRendererStream() = default;
39     virtual int32_t GetStreamFramesWritten(uint64_t &framesWritten) = 0;
40     virtual int32_t GetCurrentTimeStamp(uint64_t &timestamp) = 0;
41     virtual int32_t GetCurrentPosition(uint64_t &framePosition, uint64_t &timestamp, uint64_t &latency, int32_t base);
GetSpeedPosition(uint64_t & framePosition,uint64_t & timestamp,uint64_t & latency,int32_t base)42     virtual int32_t GetSpeedPosition(uint64_t &framePosition, uint64_t &timestamp, uint64_t &latency, int32_t base)
43     {
44         return GetCurrentPosition(framePosition, timestamp, latency, base);
45     }
46     virtual int32_t GetLatency(uint64_t &latency) = 0;
47     virtual int32_t SetRate(int32_t rate) = 0;
48     virtual int32_t SetAudioEffectMode(int32_t effectMode) = 0;
49     virtual int32_t GetAudioEffectMode(int32_t &effectMode) = 0;
50     virtual int32_t SetPrivacyType(int32_t privacyType) = 0;
51     virtual int32_t GetPrivacyType(int32_t &privacyType) = 0;
52 
53     virtual void RegisterWriteCallback(const std::weak_ptr<IWriteCallback> &callback) = 0;
54     virtual int32_t GetMinimumBufferSize(size_t &minBufferSize) const = 0;
55     virtual void GetByteSizePerFrame(size_t &byteSizePerFrame) const = 0;
56     virtual void GetSpanSizePerFrame(size_t &spanSizeInFrame) const = 0;
57 
58     virtual int32_t SetOffloadMode(int32_t state, bool isAppBack) = 0;
59     virtual int32_t UnsetOffloadMode() = 0;
60     virtual int32_t GetOffloadApproximatelyCacheTime(uint64_t &timestamp, uint64_t &paWriteIndex,
61         uint64_t &cacheTimeDsp, uint64_t &cacheTimePa) = 0;
62     virtual int32_t OffloadSetVolume(float volume) = 0;
63     virtual int32_t SetOffloadDataCallbackState(int32_t state) = 0;
64     virtual size_t GetWritableSize() = 0;
65     virtual int32_t UpdateSpatializationState(bool spatializationEnabled, bool headTrackingEnabled) = 0;
66     virtual int32_t UpdateMaxLength(uint32_t maxLength) = 0;
67 
68     virtual int32_t Peek(std::vector<char> *audioBuffer, int32_t &index) = 0;
69     virtual int32_t ReturnIndex(int32_t index) = 0;
70     virtual AudioProcessConfig GetAudioProcessConfig() const noexcept = 0;
71     virtual int32_t SetClientVolume(float clientVolume) = 0;
72     virtual int32_t SetSpeed(float speed) = 0;
73     virtual int32_t SetLoudnessGain(float loudnessGain) = 0;
74     virtual void BlockStream() noexcept = 0;
75 };
76 
77 struct CaptureInfo {
78     std::atomic<bool> isInnerCapEnabled = false;
79     std::shared_ptr<IRendererStream> dupStream = nullptr;
80 };
81 } // namespace AudioStandard
82 } // namespace OHOS
83 #endif // I_RENDERER_STREAM_H
84