aboutsummaryrefslogtreecommitdiffhomepage
path: root/libao2
diff options
context:
space:
mode:
authorGravatar Uoti Urpala <uau@glyph.nonexistent.invalid>2009-05-08 23:50:26 +0300
committerGravatar Uoti Urpala <uau@glyph.nonexistent.invalid>2009-05-08 23:50:26 +0300
commit1db1773ec27fc4e7c9d44ad02ccfa7eaf364ce07 (patch)
treec5e99bfe0e69cd37fb8ac70fadf00ce54a1cbe3c /libao2
parentf2864e9a072f53c38a04dd7c44392521777dc908 (diff)
parent86c9fb2e8930de031807513c9b93d47394d2d2fa (diff)
Merge svn changes up to r29277
Diffstat (limited to 'libao2')
-rw-r--r--libao2/ao_coreaudio.c (renamed from libao2/ao_macosx.c)118
-rw-r--r--libao2/ao_jack.c4
-rw-r--r--libao2/ao_pulse.c17
-rw-r--r--libao2/ao_sdl.c4
-rw-r--r--libao2/audio_out.c4
5 files changed, 49 insertions, 98 deletions
diff --git a/libao2/ao_macosx.c b/libao2/ao_coreaudio.c
index fb5883b3fb..3ef6d3367f 100644
--- a/libao2/ao_macosx.c
+++ b/libao2/ao_coreaudio.c
@@ -1,5 +1,5 @@
/*
- * Mac OS X audio output driver
+ * CoreAudio audio output driver for Mac OS X
*
* original copyright (C) Timothy J. Wood - Aug 2000
* ported to MPlayer libao2 by Dan Christiansen
@@ -52,21 +52,22 @@
#include "audio_out_internal.h"
#include "libaf/af_format.h"
#include "osdep/timer.h"
+#include "libavutil/fifo.h"
static const ao_info_t info =
{
"Darwin/Mac OS X native audio output",
- "macosx",
+ "coreaudio",
"Timothy J. Wood & Dan Christiansen & Chris Roccati",
""
};
-LIBAO_EXTERN(macosx)
+LIBAO_EXTERN(coreaudio)
/* Prefix for all mp_msg() calls */
-#define ao_msg(a, b, c...) mp_msg(a, b, "AO: [macosx] " c)
+#define ao_msg(a, b, c...) mp_msg(a, b, "AO: [coreaudio] " c)
-typedef struct ao_macosx_s
+typedef struct ao_coreaudio_s
{
AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device. */
int b_supports_digital; /* Does the currently selected device support digital mode? */
@@ -91,87 +92,35 @@ typedef struct ao_macosx_s
int paused;
/* Ring-buffer */
- /* does not need explicit synchronization, but needs to allocate
- * (num_chunks + 1) * chunk_size memory to store num_chunks * chunk_size
- * data */
- unsigned char *buffer;
- unsigned int buffer_len; ///< must always be (num_chunks + 1) * chunk_size
+ AVFifoBuffer *buffer;
+ unsigned int buffer_len; ///< must always be num_chunks * chunk_size
unsigned int num_chunks;
unsigned int chunk_size;
-
- unsigned int buf_read_pos;
- unsigned int buf_write_pos;
-} ao_macosx_t;
+} ao_coreaudio_t;
-static ao_macosx_t *ao = NULL;
-
-/**
- * \brief return number of free bytes in the buffer
- * may only be called by mplayer's thread
- * \return minimum number of free bytes in buffer, value may change between
- * two immediately following calls, and the real number of free bytes
- * might actually be larger!
- */
-static int buf_free(void) {
- int free = ao->buf_read_pos - ao->buf_write_pos - ao->chunk_size;
- if (free < 0) free += ao->buffer_len;
- return free;
-}
-
-/**
- * \brief return number of buffered bytes
- * may only be called by playback thread
- * \return minimum number of buffered bytes, value may change between
- * two immediately following calls, and the real number of buffered bytes
- * might actually be larger!
- */
-static int buf_used(void) {
- int used = ao->buf_write_pos - ao->buf_read_pos;
- if (used < 0) used += ao->buffer_len;
- return used;
-}
+static ao_coreaudio_t *ao = NULL;
/**
* \brief add data to ringbuffer
*/
static int write_buffer(unsigned char* data, int len){
- int first_len = ao->buffer_len - ao->buf_write_pos;
- int free = buf_free();
+ int free = ao->buffer_len - av_fifo_size(ao->buffer);
if (len > free) len = free;
- if (first_len > len) first_len = len;
- // till end of buffer
- memcpy (&ao->buffer[ao->buf_write_pos], data, first_len);
- if (len > first_len) { // we have to wrap around
- // remaining part from beginning of buffer
- memcpy (ao->buffer, &data[first_len], len - first_len);
- }
- ao->buf_write_pos = (ao->buf_write_pos + len) % ao->buffer_len;
- return len;
+ return av_fifo_generic_write(ao->buffer, data, len, NULL);
}
/**
* \brief remove data from ringbuffer
*/
static int read_buffer(unsigned char* data,int len){
- int first_len = ao->buffer_len - ao->buf_read_pos;
- int buffered = buf_used();
+ int buffered = av_fifo_size(ao->buffer);
if (len > buffered) len = buffered;
- if (first_len > len) first_len = len;
- // till end of buffer
- if (data) {
- memcpy (data, &ao->buffer[ao->buf_read_pos], first_len);
- if (len > first_len) { // we have to wrap around
- // remaining part from beginning of buffer
- memcpy (&data[first_len], ao->buffer, len - first_len);
- }
- }
- ao->buf_read_pos = (ao->buf_read_pos + len) % ao->buffer_len;
- return len;
+ return av_fifo_generic_read(ao->buffer, data, len, NULL);
}
OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
{
-int amt=buf_used();
+int amt=av_fifo_size(ao->buffer);
int req=(inNumFrames)*ao->packetSize;
if(amt>req)
@@ -266,7 +215,7 @@ static void print_format(int lev, const char* str, const AudioStreamBasicDescrip
static int AudioDeviceSupportsDigital( AudioDeviceID i_dev_id );
static int AudioStreamSupportsDigital( AudioStreamID i_stream_id );
-static int OpenSPDIF();
+static int OpenSPDIF(void);
static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format );
static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
const AudioTimeStamp * inNow,
@@ -299,7 +248,7 @@ int b_alive;
ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n", rate, channels, af_fmt2str_short(format), flags);
- ao = calloc(1, sizeof(ao_macosx_t));
+ ao = calloc(1, sizeof(ao_coreaudio_t));
ao->i_selected_dev = 0;
ao->b_supports_digital = 0;
@@ -493,8 +442,8 @@ int b_alive;
ao_data.buffersize = ao_data.bps;
ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
- ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size;
- ao->buffer = calloc(ao->num_chunks + 1, ao->chunk_size);
+ ao->buffer_len = ao->num_chunks * ao->chunk_size;
+ ao->buffer = av_fifo_alloc(ao->buffer_len);
ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
@@ -515,7 +464,7 @@ err_out2:
err_out1:
CloseComponent(ao->theOutputUnit);
err_out:
- free(ao->buffer);
+ av_fifo_free(ao->buffer);
free(ao);
ao = NULL;
return CONTROL_FALSE;
@@ -524,7 +473,7 @@ err_out:
/*****************************************************************************
* Setup a encoded digital stream (SPDIF)
*****************************************************************************/
-static int OpenSPDIF()
+static int OpenSPDIF(void)
{
OSStatus err = noErr;
UInt32 i_param_size, b_mix = 0;
@@ -737,8 +686,8 @@ static int OpenSPDIF()
ao_data.buffersize = ao_data.bps;
ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
- ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size;
- ao->buffer = calloc(ao->num_chunks + 1, ao->chunk_size);
+ ao->buffer_len = ao->num_chunks * ao->chunk_size;
+ ao->buffer = av_fifo_alloc(ao->buffer_len);
ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
@@ -782,7 +731,7 @@ err_out:
ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n",
(char *)&err);
}
- free(ao->buffer);
+ av_fifo_free(ao->buffer);
free(ao);
ao = NULL;
return CONTROL_FALSE;
@@ -981,7 +930,7 @@ static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
const AudioTimeStamp * inOutputTime,
void * threadGlobals )
{
- int amt = buf_used();
+ int amt = av_fifo_size(ao->buffer);
int req = outOutputData->mBuffers[ao->i_stream_index].mDataByteSize;
if (amt > req)
@@ -1030,27 +979,22 @@ static int play(void* output_samples,int num_bytes,int flags)
static void reset(void)
{
audio_pause();
- /* reset ring-buffer state */
- ao->buf_read_pos=0;
- ao->buf_write_pos=0;
-
- return;
+ av_fifo_reset(ao->buffer);
}
/* return available space */
static int get_space(void)
{
- return buf_free();
+ return ao->buffer_len - av_fifo_size(ao->buffer);
}
/* return delay until audio is played */
static float get_delay(void)
{
- int buffered = ao->buffer_len - ao->chunk_size - buf_free(); // could be less
// inaccurate, should also contain the data buffered e.g. by the OS
- return (float)(buffered)/(float)ao_data.bps;
+ return (float)av_fifo_size(ao->buffer)/(float)ao_data.bps;
}
@@ -1061,8 +1005,8 @@ static void uninit(int immed)
UInt32 i_param_size = 0;
if (!immed) {
- long long timeleft=(1000000LL*buf_used())/ao_data.bps;
- ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%d usec)\n", buf_used(), ao_data.bps, (int)timeleft);
+ long long timeleft=(1000000LL*av_fifo_size(ao->buffer))/ao_data.bps;
+ ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%d usec)\n", av_fifo_size(ao->buffer), ao_data.bps, (int)timeleft);
usec_sleep((int)timeleft);
}
@@ -1115,7 +1059,7 @@ static void uninit(int immed)
}
}
- free(ao->buffer);
+ av_fifo_free(ao->buffer);
free(ao);
ao = NULL;
}
diff --git a/libao2/ao_jack.c b/libao2/ao_jack.c
index 494d44aa19..8ee5550602 100644
--- a/libao2/ao_jack.c
+++ b/libao2/ao_jack.c
@@ -82,7 +82,7 @@ static AVFifoBuffer *buffer;
* If there is not enough room, the buffer is filled up
*/
static int write_buffer(unsigned char* data, int len) {
- int free = BUFFSIZE - av_fifo_size(buffer);
+ int free = av_fifo_space(buffer);
if (len > free) len = free;
return av_fifo_generic_write(buffer, data, len, NULL);
}
@@ -337,7 +337,7 @@ static void audio_resume(void) {
}
static int get_space(void) {
- return BUFFSIZE - av_fifo_size(buffer);
+ return av_fifo_space(buffer);
}
/**
diff --git a/libao2/ao_pulse.c b/libao2/ao_pulse.c
index 2d27c85540..b2fdcbb175 100644
--- a/libao2/ao_pulse.c
+++ b/libao2/ao_pulse.c
@@ -102,7 +102,10 @@ static void success_cb(pa_stream *s, int success, void *userdata) {
*/
static int waitop(pa_operation *op) {
pa_operation_state_t state;
- if (!op) return 0;
+ if (!op) {
+ pa_threaded_mainloop_unlock(mainloop);
+ return 0;
+ }
state = pa_operation_get_state(op);
while (state == PA_OPERATION_RUNNING) {
pa_threaded_mainloop_wait(mainloop);
@@ -150,11 +153,11 @@ static int init(int rate_hz, int channels, int format, int flags) {
}
broken_pause = 0;
- // not sure which versions are affected, assume 0.9.1*
+ // not sure which versions are affected, assume 0.9.11* to 0.9.14*
// known bad: 0.9.14, 0.9.13
- // known good: 0.9.9, 0.9.10
+ // known good: 0.9.9, 0.9.10, 0.9.15
// to test: pause, wait ca. 5 seconds framestep and see if MPlayer hangs somewhen
- if (strncmp(version, "0.9.1", 5) == 0 && strncmp(version, "0.9.10", 6) != 0) {
+ if (strncmp(version, "0.9.1", 5) == 0 && version[5] >= '1' && version[5] <= '4') {
mp_msg(MSGT_AO, MSGL_WARN, "[pulse] working around probably broken pause functionality,\n"
" see http://www.pulseaudio.org/ticket/440\n");
broken_pause = 1;
@@ -389,12 +392,16 @@ static int control(int cmd, void *arg) {
volume.values[1] = (pa_volume_t)vol->right*PA_VOLUME_NORM/100;
}
- if (!(o = pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), &volume, NULL, NULL))) {
+ pa_threaded_mainloop_lock(mainloop);
+ o = pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), &volume, NULL, NULL);
+ if (!o) {
+ pa_threaded_mainloop_unlock(mainloop);
GENERIC_ERR_MSG(context, "pa_context_set_sink_input_volume() failed");
return CONTROL_ERROR;
}
/* We don't wait for completion here */
pa_operation_unref(o);
+ pa_threaded_mainloop_unlock(mainloop);
return CONTROL_OK;
}
diff --git a/libao2/ao_sdl.c b/libao2/ao_sdl.c
index 63ddec6f29..df643cb62a 100644
--- a/libao2/ao_sdl.c
+++ b/libao2/ao_sdl.c
@@ -67,7 +67,7 @@ static unsigned char volume=SDL_MIX_MAXVOLUME;
#endif
static int write_buffer(unsigned char* data,int len){
- int free = BUFFSIZE - av_fifo_size(buffer);
+ int free = av_fifo_space(buffer);
if (len > free) len = free;
return av_fifo_generic_write(buffer, data, len, NULL);
}
@@ -280,7 +280,7 @@ static void audio_resume(void)
// return: how many bytes can be played without blocking
static int get_space(void){
- return BUFFSIZE - av_fifo_size(buffer);
+ return av_fifo_space(buffer);
}
// plays 'len' bytes of 'data'
diff --git a/libao2/audio_out.c b/libao2/audio_out.c
index 8c64abbb95..fe95ab192f 100644
--- a/libao2/audio_out.c
+++ b/libao2/audio_out.c
@@ -31,7 +31,7 @@ ao_data_t ao_data={0,0,0,0,OUTBURST,-1,0};
char *ao_subdevice = NULL;
extern const ao_functions_t audio_out_oss;
-extern const ao_functions_t audio_out_macosx;
+extern const ao_functions_t audio_out_coreaudio;
extern const ao_functions_t audio_out_arts;
extern const ao_functions_t audio_out_esd;
extern const ao_functions_t audio_out_pulse;
@@ -67,7 +67,7 @@ const ao_functions_t* const audio_out_drivers[] =
&audio_out_dart,
#endif
#ifdef CONFIG_COREAUDIO
- &audio_out_macosx,
+ &audio_out_coreaudio,
#endif
#ifdef CONFIG_OSS_AUDIO
&audio_out_oss,