mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Added the support for the hardware depedent interface.
This commit is contained in:
parent
c569de6883
commit
a6aee7bee0
6 changed files with 186 additions and 19 deletions
|
|
@ -31,6 +31,6 @@ SAVE_LIBRARY_VERSION
|
|||
AC_OUTPUT(Makefile doc/Makefile include/Makefile src/Makefile \
|
||||
src/control/Makefile src/mixer/Makefile src/pcm/Makefile \
|
||||
src/pcm/plugin/Makefile src/rawmidi/Makefile src/timer/Makefile \
|
||||
src/seq/Makefile src/instr/Makefile \
|
||||
src/hwdep/Makefile src/seq/Makefile src/instr/Makefile \
|
||||
test/Makefile utils/Makefile \
|
||||
utils/alsa-lib.spec)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ sysinclude_HEADERS = asoundlib.h
|
|||
# This is the order they will be concatenated into asoundlib.h!
|
||||
#
|
||||
header_files=header.h version.h error.h control.h mixer.h pcm.h rawmidi.h \
|
||||
timer.h seq.h seqmid.h conv.h instr.h footer.h
|
||||
timer.h hwdep.h seq.h seqmid.h conv.h instr.h footer.h
|
||||
|
||||
noinst_HEADERS=$(header_files)
|
||||
|
||||
|
|
|
|||
30
include/hwdep.h
Normal file
30
include/hwdep.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/****************************************************************************
|
||||
* *
|
||||
* hwdep.h *
|
||||
* Hardware depedent interface *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#define SND_HWDEP_OPEN_READ (O_RDONLY)
|
||||
#define SND_HWDEP_OPEN_WRITE (O_WRONLY)
|
||||
#define SND_HWDEP_OPEN_DUPLEX (O_RDWR)
|
||||
#define SND_HWDEP_OPEN_NONBLOCK (O_NONBLOCK)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct snd_hwdep snd_hwdep_t;
|
||||
|
||||
int snd_hwdep_open(snd_hwdep_t **handle, int card, int device, int mode);
|
||||
int snd_hwdep_close(snd_hwdep_t *handle);
|
||||
int snd_hwdep_file_descriptor(snd_hwdep_t *handle);
|
||||
int snd_hwdep_block_mode(snd_hwdep_t *handle, int enable);
|
||||
int snd_hwdep_info(snd_hwdep_t *handle, snd_hwdep_info_t * info);
|
||||
ssize_t snd_hwdep_write(snd_hwdep_t *handle, const void *buffer, size_t size);
|
||||
ssize_t snd_hwdep_read(snd_hwdep_t *handle, void *buffer, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,24 +1,10 @@
|
|||
SUBDIRS=control mixer pcm rawmidi timer seq instr
|
||||
SUBDIRS=control mixer pcm rawmidi timer hwdep seq instr
|
||||
|
||||
lib_LTLIBRARIES = libasound.la
|
||||
libasound_la_SOURCES = error.c
|
||||
libasound_la_LIBADD = control/libcontrol.la mixer/libmixer.la pcm/libpcm.la \
|
||||
rawmidi/librawmidi.la timer/libtimer.la seq/libseq.la \
|
||||
instr/libinstr.la
|
||||
rawmidi/librawmidi.la timer/libtimer.la hwdep/libhwdep.la \
|
||||
seq/libseq.la instr/libinstr.la
|
||||
libasound_la_LDFLAGS = -release 0.5 -version-info 5:0:5
|
||||
|
||||
control/libcontrol.la:
|
||||
$(MAKE) -C control libcontrol.la
|
||||
|
||||
mixer/libmixer.la:
|
||||
$(MAKE) -C mixer libmixer.la
|
||||
|
||||
pcm/libpcm.la:
|
||||
$(MAKE) -C pcm libpcm.la
|
||||
|
||||
rawmidi/librawmidi.la:
|
||||
$(MAKE) -C rawmidi librawmidi.la
|
||||
|
||||
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include
|
||||
|
|
|
|||
7
src/hwdep/Makefile.am
Normal file
7
src/hwdep/Makefile.am
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
EXTRA_LTLIBRARIES=libhwdep.la
|
||||
|
||||
libhwdep_la_SOURCES = hwdep.c
|
||||
all: libhwdep.la
|
||||
|
||||
|
||||
INCLUDES=-I$(top_srcdir)/include
|
||||
144
src/hwdep/hwdep.c
Normal file
144
src/hwdep/hwdep.c
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Hardware dependent Interface - main file
|
||||
* Copyright (c) 2000 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "asoundlib.h"
|
||||
|
||||
#define SND_FILE_HWDEP "/dev/snd/hwdepC%iD%i"
|
||||
#define SND_HWDEP_VERSION_MAX SND_PROTOCOL_VERSION(1, 0, 0)
|
||||
|
||||
struct snd_hwdep {
|
||||
int card;
|
||||
int device;
|
||||
int fd;
|
||||
int mode;
|
||||
};
|
||||
|
||||
int snd_hwdep_open(snd_hwdep_t **handle, int card, int device, int mode)
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
snd_hwdep_t *hwdep;
|
||||
|
||||
*handle = NULL;
|
||||
|
||||
if (card < 0 || card >= SND_CARDS)
|
||||
return -EINVAL;
|
||||
sprintf(filename, SND_FILE_HWDEP, card, device);
|
||||
if ((fd = open(filename, mode)) < 0) {
|
||||
snd_card_load(card);
|
||||
if ((fd = open(filename, mode)) < 0)
|
||||
return -errno;
|
||||
}
|
||||
if (ioctl(fd, SND_HWDEP_IOCTL_PVERSION, &ver) < 0) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
if (SND_PROTOCOL_INCOMPATIBLE(ver, SND_HWDEP_VERSION_MAX)) {
|
||||
close(fd);
|
||||
return -SND_ERROR_INCOMPATIBLE_VERSION;
|
||||
}
|
||||
hwdep = (snd_hwdep_t *) calloc(1, sizeof(snd_hwdep_t));
|
||||
if (hwdep == NULL) {
|
||||
close(fd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
hwdep->card = card;
|
||||
hwdep->device = device;
|
||||
hwdep->fd = fd;
|
||||
hwdep->mode = mode;
|
||||
*handle = hwdep;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_hwdep_close(snd_hwdep_t *hwdep)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (!hwdep)
|
||||
return -EINVAL;
|
||||
res = close(hwdep->fd) < 0 ? -errno : 0;
|
||||
free(hwdep);
|
||||
return res;
|
||||
}
|
||||
|
||||
int snd_hwdep_file_descriptor(snd_hwdep_t *hwdep)
|
||||
{
|
||||
if (!hwdep)
|
||||
return -EINVAL;
|
||||
return hwdep->fd;
|
||||
}
|
||||
|
||||
int snd_hwdep_block_mode(snd_hwdep_t *hwdep, int enable)
|
||||
{
|
||||
long flags;
|
||||
|
||||
if (!hwdep)
|
||||
return -EINVAL;
|
||||
if ((flags = fcntl(hwdep->fd, F_GETFL)) < 0)
|
||||
return -errno;
|
||||
if (enable)
|
||||
flags &= ~O_NONBLOCK;
|
||||
else
|
||||
flags |= O_NONBLOCK;
|
||||
if (fcntl(hwdep->fd, F_SETFL, flags) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t * info)
|
||||
{
|
||||
if (!hwdep || !info)
|
||||
return -EINVAL;
|
||||
if (ioctl(hwdep->fd, SND_HWDEP_IOCTL_INFO, info) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
if (!hwdep || (!buffer && size > 0) || size < 0)
|
||||
return -EINVAL;
|
||||
result = write(hwdep->fd, buffer, size);
|
||||
if (result < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
|
||||
ssize_t snd_hwdep_read(snd_hwdep_t *hwdep, void *buffer, size_t size)
|
||||
{
|
||||
ssize_t result;
|
||||
|
||||
if (!hwdep || (!buffer && size > 0) || size < 0)
|
||||
return -EINVAL;
|
||||
result = read(hwdep->fd, buffer, size);
|
||||
if (result < 0)
|
||||
return -errno;
|
||||
return result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue