blob: 204a3cee1c791063dc70c73f9ed08d839c1bf795 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "call/bitrate_allocator.h"
19#include "call/video_receive_stream.h"
20#include "call/video_send_stream.h"
21#include "common_video/libyuv/include/webrtc_libyuv.h"
Ying Wang38a31b02017-12-21 12:26:19 +000022#include "modules/video_coding/protection_bitrate_calculator.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"
26#include "video/encoder_rtcp_feedback.h"
27#include "video/send_delay_stats.h"
28#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,
66 const std::map<uint32_t, RtpPayloadState>& suspended_payload_states);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000067
Jelena Marusiccd670222015-07-16 09:30:09 +020068 ~VideoSendStream() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000069
pbos1ba8d392016-05-01 20:18:34 -070070 void SignalNetworkState(NetworkState state);
71 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000072
Jelena Marusiccd670222015-07-16 09:30:09 +020073 // webrtc::VideoSendStream implementation.
pbos1ba8d392016-05-01 20:18:34 -070074 void Start() override;
75 void Stop() override;
perkja49cbd32016-09-16 07:53:41 -070076
perkj803d97f2016-11-01 11:45:46 -070077 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
78 const DegradationPreference& degradation_preference) override;
perkja49cbd32016-09-16 07:53:41 -070079
perkj26091b12016-09-01 01:17:40 -070080 void ReconfigureVideoEncoder(VideoEncoderConfig) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000081 Stats GetStats() override;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000082
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000083 typedef std::map<uint32_t, RtpState> RtpStateMap;
Åsa Persson4bece9a2017-10-06 10:04:04 +020084 typedef std::map<uint32_t, RtpPayloadState> RtpPayloadStateMap;
palmkviste75f2042016-09-28 06:19:48 -070085
86 // Takes ownership of each file, is responsible for closing them later.
87 // Calling this method will close and finalize any current logs.
88 // Giving rtc::kInvalidPlatformFileValue in any position disables logging
89 // for the corresponding stream.
90 // If a frame to be written would make the log too large the write fails and
91 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
92 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
93 size_t byte_limit) override;
94
Åsa Persson4bece9a2017-10-06 10:04:04 +020095 void StopPermanentlyAndGetRtpStates(RtpStateMap* rtp_state_map,
96 RtpPayloadStateMap* payload_state_map);
Per83d09102016-04-15 14:59:13 +020097
nisse284542b2017-01-10 08:58:32 -080098 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -080099
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000100 private:
Sebastian Janssona45c8da2018-01-16 10:55:29 +0100101 friend class test::VideoSendStreamPeer;
102
perkj26091b12016-09-01 01:17:40 -0700103 class ConstructionTask;
104 class DestructAndGetRtpStateTask;
perkjbc75d972016-05-02 06:31:25 -0700105
Sebastian Janssona45c8da2018-01-16 10:55:29 +0100106 rtc::Optional<float> GetPacingFactorOverride() const;
107
perkj26091b12016-09-01 01:17:40 -0700108 rtc::ThreadChecker thread_checker_;
109 rtc::TaskQueue* const worker_queue_;
110 rtc::Event thread_sync_event_;
Peter Boström373284d2015-11-03 13:53:06 +0100111
112 SendStatisticsProxy stats_proxy_;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000113 const VideoSendStream::Config config_;
sprangf24a0642017-02-28 13:23:26 -0800114 const VideoEncoderConfig::ContentType content_type_;
perkj26091b12016-09-01 01:17:40 -0700115 std::unique_ptr<VideoSendStreamImpl> send_stream_;
mflodmancc3d4422017-08-03 08:27:51 -0700116 std::unique_ptr<VideoStreamEncoder> video_stream_encoder_;
perkj8eb37a32016-08-16 02:40:55 -0700117};
perkj26091b12016-09-01 01:17:40 -0700118
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000119} // namespace internal
120} // namespace webrtc
121
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200122#endif // VIDEO_VIDEO_SEND_STREAM_H_