OSDN Git Service

Wire up SetChannelTxPriority
authorHansong Zhang <hsz@google.com>
Fri, 15 Jan 2021 02:56:02 +0000 (18:56 -0800)
committerHansong Zhang <hsz@google.com>
Fri, 15 Jan 2021 19:42:35 +0000 (11:42 -0800)
Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: Iceb6559d7468a886d3720038f172dce6297016d3

gd/l2cap/classic/internal/link.cc
gd/l2cap/classic/internal/link.h
gd/l2cap/dynamic_channel.cc
gd/l2cap/dynamic_channel.h
gd/l2cap/internal/data_pipeline_manager.cc
gd/l2cap/internal/data_pipeline_manager.h
gd/l2cap/internal/dynamic_channel_impl.h
gd/l2cap/internal/ilink.h
main/shim/l2c_api.cc

index 0d6bea0..c3f0f78 100644 (file)
@@ -171,6 +171,10 @@ void Link::SendConnectionRequest(Psm psm, Cid local_cid,
   }
 }
 
+void Link::SetChannelTxPriority(Cid local_cid, bool high_priority) {
+  data_pipeline_manager_.SetChannelTxPriority(local_cid, high_priority);
+}
+
 void Link::SetPendingDynamicChannels(std::list<Psm> psm_list,
                                      std::list<Link::PendingDynamicChannelConnection> callback_list) {
   ASSERT(psm_list.size() == callback_list.size());
index 958ad71..c8c9514 100644 (file)
@@ -106,6 +106,7 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::ConnectionM
   virtual void SendConnectionRequest(Psm psm, Cid local_cid);
   virtual void SendConnectionRequest(Psm psm, Cid local_cid,
                                      PendingDynamicChannelConnection pending_dynamic_channel_connection);
+  void SetChannelTxPriority(Cid local_cid, bool high_priority) override;
 
   // When a Link is established, LinkManager notifies pending dynamic channels to connect
   virtual void SetPendingDynamicChannels(std::list<Psm> psm_list,
index 19d527f..a49aed7 100644 (file)
@@ -42,5 +42,10 @@ DynamicChannel::GetQueueUpEnd() const {
 Cid DynamicChannel::HACK_GetRemoteCid() {
   return impl_->GetRemoteCid();
 }
+
+void DynamicChannel::HACK_SetChannelTxPriority(bool high_priority) {
+  return impl_->SetChannelTxPriority(high_priority);
+}
+
 }  // namespace l2cap
 }  // namespace bluetooth
index 7bb34fe..ba4e750 100644 (file)
@@ -72,6 +72,12 @@ class DynamicChannel {
 
   Cid HACK_GetRemoteCid();
 
+  /**
+   * Used by A2dp software encoding to prioritize Tx of this channel
+   * @param high_priority
+   */
+  void HACK_SetChannelTxPriority(bool high_priority);
+
  private:
   std::shared_ptr<l2cap::internal::DynamicChannelImpl> impl_;
   os::Handler* l2cap_handler_;
index b19412a..7247e28 100644 (file)
@@ -36,6 +36,7 @@ void DataPipelineManager::AttachChannel(Cid cid, std::shared_ptr<ChannelImpl> ch
 void DataPipelineManager::DetachChannel(Cid cid) {
   ASSERT(sender_map_.find(cid) != sender_map_.end());
   sender_map_.erase(cid);
+  scheduler_->SetChannelTxPriority(cid, false);
 }
 
 DataController* DataPipelineManager::GetDataController(Cid cid) {
@@ -55,6 +56,11 @@ void DataPipelineManager::UpdateClassicConfiguration(Cid cid, classic::internal:
   sender_map_.find(cid)->second.UpdateClassicConfiguration(config);
 }
 
+void DataPipelineManager::SetChannelTxPriority(Cid cid, bool high_priority) {
+  ASSERT(sender_map_.find(cid) != sender_map_.end());
+  scheduler_->SetChannelTxPriority(cid, high_priority);
+}
+
 }  // namespace internal
 }  // namespace l2cap
 }  // namespace bluetooth
index aea8d7c..104f49e 100644 (file)
@@ -66,6 +66,7 @@ class DataPipelineManager {
   virtual DataController* GetDataController(Cid cid);
   virtual void OnPacketSent(Cid cid);
   virtual void UpdateClassicConfiguration(Cid cid, classic::internal::ChannelConfigurationState config);
+  virtual void SetChannelTxPriority(Cid cid, bool high_priority);
   virtual ~DataPipelineManager() = default;
 
  private:
index c54332e..a012fff 100644 (file)
@@ -66,6 +66,10 @@ class DynamicChannelImpl : public l2cap::internal::ChannelImpl {
     return psm_;
   }
 
+  virtual void SetChannelTxPriority(bool high_priority) {
+    link_->SetChannelTxPriority(cid_, high_priority);
+  }
+
   // TODO(cmanton) Do something a little bit better than this
   bool local_initiated_{false};
 
index 2f354cb..4f6d664 100644 (file)
@@ -33,7 +33,10 @@ class ILink {
   virtual hci::AddressWithType GetDevice() const = 0;
 
   // To be used by LE credit based channel data controller over LE link
-  virtual void SendLeCredit(Cid local_cid, uint16_t credit) = 0;
+  virtual void SendLeCredit(Cid local_cid, uint16_t credit) {}
+
+  // Used by A2dp software encoding
+  virtual void SetChannelTxPriority(Cid local_cid, bool high_priority) {}
 };
 }  // namespace internal
 }  // namespace l2cap
index 700af45..19d4b73 100644 (file)
@@ -252,6 +252,16 @@ struct ClassicDynamicChannelHelper {
     return channel->second->HACK_GetRemoteCid();
   }
 
+  bool SetChannelTxPriority(uint16_t cid, bool high_priority) {
+    auto channel = channels_.find(cid);
+    if (channel == channels_.end()) {
+      LOG_ERROR("Channel is not open");
+      return false;
+    }
+    channel->second->HACK_SetChannelTxPriority(high_priority);
+    return true;
+  }
+
   std::unordered_map<uint16_t, std::unique_ptr<classic::DynamicChannel>>
       channels_;
   std::unordered_map<uint16_t, std::unique_ptr<bluetooth::os::EnqueueBuffer<
@@ -1073,8 +1083,14 @@ bool L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid) {
 }
 
 bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) {
-  LOG_INFO("UNIMPLEMENTED %s", __func__);
-  return false;
+  auto psm = classic_cid_token_to_channel_map_[cid];
+  if (classic_dynamic_channel_helper_map_.count(psm) == 0) {
+    LOG(ERROR) << __func__ << "Not registered psm: " << psm;
+    return false;
+  }
+  bool high_priority = priority == L2CAP_CHNL_PRIORITY_HIGH;
+  return classic_dynamic_channel_helper_map_[psm]->SetChannelTxPriority(
+      cid, high_priority);
 }
 
 bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout) {