Skip to content

Commit

Permalink
CRAS: iodev: Add cras_iodev_get_use_case
Browse files Browse the repository at this point in the history
Allow query of use case from an iodev for reporting metrics and dumping
debug info from cras_test_client. alsa_io implements the callback based
on UCM files. If the callback is NULL, CRAS_USE_CASE_HIFI is returned by
default.

BUG=b:250544745
TEST=Check iodev use cases reported by cras_test_client on Redrix with
the rest of the patch series.

Change-Id: I530a29ce2269703fe3a6edaa94f924075ef02a12
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/5170386
Commit-Queue: Ben Zhang <benzh@chromium.org>
Tested-by: chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com <chromeos-cop-builder@chromeos-cop.iam.gserviceaccount.com>
Reviewed-by: Curtis Malainey <cujomalainey@chromium.org>
  • Loading branch information
bzhg authored and Chromeos LUCI committed Jan 10, 2024
1 parent d03a32e commit 6d1f91f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cras/src/server/cras_alsa_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,12 @@ static struct alsa_io_group* create_iodev_group(struct cras_iodev* iodev) {
return group;
}

enum CRAS_USE_CASE get_use_case(const struct cras_iodev* iodev) {
const struct alsa_io* aio = (const struct alsa_io*)iodev;

return aio->use_case;
}

/*
* Exported Interface.
*/
Expand Down Expand Up @@ -2223,6 +2229,7 @@ struct cras_iodev* alsa_iodev_create(
iodev->get_dev_group = get_dev_group;
iodev->get_dev_group_id = get_dev_group_id;
iodev->should_attach_stream = should_attach_stream;
iodev->get_use_case = get_use_case;
iodev->get_htimestamp = cras_alsa_common_get_htimestamp;

iodev->ramp = cras_ramp_create();
Expand Down
18 changes: 18 additions & 0 deletions cras/src/server/cras_iodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdbool.h>
#include <time.h>

#include "cras/src/common/cras_types_internal.h"
#include "cras/src/server/cras_dsp.h"
#include "cras/src/server/cras_nc.h"
#include "cras/src/server/ewma_power.h"
Expand Down Expand Up @@ -282,6 +283,8 @@ struct cras_iodev {
// on the iodev's use case and stream parameters.
int (*should_attach_stream)(const struct cras_iodev* iodev,
const struct cras_rstream* stream);
// (Optional) Gets the use case of the iodev.
enum CRAS_USE_CASE (*get_use_case)(const struct cras_iodev* iodev);
// (Optional) Obtain the hardware timestamp for the last update
// The hardware timestamp should be using the MONOTONIC_RAW clock
// For playback, the timestamp is the last time the iodev wrote into the
Expand Down Expand Up @@ -1183,6 +1186,21 @@ static inline int cras_iodev_group_has_dev(const struct cras_iodev* iodev,
return false;
}

/* Gets the use case of the iodev. e.g. HiFi, LowLatency.
* Args:
* iodev - The device
* Returns:
* Use case of the device.
*/
static inline enum CRAS_USE_CASE cras_iodev_get_use_case(
const struct cras_iodev* iodev) {
if (iodev->get_use_case) {
return iodev->get_use_case(iodev);
}

return CRAS_USE_CASE_HIFI;
}

/* Gets the hardware timestamp of the last update. If there is no hardware
* timestamp, returns the current time as the timestamp.
* Args:
Expand Down

0 comments on commit 6d1f91f

Please sign in to comment.