blob: dccf0b69a136f9581ed8b52992ffe04a7df39f61 [file] [log] [blame]
nissee4bcd6d2017-05-16 04:47:04 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
eladalond0244c22017-06-08 04:19:13 -070010
nissee4bcd6d2017-05-16 04:47:04 -070011#ifndef WEBRTC_CALL_RTP_DEMUXER_H_
12#define WEBRTC_CALL_RTP_DEMUXER_H_
13
14#include <map>
eladalond0244c22017-06-08 04:19:13 -070015#include <string>
eladalona52722f2017-06-26 11:23:54 -070016#include <vector>
nissee4bcd6d2017-05-16 04:47:04 -070017
18namespace webrtc {
19
eladalona52722f2017-06-26 11:23:54 -070020class RsidResolutionObserver;
nissee4bcd6d2017-05-16 04:47:04 -070021class RtpPacketReceived;
nissed76b7b22017-06-01 04:02:35 -070022class RtpPacketSinkInterface;
nissee4bcd6d2017-05-16 04:47:04 -070023
24// This class represents the RTP demuxing, for a single RTP session (i.e., one
25// ssrc space, see RFC 7656). It isn't thread aware, leaving responsibility of
26// multithreading issues to the user of this class.
27// TODO(nisse): Should be extended to also do MID-based demux and payload-type
28// demux.
29class RtpDemuxer {
30 public:
31 RtpDemuxer();
32 ~RtpDemuxer();
33
eladalon5daecca2017-08-04 06:34:54 -070034 // Registers a sink. Multiple SSRCs may be mapped to the same sink, but
35 // each SSRC may only be mapped to one sink. The return value reports
36 // whether the association has been recorded or rejected. Rejection may occur
37 // if the SSRC has already been associated with a sink. The previously added
38 // sink is *not* forgotten.
39 bool AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink);
eladalond0244c22017-06-08 04:19:13 -070040
eladalon5daecca2017-08-04 06:34:54 -070041 // Registers a sink's association to an RSID. Only one sink may be associated
42 // with a given RSID. Null pointer is not allowed.
eladalond0244c22017-06-08 04:19:13 -070043 void AddSink(const std::string& rsid, RtpPacketSinkInterface* sink);
44
45 // Removes a sink. Return value reports if anything was actually removed.
46 // Null pointer is not allowed.
47 bool RemoveSink(const RtpPacketSinkInterface* sink);
nissee4bcd6d2017-05-16 04:47:04 -070048
eladalon5daecca2017-08-04 06:34:54 -070049 // Handles RTP packets. Returns true if at least one matching sink was found.
nissee4bcd6d2017-05-16 04:47:04 -070050 bool OnRtpPacket(const RtpPacketReceived& packet);
51
eladalona52722f2017-06-26 11:23:54 -070052 // Allows other objects to be notified when RSID-SSRC associations are
53 // resolved by this object.
54 void RegisterRsidResolutionObserver(RsidResolutionObserver* observer);
55
56 // Undo a previous RegisterRsidResolutionObserver().
57 void DeregisterRsidResolutionObserver(const RsidResolutionObserver* observer);
58
nissee4bcd6d2017-05-16 04:47:04 -070059 private:
eladalona52722f2017-06-26 11:23:54 -070060 // Find the associations of RSID to SSRCs.
61 void ResolveRsidToSsrcAssociations(const RtpPacketReceived& packet);
62
63 // Notify observers of the resolution of an RSID to an SSRC.
64 void NotifyObserversOfRsidResolution(const std::string& rsid, uint32_t ssrc);
eladalond0244c22017-06-08 04:19:13 -070065
66 // This records the association SSRCs to sinks. Other associations, such
67 // as by RSID, also end up here once the RSID, etc., is resolved to an SSRC.
eladalon5daecca2017-08-04 06:34:54 -070068 std::map<uint32_t, RtpPacketSinkInterface*> ssrc_sinks_;
eladalond0244c22017-06-08 04:19:13 -070069
70 // A sink may be associated with an RSID - RTP Stream ID. This tag has a
71 // one-to-one association with an SSRC, but that SSRC is not yet known.
72 // When it becomes known, the association of the sink to the RSID is deleted
eladalonc3e3e602017-06-28 08:18:51 -070073 // from this container, and moved into |ssrc_sinks_|.
eladalon5daecca2017-08-04 06:34:54 -070074 std::map<std::string, RtpPacketSinkInterface*> rsid_sinks_;
eladalond0244c22017-06-08 04:19:13 -070075
eladalona52722f2017-06-26 11:23:54 -070076 // Observers which will be notified when an RSID association to an SSRC is
77 // resolved by this object.
78 std::vector<RsidResolutionObserver*> rsid_resolution_observers_;
nissee4bcd6d2017-05-16 04:47:04 -070079};
80
81} // namespace webrtc
82
83#endif // WEBRTC_CALL_RTP_DEMUXER_H_