components/bt/host/bluedroid/stack/a2dp/a2dp_vendor_aptx.c
tA2D_STATUS A2DP_ParseInfoAptx(tA2DP_APTX_CIE* p_ie,const uint8_t* p_codec_info,bool is_capability,char *caller_s)
{
  uint8_t losc;
  uint8_t media_type;
  tA2DP_CODEC_TYPE codec_type;

  // add by nishi
  APPL_TRACE_WARNING("a2d_vender_aptx.c::A2DP_ParseInfoAptx() : #1 ,caller_s=%s",caller_s);


  if (p_ie == NULL || p_codec_info == NULL) return A2DP_INVALID_PARAMS;

  // Check the codec capability length
  losc = *p_codec_info++;
  if (losc != A2DP_APTX_CODEC_LEN) return A2DP_WRONG_CODEC;

  media_type = (*p_codec_info++) >> 4;
  codec_type = *p_codec_info++;
  /* Check the Media Type and Media Codec Type */
  //if (media_type != AVDT_MEDIA_TYPE_AUDIO ||
  if (media_type != AVDT_MEDIA_AUDIO ||
      codec_type != A2DP_MEDIA_CT_NON_A2DP) {
    return A2DP_WRONG_CODEC;
  }

  // Check the Vendor ID and Codec ID */
  p_ie->vendorId = (*p_codec_info & 0x000000FF) |
                   (*(p_codec_info + 1) << 8 & 0x0000FF00) |
                   (*(p_codec_info + 2) << 16 & 0x00FF0000) |
                   (*(p_codec_info + 3) << 24 & 0xFF000000);
  p_codec_info += 4;
  p_ie->codecId =
      (*p_codec_info & 0x00FF) | (*(p_codec_info + 1) << 8 & 0xFF00);
  p_codec_info += 2;
  if (p_ie->vendorId != A2DP_APTX_VENDOR_ID ||
      p_ie->codecId != A2DP_APTX_CODEC_ID_BLUETOOTH) {
    return A2DP_WRONG_CODEC;
  }

  p_ie->channelMode = *p_codec_info & 0x0F;
  p_ie->sampleRate = *p_codec_info & 0xF0;
  p_codec_info++;

  if (is_capability) {
    // NOTE: The checks here are very liberal. We should be using more
    // pedantic checks specific to the SRC or SNK as specified in the spec.
    if (A2DP_BitsSet(p_ie->sampleRate) == A2D_SET_ZERO_BIT)
      return A2DP_BAD_SAMP_FREQ;
    if (A2DP_BitsSet(p_ie->channelMode) == A2D_SET_ZERO_BIT)
      return A2DP_BAD_CH_MODE;

    return A2DP_SUCCESS;
  }

  if (A2DP_BitsSet(p_ie->sampleRate) != A2D_SET_ONE_BIT)
    return A2DP_BAD_SAMP_FREQ;
  if (A2DP_BitsSet(p_ie->channelMode) != A2D_SET_ONE_BIT)
    return A2DP_BAD_CH_MODE;

  return A2DP_SUCCESS;
}
// Parses the aptX Media Codec Capabilities byte sequence beginning from the
// LOSC octet. The result is stored in |p_ie|. The byte sequence to parse is
// |p_codec_info|. If |is_capability| is true, the byte sequence is
// codec capabilities, otherwise is codec configuration.
// Returns A2DP_SUCCESS on success, otherwise the corresponding A2DP error
// status code.
//tA2D_STATUS A2DP_ParseInfoAptx(tA2DP_APTX_CIE* p_ie,const uint8_t* p_codec_info,bool is_capability)
Parses the aptX Media Codec Capabilities byte sequence beginning from the
LOSC octet. The result is stored in |p_ie|. The byte sequence to parse is
|p_codec_info|. If |is_capability| is true, the byte sequence is
codec capabilities, otherwise is codec configuration.
Returns A2DP_SUCCESS on success, otherwise the corresponding A2DP error
status code.
Parses the aptX Media Codec Capabilities byte sequence beginning from the LOSC octet . The result is stored in |p_ie| . The byte sequence to parse is |p_codec_info| . If |is_capability| is true the byte sequence is codec capabilities otherwise is codec configuration . Returns A2DP_SUCCESS on success otherwise the corresponding A2DP error status code .
tA2D_STATUS A2DP_ParseInfoAptx(tA2DP_APTX_CIE* p_ie,const uint8_t* p_codec_info,bool is_capability,char *caller_s)
{
  uint8_t losc;
  uint8_t media_type;
  tA2DP_CODEC_TYPE codec_type;
  APPL_TRACE_WARNING("a2d_vender_aptx.c::A2DP_ParseInfoAptx() : #1 ,caller_s=%s",caller_s);
  if (p_ie == NULL || p_codec_info == NULL) return A2DP_INVALID_PARAMS;
  losc = *p_codec_info++;
  if (losc != A2DP_APTX_CODEC_LEN) return A2DP_WRONG_CODEC;
  media_type = (*p_codec_info++) >> 4;
  codec_type = *p_codec_info++;
  if (media_type != AVDT_MEDIA_AUDIO ||
      codec_type != A2DP_MEDIA_CT_NON_A2DP) {
    return A2DP_WRONG_CODEC;
  }
  p_ie->vendorId = (*p_codec_info & 0x000000FF) |
                   (*(p_codec_info + 1) << 8 & 0x0000FF00) |
                   (*(p_codec_info + 2) << 16 & 0x00FF0000) |
                   (*(p_codec_info + 3) << 24 & 0xFF000000);
  p_codec_info += 4;
  p_ie->codecId =
      (*p_codec_info & 0x00FF) | (*(p_codec_info + 1) << 8 & 0xFF00);
  p_codec_info += 2;
  if (p_ie->vendorId != A2DP_APTX_VENDOR_ID ||
      p_ie->codecId != A2DP_APTX_CODEC_ID_BLUETOOTH) {
    return A2DP_WRONG_CODEC;
  }
  p_ie->channelMode = *p_codec_info & 0x0F;
  p_ie->sampleRate = *p_codec_info & 0xF0;
  p_codec_info++;
  if (is_capability) {
    if (A2DP_BitsSet(p_ie->sampleRate) == A2D_SET_ZERO_BIT)
      return A2DP_BAD_SAMP_FREQ;
    if (A2DP_BitsSet(p_ie->channelMode) == A2D_SET_ZERO_BIT)
      return A2DP_BAD_CH_MODE;
    return A2DP_SUCCESS;
  }
  if (A2DP_BitsSet(p_ie->sampleRate) != A2D_SET_ONE_BIT)
    return A2DP_BAD_SAMP_FREQ;
  if (A2DP_BitsSet(p_ie->channelMode) != A2D_SET_ONE_BIT)
    return A2DP_BAD_CH_MODE;
  return A2DP_SUCCESS;
}
tA2D_STATUS A2DP_ParseInfoAptx ( tA2DP_APTX_CIE * p_ie , const uint8_t * p_codec_info , bool is_capability , char * caller_s ) { uint8_t losc ; uint8_t media_type ; tA2DP_CODEC_TYPE codec_type ; APPL_TRACE_WARNING ( " " , caller_s ) ; if ( p_ie == NULL || p_codec_info == NULL ) return A2DP_INVALID_PARAMS ; losc = * p_codec_info ++ ; if ( losc != A2DP_APTX_CODEC_LEN ) return A2DP_WRONG_CODEC ; media_type = ( * p_codec_info ++ ) >> 4 ; codec_type = * p_codec_info ++ ; if ( media_type != AVDT_MEDIA_AUDIO || codec_type != A2DP_MEDIA_CT_NON_A2DP ) { return A2DP_WRONG_CODEC ; } p_ie -> vendorId = ( * p_codec_info & 0x000000FF ) | ( * ( p_codec_info + 1 ) << 8 & 0x0000FF00 ) | ( * ( p_codec_info + 2 ) << 16 & 0x00FF0000 ) | ( * ( p_codec_info + 3 ) << 24 & 0xFF000000 ) ; p_codec_info += 4 ; p_ie -> codecId = ( * p_codec_info & 0x00FF ) | ( * ( p_codec_info + 1 ) << 8 & 0xFF00 ) ; p_codec_info += 2 ; if ( p_ie -> vendorId != A2DP_APTX_VENDOR_ID || p_ie -> codecId != A2DP_APTX_CODEC_ID_BLUETOOTH ) { return A2DP_WRONG_CODEC ; } p_ie -> channelMode = * p_codec_info & 0x0F ; p_ie -> sampleRate = * p_codec_info & 0xF0 ; p_codec_info ++ ; if ( is_capability ) { if ( A2DP_BitsSet ( p_ie -> sampleRate ) == A2D_SET_ZERO_BIT ) return A2DP_BAD_SAMP_FREQ ; if ( A2DP_BitsSet ( p_ie -> channelMode ) == A2D_SET_ZERO_BIT ) return A2DP_BAD_CH_MODE ; return A2DP_SUCCESS ; } if ( A2DP_BitsSet ( p_ie -> sampleRate ) != A2D_SET_ONE_BIT ) return A2DP_BAD_SAMP_FREQ ; if ( A2DP_BitsSet ( p_ie -> channelMode ) != A2D_SET_ONE_BIT ) return A2DP_BAD_CH_MODE ; return A2DP_SUCCESS ; }
Parses the aptX Media Codec Capabilities byte sequence beginning from the
LOSC octet.
Parses the aptX Media Codec Capabilities byte sequence beginning from the LOSC octet .
// add by nishi // Check the codec capability length /* Check the Media Type and Media Codec Type */ //if (media_type != AVDT_MEDIA_TYPE_AUDIO || // Check the Vendor ID and Codec ID */ // NOTE: The checks here are very liberal. We should be using more // pedantic checks specific to the SRC or SNK as specified in the spec.