• 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") override;
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 REMOTE_AUDIO_CAPTURER_SOURCE_H
17 #define REMOTE_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 #include <map>
26 
27 namespace OHOS {
28 namespace AudioStandard {
29 class RemoteAudioCapturerSource : public IAudioCapturerSource {
30 public:
31     static RemoteAudioCapturerSource *GetInstance(std::string deviceNetworkId);
32 
33     int32_t Init(IAudioSourceAttr &atrr) override;
34     bool IsInited(void) override;
35     void DeInit(void) override;
36 
37     int32_t Start(void) override;
38     int32_t Stop(void) override;
39     int32_t Flush(void) override;
40     int32_t Reset(void) override;
41     int32_t Pause(void) override;
42     int32_t Resume(void) override;
43     int32_t CaptureFrame(char *frame, uint64_t requestBytes, uint64_t &replyBytes) override;
44     int32_t SetVolume(float left, float right) override;
45     int32_t GetVolume(float &left, float &right) override;
46     int32_t SetMute(bool isMute) override;
47     int32_t GetMute(bool &isMute) override;
48     int32_t SetAudioScene(AudioScene audioScene, DeviceType activeDevice) override;
49     int32_t SetInputRoute(DeviceType deviceType) override;
50     uint64_t GetTransactionId() override;
51 private:
52     static std::map<std::string, RemoteAudioCapturerSource *> allRemoteSources;
53 
54     const uint32_t maxInt32 = 0x7fffffff;
55     const uint32_t audioBufferSize = 16 * 1024;
56     const uint32_t internalInputStreamId = 1;
57     const uint32_t deepBufferCapturePeriodSize = 4096;
58 
59     explicit RemoteAudioCapturerSource(std::string deviceNetworkId);
60     ~RemoteAudioCapturerSource();
61 
62     IAudioSourceAttr attr_;
63     std::string deviceNetworkId_;
64     bool capturerInited_;
65     bool started_;
66     bool paused_;
67     bool micMuteState_ = false;
68 
69     int32_t routeHandle_ = -1;
70     struct AudioManager *audioManager_;
71     struct AudioAdapter *audioAdapter_;
72     struct AudioCapture *audioCapture_;
73     struct AudioPort audioPort;
74 
75     int32_t CreateCapture(struct AudioPort &capturePort);
76     int32_t InitAudioManager();
77 #ifdef DEBUG_CAPTURE_DUMP
78     FILE *pfd;
79 #endif // DEBUG_CAPTURE_DUMP
80 };
81 }  // namespace AudioStandard
82 }  // namespace OHOS
83 #endif  // AUDIO_CAPTURER_SOURCE_H
84