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

Unified Diff: webrtc/call/rtp_demuxer.cc

Issue 2867943003: New class RtpDemuxer and RtpPacketSinkInterface, use in Call. (Closed)
Patch Set: Fix use-after-free crash in av sync. Created 3 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/call/rtp_demuxer.cc
diff --git a/webrtc/call/rtp_demuxer.cc b/webrtc/call/rtp_demuxer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..638c8c6e2ab5d08e23f5cf4aae65086c3c4497bd
--- /dev/null
+++ b/webrtc/call/rtp_demuxer.cc
@@ -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.
+ */
+
+#include <utility>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/call/rtp_demuxer.h"
+#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
+
+namespace webrtc {
+
+RtpDemuxer::RtpDemuxer() {}
+
+RtpDemuxer::~RtpDemuxer() {
+ RTC_DCHECK(sinks_.empty());
+}
+
+void RtpDemuxer::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) {
+ sinks_.insert(std::pair<uint32_t, RtpPacketSinkInterface*>(ssrc, sink));
danilchap 2017/05/09 09:20:22 sinks_.emplace(ssrc, sink);
nisse-webrtc 2017/05/09 12:11:49 Thanks, that looks better.
+}
+
+void RtpDemuxer::RemoveSink(const RtpPacketSinkInterface* sink) {
+ for (auto it = sinks_.begin(); it != sinks_.end(); ) {
+ if (it->second == sink)
+ it = sinks_.erase(it);
+ else
+ ++it;
+ }
+}
+
+bool RtpDemuxer::OnRtpPacket(const RtpPacketReceived& packet) {
+ bool found = false;
+ auto it_range = sinks_.equal_range(packet.Ssrc());
+ for (auto it = it_range.first; it != it_range.second; ++it) {
+ found = true;
+ it->second->OnRtpPacket(packet);
+ }
+ return found;
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698