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