Skip to content

Commit 3fc90e6

Browse files
committed
audio: Use get_device_alsadev() to support device' specific card/device
Implement support for card and device number specific to a given device. TODO: - don't hardcode the card/device for non-alsadev devices. Gotta retrieve the numbers using configmgr I guess... - the ifdef'ed code in out_set_parameters() requires non-const hwstream. Probably not the good way to do it... - mirror support for input devices Change-Id: Idf34ee23cfcfa02692bcb8914dfdd38ebc1d724c Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
1 parent e57f19f commit 3fc90e6

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

audio/audio_hw.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
379379

380380
struct stream_out_common *out = (struct stream_out_common *)stream;
381381
struct audio_device *adev = out->dev;
382+
#if 0
383+
uint32_t cardnum, devnum;
384+
#endif
382385
uint32_t v;
383386
int ret;
384387

@@ -387,6 +390,17 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
387390
pthread_mutex_lock(&adev->lock);
388391

389392
if (ret >= 0) {
393+
#if 0
394+
if (get_device_alsadev(adev->cm, v, &cardnum, &devnum) < 0) {
395+
ALOGI("restoring params with card=0 dev=2"); // TODO: don't hardcode
396+
out->hw->card_number = 0;
397+
out->hw->device_number = 2;
398+
} else {
399+
ALOGI("updating params with card=%u dev=%u", cardnum, devnum);
400+
out->hw->card_number = cardnum;
401+
out->hw->device_number = devnum;
402+
}
403+
#endif
390404
apply_route(out->hw, v);
391405
}
392406

@@ -735,6 +749,8 @@ static void out_pcm_fill_params(struct stream_out_pcm *out,
735749
/* Must be called with hw device and output stream mutexes locked */
736750
static int start_output_pcm(struct stream_out_pcm *out)
737751
{
752+
struct config_mgr *cm = out->common.dev->cm;
753+
uint32_t device, cardnum, devnum;
738754
int ret;
739755

740756
struct pcm_config config = {
@@ -750,10 +766,21 @@ static int start_output_pcm(struct stream_out_pcm *out)
750766

751767
ALOGV("+start_output_stream(%p)", out);
752768

753-
out->pcm = pcm_open(out->common.hw->card_number,
754-
out->common.hw->device_number,
755-
PCM_OUT | PCM_MONOTONIC,
756-
&config);
769+
device = get_current_routes(out->common.hw);
770+
ret = get_device_alsadev(cm, device, &cardnum, &devnum);
771+
if (ret < 0) {
772+
ALOGI("device = %u (not alsadev, ret=%d)", device, ret);
773+
out->pcm = pcm_open(out->common.hw->card_number,
774+
out->common.hw->device_number,
775+
PCM_OUT | PCM_MONOTONIC,
776+
&config);
777+
} else {
778+
ALOGI("device = %u (alsadev)", device);
779+
out->pcm = pcm_open(cardnum,
780+
devnum,
781+
PCM_OUT | PCM_MONOTONIC,
782+
&config);
783+
}
757784

758785
if (out->pcm && !pcm_is_ready(out->pcm)) {
759786
ALOGE("pcm_open(out) failed: %s", pcm_get_error(out->pcm));

0 commit comments

Comments
 (0)