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

Commit 178c2fbb authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Andre Eisenbach
Browse files

Removed function osi_get_buf_size()

Refactored code that uses function osi_get_buf_size(), and removed
the need for that function.

Bug: 24914560
Change-Id: I0d002635024a9703acb78f47735aafc957a2b761
parent 04fde263
Loading
Loading
Loading
Loading
+24 −34
Original line number Original line Diff line number Diff line
@@ -1181,45 +1181,35 @@ UINT16 bta_av_chk_mtu(tBTA_AV_SCB *p_scb, UINT16 mtu)
*******************************************************************************/
*******************************************************************************/
void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
void bta_av_dup_audio_buf(tBTA_AV_SCB *p_scb, BT_HDR *p_buf)
{
{
    tBTA_AV_SCB *p_scbi;
    /* Test whether there is more than one audio channel connected */
    int     i;
    if ((p_buf == NULL) || (bta_av_cb.audio_open_cnt < 2))
    UINT16  size, copy_size;
    BT_HDR *p_new;

    if(!p_buf)
        return;
        return;


    if(bta_av_cb.audio_open_cnt >= 2)
    UINT16 copy_size = BT_HDR_SIZE + p_buf->len + p_buf->offset;
    {
    for (int i = 0; i < BTA_AV_NUM_STRS; i++) {
        size = osi_get_buf_size(p_buf);
        tBTA_AV_SCB *p_scbi = bta_av_cb.p_scb[i];
        copy_size = BT_HDR_SIZE + p_buf->len + p_buf->offset;

        /* more than one audio channel is connected */
        if (i == p_scb->hdi)
        for(i=0; i<BTA_AV_NUM_STRS; i++)
            continue;           /* Ignore the original channel */
        {
        if ((p_scbi == NULL) || !p_scbi->co_started)
            p_scbi = bta_av_cb.p_scb[i];
            continue;           /* Ignore if SCB is not used or started */
            if( (p_scb->hdi != i) && /* not the original channel */
        if (!(bta_av_cb.conn_audio & BTA_AV_HNDL_TO_MSK(i)))
                (bta_av_cb.conn_audio & BTA_AV_HNDL_TO_MSK(i)) && /* connected audio */
            continue;           /* Audio is not connected */
                p_scbi && p_scbi->co_started ) /* scb is used and started */

            {
        /* Enqueue the data */
                /* enqueue the data only when the stream is started */
        BT_HDR *p_new = (BT_HDR *)osi_getbuf(copy_size);
                p_new = (BT_HDR *)osi_getbuf(size);
                if(p_new)
                {
        memcpy(p_new, p_buf, copy_size);
        memcpy(p_new, p_buf, copy_size);
        list_append(p_scbi->a2d_list, p_new);
        list_append(p_scbi->a2d_list, p_new);

        if (list_length(p_scbi->a2d_list) > p_bta_av_cfg->audio_mqs) {
        if (list_length(p_scbi->a2d_list) > p_bta_av_cfg->audio_mqs) {
            // Drop the oldest packet
            // Drop the oldest packet
            bta_av_co_audio_drop(p_scbi->hndl);
            bta_av_co_audio_drop(p_scbi->hndl);
                        BT_HDR *p_buf = list_front(p_scbi->a2d_list);
            BT_HDR *p_buf_drop = list_front(p_scbi->a2d_list);
                        list_remove(p_scbi->a2d_list, p_buf);
            list_remove(p_scbi->a2d_list, p_buf_drop);
                        osi_freebuf(p_buf);
            osi_freebuf(p_buf_drop);
        }
        }
    }
    }
}
}
        }
    }

}


