Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: talk/media/webrtc/webrtcmediaengine.cc

Issue 1481963002: Add header extension filtering for WebRtcVoiceEngine/MediaChannel. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Simpler implementation of set<>, requiring no heap allocs. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products 13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/media/webrtc/webrtcmediaengine.h" 28 #include "talk/media/webrtc/webrtcmediaengine.h"
29
30 #include <algorithm>
31
29 #include "talk/media/webrtc/webrtcvideoengine2.h" 32 #include "talk/media/webrtc/webrtcvideoengine2.h"
30 #include "talk/media/webrtc/webrtcvoiceengine.h" 33 #include "talk/media/webrtc/webrtcvoiceengine.h"
31 #include "webrtc/base/arraysize.h"
32 34
33 namespace cricket { 35 namespace cricket {
34 36
35 class WebRtcMediaEngine2 37 class WebRtcMediaEngine2
36 : public CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2> { 38 : public CompositeMediaEngine<WebRtcVoiceEngine, WebRtcVideoEngine2> {
37 public: 39 public:
38 WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm, 40 WebRtcMediaEngine2(webrtc::AudioDeviceModule* adm,
39 WebRtcVideoEncoderFactory* encoder_factory, 41 WebRtcVideoEncoderFactory* encoder_factory,
40 WebRtcVideoDecoderFactory* decoder_factory) { 42 WebRtcVideoDecoderFactory* decoder_factory) {
41 voice_.SetAudioDeviceModule(adm); 43 voice_.SetAudioDeviceModule(adm);
(...skipping 20 matching lines...) Expand all
62 64
63 // Used by PeerConnectionFactory to create a media engine passed into 65 // Used by PeerConnectionFactory to create a media engine passed into
64 // ChannelManager. 66 // ChannelManager.
65 MediaEngineInterface* WebRtcMediaEngineFactory::Create( 67 MediaEngineInterface* WebRtcMediaEngineFactory::Create(
66 webrtc::AudioDeviceModule* adm, 68 webrtc::AudioDeviceModule* adm,
67 WebRtcVideoEncoderFactory* encoder_factory, 69 WebRtcVideoEncoderFactory* encoder_factory,
68 WebRtcVideoDecoderFactory* decoder_factory) { 70 WebRtcVideoDecoderFactory* decoder_factory) {
69 return CreateWebRtcMediaEngine(adm, encoder_factory, decoder_factory); 71 return CreateWebRtcMediaEngine(adm, encoder_factory, decoder_factory);
70 } 72 }
71 73
72 const char* kBweExtensionPriorities[] = { 74 namespace {
73 kRtpTransportSequenceNumberHeaderExtension, 75 // Remove mutually exclusive extensions with lower priority.
stefan-webrtc 2015/12/01 15:36:57 Maybe comment on that extension_prios are sorted i
the sun 2015/12/01 16:34:44 Done.
74 kRtpAbsoluteSenderTimeHeaderExtension, kRtpTimestampOffsetHeaderExtension}; 76 void DiscardRedundantExtensions(
77 std::vector<webrtc::RtpExtension>* extensions,
78 rtc::ArrayView<const char*> extension_prios) {
79 RTC_DCHECK(extensions);
80 bool found = false;
81 for (const char* name : extension_prios) {
82 auto it = std::find_if(extensions->begin(), extensions->end(),
83 [name](const webrtc::RtpExtension& rhs) {
84 return rhs.name == name;
85 });
86 if (it != extensions->end()) {
87 if (found) {
88 extensions->erase(it);
89 }
stefan-webrtc 2015/12/01 15:36:57 Remove {}, or keep if you prefer. :)
the sun 2015/12/01 16:34:45 Acknowledged.
90 found = true;
91 }
92 }
93 }
94 } // namespace
75 95
76 const size_t kBweExtensionPrioritiesLength = arraysize(kBweExtensionPriorities); 96 bool ValidateRtpExtensions(const std::vector<RtpHeaderExtension>& extensions) {
77 97 bool id_used[14] = {false};
78 int GetPriority(const RtpHeaderExtension& extension, 98 for (const auto& extension : extensions) {
79 const char* extension_prios[], 99 if (extension.id <= 0 || extension.id >= 15) {
80 size_t extension_prios_length) { 100 LOG(LS_ERROR) << "Bad RTP extension ID: " << extension.ToString();
81 for (size_t i = 0; i < extension_prios_length; ++i) { 101 return false;
82 if (extension.uri == extension_prios[i]) 102 }
83 return static_cast<int>(i); 103 if (id_used[extension.id - 1]) {
104 LOG(LS_ERROR) << "Duplicate RTP extension ID: " << extension.ToString();
105 return false;
106 }
107 id_used[extension.id - 1] = true;
84 } 108 }
85 return -1; 109 return true;
86 } 110 }
87 111
88 std::vector<RtpHeaderExtension> FilterRedundantRtpExtensions( 112 std::vector<webrtc::RtpExtension> FilterRtpExtensions(
89 const std::vector<RtpHeaderExtension>& extensions, 113 const std::vector<RtpHeaderExtension>& extensions,
90 const char* extension_prios[], 114 bool (*supported)(const std::string&),
91 size_t extension_prios_length) { 115 bool filter_redundant_extensions) {
92 if (extensions.empty()) 116 RTC_DCHECK(ValidateRtpExtensions(extensions));
93 return std::vector<RtpHeaderExtension>(); 117 RTC_DCHECK(supported);
94 std::vector<RtpHeaderExtension> filtered; 118 std::vector<webrtc::RtpExtension> result;
95 std::map<int, const RtpHeaderExtension*> sorted; 119
96 for (auto& extension : extensions) { 120 // Ignore any extensions that we don't recognize.
97 int priority = 121 for (const auto& extension : extensions) {
98 GetPriority(extension, extension_prios, extension_prios_length); 122 if (supported(extension.uri)) {
99 if (priority == -1) { 123 result.push_back({extension.uri, extension.id});
100 filtered.push_back(extension);
101 continue;
102 } else { 124 } else {
103 sorted[priority] = &extension; 125 LOG(LS_WARNING) << "Unsupported RTP extension: " << extension.ToString();
104 } 126 }
105 } 127 }
106 if (!sorted.empty()) 128
107 filtered.push_back(*sorted.begin()->second); 129 // Sort ascending, by name.
108 return filtered; 130 std::sort(result.begin(), result.end(),
131 [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) {
132 return rhs.name < lhs.name;
133 });
stefan-webrtc 2015/12/01 15:36:57 Why do we have to sort?
the sun 2015/12/01 16:34:45 Done.
134
135 // When sending, remove unnecessary extensions.
stefan-webrtc 2015/12/01 15:36:57 I don't see anything taking sending or receiving i
the sun 2015/12/01 16:34:44 Done.
136 if (filter_redundant_extensions) {
137 auto it = std::unique(result.begin(), result.end(),
138 [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) {
139 return rhs.name == lhs.name;
140 });
141 result.erase(it, result.end());
142
143 // Keep just the highest priority extension of any in the following list.
144 static const char* kBweExtensionPriorities[] = {
145 kRtpTransportSequenceNumberHeaderExtension,
146 kRtpAbsoluteSenderTimeHeaderExtension,
147 kRtpTimestampOffsetHeaderExtension
148 };
149 DiscardRedundantExtensions(&result, kBweExtensionPriorities);
150 }
151
152 return result;
109 } 153 }
110
111 } // namespace cricket 154 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698