mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	bluetooth: show negotiated HFP codec
While codec switching for HFP is not implemented, show current codec via messaging api. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/507>
This commit is contained in:
		
							parent
							
								
									f0d32e9454
								
							
						
					
					
						commit
						ddad63a23c
					
				
					 3 changed files with 53 additions and 18 deletions
				
			
		| 
						 | 
					@ -80,6 +80,15 @@ const pa_a2dp_codec *pa_bluetooth_a2dp_codec_iter(unsigned int i) {
 | 
				
			||||||
    return pa_a2dp_codecs[i];
 | 
					    return pa_a2dp_codecs[i];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned int pa_bluetooth_hf_codec_count(void) {
 | 
				
			||||||
 | 
					    return PA_ELEMENTSOF(pa_hf_codecs);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const pa_a2dp_codec *pa_bluetooth_hf_codec_iter(unsigned int i) {
 | 
				
			||||||
 | 
					    pa_assert(i < pa_bluetooth_hf_codec_count());
 | 
				
			||||||
 | 
					    return pa_hf_codecs[i];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const pa_a2dp_codec *pa_bluetooth_get_hf_codec(const char *name) {
 | 
					const pa_a2dp_codec *pa_bluetooth_get_hf_codec(const char *name) {
 | 
				
			||||||
    unsigned int i;
 | 
					    unsigned int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,12 @@ bool pa_bluetooth_a2dp_codec_is_available(const pa_a2dp_codec_id *id, bool is_a2
 | 
				
			||||||
/* Initialise GStreamer */
 | 
					/* Initialise GStreamer */
 | 
				
			||||||
void pa_bluetooth_a2dp_codec_gst_init(void);
 | 
					void pa_bluetooth_a2dp_codec_gst_init(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Get number of supported HSP/HFP codecs */
 | 
				
			||||||
 | 
					unsigned int pa_bluetooth_hf_codec_count(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Get i-th codec. Codec with higher number has higher priority */
 | 
				
			||||||
 | 
					const pa_a2dp_codec *pa_bluetooth_hf_codec_iter(unsigned int i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Get HSP/HFP codec by name */
 | 
					/* Get HSP/HFP codec by name */
 | 
				
			||||||
const pa_a2dp_codec *pa_bluetooth_get_hf_codec(const char *name);
 | 
					const pa_a2dp_codec *pa_bluetooth_get_hf_codec(const char *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2361,31 +2361,49 @@ static char *list_codecs(struct userdata *u) {
 | 
				
			||||||
    bool is_a2dp_sink;
 | 
					    bool is_a2dp_sink;
 | 
				
			||||||
    void *state;
 | 
					    void *state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    is_a2dp_sink = u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    a2dp_endpoints = is_a2dp_sink ? u->device->a2dp_sink_endpoints : u->device->a2dp_source_endpoints;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    encoder = pa_json_encoder_new();
 | 
					    encoder = pa_json_encoder_new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_json_encoder_begin_element_array(encoder);
 | 
					    pa_json_encoder_begin_element_array(encoder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PA_HASHMAP_FOREACH_KV(key, a2dp_capabilities, a2dp_endpoints, state) {
 | 
					    if (u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK || u->profile == PA_BLUETOOTH_PROFILE_A2DP_SOURCE) {
 | 
				
			||||||
        for (i = 0; i < pa_bluetooth_a2dp_codec_count(); i++) {
 | 
					        is_a2dp_sink = u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK;
 | 
				
			||||||
            const pa_a2dp_codec *a2dp_codec;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
 | 
					        a2dp_endpoints = is_a2dp_sink ? u->device->a2dp_sink_endpoints : u->device->a2dp_source_endpoints;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (memcmp(key, &a2dp_codec->id, sizeof(pa_a2dp_codec_id)) == 0) {
 | 
					        PA_HASHMAP_FOREACH_KV(key, a2dp_capabilities, a2dp_endpoints, state) {
 | 
				
			||||||
                if (a2dp_codec->can_be_supported(is_a2dp_sink)) {
 | 
					            for (i = 0; i < pa_bluetooth_a2dp_codec_count(); i++) {
 | 
				
			||||||
                    pa_json_encoder_begin_element_object(encoder);
 | 
					                const pa_a2dp_codec *a2dp_codec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    pa_json_encoder_add_member_string(encoder, "name", a2dp_codec->name);
 | 
					                a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
 | 
				
			||||||
                    pa_json_encoder_add_member_string(encoder, "description", a2dp_codec->description);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    pa_json_encoder_end_object(encoder);
 | 
					                if (memcmp(key, &a2dp_codec->id, sizeof(pa_a2dp_codec_id)) == 0) {
 | 
				
			||||||
 | 
					                    if (a2dp_codec->can_be_supported(is_a2dp_sink)) {
 | 
				
			||||||
 | 
					                        pa_json_encoder_begin_element_object(encoder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        pa_json_encoder_add_member_string(encoder, "name", a2dp_codec->name);
 | 
				
			||||||
 | 
					                        pa_json_encoder_add_member_string(encoder, "description", a2dp_codec->description);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        pa_json_encoder_end_object(encoder);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        /* find out active codec selection from device profile */
 | 
				
			||||||
 | 
					        for (i = 0; i < pa_bluetooth_hf_codec_count(); i++) {
 | 
				
			||||||
 | 
					            const pa_a2dp_codec *hf_codec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            hf_codec = pa_bluetooth_hf_codec_iter(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (true) {
 | 
				
			||||||
 | 
					                pa_json_encoder_begin_element_object(encoder);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pa_json_encoder_add_member_string(encoder, "name", hf_codec->name);
 | 
				
			||||||
 | 
					                pa_json_encoder_add_member_string(encoder, "description", hf_codec->description);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                pa_json_encoder_end_object(encoder);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_json_encoder_end_array(encoder);
 | 
					    pa_json_encoder_end_array(encoder);
 | 
				
			||||||
| 
						 | 
					@ -2428,13 +2446,15 @@ static int bluez5_device_message_handler(const char *object_path, const char *me
 | 
				
			||||||
    if (u->profile == PA_BLUETOOTH_PROFILE_OFF) {
 | 
					    if (u->profile == PA_BLUETOOTH_PROFILE_OFF) {
 | 
				
			||||||
        pa_log_info("Bluetooth profile is off. Message cannot be handled.");
 | 
					        pa_log_info("Bluetooth profile is off. Message cannot be handled.");
 | 
				
			||||||
        return -PA_ERR_INVALID;
 | 
					        return -PA_ERR_INVALID;
 | 
				
			||||||
    } else if (u->profile != PA_BLUETOOTH_PROFILE_A2DP_SINK &&
 | 
					 | 
				
			||||||
            u->profile != PA_BLUETOOTH_PROFILE_A2DP_SOURCE) {
 | 
					 | 
				
			||||||
        pa_log_info("Listing or switching codecs only allowed for A2DP sink or source");
 | 
					 | 
				
			||||||
        return -PA_ERR_INVALID;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_streq(message, "switch-codec")) {
 | 
					    if (pa_streq(message, "switch-codec")) {
 | 
				
			||||||
 | 
					        if (u->profile != PA_BLUETOOTH_PROFILE_A2DP_SINK &&
 | 
				
			||||||
 | 
					            u->profile != PA_BLUETOOTH_PROFILE_A2DP_SOURCE) {
 | 
				
			||||||
 | 
					            pa_log_info("Switching codecs only allowed for A2DP sink or source");
 | 
				
			||||||
 | 
					            return -PA_ERR_INVALID;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!parameters) {
 | 
					        if (!parameters) {
 | 
				
			||||||
            pa_log_info("Codec switching operation requires codec name string parameter");
 | 
					            pa_log_info("Codec switching operation requires codec name string parameter");
 | 
				
			||||||
            return -PA_ERR_INVALID;
 | 
					            return -PA_ERR_INVALID;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue