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 #ifndef WEBRTC_CALL_RTP_DEMUXER_H_ | 11 #ifndef WEBRTC_CALL_RTP_DEMUXER_H_ |
11 #define WEBRTC_CALL_RTP_DEMUXER_H_ | 12 #define WEBRTC_CALL_RTP_DEMUXER_H_ |
12 | 13 |
13 #include <map> | 14 #include <map> |
15 #include <set> | |
16 #include <string> | |
14 | 17 |
15 namespace webrtc { | 18 namespace webrtc { |
16 | 19 |
17 class RtpPacketReceived; | 20 class RtpPacketReceived; |
18 | 21 |
19 // This class represents a receiver of an already parsed RTP packets. | 22 // This class represents a receiver of an already parsed RTP packets. |
20 class RtpPacketSinkInterface { | 23 class RtpPacketSinkInterface { |
21 public: | 24 public: |
22 virtual ~RtpPacketSinkInterface() {} | 25 virtual ~RtpPacketSinkInterface() {} |
23 virtual void OnRtpPacket(const RtpPacketReceived& packet) = 0; | 26 virtual void OnRtpPacket(const RtpPacketReceived& packet) = 0; |
24 }; | 27 }; |
25 | 28 |
26 // This class represents the RTP demuxing, for a single RTP session (i.e., one | 29 // This class represents the RTP demuxing, for a single RTP session (i.e., one |
27 // ssrc space, see RFC 7656). It isn't thread aware, leaving responsibility of | 30 // ssrc space, see RFC 7656). It isn't thread aware, leaving responsibility of |
28 // multithreading issues to the user of this class. | 31 // multithreading issues to the user of this class. |
29 // TODO(nisse): Should be extended to also do MID-based demux and payload-type | 32 // TODO(nisse): Should be extended to also do MID-based demux and payload-type |
30 // demux. | 33 // demux. |
31 class RtpDemuxer { | 34 class RtpDemuxer { |
32 public: | 35 public: |
33 RtpDemuxer(); | 36 RtpDemuxer(); |
34 ~RtpDemuxer(); | 37 ~RtpDemuxer(); |
35 | 38 |
36 // Registers a sink. The same sink can be registered for multiple ssrcs, and | 39 // Registers a sink. The same sink can be registered for multiple ssrcs, and |
37 // the same ssrc can have multiple sinks. Null pointer is not allowed. | 40 // the same ssrc can have multiple sinks. Null pointer is not allowed. |
38 void AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink); | 41 void AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink); |
42 | |
43 // Registers a sink's association to an RSID. Null pointer is not allowed. | |
44 void AddSink(const std::string& rsid, RtpPacketSinkInterface* sink); | |
45 | |
39 // Removes a sink. Returns deletion count (a sink may be registered | 46 // Removes a sink. Returns deletion count (a sink may be registered |
40 // for multiple ssrcs). Null pointer is not allowed. | 47 // for multiple SSRCs and/or RSIDs). Null pointer is not allowed. |
41 size_t RemoveSink(const RtpPacketSinkInterface* sink); | 48 size_t RemoveSink(const RtpPacketSinkInterface* sink); |
42 | 49 |
43 // Returns true if at least one matching sink was found, otherwise false. | 50 // Returns true if at least one matching sink was found, otherwise false. |
44 bool OnRtpPacket(const RtpPacketReceived& packet); | 51 bool OnRtpPacket(const RtpPacketReceived& packet); |
45 | 52 |
46 private: | 53 private: |
54 // Records a sink<->SSRC association. This can happen by explicit | |
55 // configuration by AddSink(ssrc...), or by inferred configuration from an | |
56 // RSID-based configuration which is resolved to an SSRC upon | |
57 // packet reception. | |
58 void RecordSsrcToSinkAssociation(uint32_t ssrc, RtpPacketSinkInterface* sink); | |
59 | |
60 // When a new packet arrives, we attempt to resolve extra associations, | |
61 // such as which RSIDs are associated with which SSRCs. | |
62 void FindSsrcAssociations(const RtpPacketReceived& packet); | |
63 | |
64 // This records the association SSRCs to sinks. Other associations, such | |
65 // as by RSID, also end up here once the RSID, etc., is resolved to an SSRC. | |
47 std::multimap<uint32_t, RtpPacketSinkInterface*> sinks_; | 66 std::multimap<uint32_t, RtpPacketSinkInterface*> sinks_; |
67 | |
68 // A sink may be associated with an RSID - RTP Stream ID. This tag has a | |
69 // one-to-one association with an SSRC, but that SSRC is not yet known. | |
70 // When it becomes known, the association of the sink to the RSID is deleted | |
71 // from this container, and moved into |sinks_|. | |
72 std::multimap<std::string, RtpPacketSinkInterface*> rsid_sinks_; | |
73 | |
74 // Iterating over |rsid_sinks_| for each incoming and performing multiple | |
75 // string comparisons is of non-trivial cost. To avoid this cost, we only | |
76 // check RSIDs for the first packet on each incoming SSRC stream. | |
77 // (If RSID associations are added later, we check again.) | |
78 std::set<uint32_t> processed_ssrcs_; | |
danilchap
2017/06/07 13:45:42
In 'all good' scenario this set cause extra lookup
eladalon
2017/06/07 19:30:00
Discussed offline; keeping as is.
| |
48 }; | 79 }; |
49 | 80 |
50 } // namespace webrtc | 81 } // namespace webrtc |
51 | 82 |
52 #endif // WEBRTC_CALL_RTP_DEMUXER_H_ | 83 #endif // WEBRTC_CALL_RTP_DEMUXER_H_ |
OLD | NEW |