2001-10-24 14:06:36 +00:00
|
|
|
/*
|
|
|
|
ao_sgi - sgi/irix output plugin for MPlayer
|
|
|
|
|
|
|
|
22oct2001 oliver.schoenbrunner@jku.at
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dmedia/audio.h>
|
|
|
|
|
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
2004-09-18 20:31:28 +00:00
|
|
|
#include "../mp_msg.h"
|
|
|
|
#include "../help_mp.h"
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
static ao_info_t info =
|
|
|
|
{
|
|
|
|
"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;
|
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){
|
2001-10-24 14:06:36 +00:00
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_INFO);
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// open & setup audio device
|
|
|
|
// return: 1=success 0=fail
|
|
|
|
static int init(int rate, int channels, int format, int flags) {
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_InitInfo, rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
{ /* from /usr/share/src/dmedia/audio/setrate.c */
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
int rv;
|
|
|
|
double frate;
|
|
|
|
ALpv x[2];
|
|
|
|
|
|
|
|
rv = alGetResourceByName(AL_SYSTEM, "out.analog", AL_DEVICE_TYPE);
|
|
|
|
if (!rv) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InvalidDevice);
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
frate = rate;
|
2003-10-30 00:08:06 +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) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetParms_Samplerate, alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x[0].sizeOut < 0) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetAlRate);
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (alGetParams(rv,x, 1)<0) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantGetParms, alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (frate != alFixedToDouble(x[0].value.ll)) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_SampleRateInfo, alFixedToDouble(x[0].value.ll), frate);
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
2003-10-30 00:08:06 +00:00
|
|
|
sample_rate = (int)frate;
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
ao_data.buffersize=131072;
|
|
|
|
ao_data.outburst = ao_data.buffersize/16;
|
|
|
|
ao_data.channels = channels;
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
ao_config = alNewConfig();
|
|
|
|
|
|
|
|
if (!ao_config) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(channels == 2) alSetChannels(ao_config, AL_STEREO);
|
|
|
|
else alSetChannels(ao_config, AL_MONO);
|
|
|
|
|
|
|
|
alSetWidth(ao_config, AL_SAMPLE_16);
|
|
|
|
alSetSampFmt(ao_config, AL_SAMPFMT_TWOSCOMP);
|
|
|
|
alSetQueueSize(ao_config, 48000);
|
|
|
|
|
|
|
|
if (alSetDevice(ao_config, AL_DEFAULT_OUTPUT) < 0) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ao_port = alOpenPort("mplayer", "w", ao_config);
|
|
|
|
|
|
|
|
if (!ao_port) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitOpenAudioFailed, alGetErrorString(oserror()));
|
2001-10-24 14:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2001-10-24 14:06:36 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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! */
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Uninit);
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
if (ao_port) {
|
|
|
|
while(alGetFilled(ao_port) > 0) sginap(1);
|
|
|
|
alClosePort(ao_port);
|
|
|
|
alFreeConfig(ao_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing and empty buffers (for seeking/pause)
|
|
|
|
static void reset() {
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_Reset);
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing, keep buffers (for pause)
|
|
|
|
static void audio_pause() {
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_PauseInfo);
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// resume playing, after audio_pause()
|
|
|
|
static void audio_resume() {
|
|
|
|
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_ResumeInfo);
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// return: how many bytes can be played without blocking
|
|
|
|
static int get_space() {
|
|
|
|
|
|
|
|
// printf("ao_sgi, get_space: (ao_outburst %d)\n", ao_outburst);
|
|
|
|
// printf("ao_sgi, get_space: alGetFillable [%d] \n", alGetFillable(ao_port));
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
return alGetFillable(ao_port)*(2*ao_data.channels);
|
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) {
|
|
|
|
|
|
|
|
// printf("ao_sgi, play: len %d flags %d (%d %d)\n", len, flags, ao_port, ao_config);
|
|
|
|
// printf("channels %d\n", ao_channels);
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
alWriteFrames(ao_port, data, len/(2*ao_data.channels));
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
return len;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
// return: delay in seconds between first and last sample in buffer
|
|
|
|
static float get_delay(){
|
2001-10-24 14:06:36 +00:00
|
|
|
|
|
|
|
// printf("ao_sgi, get_delay: (ao_buffersize %d)\n", ao_buffersize);
|
|
|
|
|
2003-10-30 00:08:06 +00:00
|
|
|
//return 0;
|
|
|
|
return (float)queue_size/((float)sample_rate);
|
2001-10-24 14:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|