xref: /aosp_15_r20/external/webrtc/call/rtp_stream_receiver_controller.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
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  */
10 #ifndef CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_
11 #define CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_
12 
13 #include <memory>
14 
15 #include "api/sequence_checker.h"
16 #include "call/rtp_demuxer.h"
17 #include "call/rtp_stream_receiver_controller_interface.h"
18 
19 namespace webrtc {
20 
21 class RtpPacketReceived;
22 
23 // This class represents the RTP receive parsing and demuxing, for a
24 // single RTP session.
25 // TODO(bugs.webrtc.org/7135): Add RTCP processing, we should aim to terminate
26 // RTCP and not leave any RTCP processing to individual receive streams.
27 class RtpStreamReceiverController
28     : public RtpStreamReceiverControllerInterface {
29  public:
30   RtpStreamReceiverController();
31   ~RtpStreamReceiverController() override;
32 
33   // Implements RtpStreamReceiverControllerInterface.
34   std::unique_ptr<RtpStreamReceiverInterface> CreateReceiver(
35       uint32_t ssrc,
36       RtpPacketSinkInterface* sink) override;
37 
38   // TODO(bugs.webrtc.org/7135): Not yet responsible for parsing.
39   bool OnRtpPacket(const RtpPacketReceived& packet);
40 
41  private:
42   class Receiver : public RtpStreamReceiverInterface {
43    public:
44     Receiver(RtpStreamReceiverController* controller,
45              uint32_t ssrc,
46              RtpPacketSinkInterface* sink);
47 
48     ~Receiver() override;
49 
50    private:
51     RtpStreamReceiverController* const controller_;
52     RtpPacketSinkInterface* const sink_;
53   };
54 
55   // Thread-safe wrappers for the corresponding RtpDemuxer methods.
56   bool AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink);
57   bool RemoveSink(const RtpPacketSinkInterface* sink);
58 
59   // TODO(bugs.webrtc.org/11993): We expect construction and all methods to be
60   // called on the same thread/tq. Currently this is the worker thread
61   // (including OnRtpPacket) but a more natural fit would be the network thread.
62   // Using a sequence checker to ensure that usage is correct but at the same
63   // time not require a specific thread/tq, an instance of this class + the
64   // associated functionality should be easily moved from one execution context
65   // to another (i.e. when network packets don't hop to the worker thread inside
66   // of Call).
67   SequenceChecker demuxer_sequence_;
68   // At this level the demuxer is only configured to demux by SSRC, so don't
69   // worry about MIDs (MIDs are handled by upper layers).
70   RtpDemuxer demuxer_ RTC_GUARDED_BY(&demuxer_sequence_){false /*use_mid*/};
71 };
72 
73 }  // namespace webrtc
74 
75 #endif  // CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_
76