static int adev_open_output_stream(struct audio_hw_device *dev, audio_io_handle_t handle, audio_devices_t devices, audio_output_flags_t flags, struct audio_config *config, struct audio_stream_out **stream_out) { struct audio_device *adev = (struct audio_device *)dev; struct stream_out *out; int ret; out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); if (!out) return -ENOMEM; out->stream.common.get_sample_rate = out_get_sample_rate; out->stream.common.set_sample_rate = out_set_sample_rate; out->stream.common.get_buffer_size = out_get_buffer_size; out->stream.common.get_channels = out_get_channels; out->stream.common.get_format = out_get_format; out->stream.common.set_format = out_set_format; out->stream.common.standby = out_standby; out->stream.common.dump = out_dump; out->stream.common.set_parameters = out_set_parameters; out->stream.common.get_parameters = out_get_parameters; out->stream.common.add_audio_effect = out_add_audio_effect; out->stream.common.remove_audio_effect = out_remove_audio_effect; out->stream.get_latency = out_get_latency; out->stream.set_volume = out_set_volume; out->stream.write = out_write; out->stream.get_render_position = out_get_render_position; out->stream.get_next_write_timestamp = out_get_next_write_timestamp; out->dev = adev; config->format = out_get_format(&out->stream.common); config->channel_mask = out_get_channels(&out->stream.common); config->sample_rate = out_get_sample_rate(&out->stream.common); out->standby = true; adev->card = -1; adev->device = -1; *stream_out = &out->stream; return 0; err_open: free(out); *stream_out = NULL; return ret; }
static int adev_open_output_stream(struct audio_hw_device *dev, audio_io_handle_t handle, audio_devices_t devices, audio_output_flags_t flags, struct audio_config *config, struct audio_stream_out **stream_out) { struct audio_device *adev = (struct audio_device *)dev; struct stream_out *out; int ret; ALOGV("%s enter card %d device %d ",__func__, adev->card, adev->device); out = (struct stream_out *)calloc(1, sizeof(struct stream_out)); if (!out) return -ENOMEM; out->channel_mask = AUDIO_CHANNEL_OUT_STEREO; if (flags & AUDIO_OUTPUT_FLAG_DIRECT) { ALOGV("%s: USB Audio (device mode) HD",__func__); if (config->format == 0) config->format = pcm_config_HD_default.format; if (config->channel_mask == 0) config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; if (config->sample_rate == 0) config->sample_rate = pcm_config_HD_default.rate; out->pcm_config.period_size = pcm_config_HD_default.period_size; out->flags |= flags; } else { ALOGV("%s: USB Audio (device mode) Stereo",__func__); if (config->format == 0) config->format = pcm_config_default.format; if (config->channel_mask == 0) config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; if (config->sample_rate == 0) config->sample_rate = pcm_config_default.rate; out->pcm_config.period_size = pcm_config_default.period_size; } out->channel_mask = config->channel_mask; out->pcm_config.channels = popcount(config->channel_mask); out->pcm_config.rate = config->sample_rate; out->pcm_config.format = config->format; out->pcm_config.period_count = pcm_config_default.period_count; out->stream.common.get_sample_rate = out_get_sample_rate; out->stream.common.set_sample_rate = out_set_sample_rate; out->stream.common.get_buffer_size = out_get_buffer_size; out->stream.common.get_channels = out_get_channels; out->stream.common.get_format = out_get_format; out->stream.common.set_format = out_set_format; out->stream.common.standby = out_standby; out->stream.common.dump = out_dump; out->stream.common.set_parameters = out_set_parameters; out->stream.common.get_parameters = out_get_parameters; out->stream.common.add_audio_effect = out_add_audio_effect; out->stream.common.remove_audio_effect = out_remove_audio_effect; out->stream.get_latency = out_get_latency; out->stream.set_volume = out_set_volume; out->stream.write = out_write; out->stream.get_render_position = out_get_render_position; out->stream.get_next_write_timestamp = out_get_next_write_timestamp; out->dev = adev; config->format = out_get_format(&out->stream.common); config->channel_mask = out_get_channels(&out->stream.common); config->sample_rate = out_get_sample_rate(&out->stream.common); out->standby = true; adev->card = -1; adev->device = -1; *stream_out = &out->stream; ALOGV("%s exit",__func__); return 0; }