blob: db345395357b8e3ec15754c57e4f0789ae11a80a [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
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +000011#ifndef WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_
12#define WEBRTC_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
mflodman86aabb22016-03-11 15:44:32 +010018#include "webrtc/call/bitrate_allocator.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000019#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
Per69b332d2016-06-02 15:45:42 +020020#include "webrtc/modules/video_coding/protection_bitrate_calculator.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020021#include "webrtc/rtc_base/criticalsection.h"
22#include "webrtc/rtc_base/event.h"
23#include "webrtc/rtc_base/task_queue.h"
mflodman15d83572016-10-06 08:35:11 -070024#include "webrtc/video/encoder_rtcp_feedback.h"
asapersson35151f32016-05-02 23:44:01 -070025#include "webrtc/video/send_delay_stats.h"
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000026#include "webrtc/video/send_statistics_proxy.h"
mflodmancc3d4422017-08-03 08:27:51 -070027#include "webrtc/video/video_stream_encoder.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000028#include "webrtc/video_receive_stream.h"
29#include "webrtc/video_send_stream.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000030
31namespace webrtc {
32
mflodmane3787022015-10-21 13:24:28 +020033class CallStats;
nisse559af382017-03-21 06:41:12 -070034class SendSideCongestionController;
perkj600246e2016-05-04 11:26:51 -070035class IvfFileWriter;
Peter Boströmf16fcbe2015-04-30 12:16:05 +020036class ProcessThread;
Peter Boström723ead82016-02-22 15:14:01 +010037class RtpRtcp;
nisseb8f9a322017-03-27 05:36:15 -070038class RtpTransportControllerSendInterface;
tereliusadafe0b2016-05-26 01:58:40 -070039class RtcEventLog;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000040
41namespace internal {
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000042
perkj26091b12016-09-01 01:17:40 -070043class VideoSendStreamImpl;
44
45// VideoSendStream implements webrtc::VideoSendStream.
46// Internally, it delegates all public methods to VideoSendStreamImpl and / or
mflodmancc3d4422017-08-03 08:27:51 -070047// VideoStreamEncoder. VideoSendStreamInternal is created and deleted on
48// |worker_queue|.
perkj26091b12016-09-01 01:17:40 -070049class VideoSendStream : public webrtc::VideoSendStream {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000050 public:
solenberge5269742015-09-08 05:13:22 -070051 VideoSendStream(int num_cpu_cores,
Peter Boströmf16fcbe2015-04-30 12:16:05 +020052 ProcessThread* module_process_thread,
perkj26091b12016-09-01 01:17:40 -070053 rtc::TaskQueue* worker_queue,
mflodmane3787022015-10-21 13:24:28 +020054 CallStats* call_stats,
nisseb8f9a322017-03-27 05:36:15 -070055 RtpTransportControllerSendInterface* transport,
mflodman0e7e2592015-11-12 21:02:42 -080056 BitrateAllocator* bitrate_allocator,
asapersson35151f32016-05-02 23:44:01 -070057 SendDelayStats* send_delay_stats,
tereliusadafe0b2016-05-26 01:58:40 -070058 RtcEventLog* event_log,
perkj26091b12016-09-01 01:17:40 -070059 VideoSendStream::Config config,
60 VideoEncoderConfig encoder_config,
sprange5c4a812017-07-11 03:44:17 -070061 const std::map<uint32_t, RtpState>& suspended_ssrcs,
62 const RtpKeepAliveConfig& keepalive_config);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000063
Jelena Marusiccd670222015-07-16 09:30:09 +020064 ~VideoSendStream() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000065
pbos1ba8d392016-05-01 20:18:34 -070066 void SignalNetworkState(NetworkState state);
67 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000068
Jelena Marusiccd670222015-07-16 09:30:09 +020069 // webrtc::VideoSendStream implementation.
pbos1ba8d392016-05-01 20:18:34 -070070 void Start() override;
71 void Stop() override;
perkja49cbd32016-09-16 07:53:41 -070072
perkj803d97f2016-11-01 11:45:46 -070073 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
74 const DegradationPreference& degradation_preference) override;
perkja49cbd32016-09-16 07:53:41 -070075
perkj26091b12016-09-01 01:17:40 -070076 void ReconfigureVideoEncoder(VideoEncoderConfig) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000077 Stats GetStats() override;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000078
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000079 typedef std::map<uint32_t, RtpState> RtpStateMap;
palmkviste75f2042016-09-28 06:19:48 -070080
81 // Takes ownership of each file, is responsible for closing them later.
82 // Calling this method will close and finalize any current logs.
83 // Giving rtc::kInvalidPlatformFileValue in any position disables logging
84 // for the corresponding stream.
85 // If a frame to be written would make the log too large the write fails and
86 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
87 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
88 size_t byte_limit) override;
89
perkj26091b12016-09-01 01:17:40 -070090 RtpStateMap StopPermanentlyAndGetRtpStates();
Per83d09102016-04-15 14:59:13 +020091
nisse284542b2017-01-10 08:58:32 -080092 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -080093
pbos@webrtc.org29d58392013-05-16 12:08:03 +000094 private:
perkj26091b12016-09-01 01:17:40 -070095 class ConstructionTask;
96 class DestructAndGetRtpStateTask;
perkjbc75d972016-05-02 06:31:25 -070097
perkj26091b12016-09-01 01:17:40 -070098 rtc::ThreadChecker thread_checker_;
99 rtc::TaskQueue* const worker_queue_;
100 rtc::Event thread_sync_event_;
Peter Boström373284d2015-11-03 13:53:06 +0100101
102 SendStatisticsProxy stats_proxy_;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000103 const VideoSendStream::Config config_;
sprangf24a0642017-02-28 13:23:26 -0800104 const VideoEncoderConfig::ContentType content_type_;
perkj26091b12016-09-01 01:17:40 -0700105 std::unique_ptr<VideoSendStreamImpl> send_stream_;
mflodmancc3d4422017-08-03 08:27:51 -0700106 std::unique_ptr<VideoStreamEncoder> video_stream_encoder_;
perkj8eb37a32016-08-16 02:40:55 -0700107};
perkj26091b12016-09-01 01:17:40 -0700108
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000109} // namespace internal
110} // namespace webrtc
111
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000112#endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_