blob: 1735dc751ae2b5c18a85343a8d46aa523b530ca5 [file] [log] [blame]
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +00001/*
2 * Copyright (c) 2015 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
Stefan Holmer9416ef82018-07-19 10:34:38 +020011#ifndef CALL_RTP_VIDEO_SENDER_H_
12#define CALL_RTP_VIDEO_SENDER_H_
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000013
Åsa Persson4bece9a2017-10-06 10:04:04 +020014#include <map>
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020015#include <memory>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000016#include <vector>
17
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020018#include "api/call/transport.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/video_codecs/video_encoder.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020020#include "call/rtp_config.h"
Stefan Holmerf7044682018-07-17 10:16:41 +020021#include "call/rtp_payload_params.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020022#include "call/rtp_transport_controller_send_interface.h"
Stefan Holmer9416ef82018-07-19 10:34:38 +020023#include "call/rtp_video_sender_interface.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020024#include "common_types.h" // NOLINT(build/include)
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020025#include "logging/rtc_event_log/rtc_event_log.h"
26#include "modules/rtp_rtcp/include/flexfec_sender.h"
philipel1a4746a2018-07-09 15:52:29 +020027#include "modules/rtp_rtcp/source/rtp_video_header.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020028#include "modules/utility/include/process_thread.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/constructormagic.h"
30#include "rtc_base/criticalsection.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020031#include "rtc_base/rate_limiter.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_base/thread_annotations.h"
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020033#include "rtc_base/thread_checker.h"
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000034
35namespace webrtc {
36
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000037class RTPFragmentationHeader;
38class RtpRtcp;
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020039class RtpTransportControllerSendInterface;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000040
Stefan Holmer9416ef82018-07-19 10:34:38 +020041// RtpVideoSender routes outgoing data to the correct sending RTP module, based
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000042// on the simulcast layer in RTPVideoHeader.
Stefan Holmer9416ef82018-07-19 10:34:38 +020043class RtpVideoSender : public RtpVideoSenderInterface {
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000044 public:
Per83d09102016-04-15 14:59:13 +020045 // Rtp modules are assumed to be sorted in simulcast index order.
Stefan Holmer9416ef82018-07-19 10:34:38 +020046 RtpVideoSender(
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020047 const std::vector<uint32_t>& ssrcs,
48 std::map<uint32_t, RtpState> suspended_ssrcs,
49 const std::map<uint32_t, RtpPayloadState>& states,
50 const RtpConfig& rtp_config,
51 const RtcpConfig& rtcp_config,
52 Transport* send_transport,
53 const RtpSenderObservers& observers,
54 RtpTransportControllerSendInterface* transport,
55 RtcEventLog* event_log,
56 RateLimiter* retransmission_limiter); // move inside RtpTransport
Stefan Holmer9416ef82018-07-19 10:34:38 +020057 ~RtpVideoSender() override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000058
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020059 // RegisterProcessThread register |module_process_thread| with those objects
60 // that use it. Registration has to happen on the thread were
61 // |module_process_thread| was created (libjingle's worker thread).
62 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue,
63 // maybe |worker_queue|.
64 void RegisterProcessThread(ProcessThread* module_process_thread) override;
65 void DeRegisterProcessThread() override;
66
Stefan Holmer9416ef82018-07-19 10:34:38 +020067 // RtpVideoSender will only route packets if being active, all packets will be
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000068 // dropped otherwise.
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020069 void SetActive(bool active) override;
Seth Hampsoncc7125f2018-02-02 08:46:16 -080070 // Sets the sending status of the rtp modules and appropriately sets the
71 // payload router to active if any rtp modules are active.
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020072 void SetActiveModules(const std::vector<bool> active_modules) override;
73 bool IsActive() override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000074
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020075 void OnNetworkAvailability(bool network_available) override;
76 std::map<uint32_t, RtpState> GetRtpStates() const override;
77 std::map<uint32_t, RtpPayloadState> GetRtpPayloadStates() const override;
78
79 bool FecEnabled() const override;
80
81 bool NackEnabled() const override;
82
83 void DeliverRtcp(const uint8_t* packet, size_t length) override;
84
85 void ProtectionRequest(const FecProtectionParams* delta_params,
86 const FecProtectionParams* key_params,
87 uint32_t* sent_video_rate_bps,
88 uint32_t* sent_nack_rate_bps,
89 uint32_t* sent_fec_rate_bps) override;
90
91 void SetMaxRtpPacketSize(size_t max_rtp_packet_size) override;
Åsa Persson4bece9a2017-10-06 10:04:04 +020092
kjellander02b3d272016-04-20 05:05:54 -070093 // Implements EncodedImageCallback.
94 // Returns 0 if the packet was routed / sent, -1 otherwise.
Sergey Ulanov525df3f2016-08-02 17:46:41 -070095 EncodedImageCallback::Result OnEncodedImage(
96 const EncodedImage& encoded_image,
97 const CodecSpecificInfo* codec_specific_info,
98 const RTPFragmentationHeader* fragmentation) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000099
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200100 void OnBitrateAllocationUpdated(
101 const VideoBitrateAllocation& bitrate) override;
sprang1a646ee2016-12-01 06:34:11 -0800102
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000103 private:
danilchapa37de392017-09-09 04:17:22 -0700104 void UpdateModuleSendingState() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200105 void ConfigureProtection(const RtpConfig& rtp_config);
106 void ConfigureSsrcs(const RtpConfig& rtp_config);
Peter Boström8b79b072016-02-26 16:31:37 +0100107
pbosd8de1152016-02-01 09:00:51 -0800108 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -0700109 bool active_ RTC_GUARDED_BY(crit_);
mflodman@webrtc.org7ac374a2015-02-20 12:45:40 +0000110
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200111 ProcessThread* module_process_thread_;
112 rtc::ThreadChecker module_process_thread_checker_;
113 std::map<uint32_t, RtpState> suspended_ssrcs_;
114
115 std::unique_ptr<FlexfecSender> flexfec_sender_;
Niels Möller2a152672018-08-08 12:03:00 +0200116 // Rtp modules are assumed to be sorted in simulcast index order.
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200117 const std::vector<std::unique_ptr<RtpRtcp>> rtp_modules_;
118 const RtpConfig rtp_config_;
119 RtpTransportControllerSendInterface* const transport_;
Per83d09102016-04-15 14:59:13 +0200120
philipel25d31ec2018-08-08 16:33:01 +0200121 // When using the generic descriptor we want all simulcast streams to share
122 // one frame id space (so that the SFU can switch stream without having to
123 // rewrite the frame id), therefore |shared_frame_id| has to live in a place
124 // where we are aware of all the different streams.
125 int64_t shared_frame_id_ = 0;
Åsa Persson4bece9a2017-10-06 10:04:04 +0200126 std::vector<RtpPayloadParams> params_ RTC_GUARDED_BY(crit_);
127
Stefan Holmer9416ef82018-07-19 10:34:38 +0200128 RTC_DISALLOW_COPY_AND_ASSIGN(RtpVideoSender);
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +0000129};
130
131} // namespace webrtc
132
Stefan Holmer9416ef82018-07-19 10:34:38 +0200133#endif // CALL_RTP_VIDEO_SENDER_H_