1 /* 2 * Copyright (c) 2020-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 FRAMEWORKS_AUDIO_CAPTURER_IMPL_H 17 #define FRAMEWORKS_AUDIO_CAPTURER_IMPL_H 18 19 #include <mutex> 20 #include <sys/time.h> 21 22 #include "audio_capturer.h" 23 24 namespace OHOS { 25 namespace Audio { 26 enum AudioChannel { 27 AUDIO_CHANNEL_IN_MONO = 1, /* mono */ 28 AUDIO_CHANNEL_IN_STEREO = 2, /* stereo */ 29 AUDIO_CHANNEL_BUTT 30 }; 31 32 class AudioSource; 33 class AudioEncoder; 34 class AudioCapturerImpl { 35 public: 36 AudioCapturerImpl(); 37 virtual ~AudioCapturerImpl(); 38 static bool GetMinFrameCount(int32_t sampleRate, int32_t channelCount, AudioCodecFormat audioFormat, 39 size_t &frameCount); 40 int32_t SetCapturerInfo(const AudioCapturerInfo info); 41 int32_t GetCapturerInfo(AudioCapturerInfo &info); 42 bool Record(); 43 bool Stop(); 44 bool Release(); 45 int32_t Read(uint8_t *buffer, size_t userSize, bool isBlockingRead); 46 uint64_t GetFrameCount(); 47 State GetStatus(); 48 bool GetTimestamp(Timestamp ×tamp, Timestamp::Timebase base); 49 50 private: 51 bool StopInternal(); 52 53 std::unique_ptr<AudioSource> audioSource_; 54 std::unique_ptr<AudioEncoder> audioEncoder_; 55 State status_ = INITIALIZED; 56 AudioCapturerInfo info_; 57 Timestamp timestamp_; 58 int32_t inputDeviceId_ = 0; 59 std::mutex mutex_; 60 }; 61 } // namespace Audio 62 } // namespace OHOS 63 #endif // FRAMEWORKS_AUDIO_CAPTURER_IMPL_H 64