blob: a41add8e9ef24cb2f0bed06cdb4a1b45d1899fe7 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:03 +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 VIDEO_VIDEO_SEND_STREAM_H_
12#define VIDEO_VIDEO_SEND_STREAM_H_
pbos@webrtc.org29d58392013-05-16 12:08:03 +000013
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000014#include <map>
kwibergbfefb032016-05-01 14:53:46 -070015#include <memory>
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +000016#include <vector>
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000017
Ying Wang3b790f32018-01-19 17:58:57 +010018#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "call/bitrate_allocator.h"
20#include "call/video_receive_stream.h"
21#include "call/video_send_stream.h"
22#include "common_video/libyuv/include/webrtc_libyuv.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/criticalsection.h"
24#include "rtc_base/event.h"
25#include "rtc_base/task_queue.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "video/send_delay_stats.h"
Niels Möller9d138fc2018-02-15 16:58:43 +010027#include "video/payload_router.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "video/send_statistics_proxy.h"
29#include "video/video_stream_encoder.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000030
31namespace webrtc {
Sebastian Janssona45c8da2018-01-16 10:55:29 +010032namespace test {
33class VideoSendStreamPeer;
34} // namespace test
pbos@webrtc.org29d58392013-05-16 12:08:03 +000035
mflodmane3787022015-10-21 13:24:28 +020036class CallStats;
nisse559af382017-03-21 06:41:12 -070037class SendSideCongestionController;
perkj600246e2016-05-04 11:26:51 -070038class IvfFileWriter;
Peter Boströmf16fcbe2015-04-30 12:16:05 +020039class ProcessThread;
Peter Boström723ead82016-02-22 15:14:01 +010040class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070041class RtpTransportControllerSendInterface;
tereliusadafe0b2016-05-26 01:58:40 -070042class RtcEventLog;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000043
44namespace internal {
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000045
perkj26091b12016-09-01 01:17:40 -070046class VideoSendStreamImpl;
47
48// VideoSendStream implements webrtc::VideoSendStream.
49// Internally, it delegates all public methods to VideoSendStreamImpl and / or
mflodmancc3d4422017-08-03 08:27:51 -070050// VideoStreamEncoder. VideoSendStreamInternal is created and deleted on
51// |worker_queue|.
perkj26091b12016-09-01 01:17:40 -070052class VideoSendStream : public webrtc::VideoSendStream {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000053 public:
Åsa Persson4bece9a2017-10-06 10:04:04 +020054 VideoSendStream(
55 int num_cpu_cores,
56 ProcessThread* module_process_thread,
57 rtc::TaskQueue* worker_queue,
58 CallStats* call_stats,
59 RtpTransportControllerSendInterface* transport,
60 BitrateAllocator* bitrate_allocator,
61 SendDelayStats* send_delay_stats,
62 RtcEventLog* event_log,
63 VideoSendStream::Config config,
64 VideoEncoderConfig encoder_config,
65 const std::map<uint32_t, RtpState>& suspended_ssrcs,
Ying Wang3b790f32018-01-19 17:58:57 +010066 const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
Sebastian Jansson25e51102018-03-01 15:56:47 +010067 std::unique_ptr<FecController> fec_controller,
68 RateLimiter* retransmission_limiter);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000069
Jelena Marusiccd670222015-07-16 09:30:09 +020070 ~VideoSendStream() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000071
pbos1ba8d392016-05-01 20:18:34 -070072 void SignalNetworkState(NetworkState state);
73 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000074
Jelena Marusiccd670222015-07-16 09:30:09 +020075 // webrtc::VideoSendStream implementation.
Seth Hampsoncc7125f2018-02-02 08:46:16 -080076 void UpdateActiveSimulcastLayers(
77 const std::vector<bool> active_layers) override;
pbos1ba8d392016-05-01 20:18:34 -070078 void Start() override;
79 void Stop() override;
perkja49cbd32016-09-16 07:53:41 -070080
perkj803d97f2016-11-01 11:45:46 -070081 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
82 const DegradationPreference& degradation_preference) override;
perkja49cbd32016-09-16 07:53:41 -070083
perkj26091b12016-09-01 01:17:40 -070084 void ReconfigureVideoEncoder(VideoEncoderConfig) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000085 Stats GetStats() override;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000086
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000087 typedef std::map<uint32_t, RtpState> RtpStateMap;
Åsa Persson4bece9a2017-10-06 10:04:04 +020088 typedef std::map<uint32_t, RtpPayloadState> RtpPayloadStateMap;
palmkviste75f2042016-09-28 06:19:48 -070089
90 // Takes ownership of each file, is responsible for closing them later.
91 // Calling this method will close and finalize any current logs.
92 // Giving rtc::kInvalidPlatformFileValue in any position disables logging
93 // for the corresponding stream.
94 // If a frame to be written would make the log too large the write fails and
95 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
96 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
97 size_t byte_limit) override;
98
Åsa Persson4bece9a2017-10-06 10:04:04 +020099 void StopPermanentlyAndGetRtpStates(RtpStateMap* rtp_state_map,
100 RtpPayloadStateMap* payload_state_map);
Per83d09102016-04-15 14:59:13 +0200101
nisse284542b2017-01-10 08:58:32 -0800102 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -0800103
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000104 private:
Sebastian Janssona45c8da2018-01-16 10:55:29 +0100105 friend class test::VideoSendStreamPeer;
106
perkj26091b12016-09-01 01:17:40 -0700107 class ConstructionTask;
perkjbc75d972016-05-02 06:31:25 -0700108
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200109 absl::optional<float> GetPacingFactorOverride() const;
Sebastian Janssona45c8da2018-01-16 10:55:29 +0100110
perkj26091b12016-09-01 01:17:40 -0700111 rtc::ThreadChecker thread_checker_;
112 rtc::TaskQueue* const worker_queue_;
113 rtc::Event thread_sync_event_;
Peter Boström373284d2015-11-03 13:53:06 +0100114
115 SendStatisticsProxy stats_proxy_;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000116 const VideoSendStream::Config config_;
sprangf24a0642017-02-28 13:23:26 -0800117 const VideoEncoderConfig::ContentType content_type_;
perkj26091b12016-09-01 01:17:40 -0700118 std::unique_ptr<VideoSendStreamImpl> send_stream_;
mflodmancc3d4422017-08-03 08:27:51 -0700119 std::unique_ptr<VideoStreamEncoder> video_stream_encoder_;
perkj8eb37a32016-08-16 02:40:55 -0700120};
perkj26091b12016-09-01 01:17:40 -0700121
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000122} // namespace internal
123} // namespace webrtc
124
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200125#endif // VIDEO_VIDEO_SEND_STREAM_H_