[xiph-commits] r17629 - in trunk/ao/src: . plugins/alsa plugins/oss plugins/pulse plugins/sndio plugins/sun
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Thu Nov 18 04:04:46 PST 2010
Author: xiphmont
Date: 2010-11-18 04:04:46 -0800 (Thu, 18 Nov 2010)
New Revision: 17629
Modified:
trunk/ao/src/ao_aixs.c
trunk/ao/src/ao_au.c
trunk/ao/src/ao_null.c
trunk/ao/src/ao_raw.c
trunk/ao/src/ao_wav.c
trunk/ao/src/ao_wmm.c
trunk/ao/src/plugins/alsa/ao_alsa.c
trunk/ao/src/plugins/oss/ao_oss.c
trunk/ao/src/plugins/pulse/ao_pulse.c
trunk/ao/src/plugins/sndio/ao_sndio.c
trunk/ao/src/plugins/sun/ao_sun.c
Log:
More cleanup in live driver tear-down (in the built-in drivers)
Add consistent 'dev' and 'id' options to each driver that allows
specification of a specific hardware output device. This allows
addressing device by number, as well as makes sure the named-device
option is available as 'dev' in each driver (PA used 'sink' and OSS used
'dsp'). The old names are kept as synonyms.
Modified: trunk/ao/src/ao_aixs.c
===================================================================
--- trunk/ao/src/ao_aixs.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_aixs.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -49,82 +49,87 @@
*/
#ifndef AO_AIX_DEFAULT_DEV
#define AO_AIX_DEFAULT_DEV "/dev/baud0/1"
+#define AO_AIX_DEFAULT_DEV2 "/dev/paud0/1"
+#define AO_AIX_DEFAULT_DEV3 "/dev/acpa0/1"
#endif
-static char *ao_aixs_options[] = {"dev","matrix","verbose","quiet","debug"};
+static char *ao_aixs_options[] = {"dev","id","matrix","verbose","quiet","debug"};
ao_info ao_aixs_info = {
- AO_TYPE_LIVE,
- "AIX audio driver output",
- "aixs",
- "Stefan Tibus <sjti at gmx.net>",
- "Outputs to the AIX audio system.",
- AO_FMT_NATIVE,
- 20,
- ao_aixs_options,
- 5
+ AO_TYPE_LIVE,
+ "AIX audio driver output",
+ "aixs",
+ "Stefan Tibus <sjti at gmx.net>",
+ "Outputs to the AIX audio system.",
+ AO_FMT_NATIVE,
+ 20,
+ ao_aixs_options,
+ 6
};
typedef struct ao_aixs_internal {
- char *dev;
- int fd;
+ char *dev;
+ int id;
+ int fd;
} ao_aixs_internal;
int ao_aixs_test()
{
- int fd;
+ int fd;
- if ( (fd = open(AO_AIX_DEFAULT_DEV, O_WRONLY)) < 0 )
- return 0; /* Cannot use this plugin with default parameters */
- else {
- close(fd);
- return 1; /* This plugin works in default mode */
- }
+ fd = open(AO_AIX_DEFAULT_DEV, O_WRONLY);
+ if(fd<0)
+ fd = open(AO_AIX_DEFAULT_DEV2, O_WRONLY);
+ if(fd<0)
+ fd = open(AO_AIX_DEFAULT_DEV3, O_WRONLY);
+ if(fd<0)
+ return 0; /* Cannot use this plugin with default parameters */
+
+ close(fd);
+ return 1; /* This plugin works in default mode */
}
ao_info *ao_aixs_driver_info(void)
{
- return &ao_aixs_info;
+ return &ao_aixs_info;
}
int ao_aixs_device_init(ao_device *device)
{
- ao_aixs_internal *internal;
+ ao_aixs_internal *internal;
- internal = (ao_aixs_internal *) malloc(sizeof(ao_aixs_internal));
+ internal = (ao_aixs_internal *) calloc(1,sizeof(ao_aixs_internal));
- if (internal == NULL)
- return 0; /* Could not initialize device memory */
+ if (internal == NULL)
+ return 0; /* Could not initialize device memory */
- internal->dev = strdup(AO_AIX_DEFAULT_DEV);
+ device->internal = internal;
+ device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
- if (internal->dev == NULL) {
- free(internal);
- return 0;
- }
-
- device->internal = internal;
- device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
-
- return 1; /* Memory alloc successful */
+ return 1; /* Memory alloc successful */
}
int ao_aixs_set_option(ao_device *device, const char *key, const char *value)
{
- ao_aixs_internal *internal = (ao_aixs_internal *) device->internal;
+ ao_aixs_internal *internal = (ao_aixs_internal *) device->internal;
+ if (!strcmp(key, "dev")) {
+ if(internal->dev)
+ free(internal->dev);
+ internal->dev = strdup(value);
+ }
+ if (!strcmp(key, "id")) {
+ internal->id = atoi(value);
+ if(internal->dev)
+ free(internal->dev);
+ internal->dev = NULL;
+ }
- if (!strcmp(key, "dev")) {
- /* Free old string in case "dsp" set twice in options */
- free(internal->dev);
- internal->dev = strdup(value);
- }
-
- return 1;
+ return 1;
}
@@ -136,9 +141,27 @@
audio_control control;
audio_change change;
- if ( (internal->fd = open(internal->dev, O_WRONLY)) < 0 )
- return 0;
+ if(!internal->dev){
+ char buffer[80];
+ int fd;
+ sprintf(buffer,"/dev/baud%d/1",id);
+ fd = open(buffer, O_WRONLY);
+ if(fd<0){
+ sprintf(buffer,"/dev/paud%d/1",id);
+ fd = open(buffer, O_WRONLY);
+ }
+ if(fd<0){
+ sprintf(buffer,"/dev/acpa%d/1",id);
+ fd = open(buffer, O_WRONLY);
+ }
+ if(fd<0) return 0;
+ internal->fd = fd;
+ internal->dev = strdup(buffer);
+ }else
+ if ( (internal->fd = open(internal->dev, O_WRONLY)) < 0 )
+ return 0;
+
init.srate = format->rate;
init.bits_per_sample = format->bits;
init.channels = device->output_channels;
@@ -202,8 +225,9 @@
{
ao_aixs_internal *internal = (ao_aixs_internal *) device->internal;
- close(internal->fd);
-
+ if(internal->fd)
+ close(internal->fd);
+ internal->fd=-1;
return 1;
}
@@ -212,8 +236,10 @@
{
ao_aixs_internal *internal = (ao_aixs_internal *) device->internal;
- free(internal->dev);
+ if(internal->dev)
+ free(internal->dev);
free(internal);
+ device->internal = NULL;
}
ao_functions ao_aixs = {
Modified: trunk/ao/src/ao_au.c
===================================================================
--- trunk/ao/src/ao_au.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_au.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -235,6 +235,7 @@
ao_au_internal *internal = (ao_au_internal *) device->internal;
free(internal);
+ device->internal=NULL;
}
ao_functions ao_au = {
Modified: trunk/ao/src/ao_null.c
===================================================================
--- trunk/ao/src/ao_null.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_null.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -134,6 +134,7 @@
ao_null_internal *internal = (ao_null_internal *) device->internal;
free(internal);
+ device->internal=NULL;
}
Modified: trunk/ao/src/ao_raw.c
===================================================================
--- trunk/ao/src/ao_raw.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_raw.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -144,6 +144,7 @@
ao_raw_internal *internal = (ao_raw_internal *) device->internal;
free(internal);
+ device->internal=NULL;
}
Modified: trunk/ao/src/ao_wav.c
===================================================================
--- trunk/ao/src/ao_wav.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_wav.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -275,6 +275,7 @@
ao_wav_internal *internal = (ao_wav_internal *) device->internal;
free(internal);
+ device->internal=NULL;
}
Modified: trunk/ao/src/ao_wmm.c
===================================================================
--- trunk/ao/src/ao_wmm.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/ao_wmm.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -627,7 +627,7 @@
free(internal->bigbuffer); internal->bigbuffer = NULL;
}
free(internal);
-
+ device->internal=NULL;
}
ao_functions ao_wmm = {
Modified: trunk/ao/src/plugins/alsa/ao_alsa.c
===================================================================
--- trunk/ao/src/plugins/alsa/ao_alsa.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/plugins/alsa/ao_alsa.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -65,6 +65,7 @@
static char *ao_alsa_options[] = {
"dev",
+ "id",
"buffer_time",
"period_time",
"use_mmap",
@@ -85,7 +86,7 @@
AO_FMT_NATIVE,
35,
ao_alsa_options,
- 8
+ 9
};
@@ -98,6 +99,7 @@
int sample_size;
snd_pcm_format_t bitformat;
char *dev;
+ int id;
ao_alsa_writei_t * writei;
snd_pcm_access_t access_mask;
} ao_alsa_internal;
@@ -143,6 +145,7 @@
internal->period_time = AO_ALSA_PERIOD_TIME;
internal->writei = AO_ALSA_WRITEI;
internal->access_mask = AO_ALSA_ACCESS_MASK;
+ internal->id=-1;
device->internal = internal;
device->output_matrix = strdup("L,R,BL,BR,C,LFE,SL,SR");
@@ -163,7 +166,12 @@
if (!(internal->dev = strdup(value)))
return 0;
}
- else if (!strcmp(key, "buffer_time"))
+ else if (!strcmp(key, "id")){
+ internal->id = atoi(value);
+ if (internal->dev)
+ free (internal->dev);
+ internal->dev = NULL;
+ }else if (!strcmp(key, "buffer_time"))
internal->buffer_time = atoi(value) * 1000;
else if (!strcmp(key, "period_time"))
internal->period_time = atoi(value);
@@ -412,6 +420,11 @@
device->output_channels=2;
}
}
+ if(!strcasecmp(dev,"default") || !strncasecmp(dev,"plug",4)){
+ if(format->bits>16){
+ awarn("ALSA '%s' device may only simulate >16 bit playback\n",dev);
+ }
+ }
/* try to set up hw params */
err = alsa_set_hwparams(device,format);
@@ -454,38 +467,45 @@
/* Open the ALSA device */
err=0;
if(!internal->dev){
- char *tmp=NULL;
- /* we don't try just 'default' as it's a plug device that
- will accept any number of channels but usually plays back
- everything as stereo. */
- switch(device->output_channels){
- default:
- case 8:
- case 7:
- err = alsa_test_open(device, tmp="surround71", format);
- break;
- case 4:
- case 3:
- err = alsa_test_open(device, tmp="surround40", format);
- if(err==0)break;
- case 6:
- case 5:
- err = alsa_test_open(device, tmp="surround51", format);
- case 1:
- case 2:
- break;
- }
+ if(internal->id<0){
+ char *tmp=NULL;
+ /* we don't try just 'default' as it's a plug device that
+ will accept any number of channels but usually plays back
+ everything as stereo. */
+ switch(device->output_channels){
+ default:
+ case 8:
+ case 7:
+ err = alsa_test_open(device, tmp="surround71", format);
+ break;
+ case 4:
+ case 3:
+ err = alsa_test_open(device, tmp="surround40", format);
+ if(err==0)break;
+ case 6:
+ case 5:
+ err = alsa_test_open(device, tmp="surround51", format);
+ break;
+ case 2:
+ err = alsa_test_open(device, tmp="front", format);
+ case 1:
+ break;
+ }
- if(err){
- awarn("Unable to open surround playback. Trying default device...\n");
- tmp=NULL;
- }
+ if(err){
+ awarn("Unable to open surround playback. Trying default device...\n");
+ tmp=NULL;
+ }
- if(!tmp)
- err = alsa_test_open(device, tmp="default", format);
+ if(!tmp)
+ err = alsa_test_open(device, tmp="default", format);
- internal->dev=strdup(tmp);
-
+ internal->dev=strdup(tmp);
+ }else{
+ char tmp[80];
+ sprintf(tmp,"hw:%d",internal->id);
+ internal->dev=strdup(tmp);
+ }
}else
err = alsa_test_open(device, internal->dev, format);
Modified: trunk/ao/src/plugins/oss/ao_oss.c
===================================================================
--- trunk/ao/src/plugins/oss/ao_oss.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/plugins/oss/ao_oss.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -45,7 +45,7 @@
#include "ao/plugin.h"
-static char *ao_oss_options[] = {"dsp","verbose","quiet","matrix","debug"};
+static char *ao_oss_options[] = {"dsp","dev","id","verbose","quiet","matrix","debug"};
static ao_info ao_oss_info =
{
AO_TYPE_LIVE,
@@ -56,12 +56,13 @@
AO_FMT_NATIVE,
20,
ao_oss_options,
- 5
+ 7
};
typedef struct ao_oss_internal {
char *dev;
+ int id;
int fd;
int buf_size;
} ao_oss_internal;
@@ -79,13 +80,20 @@
* blocking is non-zero, we remove the blocking flag if possible so
* that the device can be used for actual output.
*/
-int _open_default_oss_device (char **dev_path, int blocking)
+int _open_default_oss_device (char **dev_path, int id, int blocking)
{
int fd;
+ char buf[80];
/* default: first try the devfs path */
- if(!(*dev_path = strdup("/dev/sound/dsp")))
- return -1;
+ if(id>0){
+ sprintf(buf,"/dev/sound/dsp%d",id);
+ if(!(*dev_path = strdup(buf)))
+ return -1;
+ }else{
+ if(!(*dev_path = strdup("/dev/sound/dsp")))
+ return -1;
+ }
#ifdef BROKEN_OSS
fd = open(*dev_path, O_WRONLY | O_NONBLOCK);
@@ -98,8 +106,14 @@
{
/* no? then try the traditional path */
free(*dev_path);
- if(!(*dev_path = strdup("/dev/dsp")))
- return -1;
+ if(id>0){
+ sprintf(buf,"/dev/dsp%d",id);
+ if(!(*dev_path = strdup(buf)))
+ return -1;
+ }else{
+ if(!(*dev_path = strdup("/dev/dsp")))
+ return -1;
+ }
#ifdef BROKEN_OSS
fd = open(*dev_path, O_WRONLY | O_NONBLOCK);
#else
@@ -141,7 +155,7 @@
driver detection unless the O_NONBLOCK flag is passed to
open(). We cannot use this flag when we actually open the
device for writing because then we will overflow the buffer. */
- if ( (fd = _open_default_oss_device(&dev_path, 0)) < 0 )
+ if ( (fd = _open_default_oss_device(&dev_path, 0, 0)) < 0 )
return 0; /* Cannot use this plugin with default parameters */
else {
free(dev_path);
@@ -161,12 +175,13 @@
{
ao_oss_internal *internal;
- internal = (ao_oss_internal *) malloc(sizeof(ao_oss_internal));
+ internal = (ao_oss_internal *) calloc(1,sizeof(ao_oss_internal));
if (internal == NULL)
return 0; /* Could not initialize device memory */
internal->dev = NULL;
+ internal->id = -1;
device->internal = internal;
device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
@@ -179,12 +194,17 @@
ao_oss_internal *internal = (ao_oss_internal *) device->internal;
- if (!strcmp(key, "dsp")) {
- /* Free old string in case "dsp" set twice in options */
- free(internal->dev);
- if(!(internal->dev = strdup(value)))
- return 1;
+ if (!strcmp(key, "dsp") || !strcmp(key, "dev")) {
+ /* Free old string in case "dsp" set twice in options */
+ free(internal->dev);
+ if(!(internal->dev = strdup(value)))
+ return 0;
}
+ if (!strcmp(key, "id")) {
+ free(internal->dev);
+ internal->dev=NULL;
+ internal->id=atoi(value);
+ }
return 1;
}
@@ -201,21 +221,21 @@
/* Open the device driver */
if (internal->dev != NULL) {
- /* open the user-specified path */
- internal->fd = open(internal->dev, O_WRONLY);
+ /* open the user-specified path */
+ internal->fd = open(internal->dev, O_WRONLY);
- if(internal->fd < 0) {
- aerror("open(%s) => %s\n",internal->dev,strerror(errno));
- return 0; /* Cannot open device */
- }
+ if(internal->fd < 0) {
+ aerror("open(%s) => %s\n",internal->dev,strerror(errno));
+ return 0; /* Cannot open device */
+ }
- } else {
- internal->fd = _open_default_oss_device(&internal->dev, 1);
- if (internal->fd < 0){
- aerror("open default => %s\n",strerror(errno));
- return 0; /* Cannot open default device */
- }
- }
+ }else{
+ internal->fd = _open_default_oss_device(&internal->dev, internal->id, 1);
+ if (internal->fd < 0){
+ aerror("open default => %s\n",strerror(errno));
+ return 0; /* Cannot open default device */
+ }
+ }
/* Now set all of the parameters */
Modified: trunk/ao/src/plugins/pulse/ao_pulse.c
===================================================================
--- trunk/ao/src/plugins/pulse/ao_pulse.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/plugins/pulse/ao_pulse.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -44,6 +44,8 @@
static char * ao_pulse_options[] = {
"server",
"sink",
+ "dev",
+ "id",
"verbose",
"quiet",
"matrix",
@@ -59,7 +61,7 @@
AO_FMT_NATIVE,
50,
ao_pulse_options,
- 6
+ 8
};
typedef struct ao_pulse_internal {
@@ -157,7 +159,7 @@
if (!strcmp(key, "server")) {
free(internal->server);
internal->server = strdup(value);
- } else if (!strcmp(key, "sink")) {
+ } else if (!strcmp(key, "sink") || !strcmp(key, "dev") || !strcmp(key, "id")) {
free(internal->sink);
internal->sink = strdup(value);
} else
Modified: trunk/ao/src/plugins/sndio/ao_sndio.c
===================================================================
--- trunk/ao/src/plugins/sndio/ao_sndio.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/plugins/sndio/ao_sndio.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -17,12 +17,13 @@
#include <ao/ao.h>
#include <ao/plugin.h>
-static char * ao_sndio_options[] = {
+static char *ao_sndio_options[] = {
"verbose",
"quiet",
"matrix",
"debug",
- "dev"
+ "dev",
+ "id"
};
ao_info ao_sndio_info = {
@@ -34,13 +35,14 @@
AO_FMT_NATIVE,
30,
ao_sndio_options,
- 4
+ 6
};
typedef struct ao_sndio_internal
{
struct sio_hdl *hdl;
char *dev;
+ int id;
} ao_sndio_internal;
int ao_plugin_test()
@@ -63,6 +65,7 @@
{
ao_sndio_internal *internal;
internal = (ao_sndio_internal *) calloc(1,sizeof(*internal));
+ internal->id=-1;
device->internal = internal;
device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;
return 1;
@@ -82,6 +85,12 @@
return 0;
}
}
+ if (!strcmp(key, "id")) {
+ if(internal->dev)
+ free (internal->dev);
+ internal->dev=NULL;
+ internal->id=atoi(value);
+ }
return 1;
}
@@ -90,6 +99,12 @@
ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
struct sio_par par;
+ if(!internal->dev && internal->id>=0){
+ char buf[80];
+ sprintf(buf,"sun:%d",internal->id);
+ internal->dev = strdup(buf);
+ }
+
internal->hdl = sio_open(internal->dev, SIO_PLAY, 0);
if (internal->hdl == NULL)
return 0;
Modified: trunk/ao/src/plugins/sun/ao_sun.c
===================================================================
--- trunk/ao/src/plugins/sun/ao_sun.c 2010-11-18 10:38:54 UTC (rev 17628)
+++ trunk/ao/src/plugins/sun/ao_sun.c 2010-11-18 12:04:46 UTC (rev 17629)
@@ -60,7 +60,7 @@
#endif
-static char *ao_sun_options[] = {"dev","verbose","quiet","matrix","debug"};
+static char *ao_sun_options[] = {"dev","id","verbose","quiet","matrix","debug"};
ao_info ao_sun_info = {
AO_TYPE_LIVE,
"Sun audio driver output",
@@ -70,12 +70,13 @@
AO_FMT_NATIVE,
20,
ao_sun_options,
- 5
+ 6
};
typedef struct ao_sun_internal {
char *dev;
+ int id;
int fd;
} ao_sun_internal;
@@ -109,7 +110,7 @@
ao_sun_internal *internal;
char *dev = NULL;
- internal = (ao_sun_internal *) malloc(sizeof(ao_sun_internal));
+ internal = (ao_sun_internal *) calloc(1,sizeof(ao_sun_internal));
if (internal == NULL)
return 0; /* Could not initialize device memory */
@@ -140,6 +141,12 @@
free(internal->dev);
internal->dev = strdup(value);
}
+ if (!strcmp(key, "id")) {
+ /* Free old string in case "dsp" set twice in options */
+ free(internal->dev);
+ internal->dev = NULL;
+ internal->id=atoi(value);
+ }
return 1;
}
@@ -151,6 +158,12 @@
audio_info_t info;
+ if(internal->dev==NULL){
+ char buf[80];
+ sprintf(buf,"/dev/sound/%d",internal->id);
+ internal->dev=strdup(buf);
+ }
+
if ( (internal->fd = open(internal->dev, O_WRONLY)) < 0 )
return 0;
More information about the commits
mailing list