static char * adev_get_parameters(const struct audio_hw_device *dev,
                                  const char *keys)
{
    struct adev_a2dp *adev = (struct adev_a2dp *)dev;
    struct str_parms *parms;
    struct str_parms *out_parms;
    char *str;
    char value[8];
    int ret;

    parms = str_parms_create_str(keys);
    out_parms = str_parms_create();

    pthread_mutex_lock(&adev->lock);

    ret = str_parms_get_str(parms, BLUETOOOTH_ENABLED_PARM, value,
                            sizeof(value));
    if (ret >= 0)
        str_parms_add_str(out_parms, BLUETOOOTH_ENABLED_PARM,
                          adev->bt_enabled ? "true" : "false");

    ret = str_parms_get_str(parms, A2DP_SUSPENDED_PARM, value, sizeof(value));
    if (ret >= 0)
        str_parms_add_str(out_parms, A2DP_SUSPENDED_PARM,
                          adev->suspended ? "true" : "false");

    pthread_mutex_unlock(&adev->lock);

    str = str_parms_to_str(out_parms);
    str_parms_destroy(out_parms);
    str_parms_destroy(parms);

    return str;
}
static char * out_get_parameters(const struct audio_stream *stream,
                                 const char *keys)
{
    struct astream_out *out = (struct astream_out *)stream;
    struct str_parms *parms;
    struct str_parms *out_parms;
    char *str;
    char value[20];
    int ret;

    parms = str_parms_create_str(keys);
    out_parms = str_parms_create();

    pthread_mutex_lock(&out->lock);

    ret = str_parms_get_str(parms, OUT_SINK_ADDR_PARM, value, sizeof(value));
    if (ret >= 0)
        str_parms_add_str(out_parms, OUT_SINK_ADDR_PARM, out->a2dp_addr);

    pthread_mutex_unlock(&out->lock);

    str = str_parms_to_str(out_parms);
    str_parms_destroy(out_parms);
    str_parms_destroy(parms);

    return str;
}
static void test_str_parms_str(const char* str, const char* expected) {
    str_parms* str_parms = str_parms_create_str(str);
    str_parms_add_str(str_parms, "dude", "woah");
    str_parms_add_str(str_parms, "dude", "woah");
    str_parms_del(str_parms, "dude");
    str_parms_dump(str_parms);
    char* out_str = str_parms_to_str(str_parms);
    str_parms_destroy(str_parms);
    ASSERT_STREQ(expected, out_str) << str;
    free(out_str);
}
static int usb_connect_output(hw_ext_module_t * hw_module,
                                                                    audio_devices_t              device,
                                                                    const char*                  CardAndDevice)
{
    audio_policy_anm *apm=hw_module->apm;
    struct usb_internal_data_s * usb_info = (struct usb_internal_data_s *)hw_module->data;
    char *str = NULL;
    struct str_parms *param;

    if(usb_info==NULL) return -1;

    switch(usb_info->state) {
        case IO_OPENED:
        case IO_DISCONNECTED:
            //continue treatment
            break;
        case IO_CLOSED:
            ALOG_WARN("USB output is in closed state ; Impossible to connect it");
            return -1;
            break;
        case IO_CONNECTED:
            ALOG_WARN("usb_connect_output : already connected");
            return 0;
            break;
        default:
            ALOG_WARN("usb_connect_output : unknown state");
    }

    if (usb_info->output_handle <=0 ) {
        ALOG_WARN("USB output is invalid ; Impossible to connect it");
        return -1;
    }

    ALOG_INFO("USB Output = %d, mStrategyRefCount = %d, CardAndDevice =>  %s",
                usb_info->output_handle,usb_info->output_desc.mStrategyRefCount,CardAndDevice);

    // handle USB device connection
    strncpy(usb_info->usb_card_and_device,CardAndDevice, sizeof(char)*MAX_DEVICE_ADDRESS_LEN);
    param = str_parms_create_str(usb_info->usb_card_and_device);
    str = str_parms_to_str(param);
    apm->mp_client_interface->set_parameters(apm->mService, usb_info->output_handle, str, 0);
    str_parms_destroy(param);

    usb_info->state=IO_CONNECTED;
    return 0;
}
Esempio n. 5
0
static char * device_get_parameters(alsa_device_profile * profile, const char * keys)
{
    ALOGV("usb:audio_hw::device_get_parameters() keys:%s", keys);

    if (profile->card < 0 || profile->device < 0) {
        return strdup("");
    }

    struct str_parms *query = str_parms_create_str(keys);
    struct str_parms *result = str_parms_create();

    /* These keys are from hardware/libhardware/include/audio.h */
    /* supported sample rates */
    if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES)) {
        char* rates_list = profile_get_sample_rate_strs(profile);
        str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES,
                          rates_list);
        free(rates_list);
    }

    /* supported channel counts */
    if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS)) {
        char* channels_list = profile_get_channel_count_strs(profile);
        str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_CHANNELS,
                          channels_list);
        free(channels_list);
    }

    /* supported sample formats */
    if (str_parms_has_key(query, AUDIO_PARAMETER_STREAM_SUP_FORMATS)) {
        char * format_params = profile_get_format_strs(profile);
        str_parms_add_str(result, AUDIO_PARAMETER_STREAM_SUP_FORMATS,
                          format_params);
        free(format_params);
    }
    str_parms_destroy(query);

    char* result_str = str_parms_to_str(result);
    str_parms_destroy(result);

    ALOGV("usb:audio_hw::device_get_parameters = %s", result_str);

    return result_str;
}
static int usb_close_output(hw_ext_module_t * hw_module,audio_devices_t   device){
    struct usb_internal_data_s * usb_info = (struct usb_internal_data_s *)hw_module->data;
    audio_policy_anm *apm=hw_module->apm;
    struct str_parms *param;

    if(usb_info==NULL)
        return -1;

    switch(usb_info->state) {
        case IO_OPENED:
        case IO_DISCONNECTED:
            //continue treatment
            break;
        case IO_CONNECTED:
            ALOG_WARN("usb_close_output : USB output is not in disconnected state ; Impossible to close it");
            return -1;
            break;
        case IO_CLOSED:
            ALOG_WARN("usb_close_output : already closed");
            return 0;
            break;
        default:
            ALOG_WARN("usb_close_output : unknown state");
    }

    if (usb_info->output_handle <=0 ) {
        ALOG_WARN("USB output is invalid ; Impossible to connect it");
        return -1;
    }
    ALOG_INFO("USB request closing ");
    param = str_parms_create_str("closing");
    str_parms_add_str(param, "closing", "true");
    apm->mp_client_interface->set_parameters(apm->mService, usb_info->output_handle, str_parms_to_str(param), 0);
    str_parms_destroy(param);

    apm->mp_client_interface->close_output(apm->mService, usb_info->output_handle);
    ALOG_INFO("Usb closed ");
    return(usb_init(hw_module));
}
void audio_extn_a2dp_set_parameters(struct str_parms *parms)
{
     int ret, val;
     char value[32]={0};

     ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value,
                            sizeof(value));
     if( ret >= 0) {
         val = atoi(value);
         if (val & AUDIO_DEVICE_OUT_ALL_A2DP) {
             ALOGV("Received device connect request for A2DP");
             open_a2dp_output();
         }
     }

     ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value,
                         sizeof(value));

     if( ret >= 0) {
         val = atoi(value);
         if (val & AUDIO_DEVICE_OUT_ALL_A2DP) {
             ALOGV("Received device dis- connect request");
             close_a2dp_output();
         }
     }

     ret = str_parms_get_str(parms, "A2dpSuspended", value, sizeof(value));
     if (ret >= 0) {
         if (a2dp.a2dp_device && a2dp.a2dp_stream) {
             a2dp.a2dp_device->set_parameters(a2dp.a2dp_device, str_parms_to_str(parms));
             if (!strncmp(value,"true",sizeof(value))) {
                 a2dp.a2dp_suspended = true;
             } else {
                 a2dp.a2dp_suspended = false;
             }
         }
     }
}
char * hdmi_out_get_parameters(const struct audio_stream *stream,
			 const char *keys)
{
    struct str_parms *query = str_parms_create_str(keys);
    char *str;
    char value[256];
    struct str_parms *reply = str_parms_create();
    int status;
    hdmi_audio_caps_t caps;

    TRACEM("stream=%p keys='%s'", stream, keys);

    if (hdmi_query_audio_caps(HDMI_EDID_PATH, &caps)) {
        ALOGE("Unable to get the HDMI audio capabilities");
        str = calloc(1, 1);
        goto end;
    }

    status = str_parms_get_str(query, AUDIO_PARAMETER_STREAM_SUP_CHANNELS,
                                value, sizeof(value));
    if (status >= 0) {
        unsigned sa = caps.speaker_alloc;
        bool first = true;

        /* STEREO is intentionally skipped.  This code is only
         * executed for the 'DIRECT' interface, and we don't
         * want stereo on a DIRECT thread.
         */
        value[0] = '\0';
        if (SUPPORTS_ARR(sa, MASK_CEA_QUAD)) {
            if (!first) {
                strcat(value, "|");
            }
            first = false;
            strcat(value, "AUDIO_CHANNEL_OUT_QUAD");
        }
        if (SUPPORTS_ARR(sa, MASK_CEA_SURROUND)) {
            if (!first) {
                strcat(value, "|");
            }
            first = false;
            strcat(value, "AUDIO_CHANNEL_OUT_SURROUND");
        }
        if (SUPPORTS_ARR(sa, MASK_CEA_5POINT1)) {
            if (!first) {
                strcat(value, "|");
            }
            first = false;
            strcat(value, "AUDIO_CHANNEL_OUT_5POINT1");
        }
        if (SUPPORTS_ARR(sa, MASK_CEA_7POINT1)) {
            if (!first) {
                strcat(value, "|");
            }
            first = false;
            strcat(value, "AUDIO_CHANNEL_OUT_7POINT1");
        }
        str_parms_add_str(reply, AUDIO_PARAMETER_STREAM_SUP_CHANNELS, value);
        str = strdup(str_parms_to_str(reply));
    } else {
        str = strdup(keys);
    }

    ALOGV("%s() reply: '%s'", __func__, str);

end:
    str_parms_destroy(query);
    str_parms_destroy(reply);
    return str;
}