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 #include "audio_capturer.h" 19 #include "foundation/osal/thread/mutex.h" 20 #include "plugin/common/plugin_types.h" 21 #include "plugin/interface/source_plugin.h" 22 23 namespace OHOS { 24 namespace Media { 25 namespace Plugin { 26 namespace AuCapturePlugin { 27 class AudioCapturePlugin : public SourcePlugin { 28 public: 29 explicit AudioCapturePlugin(std::string name); 30 ~AudioCapturePlugin() override; 31 32 Status Init() override; 33 Status Deinit() override; 34 Status Prepare() override; 35 Status Reset() override; 36 Status Start() override; 37 Status Stop() override; 38 Status GetParameter(Tag tag, ValueType& value) override; 39 Status SetParameter(Tag tag, const ValueType& value) override; 40 std::shared_ptr<Allocator> GetAllocator() override; 41 Status SetCallback(Callback* cb) override; 42 Status SetSource(std::shared_ptr<MediaSource> source) override; 43 Status Read(std::shared_ptr<Buffer>& buffer, size_t expectedLen) override; 44 Status GetSize(uint64_t& size) override; 45 Seekable GetSeekable() override; 46 Status SeekTo(uint64_t offset) override; 47 48 private: 49 Status DoDeinit(); 50 bool AssignSampleRateIfSupported(const ValueType& value); 51 bool AssignChannelNumIfSupported(const ValueType& value); 52 bool AssignSampleFmtIfSupported(const ValueType& value); 53 Status GetAudioTimeLocked(int64_t& audioTimeNs); 54 55 OSAL::Mutex captureMutex_ {}; 56 std::unique_ptr<OHOS::AudioStandard::AudioCapturer> audioCapturer_ {nullptr}; 57 AudioStandard::AudioCapturerParams capturerParams_ {}; 58 int64_t bitRate_ {0}; 59 uint32_t appTokenId_ {0}; 60 int32_t appUid_ {0}; 61 int32_t appPid_ {0}; 62 size_t bufferSize_ {0}; 63 }; 64 } // namespace AuCapturePlugin 65 } // namespace Plugin 66 } // namespace Media 67 } // namespace OHOS 68 #endif // HISTREAMER_AUDIO_CAPTURE_PLUGIN_H 69 70