1 /* 2 * Copyright (c) 2022 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_GATEWAY_H 17 #define AUDIO_CAPTURER_GATEWAY_H 18 19 #include "audio_stream.h" 20 #include "audio_container_stream_base.h" 21 22 namespace OHOS { 23 namespace AudioStandard { 24 class AudioCapturerGateway : public AudioCapturer { 25 public: 26 27 int32_t GetFrameCount(uint32_t &frameCount) const override; 28 int32_t SetParams(const AudioCapturerParams params) override; 29 int32_t SetCapturerCallback(const std::shared_ptr<AudioCapturerCallback> &callback) override; 30 int32_t GetParams(AudioCapturerParams ¶ms) const override; 31 int32_t GetCapturerInfo(AudioCapturerInfo &capturerInfo) const override; 32 int32_t GetStreamInfo(AudioStreamInfo &streamInfo) const override; 33 bool Start() const override; 34 int32_t Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) const override; 35 CapturerState GetStatus() const override; 36 bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const override; 37 bool Pause() const override; 38 bool Stop() const override; 39 bool Flush() const override; 40 bool Release() const override; 41 int32_t GetBufferSize(size_t &bufferSize) const override; 42 int32_t GetAudioStreamId(uint32_t &sessionID) const override; 43 int32_t SetCapturerPositionCallback(int64_t markPosition, 44 const std::shared_ptr<CapturerPositionCallback> &callback) override; 45 void UnsetCapturerPositionCallback() override; 46 int32_t SetCapturerPeriodPositionCallback(int64_t frameNumber, 47 const std::shared_ptr<CapturerPeriodPositionCallback> &callback) override; 48 void UnsetCapturerPeriodPositionCallback() override; 49 int32_t SetBufferDuration(uint64_t bufferDuration) const override; 50 int32_t SetCaptureMode(AudioCaptureMode capturerMode)const override; 51 AudioCaptureMode GetCaptureMode()const override; 52 int32_t SetCapturerReadCallback(const std::shared_ptr<AudioCapturerReadCallback> &callback) override; 53 int32_t GetBufferDesc(BufferDesc &bufDesc)const override; 54 int32_t Enqueue(const BufferDesc &bufDesc)const override; 55 int32_t Clear()const override; 56 int32_t GetBufQueueState(BufferQueueState &bufState)const override; 57 void SetApplicationCachePath(const std::string cachePath) override; 58 59 AudioCapturerInfo capturerInfo_ = {}; 60 61 explicit AudioCapturerGateway(AudioStreamType audioStreamType, const AppInfo &appInfo); 62 virtual ~AudioCapturerGateway(); 63 bool isChannelChange_ = false; 64 65 private: 66 std::shared_ptr<AudioContainerCaptureStream> audioStream_; 67 std::shared_ptr<AudioStreamCallback> audioStreamCallback_ = nullptr; 68 AppInfo appInfo_ = {}; 69 }; 70 71 class AudioStreamCapturerCallback : public AudioStreamCallback { 72 public: 73 virtual ~AudioStreamCapturerCallback() = default; 74 75 void OnStateChange(const State state, StateChangeCmdType cmdType = CMD_FROM_CLIENT) override; 76 void SaveCallback(const std::weak_ptr<AudioCapturerCallback> &callback); 77 78 private: 79 std::weak_ptr<AudioCapturerCallback> callback_; 80 }; 81 } // namespace AudioStandard 82 } // namespace OHOS 83 84 #endif // AUDIO_CAPTURER_GATEWAY_H 85