/*******************************************************************************
/*******************************************************************************
**
**
+1 −5
Original line number Original line Diff line number Diff line
@@ -48,8 +48,7 @@ void osi_free(void *ptr);
void osi_free_and_reset(void **p_ptr);
void osi_free_and_reset(void **p_ptr);


//
//
// TODO: Function osi_get_buf_size() should be removed.
// TODO: The functions below should be removed and replaced with the
// The rest of the functions below should be removed and replaced with the
// corresponding functions above.
// corresponding functions above.
//
//


@@ -66,6 +65,3 @@ void osi_freebuf(void *ptr);
// |p_ptr| is a pointer to the buffer pointer to be reset.
// |p_ptr| is a pointer to the buffer pointer to be reset.
// |p_ptr| cannot be NULL.
// |p_ptr| cannot be NULL.
void osi_freebuf_and_reset(void **p_ptr);
void osi_freebuf_and_reset(void **p_ptr);

// Get the size of the buffer previously allocated with function |osi_getbuf|
uint16_t osi_get_buf_size(void *ptr);
+0 −7
Original line number Original line Diff line number Diff line
@@ -131,10 +131,3 @@ void osi_freebuf_and_reset(void **p_ptr)
  osi_freebuf(*p_ptr);
  osi_freebuf(*p_ptr);
  *p_ptr = NULL;
  *p_ptr = NULL;
}
}

uint16_t osi_get_buf_size(void *p_buf)
{
  BUFFER_HDR_T *header = (BUFFER_HDR_T *)p_buf - 1;
  assert(header->magic_number == MAGIC_NUMBER);
  return header->size;
}
+29 −34
Original line number Original line Diff line number Diff line
@@ -55,7 +55,6 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
    UINT8   *p;
    UINT8   *p;
    UINT8   pkt_type;
    UINT8   pkt_type;
    BT_HDR  *p_ret;
    BT_HDR  *p_ret;
    UINT16  buf_len;


    /* parse the message header */
    /* parse the message header */
    p = (UINT8 *)(p_buf + 1) + p_buf->offset;
    p = (UINT8 *)(p_buf + 1) + p_buf->offset;
@@ -73,10 +72,10 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
    {
    {
        /* if reassembly in progress drop message and process new single */
        /* if reassembly in progress drop message and process new single */
        if (p_lcb->p_rx_msg != NULL)
        if (p_lcb->p_rx_msg != NULL)
        {
            AVCT_TRACE_WARNING("Got single during reassembly");
            AVCT_TRACE_WARNING("Got single during reassembly");

        osi_freebuf_and_reset((void **)&p_lcb->p_rx_msg);
        osi_freebuf_and_reset((void **)&p_lcb->p_rx_msg);
        }

        p_ret = p_buf;
        p_ret = p_buf;
    }
    }
    /* start packet */
    /* start packet */
@@ -88,20 +87,15 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)


        osi_freebuf(p_lcb->p_rx_msg);
        osi_freebuf(p_lcb->p_rx_msg);


        /* Allocate bigger buffer for reassembly. As lower layers are
        /*
         * not aware of possible packet size after reassembly they
         * Allocate bigger buffer for reassembly. As lower layers are
         * not aware of possible packet size after reassembly, they
         * would have allocated smaller buffer.
         * would have allocated smaller buffer.
         */
         */
        p_lcb->p_rx_msg = (BT_HDR *)osi_getbuf(BT_DEFAULT_BUFFER_SIZE);
        p_lcb->p_rx_msg = (BT_HDR *)osi_getbuf(BT_DEFAULT_BUFFER_SIZE);
        if (p_lcb->p_rx_msg == NULL)
        {
            AVCT_TRACE_ERROR ("Cannot alloc buffer for reassembly !!");
            osi_freebuf(p_buf);
        }
        else
        {
        memcpy(p_lcb->p_rx_msg, p_buf,
        memcpy(p_lcb->p_rx_msg, p_buf,
               sizeof(BT_HDR) + p_buf->offset + p_buf->len);
               sizeof(BT_HDR) + p_buf->offset + p_buf->len);

        /* Free original buffer */
        /* Free original buffer */
        osi_freebuf(p_buf);
        osi_freebuf(p_buf);


@@ -116,7 +110,7 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)


        /* adjust length for packet header */
        /* adjust length for packet header */
        p_lcb->p_rx_msg->len -= 1;
        p_lcb->p_rx_msg->len -= 1;
        }

        p_ret = NULL;
        p_ret = NULL;
    }
    }
    /* continue or end */
    /* continue or end */
