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

Commit 643b0069 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Added A2DP codec-related APIs

Those APIs can be used to check various codec-related characterictics,
and minimize the codec-specific knowledge in the rest of the code.

The added APIs are:
 - A2D_GetCodecType()
 - A2D_IsCodecSupported()
 - A2D_UsesRtpHeader()
 - A2D_IsVendorCodecSupported()
 - A2D_VendorCodecGetVendorId()
 - A2D_VendorCodecGetCodecId()
 - A2D_VendorUsesRtpHeader()

Also:
 - Added unit tests for the new API calls
 - Removed redundant definition of BTA_AV_CODEC_TYPE_IDX
 - Removed unused A2D_MEDIA_CT_* codec type defines

Bug: 30958229
Change-Id: Id9ab01fd93b0b0a9b55a0af9bfb482310ae0ade4
parent 4e106c0c
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -1142,7 +1142,7 @@ void bta_av_config_ind (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    local_sep = bta_av_get_scb_sep_type(p_scb, p_msg->handle);
    p_scb->avdt_label = p_data->str_msg.msg.hdr.label;
    memcpy(p_scb->cfg.codec_info, p_evt_cfg->codec_info, AVDT_CODEC_SIZE);
    p_scb->codec_type = p_evt_cfg->codec_info[BTA_AV_CODEC_TYPE_IDX];
    p_scb->codec_type = A2D_GetCodecType(p_evt_cfg->codec_info);
    bta_av_save_addr(p_scb, p_data->str_msg.bd_addr);

    /* Clear collision mask */
@@ -1733,7 +1733,7 @@ void bta_av_save_caps(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
        p_scb->num_seps, p_scb->sep_info_idx, p_scb->wait);
    memcpy(&cfg, p_scb->p_cap, sizeof(tAVDT_CFG));
    /* let application know the capability of the SNK */
    p_scb->p_cos->getcfg(p_scb->hndl, cfg.codec_info[BTA_AV_CODEC_TYPE_IDX],
    p_scb->p_cos->getcfg(p_scb->hndl, A2D_GetCodecType(cfg.codec_info),
        cfg.codec_info, &p_scb->sep_info_idx, p_info->seid,
        &cfg.num_protect, cfg.protect_info);

@@ -1889,16 +1889,18 @@ void bta_av_getcap_results (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    /* if codec present and we get a codec configuration */
    if ((p_scb->p_cap->num_codec != 0) &&
        (media_type == p_scb->media_type) &&
        (p_scb->p_cos->getcfg(p_scb->hndl, p_scb->p_cap->codec_info[BTA_AV_CODEC_TYPE_IDX],
            cfg.codec_info, &p_scb->sep_info_idx, p_info->seid,
            &cfg.num_protect, cfg.protect_info) == 0))
        (p_scb->p_cos->getcfg(p_scb->hndl,
                              A2D_GetCodecType(p_scb->p_cap->codec_info),
                              cfg.codec_info, &p_scb->sep_info_idx,
                              p_info->seid, &cfg.num_protect,
                              cfg.protect_info) == 0))
    {
#if AVDT_MULTIPLEXING == TRUE
        cfg.mux_mask &= p_scb->p_cap->mux_mask;
        APPL_TRACE_DEBUG("mux_mask used x%x", cfg.mux_mask);
#endif
        /* save copy of codec type and configuration */
        p_scb->codec_type = cfg.codec_info[BTA_AV_CODEC_TYPE_IDX];
        p_scb->codec_type = A2D_GetCodecType(cfg.codec_info);
        memcpy(&p_scb->cfg, &cfg, sizeof(tAVDT_CFG));

        uuid_int = p_scb->uuid_int;
@@ -2945,7 +2947,7 @@ void bta_av_rcfg_open (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
    }
    else
    {
        p_scb->codec_type = p_scb->p_cap->codec_info[BTA_AV_CODEC_TYPE_IDX];
        p_scb->codec_type = A2D_GetCodecType(p_scb->p_cap->codec_info);
        memcpy(p_scb->cfg.codec_info, p_scb->p_cap->codec_info, AVDT_CODEC_SIZE);
        /* we may choose to use a different SEP at reconfig.
         * adjust the sep_idx now */
+0 −3
Original line number Diff line number Diff line
@@ -90,9 +90,6 @@ typedef uint8_t tBTA_AV_HNDL;
/* tBTA_AV_HNDL to mask */
#define BTA_AV_HNDL_TYPE_TO_MSK(h)  ((uint8_t)(1 << ((h)&BTA_AV_HNDL_MSK)))

/* offset of codec type in codec info byte array */
#define BTA_AV_CODEC_TYPE_IDX       AVDT_CODEC_TYPE_INDEX   /* 2 */

/* maximum number of streams created: 1 for audio, 1 for video */
#ifndef BTA_AV_NUM_STRS
#define BTA_AV_NUM_STRS         2
+27 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ LOCAL_C_INCLUDES:= \
LOCAL_SRC_FILES := \
    ./a2dp/a2d_api.c \
    ./a2dp/a2d_sbc.c \
    ./a2dp/a2d_vendor.c \
    ./avrc/avrc_api.c \
    ./avrc/avrc_sdp.c \
    ./avrc/avrc_opt.c \
@@ -158,3 +159,27 @@ LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)

include $(BUILD_STATIC_LIBRARY)

# Bluetooth stack unit tests for target
# ========================================================
include $(CLEAR_VARS)

LOCAL_CPP_EXTENSION := .cc

LOCAL_C_INCLUDES := \
                   $(LOCAL_PATH)/include \
                   $(LOCAL_PATH)/../include \
                   $(LOCAL_PATH)/../ \
                   $(bluetooth_C_INCLUDES)

LOCAL_SRC_FILES := test/stack_a2d_test.cc
LOCAL_SHARED_LIBRARIES :=
LOCAL_STATIC_LIBRARIES := libbt-stack
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := net_test_stack

LOCAL_CFLAGS += $(bluetooth_CFLAGS)
LOCAL_CONLYFLAGS += $(bluetooth_CONLYFLAGS)
LOCAL_CPPFLAGS += $(bluetooth_CPPFLAGS)

include $(BUILD_NATIVE_TEST)
+33 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@

/******************************************************************************
 *
 *  ommon API for the Advanced Audio Distribution Profile (A2DP)
 *  Common API for the Advanced Audio Distribution Profile (A2DP)
 *
 ******************************************************************************/
#include <string.h>
@@ -27,6 +27,7 @@
#include "sdpdefs.h"
#include "a2d_api.h"
#include "a2d_int.h"
#include "a2d_vendor.h"
#include "avdt_api.h"

/*****************************************************************************
@@ -397,3 +398,34 @@ void A2D_Init(void)
#endif
}

tA2D_CODEC A2D_GetCodecType(const uint8_t *p_codec_info)
{
    return (tA2D_CODEC)(p_codec_info[AVDT_CODEC_TYPE_INDEX]);
}

bool A2D_IsCodecSupported(const uint8_t *p_codec_info)
{
    tA2D_CODEC codec_type = A2D_GetCodecType(p_codec_info);

    switch (codec_type) {
    case A2D_MEDIA_CT_SBC:
        return true;
    case A2D_MEDIA_CT_NON_A2DP:
        return A2D_IsVendorCodecSupported(p_codec_info);
    default:
        return false;
    }

    return false;
}

bool A2D_UsesRtpHeader(bool content_protection_enabled,
                       const uint8_t *p_codec_info)
{
    tA2D_CODEC codec_type = A2D_GetCodecType(p_codec_info);

    if (codec_type != A2D_MEDIA_CT_NON_A2DP)
        return true;

    return A2D_VendorUsesRtpHeader(content_protection_enabled, p_codec_info);
}
+66 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Vendor Specific A2DP Codecs Support
 */

#include "bt_target.h"
#include "a2d_vendor.h"
#include "osi/include/osi.h"

bool A2D_IsVendorCodecSupported(UNUSED_ATTR const uint8_t *p_codec_info)
{
    // uint32_t vendor_id = A2D_VendorCodecGetVendorId(p_codec_info);
    // uint16_t codec_id = A2D_VendorCodecGetCodecId(p_codec_info);

    // Add checks based on <vendor_id, codec_id>

    return false;
}

uint32_t A2D_VendorCodecGetVendorId(const uint8_t *p_codec_info)
{
    const uint8_t *p = &p_codec_info[A2D_VENDOR_CODEC_VENDOR_ID_START_IDX];

    uint32_t vendor_id =
      (p[0] & 0x000000ff) |
      ((p[1] << 8) & 0x0000ff00) |
      ((p[2] << 16) & 0x00ff0000) |
      ((p[3] << 24) & 0xff000000);

    return vendor_id;
}

uint16_t A2D_VendorCodecGetCodecId(const uint8_t *p_codec_info)
{
    const uint8_t *p = &p_codec_info[A2D_VENDOR_CODEC_CODEC_ID_START_IDX];

    uint16_t codec_id = (p[0] & 0x00ff) | ((p[1] << 8) & 0xff00);

    return codec_id;
}

bool A2D_VendorUsesRtpHeader(UNUSED_ATTR bool content_protection_enabled,
                             UNUSED_ATTR const uint8_t *p_codec_info)
{
    // uint32_t vendor_id = A2D_VendorCodecGetVendorId(p_codec_info);
    // uint16_t codec_id = A2D_VendorCodecGetCodecId(p_codec_info);

    // Add checks based on <content_protection_enabled, vendor_id, codec_id>

    return true;
}
Loading