summaryrefslogtreecommitdiffstats
path: root/audio/out
diff options
context:
space:
mode:
Diffstat (limited to 'audio/out')
-rw-r--r--audio/out/ao_coreaudio.c5
-rw-r--r--audio/out/ao_lavc.c34
2 files changed, 23 insertions, 16 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index 6a15690074..54ff1b4915 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -1080,7 +1080,6 @@ static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
static int play(void* output_samples,int num_bytes,int flags)
{
int wrote, b_digital;
- SInt32 exit_reason;
// Check whether we need to reset the digital output stream.
if (ao->b_digital && ao->b_stream_format_changed)
@@ -1110,10 +1109,6 @@ static int play(void* output_samples,int num_bytes,int flags)
wrote=write_buffer(output_samples, num_bytes);
audio_resume();
- do {
- exit_reason = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, true);
- } while (exit_reason == kCFRunLoopRunHandledSource);
-
return wrote;
}
diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c
index 0fda9a2b3a..d8185a8dca 100644
--- a/audio/out/ao_lavc.c
+++ b/audio/out/ao_lavc.c
@@ -309,6 +309,7 @@ static void fill_with_padding(void *buf, int cnt, int sz, const void *padding)
// close audio device
static int encode(struct ao *ao, double apts, void *data);
+static int play(struct ao *ao, void *data, int len, int flags);
static void uninit(struct ao *ao, bool cut_audio)
{
struct priv *ac = ao->priv;
@@ -321,21 +322,31 @@ static void uninit(struct ao *ao, bool cut_audio)
}
if (ac->buffer) {
- double pts = ao->pts + ac->offset / (double) ao->samplerate;
if (ao->buffer.len > 0) {
- void *paddingbuf = talloc_size(ao,
- ac->aframesize * ao->channels.num * ac->sample_size);
+ // TRICK: append aframesize-1 samples to the end, then play() will
+ // encode all it can
+ size_t extralen =
+ (ac->aframesize - 1) * ao->channels.num * ac->sample_size;
+ void *paddingbuf = talloc_size(ao, ao->buffer.len + extralen);
memcpy(paddingbuf, ao->buffer.start, ao->buffer.len);
fill_with_padding((char *) paddingbuf + ao->buffer.len,
- (ac->aframesize * ao->channels.num * ac->sample_size -
- ao->buffer.len) / ac->sample_size,
- ac->sample_size, ac->sample_padding);
- encode(ao, pts, paddingbuf);
- pts += ac->aframesize / (double) ao->samplerate;
+ extralen / ac->sample_size,
+ ac->sample_size, ac->sample_padding);
+ int written = play(ao, paddingbuf, ao->buffer.len + extralen, 0);
+ if (written < ao->buffer.len) {
+ mp_msg(MSGT_ENCODE, MSGL_ERR,
+ "ao-lavc: did not write enough data at the end\n");
+ }
talloc_free(paddingbuf);
ao->buffer.len = 0;
}
- while (encode(ao, pts, NULL) > 0) ;
+
+ double outpts = ac->expected_next_pts;
+ if (!ectx->options->rawts && ectx->options->copyts)
+ outpts += ectx->discontinuity_pts_offset;
+ outpts += encode_lavc_getoffset(ectx, ac->stream);
+
+ while (encode(ao, outpts, NULL) > 0) ;
}
ao->priv = NULL;
@@ -494,11 +505,12 @@ static int play(struct ao *ao, void *data, int len, int flags)
if (!encode_lavc_start(ectx)) {
mp_msg(MSGT_ENCODE, MSGL_WARN,
- "ao-lavc: not ready yet for encoding audio\n");
+ "ao-lavc: not ready yet for encoding audio\n");
return 0;
}
if (pts == MP_NOPTS_VALUE) {
- mp_msg(MSGT_ENCODE, MSGL_WARN, "ao-lavc: frame without pts, please report; synthesizing pts instead\n");
+ mp_msg(MSGT_ENCODE, MSGL_WARN,
+ "ao-lavc: frame without pts, please report; synthesizing pts instead\n");
// synthesize pts from previous expected next pts
pts = ac->expected_next_pts;
}