diff --git a/pc/BUILD.gn b/pc/BUILD.gn index f36505b153..94b0842eab 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -41,6 +41,7 @@ rtc_library("rtc_pc_base") { visibility = [ "*" ] defines = [] sources = [ + "bundle_manager.cc", "bundle_manager.h", "channel.cc", "channel.h", diff --git a/pc/bundle_manager.cc b/pc/bundle_manager.cc new file mode 100644 index 0000000000..0228635998 --- /dev/null +++ b/pc/bundle_manager.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2021 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "pc/bundle_manager.h" + +namespace webrtc { + +void BundleManager::Update(const cricket::SessionDescription* description) { + bundle_groups_.clear(); + for (const cricket::ContentGroup* new_bundle_group : + description->GetGroupsByName(cricket::GROUP_TYPE_BUNDLE)) { + bundle_groups_.push_back( + std::make_unique(*new_bundle_group)); + } +} + +void BundleManager::DeleteMid(const cricket::ContentGroup* bundle_group, + const std::string& mid) { + // Remove the rejected content from the |bundle_group|. + // The const pointer arg is used to identify the group, we verify + // it before we use it to make a modification. + auto bundle_group_it = std::find_if( + bundle_groups_.begin(), bundle_groups_.end(), + [bundle_group](std::unique_ptr& group) { + return bundle_group == group.get(); + }); + RTC_DCHECK(bundle_group_it != bundle_groups_.end()); + (*bundle_group_it)->RemoveContentName(mid); +} + +void BundleManager::DeleteGroup(const cricket::ContentGroup* bundle_group) { + // Delete the BUNDLE group. + auto bundle_group_it = std::find_if( + bundle_groups_.begin(), bundle_groups_.end(), + [bundle_group](std::unique_ptr& group) { + return bundle_group == group.get(); + }); + RTC_DCHECK(bundle_group_it != bundle_groups_.end()); + bundle_groups_.erase(bundle_group_it); +} + +} // namespace webrtc diff --git a/pc/bundle_manager.h b/pc/bundle_manager.h index 3cbf351bbc..2e2aa77f6d 100644 --- a/pc/bundle_manager.h +++ b/pc/bundle_manager.h @@ -12,6 +12,7 @@ #define PC_BUNDLE_MANAGER_H_ #include +#include #include #include "pc/session_description.h" @@ -22,7 +23,7 @@ namespace webrtc { // This is a work-in-progress. Planned steps: // 1) Move all Bundle-related data structures from JsepTransport -// into this class. +// into this class. // 2) Move all Bundle-related functions into this class. // 3) Move remaining Bundle-related logic into this class. // Make data members private. @@ -35,12 +36,16 @@ class BundleManager { const { return bundle_groups_; } - std::vector>& bundle_groups() { - return bundle_groups_; - } + // Update the groups description. This completely replaces the group + // description with the one from the SessionDescription. + void Update(const cricket::SessionDescription* description); + // Delete a MID from the group that contains it. + void DeleteMid(const cricket::ContentGroup* bundle_group, + const std::string& mid); + // Delete a group. + void DeleteGroup(const cricket::ContentGroup* bundle_group); private: - // Use unique_ptr<> to get a stable address. std::vector> bundle_groups_; }; diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index 69e71d961a..413c940da8 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -778,11 +778,7 @@ RTCError JsepTransportController::ValidateAndMaybeUpdateBundleGroups( } if (ShouldUpdateBundleGroup(type, description)) { - bundles_.bundle_groups().clear(); - for (const cricket::ContentGroup* new_bundle_group : new_bundle_groups) { - bundles_.bundle_groups().push_back( - std::make_unique(*new_bundle_group)); - } + bundles_.Update(description); } for (const auto& bundle_group : bundles_.bundle_groups()) { @@ -850,18 +846,12 @@ void JsepTransportController::HandleRejectedContent( established_bundle_groups_by_mid.erase(it); } // Delete the BUNDLE group. - auto bundle_group_it = std::find_if( - bundles_.bundle_groups().begin(), bundles_.bundle_groups().end(), - [bundle_group](std::unique_ptr& group) { - return bundle_group == group.get(); - }); - RTC_DCHECK(bundle_group_it != bundles_.bundle_groups().end()); - bundles_.bundle_groups().erase(bundle_group_it); + bundles_.DeleteGroup(bundle_group); } else { RemoveTransportForMid(content_info.name); if (bundle_group) { // Remove the rejected content from the |bundle_group|. - bundle_group->RemoveContentName(content_info.name); + bundles_.DeleteMid(bundle_group, content_info.name); } } MaybeDestroyJsepTransport(content_info.name);