Moving UniqueIdGenerator into rtc_base.
UniqueIdGenerator classes are useful outside the pc directory.
This change moves them to the rtc_base directory to enable code
in all directories to reference them.
Bug: None
Change-Id: I1c77da87ea26d9611f37dc1d4d2c16006a6589c6
Reviewed-on: https://webrtc-review.googlesource.com/c/119460
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Amit Hilbuch <amithi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26378}
diff --git a/pc/BUILD.gn b/pc/BUILD.gn
index f8fd591..ce4e6dc 100644
--- a/pc/BUILD.gn
+++ b/pc/BUILD.gn
@@ -85,8 +85,6 @@
"transport_stats.cc",
"transport_stats.h",
"transportstats.h",
- "unique_id_generator.cc",
- "unique_id_generator.h",
]
deps = [
@@ -305,7 +303,6 @@
"srtptestutil.h",
"test/rtp_transport_test_util.h",
"test/srtp_test_util.h",
- "unique_id_generator_unittest.cc",
]
include_dirs = [ "//third_party/libsrtp/srtp" ]
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 9f3a7df..3c98117 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -28,16 +28,16 @@
#include "pc/channel_manager.h"
#include "pc/rtp_media_utils.h"
#include "pc/srtp_filter.h"
-#include "pc/unique_id_generator.h"
#include "rtc_base/checks.h"
#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.h"
+#include "rtc_base/unique_id_generator.h"
namespace {
+using rtc::UniqueRandomIdGenerator;
using webrtc::RtpTransceiverDirection;
-using webrtc::UniqueRandomIdGenerator;
const char kInline[] = "inline:";
diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc
index 0cbd315..4cdab68 100644
--- a/pc/peer_connection.cc
+++ b/pc/peer_connection.cc
@@ -42,7 +42,6 @@
#include "pc/sctp_utils.h"
#include "pc/sdp_utils.h"
#include "pc/stream_collection.h"
-#include "pc/unique_id_generator.h"
#include "pc/video_capturer_track_source.h"
#include "pc/video_track.h"
#include "rtc_base/bind.h"
diff --git a/pc/peer_connection.h b/pc/peer_connection.h
index ca92d76..dde19ba 100644
--- a/pc/peer_connection.h
+++ b/pc/peer_connection.h
@@ -28,8 +28,8 @@
#include "pc/rtp_transceiver.h"
#include "pc/stats_collector.h"
#include "pc/stream_collection.h"
-#include "pc/unique_id_generator.h"
#include "pc/webrtc_session_description_factory.h"
+#include "rtc_base/unique_id_generator.h"
namespace webrtc {
@@ -1062,7 +1062,7 @@
rtc::scoped_refptr<MediaStreamInterface> missing_msid_default_stream_;
// MIDs will be generated using this generator which will keep track of
// all the MIDs that have been seen over the life of the PeerConnection.
- UniqueStringGenerator mid_generator_;
+ rtc::UniqueStringGenerator mid_generator_;
SessionError session_error_ = SessionError::kNone;
std::string session_error_desc_;
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index ceb856c..e38da1f 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -1028,6 +1028,8 @@
"stream.h",
"thread.cc",
"thread.h",
+ "unique_id_generator.cc",
+ "unique_id_generator.h",
]
if (build_with_chromium) {
@@ -1519,6 +1521,7 @@
"stream_unittest.cc",
"test_client_unittest.cc",
"thread_unittest.cc",
+ "unique_id_generator_unittest.cc",
]
if (is_win) {
sources += [
diff --git a/pc/unique_id_generator.cc b/rtc_base/unique_id_generator.cc
similarity index 77%
rename from pc/unique_id_generator.cc
rename to rtc_base/unique_id_generator.cc
index 6b508f1..62cd068 100644
--- a/pc/unique_id_generator.cc
+++ b/rtc_base/unique_id_generator.cc
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "pc/unique_id_generator.h"
+#include "rtc_base/unique_id_generator.h"
#include <limits>
#include <vector>
@@ -17,11 +17,10 @@
#include "rtc_base/string_encode.h"
#include "rtc_base/string_to_number.h"
-namespace webrtc {
+namespace rtc {
UniqueRandomIdGenerator::UniqueRandomIdGenerator() : known_ids_() {}
-UniqueRandomIdGenerator::UniqueRandomIdGenerator(
- rtc::ArrayView<uint32_t> known_ids)
+UniqueRandomIdGenerator::UniqueRandomIdGenerator(ArrayView<uint32_t> known_ids)
: known_ids_(known_ids.begin(), known_ids.end()) {}
UniqueRandomIdGenerator::~UniqueRandomIdGenerator() = default;
@@ -29,7 +28,7 @@
uint32_t UniqueRandomIdGenerator::GenerateId() {
while (true) {
RTC_CHECK_LT(known_ids_.size(), std::numeric_limits<uint32_t>::max());
- auto pair = known_ids_.insert(rtc::CreateRandomNonZeroId());
+ auto pair = known_ids_.insert(CreateRandomNonZeroId());
if (pair.second) {
return *pair.first;
}
@@ -41,8 +40,7 @@
}
UniqueStringGenerator::UniqueStringGenerator() : unique_number_generator_() {}
-UniqueStringGenerator::UniqueStringGenerator(
- rtc::ArrayView<std::string> known_ids) {
+UniqueStringGenerator::UniqueStringGenerator(ArrayView<std::string> known_ids) {
for (const std::string& str : known_ids) {
AddKnownId(str);
}
@@ -51,11 +49,11 @@
UniqueStringGenerator::~UniqueStringGenerator() = default;
std::string UniqueStringGenerator::GenerateString() {
- return rtc::ToString(unique_number_generator_.GenerateNumber());
+ return ToString(unique_number_generator_.GenerateNumber());
}
void UniqueStringGenerator::AddKnownId(const std::string& value) {
- absl::optional<uint32_t> int_value = rtc::StringToNumber<uint32_t>(value);
+ absl::optional<uint32_t> int_value = StringToNumber<uint32_t>(value);
// The underlying generator works for uint32_t values, so if the provided
// value is not a uint32_t it will never be generated anyway.
if (int_value.has_value()) {
@@ -63,4 +61,4 @@
}
}
-} // namespace webrtc
+} // namespace rtc
diff --git a/pc/unique_id_generator.h b/rtc_base/unique_id_generator.h
similarity index 91%
rename from pc/unique_id_generator.h
rename to rtc_base/unique_id_generator.h
index cd6e085..849daa9 100644
--- a/pc/unique_id_generator.h
+++ b/rtc_base/unique_id_generator.h
@@ -8,8 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#ifndef PC_UNIQUE_ID_GENERATOR_H_
-#define PC_UNIQUE_ID_GENERATOR_H_
+#ifndef RTC_BASE_UNIQUE_ID_GENERATOR_H_
+#define RTC_BASE_UNIQUE_ID_GENERATOR_H_
#include <limits>
#include <set>
@@ -17,7 +17,7 @@
#include "api/array_view.h"
-namespace webrtc {
+namespace rtc {
// This class will generate numbers. A common use case is for identifiers.
// The generated numbers will be unique, in the local scope of the generator.
@@ -33,7 +33,7 @@
typedef TIntegral value_type;
UniqueNumberGenerator();
// Creates a generator that will never return any value from the given list.
- explicit UniqueNumberGenerator(rtc::ArrayView<TIntegral> known_ids);
+ explicit UniqueNumberGenerator(ArrayView<TIntegral> known_ids);
~UniqueNumberGenerator();
// Generates a number that this generator has never produced before.
@@ -61,7 +61,7 @@
typedef uint32_t value_type;
UniqueRandomIdGenerator();
// Create a generator that will never return any value from the given list.
- explicit UniqueRandomIdGenerator(rtc::ArrayView<uint32_t> known_ids);
+ explicit UniqueRandomIdGenerator(ArrayView<uint32_t> known_ids);
~UniqueRandomIdGenerator();
// Generates a random id that this generator has never produced before.
@@ -86,7 +86,7 @@
public:
typedef std::string value_type;
UniqueStringGenerator();
- explicit UniqueStringGenerator(rtc::ArrayView<std::string> known_ids);
+ explicit UniqueStringGenerator(ArrayView<std::string> known_ids);
~UniqueStringGenerator();
std::string GenerateString();
@@ -105,7 +105,7 @@
template <typename TIntegral>
UniqueNumberGenerator<TIntegral>::UniqueNumberGenerator(
- rtc::ArrayView<TIntegral> known_ids)
+ ArrayView<TIntegral> known_ids)
: counter_(0), known_ids_(known_ids.begin(), known_ids.end()) {}
template <typename TIntegral>
@@ -126,6 +126,6 @@
void UniqueNumberGenerator<TIntegral>::AddKnownId(TIntegral value) {
known_ids_.insert(value);
}
-} // namespace webrtc
+} // namespace rtc
-#endif // PC_UNIQUE_ID_GENERATOR_H_
+#endif // RTC_BASE_UNIQUE_ID_GENERATOR_H_
diff --git a/pc/unique_id_generator_unittest.cc b/rtc_base/unique_id_generator_unittest.cc
similarity index 97%
rename from pc/unique_id_generator_unittest.cc
rename to rtc_base/unique_id_generator_unittest.cc
index f3cba76..5b6ce4d 100644
--- a/pc/unique_id_generator_unittest.cc
+++ b/rtc_base/unique_id_generator_unittest.cc
@@ -13,15 +13,15 @@
#include "vector"
#include "api/array_view.h"
-#include "pc/unique_id_generator.h"
#include "rtc_base/gunit.h"
#include "rtc_base/helpers.h"
+#include "rtc_base/unique_id_generator.h"
#include "test/gmock.h"
using ::testing::IsEmpty;
using ::testing::Test;
-namespace webrtc {
+namespace rtc {
template <typename Generator>
class UniqueIdGeneratorTest : public Test {};
@@ -107,4 +107,4 @@
EXPECT_THAT(intersection, IsEmpty());
}
-} // namespace webrtc
+} // namespace rtc