2002-05-13 19:57:27 +00:00
|
|
|
#include <math.h>
|
2002-05-13 13:15:40 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <inttypes.h>
|
2002-05-13 19:57:27 +00:00
|
|
|
#include <dxr2ioctl.h>
|
2004-12-07 02:24:15 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
2006-11-29 15:02:45 +00:00
|
|
|
#include "libavutil/common.h"
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2002-05-13 13:15:40 +00:00
|
|
|
|
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
2004-12-27 17:30:15 +00:00
|
|
|
#include "libaf/af_format.h"
|
2006-07-22 10:39:00 +00:00
|
|
|
#include "libmpdemux/mpeg_packetizer.h"
|
2002-05-13 13:15:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
static ao_info_t info =
|
|
|
|
{
|
|
|
|
"DXR2 audio output",
|
|
|
|
"dxr2",
|
2005-06-19 09:17:44 +00:00
|
|
|
"Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
|
2002-05-13 13:15:40 +00:00
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAO_EXTERN(dxr2)
|
|
|
|
|
2002-05-13 19:57:27 +00:00
|
|
|
static int volume=19;
|
2006-07-23 10:10:06 +00:00
|
|
|
static int last_freq_id = -1;
|
2002-05-13 19:57:27 +00:00
|
|
|
extern int dxr2_fd;
|
|
|
|
|
2002-05-13 13:15:40 +00:00
|
|
|
// to set/get/query special features/parameters
|
2003-03-21 16:42:50 +00:00
|
|
|
static int control(int cmd,void *arg){
|
2002-05-13 19:57:27 +00:00
|
|
|
switch(cmd){
|
|
|
|
case AOCONTROL_GET_VOLUME:
|
|
|
|
if(dxr2_fd > 0) {
|
|
|
|
ao_control_vol_t* vol = (ao_control_vol_t*)arg;
|
|
|
|
vol->left = vol->right = volume * 19.0 / 100.0;
|
|
|
|
return CONTROL_OK;
|
|
|
|
}
|
|
|
|
return CONTROL_ERROR;
|
|
|
|
case AOCONTROL_SET_VOLUME:
|
|
|
|
if(dxr2_fd > 0) {
|
|
|
|
dxr2_oneArg_t v;
|
|
|
|
float diff;
|
|
|
|
ao_control_vol_t* vol = (ao_control_vol_t*)arg;
|
|
|
|
// We need this trick because the volume stepping is often too small
|
|
|
|
diff = ((vol->left+vol->right) / 2 - (volume*19.0/100.0)) * 19.0 / 100.0;
|
|
|
|
v.arg = volume + (diff > 0 ? ceil(diff) : floor(diff));
|
|
|
|
if(v.arg > 19) v.arg = 19;
|
|
|
|
if(v.arg < 0) v.arg = 0;
|
|
|
|
if(v.arg != volume) {
|
|
|
|
volume = v.arg;
|
|
|
|
if( ioctl(dxr2_fd,DXR2_IOC_SET_AUDIO_VOLUME,&v) < 0) {
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_DXR2_SetVolFailed,volume);
|
2002-05-13 19:57:27 +00:00
|
|
|
return CONTROL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CONTROL_OK;
|
|
|
|
}
|
|
|
|
return CONTROL_ERROR;
|
|
|
|
}
|
2002-05-13 13:15:40 +00:00
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int freq=0;
|
|
|
|
static int freq_id=0;
|
|
|
|
|
|
|
|
// open & setup audio device
|
|
|
|
// return: 1=success 0=fail
|
|
|
|
static int init(int rate,int channels,int format,int flags){
|
|
|
|
|
2002-05-17 23:51:37 +00:00
|
|
|
if(dxr2_fd <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2006-07-23 10:10:06 +00:00
|
|
|
last_freq_id = -1;
|
|
|
|
|
2002-05-13 13:15:40 +00:00
|
|
|
ao_data.outburst=2048;
|
|
|
|
ao_data.samplerate=rate;
|
|
|
|
ao_data.channels=channels;
|
|
|
|
ao_data.buffersize=2048;
|
|
|
|
ao_data.bps=rate*4;
|
|
|
|
ao_data.format=format;
|
|
|
|
freq=rate;
|
|
|
|
|
|
|
|
switch(rate){
|
|
|
|
case 48000:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_48;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 96000:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_96;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 44100:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_441;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 32000:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_32;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 22050:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_2205;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
2002-05-13 19:57:27 +00:00
|
|
|
#ifdef DXR2_AUDIO_FREQ_24
|
|
|
|
// This is not yet in the dxr2 driver CVS
|
|
|
|
// you can get the patch at
|
2005-11-29 19:53:05 +00:00
|
|
|
// http://www.tdiedrich.de/~ranma/patches/dxr2.pcm1723.20020513
|
2002-05-13 13:15:40 +00:00
|
|
|
case 24000:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_24;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 64000:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_64;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
case 88200:
|
2002-05-13 19:57:27 +00:00
|
|
|
freq_id=DXR2_AUDIO_FREQ_882;
|
2002-05-13 13:15:40 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2004-09-18 20:31:28 +00:00
|
|
|
mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_DXR2_UnsupSamplerate,rate);
|
2002-05-13 13:15:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// close audio device
|
2004-04-06 17:55:36 +00:00
|
|
|
static void uninit(int immed){
|
2002-05-13 13:15:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing and empty buffers (for seeking/pause)
|
2006-07-06 04:30:19 +00:00
|
|
|
static void reset(void){
|
2002-05-13 13:15:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing, keep buffers (for pause)
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_pause(void)
|
2002-05-13 13:15:40 +00:00
|
|
|
{
|
|
|
|
// for now, just call reset();
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// resume playing, after audio_pause()
|
2006-07-06 04:30:19 +00:00
|
|
|
static void audio_resume(void)
|
2002-05-13 13:15:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int vo_pts;
|
|
|
|
// return: how many bytes can be played without blocking
|
2006-07-06 04:30:19 +00:00
|
|
|
static int get_space(void){
|
2002-05-13 13:15:40 +00:00
|
|
|
float x=(float)(vo_pts-ao_data.pts)/90000.0;
|
|
|
|
int y;
|
|
|
|
if(x<=0) return 0;
|
|
|
|
y=freq*4*x;y/=ao_data.outburst;y*=ao_data.outburst;
|
|
|
|
if(y>32768) y=32768;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2006-07-23 10:10:06 +00:00
|
|
|
static void dxr2_send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id)
|
|
|
|
{
|
2008-01-12 16:05:04 +00:00
|
|
|
extern int write_dxr2(const unsigned char *data, int len);
|
2006-07-23 10:10:06 +00:00
|
|
|
|
|
|
|
if(dxr2_fd < 0) {
|
|
|
|
mp_msg(MSGT_AO,MSGL_ERR,"DXR2 fd is not valid\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(last_freq_id != freq_id) {
|
|
|
|
ioctl(dxr2_fd, DXR2_IOC_SET_AUDIO_SAMPLE_FREQUENCY, &freq_id);
|
|
|
|
last_freq_id = freq_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_mpeg_lpcm_packet (data, len, id, timestamp, freq_id, write_dxr2);
|
|
|
|
}
|
|
|
|
|
2002-05-13 13:15:40 +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){
|
2008-01-12 16:05:04 +00:00
|
|
|
extern int write_dxr2(const unsigned char *data, int len);
|
2006-07-22 10:39:00 +00:00
|
|
|
|
2002-05-13 13:15:40 +00:00
|
|
|
// MPEG and AC3 don't work :-(
|
2004-12-27 17:30:15 +00:00
|
|
|
if(ao_data.format==AF_FORMAT_MPEG2)
|
2006-07-22 10:39:00 +00:00
|
|
|
send_mpeg_ps_packet (data, len, 0xC0, ao_data.pts, 2, write_dxr2);
|
2004-12-27 17:30:15 +00:00
|
|
|
else if(ao_data.format==AF_FORMAT_AC3)
|
2006-07-22 10:39:00 +00:00
|
|
|
send_mpeg_ps_packet (data, len, 0x80, ao_data.pts, 2, write_dxr2);
|
2002-05-13 13:15:40 +00:00
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
//unsigned short *s=data;
|
|
|
|
uint16_t *s=data;
|
|
|
|
#ifndef WORDS_BIGENDIAN
|
2002-05-13 19:57:27 +00:00
|
|
|
for(i=0;i<len/2;i++) s[i] = bswap_16(s[i]);
|
2002-05-13 13:15:40 +00:00
|
|
|
#endif
|
|
|
|
dxr2_send_lpcm_packet(data,len,0xA0,ao_data.pts-10000,freq_id);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return: delay in seconds between first and last sample in buffer
|
2006-07-06 04:30:19 +00:00
|
|
|
static float get_delay(void){
|
2002-05-13 13:15:40 +00:00
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|