summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-11-08 20:02:09 +0100
committerwm4 <wm4@nowhere>2013-11-08 20:29:26 +0100
commit6354a6b07dd3e0aee23e71ee2574754d620bdd09 (patch)
tree2cd4137ddec69890434273774d4571786668e9e2 /mpvcore
parent8125252399d9b02a6f143d109a92341ff7eff5a9 (diff)
downloadmpv-6354a6b07dd3e0aee23e71ee2574754d620bdd09.tar.bz2
mpv-6354a6b07dd3e0aee23e71ee2574754d620bdd09.tar.xz
player: factor audio buffer clearing code
Note that the change in seek_reset is not entirely equivalent: we even drop the remainder of buffered audio when seeking. This should be more correct, because the whole point of the reset_ao parameter is to control whether audio queued for output should be dropped or not.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/player/audio.c17
-rw-r--r--mpvcore/player/loadfile.c8
-rw-r--r--mpvcore/player/mp_core.h2
-rw-r--r--mpvcore/player/playloop.c11
4 files changed, 25 insertions, 13 deletions
diff --git a/mpvcore/player/audio.c b/mpvcore/player/audio.c
index 2c3d044c41..a0c558f02a 100644
--- a/mpvcore/player/audio.c
+++ b/mpvcore/player/audio.c
@@ -421,3 +421,20 @@ int fill_audio_out_buffers(struct MPContext *mpctx, double endpts)
return signal_eof ? -2 : -partial_fill;
}
+
+// Drop data queued for output, or which the AO is currently outputting.
+void clear_audio_output_buffers(struct MPContext *mpctx)
+{
+ if (mpctx->ao) {
+ ao_reset(mpctx->ao);
+ mpctx->ao->buffer.len = 0;
+ mpctx->ao->buffer_playable_size = 0;
+ }
+}
+
+// Drop decoded data queued for filtering.
+void clear_audio_decode_buffers(struct MPContext *mpctx)
+{
+ if (mpctx->sh_audio)
+ mpctx->sh_audio->a_buffer_len = 0;
+}
diff --git a/mpvcore/player/loadfile.c b/mpvcore/player/loadfile.c
index 569532840c..a35da703ed 100644
--- a/mpvcore/player/loadfile.c
+++ b/mpvcore/player/loadfile.c
@@ -1292,12 +1292,8 @@ terminate_playback: // don't jump here after ao/vo/getch initialization!
if (mpctx->stop_play == KEEP_PLAYING)
mpctx->stop_play = AT_END_OF_FILE;
- // Drop audio left in the buffers
- if (mpctx->stop_play != AT_END_OF_FILE && mpctx->ao) {
- mpctx->ao->buffer_playable_size = 0;
- mpctx->ao->buffer.len = 0;
- ao_reset(mpctx->ao);
- }
+ if (mpctx->stop_play != AT_END_OF_FILE)
+ clear_audio_output_buffers(mpctx);
if (opts->position_save_on_quit && mpctx->stop_play == PT_QUIT)
mp_write_watch_later_conf(mpctx);
diff --git a/mpvcore/player/mp_core.h b/mpvcore/player/mp_core.h
index 05909543f4..3f20f9ab2e 100644
--- a/mpvcore/player/mp_core.h
+++ b/mpvcore/player/mp_core.h
@@ -330,6 +330,8 @@ int reinit_audio_filters(struct MPContext *mpctx);
double playing_audio_pts(struct MPContext *mpctx);
int fill_audio_out_buffers(struct MPContext *mpctx, double endpts);
double written_audio_pts(struct MPContext *mpctx);
+void clear_audio_output_buffers(struct MPContext *mpctx);
+void clear_audio_decode_buffers(struct MPContext *mpctx);
// configfiles.c
bool mp_parse_cfgfiles(struct MPContext *mpctx);
diff --git a/mpvcore/player/playloop.c b/mpvcore/player/playloop.c
index 6cd53214a2..9d5b4a5e25 100644
--- a/mpvcore/player/playloop.c
+++ b/mpvcore/player/playloop.c
@@ -185,9 +185,8 @@ static void seek_reset(struct MPContext *mpctx, bool reset_ao, bool reset_ac)
if (mpctx->sh_audio && reset_ac) {
resync_audio_stream(mpctx->sh_audio);
if (reset_ao)
- ao_reset(mpctx->ao);
- mpctx->ao->buffer.len = mpctx->ao->buffer_playable_size;
- mpctx->sh_audio->a_buffer_len = 0;
+ clear_audio_output_buffers(mpctx);
+ clear_audio_decode_buffers(mpctx);
}
reset_subtitles(mpctx);
@@ -256,10 +255,8 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
mpctx->stop_play = AT_END_OF_FILE;
if (mpctx->sh_audio && !timeline_fallthrough) {
// Seek outside of the file -> clear audio from current position
- ao_reset(mpctx->ao);
- mpctx->sh_audio->a_buffer_len = 0;
- mpctx->ao->buffer.len = 0;
- mpctx->ao->buffer_playable_size = 0;
+ clear_audio_decode_buffers(mpctx);
+ clear_audio_output_buffers(mpctx);
}
return -1;
}