2001-06-02 23:25:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-01-31 08:39:21 +00:00
|
|
|
#include <sys/time.h>
|
2001-06-02 23:25:43 +00:00
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
#include "afmt.h"
|
2001-06-02 23:25:43 +00:00
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
|
|
|
|
|
|
|
static ao_info_t info =
|
|
|
|
{
|
|
|
|
"Null audio output",
|
|
|
|
"null",
|
2002-01-31 00:32:04 +00:00
|
|
|
"Tobias Diedrich",
|
2001-06-02 23:25:43 +00:00
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
LIBAO_EXTERN(null)
|
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
struct timeval last_tv;
|
|
|
|
int buffer;
|
|
|
|
|
2002-09-22 02:33:28 +00:00
|
|
|
static void drain(){
|
2002-01-31 00:32:04 +00:00
|
|
|
|
|
|
|
struct timeval now_tv;
|
|
|
|
int temp, temp2;
|
|
|
|
|
|
|
|
gettimeofday(&now_tv, 0);
|
|
|
|
temp = now_tv.tv_sec - last_tv.tv_sec;
|
|
|
|
temp *= ao_data.bps;
|
|
|
|
|
|
|
|
temp2 = now_tv.tv_usec - last_tv.tv_usec;
|
|
|
|
temp2 /= 1000;
|
|
|
|
temp2 *= ao_data.bps;
|
|
|
|
temp2 /= 1000;
|
|
|
|
temp += temp2;
|
|
|
|
|
|
|
|
buffer-=temp;
|
|
|
|
if (buffer<0) buffer=0;
|
|
|
|
|
2002-05-03 18:42:43 +00:00
|
|
|
if(temp>0) last_tv = now_tv;//mplayer is fast
|
2002-01-31 00:32:04 +00:00
|
|
|
}
|
2001-06-02 23:25:43 +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-06-02 23:25:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// open & setup audio device
|
|
|
|
// return: 1=success 0=fail
|
|
|
|
static int init(int rate,int channels,int format,int flags){
|
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
ao_data.buffersize= 65536;
|
|
|
|
ao_data.outburst=1024;
|
|
|
|
ao_data.channels=channels;
|
|
|
|
ao_data.samplerate=rate;
|
|
|
|
ao_data.format=format;
|
|
|
|
ao_data.bps=channels*rate;
|
|
|
|
if (format != AFMT_U8 && format != AFMT_S8)
|
|
|
|
ao_data.bps*=2;
|
|
|
|
buffer=0;
|
|
|
|
gettimeofday(&last_tv, 0);
|
|
|
|
|
|
|
|
return 1;
|
2001-06-02 23:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// close audio device
|
|
|
|
static void uninit(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing and empty buffers (for seeking/pause)
|
|
|
|
static void reset(){
|
2002-01-31 00:32:04 +00:00
|
|
|
buffer=0;
|
2001-06-02 23:25:43 +00:00
|
|
|
}
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
// stop playing, keep buffers (for pause)
|
|
|
|
static void audio_pause()
|
|
|
|
{
|
|
|
|
// for now, just call reset();
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// resume playing, after audio_pause()
|
|
|
|
static void audio_resume()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-02 23:25:43 +00:00
|
|
|
// return: how many bytes can be played without blocking
|
|
|
|
static int get_space(){
|
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
drain();
|
|
|
|
return ao_data.buffersize - buffer;
|
2001-06-02 23:25:43 +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){
|
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
int maxbursts = (ao_data.buffersize - buffer) / ao_data.outburst;
|
|
|
|
int playbursts = len / ao_data.outburst;
|
|
|
|
int bursts = playbursts > maxbursts ? maxbursts : playbursts;
|
|
|
|
buffer += bursts * ao_data.outburst;
|
|
|
|
return bursts * ao_data.outburst;
|
2001-06-02 23:25:43 +00:00
|
|
|
}
|
|
|
|
|
2001-11-24 05:21:22 +00:00
|
|
|
// return: delay in seconds between first and last sample in buffer
|
|
|
|
static float get_delay(){
|
2001-06-02 23:25:43 +00:00
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
drain();
|
|
|
|
return (float) buffer / (float) ao_data.bps;
|
2001-06-02 23:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|