1 /* 2 * Copyright (c) 2021-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_SOURCE_H 17 #define AUDIO_CAPTURER_SOURCE_H 18 19 #include "audio_info.h" 20 #include "audio_manager.h" 21 #include "i_audio_capturer_source.h" 22 23 #include <cstdio> 24 #include <list> 25 26 namespace OHOS { 27 namespace AudioStandard { 28 #define AUDIO_CHANNELCOUNT 2 29 #define AUDIO_SAMPLE_RATE_48K 48000 30 #define DEEP_BUFFER_CAPTURE_PERIOD_SIZE 4096 31 #define INT_32_MAX 0x7fffffff 32 #define PERIOD_SIZE 1024 33 #define PATH_LEN 256 34 #define AUDIO_BUFF_SIZE (16 * 1024) 35 #define PCM_8_BIT 8 36 #define PCM_16_BIT 16 37 #define INTERNAL_INPUT_STREAM_ID 1 38 39 class AudioCapturerSource : public IAudioCapturerSource { 40 public: 41 int32_t Init(IAudioSourceAttr &atrr) override; 42 bool IsInited(void) override; 43 void DeInit(void) override; 44 45 int32_t Start(void) override; 46 int32_t Stop(void) override; 47 int32_t Flush(void) override; 48 int32_t Reset(void) override; 49 int32_t Pause(void) override; 50 int32_t Resume(void) override; 51 int32_t CaptureFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes) override; 52 int32_t SetVolume(float left, float right) override; 53 int32_t GetVolume(float &left, float &right) override; 54 int32_t SetMute(bool isMute) override; 55 int32_t GetMute(bool &isMute) override; 56 57 int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) override; 58 59 int32_t SetInputRoute(DeviceType deviceType, AudioPortPin &inputPortPin); 60 61 int32_t SetInputRoute(DeviceType deviceType) override; 62 63 uint64_t GetTransactionId() override; 64 65 static AudioCapturerSource *GetInstance(void); 66 bool capturerInited_; 67 static bool micMuteState_; 68 69 private: 70 const int32_t HALF_FACTOR = 2; 71 const int32_t MAX_AUDIO_ADAPTER_NUM = 5; 72 const float MAX_VOLUME_LEVEL = 15.0f; 73 74 IAudioSourceAttr attr_; 75 bool started_; 76 bool paused_; 77 float leftVolume_; 78 float rightVolume_; 79 80 int32_t routeHandle_ = -1; 81 uint32_t openMic_; 82 std::string adapterNameCase_; 83 struct AudioManager *audioManager_; 84 struct AudioAdapter *audioAdapter_; 85 struct AudioCapture *audioCapture_; 86 struct AudioPort audioPort; 87 88 int32_t CreateCapture(struct AudioPort &capturePort); 89 int32_t InitAudioManager(); 90 91 #ifdef CAPTURE_DUMP 92 FILE *pfd; 93 #endif 94 95 AudioCapturerSource(); 96 ~AudioCapturerSource(); 97 }; 98 } // namespace AudioStandard 99 } // namespace OHOS 100 #endif // AUDIO_CAPTURER_SOURCE_H 101