1 /*
2  * Copyright (c) 2021-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 AUDIO_CAPTURER_FILE_SOURCE_H
17 #define AUDIO_CAPTURER_FILE_SOURCE_H
18 
19 #include <cstdint>
20 #include <cstdio>
21 #include "audio_info.h"
22 #include "i_audio_capturer_source.h"
23 
24 namespace OHOS {
25 namespace AudioStandard {
26 class AudioCapturerFileSource : public IAudioCapturerSource {
27 public:
28     AudioCapturerFileSource();
29     ~AudioCapturerFileSource();
30     int32_t Init(const IAudioSourceAttr &attr) override;
31     bool IsInited(void) override;
32     void DeInit(void) override;
33 
34     int32_t Start(void) override;
35     int32_t Stop(void) override;
36     int32_t Flush(void) override;
37     int32_t Reset(void) override;
38     int32_t Pause(void) override;
39     int32_t Resume(void) override;
40     int32_t CaptureFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes) override;
41     int32_t SetVolume(float left, float right) override;
42     int32_t GetVolume(float &left, float &right) override;
43     int32_t SetMute(bool isMute) override;
44     int32_t GetMute(bool &isMute) override;
45     int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) override;
46     int32_t SetInputRoute(DeviceType deviceType) override;
47     uint64_t GetTransactionId() override;
48     int32_t GetPresentationPosition(uint64_t& frames, int64_t& timeSec, int64_t& timeNanoSec) override;
49     void RegisterWakeupCloseCallback(IAudioSourceCallback *callback) override;
50     void RegisterAudioCapturerSourceCallback(std::unique_ptr<ICapturerStateCallback> callback) override;
51     void RegisterParameterCallback(IAudioSourceCallback *callback) override;
52     std::string GetAudioParameter(const AudioParamKey key, const std::string &condition) override;
53 
54     float GetMaxAmplitude() override;
55 
56     int32_t UpdateAppsUid(const int32_t appsUid[PA_MAX_OUTPUTS_PER_SOURCE], const size_t size) final;
57     int32_t UpdateAppsUid(const std::vector<int32_t> &appsUid) final;
58 private:
59     bool capturerInited_ = false;
60     FILE *filePtr = nullptr;
61 };
62 }  // namespace AudioStandard
63 }  // namespace OHOS
64 #endif // AUDIO_CAPTURER_FILE_SOURCE_H
65