Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shutdown audio pipe when closing input stream

Writing to the audio pipe for the remote submix is blocking, unless
 the audio output pipe is in shutdown mode. The playback thread
 could stay blocked on the write if the input stream has already
 been closed.
The change consists in shutting down the pipe also when the input
 stream gets closed. When the pipe is in this state, simulate
 timing in the write operation so we don't drain the output faster
 than realtime.

Bug 7424646

Change-Id: I5feb3be642b0ee7eef10dee0141308684ee9c811
  • Loading branch information...
commit 90b0fbd13f97127e29ea565c09b64cc25ab6e9c9 1 parent 20c7f50
@jmtrivi jmtrivi authored
Showing with 16 additions and 2 deletions.
  1. +16 −2 modules/audio_remote_submix/audio_hw.cpp
View
18 modules/audio_remote_submix/audio_hw.cpp
@@ -233,12 +233,22 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
ssize_t written_frames = 0;
struct submix_stream_out *out = reinterpret_cast<struct submix_stream_out *>(stream);
+ const size_t frame_size = audio_stream_frame_size(&stream->common);
+ const size_t frames = bytes / frame_size;
+
pthread_mutex_lock(&out->dev->lock);
out->dev->output_standby = false;
MonoPipe* sink = out->dev->rsxSink.get();
if (sink != NULL) {
+ if (sink->isShutdown()) {
+ pthread_mutex_unlock(&out->dev->lock);
+ // the pipe has already been shutdown, this buffer will be lost but we must
+ // simulate timing so we don't drain the output faster than realtime
+ usleep(frames * 1000000 / out_get_sample_rate(&stream->common));
+ return bytes;
+ }
sink->incStrong(buffer);
} else {
pthread_mutex_unlock(&out->dev->lock);
@@ -249,8 +259,6 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
pthread_mutex_unlock(&out->dev->lock);
- const size_t frame_size = audio_stream_frame_size(&stream->common);
- const size_t frames = bytes / frame_size;
written_frames = sink->write(buffer, frames);
if (written_frames < 0) {
if (written_frames == (ssize_t)NEGOTIATE) {
@@ -741,6 +749,12 @@ static void adev_close_input_stream(struct audio_hw_device *dev,
pthread_mutex_lock(&rsxadev->lock);
+ MonoPipe* sink = rsxadev->rsxSink.get();
+ if (sink != NULL) {
+ ALOGI("shutdown");
+ sink->shutdown(true);
+ }
+
free(stream);
pthread_mutex_unlock(&rsxadev->lock);
Please sign in to comment.
Something went wrong with that request. Please try again.