Index: ao_sun.c =================================================================== RCS file: /cvsroot/mplayer/main/libao2/ao_sun.c,v retrieving revision 1.35 diff -u -r1.35 ao_sun.c --- ao_sun.c 6 Jan 2005 22:56:54 -0000 1.35 +++ ao_sun.c 25 Jan 2006 20:11:06 -0000 @@ -66,6 +66,56 @@ extern int verbose; +#if defined(__OpenBSD__) +int sun_mixer_get_dev(int fd, int *dev, char *id) +{ + mixer_devinfo_t info; + + for (info.index = 0; ioctl(fd, AUDIO_MIXER_DEVINFO, &info) >= 0; + info.index++) { + if (!strcmp(id, info.label.name)) { + *dev = info.index; + return 0; + } + } + return -1; +} + +int sun_get_volume(int fd, int *l, int *r) +{ + mixer_ctrl_t mixer; + + if (sun_mixer_get_dev(fd, &mixer.dev, "master") < 0) + return -1; + + mixer.type = AUDIO_MIXER_VALUE; + mixer.un.value.num_channels = 2; + if (ioctl(fd, AUDIO_MIXER_READ, &mixer) < 0) + return -1; + *l = mixer.un.value.level[AUDIO_MIXER_LEVEL_LEFT]; + *r = mixer.un.value.level[AUDIO_MIXER_LEVEL_RIGHT]; + + return 0; +} + +int sun_set_volume(int fd, int l, int r) +{ + mixer_ctrl_t mixer; + + if (sun_mixer_get_dev(fd, &mixer.dev, "master") < 0) + return -1; + + mixer.type = AUDIO_MIXER_VALUE; + mixer.un.value.num_channels = 2; + mixer.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l; + mixer.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r; + + if (ioctl(fd, AUDIO_MIXER_WRITE, &mixer) < 0) + return -1; + + return 0; +} +#endif // convert an OSS audio format specification into a sun audio encoding static int af2sunfmt(int format) @@ -366,6 +416,13 @@ audio_dev = "/dev/audio"; } +#if defined(__OpenBSD__) + if (sun_mixer_device == NULL) { + if (mixer_device == NULL) + mixer_device = strdup("/dev/mixer"); + sun_mixer_device = mixer_device; + } +#else if (sun_mixer_device == NULL) { if ((sun_mixer_device = mixer_device) == NULL || !sun_mixer_device[0]) { sun_mixer_device = malloc(strlen(audio_dev) + 4); @@ -373,6 +430,7 @@ strcat(sun_mixer_device, "ctl"); } } +#endif if (ao_subdevice) audio_dev = ao_subdevice; } @@ -396,6 +454,14 @@ if ( fd != -1 ) { ao_control_vol_t *vol = (ao_control_vol_t *)arg; +#if defined(__OpenBSD__) + int r, l; + if (sun_get_volume(fd, &r, &l) < 0) { + close(fd); + goto cgerr; + } + vol->right = vol->left = (float)(r * 100. / AUDIO_MAX_GAIN); +#else float volume; struct audio_info info; ioctl( fd,AUDIO_GETINFO,&info); @@ -410,9 +476,11 @@ / AUDIO_MID_BALANCE; vol->right = volume; } +#endif close( fd ); return CONTROL_OK; - } + } +cgerr: return CONTROL_ERROR; } case AOCONTROL_SET_VOLUME: @@ -423,10 +491,18 @@ if ( !sun_mixer_device ) /* control function is used before init? */ setup_device_paths(); - fd=open( sun_mixer_device,O_RDONLY ); + fd=open( sun_mixer_device,O_RDWR ); if ( fd != -1 ) { struct audio_info info; +#if defined(__OpenBSD__) + int r; + r = (int)(vol->right * AUDIO_MAX_GAIN / 100); + if (sun_set_volume(fd, r, r) < 0) { + close(fd); + goto cserr; + } +#else float volume; AUDIO_INITINFO(&info); volume = vol->right > vol->left ? vol->right : vol->left; @@ -441,9 +517,11 @@ info.output_muted = (volume == 0); #endif ioctl( fd,AUDIO_SETINFO,&info ); +#endif close( fd ); return CONTROL_OK; - } + } +cserr: return CONTROL_ERROR; } }