Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0c38ef2 authored by Ajay Panicker's avatar Ajay Panicker Committed by Myles Watson
Browse files

Replace AVRC callback function pointers with base::Callback

Replace function pointers with base::Callback for AVRCP to make
interfacing with the new AVRCP service easier.

Bug: 68812037
Test: Connect headset and see that Absolute volume and passthrough
commands still work.

Change-Id: I2ab20b7b59186aea413a736f43e926e17915a139
parent 730dc687
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -322,8 +322,8 @@ uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl,
    }
  }

  ccb.p_ctrl_cback = bta_av_rc_ctrl_cback;
  ccb.p_msg_cback = bta_av_rc_msg_cback;
  ccb.ctrl_cback = base::Bind(bta_av_rc_ctrl_cback);
  ccb.msg_cback = base::Bind(bta_av_rc_msg_cback);
  ccb.company_id = p_bta_av_cfg->company_id;
  ccb.conn = role;
  /* note: BTA_AV_FEAT_RCTG = AVRC_CT_TARGET, BTA_AV_FEAT_RCCT = AVRC_CT_CONTROL
@@ -2002,7 +2002,7 @@ void bta_av_rc_disc(uint8_t disc) {

    /* searching for UUID_SERVCLASS_AV_REMOTE_CONTROL gets both TG and CT */
    if (AVRC_FindService(UUID_SERVCLASS_AV_REMOTE_CONTROL, *p_addr, &db_params,
                         bta_av_avrc_sdp_cback) == AVRC_SUCCESS) {
                         base::Bind(bta_av_avrc_sdp_cback)) == AVRC_SUCCESS) {
      p_cb->disc = disc;
      APPL_TRACE_DEBUG("%s: disc 0x%x", __func__, p_cb->disc);
    }
