summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authorranma <ranma@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-08-24 13:36:04 +0000
committerranma <ranma@b3059339-0415-0410-9bf9-f77b7e298cf2>2008-08-24 13:36:04 +0000
commit7f26ceaa54b1956f9d2c8c36e4a85e7718066bb4 (patch)
tree21ce705d8e226efa8706cd998570d2b30cd750f3 /libao2
parent6d97b19a73ccfc3e09a2ea19d91ef307d6653fd6 (diff)
downloadmpv-7f26ceaa54b1956f9d2c8c36e4a85e7718066bb4.tar.bz2
mpv-7f26ceaa54b1956f9d2c8c36e4a85e7718066bb4.tar.xz
Handle AOPLAY_FINAL_CHUNK
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27481 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libao2')
-rw-r--r--libao2/ao_nas.c53
1 files changed, 20 insertions, 33 deletions
diff --git a/libao2/ao_nas.c b/libao2/ao_nas.c
index f50c25c02c..5428c7489f 100644
--- a/libao2/ao_nas.c
+++ b/libao2/ao_nas.c
@@ -41,6 +41,7 @@
#include "audio_out_internal.h"
#include "libaf/af_format.h"
+/* NAS_FRAG_SIZE must be a power-of-two value */
#define NAS_FRAG_SIZE 4096
static char *nas_event_types[] = {
@@ -566,7 +567,7 @@ static int get_space(void)
// return: number of bytes played
static int play(void* data,int len,int flags)
{
- int maxbursts, playbursts, writelen;
+ int written, maxbursts = 0, playbursts = 0;
AuStatus as;
mp_msg(MSGT_AO, MSGL_DBG3,
@@ -576,41 +577,27 @@ static int play(void* data,int len,int flags)
if (len == 0)
return 0;
- if (len < ao_data.outburst) {
- unsigned tempbufsz = ao_data.outburst;
- void *tempbuf = malloc(tempbufsz);
-
- memset(tempbuf, 0, tempbufsz);
- memcpy(tempbuf, data, len);
-
- play(tempbuf, ao_data.outburst, flags);
-
- if (nas_data->state != AuStateStart) {
- mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n");
- nas_data->expect_underrun = 1;
- nas_data->state = AuStateStart;
- AuStartFlow(nas_data->aud, nas_data->flow, &as);
- if (as != AuSuccess)
- nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
- }
-
- free(tempbuf);
-
- return len;
+ if (!(flags & AOPLAY_FINAL_CHUNK)) {
+ pthread_mutex_lock(&nas_data->buffer_mutex);
+ maxbursts = (nas_data->client_buffer_size -
+ nas_data->client_buffer_used) / ao_data.outburst;
+ playbursts = len / ao_data.outburst;
+ len = (playbursts > maxbursts ? maxbursts : playbursts) *
+ ao_data.outburst;
+ pthread_mutex_unlock(&nas_data->buffer_mutex);
}
- pthread_mutex_lock(&nas_data->buffer_mutex);
- maxbursts = (nas_data->client_buffer_size -
- nas_data->client_buffer_used) / ao_data.outburst;
- playbursts = len / ao_data.outburst;
- writelen = (playbursts > maxbursts ? maxbursts : playbursts) *
- ao_data.outburst;
- pthread_mutex_unlock(&nas_data->buffer_mutex);
-
- writelen = nas_writeBuffer(nas_data, data, writelen);
+ /*
+ * If AOPLAY_FINAL_CHUNK is set, we did not actually check len fits
+ * into the available buffer space, but mplayer.c shouldn't give us
+ * more to play than we report to it by get_space(), so this should be
+ * fine.
+ */
+ written = nas_writeBuffer(nas_data, data, len);
if (nas_data->state != AuStateStart &&
- maxbursts == playbursts) {
+ (maxbursts == playbursts ||
+ flags & AOPLAY_FINAL_CHUNK)) {
mp_msg(MSGT_AO, MSGL_DBG2, "ao_nas: play(): Starting flow.\n");
nas_data->expect_underrun = 1;
AuStartFlow(nas_data->aud, nas_data->flow, &as);
@@ -618,7 +605,7 @@ static int play(void* data,int len,int flags)
nas_print_error(nas_data->aud, "play(): AuStartFlow", as);
}
- return writelen;
+ return written;
}
// return: delay in seconds between first and last sample in buffer