Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_CALL_RTP_DEMUXER_H_ | 11 #ifndef WEBRTC_CALL_RTP_DEMUXER_H_ |
| 12 #define WEBRTC_CALL_RTP_DEMUXER_H_ | 12 #define WEBRTC_CALL_RTP_DEMUXER_H_ |
| 13 | 13 |
| 14 #include <map> | 14 #include <map> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <vector> | |
| 18 | |
| 19 #include "webrtc/call/rsid_ssrc_association_resolution_observer.h" | |
|
danilchap
2017/06/16 16:46:18
prefer to forward declare over include when it is
eladalon
2017/06/19 11:28:46
Done.
| |
| 17 | 20 |
| 18 namespace webrtc { | 21 namespace webrtc { |
| 19 | 22 |
| 20 class RtpPacketReceived; | 23 class RtpPacketReceived; |
| 21 class RtpPacketSinkInterface; | 24 class RtpPacketSinkInterface; |
| 22 | 25 |
| 23 // This class represents the RTP demuxing, for a single RTP session (i.e., one | 26 // This class represents the RTP demuxing, for a single RTP session (i.e., one |
| 24 // ssrc space, see RFC 7656). It isn't thread aware, leaving responsibility of | 27 // ssrc space, see RFC 7656). It isn't thread aware, leaving responsibility of |
| 25 // multithreading issues to the user of this class. | 28 // multithreading issues to the user of this class. |
| 26 // TODO(nisse): Should be extended to also do MID-based demux and payload-type | 29 // TODO(nisse): Should be extended to also do MID-based demux and payload-type |
| 27 // demux. | 30 // demux. |
| 28 class RtpDemuxer { | 31 class RtpDemuxer { |
| 29 public: | 32 public: |
| 30 RtpDemuxer(); | 33 RtpDemuxer(); |
| 31 ~RtpDemuxer(); | 34 ~RtpDemuxer(); |
| 32 | 35 |
| 33 // Registers a sink. The same sink can be registered for multiple ssrcs, and | 36 // Registers a sink. The same sink can be registered for multiple ssrcs, and |
| 34 // the same ssrc can have multiple sinks. Null pointer is not allowed. | 37 // the same ssrc can have multiple sinks. Null pointer is not allowed. |
| 35 void AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink); | 38 void AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink); |
| 36 | 39 |
| 37 // Registers a sink's association to an RSID. Null pointer is not allowed. | 40 // Registers a sink's association to an RSID. Null pointer is not allowed. |
| 38 void AddSink(const std::string& rsid, RtpPacketSinkInterface* sink); | 41 void AddSink(const std::string& rsid, RtpPacketSinkInterface* sink); |
| 39 | 42 |
| 40 // Removes a sink. Return value reports if anything was actually removed. | 43 // Removes a sink. Return value reports if anything was actually removed. |
| 41 // Null pointer is not allowed. | 44 // Null pointer is not allowed. |
| 42 bool RemoveSink(const RtpPacketSinkInterface* sink); | 45 bool RemoveSink(const RtpPacketSinkInterface* sink); |
| 43 | 46 |
| 44 // Returns true if at least one matching sink was found, otherwise false. | 47 // Returns true if at least one matching sink was found. |
| 45 bool OnRtpPacket(const RtpPacketReceived& packet); | 48 bool OnRtpPacket(const RtpPacketReceived& packet); |
| 46 | 49 |
| 50 // Allows other objects to be notified when RSID-SSRC associations are | |
| 51 // resolved by this object. | |
| 52 // Notifications received from outside are *not* propagated. (The ability | |
|
danilchap
2017/06/16 16:46:18
may be add this half of the comment when RtpDemuxe
eladalon
2017/06/19 11:28:46
Done.
| |
| 53 // to receive such notifications will be added later.) | |
| 54 void RegisterRsidResolutionObserver(RsidResolutionObserver* observer); | |
| 55 | |
| 56 // Undo a previous RegisterRsidResolutionObserver(). | |
| 57 void DeregisterRsidResolutionObserver(const RsidResolutionObserver* observer); | |
| 58 | |
| 47 private: | 59 private: |
| 48 // Records a sink<->SSRC association. This can happen by explicit | 60 // Records a sink<->SSRC association. This can happen by explicit |
| 49 // configuration by AddSink(ssrc...), or by inferred configuration from an | 61 // configuration by AddSink(ssrc...), or by inferred configuration from an |
| 50 // RSID-based configuration which is resolved to an SSRC upon | 62 // RSID-based configuration which is resolved to an SSRC upon |
| 51 // packet reception. | 63 // packet reception. |
| 52 void RecordSsrcToSinkAssociation(uint32_t ssrc, RtpPacketSinkInterface* sink); | 64 void RecordSsrcToSinkAssociation(uint32_t ssrc, RtpPacketSinkInterface* sink); |
| 53 | 65 |
| 54 // When a new packet arrives, we attempt to resolve extra associations, | 66 // When a new packet arrives, we attempt to resolve extra associations. |
| 55 // such as which RSIDs are associated with which SSRCs. | 67 void ResolveAssociations(const RtpPacketReceived& packet); |
| 56 void FindSsrcAssociations(const RtpPacketReceived& packet); | 68 |
| 69 // Find the associations of RSID to SSRCs. | |
| 70 void ResolveRsidToSsrcAssociations(const RtpPacketReceived& packet); | |
| 71 | |
| 72 // Notify observers of the resolution of an RSID to an SSRC. | |
| 73 void NotifyObserversOfRsidResolution(const std::string& rsid, uint32_t ssrc); | |
| 57 | 74 |
| 58 // This records the association SSRCs to sinks. Other associations, such | 75 // This records the association SSRCs to sinks. Other associations, such |
| 59 // as by RSID, also end up here once the RSID, etc., is resolved to an SSRC. | 76 // as by RSID, also end up here once the RSID, etc., is resolved to an SSRC. |
| 60 std::multimap<uint32_t, RtpPacketSinkInterface*> sinks_; | 77 std::multimap<uint32_t, RtpPacketSinkInterface*> sinks_; |
| 61 | 78 |
| 62 // A sink may be associated with an RSID - RTP Stream ID. This tag has a | 79 // A sink may be associated with an RSID - RTP Stream ID. This tag has a |
| 63 // one-to-one association with an SSRC, but that SSRC is not yet known. | 80 // one-to-one association with an SSRC, but that SSRC is not yet known. |
| 64 // When it becomes known, the association of the sink to the RSID is deleted | 81 // When it becomes known, the association of the sink to the RSID is deleted |
| 65 // from this container, and moved into |sinks_|. | 82 // from this container, and moved into |sinks_|. |
| 66 std::multimap<std::string, RtpPacketSinkInterface*> rsid_sinks_; | 83 std::multimap<std::string, RtpPacketSinkInterface*> rsid_sinks_; |
| 67 | 84 |
| 68 // Iterating over |rsid_sinks_| for each incoming and performing multiple | 85 // Iterating over |rsid_sinks_| for each incoming and performing multiple |
| 69 // string comparisons is of non-trivial cost. To avoid this cost, we only | 86 // string comparisons is of non-trivial cost. To avoid this cost, we only |
| 70 // check RSIDs for the first packet on each incoming SSRC stream. | 87 // check RSIDs for the first packet on each incoming SSRC stream. |
| 71 // (If RSID associations are added later, we check again.) | 88 // (If RSID associations are added later, we check again.) |
| 72 std::set<uint32_t> processed_ssrcs_; | 89 std::set<uint32_t> processed_ssrcs_; |
| 73 | 90 |
| 74 // Avoid an attack that would create excessive logging. | 91 // Avoid an attack that would create excessive logging. |
| 75 bool logged_max_processed_ssrcs_exceeded_ = false; | 92 bool logged_max_processed_ssrcs_exceeded_ = false; |
| 93 | |
| 94 // Observers which will be notified when an RSID association to an SSRC is | |
| 95 // resolved by this object. | |
| 96 std::vector<RsidResolutionObserver*> rsid_resolution_observers_; | |
| 76 }; | 97 }; |
| 77 | 98 |
| 78 } // namespace webrtc | 99 } // namespace webrtc |
| 79 | 100 |
| 80 #endif // WEBRTC_CALL_RTP_DEMUXER_H_ | 101 #endif // WEBRTC_CALL_RTP_DEMUXER_H_ |
| OLD | NEW |