OSDN Git Service

Set the RTP Header Marker bit selectively per A2DP codec
authorPavlin Radoslavov <pavlin@google.com>
Fri, 12 May 2017 08:16:10 +0000 (01:16 -0700)
committerPavlin Radoslavov <pavlin@google.com>
Fri, 12 May 2017 17:06:05 +0000 (10:06 -0700)
Add a mechanism to set the RTP Header Marker bit per codec.
Currently, the Marker bit is set only for AAC.

Test: A2DP streaming, PTS AVDTP tests: TC_ACP_SRC_TRA_BTR_BV_01_C,
      TC_INT_SRC_SIG_SMG_BV_17_C, TC_INT_SRC_TRA_BTR_BV_01_C
Bug: 37723283
Change-Id: I9b8e77d44c750746c169df9628d5539ad2406b92

14 files changed:
bta/av/bta_av_aact.cc
bta/av/bta_av_int.h
stack/a2dp/a2dp_aac.cc
stack/a2dp/a2dp_sbc.cc
stack/a2dp/a2dp_vendor_aptx.cc
stack/a2dp/a2dp_vendor_aptx_hd.cc
stack/a2dp/a2dp_vendor_ldac.cc
stack/include/a2dp_aac.h
stack/include/a2dp_codec_api.h
stack/include/a2dp_sbc.h
stack/include/a2dp_vendor_aptx.h
stack/include/a2dp_vendor_aptx_hd.h
stack/include/a2dp_vendor_ldac.h
stack/test/stack_a2dp_test.cc

index defe9fb..3bf6f8e 100644 (file)
@@ -33,6 +33,7 @@
 #include "avdt_api.h"
 #include "bt_utils.h"
 #include "bta_av_int.h"
+#include "btif/include/btif_av_co.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
 #include "osi/include/osi.h"
