Add parsing/serializing for MID RTP header extension.
This is the first in a series of CLs to add support for media
identification as part of unified plan SDP.
Bug: webrtc:4050
Change-Id: I0eb5639d240a9a1412c2b047a33d5112e4901f26
Reviewed-on: https://chromium-review.googlesource.com/576374
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Peter Thatcher <pthatcher@webrtc.org>
Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#19111}
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc
index 3a4afef..8b40d04 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_header_extensions.cc
@@ -312,72 +312,51 @@
return true;
}
-// RtpStreamId.
+bool BaseRtpStringExtension::Parse(rtc::ArrayView<const uint8_t> data,
+ StringRtpHeaderExtension* str) {
+ if (data.empty() || data[0] == 0) // Valid string extension can't be empty.
+ return false;
+ str->Set(data);
+ RTC_DCHECK(!str->empty());
+ return true;
+}
+
+bool BaseRtpStringExtension::Write(uint8_t* data,
+ const StringRtpHeaderExtension& str) {
+ RTC_DCHECK_GE(str.size(), 1);
+ RTC_DCHECK_LE(str.size(), StringRtpHeaderExtension::kMaxSize);
+ memcpy(data, str.data(), str.size());
+ return true;
+}
+
+bool BaseRtpStringExtension::Parse(rtc::ArrayView<const uint8_t> data,
+ std::string* str) {
+ if (data.empty() || data[0] == 0) // Valid string extension can't be empty.
+ return false;
+ const char* cstr = reinterpret_cast<const char*>(data.data());
+ // If there is a \0 character in the middle of the |data|, treat it as end
+ // of the string. Well-formed string extensions shouldn't contain it.
+ str->assign(cstr, strnlen(cstr, data.size()));
+ RTC_DCHECK(!str->empty());
+ return true;
+}
+
+bool BaseRtpStringExtension::Write(uint8_t* data, const std::string& str) {
+ RTC_DCHECK_GE(str.size(), 1);
+ RTC_DCHECK_LE(str.size(), StringRtpHeaderExtension::kMaxSize);
+ memcpy(data, str.data(), str.size());
+ return true;
+}
+
+// Constant declarations for string RTP header extension types.
+
constexpr RTPExtensionType RtpStreamId::kId;
constexpr const char* RtpStreamId::kUri;
-bool RtpStreamId::Parse(rtc::ArrayView<const uint8_t> data, StreamId* rsid) {
- if (data.empty() || data[0] == 0) // Valid rsid can't be empty.
- return false;
- rsid->Set(data);
- RTC_DCHECK(!rsid->empty());
- return true;
-}
-
-bool RtpStreamId::Write(uint8_t* data, const StreamId& rsid) {
- RTC_DCHECK_GE(rsid.size(), 1);
- RTC_DCHECK_LE(rsid.size(), StreamId::kMaxSize);
- memcpy(data, rsid.data(), rsid.size());
- return true;
-}
-
-bool RtpStreamId::Parse(rtc::ArrayView<const uint8_t> data, std::string* rsid) {
- if (data.empty() || data[0] == 0) // Valid rsid can't be empty.
- return false;
- const char* str = reinterpret_cast<const char*>(data.data());
- // If there is a \0 character in the middle of the |data|, treat it as end of
- // the string. Well-formed rsid shouldn't contain it.
- rsid->assign(str, strnlen(str, data.size()));
- RTC_DCHECK(!rsid->empty());
- return true;
-}
-
-bool RtpStreamId::Write(uint8_t* data, const std::string& rsid) {
- RTC_DCHECK_GE(rsid.size(), 1);
- RTC_DCHECK_LE(rsid.size(), StreamId::kMaxSize);
- memcpy(data, rsid.data(), rsid.size());
- return true;
-}
-
-// RepairedRtpStreamId.
constexpr RTPExtensionType RepairedRtpStreamId::kId;
constexpr const char* RepairedRtpStreamId::kUri;
-// RtpStreamId and RepairedRtpStreamId use the same format to store rsid.
-bool RepairedRtpStreamId::Parse(rtc::ArrayView<const uint8_t> data,
- StreamId* rsid) {
- return RtpStreamId::Parse(data, rsid);
-}
-
-size_t RepairedRtpStreamId::ValueSize(const StreamId& rsid) {
- return RtpStreamId::ValueSize(rsid);
-}
-
-bool RepairedRtpStreamId::Write(uint8_t* data, const StreamId& rsid) {
- return RtpStreamId::Write(data, rsid);
-}
-
-bool RepairedRtpStreamId::Parse(rtc::ArrayView<const uint8_t> data,
- std::string* rsid) {
- return RtpStreamId::Parse(data, rsid);
-}
-
-size_t RepairedRtpStreamId::ValueSize(const std::string& rsid) {
- return RtpStreamId::ValueSize(rsid);
-}
-
-bool RepairedRtpStreamId::Write(uint8_t* data, const std::string& rsid) {
- return RtpStreamId::Write(data, rsid);
-}
+constexpr RTPExtensionType RtpMid::kId;
+constexpr const char* RtpMid::kUri;
} // namespace webrtc