1 /*
2  * Copyright (c) 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 ARK_AUDIO_CAPTURE_ADAPTER_H
17 #define ARK_AUDIO_CAPTURE_ADAPTER_H
18 #pragma once
19 
20 #include "base/include/ark_web_base_ref_counted.h"
21 #include "base/include/ark_web_types.h"
22 
23 namespace OHOS::ArkWeb {
24 
25 /*--ark web(source=webcore)--*/
26 class ArkAudioCapturerOptionsAdapter : public virtual ArkWebBaseRefCounted {
27 public:
28     /*--ark web()--*/
29     virtual int32_t GetSamplingRate() = 0;
30 
31     /*--ark web()--*/
32     virtual int32_t GetEncoding() = 0;
33 
34     /*--ark web()--*/
35     virtual int32_t GetSampleFormat() = 0;
36 
37     /*--ark web()--*/
38     virtual int32_t GetChannels() = 0;
39 
40     /*--ark web()--*/
41     virtual int32_t GetSourceType() = 0;
42 
43     /*--ark web()--*/
44     virtual int32_t GetCapturerFlags() = 0;
45 };
46 
47 /*--ark web(source=webcore)--*/
48 class ArkBufferDescAdapter : public virtual ArkWebBaseRefCounted {
49 public:
50     /*--ark web()--*/
51     virtual uint8_t* GetBuffer() = 0;
52 
53     /*--ark web()--*/
54     virtual size_t GetBufLength() = 0;
55 
56     /*--ark web()--*/
57     virtual size_t GetDataLength() = 0;
58 
59     /*--ark web()--*/
60     virtual void SetBuffer(uint8_t* buffer) = 0;
61 
62     /*--ark web()--*/
63     virtual void SetBufLength(size_t bufLength) = 0;
64 
65     /*--ark web()--*/
66     virtual void SetDataLength(size_t dataLength) = 0;
67 };
68 
69 /*--ark web(source=webcore)--*/
70 class ArkAudioCapturerReadCallbackAdapter : public virtual ArkWebBaseRefCounted {
71 public:
72     /*--ark web()--*/
73     virtual void OnReadData(size_t length) = 0;
74 };
75 
76 /*--ark web(source=webview)--*/
77 class ArkAudioCapturerAdapter : public virtual ArkWebBaseRefCounted {
78 public:
79     /*--ark web()--*/
80     virtual int32_t Create(
81         const ArkWebRefPtr<ArkAudioCapturerOptionsAdapter> capturerOptions, ArkWebString& cachePath) = 0;
82 
83     /*--ark web()--*/
84     virtual bool Start() = 0;
85 
86     /*--ark web()--*/
87     virtual bool Stop() = 0;
88 
89     /*--ark web()--*/
90     virtual bool Release2() = 0;
91 
92     /*--ark web()--*/
93     virtual int32_t SetCapturerReadCallback(ArkWebRefPtr<ArkAudioCapturerReadCallbackAdapter> callbck) = 0;
94 
95     /*--ark web()--*/
96     virtual int32_t GetBufferDesc(ArkWebRefPtr<ArkBufferDescAdapter> buffferDesc) = 0;
97 
98     /*--ark web()--*/
99     virtual int32_t Enqueue(const ArkWebRefPtr<ArkBufferDescAdapter> bufferDesc) = 0;
100 
101     /*--ark web()--*/
102     virtual int32_t GetFrameCount(uint32_t& frameCount) = 0;
103 
104     /*--ark web()--*/
105     virtual int64_t GetAudioTime() = 0;
106 };
107 
108 } // namespace OHOS::ArkWeb
109 
110 #endif // ARK_AUDIO_CAPTURE_ADAPTER_H
111