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