sound_pcm.h
浏览该文件的文档.
1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #ifndef SOUND_PCM_H
6 #define SOUND_PCM_H
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <fcntl.h>
11 #include <stdarg.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <unistd.h>
15 #include <aos/list.h>
16 #include <aos/kernel.h>
17 #ifndef HAAS_AUDIO_DEMO
18 #include <sys/ioctl.h>
19 #endif
20 #include "audio_drv.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
31 typedef unsigned long aos_pcm_uframes_t;
32 typedef signed long aos_pcm_sframes_t;
33 
34 /* AOS_PCM常用宏定义 */
35 #define AOS_PCM_BLOCK 0x00000000
36 #define AOS_PCM_NONBLOCK 0x00000001
37 #define AOS_PCM_ASYNC 0x00000002
38 #define AOS_PCM_ABORT 0x00008000
39 #define AOS_PCM_NO_AUTO_RESAMPLE 0x00010000
40 #define AOS_PCM_NO_AUTO_CHANNELS 0x00020000
41 #define AOS_PCM_NO_AUTO_FORMAT 0x00040000
42 #define AOS_PCM_NO_SOFTVOL 0x00080000
43 #define AOS_PCM_EVT_WRITE (1 << 0)
44 #define AOS_PCM_EVT_READ (1 << 1)
45 #define AOS_PCM_EVT_XRUN (1 << 2)
47 /* PCM stream 类型定义 */
48 typedef enum {
53 
54 /* PCM stream 状态定义 */
55 typedef enum {
68 
69 /* PCM stream 格式定义 */
70 typedef enum {
77 
78 /* PCM stream 访问模式定义 */
79 typedef enum {
85 
86 /* PCM stream 硬件参数类型 */
87 typedef struct {
90  unsigned int sample_bits;
91  unsigned int frame_bits;
92  unsigned int channels;
93  unsigned int rate;
94  unsigned int period_time;
95  unsigned int period_size;
96  unsigned int period_bytes;
97  unsigned int periods;
98  unsigned int buffer_time;
99  unsigned int buffer_size;
100  unsigned int buffer_bytes;
101  unsigned int tick_time;
103 
104 /* PCM stream 软件参数类型 */
105 typedef struct {
106  int tstamp_mode; /*< timestamp mode */
107  unsigned int period_step;
108  unsigned int sleep_min; /*< min ticks to sleep */
109  aos_pcm_uframes_t avail_min; /*< min avail frames for wakeup */
110  aos_pcm_uframes_t xfer_align; /*< obsolete: xfer size need to be a multiple */
111  aos_pcm_uframes_t start_threshold; /*< min hw_avail frames for automatic start */
112  aos_pcm_uframes_t stop_threshold; /*< min avail frames for automatic stop */
113  aos_pcm_uframes_t silence_threshold; /*< min distance from noise for silence filling */
114  aos_pcm_uframes_t silence_size; /*< silence block size */
115  aos_pcm_uframes_t boundary; /*< pointers wrap point */
116  unsigned int proto; /*< protocol version */
117  unsigned int tstamp_type; /*< timestamp type (req. proto >= 2.0.12) */
118  unsigned char reserved[56]; /*< reserved for future */
120 
121 /* PCM stream 类型 */
122 typedef struct {
123  /* mandatory */
124  int fd; /*< 该pcm设备节点的fd,通过open()获取 */
125  aos_pcm_stream_t stream; /*< aos_pcm_stream_t 类型 */
126  aos_pcm_state_t state; /*< aos_pcm_state_t 类型 */
127  char *name; /*< pcm stream name */
128  int mode;
129  int card; /*< pcm stream 所属的card id */
130  int device; /*< pcm stream device id */
133  aos_pcm_hw_params_t *hw_params; /*< pcm stream 硬件参数 */
134  aos_pcm_sw_params_t *sw_params; /*< pcm stream 软件参数 */
135 
136  /* options */
137  void *open_func;
140  unsigned short poll_events;
141  int setup: 1,
142  compat: 1;
143  unsigned int mmap_rw: 1;
144  unsigned int mmap_shadow: 1;
145  unsigned int donot_close: 1;
146  unsigned int own_state_check:1;
148 } aos_pcm_t;
149 
150 /* 所有声卡的PCM stream汇总 */
151 typedef struct {
152  dlist_t list; /*< 列表 */
153  unsigned int count; /*< 列表中PCM Stream个数 */
154  unsigned int allocated;
155  const char *siface; /*< 默认: AOS_CTL_ELEM_IFACE_MIXER */
156  int card; /*< 当前声卡ID */
157  int device; /*< 在当前声中的设备ID */
160  int stream; /*< 0: Capture Stream 类型,1: Playback Stream 类型 */
161  int show_all;
162  char name[100]; /*< 当前设备名 */
163 } hint_list_t;
164 
173 int aos_device_name_hint(int card, void *hints);
174 
185 int aos_pcm_open(aos_pcm_t **pcm, const char *name, aos_pcm_stream_t stream, int mode);
186 
195 
204 
213 int aos_pcm_wait(aos_pcm_t *pcm, int timeout);
214 
223 
232 
240 int aos_pcm_pause(aos_pcm_t *pcm, int enable);
241 
250 
259 
268 
277 
287 
301 int aos_pcm_set_params(aos_pcm_t *pcm, aos_pcm_format_t format, aos_pcm_access_t access, unsigned int channels,
302  unsigned int rate, int soft_resample, unsigned int latency);
303 
312 
321 
331 
342 
353 
364 
375 
384 
393 
403 
413 
418 #ifdef __cplusplus
419 }
420 #endif
421 #endif /* SOUND_PCM_H */
422 
aos_pcm_stream_t
Definition: sound_pcm.h:48
aos_pcm_sframes_t aos_pcm_readi(aos_pcm_t *pcm, void *buffer, aos_pcm_uframes_t size)
int aos_pcm_set_params(aos_pcm_t *pcm, aos_pcm_format_t format, aos_pcm_access_t access, unsigned int channels, unsigned int rate, int soft_resample, unsigned int latency)
aos_pcm_sframes_t aos_pcm_writei(aos_pcm_t *pcm, const void *buffer, aos_pcm_uframes_t size)
int aos_pcm_prepare(aos_pcm_t *pcm)
int aos_device_name_hint(int card, void *hints)
int aos_pcm_recover(aos_pcm_t *pcm)
int aos_pcm_hw_params_alloca(aos_pcm_hw_params_t **p)
int aos_pcm_suspend(aos_pcm_t *pcm)
int aos_pcm_sw_params_alloca(aos_pcm_sw_params_t **p)
int aos_pcm_sw_params_any(aos_pcm_sw_params_t *params)
signed long aos_pcm_sframes_t
Definition: sound_pcm.h:32
int aos_pcm_close(aos_pcm_t *pcm)
aos_pcm_format_t
Definition: sound_pcm.h:70
int aos_pcm_stop(aos_pcm_t *pcm)
aos_pcm_access_t
Definition: sound_pcm.h:79
unsigned long aos_pcm_uframes_t
Definition: sound_pcm.h:31
int aos_pcm_hw_params(aos_pcm_t *pcm, aos_pcm_hw_params_t *p)
aos_pcm_sframes_t aos_pcm_writen(aos_pcm_t *pcm, void **bufs, aos_pcm_uframes_t size)
int aos_pcm_resume(aos_pcm_t *pcm)
int aos_pcm_sw_params(aos_pcm_t *pcm, aos_pcm_sw_params_t *params)
int aos_pcm_pause(aos_pcm_t *pcm, int enable)
aos_pcm_sframes_t aos_pcm_readn(aos_pcm_t *pcm, void **bufs, aos_pcm_uframes_t size)
aos_pcm_sframes_t aos_pcm_bytes_to_frames(aos_pcm_t *pcm, int bytes)
int aos_pcm_hw_params_any(aos_pcm_hw_params_t *params)
int aos_pcm_frames_to_bytes(aos_pcm_t *pcm, aos_pcm_sframes_t frames)
aos_pcm_state_t
Definition: sound_pcm.h:55
int aos_pcm_open(aos_pcm_t **pcm, const char *name, aos_pcm_stream_t stream, int mode)
int aos_pcm_wait(aos_pcm_t *pcm, int timeout)
int aos_pcm_drain(aos_pcm_t *pcm)
int aos_pcm_start(aos_pcm_t *pcm)
@ AOS_PCM_STREAM_LAST
Definition: sound_pcm.h:51
@ AOS_PCM_STREAM_PLAYBACK
Definition: sound_pcm.h:49
@ AOS_PCM_STREAM_CAPTURE
Definition: sound_pcm.h:50
@ AOSRV_PCM_FORMAT_ALL
Definition: sound_pcm.h:75
@ AOSRV_PCM_FORMAT_S8
Definition: sound_pcm.h:71
@ AOSRV_PCM_FORMAT_S32_LE
Definition: sound_pcm.h:74
@ AOSRV_PCM_FORMAT_S24_LE
Definition: sound_pcm.h:73
@ AOSRV_PCM_FORMAT_S16_LE
Definition: sound_pcm.h:72
@ AOS_PCM_ACCESS_RW_NONINTERLEAVED
Definition: sound_pcm.h:83
@ AOS_PCM_ACCESS_MMAP_NONINTERLEAVED
Definition: sound_pcm.h:81
@ AOS_PCM_ACCESS_RW_INTERLEAVED
Definition: sound_pcm.h:82
@ AOS_PCM_ACCESS_MMAP_INTERLEAVED
Definition: sound_pcm.h:80
@ AOS_PCM_STATE_IDLE
Definition: sound_pcm.h:56
@ AOS_PCM_STATE_DRAINING
Definition: sound_pcm.h:61
@ AOS_PCM_STATE_OPEN
Definition: sound_pcm.h:57
@ AOS_PCM_STATE_PREPARED
Definition: sound_pcm.h:58
@ AOS_PCM_STATE_PRIVATE1
Definition: sound_pcm.h:66
@ AOS_PCM_STATE_DISCONNECTED
Definition: sound_pcm.h:64
@ AOS_PCM_STATE_LAST
Definition: sound_pcm.h:65
@ AOS_PCM_STATE_RUNNING
Definition: sound_pcm.h:59
@ AOS_PCM_STATE_PAUSED
Definition: sound_pcm.h:62
@ AOS_PCM_STATE_XRUN
Definition: sound_pcm.h:60
@ AOS_PCM_STATE_SUSPENDED
Definition: sound_pcm.h:63
void * aos_hdl_t
Definition: kernel.h:88
unsigned int period_size
Definition: sound_pcm.h:95
unsigned int frame_bits
Definition: sound_pcm.h:91
unsigned int period_time
Definition: sound_pcm.h:94
unsigned int buffer_size
Definition: sound_pcm.h:99
unsigned int buffer_bytes
Definition: sound_pcm.h:100
unsigned int tick_time
Definition: sound_pcm.h:101
aos_pcm_format_t format
Definition: sound_pcm.h:89
unsigned int channels
Definition: sound_pcm.h:92
aos_pcm_access_t access
Definition: sound_pcm.h:88
unsigned int sample_bits
Definition: sound_pcm.h:90
unsigned int period_bytes
Definition: sound_pcm.h:96
unsigned int periods
Definition: sound_pcm.h:97
unsigned int rate
Definition: sound_pcm.h:93
unsigned int buffer_time
Definition: sound_pcm.h:98
unsigned int proto
Definition: sound_pcm.h:116
aos_pcm_uframes_t boundary
Definition: sound_pcm.h:115
aos_pcm_uframes_t avail_min
Definition: sound_pcm.h:109
aos_pcm_uframes_t stop_threshold
Definition: sound_pcm.h:112
unsigned int tstamp_type
Definition: sound_pcm.h:117
unsigned int sleep_min
Definition: sound_pcm.h:108
aos_pcm_uframes_t silence_size
Definition: sound_pcm.h:114
unsigned int period_step
Definition: sound_pcm.h:107
aos_pcm_uframes_t start_threshold
Definition: sound_pcm.h:111
aos_pcm_uframes_t silence_threshold
Definition: sound_pcm.h:113
aos_pcm_uframes_t xfer_align
Definition: sound_pcm.h:110
aos_hdl_t evt
Definition: sound_pcm.h:132
unsigned int donot_close
Definition: sound_pcm.h:145
int mode
Definition: sound_pcm.h:128
aos_pcm_state_t state
Definition: sound_pcm.h:126
void * open_func
Definition: sound_pcm.h:137
int setup
Definition: sound_pcm.h:141
char * name
Definition: sound_pcm.h:127
aos_hdl_t mutex
Definition: sound_pcm.h:131
int device
Definition: sound_pcm.h:130
aos_pcm_sw_params_t * sw_params
Definition: sound_pcm.h:134
aos_pcm_stream_t stream
Definition: sound_pcm.h:125
long minperiodtime
Definition: sound_pcm.h:138
aos_pcm_hw_params_t * hw_params
Definition: sound_pcm.h:133
unsigned int own_state_check
Definition: sound_pcm.h:146
int card
Definition: sound_pcm.h:129
void * private_data
Definition: sound_pcm.h:147
int poll_fd_count
Definition: sound_pcm.h:139
unsigned short poll_events
Definition: sound_pcm.h:140
int compat
Definition: sound_pcm.h:142
unsigned int mmap_rw
Definition: sound_pcm.h:143
unsigned int mmap_shadow
Definition: sound_pcm.h:144
unsigned int count
Definition: sound_pcm.h:153
unsigned int allocated
Definition: sound_pcm.h:154
int show_all
Definition: sound_pcm.h:161
const char * siface
Definition: sound_pcm.h:155
long device_input
Definition: sound_pcm.h:158
dlist_t list
Definition: sound_pcm.h:152
long device_output
Definition: sound_pcm.h:159