+6 −6
Original line number Diff line number Diff line
@@ -84,13 +84,13 @@ static void avrc_ctrl_cback(uint8_t handle, uint8_t event, uint16_t result,
                            const RawAddress* peer_addr) {
  uint8_t avrc_event;

  if (event <= AVRC_MAX_RCV_CTRL_EVT && avrc_cb.ccb[handle].p_ctrl_cback) {
  if (event <= AVRC_MAX_RCV_CTRL_EVT && avrc_cb.ccb[handle].ctrl_cback) {
    avrc_event = avrc_ctrl_event_map[event];
    if (event == AVCT_CONNECT_CFM_EVT) {
      if (result != 0) /* failed */
        avrc_event = AVRC_CLOSE_IND_EVT;
    }
    (*avrc_cb.ccb[handle].p_ctrl_cback)(handle, avrc_event, result, peer_addr);
    avrc_cb.ccb[handle].ctrl_cback.Run(handle, avrc_event, result, peer_addr);
  }

  if ((event == AVCT_DISCONNECT_CFM_EVT) ||
@@ -135,8 +135,8 @@ void avrc_process_timeout(void* data) {
                   param->handle, param->label);

  /* Notify app */
  if (avrc_cb.ccb[param->handle].p_ctrl_cback) {
    (*avrc_cb.ccb[param->handle].p_ctrl_cback)(
  if (avrc_cb.ccb[param->handle].ctrl_cback) {
    avrc_cb.ccb[param->handle].ctrl_cback.Run(
        param->handle, AVRC_CMD_TIMEOUT_EVT, param->label, NULL);
  }

@@ -859,7 +859,7 @@ static void avrc_msg_cback(uint8_t handle, uint8_t label, uint8_t cr,

  if (!drop) {
    msg.hdr.opcode = opcode;
    (*avrc_cb.ccb[handle].p_msg_cback)(handle, label, opcode, &msg);
    avrc_cb.ccb[handle].msg_cback.Run(handle, label, opcode, &msg);
  } else {
    AVRC_TRACE_WARNING("%s %s msg handle:%d, control:%d, cr:%d, opcode:x%x",
                       __func__, p_drop_msg, handle,
@@ -981,7 +981,7 @@ uint16_t AVRC_Open(uint8_t* p_handle, tAVRC_CONN_CB* p_ccb,

  status = AVCT_CreateConn(p_handle, &cc, peer_addr);
  if (status == AVCT_SUCCESS) {
    memcpy(&avrc_cb.ccb[*p_handle], p_ccb, sizeof(tAVRC_CONN_CB));
    avrc_cb.ccb[*p_handle] = *p_ccb;
    memset(&avrc_cb.ccb_int[*p_handle], 0, sizeof(tAVRC_CONN_INT_CB));
    memset(&avrc_cb.fcb[*p_handle], 0, sizeof(tAVRC_FRAG_CB));
    memset(&avrc_cb.rcb[*p_handle], 0, sizeof(tAVRC_RASM_CB));
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ typedef struct {
      ccb_int[AVCT_NUM_CONN]; /* Internal connection control block  */
  tAVRC_FRAG_CB fcb[AVCT_NUM_CONN];
  tAVRC_RASM_CB rcb[AVCT_NUM_CONN];
  tAVRC_FIND_CBACK* p_cback; /* pointer to application callback */
  tAVRC_FIND_CBACK find_cback; /* sdp discovery callback */
  tSDP_DISCOVERY_DB* p_db;   /* pointer to discovery database */
  uint16_t service_uuid;     /* service UUID to search */
  uint8_t trace_level;
+4 −4
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ static void avrc_sdp_cback(uint16_t status) {
  avrc_cb.service_uuid = 0;

  /* return info from sdp record in app callback function */
  (*avrc_cb.p_cback)(status);
  avrc_cb.find_cback.Run(status);

  return;
}
@@ -107,13 +107,13 @@ static void avrc_sdp_cback(uint16_t status) {
 *****************************************************************************/
uint16_t AVRC_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
                          tAVRC_SDP_DB_PARAMS* p_db,
                          tAVRC_FIND_CBACK* p_cback) {
                          const tAVRC_FIND_CBACK& find_cback) {
  bool result = true;

  AVRC_TRACE_API("%s uuid: %x", __func__, service_uuid);
  if ((service_uuid != UUID_SERVCLASS_AV_REM_CTRL_TARGET &&
       service_uuid != UUID_SERVCLASS_AV_REMOTE_CONTROL) ||
      p_db == NULL || p_db->p_db == NULL || p_cback == NULL)
      p_db == NULL || p_db->p_db == NULL || find_cback.is_null())
    return AVRC_BAD_PARAM;

  /* check if it is busy */
@@ -135,7 +135,7 @@ uint16_t AVRC_FindService(uint16_t service_uuid, const RawAddress& bd_addr,
    /* store service_uuid and discovery db pointer */
    avrc_cb.p_db = p_db->p_db;
    avrc_cb.service_uuid = service_uuid;
    avrc_cb.p_cback = p_cback;
    avrc_cb.find_cback = find_cback;

    /* perform service search */
    result =
+12 −8
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@
 ******************************************************************************/
#ifndef AVRC_API_H
#define AVRC_API_H

#include <base/bind.h>

#include "avct_api.h"
#include "avrc_defs.h"
#include "bt_target.h"
@@ -161,23 +164,24 @@ typedef struct {
 * implementation of this callback function must copy the p_service_name
 * and p_provider_name parameters passed to it as they are not guaranteed
 * to remain after the callback function exits. */
typedef void(tAVRC_FIND_CBACK)(uint16_t status);
using tAVRC_FIND_CBACK = base::Callback<void(uint16_t status)>;

/* This is the control callback function.  This function passes events
 * listed in Table 20 to the application. */
typedef void(tAVRC_CTRL_CBACK)(uint8_t handle, uint8_t event, uint16_t result,
                               const RawAddress* peer_addr);
using tAVRC_CTRL_CBACK =
    base::Callback<void(uint8_t handle, uint8_t event, uint16_t result,
                        const RawAddress* peer_addr)>;

/* This is the message callback function.  It is executed when AVCTP has
 * a message packet ready for the application.  The implementation of this
 * callback function must copy the tAVRC_MSG structure passed to it as it
 * is not guaranteed to remain after the callback function exits. */
typedef void(tAVRC_MSG_CBACK)(uint8_t handle, uint8_t label, uint8_t opcode,
                              tAVRC_MSG* p_msg);
using tAVRC_MSG_CBACK = base::Callback<void(uint8_t handle, uint8_t label,
                                            uint8_t opcode, tAVRC_MSG* p_msg)>;

typedef struct {
  tAVRC_CTRL_CBACK* p_ctrl_cback; /* pointer to application control callback */
  tAVRC_MSG_CBACK* p_msg_cback;   /* pointer to application message callback */
  tAVRC_CTRL_CBACK ctrl_cback;    /* application control callback */
  tAVRC_MSG_CBACK msg_cback;      /* application message callback */
  uint32_t company_id;            /* the company ID  */
  uint8_t conn;                   /* Connection role (Initiator/acceptor) */
  uint8_t control;                /* Control role (Control/Target) */
@@ -274,7 +278,7 @@ extern uint16_t AVRC_AddRecord(uint16_t service_uuid,
extern uint16_t AVRC_FindService(uint16_t service_uuid,
                                 const RawAddress& bd_addr,
                                 tAVRC_SDP_DB_PARAMS* p_db,
                                 tAVRC_FIND_CBACK* p_cback);
                                 const tAVRC_FIND_CBACK& cback);

/******************************************************************************
 *