Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp331810pxu; Fri, 23 Oct 2020 01:44:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJSd6/o6LwEL036GU5/a9CHGPR1nWO3abZnve84n4zHbP3gwb5Ak70hU3fR2JClzh6Zmyu X-Received: by 2002:a50:8b62:: with SMTP id l89mr1212060edl.132.1603442696478; Fri, 23 Oct 2020 01:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603442696; cv=none; d=google.com; s=arc-20160816; b=bGu69l2C1Ts3gEmMwZoLgtkXtuURF7HMIDh9yq4gvaifeaYuXmsQJjXqZCFk0QPJVT Ze9JtQVqc927TX8abK1fmy1GcMSCWq8HXKfoVdsdV0PT7g9tXLHPfUxCIQEb2tVy0CuS QDKD8ZhWoCpnOk2JqGh+3qR6XOxvwXMNwpuPmHgvg7+4ZGY9nsoZPF9MI7LEaIFeO6qW BycpFHZr8SYYVyywK9SjRvN6aihROyAVOsv27nmh6IOpQs99lajFnGO8MeSLJXX++AWC wtW5NxEix1tFeYzjhJqszHn+x8IZAe2S9QaZkx3P7Ssd7tmy7gVe4sjr1DyRcSXj7+Wu 3bLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UyG8ArYAbK110ayV7Uk+lJxVbB7boS9PZE4hAOktp5E=; b=yFjFDvJd+0XehU/B61g1h1NkppDw6kxlX5gE7Xsxm6d5M/g7717df+n/aJLsdpHYVy eWjIKgrKnMcYfcRPnthpeF5PBSMcOHh1NVUuQvds7WvK7Qy/IvSE8RrOfNq0+mdRAFs7 CEbvdl1RVQeCr2u7hTfktMsWgxYTlA/XEt339Nl9ZGfVNVRg6R5JDbPh9fUeGDd1ftx9 HzdQCMBbWGRyYMvGJuQYbbKMSUSoFZvpk1sQ6qlV0G9lKW7vXf9Og0Ltjcz84Yf8cZW/ Y1m+VPmgIZiP07O50J0TPpTJXQe4JN2NmjXLNzHgEV5gMmFY5L63lmNKN50IiF+Q562J TV/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OH6GUggt; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f24si319588edj.0.2020.10.23.01.44.16; Fri, 23 Oct 2020 01:44:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OH6GUggt; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S376016AbgJWInf (ORCPT + 99 others); Fri, 23 Oct 2020 04:43:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S375938AbgJWInf (ORCPT ); Fri, 23 Oct 2020 04:43:35 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0721C0613CE for ; Fri, 23 Oct 2020 01:43:34 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id dn5so759070edb.10 for ; Fri, 23 Oct 2020 01:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UyG8ArYAbK110ayV7Uk+lJxVbB7boS9PZE4hAOktp5E=; b=OH6GUggtgW5E+0nLfrwH4/lZXUM0s6RnnUoOAIQnTB1y/kzZnhc6Dyx2YSa7FjlifB nxIHlnYLM/Ctri0fR2TOCAT8hD1NEyzS7E5CkFs6UaH2svZCyYyoBXvmvNrmSd9hNrUx N+u0dkP4jqsnnrBVWO+RNs935zgvhhtXuiMOrh47t8CKP/VsTlqdPojnE5s3GSqN3pgf gTWvKeqw0943yyt9rrtIYF6AiRG3D9es4tuTjrCGangfImfTnikk9g4NjW2YnzCB7qw2 uAgpW7xfnkipe5yq2c/BTLWOc5wqF7ttRNhl5xgAtwWLCANrtjdISY2NSQZ3qZisTtex DtVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=UyG8ArYAbK110ayV7Uk+lJxVbB7boS9PZE4hAOktp5E=; b=sWVZ5tgQJp4PNhoW8aT4eooAqQ7SYlLZXaJhSEsKLMKhvauRwulI7heCWoBD57qD48 S4cR07s6N2RMEpqL9MmSIOQGHe+tm4pCGleGgPGY9vPC4RhSO52wC237PpcReYeSaUV8 7BHrK9L8w0bUn2yBjqAhFQVwcBs/joEegRCBHadD+E8Jp9jHE2YqrmJrhDH+WZ2LWFFN 9o1vV89u1PGOA4Y/gMV8XQo8uJKY+5GmSoIHJPW/+Bnk/snzfNpJJeZwyK0A29zWsu7I SuICBlrvxWbG1FdIw3NtHjnG6ymSjHKKfMRzNQaU3eENpJhIi7driniQ+R8idrGA6SpM SERg== X-Gm-Message-State: AOAM530S2bXmb0WLCI8q7fVURFPAxFWbjb2VmRMu06qlBH/UMlK/hd8Y wV2x1aBPU5DLdEfhQHG5pBbbiwKUAL1N3qno1w== X-Received: by 2002:aa7:c9c3:: with SMTP id i3mr1191855edt.236.1603442612866; Fri, 23 Oct 2020 01:43:32 -0700 (PDT) MIME-Version: 1.0 References: <20201021221931.931878-1-marijns95@gmail.com> In-Reply-To: From: Marek Czerski Date: Fri, 23 Oct 2020 10:43:21 +0200 Message-ID: Subject: Re: [PATCH BlueZ] audio: avrcp: Split supported events between target and controller To: Marijn Suijten Cc: Luiz Augusto von Dentz , "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) {Hi= Marijn, Luiz, I tested this patch in a use case where bluez acts as a2dp sink and an andorid phone as a2dp source. It is working as expected. czw., 22 pa=C5=BA 2020 o 23:59 Marijn Suijten napisa= =C5=82(a): > > Luiz, > > On Thu, 22 Oct 2020 at 22:11, Luiz Augusto von Dentz > wrote: > > > > Marijn, > > > > On Wed, Oct 21, 2020 at 3:19 PM Marijn Suijten wr= ote: > > > > > > supported_events was previously initialized based on whatever the AV > > > Remote Controller profile running on the peer device could request ba= sed > > > on its version, and assumes BlueZ is running in the AV Remote Target > > > profile. > > > If however BlueZ runs the Remote Controller profile (is an audio sink= ) > > > against a Remote Target profile on the peer (the audio source) this > > > version is incorrectly taken into account: a Remote Controller profil= e > > > on the peer is not involved in this connection. If its version is to= o > > > low supported_events will not contain all events the peer might > > > rightfully attempt to register. > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > > > > This is particularly problematic with Android phones as an A2DP audio > > > source playing back to BlueZ which is the sink. Most Android phones > > > report their Remote Controller profile version as 1.3 when initializi= ng > > > as audio source [1] meaning that AVRCP_EVENT_VOLUME_CHANGED is > > > inadvertently rejected in avrcp_handle_register_notification. As > > > mentioned above this profile is of no relevance to the connection, on= ly > > > the Remote Target on the phone (source) and Remote Controller on Blue= Z > > > (sink) take part. > > > > > > The problem is addressed by splitting supported_events in two variabl= es: > > > target_supported_events containing all events the peer Remote Control= ler > > > might attempt to register with the local Remote Target profile, and > > > controller_supported_events containing all events the Remote Target > > > might attempt to register with the local Remote Controller profile. > > > > > > In addition the possible notifications going either way have been > > > limited. An audio source is in control over media playback and will > > > never request playback state changes from the Remote Controller. > > > Likewise the audio sink is in control over its rendering volume and w= ill > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > never have to request volume notifications from the Remote Target. > > > This does however still allow the Remote Controller to send playback > > > control messages to the source, and the Remote Target to send > > > SetAbsoluteVolume to the sink; both of which are not notifications. > > > > > > [1]: https://android.googlesource.com/platform/system/bt/+/android-11= .0.0_r4/bta/av/bta_av_main.cc#761 > > > > > > --- > > > > > > Hi Luiz, Marek, > > > > > > This is a preliminary version of the patch that aims to address the > > > issues covered in our mail thread. Keep in mind it is "intentionally= " > > > messy; I commented out unexpected events based on logically deriving = the > > > possibilities (as described in the message above) without checking if > > > this is in accordance with the documentation. > > > > > > I still have to test this between two devices that can both run an au= dio > > > sink and source, such as two machines running BlueZ. Playing back au= dio > > > both ways should never make this collapse on its own, though I think = at > > > that point multiple transports are associated with a device and > > > media_transport_is_source would be lying, based on whichever transpor= t > > > comes first in the list. Likewise registered_events needs to be spli= t > > > in two variables as well. > > > > > > I'm not sure what's causing the race condition Marek was observing. = I > > > assume the call to avrcp_get_capabilities or avrcp_connect_browsing i= n > > > controller_init triggers the peer to start requesting capabilities an= d > > > registering for notifications, before target_init is called (which wo= uld > > > previously be too late to initialize supported_events). That case wi= ll > > > also be addressed in this patch, but if it happens "at random" becaus= e > > > the pdu handler is registered before supported_events is assigned I > > > propose to split session_init_control in 3 steps instead: > > > > > > 1. Retrieve remote profile versions and set up *_supported_events; > > > 2. Register pdu and passthrough handler; > > > 3. The rest from {controller,target}_init. > > > > > > Looking forward to hearing your suggestions. > > > > > > Best regards, > > > Marijn Suijten > > > > > > profiles/audio/avrcp.c | 58 +++++++++++++++++++++++++++++++-----= -- > > > profiles/audio/transport.c | 20 +++++++++++++ > > > profiles/audio/transport.h | 1 + > > > 3 files changed, 69 insertions(+), 10 deletions(-) > > > > > > diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c > > > index c093deac8..af5dc4212 100644 > > > --- a/profiles/audio/avrcp.c > > > +++ b/profiles/audio/avrcp.c > > > @@ -269,7 +269,13 @@ struct avrcp { > > > unsigned int control_id; > > > unsigned int browsing_id; > > > unsigned int browsing_timer; > > > - uint16_t supported_events; > > > + // TODO: Swap names to make them represent the name of the pe= er profile, > > > > Please do not use c++ tyle when commenting use /* */ > > This is a preliminary patch to aid our discussions and show a > potential solution to the problem. If you want to enforce commenting > style there as well I'll clean that up next time. It wasn't my intent > to get this merged at all anyway. > > > > > > + // instead of the opposite local profile? > > > + /* Events the Remote Target expects based on peer Remote Cont= roller version */ > > > + uint16_t target_supported_events; > > > + /* Events the Remote Controller expects based on peer Remote = Target version */ > > > + uint16_t controller_supported_events; > > > + // TODO: Registered_events should be split across controller/= target too! > > > uint16_t registered_events; > > > > I'd prefer to have a separate struct: > > > > struct avrcp_role { > > uint16_t version; > > uint16_t supported_events; > > uint16_t registered_events; > > }; > > Agreed, though I don't know if we need the version. Perhaps this comes > in handy in other places. > > > struct avrcp { > > ... > > struct avrcp_role ct; > > struct avrcp_role tg; > > CT/TG? I've read section 2.2.1 of the 1.6.2 over and over again, this > doesn't make sense. > > > > > > uint8_t transaction; > > > uint8_t transaction_events[AVRCP_EVENT_LAST + 1]; > > > @@ -1060,7 +1066,7 @@ static uint8_t avrcp_handle_get_capabilities(st= ruct avrcp *session, > > > struct avrcp_header *= pdu, > > > uint8_t transaction) > > > { > > > - uint16_t len =3D ntohs(pdu->params_len); > > > + uint16_t len =3D ntohs(pdu->params_len), supported_events; > > > unsigned int i; > > > > > > if (len !=3D 1) > > > @@ -1068,6 +1074,11 @@ static uint8_t avrcp_handle_get_capabilities(s= truct avrcp *session, > > > > > > DBG("id=3D%u", pdu->params[0]); > > > > > > + if (media_transport_is_source(session->dev)) > > > + supported_events =3D session->target_supported_events= ; > > > + else > > > + supported_events =3D session->controller_supported_ev= ents; > > > > I guess you did not fully understand my comments regarding AVRCP > > roles, the roles are solely based on client/server, so here it is a > > server/target no matter the A2DP role since we are receiving a > > command. > I think that we all have correct understanding and only wording is misleadi= ng. What I believe Marijn wants to express in this piece of code is that: AVRCP_GET_CAPABILITIES command can be sent only from the peer acting as a CT role, but local device capabilities are depending on a2dp role. It means that if the local device is acting an a2dp sink role in this specific session it should present capabilities that it actually can handle as a2dp sink which is only the absolute volume. And if the local device is acting an a2dp source role in this specific session it should present capabilities for playback control such as play or pause. I'm assuming here that the scenario where both devices (local and peer) are acting both a2dp roles (which means that audio is flowing in both directions) is not realistic and maybe not even allowed by the specification. Maybe renaming target_supported_events and controller_supported_events names for source_supported_events and sink_supported_events would be more readable. Because the supported events clearly depend on the a2dp role of the local device (and on the avrcp version of the peer). > Indeed, I don't understand this anymore at all. The A2DP role should > map directly to the AV Remote (0x110e) and AV Remote Target (0x110c). No, where is that written in the specification ? A2DP sink can act both AVRCP roles. > It is my understanding that these define what _direction_ events could > possibly go in. Yes, "AV Remote (0x110e) and AV Remote Target (0x110c)" define the direction of the events. AV Remote (0x110e) is the one that sends commands and receives notifications and AV Remote Target (0x110c) is the one that receives commands and sends notifications. >For example in 6.13.2 SetAbsoluteVolume we find: > > It is expected that the audio sink will perform as the TG for this co= mmand. > Exactly, for playback control a2dp sink plays the CT role, but for absolute volume it must play TG role. This is exactly proving that the a2dp sink role does not force avrcp role. The avrcp role depends on the action (playback control or volume control). > Then, in 6.13.3 Notify Volume Change: > > This Register Notification event is used by the CT to detect when > the volume has been changed locally on the TG, or what the actual > volume level is following use of relative volume commands. > [...] > It is expected for this command that the audio sink fulfills the TG r= ole. > Another proof for duality of AVRCP roles. For playback control local device act the CT role, and for absolute volume the local device act TG role. > That matches what I am trying to explain in all these mails. We > cannot assume in this function that we are always the server or TG; If we are in any of the control_handlers (for example in avrcp_handle_get_capabilities) we for sure are TG (AVRCP target) because only CT is allowed to send commands. We just don't know if we are a2dp source or sink. >if > we are the audio source, we must be the CT (when Absolute Volume is > concerned). When we are the audio source we must implement CT role for controlling the absolute volume, but that does not mean that in avrcp_handle_get_capabilities we play this role. >This is in accordance with the logical expectation that > the sink is in control of the volume. Yes, but the sink is not the one that is sending SetAbsoluteVolume commands, it is the source that is sending those commands. >The target (source) can change > it by sending SetAbsoluteVolume No, target cannot send commands. >, or ask the controller (sink) to > update it about volume changes by means of registering this event. No, target cannot send commands so it cannot register events on controller. > Not the other way around (what would happen if the sink starts sending > SetAbsoluteVolume to the source?). Yes, sink is not supposed to send SetAbsoluteVolume command, but the source act as a CT role in the context of absolute volume. I guess that here is the confusion. > What can we do to clarify the difference between CT/TG, > target/controller (the profiles), source/sink, client/server? > Terminology is going all over the place to the point that I don't know > how to express my understanding of the system (nor specs) anymore. > We should stick strictly to specification terminology. 1. target/controller are not profiles, they are roles of the AVRCP profile. So the profile is only one which has two roles. 2. These roles are represented by the services "AV Remote (0x110e)" and "AV Remote Target (0x110c)" in the service records. So if one device is including "AV Remote (0x110e)" service in one of its service records it means it can act the CT role (but this is not defining what a2dp role it plays !). 3. source/sink are the roles of the A2DP profile. So there is one A2DP profile with two roles. 4. client/server - don't use that, there is nothing like that in the specification. So bottom line, the way I understand this is that in case when we are the a2dp sink: 1. if we want to control playback on the a2dp source we must implement AVRCP CT role for sending playback commands 2, if we want our volume to be controlled by the a2dp source we must implement AVRCP TG role for receiving commands. > > > switch (pdu->params[0]) { > > > case CAP_COMPANY_ID: > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > for (i =3D 0; i < G_N_ELEMENTS(company_ids); i++) { > > > @@ -1082,7 +1093,7 @@ static uint8_t avrcp_handle_get_capabilities(st= ruct avrcp *session, > > > case CAP_EVENTS_SUPPORTED: > > > pdu->params[1] =3D 0; > > > for (i =3D 1; i <=3D AVRCP_EVENT_LAST; i++) { > > > - if (session->supported_events & (1 << i)) { > > > + if (supported_events & (1 << i)) { > > > pdu->params[1]++; > > > pdu->params[pdu->params[1] + 1] =3D i= ; > > > } > > > @@ -1607,7 +1618,7 @@ static uint8_t avrcp_handle_register_notificati= on(struct avrcp *session, > > > { > > > struct avrcp_player *player =3D target_get_player(session); > > > struct btd_device *dev =3D session->dev; > > > - uint16_t len =3D ntohs(pdu->params_len); > > > + uint16_t len =3D ntohs(pdu->params_len), supported_events; > > > uint64_t uid; > > > int8_t volume; > > > > > > @@ -1620,7 +1631,12 @@ static uint8_t avrcp_handle_register_notificat= ion(struct avrcp *session, > > > goto err; > > > > > > /* Check if event is supported otherwise reject */ > > > - if (!(session->supported_events & (1 << pdu->params[0]))) > > > + if (media_transport_is_source(session->dev)) > > > + supported_events =3D session->target_supported_events= ; > > > + else > > > + supported_events =3D session->controller_supported_ev= ents; > > > + > > > + if (!(supported_events & (1 << pdu->params[0]))) > > > goto err; > > > > Ditto. > > How do you propose to figure out what "role" we are providing when > this function is called? As explained above it depends if we are > sink/controller or source/target what events we are expecting to be > registered. > Here we are for sure TG because we are receiving a command. This is the A2DP role which is unknown and on which our capabilities depends. But I believe that the code here is exactly doing that, it checks if we are a2dp source or sink. > > > > > switch (pdu->params[0]) { > > > @@ -4129,7 +4145,11 @@ static void target_init(struct avrcp *session) > > > media_transport_update_device_volume(session->dev, in= it_volume); > > > } > > > > > > - session->supported_events |=3D (1 << AVRCP_EVENT_STATUS_CHANG= ED) | > > > + if (target->version < 0x0103) > > > + return; > > > + > > > + session->target_supported_events |=3D > > > + (1 << AVRCP_EVENT_STATUS_CHANGED) | > > > (1 << AVRCP_EVENT_TRACK_CHANGED) | > > > (1 << AVRCP_EVENT_TRACK_REACHED_START= ) | > > > (1 << AVRCP_EVENT_TRACK_REACHED_END) = | > > > @@ -4138,10 +4158,13 @@ static void target_init(struct avrcp *session= ) > > > if (target->version < 0x0104) > > > return; > > > > > > - session->supported_events |=3D > > > + session->target_supported_events |=3D > > > (1 << AVRCP_EVENT_ADDRESSED_PLAYER_CH= ANGED) | > > > - (1 << AVRCP_EVENT_AVAILABLE_PLAYERS_C= HANGED) | > > > - (1 << AVRCP_EVENT_VOLUME_CHANGED); > > > + (1 << AVRCP_EVENT_AVAILABLE_PLAYERS_C= HANGED); > > > + // Does not make sense here; the remo= te is the > > > + // rendering device and in control, i= t'll never > > > + // request this notification. > > > + // (1 << AVRCP_EVENT_VOLUME_CHANGED); > > > > Again you are think the roles are based on A2DP roles when they are > > not, target supported events should reflect what events we support as > > server, > > I think you are confusing what these variables represent. In the > original BlueZ code this value is based on the version of the peer > AVRCP_REMOTE_UUID. That to me means we are checking whether we are > expecting our peer to register for that particular event, and > rejecting it otherwise. I simply extended this to do the same for the > remote version of the AVRCP_TARGET_UUID profile as well. > What you are suggesting is implicitly encoded as well: if we cannot > handle an event registration even though the peer could realistically > request it based on its version, it's not in the list. > supported_events are used only when receiving commands (get_capabilietes or register_event) and while receiving those commands we play the TG role. So the peer act as CT so it should declare AVRCP_REMOTE_UUID(0x110e) service. So only if the peer has AVRCP_REMOTE_UUID declared supported_events should be initialised. If we are the a2dp source we should declare that we support playback control events. If we are a2dp sink we should declare that we support absolute volume event. So what I believe Luiz is saying is that both supported_events fields (target and controller or better name then source and sink) should be initialized in target_init. But then we have the problem that peer controller wants to register absolute volume event before target_init is called. I think that those supported_events should be statically initialised separately for a2dp sink and source roles. I cannot understand the need for checking the peer side avrcp version, is it against the specification if we declare events that are not supported by the peer version ? If the peer has avrcp version 1.3 and sends registration command of absolute volume event then the peer is not consistent with the specification already. > > so we should indicate that we support volume changed even when > > acting as a A2DP Source although this seems to be always omitting > > volume changed which would be a regression. > > It does not regress, and was tested with a bluetooth headset to > confirm. This is indeed rejecting EVENT_VOLUME_CHANGED, and for a > good reason as explained above. If BlueZ is the source, _it_ will > register this notification with the headset, not the other way around. > Note that get_capabilities_resp/register_notification do not check > *_supported_events, and they shouldn't. > > However, say we flip the roles around and make BlueZ a sink, playing > back from an Android phone. Now avrcp_handle_register_notification > takes controller_supported_events and will happily comply when the > source (the Android phone) registers EVENT_VOLUME_CHANGED. > > To make this even more explicit insert some log lines in > get_capabilities_resp: this clearly shows when connecting headphones > as sink it only supports EVENT_VOLUME_CHANGED - when connecting an > Android phone as source it reports a bunch of playback/player related > events but not EVENT_VOLUME_CHANGED. > > > > > > /* Only check capabilities if controller is not supported */ > > > if (session->controller =3D=3D NULL) > > > @@ -4180,11 +4203,26 @@ static void controller_init(struct avrcp *ses= sion) > > > if (controller->version < 0x0103) > > > return; > > > > > > - avrcp_get_capabilities(session); > > > + // Players should only run on the remote target; they > > > + // should never request notifications about their own > > > + // playback status. > > > + // session->controller_supported_events |=3D > > > + // (1 << AVRCP_EVENT_STATUS_CHANGED) | > > > + // (1 << AVRCP_EVENT_TRACK_CHANGED) | > > > + // (1 << AVRCP_EVENT_TRACK_REACHED_START= ) | > > > + // (1 << AVRCP_EVENT_TRACK_REACHED_END) = | > > > + // (1 << AVRCP_EVENT_SETTINGS_CHANGED); > > > > The controller/client supported_events should reflect what the remote > > target/server supports, so here we should probably not initialize with > > anything (or perhaps initialize with the mandatory ones if there are > > any events that the spec indicates as mandatory) but read the > > supported events from the remote with avrcp_get_capabilities. > > I think we can initialize this list (as well as > target_supported_events) based on what we expect (as explained above), > and AND it as soon as get_capabilities_resp tells us what the remote > can comply with. > > > > if (controller->version < 0x0104) > > > return; > > > > > > + session->controller_supported_events |=3D > > > + // (1 << AVRCP_EVENT_ADDRESSED_PLAYER= _CHANGED) | > > > + // (1 << AVRCP_EVENT_AVAILABLE_PLAYER= S_CHANGED) | > > > + (1 << AVRCP_EVENT_VOLUME_CHANGED); > > > + > > > + avrcp_get_capabilities(session); > > > + > > > if (!(controller->features & AVRCP_FEATURE_BROWSING)) > > > return; > > > > > > diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c > > > index 8248014ae..f5226776f 100644 > > > --- a/profiles/audio/transport.c > > > +++ b/profiles/audio/transport.c > > > @@ -980,3 +980,23 @@ void media_transport_update_device_volume(struct= btd_device *dev, > > > media_transport_update_volume(transport, volu= me); > > > } > > > } > > > + > > > +gboolean media_transport_is_source(struct btd_device *dev) > > > +{ > > > + GSList *l; > > > + const char *uuid; > > > + > > > + if (dev =3D=3D NULL) > > > + return FALSE; > > > + > > > + for (l =3D transports; l; l =3D l->next) { > > > + struct media_transport *transport =3D l->data; > > > + if (transport->device !=3D dev) > > > + continue; > > > + > > > + uuid =3D media_endpoint_get_uuid(transport->endpoint)= ; > > > + return strcasecmp(uuid, A2DP_SOURCE_UUID) =3D=3D 0; > > > + } > > > + > > > + return FALSE; > > > +} > > > diff --git a/profiles/audio/transport.h b/profiles/audio/transport.h > > > index 51a67ea74..eb1621813 100644 > > > --- a/profiles/audio/transport.h > > > +++ b/profiles/audio/transport.h > > > @@ -30,3 +30,4 @@ void transport_get_properties(struct media_transpor= t *transport, > > > int8_t media_transport_get_device_volume(struct btd_device *dev); > > > void media_transport_update_device_volume(struct btd_device *dev, > > > int8_= t volume); > > > +gboolean media_transport_is_source(struct btd_device *dev); > > > -- > > > 2.29.0 > > > > > > > > > -- > > Luiz Augusto von Dentz > > - Marijn --=20 mgr in=C5=BC. Marek Czerski +48 696 842 686