2009-01-26 15:06:44 +00:00
|
|
|
/*
|
|
|
|
* null audio output driver
|
|
|
|
*
|
|
|
|
* 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-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
|
|
|
|
2005-01-12 22:00:02 +00:00
|
|
|
#include "config.h"
|
2004-12-27 17:30:15 +00:00
|
|
|
#include "libaf/af_format.h"
|
2001-06-02 23:25:43 +00:00
|
|
|
#include "audio_out.h"
|
|
|
|
#include "audio_out_internal.h"
|
|
|
|
|
2009-05-13 02:58:57 +00:00
|
|
|
static const ao_info_t info =
|
2001-06-02 23:25:43 +00:00
|
|
|
{
|
|
|
|
"Null audio output",
|
|
|
|
"null",
|
2005-06-19 09:17:44 +00:00
|
|
|
"Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
|
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;
|
|
|
|
|
2006-02-09 14:08:03 +00:00
|
|
|
static void drain(void){
|
2009-05-13 02:58:57 +00:00
|
|
|
|
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;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-01-31 00:32:04 +00:00
|
|
|
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){
|
|
|
|
|
2007-12-01 05:17:08 +00:00
|
|
|
int samplesize = af_fmt2bits(format) / 8;
|
2007-12-01 01:39:39 +00:00
|
|
|
ao_data.outburst = 256 * channels * samplesize;
|
|
|
|
// A "buffer" for about 0.2 seconds of audio
|
|
|
|
ao_data.buffersize = (int)(rate * 0.2 / 256 + 1) * ao_data.outburst;
|
2002-01-31 00:32:04 +00:00
|
|
|
ao_data.channels=channels;
|
|
|
|
ao_data.samplerate=rate;
|
|
|
|
ao_data.format=format;
|
2007-12-01 01:39:39 +00:00
|
|
|
ao_data.bps=channels*rate*samplesize;
|
2002-01-31 00:32:04 +00:00
|
|
|
buffer=0;
|
|
|
|
gettimeofday(&last_tv, 0);
|
|
|
|
|
|
|
|
return 1;
|
2001-06-02 23:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// close audio device
|
2004-04-06 17:55:36 +00:00
|
|
|
static void uninit(int immed){
|
2001-06-02 23:25:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop playing and empty buffers (for seeking/pause)
|
2006-02-09 14:08:03 +00:00
|
|
|
static void reset(void){
|
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)
|
2006-02-09 14:08:03 +00:00
|
|
|
static void audio_pause(void)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
|
|
|
// for now, just call reset();
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// resume playing, after audio_pause()
|
2006-02-09 14:08:03 +00:00
|
|
|
static void audio_resume(void)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-02 23:25:43 +00:00
|
|
|
// return: how many bytes can be played without blocking
|
2006-02-09 14:08:03 +00:00
|
|
|
static int get_space(void){
|
2001-06-02 23:25:43 +00:00
|
|
|
|
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
|
2006-02-09 14:08:03 +00:00
|
|
|
static float get_delay(void){
|
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
|
|
|
}
|