Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: softtabstop=2:shiftwidth=2:expandtab
3 : * */
4 : /* This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
6 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 :
8 : // Original author: bcampen@mozilla.com
9 :
10 : #include "MediaPipelineFilter.h"
11 :
12 : #include "webrtc/common_types.h"
13 : #include "logging.h"
14 :
15 : // Logging context
16 0 : MOZ_MTLOG_MODULE("mediapipeline")
17 :
18 : namespace mozilla {
19 :
20 0 : MediaPipelineFilter::MediaPipelineFilter() : correlator_(0) {
21 0 : }
22 :
23 0 : bool MediaPipelineFilter::Filter(const webrtc::RTPHeader& header,
24 : uint32_t correlator) {
25 0 : if (correlator) {
26 : // This special correlator header takes precedence. It also lets us learn
27 : // about SSRC mappings if we don't know about them yet.
28 0 : if (correlator == correlator_) {
29 0 : AddRemoteSSRC(header.ssrc);
30 0 : return true;
31 : }
32 : // Some other stream; it is possible that an SSRC has moved, so make sure
33 : // we don't have that SSRC in our filter any more.
34 0 : remote_ssrc_set_.erase(header.ssrc);
35 0 : return false;
36 : }
37 :
38 0 : if (header.extension.hasRID &&
39 0 : remote_rid_set_.size() &&
40 0 : remote_rid_set_.count(header.extension.rid.get())) {
41 0 : return true;
42 : }
43 0 : if (header.extension.hasRID) {
44 0 : MOZ_MTLOG(ML_DEBUG, "MediaPipelineFilter ignoring seq# " << header.sequenceNumber <<
45 : " ssrc: " << header.ssrc << " RID: " << header.extension.rid.get());
46 : }
47 :
48 0 : if (remote_ssrc_set_.count(header.ssrc)) {
49 0 : return true;
50 : }
51 :
52 : // Last ditch effort...
53 0 : if (payload_type_set_.count(header.payloadType)) {
54 : // Actual match. We need to update the ssrc map so we can route rtcp
55 : // sender reports correctly (these use a different payload-type field)
56 0 : AddRemoteSSRC(header.ssrc);
57 0 : return true;
58 : }
59 :
60 0 : return false;
61 : }
62 :
63 0 : void MediaPipelineFilter::AddRemoteSSRC(uint32_t ssrc) {
64 0 : remote_ssrc_set_.insert(ssrc);
65 0 : }
66 :
67 0 : void MediaPipelineFilter::AddRemoteRtpStreamId(const std::string& rtp_strm_id) {
68 0 : remote_rid_set_.insert(rtp_strm_id);
69 0 : }
70 :
71 0 : void MediaPipelineFilter::AddUniquePT(uint8_t payload_type) {
72 0 : payload_type_set_.insert(payload_type);
73 0 : }
74 :
75 0 : void MediaPipelineFilter::SetCorrelator(uint32_t correlator) {
76 0 : correlator_ = correlator;
77 0 : }
78 :
79 0 : void MediaPipelineFilter::Update(const MediaPipelineFilter& filter_update) {
80 : // We will not stomp the remote_ssrc_set_ if the update has no ssrcs,
81 : // because we don't want to unlearn any remote ssrcs unless the other end
82 : // has explicitly given us a new set.
83 0 : if (!filter_update.remote_ssrc_set_.empty()) {
84 0 : remote_ssrc_set_ = filter_update.remote_ssrc_set_;
85 : }
86 :
87 0 : payload_type_set_ = filter_update.payload_type_set_;
88 0 : correlator_ = filter_update.correlator_;
89 0 : }
90 :
91 : bool
92 0 : MediaPipelineFilter::FilterSenderReport(const unsigned char* data,
93 : size_t len) const {
94 :
95 0 : if (!data) {
96 0 : return false;
97 : }
98 :
99 0 : if (len < FIRST_SSRC_OFFSET + 4) {
100 0 : return false;
101 : }
102 :
103 0 : uint8_t payload_type = data[PT_OFFSET];
104 :
105 0 : if (payload_type != SENDER_REPORT_T) {
106 0 : return false;
107 : }
108 :
109 0 : uint32_t ssrc = 0;
110 0 : ssrc += (uint32_t)data[FIRST_SSRC_OFFSET] << 24;
111 0 : ssrc += (uint32_t)data[FIRST_SSRC_OFFSET + 1] << 16;
112 0 : ssrc += (uint32_t)data[FIRST_SSRC_OFFSET + 2] << 8;
113 0 : ssrc += (uint32_t)data[FIRST_SSRC_OFFSET + 3];
114 :
115 0 : return !!remote_ssrc_set_.count(ssrc);
116 : }
117 :
118 : } // end namespace mozilla
119 :
|