diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/libwebrtc/webrtc/api | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/webrtc/api')
195 files changed, 25466 insertions, 0 deletions
diff --git a/third_party/libwebrtc/webrtc/api/BUILD.gn b/third_party/libwebrtc/webrtc/api/BUILD.gn new file mode 100644 index 0000000000..138a61ee2b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/BUILD.gn @@ -0,0 +1,395 @@ +# Copyright (c) 2015 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. + +import("../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +group("api") { + public_deps = [] + + if (!build_with_mozilla) { + public_deps += [ ":libjingle_peerconnection_api" ] + } +} + +rtc_source_set("call_api") { + sources = [ + "call/audio_sink.h", + ] + + deps = [ + # TODO(kjellander): Add remaining dependencies when webrtc:4243 is done. + ":audio_mixer_api", + ":transport_api", + "..:webrtc_common", + "../rtc_base:rtc_base_approved", + "audio_codecs:audio_codecs_api", + ] +} + +rtc_static_library("base_peerconnection_api") { + sources = [ + "rtpparameters.cc", + "rtpparameters.h", + ] +} + +if (!build_with_mozilla) { + rtc_static_library("libjingle_peerconnection_api") { + cflags = [] + sources = [ + "candidate.cc", + "candidate.h", + "cryptoparams.h", + "datachannelinterface.h", + "dtmfsenderinterface.h", + "jsep.h", + "jsepicecandidate.h", + "jsepsessiondescription.h", + "mediaconstraintsinterface.cc", + "mediaconstraintsinterface.h", + "mediastreaminterface.cc", + "mediastreamproxy.h", + "mediastreamtrackproxy.h", + "mediatypes.cc", + "mediatypes.h", + "notifier.h", + "peerconnectionfactoryproxy.h", + "peerconnectionproxy.h", + "proxy.cc", + "proxy.h", + "rtcerror.cc", + "rtcerror.h", + "rtpreceiverinterface.h", + "rtpsenderinterface.h", + "rtptransceiverinterface.h", + "setremotedescriptionobserverinterface.h", + "statstypes.cc", + "statstypes.h", + "turncustomizer.h", + "umametrics.cc", + "umametrics.h", + "videosourceproxy.h", + ] + + 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" ] + } + + public_deps = [ + ":libjingle_api_deprecated_headers", + ":peerconnection_and_implicit_call_api", + ] + + deps = [ + ":base_peerconnection_api", + ":optional", + ":rtc_stats_api", + ":video_frame_api", + "audio_codecs:audio_codecs_api", + + # Basically, don't add stuff here. You might break sensitive downstream + # targets like pnacl. API should not depend on anything outside of this + # file, really. All these should arguably go away in time. + "..:webrtc_common", + "../modules/audio_processing:audio_processing_statistics", + "../rtc_base:rtc_base", + "../rtc_base:rtc_base_approved", + ] + + # This is needed until bugs.webrtc.org/7504 is removed so this target can + # properly depend on ../media:rtc_media_base + # TODO(kjellander): Remove this dependency. + if (is_nacl) { + deps += [ "//native_client_sdk/src/libraries/nacl_io" ] + } + } + + rtc_source_set("peerconnection_and_implicit_call_api") { + # The peerconnectioninterface.h file pulls in call/callfactoryinterface.h + # and the entire call module with it. We need to either get rid of this + # dependency or pull most of call/ into the API. For now, silence the warnings + # this creates since it creates a circular dependency (call very much depends + # on API). See bugs.webrtc.org/7504. + check_includes = false + sources = [ + "peerconnectioninterface.h", + ] + } + + rtc_source_set("libjingle_api_deprecated_headers") { + # We need to include headers from undeclared targets here, since they cause + # circular dependencies. These deprecated headers are going away anyway. + # See http://bugs.webrtc.org/5883. + check_includes = false + sources = [ + "datachannel.h", + "mediastream.h", + "mediastreamtrack.h", + "rtpsender.h", + "streamcollection.h", + "videotracksource.h", + "webrtcsdp.h", + ] + } + + rtc_source_set("libjingle_logging_api") { + sources = [ + "rtceventlogoutput.h", + ] + } + + rtc_source_set("ortc_api") { + 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", + ] + + # For mediastreaminterface.h, etc. + # TODO(deadbeef): Create a separate target for the common things ORTC and + # PeerConnection code shares, so that ortc_api can depend on that instead of + # libjingle_peerconnection_api. + deps = [ + ":libjingle_peerconnection_api", + ":optional", + "..:webrtc_common", + "../rtc_base:rtc_base", + ] + 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. + rtc_source_set("libjingle_peerconnection") { + public_deps = [] + + if (!build_with_mozilla) { + public_deps += [ "../pc:libjingle_peerconnection" ] + } + } +} + +rtc_source_set("rtc_stats_api") { + cflags = [] + sources = [ + "stats/rtcstats.h", + "stats/rtcstats_objects.h", + "stats/rtcstatscollectorcallback.h", + "stats/rtcstatsreport.h", + ] + + deps = [ + "../rtc_base:rtc_base_approved", + ] +} + +rtc_source_set("audio_mixer_api") { + sources = [ + "audio/audio_mixer.h", + ] + + deps = [ + "../modules:module_api", + "../rtc_base:rtc_base_approved", + ] +} + +rtc_source_set("transport_api") { + sources = [ + "call/transport.h", + ] +} + +rtc_source_set("video_frame_api") { + sources = [ + "video/video_content_type.cc", + "video/video_content_type.h", + "video/video_frame.cc", + "video/video_frame.h", + "video/video_frame_buffer.cc", + "video/video_frame_buffer.h", + "video/video_rotation.h", + "video/video_timing.cc", + "video/video_timing.h", + ] + + deps = [ + "../rtc_base:rtc_base_approved", + ] + + # TODO(nisse): This logic is duplicated in multiple places. + # Define in a single place. + if (rtc_build_libyuv) { + deps += [ "$rtc_libyuv_dir" ] + public_deps = [ + "$rtc_libyuv_dir", + ] + } else { + # Need to add a directory normally exported by libyuv. + include_dirs = [ "$rtc_libyuv_dir/include" ] + } +} + +rtc_source_set("video_frame_api_i420") { + sources = [ + "video/i420_buffer.cc", + "video/i420_buffer.h", + ] + deps = [ + ":video_frame_api", + "../rtc_base:rtc_base_approved", + "../system_wrappers", + ] + if (build_with_mozilla) { + include_dirs = [ "/media/libyuv/libyuv/include" ] + } +} + +rtc_source_set("array_view") { + sources = [ + "array_view.h", + ] + deps = [ + "../rtc_base:rtc_base_approved", + ] +} + +rtc_source_set("optional") { + sources = [ + "optional.cc", + "optional.h", + ] + deps = [ + ":array_view", + "../rtc_base:rtc_base_approved", + ] +} + +rtc_source_set("refcountedbase") { + sources = [ + "refcountedbase.h", + ] + deps = [ + "../rtc_base:rtc_base_approved", + ] +} + +if (rtc_include_tests) { + rtc_source_set("libjingle_peerconnection_test_api") { + testonly = true + sources = [ + "test/fakeconstraints.h", + ] + + public_deps = [ + ":libjingle_peerconnection_api", + ] + + deps = [ + "../rtc_base:rtc_base_approved", + ] + } +} + +if (rtc_include_tests) { + rtc_source_set("mock_audio_mixer") { + testonly = true + sources = [ + "test/mock_audio_mixer.h", + ] + + public_deps = [ + ":audio_mixer_api", + ] + + deps = [ + "../test:test_support", + "//testing/gmock", + ] + } + + rtc_source_set("mock_video_codec_factory") { + testonly = true + sources = [ + "test/mock_video_decoder_factory.h", + "test/mock_video_encoder_factory.h", + ] + + public_deps = [ + "../api/video_codecs:video_codecs_api", + ] + + deps = [ + "../test:test_support", + "//testing/gmock", + ] + } + + rtc_source_set("fakemetricsobserver") { + testonly = true + sources = [ + "fakemetricsobserver.cc", + "fakemetricsobserver.h", + ] + deps = [ + ":libjingle_peerconnection_api", + "../api:peerconnection_and_implicit_call_api", + "../media:rtc_media_base", + "../rtc_base:rtc_base_approved", + ] + 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" ] + } + } + + rtc_source_set("rtc_api_unittests") { + testonly = true + + sources = [ + "array_view_unittest.cc", + "optional_unittest.cc", + "ortc/mediadescription_unittest.cc", + "ortc/sessiondescription_unittest.cc", + "rtcerror_unittest.cc", + "rtpparameters_unittest.cc", + ] + + 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" ] + } + + deps = [ + ":array_view", + ":libjingle_peerconnection_api", + ":libjingle_peerconnection_test_api", + ":optional", + ":ortc_api", + "../rtc_base:rtc_base_approved", + "../rtc_base:rtc_base_tests_utils", + "../test:test_support", + ] + } +} diff --git a/third_party/libwebrtc/webrtc/api/DEPS b/third_party/libwebrtc/webrtc/api/DEPS new file mode 100644 index 0000000000..a537633981 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/DEPS @@ -0,0 +1,46 @@ +include_rules = [ + "+third_party/libyuv", + "+common_video", + "+media", + "+p2p", + "+pc", +] + +specific_include_rules = { + "peerconnection_jni\.cc": [ + "+voice_engine", + ], + + # TODO(ossu): Remove this exception when {builtin_,}audio_encoder_factory.h + # has moved to api/. + "peerconnectioninterface\.h": [ + "+call/callfactoryinterface.h", + "+logging/rtc_event_log/rtc_event_log_factory_interface.h", + "+modules/audio_coding/codecs/audio_encoder_factory.h", + "+modules/audio_coding/codecs/builtin_audio_encoder_factory.h", + ], + + # Needed because AudioEncoderOpus is in the wrong place for + # backwards compatibilty reasons. See + # https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 + "audio_encoder_opus\.h": [ + "+modules/audio_coding/codecs/opus/audio_encoder_opus.h", + ], + + # We allow .cc files in webrtc/api/ to #include a bunch of stuff + # that's off-limits for the .h files. That's because .h files leak + # their #includes to whoever's #including them, but .cc files do not + # since no one #includes them. + ".*\.cc": [ + "+modules/audio_coding", + ], + + ".*i420_buffer\.h": [ + "+system_wrappers/include/aligned_malloc.h", + ], + + # Needed to use the APM statistics. + "mediastreaminterface.h": [ + "+modules/audio_processing/include/audio_processing_statistics.h", + ], +} diff --git a/third_party/libwebrtc/webrtc/api/OWNERS b/third_party/libwebrtc/webrtc/api/OWNERS new file mode 100644 index 0000000000..1c30e33a68 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/OWNERS @@ -0,0 +1,14 @@ +pthatcher@webrtc.org +glaznev@webrtc.org +juberti@webrtc.org +perkj@webrtc.org +solenberg@webrtc.org +tkchin@webrtc.org +tommi@webrtc.org +deadbeef@webrtc.org +kwiberg@webrtc.org + +per-file peerconnection*=hbos@webrtc.org + +per-file *.gn=phoglund@webrtc.org +per-file *.gni=phoglund@webrtc.org diff --git a/third_party/libwebrtc/webrtc/api/array_view.h b/third_party/libwebrtc/webrtc/api/array_view.h new file mode 100644 index 0000000000..d951d0f02d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/array_view.h @@ -0,0 +1,263 @@ +/* + * Copyright 2015 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 API_ARRAY_VIEW_H_ +#define API_ARRAY_VIEW_H_ + +#include <algorithm> +#include <type_traits> + +#include "rtc_base/checks.h" +#include "rtc_base/type_traits.h" + +namespace rtc { + +// tl;dr: rtc::ArrayView is the same thing as gsl::span from the Guideline +// Support Library. +// +// Many functions read from or write to arrays. The obvious way to do this is +// to use two arguments, a pointer to the first element and an element count: +// +// bool Contains17(const int* arr, size_t size) { +// for (size_t i = 0; i < size; ++i) { +// if (arr[i] == 17) +// return true; +// } +// return false; +// } +// +// This is flexible, since it doesn't matter how the array is stored (C array, +// std::vector, rtc::Buffer, ...), but it's error-prone because the caller has +// to correctly specify the array length: +// +// Contains17(arr, arraysize(arr)); // C array +// Contains17(arr.data(), arr.size()); // std::vector +// Contains17(arr, size); // pointer + size +// ... +// +// It's also kind of messy to have two separate arguments for what is +// conceptually a single thing. +// +// Enter rtc::ArrayView<T>. It contains a T pointer (to an array it doesn't +// own) and a count, and supports the basic things you'd expect, such as +// indexing and iteration. It allows us to write our function like this: +// +// bool Contains17(rtc::ArrayView<const int> arr) { +// for (auto e : arr) { +// if (e == 17) +// return true; +// } +// return false; +// } +// +// And even better, because a bunch of things will implicitly convert to +// ArrayView, we can call it like this: +// +// Contains17(arr); // C array +// Contains17(arr); // std::vector +// Contains17(rtc::ArrayView<int>(arr, size)); // pointer + size +// Contains17(nullptr); // nullptr -> empty ArrayView +// ... +// +// ArrayView<T> stores both a pointer and a size, but you may also use +// ArrayView<T, N>, which has a size that's fixed at compile time (which means +// it only has to store the pointer). +// +// One important point is that ArrayView<T> and ArrayView<const T> are +// different types, which allow and don't allow mutation of the array elements, +// respectively. The implicit conversions work just like you'd hope, so that +// e.g. vector<int> will convert to either ArrayView<int> or ArrayView<const +// int>, but const vector<int> will convert only to ArrayView<const int>. +// (ArrayView itself can be the source type in such conversions, so +// ArrayView<int> will convert to ArrayView<const int>.) +// +// Note: ArrayView is tiny (just a pointer and a count if variable-sized, just +// a pointer if fix-sized) and trivially copyable, so it's probably cheaper to +// pass it by value than by const reference. + +namespace impl { + +// Magic constant for indicating that the size of an ArrayView is variable +// instead of fixed. +enum : std::ptrdiff_t { kArrayViewVarSize = -4711 }; + +// Base class for ArrayViews of fixed nonzero size. +template <typename T, std::ptrdiff_t Size> +class ArrayViewBase { + static_assert(Size > 0, "ArrayView size must be variable or non-negative"); + + public: + ArrayViewBase(T* data, size_t size) : data_(data) {} + + static constexpr size_t size() { return Size; } + static constexpr bool empty() { return false; } + T* data() const { return data_; } + + protected: + static constexpr bool fixed_size() { return true; } + + private: + T* data_; +}; + +// Specialized base class for ArrayViews of fixed zero size. +template <typename T> +class ArrayViewBase<T, 0> { + public: + explicit ArrayViewBase(T* data, size_t size) {} + + static constexpr size_t size() { return 0; } + static constexpr bool empty() { return true; } + T* data() const { return nullptr; } + + protected: + static constexpr bool fixed_size() { return true; } +}; + +// Specialized base class for ArrayViews of variable size. +template <typename T> +class ArrayViewBase<T, impl::kArrayViewVarSize> { + public: + ArrayViewBase(T* data, size_t size) + : data_(size == 0 ? nullptr : data), size_(size) {} + + size_t size() const { return size_; } + bool empty() const { return size_ == 0; } + T* data() const { return data_; } + + protected: + static constexpr bool fixed_size() { return false; } + + private: + T* data_; + size_t size_; +}; + +} // namespace impl + +template <typename T, std::ptrdiff_t Size = impl::kArrayViewVarSize> +class ArrayView final : public impl::ArrayViewBase<T, Size> { + public: + using value_type = T; + using const_iterator = const T*; + + // Construct an ArrayView from a pointer and a length. + template <typename U> + ArrayView(U* data, size_t size) + : impl::ArrayViewBase<T, Size>::ArrayViewBase(data, size) { + RTC_DCHECK_EQ(size == 0 ? nullptr : data, this->data()); + RTC_DCHECK_EQ(size, this->size()); + RTC_DCHECK_EQ(!this->data(), + this->size() == 0); // data is null iff size == 0. + } + + // Construct an empty ArrayView. Note that fixed-size ArrayViews of size > 0 + // cannot be empty. + ArrayView() : ArrayView(nullptr, 0) {} + ArrayView(std::nullptr_t) // NOLINT + : ArrayView() {} + ArrayView(std::nullptr_t, size_t size) + : ArrayView(static_cast<T*>(nullptr), size) { + static_assert(Size == 0 || Size == impl::kArrayViewVarSize, ""); + RTC_DCHECK_EQ(0, size); + } + + // Construct an ArrayView from an array. + template <typename U, size_t N> + ArrayView(U (&array)[N]) // NOLINT + : ArrayView(array, N) { + static_assert(Size == N || Size == impl::kArrayViewVarSize, + "Array size must match ArrayView size"); + } + + // (Only if size is fixed.) Construct an ArrayView from any type U that has a + // static constexpr size() method whose return value is equal to Size, and a + // data() method whose return value converts implicitly to T*. In particular, + // this means we allow conversion from ArrayView<T, N> to ArrayView<const T, + // N>, but not the other way around. We also don't allow conversion from + // ArrayView<T> to ArrayView<T, N>, or from ArrayView<T, M> to ArrayView<T, + // N> when M != N. + template < + typename U, + typename std::enable_if<Size != impl::kArrayViewVarSize && + HasDataAndSize<U, T>::value>::type* = nullptr> + ArrayView(U& u) // NOLINT + : ArrayView(u.data(), u.size()) { + static_assert(U::size() == Size, "Sizes must match exactly"); + } + + // (Only if size is variable.) Construct an ArrayView from any type U that + // has a size() method whose return value converts implicitly to size_t, and + // a data() method whose return value converts implicitly to T*. In + // particular, this means we allow conversion from ArrayView<T> to + // ArrayView<const T>, but not the other way around. Other allowed + // conversions include + // ArrayView<T, N> to ArrayView<T> or ArrayView<const T>, + // std::vector<T> to ArrayView<T> or ArrayView<const T>, + // const std::vector<T> to ArrayView<const T>, + // rtc::Buffer to ArrayView<uint8_t> or ArrayView<const uint8_t>, and + // const rtc::Buffer to ArrayView<const uint8_t>. + template < + typename U, + typename std::enable_if<Size == impl::kArrayViewVarSize && + HasDataAndSize<U, T>::value>::type* = nullptr> + ArrayView(U& u) // NOLINT + : ArrayView(u.data(), u.size()) {} + + // Indexing and iteration. These allow mutation even if the ArrayView is + // const, because the ArrayView doesn't own the array. (To prevent mutation, + // use a const element type.) + T& operator[](size_t idx) const { + RTC_DCHECK_LT(idx, this->size()); + RTC_DCHECK(this->data()); + return this->data()[idx]; + } + T* begin() const { return this->data(); } + T* end() const { return this->data() + this->size(); } + const T* cbegin() const { return this->data(); } + const T* cend() const { return this->data() + this->size(); } + + ArrayView<T> subview(size_t offset, size_t size) const { + return offset < this->size() + ? ArrayView<T>(this->data() + offset, + std::min(size, this->size() - offset)) + : ArrayView<T>(); + } + ArrayView<T> subview(size_t offset) const { + return subview(offset, this->size()); + } +}; + +// Comparing two ArrayViews compares their (pointer,size) pairs; it does *not* +// dereference the pointers. +template <typename T, std::ptrdiff_t Size1, std::ptrdiff_t Size2> +bool operator==(const ArrayView<T, Size1>& a, const ArrayView<T, Size2>& b) { + return a.data() == b.data() && a.size() == b.size(); +} +template <typename T, std::ptrdiff_t Size1, std::ptrdiff_t Size2> +bool operator!=(const ArrayView<T, Size1>& a, const ArrayView<T, Size2>& b) { + return !(a == b); +} + +// Variable-size ArrayViews are the size of two pointers; fixed-size ArrayViews +// are the size of one pointer. (And as a special case, fixed-size ArrayViews +// of size 0 require no storage.) +static_assert(sizeof(ArrayView<int>) == 2 * sizeof(int*), ""); +static_assert(sizeof(ArrayView<int, 17>) == sizeof(int*), ""); +static_assert(std::is_empty<ArrayView<int, 0>>::value, ""); + +template <typename T> +inline ArrayView<T> MakeArrayView(T* data, size_t size) { + return ArrayView<T>(data, size); +} + +} // namespace rtc + +#endif // API_ARRAY_VIEW_H_ diff --git a/third_party/libwebrtc/webrtc/api/array_view_gn/moz.build b/third_party/libwebrtc/webrtc/api/array_view_gn/moz.build new file mode 100644 index 0000000000..305d525d64 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/array_view_gn/moz.build @@ -0,0 +1,179 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("array_view_gn") diff --git a/third_party/libwebrtc/webrtc/api/array_view_unittest.cc b/third_party/libwebrtc/webrtc/api/array_view_unittest.cc new file mode 100644 index 0000000000..48dff2c266 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/array_view_unittest.cc @@ -0,0 +1,412 @@ +/* + * Copyright 2015 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 <algorithm> +#include <string> +#include <utility> +#include <vector> + +#include "api/array_view.h" +#include "rtc_base/buffer.h" +#include "rtc_base/checks.h" +#include "rtc_base/gunit.h" +#include "test/gmock.h" + +namespace rtc { + +namespace { + +using ::testing::ElementsAre; +using ::testing::IsEmpty; + +template <typename T> +void Call(ArrayView<T>) {} + +} // namespace + +TEST(ArrayViewTest, TestConstructFromPtrAndArray) { + char arr[] = "Arrr!"; + const char carr[] = "Carrr!"; + Call<const char>(arr); + Call<const char>(carr); + Call<char>(arr); + // Call<char>(carr); // Compile error, because can't drop const. + // Call<int>(arr); // Compile error, because incompatible types. + ArrayView<int*> x; + EXPECT_EQ(0u, x.size()); + EXPECT_EQ(nullptr, x.data()); + ArrayView<char> y = arr; + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView<char, 6> yf = arr; + static_assert(yf.size() == 6, ""); + EXPECT_EQ(arr, yf.data()); + ArrayView<const char> z(arr + 1, 3); + EXPECT_EQ(3u, z.size()); + EXPECT_EQ(arr + 1, z.data()); + ArrayView<const char, 3> zf(arr + 1, 3); + static_assert(zf.size() == 3, ""); + EXPECT_EQ(arr + 1, zf.data()); + ArrayView<const char> w(arr, 2); + EXPECT_EQ(2u, w.size()); + EXPECT_EQ(arr, w.data()); + ArrayView<const char, 2> wf(arr, 2); + static_assert(wf.size() == 2, ""); + EXPECT_EQ(arr, wf.data()); + ArrayView<char> q(arr, 0); + EXPECT_EQ(0u, q.size()); + EXPECT_EQ(nullptr, q.data()); + ArrayView<char, 0> qf(arr, 0); + static_assert(qf.size() == 0, ""); + EXPECT_EQ(nullptr, qf.data()); +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + // DCHECK error (nullptr with nonzero size). + EXPECT_DEATH(ArrayView<int>(static_cast<int*>(nullptr), 5), ""); +#endif + // These are compile errors, because incompatible types. + // ArrayView<int> m = arr; + // ArrayView<float> n(arr + 2, 2); +} + +TEST(ArrayViewTest, TestCopyConstructorVariable) { + char arr[] = "Arrr!"; + ArrayView<char> x = arr; + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView<char> y = x; // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView<const char> z = x; // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView<const char> w = z; // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView<char> v = z; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestCopyConstructorFixed) { + char arr[] = "Arrr!"; + ArrayView<char, 6> x = arr; + static_assert(x.size() == 6, ""); + EXPECT_EQ(arr, x.data()); + + // Copy fixed -> fixed. + ArrayView<char, 6> y = x; // Copy non-const -> non-const. + static_assert(y.size() == 6, ""); + EXPECT_EQ(arr, y.data()); + ArrayView<const char, 6> z = x; // Copy non-const -> const. + static_assert(z.size() == 6, ""); + EXPECT_EQ(arr, z.data()); + ArrayView<const char, 6> w = z; // Copy const -> const. + static_assert(w.size() == 6, ""); + EXPECT_EQ(arr, w.data()); + // ArrayView<char, 6> v = z; // Compile error, because can't drop const. + + // Copy fixed -> variable. + ArrayView<char> yv = x; // Copy non-const -> non-const. + EXPECT_EQ(6u, yv.size()); + EXPECT_EQ(arr, yv.data()); + ArrayView<const char> zv = x; // Copy non-const -> const. + EXPECT_EQ(6u, zv.size()); + EXPECT_EQ(arr, zv.data()); + ArrayView<const char> wv = z; // Copy const -> const. + EXPECT_EQ(6u, wv.size()); + EXPECT_EQ(arr, wv.data()); + // ArrayView<char> vv = z; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestCopyAssignmentVariable) { + char arr[] = "Arrr!"; + ArrayView<char> x(arr); + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView<char> y; + y = x; // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView<const char> z; + z = x; // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView<const char> w; + w = z; // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView<char> v; + // v = z; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestCopyAssignmentFixed) { + char arr[] = "Arrr!"; + char init[] = "Init!"; + ArrayView<char, 6> x(arr); + EXPECT_EQ(arr, x.data()); + + // Copy fixed -> fixed. + ArrayView<char, 6> y(init); + y = x; // Copy non-const -> non-const. + EXPECT_EQ(arr, y.data()); + ArrayView<const char, 6> z(init); + z = x; // Copy non-const -> const. + EXPECT_EQ(arr, z.data()); + ArrayView<const char, 6> w(init); + w = z; // Copy const -> const. + EXPECT_EQ(arr, w.data()); + // ArrayView<char, 6> v(init); + // v = z; // Compile error, because can't drop const. + + // Copy fixed -> variable. + ArrayView<char> yv; + yv = x; // Copy non-const -> non-const. + EXPECT_EQ(6u, yv.size()); + EXPECT_EQ(arr, yv.data()); + ArrayView<const char> zv; + zv = x; // Copy non-const -> const. + EXPECT_EQ(6u, zv.size()); + EXPECT_EQ(arr, zv.data()); + ArrayView<const char> wv; + wv = z; // Copy const -> const. + EXPECT_EQ(6u, wv.size()); + EXPECT_EQ(arr, wv.data()); + // ArrayView<char> v; + // v = z; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestStdVector) { + std::vector<int> v; + v.push_back(3); + v.push_back(11); + Call<const int>(v); + Call<int>(v); + // Call<unsigned int>(v); // Compile error, because incompatible types. + ArrayView<int> x = v; + EXPECT_EQ(2u, x.size()); + EXPECT_EQ(v.data(), x.data()); + ArrayView<const int> y; + y = v; + EXPECT_EQ(2u, y.size()); + EXPECT_EQ(v.data(), y.data()); + // ArrayView<double> d = v; // Compile error, because incompatible types. + const std::vector<int> cv; + Call<const int>(cv); + // Call<int>(cv); // Compile error, because can't drop const. + ArrayView<const int> z = cv; + EXPECT_EQ(0u, z.size()); + EXPECT_EQ(nullptr, z.data()); + // ArrayView<int> w = cv; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestRtcBuffer) { + rtc::Buffer b = "so buffer"; + Call<const uint8_t>(b); + Call<uint8_t>(b); + // Call<int8_t>(b); // Compile error, because incompatible types. + ArrayView<uint8_t> x = b; + EXPECT_EQ(10u, x.size()); + EXPECT_EQ(b.data(), x.data()); + ArrayView<const uint8_t> y; + y = b; + EXPECT_EQ(10u, y.size()); + EXPECT_EQ(b.data(), y.data()); + // ArrayView<char> d = b; // Compile error, because incompatible types. + const rtc::Buffer cb = "very const"; + Call<const uint8_t>(cb); + // Call<uint8_t>(cb); // Compile error, because can't drop const. + ArrayView<const uint8_t> z = cb; + EXPECT_EQ(11u, z.size()); + EXPECT_EQ(cb.data(), z.data()); + // ArrayView<uint8_t> w = cb; // Compile error, because can't drop const. +} + +TEST(ArrayViewTest, TestSwapVariable) { + const char arr[] = "Arrr!"; + const char aye[] = "Aye, Cap'n!"; + ArrayView<const char> x(arr); + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView<const char> y(aye); + EXPECT_EQ(12u, y.size()); + EXPECT_EQ(aye, y.data()); + using std::swap; + swap(x, y); + EXPECT_EQ(12u, x.size()); + EXPECT_EQ(aye, x.data()); + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + // ArrayView<char> z; + // swap(x, z); // Compile error, because can't drop const. +} + +TEST(FixArrayViewTest, TestSwapFixed) { + const char arr[] = "Arr!"; + char aye[] = "Aye!"; + ArrayView<const char, 5> x(arr); + EXPECT_EQ(arr, x.data()); + ArrayView<const char, 5> y(aye); + EXPECT_EQ(aye, y.data()); + using std::swap; + swap(x, y); + EXPECT_EQ(aye, x.data()); + EXPECT_EQ(arr, y.data()); + // ArrayView<char, 5> z(aye); + // swap(x, z); // Compile error, because can't drop const. + // ArrayView<const char, 4> w(aye, 4); + // swap(x, w); // Compile error, because different sizes. +} + +TEST(ArrayViewTest, TestIndexing) { + char arr[] = "abcdefg"; + ArrayView<char> x(arr); + const ArrayView<char> y(arr); + ArrayView<const char, 8> z(arr); + EXPECT_EQ(8u, x.size()); + EXPECT_EQ(8u, y.size()); + EXPECT_EQ(8u, z.size()); + EXPECT_EQ('b', x[1]); + EXPECT_EQ('c', y[2]); + EXPECT_EQ('d', z[3]); + x[3] = 'X'; + y[2] = 'Y'; + // z[1] = 'Z'; // Compile error, because z's element type is const char. + EXPECT_EQ('b', x[1]); + EXPECT_EQ('Y', y[2]); + EXPECT_EQ('X', z[3]); +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + EXPECT_DEATH(z[8], ""); // DCHECK error (index out of bounds). +#endif +} + +TEST(ArrayViewTest, TestIterationEmpty) { + // Variable-size. + ArrayView<std::vector<std::vector<std::vector<std::string>>>> av; + EXPECT_EQ(av.begin(), av.end()); + EXPECT_EQ(av.cbegin(), av.cend()); + for (auto& e : av) { + EXPECT_TRUE(false); + EXPECT_EQ(42u, e.size()); // Dummy use of e to prevent unused var warning. + } + + // Fixed-size. + ArrayView<std::vector<std::vector<std::vector<std::string>>>, 0> af; + EXPECT_EQ(af.begin(), af.end()); + EXPECT_EQ(af.cbegin(), af.cend()); + for (auto& e : af) { + EXPECT_TRUE(false); + EXPECT_EQ(42u, e.size()); // Dummy use of e to prevent unused var warning. + } +} + +TEST(ArrayViewTest, TestIterationVariable) { + char arr[] = "Arrr!"; + ArrayView<char> av(arr); + EXPECT_EQ('A', *av.begin()); + EXPECT_EQ('A', *av.cbegin()); + EXPECT_EQ('\0', *(av.end() - 1)); + EXPECT_EQ('\0', *(av.cend() - 1)); + char i = 0; + for (auto& e : av) { + EXPECT_EQ(arr + i, &e); + e = 's' + i; + ++i; + } + i = 0; + for (auto& e : ArrayView<const char>(av)) { + EXPECT_EQ(arr + i, &e); + // e = 'q' + i; // Compile error, because e is a const char&. + ++i; + } +} + +TEST(ArrayViewTest, TestIterationFixed) { + char arr[] = "Arrr!"; + ArrayView<char, 6> av(arr); + EXPECT_EQ('A', *av.begin()); + EXPECT_EQ('A', *av.cbegin()); + EXPECT_EQ('\0', *(av.end() - 1)); + EXPECT_EQ('\0', *(av.cend() - 1)); + char i = 0; + for (auto& e : av) { + EXPECT_EQ(arr + i, &e); + e = 's' + i; + ++i; + } + i = 0; + for (auto& e : ArrayView<const char, 6>(av)) { + EXPECT_EQ(arr + i, &e); + // e = 'q' + i; // Compile error, because e is a const char&. + ++i; + } +} + +TEST(ArrayViewTest, TestEmpty) { + EXPECT_TRUE(ArrayView<int>().empty()); + const int a[] = {1, 2, 3}; + EXPECT_FALSE(ArrayView<const int>(a).empty()); + + static_assert(ArrayView<int, 0>::empty(), ""); + static_assert(!ArrayView<int, 3>::empty(), ""); +} + +TEST(ArrayViewTest, TestCompare) { + int a[] = {1, 2, 3}; + int b[] = {1, 2, 3}; + + EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); + EXPECT_EQ((ArrayView<int, 3>(a)), (ArrayView<int, 3>(a))); + EXPECT_EQ(ArrayView<int>(a), (ArrayView<int, 3>(a))); + EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); + EXPECT_EQ(ArrayView<int>(), ArrayView<int>(a, 0)); + EXPECT_EQ(ArrayView<int>(a, 0), ArrayView<int>(b, 0)); + EXPECT_EQ((ArrayView<int, 0>(a, 0)), ArrayView<int>()); + + EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); + EXPECT_NE((ArrayView<int, 3>(a)), (ArrayView<int, 3>(b))); + EXPECT_NE((ArrayView<int, 3>(a)), ArrayView<int>(b)); + EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); + EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); + EXPECT_NE((ArrayView<int, 3>(a)), (ArrayView<int, 2>(a, 2))); +} + +TEST(ArrayViewTest, TestSubViewVariable) { + int a[] = {1, 2, 3}; + ArrayView<int> av(a); + + EXPECT_EQ(av.subview(0), av); + + EXPECT_THAT(av.subview(1), ElementsAre(2, 3)); + EXPECT_THAT(av.subview(2), ElementsAre(3)); + EXPECT_THAT(av.subview(3), IsEmpty()); + EXPECT_THAT(av.subview(4), IsEmpty()); + + EXPECT_THAT(av.subview(1, 0), IsEmpty()); + EXPECT_THAT(av.subview(1, 1), ElementsAre(2)); + EXPECT_THAT(av.subview(1, 2), ElementsAre(2, 3)); + EXPECT_THAT(av.subview(1, 3), ElementsAre(2, 3)); +} + +TEST(ArrayViewTest, TestSubViewFixed) { + int a[] = {1, 2, 3}; + ArrayView<int, 3> av(a); + + EXPECT_EQ(av.subview(0), av); + + EXPECT_THAT(av.subview(1), ElementsAre(2, 3)); + EXPECT_THAT(av.subview(2), ElementsAre(3)); + EXPECT_THAT(av.subview(3), IsEmpty()); + EXPECT_THAT(av.subview(4), IsEmpty()); + + EXPECT_THAT(av.subview(1, 0), IsEmpty()); + EXPECT_THAT(av.subview(1, 1), ElementsAre(2)); + EXPECT_THAT(av.subview(1, 2), ElementsAre(2, 3)); + EXPECT_THAT(av.subview(1, 3), ElementsAre(2, 3)); +} + +} // namespace rtc diff --git a/third_party/libwebrtc/webrtc/api/audio/audio_mixer.h b/third_party/libwebrtc/webrtc/api/audio/audio_mixer.h new file mode 100644 index 0000000000..63b8b8ff9b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio/audio_mixer.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2011 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 API_AUDIO_AUDIO_MIXER_H_ +#define API_AUDIO_AUDIO_MIXER_H_ + +#include <memory> + +#include "modules/include/module_common_types.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// WORK IN PROGRESS +// This class is under development and is not yet intended for for use outside +// of WebRtc/Libjingle. +class AudioMixer : public rtc::RefCountInterface { + public: + // A callback class that all mixer participants must inherit from/implement. + class Source { + public: + enum class AudioFrameInfo { + kNormal, // The samples in audio_frame are valid and should be used. + kMuted, // The samples in audio_frame should not be used, but + // should be implicitly interpreted as zero. Other + // fields in audio_frame may be read and should + // contain meaningful values. + kError, // The audio_frame will not be used. + }; + + // Overwrites |audio_frame|. The data_ field is overwritten with + // 10 ms of new audio (either 1 or 2 interleaved channels) at + // |sample_rate_hz|. All fields in |audio_frame| must be updated. + virtual AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz, + AudioFrame* audio_frame) = 0; + + // A way for a mixer implementation to distinguish participants. + virtual int Ssrc() const = 0; + + // A way for this source to say that GetAudioFrameWithInfo called + // with this sample rate or higher will not cause quality loss. + virtual int PreferredSampleRate() const = 0; + + virtual ~Source() {} + }; + + // Returns true if adding was successful. A source is never added + // twice. Addition and removal can happen on different threads. + virtual bool AddSource(Source* audio_source) = 0; + + // Removal is never attempted if a source has not been successfully + // added to the mixer. + virtual void RemoveSource(Source* audio_source) = 0; + + // Performs mixing by asking registered audio sources for audio. The + // mixed result is placed in the provided AudioFrame. This method + // will only be called from a single thread. The channels argument + // specifies the number of channels of the mix result. The mixer + // should mix at a rate that doesn't cause quality loss of the + // sources' audio. The mixing rate is one of the rates listed in + // AudioProcessing::NativeRate. All fields in + // |audio_frame_for_mixing| must be updated. + virtual void Mix(size_t number_of_channels, + AudioFrame* audio_frame_for_mixing) = 0; + + protected: + // Since the mixer is reference counted, the destructor may be + // called from any thread. + ~AudioMixer() override {} +}; +} // namespace webrtc + +#endif // API_AUDIO_AUDIO_MIXER_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/BUILD.gn new file mode 100644 index 0000000000..8ea533b034 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/BUILD.gn @@ -0,0 +1,90 @@ +# Copyright (c) 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. + +import("../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_source_set("audio_codecs_api") { + sources = [ + "audio_decoder.cc", + "audio_decoder.h", + "audio_decoder_factory.h", + "audio_decoder_factory_template.h", + "audio_encoder.cc", + "audio_encoder.h", + "audio_encoder_factory.h", + "audio_encoder_factory_template.h", + "audio_format.cc", + "audio_format.h", + ] + deps = [ + "..:array_view", + "..:optional", + "../..:webrtc_common", + "../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("builtin_audio_decoder_factory") { + sources = [ + "builtin_audio_decoder_factory.cc", + "builtin_audio_decoder_factory.h", + ] + deps = [ + ":audio_codecs_api", + "../../rtc_base:rtc_base_approved", + "L16:audio_decoder_L16", + "g711:audio_decoder_g711", + "g722:audio_decoder_g722", + "isac:audio_decoder_isac", + ] + defines = [] + if (rtc_include_ilbc) { + deps += [ "ilbc:audio_decoder_ilbc" ] + defines += [ "WEBRTC_USE_BUILTIN_ILBC=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_ILBC=0" ] + } + if (rtc_include_opus) { + deps += [ "opus:audio_decoder_opus" ] + defines += [ "WEBRTC_USE_BUILTIN_OPUS=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_OPUS=0" ] + } +} + +rtc_static_library("builtin_audio_encoder_factory") { + sources = [ + "builtin_audio_encoder_factory.cc", + "builtin_audio_encoder_factory.h", + ] + deps = [ + ":audio_codecs_api", + "../../rtc_base:rtc_base_approved", + "L16:audio_encoder_L16", + "g711:audio_encoder_g711", + "g722:audio_encoder_g722", + "isac:audio_encoder_isac", + ] + defines = [] + if (rtc_include_ilbc) { + deps += [ "ilbc:audio_encoder_ilbc" ] + defines += [ "WEBRTC_USE_BUILTIN_ILBC=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_ILBC=0" ] + } + if (rtc_include_opus) { + deps += [ "opus:audio_encoder_opus" ] + defines += [ "WEBRTC_USE_BUILTIN_OPUS=1" ] + } else { + defines += [ "WEBRTC_USE_BUILTIN_OPUS=0" ] + } +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/BUILD.gn new file mode 100644 index 0000000000..8f06a8f332 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_static_library("audio_encoder_L16") { + sources = [ + "audio_encoder_L16.cc", + "audio_encoder_L16.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:pcm16b", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_L16") { + sources = [ + "audio_decoder_L16.cc", + "audio_decoder_L16.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:pcm16b", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.cc new file mode 100644 index 0000000000..dd14e601f4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.cc @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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 "api/audio_codecs/L16/audio_decoder_L16.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h" +#include "modules/audio_coding/codecs/pcm16b/pcm16b_common.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderL16::Config> AudioDecoderL16::SdpToConfig( + const SdpAudioFormat& format) { + Config config; + config.sample_rate_hz = format.clockrate_hz; + config.num_channels = rtc::checked_cast<int>(format.num_channels); + return STR_CASE_CMP(format.name.c_str(), "L16") == 0 && config.IsOk() + ? rtc::Optional<Config>(config) + : rtc::nullopt; +} + +void AudioDecoderL16::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + Pcm16BAppendSupportedCodecSpecs(specs); +} + +std::unique_ptr<AudioDecoder> AudioDecoderL16::MakeAudioDecoder( + const Config& config) { + return config.IsOk() ? rtc::MakeUnique<AudioDecoderPcm16B>( + config.sample_rate_hz, config.num_channels) + : nullptr; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.h b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.h new file mode 100644 index 0000000000..db863b37de --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_L16_AUDIO_DECODER_L16_H_ +#define API_AUDIO_CODECS_L16_AUDIO_DECODER_L16_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// L16 decoder API for use as a template parameter to +// CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderL16 { + struct Config { + bool IsOk() const { + return (sample_rate_hz == 8000 || sample_rate_hz == 16000 || + sample_rate_hz == 32000 || sample_rate_hz == 48000) && + num_channels >= 1; + } + int sample_rate_hz = 8000; + int num_channels = 1; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const Config& config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_L16_AUDIO_DECODER_L16_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16_gn/moz.build new file mode 100644 index 0000000000..aa89ac1e75 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_decoder_L16.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_L16_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.cc new file mode 100644 index 0000000000..d0d9f6f644 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "api/audio_codecs/L16/audio_encoder_L16.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h" +#include "modules/audio_coding/codecs/pcm16b/pcm16b_common.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderL16::Config> AudioEncoderL16::SdpToConfig( + const SdpAudioFormat& format) { + if (!rtc::IsValueInRangeForNumericType<int>(format.num_channels)) { + return rtc::nullopt; + } + Config config; + config.sample_rate_hz = format.clockrate_hz; + config.num_channels = rtc::dchecked_cast<int>(format.num_channels); + return STR_CASE_CMP(format.name.c_str(), "L16") == 0 && config.IsOk() + ? rtc::Optional<Config>(config) + : rtc::nullopt; +} + +void AudioEncoderL16::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + Pcm16BAppendSupportedCodecSpecs(specs); +} + +AudioCodecInfo AudioEncoderL16::QueryAudioEncoder( + const AudioEncoderL16::Config& config) { + RTC_DCHECK(config.IsOk()); + return {config.sample_rate_hz, + rtc::dchecked_cast<size_t>(config.num_channels), + config.sample_rate_hz * config.num_channels * 16}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderL16::MakeAudioEncoder( + const AudioEncoderL16::Config& config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + AudioEncoderPcm16B::Config c; + c.sample_rate_hz = config.sample_rate_hz; + c.num_channels = config.num_channels; + c.frame_size_ms = config.frame_size_ms; + c.payload_type = payload_type; + return rtc::MakeUnique<AudioEncoderPcm16B>(c); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.h b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.h new file mode 100644 index 0000000000..e099bd5747 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_L16_AUDIO_ENCODER_L16_H_ +#define API_AUDIO_CODECS_L16_AUDIO_ENCODER_L16_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// L16 encoder API for use as a template parameter to +// CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderL16 { + struct Config { + bool IsOk() const { + return (sample_rate_hz == 8000 || sample_rate_hz == 16000 || + sample_rate_hz == 32000 || sample_rate_hz == 48000) && + num_channels >= 1 && frame_size_ms > 0 && frame_size_ms <= 120 && + frame_size_ms % 10 == 0; + } + int sample_rate_hz = 8000; + int num_channels = 1; + int frame_size_ms = 10; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const Config& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config& config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_L16_AUDIO_ENCODER_L16_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16_gn/moz.build new file mode 100644 index 0000000000..1b5005988a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/L16/audio_encoder_L16.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_L16_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/OWNERS b/third_party/libwebrtc/webrtc/api/audio_codecs/OWNERS new file mode 100644 index 0000000000..a52dd93e5e --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/OWNERS @@ -0,0 +1,2 @@ +kwiberg@webrtc.org +ossu@webrtc.org diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_codecs_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_codecs_api_gn/moz.build new file mode 100644 index 0000000000..e37464318f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_codecs_api_gn/moz.build @@ -0,0 +1,219 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.cc", + "/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.cc", + "/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_codecs_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.cc new file mode 100644 index 0000000000..ddb06d27ee --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.cc @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2012 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 "api/audio_codecs/audio_decoder.h" + +#include <assert.h> +#include <memory> +#include <utility> + +#include "api/array_view.h" +#include "rtc_base/checks.h" +#include "rtc_base/sanitizer.h" +#include "rtc_base/trace_event.h" + +namespace webrtc { + +namespace { + +class OldStyleEncodedFrame final : public AudioDecoder::EncodedAudioFrame { + public: + OldStyleEncodedFrame(AudioDecoder* decoder, rtc::Buffer&& payload) + : decoder_(decoder), payload_(std::move(payload)) {} + + size_t Duration() const override { + const int ret = decoder_->PacketDuration(payload_.data(), payload_.size()); + return ret < 0 ? 0 : static_cast<size_t>(ret); + } + + rtc::Optional<DecodeResult> Decode( + rtc::ArrayView<int16_t> decoded) const override { + auto speech_type = AudioDecoder::kSpeech; + const int ret = decoder_->Decode( + payload_.data(), payload_.size(), decoder_->SampleRateHz(), + decoded.size() * sizeof(int16_t), decoded.data(), &speech_type); + return ret < 0 ? rtc::nullopt + : rtc::Optional<DecodeResult>( + {static_cast<size_t>(ret), speech_type}); + } + + private: + AudioDecoder* const decoder_; + const rtc::Buffer payload_; +}; + +} // namespace + +AudioDecoder::ParseResult::ParseResult() = default; +AudioDecoder::ParseResult::ParseResult(ParseResult&& b) = default; +AudioDecoder::ParseResult::ParseResult(uint32_t timestamp, + int priority, + std::unique_ptr<EncodedAudioFrame> frame) + : timestamp(timestamp), priority(priority), frame(std::move(frame)) { + RTC_DCHECK_GE(priority, 0); +} + +AudioDecoder::ParseResult::~ParseResult() = default; + +AudioDecoder::ParseResult& AudioDecoder::ParseResult::operator=( + ParseResult&& b) = default; + +std::vector<AudioDecoder::ParseResult> AudioDecoder::ParsePayload( + rtc::Buffer&& payload, + uint32_t timestamp) { + std::vector<ParseResult> results; + std::unique_ptr<EncodedAudioFrame> frame( + new OldStyleEncodedFrame(this, std::move(payload))); + results.emplace_back(timestamp, 0, std::move(frame)); + return results; +} + +int AudioDecoder::Decode(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + size_t max_decoded_bytes, + int16_t* decoded, + SpeechType* speech_type) { + TRACE_EVENT0("webrtc", "AudioDecoder::Decode"); + rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); + int duration = PacketDuration(encoded, encoded_len); + if (duration >= 0 && + duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { + return -1; + } + return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, + speech_type); +} + +int AudioDecoder::DecodeRedundant(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + size_t max_decoded_bytes, + int16_t* decoded, + SpeechType* speech_type) { + TRACE_EVENT0("webrtc", "AudioDecoder::DecodeRedundant"); + rtc::MsanCheckInitialized(rtc::MakeArrayView(encoded, encoded_len)); + int duration = PacketDurationRedundant(encoded, encoded_len); + if (duration >= 0 && + duration * Channels() * sizeof(int16_t) > max_decoded_bytes) { + return -1; + } + return DecodeRedundantInternal(encoded, encoded_len, sample_rate_hz, decoded, + speech_type); +} + +int AudioDecoder::DecodeRedundantInternal(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + int16_t* decoded, + SpeechType* speech_type) { + return DecodeInternal(encoded, encoded_len, sample_rate_hz, decoded, + speech_type); +} + +bool AudioDecoder::HasDecodePlc() const { + return false; +} + +size_t AudioDecoder::DecodePlc(size_t num_frames, int16_t* decoded) { + return 0; +} + +int AudioDecoder::IncomingPacket(const uint8_t* payload, + size_t payload_len, + uint16_t rtp_sequence_number, + uint32_t rtp_timestamp, + uint32_t arrival_timestamp) { + return 0; +} + +int AudioDecoder::ErrorCode() { + return 0; +} + +int AudioDecoder::PacketDuration(const uint8_t* encoded, + size_t encoded_len) const { + return kNotImplemented; +} + +int AudioDecoder::PacketDurationRedundant(const uint8_t* encoded, + size_t encoded_len) const { + return kNotImplemented; +} + +bool AudioDecoder::PacketHasFec(const uint8_t* encoded, + size_t encoded_len) const { + return false; +} + +AudioDecoder::SpeechType AudioDecoder::ConvertSpeechType(int16_t type) { + switch (type) { + case 0: // TODO(hlundin): Both iSAC and Opus return 0 for speech. + case 1: + return kSpeech; + case 2: + return kComfortNoise; + default: + assert(false); + return kSpeech; + } +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.h new file mode 100644 index 0000000000..545bdf52cc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2012 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 API_AUDIO_CODECS_AUDIO_DECODER_H_ +#define API_AUDIO_CODECS_AUDIO_DECODER_H_ + +#include <memory> +#include <vector> + +#include "api/array_view.h" +#include "api/optional.h" +#include "rtc_base/buffer.h" +#include "rtc_base/constructormagic.h" +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +class AudioDecoder { + public: + enum SpeechType { + kSpeech = 1, + kComfortNoise = 2, + }; + + // Used by PacketDuration below. Save the value -1 for errors. + enum { kNotImplemented = -2 }; + + AudioDecoder() = default; + virtual ~AudioDecoder() = default; + + class EncodedAudioFrame { + public: + struct DecodeResult { + size_t num_decoded_samples; + SpeechType speech_type; + }; + + virtual ~EncodedAudioFrame() = default; + + // Returns the duration in samples-per-channel of this audio frame. + // If no duration can be ascertained, returns zero. + virtual size_t Duration() const = 0; + + // Decodes this frame of audio and writes the result in |decoded|. + // |decoded| must be large enough to store as many samples as indicated by a + // call to Duration() . On success, returns an rtc::Optional containing the + // total number of samples across all channels, as well as whether the + // decoder produced comfort noise or speech. On failure, returns an empty + // rtc::Optional. Decode may be called at most once per frame object. + virtual rtc::Optional<DecodeResult> Decode( + rtc::ArrayView<int16_t> decoded) const = 0; + }; + + struct ParseResult { + ParseResult(); + ParseResult(uint32_t timestamp, + int priority, + std::unique_ptr<EncodedAudioFrame> frame); + ParseResult(ParseResult&& b); + ~ParseResult(); + + ParseResult& operator=(ParseResult&& b); + + // The timestamp of the frame is in samples per channel. + uint32_t timestamp; + // The relative priority of the frame compared to other frames of the same + // payload and the same timeframe. A higher value means a lower priority. + // The highest priority is zero - negative values are not allowed. + int priority; + std::unique_ptr<EncodedAudioFrame> frame; + }; + + // Let the decoder parse this payload and prepare zero or more decodable + // frames. Each frame must be between 10 ms and 120 ms long. The caller must + // ensure that the AudioDecoder object outlives any frame objects returned by + // this call. The decoder is free to swap or move the data from the |payload| + // buffer. |timestamp| is the input timestamp, in samples, corresponding to + // the start of the payload. + virtual std::vector<ParseResult> ParsePayload(rtc::Buffer&& payload, + uint32_t timestamp); + + // Decodes |encode_len| bytes from |encoded| and writes the result in + // |decoded|. The maximum bytes allowed to be written into |decoded| is + // |max_decoded_bytes|. Returns the total number of samples across all + // channels. If the decoder produced comfort noise, |speech_type| + // is set to kComfortNoise, otherwise it is kSpeech. The desired output + // sample rate is provided in |sample_rate_hz|, which must be valid for the + // codec at hand. + int Decode(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + size_t max_decoded_bytes, + int16_t* decoded, + SpeechType* speech_type); + + // Same as Decode(), but interfaces to the decoders redundant decode function. + // The default implementation simply calls the regular Decode() method. + int DecodeRedundant(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + size_t max_decoded_bytes, + int16_t* decoded, + SpeechType* speech_type); + + // Indicates if the decoder implements the DecodePlc method. + virtual bool HasDecodePlc() const; + + // Calls the packet-loss concealment of the decoder to update the state after + // one or several lost packets. The caller has to make sure that the + // memory allocated in |decoded| should accommodate |num_frames| frames. + virtual size_t DecodePlc(size_t num_frames, int16_t* decoded); + + // Resets the decoder state (empty buffers etc.). + virtual void Reset() = 0; + + // Notifies the decoder of an incoming packet to NetEQ. + virtual int IncomingPacket(const uint8_t* payload, + size_t payload_len, + uint16_t rtp_sequence_number, + uint32_t rtp_timestamp, + uint32_t arrival_timestamp); + + // Returns the last error code from the decoder. + virtual int ErrorCode(); + + // Returns the duration in samples-per-channel of the payload in |encoded| + // which is |encoded_len| bytes long. Returns kNotImplemented if no duration + // estimate is available, or -1 in case of an error. + virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len) const; + + // Returns the duration in samples-per-channel of the redandant payload in + // |encoded| which is |encoded_len| bytes long. Returns kNotImplemented if no + // duration estimate is available, or -1 in case of an error. + virtual int PacketDurationRedundant(const uint8_t* encoded, + size_t encoded_len) const; + + // Detects whether a packet has forward error correction. The packet is + // comprised of the samples in |encoded| which is |encoded_len| bytes long. + // Returns true if the packet has FEC and false otherwise. + virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const; + + // Returns the actual sample rate of the decoder's output. This value may not + // change during the lifetime of the decoder. + virtual int SampleRateHz() const = 0; + + // The number of channels in the decoder's output. This value may not change + // during the lifetime of the decoder. + virtual size_t Channels() const = 0; + + protected: + static SpeechType ConvertSpeechType(int16_t type); + + virtual int DecodeInternal(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + int16_t* decoded, + SpeechType* speech_type) = 0; + + virtual int DecodeRedundantInternal(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + int16_t* decoded, + SpeechType* speech_type); + + private: + RTC_DISALLOW_COPY_AND_ASSIGN(AudioDecoder); +}; + +} // namespace webrtc +#endif // API_AUDIO_CODECS_AUDIO_DECODER_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory.h new file mode 100644 index 0000000000..ac0f4519d8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2016 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 API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_H_ +#define API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// A factory that creates AudioDecoders. +// NOTE: This class is still under development and may change without notice. +class AudioDecoderFactory : public rtc::RefCountInterface { + public: + virtual std::vector<AudioCodecSpec> GetSupportedDecoders() = 0; + + virtual bool IsSupportedDecoder(const SdpAudioFormat& format) = 0; + + virtual std::unique_ptr<AudioDecoder> MakeAudioDecoder( + const SdpAudioFormat& format) = 0; +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory_template.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory_template.h new file mode 100644 index 0000000000..a1933aa2b4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_decoder_factory_template.h @@ -0,0 +1,125 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_TEMPLATE_H_ +#define API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_TEMPLATE_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder_factory.h" +#include "rtc_base/refcountedobject.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +namespace audio_decoder_factory_template_impl { + +template <typename... Ts> +struct Helper; + +// Base case: 0 template parameters. +template <> +struct Helper<> { + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) {} + static bool IsSupportedDecoder(const SdpAudioFormat& format) { return false; } + static std::unique_ptr<AudioDecoder> MakeAudioDecoder( + const SdpAudioFormat& format) { + return nullptr; + } +}; + +// Inductive case: Called with n + 1 template parameters; calls subroutines +// with n template parameters. +template <typename T, typename... Ts> +struct Helper<T, Ts...> { + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) { + T::AppendSupportedDecoders(specs); + Helper<Ts...>::AppendSupportedDecoders(specs); + } + static bool IsSupportedDecoder(const SdpAudioFormat& format) { + auto opt_config = T::SdpToConfig(format); + return opt_config ? true : Helper<Ts...>::IsSupportedDecoder(format); + } + static std::unique_ptr<AudioDecoder> MakeAudioDecoder( + const SdpAudioFormat& format) { + auto opt_config = T::SdpToConfig(format); + return opt_config ? T::MakeAudioDecoder(*opt_config) + : Helper<Ts...>::MakeAudioDecoder(format); + } +}; + +template <typename... Ts> +class AudioDecoderFactoryT : public AudioDecoderFactory { + public: + std::vector<AudioCodecSpec> GetSupportedDecoders() override { + std::vector<AudioCodecSpec> specs; + Helper<Ts...>::AppendSupportedDecoders(&specs); + return specs; + } + + bool IsSupportedDecoder(const SdpAudioFormat& format) override { + return Helper<Ts...>::IsSupportedDecoder(format); + } + + std::unique_ptr<AudioDecoder> MakeAudioDecoder( + const SdpAudioFormat& format) override { + return Helper<Ts...>::MakeAudioDecoder(format); + } +}; + +} // namespace audio_decoder_factory_template_impl + +// Make an AudioDecoderFactory that can create instances of the given decoders. +// +// Each decoder type is given as a template argument to the function; it should +// be a struct with the following static member functions: +// +// // Converts |audio_format| to a ConfigType instance. Returns an empty +// // optional if |audio_format| doesn't correctly specify an decoder of our +// // type. +// rtc::Optional<ConfigType> SdpToConfig(const SdpAudioFormat& audio_format); +// +// // Appends zero or more AudioCodecSpecs to the list that will be returned +// // by AudioDecoderFactory::GetSupportedDecoders(). +// void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); +// +// // Creates an AudioDecoder for the specified format. Used to implement +// // AudioDecoderFactory::MakeAudioDecoder(). +// std::unique_ptr<AudioDecoder> MakeAudioDecoder(const ConfigType& config); +// +// ConfigType should be a type that encapsulates all the settings needed to +// create an AudioDecoder. +// +// Whenever it tries to do something, the new factory will try each of the +// decoder types in the order they were specified in the template argument +// list, stopping at the first one that claims to be able to do the job. +// +// NOTE: This function is still under development and may change without notice. +// +// TODO(kwiberg): Point at CreateBuiltinAudioDecoderFactory() for an example of +// how it is used. +template <typename... Ts> +rtc::scoped_refptr<AudioDecoderFactory> CreateAudioDecoderFactory() { + // There's no technical reason we couldn't allow zero template parameters, + // but such a factory couldn't create any decoders, and callers can do this + // by mistake by simply forgetting the <> altogether. So we forbid it in + // order to prevent caller foot-shooting. + static_assert(sizeof...(Ts) >= 1, + "Caller must give at least one template parameter"); + + return rtc::scoped_refptr<AudioDecoderFactory>( + new rtc::RefCountedObject< + audio_decoder_factory_template_impl::AudioDecoderFactoryT<Ts...>>()); +} + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_AUDIO_DECODER_FACTORY_TEMPLATE_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.cc new file mode 100644 index 0000000000..4f9b9f0bb2 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.cc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2014 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 "api/audio_codecs/audio_encoder.h" + +#include "rtc_base/checks.h" +#include "rtc_base/trace_event.h" + +namespace webrtc { + +ANAStats::ANAStats() = default; +ANAStats::~ANAStats() = default; +ANAStats::ANAStats(const ANAStats&) = default; + +AudioEncoder::EncodedInfo::EncodedInfo() = default; +AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default; +AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default; +AudioEncoder::EncodedInfo::~EncodedInfo() = default; +AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=( + const EncodedInfo&) = default; +AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) = + default; + +int AudioEncoder::RtpTimestampRateHz() const { + return SampleRateHz(); +} + +AudioEncoder::EncodedInfo AudioEncoder::Encode( + uint32_t rtp_timestamp, + rtc::ArrayView<const int16_t> audio, + rtc::Buffer* encoded) { + TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); + RTC_CHECK_EQ(audio.size(), + static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); + + const size_t old_size = encoded->size(); + EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded); + RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes); + return info; +} + +bool AudioEncoder::SetFec(bool enable) { + return !enable; +} + +bool AudioEncoder::SetDtx(bool enable) { + return !enable; +} + +bool AudioEncoder::GetDtx() const { + return false; +} + +bool AudioEncoder::SetApplication(Application application) { + return false; +} + +void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} + +void AudioEncoder::SetTargetBitrate(int target_bps) {} + +rtc::ArrayView<std::unique_ptr<AudioEncoder>> +AudioEncoder::ReclaimContainedEncoders() { + return nullptr; +} + +bool AudioEncoder::EnableAudioNetworkAdaptor(const std::string& config_string, + RtcEventLog* event_log) { + return false; +} + +void AudioEncoder::DisableAudioNetworkAdaptor() {} + +void AudioEncoder::OnReceivedUplinkPacketLossFraction( + float uplink_packet_loss_fraction) {} + +void AudioEncoder::OnReceivedUplinkRecoverablePacketLossFraction( + float uplink_recoverable_packet_loss_fraction) {} + +void AudioEncoder::OnReceivedTargetAudioBitrate(int target_audio_bitrate_bps) { + OnReceivedUplinkBandwidth(target_audio_bitrate_bps, rtc::nullopt); +} + +void AudioEncoder::OnReceivedUplinkBandwidth( + int target_audio_bitrate_bps, + rtc::Optional<int64_t> bwe_period_ms) {} + +void AudioEncoder::OnReceivedRtt(int rtt_ms) {} + +void AudioEncoder::OnReceivedOverhead(size_t overhead_bytes_per_packet) {} + +void AudioEncoder::SetReceiverFrameLengthRange(int min_frame_length_ms, + int max_frame_length_ms) {} + +ANAStats AudioEncoder::GetANAStats() const { + return ANAStats(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.h new file mode 100644 index 0000000000..7ad9ba4d09 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder.h @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2014 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 API_AUDIO_CODECS_AUDIO_ENCODER_H_ +#define API_AUDIO_CODECS_AUDIO_ENCODER_H_ + +#include <algorithm> +#include <memory> +#include <string> +#include <vector> + +#include "api/array_view.h" +#include "api/optional.h" +#include "rtc_base/buffer.h" +#include "rtc_base/deprecation.h" +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +class RtcEventLog; + +// Statistics related to Audio Network Adaptation. +struct ANAStats { + ANAStats(); + ANAStats(const ANAStats&); + ~ANAStats(); + // Number of actions taken by the ANA bitrate controller since the start of + // the call. If this value is not set, it indicates that the bitrate + // controller is disabled. + rtc::Optional<uint32_t> bitrate_action_counter; + // Number of actions taken by the ANA channel controller since the start of + // the call. If this value is not set, it indicates that the channel + // controller is disabled. + rtc::Optional<uint32_t> channel_action_counter; + // Number of actions taken by the ANA DTX controller since the start of the + // call. If this value is not set, it indicates that the DTX controller is + // disabled. + rtc::Optional<uint32_t> dtx_action_counter; + // Number of actions taken by the ANA FEC controller since the start of the + // call. If this value is not set, it indicates that the FEC controller is + // disabled. + rtc::Optional<uint32_t> fec_action_counter; + // Number of times the ANA frame length controller decided to increase the + // frame length since the start of the call. If this value is not set, it + // indicates that the frame length controller is disabled. + rtc::Optional<uint32_t> frame_length_increase_counter; + // Number of times the ANA frame length controller decided to decrease the + // frame length since the start of the call. If this value is not set, it + // indicates that the frame length controller is disabled. + rtc::Optional<uint32_t> frame_length_decrease_counter; + // The uplink packet loss fractions as set by the ANA FEC controller. If this + // value is not set, it indicates that the ANA FEC controller is not active. + rtc::Optional<float> uplink_packet_loss_fraction; +}; + +// This is the interface class for encoders in AudioCoding module. Each codec +// type must have an implementation of this class. +class AudioEncoder { + public: + // Used for UMA logging of codec usage. The same codecs, with the + // same values, must be listed in + // src/tools/metrics/histograms/histograms.xml in chromium to log + // correct values. + enum class CodecType { + kOther = 0, // Codec not specified, and/or not listed in this enum + kOpus = 1, + kIsac = 2, + kPcmA = 3, + kPcmU = 4, + kG722 = 5, + kIlbc = 6, + + // Number of histogram bins in the UMA logging of codec types. The + // total number of different codecs that are logged cannot exceed this + // number. + kMaxLoggedAudioCodecTypes + }; + + struct EncodedInfoLeaf { + size_t encoded_bytes = 0; + uint32_t encoded_timestamp = 0; + int payload_type = 0; + bool send_even_if_empty = false; + bool speech = true; + CodecType encoder_type = CodecType::kOther; + }; + + // This is the main struct for auxiliary encoding information. Each encoded + // packet should be accompanied by one EncodedInfo struct, containing the + // total number of |encoded_bytes|, the |encoded_timestamp| and the + // |payload_type|. If the packet contains redundant encodings, the |redundant| + // vector will be populated with EncodedInfoLeaf structs. Each struct in the + // vector represents one encoding; the order of structs in the vector is the + // same as the order in which the actual payloads are written to the byte + // stream. When EncoderInfoLeaf structs are present in the vector, the main + // struct's |encoded_bytes| will be the sum of all the |encoded_bytes| in the + // vector. + struct EncodedInfo : public EncodedInfoLeaf { + EncodedInfo(); + EncodedInfo(const EncodedInfo&); + EncodedInfo(EncodedInfo&&); + ~EncodedInfo(); + EncodedInfo& operator=(const EncodedInfo&); + EncodedInfo& operator=(EncodedInfo&&); + + std::vector<EncodedInfoLeaf> redundant; + }; + + virtual ~AudioEncoder() = default; + + // Returns the input sample rate in Hz and the number of input channels. + // These are constants set at instantiation time. + virtual int SampleRateHz() const = 0; + virtual size_t NumChannels() const = 0; + + // Returns the rate at which the RTP timestamps are updated. The default + // implementation returns SampleRateHz(). + virtual int RtpTimestampRateHz() const; + + // Returns the number of 10 ms frames the encoder will put in the next + // packet. This value may only change when Encode() outputs a packet; i.e., + // the encoder may vary the number of 10 ms frames from packet to packet, but + // it must decide the length of the next packet no later than when outputting + // the preceding packet. + virtual size_t Num10MsFramesInNextPacket() const = 0; + + // Returns the maximum value that can be returned by + // Num10MsFramesInNextPacket(). + virtual size_t Max10MsFramesInAPacket() const = 0; + + // Returns the current target bitrate in bits/s. The value -1 means that the + // codec adapts the target automatically, and a current target cannot be + // provided. + virtual int GetTargetBitrate() const = 0; + + // Accepts one 10 ms block of input audio (i.e., SampleRateHz() / 100 * + // NumChannels() samples). Multi-channel audio must be sample-interleaved. + // The encoder appends zero or more bytes of output to |encoded| and returns + // additional encoding information. Encode() checks some preconditions, calls + // EncodeImpl() which does the actual work, and then checks some + // postconditions. + EncodedInfo Encode(uint32_t rtp_timestamp, + rtc::ArrayView<const int16_t> audio, + rtc::Buffer* encoded); + + // Resets the encoder to its starting state, discarding any input that has + // been fed to the encoder but not yet emitted in a packet. + virtual void Reset() = 0; + + // Enables or disables codec-internal FEC (forward error correction). Returns + // true if the codec was able to comply. The default implementation returns + // true when asked to disable FEC and false when asked to enable it (meaning + // that FEC isn't supported). + virtual bool SetFec(bool enable); + + // Enables or disables codec-internal VAD/DTX. Returns true if the codec was + // able to comply. The default implementation returns true when asked to + // disable DTX and false when asked to enable it (meaning that DTX isn't + // supported). + virtual bool SetDtx(bool enable); + + // Returns the status of codec-internal DTX. The default implementation always + // returns false. + virtual bool GetDtx() const; + + // Sets the application mode. Returns true if the codec was able to comply. + // The default implementation just returns false. + enum class Application { kSpeech, kAudio }; + virtual bool SetApplication(Application application); + + // Tells the encoder about the highest sample rate the decoder is expected to + // use when decoding the bitstream. The encoder would typically use this + // information to adjust the quality of the encoding. The default + // implementation does nothing. + virtual void SetMaxPlaybackRate(int frequency_hz); + + // This is to be deprecated. Please use |OnReceivedTargetAudioBitrate| + // instead. + // Tells the encoder what average bitrate we'd like it to produce. The + // encoder is free to adjust or disregard the given bitrate (the default + // implementation does the latter). + RTC_DEPRECATED virtual void SetTargetBitrate(int target_bps); + + // Causes this encoder to let go of any other encoders it contains, and + // returns a pointer to an array where they are stored (which is required to + // live as long as this encoder). Unless the returned array is empty, you may + // not call any methods on this encoder afterwards, except for the + // destructor. The default implementation just returns an empty array. + // NOTE: This method is subject to change. Do not call or override it. + virtual rtc::ArrayView<std::unique_ptr<AudioEncoder>> + ReclaimContainedEncoders(); + + // Enables audio network adaptor. Returns true if successful. + virtual bool EnableAudioNetworkAdaptor(const std::string& config_string, + RtcEventLog* event_log); + + // Disables audio network adaptor. + virtual void DisableAudioNetworkAdaptor(); + + // Provides uplink packet loss fraction to this encoder to allow it to adapt. + // |uplink_packet_loss_fraction| is in the range [0.0, 1.0]. + virtual void OnReceivedUplinkPacketLossFraction( + float uplink_packet_loss_fraction); + + // Provides 1st-order-FEC-recoverable uplink packet loss rate to this encoder + // to allow it to adapt. + // |uplink_recoverable_packet_loss_fraction| is in the range [0.0, 1.0]. + virtual void OnReceivedUplinkRecoverablePacketLossFraction( + float uplink_recoverable_packet_loss_fraction); + + // Provides target audio bitrate to this encoder to allow it to adapt. + virtual void OnReceivedTargetAudioBitrate(int target_bps); + + // Provides target audio bitrate and corresponding probing interval of + // the bandwidth estimator to this encoder to allow it to adapt. + virtual void OnReceivedUplinkBandwidth( + int target_audio_bitrate_bps, + rtc::Optional<int64_t> bwe_period_ms); + + // Provides RTT to this encoder to allow it to adapt. + virtual void OnReceivedRtt(int rtt_ms); + + // Provides overhead to this encoder to adapt. The overhead is the number of + // bytes that will be added to each packet the encoder generates. + virtual void OnReceivedOverhead(size_t overhead_bytes_per_packet); + + // To allow encoder to adapt its frame length, it must be provided the frame + // length range that receivers can accept. + virtual void SetReceiverFrameLengthRange(int min_frame_length_ms, + int max_frame_length_ms); + + // Get statistics related to audio network adaptation. + virtual ANAStats GetANAStats() const; + + protected: + // Subclasses implement this to perform the actual encoding. Called by + // Encode(). + virtual EncodedInfo EncodeImpl(uint32_t rtp_timestamp, + rtc::ArrayView<const int16_t> audio, + rtc::Buffer* encoded) = 0; +}; +} // namespace webrtc +#endif // API_AUDIO_CODECS_AUDIO_ENCODER_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory.h new file mode 100644 index 0000000000..43461f6b9a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ +#define API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// A factory that creates AudioEncoders. +// NOTE: This class is still under development and may change without notice. +class AudioEncoderFactory : public rtc::RefCountInterface { + public: + // Returns a prioritized list of audio codecs, to use for signaling etc. + virtual std::vector<AudioCodecSpec> GetSupportedEncoders() = 0; + + // Returns information about how this format would be encoded, provided it's + // supported. More format and format variations may be supported than those + // returned by GetSupportedEncoders(). + virtual rtc::Optional<AudioCodecInfo> QueryAudioEncoder( + const SdpAudioFormat& format) = 0; + + // Creates an AudioEncoder for the specified format. The encoder will tags its + // payloads with the specified payload type. + // TODO(ossu): Try to avoid audio encoders having to know their payload type. + virtual std::unique_ptr<AudioEncoder> MakeAudioEncoder( + int payload_type, + const SdpAudioFormat& format) = 0; +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory_template.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory_template.h new file mode 100644 index 0000000000..1d0325d1a0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_encoder_factory_template.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_TEMPLATE_H_ +#define API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_TEMPLATE_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder_factory.h" +#include "rtc_base/refcountedobject.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +namespace audio_encoder_factory_template_impl { + +template <typename... Ts> +struct Helper; + +// Base case: 0 template parameters. +template <> +struct Helper<> { + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) {} + static rtc::Optional<AudioCodecInfo> QueryAudioEncoder( + const SdpAudioFormat& format) { + return rtc::nullopt; + } + static std::unique_ptr<AudioEncoder> MakeAudioEncoder( + int payload_type, + const SdpAudioFormat& format) { + return nullptr; + } +}; + +// Inductive case: Called with n + 1 template parameters; calls subroutines +// with n template parameters. +template <typename T, typename... Ts> +struct Helper<T, Ts...> { + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) { + T::AppendSupportedEncoders(specs); + Helper<Ts...>::AppendSupportedEncoders(specs); + } + static rtc::Optional<AudioCodecInfo> QueryAudioEncoder( + const SdpAudioFormat& format) { + auto opt_config = T::SdpToConfig(format); + return opt_config ? rtc::Optional<AudioCodecInfo>( + T::QueryAudioEncoder(*opt_config)) + : Helper<Ts...>::QueryAudioEncoder(format); + } + static std::unique_ptr<AudioEncoder> MakeAudioEncoder( + int payload_type, + const SdpAudioFormat& format) { + auto opt_config = T::SdpToConfig(format); + if (opt_config) { + return T::MakeAudioEncoder(*opt_config, payload_type); + } else { + return Helper<Ts...>::MakeAudioEncoder(payload_type, format); + } + } +}; + +template <typename... Ts> +class AudioEncoderFactoryT : public AudioEncoderFactory { + public: + std::vector<AudioCodecSpec> GetSupportedEncoders() override { + std::vector<AudioCodecSpec> specs; + Helper<Ts...>::AppendSupportedEncoders(&specs); + return specs; + } + + rtc::Optional<AudioCodecInfo> QueryAudioEncoder( + const SdpAudioFormat& format) override { + return Helper<Ts...>::QueryAudioEncoder(format); + } + + std::unique_ptr<AudioEncoder> MakeAudioEncoder( + int payload_type, + const SdpAudioFormat& format) override { + return Helper<Ts...>::MakeAudioEncoder(payload_type, format); + } +}; + +} // namespace audio_encoder_factory_template_impl + +// Make an AudioEncoderFactory that can create instances of the given encoders. +// +// Each encoder type is given as a template argument to the function; it should +// be a struct with the following static member functions: +// +// // Converts |audio_format| to a ConfigType instance. Returns an empty +// // optional if |audio_format| doesn't correctly specify an encoder of our +// // type. +// rtc::Optional<ConfigType> SdpToConfig(const SdpAudioFormat& audio_format); +// +// // Appends zero or more AudioCodecSpecs to the list that will be returned +// // by AudioEncoderFactory::GetSupportedEncoders(). +// void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); +// +// // Returns information about how this format would be encoded. Used to +// // implement AudioEncoderFactory::QueryAudioEncoder(). +// AudioCodecInfo QueryAudioEncoder(const ConfigType& config); +// +// // Creates an AudioEncoder for the specified format. Used to implement +// // AudioEncoderFactory::MakeAudioEncoder(). +// std::unique_ptr<AudioEncoder> MakeAudioEncoder(const ConfigType& config, +// int payload_type); +// +// ConfigType should be a type that encapsulates all the settings needed to +// create an AudioDecoder. +// +// Whenever it tries to do something, the new factory will try each of the +// encoders in the order they were specified in the template argument list, +// stopping at the first one that claims to be able to do the job. +// +// NOTE: This function is still under development and may change without notice. +// +// TODO(kwiberg): Point at CreateBuiltinAudioEncoderFactory() for an example of +// how it is used. +template <typename... Ts> +rtc::scoped_refptr<AudioEncoderFactory> CreateAudioEncoderFactory() { + // There's no technical reason we couldn't allow zero template parameters, + // but such a factory couldn't create any encoders, and callers can do this + // by mistake by simply forgetting the <> altogether. So we forbid it in + // order to prevent caller foot-shooting. + static_assert(sizeof...(Ts) >= 1, + "Caller must give at least one template parameter"); + + return rtc::scoped_refptr<AudioEncoderFactory>( + new rtc::RefCountedObject< + audio_encoder_factory_template_impl::AudioEncoderFactoryT<Ts...>>()); +} + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_AUDIO_ENCODER_FACTORY_TEMPLATE_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.cc new file mode 100644 index 0000000000..82c166f5c0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.cc @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 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 "api/audio_codecs/audio_format.h" + +#include "common_types.h" // NOLINT(build/include) + +namespace webrtc { + +SdpAudioFormat::SdpAudioFormat(const SdpAudioFormat&) = default; +SdpAudioFormat::SdpAudioFormat(SdpAudioFormat&&) = default; + +SdpAudioFormat::SdpAudioFormat(const char* name, + int clockrate_hz, + size_t num_channels) + : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {} + +SdpAudioFormat::SdpAudioFormat(const std::string& name, + int clockrate_hz, + size_t num_channels) + : name(name), clockrate_hz(clockrate_hz), num_channels(num_channels) {} + +SdpAudioFormat::SdpAudioFormat(const char* name, + int clockrate_hz, + size_t num_channels, + const Parameters& param) + : name(name), + clockrate_hz(clockrate_hz), + num_channels(num_channels), + parameters(param) {} + +SdpAudioFormat::SdpAudioFormat(const std::string& name, + int clockrate_hz, + size_t num_channels, + const Parameters& param) + : name(name), + clockrate_hz(clockrate_hz), + num_channels(num_channels), + parameters(param) {} + +bool SdpAudioFormat::Matches(const SdpAudioFormat& o) const { + return STR_CASE_CMP(name.c_str(), o.name.c_str()) == 0 && + clockrate_hz == o.clockrate_hz && num_channels == o.num_channels; +} + +SdpAudioFormat::~SdpAudioFormat() = default; +SdpAudioFormat& SdpAudioFormat::operator=(const SdpAudioFormat&) = default; +SdpAudioFormat& SdpAudioFormat::operator=(SdpAudioFormat&&) = default; + +bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b) { + return STR_CASE_CMP(a.name.c_str(), b.name.c_str()) == 0 && + a.clockrate_hz == b.clockrate_hz && a.num_channels == b.num_channels && + a.parameters == b.parameters; +} + +void swap(SdpAudioFormat& a, SdpAudioFormat& b) { + using std::swap; + swap(a.name, b.name); + swap(a.clockrate_hz, b.clockrate_hz); + swap(a.num_channels, b.num_channels); + swap(a.parameters, b.parameters); +} + +std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf) { + os << "{name: " << saf.name; + os << ", clockrate_hz: " << saf.clockrate_hz; + os << ", num_channels: " << saf.num_channels; + os << ", parameters: {"; + const char* sep = ""; + for (const auto& kv : saf.parameters) { + os << sep << kv.first << ": " << kv.second; + sep = ", "; + } + os << "}}"; + return os; +} + +AudioCodecInfo::AudioCodecInfo(int sample_rate_hz, + size_t num_channels, + int bitrate_bps) + : AudioCodecInfo(sample_rate_hz, + num_channels, + bitrate_bps, + bitrate_bps, + bitrate_bps) {} + +AudioCodecInfo::AudioCodecInfo(int sample_rate_hz, + size_t num_channels, + int default_bitrate_bps, + int min_bitrate_bps, + int max_bitrate_bps) + : sample_rate_hz(sample_rate_hz), + num_channels(num_channels), + default_bitrate_bps(default_bitrate_bps), + min_bitrate_bps(min_bitrate_bps), + max_bitrate_bps(max_bitrate_bps) { + RTC_DCHECK_GT(sample_rate_hz, 0); + RTC_DCHECK_GT(num_channels, 0); + RTC_DCHECK_GE(min_bitrate_bps, 0); + RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps); + RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps); +} + +std::ostream& operator<<(std::ostream& os, const AudioCodecInfo& aci) { + os << "{sample_rate_hz: " << aci.sample_rate_hz; + os << ", num_channels: " << aci.num_channels; + os << ", default_bitrate_bps: " << aci.default_bitrate_bps; + os << ", min_bitrate_bps: " << aci.min_bitrate_bps; + os << ", max_bitrate_bps: " << aci.max_bitrate_bps; + os << ", allow_comfort_noise: " << aci.allow_comfort_noise; + os << ", supports_network_adaption: " << aci.supports_network_adaption; + os << "}"; + return os; +} + +std::ostream& operator<<(std::ostream& os, const AudioCodecSpec& acs) { + os << "{format: " << acs.format; + os << ", info: " << acs.info; + os << "}"; + return os; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.h b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.h new file mode 100644 index 0000000000..12e9552e93 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/audio_format.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2016 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 API_AUDIO_CODECS_AUDIO_FORMAT_H_ +#define API_AUDIO_CODECS_AUDIO_FORMAT_H_ + +#include <map> +#include <ostream> +#include <string> +#include <utility> + +#include "api/optional.h" + +namespace webrtc { + +// SDP specification for a single audio codec. +// NOTE: This class is still under development and may change without notice. +struct SdpAudioFormat { + using Parameters = std::map<std::string, std::string>; + + SdpAudioFormat(const SdpAudioFormat&); + SdpAudioFormat(SdpAudioFormat&&); + SdpAudioFormat(const char* name, int clockrate_hz, size_t num_channels); + SdpAudioFormat(const std::string& name, + int clockrate_hz, + size_t num_channels); + SdpAudioFormat(const char* name, + int clockrate_hz, + size_t num_channels, + const Parameters& param); + SdpAudioFormat(const std::string& name, + int clockrate_hz, + size_t num_channels, + const Parameters& param); + ~SdpAudioFormat(); + + // Returns true if this format is compatible with |o|. In SDP terminology: + // would it represent the same codec between an offer and an answer? As + // opposed to operator==, this method disregards codec parameters. + bool Matches(const SdpAudioFormat& o) const; + + SdpAudioFormat& operator=(const SdpAudioFormat&); + SdpAudioFormat& operator=(SdpAudioFormat&&); + + friend bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b); + friend bool operator!=(const SdpAudioFormat& a, const SdpAudioFormat& b) { + return !(a == b); + } + + std::string name; + int clockrate_hz; + size_t num_channels; + Parameters parameters; +}; + +void swap(SdpAudioFormat& a, SdpAudioFormat& b); +std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf); + +// Information about how an audio format is treated by the codec implementation. +// Contains basic information, such as sample rate and number of channels, which +// isn't uniformly presented by SDP. Also contains flags indicating support for +// integrating with other parts of WebRTC, like external VAD and comfort noise +// level calculation. +// +// To avoid API breakage, and make the code clearer, AudioCodecInfo should not +// be directly initializable with any flags indicating optional support. If it +// were, these initializers would break any time a new flag was added. It's also +// more difficult to understand: +// AudioCodecInfo info{16000, 1, 32000, true, false, false, true, true}; +// than +// AudioCodecInfo info(16000, 1, 32000); +// info.allow_comfort_noise = true; +// info.future_flag_b = true; +// info.future_flag_c = true; +struct AudioCodecInfo { + AudioCodecInfo(int sample_rate_hz, size_t num_channels, int bitrate_bps); + AudioCodecInfo(int sample_rate_hz, + size_t num_channels, + int default_bitrate_bps, + int min_bitrate_bps, + int max_bitrate_bps); + AudioCodecInfo(const AudioCodecInfo& b) = default; + ~AudioCodecInfo() = default; + + bool operator==(const AudioCodecInfo& b) const { + return sample_rate_hz == b.sample_rate_hz && + num_channels == b.num_channels && + default_bitrate_bps == b.default_bitrate_bps && + min_bitrate_bps == b.min_bitrate_bps && + max_bitrate_bps == b.max_bitrate_bps && + allow_comfort_noise == b.allow_comfort_noise && + supports_network_adaption == b.supports_network_adaption; + } + + bool operator!=(const AudioCodecInfo& b) const { return !(*this == b); } + + bool HasFixedBitrate() const { + RTC_DCHECK_GE(min_bitrate_bps, 0); + RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps); + RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps); + return min_bitrate_bps == max_bitrate_bps; + } + + int sample_rate_hz; + size_t num_channels; + int default_bitrate_bps; + int min_bitrate_bps; + int max_bitrate_bps; + + bool allow_comfort_noise = true; // This codec can be used with an external + // comfort noise generator. + bool supports_network_adaption = false; // This codec can adapt to varying + // network conditions. +}; + +std::ostream& operator<<(std::ostream& os, const AudioCodecInfo& aci); + +// AudioCodecSpec ties an audio format to specific information about the codec +// and its implementation. +struct AudioCodecSpec { + bool operator==(const AudioCodecSpec& b) const { + return format == b.format && info == b.info; + } + + bool operator!=(const AudioCodecSpec& b) const { return !(*this == b); } + + SdpAudioFormat format; + AudioCodecInfo info; +}; + +std::ostream& operator<<(std::ostream& os, const AudioCodecSpec& acs); + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_AUDIO_FORMAT_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc new file mode 100644 index 0000000000..9520d2a9e7 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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 "api/audio_codecs/builtin_audio_decoder_factory.h" + +#include <memory> +#include <vector> + +#include "api/audio_codecs/L16/audio_decoder_L16.h" +#include "api/audio_codecs/audio_decoder_factory_template.h" +#include "api/audio_codecs/g711/audio_decoder_g711.h" +#include "api/audio_codecs/g722/audio_decoder_g722.h" +#if WEBRTC_USE_BUILTIN_ILBC +#include "api/audio_codecs/ilbc/audio_decoder_ilbc.h" // nogncheck +#endif +#include "api/audio_codecs/isac/audio_decoder_isac.h" +#if WEBRTC_USE_BUILTIN_OPUS +#include "api/audio_codecs/opus/audio_decoder_opus.h" // nogncheck +#endif + +namespace webrtc { + +namespace { + +// Modify an audio decoder to not advertise support for anything. +template <typename T> +struct NotAdvertised { + using Config = typename T::Config; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format) { + return T::SdpToConfig(audio_format); + } + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) { + // Don't advertise support for anything. + } + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const Config& config) { + return T::MakeAudioDecoder(config); + } +}; + +} // namespace + +rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory() { + return CreateAudioDecoderFactory< + +#if WEBRTC_USE_BUILTIN_OPUS + AudioDecoderOpus, +#endif + + AudioDecoderIsac, AudioDecoderG722, + +#if WEBRTC_USE_BUILTIN_ILBC + AudioDecoderIlbc, +#endif + + AudioDecoderG711, NotAdvertised<AudioDecoderL16>>(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.h b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.h new file mode 100644 index 0000000000..3127403e24 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 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 API_AUDIO_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_H_ +#define API_AUDIO_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_H_ + +#include "api/audio_codecs/audio_decoder_factory.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +// Creates a new factory that can create the built-in types of audio decoders. +// NOTE: This function is still under development and may change without notice. +rtc::scoped_refptr<AudioDecoderFactory> CreateBuiltinAudioDecoderFactory(); + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_BUILTIN_AUDIO_DECODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory_gn/moz.build new file mode 100644 index 0000000000..509d37789b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory_gn/moz.build @@ -0,0 +1,327 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True +DEFINES["WEBRTC_USE_BUILTIN_ILBC"] = "1" +DEFINES["WEBRTC_USE_BUILTIN_OPUS"] = "1" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_decoder_factory.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "1" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "0" + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "ppc64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +Library("builtin_audio_decoder_factory_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc new file mode 100644 index 0000000000..877f85026f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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 "api/audio_codecs/builtin_audio_encoder_factory.h" + +#include <memory> +#include <vector> + +#include "api/audio_codecs/L16/audio_encoder_L16.h" +#include "api/audio_codecs/audio_encoder_factory_template.h" +#include "api/audio_codecs/g711/audio_encoder_g711.h" +#include "api/audio_codecs/g722/audio_encoder_g722.h" +#if WEBRTC_USE_BUILTIN_ILBC +#include "api/audio_codecs/ilbc/audio_encoder_ilbc.h" // nogncheck +#endif +#include "api/audio_codecs/isac/audio_encoder_isac.h" +#if WEBRTC_USE_BUILTIN_OPUS +#include "api/audio_codecs/opus/audio_encoder_opus.h" // nogncheck +#endif + +namespace webrtc { + +namespace { + +// Modify an audio encoder to not advertise support for anything. +template <typename T> +struct NotAdvertised { + using Config = typename T::Config; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format) { + return T::SdpToConfig(audio_format); + } + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) { + // Don't advertise support for anything. + } + static AudioCodecInfo QueryAudioEncoder(const Config& config) { + return T::QueryAudioEncoder(config); + } + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config& config, + int payload_type) { + return T::MakeAudioEncoder(config, payload_type); + } +}; + +} // namespace + +rtc::scoped_refptr<AudioEncoderFactory> CreateBuiltinAudioEncoderFactory() { + return CreateAudioEncoderFactory< + +#if WEBRTC_USE_BUILTIN_OPUS + AudioEncoderOpus, +#endif + + AudioEncoderIsac, AudioEncoderG722, + +#if WEBRTC_USE_BUILTIN_ILBC + AudioEncoderIlbc, +#endif + + AudioEncoderG711, NotAdvertised<AudioEncoderL16>>(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.h b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.h new file mode 100644 index 0000000000..d37ff257e6 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 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 API_AUDIO_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_H_ +#define API_AUDIO_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_H_ + +#include "api/audio_codecs/audio_encoder_factory.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +// Creates a new factory that can create the built-in types of audio encoders. +// NOTE: This function is still under development and may change without notice. +rtc::scoped_refptr<AudioEncoderFactory> CreateBuiltinAudioEncoderFactory(); + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_BUILTIN_AUDIO_ENCODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory_gn/moz.build new file mode 100644 index 0000000000..476007a567 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory_gn/moz.build @@ -0,0 +1,327 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True +DEFINES["WEBRTC_USE_BUILTIN_ILBC"] = "1" +DEFINES["WEBRTC_USE_BUILTIN_OPUS"] = "1" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/builtin_audio_encoder_factory.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "1" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "0" + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "ppc64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +Library("builtin_audio_encoder_factory_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/BUILD.gn new file mode 100644 index 0000000000..aa86490a73 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_static_library("audio_encoder_g711") { + sources = [ + "audio_encoder_g711.cc", + "audio_encoder_g711.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:g711", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_g711") { + sources = [ + "audio_decoder_g711.cc", + "audio_decoder_g711.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:g711", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.cc new file mode 100644 index 0000000000..71d363be73 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 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 "api/audio_codecs/g711/audio_decoder_g711.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/g711/audio_decoder_pcm.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderG711::Config> AudioDecoderG711::SdpToConfig( + const SdpAudioFormat& format) { + const bool is_pcmu = STR_CASE_CMP(format.name.c_str(), "PCMU") == 0; + const bool is_pcma = STR_CASE_CMP(format.name.c_str(), "PCMA") == 0; + if (format.clockrate_hz == 8000 && format.num_channels >= 1 && + (is_pcmu || is_pcma)) { + Config config; + config.type = is_pcmu ? Config::Type::kPcmU : Config::Type::kPcmA; + config.num_channels = rtc::dchecked_cast<int>(format.num_channels); + RTC_DCHECK(config.IsOk()); + return config; + } else { + return rtc::nullopt; + } +} + +void AudioDecoderG711::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + for (const char* type : {"PCMU", "PCMA"}) { + specs->push_back({{type, 8000, 1}, {8000, 1, 64000}}); + } +} + +std::unique_ptr<AudioDecoder> AudioDecoderG711::MakeAudioDecoder( + const Config& config) { + RTC_DCHECK(config.IsOk()); + switch (config.type) { + case Config::Type::kPcmU: + return rtc::MakeUnique<AudioDecoderPcmU>(config.num_channels); + case Config::Type::kPcmA: + return rtc::MakeUnique<AudioDecoderPcmA>(config.num_channels); + default: + return nullptr; + } +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.h b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.h new file mode 100644 index 0000000000..652e23ebcf --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_G711_AUDIO_DECODER_G711_H_ +#define API_AUDIO_CODECS_G711_AUDIO_DECODER_G711_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// G711 decoder API for use as a template parameter to +// CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderG711 { + struct Config { + enum class Type { kPcmU, kPcmA }; + bool IsOk() const { + return (type == Type::kPcmU || type == Type::kPcmA) && num_channels >= 1; + } + Type type; + int num_channels; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const Config& config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_G711_AUDIO_DECODER_G711_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711_gn/moz.build new file mode 100644 index 0000000000..bd32703ebd --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_decoder_g711.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_g711_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.cc new file mode 100644 index 0000000000..7029caeaad --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.cc @@ -0,0 +1,85 @@ +/* + * Copyright (c) 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 "api/audio_codecs/g711/audio_encoder_g711.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/g711/audio_encoder_pcm.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/numerics/safe_minmax.h" +#include "rtc_base/ptr_util.h" +#include "rtc_base/string_to_number.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderG711::Config> AudioEncoderG711::SdpToConfig( + const SdpAudioFormat& format) { + const bool is_pcmu = STR_CASE_CMP(format.name.c_str(), "PCMU") == 0; + const bool is_pcma = STR_CASE_CMP(format.name.c_str(), "PCMA") == 0; + if (format.clockrate_hz == 8000 && format.num_channels >= 1 && + (is_pcmu || is_pcma)) { + Config config; + config.type = is_pcmu ? Config::Type::kPcmU : Config::Type::kPcmA; + config.num_channels = rtc::dchecked_cast<int>(format.num_channels); + config.frame_size_ms = 20; + auto ptime_iter = format.parameters.find("ptime"); + if (ptime_iter != format.parameters.end()) { + const auto ptime = rtc::StringToNumber<int>(ptime_iter->second); + if (ptime && *ptime > 0) { + config.frame_size_ms = rtc::SafeClamp(10 * (*ptime / 10), 10, 60); + } + } + RTC_DCHECK(config.IsOk()); + return config; + } else { + return rtc::nullopt; + } +} + +void AudioEncoderG711::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + for (const char* type : {"PCMU", "PCMA"}) { + specs->push_back({{type, 8000, 1}, {8000, 1, 64000}}); + } +} + +AudioCodecInfo AudioEncoderG711::QueryAudioEncoder(const Config& config) { + RTC_DCHECK(config.IsOk()); + return {8000, rtc::dchecked_cast<size_t>(config.num_channels), + 64000 * config.num_channels}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderG711::MakeAudioEncoder( + const Config& config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + switch (config.type) { + case Config::Type::kPcmU: { + AudioEncoderPcmU::Config impl_config; + impl_config.num_channels = config.num_channels; + impl_config.frame_size_ms = config.frame_size_ms; + impl_config.payload_type = payload_type; + return rtc::MakeUnique<AudioEncoderPcmU>(impl_config); + } + case Config::Type::kPcmA: { + AudioEncoderPcmA::Config impl_config; + impl_config.num_channels = config.num_channels; + impl_config.frame_size_ms = config.frame_size_ms; + impl_config.payload_type = payload_type; + return rtc::MakeUnique<AudioEncoderPcmA>(impl_config); + } + default: { return nullptr; } + } +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.h b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.h new file mode 100644 index 0000000000..ecdb9a3901 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_G711_AUDIO_ENCODER_G711_H_ +#define API_AUDIO_CODECS_G711_AUDIO_ENCODER_G711_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// G711 encoder API for use as a template parameter to +// CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderG711 { + struct Config { + enum class Type { kPcmU, kPcmA }; + bool IsOk() const { + return (type == Type::kPcmU || type == Type::kPcmA) && + frame_size_ms > 0 && frame_size_ms % 10 == 0 && num_channels >= 1; + } + Type type = Type::kPcmU; + int num_channels = 1; + int frame_size_ms = 20; + }; + static rtc::Optional<AudioEncoderG711::Config> SdpToConfig( + const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const Config& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config& config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_G711_AUDIO_ENCODER_G711_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711_gn/moz.build new file mode 100644 index 0000000000..8cbefc33f8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/g711/audio_encoder_g711.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_g711_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/BUILD.gn new file mode 100644 index 0000000000..5af7e5c223 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_source_set("audio_encoder_g722_config") { + sources = [ + "audio_encoder_g722_config.h", + ] +} + +rtc_static_library("audio_encoder_g722") { + sources = [ + "audio_encoder_g722.cc", + "audio_encoder_g722.h", + ] + deps = [ + ":audio_encoder_g722_config", + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:g722", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_g722") { + sources = [ + "audio_decoder_g722.cc", + "audio_decoder_g722.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:g722", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc new file mode 100644 index 0000000000..961b1267fe --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc @@ -0,0 +1,50 @@ +/* + * Copyright (c) 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 "api/audio_codecs/g722/audio_decoder_g722.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/g722/audio_decoder_g722.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig( + const SdpAudioFormat& format) { + return STR_CASE_CMP(format.name.c_str(), "G722") == 0 && + format.clockrate_hz == 8000 && + (format.num_channels == 1 || format.num_channels == 2) + ? rtc::Optional<Config>( + Config{rtc::dchecked_cast<int>(format.num_channels)}) + : rtc::nullopt; +} + +void AudioDecoderG722::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}}); +} + +std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder( + Config config) { + switch (config.num_channels) { + case 1: + return rtc::MakeUnique<AudioDecoderG722Impl>(); + case 2: + return rtc::MakeUnique<AudioDecoderG722StereoImpl>(); + default: + return nullptr; + } +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.h b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.h new file mode 100644 index 0000000000..fddb89aaf8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_G722_AUDIO_DECODER_G722_H_ +#define API_AUDIO_CODECS_G722_AUDIO_DECODER_G722_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// G722 decoder API for use as a template parameter to +// CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderG722 { + struct Config { + bool IsOk() const { return num_channels == 1 || num_channels == 2; } + int num_channels; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_G722_AUDIO_DECODER_G722_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722_gn/moz.build new file mode 100644 index 0000000000..7d078ee84c --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_decoder_g722.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_g722_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc new file mode 100644 index 0000000000..f8aa6162d2 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc @@ -0,0 +1,67 @@ +/* + * Copyright (c) 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 "api/audio_codecs/g722/audio_encoder_g722.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/g722/audio_encoder_g722.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/numerics/safe_minmax.h" +#include "rtc_base/ptr_util.h" +#include "rtc_base/string_to_number.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderG722Config> AudioEncoderG722::SdpToConfig( + const SdpAudioFormat& format) { + if (STR_CASE_CMP(format.name.c_str(), "g722") != 0 || + format.clockrate_hz != 8000) { + return rtc::nullopt; + } + + AudioEncoderG722Config config; + config.num_channels = rtc::checked_cast<int>(format.num_channels); + auto ptime_iter = format.parameters.find("ptime"); + if (ptime_iter != format.parameters.end()) { + auto ptime = rtc::StringToNumber<int>(ptime_iter->second); + if (ptime && *ptime > 0) { + const int whole_packets = *ptime / 10; + config.frame_size_ms = rtc::SafeClamp<int>(whole_packets * 10, 10, 60); + } + } + return config.IsOk() ? rtc::Optional<AudioEncoderG722Config>(config) + : rtc::nullopt; +} + +void AudioEncoderG722::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + const SdpAudioFormat fmt = {"G722", 8000, 1}; + const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); + specs->push_back({fmt, info}); +} + +AudioCodecInfo AudioEncoderG722::QueryAudioEncoder( + const AudioEncoderG722Config& config) { + RTC_DCHECK(config.IsOk()); + return {16000, rtc::dchecked_cast<size_t>(config.num_channels), + 64000 * config.num_channels}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderG722::MakeAudioEncoder( + const AudioEncoderG722Config& config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + return rtc::MakeUnique<AudioEncoderG722Impl>(config, payload_type); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.h b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.h new file mode 100644 index 0000000000..6c8b689894 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_H_ +#define API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/audio_codecs/g722/audio_encoder_g722_config.h" +#include "api/optional.h" + +namespace webrtc { + +// G722 encoder API for use as a template parameter to +// CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderG722 { + static rtc::Optional<AudioEncoderG722Config> SdpToConfig( + const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const AudioEncoderG722Config& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder( + const AudioEncoderG722Config& config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config.h b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config.h new file mode 100644 index 0000000000..773e430ce3 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_CONFIG_H_ +#define API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_CONFIG_H_ + +namespace webrtc { + +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderG722Config { + bool IsOk() const { + return frame_size_ms > 0 && frame_size_ms % 10 == 0 && num_channels >= 1; + } + int frame_size_ms = 20; + int num_channels = 1; +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_G722_AUDIO_ENCODER_G722_CONFIG_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config_gn/moz.build new file mode 100644 index 0000000000..a11371141d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_config_gn/moz.build @@ -0,0 +1,171 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("audio_encoder_g722_config_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_gn/moz.build new file mode 100644 index 0000000000..b3abcc533a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/g722/audio_encoder_g722.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_g722_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/BUILD.gn new file mode 100644 index 0000000000..0f5f80dfe2 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_source_set("audio_encoder_ilbc_config") { + sources = [ + "audio_encoder_ilbc_config.h", + ] +} + +rtc_static_library("audio_encoder_ilbc") { + sources = [ + "audio_encoder_ilbc.cc", + "audio_encoder_ilbc.h", + ] + deps = [ + ":audio_encoder_ilbc_config", + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:ilbc", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_ilbc") { + sources = [ + "audio_decoder_ilbc.cc", + "audio_decoder_ilbc.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:ilbc", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc new file mode 100644 index 0000000000..2ffae480ca --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 "api/audio_codecs/ilbc/audio_decoder_ilbc.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/ilbc/audio_decoder_ilbc.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderIlbc::Config> AudioDecoderIlbc::SdpToConfig( + const SdpAudioFormat& format) { + return STR_CASE_CMP(format.name.c_str(), "ILBC") == 0 && + format.clockrate_hz == 8000 && format.num_channels == 1 + ? rtc::Optional<Config>(Config()) + : rtc::nullopt; +} + +void AudioDecoderIlbc::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + specs->push_back({{"ILBC", 8000, 1}, {8000, 1, 13300}}); +} + +std::unique_ptr<AudioDecoder> AudioDecoderIlbc::MakeAudioDecoder( + Config config) { + return rtc::MakeUnique<AudioDecoderIlbcImpl>(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.h b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.h new file mode 100644 index 0000000000..f7292d60c6 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ILBC_AUDIO_DECODER_ILBC_H_ +#define API_AUDIO_CODECS_ILBC_AUDIO_DECODER_ILBC_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// ILBC decoder API for use as a template parameter to +// CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderIlbc { + struct Config {}; // Empty---no config values needed! + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ILBC_AUDIO_DECODER_ILBC_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc_gn/moz.build new file mode 100644 index 0000000000..ea9d174d0e --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc_gn/moz.build @@ -0,0 +1,225 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_decoder_ilbc.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_ilbc_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.cc new file mode 100644 index 0000000000..a7c68ffcf0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.cc @@ -0,0 +1,81 @@ +/* + * Copyright (c) 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 "api/audio_codecs/ilbc/audio_encoder_ilbc.h" + +#include <memory> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.h" +#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/numerics/safe_minmax.h" +#include "rtc_base/ptr_util.h" +#include "rtc_base/string_to_number.h" + +namespace webrtc { +namespace { +int GetIlbcBitrate(int ptime) { + switch (ptime) { + case 20: + case 40: + // 38 bytes per frame of 20 ms => 15200 bits/s. + return 15200; + case 30: + case 60: + // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. + return 13333; + default: + FATAL(); + } +} +} // namespace + +rtc::Optional<AudioEncoderIlbcConfig> AudioEncoderIlbc::SdpToConfig( + const SdpAudioFormat& format) { + if (STR_CASE_CMP(format.name.c_str(), "ILBC") != 0 || + format.clockrate_hz != 8000 || format.num_channels != 1) { + return rtc::nullopt; + } + + AudioEncoderIlbcConfig config; + auto ptime_iter = format.parameters.find("ptime"); + if (ptime_iter != format.parameters.end()) { + auto ptime = rtc::StringToNumber<int>(ptime_iter->second); + if (ptime && *ptime > 0) { + const int whole_packets = *ptime / 10; + config.frame_size_ms = rtc::SafeClamp<int>(whole_packets * 10, 20, 60); + } + } + return config.IsOk() ? rtc::Optional<AudioEncoderIlbcConfig>(config) + : rtc::nullopt; +} + +void AudioEncoderIlbc::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + const SdpAudioFormat fmt = {"ILBC", 8000, 1}; + const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); + specs->push_back({fmt, info}); +} + +AudioCodecInfo AudioEncoderIlbc::QueryAudioEncoder( + const AudioEncoderIlbcConfig& config) { + RTC_DCHECK(config.IsOk()); + return {8000, 1, GetIlbcBitrate(config.frame_size_ms)}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderIlbc::MakeAudioEncoder( + const AudioEncoderIlbcConfig& config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + return rtc::MakeUnique<AudioEncoderIlbcImpl>(config, payload_type); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h new file mode 100644 index 0000000000..22c7a67071 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_H_ +#define API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/audio_codecs/ilbc/audio_encoder_ilbc_config.h" +#include "api/optional.h" + +namespace webrtc { + +// ILBC encoder API for use as a template parameter to +// CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderIlbc { + static rtc::Optional<AudioEncoderIlbcConfig> SdpToConfig( + const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const AudioEncoderIlbcConfig& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder( + const AudioEncoderIlbcConfig& config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config.h b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config.h new file mode 100644 index 0000000000..22909a957b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_CONFIG_H_ +#define API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_CONFIG_H_ + +namespace webrtc { + +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderIlbcConfig { + bool IsOk() const { + return (frame_size_ms == 20 || frame_size_ms == 30 || frame_size_ms == 40 || + frame_size_ms == 60); + } + int frame_size_ms = 30; // Valid values are 20, 30, 40, and 60 ms. + // Note that frame size 40 ms produces encodings with two 20 ms frames in + // them, and frame size 60 ms consists of two 30 ms frames. +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ILBC_AUDIO_ENCODER_ILBC_CONFIG_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config_gn/moz.build new file mode 100644 index 0000000000..d9c0c40418 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_config_gn/moz.build @@ -0,0 +1,171 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("audio_encoder_ilbc_config_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_gn/moz.build new file mode 100644 index 0000000000..6cf9fd4419 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc_gn/moz.build @@ -0,0 +1,225 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_ilbc_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/BUILD.gn new file mode 100644 index 0000000000..5bd477d1d7 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/BUILD.gn @@ -0,0 +1,121 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +# The targets with _fix and _float suffixes unconditionally use the +# fixed-point and floating-point iSAC implementations, respectively. +# The targets without suffixes pick one of the implementations based +# on cleverly chosen criteria. + +rtc_source_set("audio_encoder_isac") { + public = [ + "audio_encoder_isac.h", + ] + public_configs = [ ":isac_config" ] + if (current_cpu == "arm") { + deps = [ + ":audio_encoder_isac_fix", + ] + } else { + deps = [ + ":audio_encoder_isac_float", + ] + } +} + +rtc_source_set("audio_decoder_isac") { + public = [ + "audio_decoder_isac.h", + ] + public_configs = [ ":isac_config" ] + if (current_cpu == "arm") { + deps = [ + ":audio_decoder_isac_fix", + ] + } else { + deps = [ + ":audio_decoder_isac_float", + ] + } +} + +config("isac_config") { + visibility = [ ":*" ] + if (current_cpu == "arm") { + defines = [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=1", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=0", + ] + } else { + defines = [ + "WEBRTC_USE_BUILTIN_ISAC_FIX=0", + "WEBRTC_USE_BUILTIN_ISAC_FLOAT=1", + ] + } +} + +rtc_static_library("audio_encoder_isac_fix") { + sources = [ + "audio_encoder_isac_fix.cc", + "audio_encoder_isac_fix.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:isac_fix", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_isac_fix") { + sources = [ + "audio_decoder_isac_fix.cc", + "audio_decoder_isac_fix.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:isac_fix", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_encoder_isac_float") { + sources = [ + "audio_encoder_isac_float.cc", + "audio_encoder_isac_float.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:isac", + "../../../rtc_base:rtc_base_approved", + ] +} + +rtc_static_library("audio_decoder_isac_float") { + sources = [ + "audio_decoder_isac_float.cc", + "audio_decoder_isac_float.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:isac", + "../../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac.h new file mode 100644 index 0000000000..f4e9331282 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_H_ + +#if WEBRTC_USE_BUILTIN_ISAC_FIX && !WEBRTC_USE_BUILTIN_ISAC_FLOAT +#include "api/audio_codecs/isac/audio_decoder_isac_fix.h" // nogncheck +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT && !WEBRTC_USE_BUILTIN_ISAC_FIX +#include "api/audio_codecs/isac/audio_decoder_isac_float.h" // nogncheck +#else +#error "Must choose either fix or float" +#endif + +namespace webrtc { + +#if WEBRTC_USE_BUILTIN_ISAC_FIX +using AudioDecoderIsac = AudioDecoderIsacFix; +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT +using AudioDecoderIsac = AudioDecoderIsacFloat; +#endif + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.cc new file mode 100644 index 0000000000..011be4f24a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 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 "api/audio_codecs/isac/audio_decoder_isac_fix.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/isac/fix/include/audio_decoder_isacfix.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderIsacFix::Config> AudioDecoderIsacFix::SdpToConfig( + const SdpAudioFormat& format) { + return STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 && + format.clockrate_hz == 16000 && format.num_channels == 1 + ? rtc::Optional<Config>(Config()) + : rtc::nullopt; +} + +void AudioDecoderIsacFix::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + specs->push_back({{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}}); +} + +std::unique_ptr<AudioDecoder> AudioDecoderIsacFix::MakeAudioDecoder( + Config config) { + return rtc::MakeUnique<AudioDecoderIsacFixImpl>(16000); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.h new file mode 100644 index 0000000000..f3d210eb84 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FIX_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FIX_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// iSAC decoder API (fixed-point implementation) for use as a template +// parameter to CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderIsacFix { + struct Config {}; // Empty---no config values needed! + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FIX_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix_gn/moz.build new file mode 100644 index 0000000000..62e4b4206c --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix_gn/moz.build @@ -0,0 +1,112 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +CXXFLAGS += [ + "-mfpu=neon" +] + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ARCH_ARM"] = True +DEFINES["WEBRTC_ARCH_ARM_V7"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_HAS_NEON"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_POSIX"] = True +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True +DEFINES["_FILE_OFFSET_BITS"] = "64" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/", + "/third_party/libwebrtc/webrtc/modules/audio_coding/codecs/isac/fix/include/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_fix.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +Library("audio_decoder_isac_fix_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.cc new file mode 100644 index 0000000000..65ad6ac15d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.cc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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 "api/audio_codecs/isac/audio_decoder_isac_float.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/isac/main/include/audio_decoder_isac.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderIsacFloat::Config> AudioDecoderIsacFloat::SdpToConfig( + const SdpAudioFormat& format) { + if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 && + (format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && + format.num_channels == 1) { + Config config; + config.sample_rate_hz = format.clockrate_hz; + return config; + } else { + return rtc::nullopt; + } +} + +void AudioDecoderIsacFloat::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + specs->push_back({{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}}); + specs->push_back({{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}}); +} + +std::unique_ptr<AudioDecoder> AudioDecoderIsacFloat::MakeAudioDecoder( + Config config) { + RTC_DCHECK(config.IsOk()); + return rtc::MakeUnique<AudioDecoderIsacFloatImpl>(config.sample_rate_hz); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.h new file mode 100644 index 0000000000..1decd5af3d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// iSAC decoder API (floating-point implementation) for use as a template +// parameter to CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderIsacFloat { + struct Config { + bool IsOk() const { + return sample_rate_hz == 16000 || sample_rate_hz == 32000; + } + int sample_rate_hz = 16000; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_DECODER_ISAC_FLOAT_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float_gn/moz.build new file mode 100644 index 0000000000..2ce2b8c24d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/", + "/third_party/libwebrtc/webrtc/modules/audio_coding/codecs/isac/main/include/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_float.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "m", + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_isac_float_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_gn/moz.build new file mode 100644 index 0000000000..0688f8e402 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_decoder_isac_gn/moz.build @@ -0,0 +1,297 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "1" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "0" + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "ppc64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +Library("audio_decoder_isac_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac.h new file mode 100644 index 0000000000..3cb0a1f053 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_H_ + +#if WEBRTC_USE_BUILTIN_ISAC_FIX && !WEBRTC_USE_BUILTIN_ISAC_FLOAT +#include "api/audio_codecs/isac/audio_encoder_isac_fix.h" // nogncheck +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT && !WEBRTC_USE_BUILTIN_ISAC_FIX +#include "api/audio_codecs/isac/audio_encoder_isac_float.h" // nogncheck +#else +#error "Must choose either fix or float" +#endif + +namespace webrtc { + +#if WEBRTC_USE_BUILTIN_ISAC_FIX +using AudioEncoderIsac = AudioEncoderIsacFix; +#elif WEBRTC_USE_BUILTIN_ISAC_FLOAT +using AudioEncoderIsac = AudioEncoderIsacFloat; +#endif + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.cc new file mode 100644 index 0000000000..17c1a761b8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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 "api/audio_codecs/isac/audio_encoder_isac_fix.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/isac/fix/include/audio_encoder_isacfix.h" +#include "rtc_base/ptr_util.h" +#include "rtc_base/string_to_number.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderIsacFix::Config> AudioEncoderIsacFix::SdpToConfig( + const SdpAudioFormat& format) { + if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 && + format.clockrate_hz == 16000 && format.num_channels == 1) { + Config config; + const auto ptime_iter = format.parameters.find("ptime"); + if (ptime_iter != format.parameters.end()) { + const auto ptime = rtc::StringToNumber<int>(ptime_iter->second); + if (ptime && *ptime >= 60) { + config.frame_size_ms = 60; + } + } + return config; + } else { + return rtc::nullopt; + } +} + +void AudioEncoderIsacFix::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + const SdpAudioFormat fmt = {"ISAC", 16000, 1}; + const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); + specs->push_back({fmt, info}); +} + +AudioCodecInfo AudioEncoderIsacFix::QueryAudioEncoder( + AudioEncoderIsacFix::Config config) { + RTC_DCHECK(config.IsOk()); + return {16000, 1, 32000, 10000, 32000}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderIsacFix::MakeAudioEncoder( + AudioEncoderIsacFix::Config config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + AudioEncoderIsacFixImpl::Config c; + c.frame_size_ms = config.frame_size_ms; + c.payload_type = payload_type; + return rtc::MakeUnique<AudioEncoderIsacFixImpl>(c); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.h new file mode 100644 index 0000000000..5970c02534 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FIX_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FIX_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// iSAC encoder API (fixed-point implementation) for use as a template +// parameter to CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderIsacFix { + struct Config { + bool IsOk() const { return frame_size_ms == 30 || frame_size_ms == 60; } + int frame_size_ms = 30; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(Config config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(Config config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FIX_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix_gn/moz.build new file mode 100644 index 0000000000..221ff2b74f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix_gn/moz.build @@ -0,0 +1,112 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +CXXFLAGS += [ + "-mfpu=neon" +] + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ARCH_ARM"] = True +DEFINES["WEBRTC_ARCH_ARM_V7"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_HAS_NEON"] = True +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_POSIX"] = True +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True +DEFINES["_FILE_OFFSET_BITS"] = "64" + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/", + "/third_party/libwebrtc/webrtc/modules/audio_coding/codecs/isac/fix/include/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_fix.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +Library("audio_encoder_isac_fix_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.cc new file mode 100644 index 0000000000..bdfbcfbebc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.cc @@ -0,0 +1,73 @@ +/* + * Copyright (c) 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 "api/audio_codecs/isac/audio_encoder_isac_float.h" + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" +#include "rtc_base/ptr_util.h" +#include "rtc_base/string_to_number.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderIsacFloat::Config> AudioEncoderIsacFloat::SdpToConfig( + const SdpAudioFormat& format) { + if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 && + (format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && + format.num_channels == 1) { + Config config; + config.sample_rate_hz = format.clockrate_hz; + if (config.sample_rate_hz == 16000) { + // For sample rate 16 kHz, optionally use 60 ms frames, instead of the + // default 30 ms. + const auto ptime_iter = format.parameters.find("ptime"); + if (ptime_iter != format.parameters.end()) { + const auto ptime = rtc::StringToNumber<int>(ptime_iter->second); + if (ptime && *ptime >= 60) { + config.frame_size_ms = 60; + } + } + } + return config; + } else { + return rtc::nullopt; + } +} + +void AudioEncoderIsacFloat::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + for (int sample_rate_hz : {16000, 32000}) { + const SdpAudioFormat fmt = {"ISAC", sample_rate_hz, 1}; + const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); + specs->push_back({fmt, info}); + } +} + +AudioCodecInfo AudioEncoderIsacFloat::QueryAudioEncoder( + const AudioEncoderIsacFloat::Config& config) { + RTC_DCHECK(config.IsOk()); + constexpr int min_bitrate = 10000; + const int max_bitrate = config.sample_rate_hz == 16000 ? 32000 : 56000; + const int default_bitrate = max_bitrate; + return {config.sample_rate_hz, 1, default_bitrate, min_bitrate, max_bitrate}; +} + +std::unique_ptr<AudioEncoder> AudioEncoderIsacFloat::MakeAudioEncoder( + const AudioEncoderIsacFloat::Config& config, + int payload_type) { + RTC_DCHECK(config.IsOk()); + AudioEncoderIsacFloatImpl::Config c; + c.sample_rate_hz = config.sample_rate_hz; + c.frame_size_ms = config.frame_size_ms; + c.payload_type = payload_type; + return rtc::MakeUnique<AudioEncoderIsacFloatImpl>(c); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.h b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.h new file mode 100644 index 0000000000..f14c2a25f5 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_ +#define API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// iSAC encoder API (floating-point implementation) for use as a template +// parameter to CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderIsacFloat { + struct Config { + bool IsOk() const { + return (sample_rate_hz == 16000 && + (frame_size_ms == 30 || frame_size_ms == 60)) || + (sample_rate_hz == 32000 && frame_size_ms == 30); + } + int sample_rate_hz = 16000; + int frame_size_ms = 30; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const Config& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const Config& config, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_ISAC_AUDIO_ENCODER_ISAC_FLOAT_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float_gn/moz.build new file mode 100644 index 0000000000..e59b8ce567 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/", + "/third_party/libwebrtc/webrtc/modules/audio_coding/codecs/isac/main/include/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_float.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "m", + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_isac_float_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_gn/moz.build new file mode 100644 index 0000000000..e377f807f0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/isac/audio_encoder_isac_gn/moz.build @@ -0,0 +1,297 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "1" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "0" + +if CONFIG["CPU_ARCH"] == "mips64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "ppc64": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Android": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + + OS_LIBS += [ + "m" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FIX"] = "0" + DEFINES["WEBRTC_USE_BUILTIN_ISAC_FLOAT"] = "1" + +Library("audio_encoder_isac_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/BUILD.gn new file mode 100644 index 0000000000..f56737d91f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_static_library("audio_encoder_opus_config") { + sources = [ + "audio_encoder_opus_config.cc", + "audio_encoder_opus_config.h", + ] + deps = [ + "../..:optional", + "../../../rtc_base:rtc_base_approved", + ] + defines = [] + if (rtc_opus_variable_complexity) { + defines += [ "WEBRTC_OPUS_VARIABLE_COMPLEXITY=1" ] + } else { + defines += [ "WEBRTC_OPUS_VARIABLE_COMPLEXITY=0" ] + } + + if (build_with_mozilla) { + include_dirs = [ "/media/libopus/include" ] + } +} + +rtc_source_set("audio_encoder_opus") { + public = [ + "audio_encoder_opus.h", + ] + sources = [ + "audio_encoder_opus.cc", + ] + deps = [ + ":audio_encoder_opus_config", + "..:audio_codecs_api", + "../..:optional", + "../../../modules/audio_coding:webrtc_opus", + "../../../rtc_base:rtc_base_approved", + ] + public_deps = [ + # TODO(kwiberg): Remove this public_dep when bug 7847 has been fixed. + "../../../rtc_base:protobuf_utils", + ] + + if (build_with_mozilla) { + include_dirs = [ "/media/libopus/include" ] + } +} + +rtc_static_library("audio_decoder_opus") { + sources = [ + "audio_decoder_opus.cc", + "audio_decoder_opus.h", + ] + deps = [ + "..:audio_codecs_api", + "../..:optional", + "../../..:webrtc_common", + "../../../modules/audio_coding:webrtc_opus", + "../../../rtc_base:rtc_base_approved", + ] + + if (build_with_mozilla) { + include_dirs = [ "/media/libopus/include" ] + } +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.cc new file mode 100644 index 0000000000..472a079435 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.cc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 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 "api/audio_codecs/opus/audio_decoder_opus.h" + +#include <memory> +#include <utility> +#include <vector> + +#include "common_types.h" // NOLINT(build/include) +#include "modules/audio_coding/codecs/opus/audio_decoder_opus.h" +#include "rtc_base/ptr_util.h" + +namespace webrtc { + +rtc::Optional<AudioDecoderOpus::Config> AudioDecoderOpus::SdpToConfig( + const SdpAudioFormat& format) { + const auto num_channels = [&]() -> rtc::Optional<int> { + auto stereo = format.parameters.find("stereo"); + if (stereo != format.parameters.end()) { + if (stereo->second == "0") { + return 1; + } else if (stereo->second == "1") { + return 2; + } else { + return rtc::nullopt; // Bad stereo parameter. + } + } + return 1; // Default to mono. + }(); + if (STR_CASE_CMP(format.name.c_str(), "opus") == 0 && + format.clockrate_hz == 48000 && format.num_channels == 2 && + num_channels) { + return Config{*num_channels}; + } else { + return rtc::nullopt; + } +} + +void AudioDecoderOpus::AppendSupportedDecoders( + std::vector<AudioCodecSpec>* specs) { + AudioCodecInfo opus_info{48000, 1, 64000, 6000, 510000}; + opus_info.allow_comfort_noise = false; + opus_info.supports_network_adaption = true; + SdpAudioFormat opus_format( + {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}); + specs->push_back({std::move(opus_format), std::move(opus_info)}); +} + +std::unique_ptr<AudioDecoder> AudioDecoderOpus::MakeAudioDecoder( + Config config) { + return rtc::MakeUnique<AudioDecoderOpusImpl>(config.num_channels); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.h b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.h new file mode 100644 index 0000000000..0cd917f04b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_OPUS_AUDIO_DECODER_OPUS_H_ +#define API_AUDIO_CODECS_OPUS_AUDIO_DECODER_OPUS_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_decoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/optional.h" + +namespace webrtc { + +// Opus decoder API for use as a template parameter to +// CreateAudioDecoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioDecoderOpus { + struct Config { + int num_channels; + }; + static rtc::Optional<Config> SdpToConfig(const SdpAudioFormat& audio_format); + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs); + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(Config config); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_OPUS_AUDIO_DECODER_OPUS_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus_gn/moz.build new file mode 100644 index 0000000000..c11ceaa813 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus_gn/moz.build @@ -0,0 +1,226 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libopus/include/", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_decoder_opus.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_decoder_opus_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.cc new file mode 100644 index 0000000000..603da6f223 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.cc @@ -0,0 +1,38 @@ +/* + * Copyright (c) 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 "api/audio_codecs/opus/audio_encoder_opus.h" + +#include "modules/audio_coding/codecs/opus/audio_encoder_opus.h" + +namespace webrtc { + +rtc::Optional<AudioEncoderOpusConfig> AudioEncoderOpus::SdpToConfig( + const SdpAudioFormat& format) { + return AudioEncoderOpusImpl::SdpToConfig(format); +} + +void AudioEncoderOpus::AppendSupportedEncoders( + std::vector<AudioCodecSpec>* specs) { + AudioEncoderOpusImpl::AppendSupportedEncoders(specs); +} + +AudioCodecInfo AudioEncoderOpus::QueryAudioEncoder( + const AudioEncoderOpusConfig& config) { + return AudioEncoderOpusImpl::QueryAudioEncoder(config); +} + +std::unique_ptr<AudioEncoder> AudioEncoderOpus::MakeAudioEncoder( + const AudioEncoderOpusConfig& config, + int payload_type) { + return AudioEncoderOpusImpl::MakeAudioEncoder(config, payload_type); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.h b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.h new file mode 100644 index 0000000000..d348a17897 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ +#define API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ + +#include <memory> +#include <vector> + +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/audio_codecs/opus/audio_encoder_opus_config.h" +#include "api/optional.h" + +namespace webrtc { + +// Opus encoder API for use as a template parameter to +// CreateAudioEncoderFactory<...>(). +// +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderOpus { + using Config = AudioEncoderOpusConfig; + static rtc::Optional<AudioEncoderOpusConfig> SdpToConfig( + const SdpAudioFormat& audio_format); + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs); + static AudioCodecInfo QueryAudioEncoder(const AudioEncoderOpusConfig& config); + static std::unique_ptr<AudioEncoder> MakeAudioEncoder( + const AudioEncoderOpusConfig&, + int payload_type); +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.cc new file mode 100644 index 0000000000..301c25695d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.cc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 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 "api/audio_codecs/opus/audio_encoder_opus_config.h" + +namespace webrtc { + +namespace { + +#if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) || defined(WEBRTC_ARCH_ARM) +// If we are on Android, iOS and/or ARM, use a lower complexity setting by +// default, to save encoder complexity. +constexpr int kDefaultComplexity = 5; +#else +constexpr int kDefaultComplexity = 9; +#endif + +constexpr int kDefaultLowRateComplexity = + WEBRTC_OPUS_VARIABLE_COMPLEXITY ? 9 : kDefaultComplexity; + +} // namespace + +constexpr int AudioEncoderOpusConfig::kDefaultFrameSizeMs; +constexpr int AudioEncoderOpusConfig::kMinBitrateBps; +constexpr int AudioEncoderOpusConfig::kMaxBitrateBps; + +AudioEncoderOpusConfig::AudioEncoderOpusConfig() + : frame_size_ms(kDefaultFrameSizeMs), + num_channels(1), + application(ApplicationMode::kVoip), + bitrate_bps(32000), + fec_enabled(false), + cbr_enabled(false), + max_playback_rate_hz(48000), + complexity(kDefaultComplexity), + low_rate_complexity(kDefaultLowRateComplexity), + complexity_threshold_bps(12500), + complexity_threshold_window_bps(1500), + dtx_enabled(false), + uplink_bandwidth_update_interval_ms(200), + payload_type(-1) {} +AudioEncoderOpusConfig::AudioEncoderOpusConfig(const AudioEncoderOpusConfig&) = + default; +AudioEncoderOpusConfig::~AudioEncoderOpusConfig() = default; +AudioEncoderOpusConfig& AudioEncoderOpusConfig::operator=( + const AudioEncoderOpusConfig&) = default; + +bool AudioEncoderOpusConfig::IsOk() const { + if (frame_size_ms <= 0 || frame_size_ms % 10 != 0) + return false; + if (num_channels != 1 && num_channels != 2) + return false; + if (!bitrate_bps) + return false; + if (*bitrate_bps < kMinBitrateBps || *bitrate_bps > kMaxBitrateBps) + return false; + if (complexity < 0 || complexity > 10) + return false; + if (low_rate_complexity < 0 || low_rate_complexity > 10) + return false; + return true; +} +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.h b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.h new file mode 100644 index 0000000000..d586592ab0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 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 API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_CONFIG_H_ +#define API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_CONFIG_H_ + +#include <stddef.h> + +#include <vector> + +#include "api/optional.h" + +namespace webrtc { + +// NOTE: This struct is still under development and may change without notice. +struct AudioEncoderOpusConfig { + static constexpr int kDefaultFrameSizeMs = 20; + + // Opus API allows a min bitrate of 500bps, but Opus documentation suggests + // bitrate should be in the range of 6000 to 510000, inclusive. + static constexpr int kMinBitrateBps = 6000; + static constexpr int kMaxBitrateBps = 510000; + + AudioEncoderOpusConfig(); + AudioEncoderOpusConfig(const AudioEncoderOpusConfig&); + ~AudioEncoderOpusConfig(); + AudioEncoderOpusConfig& operator=(const AudioEncoderOpusConfig&); + + bool IsOk() const; // Checks if the values are currently OK. + + int frame_size_ms; + size_t num_channels; + enum class ApplicationMode { kVoip, kAudio }; + ApplicationMode application; + + // NOTE: This member must always be set. + // TODO(kwiberg): Turn it into just an int. + rtc::Optional<int> bitrate_bps; + + bool fec_enabled; + bool cbr_enabled; + int max_playback_rate_hz; + + // |complexity| is used when the bitrate goes above + // |complexity_threshold_bps| + |complexity_threshold_window_bps|; + // |low_rate_complexity| is used when the bitrate falls below + // |complexity_threshold_bps| - |complexity_threshold_window_bps|. In the + // interval in the middle, we keep using the most recent of the two + // complexity settings. + int complexity; + int low_rate_complexity; + int complexity_threshold_bps; + int complexity_threshold_window_bps; + + bool dtx_enabled; + std::vector<int> supported_frame_lengths_ms; + int uplink_bandwidth_update_interval_ms; + + // NOTE: This member isn't necessary, and will soon go away. See + // https://bugs.chromium.org/p/webrtc/issues/detail?id=7847 + int payload_type; +}; + +} // namespace webrtc + +#endif // API_AUDIO_CODECS_OPUS_AUDIO_ENCODER_OPUS_CONFIG_H_ diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config_gn/moz.build new file mode 100644 index 0000000000..25886b9c5c --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config_gn/moz.build @@ -0,0 +1,219 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_OPUS_VARIABLE_COMPLEXITY"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libopus/include/", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_config.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_opus_config_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_gn/moz.build new file mode 100644 index 0000000000..9cf03e7377 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus_gn/moz.build @@ -0,0 +1,226 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libopus/include/", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/audio_codecs/opus/audio_encoder_opus.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("audio_encoder_opus_gn") diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/test/BUILD.gn b/third_party/libwebrtc/webrtc/api/audio_codecs/test/BUILD.gn new file mode 100644 index 0000000000..0f742f57cc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/test/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 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. + +import("../../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +if (rtc_include_tests) { + rtc_source_set("audio_codecs_api_unittests") { + testonly = true + sources = [ + "audio_decoder_factory_template_unittest.cc", + "audio_encoder_factory_template_unittest.cc", + ] + deps = [ + "..:audio_codecs_api", + "../../../rtc_base:rtc_base_approved", + "../../../test:audio_codec_mocks", + "../../../test:test_support", + "../L16:audio_decoder_L16", + "../L16:audio_encoder_L16", + "../g711:audio_decoder_g711", + "../g711:audio_encoder_g711", + "../g722:audio_decoder_g722", + "../g722:audio_encoder_g722", + "../ilbc:audio_decoder_ilbc", + "../ilbc:audio_encoder_ilbc", + "../isac:audio_decoder_isac_fix", + "../isac:audio_decoder_isac_float", + "../isac:audio_encoder_isac_fix", + "../isac:audio_encoder_isac_float", + "../opus:audio_decoder_opus", + "../opus:audio_encoder_opus", + "//testing/gmock", + ] + } +} diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc new file mode 100644 index 0000000000..071b53a77c --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_decoder_factory_template_unittest.cc @@ -0,0 +1,241 @@ +/* + * Copyright (c) 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 "api/audio_codecs/audio_decoder_factory_template.h" +#include "api/audio_codecs/L16/audio_decoder_L16.h" +#include "api/audio_codecs/g711/audio_decoder_g711.h" +#include "api/audio_codecs/g722/audio_decoder_g722.h" +#include "api/audio_codecs/ilbc/audio_decoder_ilbc.h" +#include "api/audio_codecs/isac/audio_decoder_isac_fix.h" +#include "api/audio_codecs/isac/audio_decoder_isac_float.h" +#include "api/audio_codecs/opus/audio_decoder_opus.h" +#include "rtc_base/ptr_util.h" +#include "test/gmock.h" +#include "test/gtest.h" +#include "test/mock_audio_decoder.h" + +namespace webrtc { + +namespace { + +struct BogusParams { + static SdpAudioFormat AudioFormat() { return {"bogus", 8000, 1}; } + static AudioCodecInfo CodecInfo() { return {8000, 1, 12345}; } +}; + +struct ShamParams { + static SdpAudioFormat AudioFormat() { + return {"sham", 16000, 2, {{"param", "value"}}}; + } + static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; } +}; + +struct MyLittleConfig { + SdpAudioFormat audio_format; +}; + +template <typename Params> +struct AudioDecoderFakeApi { + static rtc::Optional<MyLittleConfig> SdpToConfig( + const SdpAudioFormat& audio_format) { + if (Params::AudioFormat() == audio_format) { + MyLittleConfig config = {audio_format}; + return config; + } else { + return rtc::nullopt; + } + } + + static void AppendSupportedDecoders(std::vector<AudioCodecSpec>* specs) { + specs->push_back({Params::AudioFormat(), Params::CodecInfo()}); + } + + static AudioCodecInfo QueryAudioDecoder(const MyLittleConfig&) { + return Params::CodecInfo(); + } + + static std::unique_ptr<AudioDecoder> MakeAudioDecoder(const MyLittleConfig&) { + auto dec = rtc::MakeUnique<testing::StrictMock<MockAudioDecoder>>(); + EXPECT_CALL(*dec, SampleRateHz()) + .WillOnce(testing::Return(Params::CodecInfo().sample_rate_hz)); + EXPECT_CALL(*dec, Die()); + return std::move(dec); + } +}; + +} // namespace + +TEST(AudioDecoderFactoryTemplateTest, NoDecoderTypes) { + rtc::scoped_refptr<AudioDecoderFactory> factory( + new rtc::RefCountedObject< + audio_decoder_factory_template_impl::AudioDecoderFactoryT<>>()); + EXPECT_THAT(factory->GetSupportedDecoders(), testing::IsEmpty()); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); +} + +TEST(AudioDecoderFactoryTemplateTest, OneDecoderType) { + auto factory = CreateAudioDecoderFactory<AudioDecoderFakeApi<BogusParams>>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"bogus", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); + auto dec = factory->MakeAudioDecoder({"bogus", 8000, 1}); + ASSERT_NE(nullptr, dec); + EXPECT_EQ(8000, dec->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, TwoDecoderTypes) { + auto factory = CreateAudioDecoderFactory<AudioDecoderFakeApi<BogusParams>, + AudioDecoderFakeApi<ShamParams>>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}}, + AudioCodecSpec{{"sham", 16000, 2, {{"param", "value"}}}, + {16000, 2, 23456}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"bogus", 8000, 1})); + EXPECT_TRUE( + factory->IsSupportedDecoder({"sham", 16000, 2, {{"param", "value"}}})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); + auto dec1 = factory->MakeAudioDecoder({"bogus", 8000, 1}); + ASSERT_NE(nullptr, dec1); + EXPECT_EQ(8000, dec1->SampleRateHz()); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"sham", 16000, 2})); + auto dec2 = + factory->MakeAudioDecoder({"sham", 16000, 2, {{"param", "value"}}}); + ASSERT_NE(nullptr, dec2); + EXPECT_EQ(16000, dec2->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, G711) { + auto factory = CreateAudioDecoderFactory<AudioDecoderG711>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"PCMU", 8000, 1}, {8000, 1, 64000}}, + AudioCodecSpec{{"PCMA", 8000, 1}, {8000, 1, 64000}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"G711", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"PCMU", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"pcma", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"pcmu", 16000, 1})); + auto dec1 = factory->MakeAudioDecoder({"pcmu", 8000, 1}); + ASSERT_NE(nullptr, dec1); + EXPECT_EQ(8000, dec1->SampleRateHz()); + auto dec2 = factory->MakeAudioDecoder({"PCMA", 8000, 1}); + ASSERT_NE(nullptr, dec2); + EXPECT_EQ(8000, dec2->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, G722) { + auto factory = CreateAudioDecoderFactory<AudioDecoderG722>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"G722", 8000, 1}, {16000, 1, 64000}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"G722", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); + auto dec1 = factory->MakeAudioDecoder({"G722", 8000, 1}); + ASSERT_NE(nullptr, dec1); + EXPECT_EQ(16000, dec1->SampleRateHz()); + EXPECT_EQ(1u, dec1->Channels()); + auto dec2 = factory->MakeAudioDecoder({"G722", 8000, 2}); + ASSERT_NE(nullptr, dec2); + EXPECT_EQ(16000, dec2->SampleRateHz()); + EXPECT_EQ(2u, dec2->Channels()); + auto dec3 = factory->MakeAudioDecoder({"G722", 8000, 3}); + ASSERT_EQ(nullptr, dec3); +} + +TEST(AudioDecoderFactoryTemplateTest, Ilbc) { + auto factory = CreateAudioDecoderFactory<AudioDecoderIlbc>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"ILBC", 8000, 1}, {8000, 1, 13300}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"ilbc", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 8000, 1})); + auto dec = factory->MakeAudioDecoder({"ilbc", 8000, 1}); + ASSERT_NE(nullptr, dec); + EXPECT_EQ(8000, dec->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, IsacFix) { + auto factory = CreateAudioDecoderFactory<AudioDecoderIsacFix>(); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre(AudioCodecSpec{ + {"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 16000, 2})); + EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 16000, 1})); + EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 32000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"isac", 8000, 1})); + auto dec = factory->MakeAudioDecoder({"isac", 16000, 1}); + ASSERT_NE(nullptr, dec); + EXPECT_EQ(16000, dec->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, IsacFloat) { + auto factory = CreateAudioDecoderFactory<AudioDecoderIsacFloat>(); + EXPECT_THAT( + factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}}, + AudioCodecSpec{{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"isac", 16000, 2})); + EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 16000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"isac", 32000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"isac", 8000, 1})); + auto dec1 = factory->MakeAudioDecoder({"isac", 16000, 1}); + ASSERT_NE(nullptr, dec1); + EXPECT_EQ(16000, dec1->SampleRateHz()); + auto dec2 = factory->MakeAudioDecoder({"isac", 32000, 1}); + ASSERT_NE(nullptr, dec2); + EXPECT_EQ(32000, dec2->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, L16) { + auto factory = CreateAudioDecoderFactory<AudioDecoderL16>(); + EXPECT_THAT( + factory->GetSupportedDecoders(), + testing::ElementsAre( + AudioCodecSpec{{"L16", 8000, 1}, {8000, 1, 8000 * 16}}, + AudioCodecSpec{{"L16", 16000, 1}, {16000, 1, 16000 * 16}}, + AudioCodecSpec{{"L16", 32000, 1}, {32000, 1, 32000 * 16}}, + AudioCodecSpec{{"L16", 8000, 2}, {8000, 2, 8000 * 16 * 2}}, + AudioCodecSpec{{"L16", 16000, 2}, {16000, 2, 16000 * 16 * 2}}, + AudioCodecSpec{{"L16", 32000, 2}, {32000, 2, 32000 * 16 * 2}})); + EXPECT_FALSE(factory->IsSupportedDecoder({"foo", 8000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"L16", 48000, 1})); + EXPECT_FALSE(factory->IsSupportedDecoder({"L16", 96000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"L16", 8000, 0})); + auto dec = factory->MakeAudioDecoder({"L16", 48000, 2}); + ASSERT_NE(nullptr, dec); + EXPECT_EQ(48000, dec->SampleRateHz()); +} + +TEST(AudioDecoderFactoryTemplateTest, Opus) { + auto factory = CreateAudioDecoderFactory<AudioDecoderOpus>(); + AudioCodecInfo opus_info{48000, 1, 64000, 6000, 510000}; + opus_info.allow_comfort_noise = false; + opus_info.supports_network_adaption = true; + const SdpAudioFormat opus_format( + {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}); + EXPECT_THAT(factory->GetSupportedDecoders(), + testing::ElementsAre(AudioCodecSpec{opus_format, opus_info})); + EXPECT_FALSE(factory->IsSupportedDecoder({"opus", 48000, 1})); + EXPECT_TRUE(factory->IsSupportedDecoder({"opus", 48000, 2})); + EXPECT_EQ(nullptr, factory->MakeAudioDecoder({"bar", 16000, 1})); + auto dec = factory->MakeAudioDecoder({"opus", 48000, 2}); + ASSERT_NE(nullptr, dec); + EXPECT_EQ(48000, dec->SampleRateHz()); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc b/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc new file mode 100644 index 0000000000..f6e4035088 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_codecs/test/audio_encoder_factory_template_unittest.cc @@ -0,0 +1,252 @@ +/* + * Copyright (c) 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 "api/audio_codecs/audio_encoder_factory_template.h" +#include "api/audio_codecs/L16/audio_encoder_L16.h" +#include "api/audio_codecs/g711/audio_encoder_g711.h" +#include "api/audio_codecs/g722/audio_encoder_g722.h" +#include "api/audio_codecs/ilbc/audio_encoder_ilbc.h" +#include "api/audio_codecs/isac/audio_encoder_isac_fix.h" +#include "api/audio_codecs/isac/audio_encoder_isac_float.h" +#include "api/audio_codecs/opus/audio_encoder_opus.h" +#include "rtc_base/ptr_util.h" +#include "test/gmock.h" +#include "test/gtest.h" +#include "test/mock_audio_encoder.h" + +namespace webrtc { + +namespace { + +struct BogusParams { + static SdpAudioFormat AudioFormat() { return {"bogus", 8000, 1}; } + static AudioCodecInfo CodecInfo() { return {8000, 1, 12345}; } +}; + +struct ShamParams { + static SdpAudioFormat AudioFormat() { + return {"sham", 16000, 2, {{"param", "value"}}}; + } + static AudioCodecInfo CodecInfo() { return {16000, 2, 23456}; } +}; + +struct MyLittleConfig { + SdpAudioFormat audio_format; +}; + +template <typename Params> +struct AudioEncoderFakeApi { + static rtc::Optional<MyLittleConfig> SdpToConfig( + const SdpAudioFormat& audio_format) { + if (Params::AudioFormat() == audio_format) { + MyLittleConfig config = {audio_format}; + return config; + } else { + return rtc::nullopt; + } + } + + static void AppendSupportedEncoders(std::vector<AudioCodecSpec>* specs) { + specs->push_back({Params::AudioFormat(), Params::CodecInfo()}); + } + + static AudioCodecInfo QueryAudioEncoder(const MyLittleConfig&) { + return Params::CodecInfo(); + } + + static std::unique_ptr<AudioEncoder> MakeAudioEncoder(const MyLittleConfig&, + int payload_type) { + auto enc = rtc::MakeUnique<testing::StrictMock<MockAudioEncoder>>(); + EXPECT_CALL(*enc, SampleRateHz()) + .WillOnce(testing::Return(Params::CodecInfo().sample_rate_hz)); + EXPECT_CALL(*enc, Die()); + return std::move(enc); + } +}; + +} // namespace + +TEST(AudioEncoderFactoryTemplateTest, NoEncoderTypes) { + rtc::scoped_refptr<AudioEncoderFactory> factory( + new rtc::RefCountedObject< + audio_encoder_factory_template_impl::AudioEncoderFactoryT<>>()); + EXPECT_THAT(factory->GetSupportedEncoders(), testing::IsEmpty()); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); +} + +TEST(AudioEncoderFactoryTemplateTest, OneEncoderType) { + auto factory = CreateAudioEncoderFactory<AudioEncoderFakeApi<BogusParams>>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ(AudioCodecInfo(8000, 1, 12345), + factory->QueryAudioEncoder({"bogus", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); + auto enc = factory->MakeAudioEncoder(17, {"bogus", 8000, 1}); + ASSERT_NE(nullptr, enc); + EXPECT_EQ(8000, enc->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, TwoEncoderTypes) { + auto factory = CreateAudioEncoderFactory<AudioEncoderFakeApi<BogusParams>, + AudioEncoderFakeApi<ShamParams>>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"bogus", 8000, 1}, {8000, 1, 12345}}, + AudioCodecSpec{{"sham", 16000, 2, {{"param", "value"}}}, + {16000, 2, 23456}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ(AudioCodecInfo(8000, 1, 12345), + factory->QueryAudioEncoder({"bogus", 8000, 1})); + EXPECT_EQ( + AudioCodecInfo(16000, 2, 23456), + factory->QueryAudioEncoder({"sham", 16000, 2, {{"param", "value"}}})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); + auto enc1 = factory->MakeAudioEncoder(17, {"bogus", 8000, 1}); + ASSERT_NE(nullptr, enc1); + EXPECT_EQ(8000, enc1->SampleRateHz()); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"sham", 16000, 2})); + auto enc2 = + factory->MakeAudioEncoder(17, {"sham", 16000, 2, {{"param", "value"}}}); + ASSERT_NE(nullptr, enc2); + EXPECT_EQ(16000, enc2->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, G711) { + auto factory = CreateAudioEncoderFactory<AudioEncoderG711>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"PCMU", 8000, 1}, {8000, 1, 64000}}, + AudioCodecSpec{{"PCMA", 8000, 1}, {8000, 1, 64000}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"PCMA", 16000, 1})); + EXPECT_EQ(AudioCodecInfo(8000, 1, 64000), + factory->QueryAudioEncoder({"PCMA", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"PCMU", 16000, 1})); + auto enc1 = factory->MakeAudioEncoder(17, {"PCMU", 8000, 1}); + ASSERT_NE(nullptr, enc1); + EXPECT_EQ(8000, enc1->SampleRateHz()); + auto enc2 = factory->MakeAudioEncoder(17, {"PCMA", 8000, 1}); + ASSERT_NE(nullptr, enc2); + EXPECT_EQ(8000, enc2->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, G722) { + auto factory = CreateAudioEncoderFactory<AudioEncoderG722>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"G722", 8000, 1}, {16000, 1, 64000}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ(AudioCodecInfo(16000, 1, 64000), + factory->QueryAudioEncoder({"G722", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); + auto enc = factory->MakeAudioEncoder(17, {"G722", 8000, 1}); + ASSERT_NE(nullptr, enc); + EXPECT_EQ(16000, enc->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, Ilbc) { + auto factory = CreateAudioEncoderFactory<AudioEncoderIlbc>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"ILBC", 8000, 1}, {8000, 1, 13333}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ(AudioCodecInfo(8000, 1, 13333), + factory->QueryAudioEncoder({"ilbc", 8000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 8000, 1})); + auto enc = factory->MakeAudioEncoder(17, {"ilbc", 8000, 1}); + ASSERT_NE(nullptr, enc); + EXPECT_EQ(8000, enc->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, IsacFix) { + auto factory = CreateAudioEncoderFactory<AudioEncoderIsacFix>(); + EXPECT_THAT(factory->GetSupportedEncoders(), + testing::ElementsAre(AudioCodecSpec{ + {"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"isac", 16000, 2})); + EXPECT_EQ(AudioCodecInfo(16000, 1, 32000, 10000, 32000), + factory->QueryAudioEncoder({"isac", 16000, 1})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"isac", 32000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"isac", 8000, 1})); + auto enc1 = factory->MakeAudioEncoder(17, {"isac", 16000, 1}); + ASSERT_NE(nullptr, enc1); + EXPECT_EQ(16000, enc1->SampleRateHz()); + EXPECT_EQ(3u, enc1->Num10MsFramesInNextPacket()); + auto enc2 = + factory->MakeAudioEncoder(17, {"isac", 16000, 1, {{"ptime", "60"}}}); + ASSERT_NE(nullptr, enc2); + EXPECT_EQ(6u, enc2->Num10MsFramesInNextPacket()); +} + +TEST(AudioEncoderFactoryTemplateTest, IsacFloat) { + auto factory = CreateAudioEncoderFactory<AudioEncoderIsacFloat>(); + EXPECT_THAT( + factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"ISAC", 16000, 1}, {16000, 1, 32000, 10000, 32000}}, + AudioCodecSpec{{"ISAC", 32000, 1}, {32000, 1, 56000, 10000, 56000}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"isac", 16000, 2})); + EXPECT_EQ(AudioCodecInfo(16000, 1, 32000, 10000, 32000), + factory->QueryAudioEncoder({"isac", 16000, 1})); + EXPECT_EQ(AudioCodecInfo(32000, 1, 56000, 10000, 56000), + factory->QueryAudioEncoder({"isac", 32000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"isac", 8000, 1})); + auto enc1 = factory->MakeAudioEncoder(17, {"isac", 16000, 1}); + ASSERT_NE(nullptr, enc1); + EXPECT_EQ(16000, enc1->SampleRateHz()); + auto enc2 = factory->MakeAudioEncoder(17, {"isac", 32000, 1}); + ASSERT_NE(nullptr, enc2); + EXPECT_EQ(32000, enc2->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, L16) { + auto factory = CreateAudioEncoderFactory<AudioEncoderL16>(); + EXPECT_THAT( + factory->GetSupportedEncoders(), + testing::ElementsAre( + AudioCodecSpec{{"L16", 8000, 1}, {8000, 1, 8000 * 16}}, + AudioCodecSpec{{"L16", 16000, 1}, {16000, 1, 16000 * 16}}, + AudioCodecSpec{{"L16", 32000, 1}, {32000, 1, 32000 * 16}}, + AudioCodecSpec{{"L16", 8000, 2}, {8000, 2, 8000 * 16 * 2}}, + AudioCodecSpec{{"L16", 16000, 2}, {16000, 2, 16000 * 16 * 2}}, + AudioCodecSpec{{"L16", 32000, 2}, {32000, 2, 32000 * 16 * 2}})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"L16", 8000, 0})); + EXPECT_EQ(AudioCodecInfo(48000, 1, 48000 * 16), + factory->QueryAudioEncoder({"L16", 48000, 1})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"L16", 8000, 0})); + auto enc = factory->MakeAudioEncoder(17, {"L16", 48000, 2}); + ASSERT_NE(nullptr, enc); + EXPECT_EQ(48000, enc->SampleRateHz()); +} + +TEST(AudioEncoderFactoryTemplateTest, Opus) { + auto factory = CreateAudioEncoderFactory<AudioEncoderOpus>(); + AudioCodecInfo info = {48000, 1, 32000, 6000, 510000}; + info.allow_comfort_noise = false; + info.supports_network_adaption = true; + EXPECT_THAT( + factory->GetSupportedEncoders(), + testing::ElementsAre(AudioCodecSpec{ + {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}, + info})); + EXPECT_EQ(rtc::nullopt, factory->QueryAudioEncoder({"foo", 8000, 1})); + EXPECT_EQ( + info, + factory->QueryAudioEncoder( + {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}})); + EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); + auto enc = factory->MakeAudioEncoder(17, {"opus", 48000, 2}); + ASSERT_NE(nullptr, enc); + EXPECT_EQ(48000, enc->SampleRateHz()); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/audio_mixer_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/audio_mixer_api_gn/moz.build new file mode 100644 index 0000000000..6c2be02cfc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/audio_mixer_api_gn/moz.build @@ -0,0 +1,187 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("audio_mixer_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/base_peerconnection_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/base_peerconnection_api_gn/moz.build new file mode 100644 index 0000000000..8a9147e8c8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/base_peerconnection_api_gn/moz.build @@ -0,0 +1,209 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/rtpparameters.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("base_peerconnection_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/call/audio_sink.h b/third_party/libwebrtc/webrtc/api/call/audio_sink.h new file mode 100644 index 0000000000..fa4c3f6814 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/call/audio_sink.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015 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 API_CALL_AUDIO_SINK_H_ +#define API_CALL_AUDIO_SINK_H_ + +#if defined(WEBRTC_POSIX) && !defined(__STDC_FORMAT_MACROS) +// Avoid conflict with format_macros.h. +#define __STDC_FORMAT_MACROS +#endif + +#include <inttypes.h> +#include <stddef.h> + +namespace webrtc { + +// Represents a simple push audio sink. +class AudioSinkInterface { + public: + virtual ~AudioSinkInterface() {} + + struct Data { + Data(const int16_t* data, + size_t samples_per_channel, + int sample_rate, + size_t channels, + uint32_t timestamp) + : data(data), + samples_per_channel(samples_per_channel), + sample_rate(sample_rate), + channels(channels), + timestamp(timestamp) {} + + const int16_t* data; // The actual 16bit audio data. + size_t samples_per_channel; // Number of frames in the buffer. + int sample_rate; // Sample rate in Hz. + size_t channels; // Number of channels in the audio data. + uint32_t timestamp; // The RTP timestamp of the first sample. + }; + + virtual void OnData(const Data& audio) = 0; +}; + +} // namespace webrtc + +#endif // API_CALL_AUDIO_SINK_H_ diff --git a/third_party/libwebrtc/webrtc/api/call/transport.h b/third_party/libwebrtc/webrtc/api/call/transport.h new file mode 100644 index 0000000000..1cdb0d366d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/call/transport.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013 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 API_CALL_TRANSPORT_H_ +#define API_CALL_TRANSPORT_H_ + +#include <stddef.h> +#include <stdint.h> + +namespace webrtc { + +// TODO(holmer): Look into unifying this with the PacketOptions in +// asyncpacketsocket.h. +struct PacketOptions { + // A 16 bits positive id. Negative ids are invalid and should be interpreted + // as packet_id not being set. + int packet_id = -1; +}; + +class Transport { + public: + virtual bool SendRtp(const uint8_t* packet, + size_t length, + const PacketOptions& options) = 0; + virtual bool SendRtcp(const uint8_t* packet, size_t length) = 0; + + protected: + virtual ~Transport() {} +}; + +} // namespace webrtc + +#endif // API_CALL_TRANSPORT_H_ diff --git a/third_party/libwebrtc/webrtc/api/call_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/call_api_gn/moz.build new file mode 100644 index 0000000000..1d0162e17b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/call_api_gn/moz.build @@ -0,0 +1,187 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("call_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/candidate.cc b/third_party/libwebrtc/webrtc/api/candidate.cc new file mode 100644 index 0000000000..62cd1bd135 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/candidate.cc @@ -0,0 +1,123 @@ +/* + * 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 "api/candidate.h" + +namespace cricket { + +Candidate::Candidate() + : id_(rtc::CreateRandomString(8)), + component_(0), + priority_(0), + network_type_(rtc::ADAPTER_TYPE_UNKNOWN), + generation_(0), + network_id_(0), + network_cost_(0) {} + +Candidate::Candidate(int component, + const std::string& protocol, + const rtc::SocketAddress& address, + uint32_t priority, + const std::string& username, + const std::string& password, + const std::string& type, + uint32_t generation, + const std::string& foundation, + uint16_t network_id, + uint16_t network_cost) + : id_(rtc::CreateRandomString(8)), + component_(component), + protocol_(protocol), + address_(address), + priority_(priority), + username_(username), + password_(password), + type_(type), + network_type_(rtc::ADAPTER_TYPE_UNKNOWN), + generation_(generation), + foundation_(foundation), + network_id_(network_id), + network_cost_(network_cost) {} + +Candidate::Candidate(const Candidate&) = default; + +Candidate::~Candidate() = default; + +bool Candidate::IsEquivalent(const Candidate& c) const { + // We ignore the network name, since that is just debug information, and + // the priority and the network cost, since they should be the same if the + // rest are. + return (component_ == c.component_) && (protocol_ == c.protocol_) && + (address_ == c.address_) && (username_ == c.username_) && + (password_ == c.password_) && (type_ == c.type_) && + (generation_ == c.generation_) && (foundation_ == c.foundation_) && + (related_address_ == c.related_address_) && + (network_id_ == c.network_id_); +} + +bool Candidate::MatchesForRemoval(const Candidate& c) const { + return component_ == c.component_ && protocol_ == c.protocol_ && + address_ == c.address_; +} + +std::string Candidate::ToStringInternal(bool sensitive) const { + std::ostringstream ost; + std::string address = + sensitive ? address_.ToSensitiveString() : address_.ToString(); + ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_ + << ":" << protocol_ << ":" << priority_ << ":" << address << ":" << type_ + << ":" << related_address_ << ":" << username_ << ":" << password_ << ":" + << network_id_ << ":" << network_cost_ << ":" << generation_ << "]"; + return ost.str(); +} + +uint32_t Candidate::GetPriority(uint32_t type_preference, + int network_adapter_preference, + int relay_preference) const { + // RFC 5245 - 4.1.2.1. + // priority = (2^24)*(type preference) + + // (2^8)*(local preference) + + // (2^0)*(256 - component ID) + + // |local_preference| length is 2 bytes, 0-65535 inclusive. + // In our implemenation we will partion local_preference into + // 0 1 + // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // | NIC Pref | Addr Pref | + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + // NIC Type - Type of the network adapter e.g. 3G/Wifi/Wired. + // Addr Pref - Address preference value as per RFC 3484. + // local preference = (NIC Type << 8 | Addr_Pref) - relay preference. + + int addr_pref = IPAddressPrecedence(address_.ipaddr()); + int local_preference = + ((network_adapter_preference << 8) | addr_pref) + relay_preference; + + return (type_preference << 24) | (local_preference << 8) | (256 - component_); +} + +bool Candidate::operator==(const Candidate& o) const { + return id_ == o.id_ && component_ == o.component_ && + protocol_ == o.protocol_ && relay_protocol_ == o.relay_protocol_ && + address_ == o.address_ && priority_ == o.priority_ && + username_ == o.username_ && password_ == o.password_ && + type_ == o.type_ && network_name_ == o.network_name_ && + network_type_ == o.network_type_ && generation_ == o.generation_ && + foundation_ == o.foundation_ && + related_address_ == o.related_address_ && tcptype_ == o.tcptype_ && + transport_name_ == o.transport_name_ && network_id_ == o.network_id_; +} + +bool Candidate::operator!=(const Candidate& o) const { + return !(*this == o); +} + +} // namespace cricket diff --git a/third_party/libwebrtc/webrtc/api/candidate.h b/third_party/libwebrtc/webrtc/api/candidate.h new file mode 100644 index 0000000000..a1f45c215e --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/candidate.h @@ -0,0 +1,208 @@ +/* + * Copyright 2004 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 API_CANDIDATE_H_ +#define API_CANDIDATE_H_ + +#include <limits.h> +#include <stdint.h> + +#include <algorithm> +#include <string> + +#include "rtc_base/checks.h" +#include "rtc_base/helpers.h" +#include "rtc_base/network_constants.h" +#include "rtc_base/socketaddress.h" + +namespace cricket { + +// Candidate for ICE based connection discovery. +// TODO(phoglund): remove things in here that are not needed in the public API. + +class Candidate { + public: + Candidate(); + // TODO(pthatcher): Match the ordering and param list as per RFC 5245 + // candidate-attribute syntax. http://tools.ietf.org/html/rfc5245#section-15.1 + Candidate(int component, + const std::string& protocol, + const rtc::SocketAddress& address, + uint32_t priority, + const std::string& username, + const std::string& password, + const std::string& type, + uint32_t generation, + const std::string& foundation, + uint16_t network_id = 0, + uint16_t network_cost = 0); + Candidate(const Candidate&); + ~Candidate(); + + const std::string & id() const { return id_; } + void set_id(const std::string & id) { id_ = id; } + + int component() const { return component_; } + void set_component(int component) { component_ = component; } + + const std::string & protocol() const { return protocol_; } + void set_protocol(const std::string & protocol) { protocol_ = protocol; } + + // The protocol used to talk to relay. + const std::string& relay_protocol() const { return relay_protocol_; } + void set_relay_protocol(const std::string& protocol) { + relay_protocol_ = protocol; + } + + const rtc::SocketAddress & address() const { return address_; } + void set_address(const rtc::SocketAddress & address) { + address_ = address; + } + + uint32_t priority() const { return priority_; } + void set_priority(const uint32_t priority) { priority_ = priority; } + + // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc + // doesn't use it. + // Maps old preference (which was 0.0-1.0) to match priority (which + // is 0-2^32-1) to to match RFC 5245, section 4.1.2.1. Also see + // https://docs.google.com/a/google.com/document/d/ + // 1iNQDiwDKMh0NQOrCqbj3DKKRT0Dn5_5UJYhmZO-t7Uc/edit + float preference() const { + // The preference value is clamped to two decimal precision. + return static_cast<float>(((priority_ >> 24) * 100 / 127) / 100.0); + } + + // TODO(pthatcher): Remove once Chromium's jingle/glue/utils.cc + // doesn't use it. + void set_preference(float preference) { + // Limiting priority to UINT_MAX when value exceeds uint32_t max. + // This can happen for e.g. when preference = 3. + uint64_t prio_val = static_cast<uint64_t>(preference * 127) << 24; + priority_ = static_cast<uint32_t>( + std::min(prio_val, static_cast<uint64_t>(UINT_MAX))); + } + + // TODO(honghaiz): Change to usernameFragment or ufrag. + const std::string & username() const { return username_; } + void set_username(const std::string & username) { username_ = username; } + + const std::string & password() const { return password_; } + void set_password(const std::string & password) { password_ = password; } + + const std::string & type() const { return type_; } + void set_type(const std::string & type) { type_ = type; } + + const std::string & network_name() const { return network_name_; } + void set_network_name(const std::string & network_name) { + network_name_ = network_name; + } + + rtc::AdapterType network_type() const { return network_type_; } + void set_network_type(rtc::AdapterType network_type) { + network_type_ = network_type; + } + + // Candidates in a new generation replace those in the old generation. + uint32_t generation() const { return generation_; } + void set_generation(uint32_t generation) { generation_ = generation; } + + // |network_cost| measures the cost/penalty of using this candidate. A network + // cost of 0 indicates this candidate can be used freely. A value of + // rtc::kNetworkCostMax indicates it should be used only as the last resort. + void set_network_cost(uint16_t network_cost) { + RTC_DCHECK_LE(network_cost, rtc::kNetworkCostMax); + network_cost_ = network_cost; + } + uint16_t network_cost() const { return network_cost_; } + + // An ID assigned to the network hosting the candidate. + uint16_t network_id() const { return network_id_; } + void set_network_id(uint16_t network_id) { network_id_ = network_id; } + + const std::string& foundation() const { + return foundation_; + } + void set_foundation(const std::string& foundation) { + foundation_ = foundation; + } + + const rtc::SocketAddress & related_address() const { + return related_address_; + } + void set_related_address( + const rtc::SocketAddress & related_address) { + related_address_ = related_address; + } + const std::string& tcptype() const { return tcptype_; } + void set_tcptype(const std::string& tcptype) { + tcptype_ = tcptype; + } + + // The name of the transport channel of this candidate. + // TODO(phoglund): remove. + const std::string& transport_name() const { return transport_name_; } + void set_transport_name(const std::string& transport_name) { + transport_name_ = transport_name; + } + + // The URL of the ICE server which this candidate is gathered from. + const std::string& url() const { return url_; } + void set_url(const std::string& url) { url_ = url; } + + // Determines whether this candidate is equivalent to the given one. + bool IsEquivalent(const Candidate& c) const; + + // Determines whether this candidate can be considered equivalent to the + // given one when looking for a matching candidate to remove. + bool MatchesForRemoval(const Candidate& c) const; + + std::string ToString() const { + return ToStringInternal(false); + } + + std::string ToSensitiveString() const { + return ToStringInternal(true); + } + + uint32_t GetPriority(uint32_t type_preference, + int network_adapter_preference, + int relay_preference) const; + + bool operator==(const Candidate& o) const; + bool operator!=(const Candidate& o) const; + + private: + std::string ToStringInternal(bool sensitive) const; + + std::string id_; + int component_; + std::string protocol_; + std::string relay_protocol_; + rtc::SocketAddress address_; + uint32_t priority_; + std::string username_; + std::string password_; + std::string type_; + std::string network_name_; + rtc::AdapterType network_type_; + uint32_t generation_; + std::string foundation_; + rtc::SocketAddress related_address_; + std::string tcptype_; + std::string transport_name_; + uint16_t network_id_; + uint16_t network_cost_; + std::string url_; +}; + +} // namespace cricket + +#endif // API_CANDIDATE_H_ diff --git a/third_party/libwebrtc/webrtc/api/cryptoparams.h b/third_party/libwebrtc/webrtc/api/cryptoparams.h new file mode 100644 index 0000000000..2350528358 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/cryptoparams.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2004 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 API_CRYPTOPARAMS_H_ +#define API_CRYPTOPARAMS_H_ + +#include <string> + +namespace cricket { + +// Parameters for SRTP negotiation, as described in RFC 4568. +struct CryptoParams { + CryptoParams() : tag(0) {} + CryptoParams(int t, + const std::string& cs, + const std::string& kp, + const std::string& sp) + : tag(t), cipher_suite(cs), key_params(kp), session_params(sp) {} + + bool Matches(const CryptoParams& params) const { + return (tag == params.tag && cipher_suite == params.cipher_suite); + } + + int tag; + std::string cipher_suite; + std::string key_params; + std::string session_params; +}; + +} // namespace cricket + +#endif // API_CRYPTOPARAMS_H_ diff --git a/third_party/libwebrtc/webrtc/api/datachannel.h b/third_party/libwebrtc/webrtc/api/datachannel.h new file mode 100644 index 0000000000..70be913a81 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/datachannel.h @@ -0,0 +1,18 @@ +/* + * Copyright 2012 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 API_DATACHANNEL_H_ +#define API_DATACHANNEL_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/datachannel.h" + +#endif // API_DATACHANNEL_H_ diff --git a/third_party/libwebrtc/webrtc/api/datachannelinterface.h b/third_party/libwebrtc/webrtc/api/datachannelinterface.h new file mode 100644 index 0000000000..4ab7efb740 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/datachannelinterface.h @@ -0,0 +1,183 @@ +/* + * Copyright 2012 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. + */ + +// This file contains interfaces for DataChannels +// http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcdatachannel + +#ifndef API_DATACHANNELINTERFACE_H_ +#define API_DATACHANNELINTERFACE_H_ + +#include <string> + +#include "rtc_base/basictypes.h" +#include "rtc_base/checks.h" +#include "rtc_base/copyonwritebuffer.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// C++ version of: https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannelinit +// TODO(deadbeef): Use rtc::Optional for the "-1 if unset" things. +struct DataChannelInit { + // Deprecated. Reliability is assumed, and channel will be unreliable if + // maxRetransmitTime or MaxRetransmits is set. + bool reliable = false; + + // True if ordered delivery is required. + bool ordered = true; + + // The max period of time in milliseconds in which retransmissions will be + // sent. After this time, no more retransmissions will be sent. -1 if unset. + // + // Cannot be set along with |maxRetransmits|. + int maxRetransmitTime = -1; + + // The max number of retransmissions. -1 if unset. + // + // Cannot be set along with |maxRetransmitTime|. + int maxRetransmits = -1; + + // This is set by the application and opaque to the WebRTC implementation. + std::string protocol; + + // True if the channel has been externally negotiated and we do not send an + // in-band signalling in the form of an "open" message. If this is true, |id| + // below must be set; otherwise it should be unset and will be negotiated + // in-band. + bool negotiated = false; + + // The stream id, or SID, for SCTP data channels. -1 if unset (see above). + int id = -1; +}; + +// At the JavaScript level, data can be passed in as a string or a blob, so +// this structure's |binary| flag tells whether the data should be interpreted +// as binary or text. +struct DataBuffer { + DataBuffer(const rtc::CopyOnWriteBuffer& data, bool binary) + : data(data), + binary(binary) { + } + // For convenience for unit tests. + explicit DataBuffer(const std::string& text) + : data(text.data(), text.length()), + binary(false) { + } + size_t size() const { return data.size(); } + + rtc::CopyOnWriteBuffer data; + // Indicates if the received data contains UTF-8 or binary data. + // Note that the upper layers are left to verify the UTF-8 encoding. + // TODO(jiayl): prefer to use an enum instead of a bool. + bool binary; +}; + +// Used to implement RTCDataChannel events. +// +// The code responding to these callbacks should unwind the stack before +// using any other webrtc APIs; re-entrancy is not supported. +class DataChannelObserver { + public: + // The data channel state have changed. + virtual void OnStateChange() = 0; + // A data buffer was successfully received. + virtual void OnMessage(const DataBuffer& buffer) = 0; + // The data channel's buffered_amount has changed. + virtual void OnBufferedAmountChange(uint64_t previous_amount) {} + + protected: + virtual ~DataChannelObserver() {} +}; + +class DataChannelInterface : public rtc::RefCountInterface { + public: + // C++ version of: https://www.w3.org/TR/webrtc/#idl-def-rtcdatachannelstate + // Unlikely to change, but keep in sync with DataChannel.java:State and + // RTCDataChannel.h:RTCDataChannelState. + enum DataState { + kConnecting, + kOpen, // The DataChannel is ready to send data. + kClosing, + kClosed + }; + + static const char* DataStateString(DataState state) { + switch (state) { + case kConnecting: + return "connecting"; + case kOpen: + return "open"; + case kClosing: + return "closing"; + case kClosed: + return "closed"; + } + RTC_CHECK(false) << "Unknown DataChannel state: " << state; + return ""; + } + + // Used to receive events from the data channel. Only one observer can be + // registered at a time. UnregisterObserver should be called before the + // observer object is destroyed. + virtual void RegisterObserver(DataChannelObserver* observer) = 0; + virtual void UnregisterObserver() = 0; + + // The label attribute represents a label that can be used to distinguish this + // DataChannel object from other DataChannel objects. + virtual std::string label() const = 0; + + // The accessors below simply return the properties from the DataChannelInit + // the data channel was constructed with. + virtual bool reliable() const = 0; + // TODO(deadbeef): Remove these dummy implementations when all classes have + // implemented these APIs. They should all just return the values the + // DataChannel was created with. + virtual bool ordered() const { return false; } + virtual uint16_t maxRetransmitTime() const { return 0; } + virtual uint16_t maxRetransmits() const { return 0; } + virtual std::string protocol() const { return std::string(); } + virtual bool negotiated() const { return false; } + + // Returns the ID from the DataChannelInit, if it was negotiated out-of-band. + // If negotiated in-band, this ID will be populated once the DTLS role is + // determined, and until then this will return -1. + virtual int id() const = 0; + virtual DataState state() const = 0; + virtual uint32_t messages_sent() const = 0; + virtual uint64_t bytes_sent() const = 0; + virtual uint32_t messages_received() const = 0; + virtual uint64_t bytes_received() const = 0; + + // Returns the number of bytes of application data (UTF-8 text and binary + // data) that have been queued using Send but have not yet been processed at + // the SCTP level. See comment above Send below. + virtual uint64_t buffered_amount() const = 0; + + // Begins the graceful data channel closing procedure. See: + // https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.7 + virtual void Close() = 0; + + // Sends |data| to the remote peer. If the data can't be sent at the SCTP + // level (due to congestion control), it's buffered at the data channel level, + // up to a maximum of 16MB. If Send is called while this buffer is full, the + // data channel will be closed abruptly. + // + // So, it's important to use buffered_amount() and OnBufferedAmountChange to + // ensure the data channel is used efficiently but without filling this + // buffer. + virtual bool Send(const DataBuffer& buffer) = 0; + + protected: + virtual ~DataChannelInterface() {} +}; + +} // namespace webrtc + +#endif // API_DATACHANNELINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/dtmfsenderinterface.h b/third_party/libwebrtc/webrtc/api/dtmfsenderinterface.h new file mode 100644 index 0000000000..8f0ab71206 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/dtmfsenderinterface.h @@ -0,0 +1,97 @@ +/* + * Copyright 2012 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 API_DTMFSENDERINTERFACE_H_ +#define API_DTMFSENDERINTERFACE_H_ + +#include <string> + +#include "api/mediastreaminterface.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// DtmfSender callback interface, used to implement RTCDtmfSender events. +// Applications should implement this interface to get notifications from the +// DtmfSender. +class DtmfSenderObserverInterface { + public: + // Triggered when DTMF |tone| is sent. + // If |tone| is empty that means the DtmfSender has sent out all the given + // tones. + virtual void OnToneChange(const std::string& tone) = 0; + + protected: + virtual ~DtmfSenderObserverInterface() {} +}; + +// The interface of native implementation of the RTCDTMFSender defined by the +// WebRTC W3C Editor's Draft. +// See: https://www.w3.org/TR/webrtc/#peer-to-peer-dtmf +class DtmfSenderInterface : public rtc::RefCountInterface { + public: + // Used to receive events from the DTMF sender. Only one observer can be + // registered at a time. UnregisterObserver should be called before the + // observer object is destroyed. + virtual void RegisterObserver(DtmfSenderObserverInterface* observer) = 0; + virtual void UnregisterObserver() = 0; + + // Returns true if this DtmfSender is capable of sending DTMF. Otherwise + // returns false. To be able to send DTMF, the associated RtpSender must be + // able to send packets, and a "telephone-event" codec must be negotiated. + virtual bool CanInsertDtmf() = 0; + + // Queues a task that sends the DTMF |tones|. The |tones| parameter is treated + // as a series of characters. The characters 0 through 9, A through D, #, and + // * generate the associated DTMF tones. The characters a to d are equivalent + // to A to D. The character ',' indicates a delay of 2 seconds before + // processing the next character in the tones parameter. + // + // Unrecognized characters are ignored. + // + // The |duration| parameter indicates the duration in ms to use for each + // character passed in the |tones| parameter. The duration cannot be more + // than 6000 or less than 70. + // + // The |inter_tone_gap| parameter indicates the gap between tones in ms. The + // |inter_tone_gap| must be at least 50 ms but should be as short as + // possible. + // + // If InsertDtmf is called on the same object while an existing task for this + // object to generate DTMF is still running, the previous task is canceled. + // Returns true on success and false on failure. + virtual bool InsertDtmf(const std::string& tones, int duration, + int inter_tone_gap) = 0; + + // Returns the track given as argument to the constructor. Only exists for + // backwards compatibilty; now that DtmfSenders are tied to RtpSenders, it's + // no longer relevant. + virtual const AudioTrackInterface* track() const = 0; + + // Returns the tones remaining to be played out. + virtual std::string tones() const = 0; + + // Returns the current tone duration value in ms. + // This value will be the value last set via the InsertDtmf() method, or the + // default value of 100 ms if InsertDtmf() was never called. + virtual int duration() const = 0; + + // Returns the current value of the between-tone gap in ms. + // This value will be the value last set via the InsertDtmf() method, or the + // default value of 50 ms if InsertDtmf() was never called. + virtual int inter_tone_gap() const = 0; + + protected: + virtual ~DtmfSenderInterface() {} +}; + +} // namespace webrtc + +#endif // API_DTMFSENDERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/fakemetricsobserver.cc b/third_party/libwebrtc/webrtc/api/fakemetricsobserver.cc new file mode 100644 index 0000000000..d09bf17185 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/fakemetricsobserver.cc @@ -0,0 +1,64 @@ +/* + * Copyright 2015 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 "api/fakemetricsobserver.h" +#include "rtc_base/checks.h" + +namespace webrtc { + +FakeMetricsObserver::FakeMetricsObserver() { + Reset(); +} + +void FakeMetricsObserver::Reset() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + counters_.clear(); + memset(histogram_samples_, 0, sizeof(histogram_samples_)); +} + +void FakeMetricsObserver::IncrementEnumCounter( + PeerConnectionEnumCounterType type, + int counter, + int counter_max) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + if (counters_.size() <= static_cast<size_t>(type)) { + counters_.resize(type + 1); + } + auto& counters = counters_[type]; + ++counters[counter]; +} + +void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, + int value) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + RTC_DCHECK_EQ(histogram_samples_[type], 0); + histogram_samples_[type] = value; +} + +int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, + int counter) const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + if (counters_.size() <= static_cast<size_t>(type)) { + return 0; + } + const auto& it = counters_[type].find(counter); + if (it == counters_[type].end()) { + return 0; + } + return it->second; +} + +int FakeMetricsObserver::GetHistogramSample( + PeerConnectionMetricsName type) const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return histogram_samples_[type]; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/fakemetricsobserver.h b/third_party/libwebrtc/webrtc/api/fakemetricsobserver.h new file mode 100644 index 0000000000..afd019391a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/fakemetricsobserver.h @@ -0,0 +1,52 @@ +/* + * Copyright 2015 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 API_FAKEMETRICSOBSERVER_H_ +#define API_FAKEMETRICSOBSERVER_H_ + +#include <map> +#include <string> +#include <vector> + +#include "api/peerconnectioninterface.h" +#include "rtc_base/thread_checker.h" + +namespace webrtc { + +class FakeMetricsObserver : public MetricsObserverInterface { + public: + FakeMetricsObserver(); + void Reset(); + + void IncrementEnumCounter(PeerConnectionEnumCounterType, + int counter, + int counter_max) override; + void AddHistogramSample(PeerConnectionMetricsName type, + int value) override; + + // Accessors to be used by the tests. + int GetEnumCounter(PeerConnectionEnumCounterType type, int counter) const; + int GetHistogramSample(PeerConnectionMetricsName type) const; + + protected: + ~FakeMetricsObserver() {} + + private: + rtc::ThreadChecker thread_checker_; + // The vector contains maps for each counter type. In the map, it's a mapping + // from individual counter to its count, such that it's memory efficient when + // comes to sparse enum types, like the SSL ciphers in the IANA registry. + std::vector<std::map<int, int>> counters_; + int histogram_samples_[kPeerConnectionMetricsName_Max]; +}; + +} // namespace webrtc + +#endif // API_FAKEMETRICSOBSERVER_H_ diff --git a/third_party/libwebrtc/webrtc/api/jsep.h b/third_party/libwebrtc/webrtc/api/jsep.h new file mode 100644 index 0000000000..acfffd4d0a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/jsep.h @@ -0,0 +1,175 @@ +/* + * Copyright 2012 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. + */ + +// This file contains declarations of interfaces that wrap SDP-related +// constructs; session descriptions and ICE candidates. The inner "cricket::" +// objects shouldn't be accessed directly; the intention is that an application +// using the PeerConnection API only creates these objects from strings, and +// them passes them into the PeerConnection. +// +// Though in the future, we're planning to provide an SDP parsing API, with a +// structure more friendly than cricket::SessionDescription. + +#ifndef API_JSEP_H_ +#define API_JSEP_H_ + +#include <stddef.h> + +#include <string> +#include <vector> + +#include "rtc_base/refcount.h" + +namespace cricket { +class Candidate; +class SessionDescription; +} // namespace cricket + +namespace webrtc { + +struct SdpParseError { + public: + // The sdp line that causes the error. + std::string line; + // Explains the error. + std::string description; +}; + +// Class representation of an ICE candidate. +// +// An instance of this interface is supposed to be owned by one class at +// a time and is therefore not expected to be thread safe. +// +// An instance can be created by CreateIceCandidate. +class IceCandidateInterface { + public: + virtual ~IceCandidateInterface() {} + // If present, this is the value of the "a=mid" attribute of the candidate's + // m= section in SDP, which identifies the m= section. + virtual std::string sdp_mid() const = 0; + // This indicates the index (starting at zero) of m= section this candidate + // is assocated with. Needed when an endpoint doesn't support MIDs. + virtual int sdp_mline_index() const = 0; + // Only for use internally. + virtual const cricket::Candidate& candidate() const = 0; + // The URL of the ICE server which this candidate was gathered from. + // TODO(zhihuang): Remove the default implementation once the subclasses + // implement this method. + virtual std::string server_url() const { return ""; } + // Creates a SDP-ized form of this candidate. + virtual bool ToString(std::string* out) const = 0; +}; + +// Creates a IceCandidateInterface based on SDP string. +// Returns null if the sdp string can't be parsed. +// |error| may be null. +IceCandidateInterface* CreateIceCandidate(const std::string& sdp_mid, + int sdp_mline_index, + const std::string& sdp, + SdpParseError* error); + +// This class represents a collection of candidates for a specific m= section. +// Used in SessionDescriptionInterface. +class IceCandidateCollection { + public: + virtual ~IceCandidateCollection() {} + virtual size_t count() const = 0; + // Returns true if an equivalent |candidate| exist in the collection. + virtual bool HasCandidate(const IceCandidateInterface* candidate) const = 0; + virtual const IceCandidateInterface* at(size_t index) const = 0; +}; + +// Class representation of an SDP session description. +// +// An instance of this interface is supposed to be owned by one class at a time +// and is therefore not expected to be thread safe. +// +// An instance can be created by CreateSessionDescription. +class SessionDescriptionInterface { + public: + // Supported types: + static const char kOffer[]; + static const char kPrAnswer[]; + static const char kAnswer[]; + + virtual ~SessionDescriptionInterface() {} + + // Only for use internally. + virtual cricket::SessionDescription* description() = 0; + virtual const cricket::SessionDescription* description() const = 0; + + // Get the session id and session version, which are defined based on + // RFC 4566 for the SDP o= line. + virtual std::string session_id() const = 0; + virtual std::string session_version() const = 0; + + // kOffer/kPrAnswer/kAnswer + virtual std::string type() const = 0; + + // Adds the specified candidate to the description. + // + // Ownership is not transferred. + // + // Returns false if the session description does not have a media section + // that corresponds to |candidate.sdp_mid()| or + // |candidate.sdp_mline_index()|. + virtual bool AddCandidate(const IceCandidateInterface* candidate) = 0; + + // Removes the candidates from the description, if found. + // + // Returns the number of candidates removed. + virtual size_t RemoveCandidates( + const std::vector<cricket::Candidate>& candidates) { return 0; } + + // Returns the number of m= sections in the session description. + virtual size_t number_of_mediasections() const = 0; + + // Returns a collection of all candidates that belong to a certain m= + // section. + virtual const IceCandidateCollection* candidates( + size_t mediasection_index) const = 0; + + // Serializes the description to SDP. + virtual bool ToString(std::string* out) const = 0; +}; + +// Creates a SessionDescriptionInterface based on the SDP string and the type. +// Returns null if the sdp string can't be parsed or the type is unsupported. +// |error| may be null. +SessionDescriptionInterface* CreateSessionDescription(const std::string& type, + const std::string& sdp, + SdpParseError* error); + +// CreateOffer and CreateAnswer callback interface. +class CreateSessionDescriptionObserver : public rtc::RefCountInterface { + public: + // This callback transfers the ownership of the |desc|. + // TODO(deadbeef): Make this take an std::unique_ptr<> to avoid confusion + // around ownership. + virtual void OnSuccess(SessionDescriptionInterface* desc) = 0; + virtual void OnFailure(const std::string& error) = 0; + + protected: + ~CreateSessionDescriptionObserver() {} +}; + +// SetLocalDescription and SetRemoteDescription callback interface. +class SetSessionDescriptionObserver : public rtc::RefCountInterface { + public: + virtual void OnSuccess() = 0; + virtual void OnFailure(const std::string& error) = 0; + + protected: + ~SetSessionDescriptionObserver() {} +}; + +} // namespace webrtc + +#endif // API_JSEP_H_ diff --git a/third_party/libwebrtc/webrtc/api/jsepicecandidate.h b/third_party/libwebrtc/webrtc/api/jsepicecandidate.h new file mode 100644 index 0000000000..dae6121ead --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/jsepicecandidate.h @@ -0,0 +1,93 @@ +/* + * Copyright 2012 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. + */ + +// TODO(deadbeef): Move this out of api/; it's an implementation detail and +// shouldn't be used externally. + +#ifndef API_JSEPICECANDIDATE_H_ +#define API_JSEPICECANDIDATE_H_ + +#include <string> +#include <utility> +#include <vector> + +#include "api/candidate.h" +#include "api/jsep.h" +#include "rtc_base/constructormagic.h" + +namespace webrtc { + +// Implementation of IceCandidateInterface. +class JsepIceCandidate : public IceCandidateInterface { + public: + JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index); + JsepIceCandidate(const std::string& sdp_mid, int sdp_mline_index, + const cricket::Candidate& candidate); + ~JsepIceCandidate(); + // |err| may be null. + bool Initialize(const std::string& sdp, SdpParseError* err); + void SetCandidate(const cricket::Candidate& candidate) { + candidate_ = candidate; + } + + virtual std::string sdp_mid() const { return sdp_mid_; } + virtual int sdp_mline_index() const { return sdp_mline_index_; } + virtual const cricket::Candidate& candidate() const { + return candidate_; + } + + virtual std::string server_url() const { return candidate_.url(); } + + virtual bool ToString(std::string* out) const; + + private: + std::string sdp_mid_; + int sdp_mline_index_; + cricket::Candidate candidate_; + + RTC_DISALLOW_COPY_AND_ASSIGN(JsepIceCandidate); +}; + +// Implementation of IceCandidateCollection which stores JsepIceCandidates. +class JsepCandidateCollection : public IceCandidateCollection { + public: + JsepCandidateCollection() {} + // Move constructor is defined so that a vector of JsepCandidateCollections + // can be resized. + JsepCandidateCollection(JsepCandidateCollection&& o) + : candidates_(std::move(o.candidates_)) {} + ~JsepCandidateCollection(); + virtual size_t count() const { + return candidates_.size(); + } + virtual bool HasCandidate(const IceCandidateInterface* candidate) const; + // Adds and takes ownership of the JsepIceCandidate. + // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is + // more clear. + virtual void add(JsepIceCandidate* candidate) { + candidates_.push_back(candidate); + } + virtual const IceCandidateInterface* at(size_t index) const { + return candidates_[index]; + } + // Removes the candidate that has a matching address and protocol. + // + // Returns the number of candidates that were removed. + size_t remove(const cricket::Candidate& candidate); + + private: + std::vector<JsepIceCandidate*> candidates_; + + RTC_DISALLOW_COPY_AND_ASSIGN(JsepCandidateCollection); +}; + +} // namespace webrtc + +#endif // API_JSEPICECANDIDATE_H_ diff --git a/third_party/libwebrtc/webrtc/api/jsepsessiondescription.h b/third_party/libwebrtc/webrtc/api/jsepsessiondescription.h new file mode 100644 index 0000000000..6b115ee2e9 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/jsepsessiondescription.h @@ -0,0 +1,89 @@ +/* + * Copyright 2012 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. + */ + +// TODO(deadbeef): Move this out of api/; it's an implementation detail and +// shouldn't be used externally. + +#ifndef API_JSEPSESSIONDESCRIPTION_H_ +#define API_JSEPSESSIONDESCRIPTION_H_ + +#include <memory> +#include <string> +#include <vector> + +#include "api/candidate.h" +#include "api/jsep.h" +#include "api/jsepicecandidate.h" +#include "rtc_base/constructormagic.h" + +namespace cricket { +class SessionDescription; +} + +namespace webrtc { + +// Implementation of SessionDescriptionInterface. +class JsepSessionDescription : public SessionDescriptionInterface { + public: + explicit JsepSessionDescription(const std::string& type); + virtual ~JsepSessionDescription(); + + // Takes ownership of |description|. + // TODO(deadbeef): Make this use an std::unique_ptr<>, so ownership logic is + // more clear. + bool Initialize(cricket::SessionDescription* description, + const std::string& session_id, + const std::string& session_version); + + virtual cricket::SessionDescription* description() { + return description_.get(); + } + virtual const cricket::SessionDescription* description() const { + return description_.get(); + } + virtual std::string session_id() const { + return session_id_; + } + virtual std::string session_version() const { + return session_version_; + } + virtual std::string type() const { + return type_; + } + // Allows changing the type. Used for testing. + void set_type(const std::string& type) { type_ = type; } + virtual bool AddCandidate(const IceCandidateInterface* candidate); + virtual size_t RemoveCandidates( + const std::vector<cricket::Candidate>& candidates); + virtual size_t number_of_mediasections() const; + virtual const IceCandidateCollection* candidates( + size_t mediasection_index) const; + virtual bool ToString(std::string* out) const; + + static const int kDefaultVideoCodecId; + static const char kDefaultVideoCodecName[]; + + private: + std::unique_ptr<cricket::SessionDescription> description_; + std::string session_id_; + std::string session_version_; + std::string type_; + std::vector<JsepCandidateCollection> candidate_collection_; + + bool GetMediasectionIndex(const IceCandidateInterface* candidate, + size_t* index); + int GetMediasectionIndex(const cricket::Candidate& candidate); + + RTC_DISALLOW_COPY_AND_ASSIGN(JsepSessionDescription); +}; + +} // namespace webrtc + +#endif // API_JSEPSESSIONDESCRIPTION_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.cc b/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.cc new file mode 100644 index 0000000000..90a957cfa4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.cc @@ -0,0 +1,275 @@ +/* + * Copyright 2013 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 "api/mediaconstraintsinterface.h" + +#include "api/peerconnectioninterface.h" +#include "rtc_base/stringencode.h" + +namespace { + +// Find the highest-priority instance of the T-valued constraint named by +// |key| and return its value as |value|. |constraints| can be null. +// If |mandatory_constraints| is non-null, it is incremented if the key appears +// among the mandatory constraints. +// Returns true if the key was found and has a valid value for type T. +// If the key appears multiple times as an optional constraint, appearances +// after the first are ignored. +// Note: Because this uses FindFirst, repeated optional constraints whose +// first instance has an unrecognized value are not handled precisely in +// accordance with the specification. +template <typename T> +bool FindConstraint(const webrtc::MediaConstraintsInterface* constraints, + const std::string& key, + T* value, + size_t* mandatory_constraints) { + std::string string_value; + if (!FindConstraint(constraints, key, &string_value, mandatory_constraints)) { + return false; + } + return rtc::FromString(string_value, value); +} + +// Specialization for std::string, since a string doesn't need conversion. +template <> +bool FindConstraint(const webrtc::MediaConstraintsInterface* constraints, + const std::string& key, + std::string* value, + size_t* mandatory_constraints) { + if (!constraints) { + return false; + } + if (constraints->GetMandatory().FindFirst(key, value)) { + if (mandatory_constraints) { + ++*mandatory_constraints; + } + return true; + } + if (constraints->GetOptional().FindFirst(key, value)) { + return true; + } + return false; +} + +// Converts a constraint (mandatory takes precedence over optional) to an +// rtc::Optional. +template <typename T> +void ConstraintToOptional(const webrtc::MediaConstraintsInterface* constraints, + const std::string& key, + rtc::Optional<T>* value_out) { + T value; + bool present = FindConstraint<T>(constraints, key, &value, nullptr); + if (present) { + *value_out = value; + } +} +} // namespace + +namespace webrtc { + +const char MediaConstraintsInterface::kValueTrue[] = "true"; +const char MediaConstraintsInterface::kValueFalse[] = "false"; + +// Constraints declared as static members in mediastreaminterface.h +// Specified by draft-alvestrand-constraints-resolution-00b +const char MediaConstraintsInterface::kMinAspectRatio[] = "minAspectRatio"; +const char MediaConstraintsInterface::kMaxAspectRatio[] = "maxAspectRatio"; +const char MediaConstraintsInterface::kMaxWidth[] = "maxWidth"; +const char MediaConstraintsInterface::kMinWidth[] = "minWidth"; +const char MediaConstraintsInterface::kMaxHeight[] = "maxHeight"; +const char MediaConstraintsInterface::kMinHeight[] = "minHeight"; +const char MediaConstraintsInterface::kMaxFrameRate[] = "maxFrameRate"; +const char MediaConstraintsInterface::kMinFrameRate[] = "minFrameRate"; + +// Audio constraints. +const char MediaConstraintsInterface::kEchoCancellation[] = + "echoCancellation"; +const char MediaConstraintsInterface::kGoogEchoCancellation[] = + "googEchoCancellation"; +const char MediaConstraintsInterface::kExtendedFilterEchoCancellation[] = + "googEchoCancellation2"; +const char MediaConstraintsInterface::kDAEchoCancellation[] = + "googDAEchoCancellation"; +const char MediaConstraintsInterface::kAutoGainControl[] = + "googAutoGainControl"; +const char MediaConstraintsInterface::kExperimentalAutoGainControl[] = + "googAutoGainControl2"; +const char MediaConstraintsInterface::kNoiseSuppression[] = + "googNoiseSuppression"; +const char MediaConstraintsInterface::kExperimentalNoiseSuppression[] = + "googNoiseSuppression2"; +const char MediaConstraintsInterface::kIntelligibilityEnhancer[] = + "intelligibilityEnhancer"; +const char MediaConstraintsInterface::kLevelControl[] = "levelControl"; +const char MediaConstraintsInterface::kLevelControlInitialPeakLevelDBFS[] = + "levelControlInitialPeakLevelDBFS"; +const char MediaConstraintsInterface::kHighpassFilter[] = + "googHighpassFilter"; +const char MediaConstraintsInterface::kTypingNoiseDetection[] = + "googTypingNoiseDetection"; +const char MediaConstraintsInterface::kAudioMirroring[] = "googAudioMirroring"; +const char MediaConstraintsInterface::kAudioNetworkAdaptorConfig[] = + "googAudioNetworkAdaptorConfig"; + +// Google-specific constraint keys for a local video source (getUserMedia). +const char MediaConstraintsInterface::kNoiseReduction[] = "googNoiseReduction"; + +// Constraint keys for CreateOffer / CreateAnswer defined in W3C specification. +const char MediaConstraintsInterface::kOfferToReceiveAudio[] = + "OfferToReceiveAudio"; +const char MediaConstraintsInterface::kOfferToReceiveVideo[] = + "OfferToReceiveVideo"; +const char MediaConstraintsInterface::kVoiceActivityDetection[] = + "VoiceActivityDetection"; +const char MediaConstraintsInterface::kIceRestart[] = + "IceRestart"; +// Google specific constraint for BUNDLE enable/disable. +const char MediaConstraintsInterface::kUseRtpMux[] = + "googUseRtpMUX"; + +// Below constraints should be used during PeerConnection construction. +const char MediaConstraintsInterface::kEnableDtlsSrtp[] = + "DtlsSrtpKeyAgreement"; +const char MediaConstraintsInterface::kEnableRtpDataChannels[] = + "RtpDataChannels"; +// Google-specific constraint keys. +const char MediaConstraintsInterface::kEnableDscp[] = "googDscp"; +const char MediaConstraintsInterface::kEnableIPv6[] = "googIPv6"; +const char MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate[] = + "googSuspendBelowMinBitrate"; +const char MediaConstraintsInterface::kCombinedAudioVideoBwe[] = + "googCombinedAudioVideoBwe"; +const char MediaConstraintsInterface::kScreencastMinBitrate[] = + "googScreencastMinBitrate"; +// TODO(ronghuawu): Remove once cpu overuse detection is stable. +const char MediaConstraintsInterface::kCpuOveruseDetection[] = + "googCpuOveruseDetection"; +const char MediaConstraintsInterface::kPayloadPadding[] = "googPayloadPadding"; + + +// Set |value| to the value associated with the first appearance of |key|, or +// return false if |key| is not found. +bool MediaConstraintsInterface::Constraints::FindFirst( + const std::string& key, std::string* value) const { + for (Constraints::const_iterator iter = begin(); iter != end(); ++iter) { + if (iter->key == key) { + *value = iter->value; + return true; + } + } + return false; +} + +bool FindConstraint(const MediaConstraintsInterface* constraints, + const std::string& key, bool* value, + size_t* mandatory_constraints) { + return ::FindConstraint<bool>(constraints, key, value, mandatory_constraints); +} + +bool FindConstraint(const MediaConstraintsInterface* constraints, + const std::string& key, + int* value, + size_t* mandatory_constraints) { + return ::FindConstraint<int>(constraints, key, value, mandatory_constraints); +} + +void CopyConstraintsIntoRtcConfiguration( + const MediaConstraintsInterface* constraints, + PeerConnectionInterface::RTCConfiguration* configuration) { + // Copy info from constraints into configuration, if present. + if (!constraints) { + return; + } + + bool enable_ipv6; + if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, + &enable_ipv6, nullptr)) { + configuration->disable_ipv6 = !enable_ipv6; + } + FindConstraint(constraints, MediaConstraintsInterface::kEnableDscp, + &configuration->media_config.enable_dscp, nullptr); + FindConstraint( + constraints, MediaConstraintsInterface::kCpuOveruseDetection, + &configuration->media_config.video.enable_cpu_overuse_detection, nullptr); + FindConstraint(constraints, MediaConstraintsInterface::kEnableRtpDataChannels, + &configuration->enable_rtp_data_channel, nullptr); + // Find Suspend Below Min Bitrate constraint. + FindConstraint(constraints, + MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, + &configuration->media_config.video.suspend_below_min_bitrate, + nullptr); + ConstraintToOptional<int>(constraints, + MediaConstraintsInterface::kScreencastMinBitrate, + &configuration->screencast_min_bitrate); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kCombinedAudioVideoBwe, + &configuration->combined_audio_video_bwe); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kEnableDtlsSrtp, + &configuration->enable_dtls_srtp); +} + +void CopyConstraintsIntoAudioOptions( + const MediaConstraintsInterface* constraints, + cricket::AudioOptions* options) { + if (!constraints) { + return; + } + + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kGoogEchoCancellation, + &options->echo_cancellation); + ConstraintToOptional<bool>( + constraints, MediaConstraintsInterface::kExtendedFilterEchoCancellation, + &options->extended_filter_aec); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kDAEchoCancellation, + &options->delay_agnostic_aec); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kAutoGainControl, + &options->auto_gain_control); + ConstraintToOptional<bool>( + constraints, MediaConstraintsInterface::kExperimentalAutoGainControl, + &options->experimental_agc); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kNoiseSuppression, + &options->noise_suppression); + ConstraintToOptional<bool>( + constraints, MediaConstraintsInterface::kExperimentalNoiseSuppression, + &options->experimental_ns); + ConstraintToOptional<bool>( + constraints, MediaConstraintsInterface::kIntelligibilityEnhancer, + &options->intelligibility_enhancer); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kLevelControl, + &options->level_control); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kHighpassFilter, + &options->highpass_filter); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kTypingNoiseDetection, + &options->typing_detection); + ConstraintToOptional<bool>(constraints, + MediaConstraintsInterface::kAudioMirroring, + &options->stereo_swapping); + ConstraintToOptional<float>( + constraints, MediaConstraintsInterface::kLevelControlInitialPeakLevelDBFS, + &options->level_control_initial_peak_level_dbfs); + ConstraintToOptional<std::string>( + constraints, MediaConstraintsInterface::kAudioNetworkAdaptorConfig, + &options->audio_network_adaptor_config); + // When |kAudioNetworkAdaptorConfig| is defined, it both means that audio + // network adaptor is desired, and provides the config string. + if (options->audio_network_adaptor_config) { + options->audio_network_adaptor = true; + } +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.h b/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.h new file mode 100644 index 0000000000..73e4619bca --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediaconstraintsinterface.h @@ -0,0 +1,152 @@ +/* + * Copyright 2013 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. + */ + +// This file contains the interface for MediaConstraints, corresponding to +// the definition at +// http://www.w3.org/TR/mediacapture-streams/#mediastreamconstraints and also +// used in WebRTC: http://dev.w3.org/2011/webrtc/editor/webrtc.html#constraints. + +// This interface is being deprecated in Chrome, and may be removed +// from WebRTC too. +// https://bugs.chromium.org/p/webrtc/issues/detail?id=5617 + +#ifndef API_MEDIACONSTRAINTSINTERFACE_H_ +#define API_MEDIACONSTRAINTSINTERFACE_H_ + +#include <string> +#include <vector> + +#include "api/optional.h" +#include "api/peerconnectioninterface.h" + +namespace webrtc { + +// Interface used for passing arguments about media constraints +// to the MediaStream and PeerConnection implementation. +// +// Constraints may be either "mandatory", which means that unless satisfied, +// the method taking the constraints should fail, or "optional", which means +// they may not be satisfied.. +class MediaConstraintsInterface { + public: + struct Constraint { + Constraint() {} + Constraint(const std::string& key, const std::string value) + : key(key), value(value) { + } + std::string key; + std::string value; + }; + + class Constraints : public std::vector<Constraint> { + public: + bool FindFirst(const std::string& key, std::string* value) const; + }; + + // Constraint keys used by a local video source. + // Specified by draft-alvestrand-constraints-resolution-00b + static const char kMinAspectRatio[]; // minAspectRatio + static const char kMaxAspectRatio[]; // maxAspectRatio + static const char kMaxWidth[]; // maxWidth + static const char kMinWidth[]; // minWidth + static const char kMaxHeight[]; // maxHeight + static const char kMinHeight[]; // minHeight + static const char kMaxFrameRate[]; // maxFrameRate + static const char kMinFrameRate[]; // minFrameRate + + // Constraint keys used by a local audio source. + static const char kEchoCancellation[]; // echoCancellation + + // These keys are google specific. + static const char kGoogEchoCancellation[]; // googEchoCancellation + + static const char kExtendedFilterEchoCancellation[]; // googEchoCancellation2 + static const char kDAEchoCancellation[]; // googDAEchoCancellation + static const char kAutoGainControl[]; // googAutoGainControl + static const char kExperimentalAutoGainControl[]; // googAutoGainControl2 + static const char kNoiseSuppression[]; // googNoiseSuppression + static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2 + static const char kIntelligibilityEnhancer[]; // intelligibilityEnhancer + static const char kLevelControl[]; // levelControl + static const char + kLevelControlInitialPeakLevelDBFS[]; // levelControlInitialPeakLevelDBFS + static const char kHighpassFilter[]; // googHighpassFilter + static const char kTypingNoiseDetection[]; // googTypingNoiseDetection + static const char kAudioMirroring[]; // googAudioMirroring + static const char + kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig + + // Google-specific constraint keys for a local video source + static const char kNoiseReduction[]; // googNoiseReduction + + // Constraint keys for CreateOffer / CreateAnswer + // Specified by the W3C PeerConnection spec + static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo + static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio + static const char kVoiceActivityDetection[]; // VoiceActivityDetection + static const char kIceRestart[]; // IceRestart + // These keys are google specific. + static const char kUseRtpMux[]; // googUseRtpMUX + + // Constraints values. + static const char kValueTrue[]; // true + static const char kValueFalse[]; // false + + // PeerConnection constraint keys. + // Temporary pseudo-constraints used to enable DTLS-SRTP + static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP + // Temporary pseudo-constraints used to enable DataChannels + static const char kEnableRtpDataChannels[]; // Enable RTP DataChannels + // Google-specific constraint keys. + // Temporary pseudo-constraint for enabling DSCP through JS. + static const char kEnableDscp[]; // googDscp + // Constraint to enable IPv6 through JS. + static const char kEnableIPv6[]; // googIPv6 + // Temporary constraint to enable suspend below min bitrate feature. + static const char kEnableVideoSuspendBelowMinBitrate[]; + // googSuspendBelowMinBitrate + // Constraint to enable combined audio+video bandwidth estimation. + static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe + static const char kScreencastMinBitrate[]; // googScreencastMinBitrate + static const char kCpuOveruseDetection[]; // googCpuOveruseDetection + static const char kPayloadPadding[]; // googPayloadPadding + + // The prefix of internal-only constraints whose JS set values should be + // stripped by Chrome before passed down to Libjingle. + static const char kInternalConstraintPrefix[]; + + virtual ~MediaConstraintsInterface() = default; + + virtual const Constraints& GetMandatory() const = 0; + virtual const Constraints& GetOptional() const = 0; +}; + +bool FindConstraint(const MediaConstraintsInterface* constraints, + const std::string& key, bool* value, + size_t* mandatory_constraints); + +bool FindConstraint(const MediaConstraintsInterface* constraints, + const std::string& key, + int* value, + size_t* mandatory_constraints); + +// Copy all relevant constraints into an RTCConfiguration object. +void CopyConstraintsIntoRtcConfiguration( + const MediaConstraintsInterface* constraints, + PeerConnectionInterface::RTCConfiguration* configuration); + +// Copy all relevant constraints into an AudioOptions object. +void CopyConstraintsIntoAudioOptions( + const MediaConstraintsInterface* constraints, + cricket::AudioOptions* options); + +} // namespace webrtc + +#endif // API_MEDIACONSTRAINTSINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediastream.h b/third_party/libwebrtc/webrtc/api/mediastream.h new file mode 100644 index 0000000000..f7bae635a2 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastream.h @@ -0,0 +1,18 @@ +/* + * Copyright 2015 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 API_MEDIASTREAM_H_ +#define API_MEDIASTREAM_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/mediastream.h" + +#endif // API_MEDIASTREAM_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediastreaminterface.cc b/third_party/libwebrtc/webrtc/api/mediastreaminterface.cc new file mode 100644 index 0000000000..4821da83b3 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastreaminterface.cc @@ -0,0 +1,39 @@ +/* + * 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 "api/mediastreaminterface.h" + +namespace webrtc { + +const char MediaStreamTrackInterface::kVideoKind[] = "video"; +const char MediaStreamTrackInterface::kAudioKind[] = "audio"; + +// TODO(ivoc): Remove this when the function becomes pure virtual. +AudioProcessorInterface::AudioProcessorStatistics +AudioProcessorInterface::GetStats(bool /*has_remote_tracks*/) { + AudioProcessorStats stats; + GetStats(&stats); + AudioProcessorStatistics new_stats; + new_stats.apm_statistics.divergent_filter_fraction = + stats.aec_divergent_filter_fraction; + new_stats.apm_statistics.delay_median_ms = stats.echo_delay_median_ms; + new_stats.apm_statistics.delay_standard_deviation_ms = + stats.echo_delay_std_ms; + new_stats.apm_statistics.echo_return_loss = stats.echo_return_loss; + new_stats.apm_statistics.echo_return_loss_enhancement = + stats.echo_return_loss_enhancement; + new_stats.apm_statistics.residual_echo_likelihood = + stats.residual_echo_likelihood; + new_stats.apm_statistics.residual_echo_likelihood_recent_max = + stats.residual_echo_likelihood_recent_max; + return new_stats; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/mediastreaminterface.h b/third_party/libwebrtc/webrtc/api/mediastreaminterface.h new file mode 100644 index 0000000000..80595e09ab --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastreaminterface.h @@ -0,0 +1,341 @@ +/* + * Copyright 2012 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. + */ + +// This file contains interfaces for MediaStream, MediaTrack and MediaSource. +// These interfaces are used for implementing MediaStream and MediaTrack as +// defined in http://dev.w3.org/2011/webrtc/editor/webrtc.html#stream-api. These +// interfaces must be used only with PeerConnection. PeerConnectionManager +// interface provides the factory methods to create MediaStream and MediaTracks. + +#ifndef API_MEDIASTREAMINTERFACE_H_ +#define API_MEDIASTREAMINTERFACE_H_ + +#include <stddef.h> + +#include <string> +#include <vector> + +#include "api/optional.h" +#include "api/video/video_frame.h" +// TODO(zhihuang): Remove unrelated headers once downstream applications stop +// relying on them; they were previously transitively included by +// mediachannel.h, which is no longer a dependency of this file. +#include "media/base/videosinkinterface.h" +#include "media/base/videosourceinterface.h" +#include "modules/audio_processing/include/audio_processing_statistics.h" +#include "rtc_base/ratetracker.h" +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" +#include "rtc_base/thread.h" +#include "rtc_base/timeutils.h" + +namespace webrtc { + +// Generic observer interface. +class ObserverInterface { + public: + virtual void OnChanged() = 0; + + protected: + virtual ~ObserverInterface() {} +}; + +class NotifierInterface { + public: + virtual void RegisterObserver(ObserverInterface* observer) = 0; + virtual void UnregisterObserver(ObserverInterface* observer) = 0; + + virtual ~NotifierInterface() {} +}; + +// Base class for sources. A MediaStreamTrack has an underlying source that +// provides media. A source can be shared by multiple tracks. +class MediaSourceInterface : public rtc::RefCountInterface, + public NotifierInterface { + public: + enum SourceState { + kInitializing, + kLive, + kEnded, + kMuted + }; + + virtual SourceState state() const = 0; + + virtual bool remote() const = 0; + + protected: + virtual ~MediaSourceInterface() {} +}; + +// C++ version of MediaStreamTrack. +// See: https://www.w3.org/TR/mediacapture-streams/#mediastreamtrack +class MediaStreamTrackInterface : public rtc::RefCountInterface, + public NotifierInterface { + public: + enum TrackState { + kLive, + kEnded, + }; + + static const char kAudioKind[]; + static const char kVideoKind[]; + + // The kind() method must return kAudioKind only if the object is a + // subclass of AudioTrackInterface, and kVideoKind only if the + // object is a subclass of VideoTrackInterface. It is typically used + // to protect a static_cast<> to the corresponding subclass. + virtual std::string kind() const = 0; + + // Track identifier. + virtual std::string id() const = 0; + + // A disabled track will produce silence (if audio) or black frames (if + // video). Can be disabled and re-enabled. + virtual bool enabled() const = 0; + virtual bool set_enabled(bool enable) = 0; + + // Live or ended. A track will never be live again after becoming ended. + virtual TrackState state() const = 0; + + protected: + virtual ~MediaStreamTrackInterface() {} +}; + +// VideoTrackSourceInterface is a reference counted source used for +// VideoTracks. The same source can be used by multiple VideoTracks. +// VideoTrackSourceInterface is designed to be invoked on the signaling thread +// except for rtc::VideoSourceInterface<VideoFrame> methods that will be invoked +// on the worker thread via a VideoTrack. A custom implementation of a source +// can inherit AdaptedVideoTrackSource instead of directly implementing this +// interface. +class VideoTrackSourceInterface + : public MediaSourceInterface, + public rtc::VideoSourceInterface<VideoFrame> { + public: + struct Stats { + // Original size of captured frame, before video adaptation. + int input_width; + int input_height; + }; + + // Indicates that parameters suitable for screencasts should be automatically + // applied to RtpSenders. + // TODO(perkj): Remove these once all known applications have moved to + // explicitly setting suitable parameters for screencasts and don't need this + // implicit behavior. + virtual bool is_screencast() const = 0; + + // Indicates that the encoder should denoise video before encoding it. + // If it is not set, the default configuration is used which is different + // depending on video codec. + // TODO(perkj): Remove this once denoising is done by the source, and not by + // the encoder. + virtual rtc::Optional<bool> needs_denoising() const = 0; + + // Returns false if no stats are available, e.g, for a remote source, or a + // source which has not seen its first frame yet. + // + // Implementation should avoid blocking. + virtual bool GetStats(Stats* stats) = 0; + + protected: + virtual ~VideoTrackSourceInterface() {} +}; + +// VideoTrackInterface is designed to be invoked on the signaling thread except +// for rtc::VideoSourceInterface<VideoFrame> methods that must be invoked +// on the worker thread. +// PeerConnectionFactory::CreateVideoTrack can be used for creating a VideoTrack +// that ensures thread safety and that all methods are called on the right +// thread. +class VideoTrackInterface + : public MediaStreamTrackInterface, + public rtc::VideoSourceInterface<VideoFrame> { + public: + // Video track content hint, used to override the source is_screencast + // property. + // See https://crbug.com/653531 and https://github.com/WICG/mst-content-hint. + enum class ContentHint { kNone, kFluid, kDetailed }; + + // Register a video sink for this track. Used to connect the track to the + // underlying video engine. + void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, + const rtc::VideoSinkWants& wants) override {} + void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {} + + virtual VideoTrackSourceInterface* GetSource() const = 0; + + virtual ContentHint content_hint() const { return ContentHint::kNone; } + virtual void set_content_hint(ContentHint hint) {} + + protected: + virtual ~VideoTrackInterface() {} +}; + +// Interface for receiving audio data from a AudioTrack. +class AudioTrackSinkInterface { + public: + virtual void OnData(const void* audio_data, + int bits_per_sample, + int sample_rate, + size_t number_of_channels, + size_t number_of_frames) = 0; + + protected: + virtual ~AudioTrackSinkInterface() {} +}; + +// AudioSourceInterface is a reference counted source used for AudioTracks. +// The same source can be used by multiple AudioTracks. +class AudioSourceInterface : public MediaSourceInterface { + public: + class AudioObserver { + public: + virtual void OnSetVolume(double volume) = 0; + + protected: + virtual ~AudioObserver() {} + }; + + // TODO(deadbeef): Makes all the interfaces pure virtual after they're + // implemented in chromium. + + // Sets the volume of the source. |volume| is in the range of [0, 10]. + // TODO(tommi): This method should be on the track and ideally volume should + // be applied in the track in a way that does not affect clones of the track. + virtual void SetVolume(double volume) {} + + // Registers/unregisters observers to the audio source. + virtual void RegisterAudioObserver(AudioObserver* observer) {} + virtual void UnregisterAudioObserver(AudioObserver* observer) {} + + // TODO(tommi): Make pure virtual. + virtual void AddSink(AudioTrackSinkInterface* sink) {} + virtual void RemoveSink(AudioTrackSinkInterface* sink) {} +}; + +// Interface of the audio processor used by the audio track to collect +// statistics. +class AudioProcessorInterface : public rtc::RefCountInterface { + public: + // Deprecated, use AudioProcessorStatistics instead. + // TODO(ivoc): Remove this when all implementations have switched to the new + // GetStats function. See b/67926135. + struct AudioProcessorStats { + AudioProcessorStats() + : typing_noise_detected(false), + echo_return_loss(0), + echo_return_loss_enhancement(0), + echo_delay_median_ms(0), + echo_delay_std_ms(0), + aec_quality_min(0.0), + residual_echo_likelihood(0.0f), + residual_echo_likelihood_recent_max(0.0f), + aec_divergent_filter_fraction(0.0) {} + ~AudioProcessorStats() {} + + bool typing_noise_detected; + int echo_return_loss; + int echo_return_loss_enhancement; + int echo_delay_median_ms; + int echo_delay_std_ms; + float aec_quality_min; + float residual_echo_likelihood; + float residual_echo_likelihood_recent_max; + float aec_divergent_filter_fraction; + }; + // This struct maintains the optionality of the stats, and will replace the + // regular stats struct when all users have been updated. + struct AudioProcessorStatistics { + bool typing_noise_detected = false; + AudioProcessingStats apm_statistics; + }; + + // Get audio processor statistics. + virtual void GetStats(AudioProcessorStats* stats) = 0; + + // Get audio processor statistics. The |has_remote_tracks| argument should be + // set if there are active remote tracks (this would usually be true during + // a call). If there are no remote tracks some of the stats will not be set by + // the AudioProcessor, because they only make sense if there is at least one + // remote track. + // TODO(ivoc): Make pure virtual when all implementions are updated. + virtual AudioProcessorStatistics GetStats(bool has_remote_tracks); + + protected: + virtual ~AudioProcessorInterface() {} +}; + +class AudioTrackInterface : public MediaStreamTrackInterface { + public: + // TODO(deadbeef): Figure out if the following interface should be const or + // not. + virtual AudioSourceInterface* GetSource() const = 0; + + // Add/Remove a sink that will receive the audio data from the track. + virtual void AddSink(AudioTrackSinkInterface* sink) = 0; + virtual void RemoveSink(AudioTrackSinkInterface* sink) = 0; + + // Get the signal level from the audio track. + // Return true on success, otherwise false. + // TODO(deadbeef): Change the interface to int GetSignalLevel() and pure + // virtual after it's implemented in chromium. + virtual bool GetSignalLevel(int* level) { return false; } + + // Get the audio processor used by the audio track. Return null if the track + // does not have any processor. + // TODO(deadbeef): Make the interface pure virtual. + virtual rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() { + return nullptr; + } + + protected: + virtual ~AudioTrackInterface() {} +}; + +typedef std::vector<rtc::scoped_refptr<AudioTrackInterface> > + AudioTrackVector; +typedef std::vector<rtc::scoped_refptr<VideoTrackInterface> > + VideoTrackVector; + +// C++ version of https://www.w3.org/TR/mediacapture-streams/#mediastream. +// +// A major difference is that remote audio/video tracks (received by a +// PeerConnection/RtpReceiver) are not synchronized simply by adding them to +// the same stream; a session description with the correct "a=msid" attributes +// must be pushed down. +// +// Thus, this interface acts as simply a container for tracks. +class MediaStreamInterface : public rtc::RefCountInterface, + public NotifierInterface { + public: + // TODO(steveanton): This could be renamed to id() to match the spec. + virtual std::string label() const = 0; + + virtual AudioTrackVector GetAudioTracks() = 0; + virtual VideoTrackVector GetVideoTracks() = 0; + virtual rtc::scoped_refptr<AudioTrackInterface> + FindAudioTrack(const std::string& track_id) = 0; + virtual rtc::scoped_refptr<VideoTrackInterface> + FindVideoTrack(const std::string& track_id) = 0; + + virtual bool AddTrack(AudioTrackInterface* track) = 0; + virtual bool AddTrack(VideoTrackInterface* track) = 0; + virtual bool RemoveTrack(AudioTrackInterface* track) = 0; + virtual bool RemoveTrack(VideoTrackInterface* track) = 0; + + protected: + virtual ~MediaStreamInterface() {} +}; + +} // namespace webrtc + +#endif // API_MEDIASTREAMINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediastreamproxy.h b/third_party/libwebrtc/webrtc/api/mediastreamproxy.h new file mode 100644 index 0000000000..e32d52b16b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastreamproxy.h @@ -0,0 +1,44 @@ +/* + * Copyright 2011 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 API_MEDIASTREAMPROXY_H_ +#define API_MEDIASTREAMPROXY_H_ + +#include <string> + +#include "api/mediastreaminterface.h" +#include "api/proxy.h" + +namespace webrtc { + +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_SIGNALING_PROXY_MAP(MediaStream) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_CONSTMETHOD0(std::string, label) + PROXY_METHOD0(AudioTrackVector, GetAudioTracks) + PROXY_METHOD0(VideoTrackVector, GetVideoTracks) + PROXY_METHOD1(rtc::scoped_refptr<AudioTrackInterface>, + FindAudioTrack, + const std::string&) + PROXY_METHOD1(rtc::scoped_refptr<VideoTrackInterface>, + FindVideoTrack, + const std::string&) + PROXY_METHOD1(bool, AddTrack, AudioTrackInterface*) + PROXY_METHOD1(bool, AddTrack, VideoTrackInterface*) + PROXY_METHOD1(bool, RemoveTrack, AudioTrackInterface*) + PROXY_METHOD1(bool, RemoveTrack, VideoTrackInterface*) + PROXY_METHOD1(void, RegisterObserver, ObserverInterface*) + PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_MEDIASTREAMPROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediastreamtrack.h b/third_party/libwebrtc/webrtc/api/mediastreamtrack.h new file mode 100644 index 0000000000..4b214a48d0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastreamtrack.h @@ -0,0 +1,18 @@ +/* + * Copyright 2011 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 API_MEDIASTREAMTRACK_H_ +#define API_MEDIASTREAMTRACK_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/mediastreamtrack.h" + +#endif // API_MEDIASTREAMTRACK_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediastreamtrackproxy.h b/third_party/libwebrtc/webrtc/api/mediastreamtrackproxy.h new file mode 100644 index 0000000000..57a7695599 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediastreamtrackproxy.h @@ -0,0 +1,65 @@ +/* + * Copyright 2011 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. + */ + +// This file includes proxy classes for tracks. The purpose is +// to make sure tracks are only accessed from the signaling thread. + +#ifndef API_MEDIASTREAMTRACKPROXY_H_ +#define API_MEDIASTREAMTRACKPROXY_H_ + +#include <string> + +#include "api/mediastreaminterface.h" +#include "api/proxy.h" + +namespace webrtc { + +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. + +BEGIN_SIGNALING_PROXY_MAP(AudioTrack) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_CONSTMETHOD0(std::string, kind) + PROXY_CONSTMETHOD0(std::string, id) + PROXY_CONSTMETHOD0(TrackState, state) + PROXY_CONSTMETHOD0(bool, enabled) + PROXY_CONSTMETHOD0(AudioSourceInterface*, GetSource) + PROXY_METHOD1(void, AddSink, AudioTrackSinkInterface*) + PROXY_METHOD1(void, RemoveSink, AudioTrackSinkInterface*) + PROXY_METHOD1(bool, GetSignalLevel, int*) + PROXY_METHOD0(rtc::scoped_refptr<AudioProcessorInterface>, GetAudioProcessor) + PROXY_METHOD1(bool, set_enabled, bool) + PROXY_METHOD1(void, RegisterObserver, ObserverInterface*) + PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*) +END_PROXY_MAP() + +BEGIN_PROXY_MAP(VideoTrack) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_CONSTMETHOD0(std::string, kind) + PROXY_CONSTMETHOD0(std::string, id) + PROXY_CONSTMETHOD0(TrackState, state) + PROXY_CONSTMETHOD0(bool, enabled) + PROXY_METHOD1(bool, set_enabled, bool) + PROXY_CONSTMETHOD0(ContentHint, content_hint) + PROXY_METHOD1(void, set_content_hint, ContentHint) + PROXY_WORKER_METHOD2(void, + AddOrUpdateSink, + rtc::VideoSinkInterface<VideoFrame>*, + const rtc::VideoSinkWants&) + PROXY_WORKER_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<VideoFrame>*) + PROXY_CONSTMETHOD0(VideoTrackSourceInterface*, GetSource) + + PROXY_METHOD1(void, RegisterObserver, ObserverInterface*) + PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_MEDIASTREAMTRACKPROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/mediatypes.cc b/third_party/libwebrtc/webrtc/api/mediatypes.cc new file mode 100644 index 0000000000..599542db08 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediatypes.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2016 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 "api/mediatypes.h" + +#include "api/mediastreaminterface.h" +#include "rtc_base/checks.h" + +namespace { +static const char* kMediaTypeData = "data"; +} // namespace + +namespace cricket { + +std::string MediaTypeToString(MediaType type) { + switch (type) { + case MEDIA_TYPE_AUDIO: + return webrtc::MediaStreamTrackInterface::kAudioKind; + case MEDIA_TYPE_VIDEO: + return webrtc::MediaStreamTrackInterface::kVideoKind; + case MEDIA_TYPE_DATA: + return kMediaTypeData; + } + FATAL(); + // Not reachable; avoids compile warning. + return ""; +} + +MediaType MediaTypeFromString(const std::string& type_str) { + if (type_str == webrtc::MediaStreamTrackInterface::kAudioKind) { + return MEDIA_TYPE_AUDIO; + } else if (type_str == webrtc::MediaStreamTrackInterface::kVideoKind) { + return MEDIA_TYPE_VIDEO; + } else if (type_str == kMediaTypeData) { + return MEDIA_TYPE_DATA; + } + FATAL(); + // Not reachable; avoids compile warning. + return static_cast<MediaType>(-1); +} + +} // namespace cricket diff --git a/third_party/libwebrtc/webrtc/api/mediatypes.h b/third_party/libwebrtc/webrtc/api/mediatypes.h new file mode 100644 index 0000000000..93ce1a231d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/mediatypes.h @@ -0,0 +1,31 @@ +/* + * Copyright 2016 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 API_MEDIATYPES_H_ +#define API_MEDIATYPES_H_ + +#include <string> + +namespace cricket { + +enum MediaType { + MEDIA_TYPE_AUDIO, + MEDIA_TYPE_VIDEO, + MEDIA_TYPE_DATA +}; + +std::string MediaTypeToString(MediaType type); +// Aborts on invalid string. Only expected to be used on strings that are +// guaranteed to be valid, such as MediaStreamTrackInterface::kind(). +MediaType MediaTypeFromString(const std::string& type_str); + +} // namespace cricket + +#endif // API_MEDIATYPES_H_ diff --git a/third_party/libwebrtc/webrtc/api/notifier.h b/third_party/libwebrtc/webrtc/api/notifier.h new file mode 100644 index 0000000000..ceeda4de55 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/notifier.h @@ -0,0 +1,61 @@ +/* + * Copyright 2011 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 API_NOTIFIER_H_ +#define API_NOTIFIER_H_ + +#include <list> + +#include "api/mediastreaminterface.h" +#include "rtc_base/checks.h" + +namespace webrtc { + +// Implements a template version of a notifier. +// TODO(deadbeef): This is an implementation detail; move out of api/. +template <class T> +class Notifier : public T { + public: + Notifier() { + } + + virtual void RegisterObserver(ObserverInterface* observer) { + RTC_DCHECK(observer != nullptr); + observers_.push_back(observer); + } + + virtual void UnregisterObserver(ObserverInterface* observer) { + for (std::list<ObserverInterface*>::iterator it = observers_.begin(); + it != observers_.end(); it++) { + if (*it == observer) { + observers_.erase(it); + break; + } + } + } + + void FireOnChanged() { + // Copy the list of observers to avoid a crash if the observer object + // unregisters as a result of the OnChanged() call. If the same list is used + // UnregisterObserver will affect the list make the iterator invalid. + std::list<ObserverInterface*> observers = observers_; + for (std::list<ObserverInterface*>::iterator it = observers.begin(); + it != observers.end(); ++it) { + (*it)->OnChanged(); + } + } + + protected: + std::list<ObserverInterface*> observers_; +}; + +} // namespace webrtc + +#endif // API_NOTIFIER_H_ diff --git a/third_party/libwebrtc/webrtc/api/optional.cc b/third_party/libwebrtc/webrtc/api/optional.cc new file mode 100644 index 0000000000..0f74bd2446 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/optional.cc @@ -0,0 +1,34 @@ +/* + * Copyright 2016 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 "api/optional.h" + +namespace rtc { +namespace optional_internal { + +#if RTC_HAS_ASAN + +const void* FunctionThatDoesNothingImpl(const void* x) { + return x; +} + +#endif + +struct NulloptArg { + constexpr NulloptArg() {} +}; + +static NulloptArg nullopt_arg; + +} // namespace optional_internal + +const nullopt_t nullopt(rtc::optional_internal::nullopt_arg); + +} // namespace rtc diff --git a/third_party/libwebrtc/webrtc/api/optional.h b/third_party/libwebrtc/webrtc/api/optional.h new file mode 100644 index 0000000000..c74d53b9ae --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/optional.h @@ -0,0 +1,450 @@ +/* + * Copyright 2015 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 API_OPTIONAL_H_ +#define API_OPTIONAL_H_ + +#include <algorithm> +#include <memory> +#include <utility> + +#ifdef UNIT_TEST +#include <iomanip> +#include <ostream> +#endif // UNIT_TEST + +#include "api/array_view.h" +#include "rtc_base/checks.h" +#include "rtc_base/sanitizer.h" + +namespace rtc { + +namespace optional_internal { + +#if RTC_HAS_ASAN + +// This is a non-inlined function. The optimizer can't see inside it. It +// prevents the compiler from generating optimized code that reads value_ even +// if it is unset. Although safe, this causes memory sanitizers to complain. +const void* FunctionThatDoesNothingImpl(const void*); + +template <typename T> +inline const T* FunctionThatDoesNothing(const T* x) { + return reinterpret_cast<const T*>( + FunctionThatDoesNothingImpl(reinterpret_cast<const void*>(x))); +} + + +#else + +template <typename T> +inline T* FunctionThatDoesNothing(T* x) { + return x; +} + +#endif + +struct NulloptArg; + +} // namespace optional_internal + +// nullopt_t must be a non-aggregate literal type with a constexpr constructor +// that takes some implementation-defined literal type. It mustn't have a +// default constructor nor an initializer-list constructor. +// See: +// http://en.cppreference.com/w/cpp/utility/optional/nullopt_t +// That page uses int, though this seems to confuse older versions of GCC. +struct nullopt_t { + constexpr explicit nullopt_t(rtc::optional_internal::NulloptArg&) {} +}; + +// Specification: +// http://en.cppreference.com/w/cpp/utility/optional/nullopt +extern const nullopt_t nullopt; + +// Simple std::optional-wannabe. It either contains a T or not. +// +// A moved-from Optional<T> may only be destroyed, and assigned to if T allows +// being assigned to after having been moved from. Specifically, you may not +// assume that it just doesn't contain a value anymore. +// +// Examples of good places to use Optional: +// +// - As a class or struct member, when the member doesn't always have a value: +// struct Prisoner { +// std::string name; +// Optional<int> cell_number; // Empty if not currently incarcerated. +// }; +// +// - As a return value for functions that may fail to return a value on all +// allowed inputs. For example, a function that searches an array might +// return an Optional<size_t> (the index where it found the element, or +// nothing if it didn't find it); and a function that parses numbers might +// return Optional<double> (the parsed number, or nothing if parsing failed). +// +// Examples of bad places to use Optional: +// +// - As a return value for functions that may fail because of disallowed +// inputs. For example, a string length function should not return +// Optional<size_t> so that it can return nothing in case the caller passed +// it a null pointer; the function should probably use RTC_[D]CHECK instead, +// and return plain size_t. +// +// - As a return value for functions that may fail to return a value on all +// allowed inputs, but need to tell the caller what went wrong. Returning +// Optional<double> when parsing a single number as in the example above +// might make sense, but any larger parse job is probably going to need to +// tell the caller what the problem was, not just that there was one. +// +// - As a non-mutable function argument. When you want to pass a value of a +// type T that can fail to be there, const T* is almost always both fastest +// and cleanest. (If you're *sure* that the the caller will always already +// have an Optional<T>, const Optional<T>& is slightly faster than const T*, +// but this is a micro-optimization. In general, stick to const T*.) +// +// TODO(kwiberg): Get rid of this class when the standard library has +// std::optional (and we're allowed to use it). +template <typename T> +class Optional final { + public: + // Construct an empty Optional. + Optional() : has_value_(false), empty_('\0') { PoisonValue(); } + + Optional(rtc::nullopt_t) // NOLINT(runtime/explicit) + : Optional() {} + + // Construct an Optional that contains a value. + Optional(const T& value) // NOLINT(runtime/explicit) + : has_value_(true) { + new (&value_) T(value); + } + Optional(T&& value) // NOLINT(runtime/explicit) + : has_value_(true) { + new (&value_) T(std::move(value)); + } + + // Copy constructor: copies the value from m if it has one. + Optional(const Optional& m) : has_value_(m.has_value_) { + if (has_value_) + new (&value_) T(m.value_); + else + PoisonValue(); + } + + // Move constructor: if m has a value, moves the value from m, leaving m + // still in a state where it has a value, but a moved-from one (the + // properties of which depends on T; the only general guarantee is that we + // can destroy m). + Optional(Optional&& m) : has_value_(m.has_value_) { + if (has_value_) + new (&value_) T(std::move(m.value_)); + else + PoisonValue(); + } + + ~Optional() { + if (has_value_) + value_.~T(); + else + UnpoisonValue(); + } + + Optional& operator=(rtc::nullopt_t) { + reset(); + return *this; + } + + // Copy assignment. Uses T's copy assignment if both sides have a value, T's + // copy constructor if only the right-hand side has a value. + Optional& operator=(const Optional& m) { + if (m.has_value_) { + if (has_value_) { + value_ = m.value_; // T's copy assignment. + } else { + UnpoisonValue(); + new (&value_) T(m.value_); // T's copy constructor. + has_value_ = true; + } + } else { + reset(); + } + return *this; + } + + // Move assignment. Uses T's move assignment if both sides have a value, T's + // move constructor if only the right-hand side has a value. The state of m + // after it's been moved from is as for the move constructor. + Optional& operator=(Optional&& m) { + if (m.has_value_) { + if (has_value_) { + value_ = std::move(m.value_); // T's move assignment. + } else { + UnpoisonValue(); + new (&value_) T(std::move(m.value_)); // T's move constructor. + has_value_ = true; + } + } else { + reset(); + } + return *this; + } + + // Swap the values if both m1 and m2 have values; move the value if only one + // of them has one. + friend void swap(Optional& m1, Optional& m2) { + if (m1.has_value_) { + if (m2.has_value_) { + // Both have values: swap. + using std::swap; + swap(m1.value_, m2.value_); + } else { + // Only m1 has a value: move it to m2. + m2.UnpoisonValue(); + new (&m2.value_) T(std::move(m1.value_)); + m1.value_.~T(); // Destroy the moved-from value. + m1.has_value_ = false; + m2.has_value_ = true; + m1.PoisonValue(); + } + } else if (m2.has_value_) { + // Only m2 has a value: move it to m1. + m1.UnpoisonValue(); + new (&m1.value_) T(std::move(m2.value_)); + m2.value_.~T(); // Destroy the moved-from value. + m1.has_value_ = true; + m2.has_value_ = false; + m2.PoisonValue(); + } + } + + // Destroy any contained value. Has no effect if we have no value. + void reset() { + if (!has_value_) + return; + value_.~T(); + has_value_ = false; + PoisonValue(); + } + + template <class... Args> + void emplace(Args&&... args) { + if (has_value_) + value_.~T(); + else + UnpoisonValue(); + new (&value_) T(std::forward<Args>(args)...); + has_value_ = true; + } + + // Conversion to bool to test if we have a value. + explicit operator bool() const { return has_value_; } + bool has_value() const { return has_value_; } + + // Dereferencing. Only allowed if we have a value. + const T* operator->() const { + RTC_DCHECK(has_value_); + return &value_; + } + T* operator->() { + RTC_DCHECK(has_value_); + return &value_; + } + const T& operator*() const { + RTC_DCHECK(has_value_); + return value_; + } + T& operator*() { + RTC_DCHECK(has_value_); + return value_; + } + const T& value() const { + RTC_DCHECK(has_value_); + return value_; + } + T& value() { + RTC_DCHECK(has_value_); + return value_; + } + + // Dereference with a default value in case we don't have a value. + const T& value_or(const T& default_val) const { + // The no-op call prevents the compiler from generating optimized code that + // reads value_ even if !has_value_, but only if FunctionThatDoesNothing is + // not completely inlined; see its declaration.). + return has_value_ ? *optional_internal::FunctionThatDoesNothing(&value_) + : default_val; + } + + // Dereference and move value. + T MoveValue() { + RTC_DCHECK(has_value_); + return std::move(value_); + } + + // Equality tests. Two Optionals are equal if they contain equivalent values, + // or if they're both empty. + friend bool operator==(const Optional& m1, const Optional& m2) { + return m1.has_value_ && m2.has_value_ ? m1.value_ == m2.value_ + : m1.has_value_ == m2.has_value_; + } + friend bool operator==(const Optional& opt, const T& value) { + return opt.has_value_ && opt.value_ == value; + } + friend bool operator==(const T& value, const Optional& opt) { + return opt.has_value_ && value == opt.value_; + } + + friend bool operator==(const Optional& opt, rtc::nullopt_t) { + return !opt.has_value_; + } + + friend bool operator==(rtc::nullopt_t, const Optional& opt) { + return !opt.has_value_; + } + + friend bool operator!=(const Optional& m1, const Optional& m2) { + return m1.has_value_ && m2.has_value_ ? m1.value_ != m2.value_ + : m1.has_value_ != m2.has_value_; + } + friend bool operator!=(const Optional& opt, const T& value) { + return !opt.has_value_ || opt.value_ != value; + } + friend bool operator!=(const T& value, const Optional& opt) { + return !opt.has_value_ || value != opt.value_; + } + + friend bool operator!=(const Optional& opt, rtc::nullopt_t) { + return opt.has_value_; + } + + friend bool operator!=(rtc::nullopt_t, const Optional& opt) { + return opt.has_value_; + } + + private: + // Tell sanitizers that value_ shouldn't be touched. + void PoisonValue() { + rtc::AsanPoison(rtc::MakeArrayView(&value_, 1)); + rtc::MsanMarkUninitialized(rtc::MakeArrayView(&value_, 1)); + } + + // Tell sanitizers that value_ is OK to touch again. + void UnpoisonValue() { rtc::AsanUnpoison(rtc::MakeArrayView(&value_, 1)); } + + bool has_value_; // True iff value_ contains a live value. + union { + // empty_ exists only to make it possible to initialize the union, even when + // it doesn't contain any data. If the union goes uninitialized, it may + // trigger compiler warnings. + char empty_; + // By placing value_ in a union, we get to manage its construction and + // destruction manually: the Optional constructors won't automatically + // construct it, and the Optional destructor won't automatically destroy + // it. Basically, this just allocates a properly sized and aligned block of + // memory in which we can manually put a T with placement new. + T value_; + }; +}; + +#ifdef UNIT_TEST +namespace optional_internal { + +// Checks if there's a valid PrintTo(const T&, std::ostream*) call for T. +template <typename T> +struct HasPrintTo { + private: + struct No {}; + + template <typename T2> + static auto Test(const T2& obj) + -> decltype(PrintTo(obj, std::declval<std::ostream*>())); + + template <typename> + static No Test(...); + + public: + static constexpr bool value = + !std::is_same<decltype(Test<T>(std::declval<const T&>())), No>::value; +}; + +// Checks if there's a valid operator<<(std::ostream&, const T&) call for T. +template <typename T> +struct HasOstreamOperator { + private: + struct No {}; + + template <typename T2> + static auto Test(const T2& obj) + -> decltype(std::declval<std::ostream&>() << obj); + + template <typename> + static No Test(...); + + public: + static constexpr bool value = + !std::is_same<decltype(Test<T>(std::declval<const T&>())), No>::value; +}; + +// Prefer using PrintTo to print the object. +template <typename T> +typename std::enable_if<HasPrintTo<T>::value, void>::type OptionalPrintToHelper( + const T& value, + std::ostream* os) { + PrintTo(value, os); +} + +// Fall back to operator<<(std::ostream&, ...) if it exists. +template <typename T> +typename std::enable_if<HasOstreamOperator<T>::value && !HasPrintTo<T>::value, + void>::type +OptionalPrintToHelper(const T& value, std::ostream* os) { + *os << value; +} + +inline void OptionalPrintObjectBytes(const unsigned char* bytes, + size_t size, + std::ostream* os) { + *os << "<optional with " << size << "-byte object ["; + for (size_t i = 0; i != size; ++i) { + *os << (i == 0 ? "" : ((i & 1) ? "-" : " ")); + *os << std::hex << std::setw(2) << std::setfill('0') + << static_cast<int>(bytes[i]); + } + *os << "]>"; +} + +// As a final back-up, just print the contents of the objcets byte-wise. +template <typename T> +typename std::enable_if<!HasOstreamOperator<T>::value && !HasPrintTo<T>::value, + void>::type +OptionalPrintToHelper(const T& value, std::ostream* os) { + OptionalPrintObjectBytes(reinterpret_cast<const unsigned char*>(&value), + sizeof(value), os); +} + +} // namespace optional_internal + +// PrintTo is used by gtest to print out the results of tests. We want to ensure +// the object contained in an Optional can be printed out if it's set, while +// avoiding touching the object's storage if it is undefined. +template <typename T> +void PrintTo(const rtc::Optional<T>& opt, std::ostream* os) { + if (opt) { + optional_internal::OptionalPrintToHelper(*opt, os); + } else { + *os << "<empty optional>"; + } +} + +#endif // UNIT_TEST + +} // namespace rtc + +#endif // API_OPTIONAL_H_ diff --git a/third_party/libwebrtc/webrtc/api/optional_gn/moz.build b/third_party/libwebrtc/webrtc/api/optional_gn/moz.build new file mode 100644 index 0000000000..c20d31385a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/optional_gn/moz.build @@ -0,0 +1,217 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/optional.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("optional_gn") diff --git a/third_party/libwebrtc/webrtc/api/optional_unittest.cc b/third_party/libwebrtc/webrtc/api/optional_unittest.cc new file mode 100644 index 0000000000..2149033f40 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/optional_unittest.cc @@ -0,0 +1,902 @@ +/* + * Copyright 2015 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 <memory> +#include <sstream> +#include <string> +#include <utility> +#include <vector> + +#include "api/optional.h" +#include "rtc_base/gunit.h" + +namespace rtc { + +namespace { + +struct MyUnprintableType { + int value; +}; + +struct MyPrintableType { + int value; +}; + +struct MyOstreamPrintableType { + int value; +}; + +void PrintTo(const MyPrintableType& mpt, std::ostream* os) { + *os << "The value is " << mpt.value; +} + +std::ostream& operator<<(std::ostream& os, const MyPrintableType& mpt) { + os << mpt.value; + return os; +} + +std::ostream& operator<<(std::ostream& os, const MyOstreamPrintableType& mpt) { + os << mpt.value; + return os; +} + +// Class whose instances logs various method calls (constructor, destructor, +// etc.). Each instance has a unique ID (a simple global sequence number) and +// an origin ID. When a copy is made, the new object gets a fresh ID but copies +// the origin ID from the original. When a new Logger is created from scratch, +// it gets a fresh ID, and the origin ID is the same as the ID (default +// constructor) or given as an argument (explicit constructor). +class Logger { + public: + Logger() : id_(g_next_id++), origin_(id_) { Log("default constructor"); } + explicit Logger(int origin) : id_(g_next_id++), origin_(origin) { + Log("explicit constructor"); + } + Logger(int origin, const Logger& pass_by_ref, Logger pass_by_value) + : id_(g_next_id++), origin_(origin) { + Log("multi parameter constructor"); + } + Logger(const Logger& other) : id_(g_next_id++), origin_(other.origin_) { + LogFrom("copy constructor", other); + } + Logger(Logger&& other) : id_(g_next_id++), origin_(other.origin_) { + LogFrom("move constructor", other); + } + ~Logger() { Log("destructor"); } + Logger& operator=(const Logger& other) { + origin_ = other.origin_; + LogFrom("operator= copy", other); + return *this; + } + Logger& operator=(Logger&& other) { + origin_ = other.origin_; + LogFrom("operator= move", other); + return *this; + } + friend void swap(Logger& a, Logger& b) { + using std::swap; + swap(a.origin_, b.origin_); + Log2("swap", a, b); + } + friend bool operator==(const Logger& a, const Logger& b) { + Log2("operator==", a, b); + return a.origin_ == b.origin_; + } + friend bool operator!=(const Logger& a, const Logger& b) { + Log2("operator!=", a, b); + return a.origin_ != b.origin_; + } + void Foo() { Log("Foo()"); } + void Foo() const { Log("Foo() const"); } + static std::unique_ptr<std::vector<std::string>> Setup() { + std::unique_ptr<std::vector<std::string>> s(new std::vector<std::string>); + g_log = s.get(); + g_next_id = 0; + return s; + } + + private: + int id_; + int origin_; + static std::vector<std::string>* g_log; + static int g_next_id; + void Log(const char* msg) const { + std::ostringstream oss; + oss << id_ << ':' << origin_ << ". " << msg; + g_log->push_back(oss.str()); + } + void LogFrom(const char* msg, const Logger& other) const { + std::ostringstream oss; + oss << id_ << ':' << origin_ << ". " << msg << " (from " << other.id_ << ':' + << other.origin_ << ")"; + g_log->push_back(oss.str()); + } + static void Log2(const char* msg, const Logger& a, const Logger& b) { + std::ostringstream oss; + oss << msg << ' ' << a.id_ << ':' << a.origin_ << ", " << b.id_ << ':' + << b.origin_; + g_log->push_back(oss.str()); + } +}; + +std::vector<std::string>* Logger::g_log = nullptr; +int Logger::g_next_id = 0; + +// Append all the other args to the vector pointed to by the first arg. +template <typename T> +void VectorAppend(std::vector<T>* v) {} +template <typename T, typename... Ts> +void VectorAppend(std::vector<T>* v, const T& e, Ts... es) { + v->push_back(e); + VectorAppend(v, es...); +} + +// Create a vector of strings. Because we're not allowed to use +// std::initializer_list. +template <typename... Ts> +std::vector<std::string> V(Ts... es) { + std::vector<std::string> strings; + VectorAppend(&strings, static_cast<std::string>(es)...); + return strings; +} + +} // namespace + +TEST(OptionalTest, TestConstructDefault) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + EXPECT_FALSE(x); + EXPECT_FALSE(x.has_value()); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestConstructNullopt) { + auto log = Logger::Setup(); + { + Optional<Logger> x(nullopt); + EXPECT_FALSE(x); + EXPECT_FALSE(x.has_value()); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestConstructCopyEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + EXPECT_FALSE(x); + EXPECT_FALSE(x.has_value()); + auto y = x; + EXPECT_FALSE(y); + EXPECT_FALSE(y.has_value()); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestConstructCopyFull) { + auto log = Logger::Setup(); + { + Logger a; + Optional<Logger> x(a); + EXPECT_TRUE(x); + EXPECT_TRUE(x.has_value()); + log->push_back("---"); + auto y = x; + EXPECT_TRUE(y); + EXPECT_TRUE(y.has_value()); + log->push_back("---"); + } + EXPECT_EQ(V("0:0. default constructor", "1:0. copy constructor (from 0:0)", + "---", "2:0. copy constructor (from 1:0)", "---", + "2:0. destructor", "1:0. destructor", "0:0. destructor"), + *log); +} + +TEST(OptionalTest, TestConstructMoveEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + EXPECT_FALSE(x); + EXPECT_FALSE(x.has_value()); + auto y = std::move(x); + EXPECT_FALSE(y); + EXPECT_FALSE(y.has_value()); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestConstructMoveFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + EXPECT_TRUE(x); + EXPECT_TRUE(x.has_value()); + log->push_back("---"); + auto y = std::move(x); + EXPECT_TRUE(x); + EXPECT_TRUE(x.has_value()); + EXPECT_TRUE(y); + EXPECT_TRUE(y.has_value()); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---", + "2:17. destructor", "1:17. destructor"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToEmptyFromEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x, y; + x = y; + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestCopyAssignToFullFromEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Optional<Logger> y; + log->push_back("---"); + x = y; + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "1:17. destructor", "---"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToFullFromNullopt) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + log->push_back("---"); + x = nullopt; + log->push_back("---"); + EXPECT_FALSE(x); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "1:17. destructor", "---"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToFullFromEmptyBraces) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + log->push_back("---"); + x = {}; + log->push_back("---"); + EXPECT_FALSE(x); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "1:17. destructor", "---"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToEmptyFromFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Optional<Logger> y(Logger(17)); + log->push_back("---"); + x = y; + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "2:17. copy constructor (from 1:17)", "---", + "1:17. destructor", "2:17. destructor"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToFullFromFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Optional<Logger> y(Logger(42)); + log->push_back("---"); + x = y; + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "2:42. explicit constructor", + "3:42. move constructor (from 2:42)", "2:42. destructor", "---", + "1:42. operator= copy (from 3:42)", "---", "3:42. destructor", + "1:42. destructor"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToEmptyFromT) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Logger y(17); + log->push_back("---"); + x = Optional<Logger>(y); + log->push_back("---"); + } + EXPECT_EQ(V("0:17. explicit constructor", "---", + "1:17. copy constructor (from 0:17)", + "2:17. move constructor (from 1:17)", "1:17. destructor", "---", + "0:17. destructor", "2:17. destructor"), + *log); +} + +TEST(OptionalTest, TestCopyAssignToFullFromT) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Logger y(42); + log->push_back("---"); + x = Optional<Logger>(y); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "2:42. explicit constructor", "---", + "3:42. copy constructor (from 2:42)", + "1:42. operator= move (from 3:42)", "3:42. destructor", "---", + "2:42. destructor", "1:42. destructor"), + *log); +} + +TEST(OptionalTest, TestMoveAssignToEmptyFromEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x, y; + x = std::move(y); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestMoveAssignToFullFromEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Optional<Logger> y; + log->push_back("---"); + x = std::move(y); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "1:17. destructor", "---"), + *log); +} + +TEST(OptionalTest, TestMoveAssignToEmptyFromFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Optional<Logger> y(Logger(17)); + log->push_back("---"); + x = std::move(y); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "2:17. move constructor (from 1:17)", "---", + "1:17. destructor", "2:17. destructor"), + *log); +} + +TEST(OptionalTest, TestMoveAssignToFullFromFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Optional<Logger> y(Logger(42)); + log->push_back("---"); + x = std::move(y); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "2:42. explicit constructor", + "3:42. move constructor (from 2:42)", "2:42. destructor", "---", + "1:42. operator= move (from 3:42)", "---", "3:42. destructor", + "1:42. destructor"), + *log); +} + +TEST(OptionalTest, TestMoveAssignToEmptyFromT) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Logger y(17); + log->push_back("---"); + x = Optional<Logger>(std::move(y)); + log->push_back("---"); + } + EXPECT_EQ(V("0:17. explicit constructor", "---", + "1:17. move constructor (from 0:17)", + "2:17. move constructor (from 1:17)", "1:17. destructor", "---", + "0:17. destructor", "2:17. destructor"), + *log); +} + +TEST(OptionalTest, TestMoveAssignToFullFromT) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Logger y(42); + log->push_back("---"); + x = Optional<Logger>(std::move(y)); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "2:42. explicit constructor", "---", + "3:42. move constructor (from 2:42)", + "1:42. operator= move (from 3:42)", "3:42. destructor", "---", + "2:42. destructor", "1:42. destructor"), + *log); +} + +TEST(OptionalTest, TestResetEmpty) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + x.reset(); + } + EXPECT_EQ(V(), *log); +} + +TEST(OptionalTest, TestResetFull) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + log->push_back("---"); + x.reset(); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:17. move constructor (from 0:17)", + "0:17. destructor", "---", "1:17. destructor", "---"), + *log); +} + +TEST(OptionalTest, TestEmplaceEmptyWithExplicit) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + log->push_back("---"); + x.emplace(42); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("---", + "0:42. explicit constructor", + "---", + "0:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceEmptyWithMultipleParameters) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Logger ref(21); + Logger value(35); + log->push_back("---"); + x.emplace(42, ref, std::move(value)); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:21. explicit constructor", + "1:35. explicit constructor", + "---", + "2:35. move constructor (from 1:35)", + "3:42. multi parameter constructor", + "2:35. destructor", + "---", + "1:35. destructor", + "0:21. destructor", + "3:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceEmptyWithCopy) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Logger y(42); + log->push_back("---"); + x.emplace(y); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:42. explicit constructor", + "---", + "1:42. copy constructor (from 0:42)", + "---", + "0:42. destructor", + "1:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceEmptyWithMove) { + auto log = Logger::Setup(); + { + Optional<Logger> x; + Logger y(42); + log->push_back("---"); + x.emplace(std::move(y)); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:42. explicit constructor", + "---", + "1:42. move constructor (from 0:42)", + "---", + "0:42. destructor", + "1:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceFullWithExplicit) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + log->push_back("---"); + x.emplace(42); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ( + V("0:17. explicit constructor", + "1:17. move constructor (from 0:17)", + "0:17. destructor", + "---", + "1:17. destructor", + "2:42. explicit constructor", + "---", + "2:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceFullWithMultipleParameters) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Logger ref(21); + Logger value(35); + log->push_back("---"); + x.emplace(42, ref, std::move(value)); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:17. explicit constructor", + "1:17. move constructor (from 0:17)", + "0:17. destructor", + "2:21. explicit constructor", + "3:35. explicit constructor", + "---", + "1:17. destructor", + "4:35. move constructor (from 3:35)", + "5:42. multi parameter constructor", + "4:35. destructor", + "---", + "3:35. destructor", + "2:21. destructor", + "5:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceFullWithCopy) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Logger y(42); + log->push_back("---"); + x.emplace(y); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:17. explicit constructor", + "1:17. move constructor (from 0:17)", + "0:17. destructor", + "2:42. explicit constructor", + "---", + "1:17. destructor", + "3:42. copy constructor (from 2:42)", + "---", + "2:42. destructor", + "3:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEmplaceFullWithMove) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(17)); + Logger y(42); + log->push_back("---"); + x.emplace(std::move(y)); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:17. explicit constructor", + "1:17. move constructor (from 0:17)", + "0:17. destructor", + "2:42. explicit constructor", + "---", + "1:17. destructor", + "3:42. move constructor (from 2:42)", + "---", + "2:42. destructor", + "3:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestDereference) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(42)); + const auto& y = x; + log->push_back("---"); + x->Foo(); + y->Foo(); + std::move(x)->Foo(); + std::move(y)->Foo(); + log->push_back("---"); + (*x).Foo(); + (*y).Foo(); + (*std::move(x)).Foo(); + (*std::move(y)).Foo(); + log->push_back("---"); + x.value().Foo(); + y.value().Foo(); + std::move(x).value().Foo(); + std::move(y).value().Foo(); + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:42. explicit constructor", + "1:42. move constructor (from 0:42)", + "0:42. destructor", + "---", + "1:42. Foo()", + "1:42. Foo() const", + "1:42. Foo()", + "1:42. Foo() const", + "---", + "1:42. Foo()", + "1:42. Foo() const", + "1:42. Foo()", + "1:42. Foo() const", + "---", + "1:42. Foo()", + "1:42. Foo() const", + "1:42. Foo()", + "1:42. Foo() const", + "---", + "1:42. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestDereferenceWithDefault) { + auto log = Logger::Setup(); + { + const Logger a(17), b(42); + Optional<Logger> x(a); + Optional<Logger> y; + log->push_back("-1-"); + EXPECT_EQ(a, x.value_or(Logger(42))); + log->push_back("-2-"); + EXPECT_EQ(b, y.value_or(Logger(42))); + log->push_back("-3-"); + EXPECT_EQ(a, Optional<Logger>(Logger(17)).value_or(b)); + log->push_back("-4-"); + EXPECT_EQ(b, Optional<Logger>().value_or(b)); + log->push_back("-5-"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:42. explicit constructor", + "2:17. copy constructor (from 0:17)", "-1-", + "3:42. explicit constructor", "operator== 0:17, 2:17", + "3:42. destructor", "-2-", "4:42. explicit constructor", + "operator== 1:42, 4:42", "4:42. destructor", "-3-", + "5:17. explicit constructor", "6:17. move constructor (from 5:17)", + "operator== 0:17, 6:17", "6:17. destructor", "5:17. destructor", "-4-", + "operator== 1:42, 1:42", "-5-", "2:17. destructor", "1:42. destructor", + "0:17. destructor"), + *log); +} + +TEST(OptionalTest, TestEquality) { + auto log = Logger::Setup(); + { + Logger a(17), b(42); + Optional<Logger> ma1(a), ma2(a), mb(b), me1, me2; + log->push_back("---"); + EXPECT_EQ(ma1, ma1); + EXPECT_EQ(ma1, ma2); + EXPECT_NE(ma1, mb); + EXPECT_NE(ma1, me1); + EXPECT_EQ(me1, me1); + EXPECT_EQ(me1, me2); + log->push_back("---"); + } + EXPECT_EQ( + V("0:17. explicit constructor", "1:42. explicit constructor", + "2:17. copy constructor (from 0:17)", + "3:17. copy constructor (from 0:17)", + "4:42. copy constructor (from 1:42)", "---", "operator== 2:17, 2:17", + "operator== 2:17, 3:17", "operator!= 2:17, 4:42", "---", + "4:42. destructor", "3:17. destructor", "2:17. destructor", + "1:42. destructor", "0:17. destructor"), + *log); +} + +TEST(OptionalTest, TestEqualityWithNullopt) { + auto log = Logger::Setup(); + { + Logger a(17); + Optional<Logger> ma(a), me; + // Using operator== and operator!= explicitly instead of EXPECT_EQ/EXPECT_NE + // macros because those operators are under test. + log->push_back("---"); + + EXPECT_FALSE(ma == nullopt); + EXPECT_FALSE(nullopt == ma); + EXPECT_TRUE(me == nullopt); + EXPECT_TRUE(nullopt == me); + + EXPECT_TRUE(ma != nullopt); + EXPECT_TRUE(nullopt != ma); + EXPECT_FALSE(me != nullopt); + EXPECT_FALSE(nullopt != me); + + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:17. explicit constructor", + "1:17. copy constructor (from 0:17)", + "---", + // No operators should be called when comparing to empty. + "---", + "1:17. destructor", + "0:17. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestEqualityWithObject) { + auto log = Logger::Setup(); + { + Logger a(17), b(42); + Optional<Logger> ma(a), me; + // Using operator== and operator!= explicitly instead of EXPECT_EQ/EXPECT_NE + // macros because those operators are under test. + log->push_back("---"); + + EXPECT_TRUE(ma == a); + EXPECT_TRUE(a == ma); + EXPECT_FALSE(ma == b); + EXPECT_FALSE(b == ma); + EXPECT_FALSE(me == a); + EXPECT_FALSE(a == me); + + EXPECT_FALSE(ma != a); + EXPECT_FALSE(a != ma); + EXPECT_TRUE(ma != b); + EXPECT_TRUE(b != ma); + EXPECT_TRUE(me != a); + EXPECT_TRUE(a != me); + + log->push_back("---"); + } + // clang-format off + EXPECT_EQ(V("0:17. explicit constructor", + "1:42. explicit constructor", + "2:17. copy constructor (from 0:17)", + "---", + "operator== 2:17, 0:17", + "operator== 0:17, 2:17", + "operator== 2:17, 1:42", + "operator== 1:42, 2:17", + // No operator should be called when comparing to empty. + "operator!= 2:17, 0:17", + "operator!= 0:17, 2:17", + "operator!= 2:17, 1:42", + "operator!= 1:42, 2:17", + // No operator should be called when comparing to empty. + "---", + "2:17. destructor", + "1:42. destructor", + "0:17. destructor"), + *log); + // clang-format on +} + +TEST(OptionalTest, TestSwap) { + auto log = Logger::Setup(); + { + Logger a(17), b(42); + Optional<Logger> x1(a), x2(b), y1(a), y2, z1, z2; + log->push_back("---"); + swap(x1, x2); // Swap full <-> full. + swap(y1, y2); // Swap full <-> empty. + swap(z1, z2); // Swap empty <-> empty. + log->push_back("---"); + } + EXPECT_EQ(V("0:17. explicit constructor", "1:42. explicit constructor", + "2:17. copy constructor (from 0:17)", + "3:42. copy constructor (from 1:42)", + "4:17. copy constructor (from 0:17)", "---", "swap 2:42, 3:17", + "5:17. move constructor (from 4:17)", "4:17. destructor", "---", + "5:17. destructor", "3:17. destructor", "2:42. destructor", + "1:42. destructor", "0:17. destructor"), + *log); +} + +TEST(OptionalTest, TestMoveValue) { + auto log = Logger::Setup(); + { + Optional<Logger> x(Logger(42)); + log->push_back("---"); + Logger moved = x.MoveValue(); + log->push_back("---"); + } + EXPECT_EQ( + V("0:42. explicit constructor", "1:42. move constructor (from 0:42)", + "0:42. destructor", "---", "2:42. move constructor (from 1:42)", "---", + "2:42. destructor", "1:42. destructor"), + *log); +} + +TEST(OptionalTest, TestPrintTo) { + constexpr char kEmptyOptionalMessage[] = "<empty optional>"; + const Optional<MyUnprintableType> empty_unprintable; + const Optional<MyPrintableType> empty_printable; + const Optional<MyOstreamPrintableType> empty_ostream_printable; + EXPECT_EQ(kEmptyOptionalMessage, ::testing::PrintToString(empty_unprintable)); + EXPECT_EQ(kEmptyOptionalMessage, ::testing::PrintToString(empty_printable)); + EXPECT_EQ(kEmptyOptionalMessage, + ::testing::PrintToString(empty_ostream_printable)); + EXPECT_NE("1", ::testing::PrintToString(Optional<MyUnprintableType>({1}))); + EXPECT_NE("1", ::testing::PrintToString(Optional<MyPrintableType>({1}))); + EXPECT_EQ("The value is 1", + ::testing::PrintToString(Optional<MyPrintableType>({1}))); + EXPECT_EQ("1", + ::testing::PrintToString(Optional<MyOstreamPrintableType>({1}))); +} + +void UnusedFunctionWorkaround() { + // These are here to ensure we don't get warnings about ostream and PrintTo + // for MyPrintableType never getting called. + const MyPrintableType dont_warn{17}; + const MyOstreamPrintableType dont_warn2{18}; + std::stringstream sstr; + sstr << dont_warn; + PrintTo(dont_warn, &sstr); + sstr << dont_warn2; +} + +} // namespace rtc diff --git a/third_party/libwebrtc/webrtc/api/ortc/mediadescription.cc b/third_party/libwebrtc/webrtc/api/ortc/mediadescription.cc new file mode 100644 index 0000000000..d5155f22fe --- /dev/null +++ b/third_party/libwebrtc/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 "api/ortc/mediadescription.h" + +namespace webrtc {} diff --git a/third_party/libwebrtc/webrtc/api/ortc/mediadescription.h b/third_party/libwebrtc/webrtc/api/ortc/mediadescription.h new file mode 100644 index 0000000000..1a6d0e9037 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/mediadescription.h @@ -0,0 +1,53 @@ +/* + * 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 API_ORTC_MEDIADESCRIPTION_H_ +#define API_ORTC_MEDIADESCRIPTION_H_ + +#include <string> +#include <utility> +#include <vector> + +#include "api/cryptoparams.h" +#include "api/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<std::string> mid() const { return mid_; } + void set_mid(std::string mid) { mid_.emplace(std::move(mid)); } + + // Security keys and parameters for this media stream. Can be used to + // negotiate parameters for SRTP. + // https://tools.ietf.org/html/rfc4568#page-5 + std::vector<cricket::CryptoParams>& sdes_params() { return sdes_params_; } + const std::vector<cricket::CryptoParams>& sdes_params() const { + return sdes_params_; + } + + private: + rtc::Optional<std::string> mid_; + + std::vector<cricket::CryptoParams> sdes_params_; +}; + +} // namespace webrtc + +#endif // API_ORTC_MEDIADESCRIPTION_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/mediadescription_unittest.cc b/third_party/libwebrtc/webrtc/api/ortc/mediadescription_unittest.cc new file mode 100644 index 0000000000..9ff943af6f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/mediadescription_unittest.cc @@ -0,0 +1,30 @@ +/* + * 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 "api/ortc/mediadescription.h" +#include "test/gtest.h" + +namespace webrtc { + +class MediaDescriptionTest : public testing::Test {}; + +TEST_F(MediaDescriptionTest, CreateMediaDescription) { + MediaDescription m("a"); + EXPECT_EQ("a", m.mid()); +} + +TEST_F(MediaDescriptionTest, AddSdesParam) { + MediaDescription m("a"); + m.sdes_params().push_back(cricket::CryptoParams()); + const std::vector<cricket::CryptoParams>& params = m.sdes_params(); + EXPECT_EQ(1u, params.size()); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/ortc/ortcfactoryinterface.h b/third_party/libwebrtc/webrtc/api/ortc/ortcfactoryinterface.h new file mode 100644 index 0000000000..d99fcd4465 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/ortcfactoryinterface.h @@ -0,0 +1,246 @@ +/* + * 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 API_ORTC_ORTCFACTORYINTERFACE_H_ +#define API_ORTC_ORTCFACTORYINTERFACE_H_ + +#include <memory> +#include <string> +#include <utility> // For std::move. + +#include "api/mediaconstraintsinterface.h" +#include "api/mediastreaminterface.h" +#include "api/mediatypes.h" +#include "api/ortc/ortcrtpreceiverinterface.h" +#include "api/ortc/ortcrtpsenderinterface.h" +#include "api/ortc/packettransportinterface.h" +#include "api/ortc/rtptransportcontrollerinterface.h" +#include "api/ortc/rtptransportinterface.h" +#include "api/ortc/srtptransportinterface.h" +#include "api/ortc/udptransportinterface.h" +#include "api/rtcerror.h" +#include "api/rtpparameters.h" +#include "rtc_base/network.h" +#include "rtc_base/scoped_ref_ptr.h" +#include "rtc_base/thread.h" + +namespace webrtc { + +// TODO(deadbeef): This should be part of /api/, but currently it's not and +// including its header violates checkdeps rules. +class AudioDeviceModule; + +// WARNING: This is experimental/under development, so use at your own risk; no +// guarantee about API stability is guaranteed here yet. +// +// This class is the ORTC analog of PeerConnectionFactory. It acts as a factory +// for ORTC objects that can be connected to each other. +// +// Some of these objects may not be represented by the ORTC specification, but +// follow the same general principles. +// +// If one of the factory methods takes another object as an argument, it MUST +// have been created by the same OrtcFactory. +// +// On object lifetimes: objects should be destroyed in this order: +// 1. Objects created by the factory. +// 2. The factory itself. +// 3. Objects passed into OrtcFactoryInterface::Create. +class OrtcFactoryInterface { + public: + // |network_thread| is the thread on which packets are sent and received. + // If null, a new rtc::Thread with a default socket server is created. + // + // |signaling_thread| is used for callbacks to the consumer of the API. If + // null, the current thread will be used, which assumes that the API consumer + // is running a message loop on this thread (either using an existing + // rtc::Thread, or by calling rtc::Thread::Current()->ProcessMessages). + // + // |network_manager| is used to determine which network interfaces are + // available. This is used for ICE, for example. If null, a default + // implementation will be used. Only accessed on |network_thread|. + // + // |socket_factory| is used (on the network thread) for creating sockets. If + // it's null, a default implementation will be used, which assumes + // |network_thread| is a normal rtc::Thread. + // + // |adm| is optional, and allows a different audio device implementation to + // be injected; otherwise a platform-specific module will be used that will + // use the default audio input. + // + // |audio_encoder_factory| and |audio_decoder_factory| are used to + // instantiate audio codecs; they determine what codecs are supported. + // + // Note that the OrtcFactoryInterface does not take ownership of any of the + // objects passed in by raw pointer, and as previously stated, these objects + // can't be destroyed before the factory is. + static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create( + rtc::Thread* network_thread, + rtc::Thread* signaling_thread, + rtc::NetworkManager* network_manager, + rtc::PacketSocketFactory* socket_factory, + AudioDeviceModule* adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory); + + // Constructor for convenience which uses default implementations where + // possible (though does still require that the current thread runs a message + // loop; see above). + static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create( + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) { + return Create(nullptr, nullptr, nullptr, nullptr, nullptr, + audio_encoder_factory, audio_decoder_factory); + } + + virtual ~OrtcFactoryInterface() {} + + // Creates an RTP transport controller, which is used in calls to + // CreateRtpTransport methods. If your application has some notion of a + // "call", you should create one transport controller per call. + // + // However, if you only are using one RtpTransport object, this doesn't need + // to be called explicitly; CreateRtpTransport will create one automatically + // if |rtp_transport_controller| is null. See below. + // + // TODO(deadbeef): Add MediaConfig and RtcEventLog arguments? + virtual RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>> + CreateRtpTransportController() = 0; + + // Creates an RTP transport using the provided packet transports and + // transport controller. + // + // |rtp| will be used for sending RTP packets, and |rtcp| for RTCP packets. + // + // |rtp| can't be null. |rtcp| must be non-null if and only if + // |rtp_parameters.rtcp.mux| is false, indicating that RTCP muxing isn't used. + // Note that if RTCP muxing isn't enabled initially, it can still enabled + // later through SetParameters. + // + // If |transport_controller| is null, one will automatically be created, and + // its lifetime managed by the returned RtpTransport. This should only be + // done if a single RtpTransport is being used to communicate with the remote + // endpoint. + virtual RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport( + const RtpTransportParameters& rtp_parameters, + PacketTransportInterface* rtp, + PacketTransportInterface* rtcp, + RtpTransportControllerInterface* transport_controller) = 0; + + // Creates an SrtpTransport which is an RTP transport that uses SRTP. + virtual RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> + CreateSrtpTransport( + const RtpTransportParameters& rtp_parameters, + PacketTransportInterface* rtp, + PacketTransportInterface* rtcp, + RtpTransportControllerInterface* transport_controller) = 0; + + // Returns the capabilities of an RTP sender of type |kind|. These + // capabilities can be used to determine what RtpParameters to use to create + // an RtpSender. + // + // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure. + virtual RtpCapabilities GetRtpSenderCapabilities( + cricket::MediaType kind) const = 0; + + // Creates an RTP sender with |track|. Will not start sending until Send is + // called. This is provided as a convenience; it's equivalent to calling + // CreateRtpSender with a kind (see below), followed by SetTrack. + // + // |track| and |transport| must not be null. + virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( + rtc::scoped_refptr<MediaStreamTrackInterface> track, + RtpTransportInterface* transport) = 0; + + // Overload of CreateRtpSender allows creating the sender without a track. + // + // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO. + virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( + cricket::MediaType kind, + RtpTransportInterface* transport) = 0; + + // Returns the capabilities of an RTP receiver of type |kind|. These + // capabilities can be used to determine what RtpParameters to use to create + // an RtpReceiver. + // + // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure. + virtual RtpCapabilities GetRtpReceiverCapabilities( + cricket::MediaType kind) const = 0; + + // Creates an RTP receiver of type |kind|. Will not start receiving media + // until Receive is called. + // + // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO. + // + // |transport| must not be null. + virtual RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> + CreateRtpReceiver(cricket::MediaType kind, + RtpTransportInterface* transport) = 0; + + // Create a UDP transport with IP address family |family|, using a port + // within the specified range. + // + // |family| must be AF_INET or AF_INET6. + // + // |min_port|/|max_port| values of 0 indicate no range restriction. + // + // Returns an error if the transport wasn't successfully created. + virtual RTCErrorOr<std::unique_ptr<UdpTransportInterface>> + CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) = 0; + + // Method for convenience that has no port range restrictions. + RTCErrorOr<std::unique_ptr<UdpTransportInterface>> CreateUdpTransport( + int family) { + return CreateUdpTransport(family, 0, 0); + } + + // NOTE: The methods below to create tracks/sources return scoped_refptrs + // rather than unique_ptrs, because these interfaces are also used with + // PeerConnection, where everything is ref-counted. + + // Creates a audio source representing the default microphone input. + // |options| decides audio processing settings. + virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( + const cricket::AudioOptions& options) = 0; + + // Version of the above method that uses default options. + rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource() { + return CreateAudioSource(cricket::AudioOptions()); + } + + // Creates a video source object wrapping and taking ownership of |capturer|. + // + // |constraints| can be used for selection of resolution and frame rate, and + // may be null if no constraints are desired. + virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + std::unique_ptr<cricket::VideoCapturer> capturer, + const MediaConstraintsInterface* constraints) = 0; + + // Version of the above method that omits |constraints|. + rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + std::unique_ptr<cricket::VideoCapturer> capturer) { + return CreateVideoSource(std::move(capturer), nullptr); + } + + // Creates a new local video track wrapping |source|. The same |source| can + // be used in several tracks. + virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( + const std::string& id, + VideoTrackSourceInterface* source) = 0; + + // Creates an new local audio track wrapping |source|. + virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( + const std::string& id, + AudioSourceInterface* source) = 0; +}; + +} // namespace webrtc + +#endif // API_ORTC_ORTCFACTORYINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/ortcrtpreceiverinterface.h b/third_party/libwebrtc/webrtc/api/ortc/ortcrtpreceiverinterface.h new file mode 100644 index 0000000000..59ff977621 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/ortcrtpreceiverinterface.h @@ -0,0 +1,84 @@ +/* + * 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. + */ + +// This file contains interfaces for RtpReceivers: +// http://publications.ortc.org/2016/20161202/#rtcrtpreceiver* +// +// However, underneath the RtpReceiver is an RtpTransport, rather than a +// DtlsTransport. This is to allow different types of RTP transports (besides +// DTLS-SRTP) to be used. + +#ifndef API_ORTC_ORTCRTPRECEIVERINTERFACE_H_ +#define API_ORTC_ORTCRTPRECEIVERINTERFACE_H_ + +#include "api/mediastreaminterface.h" +#include "api/mediatypes.h" +#include "api/ortc/rtptransportinterface.h" +#include "api/rtcerror.h" +#include "api/rtpparameters.h" + +namespace webrtc { + +// Note: Since receiver capabilities may depend on how the OrtcFactory was +// created, instead of a static "GetCapabilities" method on this interface, +// there is a "GetRtpReceiverCapabilities" method on the OrtcFactory. +class OrtcRtpReceiverInterface { + public: + virtual ~OrtcRtpReceiverInterface() {} + + // Returns a track representing the media received by this receiver. + // + // Currently, this will return null until Receive has been successfully + // called. Also, a new track will be created every time the primary SSRC + // changes. + // + // If encodings are removed, GetTrack will return null. Though deactivating + // an encoding (setting |active| to false) will not do this. + // + // In the future, these limitations will be fixed, and GetTrack will return + // the same track for the lifetime of the RtpReceiver. So it's not + // recommended to write code that depends on this non-standard behavior. + virtual rtc::scoped_refptr<MediaStreamTrackInterface> GetTrack() const = 0; + + // Once supported, will switch to receiving media on a new transport. + // However, this is not currently supported and will always return an error. + virtual RTCError SetTransport(RtpTransportInterface* transport) = 0; + // Returns previously set (or constructed-with) transport. + virtual RtpTransportInterface* GetTransport() const = 0; + + // Start receiving media with |parameters| (if |parameters| contains an + // active encoding). + // + // There are no limitations to how the parameters can be changed after the + // initial call to Receive, as long as they're valid (for example, they can't + // use the same payload type for two codecs). + virtual RTCError Receive(const RtpParameters& parameters) = 0; + // Returns parameters that were last successfully passed into Receive, or + // empty parameters if that hasn't yet occurred. + // + // Note that for parameters that are described as having an "implementation + // default" value chosen, GetParameters() will return those chosen defaults, + // with the exception of SSRCs which have special behavior. See + // rtpparameters.h for more details. + virtual RtpParameters GetParameters() const = 0; + + // Audio or video receiver? + // + // Once GetTrack() starts always returning a track, this method will be + // redundant, as one can call "GetTrack()->kind()". However, it's still a + // nice convenience, and is symmetric with OrtcRtpSenderInterface::GetKind. + virtual cricket::MediaType GetKind() const = 0; + + // TODO(deadbeef): GetContributingSources +}; + +} // namespace webrtc + +#endif // API_ORTC_ORTCRTPRECEIVERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/ortcrtpsenderinterface.h b/third_party/libwebrtc/webrtc/api/ortc/ortcrtpsenderinterface.h new file mode 100644 index 0000000000..fd4dfaa790 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/ortcrtpsenderinterface.h @@ -0,0 +1,77 @@ +/* + * 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. + */ + +// This file contains interfaces for RtpSenders: +// http://publications.ortc.org/2016/20161202/#rtcrtpsender* +// +// However, underneath the RtpSender is an RtpTransport, rather than a +// DtlsTransport. This is to allow different types of RTP transports (besides +// DTLS-SRTP) to be used. + +#ifndef API_ORTC_ORTCRTPSENDERINTERFACE_H_ +#define API_ORTC_ORTCRTPSENDERINTERFACE_H_ + +#include "api/mediastreaminterface.h" +#include "api/mediatypes.h" +#include "api/ortc/rtptransportinterface.h" +#include "api/rtcerror.h" +#include "api/rtpparameters.h" + +namespace webrtc { + +// Note: Since sender capabilities may depend on how the OrtcFactory was +// created, instead of a static "GetCapabilities" method on this interface, +// there is a "GetRtpSenderCapabilities" method on the OrtcFactory. +class OrtcRtpSenderInterface { + public: + virtual ~OrtcRtpSenderInterface() {} + + // Sets the source of media that will be sent by this sender. + // + // If Send has already been called, will immediately switch to sending this + // track. If |track| is null, will stop sending media. + // + // Returns INVALID_PARAMETER error if an audio track is set on a video + // RtpSender, or vice-versa. + virtual RTCError SetTrack(MediaStreamTrackInterface* track) = 0; + // Returns previously set (or constructed-with) track. + virtual rtc::scoped_refptr<MediaStreamTrackInterface> GetTrack() const = 0; + + // Once supported, will switch to sending media on a new transport. However, + // this is not currently supported and will always return an error. + virtual RTCError SetTransport(RtpTransportInterface* transport) = 0; + // Returns previously set (or constructed-with) transport. + virtual RtpTransportInterface* GetTransport() const = 0; + + // Start sending media with |parameters| (if |parameters| contains an active + // encoding). + // + // There are no limitations to how the parameters can be changed after the + // initial call to Send, as long as they're valid (for example, they can't + // use the same payload type for two codecs). + virtual RTCError Send(const RtpParameters& parameters) = 0; + // Returns parameters that were last successfully passed into Send, or empty + // parameters if that hasn't yet occurred. + // + // Note that for parameters that are described as having an "implementation + // default" value chosen, GetParameters() will return those chosen defaults, + // with the exception of SSRCs which have special behavior. See + // rtpparameters.h for more details. + virtual RtpParameters GetParameters() const = 0; + + // Audio or video sender? + virtual cricket::MediaType GetKind() const = 0; + + // TODO(deadbeef): SSRC conflict signal. +}; + +} // namespace webrtc + +#endif // API_ORTC_ORTCRTPSENDERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/packettransportinterface.h b/third_party/libwebrtc/webrtc/api/ortc/packettransportinterface.h new file mode 100644 index 0000000000..9d53ad311b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/packettransportinterface.h @@ -0,0 +1,38 @@ +/* + * 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 API_ORTC_PACKETTRANSPORTINTERFACE_H_ +#define API_ORTC_PACKETTRANSPORTINTERFACE_H_ + +namespace rtc { + +class PacketTransportInternal; + +} // namespace rtc + +namespace webrtc { + +// Base class for different packet-based transports. +class PacketTransportInterface { + public: + virtual ~PacketTransportInterface() {} + + protected: + // Only for internal use. Returns a pointer to an internal interface, for use + // by the implementation. + virtual rtc::PacketTransportInternal* GetInternal() = 0; + + // Classes that can use this internal interface. + friend class RtpTransportControllerAdapter; +}; + +} // namespace webrtc + +#endif // API_ORTC_PACKETTRANSPORTINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/rtptransportcontrollerinterface.h b/third_party/libwebrtc/webrtc/api/ortc/rtptransportcontrollerinterface.h new file mode 100644 index 0000000000..85f37fa7a0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/rtptransportcontrollerinterface.h @@ -0,0 +1,57 @@ +/* + * 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 API_ORTC_RTPTRANSPORTCONTROLLERINTERFACE_H_ +#define API_ORTC_RTPTRANSPORTCONTROLLERINTERFACE_H_ + +#include <vector> + +#include "api/ortc/rtptransportinterface.h" + +namespace webrtc { + +class RtpTransportControllerAdapter; + +// Used to group RTP transports between a local endpoint and the same remote +// endpoint, for the purpose of sharing bandwidth estimation and other things. +// +// Comparing this to the PeerConnection model, non-budled audio/video would use +// two RtpTransports with a single RtpTransportController, whereas bundled +// media would use a single RtpTransport, and two PeerConnections would use +// independent RtpTransportControllers. +// +// RtpTransports are associated with this controller when they're created, by +// passing the controller into OrtcFactory's relevant "CreateRtpTransport" +// method. When a transport is destroyed, it's automatically disassociated. +// GetTransports returns all currently associated transports. +// +// This is the RTP equivalent of "IceTransportController" in ORTC; RtpTransport +// is to RtpTransportController as IceTransport is to IceTransportController. +class RtpTransportControllerInterface { + public: + virtual ~RtpTransportControllerInterface() {} + + // Returns all transports associated with this controller (see explanation + // above). No ordering is guaranteed. + virtual std::vector<RtpTransportInterface*> GetTransports() const = 0; + + protected: + // Only for internal use. Returns a pointer to an internal interface, for use + // by the implementation. + virtual RtpTransportControllerAdapter* GetInternal() = 0; + + // Classes that can use this internal interface. + friend class OrtcFactory; + friend class RtpTransportAdapter; +}; + +} // namespace webrtc + +#endif // API_ORTC_RTPTRANSPORTCONTROLLERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/rtptransportinterface.h b/third_party/libwebrtc/webrtc/api/ortc/rtptransportinterface.h new file mode 100644 index 0000000000..3c58fad9fd --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/rtptransportinterface.h @@ -0,0 +1,123 @@ +/* + * 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 API_ORTC_RTPTRANSPORTINTERFACE_H_ +#define API_ORTC_RTPTRANSPORTINTERFACE_H_ + +#include <string> + +#include "api/optional.h" +#include "api/ortc/packettransportinterface.h" +#include "api/rtcerror.h" +#include "common_types.h" // NOLINT(build/include) + +namespace webrtc { + +class RtpTransportAdapter; + +struct RtcpParameters final { + // The SSRC to be used in the "SSRC of packet sender" field. If not set, one + // will be chosen by the implementation. + // TODO(deadbeef): Not implemented. + rtc::Optional<uint32_t> ssrc; + + // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages). + // + // If empty in the construction of the RtpTransport, one will be generated by + // the implementation, and returned in GetRtcpParameters. Multiple + // RtpTransports created by the same OrtcFactory will use the same generated + // CNAME. + // + // If empty when passed into SetParameters, the CNAME simply won't be + // modified. + std::string cname; + + // Send reduced-size RTCP? + bool reduced_size = false; + + // Send RTCP multiplexed on the RTP transport? + bool mux = true; + + bool operator==(const RtcpParameters& o) const { + return ssrc == o.ssrc && cname == o.cname && + reduced_size == o.reduced_size && mux == o.mux; + } + bool operator!=(const RtcpParameters& o) const { return !(*this == o); } +}; + +struct RtpTransportParameters final { + RtcpParameters rtcp; + + // Enabled periodic sending of keep-alive packets, that help prevent timeouts + // on the network level, such as NAT bindings. See RFC6263 section 4.6. + RtpKeepAliveConfig keepalive; + + bool operator==(const RtpTransportParameters& o) const { + return rtcp == o.rtcp && keepalive == o.keepalive; + } + bool operator!=(const RtpTransportParameters& o) const { + return !(*this == o); + } +}; + +// Base class for different types of RTP transports that can be created by an +// OrtcFactory. Used by RtpSenders/RtpReceivers. +// +// This is not present in the standard ORTC API, but exists here for a few +// reasons. Firstly, it allows different types of RTP transports to be used: +// DTLS-SRTP (which is required for the web), but also SDES-SRTP and +// unencrypted RTP. It also simplifies the handling of RTCP muxing, and +// provides a better API point for it. +// +// Note that Edge's implementation of ORTC provides a similar API point, called +// RTCSrtpSdesTransport: +// https://msdn.microsoft.com/en-us/library/mt502527(v=vs.85).aspx +class RtpTransportInterface { + public: + virtual ~RtpTransportInterface() {} + + // Returns packet transport that's used to send RTP packets. + virtual PacketTransportInterface* GetRtpPacketTransport() const = 0; + + // Returns separate packet transport that's used to send RTCP packets. If + // RTCP multiplexing is being used, returns null. + virtual PacketTransportInterface* GetRtcpPacketTransport() const = 0; + + // Set/get RTP/RTCP transport params. Can be used to enable RTCP muxing or + // reduced-size RTCP if initially not enabled. + // + // Changing |mux| from "true" to "false" is not allowed, and changing the + // CNAME is currently unsupported. + // RTP keep-alive settings need to be set before before an RtpSender has + // started sending, altering the payload type or timeout interval after this + // point is not supported. The parameters must also match across all RTP + // transports for a given RTP transport controller. + virtual RTCError SetParameters(const RtpTransportParameters& parameters) = 0; + // Returns last set or constructed-with parameters. If |cname| was empty in + // construction, the generated CNAME will be present in the returned + // parameters (see above). + virtual RtpTransportParameters GetParameters() const = 0; + + protected: + // Only for internal use. Returns a pointer to an internal interface, for use + // by the implementation. + virtual RtpTransportAdapter* GetInternal() = 0; + + // Classes that can use this internal interface. + friend class OrtcFactory; + friend class OrtcRtpSenderAdapter; + friend class OrtcRtpReceiverAdapter; + friend class RtpTransportControllerAdapter; + friend class RtpTransportAdapter; +}; + +} // namespace webrtc + +#endif // API_ORTC_RTPTRANSPORTINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/sessiondescription.cc b/third_party/libwebrtc/webrtc/api/ortc/sessiondescription.cc new file mode 100644 index 0000000000..1078884ecb --- /dev/null +++ b/third_party/libwebrtc/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 "api/ortc/sessiondescription.h" + +namespace webrtc {} diff --git a/third_party/libwebrtc/webrtc/api/ortc/sessiondescription.h b/third_party/libwebrtc/webrtc/api/ortc/sessiondescription.h new file mode 100644 index 0000000000..ebbaa27d6f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/sessiondescription.h @@ -0,0 +1,45 @@ +/* + * 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 API_ORTC_SESSIONDESCRIPTION_H_ +#define API_ORTC_SESSIONDESCRIPTION_H_ + +#include <string> +#include <utility> + +namespace webrtc { + +// A structured representation of an SDP session description. +class SessionDescription { + public: + SessionDescription(int64_t session_id, std::string session_version) + : session_id_(session_id), session_version_(std::move(session_version)) {} + + // https://tools.ietf.org/html/rfc4566#section-5.2 + // o=<username> <sess-id> <sess-version> <nettype> <addrtype> + // <unicast-address> + // session_id_ is the "sess-id" field. + // session_version_ is the "sess-version" field. + int64_t session_id() { return session_id_; } + void set_session_id(int64_t session_id) { session_id_ = 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: + int64_t session_id_; + std::string session_version_; +}; + +} // namespace webrtc + +#endif // API_ORTC_SESSIONDESCRIPTION_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/sessiondescription_unittest.cc b/third_party/libwebrtc/webrtc/api/ortc/sessiondescription_unittest.cc new file mode 100644 index 0000000000..fd6f43de43 --- /dev/null +++ b/third_party/libwebrtc/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 "api/ortc/sessiondescription.h" +#include "test/gtest.h" + +namespace webrtc { + +class SessionDescriptionTest : public testing::Test {}; + +TEST_F(SessionDescriptionTest, CreateSessionDescription) { + SessionDescription s(-1, "0"); + EXPECT_EQ(-1, s.session_id()); + EXPECT_EQ("0", s.session_version()); +} +} diff --git a/third_party/libwebrtc/webrtc/api/ortc/srtptransportinterface.h b/third_party/libwebrtc/webrtc/api/ortc/srtptransportinterface.h new file mode 100644 index 0000000000..41c8ccc9c1 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/srtptransportinterface.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 API_ORTC_SRTPTRANSPORTINTERFACE_H_ +#define API_ORTC_SRTPTRANSPORTINTERFACE_H_ + +#include "api/ortc/rtptransportinterface.h" +#include "api/rtcerror.h" +#include "api/cryptoparams.h" + +namespace webrtc { + +// The subclass of the RtpTransport which uses SRTP. The keying information +// is explicitly passed in from the application. +// +// If using SDP and SDES (RFC4568) for signaling, then after applying the +// answer, the negotiated keying information from the offer and answer would be +// set and the SRTP would be active. +// +// Note that Edge's implementation of ORTC provides a similar API point, called +// RTCSrtpSdesTransport: +// https://msdn.microsoft.com/en-us/library/mt502527(v=vs.85).aspx +class SrtpTransportInterface : public RtpTransportInterface { + public: + virtual ~SrtpTransportInterface() {} + + // There are some limitations of the current implementation: + // 1. Send and receive keys must use the same crypto suite. + // 2. The keys can't be changed after initially set. + // 3. The keys must be set before creating a sender/receiver using the SRTP + // transport. + // Set the SRTP keying material for sending RTP and RTCP. + virtual RTCError SetSrtpSendKey(const cricket::CryptoParams& params) = 0; + + // Set the SRTP keying material for receiving RTP and RTCP. + virtual RTCError SetSrtpReceiveKey(const cricket::CryptoParams& params) = 0; +}; + +} // namespace webrtc + +#endif // API_ORTC_SRTPTRANSPORTINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/ortc/udptransportinterface.h b/third_party/libwebrtc/webrtc/api/ortc/udptransportinterface.h new file mode 100644 index 0000000000..f246a25e9d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/ortc/udptransportinterface.h @@ -0,0 +1,49 @@ +/* + * 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 API_ORTC_UDPTRANSPORTINTERFACE_H_ +#define API_ORTC_UDPTRANSPORTINTERFACE_H_ + +#include "api/ortc/packettransportinterface.h" +#include "api/proxy.h" +#include "rtc_base/socketaddress.h" + +namespace webrtc { + +// Interface for a raw UDP transport (not using ICE), meaning a combination of +// a local/remote IP address/port. +// +// An instance can be instantiated using OrtcFactory. +// +// Each instance reserves a UDP port, which will be freed when the +// UdpTransportInterface destructor is called. +// +// Calling SetRemoteAddress sets the destination of outgoing packets; without a +// destination, packets can't be sent, but they can be received. +class UdpTransportInterface : public virtual PacketTransportInterface { + public: + // Get the address of the socket allocated for this transport. + virtual rtc::SocketAddress GetLocalAddress() const = 0; + + // Sets the address to which packets will be delivered. + // + // Calling with a "nil" (default-constructed) address is legal, and unsets + // any previously set destination. + // + // However, calling with an incomplete address (port or IP not set) will + // fail. + virtual bool SetRemoteAddress(const rtc::SocketAddress& dest) = 0; + // Simple getter. If never set, returns nil address. + virtual rtc::SocketAddress GetRemoteAddress() const = 0; +}; + +} // namespace webrtc + +#endif // API_ORTC_UDPTRANSPORTINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/peerconnectionfactoryproxy.h b/third_party/libwebrtc/webrtc/api/peerconnectionfactoryproxy.h new file mode 100644 index 0000000000..7601ed144e --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/peerconnectionfactoryproxy.h @@ -0,0 +1,73 @@ +/* + * Copyright 2014 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 API_PEERCONNECTIONFACTORYPROXY_H_ +#define API_PEERCONNECTIONFACTORYPROXY_H_ + +#include <memory> +#include <string> +#include <utility> + +#include "api/peerconnectioninterface.h" +#include "api/proxy.h" +#include "rtc_base/bind.h" + +namespace webrtc { + +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_SIGNALING_PROXY_MAP(PeerConnectionFactory) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + // Use the overloads of CreateVideoSource that take raw VideoCapturer + // pointers from PeerConnectionFactoryInterface. + // TODO(deadbeef): Remove this using statement once those overloads are + // removed. + using PeerConnectionFactoryInterface::CreateVideoSource; + PROXY_METHOD1(void, SetOptions, const Options&) + PROXY_METHOD5(rtc::scoped_refptr<PeerConnectionInterface>, + CreatePeerConnection, + const PeerConnectionInterface::RTCConfiguration&, + const MediaConstraintsInterface*, + std::unique_ptr<cricket::PortAllocator>, + std::unique_ptr<rtc::RTCCertificateGeneratorInterface>, + PeerConnectionObserver*); + PROXY_METHOD4(rtc::scoped_refptr<PeerConnectionInterface>, + CreatePeerConnection, + const PeerConnectionInterface::RTCConfiguration&, + std::unique_ptr<cricket::PortAllocator>, + std::unique_ptr<rtc::RTCCertificateGeneratorInterface>, + PeerConnectionObserver*); + PROXY_METHOD1(rtc::scoped_refptr<MediaStreamInterface>, + CreateLocalMediaStream, const std::string&) + PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>, + CreateAudioSource, const MediaConstraintsInterface*) + PROXY_METHOD1(rtc::scoped_refptr<AudioSourceInterface>, + CreateAudioSource, + const cricket::AudioOptions&) + PROXY_METHOD2(rtc::scoped_refptr<VideoTrackSourceInterface>, + CreateVideoSource, + std::unique_ptr<cricket::VideoCapturer>, + const MediaConstraintsInterface*) + PROXY_METHOD1(rtc::scoped_refptr<VideoTrackSourceInterface>, + CreateVideoSource, + std::unique_ptr<cricket::VideoCapturer>) + PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>, + CreateVideoTrack, + const std::string&, + VideoTrackSourceInterface*) + PROXY_METHOD2(rtc::scoped_refptr<AudioTrackInterface>, + CreateAudioTrack, const std::string&, AudioSourceInterface*) + PROXY_METHOD2(bool, StartAecDump, rtc::PlatformFile, int64_t) + PROXY_METHOD0(void, StopAecDump) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_PEERCONNECTIONFACTORYPROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/peerconnectioninterface.h b/third_party/libwebrtc/webrtc/api/peerconnectioninterface.h new file mode 100644 index 0000000000..a1e7d7ee2f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/peerconnectioninterface.h @@ -0,0 +1,1338 @@ +/* + * Copyright 2012 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. + */ + +// This file contains the PeerConnection interface as defined in +// http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections. +// +// The PeerConnectionFactory class provides factory methods to create +// PeerConnection, MediaStream and MediaStreamTrack objects. +// +// The following steps are needed to setup a typical call using WebRTC: +// +// 1. Create a PeerConnectionFactoryInterface. Check constructors for more +// information about input parameters. +// +// 2. Create a PeerConnection object. Provide a configuration struct which +// points to STUN and/or TURN servers used to generate ICE candidates, and +// provide an object that implements the PeerConnectionObserver interface, +// which is used to receive callbacks from the PeerConnection. +// +// 3. Create local MediaStreamTracks using the PeerConnectionFactory and add +// them to PeerConnection by calling AddTrack (or legacy method, AddStream). +// +// 4. Create an offer, call SetLocalDescription with it, serialize it, and send +// it to the remote peer +// +// 5. Once an ICE candidate has been gathered, the PeerConnection will call the +// observer function OnIceCandidate. The candidates must also be serialized and +// sent to the remote peer. +// +// 6. Once an answer is received from the remote peer, call +// SetRemoteDescription with the remote answer. +// +// 7. Once a remote candidate is received from the remote peer, provide it to +// the PeerConnection by calling AddIceCandidate. +// +// The receiver of a call (assuming the application is "call"-based) can decide +// to accept or reject the call; this decision will be taken by the application, +// not the PeerConnection. +// +// If the application decides to accept the call, it should: +// +// 1. Create PeerConnectionFactoryInterface if it doesn't exist. +// +// 2. Create a new PeerConnection. +// +// 3. Provide the remote offer to the new PeerConnection object by calling +// SetRemoteDescription. +// +// 4. Generate an answer to the remote offer by calling CreateAnswer and send it +// back to the remote peer. +// +// 5. Provide the local answer to the new PeerConnection by calling +// SetLocalDescription with the answer. +// +// 6. Provide the remote ICE candidates by calling AddIceCandidate. +// +// 7. Once a candidate has been gathered, the PeerConnection will call the +// observer function OnIceCandidate. Send these candidates to the remote peer. + +#ifndef API_PEERCONNECTIONINTERFACE_H_ +#define API_PEERCONNECTIONINTERFACE_H_ + +#include <memory> +#include <string> +#include <utility> +#include <vector> + +#include "api/audio_codecs/audio_decoder_factory.h" +#include "api/audio_codecs/audio_encoder_factory.h" +#include "api/datachannelinterface.h" +#include "api/dtmfsenderinterface.h" +#include "api/jsep.h" +#include "api/mediastreaminterface.h" +#include "api/rtcerror.h" +#include "api/rtceventlogoutput.h" +#include "api/rtpreceiverinterface.h" +#include "api/rtpsenderinterface.h" +#include "api/rtptransceiverinterface.h" +#include "api/setremotedescriptionobserverinterface.h" +#include "api/stats/rtcstatscollectorcallback.h" +#include "api/statstypes.h" +#include "api/turncustomizer.h" +#include "api/umametrics.h" +#include "call/callfactoryinterface.h" +#include "logging/rtc_event_log/rtc_event_log_factory_interface.h" +#include "media/base/mediachannel.h" +#include "media/base/videocapturer.h" +#include "p2p/base/portallocator.h" +#include "rtc_base/network.h" +#include "rtc_base/rtccertificate.h" +#include "rtc_base/rtccertificategenerator.h" +#include "rtc_base/socketaddress.h" +#include "rtc_base/sslstreamadapter.h" + +namespace rtc { +class SSLIdentity; +class Thread; +} + +namespace cricket { +class MediaEngineInterface; +class WebRtcVideoDecoderFactory; +class WebRtcVideoEncoderFactory; +} + +namespace webrtc { +class AudioDeviceModule; +class AudioMixer; +class CallFactoryInterface; +class MediaConstraintsInterface; +class VideoDecoderFactory; +class VideoEncoderFactory; + +// MediaStream container interface. +class StreamCollectionInterface : public rtc::RefCountInterface { + public: + // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find. + virtual size_t count() = 0; + virtual MediaStreamInterface* at(size_t index) = 0; + virtual MediaStreamInterface* find(const std::string& label) = 0; + virtual MediaStreamTrackInterface* FindAudioTrack( + const std::string& id) = 0; + virtual MediaStreamTrackInterface* FindVideoTrack( + const std::string& id) = 0; + + protected: + // Dtor protected as objects shouldn't be deleted via this interface. + ~StreamCollectionInterface() {} +}; + +class StatsObserver : public rtc::RefCountInterface { + public: + virtual void OnComplete(const StatsReports& reports) = 0; + + protected: + virtual ~StatsObserver() {} +}; + +// For now, kDefault is interpreted as kPlanB. +// TODO(bugs.webrtc.org/8530): Switch default to kUnifiedPlan. +enum class SdpSemantics { kDefault, kPlanB, kUnifiedPlan }; + +class PeerConnectionInterface : public rtc::RefCountInterface { + public: + // See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions . + enum SignalingState { + kStable, + kHaveLocalOffer, + kHaveLocalPrAnswer, + kHaveRemoteOffer, + kHaveRemotePrAnswer, + kClosed, + }; + + enum IceGatheringState { + kIceGatheringNew, + kIceGatheringGathering, + kIceGatheringComplete + }; + + enum IceConnectionState { + kIceConnectionNew, + kIceConnectionChecking, + kIceConnectionConnected, + kIceConnectionCompleted, + kIceConnectionFailed, + kIceConnectionDisconnected, + kIceConnectionClosed, + kIceConnectionMax, + }; + + // TLS certificate policy. + enum TlsCertPolicy { + // For TLS based protocols, ensure the connection is secure by not + // circumventing certificate validation. + kTlsCertPolicySecure, + // For TLS based protocols, disregard security completely by skipping + // certificate validation. This is insecure and should never be used unless + // security is irrelevant in that particular context. + kTlsCertPolicyInsecureNoCheck, + }; + + struct IceServer { + // TODO(jbauch): Remove uri when all code using it has switched to urls. + // List of URIs associated with this server. Valid formats are described + // in RFC7064 and RFC7065, and more may be added in the future. The "host" + // part of the URI may contain either an IP address or a hostname. + std::string uri; + std::vector<std::string> urls; + std::string username; + std::string password; + TlsCertPolicy tls_cert_policy = kTlsCertPolicySecure; + // If the URIs in |urls| only contain IP addresses, this field can be used + // to indicate the hostname, which may be necessary for TLS (using the SNI + // extension). If |urls| itself contains the hostname, this isn't + // necessary. + std::string hostname; + // List of protocols to be used in the TLS ALPN extension. + std::vector<std::string> tls_alpn_protocols; + // List of elliptic curves to be used in the TLS elliptic curves extension. + std::vector<std::string> tls_elliptic_curves; + + bool operator==(const IceServer& o) const { + return uri == o.uri && urls == o.urls && username == o.username && + password == o.password && tls_cert_policy == o.tls_cert_policy && + hostname == o.hostname && + tls_alpn_protocols == o.tls_alpn_protocols && + tls_elliptic_curves == o.tls_elliptic_curves; + } + bool operator!=(const IceServer& o) const { return !(*this == o); } + }; + typedef std::vector<IceServer> IceServers; + + enum IceTransportsType { + // TODO(pthatcher): Rename these kTransporTypeXXX, but update + // Chromium at the same time. + kNone, + kRelay, + kNoHost, + kAll + }; + + // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1 + enum BundlePolicy { + kBundlePolicyBalanced, + kBundlePolicyMaxBundle, + kBundlePolicyMaxCompat + }; + + // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1 + enum RtcpMuxPolicy { + kRtcpMuxPolicyNegotiate, + kRtcpMuxPolicyRequire, + }; + + enum TcpCandidatePolicy { + kTcpCandidatePolicyEnabled, + kTcpCandidatePolicyDisabled + }; + + enum CandidateNetworkPolicy { + kCandidateNetworkPolicyAll, + kCandidateNetworkPolicyLowCost + }; + + enum ContinualGatheringPolicy { + GATHER_ONCE, + GATHER_CONTINUALLY + }; + + enum class RTCConfigurationType { + // A configuration that is safer to use, despite not having the best + // performance. Currently this is the default configuration. + kSafe, + // An aggressive configuration that has better performance, although it + // may be riskier and may need extra support in the application. + kAggressive + }; + + // TODO(hbos): Change into class with private data and public getters. + // TODO(nisse): In particular, accessing fields directly from an + // application is brittle, since the organization mirrors the + // organization of the implementation, which isn't stable. So we + // need getters and setters at least for fields which applications + // are interested in. + struct RTCConfiguration { + // This struct is subject to reorganization, both for naming + // consistency, and to group settings to match where they are used + // in the implementation. To do that, we need getter and setter + // methods for all settings which are of interest to applications, + // Chrome in particular. + + RTCConfiguration() = default; + explicit RTCConfiguration(RTCConfigurationType type) { + if (type == RTCConfigurationType::kAggressive) { + // These parameters are also defined in Java and IOS configurations, + // so their values may be overwritten by the Java or IOS configuration. + bundle_policy = kBundlePolicyMaxBundle; + rtcp_mux_policy = kRtcpMuxPolicyRequire; + ice_connection_receiving_timeout = + kAggressiveIceConnectionReceivingTimeout; + + // These parameters are not defined in Java or IOS configuration, + // so their values will not be overwritten. + enable_ice_renomination = true; + redetermine_role_on_ice_restart = false; + } + } + + bool operator==(const RTCConfiguration& o) const; + bool operator!=(const RTCConfiguration& o) const; + + bool dscp() { return media_config.enable_dscp; } + void set_dscp(bool enable) { media_config.enable_dscp = enable; } + + // TODO(nisse): The corresponding flag in MediaConfig and + // elsewhere should be renamed enable_cpu_adaptation. + bool cpu_adaptation() { + return media_config.video.enable_cpu_overuse_detection; + } + void set_cpu_adaptation(bool enable) { + media_config.video.enable_cpu_overuse_detection = enable; + } + + bool suspend_below_min_bitrate() { + return media_config.video.suspend_below_min_bitrate; + } + void set_suspend_below_min_bitrate(bool enable) { + media_config.video.suspend_below_min_bitrate = enable; + } + + // TODO(nisse): The negation in the corresponding MediaConfig + // attribute is inconsistent, and it should be renamed at some + // point. + bool prerenderer_smoothing() { + return !media_config.video.disable_prerenderer_smoothing; + } + void set_prerenderer_smoothing(bool enable) { + media_config.video.disable_prerenderer_smoothing = !enable; + } + + static const int kUndefined = -1; + // Default maximum number of packets in the audio jitter buffer. + static const int kAudioJitterBufferMaxPackets = 50; + // ICE connection receiving timeout for aggressive configuration. + static const int kAggressiveIceConnectionReceivingTimeout = 1000; + + //////////////////////////////////////////////////////////////////////// + // The below few fields mirror the standard RTCConfiguration dictionary: + // https://www.w3.org/TR/webrtc/#rtcconfiguration-dictionary + //////////////////////////////////////////////////////////////////////// + + // TODO(pthatcher): Rename this ice_servers, but update Chromium + // at the same time. + IceServers servers; + // TODO(pthatcher): Rename this ice_transport_type, but update + // Chromium at the same time. + IceTransportsType type = kAll; + BundlePolicy bundle_policy = kBundlePolicyBalanced; + RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire; + std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates; + int ice_candidate_pool_size = 0; + + ////////////////////////////////////////////////////////////////////////// + // The below fields correspond to constraints from the deprecated + // constraints interface for constructing a PeerConnection. + // + // rtc::Optional fields can be "missing", in which case the implementation + // default will be used. + ////////////////////////////////////////////////////////////////////////// + + // If set to true, don't gather IPv6 ICE candidates. + // TODO(deadbeef): Remove this? IPv6 support has long stopped being + // experimental + bool disable_ipv6 = false; + + // If set to true, don't gather IPv6 ICE candidates on Wi-Fi. + // Only intended to be used on specific devices. Certain phones disable IPv6 + // when the screen is turned off and it would be better to just disable the + // IPv6 ICE candidates on Wi-Fi in those cases. + bool disable_ipv6_on_wifi = false; + + // By default, the PeerConnection will use a limited number of IPv6 network + // interfaces, in order to avoid too many ICE candidate pairs being created + // and delaying ICE completion. + // + // Can be set to INT_MAX to effectively disable the limit. + int max_ipv6_networks = cricket::kDefaultMaxIPv6Networks; + + // If set to true, use RTP data channels instead of SCTP. + // TODO(deadbeef): Remove this. We no longer commit to supporting RTP data + // channels, though some applications are still working on moving off of + // them. + bool enable_rtp_data_channel = false; + + // Minimum bitrate at which screencast video tracks will be encoded at. + // This means adding padding bits up to this bitrate, which can help + // when switching from a static scene to one with motion. + rtc::Optional<int> screencast_min_bitrate; + + // Use new combined audio/video bandwidth estimation? + rtc::Optional<bool> combined_audio_video_bwe; + + // Can be used to disable DTLS-SRTP. This should never be done, but can be + // useful for testing purposes, for example in setting up a loopback call + // with a single PeerConnection. + rtc::Optional<bool> enable_dtls_srtp; + + ///////////////////////////////////////////////// + // The below fields are not part of the standard. + ///////////////////////////////////////////////// + + // Can be used to disable TCP candidate generation. + TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled; + + // Can be used to avoid gathering candidates for a "higher cost" network, + // if a lower cost one exists. For example, if both Wi-Fi and cellular + // interfaces are available, this could be used to avoid using the cellular + // interface. + CandidateNetworkPolicy candidate_network_policy = + kCandidateNetworkPolicyAll; + + // The maximum number of packets that can be stored in the NetEq audio + // jitter buffer. Can be reduced to lower tolerated audio latency. + int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets; + + // Whether to use the NetEq "fast mode" which will accelerate audio quicker + // if it falls behind. + bool audio_jitter_buffer_fast_accelerate = false; + + // Timeout in milliseconds before an ICE candidate pair is considered to be + // "not receiving", after which a lower priority candidate pair may be + // selected. + int ice_connection_receiving_timeout = kUndefined; + + // Interval in milliseconds at which an ICE "backup" candidate pair will be + // pinged. This is a candidate pair which is not actively in use, but may + // be switched to if the active candidate pair becomes unusable. + // + // This is relevant mainly to Wi-Fi/cell handoff; the application may not + // want this backup cellular candidate pair pinged frequently, since it + // consumes data/battery. + int ice_backup_candidate_pair_ping_interval = kUndefined; + + // Can be used to enable continual gathering, which means new candidates + // will be gathered as network interfaces change. Note that if continual + // gathering is used, the candidate removal API should also be used, to + // avoid an ever-growing list of candidates. + ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE; + + // If set to true, candidate pairs will be pinged in order of most likely + // to work (which means using a TURN server, generally), rather than in + // standard priority order. + bool prioritize_most_likely_ice_candidate_pairs = false; + + struct cricket::MediaConfig media_config; + + // If set to true, only one preferred TURN allocation will be used per + // network interface. UDP is preferred over TCP and IPv6 over IPv4. This + // can be used to cut down on the number of candidate pairings. + bool prune_turn_ports = false; + + // If set to true, this means the ICE transport should presume TURN-to-TURN + // candidate pairs will succeed, even before a binding response is received. + // This can be used to optimize the initial connection time, since the DTLS + // handshake can begin immediately. + bool presume_writable_when_fully_relayed = false; + + // If true, "renomination" will be added to the ice options in the transport + // description. + // See: https://tools.ietf.org/html/draft-thatcher-ice-renomination-00 + bool enable_ice_renomination = false; + + // If true, the ICE role is re-determined when the PeerConnection sets a + // local transport description that indicates an ICE restart. + // + // This is standard RFC5245 ICE behavior, but causes unnecessary role + // thrashing, so an application may wish to avoid it. This role + // re-determining was removed in ICEbis (ICE v2). + bool redetermine_role_on_ice_restart = true; + + // If set, the min interval (max rate) at which we will send ICE checks + // (STUN pings), in milliseconds. + rtc::Optional<int> ice_check_min_interval; + + // ICE Periodic Regathering + // If set, WebRTC will periodically create and propose candidates without + // starting a new ICE generation. The regathering happens continuously with + // interval specified in milliseconds by the uniform distribution [a, b]. + rtc::Optional<rtc::IntervalRange> ice_regather_interval_range; + + // Optional TurnCustomizer. + // With this class one can modify outgoing TURN messages. + // The object passed in must remain valid until PeerConnection::Close() is + // called. + webrtc::TurnCustomizer* turn_customizer = nullptr; + + // Configure the SDP semantics used by this PeerConnection. Note that the + // WebRTC 1.0 specification requires kUnifiedPlan semantics. The + // RtpTransceiver API is only available with kUnifiedPlan semantics. + // + // kPlanB will cause PeerConnection to create offers and answers with at + // most one audio and one video m= section with multiple RtpSenders and + // RtpReceivers specified as multiple a=ssrc lines within the section. This + // will also cause PeerConnection to reject offers/answers with multiple m= + // sections of the same media type. + // + // kUnifiedPlan will cause PeerConnection to create offers and answers with + // multiple m= sections where each m= section maps to one RtpSender and one + // RtpReceiver (an RtpTransceiver), either both audio or both video. Plan B + // style offers or answers will be rejected in calls to SetLocalDescription + // or SetRemoteDescription. + // + // For users who only send at most one audio and one video track, this + // choice does not matter and should be left as kDefault. + // + // For users who wish to send multiple audio/video streams and need to stay + // interoperable with legacy WebRTC implementations, specify kPlanB. + // + // For users who wish to send multiple audio/video streams and/or wish to + // use the new RtpTransceiver API, specify kUnifiedPlan. + // + // TODO(steveanton): Implement support for kUnifiedPlan. + SdpSemantics sdp_semantics = SdpSemantics::kDefault; + + // + // Don't forget to update operator== if adding something. + // + }; + + // See: https://www.w3.org/TR/webrtc/#idl-def-rtcofferansweroptions + struct RTCOfferAnswerOptions { + static const int kUndefined = -1; + static const int kMaxOfferToReceiveMedia = 1; + + // The default value for constraint offerToReceiveX:true. + static const int kOfferToReceiveMediaTrue = 1; + + // These have been removed from the standard in favor of the "transceiver" + // API, but given that we don't support that API, we still have them here. + // + // offer_to_receive_X set to 1 will cause a media description to be + // generated in the offer, even if no tracks of that type have been added. + // Values greater than 1 are treated the same. + // + // If set to 0, the generated directional attribute will not include the + // "recv" direction (meaning it will be "sendonly" or "inactive". + int offer_to_receive_video = kUndefined; + int offer_to_receive_audio = kUndefined; + + bool voice_activity_detection = true; + bool ice_restart = false; + + // If true, will offer to BUNDLE audio/video/data together. Not to be + // confused with RTCP mux (multiplexing RTP and RTCP together). + bool use_rtp_mux = true; + + RTCOfferAnswerOptions() = default; + + RTCOfferAnswerOptions(int offer_to_receive_video, + int offer_to_receive_audio, + bool voice_activity_detection, + bool ice_restart, + bool use_rtp_mux) + : offer_to_receive_video(offer_to_receive_video), + offer_to_receive_audio(offer_to_receive_audio), + voice_activity_detection(voice_activity_detection), + ice_restart(ice_restart), + use_rtp_mux(use_rtp_mux) {} + }; + + // Used by GetStats to decide which stats to include in the stats reports. + // |kStatsOutputLevelStandard| includes the standard stats for Javascript API; + // |kStatsOutputLevelDebug| includes both the standard stats and additional + // stats for debugging purposes. + enum StatsOutputLevel { + kStatsOutputLevelStandard, + kStatsOutputLevelDebug, + }; + + // Accessor methods to active local streams. + virtual rtc::scoped_refptr<StreamCollectionInterface> + local_streams() = 0; + + // Accessor methods to remote streams. + virtual rtc::scoped_refptr<StreamCollectionInterface> + remote_streams() = 0; + + // Add a new MediaStream to be sent on this PeerConnection. + // Note that a SessionDescription negotiation is needed before the + // remote peer can receive the stream. + // + // This has been removed from the standard in favor of a track-based API. So, + // this is equivalent to simply calling AddTrack for each track within the + // stream, with the one difference that if "stream->AddTrack(...)" is called + // later, the PeerConnection will automatically pick up the new track. Though + // this functionality will be deprecated in the future. + virtual bool AddStream(MediaStreamInterface* stream) = 0; + + // Remove a MediaStream from this PeerConnection. + // Note that a SessionDescription negotiation is needed before the + // remote peer is notified. + virtual void RemoveStream(MediaStreamInterface* stream) = 0; + + // Add a new MediaStreamTrack to be sent on this PeerConnection, and return + // the newly created RtpSender. + // + // |streams| indicates which stream labels the track should be associated + // with. + virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack( + MediaStreamTrackInterface* track, + std::vector<MediaStreamInterface*> streams) = 0; + + // Remove an RtpSender from this PeerConnection. + // Returns true on success. + virtual bool RemoveTrack(RtpSenderInterface* sender) = 0; + + // AddTransceiver creates a new RtpTransceiver and adds it to the set of + // transceivers. Adding a transceiver will cause future calls to CreateOffer + // to add a media description for the corresponding transceiver. + // + // The initial value of |mid| in the returned transceiver is null. Setting a + // new session description may change it to a non-null value. + // + // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver + // + // Optionally, an RtpTransceiverInit structure can be specified to configure + // the transceiver from construction. If not specified, the transceiver will + // default to having a direction of kSendRecv and not be part of any streams. + // + // These methods are only available when Unified Plan is enabled (see + // RTCConfiguration). + // + // Common errors: + // - INTERNAL_ERROR: The configuration does not have Unified Plan enabled. + // TODO(steveanton): Make these pure virtual once downstream projects have + // updated. + + // Adds a transceiver with a sender set to transmit the given track. The kind + // of the transceiver (and sender/receiver) will be derived from the kind of + // the track. + // Errors: + // - INVALID_PARAMETER: |track| is null. + virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> + AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track) { + return RTCError(RTCErrorType::INTERNAL_ERROR, "not implemented"); + } + virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> + AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track, + const RtpTransceiverInit& init) { + return RTCError(RTCErrorType::INTERNAL_ERROR, "not implemented"); + } + + // Adds a transceiver with the given kind. Can either be MEDIA_TYPE_AUDIO or + // MEDIA_TYPE_VIDEO. + // Errors: + // - INVALID_PARAMETER: |media_type| is not MEDIA_TYPE_AUDIO or + // MEDIA_TYPE_VIDEO. + virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> + AddTransceiver(cricket::MediaType media_type) { + return RTCError(RTCErrorType::INTERNAL_ERROR, "not implemented"); + } + virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> + AddTransceiver(cricket::MediaType media_type, + const RtpTransceiverInit& init) { + return RTCError(RTCErrorType::INTERNAL_ERROR, "not implemented"); + } + + // Returns pointer to a DtmfSender on success. Otherwise returns null. + // + // This API is no longer part of the standard; instead DtmfSenders are + // obtained from RtpSenders. Which is what the implementation does; it finds + // an RtpSender for |track| and just returns its DtmfSender. + virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender( + AudioTrackInterface* track) = 0; + + // TODO(deadbeef): Make these pure virtual once all subclasses implement them. + + // Creates a sender without a track. Can be used for "early media"/"warmup" + // use cases, where the application may want to negotiate video attributes + // before a track is available to send. + // + // The standard way to do this would be through "addTransceiver", but we + // don't support that API yet. + // + // |kind| must be "audio" or "video". + // + // |stream_id| is used to populate the msid attribute; if empty, one will + // be generated automatically. + virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender( + const std::string& kind, + const std::string& stream_id) { + return rtc::scoped_refptr<RtpSenderInterface>(); + } + + // Get all RtpSenders, created either through AddStream, AddTrack, or + // CreateSender. Note that these are "Plan B SDP" RtpSenders, not "Unified + // Plan SDP" RtpSenders, which means that all senders of a specific media + // type share the same media description. + virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders() + const { + return std::vector<rtc::scoped_refptr<RtpSenderInterface>>(); + } + + // Get all RtpReceivers, created when a remote description is applied. + // Note that these are "Plan B SDP" RtpReceivers, not "Unified Plan SDP" + // RtpReceivers, which means that all receivers of a specific media type + // share the same media description. + // + // It is also possible to have a media description with no associated + // RtpReceivers, if the directional attribute does not indicate that the + // remote peer is sending any media. + virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers() + const { + return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>(); + } + + // Get all RtpTransceivers, created either through AddTransceiver, AddTrack or + // by a remote description applied with SetRemoteDescription. + // Note: This method is only available when Unified Plan is enabled (see + // RTCConfiguration). + virtual std::vector<rtc::scoped_refptr<RtpTransceiverInterface>> + GetTransceivers() const { + return {}; + } + + virtual bool GetStats(StatsObserver* observer, + MediaStreamTrackInterface* track, + StatsOutputLevel level) = 0; + // Gets stats using the new stats collection API, see webrtc/api/stats/. These + // will replace old stats collection API when the new API has matured enough. + // TODO(hbos): Default implementation that does nothing only exists as to not + // break third party projects. As soon as they have been updated this should + // be changed to "= 0;". + virtual void GetStats(RTCStatsCollectorCallback* callback) {} + + // Create a data channel with the provided config, or default config if none + // is provided. Note that an offer/answer negotiation is still necessary + // before the data channel can be used. + // + // Also, calling CreateDataChannel is the only way to get a data "m=" section + // in SDP, so it should be done before CreateOffer is called, if the + // application plans to use data channels. + virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel( + const std::string& label, + const DataChannelInit* config) = 0; + + // Returns the more recently applied description; "pending" if it exists, and + // otherwise "current". See below. + virtual const SessionDescriptionInterface* local_description() const = 0; + virtual const SessionDescriptionInterface* remote_description() const = 0; + + // A "current" description the one currently negotiated from a complete + // offer/answer exchange. + virtual const SessionDescriptionInterface* current_local_description() const { + return nullptr; + } + virtual const SessionDescriptionInterface* current_remote_description() + const { + return nullptr; + } + + // A "pending" description is one that's part of an incomplete offer/answer + // exchange (thus, either an offer or a pranswer). Once the offer/answer + // exchange is finished, the "pending" description will become "current". + virtual const SessionDescriptionInterface* pending_local_description() const { + return nullptr; + } + virtual const SessionDescriptionInterface* pending_remote_description() + const { + return nullptr; + } + + // Create a new offer. + // The CreateSessionDescriptionObserver callback will be called when done. + virtual void CreateOffer(CreateSessionDescriptionObserver* observer, + const MediaConstraintsInterface* constraints) {} + + // TODO(jiayl): remove the default impl and the old interface when chromium + // code is updated. + virtual void CreateOffer(CreateSessionDescriptionObserver* observer, + const RTCOfferAnswerOptions& options) {} + + // Create an answer to an offer. + // The CreateSessionDescriptionObserver callback will be called when done. + virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, + const RTCOfferAnswerOptions& options) {} + // Deprecated - use version above. + // TODO(hta): Remove and remove default implementations when all callers + // are updated. + virtual void CreateAnswer(CreateSessionDescriptionObserver* observer, + const MediaConstraintsInterface* constraints) {} + + // Sets the local session description. + // The PeerConnection takes the ownership of |desc| even if it fails. + // The |observer| callback will be called when done. + // TODO(deadbeef): Change |desc| to be a unique_ptr, to make it clear + // that this method always takes ownership of it. + virtual void SetLocalDescription(SetSessionDescriptionObserver* observer, + SessionDescriptionInterface* desc) = 0; + // Sets the remote session description. + // The PeerConnection takes the ownership of |desc| even if it fails. + // The |observer| callback will be called when done. + // TODO(hbos): Remove when Chrome implements the new signature. + virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer, + SessionDescriptionInterface* desc) {} + // TODO(hbos): Make pure virtual when Chrome has updated its signature. + virtual void SetRemoteDescription( + std::unique_ptr<SessionDescriptionInterface> desc, + rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) {} + // Deprecated; Replaced by SetConfiguration. + // TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration. + virtual bool UpdateIce(const IceServers& configuration, + const MediaConstraintsInterface* constraints) { + return false; + } + virtual bool UpdateIce(const IceServers& configuration) { return false; } + + // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of + // PeerConnectionInterface implement it. + virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() { + return PeerConnectionInterface::RTCConfiguration(); + } + + // Sets the PeerConnection's global configuration to |config|. + // + // The members of |config| that may be changed are |type|, |servers|, + // |ice_candidate_pool_size| and |prune_turn_ports| (though the candidate + // pool size can't be changed after the first call to SetLocalDescription). + // Note that this means the BUNDLE and RTCP-multiplexing policies cannot be + // changed with this method. + // + // Any changes to STUN/TURN servers or ICE candidate policy will affect the + // next gathering phase, and cause the next call to createOffer to generate + // new ICE credentials, as described in JSEP. This also occurs when + // |prune_turn_ports| changes, for the same reasoning. + // + // If an error occurs, returns false and populates |error| if non-null: + // - INVALID_MODIFICATION if |config| contains a modified parameter other + // than one of the parameters listed above. + // - INVALID_RANGE if |ice_candidate_pool_size| is out of range. + // - SYNTAX_ERROR if parsing an ICE server URL failed. + // - INVALID_PARAMETER if a TURN server is missing |username| or |password|. + // - INTERNAL_ERROR if an unexpected error occurred. + // + // TODO(deadbeef): Make this pure virtual once all Chrome subclasses of + // PeerConnectionInterface implement it. + virtual bool SetConfiguration( + const PeerConnectionInterface::RTCConfiguration& config, + RTCError* error) { + return false; + } + // Version without error output param for backwards compatibility. + // TODO(deadbeef): Remove once chromium is updated. + virtual bool SetConfiguration( + const PeerConnectionInterface::RTCConfiguration& config) { + return false; + } + + // Provides a remote candidate to the ICE Agent. + // A copy of the |candidate| will be created and added to the remote + // description. So the caller of this method still has the ownership of the + // |candidate|. + virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0; + + // Removes a group of remote candidates from the ICE agent. Needed mainly for + // continual gathering, to avoid an ever-growing list of candidates as + // networks come and go. + virtual bool RemoveIceCandidates( + const std::vector<cricket::Candidate>& candidates) { + return false; + } + + // Register a metric observer (used by chromium). + // + // There can only be one observer at a time. Before the observer is + // destroyed, RegisterUMAOberver(nullptr) should be called. + virtual void RegisterUMAObserver(UMAObserver* observer) = 0; + + // 0 <= min <= current <= max should hold for set parameters. + struct BitrateParameters { + rtc::Optional<int> min_bitrate_bps; + rtc::Optional<int> current_bitrate_bps; + rtc::Optional<int> max_bitrate_bps; + }; + + // SetBitrate limits the bandwidth allocated for all RTP streams sent by + // this PeerConnection. Other limitations might affect these limits and + // are respected (for example "b=AS" in SDP). + // + // Setting |current_bitrate_bps| will reset the current bitrate estimate + // to the provided value. + virtual RTCError SetBitrate(const BitrateParameters& bitrate) = 0; + + // Sets current strategy. If not set default WebRTC allocator will be used. + // May be changed during an active session. The strategy + // ownership is passed with std::unique_ptr + // TODO(alexnarest): Make this pure virtual when tests will be updated + virtual void SetBitrateAllocationStrategy( + std::unique_ptr<rtc::BitrateAllocationStrategy> + bitrate_allocation_strategy) {} + + // Enable/disable playout of received audio streams. Enabled by default. Note + // that even if playout is enabled, streams will only be played out if the + // appropriate SDP is also applied. Setting |playout| to false will stop + // playout of the underlying audio device but starts a task which will poll + // for audio data every 10ms to ensure that audio processing happens and the + // audio statistics are updated. + // TODO(henrika): deprecate and remove this. + virtual void SetAudioPlayout(bool playout) {} + + // Enable/disable recording of transmitted audio streams. Enabled by default. + // Note that even if recording is enabled, streams will only be recorded if + // the appropriate SDP is also applied. + // TODO(henrika): deprecate and remove this. + virtual void SetAudioRecording(bool recording) {} + + // Returns the current SignalingState. + virtual SignalingState signaling_state() = 0; + + // Returns the aggregate state of all ICE *and* DTLS transports. + // TODO(deadbeef): Implement "PeerConnectionState" according to the standard, + // to aggregate ICE+DTLS state, and change the scope of IceConnectionState to + // be just the ICE layer. See: crbug.com/webrtc/6145 + virtual IceConnectionState ice_connection_state() = 0; + + virtual IceGatheringState ice_gathering_state() = 0; + + // Starts RtcEventLog using existing file. Takes ownership of |file| and + // passes it on to Call, which will take the ownership. If the + // operation fails the file will be closed. The logging will stop + // automatically after 10 minutes have passed, or when the StopRtcEventLog + // function is called. + // TODO(eladalon): Deprecate and remove this. + virtual bool StartRtcEventLog(rtc::PlatformFile file, + int64_t max_size_bytes) { + return false; + } + + // Start RtcEventLog using an existing output-sink. Takes ownership of + // |output| and passes it on to Call, which will take the ownership. If the + // operation fails the output will be closed and deallocated. The event log + // will send serialized events to the output object every |output_period_ms|. + virtual bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output, + int64_t output_period_ms) { + return false; + } + + // Stops logging the RtcEventLog. + // TODO(ivoc): Make this pure virtual when Chrome is updated. + virtual void StopRtcEventLog() {} + + // Terminates all media, closes the transports, and in general releases any + // resources used by the PeerConnection. This is an irreversible operation. + // + // Note that after this method completes, the PeerConnection will no longer + // use the PeerConnectionObserver interface passed in on construction, and + // thus the observer object can be safely destroyed. + virtual void Close() = 0; + + protected: + // Dtor protected as objects shouldn't be deleted via this interface. + ~PeerConnectionInterface() {} +}; + +// PeerConnection callback interface, used for RTCPeerConnection events. +// Application should implement these methods. +class PeerConnectionObserver { + public: + enum StateType { + kSignalingState, + kIceState, + }; + + // Triggered when the SignalingState changed. + virtual void OnSignalingChange( + PeerConnectionInterface::SignalingState new_state) = 0; + + // TODO(deadbeef): Once all subclasses override the scoped_refptr versions + // of the below three methods, make them pure virtual and remove the raw + // pointer version. + + // Triggered when media is received on a new stream from remote peer. + virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) = 0; + + // Triggered when a remote peer close a stream. + virtual void OnRemoveStream( + rtc::scoped_refptr<MediaStreamInterface> stream) = 0; + + // Triggered when a remote peer opens a data channel. + virtual void OnDataChannel( + rtc::scoped_refptr<DataChannelInterface> data_channel) = 0; + + // Triggered when renegotiation is needed. For example, an ICE restart + // has begun. + virtual void OnRenegotiationNeeded() = 0; + + // Called any time the IceConnectionState changes. + // + // Note that our ICE states lag behind the standard slightly. The most + // notable differences include the fact that "failed" occurs after 15 + // seconds, not 30, and this actually represents a combination ICE + DTLS + // state, so it may be "failed" if DTLS fails while ICE succeeds. + virtual void OnIceConnectionChange( + PeerConnectionInterface::IceConnectionState new_state) = 0; + + // Called any time the IceGatheringState changes. + virtual void OnIceGatheringChange( + PeerConnectionInterface::IceGatheringState new_state) = 0; + + // A new ICE candidate has been gathered. + virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0; + + // Ice candidates have been removed. + // TODO(honghaiz): Make this a pure virtual method when all its subclasses + // implement it. + virtual void OnIceCandidatesRemoved( + const std::vector<cricket::Candidate>& candidates) {} + + // Called when the ICE connection receiving status changes. + virtual void OnIceConnectionReceivingChange(bool receiving) {} + + // This is called when a receiver and its track is created. + // TODO(zhihuang): Make this pure virtual when all subclasses implement it. + virtual void OnAddTrack( + rtc::scoped_refptr<RtpReceiverInterface> receiver, + const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {} + + // TODO(hbos,deadbeef): Add |OnAssociatedStreamsUpdated| with |receiver| and + // |streams| as arguments. This should be called when an existing receiver its + // associated streams updated. https://crbug.com/webrtc/8315 + // This may be blocked on supporting multiple streams per sender or else + // this may count as the removal and addition of a track? + // https://crbug.com/webrtc/7932 + + // Called when a receiver is completely removed. This is current (Plan B SDP) + // behavior that occurs when processing the removal of a remote track, and is + // called when the receiver is removed and the track is muted. When Unified + // Plan SDP is supported, transceivers can change direction (and receivers + // stopped) but receivers are never removed. + // https://w3c.github.io/webrtc-pc/#process-remote-track-removal + // TODO(hbos,deadbeef): When Unified Plan SDP is supported and receivers are + // no longer removed, deprecate and remove this callback. + // TODO(hbos,deadbeef): Make pure virtual when all subclasses implement it. + virtual void OnRemoveTrack( + rtc::scoped_refptr<RtpReceiverInterface> receiver) {} + + protected: + // Dtor protected as objects shouldn't be deleted via this interface. + ~PeerConnectionObserver() {} +}; + +// PeerConnectionFactoryInterface is the factory interface used for creating +// PeerConnection, MediaStream and MediaStreamTrack objects. +// +// The simplest method for obtaiing one, CreatePeerConnectionFactory will +// create the required libjingle threads, socket and network manager factory +// classes for networking if none are provided, though it requires that the +// application runs a message loop on the thread that called the method (see +// explanation below) +// +// If an application decides to provide its own threads and/or implementation +// of networking classes, it should use the alternate +// CreatePeerConnectionFactory method which accepts threads as input, and use +// the CreatePeerConnection version that takes a PortAllocator as an argument. +class PeerConnectionFactoryInterface : public rtc::RefCountInterface { + public: + class Options { + public: + Options() : crypto_options(rtc::CryptoOptions::NoGcm()) {} + + // If set to true, created PeerConnections won't enforce any SRTP + // requirement, allowing unsecured media. Should only be used for + // testing/debugging. + bool disable_encryption = false; + + // Deprecated. The only effect of setting this to true is that + // CreateDataChannel will fail, which is not that useful. + bool disable_sctp_data_channels = false; + + // If set to true, any platform-supported network monitoring capability + // won't be used, and instead networks will only be updated via polling. + // + // This only has an effect if a PeerConnection is created with the default + // PortAllocator implementation. + bool disable_network_monitor = false; + + // Sets the network types to ignore. For instance, calling this with + // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and + // loopback interfaces. + int network_ignore_mask = rtc::kDefaultNetworkIgnoreMask; + + // Sets the maximum supported protocol version. The highest version + // supported by both ends will be used for the connection, i.e. if one + // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used. + rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12; + + // Sets crypto related options, e.g. enabled cipher suites. + rtc::CryptoOptions crypto_options; + }; + + // Set the options to be used for subsequently created PeerConnections. + virtual void SetOptions(const Options& options) = 0; + + // |allocator| and |cert_generator| may be null, in which case default + // implementations will be used. + // + // |observer| must not be null. + // + // Note that this method does not take ownership of |observer|; it's the + // responsibility of the caller to delete it. It can be safely deleted after + // Close has been called on the returned PeerConnection, which ensures no + // more observer callbacks will be invoked. + virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + std::unique_ptr<cricket::PortAllocator> allocator, + std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, + PeerConnectionObserver* observer) = 0; + + // Deprecated; should use RTCConfiguration for everything that previously + // used constraints. + virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( + const PeerConnectionInterface::RTCConfiguration& configuration, + const MediaConstraintsInterface* constraints, + std::unique_ptr<cricket::PortAllocator> allocator, + std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, + PeerConnectionObserver* observer) = 0; + + virtual rtc::scoped_refptr<MediaStreamInterface> + CreateLocalMediaStream(const std::string& label) = 0; + + // Creates an AudioSourceInterface. + // |options| decides audio processing settings. + virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( + const cricket::AudioOptions& options) = 0; + // Deprecated - use version above. + // Can use CopyConstraintsIntoAudioOptions to bridge the gap. + virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( + const MediaConstraintsInterface* constraints) = 0; + + // Creates a VideoTrackSourceInterface from |capturer|. + // TODO(deadbeef): We should aim to remove cricket::VideoCapturer from the + // API. It's mainly used as a wrapper around webrtc's provided + // platform-specific capturers, but these should be refactored to use + // VideoTrackSourceInterface directly. + // TODO(deadbeef): Make pure virtual once downstream mock PC factory classes + // are updated. + virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + std::unique_ptr<cricket::VideoCapturer> capturer) { + return nullptr; + } + + // A video source creator that allows selection of resolution and frame rate. + // |constraints| decides video resolution and frame rate but can be null. + // In the null case, use the version above. + // + // |constraints| is only used for the invocation of this method, and can + // safely be destroyed afterwards. + virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + std::unique_ptr<cricket::VideoCapturer> capturer, + const MediaConstraintsInterface* constraints) { + return nullptr; + } + + // Deprecated; please use the versions that take unique_ptrs above. + // TODO(deadbeef): Remove these once safe to do so. + virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + cricket::VideoCapturer* capturer) { + return CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(capturer)); + } + virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( + cricket::VideoCapturer* capturer, + const MediaConstraintsInterface* constraints) { + return CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(capturer), + constraints); + } + + // Creates a new local VideoTrack. The same |source| can be used in several + // tracks. + virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( + const std::string& label, + VideoTrackSourceInterface* source) = 0; + + // Creates an new AudioTrack. At the moment |source| can be null. + virtual rtc::scoped_refptr<AudioTrackInterface> + CreateAudioTrack(const std::string& label, + AudioSourceInterface* source) = 0; + + // Starts AEC dump using existing file. Takes ownership of |file| and passes + // it on to VoiceEngine (via other objects) immediately, which will take + // the ownerhip. If the operation fails, the file will be closed. + // A maximum file size in bytes can be specified. When the file size limit is + // reached, logging is stopped automatically. If max_size_bytes is set to a + // value <= 0, no limit will be used, and logging will continue until the + // StopAecDump function is called. + virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0; + + // Stops logging the AEC dump. + virtual void StopAecDump() = 0; + + protected: + // Dtor and ctor protected as objects shouldn't be created or deleted via + // this interface. + PeerConnectionFactoryInterface() {} + ~PeerConnectionFactoryInterface() {} // NOLINT +}; + +// Create a new instance of PeerConnectionFactoryInterface. +// +// This method relies on the thread it's called on as the "signaling thread" +// for the PeerConnectionFactory it creates. +// +// As such, if the current thread is not already running an rtc::Thread message +// loop, an application using this method must eventually either call +// rtc::Thread::Current()->Run(), or call +// rtc::Thread::Current()->ProcessMessages() within the application's own +// message loop. +rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory); + +// Create a new instance of PeerConnectionFactoryInterface. +// +// |network_thread|, |worker_thread| and |signaling_thread| are +// the only mandatory parameters. +// +// If non-null, a reference is added to |default_adm|, and ownership of +// |video_encoder_factory| and |video_decoder_factory| is transferred to the +// returned factory. +// TODO(deadbeef): Use rtc::scoped_refptr<> and std::unique_ptr<> to make this +// ownership transfer and ref counting more obvious. +rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory); + +// Create a new instance of PeerConnectionFactoryInterface with optional +// external audio mixed and audio processing modules. +// +// If |audio_mixer| is null, an internal audio mixer will be created and used. +// If |audio_processing| is null, an internal audio processing module will be +// created and used. +rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory, + rtc::scoped_refptr<AudioMixer> audio_mixer, + rtc::scoped_refptr<AudioProcessing> audio_processing); + +// Create a new instance of PeerConnectionFactoryInterface with optional video +// codec factories. These video factories represents all video codecs, i.e. no +// extra internal video codecs will be added. +rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + rtc::scoped_refptr<AudioDeviceModule> default_adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, + std::unique_ptr<VideoEncoderFactory> video_encoder_factory, + std::unique_ptr<VideoDecoderFactory> video_decoder_factory, + rtc::scoped_refptr<AudioMixer> audio_mixer, + rtc::scoped_refptr<AudioProcessing> audio_processing); + +// Create a new instance of PeerConnectionFactoryInterface with external audio +// mixer. +// +// If |audio_mixer| is null, an internal audio mixer will be created and used. +rtc::scoped_refptr<PeerConnectionFactoryInterface> +CreatePeerConnectionFactoryWithAudioMixer( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory, + rtc::scoped_refptr<AudioMixer> audio_mixer); + +// Create a new instance of PeerConnectionFactoryInterface. +// Same thread is used as worker and network thread. +inline rtc::scoped_refptr<PeerConnectionFactoryInterface> +CreatePeerConnectionFactory( + rtc::Thread* worker_and_network_thread, + rtc::Thread* signaling_thread, + AudioDeviceModule* default_adm, + rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, + rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, + cricket::WebRtcVideoEncoderFactory* video_encoder_factory, + cricket::WebRtcVideoDecoderFactory* video_decoder_factory) { + return CreatePeerConnectionFactory( + worker_and_network_thread, worker_and_network_thread, signaling_thread, + default_adm, audio_encoder_factory, audio_decoder_factory, + video_encoder_factory, video_decoder_factory); +} + +// This is a lower-level version of the CreatePeerConnectionFactory functions +// above. It's implemented in the "peerconnection" build target, whereas the +// above methods are only implemented in the broader "libjingle_peerconnection" +// build target, which pulls in the implementations of every module webrtc may +// use. +// +// If an application knows it will only require certain modules, it can reduce +// webrtc's impact on its binary size by depending only on the "peerconnection" +// target and the modules the application requires, using +// CreateModularPeerConnectionFactory instead of one of the +// CreatePeerConnectionFactory methods above. For example, if an application +// only uses WebRTC for audio, it can pass in null pointers for the +// video-specific interfaces, and omit the corresponding modules from its +// build. +// +// If |network_thread| or |worker_thread| are null, the PeerConnectionFactory +// will create the necessary thread internally. If |signaling_thread| is null, +// the PeerConnectionFactory will use the thread on which this method is called +// as the signaling thread, wrapping it in an rtc::Thread object if needed. +// +// If non-null, a reference is added to |default_adm|, and ownership of +// |video_encoder_factory| and |video_decoder_factory| is transferred to the +// returned factory. +// +// If |audio_mixer| is null, an internal audio mixer will be created and used. +// +// TODO(deadbeef): Use rtc::scoped_refptr<> and std::unique_ptr<> to make this +// ownership transfer and ref counting more obvious. +// +// TODO(deadbeef): Encapsulate these modules in a struct, so that when a new +// module is inevitably exposed, we can just add a field to the struct instead +// of adding a whole new CreateModularPeerConnectionFactory overload. +rtc::scoped_refptr<PeerConnectionFactoryInterface> +CreateModularPeerConnectionFactory( + rtc::Thread* network_thread, + rtc::Thread* worker_thread, + rtc::Thread* signaling_thread, + std::unique_ptr<cricket::MediaEngineInterface> media_engine, + std::unique_ptr<CallFactoryInterface> call_factory, + std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory); + +} // namespace webrtc + +#endif // API_PEERCONNECTIONINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/peerconnectionproxy.h b/third_party/libwebrtc/webrtc/api/peerconnectionproxy.h new file mode 100644 index 0000000000..1d8cf5faaa --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/peerconnectionproxy.h @@ -0,0 +1,144 @@ +/* + * Copyright 2012 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 API_PEERCONNECTIONPROXY_H_ +#define API_PEERCONNECTIONPROXY_H_ + +#include <memory> +#include <string> +#include <vector> + +#include "api/peerconnectioninterface.h" +#include "api/proxy.h" + +namespace webrtc { + +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_SIGNALING_PROXY_MAP(PeerConnection) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_METHOD0(rtc::scoped_refptr<StreamCollectionInterface>, local_streams) + PROXY_METHOD0(rtc::scoped_refptr<StreamCollectionInterface>, remote_streams) + PROXY_METHOD1(bool, AddStream, MediaStreamInterface*) + PROXY_METHOD1(void, RemoveStream, MediaStreamInterface*) + PROXY_METHOD2(rtc::scoped_refptr<RtpSenderInterface>, + AddTrack, + MediaStreamTrackInterface*, + std::vector<MediaStreamInterface*>) + PROXY_METHOD1(bool, RemoveTrack, RtpSenderInterface*) + PROXY_METHOD1(RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>, + AddTransceiver, + rtc::scoped_refptr<MediaStreamTrackInterface>) + PROXY_METHOD2(RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>, + AddTransceiver, + rtc::scoped_refptr<MediaStreamTrackInterface>, + const RtpTransceiverInit&) + PROXY_METHOD1(RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>, + AddTransceiver, + cricket::MediaType) + PROXY_METHOD2(RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>, + AddTransceiver, + cricket::MediaType, + const RtpTransceiverInit&) + PROXY_METHOD1(rtc::scoped_refptr<DtmfSenderInterface>, + CreateDtmfSender, + AudioTrackInterface*) + PROXY_METHOD2(rtc::scoped_refptr<RtpSenderInterface>, + CreateSender, + const std::string&, + const std::string&) + PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<RtpSenderInterface>>, + GetSenders) + PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<RtpReceiverInterface>>, + GetReceivers) + PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>, + GetTransceivers) + PROXY_METHOD3(bool, + GetStats, + StatsObserver*, + MediaStreamTrackInterface*, + StatsOutputLevel) + PROXY_METHOD1(void, GetStats, RTCStatsCollectorCallback*) + PROXY_METHOD2(rtc::scoped_refptr<DataChannelInterface>, + CreateDataChannel, + const std::string&, + const DataChannelInit*) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, local_description) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, remote_description) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, + pending_local_description) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, + pending_remote_description) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, + current_local_description) + PROXY_CONSTMETHOD0(const SessionDescriptionInterface*, + current_remote_description) + PROXY_METHOD2(void, + CreateOffer, + CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*) + PROXY_METHOD2(void, + CreateAnswer, + CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*) + PROXY_METHOD2(void, + CreateOffer, + CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&) + PROXY_METHOD2(void, + CreateAnswer, + CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&) + PROXY_METHOD2(void, + SetLocalDescription, + SetSessionDescriptionObserver*, + SessionDescriptionInterface*) + PROXY_METHOD2(void, + SetRemoteDescription, + SetSessionDescriptionObserver*, + SessionDescriptionInterface*) + PROXY_METHOD2(void, + SetRemoteDescription, + std::unique_ptr<SessionDescriptionInterface>, + rtc::scoped_refptr<SetRemoteDescriptionObserverInterface>); + PROXY_METHOD0(PeerConnectionInterface::RTCConfiguration, GetConfiguration); + PROXY_METHOD2(bool, + SetConfiguration, + const PeerConnectionInterface::RTCConfiguration&, + RTCError*); + PROXY_METHOD1(bool, + SetConfiguration, + const PeerConnectionInterface::RTCConfiguration&); + PROXY_METHOD1(bool, AddIceCandidate, const IceCandidateInterface*) + PROXY_METHOD1(bool, + RemoveIceCandidates, + const std::vector<cricket::Candidate>&); + PROXY_METHOD1(void, SetAudioPlayout, bool) + PROXY_METHOD1(void, SetAudioRecording, bool) + PROXY_METHOD1(void, RegisterUMAObserver, UMAObserver*) + PROXY_METHOD1(RTCError, SetBitrate, const BitrateParameters&); + PROXY_METHOD1(void, + SetBitrateAllocationStrategy, + std::unique_ptr<rtc::BitrateAllocationStrategy>); + PROXY_METHOD0(SignalingState, signaling_state) + PROXY_METHOD0(IceConnectionState, ice_connection_state) + PROXY_METHOD0(IceGatheringState, ice_gathering_state) + PROXY_METHOD2(bool, StartRtcEventLog, rtc::PlatformFile, int64_t) + PROXY_METHOD2(bool, + StartRtcEventLog, + std::unique_ptr<RtcEventLogOutput>, + int64_t); + PROXY_METHOD0(void, StopRtcEventLog) + PROXY_METHOD0(void, Close) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_PEERCONNECTIONPROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/proxy.cc b/third_party/libwebrtc/webrtc/api/proxy.cc new file mode 100644 index 0000000000..c86bddfa8b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/proxy.cc @@ -0,0 +1,38 @@ +/* + * 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 "api/proxy.h" + +namespace webrtc { +namespace internal { + +SynchronousMethodCall::SynchronousMethodCall(rtc::MessageHandler* proxy) + : e_(), proxy_(proxy) {} + +SynchronousMethodCall::~SynchronousMethodCall() = default; + +void SynchronousMethodCall::Invoke(const rtc::Location& posted_from, + rtc::Thread* t) { + if (t->IsCurrent()) { + proxy_->OnMessage(nullptr); + } else { + e_.reset(new rtc::Event(false, false)); + t->Post(posted_from, this, 0); + e_->Wait(rtc::Event::kForever); + } +} + +void SynchronousMethodCall::OnMessage(rtc::Message*) { + proxy_->OnMessage(nullptr); + e_->Set(); +} + +} // namespace internal +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/proxy.h b/third_party/libwebrtc/webrtc/api/proxy.h new file mode 100644 index 0000000000..dd7182e554 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/proxy.h @@ -0,0 +1,572 @@ +/* + * Copyright 2013 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. + */ + +// This file contains Macros for creating proxies for webrtc MediaStream and +// PeerConnection classes. +// TODO(deadbeef): Move this to pc/; this is part of the implementation. + +// +// Example usage: +// +// class TestInterface : public rtc::RefCountInterface { +// public: +// std::string FooA() = 0; +// std::string FooB(bool arg1) const = 0; +// std::string FooC(bool arg1) = 0; +// }; +// +// Note that return types can not be a const reference. +// +// class Test : public TestInterface { +// ... implementation of the interface. +// }; +// +// BEGIN_PROXY_MAP(Test) +// PROXY_SIGNALING_THREAD_DESTRUCTOR() +// PROXY_METHOD0(std::string, FooA) +// PROXY_CONSTMETHOD1(std::string, FooB, arg1) +// PROXY_WORKER_METHOD1(std::string, FooC, arg1) +// END_PROXY_MAP() +// +// Where the destructor and first two methods are invoked on the signaling +// thread, and the third is invoked on the worker thread. +// +// The proxy can be created using +// +// TestProxy::Create(Thread* signaling_thread, Thread* worker_thread, +// TestInterface*). +// +// The variant defined with BEGIN_SIGNALING_PROXY_MAP is unaware of +// the worker thread, and invokes all methods on the signaling thread. +// +// The variant defined with BEGIN_OWNED_PROXY_MAP does not use +// refcounting, and instead just takes ownership of the object being proxied. + +#ifndef API_PROXY_H_ +#define API_PROXY_H_ + +#include <memory> +#include <utility> + +#include "rtc_base/event.h" +#include "rtc_base/refcountedobject.h" +#include "rtc_base/thread.h" + +namespace webrtc { + +template <typename R> +class ReturnType { + public: + template<typename C, typename M> + void Invoke(C* c, M m) { r_ = (c->*m)(); } + template <typename C, typename M, typename T1> + void Invoke(C* c, M m, T1 a1) { + r_ = (c->*m)(std::move(a1)); + } + template <typename C, typename M, typename T1, typename T2> + void Invoke(C* c, M m, T1 a1, T2 a2) { + r_ = (c->*m)(std::move(a1), std::move(a2)); + } + template <typename C, typename M, typename T1, typename T2, typename T3> + void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { + r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3)); + } + template<typename C, typename M, typename T1, typename T2, typename T3, + typename T4> + void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4) { + r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4)); + } + template<typename C, typename M, typename T1, typename T2, typename T3, + typename T4, typename T5> + void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { + r_ = (c->*m)(std::move(a1), std::move(a2), std::move(a3), std::move(a4), + std::move(a5)); + } + + R moved_result() { return std::move(r_); } + + private: + R r_; +}; + +template <> +class ReturnType<void> { + public: + template<typename C, typename M> + void Invoke(C* c, M m) { (c->*m)(); } + template <typename C, typename M, typename T1> + void Invoke(C* c, M m, T1 a1) { + (c->*m)(std::move(a1)); + } + template <typename C, typename M, typename T1, typename T2> + void Invoke(C* c, M m, T1 a1, T2 a2) { + (c->*m)(std::move(a1), std::move(a2)); + } + template <typename C, typename M, typename T1, typename T2, typename T3> + void Invoke(C* c, M m, T1 a1, T2 a2, T3 a3) { + (c->*m)(std::move(a1), std::move(a2), std::move(a3)); + } + + void moved_result() {} +}; + +namespace internal { + +class SynchronousMethodCall + : public rtc::MessageData, + public rtc::MessageHandler { + public: + explicit SynchronousMethodCall(rtc::MessageHandler* proxy); + ~SynchronousMethodCall() override; + + void Invoke(const rtc::Location& posted_from, rtc::Thread* t); + + private: + void OnMessage(rtc::Message*) override; + + std::unique_ptr<rtc::Event> e_; + rtc::MessageHandler* proxy_; +}; + +} // namespace internal + +template <typename C, typename R> +class MethodCall0 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(); + MethodCall0(C* c, Method m) : c_(c), m_(m) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } + + C* c_; + Method m_; + ReturnType<R> r_; +}; + +template <typename C, typename R> +class ConstMethodCall0 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)() const; + ConstMethodCall0(C* c, Method m) : c_(c), m_(m) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { r_.Invoke(c_, m_); } + + C* c_; + Method m_; + ReturnType<R> r_; +}; + +template <typename C, typename R, typename T1> +class MethodCall1 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1); + MethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; +}; + +template <typename C, typename R, typename T1> +class ConstMethodCall1 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1) const; + ConstMethodCall1(C* c, Method m, T1 a1) : c_(c), m_(m), a1_(std::move(a1)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { r_.Invoke(c_, m_, std::move(a1_)); } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; +}; + +template <typename C, typename R, typename T1, typename T2> +class MethodCall2 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1, T2 a2); + MethodCall2(C* c, Method m, T1 a1, T2 a2) + : c_(c), m_(m), a1_(std::move(a1)), a2_(std::move(a2)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { + r_.Invoke(c_, m_, std::move(a1_), std::move(a2_)); + } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; + T2 a2_; +}; + +template <typename C, typename R, typename T1, typename T2, typename T3> +class MethodCall3 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1, T2 a2, T3 a3); + MethodCall3(C* c, Method m, T1 a1, T2 a2, T3 a3) + : c_(c), + m_(m), + a1_(std::move(a1)), + a2_(std::move(a2)), + a3_(std::move(a3)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { + r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_)); + } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; + T2 a2_; + T3 a3_; +}; + +template <typename C, typename R, typename T1, typename T2, typename T3, + typename T4> +class MethodCall4 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4); + MethodCall4(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4) + : c_(c), + m_(m), + a1_(std::move(a1)), + a2_(std::move(a2)), + a3_(std::move(a3)), + a4_(std::move(a4)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { + r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_), + std::move(a4_)); + } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; + T2 a2_; + T3 a3_; + T4 a4_; +}; + +template <typename C, typename R, typename T1, typename T2, typename T3, + typename T4, typename T5> +class MethodCall5 : public rtc::Message, + public rtc::MessageHandler { + public: + typedef R (C::*Method)(T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); + MethodCall5(C* c, Method m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) + : c_(c), + m_(m), + a1_(std::move(a1)), + a2_(std::move(a2)), + a3_(std::move(a3)), + a4_(std::move(a4)), + a5_(std::move(a5)) {} + + R Marshal(const rtc::Location& posted_from, rtc::Thread* t) { + internal::SynchronousMethodCall(this).Invoke(posted_from, t); + return r_.moved_result(); + } + + private: + void OnMessage(rtc::Message*) { + r_.Invoke(c_, m_, std::move(a1_), std::move(a2_), std::move(a3_), + std::move(a4_), std::move(a5_)); + } + + C* c_; + Method m_; + ReturnType<R> r_; + T1 a1_; + T2 a2_; + T3 a3_; + T4 a4_; + T5 a5_; +}; + + +// Helper macros to reduce code duplication. +#define PROXY_MAP_BOILERPLATE(c) \ + template <class INTERNAL_CLASS> \ + class c##ProxyWithInternal; \ + typedef c##ProxyWithInternal<c##Interface> c##Proxy; \ + template <class INTERNAL_CLASS> \ + class c##ProxyWithInternal : public c##Interface { \ + protected: \ + typedef c##Interface C; \ + \ + public: \ + const INTERNAL_CLASS* internal() const { return c_; } \ + INTERNAL_CLASS* internal() { return c_; } + +#define END_PROXY_MAP() \ + }; + +#define SIGNALING_PROXY_MAP_BOILERPLATE(c) \ + protected: \ + c##ProxyWithInternal(rtc::Thread* signaling_thread, INTERNAL_CLASS* c) \ + : signaling_thread_(signaling_thread), c_(c) {} \ + \ + private: \ + mutable rtc::Thread* signaling_thread_; + +#define WORKER_PROXY_MAP_BOILERPLATE(c) \ + protected: \ + c##ProxyWithInternal(rtc::Thread* signaling_thread, \ + rtc::Thread* worker_thread, INTERNAL_CLASS* c) \ + : signaling_thread_(signaling_thread), \ + worker_thread_(worker_thread), \ + c_(c) {} \ + \ + private: \ + mutable rtc::Thread* signaling_thread_; \ + mutable rtc::Thread* worker_thread_; + +// Note that the destructor is protected so that the proxy can only be +// destroyed via RefCountInterface. +#define REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ + protected: \ + ~c##ProxyWithInternal() { \ + MethodCall0<c##ProxyWithInternal, void> call( \ + this, &c##ProxyWithInternal::DestroyInternal); \ + call.Marshal(RTC_FROM_HERE, destructor_thread()); \ + } \ + \ + private: \ + void DestroyInternal() { c_ = nullptr; } \ + rtc::scoped_refptr<INTERNAL_CLASS> c_; + +// Note: This doesn't use a unique_ptr, because it intends to handle a corner +// case where an object's deletion triggers a callback that calls back into +// this proxy object. If relying on a unique_ptr to delete the object, its +// inner pointer would be set to null before this reentrant callback would have +// a chance to run, resulting in a segfault. +#define OWNED_PROXY_MAP_BOILERPLATE(c) \ + public: \ + ~c##ProxyWithInternal() { \ + MethodCall0<c##ProxyWithInternal, void> call( \ + this, &c##ProxyWithInternal::DestroyInternal); \ + call.Marshal(RTC_FROM_HERE, destructor_thread()); \ + } \ + \ + private: \ + void DestroyInternal() { delete c_; } \ + INTERNAL_CLASS* c_; + +#define BEGIN_SIGNALING_PROXY_MAP(c) \ + PROXY_MAP_BOILERPLATE(c) \ + SIGNALING_PROXY_MAP_BOILERPLATE(c) \ + REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ + public: \ + static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ + rtc::Thread* signaling_thread, INTERNAL_CLASS* c) { \ + return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ + c); \ + } + +#define BEGIN_PROXY_MAP(c) \ + PROXY_MAP_BOILERPLATE(c) \ + WORKER_PROXY_MAP_BOILERPLATE(c) \ + REFCOUNTED_PROXY_MAP_BOILERPLATE(c) \ + public: \ + static rtc::scoped_refptr<c##ProxyWithInternal> Create( \ + rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ + INTERNAL_CLASS* c) { \ + return new rtc::RefCountedObject<c##ProxyWithInternal>(signaling_thread, \ + worker_thread, c); \ + } + +#define BEGIN_OWNED_PROXY_MAP(c) \ + PROXY_MAP_BOILERPLATE(c) \ + WORKER_PROXY_MAP_BOILERPLATE(c) \ + OWNED_PROXY_MAP_BOILERPLATE(c) \ + public: \ + static std::unique_ptr<c##Interface> Create( \ + rtc::Thread* signaling_thread, rtc::Thread* worker_thread, \ + std::unique_ptr<INTERNAL_CLASS> c) { \ + return std::unique_ptr<c##Interface>(new c##ProxyWithInternal( \ + signaling_thread, worker_thread, c.release())); \ + } + +#define PROXY_SIGNALING_THREAD_DESTRUCTOR() \ + private: \ + rtc::Thread* destructor_thread() const { return signaling_thread_; } \ + \ + public: // NOLINTNEXTLINE + +#define PROXY_WORKER_THREAD_DESTRUCTOR() \ + private: \ + rtc::Thread* destructor_thread() const { return worker_thread_; } \ + \ + public: // NOLINTNEXTLINE + +#define PROXY_METHOD0(r, method) \ + r method() override { \ + MethodCall0<C, r> call(c_, &C::method); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_CONSTMETHOD0(r, method) \ + r method() const override { \ + ConstMethodCall0<C, r> call(c_, &C::method); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_METHOD1(r, method, t1) \ + r method(t1 a1) override { \ + MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_CONSTMETHOD1(r, method, t1) \ + r method(t1 a1) const override { \ + ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_METHOD2(r, method, t1, t2) \ + r method(t1 a1, t2 a2) override { \ + MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ + std::move(a2)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_METHOD3(r, method, t1, t2, t3) \ + r method(t1 a1, t2 a2, t3 a3) override { \ + MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ + std::move(a2), std::move(a3)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_METHOD4(r, method, t1, t2, t3, t4) \ + r method(t1 a1, t2 a2, t3 a3, t4 a4) override { \ + MethodCall4<C, r, t1, t2, t3, t4> call(c_, &C::method, std::move(a1), \ + std::move(a2), std::move(a3), \ + std::move(a4)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +#define PROXY_METHOD5(r, method, t1, t2, t3, t4, t5) \ + r method(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) override { \ + MethodCall5<C, r, t1, t2, t3, t4, t5> call(c_, &C::method, std::move(a1), \ + std::move(a2), std::move(a3), \ + std::move(a4), std::move(a5)); \ + return call.Marshal(RTC_FROM_HERE, signaling_thread_); \ + } + +// Define methods which should be invoked on the worker thread. +#define PROXY_WORKER_METHOD0(r, method) \ + r method() override { \ + MethodCall0<C, r> call(c_, &C::method); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_CONSTMETHOD0(r, method) \ + r method() const override { \ + ConstMethodCall0<C, r> call(c_, &C::method); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_METHOD1(r, method, t1) \ + r method(t1 a1) override { \ + MethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_CONSTMETHOD1(r, method, t1) \ + r method(t1 a1) const override { \ + ConstMethodCall1<C, r, t1> call(c_, &C::method, std::move(a1)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_METHOD2(r, method, t1, t2) \ + r method(t1 a1, t2 a2) override { \ + MethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ + std::move(a2)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_CONSTMETHOD2(r, method, t1, t2) \ + r method(t1 a1, t2 a2) const override { \ + ConstMethodCall2<C, r, t1, t2> call(c_, &C::method, std::move(a1), \ + std::move(a2)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_METHOD3(r, method, t1, t2, t3) \ + r method(t1 a1, t2 a2, t3 a3) override { \ + MethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ + std::move(a2), std::move(a3)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +#define PROXY_WORKER_CONSTMETHOD3(r, method, t1, t2) \ + r method(t1 a1, t2 a2, t3 a3) const override { \ + ConstMethodCall3<C, r, t1, t2, t3> call(c_, &C::method, std::move(a1), \ + std::move(a2), std::move(a3)); \ + return call.Marshal(RTC_FROM_HERE, worker_thread_); \ + } + +} // namespace webrtc + +#endif // API_PROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/refcountedbase.h b/third_party/libwebrtc/webrtc/api/refcountedbase.h new file mode 100644 index 0000000000..8c26efd3e3 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/refcountedbase.h @@ -0,0 +1,43 @@ +/* + * 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 API_REFCOUNTEDBASE_H_ +#define API_REFCOUNTEDBASE_H_ + +#include "rtc_base/constructormagic.h" +#include "rtc_base/refcount.h" +#include "rtc_base/refcounter.h" + +namespace rtc { + +class RefCountedBase { + public: + RefCountedBase() = default; + + void AddRef() const { ref_count_.IncRef(); } + RefCountReleaseStatus Release() const { + const auto status = ref_count_.DecRef(); + if (status == RefCountReleaseStatus::kDroppedLastRef) { + delete this; + } + return status; + } + + protected: + virtual ~RefCountedBase() = default; + + private: + mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; + + RTC_DISALLOW_COPY_AND_ASSIGN(RefCountedBase); +}; + +} // namespace rtc + +#endif // API_REFCOUNTEDBASE_H_ diff --git a/third_party/libwebrtc/webrtc/api/refcountedbase_gn/moz.build b/third_party/libwebrtc/webrtc/api/refcountedbase_gn/moz.build new file mode 100644 index 0000000000..01471ade9c --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/refcountedbase_gn/moz.build @@ -0,0 +1,179 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("refcountedbase_gn") diff --git a/third_party/libwebrtc/webrtc/api/rtcerror.cc b/third_party/libwebrtc/webrtc/api/rtcerror.cc new file mode 100644 index 0000000000..f9a31d0893 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtcerror.cc @@ -0,0 +1,101 @@ +/* + * 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 "api/rtcerror.h" + +#include "rtc_base/arraysize.h" + +namespace { + +static const char* const kRTCErrorTypeNames[] = { + "NONE", + "UNSUPPORTED_OPERATION", + "UNSUPPORTED_PARAMETER", + "INVALID_PARAMETER", + "INVALID_RANGE", + "SYNTAX_ERROR", + "INVALID_STATE", + "INVALID_MODIFICATION", + "NETWORK_ERROR", + "RESOURCE_EXHAUSTED", + "INTERNAL_ERROR", +}; +static_assert(static_cast<int>(webrtc::RTCErrorType::INTERNAL_ERROR) == + (arraysize(kRTCErrorTypeNames) - 1), + "kRTCErrorTypeNames must have as many strings as RTCErrorType " + "has values."); + +} // namespace + +namespace webrtc { + +RTCError::RTCError(RTCError&& other) + : type_(other.type_), have_string_message_(other.have_string_message_) { + if (have_string_message_) { + new (&string_message_) std::string(std::move(other.string_message_)); + } else { + static_message_ = other.static_message_; + } +} + +RTCError& RTCError::operator=(RTCError&& other) { + type_ = other.type_; + if (other.have_string_message_) { + set_message(std::move(other.string_message_)); + } else { + set_message(other.static_message_); + } + return *this; +} + +RTCError::~RTCError() { + // If we hold a message string that was built, rather than a static string, + // we need to delete it. + if (have_string_message_) { + string_message_.~basic_string(); + } +} + +// static +RTCError RTCError::OK() { + return RTCError(); +} + +const char* RTCError::message() const { + if (have_string_message_) { + return string_message_.c_str(); + } else { + return static_message_; + } +} + +void RTCError::set_message(const char* message) { + if (have_string_message_) { + string_message_.~basic_string(); + have_string_message_ = false; + } + static_message_ = message; +} + +void RTCError::set_message(std::string&& message) { + if (!have_string_message_) { + new (&string_message_) std::string(std::move(message)); + have_string_message_ = true; + } else { + string_message_ = message; + } +} + +std::ostream& operator<<(std::ostream& stream, RTCErrorType error) { + int index = static_cast<int>(error); + return stream << kRTCErrorTypeNames[index]; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/rtcerror.h b/third_party/libwebrtc/webrtc/api/rtcerror.h new file mode 100644 index 0000000000..962f46dd81 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtcerror.h @@ -0,0 +1,300 @@ +/* + * 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 API_RTCERROR_H_ +#define API_RTCERROR_H_ + +#include <ostream> +#include <string> +#include <utility> // For std::move. + +#include "rtc_base/checks.h" +#include "rtc_base/logging.h" + +namespace webrtc { + +// Enumeration to represent distinct classes of errors that an application +// may wish to act upon differently. These roughly map to DOMExceptions or +// RTCError "errorDetailEnum" values in the web API, as described in the +// comments below. +enum class RTCErrorType { + // No error. + NONE, + + // An operation is valid, but currently unsupported. + // Maps to OperationError DOMException. + UNSUPPORTED_OPERATION, + + // A supplied parameter is valid, but currently unsupported. + // Maps to OperationError DOMException. + UNSUPPORTED_PARAMETER, + + // General error indicating that a supplied parameter is invalid. + // Maps to InvalidAccessError or TypeError DOMException depending on context. + INVALID_PARAMETER, + + // Slightly more specific than INVALID_PARAMETER; a parameter's value was + // outside the allowed range. + // Maps to RangeError DOMException. + INVALID_RANGE, + + // Slightly more specific than INVALID_PARAMETER; an error occurred while + // parsing string input. + // Maps to SyntaxError DOMException. + SYNTAX_ERROR, + + // The object does not support this operation in its current state. + // Maps to InvalidStateError DOMException. + INVALID_STATE, + + // An attempt was made to modify the object in an invalid way. + // Maps to InvalidModificationError DOMException. + INVALID_MODIFICATION, + + // An error occurred within an underlying network protocol. + // Maps to NetworkError DOMException. + NETWORK_ERROR, + + // Some resource has been exhausted; file handles, hardware resources, ports, + // etc. + // Maps to OperationError DOMException. + RESOURCE_EXHAUSTED, + + // The operation failed due to an internal error. + // Maps to OperationError DOMException. + INTERNAL_ERROR, +}; + +// Roughly corresponds to RTCError in the web api. Holds an error type, a +// message, and possibly additional information specific to that error. +// +// Doesn't contain anything beyond a type and message now, but will in the +// future as more errors are implemented. +class RTCError { + public: + // Constructors. + + // Creates a "no error" error. + RTCError() {} + explicit RTCError(RTCErrorType type) : type_(type) {} + // For performance, prefer using the constructor that takes a const char* if + // the message is a static string. + RTCError(RTCErrorType type, const char* message) + : type_(type), static_message_(message), have_string_message_(false) {} + RTCError(RTCErrorType type, std::string&& message) + : type_(type), string_message_(message), have_string_message_(true) {} + + // Delete the copy constructor and assignment operator; there aren't any use + // cases where you should need to copy an RTCError, as opposed to moving it. + // Can revisit this decision if use cases arise in the future. + RTCError(const RTCError& other) = delete; + RTCError& operator=(const RTCError& other) = delete; + + // Move constructor and move-assignment operator. + RTCError(RTCError&& other); + RTCError& operator=(RTCError&& other); + + ~RTCError(); + + // Identical to default constructed error. + // + // Preferred over the default constructor for code readability. + static RTCError OK(); + + // Error type. + RTCErrorType type() const { return type_; } + void set_type(RTCErrorType type) { type_ = type; } + + // Human-readable message describing the error. Shouldn't be used for + // anything but logging/diagnostics, since messages are not guaranteed to be + // stable. + const char* message() const; + // For performance, prefer using the method that takes a const char* if the + // message is a static string. + void set_message(const char* message); + void set_message(std::string&& message); + + // Convenience method for situations where you only care whether or not an + // error occurred. + bool ok() const { return type_ == RTCErrorType::NONE; } + + private: + RTCErrorType type_ = RTCErrorType::NONE; + // For performance, we use static strings wherever possible. But in some + // cases the error string may need to be constructed, in which case an + // std::string is used. + union { + const char* static_message_ = ""; + std::string string_message_; + }; + // Whether or not |static_message_| or |string_message_| is being used in the + // above union. + bool have_string_message_ = false; +}; + +// Outputs the error as a friendly string. Update this method when adding a new +// error type. +// +// Only intended to be used for logging/disagnostics. +std::ostream& operator<<(std::ostream& stream, RTCErrorType error); + +// Helper macro that can be used by implementations to create an error with a +// message and log it. |message| should be a string literal or movable +// std::string. +#define LOG_AND_RETURN_ERROR_EX(type, message, severity) \ + { \ + RTC_DCHECK(type != RTCErrorType::NONE); \ + RTC_LOG(severity) << message << " (" << type << ")"; \ + return webrtc::RTCError(type, message); \ + } + +#define LOG_AND_RETURN_ERROR(type, message) \ + LOG_AND_RETURN_ERROR_EX(type, message, LS_ERROR) + +// RTCErrorOr<T> is the union of an RTCError object and a T object. RTCErrorOr +// models the concept of an object that is either a usable value, or an error +// Status explaining why such a value is not present. To this end RTCErrorOr<T> +// does not allow its RTCErrorType value to be RTCErrorType::NONE. This is +// enforced by a debug check in most cases. +// +// The primary use-case for RTCErrorOr<T> is as the return value of a function +// which may fail. For example, CreateRtpSender will fail if the parameters +// could not be successfully applied at the media engine level, but if +// successful will return a unique_ptr to an RtpSender. +// +// Example client usage for a RTCErrorOr<std::unique_ptr<T>>: +// +// RTCErrorOr<std::unique_ptr<Foo>> result = FooFactory::MakeNewFoo(arg); +// if (result.ok()) { +// std::unique_ptr<Foo> foo = result.ConsumeValue(); +// foo->DoSomethingCool(); +// } else { +// RTC_LOG(LS_ERROR) << result.error(); +// } +// +// Example factory implementation returning RTCErrorOr<std::unique_ptr<T>>: +// +// RTCErrorOr<std::unique_ptr<Foo>> FooFactory::MakeNewFoo(int arg) { +// if (arg <= 0) { +// return RTCError(RTCErrorType::INVALID_RANGE, "Arg must be positive"); +// } else { +// return std::unique_ptr<Foo>(new Foo(arg)); +// } +// } +// +template <typename T> +class RTCErrorOr { + // Used to convert between RTCErrorOr<Foo>/RtcErrorOr<Bar>, when an implicit + // conversion from Foo to Bar exists. + template <typename U> + friend class RTCErrorOr; + + public: + typedef T element_type; + + // Constructs a new RTCErrorOr with RTCErrorType::INTERNAL_ERROR error. This + // is marked 'explicit' to try to catch cases like 'return {};', where people + // think RTCErrorOr<std::vector<int>> will be initialized with an empty + // vector, instead of a RTCErrorType::INTERNAL_ERROR error. + RTCErrorOr() : error_(RTCErrorType::INTERNAL_ERROR) {} + + // Constructs a new RTCErrorOr with the given non-ok error. After calling + // this constructor, calls to value() will DCHECK-fail. + // + // NOTE: Not explicit - we want to use RTCErrorOr<T> as a return + // value, so it is convenient and sensible to be able to do 'return + // RTCError(...)' when the return type is RTCErrorOr<T>. + // + // REQUIRES: !error.ok(). This requirement is DCHECKed. + RTCErrorOr(RTCError&& error) : error_(std::move(error)) { // NOLINT + RTC_DCHECK(!error.ok()); + } + + // Constructs a new RTCErrorOr with the given value. After calling this + // constructor, calls to value() will succeed, and calls to error() will + // return a default-constructed RTCError. + // + // NOTE: Not explicit - we want to use RTCErrorOr<T> as a return type + // so it is convenient and sensible to be able to do 'return T()' + // when the return type is RTCErrorOr<T>. + RTCErrorOr(T&& value) : value_(std::move(value)) {} // NOLINT + + // Delete the copy constructor and assignment operator; there aren't any use + // cases where you should need to copy an RTCErrorOr, as opposed to moving + // it. Can revisit this decision if use cases arise in the future. + RTCErrorOr(const RTCErrorOr& other) = delete; + RTCErrorOr& operator=(const RTCErrorOr& other) = delete; + + // Move constructor and move-assignment operator. + // + // Visual Studio doesn't support "= default" with move constructors or + // assignment operators (even though they compile, they segfault), so define + // them explicitly. + RTCErrorOr(RTCErrorOr&& other) + : error_(std::move(other.error_)), value_(std::move(other.value_)) {} + RTCErrorOr& operator=(RTCErrorOr&& other) { + error_ = std::move(other.error_); + value_ = std::move(other.value_); + return *this; + } + + // Conversion constructor and assignment operator; T must be copy or move + // constructible from U. + template <typename U> + RTCErrorOr(RTCErrorOr<U> other) // NOLINT + : error_(std::move(other.error_)), value_(std::move(other.value_)) {} + template <typename U> + RTCErrorOr& operator=(RTCErrorOr<U> other) { + error_ = std::move(other.error_); + value_ = std::move(other.value_); + return *this; + } + + // Returns a reference to our error. If this contains a T, then returns + // default-constructed RTCError. + const RTCError& error() const { return error_; } + + // Moves the error. Can be useful if, say "CreateFoo" returns an + // RTCErrorOr<Foo>, and internally calls "CreateBar" which returns an + // RTCErrorOr<Bar>, and wants to forward the error up the stack. + RTCError MoveError() { return std::move(error_); } + + // Returns this->error().ok() + bool ok() const { return error_.ok(); } + + // Returns a reference to our current value, or DCHECK-fails if !this->ok(). + // + // Can be convenient for the implementation; for example, a method may want + // to access the value in some way before returning it to the next method on + // the stack. + const T& value() const { + RTC_DCHECK(ok()); + return value_; + } + T& value() { + RTC_DCHECK(ok()); + return value_; + } + + // Moves our current value out of this object and returns it, or DCHECK-fails + // if !this->ok(). + T MoveValue() { + RTC_DCHECK(ok()); + return std::move(value_); + } + + private: + RTCError error_; + T value_; +}; + +} // namespace webrtc + +#endif // API_RTCERROR_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtcerror_unittest.cc b/third_party/libwebrtc/webrtc/api/rtcerror_unittest.cc new file mode 100644 index 0000000000..d8f7ca6d49 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtcerror_unittest.cc @@ -0,0 +1,249 @@ +/* + * 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 <utility> + +#include "api/rtcerror.h" +#include "test/gtest.h" + +namespace { + +const int kDefaultMoveOnlyIntValue = 0xbadf00d; + +// Class that has no copy constructor, ensuring that RTCErrorOr can +struct MoveOnlyInt { + MoveOnlyInt() {} + explicit MoveOnlyInt(int value) : value(value) {} + MoveOnlyInt(const MoveOnlyInt& other) = delete; + MoveOnlyInt& operator=(const MoveOnlyInt& other) = delete; + MoveOnlyInt(MoveOnlyInt&& other) : value(other.value) {} + MoveOnlyInt& operator=(MoveOnlyInt&& other) { + value = other.value; + return *this; + } + + int value = kDefaultMoveOnlyIntValue; +}; + +// Same as above. Used to test conversion from RTCErrorOr<A> to RTCErrorOr<B> +// when A can be converted to B. +struct MoveOnlyInt2 { + MoveOnlyInt2() {} + explicit MoveOnlyInt2(int value) : value(value) {} + MoveOnlyInt2(const MoveOnlyInt2& other) = delete; + MoveOnlyInt2& operator=(const MoveOnlyInt2& other) = delete; + MoveOnlyInt2(MoveOnlyInt2&& other) : value(other.value) {} + MoveOnlyInt2& operator=(MoveOnlyInt2&& other) { + value = other.value; + return *this; + } + + explicit MoveOnlyInt2(MoveOnlyInt&& other) : value(other.value) {} + MoveOnlyInt2& operator=(MoveOnlyInt&& other) { + value = other.value; + return *this; + } + + int value = kDefaultMoveOnlyIntValue; +}; + +} // namespace + +namespace webrtc { + +// Simple test for ostream operator for RTCErrorType. +TEST(RTCErrorTypeTest, OstreamOperator) { + std::ostringstream oss; + oss << webrtc::RTCErrorType::NONE << ' ' + << webrtc::RTCErrorType::INVALID_PARAMETER << ' ' + << webrtc::RTCErrorType::INTERNAL_ERROR; + EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str()); +} + +// Test that the default constructor creates a "no error" error. +TEST(RTCErrorTest, DefaultConstructor) { + RTCError e; + EXPECT_EQ(RTCErrorType::NONE, e.type()); + EXPECT_EQ(std::string(), e.message()); + EXPECT_TRUE(e.ok()); +} + +TEST(RTCErrorTest, NormalConstructors) { + RTCError a(RTCErrorType::INVALID_PARAMETER); + EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, a.type()); + EXPECT_EQ(std::string(), a.message()); + + // Constructor that takes const char* message. + RTCError b(RTCErrorType::UNSUPPORTED_PARAMETER, "foobar"); + EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, b.type()); + EXPECT_EQ(std::string("foobar"), b.message()); + + // Constructor that takes std::string message. + RTCError c(RTCErrorType::INVALID_RANGE, std::string("new")); + EXPECT_EQ(RTCErrorType::INVALID_RANGE, c.type()); + EXPECT_EQ(std::string("new"), c.message()); +} + +TEST(RTCErrorTest, MoveConstructor) { + // Static string. + RTCError a(RTCErrorType::INVALID_PARAMETER, "foo"); + RTCError b(std::move(a)); + EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, b.type()); + EXPECT_EQ(std::string("foo"), b.message()); + + // Non-static string. + RTCError c(RTCErrorType::UNSUPPORTED_PARAMETER, std::string("bar")); + RTCError d(std::move(c)); + EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, d.type()); + EXPECT_EQ(std::string("bar"), d.message()); +} + +TEST(RTCErrorTest, MoveAssignment) { + // Try all combinations of "is static string"/"is non-static string" moves. + RTCError e(RTCErrorType::INVALID_PARAMETER, "foo"); + + e = RTCError(RTCErrorType::UNSUPPORTED_PARAMETER, "bar"); + EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, e.type()); + EXPECT_EQ(std::string("bar"), e.message()); + + e = RTCError(RTCErrorType::SYNTAX_ERROR, std::string("baz")); + EXPECT_EQ(std::string("baz"), e.message()); + + e = RTCError(RTCErrorType::SYNTAX_ERROR, std::string("another")); + EXPECT_EQ(std::string("another"), e.message()); + + e = RTCError(RTCErrorType::SYNTAX_ERROR, "last"); + EXPECT_EQ(std::string("last"), e.message()); +} + +// Test that the error returned by RTCError::OK() is a "no error" error. +TEST(RTCErrorTest, OKConstant) { + RTCError ok = RTCError::OK(); + EXPECT_EQ(RTCErrorType::NONE, ok.type()); + EXPECT_EQ(std::string(), ok.message()); + EXPECT_TRUE(ok.ok()); +} + +// Test that "error.ok()" behaves as expected. +TEST(RTCErrorTest, OkMethod) { + RTCError success; + RTCError failure(RTCErrorType::INTERNAL_ERROR); + EXPECT_TRUE(success.ok()); + EXPECT_FALSE(failure.ok()); +} + +// Test that a message can be set using either static const strings or +// std::strings. +TEST(RTCErrorTest, SetMessage) { + RTCError e; + // Try all combinations of "is static string"/"is non-static string" calls. + e.set_message("foo"); + EXPECT_EQ(std::string("foo"), e.message()); + + e.set_message("bar"); + EXPECT_EQ(std::string("bar"), e.message()); + + e.set_message(std::string("string")); + EXPECT_EQ(std::string("string"), e.message()); + + e.set_message(std::string("more")); + EXPECT_EQ(std::string("more"), e.message()); + + e.set_message("love to test"); + EXPECT_EQ(std::string("love to test"), e.message()); +} + +// Test that the default constructor creates an "INTERNAL_ERROR". +TEST(RTCErrorOrTest, DefaultConstructor) { + RTCErrorOr<MoveOnlyInt> e; + EXPECT_EQ(RTCErrorType::INTERNAL_ERROR, e.error().type()); +} + +// Test that an RTCErrorOr can be implicitly constructed from a value. +TEST(RTCErrorOrTest, ImplicitValueConstructor) { + RTCErrorOr<MoveOnlyInt> e = [] { return MoveOnlyInt(100); }(); + EXPECT_EQ(100, e.value().value); +} + +// Test that an RTCErrorOr can be implicitly constructed from an RTCError. +TEST(RTCErrorOrTest, ImplicitErrorConstructor) { + RTCErrorOr<MoveOnlyInt> e = [] { + return RTCError(RTCErrorType::SYNTAX_ERROR); + }(); + EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, e.error().type()); +} + +TEST(RTCErrorOrTest, MoveConstructor) { + RTCErrorOr<MoveOnlyInt> a(MoveOnlyInt(5)); + RTCErrorOr<MoveOnlyInt> b(std::move(a)); + EXPECT_EQ(5, b.value().value); +} + +TEST(RTCErrorOrTest, MoveAssignment) { + RTCErrorOr<MoveOnlyInt> a(MoveOnlyInt(5)); + RTCErrorOr<MoveOnlyInt> b(MoveOnlyInt(10)); + a = std::move(b); + EXPECT_EQ(10, a.value().value); +} + +TEST(RTCErrorOrTest, ConversionConstructor) { + RTCErrorOr<MoveOnlyInt> a(MoveOnlyInt(1)); + RTCErrorOr<MoveOnlyInt2> b(std::move(a)); +} + +TEST(RTCErrorOrTest, ConversionAssignment) { + RTCErrorOr<MoveOnlyInt> a(MoveOnlyInt(5)); + RTCErrorOr<MoveOnlyInt2> b(MoveOnlyInt2(10)); + b = std::move(a); + EXPECT_EQ(5, b.value().value); +} + +TEST(RTCErrorOrTest, OkMethod) { + RTCErrorOr<int> success(1337); + RTCErrorOr<int> error = RTCError(RTCErrorType::INTERNAL_ERROR); + EXPECT_TRUE(success.ok()); + EXPECT_FALSE(error.ok()); +} + +TEST(RTCErrorOrTest, MoveError) { + RTCErrorOr<int> e({RTCErrorType::SYNTAX_ERROR, "message"}); + RTCError err = e.MoveError(); + EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, err.type()); + EXPECT_EQ(std::string("message"), err.message()); +} + +TEST(RTCErrorOrTest, MoveValue) { + RTCErrorOr<MoveOnlyInt> e(MoveOnlyInt(88)); + MoveOnlyInt value = e.MoveValue(); + EXPECT_EQ(88, value.value); +} + +// Death tests. +// Disabled on Android because death tests misbehave on Android, see +// base/test/gtest_util.h. +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + +TEST(RTCErrorOrDeathTest, ConstructWithOkError) { + EXPECT_DEATH(RTCErrorOr<int> err = RTCError::OK(), ""); +} + +TEST(RTCErrorOrDeathTest, DereferenceErrorValue) { + RTCErrorOr<int> error = RTCError(RTCErrorType::INTERNAL_ERROR); + EXPECT_DEATH(error.value(), ""); +} + +TEST(RTCErrorOrDeathTest, MoveErrorValue) { + RTCErrorOr<int> error = RTCError(RTCErrorType::INTERNAL_ERROR); + EXPECT_DEATH(error.MoveValue(), ""); +} + +#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/rtceventlogoutput.h b/third_party/libwebrtc/webrtc/api/rtceventlogoutput.h new file mode 100644 index 0000000000..67e408d648 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtceventlogoutput.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 API_RTCEVENTLOGOUTPUT_H_ +#define API_RTCEVENTLOGOUTPUT_H_ + +#include <string> + +namespace webrtc { + +// NOTE: This class is still under development and may change without notice. +class RtcEventLogOutput { + public: + virtual ~RtcEventLogOutput() = default; + + // An output normally starts out active, though that might not always be + // the case (e.g. failed to open a file for writing). + // Once an output has become inactive (e.g. maximum file size reached), it can + // never become active again. + virtual bool IsActive() const = 0; + + // Write encoded events to an output. Returns true if the output was + // successfully written in its entirety. Otherwise, no guarantee is given + // about how much data was written, if any. The output sink becomes inactive + // after the first time |false| is returned. Write() may not be called on + // an inactive output sink. + virtual bool Write(const std::string& output) = 0; +}; + +} // namespace webrtc + +#endif // API_RTCEVENTLOGOUTPUT_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtpparameters.cc b/third_party/libwebrtc/webrtc/api/rtpparameters.cc new file mode 100644 index 0000000000..550b2f917a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpparameters.cc @@ -0,0 +1,213 @@ +/* + * Copyright (c) 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 "api/rtpparameters.h" + +#include <algorithm> +#include <sstream> +#include <string> + +#include "rtc_base/checks.h" + +namespace webrtc { + +RtcpFeedback::RtcpFeedback() {} +RtcpFeedback::RtcpFeedback(RtcpFeedbackType type) : type(type) {} +RtcpFeedback::RtcpFeedback(RtcpFeedbackType type, + RtcpFeedbackMessageType message_type) + : type(type), message_type(message_type) {} +RtcpFeedback::~RtcpFeedback() {} + +RtpCodecCapability::RtpCodecCapability() {} +RtpCodecCapability::~RtpCodecCapability() {} + +RtpHeaderExtensionCapability::RtpHeaderExtensionCapability() {} +RtpHeaderExtensionCapability::RtpHeaderExtensionCapability( + const std::string& uri) + : uri(uri) {} +RtpHeaderExtensionCapability::RtpHeaderExtensionCapability( + const std::string& uri, + int preferred_id) + : uri(uri), preferred_id(preferred_id) {} +RtpHeaderExtensionCapability::~RtpHeaderExtensionCapability() {} + +RtpExtension::RtpExtension() {} +RtpExtension::RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {} +RtpExtension::RtpExtension(const std::string& uri, int id, bool encrypt) + : uri(uri), id(id), encrypt(encrypt) {} +RtpExtension::~RtpExtension() {} + +RtpFecParameters::RtpFecParameters() {} +RtpFecParameters::RtpFecParameters(FecMechanism mechanism) + : mechanism(mechanism) {} +RtpFecParameters::RtpFecParameters(FecMechanism mechanism, uint32_t ssrc) + : ssrc(ssrc), mechanism(mechanism) {} +RtpFecParameters::~RtpFecParameters() {} + +RtpRtxParameters::RtpRtxParameters() {} +RtpRtxParameters::RtpRtxParameters(uint32_t ssrc) : ssrc(ssrc) {} +RtpRtxParameters::~RtpRtxParameters() {} + +RtpEncodingParameters::RtpEncodingParameters() {} +RtpEncodingParameters::~RtpEncodingParameters() {} + +RtpCodecParameters::RtpCodecParameters() {} +RtpCodecParameters::~RtpCodecParameters() {} + +RtpCapabilities::RtpCapabilities() {} +RtpCapabilities::~RtpCapabilities() {} + +RtpParameters::RtpParameters() {} +RtpParameters::~RtpParameters() {} + +std::string RtpExtension::ToString() const { + std::stringstream ss; + ss << "{uri: " << uri; + ss << ", id: " << id; + if (encrypt) { + ss << ", encrypt"; + } + ss << '}'; + return ss.str(); +} + +const char RtpExtension::kAudioLevelUri[] = + "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; +const int RtpExtension::kAudioLevelDefaultId = 1; + +const char RtpExtension::kTimestampOffsetUri[] = + "urn:ietf:params:rtp-hdrext:toffset"; +const int RtpExtension::kTimestampOffsetDefaultId = 2; + +const char RtpExtension::kAbsSendTimeUri[] = + "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; +const int RtpExtension::kAbsSendTimeDefaultId = 3; + +const char RtpExtension::kVideoRotationUri[] = "urn:3gpp:video-orientation"; +const int RtpExtension::kVideoRotationDefaultId = 4; + +const char RtpExtension::kTransportSequenceNumberUri[] = + "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"; +const int RtpExtension::kTransportSequenceNumberDefaultId = 5; + +// This extension allows applications to adaptively limit the playout delay +// on frames as per the current needs. For example, a gaming application +// has very different needs on end-to-end delay compared to a video-conference +// application. +const char RtpExtension::kPlayoutDelayUri[] = + "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; +const int RtpExtension::kPlayoutDelayDefaultId = 6; + +const char RtpExtension::kVideoContentTypeUri[] = + "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"; +const int RtpExtension::kVideoContentTypeDefaultId = 7; + +const char RtpExtension::kVideoTimingUri[] = + "http://www.webrtc.org/experiments/rtp-hdrext/video-timing"; +const int RtpExtension::kVideoTimingDefaultId = 8; + +const char RtpExtension::kEncryptHeaderExtensionsUri[] = + "urn:ietf:params:rtp-hdrext:encrypt"; + +const char* RtpExtension::kRtpStreamIdUri = + "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"; +const int RtpExtension::kRtpStreamIdDefaultId = 9; + +const char* RtpExtension::kRepairedRtpStreamIdUri = + "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"; +const int RtpExtension::kRepairedRtpStreamIdDefaultId = 10; + +const char* RtpExtension::kMIdUri = + "urn:ietf:params:rtp-hdrext:sdes:mid"; +const int RtpExtension::kMIdDefaultId = 11; + +const char* RtpExtension::kCsrcAudioLevelUri = + "urn:ietf:params:rtp-hdrext:csrc-audio-level"; +const int RtpExtension::kCsrcAudioLevelDefaultId = 12; + +const int RtpExtension::kMinId = 1; +const int RtpExtension::kMaxId = 14; + +bool RtpExtension::IsSupportedForAudio(const std::string& uri) { + return uri == webrtc::RtpExtension::kAudioLevelUri || + uri == webrtc::RtpExtension::kTransportSequenceNumberUri || + uri == webrtc::RtpExtension::kRtpStreamIdUri || + uri == webrtc::RtpExtension::kRepairedRtpStreamIdUri || + uri == webrtc::RtpExtension::kMIdUri || + uri == webrtc::RtpExtension::kCsrcAudioLevelUri; +} + +bool RtpExtension::IsSupportedForVideo(const std::string& uri) { + return uri == webrtc::RtpExtension::kTimestampOffsetUri || + uri == webrtc::RtpExtension::kAbsSendTimeUri || + uri == webrtc::RtpExtension::kVideoRotationUri || + uri == webrtc::RtpExtension::kTransportSequenceNumberUri || + uri == webrtc::RtpExtension::kPlayoutDelayUri || + uri == webrtc::RtpExtension::kVideoContentTypeUri || + uri == webrtc::RtpExtension::kVideoTimingUri || + uri == webrtc::RtpExtension::kRtpStreamIdUri || + uri == webrtc::RtpExtension::kRepairedRtpStreamIdUri || + uri == webrtc::RtpExtension::kMIdUri; +} + +bool RtpExtension::IsEncryptionSupported(const std::string& uri) { + return uri == webrtc::RtpExtension::kAudioLevelUri || + uri == webrtc::RtpExtension::kTimestampOffsetUri || +#if !defined(ENABLE_EXTERNAL_AUTH) + // TODO(jbauch): Figure out a way to always allow "kAbsSendTimeUri" + // here and filter out later if external auth is really used in + // srtpfilter. External auth is used by Chromium and replaces the + // extension header value of "kAbsSendTimeUri", so it must not be + // encrypted (which can't be done by Chromium). + uri == webrtc::RtpExtension::kAbsSendTimeUri || +#endif + uri == webrtc::RtpExtension::kVideoRotationUri || + uri == webrtc::RtpExtension::kTransportSequenceNumberUri || + uri == webrtc::RtpExtension::kPlayoutDelayUri || + uri == webrtc::RtpExtension::kVideoContentTypeUri; +} + +const RtpExtension* RtpExtension::FindHeaderExtensionByUri( + const std::vector<RtpExtension>& extensions, + const std::string& uri) { + for (const auto& extension : extensions) { + if (extension.uri == uri) { + return &extension; + } + } + return nullptr; +} + +std::vector<RtpExtension> RtpExtension::FilterDuplicateNonEncrypted( + const std::vector<RtpExtension>& extensions) { + std::vector<RtpExtension> filtered; + for (auto extension = extensions.begin(); extension != extensions.end(); + ++extension) { + if (extension->encrypt) { + filtered.push_back(*extension); + continue; + } + + // Only add non-encrypted extension if no encrypted with the same URI + // is also present... + if (std::find_if(extension + 1, extensions.end(), + [extension](const RtpExtension& check) { + return extension->uri == check.uri; + }) != extensions.end()) { + continue; + } + + // ...and has not been added before. + if (!FindHeaderExtensionByUri(filtered, extension->uri)) { + filtered.push_back(*extension); + } + } + return filtered; +} +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/rtpparameters.h b/third_party/libwebrtc/webrtc/api/rtpparameters.h new file mode 100644 index 0000000000..51abffff40 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpparameters.h @@ -0,0 +1,561 @@ +/* + * Copyright 2015 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 API_RTPPARAMETERS_H_ +#define API_RTPPARAMETERS_H_ + +#include <string> +#include <unordered_map> +#include <vector> + +#include "api/mediatypes.h" +#include "api/optional.h" + +namespace webrtc { + +// These structures are intended to mirror those defined by: +// http://draft.ortc.org/#rtcrtpdictionaries* +// Contains everything specified as of 2017 Jan 24. +// +// They are used when retrieving or modifying the parameters of an +// RtpSender/RtpReceiver, or retrieving capabilities. +// +// Note on conventions: Where ORTC may use "octet", "short" and "unsigned" +// types, we typically use "int", in keeping with our style guidelines. The +// parameter's actual valid range will be enforced when the parameters are set, +// rather than when the parameters struct is built. An exception is made for +// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to +// be used for any numeric comparisons/operations. +// +// Additionally, where ORTC uses strings, we may use enums for things that have +// a fixed number of supported values. However, for things that can be extended +// (such as codecs, by providing an external encoder factory), a string +// identifier is used. + +enum class FecMechanism { + RED, + RED_AND_ULPFEC, + FLEXFEC, +}; + +// Used in RtcpFeedback struct. +enum class RtcpFeedbackType { + CCM, + NACK, + REMB, // "goog-remb" + TRANSPORT_CC, +}; + +// Used in RtcpFeedback struct when type is NACK or CCM. +enum class RtcpFeedbackMessageType { + // Equivalent to {type: "nack", parameter: undefined} in ORTC. + GENERIC_NACK, + PLI, // Usable with NACK. + FIR, // Usable with CCM. +}; + +enum class DtxStatus { + DISABLED, + ENABLED, +}; + +enum class DegradationPreference { + MAINTAIN_FRAMERATE, + MAINTAIN_RESOLUTION, + BALANCED, +}; + +enum class PriorityType { VERY_LOW, LOW, MEDIUM, HIGH }; + +struct RtcpFeedback { + RtcpFeedbackType type = RtcpFeedbackType::CCM; + + // Equivalent to ORTC "parameter" field with slight differences: + // 1. It's an enum instead of a string. + // 2. Generic NACK feedback is represented by a GENERIC_NACK message type, + // rather than an unset "parameter" value. + rtc::Optional<RtcpFeedbackMessageType> message_type; + + // Constructors for convenience. + RtcpFeedback(); + explicit RtcpFeedback(RtcpFeedbackType type); + RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type); + ~RtcpFeedback(); + + bool operator==(const RtcpFeedback& o) const { + return type == o.type && message_type == o.message_type; + } + bool operator!=(const RtcpFeedback& o) const { return !(*this == o); } +}; + +// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to +// RtpParameters. This represents the static capabilities of an endpoint's +// implementation of a codec. +struct RtpCodecCapability { + RtpCodecCapability(); + ~RtpCodecCapability(); + + // Build MIME "type/subtype" string from |name| and |kind|. + std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; } + + // Used to identify the codec. Equivalent to MIME subtype. + std::string name; + + // The media type of this codec. Equivalent to MIME top-level type. + cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO; + + // Clock rate in Hertz. If unset, the codec is applicable to any clock rate. + rtc::Optional<int> clock_rate; + + // Default payload type for this codec. Mainly needed for codecs that use + // that have statically assigned payload types. + rtc::Optional<int> preferred_payload_type; + + // Maximum packetization time supported by an RtpReceiver for this codec. + // TODO(deadbeef): Not implemented. + rtc::Optional<int> max_ptime; + + // Preferred packetization time for an RtpReceiver or RtpSender of this + // codec. + // TODO(deadbeef): Not implemented. + rtc::Optional<int> ptime; + + // The number of audio channels supported. Unused for video codecs. + rtc::Optional<int> num_channels; + + // Feedback mechanisms supported for this codec. + std::vector<RtcpFeedback> rtcp_feedback; + + // Codec-specific parameters that must be signaled to the remote party. + // + // Corresponds to "a=fmtp" parameters in SDP. + // + // Contrary to ORTC, these parameters are named using all lowercase strings. + // This helps make the mapping to SDP simpler, if an application is using + // SDP. Boolean values are represented by the string "1". + std::unordered_map<std::string, std::string> parameters; + + // Codec-specific parameters that may optionally be signaled to the remote + // party. + // TODO(deadbeef): Not implemented. + std::unordered_map<std::string, std::string> options; + + // Maximum number of temporal layer extensions supported by this codec. + // For example, a value of 1 indicates that 2 total layers are supported. + // TODO(deadbeef): Not implemented. + int max_temporal_layer_extensions = 0; + + // Maximum number of spatial layer extensions supported by this codec. + // For example, a value of 1 indicates that 2 total layers are supported. + // TODO(deadbeef): Not implemented. + int max_spatial_layer_extensions = 0; + + // Whether the implementation can send/receive SVC layers with distinct + // SSRCs. Always false for audio codecs. True for video codecs that support + // scalable video coding with MRST. + // TODO(deadbeef): Not implemented. + bool svc_multi_stream_support = false; + + bool operator==(const RtpCodecCapability& o) const { + return name == o.name && kind == o.kind && clock_rate == o.clock_rate && + preferred_payload_type == o.preferred_payload_type && + max_ptime == o.max_ptime && ptime == o.ptime && + num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback && + parameters == o.parameters && options == o.options && + max_temporal_layer_extensions == o.max_temporal_layer_extensions && + max_spatial_layer_extensions == o.max_spatial_layer_extensions && + svc_multi_stream_support == o.svc_multi_stream_support; + } + bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); } +}; + +// Used in RtpCapabilities; represents the capabilities/preferences of an +// implementation for a header extension. +// +// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was +// added here for consistency and to avoid confusion with +// RtpHeaderExtensionParameters. +// +// Note that ORTC includes a "kind" field, but we omit this because it's +// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)", +// you know you're getting audio capabilities. +struct RtpHeaderExtensionCapability { + // URI of this extension, as defined in RFC5285. + std::string uri; + + // Preferred value of ID that goes in the packet. + rtc::Optional<int> preferred_id; + + // If true, it's preferred that the value in the header is encrypted. + // TODO(deadbeef): Not implemented. + bool preferred_encrypt = false; + + // Constructors for convenience. + RtpHeaderExtensionCapability(); + explicit RtpHeaderExtensionCapability(const std::string& uri); + RtpHeaderExtensionCapability(const std::string& uri, int preferred_id); + ~RtpHeaderExtensionCapability(); + + bool operator==(const RtpHeaderExtensionCapability& o) const { + return uri == o.uri && preferred_id == o.preferred_id && + preferred_encrypt == o.preferred_encrypt; + } + bool operator!=(const RtpHeaderExtensionCapability& o) const { + return !(*this == o); + } +}; + +// RTP header extension, see RFC 5285. +struct RtpExtension { + RtpExtension(); + RtpExtension(const std::string& uri, int id); + RtpExtension(const std::string& uri, int id, bool encrypt); + ~RtpExtension(); + std::string ToString() const; + bool operator==(const RtpExtension& rhs) const { + return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt; + } + static bool IsSupportedForAudio(const std::string& uri); + static bool IsSupportedForVideo(const std::string& uri); + // Return "true" if the given RTP header extension URI may be encrypted. + static bool IsEncryptionSupported(const std::string& uri); + + // Returns the named header extension if found among all extensions, + // nullptr otherwise. + static const RtpExtension* FindHeaderExtensionByUri( + const std::vector<RtpExtension>& extensions, + const std::string& uri); + + // Return a list of RTP header extensions with the non-encrypted extensions + // removed if both the encrypted and non-encrypted extension is present for + // the same URI. + static std::vector<RtpExtension> FilterDuplicateNonEncrypted( + const std::vector<RtpExtension>& extensions); + + // Header extension for audio levels, as defined in: + // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03 + static const char kAudioLevelUri[]; + static const int kAudioLevelDefaultId; + + // Header extension for RTP timestamp offset, see RFC 5450 for details: + // http://tools.ietf.org/html/rfc5450 + static const char kTimestampOffsetUri[]; + static const int kTimestampOffsetDefaultId; + + // Header extension for absolute send time, see url for details: + // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time + static const char kAbsSendTimeUri[]; + static const int kAbsSendTimeDefaultId; + + // Header extension for coordination of video orientation, see url for + // details: + // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf + static const char kVideoRotationUri[]; + static const int kVideoRotationDefaultId; + + // Header extension for video content type. E.g. default or screenshare. + static const char kVideoContentTypeUri[]; + static const int kVideoContentTypeDefaultId; + + // Header extension for video timing. + static const char kVideoTimingUri[]; + static const int kVideoTimingDefaultId; + + // Header extension for transport sequence number, see url for details: + // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions + static const char kTransportSequenceNumberUri[]; + static const int kTransportSequenceNumberDefaultId; + + static const char kPlayoutDelayUri[]; + static const int kPlayoutDelayDefaultId; + + // Encryption of Header Extensions, see RFC 6904 for details: + // https://tools.ietf.org/html/rfc6904 + static const char kEncryptHeaderExtensionsUri[]; + + static const char* kRtpStreamIdUri; + static const int kRtpStreamIdDefaultId; + + static const char* kRepairedRtpStreamIdUri; + static const int kRepairedRtpStreamIdDefaultId; + + static const char* kMIdUri; + static const int kMIdDefaultId; + + static const char* kCsrcAudioLevelUri; + static const int kCsrcAudioLevelDefaultId; + + // Inclusive min and max IDs for one-byte header extensions, per RFC5285. + static const int kMinId; + static const int kMaxId; + + std::string uri; + int id = 0; + bool encrypt = false; +}; + +// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented. +typedef RtpExtension RtpHeaderExtensionParameters; + +struct RtpFecParameters { + // If unset, a value is chosen by the implementation. + // Works just like RtpEncodingParameters::ssrc. + rtc::Optional<uint32_t> ssrc; + + FecMechanism mechanism = FecMechanism::RED; + + // Constructors for convenience. + RtpFecParameters(); + explicit RtpFecParameters(FecMechanism mechanism); + RtpFecParameters(FecMechanism mechanism, uint32_t ssrc); + ~RtpFecParameters(); + + bool operator==(const RtpFecParameters& o) const { + return ssrc == o.ssrc && mechanism == o.mechanism; + } + bool operator!=(const RtpFecParameters& o) const { return !(*this == o); } +}; + +struct RtpRtxParameters { + // If unset, a value is chosen by the implementation. + // Works just like RtpEncodingParameters::ssrc. + rtc::Optional<uint32_t> ssrc; + + // Constructors for convenience. + RtpRtxParameters(); + explicit RtpRtxParameters(uint32_t ssrc); + ~RtpRtxParameters(); + + bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; } + bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); } +}; + +struct RtpEncodingParameters { + RtpEncodingParameters(); + ~RtpEncodingParameters(); + + // If unset, a value is chosen by the implementation. + // + // Note that the chosen value is NOT returned by GetParameters, because it + // may change due to an SSRC conflict, in which case the conflict is handled + // internally without any event. Another way of looking at this is that an + // unset SSRC acts as a "wildcard" SSRC. + rtc::Optional<uint32_t> ssrc; + + // Can be used to reference a codec in the |codecs| member of the + // RtpParameters that contains this RtpEncodingParameters. If unset, the + // implementation will choose the first possible codec (if a sender), or + // prepare to receive any codec (for a receiver). + // TODO(deadbeef): Not implemented. Implementation of RtpSender will always + // choose the first codec from the list. + rtc::Optional<int> codec_payload_type; + + // Specifies the FEC mechanism, if set. + // TODO(deadbeef): Not implemented. Current implementation will use whatever + // FEC codecs are available, including red+ulpfec. + rtc::Optional<RtpFecParameters> fec; + + // Specifies the RTX parameters, if set. + // TODO(deadbeef): Not implemented with PeerConnection senders/receivers. + rtc::Optional<RtpRtxParameters> rtx; + + // Only used for audio. If set, determines whether or not discontinuous + // transmission will be used, if an available codec supports it. If not + // set, the implementation default setting will be used. + // TODO(deadbeef): Not implemented. Current implementation will use a CN + // codec as long as it's present. + rtc::Optional<DtxStatus> dtx; + + // The relative priority of this encoding. + // TODO(deadbeef): Not implemented. + rtc::Optional<PriorityType> priority; + + // If set, this represents the Transport Independent Application Specific + // maximum bandwidth defined in RFC3890. If unset, there is no maximum + // bitrate. + // + // Just called "maxBitrate" in ORTC spec. + // + // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total + // bandwidth for the entire bandwidth estimator (audio and video). This is + // just always how "b=AS" was handled, but it's not correct and should be + // fixed. + rtc::Optional<int> max_bitrate_bps; + + // TODO(deadbeef): Not implemented. + rtc::Optional<int> max_framerate; + + // For video, scale the resolution down by this factor. + // TODO(deadbeef): Not implemented. + double scale_resolution_down_by = 1.0; + + // Scale the framerate down by this factor. + // TODO(deadbeef): Not implemented. + double scale_framerate_down_by = 1.0; + + // For an RtpSender, set to true to cause this encoding to be sent, and false + // for it not to be sent. For an RtpReceiver, set to true to cause the + // encoding to be decoded, and false for it to be ignored. + // TODO(deadbeef): Not implemented for PeerConnection RtpReceivers. + bool active = true; + + // Value to use for RID RTP header extension. + // Called "encodingId" in ORTC. + // TODO(deadbeef): Not implemented. + std::string rid; + + // RIDs of encodings on which this layer depends. + // Called "dependencyEncodingIds" in ORTC spec. + // TODO(deadbeef): Not implemented. + std::vector<std::string> dependency_rids; + + bool operator==(const RtpEncodingParameters& o) const { + return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type && + fec == o.fec && rtx == o.rtx && dtx == o.dtx && + priority == o.priority && max_bitrate_bps == o.max_bitrate_bps && + max_framerate == o.max_framerate && + scale_resolution_down_by == o.scale_resolution_down_by && + scale_framerate_down_by == o.scale_framerate_down_by && + active == o.active && rid == o.rid && + dependency_rids == o.dependency_rids; + } + bool operator!=(const RtpEncodingParameters& o) const { + return !(*this == o); + } +}; + +struct RtpCodecParameters { + RtpCodecParameters(); + ~RtpCodecParameters(); + + // Build MIME "type/subtype" string from |name| and |kind|. + std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; } + + // Used to identify the codec. Equivalent to MIME subtype. + std::string name; + + // The media type of this codec. Equivalent to MIME top-level type. + cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO; + + // Payload type used to identify this codec in RTP packets. + // This must always be present, and must be unique across all codecs using + // the same transport. + int payload_type = 0; + + // If unset, the implementation default is used. + rtc::Optional<int> clock_rate; + + // The number of audio channels used. Unset for video codecs. If unset for + // audio, the implementation default is used. + // TODO(deadbeef): The "implementation default" part isn't fully implemented. + // Only defaults to 1, even though some codecs (such as opus) should really + // default to 2. + rtc::Optional<int> num_channels; + + // The maximum packetization time to be used by an RtpSender. + // If |ptime| is also set, this will be ignored. + // TODO(deadbeef): Not implemented. + rtc::Optional<int> max_ptime; + + // The packetization time to be used by an RtpSender. + // If unset, will use any time up to max_ptime. + // TODO(deadbeef): Not implemented. + rtc::Optional<int> ptime; + + // Feedback mechanisms to be used for this codec. + // TODO(deadbeef): Not implemented with PeerConnection senders/receivers. + std::vector<RtcpFeedback> rtcp_feedback; + + // Codec-specific parameters that must be signaled to the remote party. + // + // Corresponds to "a=fmtp" parameters in SDP. + // + // Contrary to ORTC, these parameters are named using all lowercase strings. + // This helps make the mapping to SDP simpler, if an application is using + // SDP. Boolean values are represented by the string "1". + // + // TODO(deadbeef): Not implemented with PeerConnection senders/receivers. + std::unordered_map<std::string, std::string> parameters; + + bool operator==(const RtpCodecParameters& o) const { + return name == o.name && kind == o.kind && payload_type == o.payload_type && + clock_rate == o.clock_rate && num_channels == o.num_channels && + max_ptime == o.max_ptime && ptime == o.ptime && + rtcp_feedback == o.rtcp_feedback && parameters == o.parameters; + } + bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); } +}; + +// RtpCapabilities is used to represent the static capabilities of an +// endpoint. An application can use these capabilities to construct an +// RtpParameters. +struct RtpCapabilities { + RtpCapabilities(); + ~RtpCapabilities(); + + // Supported codecs. + std::vector<RtpCodecCapability> codecs; + + // Supported RTP header extensions. + std::vector<RtpHeaderExtensionCapability> header_extensions; + + // Supported Forward Error Correction (FEC) mechanisms. Note that the RED, + // ulpfec and flexfec codecs used by these mechanisms will still appear in + // |codecs|. + std::vector<FecMechanism> fec; + + bool operator==(const RtpCapabilities& o) const { + return codecs == o.codecs && header_extensions == o.header_extensions && + fec == o.fec; + } + bool operator!=(const RtpCapabilities& o) const { return !(*this == o); } +}; + +// Note that unlike in ORTC, an RtcpParameters structure is not included in +// RtpParameters, because our API includes an additional "RtpTransport" +// abstraction on which RTCP parameters are set. +struct RtpParameters { + RtpParameters(); + ~RtpParameters(); + + // Used when calling getParameters/setParameters with a PeerConnection + // RtpSender, to ensure that outdated parameters are not unintentionally + // applied successfully. + // TODO(deadbeef): Not implemented. + std::string transaction_id; + + // Value to use for MID RTP header extension. + // Called "muxId" in ORTC. + // TODO(deadbeef): Not implemented. + std::string mid; + + std::vector<RtpCodecParameters> codecs; + + // TODO(deadbeef): Not implemented with PeerConnection senders/receivers. + std::vector<RtpHeaderExtensionParameters> header_extensions; + + std::vector<RtpEncodingParameters> encodings; + + // TODO(deadbeef): Not implemented. + DegradationPreference degradation_preference = + DegradationPreference::BALANCED; + + bool operator==(const RtpParameters& o) const { + return mid == o.mid && codecs == o.codecs && + header_extensions == o.header_extensions && + encodings == o.encodings && + degradation_preference == o.degradation_preference; + } + bool operator!=(const RtpParameters& o) const { return !(*this == o); } +}; + +} // namespace webrtc + +#endif // API_RTPPARAMETERS_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtpparameters_unittest.cc b/third_party/libwebrtc/webrtc/api/rtpparameters_unittest.cc new file mode 100644 index 0000000000..ac3b1c7cc3 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpparameters_unittest.cc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 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 <utility> + +#include "api/rtpparameters.h" +#include "test/gtest.h" + +namespace webrtc { + +using webrtc::RtpExtension; + +static const char kExtensionUri1[] = "extension-uri1"; +static const char kExtensionUri2[] = "extension-uri2"; + +static const RtpExtension kExtension1(kExtensionUri1, 1); +static const RtpExtension kExtension1Encrypted(kExtensionUri1, 10, true); +static const RtpExtension kExtension2(kExtensionUri2, 2); + +TEST(RtpExtensionTest, FilterDuplicateNonEncrypted) { + std::vector<RtpExtension> extensions; + std::vector<RtpExtension> filtered; + + extensions.push_back(kExtension1); + extensions.push_back(kExtension1Encrypted); + filtered = RtpExtension::FilterDuplicateNonEncrypted(extensions); + EXPECT_EQ(1u, filtered.size()); + EXPECT_EQ(std::vector<RtpExtension>{kExtension1Encrypted}, filtered); + + extensions.clear(); + extensions.push_back(kExtension1Encrypted); + extensions.push_back(kExtension1); + filtered = RtpExtension::FilterDuplicateNonEncrypted(extensions); + EXPECT_EQ(1u, filtered.size()); + EXPECT_EQ(std::vector<RtpExtension>{kExtension1Encrypted}, filtered); + + extensions.clear(); + extensions.push_back(kExtension1); + extensions.push_back(kExtension2); + filtered = RtpExtension::FilterDuplicateNonEncrypted(extensions); + EXPECT_EQ(2u, filtered.size()); + EXPECT_EQ(extensions, filtered); +} +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/rtpreceiverinterface.h b/third_party/libwebrtc/webrtc/api/rtpreceiverinterface.h new file mode 100644 index 0000000000..311971d951 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpreceiverinterface.h @@ -0,0 +1,153 @@ +/* + * Copyright 2015 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. + */ + +// This file contains interfaces for RtpReceivers +// http://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface + +#ifndef API_RTPRECEIVERINTERFACE_H_ +#define API_RTPRECEIVERINTERFACE_H_ + +#include <string> +#include <vector> + +#include "api/mediastreaminterface.h" +#include "api/mediatypes.h" +#include "api/proxy.h" +#include "api/rtpparameters.h" +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +enum class RtpSourceType { + SSRC, + CSRC, +}; + +class RtpSource { + public: + RtpSource() = delete; + RtpSource(int64_t timestamp_ms, uint32_t source_id, RtpSourceType source_type) + : timestamp_ms_(timestamp_ms), + source_id_(source_id), + source_type_(source_type) {} + + RtpSource(int64_t timestamp_ms, + uint32_t source_id, + RtpSourceType source_type, + uint8_t audio_level) + : timestamp_ms_(timestamp_ms), + source_id_(source_id), + source_type_(source_type), + audio_level_(audio_level) {} + + int64_t timestamp_ms() const { return timestamp_ms_; } + void update_timestamp_ms(int64_t timestamp_ms) { + RTC_DCHECK_LE(timestamp_ms_, timestamp_ms); + timestamp_ms_ = timestamp_ms; + } + + // The identifier of the source can be the CSRC or the SSRC. + uint32_t source_id() const { return source_id_; } + + // The source can be either a contributing source or a synchronization source. + RtpSourceType source_type() const { return source_type_; } + + rtc::Optional<uint8_t> audio_level() const { return audio_level_; } + void set_audio_level(const rtc::Optional<uint8_t>& level) { + audio_level_ = level; + } + + bool operator==(const RtpSource& o) const { + return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() && + source_type_ == o.source_type() && audio_level_ == o.audio_level_; + } + + private: + int64_t timestamp_ms_; + uint32_t source_id_; + RtpSourceType source_type_; + rtc::Optional<uint8_t> audio_level_; +}; + +class RtpReceiverObserverInterface { + public: + // Note: Currently if there are multiple RtpReceivers of the same media type, + // they will all call OnFirstPacketReceived at once. + // + // In the future, it's likely that an RtpReceiver will only call + // OnFirstPacketReceived when a packet is received specifically for its + // SSRC/mid. + virtual void OnFirstPacketReceived(cricket::MediaType media_type) = 0; + + protected: + virtual ~RtpReceiverObserverInterface() {} +}; + +class RtpReceiverInterface : public rtc::RefCountInterface { + public: + virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; + // The list of streams that |track| is associated with. This is the same as + // the [[AssociatedRemoteMediaStreams]] internal slot in the spec. + // https://w3c.github.io/webrtc-pc/#dfn-x%5B%5Bassociatedremotemediastreams%5D%5D + // TODO(hbos): Make pure virtual as soon as Chromium's mock implements this. + virtual std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() + const { + return std::vector<rtc::scoped_refptr<MediaStreamInterface>>(); + } + + // Audio or video receiver? + virtual cricket::MediaType media_type() const = 0; + + // Not to be confused with "mid", this is a field we can temporarily use + // to uniquely identify a receiver until we implement Unified Plan SDP. + virtual std::string id() const = 0; + + // The WebRTC specification only defines RTCRtpParameters in terms of senders, + // but this API also applies them to receivers, similar to ORTC: + // http://ortc.org/wp-content/uploads/2016/03/ortc.html#rtcrtpparameters*. + virtual RtpParameters GetParameters() const = 0; + // Currently, doesn't support changing any parameters, but may in the future. + virtual bool SetParameters(const RtpParameters& parameters) = 0; + + // Does not take ownership of observer. + // Must call SetObserver(nullptr) before the observer is destroyed. + virtual void SetObserver(RtpReceiverObserverInterface* observer) = 0; + + // TODO(zhihuang): Remove the default implementation once the subclasses + // implement this. Currently, the only relevant subclass is the + // content::FakeRtpReceiver in Chromium. + virtual std::vector<RtpSource> GetSources() const { + return std::vector<RtpSource>(); + } + + protected: + virtual ~RtpReceiverInterface() {} +}; + +// Define proxy for RtpReceiverInterface. +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_SIGNALING_PROXY_MAP(RtpReceiver) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) + PROXY_CONSTMETHOD0(std::vector<rtc::scoped_refptr<MediaStreamInterface>>, + streams) + PROXY_CONSTMETHOD0(cricket::MediaType, media_type) + PROXY_CONSTMETHOD0(std::string, id) + PROXY_CONSTMETHOD0(RtpParameters, GetParameters); + PROXY_METHOD1(bool, SetParameters, const RtpParameters&) + PROXY_METHOD1(void, SetObserver, RtpReceiverObserverInterface*); + PROXY_CONSTMETHOD0(std::vector<RtpSource>, GetSources); + END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_RTPRECEIVERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtpsender.h b/third_party/libwebrtc/webrtc/api/rtpsender.h new file mode 100644 index 0000000000..567a7af92b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpsender.h @@ -0,0 +1,18 @@ +/* + * Copyright 2015 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 API_RTPSENDER_H_ +#define API_RTPSENDER_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/rtpsender.h" + +#endif // API_RTPSENDER_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtpsenderinterface.h b/third_party/libwebrtc/webrtc/api/rtpsenderinterface.h new file mode 100644 index 0000000000..a7fbbda46b --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtpsenderinterface.h @@ -0,0 +1,84 @@ +/* + * Copyright 2015 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. + */ + +// This file contains interfaces for RtpSenders +// http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface + +#ifndef API_RTPSENDERINTERFACE_H_ +#define API_RTPSENDERINTERFACE_H_ + +#include <string> +#include <vector> + +#include "api/dtmfsenderinterface.h" +#include "api/mediastreaminterface.h" +#include "api/mediatypes.h" +#include "api/proxy.h" +#include "api/rtpparameters.h" +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +class RtpSenderInterface : public rtc::RefCountInterface { + public: + // Returns true if successful in setting the track. + // Fails if an audio track is set on a video RtpSender, or vice-versa. + virtual bool SetTrack(MediaStreamTrackInterface* track) = 0; + virtual rtc::scoped_refptr<MediaStreamTrackInterface> track() const = 0; + + // Returns primary SSRC used by this sender for sending media. + // Returns 0 if not yet determined. + // TODO(deadbeef): Change to rtc::Optional. + // TODO(deadbeef): Remove? With GetParameters this should be redundant. + virtual uint32_t ssrc() const = 0; + + // Audio or video sender? + virtual cricket::MediaType media_type() const = 0; + + // Not to be confused with "mid", this is a field we can temporarily use + // to uniquely identify a receiver until we implement Unified Plan SDP. + virtual std::string id() const = 0; + + // Returns a list of streams associated with this sender's track. Although we + // only support one track per stream, in theory the API allows for multiple. + virtual std::vector<std::string> stream_ids() const = 0; + + virtual RtpParameters GetParameters() const = 0; + // Note that only a subset of the parameters can currently be changed. See + // rtpparameters.h + virtual bool SetParameters(const RtpParameters& parameters) = 0; + + // Returns null for a video sender. + virtual rtc::scoped_refptr<DtmfSenderInterface> GetDtmfSender() const = 0; + + protected: + virtual ~RtpSenderInterface() {} +}; + +// Define proxy for RtpSenderInterface. +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_SIGNALING_PROXY_MAP(RtpSender) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_METHOD1(bool, SetTrack, MediaStreamTrackInterface*) + PROXY_CONSTMETHOD0(rtc::scoped_refptr<MediaStreamTrackInterface>, track) + PROXY_CONSTMETHOD0(uint32_t, ssrc) + PROXY_CONSTMETHOD0(cricket::MediaType, media_type) + PROXY_CONSTMETHOD0(std::string, id) + PROXY_CONSTMETHOD0(std::vector<std::string>, stream_ids) + PROXY_CONSTMETHOD0(RtpParameters, GetParameters); + PROXY_METHOD1(bool, SetParameters, const RtpParameters&) + PROXY_CONSTMETHOD0(rtc::scoped_refptr<DtmfSenderInterface>, GetDtmfSender); +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_RTPSENDERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/rtptransceiverinterface.h b/third_party/libwebrtc/webrtc/api/rtptransceiverinterface.h new file mode 100644 index 0000000000..88607b2ed4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/rtptransceiverinterface.h @@ -0,0 +1,124 @@ +/* + * 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 API_RTPTRANSCEIVERINTERFACE_H_ +#define API_RTPTRANSCEIVERINTERFACE_H_ + +#include <string> +#include <vector> + +#include "api/optional.h" +#include "api/rtpreceiverinterface.h" +#include "api/rtpsenderinterface.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverdirection +enum class RtpTransceiverDirection { + kSendRecv, + kSendOnly, + kRecvOnly, + kInactive +}; + +// Structure for initializing an RtpTransceiver in a call to +// PeerConnectionInterface::AddTransceiver. +// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiverinit +struct RtpTransceiverInit final { + // Direction of the RtpTransceiver. See RtpTransceiverInterface::direction(). + RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv; + + // The added RtpTransceiver will be added to these streams. + // TODO(bugs.webrtc.org/7600): Not implemented. + std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams; + + // TODO(bugs.webrtc.org/7600): Not implemented. + std::vector<RtpEncodingParameters> send_encodings; +}; + +// The RtpTransceiverInterface maps to the RTCRtpTransceiver defined by the +// WebRTC specification. A transceiver represents a combination of an RtpSender +// and an RtpReceiver than share a common mid. As defined in JSEP, an +// RtpTransceiver is said to be associated with a media description if its mid +// property is non-null; otherwise, it is said to be disassociated. +// JSEP: https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24 +// +// Note that RtpTransceivers are only supported when using PeerConnection with +// Unified Plan SDP. +// +// This class is thread-safe. +// +// WebRTC specification for RTCRtpTransceiver, the JavaScript analog: +// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver +class RtpTransceiverInterface : public rtc::RefCountInterface { + public: + // The mid attribute is the mid negotiated and present in the local and + // remote descriptions. Before negotiation is complete, the mid value may be + // null. After rollbacks, the value may change from a non-null value to null. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid + virtual rtc::Optional<std::string> mid() const = 0; + + // The sender attribute exposes the RtpSender corresponding to the RTP media + // that may be sent with the transceiver's mid. The sender is always present, + // regardless of the direction of media. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender + virtual rtc::scoped_refptr<RtpSenderInterface> sender() const = 0; + + // The receiver attribute exposes the RtpReceiver corresponding to the RTP + // media that may be received with the transceiver's mid. The receiver is + // always present, regardless of the direction of media. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-receiver + virtual rtc::scoped_refptr<RtpReceiverInterface> receiver() const = 0; + + // The stopped attribute indicates that the sender of this transceiver will no + // longer send, and that the receiver will no longer receive. It is true if + // either stop has been called or if setting the local or remote description + // has caused the RtpTransceiver to be stopped. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped + virtual bool stopped() const = 0; + + // The direction attribute indicates the preferred direction of this + // transceiver, which will be used in calls to CreateOffer and CreateAnswer. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction + virtual RtpTransceiverDirection direction() const = 0; + + // Sets the preferred direction of this transceiver. An update of + // directionality does not take effect immediately. Instead, future calls to + // CreateOffer and CreateAnswer mark the corresponding media descriptions as + // sendrecv, sendonly, recvonly, or inactive. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction + virtual void SetDirection(RtpTransceiverDirection new_direction) = 0; + + // The current_direction attribute indicates the current direction negotiated + // for this transceiver. If this transceiver has never been represented in an + // offer/answer exchange, or if the transceiver is stopped, the value is null. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection + virtual rtc::Optional<RtpTransceiverDirection> current_direction() const = 0; + + // The Stop method irreversibly stops the RtpTransceiver. The sender of this + // transceiver will no longer send, the receiver will no longer receive. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop + virtual void Stop() = 0; + + // The SetCodecPreferences method overrides the default codec preferences used + // by WebRTC for this transceiver. + // https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences + // TODO(steveanton): Not implemented. + virtual void SetCodecPreferences( + rtc::ArrayView<RtpCodecCapability> codecs) = 0; + + protected: + virtual ~RtpTransceiverInterface() = default; +}; + +} // namespace webrtc + +#endif // API_RTPTRANSCEIVERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/setremotedescriptionobserverinterface.h b/third_party/libwebrtc/webrtc/api/setremotedescriptionobserverinterface.h new file mode 100644 index 0000000000..bea8b82bd5 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/setremotedescriptionobserverinterface.h @@ -0,0 +1,31 @@ +/* + * 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 API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_ +#define API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_ + +#include "api/rtcerror.h" +#include "rtc_base/refcount.h" + +namespace webrtc { + +// An observer for PeerConnectionInterface::SetRemoteDescription(). The +// callback is invoked such that the state of the peer connection can be +// examined to accurately reflect the effects of the SetRemoteDescription +// operation. +class SetRemoteDescriptionObserverInterface : public rtc::RefCountInterface { + public: + // On success, |error.ok()| is true. + virtual void OnSetRemoteDescriptionComplete(RTCError error) = 0; +}; + +} // namespace webrtc + +#endif // API_SETREMOTEDESCRIPTIONOBSERVERINTERFACE_H_ diff --git a/third_party/libwebrtc/webrtc/api/stats/OWNERS b/third_party/libwebrtc/webrtc/api/stats/OWNERS new file mode 100644 index 0000000000..633d6b9a76 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/stats/OWNERS @@ -0,0 +1,7 @@ +hbos@webrtc.org +hta@webrtc.org + +# These are for the common case of adding or renaming files. If you're doing +# structural changes, please get a review from a reviewer in this file. +per-file *.gn=* +per-file *.gni=* diff --git a/third_party/libwebrtc/webrtc/api/stats/rtcstats.h b/third_party/libwebrtc/webrtc/api/stats/rtcstats.h new file mode 100644 index 0000000000..887d602042 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/stats/rtcstats.h @@ -0,0 +1,332 @@ +/* + * Copyright 2016 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 API_STATS_RTCSTATS_H_ +#define API_STATS_RTCSTATS_H_ + +#include <map> +#include <memory> +#include <string> +#include <utility> +#include <vector> + +#include "rtc_base/checks.h" + +namespace webrtc { + +class RTCStatsMemberInterface; + +// Abstract base class for RTCStats-derived dictionaries, see +// https://w3c.github.io/webrtc-stats/. +// +// All derived classes must have the following static variable defined: +// static const char kType[]; +// It is used as a unique class identifier and a string representation of the +// class type, see https://w3c.github.io/webrtc-stats/#rtcstatstype-str*. +// Use the |WEBRTC_RTCSTATS_IMPL| macro when implementing subclasses, see macro +// for details. +// +// Derived classes list their dictionary members, RTCStatsMember<T>, as public +// fields, allowing the following: +// +// RTCFooStats foo("fooId", GetCurrentTime()); +// foo.bar = 42; +// foo.baz = std::vector<std::string>(); +// foo.baz->push_back("hello world"); +// uint32_t x = *foo.bar; +// +// Pointers to all the members are available with |Members|, allowing iteration: +// +// for (const RTCStatsMemberInterface* member : foo.Members()) { +// printf("%s = %s\n", member->name(), member->ValueToString().c_str()); +// } +class RTCStats { + public: + RTCStats(const std::string& id, int64_t timestamp_us) + : id_(id), timestamp_us_(timestamp_us) {} + RTCStats(std::string&& id, int64_t timestamp_us) + : id_(std::move(id)), timestamp_us_(timestamp_us) {} + virtual ~RTCStats() {} + + virtual std::unique_ptr<RTCStats> copy() const = 0; + + const std::string& id() const { return id_; } + // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. + int64_t timestamp_us() const { return timestamp_us_; } + // Returns the static member variable |kType| of the implementing class. + virtual const char* type() const = 0; + // Returns a vector of pointers to all the |RTCStatsMemberInterface| members + // of this class. This allows for iteration of members. For a given class, + // |Members| always returns the same members in the same order. + std::vector<const RTCStatsMemberInterface*> Members() const; + // Checks if the two stats objects are of the same type and have the same + // member values. Timestamps are not compared. These operators are exposed for + // testing. + bool operator==(const RTCStats& other) const; + bool operator!=(const RTCStats& other) const; + + // Creates a JSON readable string representation of the stats + // object, listing all of its members (names and values). + std::string ToJson() const; + + // Downcasts the stats object to an |RTCStats| subclass |T|. DCHECKs that the + // object is of type |T|. + template<typename T> + const T& cast_to() const { + RTC_DCHECK_EQ(type(), T::kType); + return static_cast<const T&>(*this); + } + + protected: + // Gets a vector of all members of this |RTCStats| object, including members + // derived from parent classes. |additional_capacity| is how many more members + // shall be reserved in the vector (so that subclasses can allocate a vector + // with room for both parent and child members without it having to resize). + virtual std::vector<const RTCStatsMemberInterface*> + MembersOfThisObjectAndAncestors( + size_t additional_capacity) const; + + std::string const id_; + int64_t timestamp_us_; +}; + +// All |RTCStats| classes should use these macros. +// |WEBRTC_RTCSTATS_DECL| is placed in a public section of the class definition. +// |WEBRTC_RTCSTATS_IMPL| is placed outside the class definition (in a .cc). +// +// These macros declare (in _DECL) and define (in _IMPL) the static |kType| and +// overrides methods as required by subclasses of |RTCStats|: |copy|, |type| and +// |MembersOfThisObjectAndAncestors|. The |...| argument is a list of addresses +// to each member defined in the implementing class. The list must have at least +// one member. +// +// (Since class names need to be known to implement these methods this cannot be +// part of the base |RTCStats|. While these methods could be implemented using +// templates, that would only work for immediate subclasses. Subclasses of +// subclasses also have to override these methods, resulting in boilerplate +// code. Using a macro avoids this and works for any |RTCStats| class, including +// grandchildren.) +// +// Sample usage: +// +// rtcfoostats.h: +// class RTCFooStats : public RTCStats { +// public: +// WEBRTC_RTCSTATS_DECL(); +// +// RTCFooStats(const std::string& id, int64_t timestamp_us); +// +// RTCStatsMember<int32_t> foo; +// RTCStatsMember<int32_t> bar; +// }; +// +// rtcfoostats.cc: +// WEBRTC_RTCSTATS_IMPL(RTCFooStats, RTCStats, "foo-stats" +// &foo, +// &bar); +// +// RTCFooStats::RTCFooStats(const std::string& id, int64_t timestamp_us) +// : RTCStats(id, timestamp_us), +// foo("foo"), +// bar("bar") { +// } +// +#define WEBRTC_RTCSTATS_DECL() \ + public: \ + static const char kType[]; \ + \ + std::unique_ptr<webrtc::RTCStats> copy() const override; \ + const char* type() const override; \ + \ + protected: \ + std::vector<const webrtc::RTCStatsMemberInterface*> \ + MembersOfThisObjectAndAncestors( \ + size_t local_var_additional_capacity) const override; \ + \ + public: + +#define WEBRTC_RTCSTATS_IMPL(this_class, parent_class, type_str, ...) \ + const char this_class::kType[] = type_str; \ + \ + std::unique_ptr<webrtc::RTCStats> this_class::copy() const { \ + return std::unique_ptr<webrtc::RTCStats>(new this_class(*this)); \ + } \ + \ + const char* this_class::type() const { \ + return this_class::kType; \ + } \ + \ + std::vector<const webrtc::RTCStatsMemberInterface*> \ + this_class::MembersOfThisObjectAndAncestors( \ + size_t local_var_additional_capacity) const { \ + const webrtc::RTCStatsMemberInterface* local_var_members[] = { \ + __VA_ARGS__ \ + }; \ + size_t local_var_members_count = \ + sizeof(local_var_members) / sizeof(local_var_members[0]); \ + std::vector<const webrtc::RTCStatsMemberInterface*> local_var_members_vec =\ + parent_class::MembersOfThisObjectAndAncestors( \ + local_var_members_count + local_var_additional_capacity); \ + RTC_DCHECK_GE( \ + local_var_members_vec.capacity() - local_var_members_vec.size(), \ + local_var_members_count + local_var_additional_capacity); \ + local_var_members_vec.insert(local_var_members_vec.end(), \ + &local_var_members[0], \ + &local_var_members[local_var_members_count]); \ + return local_var_members_vec; \ + } + +// Interface for |RTCStats| members, which have a name and a value of a type +// defined in a subclass. Only the types listed in |Type| are supported, these +// are implemented by |RTCStatsMember<T>|. The value of a member may be +// undefined, the value can only be read if |is_defined|. +class RTCStatsMemberInterface { + public: + // Member value types. + enum Type { + kBool, // bool + kInt32, // int32_t + kUint32, // uint32_t + kInt64, // int64_t + kUint64, // uint64_t + kDouble, // double + kString, // std::string + + kSequenceBool, // std::vector<bool> + kSequenceInt32, // std::vector<int32_t> + kSequenceUint32, // std::vector<uint32_t> + kSequenceInt64, // std::vector<int64_t> + kSequenceUint64, // std::vector<uint64_t> + kSequenceDouble, // std::vector<double> + kSequenceString, // std::vector<std::string> + }; + + virtual ~RTCStatsMemberInterface() {} + + const char* name() const { return name_; } + virtual Type type() const = 0; + virtual bool is_sequence() const = 0; + virtual bool is_string() const = 0; + bool is_defined() const { return is_defined_; } + // Type and value comparator. The names are not compared. These operators are + // exposed for testing. + virtual bool operator==(const RTCStatsMemberInterface& other) const = 0; + bool operator!=(const RTCStatsMemberInterface& other) const { + return !(*this == other); + } + virtual std::string ValueToString() const = 0; + // This is the same as ValueToString except for kInt64 and kUint64 types, + // where the value is represented as a double instead of as an integer. + // Since JSON stores numbers as floating point numbers, very large integers + // cannot be accurately represented, so we prefer to display them as doubles + // instead. + virtual std::string ValueToJson() const = 0; + + template<typename T> + const T& cast_to() const { + RTC_DCHECK_EQ(type(), T::kType); + return static_cast<const T&>(*this); + } + + protected: + RTCStatsMemberInterface(const char* name, bool is_defined) + : name_(name), is_defined_(is_defined) {} + + const char* const name_; + bool is_defined_; +}; + +// Template implementation of |RTCStatsMemberInterface|. Every possible |T| is +// specialized in rtcstats.cc, using a different |T| results in a linker error +// (undefined reference to |kType|). The supported types are the ones described +// by |RTCStatsMemberInterface::Type|. +template<typename T> +class RTCStatsMember : public RTCStatsMemberInterface { + public: + static const Type kType; + + explicit RTCStatsMember(const char* name) + : RTCStatsMemberInterface(name, false), + value_() {} + RTCStatsMember(const char* name, const T& value) + : RTCStatsMemberInterface(name, true), + value_(value) {} + RTCStatsMember(const char* name, T&& value) + : RTCStatsMemberInterface(name, true), + value_(std::move(value)) {} + explicit RTCStatsMember(const RTCStatsMember<T>& other) + : RTCStatsMemberInterface(other.name_, other.is_defined_), + value_(other.value_) {} + explicit RTCStatsMember(RTCStatsMember<T>&& other) + : RTCStatsMemberInterface(other.name_, other.is_defined_), + value_(std::move(other.value_)) {} + + Type type() const override { return kType; } + bool is_sequence() const override; + bool is_string() const override; + bool operator==(const RTCStatsMemberInterface& other) const override { + if (type() != other.type()) + return false; + const RTCStatsMember<T>& other_t = + static_cast<const RTCStatsMember<T>&>(other); + if (!is_defined_) + return !other_t.is_defined(); + if (!other.is_defined()) + return false; + return value_ == other_t.value_; + } + std::string ValueToString() const override; + std::string ValueToJson() const override; + + // Assignment operators. + T& operator=(const T& value) { + value_ = value; + is_defined_ = true; + return value_; + } + T& operator=(const T&& value) { + value_ = std::move(value); + is_defined_ = true; + return value_; + } + T& operator=(const RTCStatsMember<T>& other) { + RTC_DCHECK(other.is_defined_); + value_ = other.is_defined_; + is_defined_ = true; + return value_; + } + + // Value getters. + T& operator*() { + RTC_DCHECK(is_defined_); + return value_; + } + const T& operator*() const { + RTC_DCHECK(is_defined_); + return value_; + } + + // Value getters, arrow operator. + T* operator->() { + RTC_DCHECK(is_defined_); + return &value_; + } + const T* operator->() const { + RTC_DCHECK(is_defined_); + return &value_; + } + + private: + T value_; +}; + +} // namespace webrtc + +#endif // API_STATS_RTCSTATS_H_ diff --git a/third_party/libwebrtc/webrtc/api/stats/rtcstats_objects.h b/third_party/libwebrtc/webrtc/api/stats/rtcstats_objects.h new file mode 100644 index 0000000000..b0cf3d0f65 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/stats/rtcstats_objects.h @@ -0,0 +1,435 @@ +/* + * Copyright 2016 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 API_STATS_RTCSTATS_OBJECTS_H_ +#define API_STATS_RTCSTATS_OBJECTS_H_ + +#include <string> +#include <vector> + +#include "api/stats/rtcstats.h" + +namespace webrtc { + +// https://w3c.github.io/webrtc-pc/#idl-def-rtcdatachannelstate +struct RTCDataChannelState { + static const char* const kConnecting; + static const char* const kOpen; + static const char* const kClosing; + static const char* const kClosed; +}; + +// https://w3c.github.io/webrtc-stats/#dom-rtcstatsicecandidatepairstate +struct RTCStatsIceCandidatePairState { + static const char* const kFrozen; + static const char* const kWaiting; + static const char* const kInProgress; + static const char* const kFailed; + static const char* const kSucceeded; +}; + +// https://w3c.github.io/webrtc-pc/#rtcicecandidatetype-enum +struct RTCIceCandidateType { + static const char* const kHost; + static const char* const kSrflx; + static const char* const kPrflx; + static const char* const kRelay; +}; + +// https://w3c.github.io/webrtc-pc/#idl-def-rtcdtlstransportstate +struct RTCDtlsTransportState { + static const char* const kNew; + static const char* const kConnecting; + static const char* const kConnected; + static const char* const kClosed; + static const char* const kFailed; +}; + +// |RTCMediaStreamTrackStats::kind| is not an enum in the spec but the only +// valid values are "audio" and "video". +// https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-kind +struct RTCMediaStreamTrackKind { + static const char* const kAudio; + static const char* const kVideo; +}; + +// https://w3c.github.io/webrtc-stats/#dom-rtcnetworktype +struct RTCNetworkType { + static const char* const kBluetooth; + static const char* const kCellular; + static const char* const kEthernet; + static const char* const kWifi; + static const char* const kWimax; + static const char* const kVpn; + static const char* const kUnknown; +}; + +// https://w3c.github.io/webrtc-stats/#certificatestats-dict* +class RTCCertificateStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCCertificateStats(const std::string& id, int64_t timestamp_us); + RTCCertificateStats(std::string&& id, int64_t timestamp_us); + RTCCertificateStats(const RTCCertificateStats& other); + ~RTCCertificateStats() override; + + RTCStatsMember<std::string> fingerprint; + RTCStatsMember<std::string> fingerprint_algorithm; + RTCStatsMember<std::string> base64_certificate; + RTCStatsMember<std::string> issuer_certificate_id; +}; + +// https://w3c.github.io/webrtc-stats/#codec-dict* +class RTCCodecStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCCodecStats(const std::string& id, int64_t timestamp_us); + RTCCodecStats(std::string&& id, int64_t timestamp_us); + RTCCodecStats(const RTCCodecStats& other); + ~RTCCodecStats() override; + + RTCStatsMember<uint32_t> payload_type; + RTCStatsMember<std::string> mime_type; + RTCStatsMember<uint32_t> clock_rate; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061 + RTCStatsMember<uint32_t> channels; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061 + RTCStatsMember<std::string> sdp_fmtp_line; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7061 + RTCStatsMember<std::string> implementation; +}; + +// https://w3c.github.io/webrtc-stats/#dcstats-dict* +class RTCDataChannelStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCDataChannelStats(const std::string& id, int64_t timestamp_us); + RTCDataChannelStats(std::string&& id, int64_t timestamp_us); + RTCDataChannelStats(const RTCDataChannelStats& other); + ~RTCDataChannelStats() override; + + RTCStatsMember<std::string> label; + RTCStatsMember<std::string> protocol; + RTCStatsMember<int32_t> datachannelid; + // TODO(hbos): Support enum types? "RTCStatsMember<RTCDataChannelState>"? + RTCStatsMember<std::string> state; + RTCStatsMember<uint32_t> messages_sent; + RTCStatsMember<uint64_t> bytes_sent; + RTCStatsMember<uint32_t> messages_received; + RTCStatsMember<uint64_t> bytes_received; +}; + +// https://w3c.github.io/webrtc-stats/#candidatepair-dict* +// TODO(hbos): Tracking bug https://bugs.webrtc.org/7062 +class RTCIceCandidatePairStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCIceCandidatePairStats(const std::string& id, int64_t timestamp_us); + RTCIceCandidatePairStats(std::string&& id, int64_t timestamp_us); + RTCIceCandidatePairStats(const RTCIceCandidatePairStats& other); + ~RTCIceCandidatePairStats() override; + + RTCStatsMember<std::string> transport_id; + RTCStatsMember<std::string> local_candidate_id; + RTCStatsMember<std::string> remote_candidate_id; + // TODO(hbos): Support enum types? + // "RTCStatsMember<RTCStatsIceCandidatePairState>"? + RTCStatsMember<std::string> state; + RTCStatsMember<uint64_t> priority; + RTCStatsMember<bool> nominated; + // TODO(hbos): Collect this the way the spec describes it. We have a value for + // it but it is not spec-compliant. https://bugs.webrtc.org/7062 + RTCStatsMember<bool> writable; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<bool> readable; + RTCStatsMember<uint64_t> bytes_sent; + RTCStatsMember<uint64_t> bytes_received; + RTCStatsMember<double> total_round_trip_time; + RTCStatsMember<double> current_round_trip_time; + RTCStatsMember<double> available_outgoing_bitrate; + // TODO(hbos): Populate this value. It is wired up and collected the same way + // "VideoBwe.googAvailableReceiveBandwidth" is, but that value is always + // undefined. https://bugs.webrtc.org/7062 + RTCStatsMember<double> available_incoming_bitrate; + RTCStatsMember<uint64_t> requests_received; + RTCStatsMember<uint64_t> requests_sent; + RTCStatsMember<uint64_t> responses_received; + RTCStatsMember<uint64_t> responses_sent; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<uint64_t> retransmissions_received; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<uint64_t> retransmissions_sent; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<uint64_t> consent_requests_received; + RTCStatsMember<uint64_t> consent_requests_sent; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<uint64_t> consent_responses_received; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7062 + RTCStatsMember<uint64_t> consent_responses_sent; +}; + +// https://w3c.github.io/webrtc-stats/#icecandidate-dict* +// TODO(hbos): |RTCStatsCollector| only collects candidates that are part of +// ice candidate pairs, but there could be candidates not paired with anything. +// crbug.com/632723 +class RTCIceCandidateStats : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCIceCandidateStats(const RTCIceCandidateStats& other); + ~RTCIceCandidateStats() override; + + RTCStatsMember<std::string> transport_id; + RTCStatsMember<bool> is_remote; + RTCStatsMember<std::string> network_type; + RTCStatsMember<std::string> ip; + RTCStatsMember<int32_t> port; + RTCStatsMember<std::string> protocol; + // TODO(hbos): Support enum types? "RTCStatsMember<RTCIceCandidateType>"? + RTCStatsMember<std::string> candidate_type; + RTCStatsMember<int32_t> priority; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/632723 + RTCStatsMember<std::string> url; + // TODO(hbos): |deleted = true| case is not supported by |RTCStatsCollector|. + // crbug.com/632723 + RTCStatsMember<bool> deleted; // = false + + protected: + RTCIceCandidateStats( + const std::string& id, int64_t timestamp_us, bool is_remote); + RTCIceCandidateStats(std::string&& id, int64_t timestamp_us, bool is_remote); +}; + +// In the spec both local and remote varieties are of type RTCIceCandidateStats. +// But here we define them as subclasses of |RTCIceCandidateStats| because the +// |kType| need to be different ("RTCStatsType type") in the local/remote case. +// https://w3c.github.io/webrtc-stats/#rtcstatstype-str* +class RTCLocalIceCandidateStats final : public RTCIceCandidateStats { + public: + static const char kType[]; + RTCLocalIceCandidateStats(const std::string& id, int64_t timestamp_us); + RTCLocalIceCandidateStats(std::string&& id, int64_t timestamp_us); + const char* type() const override; +}; + +class RTCRemoteIceCandidateStats final : public RTCIceCandidateStats { + public: + static const char kType[]; + RTCRemoteIceCandidateStats(const std::string& id, int64_t timestamp_us); + RTCRemoteIceCandidateStats(std::string&& id, int64_t timestamp_us); + const char* type() const override; +}; + +// https://w3c.github.io/webrtc-stats/#msstats-dict* +// TODO(hbos): Tracking bug crbug.com/660827 +class RTCMediaStreamStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCMediaStreamStats(const std::string& id, int64_t timestamp_us); + RTCMediaStreamStats(std::string&& id, int64_t timestamp_us); + RTCMediaStreamStats(const RTCMediaStreamStats& other); + ~RTCMediaStreamStats() override; + + RTCStatsMember<std::string> stream_identifier; + RTCStatsMember<std::vector<std::string>> track_ids; +}; + +// https://w3c.github.io/webrtc-stats/#mststats-dict* +// TODO(hbos): Tracking bug crbug.com/659137 +class RTCMediaStreamTrackStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCMediaStreamTrackStats(const std::string& id, int64_t timestamp_us, + const char* kind); + RTCMediaStreamTrackStats(std::string&& id, int64_t timestamp_us, + const char* kind); + RTCMediaStreamTrackStats(const RTCMediaStreamTrackStats& other); + ~RTCMediaStreamTrackStats() override; + + RTCStatsMember<std::string> track_identifier; + RTCStatsMember<bool> remote_source; + RTCStatsMember<bool> ended; + // TODO(hbos): |RTCStatsCollector| does not return stats for detached tracks. + // crbug.com/659137 + RTCStatsMember<bool> detached; + // See |RTCMediaStreamTrackKind| for valid values. + RTCStatsMember<std::string> kind; + // TODO(gustaf): Implement jitter_buffer_delay for video (currently + // implemented for audio only). + // https://crbug.com/webrtc/8318 + RTCStatsMember<double> jitter_buffer_delay; + // Video-only members + RTCStatsMember<uint32_t> frame_width; + RTCStatsMember<uint32_t> frame_height; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137 + RTCStatsMember<double> frames_per_second; + RTCStatsMember<uint32_t> frames_sent; + RTCStatsMember<uint32_t> frames_received; + RTCStatsMember<uint32_t> frames_decoded; + RTCStatsMember<uint32_t> frames_dropped; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137 + RTCStatsMember<uint32_t> frames_corrupted; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137 + RTCStatsMember<uint32_t> partial_frames_lost; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/659137 + RTCStatsMember<uint32_t> full_frames_lost; + // Audio-only members + RTCStatsMember<double> audio_level; + RTCStatsMember<double> total_audio_energy; + RTCStatsMember<double> echo_return_loss; + RTCStatsMember<double> echo_return_loss_enhancement; + RTCStatsMember<uint64_t> total_samples_received; + RTCStatsMember<double> total_samples_duration; + RTCStatsMember<uint64_t> concealed_samples; + RTCStatsMember<uint64_t> concealment_events; +}; + +// https://w3c.github.io/webrtc-stats/#pcstats-dict* +class RTCPeerConnectionStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCPeerConnectionStats(const std::string& id, int64_t timestamp_us); + RTCPeerConnectionStats(std::string&& id, int64_t timestamp_us); + RTCPeerConnectionStats(const RTCPeerConnectionStats& other); + ~RTCPeerConnectionStats() override; + + RTCStatsMember<uint32_t> data_channels_opened; + RTCStatsMember<uint32_t> data_channels_closed; +}; + +// https://w3c.github.io/webrtc-stats/#streamstats-dict* +// TODO(hbos): Tracking bug crbug.com/657854 +class RTCRTPStreamStats : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCRTPStreamStats(const RTCRTPStreamStats& other); + ~RTCRTPStreamStats() override; + + RTCStatsMember<uint32_t> ssrc; + // TODO(hbos): When the remote case is supported |RTCStatsCollector| needs to + // set this. crbug.com/657855, 657856 + RTCStatsMember<std::string> associate_stats_id; + // TODO(hbos): Remote case not supported by |RTCStatsCollector|. + // crbug.com/657855, 657856 + RTCStatsMember<bool> is_remote; // = false + RTCStatsMember<std::string> media_type; + RTCStatsMember<std::string> track_id; + RTCStatsMember<std::string> transport_id; + RTCStatsMember<std::string> codec_id; + // FIR and PLI counts are only defined for |media_type == "video"|. + RTCStatsMember<uint32_t> fir_count; + RTCStatsMember<uint32_t> pli_count; + // TODO(hbos): NACK count should be collected by |RTCStatsCollector| for both + // audio and video but is only defined in the "video" case. crbug.com/657856 + RTCStatsMember<uint32_t> nack_count; + // TODO(hbos): Not collected by |RTCStatsCollector|. crbug.com/657854 + // SLI count is only defined for |media_type == "video"|. + RTCStatsMember<uint32_t> sli_count; + RTCStatsMember<uint64_t> qp_sum; + + protected: + RTCRTPStreamStats(const std::string& id, int64_t timestamp_us); + RTCRTPStreamStats(std::string&& id, int64_t timestamp_us); +}; + +// https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict* +// TODO(hbos): Support the remote case |is_remote = true|. +// https://bugs.webrtc.org/7065 +class RTCInboundRTPStreamStats final : public RTCRTPStreamStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCInboundRTPStreamStats(const std::string& id, int64_t timestamp_us); + RTCInboundRTPStreamStats(std::string&& id, int64_t timestamp_us); + RTCInboundRTPStreamStats(const RTCInboundRTPStreamStats& other); + ~RTCInboundRTPStreamStats() override; + + RTCStatsMember<uint32_t> packets_received; + RTCStatsMember<uint64_t> bytes_received; + RTCStatsMember<uint32_t> packets_lost; + // TODO(hbos): Collect and populate this value for both "audio" and "video", + // currently not collected for "video". https://bugs.webrtc.org/7065 + RTCStatsMember<double> jitter; + RTCStatsMember<double> fraction_lost; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<double> round_trip_time; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> packets_discarded; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> packets_repaired; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> burst_packets_lost; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> burst_packets_discarded; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> burst_loss_count; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<uint32_t> burst_discard_count; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<double> burst_loss_rate; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<double> burst_discard_rate; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<double> gap_loss_rate; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7065 + RTCStatsMember<double> gap_discard_rate; + RTCStatsMember<uint32_t> frames_decoded; +}; + +// https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict* +// TODO(hbos): Support the remote case |is_remote = true|. +// https://bugs.webrtc.org/7066 +class RTCOutboundRTPStreamStats final : public RTCRTPStreamStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCOutboundRTPStreamStats(const std::string& id, int64_t timestamp_us); + RTCOutboundRTPStreamStats(std::string&& id, int64_t timestamp_us); + RTCOutboundRTPStreamStats(const RTCOutboundRTPStreamStats& other); + ~RTCOutboundRTPStreamStats() override; + + RTCStatsMember<uint32_t> packets_sent; + RTCStatsMember<uint64_t> bytes_sent; + // TODO(hbos): Collect and populate this value. https://bugs.webrtc.org/7066 + RTCStatsMember<double> target_bitrate; + RTCStatsMember<uint32_t> frames_encoded; +}; + +// https://w3c.github.io/webrtc-stats/#transportstats-dict* +class RTCTransportStats final : public RTCStats { + public: + WEBRTC_RTCSTATS_DECL(); + + RTCTransportStats(const std::string& id, int64_t timestamp_us); + RTCTransportStats(std::string&& id, int64_t timestamp_us); + RTCTransportStats(const RTCTransportStats& other); + ~RTCTransportStats() override; + + RTCStatsMember<uint64_t> bytes_sent; + RTCStatsMember<uint64_t> bytes_received; + RTCStatsMember<std::string> rtcp_transport_stats_id; + // TODO(hbos): Support enum types? "RTCStatsMember<RTCDtlsTransportState>"? + RTCStatsMember<std::string> dtls_state; + RTCStatsMember<std::string> selected_candidate_pair_id; + RTCStatsMember<std::string> local_certificate_id; + RTCStatsMember<std::string> remote_certificate_id; +}; + +} // namespace webrtc + +#endif // API_STATS_RTCSTATS_OBJECTS_H_ diff --git a/third_party/libwebrtc/webrtc/api/stats/rtcstatscollectorcallback.h b/third_party/libwebrtc/webrtc/api/stats/rtcstatscollectorcallback.h new file mode 100644 index 0000000000..2c67bb81bb --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/stats/rtcstatscollectorcallback.h @@ -0,0 +1,30 @@ +/* + * Copyright 2016 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 API_STATS_RTCSTATSCOLLECTORCALLBACK_H_ +#define API_STATS_RTCSTATSCOLLECTORCALLBACK_H_ + +#include "api/stats/rtcstatsreport.h" +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface { + public: + virtual ~RTCStatsCollectorCallback() {} + + virtual void OnStatsDelivered( + const rtc::scoped_refptr<const RTCStatsReport>& report) = 0; +}; + +} // namespace webrtc + +#endif // API_STATS_RTCSTATSCOLLECTORCALLBACK_H_ diff --git a/third_party/libwebrtc/webrtc/api/stats/rtcstatsreport.h b/third_party/libwebrtc/webrtc/api/stats/rtcstatsreport.h new file mode 100644 index 0000000000..ee56b35d06 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/stats/rtcstatsreport.h @@ -0,0 +1,100 @@ +/* + * Copyright 2016 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 API_STATS_RTCSTATSREPORT_H_ +#define API_STATS_RTCSTATSREPORT_H_ + +#include <map> +#include <memory> +#include <string> +#include <vector> + +#include "api/stats/rtcstats.h" +#include "rtc_base/refcount.h" +#include "rtc_base/refcountedobject.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +// A collection of stats. +// This is accessible as a map from |RTCStats::id| to |RTCStats|. +class RTCStatsReport : public rtc::RefCountInterface { + public: + typedef std::map<std::string, std::unique_ptr<const RTCStats>> StatsMap; + + class ConstIterator { + public: + ConstIterator(const ConstIterator&& other); + ~ConstIterator(); + + ConstIterator& operator++(); + ConstIterator& operator++(int); + const RTCStats& operator*() const; + const RTCStats* operator->() const; + bool operator==(const ConstIterator& other) const; + bool operator!=(const ConstIterator& other) const; + + private: + friend class RTCStatsReport; + ConstIterator(const rtc::scoped_refptr<const RTCStatsReport>& report, + StatsMap::const_iterator it); + + // Reference report to make sure it is kept alive. + rtc::scoped_refptr<const RTCStatsReport> report_; + StatsMap::const_iterator it_; + }; + + // TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call + // with a parameter. crbug.com/627816 + static rtc::scoped_refptr<RTCStatsReport> Create(int64_t timestamp_us = 0); + + explicit RTCStatsReport(int64_t timestamp_us); + RTCStatsReport(const RTCStatsReport& other) = delete; + + int64_t timestamp_us() const { return timestamp_us_; } + void AddStats(std::unique_ptr<const RTCStats> stats); + const RTCStats* Get(const std::string& id) const; + size_t size() const { return stats_.size(); } + + // Takes ownership of all the stats in |victim|, leaving it empty. + void TakeMembersFrom(rtc::scoped_refptr<RTCStatsReport> victim); + + // Stats iterators. Stats are ordered lexicographically on |RTCStats::id|. + ConstIterator begin() const; + ConstIterator end() const; + + // Gets the subset of stats that are of type |T|, where |T| is any class + // descending from |RTCStats|. + template<typename T> + std::vector<const T*> GetStatsOfType() const { + std::vector<const T*> stats_of_type; + for (const RTCStats& stats : *this) { + if (stats.type() == T::kType) + stats_of_type.push_back(&stats.cast_to<const T>()); + } + return stats_of_type; + } + + // Creates a JSON readable string representation of the report, + // listing all of its stats objects. + std::string ToJson() const; + + friend class rtc::RefCountedObject<RTCStatsReport>; + + private: + ~RTCStatsReport() override; + + int64_t timestamp_us_; + StatsMap stats_; +}; + +} // namespace webrtc + +#endif // API_STATS_RTCSTATSREPORT_H_ diff --git a/third_party/libwebrtc/webrtc/api/statstypes.cc b/third_party/libwebrtc/webrtc/api/statstypes.cc new file mode 100644 index 0000000000..ff70bac442 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/statstypes.cc @@ -0,0 +1,828 @@ +/* + * Copyright 2014 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 "api/statstypes.h" + +#include <string.h> + +#include "rtc_base/checks.h" +#include "rtc_base/refcountedobject.h" + +// TODO(tommi): Could we have a static map of value name -> expected type +// and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)? +// Alternatively, we could define the names+type in a separate document and +// generate strongly typed inline C++ code that forces the correct type to be +// used for a given name at compile time. + +using rtc::RefCountedObject; + +namespace webrtc { +namespace { + +// The id of StatsReport of type kStatsReportTypeBwe. +const char kStatsReportVideoBweId[] = "bweforvideo"; + +// NOTE: These names need to be consistent with an external +// specification (W3C Stats Identifiers). +const char* InternalTypeToString(StatsReport::StatsType type) { + switch (type) { + case StatsReport::kStatsReportTypeSession: + return "googLibjingleSession"; + case StatsReport::kStatsReportTypeBwe: + return "VideoBwe"; + case StatsReport::kStatsReportTypeRemoteSsrc: + return "remoteSsrc"; + case StatsReport::kStatsReportTypeSsrc: + return "ssrc"; + case StatsReport::kStatsReportTypeTrack: + return "googTrack"; + case StatsReport::kStatsReportTypeIceLocalCandidate: + return "localcandidate"; + case StatsReport::kStatsReportTypeIceRemoteCandidate: + return "remotecandidate"; + case StatsReport::kStatsReportTypeTransport: + return "transport"; + case StatsReport::kStatsReportTypeComponent: + return "googComponent"; + case StatsReport::kStatsReportTypeCandidatePair: + return "googCandidatePair"; + case StatsReport::kStatsReportTypeCertificate: + return "googCertificate"; + case StatsReport::kStatsReportTypeDataChannel: + return "datachannel"; + } + RTC_NOTREACHED(); + return nullptr; +} + +class BandwidthEstimationId : public StatsReport::IdBase { + public: + BandwidthEstimationId() + : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {} + std::string ToString() const override { return kStatsReportVideoBweId; } +}; + +class TypedId : public StatsReport::IdBase { + public: + TypedId(StatsReport::StatsType type, const std::string& id) + : StatsReport::IdBase(type), id_(id) {} + + bool Equals(const IdBase& other) const override { + return IdBase::Equals(other) && + static_cast<const TypedId&>(other).id_ == id_; + } + + std::string ToString() const override { + return std::string(InternalTypeToString(type_)) + kSeparator + id_; + } + + protected: + const std::string id_; +}; + +class TypedIntId : public StatsReport::IdBase { + public: + TypedIntId(StatsReport::StatsType type, int id) + : StatsReport::IdBase(type), id_(id) {} + + bool Equals(const IdBase& other) const override { + return IdBase::Equals(other) && + static_cast<const TypedIntId&>(other).id_ == id_; + } + + std::string ToString() const override { + return std::string(InternalTypeToString(type_)) + + kSeparator + + rtc::ToString<int>(id_); + } + + protected: + const int id_; +}; + +class IdWithDirection : public TypedId { + public: + IdWithDirection(StatsReport::StatsType type, const std::string& id, + StatsReport::Direction direction) + : TypedId(type, id), direction_(direction) {} + + bool Equals(const IdBase& other) const override { + return TypedId::Equals(other) && + static_cast<const IdWithDirection&>(other).direction_ == direction_; + } + + std::string ToString() const override { + std::string ret(TypedId::ToString()); + ret += kSeparator; + ret += direction_ == StatsReport::kSend ? "send" : "recv"; + return ret; + } + + private: + const StatsReport::Direction direction_; +}; + +class CandidateId : public TypedId { + public: + CandidateId(bool local, const std::string& id) + : TypedId(local ? + StatsReport::kStatsReportTypeIceLocalCandidate : + StatsReport::kStatsReportTypeIceRemoteCandidate, + id) { + } + + std::string ToString() const override { + return "Cand-" + id_; + } +}; + +class ComponentId : public StatsReport::IdBase { + public: + ComponentId(const std::string& content_name, int component) + : ComponentId(StatsReport::kStatsReportTypeComponent, content_name, + component) {} + + bool Equals(const IdBase& other) const override { + return IdBase::Equals(other) && + static_cast<const ComponentId&>(other).component_ == component_ && + static_cast<const ComponentId&>(other).content_name_ == content_name_; + } + + std::string ToString() const override { + return ToString("Channel-"); + } + + protected: + ComponentId(StatsReport::StatsType type, const std::string& content_name, + int component) + : IdBase(type), + content_name_(content_name), + component_(component) {} + + std::string ToString(const char* prefix) const { + std::string ret(prefix); + ret += content_name_; + ret += '-'; + ret += rtc::ToString<>(component_); + return ret; + } + + private: + const std::string content_name_; + const int component_; +}; + +class CandidatePairId : public ComponentId { + public: + CandidatePairId(const std::string& content_name, int component, int index) + : ComponentId(StatsReport::kStatsReportTypeCandidatePair, content_name, + component), + index_(index) {} + + bool Equals(const IdBase& other) const override { + return ComponentId::Equals(other) && + static_cast<const CandidatePairId&>(other).index_ == index_; + } + + std::string ToString() const override { + std::string ret(ComponentId::ToString("Conn-")); + ret += '-'; + ret += rtc::ToString<>(index_); + return ret; + } + + private: + const int index_; +}; + +} // namespace + +StatsReport::IdBase::IdBase(StatsType type) : type_(type) {} +StatsReport::IdBase::~IdBase() {} + +StatsReport::StatsType StatsReport::IdBase::type() const { return type_; } + +bool StatsReport::IdBase::Equals(const IdBase& other) const { + return other.type_ == type_; +} + +StatsReport::Value::Value(StatsValueName name, int64_t value, Type int_type) + : name(name), type_(int_type) { + RTC_DCHECK(type_ == kInt || type_ == kInt64); + type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value; +} + +StatsReport::Value::Value(StatsValueName name, float f) + : name(name), type_(kFloat) { + value_.float_ = f; +} + +StatsReport::Value::Value(StatsValueName name, const std::string& value) + : name(name), type_(kString) { + value_.string_ = new std::string(value); +} + +StatsReport::Value::Value(StatsValueName name, const char* value) + : name(name), type_(kStaticString) { + value_.static_string_ = value; +} + +StatsReport::Value::Value(StatsValueName name, bool b) + : name(name), type_(kBool) { + value_.bool_ = b; +} + +StatsReport::Value::Value(StatsValueName name, const Id& value) + : name(name), type_(kId) { + value_.id_ = new Id(value); +} + +StatsReport::Value::~Value() { + switch (type_) { + case kInt: + case kInt64: + case kFloat: + case kBool: + case kStaticString: + break; + case kString: + delete value_.string_; + break; + case kId: + delete value_.id_; + break; + } +} + +bool StatsReport::Value::Equals(const Value& other) const { + if (name != other.name) + return false; + + // There's a 1:1 relation between a name and a type, so we don't have to + // check that. + RTC_DCHECK_EQ(type_, other.type_); + + switch (type_) { + case kInt: + return value_.int_ == other.value_.int_; + case kInt64: + return value_.int64_ == other.value_.int64_; + case kFloat: + return value_.float_ == other.value_.float_; + case kStaticString: { +#if RTC_DCHECK_IS_ON + if (value_.static_string_ != other.value_.static_string_) { + RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) != + 0) + << "Duplicate global?"; + } +#endif + return value_.static_string_ == other.value_.static_string_; + } + case kString: + return *value_.string_ == *other.value_.string_; + case kBool: + return value_.bool_ == other.value_.bool_; + case kId: + return (*value_.id_)->Equals(*other.value_.id_); + } + RTC_NOTREACHED(); + return false; +} + +bool StatsReport::Value::operator==(const std::string& value) const { + return (type_ == kString && value_.string_->compare(value) == 0) || + (type_ == kStaticString && value.compare(value_.static_string_) == 0); +} + +bool StatsReport::Value::operator==(const char* value) const { + if (type_ == kString) + return value_.string_->compare(value) == 0; + if (type_ != kStaticString) + return false; +#if RTC_DCHECK_IS_ON + if (value_.static_string_ != value) + RTC_DCHECK(strcmp(value_.static_string_, value) != 0) + << "Duplicate global?"; +#endif + return value == value_.static_string_; +} + +bool StatsReport::Value::operator==(int64_t value) const { + return type_ == kInt ? value_.int_ == static_cast<int>(value) : + (type_ == kInt64 ? value_.int64_ == value : false); +} + +bool StatsReport::Value::operator==(bool value) const { + return type_ == kBool && value_.bool_ == value; +} + +bool StatsReport::Value::operator==(float value) const { + return type_ == kFloat && value_.float_ == value; +} + +bool StatsReport::Value::operator==(const Id& value) const { + return type_ == kId && (*value_.id_)->Equals(value); +} + +int StatsReport::Value::int_val() const { + RTC_DCHECK(type_ == kInt); + return value_.int_; +} + +int64_t StatsReport::Value::int64_val() const { + RTC_DCHECK(type_ == kInt64); + return value_.int64_; +} + +float StatsReport::Value::float_val() const { + RTC_DCHECK(type_ == kFloat); + return value_.float_; +} + +const char* StatsReport::Value::static_string_val() const { + RTC_DCHECK(type_ == kStaticString); + return value_.static_string_; +} + +const std::string& StatsReport::Value::string_val() const { + RTC_DCHECK(type_ == kString); + return *value_.string_; +} + +bool StatsReport::Value::bool_val() const { + RTC_DCHECK(type_ == kBool); + return value_.bool_; +} + +const char* StatsReport::Value::display_name() const { + switch (name) { + case kStatsValueNameAecDivergentFilterFraction: + return "aecDivergentFilterFraction"; + case kStatsValueNameAudioOutputLevel: + return "audioOutputLevel"; + case kStatsValueNameAudioInputLevel: + return "audioInputLevel"; + case kStatsValueNameBytesSent: + return "bytesSent"; + case kStatsValueNameConcealedSamples: + return "concealedSamples"; + case kStatsValueNameConcealmentEvents: + return "concealmentEvents"; + case kStatsValueNamePacketsSent: + return "packetsSent"; + case kStatsValueNameBytesReceived: + return "bytesReceived"; + case kStatsValueNameLabel: + return "label"; + case kStatsValueNamePacketsReceived: + return "packetsReceived"; + case kStatsValueNamePacketsLost: + return "packetsLost"; + case kStatsValueNameProtocol: + return "protocol"; + case kStatsValueNameTotalSamplesReceived: + return "totalSamplesReceived"; + case kStatsValueNameTransportId: + return "transportId"; + case kStatsValueNameSelectedCandidatePairId: + return "selectedCandidatePairId"; + case kStatsValueNameSsrc: + return "ssrc"; + case kStatsValueNameState: + return "state"; + case kStatsValueNameDataChannelId: + return "datachannelid"; + case kStatsValueNameFramesDecoded: + return "framesDecoded"; + case kStatsValueNameFramesEncoded: + return "framesEncoded"; + case kStatsValueNameJitterBufferDelay: + return "jitterBufferDelay"; + case kStatsValueNameCodecImplementationName: + return "codecImplementationName"; + case kStatsValueNameMediaType: + return "mediaType"; + case kStatsValueNameQpSum: + return "qpSum"; + // 'goog' prefixed constants. + case kStatsValueNameAccelerateRate: + return "googAccelerateRate"; + case kStatsValueNameActiveConnection: + return "googActiveConnection"; + case kStatsValueNameActualEncBitrate: + return "googActualEncBitrate"; + case kStatsValueNameAvailableReceiveBandwidth: + return "googAvailableReceiveBandwidth"; + case kStatsValueNameAvailableSendBandwidth: + return "googAvailableSendBandwidth"; + case kStatsValueNameAvgEncodeMs: + return "googAvgEncodeMs"; + case kStatsValueNameBucketDelay: + return "googBucketDelay"; + case kStatsValueNameBandwidthLimitedResolution: + return "googBandwidthLimitedResolution"; + // STUN ping related attributes. + // TODO(zhihuang) Rename these stats to follow the standards. + case kStatsValueNameSentPingRequestsTotal: + return "requestsSent"; + case kStatsValueNameSentPingRequestsBeforeFirstResponse: + return "consentRequestsSent"; + case kStatsValueNameSentPingResponses: + return "responsesSent"; + case kStatsValueNameRecvPingRequests: + return "requestsReceived"; + case kStatsValueNameRecvPingResponses: + return "responsesReceived"; + + // Candidate related attributes. Values are taken from + // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. + case kStatsValueNameCandidateIPAddress: + return "ipAddress"; + case kStatsValueNameCandidateNetworkType: + return "networkType"; + case kStatsValueNameCandidatePortNumber: + return "portNumber"; + case kStatsValueNameCandidatePriority: + return "priority"; + case kStatsValueNameCandidateTransportType: + return "transport"; + case kStatsValueNameCandidateType: + return "candidateType"; + + case kStatsValueNameChannelId: + return "googChannelId"; + case kStatsValueNameCodecName: + return "googCodecName"; + case kStatsValueNameComponent: + return "googComponent"; + case kStatsValueNameContentName: + return "googContentName"; + case kStatsValueNameContentType: + return "googContentType"; + case kStatsValueNameCpuLimitedResolution: + return "googCpuLimitedResolution"; + case kStatsValueNameDecodingCTSG: + return "googDecodingCTSG"; + case kStatsValueNameDecodingCTN: + return "googDecodingCTN"; + case kStatsValueNameDecodingMutedOutput: + return "googDecodingMuted"; + case kStatsValueNameDecodingNormal: + return "googDecodingNormal"; + case kStatsValueNameDecodingPLC: + return "googDecodingPLC"; + case kStatsValueNameDecodingCNG: + return "googDecodingCNG"; + case kStatsValueNameDecodingPLCCNG: + return "googDecodingPLCCNG"; + case kStatsValueNameDer: + return "googDerBase64"; + case kStatsValueNameDtlsCipher: + return "dtlsCipher"; + case kStatsValueNameEchoCancellationQualityMin: + return "googEchoCancellationQualityMin"; + case kStatsValueNameEchoDelayMedian: + return "googEchoCancellationEchoDelayMedian"; + case kStatsValueNameEchoDelayStdDev: + return "googEchoCancellationEchoDelayStdDev"; + case kStatsValueNameEchoReturnLoss: + return "googEchoCancellationReturnLoss"; + case kStatsValueNameEchoReturnLossEnhancement: + return "googEchoCancellationReturnLossEnhancement"; + case kStatsValueNameEncodeUsagePercent: + return "googEncodeUsagePercent"; + case kStatsValueNameExpandRate: + return "googExpandRate"; + case kStatsValueNameFingerprint: + return "googFingerprint"; + case kStatsValueNameFingerprintAlgorithm: + return "googFingerprintAlgorithm"; + case kStatsValueNameFirsReceived: + return "googFirsReceived"; + case kStatsValueNameFirsSent: + return "googFirsSent"; + case kStatsValueNameFrameHeightInput: + return "googFrameHeightInput"; + case kStatsValueNameFrameHeightReceived: + return "googFrameHeightReceived"; + case kStatsValueNameFrameHeightSent: + return "googFrameHeightSent"; + case kStatsValueNameFrameRateReceived: + return "googFrameRateReceived"; + case kStatsValueNameFrameRateDecoded: + return "googFrameRateDecoded"; + case kStatsValueNameFrameRateOutput: + return "googFrameRateOutput"; + case kStatsValueNameDecodeMs: + return "googDecodeMs"; + case kStatsValueNameMaxDecodeMs: + return "googMaxDecodeMs"; + case kStatsValueNameCurrentDelayMs: + return "googCurrentDelayMs"; + case kStatsValueNameTargetDelayMs: + return "googTargetDelayMs"; + case kStatsValueNameJitterBufferMs: + return "googJitterBufferMs"; + case kStatsValueNameMinPlayoutDelayMs: + return "googMinPlayoutDelayMs"; + case kStatsValueNameRenderDelayMs: + return "googRenderDelayMs"; + case kStatsValueNameCaptureStartNtpTimeMs: + return "googCaptureStartNtpTimeMs"; + case kStatsValueNameFrameRateInput: + return "googFrameRateInput"; + case kStatsValueNameFrameRateSent: + return "googFrameRateSent"; + case kStatsValueNameFrameWidthInput: + return "googFrameWidthInput"; + case kStatsValueNameFrameWidthReceived: + return "googFrameWidthReceived"; + case kStatsValueNameFrameWidthSent: + return "googFrameWidthSent"; + case kStatsValueNameHasEnteredLowResolution: + return "googHasEnteredLowResolution"; + case kStatsValueNameInitiator: + return "googInitiator"; + case kStatsValueNameInterframeDelayMaxMs: + return "googInterframeDelayMax"; + case kStatsValueNameIssuerId: + return "googIssuerId"; + case kStatsValueNameJitterReceived: + return "googJitterReceived"; + case kStatsValueNameLocalAddress: + return "googLocalAddress"; + case kStatsValueNameLocalCandidateId: + return "localCandidateId"; + case kStatsValueNameLocalCandidateType: + return "googLocalCandidateType"; + case kStatsValueNameLocalCertificateId: + return "localCertificateId"; + case kStatsValueNameAdaptationChanges: + return "googAdaptationChanges"; + case kStatsValueNameNacksReceived: + return "googNacksReceived"; + case kStatsValueNameNacksSent: + return "googNacksSent"; + case kStatsValueNamePreemptiveExpandRate: + return "googPreemptiveExpandRate"; + case kStatsValueNamePlisReceived: + return "googPlisReceived"; + case kStatsValueNamePlisSent: + return "googPlisSent"; + case kStatsValueNamePreferredJitterBufferMs: + return "googPreferredJitterBufferMs"; + case kStatsValueNameReceiving: + return "googReadable"; + case kStatsValueNameRemoteAddress: + return "googRemoteAddress"; + case kStatsValueNameRemoteCandidateId: + return "remoteCandidateId"; + case kStatsValueNameRemoteCandidateType: + return "googRemoteCandidateType"; + case kStatsValueNameRemoteCertificateId: + return "remoteCertificateId"; + case kStatsValueNameResidualEchoLikelihood: + return "googResidualEchoLikelihood"; + case kStatsValueNameResidualEchoLikelihoodRecentMax: + return "googResidualEchoLikelihoodRecentMax"; + case kStatsValueNameAnaBitrateActionCounter: + return "googAnaBitrateActionCounter"; + case kStatsValueNameAnaChannelActionCounter: + return "googAnaChannelActionCounter"; + case kStatsValueNameAnaDtxActionCounter: + return "googAnaDtxActionCounter"; + case kStatsValueNameAnaFecActionCounter: + return "googAnaFecActionCounter"; + case kStatsValueNameAnaFrameLengthIncreaseCounter: + return "googAnaFrameLengthIncreaseCounter"; + case kStatsValueNameAnaFrameLengthDecreaseCounter: + return "googAnaFrameLengthDecreaseCounter"; + case kStatsValueNameAnaUplinkPacketLossFraction: + return "googAnaUplinkPacketLossFraction"; + case kStatsValueNameRetransmitBitrate: + return "googRetransmitBitrate"; + case kStatsValueNameRtt: + return "googRtt"; + case kStatsValueNameSecondaryDecodedRate: + return "googSecondaryDecodedRate"; + case kStatsValueNameSecondaryDiscardedRate: + return "googSecondaryDiscardedRate"; + case kStatsValueNameSendPacketsDiscarded: + return "packetsDiscardedOnSend"; + case kStatsValueNameSpeechExpandRate: + return "googSpeechExpandRate"; + case kStatsValueNameSrtpCipher: + return "srtpCipher"; + case kStatsValueNameTargetEncBitrate: + return "googTargetEncBitrate"; + case kStatsValueNameTotalAudioEnergy: + return "totalAudioEnergy"; + case kStatsValueNameTotalSamplesDuration: + return "totalSamplesDuration"; + case kStatsValueNameTransmitBitrate: + return "googTransmitBitrate"; + case kStatsValueNameTransportType: + return "googTransportType"; + case kStatsValueNameTrackId: + return "googTrackId"; + case kStatsValueNameTimingFrameInfo: + return "googTimingFrameInfo"; + case kStatsValueNameTypingNoiseState: + return "googTypingNoiseState"; + case kStatsValueNameWritable: + return "googWritable"; + } + + return nullptr; +} + +std::string StatsReport::Value::ToString() const { + switch (type_) { + case kInt: + return rtc::ToString(value_.int_); + case kInt64: + return rtc::ToString(value_.int64_); + case kFloat: + return rtc::ToString(value_.float_); + case kStaticString: + return std::string(value_.static_string_); + case kString: + return *value_.string_; + case kBool: + return value_.bool_ ? "true" : "false"; + case kId: + return (*value_.id_)->ToString(); + } + RTC_NOTREACHED(); + return std::string(); +} + +StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { + RTC_DCHECK(id_.get()); +} + +StatsReport::~StatsReport() = default; + +// static +StatsReport::Id StatsReport::NewBandwidthEstimationId() { + return Id(new RefCountedObject<BandwidthEstimationId>()); +} + +// static +StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { + return Id(new RefCountedObject<TypedId>(type, id)); +} + +// static +StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) { + return Id(new RefCountedObject<TypedIntId>(type, id)); +} + +// static +StatsReport::Id StatsReport::NewIdWithDirection( + StatsType type, const std::string& id, StatsReport::Direction direction) { + return Id(new RefCountedObject<IdWithDirection>(type, id, direction)); +} + +// static +StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) { + return Id(new RefCountedObject<CandidateId>(local, id)); +} + +// static +StatsReport::Id StatsReport::NewComponentId( + const std::string& content_name, int component) { + return Id(new RefCountedObject<ComponentId>(content_name, component)); +} + +// static +StatsReport::Id StatsReport::NewCandidatePairId( + const std::string& content_name, int component, int index) { + return Id(new RefCountedObject<CandidatePairId>( + content_name, component, index)); +} + +const char* StatsReport::TypeToString() const { + return InternalTypeToString(id_->type()); +} + +void StatsReport::AddString(StatsReport::StatsValueName name, + const std::string& value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value)); +} + +void StatsReport::AddString(StatsReport::StatsValueName name, + const char* value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value)); +} + +void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value, Value::kInt64)); +} + +void StatsReport::AddInt(StatsReport::StatsValueName name, int value) { + const Value* found = FindValue(name); + if (!found || !(*found == static_cast<int64_t>(value))) + values_[name] = ValuePtr(new Value(name, value, Value::kInt)); +} + +void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value)); +} + +void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value)); +} + +void StatsReport::AddId(StatsReport::StatsValueName name, + const Id& value) { + const Value* found = FindValue(name); + if (!found || !(*found == value)) + values_[name] = ValuePtr(new Value(name, value)); +} + +const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { + Values::const_iterator it = values_.find(name); + return it == values_.end() ? nullptr : it->second.get(); +} + +StatsCollection::StatsCollection() { +} + +StatsCollection::~StatsCollection() { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + for (auto* r : list_) + delete r; +} + +StatsCollection::const_iterator StatsCollection::begin() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return list_.begin(); +} + +StatsCollection::const_iterator StatsCollection::end() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return list_.end(); +} + +size_t StatsCollection::size() const { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + return list_.size(); +} + +StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + RTC_DCHECK(Find(id) == nullptr); + StatsReport* report = new StatsReport(id); + list_.push_back(report); + return report; +} + +StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + StatsReport* ret = Find(id); + return ret ? ret : InsertNew(id); +} + +StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + RTC_DCHECK(id.get()); + Container::iterator it = std::find_if(list_.begin(), list_.end(), + [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); + if (it != end()) { + StatsReport* report = new StatsReport((*it)->id()); + delete *it; + *it = report; + return report; + } + return InsertNew(id); +} + +// Looks for a report with the given |id|. If one is not found, null +// will be returned. +StatsReport* StatsCollection::Find(const StatsReport::Id& id) { + RTC_DCHECK(thread_checker_.CalledOnValidThread()); + Container::iterator it = std::find_if(list_.begin(), list_.end(), + [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); + return it == list_.end() ? nullptr : *it; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/statstypes.h b/third_party/libwebrtc/webrtc/api/statstypes.h new file mode 100644 index 0000000000..80f0eb5ae6 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/statstypes.h @@ -0,0 +1,447 @@ +/* + * Copyright 2012 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. + */ + +// This file contains structures used for retrieving statistics from an ongoing +// libjingle session. + +#ifndef API_STATSTYPES_H_ +#define API_STATSTYPES_H_ + +#include <algorithm> +#include <list> +#include <map> +#include <string> +#include <vector> + +#include "rtc_base/basictypes.h" +#include "rtc_base/constructormagic.h" +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" +#include "rtc_base/stringencode.h" +#include "rtc_base/thread_checker.h" + +namespace webrtc { + +class StatsReport { + public: + // Indicates whether a track is for sending or receiving. + // Used in reports for audio/video tracks. + enum Direction { + kSend = 0, + kReceive, + }; + + enum StatsType { + // StatsReport types. + // A StatsReport of |type| = "googSession" contains overall information + // about the thing libjingle calls a session (which may contain one + // or more RTP sessions. + kStatsReportTypeSession, + + // A StatsReport of |type| = "googTransport" contains information + // about a libjingle "transport". + kStatsReportTypeTransport, + + // A StatsReport of |type| = "googComponent" contains information + // about a libjingle "channel" (typically, RTP or RTCP for a transport). + // This is intended to be the same thing as an ICE "Component". + kStatsReportTypeComponent, + + // A StatsReport of |type| = "googCandidatePair" contains information + // about a libjingle "connection" - a single source/destination port pair. + // This is intended to be the same thing as an ICE "candidate pair". + kStatsReportTypeCandidatePair, + + // A StatsReport of |type| = "VideoBWE" is statistics for video Bandwidth + // Estimation, which is global per-session. The |id| field is "bweforvideo" + // (will probably change in the future). + kStatsReportTypeBwe, + + // A StatsReport of |type| = "ssrc" is statistics for a specific rtp stream. + // The |id| field is the SSRC in decimal form of the rtp stream. + kStatsReportTypeSsrc, + + // A StatsReport of |type| = "remoteSsrc" is statistics for a specific + // rtp stream, generated by the remote end of the connection. + kStatsReportTypeRemoteSsrc, + + // A StatsReport of |type| = "googTrack" is statistics for a specific media + // track. The |id| field is the track id. + kStatsReportTypeTrack, + + // A StatsReport of |type| = "localcandidate" or "remotecandidate" is + // attributes on a specific ICE Candidate. It links to its connection pair + // by candidate id. The string value is taken from + // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. + kStatsReportTypeIceLocalCandidate, + kStatsReportTypeIceRemoteCandidate, + + // A StatsReport of |type| = "googCertificate" contains an SSL certificate + // transmitted by one of the endpoints of this connection. The |id| is + // controlled by the fingerprint, and is used to identify the certificate in + // the Channel stats (as "googLocalCertificateId" or + // "googRemoteCertificateId") and in any child certificates (as + // "googIssuerId"). + kStatsReportTypeCertificate, + + // A StatsReport of |type| = "datachannel" with statistics for a + // particular DataChannel. + kStatsReportTypeDataChannel, + }; + + enum StatsValueName { + kStatsValueNameActiveConnection, + kStatsValueNameAecDivergentFilterFraction, + kStatsValueNameAudioInputLevel, + kStatsValueNameAudioOutputLevel, + kStatsValueNameBytesReceived, + kStatsValueNameBytesSent, + kStatsValueNameCodecImplementationName, + kStatsValueNameConcealedSamples, + kStatsValueNameConcealmentEvents, + kStatsValueNameDataChannelId, + kStatsValueNameFramesDecoded, + kStatsValueNameFramesEncoded, + kStatsValueNameJitterBufferDelay, + kStatsValueNameMediaType, + kStatsValueNamePacketsLost, + kStatsValueNamePacketsReceived, + kStatsValueNamePacketsSent, + kStatsValueNameProtocol, + kStatsValueNameQpSum, + kStatsValueNameReceiving, + kStatsValueNameSelectedCandidatePairId, + kStatsValueNameSsrc, + kStatsValueNameState, + kStatsValueNameTotalAudioEnergy, + kStatsValueNameTotalSamplesDuration, + kStatsValueNameTotalSamplesReceived, + kStatsValueNameTransportId, + kStatsValueNameSentPingRequestsTotal, + kStatsValueNameSentPingRequestsBeforeFirstResponse, + kStatsValueNameSentPingResponses, + kStatsValueNameRecvPingRequests, + kStatsValueNameRecvPingResponses, + + // Internal StatsValue names. + kStatsValueNameAccelerateRate, + kStatsValueNameActualEncBitrate, + kStatsValueNameAdaptationChanges, + kStatsValueNameAvailableReceiveBandwidth, + kStatsValueNameAvailableSendBandwidth, + kStatsValueNameAvgEncodeMs, + kStatsValueNameBandwidthLimitedResolution, + kStatsValueNameBucketDelay, + kStatsValueNameCaptureStartNtpTimeMs, + kStatsValueNameCandidateIPAddress, + kStatsValueNameCandidateNetworkType, + kStatsValueNameCandidatePortNumber, + kStatsValueNameCandidatePriority, + kStatsValueNameCandidateTransportType, + kStatsValueNameCandidateType, + kStatsValueNameChannelId, + kStatsValueNameCodecName, + kStatsValueNameComponent, + kStatsValueNameContentName, + kStatsValueNameContentType, + kStatsValueNameCpuLimitedResolution, + kStatsValueNameCurrentDelayMs, + kStatsValueNameDecodeMs, + kStatsValueNameDecodingCNG, + kStatsValueNameDecodingCTN, + kStatsValueNameDecodingCTSG, + kStatsValueNameDecodingMutedOutput, + kStatsValueNameDecodingNormal, + kStatsValueNameDecodingPLC, + kStatsValueNameDecodingPLCCNG, + kStatsValueNameDer, + kStatsValueNameDtlsCipher, + kStatsValueNameEchoCancellationQualityMin, + kStatsValueNameEchoDelayMedian, + kStatsValueNameEchoDelayStdDev, + kStatsValueNameEchoReturnLoss, + kStatsValueNameEchoReturnLossEnhancement, + kStatsValueNameEncodeUsagePercent, + kStatsValueNameExpandRate, + kStatsValueNameFingerprint, + kStatsValueNameFingerprintAlgorithm, + kStatsValueNameFirsReceived, + kStatsValueNameFirsSent, + kStatsValueNameFrameHeightInput, + kStatsValueNameFrameHeightReceived, + kStatsValueNameFrameHeightSent, + kStatsValueNameFrameRateDecoded, + kStatsValueNameFrameRateInput, + kStatsValueNameFrameRateOutput, + kStatsValueNameFrameRateReceived, + kStatsValueNameFrameRateSent, + kStatsValueNameFrameWidthInput, + kStatsValueNameFrameWidthReceived, + kStatsValueNameFrameWidthSent, + kStatsValueNameHasEnteredLowResolution, + kStatsValueNameInitiator, + kStatsValueNameInterframeDelayMaxMs, // Max over last 10 seconds. + kStatsValueNameIssuerId, + kStatsValueNameJitterBufferMs, + kStatsValueNameJitterReceived, + kStatsValueNameLabel, + kStatsValueNameLocalAddress, + kStatsValueNameLocalCandidateId, + kStatsValueNameLocalCandidateType, + kStatsValueNameLocalCertificateId, + kStatsValueNameMaxDecodeMs, + kStatsValueNameMinPlayoutDelayMs, + kStatsValueNameNacksReceived, + kStatsValueNameNacksSent, + kStatsValueNamePlisReceived, + kStatsValueNamePlisSent, + kStatsValueNamePreemptiveExpandRate, + kStatsValueNamePreferredJitterBufferMs, + kStatsValueNameRemoteAddress, + kStatsValueNameRemoteCandidateId, + kStatsValueNameRemoteCandidateType, + kStatsValueNameRemoteCertificateId, + kStatsValueNameRenderDelayMs, + kStatsValueNameResidualEchoLikelihood, + kStatsValueNameResidualEchoLikelihoodRecentMax, + kStatsValueNameAnaBitrateActionCounter, + kStatsValueNameAnaChannelActionCounter, + kStatsValueNameAnaDtxActionCounter, + kStatsValueNameAnaFecActionCounter, + kStatsValueNameAnaFrameLengthIncreaseCounter, + kStatsValueNameAnaFrameLengthDecreaseCounter, + kStatsValueNameAnaUplinkPacketLossFraction, + kStatsValueNameRetransmitBitrate, + kStatsValueNameRtt, + kStatsValueNameSecondaryDecodedRate, + kStatsValueNameSecondaryDiscardedRate, + kStatsValueNameSendPacketsDiscarded, + kStatsValueNameSpeechExpandRate, + kStatsValueNameSrtpCipher, + kStatsValueNameTargetDelayMs, + kStatsValueNameTargetEncBitrate, + kStatsValueNameTimingFrameInfo, // Result of |TimingFrameInfo::ToString| + kStatsValueNameTrackId, + kStatsValueNameTransmitBitrate, + kStatsValueNameTransportType, + kStatsValueNameTypingNoiseState, + kStatsValueNameWritable, + }; + + class IdBase : public rtc::RefCountInterface { + public: + ~IdBase() override; + StatsType type() const; + + // Users of IdBase will be using the Id typedef, which is compatible with + // this Equals() function. It simply calls the protected (and overridden) + // Equals() method. + bool Equals(const rtc::scoped_refptr<IdBase>& other) const { + return Equals(*other.get()); + } + + virtual std::string ToString() const = 0; + + protected: + // Protected since users of the IdBase type will be using the Id typedef. + virtual bool Equals(const IdBase& other) const; + + explicit IdBase(StatsType type); // Only meant for derived classes. + const StatsType type_; + + static const char kSeparator = '_'; + }; + + typedef rtc::scoped_refptr<IdBase> Id; + + struct Value { + enum Type { + kInt, // int. + kInt64, // int64_t. + kFloat, // float. + kString, // std::string + kStaticString, // const char*. + kBool, // bool. + kId, // Id. + }; + + Value(StatsValueName name, int64_t value, Type int_type); + Value(StatsValueName name, float f); + Value(StatsValueName name, const std::string& value); + Value(StatsValueName name, const char* value); + Value(StatsValueName name, bool b); + Value(StatsValueName name, const Id& value); + + ~Value(); + + // Support ref counting. Note that for performance reasons, we + // don't use thread safe operations. Therefore, all operations + // affecting the ref count (in practice, creation and copying of + // the Values mapping) must occur on webrtc's signalling thread. + int AddRef() const { + RTC_DCHECK_RUN_ON(&thread_checker_); + return ++ref_count_; + } + int Release() const { + RTC_DCHECK_RUN_ON(&thread_checker_); + int count = --ref_count_; + if (!count) + delete this; + return count; + } + + // TODO(tommi): This compares name as well as value... + // I think we should only need to compare the value part and + // move the name part into a hash map. + bool Equals(const Value& other) const; + + // Comparison operators. Return true iff the current instance is of the + // correct type and holds the same value. No conversion is performed so + // a string value of "123" is not equal to an int value of 123 and an int + // value of 123 is not equal to a float value of 123.0f. + // One exception to this is that types kInt and kInt64 can be compared and + // kString and kStaticString too. + bool operator==(const std::string& value) const; + bool operator==(const char* value) const; + bool operator==(int64_t value) const; + bool operator==(bool value) const; + bool operator==(float value) const; + bool operator==(const Id& value) const; + + // Getters that allow getting the native value directly. + // The caller must know the type beforehand or else hit a check. + int int_val() const; + int64_t int64_val() const; + float float_val() const; + const char* static_string_val() const; + const std::string& string_val() const; + bool bool_val() const; + const Id& id_val() const; + + // Returns the string representation of |name|. + const char* display_name() const; + + // Converts the native value to a string representation of the value. + std::string ToString() const; + + Type type() const { return type_; } + + // TODO(tommi): Move |name| and |display_name| out of the Value struct. + const StatsValueName name; + + private: + rtc::ThreadChecker thread_checker_; + mutable int ref_count_ RTC_ACCESS_ON(thread_checker_) = 0; + + const Type type_; + // TODO(tommi): Use C++ 11 union and make value_ const. + union InternalType { + int int_; + int64_t int64_; + float float_; + bool bool_; + std::string* string_; + const char* static_string_; + Id* id_; + } value_; + + RTC_DISALLOW_COPY_AND_ASSIGN(Value); + }; + + typedef rtc::scoped_refptr<Value> ValuePtr; + typedef std::map<StatsValueName, ValuePtr> Values; + + // Ownership of |id| is passed to |this|. + explicit StatsReport(const Id& id); + ~StatsReport(); + + // Factory functions for various types of stats IDs. + static Id NewBandwidthEstimationId(); + static Id NewTypedId(StatsType type, const std::string& id); + static Id NewTypedIntId(StatsType type, int id); + static Id NewIdWithDirection( + StatsType type, const std::string& id, Direction direction); + static Id NewCandidateId(bool local, const std::string& id); + static Id NewComponentId( + const std::string& content_name, int component); + static Id NewCandidatePairId( + const std::string& content_name, int component, int index); + + const Id& id() const { return id_; } + StatsType type() const { return id_->type(); } + double timestamp() const { return timestamp_; } + void set_timestamp(double t) { timestamp_ = t; } + bool empty() const { return values_.empty(); } + const Values& values() const { return values_; } + + const char* TypeToString() const; + + void AddString(StatsValueName name, const std::string& value); + void AddString(StatsValueName name, const char* value); + void AddInt64(StatsValueName name, int64_t value); + void AddInt(StatsValueName name, int value); + void AddFloat(StatsValueName name, float value); + void AddBoolean(StatsValueName name, bool value); + void AddId(StatsValueName name, const Id& value); + + const Value* FindValue(StatsValueName name) const; + + private: + // The unique identifier for this object. + // This is used as a key for this report in ordered containers, + // so it must never be changed. + const Id id_; + double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds. + Values values_; + + RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport); +}; + +// Typedef for an array of const StatsReport pointers. +// Ownership of the pointers held by this implementation is assumed to lie +// elsewhere and lifetime guarantees are made by the implementation that uses +// this type. In the StatsCollector, object ownership lies with the +// StatsCollection class. +typedef std::vector<const StatsReport*> StatsReports; + +// A map from the report id to the report. +// This class wraps an STL container and provides a limited set of +// functionality in order to keep things simple. +class StatsCollection { + public: + StatsCollection(); + ~StatsCollection(); + + typedef std::list<StatsReport*> Container; + typedef Container::iterator iterator; + typedef Container::const_iterator const_iterator; + + const_iterator begin() const; + const_iterator end() const; + size_t size() const; + + // Creates a new report object with |id| that does not already + // exist in the list of reports. + StatsReport* InsertNew(const StatsReport::Id& id); + StatsReport* FindOrAddNew(const StatsReport::Id& id); + StatsReport* ReplaceOrAddNew(const StatsReport::Id& id); + + // Looks for a report with the given |id|. If one is not found, null + // will be returned. + StatsReport* Find(const StatsReport::Id& id); + + private: + Container list_; + rtc::ThreadChecker thread_checker_; +}; + +} // namespace webrtc + +#endif // API_STATSTYPES_H_ diff --git a/third_party/libwebrtc/webrtc/api/streamcollection.h b/third_party/libwebrtc/webrtc/api/streamcollection.h new file mode 100644 index 0000000000..d14e3d484d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/streamcollection.h @@ -0,0 +1,18 @@ +/* + * Copyright 2011 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 API_STREAMCOLLECTION_H_ +#define API_STREAMCOLLECTION_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/streamcollection.h" + +#endif // API_STREAMCOLLECTION_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/fakeconstraints.h b/third_party/libwebrtc/webrtc/api/test/fakeconstraints.h new file mode 100644 index 0000000000..2010400aa4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/fakeconstraints.h @@ -0,0 +1,116 @@ +/* + * Copyright 2012 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 API_TEST_FAKECONSTRAINTS_H_ +#define API_TEST_FAKECONSTRAINTS_H_ + +#include <string> +#include <vector> + +#include "api/mediaconstraintsinterface.h" +#include "rtc_base/stringencode.h" + +namespace webrtc { + +class FakeConstraints : public webrtc::MediaConstraintsInterface { + public: + FakeConstraints() { } + virtual ~FakeConstraints() { } + + virtual const Constraints& GetMandatory() const { + return mandatory_; + } + + virtual const Constraints& GetOptional() const { + return optional_; + } + + template <class T> + void AddMandatory(const std::string& key, const T& value) { + mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); + } + + template <class T> + void SetMandatory(const std::string& key, const T& value) { + std::string value_str; + if (mandatory_.FindFirst(key, &value_str)) { + for (Constraints::iterator iter = mandatory_.begin(); + iter != mandatory_.end(); ++iter) { + if (iter->key == key) { + mandatory_.erase(iter); + break; + } + } + } + mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); + } + + template <class T> + void AddOptional(const std::string& key, const T& value) { + optional_.push_back(Constraint(key, rtc::ToString<T>(value))); + } + + void SetMandatoryMinAspectRatio(double ratio) { + SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio); + } + + void SetMandatoryMinWidth(int width) { + SetMandatory(MediaConstraintsInterface::kMinWidth, width); + } + + void SetMandatoryMinHeight(int height) { + SetMandatory(MediaConstraintsInterface::kMinHeight, height); + } + + void SetOptionalMaxWidth(int width) { + AddOptional(MediaConstraintsInterface::kMaxWidth, width); + } + + void SetMandatoryMaxFrameRate(int frame_rate) { + SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate); + } + + void SetMandatoryReceiveAudio(bool enable) { + SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable); + } + + void SetMandatoryReceiveVideo(bool enable) { + SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable); + } + + void SetMandatoryUseRtpMux(bool enable) { + SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable); + } + + void SetMandatoryIceRestart(bool enable) { + SetMandatory(MediaConstraintsInterface::kIceRestart, enable); + } + + void SetAllowRtpDataChannels() { + SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true); + SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false); + } + + void SetOptionalVAD(bool enable) { + AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable); + } + + void SetAllowDtlsSctpDataChannels() { + SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); + } + + private: + Constraints mandatory_; + Constraints optional_; +}; + +} // namespace webrtc + +#endif // API_TEST_FAKECONSTRAINTS_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/mock_audio_mixer.h b/third_party/libwebrtc/webrtc/api/test/mock_audio_mixer.h new file mode 100644 index 0000000000..7a6c7420e8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/mock_audio_mixer.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2016 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 API_TEST_MOCK_AUDIO_MIXER_H_ +#define API_TEST_MOCK_AUDIO_MIXER_H_ + +#include "api/audio/audio_mixer.h" + +#include "test/gmock.h" + +namespace webrtc { +namespace test { + +class MockAudioMixer : public AudioMixer { + public: + MOCK_METHOD1(AddSource, bool(Source* audio_source)); + MOCK_METHOD1(RemoveSource, void(Source* audio_source)); + MOCK_METHOD2(Mix, + void(size_t number_of_channels, + AudioFrame* audio_frame_for_mixing)); +}; +} // namespace test +} // namespace webrtc + +#endif // API_TEST_MOCK_AUDIO_MIXER_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/mock_rtpreceiver.h b/third_party/libwebrtc/webrtc/api/test/mock_rtpreceiver.h new file mode 100644 index 0000000000..7097adc02d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/mock_rtpreceiver.h @@ -0,0 +1,36 @@ +/* + * Copyright 2016 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 API_TEST_MOCK_RTPRECEIVER_H_ +#define API_TEST_MOCK_RTPRECEIVER_H_ + +#include <string> +#include <vector> + +#include "api/rtpreceiverinterface.h" +#include "test/gmock.h" + +namespace webrtc { + +class MockRtpReceiver : public rtc::RefCountedObject<RtpReceiverInterface> { + public: + MOCK_METHOD1(SetTrack, void(MediaStreamTrackInterface*)); + MOCK_CONST_METHOD0(track, rtc::scoped_refptr<MediaStreamTrackInterface>()); + MOCK_CONST_METHOD0(media_type, cricket::MediaType()); + MOCK_CONST_METHOD0(id, std::string()); + MOCK_CONST_METHOD0(GetParameters, RtpParameters()); + MOCK_METHOD1(SetParameters, bool(const RtpParameters&)); + MOCK_METHOD1(SetObserver, void(RtpReceiverObserverInterface*)); + MOCK_CONST_METHOD0(GetSources, std::vector<RtpSource>()); +}; + +} // namespace webrtc + +#endif // API_TEST_MOCK_RTPRECEIVER_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/mock_rtpsender.h b/third_party/libwebrtc/webrtc/api/test/mock_rtpsender.h new file mode 100644 index 0000000000..a89fa9264a --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/mock_rtpsender.h @@ -0,0 +1,37 @@ +/* + * Copyright 2016 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 API_TEST_MOCK_RTPSENDER_H_ +#define API_TEST_MOCK_RTPSENDER_H_ + +#include <string> +#include <vector> + +#include "api/rtpsenderinterface.h" +#include "test/gmock.h" + +namespace webrtc { + +class MockRtpSender : public rtc::RefCountedObject<RtpSenderInterface> { + public: + MOCK_METHOD1(SetTrack, bool(MediaStreamTrackInterface*)); + MOCK_CONST_METHOD0(track, rtc::scoped_refptr<MediaStreamTrackInterface>()); + MOCK_CONST_METHOD0(ssrc, uint32_t()); + MOCK_CONST_METHOD0(media_type, cricket::MediaType()); + MOCK_CONST_METHOD0(id, std::string()); + MOCK_CONST_METHOD0(stream_ids, std::vector<std::string>()); + MOCK_CONST_METHOD0(GetParameters, RtpParameters()); + MOCK_METHOD1(SetParameters, bool(const RtpParameters&)); + MOCK_CONST_METHOD0(GetDtmfSender, rtc::scoped_refptr<DtmfSenderInterface>()); +}; + +} // namespace webrtc + +#endif // API_TEST_MOCK_RTPSENDER_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/mock_video_decoder_factory.h b/third_party/libwebrtc/webrtc/api/test/mock_video_decoder_factory.h new file mode 100644 index 0000000000..915e3911f0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/mock_video_decoder_factory.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 API_TEST_MOCK_VIDEO_DECODER_FACTORY_H_ +#define API_TEST_MOCK_VIDEO_DECODER_FACTORY_H_ + +#include <memory> +#include <vector> + +#include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_decoder_factory.h" +#include "test/gmock.h" + +namespace webrtc { + +class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory { + public: + MOCK_CONST_METHOD0(GetSupportedFormats, + std::vector<webrtc::SdpVideoFormat>()); + + // We need to proxy to a return type that is copyable. + std::unique_ptr<webrtc::VideoDecoder> CreateVideoDecoder( + const webrtc::SdpVideoFormat& format) { + return std::unique_ptr<webrtc::VideoDecoder>( + CreateVideoDecoderProxy(format)); + } + MOCK_METHOD1(CreateVideoDecoderProxy, + webrtc::VideoDecoder*(const webrtc::SdpVideoFormat&)); + + MOCK_METHOD0(Die, void()); + ~MockVideoDecoderFactory() { Die(); } +}; +} // namespace webrtc + +#endif // API_TEST_MOCK_VIDEO_DECODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/test/mock_video_encoder_factory.h b/third_party/libwebrtc/webrtc/api/test/mock_video_encoder_factory.h new file mode 100644 index 0000000000..a694b636e0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/test/mock_video_encoder_factory.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 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 API_TEST_MOCK_VIDEO_ENCODER_FACTORY_H_ +#define API_TEST_MOCK_VIDEO_ENCODER_FACTORY_H_ + +#include <memory> +#include <vector> + +#include "api/video_codecs/sdp_video_format.h" +#include "api/video_codecs/video_encoder_factory.h" +#include "test/gmock.h" + +namespace webrtc { + +class MockVideoEncoderFactory : public webrtc::VideoEncoderFactory { + public: + MOCK_CONST_METHOD0(GetSupportedFormats, + std::vector<webrtc::SdpVideoFormat>()); + MOCK_CONST_METHOD1(QueryVideoEncoder, + CodecInfo(const webrtc::SdpVideoFormat&)); + + // We need to proxy to a return type that is copyable. + std::unique_ptr<webrtc::VideoEncoder> CreateVideoEncoder( + const webrtc::SdpVideoFormat& format) { + return std::unique_ptr<webrtc::VideoEncoder>( + CreateVideoEncoderProxy(format)); + } + MOCK_METHOD1(CreateVideoEncoderProxy, + webrtc::VideoEncoder*(const webrtc::SdpVideoFormat&)); + + MOCK_METHOD0(Die, void()); + ~MockVideoEncoderFactory() { Die(); } +}; + +} // namespace webrtc + +#endif // API_TEST_MOCK_VIDEO_ENCODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/transport_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/transport_api_gn/moz.build new file mode 100644 index 0000000000..493d3c6914 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/transport_api_gn/moz.build @@ -0,0 +1,171 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/third_party/libwebrtc/webrtc/" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +Library("transport_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/turncustomizer.h b/third_party/libwebrtc/webrtc/api/turncustomizer.h new file mode 100644 index 0000000000..517abcc8f0 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/turncustomizer.h @@ -0,0 +1,46 @@ +/* + * 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 API_TURNCUSTOMIZER_H_ +#define API_TURNCUSTOMIZER_H_ + +#include <stdlib.h> + +namespace cricket { +class PortInterface; +class StunMessage; +} // namespace cricket + + +namespace webrtc { + +class TurnCustomizer { + public: + // This is called before a TURN message is sent. + // This could be used to add implementation specific attributes to a request. + virtual void MaybeModifyOutgoingStunMessage( + cricket::PortInterface* port, + cricket::StunMessage* message) = 0; + + // TURN can send data using channel data messages or Send indication. + // This method should return false if |data| should be sent using + // a Send indication instead of a ChannelData message, even if a + // channel is bound. + virtual bool AllowChannelData(cricket::PortInterface* port, + const void* data, + size_t size, + bool payload) = 0; + + virtual ~TurnCustomizer() {} +}; + +} // namespace webrtc + +#endif // API_TURNCUSTOMIZER_H_ diff --git a/third_party/libwebrtc/webrtc/api/umametrics.cc b/third_party/libwebrtc/webrtc/api/umametrics.cc new file mode 100644 index 0000000000..d5f2bb62b2 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/umametrics.cc @@ -0,0 +1,21 @@ +/* + * 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 "api/umametrics.h" + +namespace webrtc { + +void MetricsObserverInterface::IncrementSparseEnumCounter( + PeerConnectionEnumCounterType type, + int counter) { + IncrementEnumCounter(type, counter, 0 /* Ignored */); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/umametrics.h b/third_party/libwebrtc/webrtc/api/umametrics.h new file mode 100644 index 0000000000..c512598523 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/umametrics.h @@ -0,0 +1,137 @@ +/* + * Copyright 2014 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. + */ + +// This file contains enums related to IPv4/IPv6 metrics. + +#ifndef API_UMAMETRICS_H_ +#define API_UMAMETRICS_H_ + +#include "rtc_base/refcount.h" + +namespace webrtc { + +// Used to specify which enum counter type we're incrementing in +// MetricsObserverInterface::IncrementEnumCounter. +enum PeerConnectionEnumCounterType { + kEnumCounterAddressFamily, + // For the next 2 counters, we track them separately based on the "first hop" + // protocol used by the local candidate. "First hop" means the local candidate + // type in the case of non-TURN candidates, and the protocol used to connect + // to the TURN server in the case of TURN candidates. + kEnumCounterIceCandidatePairTypeUdp, + kEnumCounterIceCandidatePairTypeTcp, + + kEnumCounterAudioSrtpCipher, + kEnumCounterAudioSslCipher, + kEnumCounterVideoSrtpCipher, + kEnumCounterVideoSslCipher, + kEnumCounterDataSrtpCipher, + kEnumCounterDataSslCipher, + kEnumCounterDtlsHandshakeError, + kEnumCounterIceRegathering, + kEnumCounterIceRestart, + kPeerConnectionEnumCounterMax +}; + +// Currently this contains information related to WebRTC network/transport +// information. + +// The difference between PeerConnectionEnumCounter and +// PeerConnectionMetricsName is that the "EnumCounter" is only counting the +// occurrences of events, while "Name" has a value associated with it which is +// used to form a histogram. + +// This enum is backed by Chromium's histograms.xml, +// chromium/src/tools/metrics/histograms/histograms.xml +// Existing values cannot be re-ordered and new enums must be added +// before kBoundary. +enum PeerConnectionAddressFamilyCounter { + kPeerConnection_IPv4, + kPeerConnection_IPv6, + kBestConnections_IPv4, + kBestConnections_IPv6, + kPeerConnectionAddressFamilyCounter_Max, +}; + +// TODO(guoweis): Keep previous name here until all references are renamed. +#define kBoundary kPeerConnectionAddressFamilyCounter_Max + +// TODO(guoweis): Keep previous name here until all references are renamed. +typedef PeerConnectionAddressFamilyCounter PeerConnectionUMAMetricsCounter; + +// This enum defines types for UMA samples, which will have a range. +enum PeerConnectionMetricsName { + kNetworkInterfaces_IPv4, // Number of IPv4 interfaces. + kNetworkInterfaces_IPv6, // Number of IPv6 interfaces. + kTimeToConnect, // In milliseconds. + kLocalCandidates_IPv4, // Number of IPv4 local candidates. + kLocalCandidates_IPv6, // Number of IPv6 local candidates. + kPeerConnectionMetricsName_Max +}; + +// TODO(guoweis): Keep previous name here until all references are renamed. +typedef PeerConnectionMetricsName PeerConnectionUMAMetricsName; + +// The IceCandidatePairType has the format of +// <local_candidate_type>_<remote_candidate_type>. It is recorded based on the +// type of candidate pair used when the PeerConnection first goes to a completed +// state. When BUNDLE is enabled, only the first transport gets recorded. +enum IceCandidatePairType { + // HostHost is deprecated. It was replaced with the set of types at the bottom + // to report private or public host IP address. + kIceCandidatePairHostHost, + kIceCandidatePairHostSrflx, + kIceCandidatePairHostRelay, + kIceCandidatePairHostPrflx, + kIceCandidatePairSrflxHost, + kIceCandidatePairSrflxSrflx, + kIceCandidatePairSrflxRelay, + kIceCandidatePairSrflxPrflx, + kIceCandidatePairRelayHost, + kIceCandidatePairRelaySrflx, + kIceCandidatePairRelayRelay, + kIceCandidatePairRelayPrflx, + kIceCandidatePairPrflxHost, + kIceCandidatePairPrflxSrflx, + kIceCandidatePairPrflxRelay, + + // The following 4 types tell whether local and remote hosts have private or + // public IP addresses. + kIceCandidatePairHostPrivateHostPrivate, + kIceCandidatePairHostPrivateHostPublic, + kIceCandidatePairHostPublicHostPrivate, + kIceCandidatePairHostPublicHostPublic, + kIceCandidatePairMax +}; + +class MetricsObserverInterface : public rtc::RefCountInterface { + public: + // |type| is the type of the enum counter to be incremented. |counter| + // is the particular counter in that type. |counter_max| is the next sequence + // number after the highest counter. + virtual void IncrementEnumCounter(PeerConnectionEnumCounterType type, + int counter, + int counter_max) {} + + // This is used to handle sparse counters like SSL cipher suites. + // TODO(guoweis): Remove the implementation once the dependency's interface + // definition is updated. + virtual void IncrementSparseEnumCounter(PeerConnectionEnumCounterType type, + int counter); + + virtual void AddHistogramSample(PeerConnectionMetricsName type, + int value) = 0; +}; + +typedef MetricsObserverInterface UMAObserver; + +} // namespace webrtc + +#endif // API_UMAMETRICS_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/OWNERS b/third_party/libwebrtc/webrtc/api/video/OWNERS new file mode 100644 index 0000000000..8327124e23 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/OWNERS @@ -0,0 +1,3 @@ +magjed@webrtc.org + +per-file video_timing.h=ilnik@webrtc.org diff --git a/third_party/libwebrtc/webrtc/api/video/i420_buffer.cc b/third_party/libwebrtc/webrtc/api/video/i420_buffer.cc new file mode 100644 index 0000000000..20af2c2289 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/i420_buffer.cc @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2015 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 "api/video/i420_buffer.h" + +#include <string.h> + +#include <algorithm> +#include <utility> + +#include "libyuv/convert.h" +#include "libyuv/planar_functions.h" +#include "libyuv/scale.h" +#include "rtc_base/checks.h" +#include "rtc_base/keep_ref_until_done.h" + +// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. +static const int kBufferAlignment = 64; + +namespace webrtc { + +namespace { + +int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { + return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); +} + +} // namespace + +I420Buffer::I420Buffer(int width, int height) + : I420Buffer(width, height, width, (width + 1) / 2, (width + 1) / 2) { +} + +I420Buffer::I420Buffer(int width, + int height, + int stride_y, + int stride_u, + int stride_v) + : width_(width), + height_(height), + stride_y_(stride_y), + stride_u_(stride_u), + stride_v_(stride_v), + data_(static_cast<uint8_t*>(AlignedMalloc( + I420DataSize(height, stride_y, stride_u, stride_v), + kBufferAlignment))) { + RTC_DCHECK_GT(width, 0); + RTC_DCHECK_GT(height, 0); + RTC_DCHECK_GE(stride_y, width); + RTC_DCHECK_GE(stride_u, (width + 1) / 2); + RTC_DCHECK_GE(stride_v, (width + 1) / 2); +} + +I420Buffer::~I420Buffer() { +} + +// static +rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, int height) { + return new rtc::RefCountedObject<I420Buffer>(width, height); +} + +// static +rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, + int height, + int stride_y, + int stride_u, + int stride_v) { + return new rtc::RefCountedObject<I420Buffer>( + width, height, stride_y, stride_u, stride_v); +} + +// static +rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( + const I420BufferInterface& source) { + return Copy(source.width(), source.height(), + source.DataY(), source.StrideY(), + source.DataU(), source.StrideU(), + source.DataV(), source.StrideV()); +} + +// static +rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( + int width, int height, + const uint8_t* data_y, int stride_y, + const uint8_t* data_u, int stride_u, + const uint8_t* data_v, int stride_v) { + // Note: May use different strides than the input data. + rtc::scoped_refptr<I420Buffer> buffer = Create(width, height); + RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, + data_u, stride_u, + data_v, stride_v, + buffer->MutableDataY(), buffer->StrideY(), + buffer->MutableDataU(), buffer->StrideU(), + buffer->MutableDataV(), buffer->StrideV(), + width, height)); + return buffer; +} + +// static +rtc::scoped_refptr<I420Buffer> I420Buffer::Rotate( + const I420BufferInterface& src, + VideoRotation rotation) { + RTC_CHECK(src.DataY()); + RTC_CHECK(src.DataU()); + RTC_CHECK(src.DataV()); + + int rotated_width = src.width(); + int rotated_height = src.height(); + if (rotation == webrtc::kVideoRotation_90 || + rotation == webrtc::kVideoRotation_270) { + std::swap(rotated_width, rotated_height); + } + + rtc::scoped_refptr<webrtc::I420Buffer> buffer = + I420Buffer::Create(rotated_width, rotated_height); + + RTC_CHECK_EQ(0, libyuv::I420Rotate( + src.DataY(), src.StrideY(), + src.DataU(), src.StrideU(), + src.DataV(), src.StrideV(), + buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), + buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), + src.width(), src.height(), + static_cast<libyuv::RotationMode>(rotation))); + + return buffer; +} + +void I420Buffer::InitializeData() { + memset(data_.get(), 0, + I420DataSize(height_, stride_y_, stride_u_, stride_v_)); +} + +int I420Buffer::width() const { + return width_; +} + +int I420Buffer::height() const { + return height_; +} + +const uint8_t* I420Buffer::DataY() const { + return data_.get(); +} +const uint8_t* I420Buffer::DataU() const { + return data_.get() + stride_y_ * height_; +} +const uint8_t* I420Buffer::DataV() const { + return data_.get() + stride_y_ * height_ + stride_u_ * ((height_ + 1) / 2); +} + +int I420Buffer::StrideY() const { + return stride_y_; +} +int I420Buffer::StrideU() const { + return stride_u_; +} +int I420Buffer::StrideV() const { + return stride_v_; +} + +uint8_t* I420Buffer::MutableDataY() { + return const_cast<uint8_t*>(DataY()); +} +uint8_t* I420Buffer::MutableDataU() { + return const_cast<uint8_t*>(DataU()); +} +uint8_t* I420Buffer::MutableDataV() { + return const_cast<uint8_t*>(DataV()); +} + +// static +void I420Buffer::SetBlack(I420Buffer* buffer) { + RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), + buffer->MutableDataU(), buffer->StrideU(), + buffer->MutableDataV(), buffer->StrideV(), + 0, 0, buffer->width(), buffer->height(), + 0, 128, 128) == 0); +} + +void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src, + int offset_x, + int offset_y, + int crop_width, + int crop_height) { + RTC_CHECK_LE(crop_width, src.width()); + RTC_CHECK_LE(crop_height, src.height()); + RTC_CHECK_LE(crop_width + offset_x, src.width()); + RTC_CHECK_LE(crop_height + offset_y, src.height()); + RTC_CHECK_GE(offset_x, 0); + RTC_CHECK_GE(offset_y, 0); + + // Make sure offset is even so that u/v plane becomes aligned. + const int uv_offset_x = offset_x / 2; + const int uv_offset_y = offset_y / 2; + offset_x = uv_offset_x * 2; + offset_y = uv_offset_y * 2; + + const uint8_t* y_plane = + src.DataY() + src.StrideY() * offset_y + offset_x; + const uint8_t* u_plane = + src.DataU() + src.StrideU() * uv_offset_y + uv_offset_x; + const uint8_t* v_plane = + src.DataV() + src.StrideV() * uv_offset_y + uv_offset_x; + int res = libyuv::I420Scale(y_plane, src.StrideY(), + u_plane, src.StrideU(), + v_plane, src.StrideV(), + crop_width, crop_height, + MutableDataY(), StrideY(), + MutableDataU(), StrideU(), + MutableDataV(), StrideV(), + width(), height(), libyuv::kFilterBox); + + RTC_DCHECK_EQ(res, 0); +} + +void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src) { + const int crop_width = height() ? + std::min(src.width(), width() * src.height() / height()) : src.width(); + const int crop_height = width() ? + std::min(src.height(), height() * src.width() / width()) : src.height(); + + CropAndScaleFrom( + src, + (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, + crop_width, crop_height); +} + +void I420Buffer::ScaleFrom(const I420BufferInterface& src) { + CropAndScaleFrom(src, 0, 0, src.width(), src.height()); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video/i420_buffer.h b/third_party/libwebrtc/webrtc/api/video/i420_buffer.h new file mode 100644 index 0000000000..bdac80bbc1 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/i420_buffer.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2015 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 API_VIDEO_I420_BUFFER_H_ +#define API_VIDEO_I420_BUFFER_H_ + +#include <memory> + +#include "api/video/video_rotation.h" +#include "api/video/video_frame_buffer.h" +#include "system_wrappers/include/aligned_malloc.h" + +namespace webrtc { + +// Plain I420 buffer in standard memory. +class I420Buffer : public I420BufferInterface { + public: + static rtc::scoped_refptr<I420Buffer> Create(int width, int height); + static rtc::scoped_refptr<I420Buffer> Create(int width, + int height, + int stride_y, + int stride_u, + int stride_v); + + // Create a new buffer and copy the pixel data. + static rtc::scoped_refptr<I420Buffer> Copy(const I420BufferInterface& buffer); + // Deprecated. + static rtc::scoped_refptr<I420Buffer> Copy(const VideoFrameBuffer& buffer) { + return Copy(*buffer.GetI420()); + } + + static rtc::scoped_refptr<I420Buffer> Copy( + int width, int height, + const uint8_t* data_y, int stride_y, + const uint8_t* data_u, int stride_u, + const uint8_t* data_v, int stride_v); + + // Returns a rotated copy of |src|. + static rtc::scoped_refptr<I420Buffer> Rotate(const I420BufferInterface& src, + VideoRotation rotation); + // Deprecated. + static rtc::scoped_refptr<I420Buffer> Rotate(const VideoFrameBuffer& src, + VideoRotation rotation) { + return Rotate(*src.GetI420(), rotation); + } + + // Sets the buffer to all black. + static void SetBlack(I420Buffer* buffer); + + // Sets all three planes to all zeros. Used to work around for + // quirks in memory checkers + // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and + // ffmpeg (http://crbug.com/390941). + // TODO(nisse): Deprecated. Should be deleted if/when those issues + // are resolved in a better way. Or in the mean time, use SetBlack. + void InitializeData(); + + int width() const override; + int height() const override; + const uint8_t* DataY() const override; + const uint8_t* DataU() const override; + const uint8_t* DataV() const override; + + int StrideY() const override; + int StrideU() const override; + int StrideV() const override; + + uint8_t* MutableDataY(); + uint8_t* MutableDataU(); + uint8_t* MutableDataV(); + + // Scale the cropped area of |src| to the size of |this| buffer, and + // write the result into |this|. + void CropAndScaleFrom(const I420BufferInterface& src, + int offset_x, + int offset_y, + int crop_width, + int crop_height); + + // The common case of a center crop, when needed to adjust the + // aspect ratio without distorting the image. + void CropAndScaleFrom(const I420BufferInterface& src); + + // Scale all of |src| to the size of |this| buffer, with no cropping. + void ScaleFrom(const I420BufferInterface& src); + + protected: + I420Buffer(int width, int height); + I420Buffer(int width, int height, int stride_y, int stride_u, int stride_v); + + ~I420Buffer() override; + + private: + const int width_; + const int height_; + const int stride_y_; + const int stride_u_; + const int stride_v_; + const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; +}; + +} // namespace webrtc + +#endif // API_VIDEO_I420_BUFFER_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/video_content_type.cc b/third_party/libwebrtc/webrtc/api/video/video_content_type.cc new file mode 100644 index 0000000000..149b4f9926 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_content_type.cc @@ -0,0 +1,96 @@ +/* + * Copyright (c) 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 "api/video/video_content_type.h" + +// VideoContentType stored as a single byte, which is sent over the network. +// Structure: +// +// 0 1 2 3 4 5 6 7 +// +---------------+ +// |r r e e e s s c| +// +// where: +// r - reserved bits. +// e - 3-bit number of an experiment group counted from 1. 0 means there's no +// experiment ongoing. +// s - 2-bit simulcast stream id or spatial layer, counted from 1. 0 means that +// no simulcast information is set. +// c - content type. 0 means real-time video, 1 means screenshare. +// + +namespace webrtc { +namespace videocontenttypehelpers { + +namespace { +static constexpr uint8_t kScreenshareBitsSize = 1; +static constexpr uint8_t kScreenshareBitsMask = + (1u << kScreenshareBitsSize) - 1; + +static constexpr uint8_t kSimulcastShift = 1; +static constexpr uint8_t kSimulcastBitsSize = 2; +static constexpr uint8_t kSimulcastBitsMask = ((1u << kSimulcastBitsSize) - 1) + << kSimulcastShift; // 0b00000110 + +static constexpr uint8_t kExperimentShift = 3; +static constexpr uint8_t kExperimentBitsSize = 3; +static constexpr uint8_t kExperimentBitsMask = + ((1u << kExperimentBitsSize) - 1) << kExperimentShift; // 0b00111000 + +static constexpr uint8_t kTotalBitsSize = + kScreenshareBitsSize + kSimulcastBitsSize + kExperimentBitsSize; +} // namespace + +bool SetExperimentId(VideoContentType* content_type, uint8_t experiment_id) { + // Store in bits 2-4. + if (experiment_id >= (1 << kExperimentBitsSize)) + return false; + *content_type = static_cast<VideoContentType>( + (static_cast<uint8_t>(*content_type) & ~kExperimentBitsMask) | + ((experiment_id << kExperimentShift) & kExperimentBitsMask)); + return true; +} + +bool SetSimulcastId(VideoContentType* content_type, uint8_t simulcast_id) { + // Store in bits 5-6. + if (simulcast_id >= (1 << kSimulcastBitsSize)) + return false; + *content_type = static_cast<VideoContentType>( + (static_cast<uint8_t>(*content_type) & ~kSimulcastBitsMask) | + ((simulcast_id << kSimulcastShift) & kSimulcastBitsMask)); + return true; +} + +uint8_t GetExperimentId( + const VideoContentType& content_type) { + return (static_cast<uint8_t>(content_type) & kExperimentBitsMask) >> + kExperimentShift; +} +uint8_t GetSimulcastId( + const VideoContentType& content_type) { + return (static_cast<uint8_t>(content_type) & kSimulcastBitsMask) >> + kSimulcastShift; +} + +bool IsScreenshare( + const VideoContentType& content_type) { + return (static_cast<uint8_t>(content_type) & kScreenshareBitsMask) > 0; +} + +bool IsValidContentType(uint8_t value) { + // Any 6-bit value is allowed. + return value < (1 << kTotalBitsSize); +} + +const char* ToString(const VideoContentType& content_type) { + return IsScreenshare(content_type) ? "screen" : "realtime"; +} +} // namespace videocontenttypehelpers +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video/video_content_type.h b/third_party/libwebrtc/webrtc/api/video/video_content_type.h new file mode 100644 index 0000000000..8c6460288d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_content_type.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 API_VIDEO_VIDEO_CONTENT_TYPE_H_ +#define API_VIDEO_VIDEO_CONTENT_TYPE_H_ + +#include <stdint.h> + +#include <string> + +namespace webrtc { + +enum class VideoContentType : uint8_t { + UNSPECIFIED = 0, + SCREENSHARE = 1, +}; + +namespace videocontenttypehelpers { +bool SetExperimentId(VideoContentType* content_type, uint8_t experiment_id); +bool SetSimulcastId(VideoContentType* content_type, uint8_t simulcast_id); + +uint8_t GetExperimentId(const VideoContentType& content_type); +uint8_t GetSimulcastId(const VideoContentType& content_type); + +bool IsScreenshare(const VideoContentType& content_type); + +bool IsValidContentType(uint8_t value); + +const char* ToString(const VideoContentType& content_type); +} // namespace videocontenttypehelpers + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_CONTENT_TYPE_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/video_frame.cc b/third_party/libwebrtc/webrtc/api/video/video_frame.cc new file mode 100644 index 0000000000..93b3c9c6b9 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_frame.cc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 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 "api/video/video_frame.h" + +#include "rtc_base/checks.h" +#include "rtc_base/timeutils.h" + +namespace webrtc { + +VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, + webrtc::VideoRotation rotation, + int64_t timestamp_us) + : video_frame_buffer_(buffer), + timestamp_rtp_(0), + ntp_time_ms_(0), + timestamp_us_(timestamp_us), + rotation_(rotation) {} + +VideoFrame::VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, + uint32_t timestamp, + int64_t render_time_ms, + VideoRotation rotation) + : video_frame_buffer_(buffer), + timestamp_rtp_(timestamp), + ntp_time_ms_(0), + timestamp_us_(render_time_ms * rtc::kNumMicrosecsPerMillisec), + rotation_(rotation) { + RTC_DCHECK(buffer); +} + +VideoFrame::~VideoFrame() = default; + +VideoFrame::VideoFrame(const VideoFrame&) = default; +VideoFrame::VideoFrame(VideoFrame&&) = default; +VideoFrame& VideoFrame::operator=(const VideoFrame&) = default; +VideoFrame& VideoFrame::operator=(VideoFrame&&) = default; + +int VideoFrame::width() const { + return video_frame_buffer_ ? video_frame_buffer_->width() : 0; +} + +int VideoFrame::height() const { + return video_frame_buffer_ ? video_frame_buffer_->height() : 0; +} + +uint32_t VideoFrame::size() const { + return width() * height(); +} + +rtc::scoped_refptr<VideoFrameBuffer> VideoFrame::video_frame_buffer() const { + return video_frame_buffer_; +} + +int64_t VideoFrame::render_time_ms() const { + return timestamp_us() / rtc::kNumMicrosecsPerMillisec; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video/video_frame.h b/third_party/libwebrtc/webrtc/api/video/video_frame.h new file mode 100644 index 0000000000..a72bef1d32 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_frame.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2014 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 API_VIDEO_VIDEO_FRAME_H_ +#define API_VIDEO_VIDEO_FRAME_H_ + +#include <stdint.h> + +#include "api/video/video_rotation.h" +#include "api/video/video_frame_buffer.h" + +namespace webrtc { + +class VideoFrame { + public: + // TODO(nisse): This constructor is consistent with the now deleted + // cricket::WebRtcVideoFrame. We should consider whether or not we + // want to stick to this style and deprecate the other constructor. + VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, + webrtc::VideoRotation rotation, + int64_t timestamp_us); + + // Preferred constructor. + VideoFrame(const rtc::scoped_refptr<VideoFrameBuffer>& buffer, + uint32_t timestamp, + int64_t render_time_ms, + VideoRotation rotation); + + ~VideoFrame(); + + // Support move and copy. + VideoFrame(const VideoFrame&); + VideoFrame(VideoFrame&&); + VideoFrame& operator=(const VideoFrame&); + VideoFrame& operator=(VideoFrame&&); + + // Get frame width. + int width() const; + // Get frame height. + int height() const; + // Get frame size in pixels. + uint32_t size() const; + + // System monotonic clock, same timebase as rtc::TimeMicros(). + int64_t timestamp_us() const { return timestamp_us_; } + void set_timestamp_us(int64_t timestamp_us) { timestamp_us_ = timestamp_us; } + + // TODO(nisse): After the cricket::VideoFrame and webrtc::VideoFrame + // merge, timestamps other than timestamp_us will likely be + // deprecated. + + // Set frame timestamp (90kHz). + void set_timestamp(uint32_t timestamp) { timestamp_rtp_ = timestamp; } + + // Get frame timestamp (90kHz). + uint32_t timestamp() const { return timestamp_rtp_; } + + // For now, transport_frame_id and rtp timestamp are the same. + // TODO(nisse): Must be handled differently for QUIC. + uint32_t transport_frame_id() const { return timestamp(); } + + // Set capture ntp time in milliseconds. + // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). + void set_ntp_time_ms(int64_t ntp_time_ms) { ntp_time_ms_ = ntp_time_ms; } + + // Get capture ntp time in milliseconds. + // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). + int64_t ntp_time_ms() const { return ntp_time_ms_; } + + // Naming convention for Coordination of Video Orientation. Please see + // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf + // + // "pending rotation" or "pending" = a frame that has a VideoRotation > 0. + // + // "not pending" = a frame that has a VideoRotation == 0. + // + // "apply rotation" = modify a frame from being "pending" to being "not + // pending" rotation (a no-op for "unrotated"). + // + VideoRotation rotation() const { return rotation_; } + void set_rotation(VideoRotation rotation) { rotation_ = rotation; } + + // Get render time in milliseconds. + // TODO(nisse): Deprecated. Migrate all users to timestamp_us(). + int64_t render_time_ms() const; + + // Return the underlying buffer. Never nullptr for a properly + // initialized VideoFrame. + rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer() const; + + // TODO(nisse): Deprecated. + // Return true if the frame is stored in a texture. + bool is_texture() const { + return video_frame_buffer()->type() == VideoFrameBuffer::Type::kNative; + } + + private: + // An opaque reference counted handle that stores the pixel data. + rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; + uint32_t timestamp_rtp_; + int64_t ntp_time_ms_; + int64_t timestamp_us_; + VideoRotation rotation_; +}; + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_FRAME_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.cc b/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.cc new file mode 100644 index 0000000000..867f249fe6 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.cc @@ -0,0 +1,80 @@ +/* + * Copyright (c) 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 "api/video/video_frame_buffer.h" + +#include "rtc_base/checks.h" + +namespace webrtc { + +rtc::scoped_refptr<I420BufferInterface> VideoFrameBuffer::GetI420() { + RTC_CHECK(type() == Type::kI420); + return static_cast<I420BufferInterface*>(this); +} + +rtc::scoped_refptr<const I420BufferInterface> VideoFrameBuffer::GetI420() + const { + RTC_CHECK(type() == Type::kI420); + return static_cast<const I420BufferInterface*>(this); +} + +I420ABufferInterface* VideoFrameBuffer::GetI420A() { + RTC_CHECK(type() == Type::kI420A); + return static_cast<I420ABufferInterface*>(this); +} + +const I420ABufferInterface* VideoFrameBuffer::GetI420A() const { + RTC_CHECK(type() == Type::kI420A); + return static_cast<const I420ABufferInterface*>(this); +} + +I444BufferInterface* VideoFrameBuffer::GetI444() { + RTC_CHECK(type() == Type::kI444); + return static_cast<I444BufferInterface*>(this); +} + +const I444BufferInterface* VideoFrameBuffer::GetI444() const { + RTC_CHECK(type() == Type::kI444); + return static_cast<const I444BufferInterface*>(this); +} + +VideoFrameBuffer::Type I420BufferInterface::type() const { + return Type::kI420; +} + +int I420BufferInterface::ChromaWidth() const { + return (width() + 1) / 2; +} + +int I420BufferInterface::ChromaHeight() const { + return (height() + 1) / 2; +} + +rtc::scoped_refptr<I420BufferInterface> I420BufferInterface::ToI420() { + return this; +} + +VideoFrameBuffer::Type I420ABufferInterface::type() const { + return Type::kI420A; +} + +VideoFrameBuffer::Type I444BufferInterface::type() const { + return Type::kI444; +} + +int I444BufferInterface::ChromaWidth() const { + return width(); +} + +int I444BufferInterface::ChromaHeight() const { + return height(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.h b/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.h new file mode 100644 index 0000000000..2be7e0bb9f --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.h @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2015 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 API_VIDEO_VIDEO_FRAME_BUFFER_H_ +#define API_VIDEO_VIDEO_FRAME_BUFFER_H_ + +#include <stdint.h> + +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +class I420BufferInterface; +class I420ABufferInterface; +class I444BufferInterface; + +// Base class for frame buffers of different types of pixel format and storage. +// The tag in type() indicates how the data is represented, and each type is +// implemented as a subclass. To access the pixel data, call the appropriate +// GetXXX() function, where XXX represents the type. There is also a function +// ToI420() that returns a frame buffer in I420 format, converting from the +// underlying representation if necessary. I420 is the most widely accepted +// format and serves as a fallback for video sinks that can only handle I420, +// e.g. the internal WebRTC software encoders. A special enum value 'kNative' is +// provided for external clients to implement their own frame buffer +// representations, e.g. as textures. The external client can produce such +// native frame buffers from custom video sources, and then cast it back to the +// correct subclass in custom video sinks. The purpose of this is to improve +// performance by providing an optimized path without intermediate conversions. +// Frame metadata such as rotation and timestamp are stored in +// webrtc::VideoFrame, and not here. +class VideoFrameBuffer : public rtc::RefCountInterface { + public: + // New frame buffer types will be added conservatively when there is an + // opportunity to optimize the path between some pair of video source and + // video sink. + enum class Type { + kNative, + kI420, + kI420A, + kI444, + }; + + // This function specifies in what pixel format the data is stored in. + virtual Type type() const = 0; + + // The resolution of the frame in pixels. For formats where some planes are + // subsampled, this is the highest-resolution plane. + virtual int width() const = 0; + virtual int height() const = 0; + + // Returns a memory-backed frame buffer in I420 format. If the pixel data is + // in another format, a conversion will take place. All implementations must + // provide a fallback to I420 for compatibility with e.g. the internal WebRTC + // software encoders. + virtual rtc::scoped_refptr<I420BufferInterface> ToI420() = 0; + + // These functions should only be called if type() is of the correct type. + // Calling with a different type will result in a crash. + // TODO(magjed): Return raw pointers for GetI420 once deprecated interface is + // removed. + rtc::scoped_refptr<I420BufferInterface> GetI420(); + rtc::scoped_refptr<const I420BufferInterface> GetI420() const; + I420ABufferInterface* GetI420A(); + const I420ABufferInterface* GetI420A() const; + I444BufferInterface* GetI444(); + const I444BufferInterface* GetI444() const; + + protected: + ~VideoFrameBuffer() override {} +}; + +// This interface represents Type::kI420 and Type::kI444. +class PlanarYuvBuffer : public VideoFrameBuffer { + public: + virtual int ChromaWidth() const = 0; + virtual int ChromaHeight() const = 0; + + // Returns pointer to the pixel data for a given plane. The memory is owned by + // the VideoFrameBuffer object and must not be freed by the caller. + virtual const uint8_t* DataY() const = 0; + virtual const uint8_t* DataU() const = 0; + virtual const uint8_t* DataV() const = 0; + + // Returns the number of bytes between successive rows for a given plane. + virtual int StrideY() const = 0; + virtual int StrideU() const = 0; + virtual int StrideV() const = 0; + + protected: + ~PlanarYuvBuffer() override {} +}; + +class I420BufferInterface : public PlanarYuvBuffer { + public: + Type type() const override; + + int ChromaWidth() const final; + int ChromaHeight() const final; + + rtc::scoped_refptr<I420BufferInterface> ToI420() final; + + protected: + ~I420BufferInterface() override {} +}; + +class I420ABufferInterface : public I420BufferInterface { + public: + Type type() const final; + virtual const uint8_t* DataA() const = 0; + virtual int StrideA() const = 0; + + protected: + ~I420ABufferInterface() override {} +}; + +class I444BufferInterface : public PlanarYuvBuffer { + public: + Type type() const final; + + int ChromaWidth() const final; + int ChromaHeight() const final; + + protected: + ~I444BufferInterface() override {} +}; + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_FRAME_BUFFER_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/video_rotation.h b/third_party/libwebrtc/webrtc/api/video/video_rotation.h new file mode 100644 index 0000000000..6a29588ee5 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_rotation.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 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 API_VIDEO_VIDEO_ROTATION_H_ +#define API_VIDEO_VIDEO_ROTATION_H_ + +namespace webrtc { + +// enum for clockwise rotation. +enum VideoRotation { + kVideoRotation_0 = 0, + kVideoRotation_90 = 90, + kVideoRotation_180 = 180, + kVideoRotation_270 = 270 +}; + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_ROTATION_H_ diff --git a/third_party/libwebrtc/webrtc/api/video/video_timing.cc b/third_party/libwebrtc/webrtc/api/video/video_timing.cc new file mode 100644 index 0000000000..3ccbe4eae5 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_timing.cc @@ -0,0 +1,78 @@ +/* + * Copyright (c) 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 "api/video/video_timing.h" + +#include <sstream> + +namespace webrtc { + +TimingFrameInfo::TimingFrameInfo() + : rtp_timestamp(0), + capture_time_ms(-1), + encode_start_ms(-1), + encode_finish_ms(-1), + packetization_finish_ms(-1), + pacer_exit_ms(-1), + network_timestamp_ms(-1), + network2_timestamp_ms(-1), + receive_start_ms(-1), + receive_finish_ms(-1), + decode_start_ms(-1), + decode_finish_ms(-1), + render_time_ms(-1), + flags(TimingFrameFlags::kDefault) {} + +int64_t TimingFrameInfo::EndToEndDelay() const { + return capture_time_ms >= 0 ? decode_finish_ms - capture_time_ms : -1; +} + +bool TimingFrameInfo::IsLongerThan(const TimingFrameInfo& other) const { + int64_t other_delay = other.EndToEndDelay(); + return other_delay == -1 || EndToEndDelay() > other_delay; +} + +bool TimingFrameInfo::operator<(const TimingFrameInfo& other) const { + return other.IsLongerThan(*this); +} + +bool TimingFrameInfo::operator<=(const TimingFrameInfo& other) const { + return !IsLongerThan(other); +} + +bool TimingFrameInfo::IsOutlier() const { + return !IsInvalid() && (flags & TimingFrameFlags::kTriggeredBySize); +} + +bool TimingFrameInfo::IsTimerTriggered() const { + return !IsInvalid() && (flags & TimingFrameFlags::kTriggeredByTimer); +} + +bool TimingFrameInfo::IsInvalid() const { + return flags == TimingFrameFlags::kInvalid; +} + +std::string TimingFrameInfo::ToString() const { + std::stringstream out; + if (IsInvalid()) { + out << ""; + } else { + out << rtp_timestamp << ',' << capture_time_ms << ',' << encode_start_ms + << ',' << encode_finish_ms << ',' << packetization_finish_ms << ',' + << pacer_exit_ms << ',' << network_timestamp_ms << ',' + << network2_timestamp_ms << ',' << receive_start_ms << ',' + << receive_finish_ms << ',' << decode_start_ms << ',' + << decode_finish_ms << ',' << render_time_ms << ',' + << IsOutlier() << ',' << IsTimerTriggered(); + } + return out.str(); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video/video_timing.h b/third_party/libwebrtc/webrtc/api/video/video_timing.h new file mode 100644 index 0000000000..ab8cd99136 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video/video_timing.h @@ -0,0 +1,124 @@ +/* + * Copyright (c) 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 API_VIDEO_VIDEO_TIMING_H_ +#define API_VIDEO_VIDEO_TIMING_H_ + +#include <stdint.h> + +#include <limits> +#include <string> + +#include "rtc_base/checks.h" +#include "rtc_base/numerics/safe_conversions.h" + +namespace webrtc { + +enum TimingFrameFlags : uint8_t { + kNotTriggered = 0, // Timing info valid, but not to be transmitted. + // Used on send-side only. + // TODO(ilnik): Delete compatibility alias. + // Used to be sent over the wire, for the old protocol. + kDefault = 0, // Old name, for API compatibility. + kTriggeredByTimer = 1 << 0, // Frame marked for tracing by periodic timer. + kTriggeredBySize = 1 << 1, // Frame marked for tracing due to size. + kInvalid = std::numeric_limits<uint8_t>::max() // Invalid, ignore! +}; + +// Video timing timestamps in ms counted from capture_time_ms of a frame. +// This structure represents data sent in video-timing RTP header extension. +struct VideoSendTiming { + // Offsets of the fields in the RTP header extension, counting from the first + // byte after the one-byte header. + static constexpr uint8_t kFlagsOffset = 0; + static constexpr uint8_t kEncodeStartDeltaOffset = 1; + static constexpr uint8_t kEncodeFinishDeltaOffset = 3; + static constexpr uint8_t kPacketizationFinishDeltaOffset = 5; + static constexpr uint8_t kPacerExitDeltaOffset = 7; + static constexpr uint8_t kNetworkTimestampDeltaOffset = 9; + static constexpr uint8_t kNetwork2TimestampDeltaOffset = 11; + + // Returns |time_ms - base_ms| capped at max 16-bit value. + // Used to fill this data structure as per + // https://webrtc.org/experiments/rtp-hdrext/video-timing/ extension stores + // 16-bit deltas of timestamps from packet capture time. + static uint16_t GetDeltaCappedMs(int64_t base_ms, int64_t time_ms) { + RTC_DCHECK_GE(time_ms, base_ms); + return rtc::saturated_cast<uint16_t>(time_ms - base_ms); + } + + uint16_t encode_start_delta_ms; + uint16_t encode_finish_delta_ms; + uint16_t packetization_finish_delta_ms; + uint16_t pacer_exit_delta_ms; + uint16_t network_timestamp_delta_ms; + uint16_t network2_timestamp_delta_ms; + uint8_t flags; +}; + +// Used to report precise timings of a 'timing frames'. Contains all important +// timestamps for a lifetime of that specific frame. Reported as a string via +// GetStats(). Only frame which took the longest between two GetStats calls is +// reported. +struct TimingFrameInfo { + TimingFrameInfo(); + + // Returns end-to-end delay of a frame, if sender and receiver timestamps are + // synchronized, -1 otherwise. + int64_t EndToEndDelay() const; + + // Returns true if current frame took longer to process than |other| frame. + // If other frame's clocks are not synchronized, current frame is always + // preferred. + bool IsLongerThan(const TimingFrameInfo& other) const; + + // Returns true if flags are set to indicate this frame was marked for tracing + // due to the size being outside some limit. + bool IsOutlier() const; + + // Returns true if flags are set to indicate this frame was marked fro tracing + // due to cyclic timer. + bool IsTimerTriggered() const; + + // Returns true if the timing data is marked as invalid, in which case it + // should be ignored. + bool IsInvalid() const; + + std::string ToString() const; + + bool operator<(const TimingFrameInfo& other) const; + + bool operator<=(const TimingFrameInfo& other) const; + + uint32_t rtp_timestamp; // Identifier of a frame. + // All timestamps below are in local monotonous clock of a receiver. + // If sender clock is not yet estimated, sender timestamps + // (capture_time_ms ... pacer_exit_ms) are negative values, still + // relatively correct. + int64_t capture_time_ms; // Captrue time of a frame. + int64_t encode_start_ms; // Encode start time. + int64_t encode_finish_ms; // Encode completion time. + int64_t packetization_finish_ms; // Time when frame was passed to pacer. + int64_t pacer_exit_ms; // Time when last packet was pushed out of pacer. + // Two in-network RTP processor timestamps: meaning is application specific. + int64_t network_timestamp_ms; + int64_t network2_timestamp_ms; + int64_t receive_start_ms; // First received packet time. + int64_t receive_finish_ms; // Last received packet time. + int64_t decode_start_ms; // Decode start time. + int64_t decode_finish_ms; // Decode completion time. + int64_t render_time_ms; // Proposed render time to insure smooth playback. + + uint8_t flags; // Flags indicating validity and/or why tracing was triggered. +}; + +} // namespace webrtc + +#endif // API_VIDEO_VIDEO_TIMING_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/BUILD.gn b/third_party/libwebrtc/webrtc/api/video_codecs/BUILD.gn new file mode 100644 index 0000000000..4a050ab5cc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (c) 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. + +import("../../webrtc.gni") +if (is_android) { + import("//build/config/android/config.gni") + import("//build/config/android/rules.gni") +} + +rtc_source_set("video_codecs_api") { + sources = [ + "sdp_video_format.h", + "video_decoder.h", + "video_decoder_factory.h", + "video_encoder.cc", + "video_encoder.h", + "video_encoder_factory.h", + ] + + deps = [ + "..:optional", + "..:video_frame_api", + "../..:webrtc_common", + "../../common_video", + "../../rtc_base:rtc_base_approved", + ] +} diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/sdp_video_format.h b/third_party/libwebrtc/webrtc/api/video_codecs/sdp_video_format.h new file mode 100644 index 0000000000..542353aea7 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/sdp_video_format.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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 API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_ +#define API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_ + +#include <map> +#include <string> + +namespace webrtc { + +// SDP specification for a single video codec. +// NOTE: This class is still under development and may change without notice. +struct SdpVideoFormat { + using Parameters = std::map<std::string, std::string>; + + explicit SdpVideoFormat(const std::string& name) : name(name) {} + SdpVideoFormat(const std::string& name, const Parameters& parameters) + : name(name), parameters(parameters) {} + + friend bool operator==(const SdpVideoFormat& a, const SdpVideoFormat& b) { + return a.name == b.name && a.parameters == b.parameters; + } + + friend bool operator!=(const SdpVideoFormat& a, const SdpVideoFormat& b) { + return !(a == b); + } + + std::string name; + Parameters parameters; +}; + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_SDP_VIDEO_FORMAT_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_codecs_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/video_codecs/video_codecs_api_gn/moz.build new file mode 100644 index 0000000000..cc3b155592 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_codecs_api_gn/moz.build @@ -0,0 +1,227 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libyuv/libyuv/include/", + "/third_party/libwebrtc/webrtc/", + "/third_party/libwebrtc/webrtc/common_video/include/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("video_codecs_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder.h b/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder.h new file mode 100644 index 0000000000..5897901346 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2014 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 API_VIDEO_CODECS_VIDEO_DECODER_H_ +#define API_VIDEO_CODECS_VIDEO_DECODER_H_ + +#include <memory> +#include <string> +#include <vector> + +#include "api/video/video_frame.h" +#include "common_types.h" // NOLINT(build/include) +#include "common_video/include/video_frame.h" +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +class RTPFragmentationHeader; +// TODO(pbos): Expose these through a public (root) header or change these APIs. +struct CodecSpecificInfo; +class VideoCodec; + +class DecodedImageCallback { + public: + virtual ~DecodedImageCallback() {} + + virtual int32_t Decoded(VideoFrame& decodedImage) = 0; + // Provides an alternative interface that allows the decoder to specify the + // decode time excluding waiting time for any previous pending frame to + // return. This is necessary for breaking positive feedback in the delay + // estimation when the decoder has a single output buffer. + virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) { + // The default implementation ignores custom decode time value. + return Decoded(decodedImage); + } + // TODO(sakal): Remove other implementations when upstream projects have been + // updated. + virtual void Decoded(VideoFrame& decodedImage, + rtc::Optional<int32_t> decode_time_ms, + rtc::Optional<uint8_t> qp) { + Decoded(decodedImage, + decode_time_ms ? static_cast<int32_t>(*decode_time_ms) : -1); + } + + virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) { + return -1; + } + + virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; } +}; + +class VideoDecoder { + public: + virtual ~VideoDecoder() {} + + virtual int32_t InitDecode(const VideoCodec* codec_settings, + int32_t number_of_cores) = 0; + + virtual int32_t Decode(const EncodedImage& input_image, + bool missing_frames, + const RTPFragmentationHeader* fragmentation, + const CodecSpecificInfo* codec_specific_info = NULL, + int64_t render_time_ms = -1) = 0; + + virtual int32_t RegisterDecodeCompleteCallback( + DecodedImageCallback* callback) = 0; + + virtual int32_t Release() = 0; + + // Returns true if the decoder prefer to decode frames late. + // That is, it can not decode infinite number of frames before the decoded + // frame is consumed. + virtual bool PrefersLateDecoding() const { return true; } + + virtual const char* ImplementationName() const { return "unknown"; } +}; + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder_factory.h b/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder_factory.h new file mode 100644 index 0000000000..9c58ad468d --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_decoder_factory.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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 API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_ +#define API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_ + +#include <memory> +#include <vector> + +namespace webrtc { + +class VideoDecoder; +struct SdpVideoFormat; + +// A factory that creates VideoDecoders. +// NOTE: This class is still under development and may change without notice. +class VideoDecoderFactory { + public: + // Returns a list of supported video formats in order of preference, to use + // for signaling etc. + virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0; + + // Creates a VideoDecoder for the specified format. + virtual std::unique_ptr<VideoDecoder> CreateVideoDecoder( + const SdpVideoFormat& format) = 0; + + virtual ~VideoDecoderFactory() {} +}; + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.cc b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.cc new file mode 100644 index 0000000000..e1cc0cfac7 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.cc @@ -0,0 +1,108 @@ +/* + * Copyright (c) 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 "api/video_codecs/video_encoder.h" + +namespace webrtc { + +// TODO(mflodman): Add default complexity for VP9 and VP9. +VideoCodecVP8 VideoEncoder::GetDefaultVp8Settings() { + VideoCodecVP8 vp8_settings; + memset(&vp8_settings, 0, sizeof(vp8_settings)); + + vp8_settings.resilience = kResilientStream; + vp8_settings.numberOfTemporalLayers = 1; + vp8_settings.denoisingOn = true; + vp8_settings.errorConcealmentOn = false; + vp8_settings.automaticResizeOn = false; + vp8_settings.frameDroppingOn = true; + vp8_settings.keyFrameInterval = 3000; + + return vp8_settings; +} + +VideoCodecVP9 VideoEncoder::GetDefaultVp9Settings() { + VideoCodecVP9 vp9_settings; + memset(&vp9_settings, 0, sizeof(vp9_settings)); + + vp9_settings.resilienceOn = true; + vp9_settings.numberOfTemporalLayers = 1; + vp9_settings.denoisingOn = true; + vp9_settings.frameDroppingOn = true; + vp9_settings.keyFrameInterval = 3000; + vp9_settings.adaptiveQpMode = true; + vp9_settings.automaticResizeOn = true; + vp9_settings.numberOfSpatialLayers = 1; + vp9_settings.flexibleMode = false; + + return vp9_settings; +} + +VideoCodecH264 VideoEncoder::GetDefaultH264Settings() { + VideoCodecH264 h264_settings; + memset(&h264_settings, 0, sizeof(h264_settings)); + + h264_settings.frameDroppingOn = true; + h264_settings.keyFrameInterval = 3000; + h264_settings.spsData = nullptr; + h264_settings.spsLen = 0; + h264_settings.ppsData = nullptr; + h264_settings.ppsLen = 0; + h264_settings.profile = H264::kProfileConstrainedBaseline; + + return h264_settings; +} + +VideoEncoder::ScalingSettings::ScalingSettings(bool on, int low, int high) + : enabled(on), thresholds(QpThresholds(low, high)) {} + +VideoEncoder::ScalingSettings::ScalingSettings(bool on, + int low, + int high, + int min_pixels) + : enabled(on), + thresholds(QpThresholds(low, high)), + min_pixels_per_frame(min_pixels) {} + +VideoEncoder::ScalingSettings::ScalingSettings(bool on, int min_pixels) + : enabled(on), min_pixels_per_frame(min_pixels) {} + +VideoEncoder::ScalingSettings::ScalingSettings(bool on) : enabled(on) {} + +VideoEncoder::ScalingSettings::~ScalingSettings() {} + + +int32_t VideoEncoder::SetRates(uint32_t bitrate, uint32_t framerate) { + RTC_NOTREACHED() << "SetRate(uint32_t, uint32_t) is deprecated."; + return -1; +} + +int32_t VideoEncoder::SetRateAllocation( + const BitrateAllocation& allocation, + uint32_t framerate) { + return SetRates(allocation.get_sum_kbps(), framerate); +} + +VideoEncoder::ScalingSettings VideoEncoder::GetScalingSettings() const { + return ScalingSettings(false); +} + +int32_t VideoEncoder::SetPeriodicKeyFrames(bool enable) { + return -1; +} + +bool VideoEncoder::SupportsNativeHandle() const { + return false; +} + +const char* VideoEncoder::ImplementationName() const { + return "unknown"; +} +} // namespace webrtc diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.h b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.h new file mode 100644 index 0000000000..eb401afded --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2014 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 API_VIDEO_CODECS_VIDEO_ENCODER_H_ +#define API_VIDEO_CODECS_VIDEO_ENCODER_H_ + +#include <memory> +#include <string> +#include <vector> + +#include "api/optional.h" +#include "api/video/video_frame.h" +#include "common_types.h" // NOLINT(build/include) +#include "common_video/include/video_frame.h" +#include "rtc_base/checks.h" +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +class RTPFragmentationHeader; +// TODO(pbos): Expose these through a public (root) header or change these APIs. +struct CodecSpecificInfo; +class VideoCodec; + +class EncodedImageCallback { + public: + virtual ~EncodedImageCallback() {} + + struct Result { + enum Error { + OK, + + // Failed to send the packet. + ERROR_SEND_FAILED, + }; + + explicit Result(Error error) : error(error) {} + Result(Error error, uint32_t frame_id) : error(error), frame_id(frame_id) {} + + Error error; + + // Frame ID assigned to the frame. The frame ID should be the same as the ID + // seen by the receiver for this frame. RTP timestamp of the frame is used + // as frame ID when RTP is used to send video. Must be used only when + // error=OK. + uint32_t frame_id = 0; + + // Tells the encoder that the next frame is should be dropped. + bool drop_next_frame = false; + }; + + // Used to signal the encoder about reason a frame is dropped. + // kDroppedByMediaOptimizations - dropped by MediaOptimizations (for rate + // limiting purposes). + // kDroppedByEncoder - dropped by encoder's internal rate limiter. + enum class DropReason : uint8_t { + kDroppedByMediaOptimizations, + kDroppedByEncoder + }; + + // Callback function which is called when an image has been encoded. + virtual Result OnEncodedImage( + const EncodedImage& encoded_image, + const CodecSpecificInfo* codec_specific_info, + const RTPFragmentationHeader* fragmentation) = 0; + + // Deprecated. TODO(ilnik): Remove this in few weeks. + virtual void OnDroppedFrame() {} + + virtual void OnDroppedFrame(DropReason reason) {} +}; + +class VideoEncoder { + public: + struct QpThresholds { + QpThresholds(int l, int h) : low(l), high(h) {} + QpThresholds() : low(-1), high(-1) {} + int low; + int high; + }; + struct ScalingSettings { + ScalingSettings(bool on, int low, int high); + ScalingSettings(bool on, int low, int high, int min_pixels); + ScalingSettings(bool on, int min_pixels); + explicit ScalingSettings(bool on); + ScalingSettings(const ScalingSettings&); + ~ScalingSettings(); + + const bool enabled; + const rtc::Optional<QpThresholds> thresholds; + + // We will never ask for a resolution lower than this. + // TODO(kthelgason): Lower this limit when better testing + // on MediaCodec and fallback implementations are in place. + // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206 + const int min_pixels_per_frame = 320 * 180; + }; + + static VideoCodecVP8 GetDefaultVp8Settings(); + static VideoCodecVP9 GetDefaultVp9Settings(); + static VideoCodecH264 GetDefaultH264Settings(); + + virtual ~VideoEncoder() {} + + // Initialize the encoder with the information from the codecSettings + // + // Input: + // - codec_settings : Codec settings + // - number_of_cores : Number of cores available for the encoder + // - max_payload_size : The maximum size each payload is allowed + // to have. Usually MTU - overhead. + // + // Return value : Set bit rate if OK + // <0 - Errors: + // WEBRTC_VIDEO_CODEC_ERR_PARAMETER + // WEBRTC_VIDEO_CODEC_ERR_SIZE + // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED + // WEBRTC_VIDEO_CODEC_MEMORY + // WEBRTC_VIDEO_CODEC_ERROR + virtual int32_t InitEncode(const VideoCodec* codec_settings, + int32_t number_of_cores, + size_t max_payload_size) = 0; + + // Register an encode complete callback object. + // + // Input: + // - callback : Callback object which handles encoded images. + // + // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. + virtual int32_t RegisterEncodeCompleteCallback( + EncodedImageCallback* callback) = 0; + + // Free encoder memory. + // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. + virtual int32_t Release() = 0; + + // Encode an I420 image (as a part of a video stream). The encoded image + // will be returned to the user through the encode complete callback. + // + // Input: + // - frame : Image to be encoded + // - frame_types : Frame type to be generated by the encoder. + // + // Return value : WEBRTC_VIDEO_CODEC_OK if OK + // <0 - Errors: + // WEBRTC_VIDEO_CODEC_ERR_PARAMETER + // WEBRTC_VIDEO_CODEC_MEMORY + // WEBRTC_VIDEO_CODEC_ERROR + // WEBRTC_VIDEO_CODEC_TIMEOUT + virtual int32_t Encode(const VideoFrame& frame, + const CodecSpecificInfo* codec_specific_info, + const std::vector<FrameType>* frame_types) = 0; + + // Inform the encoder of the new packet loss rate and the round-trip time of + // the network. + // + // Input: + // - packet_loss : Fraction lost + // (loss rate in percent = 100 * packetLoss / 255) + // - rtt : Round-trip time in milliseconds + // Return value : WEBRTC_VIDEO_CODEC_OK if OK + // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR + virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0; + + // Inform the encoder about the new target bit rate. + // + // Input: + // - bitrate : New target bit rate + // - framerate : The target frame rate + // + // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. + virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate); + + // Default fallback: Just use the sum of bitrates as the single target rate. + // TODO(sprang): Remove this default implementation when we remove SetRates(). + virtual int32_t SetRateAllocation(const BitrateAllocation& allocation, + uint32_t framerate); + + // Any encoder implementation wishing to use the WebRTC provided + // quality scaler must implement this method. + virtual ScalingSettings GetScalingSettings() const; + + virtual int32_t SetPeriodicKeyFrames(bool enable); + virtual bool SupportsNativeHandle() const; + virtual const char* ImplementationName() const; +}; +} // namespace webrtc +#endif // API_VIDEO_CODECS_VIDEO_ENCODER_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder_factory.h b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder_factory.h new file mode 100644 index 0000000000..7958d16acc --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_codecs/video_encoder_factory.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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 API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ +#define API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ + +#include <memory> +#include <vector> + +namespace webrtc { + +class VideoEncoder; +struct SdpVideoFormat; + +// A factory that creates VideoEncoders. +// NOTE: This class is still under development and may change without notice. +class VideoEncoderFactory { + public: + // TODO(magjed): Try to get rid of this struct. + struct CodecInfo { + // |is_hardware_accelerated| is true if the encoders created by this factory + // of the given codec will use hardware support. + bool is_hardware_accelerated; + // |has_internal_source| is true if encoders created by this factory of the + // given codec will use internal camera sources, meaning that they don't + // require/expect frames to be delivered via webrtc::VideoEncoder::Encode. + // This flag is used as the internal_source parameter to + // webrtc::ViEExternalCodec::RegisterExternalSendCodec. + bool has_internal_source; + }; + + // Returns a list of supported video formats in order of preference, to use + // for signaling etc. + virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0; + + // Returns information about how this format will be encoded. The specified + // format must be one of the supported formats by this factory. + // TODO(magjed): Try to get rid of this method. + virtual CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const = 0; + + // Creates a VideoEncoder for the specified format. + virtual std::unique_ptr<VideoEncoder> CreateVideoEncoder( + const SdpVideoFormat& format) = 0; + + virtual ~VideoEncoderFactory() {} +}; + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_ diff --git a/third_party/libwebrtc/webrtc/api/video_frame_api_gn/moz.build b/third_party/libwebrtc/webrtc/api/video_frame_api_gn/moz.build new file mode 100644 index 0000000000..c9193f9033 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_frame_api_gn/moz.build @@ -0,0 +1,221 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libyuv/libyuv/include/", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/video/video_content_type.cc", + "/third_party/libwebrtc/webrtc/api/video/video_frame.cc", + "/third_party/libwebrtc/webrtc/api/video/video_frame_buffer.cc", + "/third_party/libwebrtc/webrtc/api/video/video_timing.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("video_frame_api_gn") diff --git a/third_party/libwebrtc/webrtc/api/video_frame_api_i420_gn/moz.build b/third_party/libwebrtc/webrtc/api/video_frame_api_i420_gn/moz.build new file mode 100644 index 0000000000..18c0d956cd --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/video_frame_api_i420_gn/moz.build @@ -0,0 +1,226 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + + ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ### + ### DO NOT edit it by hand. ### + +COMPILE_FLAGS["OS_INCLUDES"] = [] +AllowCompilerWarnings() + +DEFINES["CHROMIUM_BUILD"] = True +DEFINES["V8_DEPRECATION_WARNINGS"] = True +DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0" +DEFINES["WEBRTC_MOZILLA_BUILD"] = True +DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0" +DEFINES["WEBRTC_RESTRICT_LOGGING"] = True + +FINAL_LIBRARY = "webrtc" + + +LOCAL_INCLUDES += [ + "!/ipc/ipdl/_ipdlheaders", + "/ipc/chromium/src", + "/ipc/glue", + "/media/libyuv/libyuv/include/", + "/third_party/libwebrtc/webrtc/" +] + +UNIFIED_SOURCES += [ + "/third_party/libwebrtc/webrtc/api/video/i420_buffer.cc" +] + +if not CONFIG["MOZ_DEBUG"]: + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0" + DEFINES["NDEBUG"] = True + DEFINES["NVALGRIND"] = True + +if CONFIG["MOZ_DEBUG"] == "1": + + DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1" + DEFINES["WTF_USE_DYNAMIC_ANNOTATIONS"] = "1" + +if CONFIG["OS_TARGET"] == "Android": + + DEFINES["ANDROID"] = True + DEFINES["ANDROID_NDK_VERSION"] = "r12b" + DEFINES["DISABLE_NACL"] = True + DEFINES["HAVE_SYS_UIO_H"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["USE_OPENSSL_CERTS"] = "1" + DEFINES["WEBRTC_ANDROID"] = True + DEFINES["WEBRTC_ANDROID_OPENSLES"] = True + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + DEFINES["__GNU_SOURCE"] = "1" + + OS_LIBS += [ + "log" + ] + +if CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["NO_TCMALLOC"] = True + DEFINES["WEBRTC_MAC"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE"] = "0" + + OS_LIBS += [ + "-framework Foundation" + ] + +if CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "Linux": + + DEFINES["USE_NSS_CERTS"] = "1" + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_LINUX"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + + OS_LIBS += [ + "rt" + ] + +if CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["USE_X11"] = "1" + DEFINES["WEBRTC_BSD"] = True + DEFINES["WEBRTC_POSIX"] = True + DEFINES["_FILE_OFFSET_BITS"] = "64" + +if CONFIG["OS_TARGET"] == "WINNT": + + DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True + DEFINES["NOMINMAX"] = True + DEFINES["NO_TCMALLOC"] = True + DEFINES["NTDDI_VERSION"] = "0x0A000000" + DEFINES["PSAPI_VERSION"] = "1" + DEFINES["UNICODE"] = True + DEFINES["WEBRTC_WIN"] = True + DEFINES["WIN32"] = True + DEFINES["WIN32_LEAN_AND_MEAN"] = True + DEFINES["WINVER"] = "0x0A00" + DEFINES["_ATL_NO_OPENGL"] = True + DEFINES["_CRT_RAND_S"] = True + DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True + DEFINES["_CRT_SECURE_NO_WARNINGS"] = True + DEFINES["_HAS_EXCEPTIONS"] = "0" + DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True + DEFINES["_SECURE_ATL"] = True + DEFINES["_UNICODE"] = True + DEFINES["_USING_V110_SDK71_"] = True + DEFINES["_WIN32_WINNT"] = "0x0A00" + DEFINES["_WINDOWS"] = True + DEFINES["__STD_C"] = True + + OS_LIBS += [ + "winmm" + ] + +if CONFIG["CPU_ARCH"] == "aarch64": + + DEFINES["WEBRTC_ARCH_ARM64"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if CONFIG["CPU_ARCH"] == "arm": + + CXXFLAGS += [ + "-mfpu=neon" + ] + + DEFINES["WEBRTC_ARCH_ARM"] = True + DEFINES["WEBRTC_ARCH_ARM_V7"] = True + DEFINES["WEBRTC_HAS_NEON"] = True + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Android": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "DragonFly": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "FreeBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "NetBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if not CONFIG["MOZ_DEBUG"] and CONFIG["OS_TARGET"] == "OpenBSD": + + DEFINES["_FORTIFY_SOURCE"] = "2" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Android": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0120" + +if CONFIG["CPU_ARCH"] == "x86_64" and CONFIG["OS_TARGET"] == "Darwin": + + DEFINES["CR_XCODE_VERSION"] = "0920" + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "FreeBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "aarch64" and CONFIG["OS_TARGET"] == "Linux": + + DEFINES["DISABLE_NACL"] = True + DEFINES["NO_TCMALLOC"] = True + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "Linux": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "NetBSD": + + CXXFLAGS += [ + "-msse2" + ] + +if CONFIG["CPU_ARCH"] == "x86" and CONFIG["OS_TARGET"] == "OpenBSD": + + CXXFLAGS += [ + "-msse2" + ] + +Library("video_frame_api_i420_gn") diff --git a/third_party/libwebrtc/webrtc/api/videosourceproxy.h b/third_party/libwebrtc/webrtc/api/videosourceproxy.h new file mode 100644 index 0000000000..f2d8be0681 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/videosourceproxy.h @@ -0,0 +1,41 @@ +/* + * Copyright 2012 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 API_VIDEOSOURCEPROXY_H_ +#define API_VIDEOSOURCEPROXY_H_ + +#include "api/proxy.h" +#include "api/mediastreaminterface.h" + +namespace webrtc { + +// Makes sure the real VideoTrackSourceInterface implementation is destroyed on +// the signaling thread and marshals all method calls to the signaling thread. +// TODO(deadbeef): Move this to .cc file and out of api/. What threads methods +// are called on is an implementation detail. +BEGIN_PROXY_MAP(VideoTrackSource) + PROXY_SIGNALING_THREAD_DESTRUCTOR() + PROXY_CONSTMETHOD0(SourceState, state) + PROXY_CONSTMETHOD0(bool, remote) + PROXY_CONSTMETHOD0(bool, is_screencast) + PROXY_CONSTMETHOD0(rtc::Optional<bool>, needs_denoising) + PROXY_METHOD1(bool, GetStats, Stats*) + PROXY_WORKER_METHOD2(void, + AddOrUpdateSink, + rtc::VideoSinkInterface<VideoFrame>*, + const rtc::VideoSinkWants&) + PROXY_WORKER_METHOD1(void, RemoveSink, rtc::VideoSinkInterface<VideoFrame>*) + PROXY_METHOD1(void, RegisterObserver, ObserverInterface*) + PROXY_METHOD1(void, UnregisterObserver, ObserverInterface*) +END_PROXY_MAP() + +} // namespace webrtc + +#endif // API_VIDEOSOURCEPROXY_H_ diff --git a/third_party/libwebrtc/webrtc/api/videotracksource.h b/third_party/libwebrtc/webrtc/api/videotracksource.h new file mode 100644 index 0000000000..5ed49834d9 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/videotracksource.h @@ -0,0 +1,18 @@ +/* + * Copyright 2016 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 API_VIDEOTRACKSOURCE_H_ +#define API_VIDEOTRACKSOURCE_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/videotracksource.h" + +#endif // API_VIDEOTRACKSOURCE_H_ diff --git a/third_party/libwebrtc/webrtc/api/webrtcsdp.h b/third_party/libwebrtc/webrtc/api/webrtcsdp.h new file mode 100644 index 0000000000..cc0d292c75 --- /dev/null +++ b/third_party/libwebrtc/webrtc/api/webrtcsdp.h @@ -0,0 +1,18 @@ +/* + * Copyright 2011 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 API_WEBRTCSDP_H_ +#define API_WEBRTCSDP_H_ + +// Including this file is deprecated. It is no longer part of the public API. +// This only includes the file in its new location for backwards compatibility. +#include "pc/webrtcsdp.h" + +#endif // API_WEBRTCSDP_H_ |