Update constant names for AVRCP 1.4 to avoid confusion.
AVRCP 1.4 introduces status code that is not error code, so using
"status" prefix for both. Also do not use AVRCP prefix for local
constants and add constants for addressed player feature.
---
audio/avrcp.c | 216 ++++++++++++++++++++++++++++++---------------------------
audio/avrcp.h | 17 +++--
audio/media.c | 2 +-
3 files changed, 124 insertions(+), 111 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 89ee112..125baa4 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -61,54 +61,67 @@
/* Company IDs for vendor dependent commands */
#define IEEEID_BTSIG 0x001958
-/* Error codes for metadata transfer */
-#define E_INVALID_COMMAND 0x00
-#define E_INVALID_PARAM 0x01
-#define E_PARAM_NOT_FOUND 0x02
-#define E_INTERNAL 0x03
-
/* Packet types */
-#define AVRCP_PACKET_TYPE_SINGLE 0x00
-#define AVRCP_PACKET_TYPE_START 0x01
-#define AVRCP_PACKET_TYPE_CONTINUING 0x02
-#define AVRCP_PACKET_TYPE_END 0x03
-
-/* PDU types for metadata transfer */
-#define AVRCP_GET_CAPABILITIES 0x10
-#define AVRCP_LIST_PLAYER_ATTRIBUTES 0X11
-#define AVRCP_LIST_PLAYER_VALUES 0x12
-#define AVRCP_GET_CURRENT_PLAYER_VALUE 0x13
-#define AVRCP_SET_PLAYER_VALUE 0x14
-#define AVRCP_GET_PLAYER_ATTRIBUTE_TEXT 0x15
-#define AVRCP_GET_PLAYER_VALUE_TEXT 0x16
-#define AVRCP_DISPLAYABLE_CHARSET 0x17
-#define AVRCP_CT_BATTERY_STATUS 0x18
-#define AVRCP_GET_ELEMENT_ATTRIBUTES 0x20
-#define AVRCP_GET_PLAY_STATUS 0x30
-#define AVRCP_REGISTER_NOTIFICATION 0x31
-#define AVRCP_REQUEST_CONTINUING 0x40
-#define AVRCP_ABORT_CONTINUING 0x41
-#define AVRCP_SET_ABSOLUTE_VOLUME 0x50
-
-/* Capabilities for AVRCP_GET_CAPABILITIES pdu */
+#define PACKET_TYPE_SINGLE 0x00
+#define PACKET_TYPE_START 0x01
+#define PACKET_TYPE_CONTINUING 0x02
+#define PACKET_TYPE_END 0x03
+
+/* Status codes */
+#define STATUS_INVALID_COMMAND 0x00
+#define STATUS_INVALID_PARAMETER 0x01
+#define STATUS_INTERNAL_ERROR 0x03
+#define STATUS_OK 0x04
+#define STATUS_INVALID_PLAYER_ID 0x11
+#define STATUS_NO_AVAILABLE_PLAYERS 0x15
+#define STATUS_ADDRESSED_PLAYER_CHANGED 0x16
+
+/* Control channel PDUs */
+#define PDU_GET_CAPABILITIES 0x10
+#define PDU_LIST_PLAYER_ATTRIBUTES 0X11
+#define PDU_LIST_PLAYER_VALUES 0x12
+#define PDU_GET_CURRENT_PLAYER_VALUE 0x13
+#define PDU_SET_PLAYER_VALUE 0x14
+#define PDU_GET_PLAYER_ATTRIBUTE_TEXT 0x15
+#define PDU_GET_PLAYER_VALUE_TEXT 0x16
+#define PDU_DISPLAYABLE_CHARSET 0x17
+#define PDU_CT_BATTERY_STATUS 0x18
+#define PDU_GET_ELEMENT_ATTRIBUTES 0x20
+#define PDU_GET_PLAY_STATUS 0x30
+#define PDU_REGISTER_NOTIFICATION 0x31
+#define PDU_REQUEST_CONTINUING 0x40
+#define PDU_ABORT_CONTINUING 0x41
+#define PDU_SET_ABSOLUTE_VOLUME 0x50
+#define PDU_SET_ADDRESSED_PLAYER 0x60
+
+/* Capabilities for PDU_GET_CAPABILITIES */
#define CAP_COMPANY_ID 0x02
#define CAP_EVENTS_SUPPORTED 0x03
-#define AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH 5
+/* SDP records features */
+#define FEATURE_CATEGORY_1 0x0001
+#define FEATURE_CATEGORY_2 0x0002
+#define FEATURE_CATEGORY_3 0x0004
+#define FEATURE_CATEGORY_4 0x0008
+#define FEATURE_PLAYER_SETTINGS 0x0010
-#define AVRCP_FEATURE_CATEGORY_1 0x0001
-#define AVRCP_FEATURE_CATEGORY_2 0x0002
-#define AVRCP_FEATURE_CATEGORY_3 0x0004
-#define AVRCP_FEATURE_CATEGORY_4 0x0008
-#define AVRCP_FEATURE_PLAYER_SETTINGS 0x0010
+/* Battery status */
+#define BATTERY_STATUS_NORMAL 0x00
+#define BATTERY_STATUS_WARNING 0x01
+#define BATTERY_STATUS_CRITICAL 0x02
+#define BATTERY_STATUS_EXTERNAL 0x03
+#define BATTERY_STATUS_FULL_CHARGE 0x04
-enum battery_status {
- BATTERY_STATUS_NORMAL = 0,
- BATTERY_STATUS_WARNING = 1,
- BATTERY_STATUS_CRITICAL = 2,
- BATTERY_STATUS_EXTERNAL = 3,
- BATTERY_STATUS_FULL_CHARGE = 4,
-};
+/* Profile versions */
+#define VERSION_UNKNOWN 0x0000
+#define VERSION_1_3 0x0103
+#define VERSION_1_4 0x0104
+
+#define REGISTER_NOTIFICATION_PARAM_LENGTH 5
+
+#define AVRCP_HEADER_LENGTH 7
+#define AVRCP_MTU (AVC_MTU - AVC_HEADER_LENGTH)
+#define AVRCP_PDU_MTU (AVRCP_MTU - AVRCP_HEADER_LENGTH)
#if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -120,7 +133,6 @@ struct avrcp_header {
uint16_t params_len;
uint8_t params[0];
} __attribute__ ((packed));
-#define AVRCP_HEADER_LENGTH 7
#elif __BYTE_ORDER == __BIG_ENDIAN
@@ -132,15 +144,11 @@ struct avrcp_header {
uint16_t params_len;
uint8_t params[0];
} __attribute__ ((packed));
-#define AVRCP_HEADER_LENGTH 7
#else
#error "Unknown byte order"
#endif
-#define AVRCP_MTU (AVC_MTU - AVC_HEADER_LENGTH)
-#define AVRCP_PDU_MTU (AVRCP_MTU - AVRCP_HEADER_LENGTH)
-
struct avrcp_server {
bdaddr_t src;
uint32_t tg_record_id;
@@ -190,10 +198,10 @@ static sdp_record_t *avrcp_ct_record(void)
sdp_data_t *psm, *version, *features;
uint16_t lp = AVCTP_PSM;
uint16_t avrcp_ver = 0x0100, avctp_ver = 0x0103;
- uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
- AVRCP_FEATURE_CATEGORY_2 |
- AVRCP_FEATURE_CATEGORY_3 |
- AVRCP_FEATURE_CATEGORY_4 );
+ uint16_t feat = ( FEATURE_CATEGORY_1 |
+ FEATURE_CATEGORY_2 |
+ FEATURE_CATEGORY_3 |
+ FEATURE_CATEGORY_4 );
record = sdp_record_alloc();
if (!record)
@@ -258,11 +266,11 @@ static sdp_record_t *avrcp_tg_record(void)
sdp_data_t *psm, *version, *features;
uint16_t lp = AVCTP_PSM;
uint16_t avrcp_ver = 0x0104, avctp_ver = 0x0103;
- uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
- AVRCP_FEATURE_CATEGORY_2 |
- AVRCP_FEATURE_CATEGORY_3 |
- AVRCP_FEATURE_CATEGORY_4 |
- AVRCP_FEATURE_PLAYER_SETTINGS );
+ uint16_t feat = ( FEATURE_CATEGORY_1 |
+ FEATURE_CATEGORY_2 |
+ FEATURE_CATEGORY_3 |
+ FEATURE_CATEGORY_4 |
+ FEATURE_PLAYER_SETTINGS );
record = sdp_record_alloc();
if (!record)
@@ -333,7 +341,7 @@ static unsigned int attr_get_max_val(uint8_t attr)
return 0;
}
-static const char *battery_status_to_str(enum battery_status status)
+static const char *battery_status_to_str(uint8_t status)
{
switch (status) {
case BATTERY_STATUS_NORMAL:
@@ -390,13 +398,13 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
set_company_id(pdu->company_id, IEEEID_BTSIG);
- pdu->pdu_id = AVRCP_REGISTER_NOTIFICATION;
+ pdu->pdu_id = PDU_REGISTER_NOTIFICATION;
pdu->params[0] = id;
DBG("id=%u", id);
switch (id) {
- case AVRCP_EVENT_STATUS_CHANGED:
+ case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED:
size = 2;
pdu->params[1] = *((uint8_t *)data);
@@ -581,7 +589,7 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
return AVC_CTYPE_STABLE;
case CAP_EVENTS_SUPPORTED:
pdu->params[1] = 4;
- pdu->params[2] = AVRCP_EVENT_STATUS_CHANGED;
+ pdu->params[2] = AVRCP_EVENT_PLAYBACK_STATUS_CHANGED;
pdu->params[3] = AVRCP_EVENT_TRACK_CHANGED;
pdu->params[4] = AVRCP_EVENT_TRACK_REACHED_START;
pdu->params[5] = AVRCP_EVENT_TRACK_REACHED_END;
@@ -592,7 +600,7 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -606,7 +614,7 @@ static uint8_t avrcp_handle_list_player_attributes(struct avrcp_player *player,
if (len != 0) {
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -653,7 +661,7 @@ static uint8_t avrcp_handle_list_player_values(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -715,7 +723,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
if (attr_ids != NULL) {
player->pending_pdu = pending_pdu_new(pdu->pdu_id, attr_ids,
offset);
- pdu->packet_type = AVRCP_PACKET_TYPE_START;
+ pdu->packet_type = PACKET_TYPE_START;
}
pdu->params[0] = len;
@@ -724,7 +732,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
return AVC_CTYPE_STABLE;
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -781,7 +789,7 @@ static uint8_t avrcp_handle_get_current_player_value(struct avrcp_player *player
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -802,7 +810,7 @@ static uint8_t avrcp_handle_set_player_value(struct avrcp_player *player,
* and set the existent ones. Sec. 5.2.4 is not clear however how to
* indicate that a certain ID was not accepted. If at least one
* attribute is valid, we respond with no parameters. Otherwise an
- * E_INVALID_PARAM is sent.
+ * STATUS_INVALID_PARAMETER is sent.
*/
for (len = 0, i = 0, param = &pdu->params[1]; i < pdu->params[0];
i++, param += 2) {
@@ -820,7 +828,7 @@ static uint8_t avrcp_handle_set_player_value(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -832,7 +840,7 @@ static uint8_t avrcp_handle_displayable_charset(struct avrcp_player *player,
if (len < 3) {
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -864,7 +872,7 @@ static uint8_t avrcp_handle_ct_battery_status(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -879,7 +887,7 @@ static uint8_t avrcp_handle_get_play_status(struct avrcp_player *player,
if (len != 0) {
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -918,7 +926,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
goto err;
switch (pdu->params[0]) {
- case AVRCP_EVENT_STATUS_CHANGED:
+ case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED:
len = 2;
pdu->params[1] = player->cb->get_status(player->user_data);
@@ -948,7 +956,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -978,9 +986,9 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
if (pending->attr_ids == NULL) {
g_free(player->pending_pdu);
player->pending_pdu = NULL;
- pdu->packet_type = AVRCP_PACKET_TYPE_END;
+ pdu->packet_type = PACKET_TYPE_END;
} else {
- pdu->packet_type = AVRCP_PACKET_TYPE_CONTINUING;
+ pdu->packet_type = PACKET_TYPE_CONTINUING;
}
pdu->params_len = htons(len);
@@ -988,7 +996,7 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
return AVC_CTYPE_STABLE;
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -1014,7 +1022,7 @@ static uint8_t avrcp_handle_abort_continuing(struct avrcp_player *player,
err:
pdu->params_len = htons(1);
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
return AVC_CTYPE_REJECTED;
}
@@ -1025,33 +1033,33 @@ static struct pdu_handler {
struct avrcp_header *pdu,
uint8_t transaction);
} handlers[] = {
- { AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
+ { PDU_GET_CAPABILITIES, AVC_CTYPE_STATUS,
avrcp_handle_get_capabilities },
- { AVRCP_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
+ { PDU_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
avrcp_handle_list_player_attributes },
- { AVRCP_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
+ { PDU_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
avrcp_handle_list_player_values },
- { AVRCP_GET_ELEMENT_ATTRIBUTES, AVC_CTYPE_STATUS,
+ { PDU_GET_ELEMENT_ATTRIBUTES, AVC_CTYPE_STATUS,
avrcp_handle_get_element_attributes },
- { AVRCP_GET_CURRENT_PLAYER_VALUE, AVC_CTYPE_STATUS,
+ { PDU_GET_CURRENT_PLAYER_VALUE, AVC_CTYPE_STATUS,
avrcp_handle_get_current_player_value },
- { AVRCP_SET_PLAYER_VALUE, AVC_CTYPE_CONTROL,
+ { PDU_SET_PLAYER_VALUE, AVC_CTYPE_CONTROL,
avrcp_handle_set_player_value },
- { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
+ { PDU_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
NULL },
- { AVRCP_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
+ { PDU_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
NULL },
- { AVRCP_DISPLAYABLE_CHARSET, AVC_CTYPE_STATUS,
+ { PDU_DISPLAYABLE_CHARSET, AVC_CTYPE_STATUS,
avrcp_handle_displayable_charset },
- { AVRCP_CT_BATTERY_STATUS, AVC_CTYPE_STATUS,
+ { PDU_CT_BATTERY_STATUS, AVC_CTYPE_STATUS,
avrcp_handle_ct_battery_status },
- { AVRCP_GET_PLAY_STATUS, AVC_CTYPE_STATUS,
+ { PDU_GET_PLAY_STATUS, AVC_CTYPE_STATUS,
avrcp_handle_get_play_status },
- { AVRCP_REGISTER_NOTIFICATION, AVC_CTYPE_NOTIFY,
+ { PDU_REGISTER_NOTIFICATION, AVC_CTYPE_NOTIFY,
avrcp_handle_register_notification },
- { AVRCP_REQUEST_CONTINUING, AVC_CTYPE_CONTROL,
+ { PDU_REQUEST_CONTINUING, AVC_CTYPE_CONTROL,
avrcp_handle_request_continuing },
- { AVRCP_ABORT_CONTINUING, AVC_CTYPE_CONTROL,
+ { PDU_ABORT_CONTINUING, AVC_CTYPE_CONTROL,
avrcp_handle_abort_continuing },
{ },
};
@@ -1079,7 +1087,7 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
pdu->rsvd = 0;
if (operand_count < AVRCP_HEADER_LENGTH) {
- pdu->params[0] = E_INVALID_COMMAND;
+ pdu->params[0] = STATUS_INVALID_COMMAND;
goto err_metadata;
}
@@ -1089,21 +1097,21 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
}
if (!handler || handler->code != *code) {
- pdu->params[0] = E_INVALID_COMMAND;
+ pdu->params[0] = STATUS_INVALID_COMMAND;
goto err_metadata;
}
if (!handler->func) {
- pdu->params[0] = E_INVALID_PARAM;
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
goto err_metadata;
}
*code = handler->func(player, pdu, transaction);
if (*code != AVC_CTYPE_REJECTED &&
- pdu->pdu_id != AVRCP_GET_ELEMENT_ATTRIBUTES &&
- pdu->pdu_id != AVRCP_REQUEST_CONTINUING &&
- pdu->pdu_id != AVRCP_ABORT_CONTINUING)
+ pdu->pdu_id != PDU_GET_ELEMENT_ATTRIBUTES &&
+ pdu->pdu_id != PDU_REQUEST_CONTINUING &&
+ pdu->pdu_id != PDU_ABORT_CONTINUING)
player_abort_pending_pdu(player);
return AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
@@ -1122,7 +1130,7 @@ size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
*code = AVC_CTYPE_REJECTED;
pdu->params_len = htons(1);
- pdu->params[0] = E_INTERNAL;
+ pdu->params[0] = STATUS_INTERNAL_ERROR;
DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
pdu->pdu_id, company_id, pdu->params_len);
@@ -1168,17 +1176,17 @@ static gboolean avrcp_handle_volume_changed(struct avctp *session,
static void register_volume_notification(struct avrcp_player *player)
{
- uint8_t buf[AVRCP_HEADER_LENGTH + AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH];
+ uint8_t buf[AVRCP_HEADER_LENGTH + REGISTER_NOTIFICATION_PARAM_LENGTH];
struct avrcp_header *pdu = (void *) buf;
uint8_t length;
memset(buf, 0, sizeof(buf));
set_company_id(pdu->company_id, IEEEID_BTSIG);
- pdu->pdu_id = AVRCP_REGISTER_NOTIFICATION;
- pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;
+ pdu->pdu_id = PDU_REGISTER_NOTIFICATION;
+ pdu->packet_type = PACKET_TYPE_SINGLE;
pdu->params[0] = AVRCP_EVENT_VOLUME_CHANGED;
- pdu->params_len = htons(AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH);
+ pdu->params_len = htons(REGISTER_NOTIFICATION_PARAM_LENGTH);
length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
@@ -1236,7 +1244,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
desc = list->data;
- if (desc && desc->version >= 0x0104)
+ if (desc && desc->version >= VERSION_1_4)
register_volume_notification(player);
sdp_list_free(list, free);
@@ -1456,7 +1464,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
set_company_id(pdu->company_id, IEEEID_BTSIG);
- pdu->pdu_id = AVRCP_SET_ABSOLUTE_VOLUME;
+ pdu->pdu_id = PDU_SET_ABSOLUTE_VOLUME;
pdu->params[0] = volume;
pdu->params_len = htons(1);
diff --git a/audio/avrcp.h b/audio/avrcp.h
index bf11a6c..95f69a5 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -69,12 +69,17 @@
#define AVRCP_PLAY_STATUS_ERROR 0xFF
/* Notification events */
-#define AVRCP_EVENT_STATUS_CHANGED 0x01
-#define AVRCP_EVENT_TRACK_CHANGED 0x02
-#define AVRCP_EVENT_TRACK_REACHED_END 0x03
-#define AVRCP_EVENT_TRACK_REACHED_START 0x04
-#define AVRCP_EVENT_VOLUME_CHANGED 0x0d
-#define AVRCP_EVENT_LAST AVRCP_EVENT_VOLUME_CHANGED
+#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01
+#define AVRCP_EVENT_TRACK_CHANGED 0x02
+#define AVRCP_EVENT_TRACK_REACHED_END 0x03
+#define AVRCP_EVENT_TRACK_REACHED_START 0x04
+#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05
+#define AVRCP_EVENT_PLAYER_SETTING_CHANGED 0x08
+#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09
+#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0A
+#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0B
+#define AVRCP_EVENT_VOLUME_CHANGED 0x0D
+#define AVRCP_EVENT_LAST AVRCP_EVENT_VOLUME_CHANGED
struct avrcp_player_cb {
int (*get_setting) (uint8_t attr, void *user_data);
diff --git a/audio/media.c b/audio/media.c
index 1956653..4e23273 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1414,7 +1414,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
mp->status = val;
- avrcp_player_event(mp->player, AVRCP_EVENT_STATUS_CHANGED, &val);
+ avrcp_player_event(mp->player, AVRCP_EVENT_PLAYBACK_STATUS_CHANGED, &val);
return TRUE;
}
--
on behalf of ST-Ericsson
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> Fix coding style issue.
> ---
> ?audio/avrcp.c | ? 16 ++++++++--------
> ?1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/audio/avrcp.c b/audio/avrcp.c
> index fec4e6c..4c545e3 100644
> --- a/audio/avrcp.c
> +++ b/audio/avrcp.c
> @@ -1125,17 +1125,17 @@ err_metadata:
>
> ?size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
> ?{
> - ? ?struct avrcp_header *pdu = (void *) operands;
> - ? ?uint32_t company_id = get_company_id(pdu->company_id);
> + ? ? ? struct avrcp_header *pdu = (void *) operands;
> + ? ? ? uint32_t company_id = get_company_id(pdu->company_id);
>
> - ? ?*code = AVC_CTYPE_REJECTED;
> - ? ?pdu->params_len = htons(1);
> - ? ?pdu->params[0] = STATUS_INTERNAL_ERROR;
> + ? ? ? *code = AVC_CTYPE_REJECTED;
> + ? ? ? pdu->params_len = htons(1);
> + ? ? ? pdu->params[0] = STATUS_INTERNAL_ERROR;
>
> - ? ?DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
> - ? ? ? ? ? ?pdu->pdu_id, company_id, pdu->params_len);
> + ? ? ? DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
> + ? ? ? ? ? ? ? pdu->pdu_id, company_id, pdu->params_len);
>
> - ? ?return AVRCP_HEADER_LENGTH + 1;
> + ? ? ? return AVRCP_HEADER_LENGTH + 1;
> ?}
>
> ?static struct avrcp_server *find_server(GSList *list, const bdaddr_t *src)
> --
> on behalf of ST-Ericsson
Applied, thanks.
--
Luiz Augusto von Dentz
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> This patch fix simple typo in documentation of API.
> ---
> ?doc/adapter-api.txt ? | ? ?2 +-
> ?doc/audio-api.txt ? ? | ? ?2 +-
> ?doc/device-api.txt ? ?| ? ?2 +-
> ?doc/media-api.txt ? ? | ? ?2 +-
> ?doc/proximity-api.txt | ? ?2 +-
> ?5 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
> index dccb6bf..916e941 100644
> --- a/doc/adapter-api.txt
> +++ b/doc/adapter-api.txt
> @@ -24,7 +24,7 @@ Methods ? ? ? ? ? ? ? dict GetProperties()
> ? ? ? ? ? ? ? ?void SetProperty(string name, variant value)
>
> ? ? ? ? ? ? ? ? ? ? ? ?Changes the value of the specified property. Only
> - ? ? ? ? ? ? ? ? ? ? ? properties that are listed a read-write are changeable.
> + ? ? ? ? ? ? ? ? ? ? ? properties that are listed as read-write are changeable.
> ? ? ? ? ? ? ? ? ? ? ? ?On success this will emit a PropertyChanged signal.
>
> ? ? ? ? ? ? ? ? ? ? ? ?Possible Errors: org.bluez.Error.InvalidArguments
> diff --git a/doc/audio-api.txt b/doc/audio-api.txt
> index 02291fd..9b1737d 100644
> --- a/doc/audio-api.txt
> +++ b/doc/audio-api.txt
> @@ -122,7 +122,7 @@ Methods ? ? ? ? ? ? void Connect()
> ? ? ? ? ? ? ? ?void SetProperty(string name, variant value)
>
> ? ? ? ? ? ? ? ? ? ? ? ?Changes the value of the specified property. Only
> - ? ? ? ? ? ? ? ? ? ? ? properties that are listed a read-write are changeable.
> + ? ? ? ? ? ? ? ? ? ? ? properties that are listed as read-write are changeable.
> ? ? ? ? ? ? ? ? ? ? ? ?On success this will emit a PropertyChanged signal.
>
> ? ? ? ? ? ? ? ? ? ? ? ?Possible Errors: org.bluez.Error.DoesNotExist
> diff --git a/doc/device-api.txt b/doc/device-api.txt
> index 4a170e4..0f34210 100644
> --- a/doc/device-api.txt
> +++ b/doc/device-api.txt
> @@ -25,7 +25,7 @@ Methods ? ? ? ? ? ? ? dict GetProperties()
> ? ? ? ? ? ? ? ?void SetProperty(string name, variant value)
>
> ? ? ? ? ? ? ? ? ? ? ? ?Changes the value of the specified property. Only
> - ? ? ? ? ? ? ? ? ? ? ? properties that are listed a read-write are changeable.
> + ? ? ? ? ? ? ? ? ? ? ? properties that are listed as read-write are changeable.
> ? ? ? ? ? ? ? ? ? ? ? ?On success this will emit a PropertyChanged signal.
>
> ? ? ? ? ? ? ? ? ? ? ? ?Possible Errors: org.bluez.Error.DoesNotExist
> diff --git a/doc/media-api.txt b/doc/media-api.txt
> index 4446439..e5eeaa0 100644
> --- a/doc/media-api.txt
> +++ b/doc/media-api.txt
> @@ -289,7 +289,7 @@ Methods ? ? ? ? ? ? dict GetProperties()
> ? ? ? ? ? ? ? ?void SetProperty(string name, variant value)
>
> ? ? ? ? ? ? ? ? ? ? ? ?Changes the value of the specified property. Only
> - ? ? ? ? ? ? ? ? ? ? ? properties that are listed a read-write can be changed.
> + ? ? ? ? ? ? ? ? ? ? ? properties that are listed as read-write can be changed.
>
> ? ? ? ? ? ? ? ? ? ? ? ?On success this will emit a PropertyChanged signal.
>
> diff --git a/doc/proximity-api.txt b/doc/proximity-api.txt
> index 0c60d47..c8eae50 100644
> --- a/doc/proximity-api.txt
> +++ b/doc/proximity-api.txt
> @@ -19,7 +19,7 @@ Methods ? ? ? ? ? ? ? dict GetProperties()
> ? ? ? ? ? ? ? ?void SetProperty(string name, variant value)
>
> ? ? ? ? ? ? ? ? ? ? ? ?Changes the value of the specified property. Only
> - ? ? ? ? ? ? ? ? ? ? ? properties that are listed a read-write are changeable.
> + ? ? ? ? ? ? ? ? ? ? ? properties that are listed as read-write are changeable.
> ? ? ? ? ? ? ? ? ? ? ? ?On success this will emit a PropertyChanged signal.
>
> ? ? ? ? ? ? ? ? ? ? ? ?Possible Errors: org.bluez.Error.InvalidArguments
> --
> on behalf of ST-Ericsson
This has been applied.
--
Luiz Augusto von Dentz
Set player selected by controller as addressed player.
---
audio/avrcp.c | 33 +++++++++++++++++++++++++++++++++
audio/avrcp.h | 1 +
audio/media.c | 19 ++++++++++++++++++-
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index fae04c0..07f4d22 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1079,6 +1079,37 @@ err:
return AVC_CTYPE_REJECTED;
}
+static uint8_t avrcp_handle_set_addressed_player(struct avrcp_player *player,
+ struct avrcp_header *pdu,
+ uint8_t transaction)
+{
+ uint16_t len = ntohs(pdu->params_len);
+ uint16_t player_id;
+
+ if (len != sizeof(player_id)) {
+ pdu->params[0] = STATUS_INVALID_PARAMETER;
+ return AVC_CTYPE_REJECTED;
+ }
+
+ player_id = bt_get_be16(pdu->params);
+
+ DBG("Remote controller set addressed player id=%u", player_id);
+
+ pdu->params_len = htons(1);
+
+ if (!player->cb->set_addressed_player(player_id, player->user_data)) {
+ if (g_slist_length(player->server->players) == 0)
+ pdu->params[0] = STATUS_NO_AVAILABLE_PLAYERS;
+ else
+ pdu->params[0] = STATUS_INVALID_PLAYER_ID;
+
+ return AVC_CTYPE_REJECTED;
+ }
+
+ pdu->params[0] = STATUS_OK;
+ return AVC_CTYPE_ACCEPTED;
+}
+
static struct pdu_handler {
uint8_t pdu_id;
uint8_t code;
@@ -1114,6 +1145,8 @@ static struct pdu_handler {
avrcp_handle_request_continuing },
{ PDU_ABORT_CONTINUING, AVC_CTYPE_CONTROL,
avrcp_handle_abort_continuing },
+ { PDU_SET_ADDRESSED_PLAYER, AVC_CTYPE_CONTROL,
+ avrcp_handle_set_addressed_player },
{ },
};
diff --git a/audio/avrcp.h b/audio/avrcp.h
index 510dfde..4f7b9e1 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -94,6 +94,7 @@ struct avrcp_player_cb {
gboolean (*is_dummy_player) (void *user_data);
uint16_t (*get_player_id) (void *user_data);
uint16_t (*get_uid_counter) (void *user_data);
+ gboolean (*set_addressed_player) (uint16_t player_id, void *user_data);
};
struct avrcp_player *player;
diff --git a/audio/media.c b/audio/media.c
index c99cde6..ee55a6b 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -120,6 +120,10 @@ struct metadata_value {
static GSList *adapters = NULL;
+static gboolean media_set_addressed_player(struct media_adapter *adapter,
+ const char *sender, const char *path,
+ gboolean local);
+
static void endpoint_request_free(struct endpoint_request *request)
{
if (request->call)
@@ -1418,6 +1422,18 @@ static uint16_t get_uid_counter(void *user_data)
return mp->uid_counter;
}
+static gboolean set_addressed_player(uint16_t player_id, void *user_data)
+{
+ struct media_player *player = user_data;
+ struct media_player *mp;
+
+ mp = media_adapter_find_player_by_id(player->adapter, NULL, player_id);
+ if (!mp)
+ return FALSE;
+
+ return media_set_addressed_player(player->adapter, player->sender, mp->path, FALSE);
+}
+
static struct avrcp_player_cb player_cb = {
.get_setting = get_setting,
.set_setting = set_setting,
@@ -1429,7 +1445,8 @@ static struct avrcp_player_cb player_cb = {
.set_volume = set_volume,
.is_dummy_player = is_dummy_player,
.get_player_id = get_player_id,
- .get_uid_counter = get_uid_counter
+ .get_uid_counter = get_uid_counter,
+ .set_addressed_player = set_addressed_player
};
static void media_player_exit(DBusConnection *connection, void *user_data)
--
on behalf of ST-Ericsson
It is triggered by local change of addressed player on TG while
unregistering currently addressed player.
---
audio/avrcp.c | 35 ++++++++++++++++++++++++++++++++++-
audio/avrcp.h | 2 ++
audio/media.c | 19 ++++++++++++++++++-
3 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 93d9c42..fae04c0 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -199,6 +199,11 @@ static const uint8_t events_to_complete[] = {
AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED
};
+struct addressed_param {
+ uint16_t player_id;
+ uint16_t uid_counter;
+} __attribute__ ((packed));
+
static GSList *servers = NULL;
static unsigned int avctp_id = 0;
@@ -435,6 +440,14 @@ int avrcp_event(struct avrcp_session *session, uint8_t id, void *data)
memcpy(&pdu->params[1], data, sizeof(uint64_t));
break;
+ case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED:
+ size = 5;
+ /* player id */
+ memcpy(&pdu->params[1], data, sizeof(uint16_t));
+ /* uid counter */
+ memcpy(&pdu->params[3], data + 2, sizeof(uint16_t));
+
+ break;
case AVRCP_EVENT_TRACK_REACHED_END:
case AVRCP_EVENT_TRACK_REACHED_START:
case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
@@ -609,12 +622,13 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
return AVC_CTYPE_STABLE;
case CAP_EVENTS_SUPPORTED:
- pdu->params[1] = 5;
+ pdu->params[1] = 6;
pdu->params[2] = AVRCP_EVENT_PLAYBACK_STATUS_CHANGED;
pdu->params[3] = AVRCP_EVENT_TRACK_CHANGED;
pdu->params[4] = AVRCP_EVENT_TRACK_REACHED_START;
pdu->params[5] = AVRCP_EVENT_TRACK_REACHED_END;
pdu->params[6] = AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED;
+ pdu->params[7] = AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED;
pdu->params_len = htons(2 + pdu->params[1]);
return AVC_CTYPE_STABLE;
@@ -940,6 +954,8 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
struct avrcp_session *session = &player->server->session;
uint16_t len = ntohs(pdu->params_len);
uint64_t uid;
+ uint16_t uid_counter;
+ uint16_t player_id;
/*
* 1 byte for EventID, 4 bytes for Playback interval but the latest
@@ -961,6 +977,16 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
break;
+ case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED:
+ len = 5;
+
+ player_id = htons(player->cb->get_player_id(player->user_data));
+ memcpy(&pdu->params[1], &player_id, sizeof(player_id));
+
+ uid_counter = htons(player->cb->get_uid_counter(player->user_data));
+ memcpy(&pdu->params[3], &uid_counter, sizeof(uid_counter));
+
+ break;
case AVRCP_EVENT_TRACK_REACHED_END:
case AVRCP_EVENT_TRACK_REACHED_START:
case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
@@ -1626,12 +1652,19 @@ gboolean avrcp_set_addressed_player(struct avrcp_player *player, gboolean local)
{
struct avrcp_server *server = player->server;
struct avrcp_session *session = &server->session;
+ struct addressed_param parameters;
if (player == server->addressed_player)
return TRUE;
/* if triggered from remote, try to complete events */
if (local) {
+ parameters.player_id = htons(player->cb->get_player_id(player->user_data));
+ parameters.uid_counter = htons(player->cb->get_uid_counter(player->user_data));
+
+ avrcp_event(session, AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED,
+ ¶meters);
+
if (session->version_ct == VERSION_1_3)
avrcp_events_reusing(player);
else
diff --git a/audio/avrcp.h b/audio/avrcp.h
index ec56b40..510dfde 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -92,6 +92,8 @@ struct avrcp_player_cb {
void (*set_volume) (uint8_t volume, struct audio_device *dev,
void *user_data);
gboolean (*is_dummy_player) (void *user_data);
+ uint16_t (*get_player_id) (void *user_data);
+ uint16_t (*get_uid_counter) (void *user_data);
};
struct avrcp_player *player;
diff --git a/audio/media.c b/audio/media.c
index 0c11cf0..c99cde6 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -106,6 +106,7 @@ struct media_player {
uint32_t position;
uint8_t volume;
uint16_t id;
+ uint16_t uid_counter;
GTimer *timer;
};
@@ -1403,6 +1404,20 @@ static gboolean is_dummy_player(void *user_data)
return FALSE;
}
+static uint16_t get_player_id(void *user_data)
+{
+ struct media_player *mp = user_data;
+
+ return mp->id;
+}
+
+static uint16_t get_uid_counter(void *user_data)
+{
+ struct media_player *mp = user_data;
+
+ return mp->uid_counter;
+}
+
static struct avrcp_player_cb player_cb = {
.get_setting = get_setting,
.set_setting = set_setting,
@@ -1412,7 +1427,9 @@ static struct avrcp_player_cb player_cb = {
.get_position = get_position,
.get_status = get_status,
.set_volume = set_volume,
- .is_dummy_player = is_dummy_player
+ .is_dummy_player = is_dummy_player,
+ .get_player_id = get_player_id,
+ .get_uid_counter = get_uid_counter
};
static void media_player_exit(DBusConnection *connection, void *user_data)
--
on behalf of ST-Ericsson
DummyPlayer indicate there is no available players. For AVRCP 1.4
devices use NoAvailblePlayers status code, on the other side, for
AVRCP 1.3 devices use InternalError.
---
audio/avrcp.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
audio/avrcp.h | 1 +
audio/media.c | 13 ++++++++++++-
3 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 710bb16..93d9c42 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1150,6 +1150,41 @@ err_metadata:
return AVRCP_HEADER_LENGTH + 1;
}
+static size_t handle_dummy_player(struct avctp *session, uint8_t transaction,
+ uint8_t *code, uint8_t *subunit,
+ uint8_t *operands, size_t operand_count,
+ void *user_data)
+{
+ struct avrcp_player *player = user_data;
+ struct avrcp_header *pdu = (void *) operands;
+ uint32_t company_id = get_company_id(pdu->company_id);
+
+ if (player->server->session.version_ct < VERSION_1_4)
+ goto ignoring;
+
+ if (pdu->pdu_id == PDU_GET_CAPABILITIES ||
+ pdu->pdu_id == PDU_REGISTER_NOTIFICATION)
+ goto pass;
+
+ *code = AVC_CTYPE_REJECTED;
+ pdu->params_len = htons(1);
+
+ pdu->params[0] = STATUS_NO_AVAILABLE_PLAYERS;
+
+ DBG("cannot handle regard to no available players "
+ "AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
+ pdu->pdu_id, company_id, pdu->params_len);
+
+ return AVRCP_HEADER_LENGTH + 1;
+
+ignoring:
+ DBG("ignoring AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
+ pdu->pdu_id, company_id, pdu->params_len);
+pass:
+ return handle_vendordep_pdu(session, transaction, code, subunit,
+ operands, operand_count, user_data);
+}
+
size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
{
struct avrcp_header *pdu = (void *) operands;
@@ -1157,6 +1192,7 @@ size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
*code = AVC_CTYPE_REJECTED;
pdu->params_len = htons(1);
+
pdu->params[0] = STATUS_INTERNAL_ERROR;
DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
@@ -1260,11 +1296,19 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
player->dev = dev;
- if (!player->handler)
- player->handler = avctp_register_pdu_handler(
+ if (!player->handler) {
+ if (player->cb->is_dummy_player(player->user_data))
+ player->handler = avctp_register_pdu_handler(
+ AVC_OP_VENDORDEP,
+ handle_dummy_player,
+ player);
+ else
+ player->handler = avctp_register_pdu_handler(
AVC_OP_VENDORDEP,
handle_vendordep_pdu,
player);
+ }
+
break;
case AVCTP_STATE_CONNECTED:
rec_tg = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
@@ -1602,8 +1646,13 @@ gboolean avrcp_set_addressed_player(struct avrcp_player *player, gboolean local)
avctp_unregister_pdu_handler(server->addressed_player->handler);
server->addressed_player->handler = 0;
}
- player->handler = avctp_register_pdu_handler(AVC_OP_VENDORDEP,
- handle_vendordep_pdu, player);
+
+ if (player->cb->is_dummy_player(player->user_data))
+ player->handler = avctp_register_pdu_handler(AVC_OP_VENDORDEP,
+ handle_dummy_player, player);
+ else
+ player->handler = avctp_register_pdu_handler(AVC_OP_VENDORDEP,
+ handle_vendordep_pdu, player);
server->addressed_player = player;
diff --git a/audio/avrcp.h b/audio/avrcp.h
index 5c31665..ec56b40 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -91,6 +91,7 @@ struct avrcp_player_cb {
uint32_t (*get_position) (void *user_data);
void (*set_volume) (uint8_t volume, struct audio_device *dev,
void *user_data);
+ gboolean (*is_dummy_player) (void *user_data);
};
struct avrcp_player *player;
diff --git a/audio/media.c b/audio/media.c
index 97bf7df..0c11cf0 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1393,6 +1393,16 @@ static void set_volume(uint8_t volume, struct audio_device *dev, void *user_data
}
}
+static gboolean is_dummy_player(void *user_data)
+{
+ struct media_player *mp = user_data;
+
+ if (strcmp(mp->path, DUMMY_PLAYER) == 0)
+ return TRUE;
+
+ return FALSE;
+}
+
static struct avrcp_player_cb player_cb = {
.get_setting = get_setting,
.set_setting = set_setting,
@@ -1401,7 +1411,8 @@ static struct avrcp_player_cb player_cb = {
.get_metadata = get_metadata,
.get_position = get_position,
.get_status = get_status,
- .set_volume = set_volume
+ .set_volume = set_volume,
+ .is_dummy_player = is_dummy_player
};
static void media_player_exit(DBusConnection *connection, void *user_data)
--
on behalf of ST-Ericsson
For AVRCP 1.4 complete notifications according to the specification
by rejecting all registered notifications with coresponding
transaction id.
For AVRCP 1.3 complete events by reusing already registered events.
This allows to change media player and notify remote controller
about metadata changed.
---
audio/avrcp.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
audio/avrcp.h | 1 +
audio/media.c | 5 +++
3 files changed, 105 insertions(+)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 301c3db..710bb16 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -123,6 +123,8 @@
#define AVRCP_MTU (AVC_MTU - AVC_HEADER_LENGTH)
#define AVRCP_PDU_MTU (AVRCP_MTU - AVRCP_HEADER_LENGTH)
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
struct avrcp_header {
@@ -182,6 +184,21 @@ struct avrcp_player {
GDestroyNotify destroy;
};
+struct status_reply {
+ struct avrcp_header pdu;
+ uint8_t status;
+} __attribute__ ((packed));
+
+static const uint8_t events_to_complete[] = {
+ AVRCP_EVENT_PLAYBACK_STATUS_CHANGED,
+ AVRCP_EVENT_TRACK_CHANGED,
+ AVRCP_EVENT_TRACK_REACHED_END,
+ AVRCP_EVENT_TRACK_REACHED_START,
+ AVRCP_EVENT_PLAYBACK_POS_CHANGED,
+ AVRCP_EVENT_PLAYER_SETTING_CHANGED,
+ AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED
+};
+
static GSList *servers = NULL;
static unsigned int avctp_id = 0;
@@ -1510,3 +1527,85 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
AVC_SUBUNIT_PANEL, buf, sizeof(buf),
avrcp_handle_set_volume, player);
}
+
+static void avrcp_events_completion(struct avrcp_session *session)
+{
+ struct status_reply event;
+ unsigned int i;
+ uint8_t id;
+ int err;
+
+ memset(&event, 0, sizeof(event));
+ set_company_id(event.pdu.company_id, IEEEID_BTSIG);
+ event.pdu.pdu_id = PDU_REGISTER_NOTIFICATION;
+ event.pdu.params_len = htons(1);
+ event.status = STATUS_ADDRESSED_PLAYER_CHANGED;
+
+ for (i = 0; i < ARRAY_SIZE(events_to_complete); i++) {
+ id = 1 << events_to_complete[i];
+
+ if (!(session->registered_events & id))
+ continue;
+
+ err = avctp_send_vendordep(session->avctp_session,
+ session->transaction[events_to_complete[i]],
+ AVC_CTYPE_REJECTED, AVC_SUBUNIT_PANEL,
+ (uint8_t *) &event, sizeof(event));
+ if (err < 0)
+ DBG("Cannot complete event %u: %s (%d)",
+ events_to_complete[i], strerror(-err), err);
+
+ session->registered_events ^= id;
+ }
+}
+
+static void avrcp_events_reusing(struct avrcp_player *player)
+{
+ struct avrcp_player *addressed = player->server->addressed_player;
+ struct avrcp_session *session = &player->server->session;
+ uint8_t play_status;
+ uint64_t uid;
+
+ /* Reusing previously registered events for AVRCP 1.3 devices */
+
+ play_status = player->cb->get_status(player->user_data);
+ uid = player->cb->get_uid(player->user_data);
+
+ if (play_status != addressed->cb->get_status(addressed->user_data))
+ avrcp_event(session, AVRCP_EVENT_PLAYBACK_STATUS_CHANGED,
+ &play_status);
+
+ avrcp_event(session, AVRCP_EVENT_TRACK_CHANGED, &uid);
+}
+
+gboolean avrcp_set_addressed_player(struct avrcp_player *player, gboolean local)
+{
+ struct avrcp_server *server = player->server;
+ struct avrcp_session *session = &server->session;
+
+ if (player == server->addressed_player)
+ return TRUE;
+
+ /* if triggered from remote, try to complete events */
+ if (local) {
+ if (session->version_ct == VERSION_1_3)
+ avrcp_events_reusing(player);
+ else
+ avrcp_events_completion(session);
+ }
+
+ pending_pdu_abort(session);
+
+ player->dev = server->addressed_player->dev;
+
+ if (server->addressed_player->handler) {
+ avctp_unregister_pdu_handler(server->addressed_player->handler);
+ server->addressed_player->handler = 0;
+ }
+ player->handler = avctp_register_pdu_handler(AVC_OP_VENDORDEP,
+ handle_vendordep_pdu, player);
+
+ server->addressed_player = player;
+
+ return TRUE;
+}
diff --git a/audio/avrcp.h b/audio/avrcp.h
index f027733..5c31665 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -111,5 +111,6 @@ void avrcp_unregister_player(struct avrcp_player *player);
int avrcp_event(struct avrcp_session *session, uint8_t id, void *data);
+gboolean avrcp_set_addressed_player(struct avrcp_player *player, gboolean local);
size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands);
diff --git a/audio/media.c b/audio/media.c
index ce5822a..97bf7df 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1803,12 +1803,17 @@ static gboolean media_set_addressed_player(struct media_adapter *adapter,
if (!mp)
return FALSE;
+ if (!avrcp_set_addressed_player(mp->player, local))
+ return FALSE;
+
if (adapter->addressed &&
g_strcmp0(adapter->addressed->path, DUMMY_PLAYER) == 0)
media_player_remove(adapter->addressed);
adapter->addressed = mp;
+ DBG("Set addressed player id=%u to %s", mp->id, path);
+
return TRUE;
}
--
on behalf of ST-Ericsson
There is possibility to register more than one player. This patch
allows to change currently selected player to one the list of
previously registered players. If there are no any registered players
add Dummy Player for compatibility with AVRCP 1.3 device or
AVRCP 1.4 without MultiplePlayer feature.
---
audio/media.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 107 insertions(+), 2 deletions(-)
diff --git a/audio/media.c b/audio/media.c
index f3cca25..ce5822a 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -54,6 +54,8 @@
#define MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint"
#define MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer"
+#define DUMMY_PLAYER "/dummy"
+
#define REQUEST_TIMEOUT (3 * 1000) /* 3 seconds */
struct media_adapter {
@@ -62,6 +64,7 @@ struct media_adapter {
DBusConnection *conn; /* Adapter connection */
GSList *endpoints; /* Endpoints list */
GSList *players; /* Players list */
+ struct media_player *addressed; /* Addressed Player */
};
struct endpoint_request {
@@ -102,6 +105,7 @@ struct media_player {
uint8_t status;
uint32_t position;
uint8_t volume;
+ uint16_t id;
GTimer *timer;
};
@@ -961,6 +965,25 @@ static struct media_player *media_adapter_find_player(
return NULL;
}
+static struct media_player *media_adapter_find_player_by_id(
+ struct media_adapter *adapter,
+ const char *sender,
+ uint16_t player_id) {
+ GSList *l;
+
+ for (l = adapter->players; l; l = l->next) {
+ struct media_player *mp = l->data;
+
+ if (sender && g_strcmp0(mp->sender, sender) != 0)
+ continue;
+
+ if (player_id == mp->id)
+ return mp;
+ }
+
+ return NULL;
+}
+
static void release_player(struct media_player *mp)
{
DBusMessage *msg;
@@ -1673,6 +1696,17 @@ static gboolean track_changed(DBusConnection *connection, DBusMessage *msg,
return TRUE;
}
+/* Need at least one free id to avoid infinite loop */
+static uint16_t get_free_player_id(struct media_adapter *adapter,
+ const char *sender)
+{
+ static uint16_t last_id = 0;
+
+ while (media_adapter_find_player_by_id(adapter, sender, last_id++));
+
+ return last_id - 1;
+}
+
static struct media_player *media_player_create(struct media_adapter *adapter,
const char *sender,
const char *path,
@@ -1680,6 +1714,12 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
{
struct media_player *mp;
+ if (g_slist_length(adapter->players) >= UINT16_MAX) {
+ if (err)
+ *err = -EINVAL;
+ return NULL;
+ }
+
mp = g_new0(struct media_player, 1);
mp->adapter = adapter;
mp->sender = g_strdup(sender);
@@ -1709,10 +1749,11 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
}
mp->settings = g_hash_table_new(g_direct_hash, g_direct_equal);
+ mp->id = get_free_player_id(adapter, sender);
adapter->players = g_slist_append(adapter->players, mp);
- info("Player registered: sender=%s path=%s", sender, path);
+ info("Player registered: sender=%s path=%s id=%d", sender, path, mp->id);
if (err)
*err = 0;
@@ -1720,6 +1761,57 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
return mp;
}
+static gboolean media_set_addressed_player(struct media_adapter *adapter,
+ const char *sender, const char *path,
+ gboolean local)
+{
+ struct media_player *mp;
+ struct metadata_value *value;
+
+ if (adapter->addressed &&
+ g_strcmp0(path, adapter->addressed->path) == 0)
+ return FALSE;
+
+ mp = media_adapter_find_player(adapter, NULL, path);
+ if (!mp && g_strcmp0(path, DUMMY_PLAYER) == 0) {
+ mp = media_player_create(adapter, NULL, DUMMY_PLAYER, NULL);
+ if (!mp)
+ return FALSE;
+
+ mp->position = 0;
+ mp->track = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL,
+ metadata_value_free);
+ value = g_new0(struct metadata_value, 1);
+ value->type = DBUS_TYPE_STRING;
+ value->value.str = g_strdup("no player");
+ g_hash_table_replace(mp->track, GUINT_TO_POINTER(AVRCP_MEDIA_ATTRIBUTE_TITLE), value);
+
+ g_hash_table_replace(mp->settings,
+ GUINT_TO_POINTER(AVRCP_ATTRIBUTE_EQUALIZER),
+ GUINT_TO_POINTER(AVRCP_EQUALIZER_OFF));
+ g_hash_table_replace(mp->settings,
+ GUINT_TO_POINTER(AVRCP_ATTRIBUTE_REPEAT_MODE),
+ GUINT_TO_POINTER(AVRCP_REPEAT_MODE_OFF));
+ g_hash_table_replace(mp->settings,
+ GUINT_TO_POINTER(AVRCP_ATTRIBUTE_SHUFFLE),
+ GUINT_TO_POINTER(AVRCP_SHUFFLE_OFF));
+ g_hash_table_replace(mp->settings,
+ GUINT_TO_POINTER(AVRCP_ATTRIBUTE_SCAN),
+ GUINT_TO_POINTER(AVRCP_SCAN_OFF));
+ }
+
+ if (!mp)
+ return FALSE;
+
+ if (adapter->addressed &&
+ g_strcmp0(adapter->addressed->path, DUMMY_PLAYER) == 0)
+ media_player_remove(adapter->addressed);
+
+ adapter->addressed = mp;
+
+ return TRUE;
+}
+
static gboolean parse_player_properties(struct media_player *mp,
DBusMessageIter *iter)
{
@@ -1762,7 +1854,8 @@ static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
struct media_adapter *adapter = data;
struct media_player *mp;
DBusMessageIter args;
- const char *sender, *path;
+ const char *sender;
+ char *path;
int err;
sender = dbus_message_get_sender(msg);
@@ -1772,6 +1865,8 @@ static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
dbus_message_iter_get_basic(&args, &path);
dbus_message_iter_next(&args);
+ DBG("Registering player sender=%s path=%s", sender, path);
+
if (media_adapter_find_player(adapter, sender, path) != NULL)
return btd_error_already_exists(msg);
@@ -1797,6 +1892,9 @@ static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED, NULL);
+ if (g_strcmp0(adapter->addressed->path, DUMMY_PLAYER) == 0)
+ media_set_addressed_player(adapter, sender, path, TRUE);
+
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
@@ -1814,6 +1912,8 @@ static DBusMessage *unregister_player(DBusConnection *conn, DBusMessage *msg,
sender = dbus_message_get_sender(msg);
+ DBG("Unregistering player sender=%s path=%s", sender, path);
+
player = media_adapter_find_player(adapter, sender, path);
if (player == NULL)
return btd_error_does_not_exist(msg);
@@ -1821,6 +1921,9 @@ static DBusMessage *unregister_player(DBusConnection *conn, DBusMessage *msg,
avrcp_event(avrcp_get_session(player->player), AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED, NULL);
media_player_remove(player);
+ if (g_strcmp0(adapter->addressed->path, path) == 0)
+ media_set_addressed_player(adapter, sender, DUMMY_PLAYER, TRUE);
+
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
@@ -1862,6 +1965,8 @@ int media_register(DBusConnection *conn, const char *path, const bdaddr_t *src)
adapter->conn = dbus_connection_ref(conn);
bacpy(&adapter->src, src);
adapter->path = g_strdup(path);
+ adapter->addressed = NULL;
+ media_set_addressed_player(adapter, NULL, DUMMY_PLAYER, TRUE);
if (!g_dbus_register_interface(conn, path, MEDIA_INTERFACE,
media_methods, NULL, NULL,
--
on behalf of ST-Ericsson
Notify remote controller about change in available players
when player is being registered or unregistered.
---
audio/avrcp.c | 5 ++++-
audio/media.c | 3 +++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index e37ffcf..301c3db 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -420,6 +420,7 @@ int avrcp_event(struct avrcp_session *session, uint8_t id, void *data)
break;
case AVRCP_EVENT_TRACK_REACHED_END:
case AVRCP_EVENT_TRACK_REACHED_START:
+ case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
size = 1;
break;
default:
@@ -591,11 +592,12 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
return AVC_CTYPE_STABLE;
case CAP_EVENTS_SUPPORTED:
- pdu->params[1] = 4;
+ pdu->params[1] = 5;
pdu->params[2] = AVRCP_EVENT_PLAYBACK_STATUS_CHANGED;
pdu->params[3] = AVRCP_EVENT_TRACK_CHANGED;
pdu->params[4] = AVRCP_EVENT_TRACK_REACHED_START;
pdu->params[5] = AVRCP_EVENT_TRACK_REACHED_END;
+ pdu->params[6] = AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED;
pdu->params_len = htons(2 + pdu->params[1]);
return AVC_CTYPE_STABLE;
@@ -944,6 +946,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
break;
case AVRCP_EVENT_TRACK_REACHED_END:
case AVRCP_EVENT_TRACK_REACHED_START:
+ case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
len = 1;
break;
default:
diff --git a/audio/media.c b/audio/media.c
index 5c958c6..f3cca25 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1795,6 +1795,8 @@ static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
return btd_error_invalid_args(msg);
}
+ avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED, NULL);
+
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
@@ -1816,6 +1818,7 @@ static DBusMessage *unregister_player(DBusConnection *conn, DBusMessage *msg,
if (player == NULL)
return btd_error_does_not_exist(msg);
+ avrcp_event(avrcp_get_session(player->player), AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED, NULL);
media_player_remove(player);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
--
on behalf of ST-Ericsson
Register AVRCP before MEDIA interface to avoid searching for or
accessing non-existent AVRCP server.
---
audio/manager.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/audio/manager.c b/audio/manager.c
index d442d1d..076346a 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -1238,6 +1238,9 @@ proceed:
if (enabled.socket)
unix_init();
+ if (enabled.control)
+ btd_register_adapter_driver(&avrcp_server_driver);
+
if (enabled.media)
btd_register_adapter_driver(&media_server_driver);
@@ -1250,9 +1253,6 @@ proceed:
if (enabled.source || enabled.sink)
btd_register_adapter_driver(&a2dp_server_driver);
- if (enabled.control)
- btd_register_adapter_driver(&avrcp_server_driver);
-
btd_register_device_driver(&audio_driver);
*enable_sco = (enabled.gateway || enabled.headset);
--
on behalf of ST-Ericsson
Transactions, events and fragmentation are not specified to
every player. Those fields are specific to profile, so
move them to new AVRCP session structure.
---
audio/avrcp.c | 83 ++++++++++++++++++++++++++++++++-------------------------
audio/avrcp.h | 5 +++-
audio/media.c | 10 +++----
3 files changed, 56 insertions(+), 42 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index cd21ad7..e37ffcf 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -150,8 +150,12 @@ struct avrcp_header {
#endif
struct avrcp_session {
+ struct avctp *avctp_session;
uint16_t version_tg;
uint16_t version_ct;
+ uint16_t registered_events;
+ uint8_t transaction[16];
+ struct pending_pdu *pending_pdu;
};
struct avrcp_server {
@@ -171,14 +175,8 @@ struct pending_pdu {
struct avrcp_player {
struct avrcp_server *server;
- struct avctp *session;
struct audio_device *dev;
-
unsigned int handler;
- uint16_t registered_events;
- uint8_t transaction_events[AVRCP_EVENT_LAST + 1];
- struct pending_pdu *pending_pdu;
-
struct avrcp_player_cb *cb;
void *user_data;
GDestroyNotify destroy;
@@ -387,17 +385,17 @@ static void set_company_id(uint8_t cid[3], const uint32_t cid_in)
cid[2] = cid_in;
}
-int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
+int avrcp_event(struct avrcp_session *session, uint8_t id, void *data)
{
uint8_t buf[AVRCP_HEADER_LENGTH + 9];
struct avrcp_header *pdu = (void *) buf;
uint16_t size;
int err;
- if (player->session == NULL)
+ if (session->avctp_session == NULL)
return -ENOTCONN;
- if (!(player->registered_events & (1 << id)))
+ if (!(session->registered_events & (1 << id)))
return 0;
memset(buf, 0, sizeof(buf));
@@ -430,15 +428,14 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
}
pdu->params_len = htons(size);
-
- err = avctp_send_vendordep(player->session, player->transaction_events[id],
+ err = avctp_send_vendordep(session->avctp_session, session->transaction[id],
AVC_CTYPE_CHANGED, AVC_SUBUNIT_PANEL,
buf, size + AVRCP_HEADER_LENGTH);
if (err < 0)
return err;
/* Unregister event as per AVRCP 1.3 spec, section 5.4.2 */
- player->registered_events ^= 1 << id;
+ session->registered_events ^= 1 << id;
return 0;
}
@@ -537,14 +534,14 @@ static struct pending_pdu *pending_pdu_new(uint8_t pdu_id, GList *attr_ids,
return pending;
}
-static gboolean player_abort_pending_pdu(struct avrcp_player *player)
+static gboolean pending_pdu_abort(struct avrcp_session *session)
{
- if (player->pending_pdu == NULL)
+ if (session->pending_pdu == NULL)
return FALSE;
- g_list_free(player->pending_pdu->attr_ids);
- g_free(player->pending_pdu);
- player->pending_pdu = NULL;
+ g_list_free(session->pending_pdu->attr_ids);
+ g_free(session->pending_pdu);
+ session->pending_pdu = NULL;
return TRUE;
}
@@ -675,6 +672,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
struct avrcp_header *pdu,
uint8_t transaction)
{
+ struct avrcp_session *session = &player->server->session;
uint16_t len = ntohs(pdu->params_len);
uint64_t *identifier = (uint64_t *) &pdu->params[0];
uint16_t pos;
@@ -720,14 +718,14 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
if (!len)
goto err;
- player_abort_pending_pdu(player);
+ pending_pdu_abort(session);
pos = 1;
offset = 0;
attr_ids = player_fill_media_attribute(player, attr_ids, pdu->params,
&pos, &offset);
if (attr_ids != NULL) {
- player->pending_pdu = pending_pdu_new(pdu->pdu_id, attr_ids,
+ session->pending_pdu = pending_pdu_new(pdu->pdu_id, attr_ids,
offset);
pdu->packet_type = PACKET_TYPE_START;
}
@@ -920,6 +918,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
struct avrcp_header *pdu,
uint8_t transaction)
{
+ struct avrcp_session *session = &player->server->session;
uint16_t len = ntohs(pdu->params_len);
uint64_t uid;
@@ -953,8 +952,8 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
}
/* Register event and save the transaction used */
- player->registered_events |= (1 << pdu->params[0]);
- player->transaction_events[pdu->params[0]] = transaction;
+ session->registered_events |= (1 << pdu->params[0]);
+ session->transaction[pdu->params[0]] = transaction;
pdu->params_len = htons(len);
@@ -970,13 +969,14 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
struct avrcp_header *pdu,
uint8_t transaction)
{
+ struct avrcp_session *session = &player->server->session;
uint16_t len = ntohs(pdu->params_len);
struct pending_pdu *pending;
- if (len != 1 || player->pending_pdu == NULL)
+ if (len != 1 || session->pending_pdu == NULL)
goto err;
- pending = player->pending_pdu;
+ pending = session->pending_pdu;
if (pending->pdu_id != pdu->params[0])
goto err;
@@ -990,8 +990,8 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
pdu->pdu_id = pending->pdu_id;
if (pending->attr_ids == NULL) {
- g_free(player->pending_pdu);
- player->pending_pdu = NULL;
+ g_free(session->pending_pdu);
+ session->pending_pdu = NULL;
pdu->packet_type = PACKET_TYPE_END;
} else {
pdu->packet_type = PACKET_TYPE_CONTINUING;
@@ -1010,18 +1010,19 @@ static uint8_t avrcp_handle_abort_continuing(struct avrcp_player *player,
struct avrcp_header *pdu,
uint8_t transaction)
{
+ struct avrcp_session *session = &player->server->session;
uint16_t len = ntohs(pdu->params_len);
struct pending_pdu *pending;
- if (len != 1 || player->pending_pdu == NULL)
+ if (len != 1 || session->pending_pdu == NULL)
goto err;
- pending = player->pending_pdu;
+ pending = session->pending_pdu;
if (pending->pdu_id != pdu->params[0])
goto err;
- player_abort_pending_pdu(player);
+ pending_pdu_abort(session);
pdu->params_len = 0;
return AVC_CTYPE_ACCEPTED;
@@ -1118,7 +1119,7 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
pdu->pdu_id != PDU_GET_ELEMENT_ATTRIBUTES &&
pdu->pdu_id != PDU_REQUEST_CONTINUING &&
pdu->pdu_id != PDU_ABORT_CONTINUING)
- player_abort_pending_pdu(player);
+ pending_pdu_abort(&player->server->session);
return AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
@@ -1196,7 +1197,7 @@ static void register_volume_notification(struct avrcp_player *player)
length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
- avctp_send_vendordep_req(player->session, AVC_CTYPE_NOTIFY,
+ avctp_send_vendordep_req(player->server->session.avctp_session, AVC_CTYPE_NOTIFY,
AVC_SUBUNIT_PANEL, buf, length,
avrcp_handle_volume_changed, player);
}
@@ -1205,6 +1206,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
avctp_state_t new_state, void *user_data)
{
struct avrcp_server *server;
+ struct avrcp_session *session;
struct avrcp_player *player;
const sdp_record_t *rec_tg, *rec_ct;
sdp_list_t *list;
@@ -1214,15 +1216,18 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
if (!server)
return;
+ session = &server->session;
+
player = server->addressed_player;
if (!player)
return;
switch (new_state) {
case AVCTP_STATE_DISCONNECTED:
- player->session = NULL;
+ session->avctp_session = NULL;
+
player->dev = NULL;
- player->registered_events = 0;
+ session->registered_events = 0;
if (player->handler) {
avctp_unregister_pdu_handler(player->handler);
@@ -1231,7 +1236,8 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
break;
case AVCTP_STATE_CONNECTING:
- player->session = avctp_connect(&dev->src, &dev->dst);
+ session->avctp_session = avctp_connect(&dev->src, &dev->dst);
+
player->dev = dev;
if (!player->handler)
@@ -1294,6 +1300,11 @@ void avrcp_disconnect(struct audio_device *dev)
avctp_disconnect(session);
}
+struct avrcp_session *avrcp_get_session(struct avrcp_player *player)
+{
+ return &player->server->session;
+}
+
int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
{
sdp_record_t *record;
@@ -1369,7 +1380,7 @@ static void player_destroy(gpointer data)
if (player->destroy)
player->destroy(player->user_data);
- player_abort_pending_pdu(player);
+ pending_pdu_abort(&player->server->session);
if (player->handler)
avctp_unregister_pdu_handler(player->handler);
@@ -1479,7 +1490,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
if (player == NULL)
return -ENOTSUP;
- if (player->session == NULL)
+ if (server->session.avctp_session == NULL)
return -ENOTCONN;
memset(buf, 0, sizeof(buf));
@@ -1492,7 +1503,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
DBG("volume=%u", volume);
- return avctp_send_vendordep_req(player->session, AVC_CTYPE_CONTROL,
+ return avctp_send_vendordep_req(server->session.avctp_session, AVC_CTYPE_CONTROL,
AVC_SUBUNIT_PANEL, buf, sizeof(buf),
avrcp_handle_set_volume, player);
}
diff --git a/audio/avrcp.h b/audio/avrcp.h
index 95f69a5..f027733 100644
--- a/audio/avrcp.h
+++ b/audio/avrcp.h
@@ -93,11 +93,14 @@ struct avrcp_player_cb {
void *user_data);
};
+struct avrcp_player *player;
+
int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config);
void avrcp_unregister(const bdaddr_t *src);
gboolean avrcp_connect(struct audio_device *dev);
void avrcp_disconnect(struct audio_device *dev);
+struct avrcp_session *avrcp_get_session(struct avrcp_player *player);
int avrcp_set_volume(struct audio_device *dev, uint8_t volume);
struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
@@ -106,7 +109,7 @@ struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
GDestroyNotify destroy);
void avrcp_unregister_player(struct avrcp_player *player);
-int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data);
+int avrcp_event(struct avrcp_session *session, uint8_t id, void *data);
size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands);
diff --git a/audio/media.c b/audio/media.c
index cc8ac37..5c958c6 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1414,7 +1414,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
mp->status = val;
- avrcp_player_event(mp->player, AVRCP_EVENT_PLAYBACK_STATUS_CHANGED, &val);
+ avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_PLAYBACK_STATUS_CHANGED, &val);
return TRUE;
}
@@ -1434,7 +1434,7 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
g_timer_start(mp->timer);
if (!mp->position) {
- avrcp_player_event(mp->player,
+ avrcp_event(avrcp_get_session(mp->player),
AVRCP_EVENT_TRACK_REACHED_START, NULL);
return TRUE;
}
@@ -1448,7 +1448,7 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
*/
if (mp->position == UINT32_MAX ||
(duration && mp->position >= duration->value.num))
- avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_END,
+ avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_TRACK_REACHED_END,
NULL);
return TRUE;
@@ -1641,8 +1641,8 @@ static gboolean parse_player_metadata(struct media_player *mp,
g_timer_start(mp->timer);
uid = get_uid(mp);
- avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_CHANGED, &uid);
- avrcp_player_event(mp->player, AVRCP_EVENT_TRACK_REACHED_START,
+ avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_TRACK_CHANGED, &uid);
+ avrcp_event(avrcp_get_session(mp->player), AVRCP_EVENT_TRACK_REACHED_START,
NULL);
return TRUE;
--
on behalf of ST-Ericsson
This can be used to improve compatibility between
AVRCP 1.3 vs AVRCP 1.4 devices and implementation in stack.
---
audio/avrcp.c | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 4c545e3..cd21ad7 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -149,12 +149,18 @@ struct avrcp_header {
#error "Unknown byte order"
#endif
+struct avrcp_session {
+ uint16_t version_tg;
+ uint16_t version_ct;
+};
+
struct avrcp_server {
bdaddr_t src;
uint32_t tg_record_id;
uint32_t ct_record_id;
GSList *players;
struct avrcp_player *addressed_player;
+ struct avrcp_session session;
};
struct pending_pdu {
@@ -1200,7 +1206,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
{
struct avrcp_server *server;
struct avrcp_player *player;
- const sdp_record_t *rec;
+ const sdp_record_t *rec_tg, *rec_ct;
sdp_list_t *list;
sdp_profile_desc_t *desc;
@@ -1235,19 +1241,32 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
player);
break;
case AVCTP_STATE_CONNECTED:
- rec = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
- if (rec == NULL)
- return;
+ rec_tg = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
+ rec_ct = btd_device_get_record(dev->btd_dev, AVRCP_REMOTE_UUID);
+
+ if (rec_tg && sdp_get_profile_descs(rec_tg, &list) >= 0) {
+ desc = list->data;
+ if (desc)
+ server->session.version_tg = desc->version;
+ else
+ server->session.version_tg = VERSION_UNKNOWN;
+ sdp_list_free(list, free);
+ }
- if (sdp_get_profile_descs(rec, &list) < 0)
- return;
+ if (rec_ct && sdp_get_profile_descs(rec_ct, &list) >= 0) {
+ desc = list->data;
+ if (desc)
+ server->session.version_ct = desc->version;
+ else
+ server->session.version_ct = VERSION_UNKNOWN;
+ sdp_list_free(list, free);
+ }
- desc = list->data;
+ DBG("Remote Controller TG version: 0x%03x", server->session.version_tg);
+ DBG("Remote Controller CT version: 0x%03x", server->session.version_ct);
- if (desc && desc->version >= VERSION_1_4)
+ if (server->session.version_tg >= VERSION_1_4)
register_volume_notification(player);
-
- sdp_list_free(list, free);
default:
return;
}
@@ -1335,6 +1354,9 @@ int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
bacpy(&server->src, src);
+ server->session.version_tg = VERSION_UNKNOWN;
+ server->session.version_ct = VERSION_UNKNOWN;
+
servers = g_slist_append(servers, server);
return 0;
--
on behalf of ST-Ericsson
Fix coding style issue.
---
audio/avrcp.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index fec4e6c..4c545e3 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -1125,17 +1125,17 @@ err_metadata:
size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
{
- struct avrcp_header *pdu = (void *) operands;
- uint32_t company_id = get_company_id(pdu->company_id);
+ struct avrcp_header *pdu = (void *) operands;
+ uint32_t company_id = get_company_id(pdu->company_id);
- *code = AVC_CTYPE_REJECTED;
- pdu->params_len = htons(1);
- pdu->params[0] = STATUS_INTERNAL_ERROR;
+ *code = AVC_CTYPE_REJECTED;
+ pdu->params_len = htons(1);
+ pdu->params[0] = STATUS_INTERNAL_ERROR;
- DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
- pdu->pdu_id, company_id, pdu->params_len);
+ DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
+ pdu->pdu_id, company_id, pdu->params_len);
- return AVRCP_HEADER_LENGTH + 1;
+ return AVRCP_HEADER_LENGTH + 1;
}
static struct avrcp_server *find_server(GSList *list, const bdaddr_t *src)
--
on behalf of ST-Ericsson
AVRCP 1.4 named currently controlled player as "addressed", so use
this name instead of "active". In future there where be more "browsing"
player that will be active, but not addressed.
---
audio/avrcp.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/audio/avrcp.c b/audio/avrcp.c
index 125baa4..fec4e6c 100644
--- a/audio/avrcp.c
+++ b/audio/avrcp.c
@@ -154,7 +154,7 @@ struct avrcp_server {
uint32_t tg_record_id;
uint32_t ct_record_id;
GSList *players;
- struct avrcp_player *active_player;
+ struct avrcp_player *addressed_player;
};
struct pending_pdu {
@@ -1208,7 +1208,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
if (!server)
return;
- player = server->active_player;
+ player = server->addressed_player;
if (!player)
return;
@@ -1401,7 +1401,7 @@ struct avrcp_player *avrcp_register_player(const bdaddr_t *src,
player->destroy = destroy;
if (!server->players)
- server->active_player = player;
+ server->addressed_player = player;
if (!avctp_id)
avctp_id = avctp_add_state_cb(state_changed, NULL);
@@ -1417,8 +1417,8 @@ void avrcp_unregister_player(struct avrcp_player *player)
server->players = g_slist_remove(server->players, player);
- if (server->active_player == player)
- server->active_player = g_slist_nth_data(server->players, 0);
+ if (server->addressed_player == player)
+ server->addressed_player = g_slist_nth_data(server->players, 0);
player_destroy(player);
}
@@ -1453,7 +1453,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
if (server == NULL)
return -EINVAL;
- player = server->active_player;
+ player = server->addressed_player;
if (player == NULL)
return -ENOTSUP;
--
on behalf of ST-Ericsson
This is to avoid conflicts with DBus interface convention
used in BlueZ.
---
audio/media.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/audio/media.c b/audio/media.c
index 4e23273..cc8ac37 100644
--- a/audio/media.c
+++ b/audio/media.c
@@ -1454,7 +1454,7 @@ static gboolean set_position(struct media_player *mp, DBusMessageIter *iter)
return TRUE;
}
-static gboolean set_property(struct media_player *mp, const char *key,
+static gboolean set_player_property(struct media_player *mp, const char *key,
DBusMessageIter *entry)
{
DBusMessageIter var;
@@ -1515,7 +1515,7 @@ static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
dbus_message_iter_next(&iter);
- set_property(mp, property, &iter);
+ set_player_property(mp, property, &iter);
return TRUE;
}
@@ -1747,7 +1747,7 @@ static gboolean parse_player_properties(struct media_player *mp,
dbus_message_iter_get_basic(&entry, &key);
dbus_message_iter_next(&entry);
- if (set_property(mp, key, &entry) == FALSE)
+ if (set_player_property(mp, key, &entry) == FALSE)
return FALSE;
dbus_message_iter_next(&dict);
--
on behalf of ST-Ericsson
This patch fix simple typo in documentation of API.
---
doc/adapter-api.txt | 2 +-
doc/audio-api.txt | 2 +-
doc/device-api.txt | 2 +-
doc/media-api.txt | 2 +-
doc/proximity-api.txt | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index dccb6bf..916e941 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -24,7 +24,7 @@ Methods dict GetProperties()
void SetProperty(string name, variant value)
Changes the value of the specified property. Only
- properties that are listed a read-write are changeable.
+ properties that are listed as read-write are changeable.
On success this will emit a PropertyChanged signal.
Possible Errors: org.bluez.Error.InvalidArguments
diff --git a/doc/audio-api.txt b/doc/audio-api.txt
index 02291fd..9b1737d 100644
--- a/doc/audio-api.txt
+++ b/doc/audio-api.txt
@@ -122,7 +122,7 @@ Methods void Connect()
void SetProperty(string name, variant value)
Changes the value of the specified property. Only
- properties that are listed a read-write are changeable.
+ properties that are listed as read-write are changeable.
On success this will emit a PropertyChanged signal.
Possible Errors: org.bluez.Error.DoesNotExist
diff --git a/doc/device-api.txt b/doc/device-api.txt
index 4a170e4..0f34210 100644
--- a/doc/device-api.txt
+++ b/doc/device-api.txt
@@ -25,7 +25,7 @@ Methods dict GetProperties()
void SetProperty(string name, variant value)
Changes the value of the specified property. Only
- properties that are listed a read-write are changeable.
+ properties that are listed as read-write are changeable.
On success this will emit a PropertyChanged signal.
Possible Errors: org.bluez.Error.DoesNotExist
diff --git a/doc/media-api.txt b/doc/media-api.txt
index 4446439..e5eeaa0 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -289,7 +289,7 @@ Methods dict GetProperties()
void SetProperty(string name, variant value)
Changes the value of the specified property. Only
- properties that are listed a read-write can be changed.
+ properties that are listed as read-write can be changed.
On success this will emit a PropertyChanged signal.
diff --git a/doc/proximity-api.txt b/doc/proximity-api.txt
index 0c60d47..c8eae50 100644
--- a/doc/proximity-api.txt
+++ b/doc/proximity-api.txt
@@ -19,7 +19,7 @@ Methods dict GetProperties()
void SetProperty(string name, variant value)
Changes the value of the specified property. Only
- properties that are listed a read-write are changeable.
+ properties that are listed as read-write are changeable.
On success this will emit a PropertyChanged signal.
Possible Errors: org.bluez.Error.InvalidArguments
--
on behalf of ST-Ericsson
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> DummyPlayer indicate there is no available players. For AVRCP 1.4
> devices use NoAvailblePlayers status code, on the other side, for
> AVRCP 1.3 devices use InternalError.
For reporting errors alone I don't think we really need a dummy
player, in the other hand it seems that some device (MW600) will just
stop doing anything regarding player events if it gets an error, in
that case dummy can be useful because it serves as a place holder than
once a player is registered it automatically takes place of the dummy
one so we don't need the player to be registered during boot or
anything like.
--
Luiz Augusto von Dentz
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> Register AVRCP before MEDIA interface to avoid searching for or
> accessing non-existent AVRCP server.
> ---
> audio/manager.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/audio/manager.c b/audio/manager.c
> index d442d1d..076346a 100644
> --- a/audio/manager.c
> +++ b/audio/manager.c
> @@ -1238,6 +1238,9 @@ proceed:
> if (enabled.socket)
> unix_init();
>
> + if (enabled.control)
> + btd_register_adapter_driver(&avrcp_server_driver);
> +
> if (enabled.media)
> btd_register_adapter_driver(&media_server_driver);
>
> @@ -1250,9 +1253,6 @@ proceed:
> if (enabled.source || enabled.sink)
> btd_register_adapter_driver(&a2dp_server_driver);
>
> - if (enabled.control)
> - btd_register_adapter_driver(&avrcp_server_driver);
> -
> btd_register_device_driver(&audio_driver);
>
> *enable_sco = (enabled.gateway || enabled.headset);
> --
> on behalf of ST-Ericsson
Applied thanks, please rebase the rest.
--
Luiz Augusto von Dentz
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> + rec_tg = btd_device_get_record(dev->btd_dev, AVRCP_TARGET_UUID);
> + rec_ct = btd_device_get_record(dev->btd_dev, AVRCP_REMOTE_UUID);
> +
> + if (rec_tg && sdp_get_profile_descs(rec_tg, &list) >= 0) {
> + desc = list->data;
> + if (desc)
> + server->session.version_tg = desc->version;
> + else
> + server->session.version_tg = VERSION_UNKNOWN;
> + sdp_list_free(list, free);
> + }
>
> - if (sdp_get_profile_descs(rec, &list) < 0)
> - return;
> + if (rec_ct && sdp_get_profile_descs(rec_ct, &list) >= 0) {
> + desc = list->data;
> + if (desc)
> + server->session.version_ct = desc->version;
> + else
> + server->session.version_ct = VERSION_UNKNOWN;
> + sdp_list_free(list, free);
> + }
Maybe we should create a helper function to get the version e.g int
sdp_get_profile_version(rec, uuid, &version)
> @@ -1335,6 +1354,9 @@ int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
>
> bacpy(&server->src, src);
>
> + server->session.version_tg = VERSION_UNKNOWN;
> + server->session.version_ct = VERSION_UNKNOWN;
> +
I guess we can start with 1.0, so if we are unable to read the version
(which probably indicates a malformed record) we should use 1.0 by
default.
--
Luiz Augusto von Dentz
Hi Michal,
On Thu, Jun 28, 2012 at 1:22 PM, Michal Labedzki
<[email protected]> wrote:
> Update constant names for AVRCP 1.4 to avoid confusion.
> AVRCP 1.4 introduces status code that is not error code, so using
> "status" prefix for both. Also do not use AVRCP prefix for local
> constants and add constants for addressed player feature.
> ---
> audio/avrcp.c | 216 ++++++++++++++++++++++++++++++---------------------------
> audio/avrcp.h | 17 +++--
> audio/media.c | 2 +-
> 3 files changed, 124 insertions(+), 111 deletions(-)
>
> diff --git a/audio/avrcp.c b/audio/avrcp.c
> index 89ee112..125baa4 100644
> --- a/audio/avrcp.c
> +++ b/audio/avrcp.c
> @@ -61,54 +61,67 @@
> /* Company IDs for vendor dependent commands */
> #define IEEEID_BTSIG 0x001958
>
> -/* Error codes for metadata transfer */
> -#define E_INVALID_COMMAND 0x00
> -#define E_INVALID_PARAM 0x01
> -#define E_PARAM_NOT_FOUND 0x02
> -#define E_INTERNAL 0x03
> -
> /* Packet types */
> -#define AVRCP_PACKET_TYPE_SINGLE 0x00
> -#define AVRCP_PACKET_TYPE_START 0x01
> -#define AVRCP_PACKET_TYPE_CONTINUING 0x02
> -#define AVRCP_PACKET_TYPE_END 0x03
> -
> -/* PDU types for metadata transfer */
> -#define AVRCP_GET_CAPABILITIES 0x10
> -#define AVRCP_LIST_PLAYER_ATTRIBUTES 0X11
> -#define AVRCP_LIST_PLAYER_VALUES 0x12
> -#define AVRCP_GET_CURRENT_PLAYER_VALUE 0x13
> -#define AVRCP_SET_PLAYER_VALUE 0x14
> -#define AVRCP_GET_PLAYER_ATTRIBUTE_TEXT 0x15
> -#define AVRCP_GET_PLAYER_VALUE_TEXT 0x16
> -#define AVRCP_DISPLAYABLE_CHARSET 0x17
> -#define AVRCP_CT_BATTERY_STATUS 0x18
> -#define AVRCP_GET_ELEMENT_ATTRIBUTES 0x20
> -#define AVRCP_GET_PLAY_STATUS 0x30
> -#define AVRCP_REGISTER_NOTIFICATION 0x31
> -#define AVRCP_REQUEST_CONTINUING 0x40
> -#define AVRCP_ABORT_CONTINUING 0x41
> -#define AVRCP_SET_ABSOLUTE_VOLUME 0x50
> -
> -/* Capabilities for AVRCP_GET_CAPABILITIES pdu */
> +#define PACKET_TYPE_SINGLE 0x00
> +#define PACKET_TYPE_START 0x01
> +#define PACKET_TYPE_CONTINUING 0x02
> +#define PACKET_TYPE_END 0x03
> +
> +/* Status codes */
> +#define STATUS_INVALID_COMMAND 0x00
> +#define STATUS_INVALID_PARAMETER 0x01
> +#define STATUS_INTERNAL_ERROR 0x03
> +#define STATUS_OK 0x04
> +#define STATUS_INVALID_PLAYER_ID 0x11
> +#define STATUS_NO_AVAILABLE_PLAYERS 0x15
> +#define STATUS_ADDRESSED_PLAYER_CHANGED 0x16
> +
> +/* Control channel PDUs */
> +#define PDU_GET_CAPABILITIES 0x10
> +#define PDU_LIST_PLAYER_ATTRIBUTES 0X11
> +#define PDU_LIST_PLAYER_VALUES 0x12
> +#define PDU_GET_CURRENT_PLAYER_VALUE 0x13
> +#define PDU_SET_PLAYER_VALUE 0x14
> +#define PDU_GET_PLAYER_ATTRIBUTE_TEXT 0x15
> +#define PDU_GET_PLAYER_VALUE_TEXT 0x16
> +#define PDU_DISPLAYABLE_CHARSET 0x17
> +#define PDU_CT_BATTERY_STATUS 0x18
> +#define PDU_GET_ELEMENT_ATTRIBUTES 0x20
> +#define PDU_GET_PLAY_STATUS 0x30
> +#define PDU_REGISTER_NOTIFICATION 0x31
> +#define PDU_REQUEST_CONTINUING 0x40
> +#define PDU_ABORT_CONTINUING 0x41
> +#define PDU_SET_ABSOLUTE_VOLUME 0x50
> +#define PDU_SET_ADDRESSED_PLAYER 0x60
> +
> +/* Capabilities for PDU_GET_CAPABILITIES */
> #define CAP_COMPANY_ID 0x02
> #define CAP_EVENTS_SUPPORTED 0x03
>
> -#define AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH 5
> +/* SDP records features */
> +#define FEATURE_CATEGORY_1 0x0001
> +#define FEATURE_CATEGORY_2 0x0002
> +#define FEATURE_CATEGORY_3 0x0004
> +#define FEATURE_CATEGORY_4 0x0008
> +#define FEATURE_PLAYER_SETTINGS 0x0010
>
> -#define AVRCP_FEATURE_CATEGORY_1 0x0001
> -#define AVRCP_FEATURE_CATEGORY_2 0x0002
> -#define AVRCP_FEATURE_CATEGORY_3 0x0004
> -#define AVRCP_FEATURE_CATEGORY_4 0x0008
> -#define AVRCP_FEATURE_PLAYER_SETTINGS 0x0010
> +/* Battery status */
> +#define BATTERY_STATUS_NORMAL 0x00
> +#define BATTERY_STATUS_WARNING 0x01
> +#define BATTERY_STATUS_CRITICAL 0x02
> +#define BATTERY_STATUS_EXTERNAL 0x03
> +#define BATTERY_STATUS_FULL_CHARGE 0x04
>
> -enum battery_status {
> - BATTERY_STATUS_NORMAL = 0,
> - BATTERY_STATUS_WARNING = 1,
> - BATTERY_STATUS_CRITICAL = 2,
> - BATTERY_STATUS_EXTERNAL = 3,
> - BATTERY_STATUS_FULL_CHARGE = 4,
> -};
> +/* Profile versions */
> +#define VERSION_UNKNOWN 0x0000
> +#define VERSION_1_3 0x0103
> +#define VERSION_1_4 0x0104
> +
> +#define REGISTER_NOTIFICATION_PARAM_LENGTH 5
> +
> +#define AVRCP_HEADER_LENGTH 7
> +#define AVRCP_MTU (AVC_MTU - AVC_HEADER_LENGTH)
> +#define AVRCP_PDU_MTU (AVRCP_MTU - AVRCP_HEADER_LENGTH)
>
> #if __BYTE_ORDER == __LITTLE_ENDIAN
>
> @@ -120,7 +133,6 @@ struct avrcp_header {
> uint16_t params_len;
> uint8_t params[0];
> } __attribute__ ((packed));
> -#define AVRCP_HEADER_LENGTH 7
>
> #elif __BYTE_ORDER == __BIG_ENDIAN
>
> @@ -132,15 +144,11 @@ struct avrcp_header {
> uint16_t params_len;
> uint8_t params[0];
> } __attribute__ ((packed));
> -#define AVRCP_HEADER_LENGTH 7
>
> #else
> #error "Unknown byte order"
> #endif
>
> -#define AVRCP_MTU (AVC_MTU - AVC_HEADER_LENGTH)
> -#define AVRCP_PDU_MTU (AVRCP_MTU - AVRCP_HEADER_LENGTH)
> -
> struct avrcp_server {
> bdaddr_t src;
> uint32_t tg_record_id;
> @@ -190,10 +198,10 @@ static sdp_record_t *avrcp_ct_record(void)
> sdp_data_t *psm, *version, *features;
> uint16_t lp = AVCTP_PSM;
> uint16_t avrcp_ver = 0x0100, avctp_ver = 0x0103;
> - uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
> - AVRCP_FEATURE_CATEGORY_2 |
> - AVRCP_FEATURE_CATEGORY_3 |
> - AVRCP_FEATURE_CATEGORY_4 );
> + uint16_t feat = ( FEATURE_CATEGORY_1 |
> + FEATURE_CATEGORY_2 |
> + FEATURE_CATEGORY_3 |
> + FEATURE_CATEGORY_4 );
>
> record = sdp_record_alloc();
> if (!record)
> @@ -258,11 +266,11 @@ static sdp_record_t *avrcp_tg_record(void)
> sdp_data_t *psm, *version, *features;
> uint16_t lp = AVCTP_PSM;
> uint16_t avrcp_ver = 0x0104, avctp_ver = 0x0103;
> - uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 |
> - AVRCP_FEATURE_CATEGORY_2 |
> - AVRCP_FEATURE_CATEGORY_3 |
> - AVRCP_FEATURE_CATEGORY_4 |
> - AVRCP_FEATURE_PLAYER_SETTINGS );
> + uint16_t feat = ( FEATURE_CATEGORY_1 |
> + FEATURE_CATEGORY_2 |
> + FEATURE_CATEGORY_3 |
> + FEATURE_CATEGORY_4 |
> + FEATURE_PLAYER_SETTINGS );
>
> record = sdp_record_alloc();
> if (!record)
> @@ -333,7 +341,7 @@ static unsigned int attr_get_max_val(uint8_t attr)
> return 0;
> }
>
> -static const char *battery_status_to_str(enum battery_status status)
> +static const char *battery_status_to_str(uint8_t status)
> {
> switch (status) {
> case BATTERY_STATUS_NORMAL:
> @@ -390,13 +398,13 @@ int avrcp_player_event(struct avrcp_player *player, uint8_t id, void *data)
>
> set_company_id(pdu->company_id, IEEEID_BTSIG);
>
> - pdu->pdu_id = AVRCP_REGISTER_NOTIFICATION;
> + pdu->pdu_id = PDU_REGISTER_NOTIFICATION;
> pdu->params[0] = id;
>
> DBG("id=%u", id);
>
> switch (id) {
> - case AVRCP_EVENT_STATUS_CHANGED:
> + case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED:
> size = 2;
> pdu->params[1] = *((uint8_t *)data);
>
> @@ -581,7 +589,7 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
> return AVC_CTYPE_STABLE;
> case CAP_EVENTS_SUPPORTED:
> pdu->params[1] = 4;
> - pdu->params[2] = AVRCP_EVENT_STATUS_CHANGED;
> + pdu->params[2] = AVRCP_EVENT_PLAYBACK_STATUS_CHANGED;
> pdu->params[3] = AVRCP_EVENT_TRACK_CHANGED;
> pdu->params[4] = AVRCP_EVENT_TRACK_REACHED_START;
> pdu->params[5] = AVRCP_EVENT_TRACK_REACHED_END;
> @@ -592,7 +600,7 @@ static uint8_t avrcp_handle_get_capabilities(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
>
> return AVC_CTYPE_REJECTED;
> }
> @@ -606,7 +614,7 @@ static uint8_t avrcp_handle_list_player_attributes(struct avrcp_player *player,
>
> if (len != 0) {
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -653,7 +661,7 @@ static uint8_t avrcp_handle_list_player_values(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -715,7 +723,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
> if (attr_ids != NULL) {
> player->pending_pdu = pending_pdu_new(pdu->pdu_id, attr_ids,
> offset);
> - pdu->packet_type = AVRCP_PACKET_TYPE_START;
> + pdu->packet_type = PACKET_TYPE_START;
> }
>
> pdu->params[0] = len;
> @@ -724,7 +732,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp_player *player,
> return AVC_CTYPE_STABLE;
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -781,7 +789,7 @@ static uint8_t avrcp_handle_get_current_player_value(struct avrcp_player *player
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
>
> return AVC_CTYPE_REJECTED;
> }
> @@ -802,7 +810,7 @@ static uint8_t avrcp_handle_set_player_value(struct avrcp_player *player,
> * and set the existent ones. Sec. 5.2.4 is not clear however how to
> * indicate that a certain ID was not accepted. If at least one
> * attribute is valid, we respond with no parameters. Otherwise an
> - * E_INVALID_PARAM is sent.
> + * STATUS_INVALID_PARAMETER is sent.
> */
> for (len = 0, i = 0, param = &pdu->params[1]; i < pdu->params[0];
> i++, param += 2) {
> @@ -820,7 +828,7 @@ static uint8_t avrcp_handle_set_player_value(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -832,7 +840,7 @@ static uint8_t avrcp_handle_displayable_charset(struct avrcp_player *player,
>
> if (len < 3) {
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -864,7 +872,7 @@ static uint8_t avrcp_handle_ct_battery_status(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -879,7 +887,7 @@ static uint8_t avrcp_handle_get_play_status(struct avrcp_player *player,
>
> if (len != 0) {
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -918,7 +926,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
> goto err;
>
> switch (pdu->params[0]) {
> - case AVRCP_EVENT_STATUS_CHANGED:
> + case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED:
> len = 2;
> pdu->params[1] = player->cb->get_status(player->user_data);
>
> @@ -948,7 +956,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -978,9 +986,9 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
> if (pending->attr_ids == NULL) {
> g_free(player->pending_pdu);
> player->pending_pdu = NULL;
> - pdu->packet_type = AVRCP_PACKET_TYPE_END;
> + pdu->packet_type = PACKET_TYPE_END;
> } else {
> - pdu->packet_type = AVRCP_PACKET_TYPE_CONTINUING;
> + pdu->packet_type = PACKET_TYPE_CONTINUING;
> }
>
> pdu->params_len = htons(len);
> @@ -988,7 +996,7 @@ static uint8_t avrcp_handle_request_continuing(struct avrcp_player *player,
> return AVC_CTYPE_STABLE;
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -1014,7 +1022,7 @@ static uint8_t avrcp_handle_abort_continuing(struct avrcp_player *player,
>
> err:
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> return AVC_CTYPE_REJECTED;
> }
>
> @@ -1025,33 +1033,33 @@ static struct pdu_handler {
> struct avrcp_header *pdu,
> uint8_t transaction);
> } handlers[] = {
> - { AVRCP_GET_CAPABILITIES, AVC_CTYPE_STATUS,
> + { PDU_GET_CAPABILITIES, AVC_CTYPE_STATUS,
> avrcp_handle_get_capabilities },
> - { AVRCP_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
> + { PDU_LIST_PLAYER_ATTRIBUTES, AVC_CTYPE_STATUS,
> avrcp_handle_list_player_attributes },
> - { AVRCP_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
> + { PDU_LIST_PLAYER_VALUES, AVC_CTYPE_STATUS,
> avrcp_handle_list_player_values },
> - { AVRCP_GET_ELEMENT_ATTRIBUTES, AVC_CTYPE_STATUS,
> + { PDU_GET_ELEMENT_ATTRIBUTES, AVC_CTYPE_STATUS,
> avrcp_handle_get_element_attributes },
> - { AVRCP_GET_CURRENT_PLAYER_VALUE, AVC_CTYPE_STATUS,
> + { PDU_GET_CURRENT_PLAYER_VALUE, AVC_CTYPE_STATUS,
> avrcp_handle_get_current_player_value },
> - { AVRCP_SET_PLAYER_VALUE, AVC_CTYPE_CONTROL,
> + { PDU_SET_PLAYER_VALUE, AVC_CTYPE_CONTROL,
> avrcp_handle_set_player_value },
> - { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
> + { PDU_GET_PLAYER_ATTRIBUTE_TEXT, AVC_CTYPE_STATUS,
> NULL },
> - { AVRCP_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
> + { PDU_GET_PLAYER_VALUE_TEXT, AVC_CTYPE_STATUS,
> NULL },
> - { AVRCP_DISPLAYABLE_CHARSET, AVC_CTYPE_STATUS,
> + { PDU_DISPLAYABLE_CHARSET, AVC_CTYPE_STATUS,
> avrcp_handle_displayable_charset },
> - { AVRCP_CT_BATTERY_STATUS, AVC_CTYPE_STATUS,
> + { PDU_CT_BATTERY_STATUS, AVC_CTYPE_STATUS,
> avrcp_handle_ct_battery_status },
> - { AVRCP_GET_PLAY_STATUS, AVC_CTYPE_STATUS,
> + { PDU_GET_PLAY_STATUS, AVC_CTYPE_STATUS,
> avrcp_handle_get_play_status },
> - { AVRCP_REGISTER_NOTIFICATION, AVC_CTYPE_NOTIFY,
> + { PDU_REGISTER_NOTIFICATION, AVC_CTYPE_NOTIFY,
> avrcp_handle_register_notification },
> - { AVRCP_REQUEST_CONTINUING, AVC_CTYPE_CONTROL,
> + { PDU_REQUEST_CONTINUING, AVC_CTYPE_CONTROL,
> avrcp_handle_request_continuing },
> - { AVRCP_ABORT_CONTINUING, AVC_CTYPE_CONTROL,
> + { PDU_ABORT_CONTINUING, AVC_CTYPE_CONTROL,
> avrcp_handle_abort_continuing },
> { },
> };
> @@ -1079,7 +1087,7 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
> pdu->rsvd = 0;
>
> if (operand_count < AVRCP_HEADER_LENGTH) {
> - pdu->params[0] = E_INVALID_COMMAND;
> + pdu->params[0] = STATUS_INVALID_COMMAND;
> goto err_metadata;
> }
>
> @@ -1089,21 +1097,21 @@ static size_t handle_vendordep_pdu(struct avctp *session, uint8_t transaction,
> }
>
> if (!handler || handler->code != *code) {
> - pdu->params[0] = E_INVALID_COMMAND;
> + pdu->params[0] = STATUS_INVALID_COMMAND;
> goto err_metadata;
> }
>
> if (!handler->func) {
> - pdu->params[0] = E_INVALID_PARAM;
> + pdu->params[0] = STATUS_INVALID_PARAMETER;
> goto err_metadata;
> }
>
> *code = handler->func(player, pdu, transaction);
>
> if (*code != AVC_CTYPE_REJECTED &&
> - pdu->pdu_id != AVRCP_GET_ELEMENT_ATTRIBUTES &&
> - pdu->pdu_id != AVRCP_REQUEST_CONTINUING &&
> - pdu->pdu_id != AVRCP_ABORT_CONTINUING)
> + pdu->pdu_id != PDU_GET_ELEMENT_ATTRIBUTES &&
> + pdu->pdu_id != PDU_REQUEST_CONTINUING &&
> + pdu->pdu_id != PDU_ABORT_CONTINUING)
> player_abort_pending_pdu(player);
>
> return AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
> @@ -1122,7 +1130,7 @@ size_t avrcp_handle_vendor_reject(uint8_t *code, uint8_t *operands)
>
> *code = AVC_CTYPE_REJECTED;
> pdu->params_len = htons(1);
> - pdu->params[0] = E_INTERNAL;
> + pdu->params[0] = STATUS_INTERNAL_ERROR;
>
> DBG("rejecting AVRCP PDU 0x%02X, company 0x%06X len 0x%04X",
> pdu->pdu_id, company_id, pdu->params_len);
> @@ -1168,17 +1176,17 @@ static gboolean avrcp_handle_volume_changed(struct avctp *session,
>
> static void register_volume_notification(struct avrcp_player *player)
> {
> - uint8_t buf[AVRCP_HEADER_LENGTH + AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH];
> + uint8_t buf[AVRCP_HEADER_LENGTH + REGISTER_NOTIFICATION_PARAM_LENGTH];
> struct avrcp_header *pdu = (void *) buf;
> uint8_t length;
>
> memset(buf, 0, sizeof(buf));
>
> set_company_id(pdu->company_id, IEEEID_BTSIG);
> - pdu->pdu_id = AVRCP_REGISTER_NOTIFICATION;
> - pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;
> + pdu->pdu_id = PDU_REGISTER_NOTIFICATION;
> + pdu->packet_type = PACKET_TYPE_SINGLE;
> pdu->params[0] = AVRCP_EVENT_VOLUME_CHANGED;
> - pdu->params_len = htons(AVRCP_REGISTER_NOTIFICATION_PARAM_LENGTH);
> + pdu->params_len = htons(REGISTER_NOTIFICATION_PARAM_LENGTH);
>
> length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
>
> @@ -1236,7 +1244,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,
>
> desc = list->data;
>
> - if (desc && desc->version >= 0x0104)
> + if (desc && desc->version >= VERSION_1_4)
> register_volume_notification(player);
>
> sdp_list_free(list, free);
> @@ -1456,7 +1464,7 @@ int avrcp_set_volume(struct audio_device *dev, uint8_t volume)
>
> set_company_id(pdu->company_id, IEEEID_BTSIG);
>
> - pdu->pdu_id = AVRCP_SET_ABSOLUTE_VOLUME;
> + pdu->pdu_id = PDU_SET_ABSOLUTE_VOLUME;
> pdu->params[0] = volume;
> pdu->params_len = htons(1);
>
> diff --git a/audio/avrcp.h b/audio/avrcp.h
> index bf11a6c..95f69a5 100644
> --- a/audio/avrcp.h
> +++ b/audio/avrcp.h
> @@ -69,12 +69,17 @@
> #define AVRCP_PLAY_STATUS_ERROR 0xFF
>
> /* Notification events */
> -#define AVRCP_EVENT_STATUS_CHANGED 0x01
> -#define AVRCP_EVENT_TRACK_CHANGED 0x02
> -#define AVRCP_EVENT_TRACK_REACHED_END 0x03
> -#define AVRCP_EVENT_TRACK_REACHED_START 0x04
> -#define AVRCP_EVENT_VOLUME_CHANGED 0x0d
> -#define AVRCP_EVENT_LAST AVRCP_EVENT_VOLUME_CHANGED
> +#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01
> +#define AVRCP_EVENT_TRACK_CHANGED 0x02
> +#define AVRCP_EVENT_TRACK_REACHED_END 0x03
> +#define AVRCP_EVENT_TRACK_REACHED_START 0x04
> +#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05
> +#define AVRCP_EVENT_PLAYER_SETTING_CHANGED 0x08
> +#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09
> +#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0A
> +#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0B
> +#define AVRCP_EVENT_VOLUME_CHANGED 0x0D
> +#define AVRCP_EVENT_LAST AVRCP_EVENT_VOLUME_CHANGED
>
> struct avrcp_player_cb {
> int (*get_setting) (uint8_t attr, void *user_data);
> diff --git a/audio/media.c b/audio/media.c
> index 1956653..4e23273 100644
> --- a/audio/media.c
> +++ b/audio/media.c
> @@ -1414,7 +1414,7 @@ static gboolean set_status(struct media_player *mp, DBusMessageIter *iter)
>
> mp->status = val;
>
> - avrcp_player_event(mp->player, AVRCP_EVENT_STATUS_CHANGED, &val);
> + avrcp_player_event(mp->player, AVRCP_EVENT_PLAYBACK_STATUS_CHANGED, &val);
>
> return TRUE;
> }
> --
Patches 1-4 are now applied, but I've changed this one quite a bit so
others need rebasing. The reason that I changed this is because I do
actually prefer to prefix when the define comes directly from the spec
and other files such as avdtp.c and avctp.c do already follow this so
no reason to start changing everything.
--
Luiz Augusto von Dentz