| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2012 Jan Vesely
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 | /** @addtogroup libdrv
|
|---|
| 7 | * @addtogroup usb
|
|---|
| 8 | * @{
|
|---|
| 9 | */
|
|---|
| 10 | /** @file
|
|---|
| 11 | * @brief Audio PCM buffer interface.
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #ifndef LIBDRV_AUDIO_PCM_IFACE_H_
|
|---|
| 15 | #define LIBDRV_AUDIO_PCM_IFACE_H_
|
|---|
| 16 |
|
|---|
| 17 | #include <async.h>
|
|---|
| 18 | #include <stdbool.h>
|
|---|
| 19 | #include <loc.h>
|
|---|
| 20 | #include <pcm/sample_format.h>
|
|---|
| 21 |
|
|---|
| 22 | #include "ddf/driver.h"
|
|---|
| 23 |
|
|---|
| 24 | typedef enum {
|
|---|
| 25 | /** Device is capable of audio capture */
|
|---|
| 26 | AUDIO_CAP_CAPTURE,
|
|---|
| 27 | /** Device is capable of audio playback */
|
|---|
| 28 | AUDIO_CAP_PLAYBACK,
|
|---|
| 29 | /** Maximum size of device buffer */
|
|---|
| 30 | AUDIO_CAP_MAX_BUFFER,
|
|---|
| 31 | /** Device is capable of providing accurate buffer position info */
|
|---|
| 32 | AUDIO_CAP_BUFFER_POS,
|
|---|
| 33 | /** Device is capable of event based playback or capture */
|
|---|
| 34 | AUDIO_CAP_INTERRUPT,
|
|---|
| 35 | /** Minimal size of playback/record fragment */
|
|---|
| 36 | AUDIO_CAP_INTERRUPT_MIN_FRAMES,
|
|---|
| 37 | /** Maximum size of playback/record fragment */
|
|---|
| 38 | AUDIO_CAP_INTERRUPT_MAX_FRAMES,
|
|---|
| 39 | } audio_cap_t;
|
|---|
| 40 |
|
|---|
| 41 | typedef enum {
|
|---|
| 42 | PCM_EVENT_PLAYBACK_STARTED = IPC_FIRST_USER_METHOD,
|
|---|
| 43 | PCM_EVENT_CAPTURE_STARTED,
|
|---|
| 44 | PCM_EVENT_FRAMES_PLAYED,
|
|---|
| 45 | PCM_EVENT_FRAMES_CAPTURED,
|
|---|
| 46 | PCM_EVENT_PLAYBACK_TERMINATED,
|
|---|
| 47 | PCM_EVENT_CAPTURE_TERMINATED,
|
|---|
| 48 | } pcm_event_t;
|
|---|
| 49 |
|
|---|
| 50 | const char *audio_pcm_cap_str(audio_cap_t);
|
|---|
| 51 | const char *audio_pcm_event_str(pcm_event_t);
|
|---|
| 52 |
|
|---|
| 53 | typedef async_sess_t audio_pcm_sess_t;
|
|---|
| 54 |
|
|---|
| 55 | audio_pcm_sess_t *audio_pcm_open(const char *);
|
|---|
| 56 | audio_pcm_sess_t *audio_pcm_open_default(void);
|
|---|
| 57 | audio_pcm_sess_t *audio_pcm_open_service(service_id_t service);
|
|---|
| 58 | void audio_pcm_close(audio_pcm_sess_t *);
|
|---|
| 59 |
|
|---|
| 60 | errno_t audio_pcm_get_info_str(audio_pcm_sess_t *, char **);
|
|---|
| 61 | errno_t audio_pcm_test_format(audio_pcm_sess_t *, unsigned *, unsigned *,
|
|---|
| 62 | pcm_sample_format_t *);
|
|---|
| 63 | errno_t audio_pcm_query_cap(audio_pcm_sess_t *, audio_cap_t, sysarg_t *);
|
|---|
| 64 | errno_t audio_pcm_register_event_callback(audio_pcm_sess_t *,
|
|---|
| 65 | async_port_handler_t, void *);
|
|---|
| 66 | errno_t audio_pcm_unregister_event_callback(audio_pcm_sess_t *);
|
|---|
| 67 |
|
|---|
| 68 | errno_t audio_pcm_get_buffer(audio_pcm_sess_t *, void **, size_t *);
|
|---|
| 69 | errno_t audio_pcm_get_buffer_pos(audio_pcm_sess_t *, size_t *);
|
|---|
| 70 | errno_t audio_pcm_release_buffer(audio_pcm_sess_t *);
|
|---|
| 71 |
|
|---|
| 72 | errno_t audio_pcm_start_playback_fragment(audio_pcm_sess_t *, unsigned,
|
|---|
| 73 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 74 | errno_t audio_pcm_last_playback_fragment(audio_pcm_sess_t *);
|
|---|
| 75 |
|
|---|
| 76 | errno_t audio_pcm_start_playback(audio_pcm_sess_t *,
|
|---|
| 77 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 78 | errno_t audio_pcm_stop_playback_immediate(audio_pcm_sess_t *);
|
|---|
| 79 | errno_t audio_pcm_stop_playback(audio_pcm_sess_t *);
|
|---|
| 80 |
|
|---|
| 81 | errno_t audio_pcm_start_capture_fragment(audio_pcm_sess_t *, unsigned,
|
|---|
| 82 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 83 | errno_t audio_pcm_last_capture_fragment(audio_pcm_sess_t *);
|
|---|
| 84 |
|
|---|
| 85 | errno_t audio_pcm_start_capture(audio_pcm_sess_t *,
|
|---|
| 86 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 87 | errno_t audio_pcm_stop_capture_immediate(audio_pcm_sess_t *);
|
|---|
| 88 | errno_t audio_pcm_stop_capture(audio_pcm_sess_t *);
|
|---|
| 89 |
|
|---|
| 90 | /** Audio pcm communication interface. */
|
|---|
| 91 | typedef struct {
|
|---|
| 92 | errno_t (*get_info_str)(ddf_fun_t *, const char **);
|
|---|
| 93 | errno_t (*test_format)(ddf_fun_t *, unsigned *, unsigned *,
|
|---|
| 94 | pcm_sample_format_t *);
|
|---|
| 95 | unsigned (*query_cap)(ddf_fun_t *, audio_cap_t);
|
|---|
| 96 | errno_t (*get_buffer_pos)(ddf_fun_t *, size_t *);
|
|---|
| 97 | errno_t (*get_buffer)(ddf_fun_t *, void **, size_t *);
|
|---|
| 98 | errno_t (*release_buffer)(ddf_fun_t *);
|
|---|
| 99 | errno_t (*set_event_session)(ddf_fun_t *, async_sess_t *);
|
|---|
| 100 | async_sess_t *(*get_event_session)(ddf_fun_t *);
|
|---|
| 101 | errno_t (*start_playback)(ddf_fun_t *, unsigned,
|
|---|
| 102 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 103 | errno_t (*stop_playback)(ddf_fun_t *, bool);
|
|---|
| 104 | errno_t (*start_capture)(ddf_fun_t *, unsigned,
|
|---|
| 105 | unsigned, unsigned, pcm_sample_format_t);
|
|---|
| 106 | errno_t (*stop_capture)(ddf_fun_t *, bool);
|
|---|
| 107 | } audio_pcm_iface_t;
|
|---|
| 108 |
|
|---|
| 109 | #endif
|
|---|
| 110 | /**
|
|---|
| 111 | * @}
|
|---|
| 112 | */
|
|---|