• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <hdf_log.h>
16 #include "audio_internal.h"
17 #include "audio_adapter_info_common.h"
18 #include "audio_bluetooth_manager.h"
19 #include "audio_capture.h"
20 namespace OHOS::HDI::Audio_Bluetooth {
AudioCaptureStart(AudioHandle handle)21 int32_t AudioCaptureStart(AudioHandle handle)
22 {
23     HDF_LOGI("%{public}s enter", __func__);
24 #ifdef A2DP_HDI_SERVICE
25     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(handle);
26     if (hwCapture == nullptr) {
27         return AUDIO_HAL_ERR_INVALID_PARAM;
28     }
29     return OHOS::Bluetooth::StartCapture();
30 #endif
31     return AUDIO_HAL_ERR_NOT_SUPPORT;
32 }
33 
AudioCaptureStop(AudioHandle handle)34 int32_t AudioCaptureStop(AudioHandle handle)
35 {
36     HDF_LOGI("%{public}s enter", __func__);
37 #ifdef A2DP_HDI_SERVICE
38     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(handle);
39     if (hwCapture == nullptr) {
40         return AUDIO_HAL_ERR_INVALID_PARAM;
41     }
42     OHOS::Bluetooth::StopCapture();
43     hwCapture->captureParam.captureMode.ctlParam.pause = false;
44     return AUDIO_HAL_SUCCESS;
45 #endif
46     return AUDIO_HAL_ERR_NOT_SUPPORT;
47 }
48 
AudioCapturePause(AudioHandle handle)49 int32_t AudioCapturePause(AudioHandle handle)
50 {
51     HDF_LOGI("%{public}s enter", __func__);
52 #ifdef A2DP_HDI_SERVICE
53     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(handle);
54     if (hwCapture == nullptr) {
55         return AUDIO_HAL_ERR_INVALID_PARAM;
56     }
57     if (hwCapture->captureParam.captureMode.ctlParam.pause) {
58         HDF_LOGE("Audio is already pause");
59         return AUDIO_HAL_ERR_NOT_SUPPORT;
60     }
61     OHOS::Bluetooth::StopCapture();
62     hwCapture->captureParam.captureMode.ctlParam.pause = true;
63     return AUDIO_HAL_SUCCESS;
64 #endif
65     return AUDIO_HAL_ERR_NOT_SUPPORT;
66 }
67 
AudioCaptureResume(AudioHandle handle)68 int32_t AudioCaptureResume(AudioHandle handle)
69 {
70     HDF_LOGI("%{public}s enter", __func__);
71 #ifdef A2DP_HDI_SERVICE
72     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(handle);
73     if (hwCapture == nullptr) {
74         return AUDIO_HAL_ERR_INVALID_PARAM;
75     }
76     if (!hwCapture->captureParam.captureMode.ctlParam.pause) {
77         HDF_LOGE("Audio is already Resume");
78         return AUDIO_HAL_ERR_NOT_SUPPORT;
79     }
80     OHOS::Bluetooth::StartCapture();
81     hwCapture->captureParam.captureMode.ctlParam.pause = false;
82     return AUDIO_HAL_SUCCESS;
83 #endif
84     return AUDIO_HAL_ERR_NOT_SUPPORT;
85 }
86 
AudioCaptureFlush(AudioHandle handle)87 int32_t AudioCaptureFlush(AudioHandle handle)
88 {
89     HDF_LOGI("%{public}s enter", __func__);
90     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(handle);
91     if (hwCapture == nullptr) {
92         return AUDIO_HAL_ERR_INVALID_PARAM;
93     }
94     return AUDIO_HAL_ERR_NOT_SUPPORT;
95 }
96 
AudioCaptureSetMute(AudioHandle handle,bool mute)97 int32_t AudioCaptureSetMute(AudioHandle handle, bool mute)
98 {
99     (void)mute;
100     return AUDIO_HAL_SUCCESS;
101 }
102 
AudioCaptureGetMute(AudioHandle handle,bool * mute)103 int32_t AudioCaptureGetMute(AudioHandle handle, bool *mute)
104 {
105     (void)mute;
106     return AUDIO_HAL_SUCCESS;
107 }
108 
AudioCaptureCaptureFrame(struct AudioCapture * capture,void * frame,uint64_t requestBytes,uint64_t * replyBytes)109 int32_t AudioCaptureCaptureFrame(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes)
110 {
111     HDF_LOGD("%{public}s enter", __func__);
112 #ifdef A2DP_HDI_SERVICE
113     auto *hwCapture = reinterpret_cast<struct AudioHwCapture *>(capture);
114     if (hwCapture == nullptr || frame == nullptr || replyBytes == nullptr) {
115         HDF_LOGE("Capture Frame Paras is NULL");
116         return AUDIO_HAL_ERR_INVALID_PARAM;
117     }
118     auto *data = reinterpret_cast<uint8_t *>(frame);
119     int32_t ret = OHOS::Bluetooth::ReadFrame(data, requestBytes);
120     *replyBytes = ret;
121     return ret;
122 #endif
123     return AUDIO_HAL_ERR_NOT_SUPPORT;
124 }
125 }