Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 //
     18 // A2DP Codec API for LDAC
     19 //
     20 
     21 #ifndef A2DP_VENDOR_LDAC_H
     22 #define A2DP_VENDOR_LDAC_H
     23 
     24 #include "a2dp_codec_api.h"
     25 #include "a2dp_vendor_ldac_constants.h"
     26 #include "avdt_api.h"
     27 
     28 class A2dpCodecConfigLdac : public A2dpCodecConfig {
     29  public:
     30   A2dpCodecConfigLdac(btav_a2dp_codec_priority_t codec_priority);
     31   virtual ~A2dpCodecConfigLdac();
     32 
     33   bool init() override;
     34   period_ms_t encoderIntervalMs() const override;
     35   int getEffectiveMtu() const override;
     36   bool setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
     37                       uint8_t* p_result_codec_config) override;
     38   bool setPeerCodecCapabilities(
     39       const uint8_t* p_peer_codec_capabilities) override;
     40 
     41  private:
     42   bool useRtpHeaderMarkerBit() const override;
     43   bool updateEncoderUserConfig(
     44       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
     45       bool* p_restart_input, bool* p_restart_output,
     46       bool* p_config_updated) override;
     47   void debug_codec_dump(int fd) override;
     48 };
     49 
     50 // Checks whether the codec capabilities contain a valid A2DP LDAC Source
     51 // codec.
     52 // NOTE: only codecs that are implemented are considered valid.
     53 // Returns true if |p_codec_info| contains information about a valid LDAC
     54 // codec, otherwise false.
     55 bool A2DP_IsVendorSourceCodecValidLdac(const uint8_t* p_codec_info);
     56 
     57 // Checks whether the codec capabilities contain a valid peer A2DP LDAC Sink
     58 // codec.
     59 // NOTE: only codecs that are implemented are considered valid.
     60 // Returns true if |p_codec_info| contains information about a valid LDAC
     61 // codec, otherwise false.
     62 bool A2DP_IsVendorPeerSinkCodecValidLdac(const uint8_t* p_codec_info);
     63 
     64 // Checks whether the A2DP data packets should contain RTP header.
     65 // |content_protection_enabled| is true if Content Protection is
     66 // enabled. |p_codec_info| contains information about the codec capabilities.
     67 // Returns true if the A2DP data packets should contain RTP header, otherwise
     68 // false.
     69 bool A2DP_VendorUsesRtpHeaderLdac(bool content_protection_enabled,
     70                                   const uint8_t* p_codec_info);
     71 
     72 // Gets the A2DP LDAC codec name for a given |p_codec_info|.
     73 const char* A2DP_VendorCodecNameLdac(const uint8_t* p_codec_info);
     74 
     75 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b|
     76 // have the same type.
     77 // Returns true if the two codecs have the same type, otherwise false.
     78 bool A2DP_VendorCodecTypeEqualsLdac(const uint8_t* p_codec_info_a,
     79                                     const uint8_t* p_codec_info_b);
     80 
     81 // Checks whether two A2DP LDAC codecs |p_codec_info_a| and |p_codec_info_b|
     82 // are exactly the same.
     83 // Returns true if the two codecs are exactly the same, otherwise false.
     84 // If the codec type is not LDAC, the return value is false.
     85 bool A2DP_VendorCodecEqualsLdac(const uint8_t* p_codec_info_a,
     86                                 const uint8_t* p_codec_info_b);
     87 
     88 // Gets the track sample rate value for the A2DP LDAC codec.
     89 // |p_codec_info| is a pointer to the LDAC codec_info to decode.
     90 // Returns the track sample rate on success, or -1 if |p_codec_info|
     91 // contains invalid codec information.
     92 int A2DP_VendorGetTrackSampleRateLdac(const uint8_t* p_codec_info);
     93 
     94 // Gets the track bitrate value for the A2DP LDAC codec.
     95 // |p_codec_info| is a pointer to the LDAC codec_info to decode.
     96 // Returns the track sample rate on success, or -1 if |p_codec_info|
     97 // contains invalid codec information.
     98 int A2DP_VendorGetBitRateLdac(const uint8_t* p_codec_info);
     99 
    100 // Gets the channel count for the A2DP LDAC codec.
    101 // |p_codec_info| is a pointer to the LDAC codec_info to decode.
    102 // Returns the channel count on success, or -1 if |p_codec_info|
    103 // contains invalid codec information.
    104 int A2DP_VendorGetTrackChannelCountLdac(const uint8_t* p_codec_info);
    105 
    106 // Gets the channel mode code for the A2DP LDAC codec.
    107 // The actual value is codec-specific - see |A2DP_LDAC_CHANNEL_MODE_*|.
    108 // |p_codec_info| is a pointer to the LDAC codec_info to decode.
    109 // Returns the channel mode code on success, or -1 if |p_codec_info|
    110 // contains invalid codec information.
    111 int A2DP_VendorGetChannelModeCodeLdac(const uint8_t* p_codec_info);
    112 
    113 // Gets the A2DP LDAC audio data timestamp from an audio packet.
    114 // |p_codec_info| contains the codec information.
    115 // |p_data| contains the audio data.
    116 // The timestamp is stored in |p_timestamp|.
    117 // Returns true on success, otherwise false.
    118 bool A2DP_VendorGetPacketTimestampLdac(const uint8_t* p_codec_info,
    119                                        const uint8_t* p_data,
    120                                        uint32_t* p_timestamp);
    121 
    122 // Builds A2DP LDAC codec header for audio data.
    123 // |p_codec_info| contains the codec information.
    124 // |p_buf| contains the audio data.
    125 // |frames_per_packet| is the number of frames in this packet.
    126 // Returns true on success, otherwise false.
    127 bool A2DP_VendorBuildCodecHeaderLdac(const uint8_t* p_codec_info, BT_HDR* p_buf,
    128                                      uint16_t frames_per_packet);
    129 
    130 // Decodes A2DP LDAC codec info into a human readable string.
    131 // |p_codec_info| is a pointer to the LDAC codec_info to decode.
    132 // Returns a string describing the codec information.
    133 std::string A2DP_VendorCodecInfoStringLdac(const uint8_t* p_codec_info);
    134 
    135 // Gets the A2DP LDAC encoder interface that can be used to encode and prepare
    136 // A2DP packets for transmission - see |tA2DP_ENCODER_INTERFACE|.
    137 // |p_codec_info| contains the codec information.
    138 // Returns the A2DP LDAC encoder interface if the |p_codec_info| is valid and
    139 // supported, otherwise NULL.
    140 const tA2DP_ENCODER_INTERFACE* A2DP_VendorGetEncoderInterfaceLdac(
    141     const uint8_t* p_codec_info);
    142 
    143 // Adjusts the A2DP LDAC codec, based on local support and Bluetooth
    144 // specification.
    145 // |p_codec_info| contains the codec information to adjust.
    146 // Returns true if |p_codec_info| is valid and supported, otherwise false.
    147 bool A2DP_VendorAdjustCodecLdac(uint8_t* p_codec_info);
    148 
    149 // Gets the A2DP LDAC Source codec index for a given |p_codec_info|.
    150 // Returns the corresponding |btav_a2dp_codec_index_t| on success,
    151 // otherwise |BTAV_A2DP_CODEC_INDEX_MAX|.
    152 btav_a2dp_codec_index_t A2DP_VendorSourceCodecIndexLdac(
    153     const uint8_t* p_codec_info);
    154 
    155 // Gets the A2DP LDAC Source codec name.
    156 const char* A2DP_VendorCodecIndexStrLdac(void);
    157 
    158 // Initializes A2DP LDAC Source codec information into |AvdtpSepConfig|
    159 // configuration entry pointed by |p_cfg|.
    160 bool A2DP_VendorInitCodecConfigLdac(AvdtpSepConfig* p_cfg);
    161 
    162 #endif  // A2DP_VENDOR_LDAC_H
    163