2001-10-24 14:06:36 +00:00
|
|
|
/*
|
2009-01-26 15:06:44 +00:00
|
|
|
* SGI/IRIX audio output driver
|
|
|
|
*
|
|
|
|
* copyright (c) 2001 oliver.schoenbrunner@jku.at
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2005-10-04 22:23:51 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2001-10-24 14:06:36 +00:00
|
|
|
#include <dmedia/audio.h>
|
|
|
|
|
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "mp_msg.h"
|
2005-10-04 22:23:51 +00:00
|
|
|
#include "libaf/af_format.h"
|
2001-10-24 14:06:36 +00:00
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
static const ao_info_t info =
|
2001-10-24 14:06:36 +00:00
|
|
|
{
|
|
|
|
"sgi audio output",
|
|
|
|
"sgi",
|
2004-10-04 19:07:09 +00:00
|
|
|
"Oliver Schoenbrunner",
|
2001-10-24 14:06:36 +00:00
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAO_EXTERN(sgi)
|
|
|
|
|
|
|
|
|
|
|
|
static ALconfig ao_config;
|
|
|
|
static ALport ao_port;
|
2003-10-30 00:08:06 +00:00
|
|
|
static int sample_rate;
|
|
|
|
static int queue_size;
|
2005-10-04 22:23:51 +00:00
|
|
|
static int bytes_per_frame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param [in/out] format
|
|
|
|
* \param [out] width
|
|
|
|
*
|
|
|
|
* \return the closest matching SGI AL sample format
|
|
|
|
*
|
|
|
|
* \note width is set to required per-channel sample width
|
|
|
|
* format is updated to match the SGI AL sample format
|
|
|
|
*/
|
|
|
|
static int fmt2sgial(int *format, int *width) {
|
|
|
|
int smpfmt = AL_SAMPFMT_TWOSCOMP;
|
|
|
|
|
|
|
|
/* SGI AL only supports float and signed integers in native
|
2007-09-25 16:34:23 +00:00
|
|
|
* endianness. If this is something else, we must rely on the audio
|
2005-10-04 22:23:51 +00:00
|
|
|
* filter to convert it to a compatible format. */
|
|
|
|
|
|
|
|
/* 24-bit audio is supported, but only with 32-bit alignment.
|
|
|
|
* mplayer's 24-bit format is packed, unfortunately.
|
|
|
|
* So we must upgrade 24-bit requests to 32 bits. Then we drop the
|
|
|
|
* lowest 8 bits during playback. */
|
|
|
|
|
|
|
|
switch(*format) {
|
|
|
|
case AF_FORMAT_U8:
|
|
|
|
case AF_FORMAT_S8:
|
|
|
|
*width = AL_SAMPLE_8;
|
|
|
|
*format = AF_FORMAT_S8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_U16_LE:
|
|
|
|
case AF_FORMAT_U16_BE:
|
|
|
|
case AF_FORMAT_S16_LE:
|
|
|
|
case AF_FORMAT_S16_BE:
|
|
|
|
*width = AL_SAMPLE_16;
|
|
|
|
*format = AF_FORMAT_S16_NE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_U24_LE:
|
|
|
|
case AF_FORMAT_U24_BE:
|
|
|
|
case AF_FORMAT_S24_LE:
|
|
|
|
case AF_FORMAT_S24_BE:
|
|
|
|
case AF_FORMAT_U32_LE:
|
|
|
|
case AF_FORMAT_U32_BE:
|
|
|
|
case AF_FORMAT_S32_LE:
|
|
|
|
case AF_FORMAT_S32_BE:
|
|
|
|
*width = AL_SAMPLE_24;
|
|
|
|
*format = AF_FORMAT_S32_NE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_FORMAT_FLOAT_LE:
|
|
|
|
case AF_FORMAT_FLOAT_BE:
|
|
|
|
*width = 4;
|
|
|
|
*format = AF_FORMAT_FLOAT_NE;
|
|
|
|
smpfmt = AL_SAMPFMT_FLOAT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*width = AL_SAMPLE_16;
|
|
|
|
*format = AF_FORMAT_S16_NE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return smpfmt;
|
|
|
|
}
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
// to set/get/query special features/parameters
|
2003-03-21 16:42:50 +00:00
|
|
|
static int control(int cmd, void *arg){
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] control.\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
switch(cmd) {
|
|
|
|
case AOCONTROL_QUERY_FORMAT:
|
|
|
|
/* Do not reject any format: return the closest matching
|
|
|
|
* format if the request is not supported natively. */
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CONTROL_UNKNOWN;
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// open & setup audio device
|
|
|
|
// return: 1=success 0=fail
|
|
|
|
static int init(int rate, int channels, int format, int flags) {
|
2004-12-27 18:10:30 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
int smpwidth, smpfmt;
|
|
|
|
int rv = AL_DEFAULT_OUTPUT;
|
|
|
|
|
|
|
|
smpfmt = fmt2sgial(&format, &smpwidth);
|
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
{ /* from /usr/share/src/dmedia/audio/setrate.c */
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
double frate, realrate;
|
2001-10-24 14:06:36 +00:00
|
|
|
ALpv x[2];
|
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
if(ao_subdevice) {
|
|
|
|
rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
|
|
|
|
if (!rv) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] play: invalid device.\n");
|
2005-10-04 22:23:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
frate = rate;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
x[0].param = AL_RATE;
|
|
|
|
x[0].value.ll = alDoubleToFixed(rate);
|
|
|
|
x[1].param = AL_MASTER_CLOCK;
|
|
|
|
x[1].value.i = AL_CRYSTAL_MCLK_TYPE;
|
|
|
|
|
|
|
|
if (alSetParams(rv,x, 2)<0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n", alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
if (x[0].sizeOut < 0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: AL_RATE was not accepted on the given resource.\n");
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (alGetParams(rv,x, 1)<0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: getparams failed: %s\n", alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
realrate = alFixedToDouble(x[0].value.ll);
|
|
|
|
if (frate != realrate) {
|
2009-12-15 13:27:30 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: samplerate is now %f (desired rate is %f)\n", realrate, frate);
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2005-10-04 22:23:51 +00:00
|
|
|
sample_rate = (int)realrate;
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
bytes_per_frame = channels * smpwidth;
|
|
|
|
|
|
|
|
ao_data.samplerate = sample_rate;
|
|
|
|
ao_data.channels = channels;
|
|
|
|
ao_data.format = format;
|
|
|
|
ao_data.bps = sample_rate * bytes_per_frame;
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.buffersize=131072;
|
|
|
|
ao_data.outburst = ao_data.buffersize/16;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
ao_config = alNewConfig();
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
if (!ao_config) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
if(alSetChannels(ao_config, channels) < 0 ||
|
|
|
|
alSetWidth(ao_config, smpwidth) < 0 ||
|
|
|
|
alSetSampFmt(ao_config, smpfmt) < 0 ||
|
|
|
|
alSetQueueSize(ao_config, sample_rate) < 0 ||
|
|
|
|
alSetDevice(ao_config, rv) < 0) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
ao_port = alOpenPort("mplayer", "w", ao_config);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
if (!ao_port) {
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: Unable to open audio channel: %s\n", alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
// printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
|
2003-10-30 00:08:06 +00:00
|
|
|
queue_size = alGetQueueSize(ao_config);
|
2009-07-06 23:26:13 +00:00
|
|
|
return 1;
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// close audio device
|
2004-04-06 17:55:36 +00:00
|
|
|
static void uninit(int immed) {
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
/* TODO: samplerate should be set back to the value before mplayer was started! */
|
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] uninit: ...\n");
|
2001-10-24 14:06:36 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
if (ao_config) {
|
|
|
|
alFreeConfig(ao_config);
|
|
|
|
ao_config = NULL;
|
|
|
|
}
|
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
if (ao_port) {
|
2005-02-27 23:06:32 +00:00
|
|
|
if (!immed)
|
2009-07-06 23:26:13 +00:00
|
|
|
while(alGetFilled(ao_port) > 0) sginap(1);
|
2001-10-24 14:06:36 +00:00
|
|
|
alClosePort(ao_port);
|
2005-10-04 22:23:51 +00:00
|
|
|
ao_port = NULL;
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing and empty buffers (for seeking/pause)
|
2006-07-06 04:30:19 +00:00
|
|
|
static void reset(void) {
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] reset: ...\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
alDiscardFrames(ao_port, queue_size);
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing, keep buffers (for pause)
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_pause(void) {
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] audio_pause: ...\n");
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resume playing, after audio_pause()
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_resume(void) {
|
2001-10-24 14:06:36 +00:00
|
|
|
|
2009-07-06 22:15:02 +00:00
|
|
|
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] audio_resume: ...\n");
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// return: how many bytes can be played without blocking
|
2006-07-06 04:30:19 +00:00
|
|
|
static int get_space(void) {
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
// printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_data.outburst);
|
2001-10-24 14:06:36 +00:00
|
|
|
// printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port));
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
return alGetFillable(ao_port) * bytes_per_frame;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// plays 'len' bytes of 'data'
|
|
|
|
// it should round it down to outburst*n
|
|
|
|
// return: number of bytes played
|
|
|
|
static int play(void* data, int len, int flags) {
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
/* Always process data in quadword-aligned chunks (64-bits). */
|
|
|
|
const int plen = len / (sizeof(uint64_t) * bytes_per_frame);
|
|
|
|
const int framecount = plen * sizeof(uint64_t);
|
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
// printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config);
|
2005-10-04 22:23:51 +00:00
|
|
|
// printf("channels %d\n", ao_data.channels);
|
|
|
|
|
|
|
|
if(ao_data.format == AF_FORMAT_S32_NE) {
|
|
|
|
/* The zen of this is explained in fmt2sgial() */
|
|
|
|
int32_t *smpls = data;
|
|
|
|
const int32_t *smple = smpls + (framecount * ao_data.channels);
|
|
|
|
while(smpls < smple)
|
|
|
|
*smpls++ >>= 8;
|
|
|
|
}
|
2001-10-24 14:06:36 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
alWriteFrames(ao_port, data, framecount);
|
|
|
|
|
|
|
|
return framecount * bytes_per_frame;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
// return: delay in seconds between first and last sample in buffer
|
2006-07-06 04:30:19 +00:00
|
|
|
static float get_delay(void){
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2001-10-24 14:06:36 +00:00
|
|
|
// printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-10-04 22:23:51 +00:00
|
|
|
// return (float)queue_size/((float)sample_rate);
|
|
|
|
const int outstanding = alGetFilled(ao_port);
|
|
|
|
return (float)((outstanding < 0) ? queue_size : outstanding) /
|
|
|
|
((float)sample_rate);
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|