nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_ |
| 11 | #define CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_ |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "call/rtp_demuxer.h" |
| 16 | #include "call/rtp_stream_receiver_controller_interface.h" |
| 17 | #include "rtc_base/criticalsection.h" |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 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(nisse): Add RTCP processing, we should aim to terminate RTCP |
| 26 | // and not leave any RTCP processing to individual receive streams. |
| 27 | // TODO(nisse): Extract per-packet processing, including parsing and |
| 28 | // demuxing, into a separate class. |
| 29 | class RtpStreamReceiverController |
| 30 | : public RtpStreamReceiverControllerInterface { |
| 31 | public: |
| 32 | RtpStreamReceiverController(); |
| 33 | ~RtpStreamReceiverController() override; |
| 34 | |
| 35 | // Implements RtpStreamReceiverControllerInterface. |
| 36 | std::unique_ptr<RtpStreamReceiverInterface> CreateReceiver( |
| 37 | uint32_t ssrc, |
| 38 | RtpPacketSinkInterface* sink) override; |
| 39 | |
| 40 | // Thread-safe wrappers for the corresponding RtpDemuxer methods. |
eladalon | 5daecca | 2017-08-04 06:34:54 -0700 | [diff] [blame] | 41 | bool AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) override; |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 42 | size_t RemoveSink(const RtpPacketSinkInterface* sink) override; |
| 43 | |
| 44 | // TODO(nisse): Not yet responsible for parsing. |
| 45 | bool OnRtpPacket(const RtpPacketReceived& packet); |
| 46 | |
| 47 | private: |
| 48 | class Receiver : public RtpStreamReceiverInterface { |
| 49 | public: |
| 50 | Receiver(RtpStreamReceiverController* controller, |
| 51 | uint32_t ssrc, |
| 52 | RtpPacketSinkInterface* sink); |
| 53 | |
| 54 | ~Receiver() override; |
| 55 | |
| 56 | private: |
| 57 | RtpStreamReceiverController* const controller_; |
| 58 | RtpPacketSinkInterface* const sink_; |
| 59 | }; |
| 60 | |
| 61 | // TODO(nisse): Move to a TaskQueue for synchronization. When used |
| 62 | // by Call, we expect construction and all methods but OnRtpPacket |
| 63 | // to be called on the same thread, and OnRtpPacket to be called |
| 64 | // by a single, but possibly distinct, thread. But applications not |
| 65 | // using Call may have use threads differently. |
| 66 | rtc::CriticalSection lock_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 67 | RtpDemuxer demuxer_ RTC_GUARDED_BY(&lock_); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace webrtc |
| 71 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 72 | #endif // CALL_RTP_STREAM_RECEIVER_CONTROLLER_H_ |