1 /* 2 * Copyright (c) 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 ALSA_SND_CAPTURE_H 17 #define ALSA_SND_CAPTURE_H 18 19 #include "alsa_soundcard.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 typedef void* CapturePriData; 26 27 struct AlsaCapture { 28 struct AlsaSoundCard soundCard; 29 enum AudioPortPin descPins; 30 bool muteState; 31 bool periodEvent; /* produce poll event after each period */ 32 snd_pcm_sframes_t bufferSize; 33 snd_pcm_sframes_t periodSize; 34 unsigned int bufferTime; /* (0.5s): ring buffer length in us */ 35 unsigned int periodTime; /* (0.1s): period time in us */ 36 int resample; /* enable alsa-lib resampling */ 37 CapturePriData priData; 38 39 /* Capture scene */ 40 int32_t (*Init)(struct AlsaCapture*); 41 int32_t (*Open)(struct AlsaCapture *); 42 int32_t (*SelectScene)(struct AlsaCapture *, enum AudioPortPin, const struct PathDeviceInfo *); 43 int32_t (*Start)(struct AlsaCapture *); 44 int32_t (*Stop)(struct AlsaCapture *); 45 int32_t (*Close)(struct AlsaCapture *); 46 int32_t (*Read)(struct AlsaCapture *, struct AudioHwCaptureParam *); 47 int32_t (*GetMmapPosition)(struct AlsaCapture *); 48 int32_t (*MmapRead)(struct AlsaCapture *, const struct AudioHwCaptureParam *); 49 50 /* volume operation */ 51 int32_t (*GetVolThreshold)(struct AlsaCapture *, long *, long *); 52 int32_t (*GetVolume)(struct AlsaCapture *, long *); 53 int32_t (*SetVolume)(struct AlsaCapture *, long); 54 55 /* gain operation */ 56 int32_t (*GetGainThreshold)(struct AlsaCapture *, float *, float *); 57 int32_t (*GetGain)(struct AlsaCapture *, float *); 58 int32_t (*SetGain)(struct AlsaCapture *, float); 59 60 /* mute operation */ 61 bool (*GetMute)(struct AlsaCapture *); 62 int32_t (*SetMute)(struct AlsaCapture *, bool); 63 64 /* set pause or resume state */ 65 int32_t (*SetPauseState)(struct AlsaCapture *, bool); 66 }; 67 68 struct AlsaCapture *CaptureCreateInstance(const char* adapterName); 69 struct AlsaCapture *CaptureGetInstance(const char *adapterName); 70 int32_t CaptureSetParams(struct AlsaCapture *captureIns, const struct AudioHwCaptureParam *handleData); 71 void CaptureSetPriData(struct AlsaCapture *captureIns, CapturePriData data); 72 CapturePriData CaptureGetPriData(struct AlsaCapture *captureIns); 73 74 /* 75 Different platforms implement this function rewriting capture implementation 76 */ 77 int32_t CaptureOverrideFunc(struct AlsaCapture *captureIns); 78 79 #ifdef __cplusplus 80 } 81 #endif 82 83 #endif /* ALSA_SND_CAPTURE_H */