@@ -132,23 +126,24 @@ static BT_HDR *avct_lcb_msg_asmbl(tAVCT_LCB *p_lcb, BT_HDR *p_buf)
        else
        else
        {
        {
            /* get size of buffer holding assembled message */
            /* get size of buffer holding assembled message */
            buf_len = osi_get_buf_size(p_lcb->p_rx_msg) - sizeof(BT_HDR);
            /*
             * NOTE: The buffer is allocated above at the beginning of the
             * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE.
             */
            UINT16 buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);


            /* adjust offset and len of fragment for header byte */
            /* adjust offset and len of fragment for header byte */
            p_buf->offset += AVCT_HDR_LEN_CONT;
            p_buf->offset += AVCT_HDR_LEN_CONT;
            p_buf->len -= AVCT_HDR_LEN_CONT;
            p_buf->len -= AVCT_HDR_LEN_CONT;


            /* verify length */
            /* verify length */
            if ((p_lcb->p_rx_msg->offset + p_buf->len) > buf_len)
            if ((p_lcb->p_rx_msg->offset + p_buf->len) > buf_len) {
            {
                /* won't fit; free everything */
                /* won't fit; free everything */
                AVCT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
                osi_freebuf_and_reset((void **)&p_lcb->p_rx_msg);
                osi_freebuf_and_reset((void **)&p_lcb->p_rx_msg);
                osi_freebuf(p_buf);
                osi_freebuf(p_buf);
                p_ret = NULL;
                p_ret = NULL;
                AVCT_TRACE_WARNING("Fragmented message too big!");
            } else {
            }
            else
            {
                /* copy contents of p_buf to p_rx_msg */
                /* copy contents of p_buf to p_rx_msg */
                memcpy((UINT8 *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset,
                memcpy((UINT8 *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset,
                       (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
                       (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
+23 −8
Original line number Original line Diff line number Diff line
@@ -1372,7 +1372,6 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
    UINT8   *p;
    UINT8   *p;
    UINT8   pkt_type;
    UINT8   pkt_type;
    BT_HDR  *p_ret;
    BT_HDR  *p_ret;
    UINT16  buf_len;


    /* parse the message header */
    /* parse the message header */
    p = (UINT8 *)(p_buf + 1) + p_buf->offset;
    p = (UINT8 *)(p_buf + 1) + p_buf->offset;
@@ -1404,7 +1403,21 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
            AVDT_TRACE_WARNING("Got start during reassembly");
            AVDT_TRACE_WARNING("Got start during reassembly");


        osi_freebuf_and_reset((void **)&p_ccb->p_rx_msg);
        osi_freebuf_and_reset((void **)&p_ccb->p_rx_msg);
        p_ccb->p_rx_msg = p_buf;

        /*
         * Allocate bigger buffer for reassembly. As lower layers are
         * not aware of possible packet size after reassembly, they
         * would have allocated smaller buffer.
         */
        p_ccb->p_rx_msg = (BT_HDR *)osi_getbuf(BT_DEFAULT_BUFFER_SIZE);
        memcpy(p_ccb->p_rx_msg, p_buf,
               sizeof(BT_HDR) + p_buf->offset + p_buf->len);

        /* Free original buffer */
        osi_freebuf(p_buf);

        /* update p to point to new buffer */
        p = (UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset;


        /* copy first header byte over nosp */
        /* copy first header byte over nosp */
        *(p + 1) = *p;
        *(p + 1) = *p;
@@ -1430,22 +1443,24 @@ BT_HDR *avdt_msg_asmbl(tAVDT_CCB *p_ccb, BT_HDR *p_buf)
        else
        else
        {
        {
            /* get size of buffer holding assembled message */
            /* get size of buffer holding assembled message */
            buf_len = osi_get_buf_size(p_ccb->p_rx_msg) - sizeof(BT_HDR);
            /*
             * NOTE: The buffer is allocated above at the beginning of the
             * reassembly, and is always of size BT_DEFAULT_BUFFER_SIZE.
             */
            UINT16 buf_len = BT_DEFAULT_BUFFER_SIZE - sizeof(BT_HDR);


            /* adjust offset and len of fragment for header byte */
            /* adjust offset and len of fragment for header byte */
            p_buf->offset += AVDT_LEN_TYPE_CONT;
            p_buf->offset += AVDT_LEN_TYPE_CONT;
            p_buf->len -= AVDT_LEN_TYPE_CONT;
            p_buf->len -= AVDT_LEN_TYPE_CONT;


            /* verify length */
            /* verify length */
            if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len)
            if ((p_ccb->p_rx_msg->offset + p_buf->len) > buf_len) {
            {
                /* won't fit; free everything */
                /* won't fit; free everything */
                AVDT_TRACE_WARNING("%s: Fragmented message too big!", __func__);
                osi_freebuf_and_reset((void **)&p_ccb->p_rx_msg);
                osi_freebuf_and_reset((void **)&p_ccb->p_rx_msg);
                osi_freebuf(p_buf);
                osi_freebuf(p_buf);
                p_ret = NULL;
                p_ret = NULL;
            }
            } else {
            else
            {
                /* copy contents of p_buf to p_rx_msg */
                /* copy contents of p_buf to p_rx_msg */
                memcpy((UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset,
                memcpy((UINT8 *)(p_ccb->p_rx_msg + 1) + p_ccb->p_rx_msg->offset,
                       (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
                       (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
Loading