diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-03-07 01:04:41 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-03-07 01:04:41 +0200 |
commit | e0172b96e3b6cc6a8b62ee5a52f780941a43de8b (patch) | |
tree | f652f6d15740667d5434e526db3fd12a0573aa0f /libao2 | |
parent | 0c6f667896620943ee6ae899d6e36c3da5c98c54 (diff) | |
parent | 7e253f01715811e0c4f5f5b54317b098f2cd59d9 (diff) | |
download | mpv-e0172b96e3b6cc6a8b62ee5a52f780941a43de8b.tar.bz2 mpv-e0172b96e3b6cc6a8b62ee5a52f780941a43de8b.tar.xz |
Merge svn changes up to r28862
Diffstat (limited to 'libao2')
-rw-r--r-- | libao2/ao_alsa.c | 2 | ||||
-rw-r--r-- | libao2/ao_alsa5.c | 2 | ||||
-rw-r--r-- | libao2/ao_arts.c | 2 | ||||
-rw-r--r-- | libao2/ao_dart.c | 334 | ||||
-rw-r--r-- | libao2/ao_dsound.c | 4 | ||||
-rw-r--r-- | libao2/ao_dxr2.c | 2 | ||||
-rw-r--r-- | libao2/ao_esd.c | 2 | ||||
-rw-r--r-- | libao2/ao_ivtv.c | 2 | ||||
-rw-r--r-- | libao2/ao_jack.c | 2 | ||||
-rw-r--r-- | libao2/ao_macosx.c | 2 | ||||
-rw-r--r-- | libao2/ao_mpegpes.c | 2 | ||||
-rw-r--r-- | libao2/ao_nas.c | 2 | ||||
-rw-r--r-- | libao2/ao_null.c | 2 | ||||
-rw-r--r-- | libao2/ao_openal.c | 2 | ||||
-rw-r--r-- | libao2/ao_oss.c | 2 | ||||
-rw-r--r-- | libao2/ao_pcm.c | 2 | ||||
-rw-r--r-- | libao2/ao_pulse.c | 2 | ||||
-rw-r--r-- | libao2/ao_sdl.c | 2 | ||||
-rw-r--r-- | libao2/ao_sgi.c | 2 | ||||
-rw-r--r-- | libao2/ao_sun.c | 2 | ||||
-rw-r--r-- | libao2/ao_v4l2.c | 2 | ||||
-rw-r--r-- | libao2/ao_win32.c | 95 | ||||
-rw-r--r-- | libao2/audio_out.c | 48 | ||||
-rw-r--r-- | libao2/audio_out.h | 2 | ||||
-rw-r--r-- | libao2/audio_out_internal.h | 2 |
25 files changed, 424 insertions, 99 deletions
diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index 194890ff9a..9541f9c553 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -57,7 +57,7 @@ #include "audio_out_internal.h" #include "libaf/af_format.h" -static ao_info_t info = +static const ao_info_t info = { "ALSA-0.9.x-1.x audio output", "alsa", diff --git a/libao2/ao_alsa5.c b/libao2/ao_alsa5.c index abf2eff827..007a5f1b4f 100644 --- a/libao2/ao_alsa5.c +++ b/libao2/ao_alsa5.c @@ -32,7 +32,7 @@ #include "mp_msg.h" #include "help_mp.h" -static ao_info_t info = +static const ao_info_t info = { "ALSA-0.5.x audio output", "alsa5", diff --git a/libao2/ao_arts.c b/libao2/ao_arts.c index 30db48fb22..df44db4f02 100644 --- a/libao2/ao_arts.c +++ b/libao2/ao_arts.c @@ -38,7 +38,7 @@ static arts_stream_t stream; -static ao_info_t info = +static const ao_info_t info = { "aRts audio output", "arts", diff --git a/libao2/ao_dart.c b/libao2/ao_dart.c new file mode 100644 index 0000000000..e9bff8df1b --- /dev/null +++ b/libao2/ao_dart.c @@ -0,0 +1,334 @@ +/* + * OS/2 DART audio output driver + * + * Copyright (c) 2007-2009 by KO Myung-Hun (komh@chollian.net) + * + * 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. + */ + +#define INCL_DOS +#define INCL_DOSERRORS +#include <os2.h> + +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +#include <float.h> + +#include <dart.h> + +#include "config.h" +#include "libaf/af_format.h" +#include "audio_out.h" +#include "audio_out_internal.h" +#include "mp_msg.h" +#include "libvo/fastmemcpy.h" +#include "subopt-helper.h" + +static const ao_info_t info = { + "DART audio output", + "dart", + "KO Myung-Hun <komh@chollian.net>", + "" +}; + +LIBAO_EXTERN(dart) + +#define OUTBURST_SAMPLES 512 +#define DEFAULT_DART_SAMPLES (OUTBURST_SAMPLES << 2) + +#define CHUNK_SIZE ao_data.outburst + +static uint8_t *m_audioBuf = NULL; + +static int m_nBufSize = 0; + +static volatile int m_fQuit = FALSE; +// may only be modified by DART's playback thread or while it is stopped +static volatile int m_iBufReadPos = 0; +// may only be modified by MPlayer's thread +static volatile int m_iBufWritePos = 0; + +// may only be called by MPlayer's thread +// return value may change between immediately following two calls, +// and the real number of free bytes might be larger! +static int buf_free(void) +{ + int nFree = m_iBufReadPos - m_iBufWritePos - CHUNK_SIZE; + + if (nFree < 0) + nFree += m_nBufSize; + + return nFree; +} + +// may only be called by DART's playback thread +// return value may change between immediately following two calls, +// and the real number of buffered bytes might be larger! +static int buf_used(void) +{ + int nUsed = m_iBufWritePos - m_iBufReadPos; + + if (nUsed < 0) + nUsed += m_nBufSize; + + return nUsed; +} + +static int write_buffer(unsigned char *data, int len) +{ + int nFirstLen = m_nBufSize - m_iBufWritePos; + int nFree = buf_free(); + + if (len > nFree) + len = nFree; + + if (nFirstLen > len) + nFirstLen = len; + + // till end of buffer + fast_memcpy(m_audioBuf + m_iBufWritePos, data, nFirstLen); + if (len > nFirstLen) { // we have to wrap around + // remaining part from beginning of buffer + fast_memcpy(m_audioBuf, data + nFirstLen, len - nFirstLen); + } + + m_iBufWritePos = (m_iBufWritePos + len) % m_nBufSize; + + return len; +} + +static int read_buffer(unsigned char *data, int len) +{ + int nFirstLen = m_nBufSize - m_iBufReadPos; + int nBuffered = buf_used(); + + if (len > nBuffered) + len = nBuffered; + + if (nFirstLen > len) + nFirstLen = len; + + // till end of buffer + fast_memcpy(data, m_audioBuf + m_iBufReadPos, nFirstLen); + if (len > nFirstLen) { // we have to wrap around + // remaining part from beginning of buffer + fast_memcpy(data + nFirstLen, m_audioBuf, len - nFirstLen); + } + + m_iBufReadPos = (m_iBufReadPos + len) % m_nBufSize; + + return len; +} + +// end ring buffer stuff + +static ULONG APIENTRY dart_audio_callback(PVOID pCBData, PVOID pBuffer, + ULONG ulSize) +{ + int nReadLen; + + nReadLen = read_buffer(pBuffer, ulSize); + if (nReadLen < ulSize && !m_fQuit) { + memset((uint8_t *)pBuffer + nReadLen, DART.bSilence, ulSize - nReadLen); + nReadLen = ulSize; + } + + return nReadLen; +} + +// to set/get/query special features/parameters +static int control(int cmd, void *arg) +{ + switch (cmd) { + case AOCONTROL_GET_VOLUME: + { + ao_control_vol_t *vol = arg; + + vol->left = vol->right = LOUSHORT(dartGetVolume()); + + return CONTROL_OK; + } + + case AOCONTROL_SET_VOLUME: + { + int mid; + ao_control_vol_t *vol = arg; + + mid = (vol->left + vol->right) / 2; + dartSetVolume(MCI_SET_AUDIO_ALL, mid); + + return CONTROL_OK; + } + } + + return CONTROL_UNKNOWN; +} + +static void print_help(void) +{ + mp_msg(MSGT_AO, MSGL_FATAL, + "\n-ao dart commandline help:\n" + "Example: mplayer -ao dart:noshare\n" + " open DART in exclusive mode\n" + "\nOptions:\n" + " (no)share\n" + " Open DART in shareable or exclusive mode\n" + " bufsize=<size>\n" + " Set buffer size to <size> in samples(default: 2048)\n"); +} + +// open & set up audio device +// return: 1=success 0=fail +static int init(int rate, int channels, int format, int flags) +{ + int fShare = 1; + int nDartSamples = DEFAULT_DART_SAMPLES; + int nBytesPerSample; + + opt_t subopts[] = { + {"share", OPT_ARG_BOOL, &fShare, NULL}, + {"bufsize", OPT_ARG_INT, &nDartSamples, (opt_test_f)int_non_neg}, + {NULL} + }; + + if (subopt_parse(ao_subdevice, subopts) != 0) { + print_help(); + return 0; + } + + if (!nDartSamples) + nDartSamples = DEFAULT_DART_SAMPLES; + + mp_msg(MSGT_AO, MSGL_V, "DART: opened in %s mode, buffer size = %d sample(s)\n", + fShare ? "shareable" : "exclusive", nDartSamples); + + switch (format) { + case AF_FORMAT_S16_LE: + case AF_FORMAT_S8: + break; + + default: + format = AF_FORMAT_S16_LE; + mp_msg(MSGT_AO, MSGL_V, "DART: format %s not supported defaulting to Signed 16-bit Little-Endian\n", + af_fmt2str_short(format)); + break; + } + + nBytesPerSample = (af_fmt2bits(format) >> 3) * channels; + + if (dartInit(0, af_fmt2bits(format), rate, MCI_WAVE_FORMAT_PCM, channels, + 2, nBytesPerSample * nDartSamples, fShare, + dart_audio_callback, NULL)) + return 0; + + mp_msg(MSGT_AO, MSGL_V, "DART: obtained buffer size = %lu bytes\n", + DART.ulBufferSize); + + m_fQuit = FALSE; + + ao_data.channels = channels; + ao_data.samplerate = rate; + ao_data.format = format; + ao_data.bps = nBytesPerSample * rate; + ao_data.outburst = nBytesPerSample * OUTBURST_SAMPLES; + ao_data.buffersize = DART.ulBufferSize; + + // multiple of CHUNK_SIZE + m_nBufSize = ((DART.ulBufferSize << 2) / CHUNK_SIZE) * CHUNK_SIZE; + // and one more chunk plus round up + m_nBufSize += 2 * CHUNK_SIZE; + + m_audioBuf = malloc(m_nBufSize); + + m_iBufReadPos = 0; + m_iBufWritePos = 0; + + dartPlay(); + + // might cause PM DLLs to be loaded which incorrectly enable SIG_FPE, + // which AAC decoding might trigger. + // so, mask off all floating-point exceptions. + _control87(MCW_EM, MCW_EM); + + return 1; +} + +// close audio device +static void uninit(int immed) +{ + m_fQuit = TRUE; + + if (!immed) { + while (DART.fPlaying) + DosSleep(1); + } + + dartClose(); + + free(m_audioBuf); +} + +// stop playing and empty buffers (for seeking/pause) +static void reset(void) +{ + dartPause(); + + // Reset ring-buffer state + m_iBufReadPos = 0; + m_iBufWritePos = 0; + + dartResume(); +} + +// stop playing, keep buffers (for pause) +static void audio_pause(void) +{ + dartPause(); +} + +// resume playing, after audio_pause() +static void audio_resume(void) +{ + dartResume(); +} + +// return: how many bytes can be played without blocking +static int get_space(void) +{ + return buf_free(); +} + +// 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) +{ + + if (!(flags & AOPLAY_FINAL_CHUNK)) + len = (len / ao_data.outburst) * ao_data.outburst; + + return write_buffer(data, len); +} + +// return: delay in seconds between first and last sample in buffer +static float get_delay(void) +{ + int nBuffered = m_nBufSize - CHUNK_SIZE - buf_free(); // could be less + + return (float)nBuffered / (float)ao_data.bps; +} diff --git a/libao2/ao_dsound.c b/libao2/ao_dsound.c index acd59983dd..729084b145 100644 --- a/libao2/ao_dsound.c +++ b/libao2/ao_dsound.c @@ -42,7 +42,7 @@ #include "subopt-helper.h" -static ao_info_t info = +static const ao_info_t info = { "Windows DirectSound audio output", "dsound", @@ -431,7 +431,7 @@ static int init(int rate, int channels, int format, int flags) case AF_FORMAT_AC3: case AF_FORMAT_S24_LE: case AF_FORMAT_S16_LE: - case AF_FORMAT_S8: + case AF_FORMAT_U8: break; default: mp_msg(MSGT_AO, MSGL_V,"ao_dsound: format %s not supported defaulting to Signed 16-bit Little-Endian\n",af_fmt2str_short(format)); diff --git a/libao2/ao_dxr2.c b/libao2/ao_dxr2.c index cd92ea325c..7f9594fb4d 100644 --- a/libao2/ao_dxr2.c +++ b/libao2/ao_dxr2.c @@ -36,7 +36,7 @@ #include "libmpdemux/mpeg_packetizer.h" -static ao_info_t info = +static const ao_info_t info = { "DXR2 audio output", "dxr2", diff --git a/libao2/ao_esd.c b/libao2/ao_esd.c index a5602ff894..d54f843c65 100644 --- a/libao2/ao_esd.c +++ b/libao2/ao_esd.c @@ -67,7 +67,7 @@ #define ESD_CLIENT_NAME "MPlayer" #define ESD_MAX_DELAY (1.0f) /* max amount of data buffered in esd (#sec) */ -static ao_info_t info = +static const ao_info_t info = { "EsounD audio output", "esd", diff --git a/libao2/ao_ivtv.c b/libao2/ao_ivtv.c index 71b58c0637..2b182ff191 100644 --- a/libao2/ao_ivtv.c +++ b/libao2/ao_ivtv.c @@ -41,7 +41,7 @@ static int freq = 0; -static ao_info_t info = +static const ao_info_t info = { "IVTV MPEG Audio Decoder output", "ivtv", diff --git a/libao2/ao_jack.c b/libao2/ao_jack.c index d7f2092a43..e861d08aed 100644 --- a/libao2/ao_jack.c +++ b/libao2/ao_jack.c @@ -40,7 +40,7 @@ #include <jack/jack.h> -static ao_info_t info = +static const ao_info_t info = { "JACK audio output", "jack", diff --git a/libao2/ao_macosx.c b/libao2/ao_macosx.c index fcbda6f1a1..fb5883b3fb 100644 --- a/libao2/ao_macosx.c +++ b/libao2/ao_macosx.c @@ -53,7 +53,7 @@ #include "libaf/af_format.h" #include "osdep/timer.h" -static ao_info_t info = +static const ao_info_t info = { "Darwin/Mac OS X native audio output", "macosx", diff --git a/libao2/ao_mpegpes.c b/libao2/ao_mpegpes.c index 5af124fd42..88ab903ed1 100644 --- a/libao2/ao_mpegpes.c +++ b/libao2/ao_mpegpes.c @@ -63,7 +63,7 @@ int vo_mpegpes_fd2 = -1; #include <errno.h> -static ao_info_t info = +static const ao_info_t info = { #ifdef CONFIG_DVB "DVB audio output", diff --git a/libao2/ao_nas.c b/libao2/ao_nas.c index 9394649cc0..e5e675be3f 100644 --- a/libao2/ao_nas.c +++ b/libao2/ao_nas.c @@ -119,7 +119,7 @@ static const char* nas_state(unsigned int state) { return nas_states[state]; } -static ao_info_t info = +static const ao_info_t info = { "NAS audio output", "nas", diff --git a/libao2/ao_null.c b/libao2/ao_null.c index 2e28b8f1e8..20b715fb96 100644 --- a/libao2/ao_null.c +++ b/libao2/ao_null.c @@ -27,7 +27,7 @@ #include "audio_out.h" #include "audio_out_internal.h" -static ao_info_t info = +static const ao_info_t info = { "Null audio output", "null", diff --git a/libao2/ao_openal.c b/libao2/ao_openal.c index c91694dc05..c80c49b27a 100644 --- a/libao2/ao_openal.c +++ b/libao2/ao_openal.c @@ -42,7 +42,7 @@ #include "osdep/timer.h" #include "subopt-helper.h" -static ao_info_t info = +static const ao_info_t info = { "OpenAL audio output", "openal", diff --git a/libao2/ao_oss.c b/libao2/ao_oss.c index a98d5d1922..e4688d1723 100644 --- a/libao2/ao_oss.c +++ b/libao2/ao_oss.c @@ -48,7 +48,7 @@ #include "audio_out.h" #include "audio_out_internal.h" -static ao_info_t info = +static const ao_info_t info = { "OSS/ioctl audio output", "oss", diff --git a/libao2/ao_pcm.c b/libao2/ao_pcm.c index bd66ed0dab..bf3f224e81 100644 --- a/libao2/ao_pcm.c +++ b/libao2/ao_pcm.c @@ -35,7 +35,7 @@ #include "help_mp.h" -static ao_info_t info = +static const ao_info_t info = { "RAW PCM/WAVE file writer audio output", "pcm", diff --git a/libao2/ao_pulse.c b/libao2/ao_pulse.c index d6974f85e0..2d27c85540 100644 --- a/libao2/ao_pulse.c +++ b/libao2/ao_pulse.c @@ -33,7 +33,7 @@ #define PULSE_CLIENT_NAME "MPlayer" /** General driver info */ -static ao_info_t info = { +static const ao_info_t info = { "PulseAudio audio output", "pulse", "Lennart Poettering", diff --git a/libao2/ao_sdl.c b/libao2/ao_sdl.c index 645c9e9685..31693be229 100644 --- a/libao2/ao_sdl.c +++ b/libao2/ao_sdl.c @@ -38,7 +38,7 @@ #include "libvo/fastmemcpy.h" -static ao_info_t info = +static const ao_info_t info = { "SDLlib audio output", "sdl", diff --git a/libao2/ao_sgi.c b/libao2/ao_sgi.c index db7c486c83..46b79c1e2e 100644 --- a/libao2/ao_sgi.c +++ b/libao2/ao_sgi.c @@ -32,7 +32,7 @@ #include "help_mp.h" #include "libaf/af_format.h" -static ao_info_t info = +static const ao_info_t info = { "sgi audio output", "sgi", diff --git a/libao2/ao_sun.c b/libao2/ao_sun.c index cae2287f6c..725a49e324 100644 --- a/libao2/ao_sun.c +++ b/libao2/ao_sun.c @@ -49,7 +49,7 @@ #include "mp_msg.h" #include "help_mp.h" -static ao_info_t info = +static const ao_info_t info = { "Sun audio output", "sun", diff --git a/libao2/ao_v4l2.c b/libao2/ao_v4l2.c index eca46f01ac..a57cea91c3 100644 --- a/libao2/ao_v4l2.c +++ b/libao2/ao_v4l2.c @@ -38,7 +38,7 @@ static int freq = 0; -static ao_info_t info = +static const ao_info_t info = { "V4L2 MPEG Audio Decoder output", "v4l2", diff --git a/libao2/ao_win32.c b/libao2/ao_win32.c index 40830eb233..c29e05935f 100644 --- a/libao2/ao_win32.c +++ b/libao2/ao_win32.c @@ -87,12 +87,10 @@ static const int channel_mask[] = { static WAVEHDR* waveBlocks; //pointer to our ringbuffer memory static HWAVEOUT hWaveOut; //handle to the waveout device static unsigned int buf_write=0; -static unsigned int buf_write_pos=0; -static int full_buffers=0; -static int buffered_bytes=0; +static volatile int buf_read=0; -static ao_info_t info = +static const ao_info_t info = { "Windows waveOut audio output", "win32", @@ -102,17 +100,12 @@ static ao_info_t info = LIBAO_EXTERN(win32) -static void CALLBACK waveOutProc(HWAVEOUT hWaveOut,UINT uMsg,DWORD dwInstance, +static void CALLBACK waveOutProc(HWAVEOUT hWaveOut,UINT uMsg,DWORD dwInstance, DWORD dwParam1,DWORD dwParam2) { if(uMsg != WOM_DONE) return; - if (full_buffers) { - buffered_bytes-=BUFFER_SIZE; - --full_buffers; - } else { - buffered_bytes=0; - } + buf_read = (buf_read + 1) % BUFFER_COUNT; } // to set/get/query special features/parameters @@ -145,34 +138,34 @@ static int control(int cmd,void *arg) // return: 1=success 0=fail static int init(int rate,int channels,int format,int flags) { - WAVEFORMATEXTENSIBLE wformat; - DWORD totalBufferSize = (BUFFER_SIZE + sizeof(WAVEHDR)) * BUFFER_COUNT; + WAVEFORMATEXTENSIBLE wformat; MMRESULT result; unsigned char* buffer; int i; - + switch(format){ case AF_FORMAT_AC3: case AF_FORMAT_S24_LE: case AF_FORMAT_S16_LE: - case AF_FORMAT_S8: + case AF_FORMAT_U8: break; default: mp_msg(MSGT_AO, MSGL_V,"ao_win32: format %s not supported defaulting to Signed 16-bit Little-Endian\n",af_fmt2str_short(format)); format=AF_FORMAT_S16_LE; - } + } // FIXME multichannel mode is buggy if(channels > 2) channels = 2; - - //fill global ao_data + + //fill global ao_data ao_data.channels=channels; ao_data.samplerate=rate; ao_data.format=format; ao_data.bps=channels*rate; if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8) ao_data.bps*=2; + ao_data.outburst = BUFFER_SIZE; if(ao_data.buffersize==-1) { ao_data.buffersize=af_fmt2bits(format)/8; @@ -181,22 +174,22 @@ static int init(int rate,int channels,int format,int flags) } mp_msg(MSGT_AO, MSGL_V,"ao_win32: Samplerate:%iHz Channels:%i Format:%s\n",rate, channels, af_fmt2str_short(format)); mp_msg(MSGT_AO, MSGL_V,"ao_win32: Buffersize:%d\n",ao_data.buffersize); - + //fill waveformatex ZeroMemory( &wformat, sizeof(WAVEFORMATEXTENSIBLE)); wformat.Format.cbSize = (channels>2)?sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX):0; - wformat.Format.nChannels = channels; - wformat.Format.nSamplesPerSec = rate; + wformat.Format.nChannels = channels; + wformat.Format.nSamplesPerSec = rate; if(format == AF_FORMAT_AC3) { wformat.Format.wFormatTag = WAVE_FORMAT_DOLBY_AC3_SPDIF; wformat.Format.wBitsPerSample = 16; wformat.Format.nBlockAlign = 4; } - else + else { wformat.Format.wFormatTag = (channels>2)?WAVE_FORMAT_EXTENSIBLE:WAVE_FORMAT_PCM; - wformat.Format.wBitsPerSample = af_fmt2bits(format); + wformat.Format.wBitsPerSample = af_fmt2bits(format); wformat.Format.nBlockAlign = wformat.Format.nChannels * (wformat.Format.wBitsPerSample >> 3); } if(channels>2) @@ -205,9 +198,9 @@ static int init(int rate,int channels,int format,int flags) wformat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; wformat.Samples.wValidBitsPerSample=af_fmt2bits(format); } - + wformat.Format.nAvgBytesPerSec = wformat.Format.nSamplesPerSec * wformat.Format.nBlockAlign; - + //open sound device //WAVE_MAPPER always points to the default wave device on the system result = waveOutOpen(&hWaveOut,WAVE_MAPPER,(WAVEFORMATEX*)&wformat,(DWORD_PTR)waveOutProc,0,CALLBACK_FUNCTION); @@ -231,9 +224,8 @@ static int init(int rate,int channels,int format,int flags) return 0; } //allocate buffer memory as one big block - buffer = malloc(totalBufferSize); - memset(buffer,0x0,totalBufferSize); - //and setup pointers to each buffer + buffer = calloc(BUFFER_COUNT, BUFFER_SIZE + sizeof(WAVEHDR)); + //and setup pointers to each buffer waveBlocks = (WAVEHDR*)buffer; buffer += sizeof(WAVEHDR) * BUFFER_COUNT; for(i = 0; i < BUFFER_COUNT; i++) { @@ -241,9 +233,7 @@ static int init(int rate,int channels,int format,int flags) buffer += BUFFER_SIZE; } buf_write=0; - buf_write_pos=0; - full_buffers=0; - buffered_bytes=0; + buf_read=0; return 1; } @@ -251,8 +241,8 @@ static int init(int rate,int channels,int format,int flags) // close audio device static void uninit(int immed) { - if(!immed)while(buffered_bytes > 0)usec_sleep(50000); - else buffered_bytes=0; + if(!immed) + usec_sleep(get_delay() * 1000 * 1000); waveOutReset(hWaveOut); waveOutClose(hWaveOut); mp_msg(MSGT_AO, MSGL_V,"waveOut device closed\n"); @@ -265,9 +255,7 @@ static void reset(void) { waveOutReset(hWaveOut); buf_write=0; - buf_write_pos=0; - full_buffers=0; - buffered_bytes=0; + buf_read=0; } // stop playing, keep buffers (for pause) @@ -285,7 +273,9 @@ static void audio_resume(void) // return: how many bytes can be played without blocking static int get_space(void) { - return BUFFER_COUNT*BUFFER_SIZE - buffered_bytes; + int free = buf_read - buf_write - 1; + if (free < 0) free += BUFFER_COUNT; + return free * BUFFER_SIZE; } //writes data into buffer, based on ringbuffer code in ao_sdl.c @@ -293,28 +283,23 @@ static int write_waveOutBuffer(unsigned char* data,int len){ WAVEHDR* current; int len2=0; int x; - while(len>0){ + while(len>0){ + int buf_next = (buf_write + 1) % BUFFER_COUNT; current = &waveBlocks[buf_write]; - if(buffered_bytes==BUFFER_COUNT*BUFFER_SIZE) break; + if(buf_next == buf_read) break; //unprepare the header if it is prepared - if(current->dwFlags & WHDR_PREPARED) + if(current->dwFlags & WHDR_PREPARED) waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR)); - x=BUFFER_SIZE-buf_write_pos; - if(x>len) x=len; - fast_memcpy(current->lpData+buf_write_pos,data+len2,x); - if(buf_write_pos==0)full_buffers++; - len2+=x; len-=x; - buffered_bytes+=x; buf_write_pos+=x; + x=BUFFER_SIZE; + if(x>len) x=len; + fast_memcpy(current->lpData,data+len2,x); + len2+=x; len-=x; //prepare header and write data to device - current->dwBufferLength = buf_write_pos; + current->dwBufferLength = x; waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR)); waveOutWrite(hWaveOut, current, sizeof(WAVEHDR)); - - if(buf_write_pos>=BUFFER_SIZE){ //buffer is full find next - // block is full, find next! - buf_write=(buf_write+1)%BUFFER_COUNT; - buf_write_pos=0; - } + + buf_write = buf_next; } return len2; } @@ -332,5 +317,7 @@ static int play(void* data,int len,int flags) // return: delay in seconds between first and last sample in buffer static float get_delay(void) { - return (float)(buffered_bytes + ao_data.buffersize)/(float)ao_data.bps; + int used = buf_write - buf_read; + if (used < 0) used += BUFFER_COUNT; + return (float)(used * BUFFER_SIZE + ao_data.buffersize)/(float)ao_data.bps; } diff --git a/libao2/audio_out.c b/libao2/audio_out.c index ee62ebc016..8c64abbb95 100644 --- a/libao2/audio_out.c +++ b/libao2/audio_out.c @@ -30,28 +30,29 @@ ao_data_t ao_data={0,0,0,0,OUTBURST,-1,0}; char *ao_subdevice = NULL; -extern ao_functions_t audio_out_oss; -extern ao_functions_t audio_out_macosx; -extern ao_functions_t audio_out_arts; -extern ao_functions_t audio_out_esd; -extern ao_functions_t audio_out_pulse; -extern ao_functions_t audio_out_jack; -extern ao_functions_t audio_out_openal; -extern ao_functions_t audio_out_null; -extern ao_functions_t audio_out_alsa5; -extern ao_functions_t audio_out_alsa; -extern ao_functions_t audio_out_nas; -extern ao_functions_t audio_out_sdl; -extern ao_functions_t audio_out_sun; -extern ao_functions_t audio_out_sgi; -extern ao_functions_t audio_out_win32; -extern ao_functions_t audio_out_dsound; -extern ao_functions_t audio_out_dxr2; -extern ao_functions_t audio_out_ivtv; -extern ao_functions_t audio_out_v4l2; -extern ao_functions_t audio_out_mpegpes; -extern ao_functions_t audio_out_pcm; -extern ao_functions_t audio_out_pss; +extern const ao_functions_t audio_out_oss; +extern const ao_functions_t audio_out_macosx; +extern const ao_functions_t audio_out_arts; +extern const ao_functions_t audio_out_esd; +extern const ao_functions_t audio_out_pulse; +extern const ao_functions_t audio_out_jack; +extern const ao_functions_t audio_out_openal; +extern const ao_functions_t audio_out_null |