@@ -1024,6 +1025,7 @@ void bta_av_cleanup(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
   /* if de-registering shut everything down */
   msg.hdr.layer_specific = p_scb->hndl;
   p_scb->started = false;
+  p_scb->current_codec = nullptr;
   p_scb->cong = false;
   p_scb->role = role;
   p_scb->cur_psc_mask = 0;
@@ -1454,6 +1456,7 @@ void bta_av_do_close(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
 
   /* close stream */
   p_scb->started = false;
+  p_scb->current_codec = nullptr;
 
   /* drop the buffers queued in L2CAP */
   L2CA_FlushChannel(p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
@@ -2095,11 +2098,15 @@ void bta_av_data_path(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
   BT_HDR* p_buf = NULL;
   uint32_t timestamp;
   bool new_buf = false;
-  uint8_t m_pt = AVDT_MARKER_SET | 0x60;
+  uint8_t m_pt = 0x60;
   tAVDT_DATA_OPT_MASK opt;
 
   if (p_scb->cong) return;
 
+  if (p_scb->current_codec->useRtpHeaderMarkerBit()) {
+    m_pt |= AVDT_MARKER_SET;
+  }
+
   // Always get the current number of bufs que'd up
   p_scb->l2c_bufs =
       (uint8_t)L2CA_FlushChannel(p_scb->l2c_cid, L2CAP_FLUSH_CHANS_GET);
@@ -2225,6 +2232,8 @@ void bta_av_start_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
                    p_scb->role);
 
   p_scb->started = true;
+  p_scb->current_codec = bta_av_get_a2dp_current_codec();
+
   if (p_scb->sco_suspend) {
     p_scb->sco_suspend = false;
   }
index 394562e..e1237bb 100644 (file)
@@ -482,6 +482,7 @@ typedef struct {
   uint8_t rc_handle; /* connected AVRCP handle */
   bool use_rc;       /* true if AVRCP is allowed */
   bool started;      /* true if stream started */
+  A2dpCodecConfig* current_codec; /* The current A2DP codec */
   uint8_t
       co_started;    /* non-zero, if stream started from call-out perspective */
   bool recfg_sup;    /* true if the first attempt to reconfigure the stream was
index 6c0accd..8fc8034 100644 (file)
@@ -706,6 +706,8 @@ bool A2dpCodecConfigAac::init() {
   return true;
 }
 
+bool A2dpCodecConfigAac::useRtpHeaderMarkerBit() const { return true; }
+
 //
 // Selects the best sample rate from |sampleRate|.
 // The result is stored in |p_result| and |p_codec_config|.
index 1a73258..5e3b6af 100644 (file)
@@ -1056,6 +1056,8 @@ bool A2dpCodecConfigSbc::init() {
   return true;
 }
 
+bool A2dpCodecConfigSbc::useRtpHeaderMarkerBit() const { return false; }
+
 //
 // Selects the best sample rate from |samp_freq|.
 // The result is stored in |p_result| and |p_codec_config|.
@@ -1610,6 +1612,11 @@ bool A2dpCodecConfigSbcSink::init() {
   return true;
 }
 
+bool A2dpCodecConfigSbcSink::useRtpHeaderMarkerBit() const {
+  // TODO: This method applies only to Source codecs
+  return false;
+}
+
 bool A2dpCodecConfigSbcSink::setCodecConfig(
     UNUSED_ATTR const uint8_t* p_peer_codec_info,
     UNUSED_ATTR bool is_capability,
index 1941393..c624af2 100644 (file)
@@ -436,6 +436,8 @@ bool A2dpCodecConfigAptx::init() {
   return true;
 }
 
+bool A2dpCodecConfigAptx::useRtpHeaderMarkerBit() const { return false; }
+
 //
 // Selects the best sample rate from |sampleRate|.
 // The result is stored in |p_result| and p_codec_config|.
index 798f908..4f1c8d2 100644 (file)
@@ -453,6 +453,8 @@ bool A2dpCodecConfigAptxHd::init() {
   return true;
 }
 
+bool A2dpCodecConfigAptxHd::useRtpHeaderMarkerBit() const { return false; }
+
 //
 // Selects the best sample rate from |sampleRate|.
 // The result is stored in |p_result| and p_codec_config|.
index 82d93d2..072173a 100644 (file)
@@ -558,6 +558,8 @@ bool A2dpCodecConfigLdac::init() {
   return true;
 }
 
+bool A2dpCodecConfigLdac::useRtpHeaderMarkerBit() const { return false; }
+
 //
 // Selects the best sample rate from |sampleRate|.
 // The result is stored in |p_result| and |p_codec_config|.
index cc67a15..88bb1d9 100644 (file)
@@ -36,11 +36,11 @@ class A2dpCodecConfigAac : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
       bool* p_config_updated) override;
-
   void debug_codec_dump(int fd) override;
 };
 
index 7944508..8162628 100644 (file)
@@ -107,6 +107,13 @@ class A2dpCodecConfig {
   // or 0 if not configured.
   uint8_t getAudioBitsPerSample();
 
+  // Checks whether the codec uses the RTP Header Marker bit (see RFC 6416).
+  // NOTE: Even if the encoded data uses RTP headers, some codecs do not use
+  // the Marker bit - that bit is expected to be set to 0.
+  // Returns true if the encoded data packets have RTP headers, and
+  // the Marker bit in the header is set according to RFC 6416.
+  virtual bool useRtpHeaderMarkerBit() const = 0;
+
   // Checks whether |codec_config| is empty and contains no configuration.
   // Returns true if |codec_config| is empty, otherwise false.
   static bool isCodecConfigEmpty(const btav_a2dp_codec_config_t& codec_config);
index b6379fd..ea06312 100644 (file)
@@ -36,11 +36,11 @@ class A2dpCodecConfigSbc : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
       bool* p_config_updated) override;
-
   void debug_codec_dump(int fd) override;
 };
 
@@ -55,6 +55,7 @@ class A2dpCodecConfigSbcSink : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
index a3f8c39..1fba23a 100644 (file)
@@ -36,11 +36,11 @@ class A2dpCodecConfigAptx : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
       bool* p_config_updated) override;
-
   void debug_codec_dump(int fd) override;
 };
 
index 688f440..0250ca0 100644 (file)
@@ -36,11 +36,11 @@ class A2dpCodecConfigAptxHd : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
       bool* p_config_updated) override;
-
   void debug_codec_dump(int fd) override;
 };
 
index 2bf0da0..a4dd48d 100644 (file)
@@ -36,11 +36,11 @@ class A2dpCodecConfigLdac : public A2dpCodecConfig {
                       uint8_t* p_result_codec_config) override;
 
  private:
+  bool useRtpHeaderMarkerBit() const override;
   bool updateEncoderUserConfig(
       const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
       bool* p_restart_input, bool* p_restart_output,
       bool* p_config_updated) override;
-
   void debug_codec_dump(int fd) override;
 };
 
index ef46166..7785909 100644 (file)
@@ -867,6 +867,7 @@ TEST_F(A2dpCodecConfigTest, setCodecConfig) {
   for (size_t i = 0; i < codec_info_sbc[0] + 1; i++) {
     EXPECT_EQ(codec_info_result[i], codec_info_sbc[i]);
   }
+  EXPECT_FALSE(codec_config->useRtpHeaderMarkerBit());
 
   // Create the codec config - AAC
   memset(codec_info_result, 0, sizeof(codec_info_result));
@@ -882,6 +883,7 @@ TEST_F(A2dpCodecConfigTest, setCodecConfig) {
   for (size_t i = 0; i < codec_info_aac[0] + 1; i++) {
     EXPECT_EQ(codec_info_result[i], codec_info_aac[i]);
   }
+  EXPECT_TRUE(codec_config->useRtpHeaderMarkerBit());
 
   // Test invalid codec info
   uint8_t codec_info_sbc_test1[AVDT_CODEC_SIZE];