1999-11-06 23:47:07 +00:00
|
|
|
/*
|
|
|
|
|
* PCM Interface - local header file
|
|
|
|
|
* Copyright (c) 1999 by Jaroslav Kysela <perex@suse.cz>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2000-06-04 16:24:04 +00:00
|
|
|
#include <assert.h>
|
1999-11-06 23:47:07 +00:00
|
|
|
#include "asoundlib.h"
|
|
|
|
|
|
2000-05-08 18:53:38 +00:00
|
|
|
struct snd_pcm_ops {
|
2000-05-27 16:52:17 +00:00
|
|
|
int (*stream_close)(snd_pcm_t *pcm, int stream);
|
|
|
|
|
int (*stream_nonblock)(snd_pcm_t *pcm, int stream, int nonblock);
|
2000-06-01 21:58:25 +00:00
|
|
|
int (*info)(snd_pcm_t *pcm, int stream, snd_pcm_info_t *info);
|
2000-05-27 16:52:17 +00:00
|
|
|
int (*stream_info)(snd_pcm_t *pcm, snd_pcm_stream_info_t *info);
|
|
|
|
|
int (*stream_params)(snd_pcm_t *pcm, snd_pcm_stream_params_t *params);
|
|
|
|
|
int (*stream_setup)(snd_pcm_t *pcm, snd_pcm_stream_setup_t *setup);
|
|
|
|
|
int (*channel_setup)(snd_pcm_t *pcm, int stream, snd_pcm_channel_setup_t *setup);
|
|
|
|
|
int (*stream_status)(snd_pcm_t *pcm, snd_pcm_stream_status_t *status);
|
|
|
|
|
int (*stream_prepare)(snd_pcm_t *pcm, int stream);
|
|
|
|
|
int (*stream_go)(snd_pcm_t *pcm, int stream);
|
2000-06-01 21:58:25 +00:00
|
|
|
int (*sync_go)(snd_pcm_t *pcm, int stream, snd_pcm_sync_t *sync);
|
2000-05-27 16:52:17 +00:00
|
|
|
int (*stream_drain)(snd_pcm_t *pcm, int stream);
|
|
|
|
|
int (*stream_flush)(snd_pcm_t *pcm, int stream);
|
|
|
|
|
int (*stream_pause)(snd_pcm_t *pcm, int stream, int enable);
|
2000-06-01 21:58:25 +00:00
|
|
|
int (*stream_state)(snd_pcm_t *pcm, int stream);
|
2000-06-10 12:39:51 +00:00
|
|
|
ssize_t (*stream_frame_io)(snd_pcm_t *pcm, int stream, int update);
|
|
|
|
|
ssize_t (*stream_frame_data)(snd_pcm_t *pcm, int stream, off_t offset);
|
2000-05-08 18:53:38 +00:00
|
|
|
ssize_t (*write)(snd_pcm_t *pcm, const void *buffer, size_t size);
|
|
|
|
|
ssize_t (*writev)(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count);
|
|
|
|
|
ssize_t (*read)(snd_pcm_t *pcm, void *buffer, size_t size);
|
|
|
|
|
ssize_t (*readv)(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count);
|
2000-06-10 12:39:51 +00:00
|
|
|
int (*mmap_status)(snd_pcm_t *pcm, int stream, snd_pcm_mmap_status_t **status);
|
|
|
|
|
int (*mmap_control)(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t **control);
|
2000-05-27 16:52:17 +00:00
|
|
|
int (*mmap_data)(snd_pcm_t *pcm, int stream, void **buffer, size_t bsize);
|
2000-06-10 12:39:51 +00:00
|
|
|
int (*munmap_status)(snd_pcm_t *pcm, int stream, snd_pcm_mmap_status_t *status);
|
|
|
|
|
int (*munmap_control)(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t *control);
|
2000-05-27 16:52:17 +00:00
|
|
|
int (*munmap_data)(snd_pcm_t *pcm, int stream, void *buffer, size_t bsize);
|
|
|
|
|
int (*file_descriptor)(snd_pcm_t* pcm, int stream);
|
|
|
|
|
int (*channels_mask)(snd_pcm_t *pcm, int stream, bitset_t *client_vmask);
|
2000-05-08 18:53:38 +00:00
|
|
|
};
|
|
|
|
|
|
2000-06-01 21:58:25 +00:00
|
|
|
typedef struct {
|
2000-04-17 17:31:41 +00:00
|
|
|
snd_pcm_plugin_t *first;
|
|
|
|
|
snd_pcm_plugin_t *last;
|
|
|
|
|
void *alloc_ptr[2];
|
2000-05-08 18:53:38 +00:00
|
|
|
size_t alloc_size[2];
|
2000-04-17 17:31:41 +00:00
|
|
|
int alloc_lock[2];
|
2000-06-01 21:58:25 +00:00
|
|
|
} snd_pcm_plug_stream_t;
|
2000-04-17 17:31:41 +00:00
|
|
|
|
2000-06-01 21:58:25 +00:00
|
|
|
typedef struct {
|
2000-05-08 18:53:38 +00:00
|
|
|
int close_slave;
|
|
|
|
|
snd_pcm_t *slave;
|
2000-06-01 21:58:25 +00:00
|
|
|
snd_pcm_plug_stream_t stream[2];
|
2000-05-08 18:53:38 +00:00
|
|
|
} snd_pcm_plug_t;
|
|
|
|
|
|
2000-06-01 21:58:25 +00:00
|
|
|
typedef struct {
|
2000-05-08 18:53:38 +00:00
|
|
|
int open;
|
|
|
|
|
int mode;
|
|
|
|
|
int valid_setup;
|
2000-05-27 16:52:17 +00:00
|
|
|
snd_pcm_stream_setup_t setup;
|
|
|
|
|
snd_pcm_channel_area_t *channels;
|
2000-06-10 12:39:51 +00:00
|
|
|
size_t bits_per_sample;
|
2000-05-24 21:35:55 +00:00
|
|
|
size_t bits_per_frame;
|
2000-06-10 12:39:51 +00:00
|
|
|
snd_pcm_mmap_status_t *mmap_status;
|
2000-04-17 17:31:41 +00:00
|
|
|
snd_pcm_mmap_control_t *mmap_control;
|
|
|
|
|
char *mmap_data;
|
2000-05-08 18:53:38 +00:00
|
|
|
size_t mmap_data_size;
|
2000-06-04 13:13:01 +00:00
|
|
|
enum { _INTERLEAVED, _NONINTERLEAVED, _COMPLEX } mmap_type;
|
2000-06-01 21:58:25 +00:00
|
|
|
} snd_pcm_stream_t;
|
2000-04-17 17:31:41 +00:00
|
|
|
|
1999-11-06 23:47:07 +00:00
|
|
|
struct snd_pcm {
|
2000-05-08 18:53:38 +00:00
|
|
|
snd_pcm_type_t type;
|
1999-11-06 23:47:07 +00:00
|
|
|
int mode;
|
2000-05-08 18:53:38 +00:00
|
|
|
struct snd_pcm_ops *ops;
|
2000-06-01 21:58:25 +00:00
|
|
|
snd_pcm_stream_t stream[2];
|
2000-05-08 18:53:38 +00:00
|
|
|
int private[0];
|
1999-11-06 23:47:07 +00:00
|
|
|
};
|
1999-12-11 11:46:05 +00:00
|
|
|
|
2000-05-08 18:53:38 +00:00
|
|
|
int snd_pcm_abstract_open(snd_pcm_t **handle, int mode, snd_pcm_type_t type, size_t extra);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int snd_pcm_plug_formats(unsigned int formats);
|
2000-05-27 16:52:17 +00:00
|
|
|
int snd_pcm_plug_slave_params(snd_pcm_stream_params_t *params,
|
|
|
|
|
snd_pcm_stream_info_t *slave_info,
|
|
|
|
|
snd_pcm_stream_params_t *slave_params);
|
2000-05-08 18:53:38 +00:00
|
|
|
int snd_pcm_plug_format(snd_pcm_plugin_handle_t *pcm,
|
2000-05-27 16:52:17 +00:00
|
|
|
snd_pcm_stream_params_t *params,
|
|
|
|
|
snd_pcm_stream_params_t *slave_params);
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2000-05-27 16:52:17 +00:00
|
|
|
ssize_t snd_pcm_plug_write_transfer(snd_pcm_plugin_handle_t *handle, snd_pcm_plugin_channel_t *src_channels, size_t size);
|
|
|
|
|
ssize_t snd_pcm_plug_read_transfer(snd_pcm_plugin_handle_t *handle, snd_pcm_plugin_channel_t *dst_channels_final, size_t size);
|
|
|
|
|
ssize_t snd_pcm_plug_client_channels_iovec(snd_pcm_plugin_handle_t *handle, int stream,
|
2000-05-08 18:53:38 +00:00
|
|
|
const struct iovec *vector, unsigned long count,
|
2000-05-27 16:52:17 +00:00
|
|
|
snd_pcm_plugin_channel_t **channels);
|
|
|
|
|
ssize_t snd_pcm_plug_client_channels_buf(snd_pcm_plugin_handle_t *handle, int stream,
|
2000-05-08 18:53:38 +00:00
|
|
|
char *buf, size_t count,
|
2000-05-27 16:52:17 +00:00
|
|
|
snd_pcm_plugin_channel_t **channels);
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2000-05-27 16:52:17 +00:00
|
|
|
int snd_pcm_plug_playback_channels_mask(snd_pcm_plugin_handle_t *handle,
|
2000-05-08 18:53:38 +00:00
|
|
|
bitset_t *client_vmask);
|
2000-05-27 16:52:17 +00:00
|
|
|
int snd_pcm_plug_capture_channels_mask(snd_pcm_plugin_handle_t *handle,
|
2000-05-08 18:53:38 +00:00
|
|
|
bitset_t *client_vmask);
|
2000-05-27 16:52:17 +00:00
|
|
|
int snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
|
2000-05-24 21:35:55 +00:00
|
|
|
size_t frames,
|
2000-05-27 16:52:17 +00:00
|
|
|
snd_pcm_plugin_channel_t **channels);
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2000-05-27 16:52:17 +00:00
|
|
|
void *snd_pcm_plug_buf_alloc(snd_pcm_t *pcm, int stream, size_t size);
|
|
|
|
|
void snd_pcm_plug_buf_unlock(snd_pcm_t *pcm, int stream, void *ptr);
|
1999-12-11 11:46:05 +00:00
|
|
|
|
2000-04-12 20:41:16 +00:00
|
|
|
#define ROUTE_PLUGIN_RESOLUTION 16
|
|
|
|
|
|
|
|
|
|
int getput_index(int format);
|
2000-05-08 18:53:38 +00:00
|
|
|
int conv_index(int src_format, int dst_format);
|
2000-04-12 20:41:16 +00:00
|
|
|
|
|
|
|
|
#ifdef PLUGIN_DEBUG
|
2000-05-08 18:53:38 +00:00
|
|
|
#define pdprintf( args... ) fprintf(stderr, "plugin: " ##args)
|
1999-12-11 11:46:05 +00:00
|
|
|
#else
|
|
|
|
|
#define pdprintf( args... ) { ; }
|
|
|
|
|
#endif
|
2000-06-01 21:58:25 +00:00
|
|
|
|
2000-06-10 12:39:51 +00:00
|
|
|
static inline size_t snd_pcm_mmap_playback_frames_avail(snd_pcm_stream_t *str)
|
2000-06-01 21:58:25 +00:00
|
|
|
{
|
2000-06-10 12:39:51 +00:00
|
|
|
ssize_t frames_avail;
|
|
|
|
|
frames_avail = str->mmap_status->frame_io + str->setup.buffer_size - str->mmap_control->frame_data;
|
|
|
|
|
if (frames_avail < 0)
|
|
|
|
|
frames_avail += str->setup.frame_boundary;
|
|
|
|
|
return frames_avail;
|
2000-06-01 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2000-06-10 12:39:51 +00:00
|
|
|
static inline size_t snd_pcm_mmap_capture_frames_avail(snd_pcm_stream_t *str)
|
2000-06-01 21:58:25 +00:00
|
|
|
{
|
2000-06-10 12:39:51 +00:00
|
|
|
ssize_t frames_avail;
|
|
|
|
|
frames_avail = str->mmap_status->frame_io - str->mmap_control->frame_data;
|
|
|
|
|
if (frames_avail < 0)
|
|
|
|
|
frames_avail += str->setup.frame_boundary;
|
|
|
|
|
return frames_avail;
|
2000-06-01 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
|