1 /*
2 * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved.
3 *
4 * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in
5 * the the people's Republic of China and other countries.
6 * All Allwinner Technology Co.,Ltd. trademarks are used with permission.
7 *
8 * DISCLAIMER
9 * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT.
10 * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.)
11 * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN
12 * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES.
13 * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS
14 * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE.
15 * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT
19 * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND,
20 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING
21 * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE
22 * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 #ifndef __AW_ALSA_PCM_PLUGIN_GENERIC_H
34 #define __AW_ALSA_PCM_PLUGIN_GENERIC_H
35 
36 #include "pcm_generic.h"
37 
38 typedef snd_pcm_uframes_t (*snd_pcm_slave_xfer_areas_func_t)
39     (snd_pcm_t *pcm,
40     const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset,
41     snd_pcm_uframes_t size,
42     const snd_pcm_channel_area_t *slave_areas,
43     snd_pcm_uframes_t slave_offset,
44     snd_pcm_uframes_t *slave_sizep);
45 
46 typedef snd_pcm_sframes_t (*snd_pcm_slave_xfer_areas_undo_func_t)
47     (snd_pcm_t *pcm,
48     const snd_pcm_channel_area_t *res_areas,    /* result areas */
49     snd_pcm_uframes_t res_offset,       /* offset of result areas */
50     snd_pcm_uframes_t res_size,     /* size of result areas */
51     snd_pcm_uframes_t slave_undo_size);
52 
53 typedef struct {
54     snd_pcm_generic_t gen;
55     snd_pcm_slave_xfer_areas_func_t read;
56     snd_pcm_slave_xfer_areas_func_t write;
57     snd_pcm_slave_xfer_areas_undo_func_t undo_read;
58     snd_pcm_slave_xfer_areas_undo_func_t undo_write;
59     int (*init)(snd_pcm_t *pcm);
60     snd_pcm_uframes_t appl_ptr, hw_ptr;
61 } snd_pcm_plugin_t;
62 
63 void snd_pcm_plugin_init(snd_pcm_plugin_t *plugin);
64 int snd_pcm_plugin_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
65 int snd_pcm_plugin_wait(snd_pcm_t *pcm, int timeout);
66 
67 extern const snd_pcm_fast_ops_t snd_pcm_plugin_fast_ops;
68 
69 snd_pcm_sframes_t snd_pcm_plugin_undo_read_generic
70      (snd_pcm_t *pcm,
71       const snd_pcm_channel_area_t *res_areas,  /* result areas */
72       snd_pcm_uframes_t res_offset,     /* offset of result areas */
73       snd_pcm_uframes_t res_size,       /* size of result areas */
74       snd_pcm_uframes_t slave_undo_size);
75 
76 snd_pcm_sframes_t snd_pcm_plugin_undo_write_generic
77      (snd_pcm_t *pcm,
78       const snd_pcm_channel_area_t *res_areas,  /* result areas */
79       snd_pcm_uframes_t res_offset,     /* offset of result areas */
80       snd_pcm_uframes_t res_size,       /* size of result areas */
81       snd_pcm_uframes_t slave_undo_size);
82 
83 int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
84 int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
85 int snd_pcm_linear_convert_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_format);
86 
87 #endif /* __AW_ALSA_PCM_PLUGIN_GENERIC_H */
88