1 /* 2 * Copyright (c) 2021-2021 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 HISTREAMER_AUDIO_CAPTURE_PLUGIN_H 17 #define HISTREAMER_AUDIO_CAPTURE_PLUGIN_H 18 19 #include "plugin/common/plugin_types.h" 20 #include "plugin/interface/source_plugin.h" 21 #include "audio_capturer.h" 22 23 namespace OHOS { 24 namespace Media { 25 namespace AuCapturePlugin { 26 class AudioCapturePlugin : public Plugin::SourcePlugin { 27 public: 28 explicit AudioCapturePlugin(std::string name); 29 ~AudioCapturePlugin() override; 30 31 Plugin::Status Init() override; 32 Plugin::Status Deinit() override; 33 Plugin::Status Prepare() override; 34 Plugin::Status Reset() override; 35 Plugin::Status Start() override; 36 Plugin::Status Stop() override; 37 bool IsParameterSupported(Plugin::Tag tag) override; 38 Plugin::Status GetParameter(Plugin::Tag tag, Plugin::ValueType& value) override; 39 Plugin::Status SetParameter(Plugin::Tag tag, const Plugin::ValueType& value) override; 40 std::shared_ptr<Plugin::Allocator> GetAllocator() override; 41 Plugin::Status SetCallback(Plugin::Callback* cb) override; 42 Plugin::Status SetSource(std::shared_ptr<Plugin::MediaSource> source) override; 43 Plugin::Status Read(std::shared_ptr<Plugin::Buffer>& buffer, size_t expectedLen) override; 44 Plugin::Status GetSize(size_t& size) override; 45 bool IsSeekable() override; 46 Plugin::Status SeekTo(uint64_t offset) override; 47 48 private: 49 bool AssignSampleRateIfSupported(uint32_t sampleRate); 50 bool AssignChannelNumIfSupported(uint32_t channelNum); 51 bool AssignSampleFmtIfSupported(OHOS::Media::Plugin::AudioSampleFormat sampleFormat); 52 Plugin::Status GetAudioTime(uint64_t &audioTimeNs); 53 54 std::shared_ptr<OHOS::AudioStandard::AudioCapturer> audioCapturer_ {nullptr}; 55 AudioStandard::AudioCapturerParams capturerParams_ {}; 56 bool isStop_ {false}; 57 int64_t bitRate_ {0}; 58 size_t bufferSize_ {0}; 59 uint64_t curTimestampNs_ {0}; 60 uint64_t stopTimestampNs_ {0}; 61 uint64_t totalPauseTimeNs_ {0}; 62 }; 63 } // namespace AuCapturePlugin 64 } // namespace Media 65 } // namespace OHOS 66 #endif // HISTREAMER_AUDIO_CAPTURE_PLUGIN_H 67 68