From 55adc0e1a5f39f7b4bb706c1cbc688e75c9754ae Mon Sep 17 00:00:00 2001 From: zhihuang Date: Fri, 10 Mar 2017 18:33:45 -0800 Subject: [PATCH] Add skeleton webrtc::SessionDescription and webrtc::MediaDescription classes. BUG=webrtc:7311 Review-Url: https://codereview.webrtc.org/2743003004 Cr-Commit-Position: refs/heads/master@{#17181} --- webrtc/api/BUILD.gn | 11 +++++ webrtc/api/ortc/mediadescription.cc | 13 +++++ webrtc/api/ortc/mediadescription.h | 41 ++++++++++++++++ webrtc/api/ortc/mediadescription_unittest.cc | 22 +++++++++ webrtc/api/ortc/sessiondescription.cc | 13 +++++ webrtc/api/ortc/sessiondescription.h | 48 +++++++++++++++++++ .../api/ortc/sessiondescription_unittest.cc | 23 +++++++++ 7 files changed, 171 insertions(+) create mode 100644 webrtc/api/ortc/mediadescription.cc create mode 100644 webrtc/api/ortc/mediadescription.h create mode 100644 webrtc/api/ortc/mediadescription_unittest.cc create mode 100644 webrtc/api/ortc/sessiondescription.cc create mode 100644 webrtc/api/ortc/sessiondescription.h create mode 100644 webrtc/api/ortc/sessiondescription_unittest.cc diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index e42b834c5c..71e5243f90 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -88,12 +88,16 @@ rtc_static_library("libjingle_peerconnection_api") { rtc_source_set("ortc_api") { check_includes = false # TODO(deadbeef): Remove (bugs.webrtc.org/6828) sources = [ + "ortc/mediadescription.cc", + "ortc/mediadescription.h", "ortc/ortcfactoryinterface.h", "ortc/ortcrtpreceiverinterface.h", "ortc/ortcrtpsenderinterface.h", "ortc/packettransportinterface.h", "ortc/rtptransportcontrollerinterface.h", "ortc/rtptransportinterface.h", + "ortc/sessiondescription.cc", + "ortc/sessiondescription.h", "ortc/srtptransportinterface.h", "ortc/udptransportinterface.h", ] @@ -105,6 +109,10 @@ rtc_source_set("ortc_api") { public_deps = [ ":libjingle_peerconnection_api", ] + if (!build_with_chromium && is_clang) { + # Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163). + suppressed_configs += [ "//build/config/clang:find_bad_constructs" ] + } } # TODO(ossu): Remove once downstream projects have updated. @@ -223,6 +231,8 @@ if (rtc_include_tests) { rtc_source_set("rtc_api_unittests") { testonly = true sources = [ + "ortc/mediadescription_unittest.cc", + "ortc/sessiondescription_unittest.cc", "rtcerror_unittest.cc", ] @@ -233,6 +243,7 @@ if (rtc_include_tests) { deps = [ ":libjingle_peerconnection_api", + ":ortc_api", "//webrtc/test:test_support", ] } diff --git a/webrtc/api/ortc/mediadescription.cc b/webrtc/api/ortc/mediadescription.cc new file mode 100644 index 0000000000..9fca55c9e5 --- /dev/null +++ b/webrtc/api/ortc/mediadescription.cc @@ -0,0 +1,13 @@ +/* + * Copyright 2017 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 "webrtc/api/ortc/mediadescription.h" + +namespace webrtc {} diff --git a/webrtc/api/ortc/mediadescription.h b/webrtc/api/ortc/mediadescription.h new file mode 100644 index 0000000000..7e811eca9c --- /dev/null +++ b/webrtc/api/ortc/mediadescription.h @@ -0,0 +1,41 @@ +/* + * Copyright 2017 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. + */ + +#ifndef WEBRTC_API_ORTC_MEDIADESCRIPTION_H_ +#define WEBRTC_API_ORTC_MEDIADESCRIPTION_H_ + +#include +#include + +#include "webrtc/base/optional.h" + +namespace webrtc { + +// A structured representation of a media description within an SDP session +// description. +class MediaDescription { + public: + explicit MediaDescription(std::string mid) : mid_(std::move(mid)) {} + + ~MediaDescription() {} + + // The mid(media stream identification) is used for identifying media streams + // within a session description. + // https://tools.ietf.org/html/rfc5888#section-6 + rtc::Optional mid() const { return mid_; } + void set_mid(std::string mid) { mid_.emplace(std::move(mid)); } + + private: + rtc::Optional mid_; +}; + +} // namespace webrtc + +#endif // WEBRTC_API_ORTC_MEDIADESCRIPTION_H_ diff --git a/webrtc/api/ortc/mediadescription_unittest.cc b/webrtc/api/ortc/mediadescription_unittest.cc new file mode 100644 index 0000000000..a17fde2acc --- /dev/null +++ b/webrtc/api/ortc/mediadescription_unittest.cc @@ -0,0 +1,22 @@ +/* + * Copyright 2017 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 "webrtc/api/ortc/mediadescription.h" +#include "webrtc/test/gtest.h" + +namespace webrtc { + +class MediaDescriptionTest : public testing::Test {}; + +TEST_F(MediaDescriptionTest, CreateMediaDescription) { + MediaDescription m("a"); + EXPECT_EQ("a", m.mid()); +} +} diff --git a/webrtc/api/ortc/sessiondescription.cc b/webrtc/api/ortc/sessiondescription.cc new file mode 100644 index 0000000000..c1d4bbb6f1 --- /dev/null +++ b/webrtc/api/ortc/sessiondescription.cc @@ -0,0 +1,13 @@ +/* + * Copyright 2017 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 "webrtc/api/ortc/sessiondescription.h" + +namespace webrtc {} diff --git a/webrtc/api/ortc/sessiondescription.h b/webrtc/api/ortc/sessiondescription.h new file mode 100644 index 0000000000..18a48e0878 --- /dev/null +++ b/webrtc/api/ortc/sessiondescription.h @@ -0,0 +1,48 @@ +/* + * Copyright 2017 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. + */ + +#ifndef WEBRTC_API_ORTC_SESSIONDESCRIPTION_H_ +#define WEBRTC_API_ORTC_SESSIONDESCRIPTION_H_ + +#include +#include + +namespace webrtc { + +// A structured representation of an SDP session description. +class SessionDescription { + public: + SessionDescription(std::string session_id, std::string session_version) + : session_id_(std::move(session_id)), + session_version_(std::move(session_version)) {} + + // https://tools.ietf.org/html/rfc4566#section-5.2 + // o= + // + // session_id_ is the "sess-id" field. + // session_version_ is the "sess-version" field. + const std::string& session_id() const { return session_id_; } + void set_session_id(std::string session_id) { + session_id_ = std::move(session_id); + } + + const std::string& session_version() const { return session_version_; } + void set_session_version(std::string session_version) { + session_version_ = std::move(session_version); + } + + private: + std::string session_id_; + std::string session_version_; +}; + +} // namespace webrtc + +#endif // WEBRTC_API_ORTC_SESSIONDESCRIPTION_H_ diff --git a/webrtc/api/ortc/sessiondescription_unittest.cc b/webrtc/api/ortc/sessiondescription_unittest.cc new file mode 100644 index 0000000000..c856ea944e --- /dev/null +++ b/webrtc/api/ortc/sessiondescription_unittest.cc @@ -0,0 +1,23 @@ +/* + * Copyright 2017 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 "webrtc/api/ortc/sessiondescription.h" +#include "webrtc/test/gtest.h" + +namespace webrtc { + +class SessionDescriptionTest : public testing::Test {}; + +TEST_F(SessionDescriptionTest, CreateSessionDescription) { + SessionDescription s("a", "0"); + EXPECT_EQ("a", s.session_id()); + EXPECT_EQ("0", s.session_version()); +} +}