blob: fa64b7f73bec848d02fc6f639490b866cd43308a [file] [log] [blame]
wu@webrtc.org822fbd82013-08-15 23:38:54 +00001/*
2 * Copyright (c) 2013 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
12#define MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_
wu@webrtc.org822fbd82013-08-15 23:38:54 +000013
hbos8d609f62017-04-10 07:39:05 -070014#include <list>
kwiberg84be5112016-04-27 01:19:58 -070015#include <memory>
hbos8d609f62017-04-10 07:39:05 -070016#include <unordered_map>
17#include <vector>
kwiberg84be5112016-04-27 01:19:58 -070018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/rtp_rtcp/include/rtp_receiver.h"
20#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
21#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
22#include "rtc_base/criticalsection.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020023#include "typedefs.h" // NOLINT(build/include)
wu@webrtc.org822fbd82013-08-15 23:38:54 +000024
25namespace webrtc {
26
27class RtpReceiverImpl : public RtpReceiver {
28 public:
29 // Callbacks passed in here may not be NULL (use Null Object callbacks if you
30 // want callbacks to do nothing). This class takes ownership of the media
31 // receiver but nothing else.
Peter Boströmac547a62015-09-17 23:03:57 +020032 RtpReceiverImpl(Clock* clock,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000033 RtpFeedback* incoming_messages_callback,
34 RTPPayloadRegistry* rtp_payload_registry,
35 RTPReceiverStrategy* rtp_media_receiver);
36
37 virtual ~RtpReceiverImpl();
38
magjed56124bd2016-11-24 09:34:46 -080039 int32_t RegisterReceivePayload(const CodecInst& audio_codec) override;
magjed6b272c52016-11-25 02:29:39 -080040 int32_t RegisterReceivePayload(const VideoCodec& video_codec) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000041
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000042 int32_t DeRegisterReceivePayload(const int8_t payload_type) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000043
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000044 bool IncomingRtpPacket(const RTPHeader& rtp_header,
45 const uint8_t* payload,
46 size_t payload_length,
47 PayloadUnion payload_specific,
48 bool in_order) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049
wu@webrtc.org822fbd82013-08-15 23:38:54 +000050 // Returns the last received timestamp.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000051 bool Timestamp(uint32_t* timestamp) const override;
52 bool LastReceivedTimeMs(int64_t* receive_time_ms) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000054 uint32_t SSRC() const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000055
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000056 int32_t CSRCs(uint32_t array_of_csrc[kRtpCsrcSize]) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000058 int32_t Energy(uint8_t array_of_energy[kRtpCsrcSize]) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059
danilchap799a9d02016-09-22 03:36:27 -070060 TelephoneEventHandler* GetTelephoneEventHandler() override;
61
hbos8d609f62017-04-10 07:39:05 -070062 std::vector<RtpSource> GetSources() const override;
63
64 const std::vector<RtpSource>& ssrc_sources_for_testing() const {
65 return ssrc_sources_;
66 }
67
68 const std::list<RtpSource>& csrc_sources_for_testing() const {
69 return csrc_sources_;
70 }
71
wu@webrtc.org822fbd82013-08-15 23:38:54 +000072 private:
stefan@webrtc.org48df3812013-11-08 15:18:52 +000073 bool HaveReceivedFrame() const;
74
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000075 void CheckSSRCChanged(const RTPHeader& rtp_header);
76 void CheckCSRC(const WebRtcRTPHeader& rtp_header);
77 int32_t CheckPayloadChanged(const RTPHeader& rtp_header,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000078 const int8_t first_payload_byte,
danilchap6db6cdc2015-12-15 02:54:47 -080079 bool* is_red,
pbosd4362982015-07-07 08:32:48 -070080 PayloadUnion* payload);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000081
zstein2b706342017-08-24 14:52:17 -070082 void UpdateSources(const rtc::Optional<uint8_t>& ssrc_audio_level);
hbos8d609f62017-04-10 07:39:05 -070083 void RemoveOutdatedSources(int64_t now_ms);
84
wu@webrtc.org822fbd82013-08-15 23:38:54 +000085 Clock* clock_;
86 RTPPayloadRegistry* rtp_payload_registry_;
kwiberg84be5112016-04-27 01:19:58 -070087 std::unique_ptr<RTPReceiverStrategy> rtp_media_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000088
wu@webrtc.org822fbd82013-08-15 23:38:54 +000089 RtpFeedback* cb_rtp_feedback_;
90
danilchap7c9426c2016-04-14 03:05:31 -070091 rtc::CriticalSection critical_section_rtp_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000092
93 // SSRCs.
94 uint32_t ssrc_;
95 uint8_t num_csrcs_;
96 uint32_t current_remote_csrc_[kRtpCsrcSize];
97
98 uint32_t last_received_timestamp_;
99 int64_t last_received_frame_time_ms_;
hbos8d609f62017-04-10 07:39:05 -0700100
101 std::unordered_map<uint32_t, std::list<RtpSource>::iterator>
102 iterator_by_csrc_;
103 // The RtpSource objects are sorted chronologically.
104 std::list<RtpSource> csrc_sources_;
105 std::vector<RtpSource> ssrc_sources_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000106};
107} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200108#endif // MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_