blob: 66265f5fb1021a537edce7411e4ff322247d96b4 [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
kwiberg84be5112016-04-27 01:19:58 -070014#include <memory>
hbos8d609f62017-04-10 07:39:05 -070015#include <unordered_map>
16#include <vector>
kwiberg84be5112016-04-27 01:19:58 -070017
Danil Chapovalovd264df52018-06-14 12:59:38 +020018#include "absl/types/optional.h"
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"
Niels Mölleraf175952018-08-13 13:23:08 +020021#include "modules/rtp_rtcp/source/contributing_sources.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/rtp_rtcp/source/rtp_receiver_strategy.h"
23#include "rtc_base/criticalsection.h"
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 RTPPayloadRegistry* rtp_payload_registry,
34 RTPReceiverStrategy* rtp_media_receiver);
35
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010036 ~RtpReceiverImpl() override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000037
Karl Wibergc62f6c72017-10-04 12:38:53 +020038 int32_t RegisterReceivePayload(int payload_type,
39 const SdpAudioFormat& audio_format) 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,
Niels Möller22ec9522017-10-05 08:39:15 +020047 PayloadUnion payload_specific) override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000048
Niels Möllerc3fa8e12017-10-03 15:28:26 +020049 bool GetLatestTimestamps(uint32_t* timestamp,
50 int64_t* receive_time_ms) const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000052 uint32_t SSRC() const override;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053
hbos8d609f62017-04-10 07:39:05 -070054 std::vector<RtpSource> GetSources() const override;
55
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056 private:
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000057 void CheckSSRCChanged(const RTPHeader& rtp_header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000058
Danil Chapovalovd264df52018-06-14 12:59:38 +020059 void UpdateSources(const absl::optional<uint8_t>& ssrc_audio_level);
hbos8d609f62017-04-10 07:39:05 -070060 void RemoveOutdatedSources(int64_t now_ms);
61
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062 Clock* clock_;
danilchap7c9426c2016-04-14 03:05:31 -070063 rtc::CriticalSection critical_section_rtp_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000064
Niels Möllerc9d5b052017-09-27 13:18:59 +020065 RTPPayloadRegistry* const rtp_payload_registry_
66 RTC_PT_GUARDED_BY(critical_section_rtp_receiver_);
67 const std::unique_ptr<RTPReceiverStrategy> rtp_media_receiver_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000068
Niels Möllerc9d5b052017-09-27 13:18:59 +020069 // SSRCs.
70 uint32_t ssrc_ RTC_GUARDED_BY(critical_section_rtp_receiver_);
Niels Mölleraf175952018-08-13 13:23:08 +020071
72 ContributingSources csrcs_ RTC_GUARDED_BY(critical_section_rtp_receiver_);
Niels Möllerc9d5b052017-09-27 13:18:59 +020073
Niels Möller22ec9522017-10-05 08:39:15 +020074 // Sequence number and timestamps for the latest in-order packet.
Danil Chapovalovd264df52018-06-14 12:59:38 +020075 absl::optional<uint16_t> last_received_sequence_number_
Niels Möller22ec9522017-10-05 08:39:15 +020076 RTC_GUARDED_BY(critical_section_rtp_receiver_);
Niels Möllerc9d5b052017-09-27 13:18:59 +020077 uint32_t last_received_timestamp_
78 RTC_GUARDED_BY(critical_section_rtp_receiver_);
79 int64_t last_received_frame_time_ms_
80 RTC_GUARDED_BY(critical_section_rtp_receiver_);
hbos8d609f62017-04-10 07:39:05 -070081
hbos8d609f62017-04-10 07:39:05 -070082 // The RtpSource objects are sorted chronologically.
hbos8d609f62017-04-10 07:39:05 -070083 std::vector<RtpSource> ssrc_sources_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000084};
85} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020086#endif // MODULES_RTP_RTCP_SOURCE_RTP_RECEIVER_IMPL_H_