Skip to content

Commit

Permalink
Shut down existing streams if they exist
Browse files Browse the repository at this point in the history
This leaves the stream structures intact, but puts them into "standby",
which essentially means that just the pcm is closed. The pcm is only
opened in the functions out_write and in_read, so in those functions,
we simply return before it opens the pcm with a return value that
indicates that the read or write was successful.

Change-Id: I0222f111ccab4dadad58fa4c89c7d731a1bbd975
  • Loading branch information
ASerbinski committed Jan 25, 2018
1 parent e513481 commit 0940730
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions usbaudio/audio_hal.c
Expand Up @@ -521,6 +521,8 @@ static ssize_t out_write(struct audio_stream_out *stream, const void* buffer, si
int ret;
struct stream_out *out = (struct stream_out *)stream;

if (out->adev->sco_thread != 0) return bytes;

stream_lock(&out->lock);
if (out->standby) {
device_lock(out->adev);
Expand Down Expand Up @@ -941,6 +943,8 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer, size_t byte

struct stream_in * in = (struct stream_in *)stream;

if (in->adev->sco_thread != 0) return bytes;

stream_lock(&in->lock);
if (in->standby) {
device_lock(in->adev);
Expand Down Expand Up @@ -1319,6 +1323,21 @@ fseek(out_far, sizeof(struct wav_header), SEEK_SET);

ALOGD("%s: USBCARD: %d, BTCARD: %d", __func__, adev->usbcard, adev->btcard);

// Put all existing streams into standby (closed). Note that when sco thread is running
// out_write and in_read functions will bail immediately while pretending to work and
// not opening the pcm's.
struct listnode* node;

list_for_each(node, &adev->output_stream_list) {
struct audio_stream* stream = (struct audio_stream *)node_to_item(node, struct stream_out, list_node);
out_standby((struct audio_stream_out *)stream);
}

list_for_each(node, &adev->input_stream_list) {
struct audio_stream* stream = (struct audio_stream *)node_to_item(node, struct stream_in, list_node);
in_standby((struct audio_stream_in *)stream);
}

adev->sco_pcm_far_in = pcm_open(adev->btcard, 0, PCM_IN, &bt_config);
if (adev->sco_pcm_far_in == 0) {
ALOGD("%s: failed to allocate memory for PCM far/in", __func__);
Expand Down Expand Up @@ -1392,24 +1411,28 @@ fseek(out_far, sizeof(struct wav_header), SEEK_SET);
pcm_close(adev->sco_pcm_near_out);
pcm_close(adev->sco_pcm_far_in);
pcm_close(adev->sco_pcm_far_out);
adev->sco_pcm_near_in = 0;
adev->sco_pcm_near_out = 0;
adev->sco_pcm_far_in = 0;
adev->sco_pcm_far_out = 0;
return NULL;
}

rc = create_resampler(adev->sco_samplerate, 48000, 1, RESAMPLER_QUALITY_DEFAULT, NULL, &resampler_to48);
if (rc != 0) {
resampler_to48 = NULL;
ALOGD("%s: echo_reference_write() failure to create resampler %d", __func__, rc);
pcm_close(adev->sco_pcm_near_in);
pcm_close(adev->sco_pcm_near_out);
pcm_close(adev->sco_pcm_far_in);
pcm_close(adev->sco_pcm_far_out);
return NULL;
}

rc = create_resampler(48000, adev->sco_samplerate, 1, RESAMPLER_QUALITY_DEFAULT, NULL, &resampler_from48);
if (rc != 0) {
resampler_from48 = NULL;
ALOGD("%s: echo_reference_write() failure to create resampler %d", __func__, rc);
pcm_close(adev->sco_pcm_near_in);
pcm_close(adev->sco_pcm_near_out);
pcm_close(adev->sco_pcm_far_in);
pcm_close(adev->sco_pcm_far_out);
return NULL;
}

Expand Down

0 comments on commit 0940730

Please sign in to comment.