diff options
author | Chinyue Chen <chinyue@chromium.org> | 2017-05-23 03:05:57 +0000 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-05-23 03:03:17 -0700 |
commit | 2e14c232763ac89fd9d2fa5e9b3fdcf6581b2db8 (patch) | |
tree | 71872e0a58f61d10cc20ae1c985f6b7c23c31e14 | |
parent | 70182dd089ce9646f371ce0188ce4423d7f64f6a (diff) | |
download | adhd-2e14c232763ac89fd9d2fa5e9b3fdcf6581b2db8.tar.gz |
Revert "CRAS: Deduplicate snd_pcm_open calls when opening a device."
This reverts commit 70182dd089ce9646f371ce0188ce4423d7f64f6a.
Reason for revert: broke the external mic on cyan and celes
Original change's description:
> CRAS: Deduplicate snd_pcm_open calls when opening a device.
>
> The current open device flow includes several functions like
> cras_alsa_fill_properties and update_channel_layout. They are used only
> once in the flow but each calls snd_pcm_open and then snd_pcm_close the
> device. Since snd_pcm_open is one of the most time-consuming hardware
> operations, the CL extracts the snd_pcm_open calls to the beginning of
> the device open flow to save time.
>
> 1. Update cras_alsa_fill_properties and update_channel_layout to take a
> handle as argument and do not invoke snd_pcm_open.
> 2. Rename existing open_dev functions to configure_dev. open_dev is now
> called at the beginning of the device open flow and invokes the
> snd_pcm_open call.
> 3. Put open_dev, cras_iodev_set_format, and configure_dev inside the
> cras_iodev_open function.
>
> BUG=b:719812
> TEST=make check and tested on reef
> Cuts time to open speakers from 78ms to 42ms
>
> Change-Id: I9b161217def5e87bf892f4ca8148f07bed5e71a5
> Reviewed-on: https://chromium-review.googlesource.com/505974
> Commit-Ready: Chinyue Chen <chinyue@chromium.org>
> Tested-by: Chinyue Chen <chinyue@chromium.org>
> Reviewed-by: Dylan Reid <dgreid@chromium.org>
>
BUG=b:719812
Change-Id: I22eb2fc70b4a5003a861be62d31bc2337b9918c3
Reviewed-on: https://chromium-review.googlesource.com/511982
Commit-Ready: Chinyue Chen <chinyue@chromium.org>
Tested-by: Chinyue Chen <chinyue@chromium.org>
Reviewed-by: Chinyue Chen <chinyue@chromium.org>
-rw-r--r-- | cras/src/server/cras_a2dp_iodev.c | 4 | ||||
-rw-r--r-- | cras/src/server/cras_alsa_helpers.c | 13 | ||||
-rw-r--r-- | cras/src/server/cras_alsa_helpers.h | 5 | ||||
-rw-r--r-- | cras/src/server/cras_alsa_io.c | 64 | ||||
-rw-r--r-- | cras/src/server/cras_bt_io.c | 6 | ||||
-rw-r--r-- | cras/src/server/cras_empty_iodev.c | 4 | ||||
-rw-r--r-- | cras/src/server/cras_hfp_iodev.c | 4 | ||||
-rw-r--r-- | cras/src/server/cras_iodev.c | 23 | ||||
-rw-r--r-- | cras/src/server/cras_iodev.h | 5 | ||||
-rw-r--r-- | cras/src/server/cras_iodev_list.c | 8 | ||||
-rw-r--r-- | cras/src/server/cras_loopback_iodev.c | 4 | ||||
-rw-r--r-- | cras/src/server/test_iodev.c | 4 | ||||
-rw-r--r-- | cras/src/tests/a2dp_iodev_unittest.cc | 8 | ||||
-rw-r--r-- | cras/src/tests/alsa_io_unittest.cc | 16 | ||||
-rw-r--r-- | cras/src/tests/audio_thread_unittest.cc | 7 | ||||
-rw-r--r-- | cras/src/tests/bt_device_unittest.cc | 4 | ||||
-rw-r--r-- | cras/src/tests/bt_io_unittest.cc | 16 | ||||
-rw-r--r-- | cras/src/tests/hfp_iodev_unittest.cc | 6 | ||||
-rw-r--r-- | cras/src/tests/iodev_list_unittest.cc | 3 | ||||
-rw-r--r-- | cras/src/tests/iodev_unittest.cc | 42 | ||||
-rw-r--r-- | cras/src/tests/loopback_iodev_unittest.cc | 6 |
21 files changed, 119 insertions, 133 deletions
diff --git a/cras/src/server/cras_a2dp_iodev.c b/cras/src/server/cras_a2dp_iodev.c index 75aa71f4..a9551a12 100644 --- a/cras/src/server/cras_a2dp_iodev.c +++ b/cras/src/server/cras_a2dp_iodev.c @@ -135,7 +135,7 @@ static int frames_queued(const struct cras_iodev *iodev, MAX(estimate_queued_frames, local_queued_frames)); } -static int configure_dev(struct cras_iodev *iodev) +static int open_dev(struct cras_iodev *iodev) { struct a2dp_io *a2dpio = (struct a2dp_io *)iodev; int sock_depth; @@ -484,7 +484,7 @@ struct cras_iodev *a2dp_iodev_create(struct cras_bt_transport *transport) strlen(cras_bt_device_object_path(device))); iodev->info.stable_id_new = iodev->info.stable_id; - iodev->configure_dev = configure_dev; + iodev->open_dev = open_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->get_buffer = get_buffer; diff --git a/cras/src/server/cras_alsa_helpers.c b/cras/src/server/cras_alsa_helpers.c index fd411d00..a8719c2c 100644 --- a/cras/src/server/cras_alsa_helpers.c +++ b/cras/src/server/cras_alsa_helpers.c @@ -385,16 +385,25 @@ done: return rc; } -int cras_alsa_fill_properties(snd_pcm_t *handle, +int cras_alsa_fill_properties(const char *dev, snd_pcm_stream_t stream, size_t **rates, size_t **channel_counts, snd_pcm_format_t **formats) { int rc; + snd_pcm_t *handle; size_t i, num_found; snd_pcm_hw_params_t *params; snd_pcm_hw_params_alloca(¶ms); + rc = cras_alsa_pcm_open(&handle, + dev, + stream); + if (rc < 0) { + syslog(LOG_ERR, "snd_pcm_open_failed: %s", snd_strerror(rc)); + return rc; + } + rc = snd_pcm_hw_params_any(handle, params); if (rc < 0) { snd_pcm_close(handle); @@ -448,6 +457,8 @@ int cras_alsa_fill_properties(snd_pcm_t *handle, } (*formats)[num_found] = (snd_pcm_format_t)0; + snd_pcm_close(handle); + return 0; } diff --git a/cras/src/server/cras_alsa_helpers.h b/cras/src/server/cras_alsa_helpers.h index 3cb98640..33c33908 100644 --- a/cras/src/server/cras_alsa_helpers.h +++ b/cras/src/server/cras_alsa_helpers.h @@ -105,7 +105,8 @@ int cras_alsa_resume_appl_ptr(snd_pcm_t *handle, snd_pcm_uframes_t ahead); /* Probes properties of the alsa device. * Args: - * handle - The open PCM to configure. + * dev - Path to the alsa device to test. + * stream - Alsa stream type, input or output. * rates - Pointer that will be set to the arrary of valid samples rates. * Must be freed by the caller. * channel_counts - Pointer that will be set to the array of valid channel @@ -115,7 +116,7 @@ int cras_alsa_resume_appl_ptr(snd_pcm_t *handle, snd_pcm_uframes_t ahead); * Returns: * 0 on success. On failure an error code from alsa or -ENOMEM. */ -int cras_alsa_fill_properties(snd_pcm_t *handle, +int cras_alsa_fill_properties(const char *dev, snd_pcm_stream_t stream, size_t **rates, size_t **channel_counts, snd_pcm_format_t **formats); diff --git a/cras/src/server/cras_alsa_io.c b/cras/src/server/cras_alsa_io.c index f67e17f6..80a8c3b3 100644 --- a/cras/src/server/cras_alsa_io.c +++ b/cras/src/server/cras_alsa_io.c @@ -323,20 +323,6 @@ static int open_dev(struct cras_iodev *iodev) { struct alsa_io *aio = (struct alsa_io *)iodev; snd_pcm_t *handle; - int rc; - - rc = cras_alsa_pcm_open(&handle, aio->dev, aio->alsa_stream); - if (rc < 0) - return rc; - - aio->handle = handle; - - return 0; -} - -static int configure_dev(struct cras_iodev *iodev) -{ - struct alsa_io *aio = (struct alsa_io *)iodev; int period_wakeup; int rc; @@ -356,28 +342,39 @@ static int configure_dev(struct cras_iodev *iodev) syslog(LOG_DEBUG, "Configure alsa device %s rate %zuHz, %zu channels", aio->dev, iodev->format->frame_rate, iodev->format->num_channels); + handle = 0; /* Avoid unused warning. */ + rc = cras_alsa_pcm_open(&handle, aio->dev, aio->alsa_stream); + if (rc < 0) + return rc; /* If it's a wake on voice device, period_wakeups are required. */ period_wakeup = (iodev->active_node->type == CRAS_NODE_TYPE_HOTWORD); - rc = cras_alsa_set_hwparams(aio->handle, iodev->format, + rc = cras_alsa_set_hwparams(handle, iodev->format, &iodev->buffer_size, period_wakeup, aio->dma_period_set_microsecs); - if (rc < 0) + if (rc < 0) { + cras_alsa_pcm_close(handle); return rc; + } /* Set channel map to device */ - rc = cras_alsa_set_channel_map(aio->handle, + rc = cras_alsa_set_channel_map(handle, iodev->format); - if (rc < 0) + if (rc < 0) { + cras_alsa_pcm_close(handle); return rc; + } /* Configure software params. */ - rc = cras_alsa_set_swparams(aio->handle, &aio->enable_htimestamp); - if (rc < 0) + rc = cras_alsa_set_swparams(handle, &aio->enable_htimestamp); + if (rc < 0) { + cras_alsa_pcm_close(handle); return rc; + } - /* Initialize device settings. */ + /* Assign pcm handle then initialize device settings. */ + aio->handle = handle; init_device_settings(aio); aio->poll_fd = -1; @@ -385,7 +382,7 @@ static int configure_dev(struct cras_iodev *iodev) struct pollfd *ufds; int count, i; - count = snd_pcm_poll_descriptors_count(aio->handle); + count = snd_pcm_poll_descriptors_count(handle); if (count <= 0) { syslog(LOG_ERR, "Invalid poll descriptors count\n"); return count; @@ -395,7 +392,7 @@ static int configure_dev(struct cras_iodev *iodev) if (ufds == NULL) return -ENOMEM; - rc = snd_pcm_poll_descriptors(aio->handle, ufds, count); + rc = snd_pcm_poll_descriptors(handle, ufds, count); if (rc < 0) { syslog(LOG_ERR, "Getting hotword poll descriptors: %s\n", @@ -555,6 +552,7 @@ static void update_active_node(struct cras_iodev *iodev, unsigned node_idx, static int update_channel_layout(struct cras_iodev *iodev) { struct alsa_io *aio = (struct alsa_io *)iodev; + snd_pcm_t *handle = NULL; snd_pcm_uframes_t buf_size = 0; int err = 0; @@ -572,14 +570,25 @@ static int update_channel_layout(struct cras_iodev *iodev) } } + err = cras_alsa_pcm_open(&handle, aio->dev, aio->alsa_stream); + if (err < 0) { + syslog(LOG_ERR, "snd_pcm_open_failed: %s", snd_strerror(err)); + return err; + } + /* Sets frame rate and channel count to alsa device before * we test channel mapping. */ - err = cras_alsa_set_hwparams(aio->handle, iodev->format, &buf_size, 0, + err = cras_alsa_set_hwparams(handle, iodev->format, &buf_size, 0, aio->dma_period_set_microsecs); - if (err < 0) + if (err < 0) { + cras_alsa_pcm_close(handle); return err; + } + + err = cras_alsa_get_channel_map(handle, iodev->format); - return cras_alsa_get_channel_map(aio->handle, iodev->format); + cras_alsa_pcm_close(handle); + return err; } static int set_hotword_model(struct cras_iodev *iodev, const char *model_name) @@ -1560,7 +1569,7 @@ static int update_supported_formats(struct cras_iodev *iodev) free(iodev->supported_formats); iodev->supported_formats = NULL; - err = cras_alsa_fill_properties(aio->handle, + err = cras_alsa_fill_properties(aio->dev, aio->alsa_stream, &iodev->supported_rates, &iodev->supported_channel_counts, &iodev->supported_formats); @@ -1852,7 +1861,6 @@ struct cras_iodev *alsa_iodev_create(size_t card_index, aio->base.output_underrun = alsa_output_underrun; } iodev->open_dev = open_dev; - iodev->configure_dev = configure_dev; iodev->close_dev = close_dev; iodev->update_supported_formats = update_supported_formats; iodev->frames_queued = frames_queued; diff --git a/cras/src/server/cras_bt_io.c b/cras/src/server/cras_bt_io.c index c5bdc5fb..1363d90d 100644 --- a/cras/src/server/cras_bt_io.c +++ b/cras/src/server/cras_bt_io.c @@ -173,7 +173,7 @@ static int update_supported_formats(struct cras_iodev *iodev) return 0; } -static int configure_dev(struct cras_iodev *iodev) +static int open_dev(struct cras_iodev *iodev) { int rc; struct cras_iodev *dev = active_profile_dev(iodev); @@ -183,7 +183,7 @@ static int configure_dev(struct cras_iodev *iodev) /* Fill back the format iodev is using. */ *dev->format = *iodev->format; - rc = dev->configure_dev(dev); + rc = dev->open_dev(dev); if (rc) { /* Free format here to assure the update_supported_format * callback will be called before any future open_dev call. */ @@ -331,7 +331,7 @@ struct cras_iodev *cras_bt_io_create(struct cras_bt_device *device, iodev->info.stable_id = dev->info.stable_id; iodev->info.stable_id_new = dev->info.stable_id_new; - iodev->configure_dev = configure_dev; + iodev->open_dev = open_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->get_buffer = get_buffer; diff --git a/cras/src/server/cras_empty_iodev.c b/cras/src/server/cras_empty_iodev.c index 1e1255cd..4616cd3c 100644 --- a/cras/src/server/cras_empty_iodev.c +++ b/cras/src/server/cras_empty_iodev.c @@ -93,7 +93,7 @@ static int close_dev(struct cras_iodev *iodev) return 0; } -static int configure_dev(struct cras_iodev *iodev) +static int open_dev(struct cras_iodev *iodev) { struct empty_iodev *empty_iodev = (struct empty_iodev *)iodev; @@ -196,7 +196,7 @@ struct cras_iodev *empty_iodev_create(enum CRAS_STREAM_DIRECTION direction) iodev->supported_formats = empty_supported_formats; iodev->buffer_size = EMPTY_FRAMES; - iodev->configure_dev = configure_dev; + iodev->open_dev = open_dev; iodev->close_dev = close_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; diff --git a/cras/src/server/cras_hfp_iodev.c b/cras/src/server/cras_hfp_iodev.c index 129f6fc7..10314e63 100644 --- a/cras/src/server/cras_hfp_iodev.c +++ b/cras/src/server/cras_hfp_iodev.c @@ -74,7 +74,7 @@ static void hfp_packet_size_changed(void *data) cras_bt_device_iodev_buffer_size_changed(hfpio->device); } -static int configure_dev(struct cras_iodev *iodev) +static int open_dev(struct cras_iodev *iodev) { struct hfp_io *hfpio = (struct hfp_io *)iodev; int sk, err, mtu; @@ -242,7 +242,7 @@ struct cras_iodev *hfp_iodev_create( strlen(cras_bt_device_object_path(device))); iodev->info.stable_id_new = iodev->info.stable_id; - iodev->configure_dev= configure_dev; + iodev->open_dev= open_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->get_buffer = get_buffer; diff --git a/cras/src/server/cras_iodev.c b/cras/src/server/cras_iodev.c index 138a3f4a..69e65dbf 100644 --- a/cras/src/server/cras_iodev.c +++ b/cras/src/server/cras_iodev.c @@ -820,30 +820,13 @@ unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) return max; } -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt) +int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level) { int rc; - if (iodev->open_dev) { - rc = iodev->open_dev(iodev); - if (rc) - return rc; - } - - if (iodev->ext_format == NULL) { - rc = cras_iodev_set_format(iodev, fmt); - if (rc) { - iodev->close_dev(iodev); - return rc; - } - } - - rc = iodev->configure_dev(iodev); - if (rc < 0) { - iodev->close_dev(iodev); + rc = iodev->open_dev(iodev); + if (rc < 0) return rc; - } /* Make sure the min_cb_level doesn't get too large. */ iodev->min_cb_level = MIN(iodev->buffer_size / 2, cb_level); diff --git a/cras/src/server/cras_iodev.h b/cras/src/server/cras_iodev.h index 3e564ed9..51a00038 100644 --- a/cras/src/server/cras_iodev.h +++ b/cras/src/server/cras_iodev.h @@ -99,7 +99,6 @@ struct cras_ionode { * set_capture_mute - Function to call if the system capture mute state changes. * set_swap_mode_for_node - Function to call to set swap mode for the node. * open_dev - Opens the device. - * configure_dev - Configures the device. * close_dev - Closes the device if it is open. * update_supported_formats - Refresh supported frame rates and channel counts. * frames_queued - The number of frames in the audio buffer, and fills tstamp @@ -180,7 +179,6 @@ struct cras_iodev { struct cras_ionode *node, int enable); int (*open_dev)(struct cras_iodev *iodev); - int (*configure_dev)(struct cras_iodev *iodev); int (*close_dev)(struct cras_iodev *iodev); int (*update_supported_formats)(struct cras_iodev *iodev); int (*frames_queued)(const struct cras_iodev *iodev, @@ -497,8 +495,7 @@ unsigned int cras_iodev_all_streams_written(struct cras_iodev *iodev); enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev); /* Open an iodev, does setup and invokes the open_dev callback. */ -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt); +int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level); /* Open an iodev, does teardown and invokes the close_dev callback. */ int cras_iodev_close(struct cras_iodev *iodev); diff --git a/cras/src/server/cras_iodev_list.c b/cras/src/server/cras_iodev_list.c index 0dece3ae..b89767ec 100644 --- a/cras/src/server/cras_iodev_list.c +++ b/cras/src/server/cras_iodev_list.c @@ -430,7 +430,13 @@ static int init_device(struct cras_iodev *dev, if (cras_iodev_is_open(dev)) return 0; - rc = cras_iodev_open(dev, rstream->cb_threshold, &rstream->format); + if (dev->ext_format == NULL) { + rc = cras_iodev_set_format(dev, &rstream->format); + if (rc) + return rc; + } + + rc = cras_iodev_open(dev, rstream->cb_threshold); if (rc) return rc; diff --git a/cras/src/server/cras_loopback_iodev.c b/cras/src/server/cras_loopback_iodev.c index d569da81..ff33acaf 100644 --- a/cras/src/server/cras_loopback_iodev.c +++ b/cras/src/server/cras_loopback_iodev.c @@ -170,7 +170,7 @@ static int close_record_dev(struct cras_iodev *iodev) return 0; } -static int configure_record_dev(struct cras_iodev *iodev) +static int open_record_dev(struct cras_iodev *iodev) { struct loopback_iodev *loopdev = (struct loopback_iodev *)iodev; struct cras_iodev *edev; @@ -265,7 +265,7 @@ static struct cras_iodev *create_loopback_iodev(enum CRAS_LOOPBACK_TYPE type) iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; iodev->update_active_node = update_active_node; - iodev->configure_dev = configure_record_dev; + iodev->open_dev = open_record_dev; iodev->close_dev = close_record_dev; iodev->get_buffer = get_record_buffer; iodev->put_buffer = put_record_buffer; diff --git a/cras/src/server/test_iodev.c b/cras/src/server/test_iodev.c index 1db90581..4955726e 100644 --- a/cras/src/server/test_iodev.c +++ b/cras/src/server/test_iodev.c @@ -73,7 +73,7 @@ static int close_dev(struct cras_iodev *iodev) return 0; } -static int configure_dev(struct cras_iodev *iodev) +static int open_dev(struct cras_iodev *iodev) { struct test_iodev *testio = (struct test_iodev *)iodev; @@ -193,7 +193,7 @@ struct cras_iodev *test_iodev_create(enum CRAS_STREAM_DIRECTION direction, iodev->supported_formats = test_supported_formats; iodev->buffer_size = TEST_BUFFER_SIZE; - iodev->configure_dev = configure_dev; + iodev->open_dev = open_dev; iodev->close_dev = close_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; diff --git a/cras/src/tests/a2dp_iodev_unittest.cc b/cras/src/tests/a2dp_iodev_unittest.cc index f37fe2e9..6e8e3c77 100644 --- a/cras/src/tests/a2dp_iodev_unittest.cc +++ b/cras/src/tests/a2dp_iodev_unittest.cc @@ -161,7 +161,7 @@ TEST(A2dpIoInit, OpenIodev) { iodev = a2dp_iodev_create(fake_transport); iodev_set_format(iodev, &format); - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_EQ(1, cras_bt_transport_acquire_called); @@ -183,7 +183,7 @@ TEST(A2dpIoInit, GetPutBuffer) { iodev = a2dp_iodev_create(fake_transport); iodev_set_format(iodev, &format); - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_NE(write_callback, (void *)NULL); frames = 256; @@ -248,7 +248,7 @@ TEST(A2dpIoInif, FramesQueued) { iodev_set_format(iodev, &format); time_now.tv_sec = 0; time_now.tv_nsec = 0; - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_NE(write_callback, (void *)NULL); frames = 256; @@ -317,7 +317,7 @@ TEST(A2dpIo, FlushAtLowBufferLevel) { iodev_set_format(iodev, &format); time_now.tv_sec = 0; time_now.tv_nsec = 0; - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_NE(write_callback, (void *)NULL); ASSERT_EQ(iodev->min_buffer_level, 400); diff --git a/cras/src/tests/alsa_io_unittest.cc b/cras/src/tests/alsa_io_unittest.cc index 341361d6..dc58cd75 100644 --- a/cras/src/tests/alsa_io_unittest.cc +++ b/cras/src/tests/alsa_io_unittest.cc @@ -400,8 +400,6 @@ TEST(AlsaIoInit, OpenPlayback) { aio->filled_zeros_for_draining = 512; iodev->open_dev(iodev); EXPECT_EQ(1, cras_alsa_open_called); - iodev->configure_dev(iodev); - EXPECT_EQ(1, cras_alsa_open_called); EXPECT_EQ(1, sys_set_volume_limits_called); EXPECT_EQ(1, alsa_mixer_set_dBFS_called); EXPECT_EQ(0, cras_alsa_start_called); @@ -654,8 +652,6 @@ TEST(AlsaIoInit, OpenCapture) { ResetStubData(); iodev->open_dev(iodev); EXPECT_EQ(1, cras_alsa_open_called); - iodev->configure_dev(iodev); - EXPECT_EQ(1, cras_alsa_open_called); EXPECT_EQ(1, cras_alsa_mixer_get_minimum_capture_gain_called); EXPECT_EQ(1, cras_alsa_mixer_get_maximum_capture_gain_called); EXPECT_EQ(1, sys_set_capture_gain_limits_called); @@ -698,7 +694,6 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithDefaultNodeGain) { sys_get_capture_gain_return_value = system_gain; iodev->open_dev(iodev); - iodev->configure_dev(iodev); iodev->close_dev(iodev); // Hardware gain is set to 2000 - 1000 dBm. @@ -731,7 +726,6 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithSoftwareGain) { sys_get_capture_gain_return_value = 1000; iodev->open_dev(iodev); - iodev->configure_dev(iodev); iodev->close_dev(iodev); /* Hardware gain is set to 0dB when software gain is used. */ @@ -740,7 +734,6 @@ TEST(AlsaIoInit, OpenCaptureSetCaptureGainWithSoftwareGain) { /* Test the case where software gain is not needed. */ iodev->active_node->software_volume_needed = 0; iodev->open_dev(iodev); - iodev->configure_dev(iodev); iodev->close_dev(iodev); /* Hardware gain is set to 1000dBm as got from system capture gain.*/ @@ -1792,7 +1785,7 @@ TEST_F(AlsaVolumeMuteSuite, GetDefaultVolumeCurve) { aio_output_->base.format = fmt; aio_output_->handle = (snd_pcm_t *)0x24; - rc = aio_output_->base.configure_dev(&aio_output_->base); + rc = aio_output_->base.open_dev(&aio_output_->base); ASSERT_EQ(0, rc); EXPECT_EQ(&default_curve, fake_get_dBFS_volume_curve_val); @@ -1827,7 +1820,7 @@ TEST_F(AlsaVolumeMuteSuite, GetVolumeCurveFromNode) node = aio_output_->base.nodes->next; aio_output_->base.active_node = node; - rc = aio_output_->base.configure_dev(&aio_output_->base); + rc = aio_output_->base.open_dev(&aio_output_->base); ASSERT_EQ(0, rc); EXPECT_EQ(&hp_curve, fake_get_dBFS_volume_curve_val); @@ -1848,7 +1841,7 @@ TEST_F(AlsaVolumeMuteSuite, SetVolume) { aio_output_->num_underruns = 3; // Something non-zero. sys_get_volume_return_value = fake_system_volume; - rc = aio_output_->base.configure_dev(&aio_output_->base); + rc = aio_output_->base.open_dev(&aio_output_->base); ASSERT_EQ(0, rc); EXPECT_EQ(1, alsa_mixer_set_dBFS_called); EXPECT_EQ(fake_system_volume_dB, alsa_mixer_set_dBFS_value); @@ -2195,7 +2188,8 @@ int cras_alsa_pcm_drain(snd_pcm_t *handle) { return 0; } -int cras_alsa_fill_properties(snd_pcm_t *handle, +int cras_alsa_fill_properties(const char *dev, + snd_pcm_stream_t stream, size_t **rates, size_t **channel_counts, snd_pcm_format_t **formats) diff --git a/cras/src/tests/audio_thread_unittest.cc b/cras/src/tests/audio_thread_unittest.cc index 314b4534..e1501260 100644 --- a/cras/src/tests/audio_thread_unittest.cc +++ b/cras/src/tests/audio_thread_unittest.cc @@ -91,7 +91,7 @@ class StreamDeviceSuite : public testing::Test { memset(iodev, 0, sizeof(*iodev)); iodev->info.idx = ++device_id_; iodev->direction = direction; - iodev->configure_dev = configure_dev; + iodev->open_dev = open_dev; iodev->close_dev = close_dev; iodev->frames_queued = frames_queued; iodev->delay_frames = delay_frames; @@ -133,7 +133,7 @@ class StreamDeviceSuite : public testing::Test { rstream->pinned_dev_idx = pin_to_dev->info.idx; } - static int configure_dev(cras_iodev* iodev) { + static int open_dev(cras_iodev* iodev) { open_dev_called_++; return 0; } @@ -709,8 +709,7 @@ unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) return 0; } -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt) +int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level) { return 0; } diff --git a/cras/src/tests/bt_device_unittest.cc b/cras/src/tests/bt_device_unittest.cc index 9f40aed5..4f7cd86c 100644 --- a/cras/src/tests/bt_device_unittest.cc +++ b/cras/src/tests/bt_device_unittest.cc @@ -260,9 +260,7 @@ int hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain) /* From iodev_list */ -int cras_iodev_open(struct cras_iodev *dev, unsigned int cb_level, - const struct cras_audio_format *fmt) -{ +int cras_iodev_open(struct cras_iodev *dev, unsigned int cb_level) { return 0; } diff --git a/cras/src/tests/bt_io_unittest.cc b/cras/src/tests/bt_io_unittest.cc index 63073fef..979404ac 100644 --- a/cras/src/tests/bt_io_unittest.cc +++ b/cras/src/tests/bt_io_unittest.cc @@ -62,7 +62,7 @@ class BtIoBasicSuite : public testing::Test { delay_frames_called_ = 0; get_buffer_called_ = 0; put_buffer_called_ = 0; - configure_dev_called_ = 0; + open_dev_called_ = 0; close_dev_called_ = 0; } @@ -77,7 +77,7 @@ class BtIoBasicSuite : public testing::Test { d->delay_frames = delay_frames; d->get_buffer = get_buffer; d->put_buffer = put_buffer; - d->configure_dev = configure_dev; + d->open_dev = open_dev; d->close_dev = close_dev; } @@ -118,8 +118,8 @@ class BtIoBasicSuite : public testing::Test { put_buffer_called_++; return 0; } - static int configure_dev(cras_iodev* iodev) { - configure_dev_called_++; + static int open_dev(cras_iodev* iodev) { + open_dev_called_++; return 0; } static int close_dev(cras_iodev* iodev) { @@ -135,7 +135,7 @@ class BtIoBasicSuite : public testing::Test { static unsigned int delay_frames_called_; static unsigned int get_buffer_called_; static unsigned int put_buffer_called_; - static unsigned int configure_dev_called_; + static unsigned int open_dev_called_; static unsigned int close_dev_called_; }; @@ -147,7 +147,7 @@ unsigned int BtIoBasicSuite::frames_queued_called_; unsigned int BtIoBasicSuite::delay_frames_called_; unsigned int BtIoBasicSuite::get_buffer_called_; unsigned int BtIoBasicSuite::put_buffer_called_; -unsigned int BtIoBasicSuite::configure_dev_called_; +unsigned int BtIoBasicSuite::open_dev_called_; unsigned int BtIoBasicSuite::close_dev_called_; TEST_F(BtIoBasicSuite, CreateBtIo) { @@ -164,8 +164,8 @@ TEST_F(BtIoBasicSuite, CreateBtIo) { bt_iodev->update_supported_formats(bt_iodev); EXPECT_EQ(1, update_supported_formats_called_); - bt_iodev->configure_dev(bt_iodev); - EXPECT_EQ(1, configure_dev_called_); + bt_iodev->open_dev(bt_iodev); + EXPECT_EQ(1, open_dev_called_); bt_iodev->frames_queued(bt_iodev, &tstamp); EXPECT_EQ(1, frames_queued_called_); bt_iodev->get_buffer(bt_iodev, &fake_area, &fr); diff --git a/cras/src/tests/hfp_iodev_unittest.cc b/cras/src/tests/hfp_iodev_unittest.cc index bf13e403..202bb135 100644 --- a/cras/src/tests/hfp_iodev_unittest.cc +++ b/cras/src/tests/hfp_iodev_unittest.cc @@ -116,7 +116,7 @@ TEST(HfpIodev, OpenHfpIodev) { /* hfp_info not start yet */ hfp_info_running_return_val = 0; - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_EQ(1, cras_bt_device_sco_connect_called); ASSERT_EQ(1, hfp_info_start_called); @@ -142,7 +142,7 @@ TEST(HfpIodev, OpenIodevWithHfpInfoAlreadyRunning) { /* hfp_info already started by another device */ hfp_info_running_return_val = 1; - iodev->configure_dev(iodev); + iodev->open_dev(iodev); ASSERT_EQ(0, cras_bt_device_sco_connect_called); ASSERT_EQ(0, hfp_info_start_called); @@ -164,7 +164,7 @@ TEST(HfpIodev, PutGetBuffer) { CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY, fake_info); iodev->format = &fake_format; - iodev->configure_dev(iodev); + iodev->open_dev(iodev); hfp_buf_acquire_return_val = 100; iodev->get_buffer(iodev, &area, &frames); diff --git a/cras/src/tests/iodev_list_unittest.cc b/cras/src/tests/iodev_list_unittest.cc index e5659acf..35b515d4 100644 --- a/cras/src/tests/iodev_list_unittest.cc +++ b/cras/src/tests/iodev_list_unittest.cc @@ -1441,8 +1441,7 @@ struct cras_iodev *loopback_iodev_create(enum CRAS_LOOPBACK_TYPE type) { void loopback_iodev_destroy(struct cras_iodev *iodev) { } -int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level, - const struct cras_audio_format *fmt) +int cras_iodev_open(struct cras_iodev *iodev, unsigned int cb_level) { if (cras_iodev_open_ret[cras_iodev_open_called] == 0) iodev->state = CRAS_IODEV_STATE_OPEN; diff --git a/cras/src/tests/iodev_unittest.cc b/cras/src/tests/iodev_unittest.cc index bad8de0b..29e6e22e 100644 --- a/cras/src/tests/iodev_unittest.cc +++ b/cras/src/tests/iodev_unittest.cc @@ -103,7 +103,6 @@ static unsigned int cras_scale_buffer_increment_frame; static float cras_scale_buffer_increment_scaler; static float cras_scale_buffer_increment_increment; static int cras_scale_buffer_increment_channel; -static struct cras_audio_format audio_fmt; // Iodev callback int update_channel_layout(struct cras_iodev *iodev) { @@ -195,9 +194,6 @@ void ResetStubData() { cras_scale_buffer_increment_scaler = 0; cras_scale_buffer_increment_increment = 0; cras_scale_buffer_increment_channel = 0; - audio_fmt.format = SND_PCM_FORMAT_S16_LE; - audio_fmt.frame_rate = 48000; - audio_fmt.num_channels = 2; } namespace { @@ -1276,7 +1272,7 @@ TEST(IoDev, GetBufferInvalidFrames) { EXPECT_EQ(-EINVAL, cras_iodev_get_input_buffer(&iodev, area, &frames)); } -static int configure_dev(struct cras_iodev *iodev) { +static int open_dev(struct cras_iodev *iodev) { iodev->buffer_size = iodev_buffer_size; return 0; } @@ -1285,15 +1281,14 @@ TEST(IoDev, OpenOutputDeviceNoStart) { struct cras_iodev iodev; memset(&iodev, 0, sizeof(iodev)); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.direction = CRAS_STREAM_OUTPUT; - iodev.ext_format = &audio_fmt; ResetStubData(); iodev.state = CRAS_IODEV_STATE_CLOSE; iodev_buffer_size = 1024; - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); EXPECT_EQ(0, iodev.max_cb_level); EXPECT_EQ(240, iodev.min_cb_level); @@ -1309,16 +1304,15 @@ TEST(IoDev, OpenOutputDeviceWithStart) { struct cras_iodev iodev; memset(&iodev, 0, sizeof(iodev)); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.direction = CRAS_STREAM_OUTPUT; - iodev.ext_format = &audio_fmt; ResetStubData(); iodev.state = CRAS_IODEV_STATE_CLOSE; iodev.start = fake_start; iodev_buffer_size = 1024; - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); EXPECT_EQ(0, iodev.max_cb_level); EXPECT_EQ(240, iodev.min_cb_level); @@ -1330,15 +1324,14 @@ TEST(IoDev, OpenInputDeviceNoStart) { struct cras_iodev iodev; memset(&iodev, 0, sizeof(iodev)); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.direction = CRAS_STREAM_INPUT; - iodev.ext_format = &audio_fmt; ResetStubData(); iodev.state = CRAS_IODEV_STATE_CLOSE; iodev_buffer_size = 1024; - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); EXPECT_EQ(0, iodev.max_cb_level); EXPECT_EQ(240, iodev.min_cb_level); @@ -1350,16 +1343,15 @@ TEST(IoDev, OpenInputDeviceWithStart) { struct cras_iodev iodev; memset(&iodev, 0, sizeof(iodev)); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.direction = CRAS_STREAM_INPUT; - iodev.ext_format = &audio_fmt; ResetStubData(); iodev.state = CRAS_IODEV_STATE_CLOSE; iodev.start = fake_start; iodev_buffer_size = 1024; - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); EXPECT_EQ(0, iodev.max_cb_level); EXPECT_EQ(240, iodev.min_cb_level); @@ -1380,9 +1372,8 @@ TEST(IoDev, AddRmStream) { struct dev_stream stream1, stream2; memset(&iodev, 0, sizeof(iodev)); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.no_stream = simple_no_stream; - iodev.ext_format = &audio_fmt; iodev.state = CRAS_IODEV_STATE_NORMAL_RUN; rstream1.cb_threshold = 800; stream1.stream = &rstream1; @@ -1391,7 +1382,7 @@ TEST(IoDev, AddRmStream) { ResetStubData(); iodev_buffer_size = 1024; - cras_iodev_open(&iodev, rstream1.cb_threshold, &audio_fmt); + cras_iodev_open(&iodev, rstream1.cb_threshold); EXPECT_EQ(0, iodev.max_cb_level); EXPECT_EQ(512, iodev.min_cb_level); @@ -1532,13 +1523,13 @@ TEST(IoDev, PrepareOutputBeforeWriteSamples) { iodev.direction = CRAS_STREAM_OUTPUT; iodev.buffer_size = BUFFER_SIZE; iodev.no_stream = no_stream; - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.start = fake_start; iodev.info = info; iodev_buffer_size = BUFFER_SIZE; // Open device. - cras_iodev_open(&iodev, rstream1.cb_threshold, &fmt); + cras_iodev_open(&iodev, rstream1.cb_threshold); // Add one stream to device. cras_iodev_add_stream(&iodev, &stream1); @@ -1901,15 +1892,14 @@ TEST(IoDev, RequestReset) { ResetStubData(); - iodev.configure_dev = configure_dev; + iodev.open_dev = open_dev; iodev.direction = CRAS_STREAM_OUTPUT; - iodev.ext_format = &audio_fmt; iodev.state = CRAS_IODEV_STATE_CLOSE; iodev_buffer_size = 1024; // Open device. - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); // The first reset request works. EXPECT_EQ(0, cras_iodev_reset_request(&iodev)); @@ -1920,7 +1910,7 @@ TEST(IoDev, RequestReset) { EXPECT_EQ(1, device_monitor_reset_device_called); // Assume device is opened again. - cras_iodev_open(&iodev, 240, &audio_fmt); + cras_iodev_open(&iodev, 240); // The reset request works. EXPECT_EQ(0, cras_iodev_reset_request(&iodev)); diff --git a/cras/src/tests/loopback_iodev_unittest.cc b/cras/src/tests/loopback_iodev_unittest.cc index e213dc2f..b0387bfd 100644 --- a/cras/src/tests/loopback_iodev_unittest.cc +++ b/cras/src/tests/loopback_iodev_unittest.cc @@ -76,7 +76,7 @@ TEST_F(LoopBackTestSuite, InstallLoopHook) { enabled_dev = &iodev; // Open loopback devices. - EXPECT_EQ(0, loop_in_->configure_dev(loop_in_)); + EXPECT_EQ(0, loop_in_->open_dev(loop_in_)); EXPECT_EQ(1, cras_iodev_list_set_device_enabled_callback_called); // Signal an output device is enabled. @@ -106,7 +106,7 @@ TEST_F(LoopBackTestSuite, OpenIdleSystem) { time_now.tv_sec = 100; time_now.tv_nsec = 0; - EXPECT_EQ(0, loop_in_->configure_dev(loop_in_)); + EXPECT_EQ(0, loop_in_->open_dev(loop_in_)); EXPECT_EQ(1, cras_iodev_list_set_device_enabled_callback_called); // Should be 480 samples after 480/frame rate seconds @@ -139,7 +139,7 @@ TEST_F(LoopBackTestSuite, SimpleLoopback) { iodev.streams = &stream; enabled_dev = &iodev; - loop_in_->configure_dev(loop_in_); + loop_in_->open_dev(loop_in_); ASSERT_NE(reinterpret_cast<void *>(NULL), loop_hook); // Loopback callback for the hook. |