blob: 998250cd6e4448afe92e47c5852e232c333d1bdf [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"
22#include "modules/video_coding/protection_bitrate_calculator.h"
23#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 {
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:
Åsa Persson4bece9a2017-10-06 10:04:04 +020051 VideoSendStream(
52 int num_cpu_cores,
53 ProcessThread* module_process_thread,
54 rtc::TaskQueue* worker_queue,
55 CallStats* call_stats,
56 RtpTransportControllerSendInterface* transport,
57 BitrateAllocator* bitrate_allocator,
58 SendDelayStats* send_delay_stats,
59 RtcEventLog* event_log,
60 VideoSendStream::Config config,
61 VideoEncoderConfig encoder_config,
62 const std::map<uint32_t, RtpState>& suspended_ssrcs,
63 const std::map<uint32_t, RtpPayloadState>& suspended_payload_states);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000064
Jelena Marusiccd670222015-07-16 09:30:09 +020065 ~VideoSendStream() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000066
pbos1ba8d392016-05-01 20:18:34 -070067 void SignalNetworkState(NetworkState state);
68 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000069
Jelena Marusiccd670222015-07-16 09:30:09 +020070 // webrtc::VideoSendStream implementation.
pbos1ba8d392016-05-01 20:18:34 -070071 void Start() override;
72 void Stop() override;
perkja49cbd32016-09-16 07:53:41 -070073
perkj803d97f2016-11-01 11:45:46 -070074 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
75 const DegradationPreference& degradation_preference) override;
perkja49cbd32016-09-16 07:53:41 -070076
perkj26091b12016-09-01 01:17:40 -070077 void ReconfigureVideoEncoder(VideoEncoderConfig) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000078 Stats GetStats() override;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000079
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000080 typedef std::map<uint32_t, RtpState> RtpStateMap;
Åsa Persson4bece9a2017-10-06 10:04:04 +020081 typedef std::map<uint32_t, RtpPayloadState> RtpPayloadStateMap;
palmkviste75f2042016-09-28 06:19:48 -070082
83 // Takes ownership of each file, is responsible for closing them later.
84 // Calling this method will close and finalize any current logs.
85 // Giving rtc::kInvalidPlatformFileValue in any position disables logging
86 // for the corresponding stream.
87 // If a frame to be written would make the log too large the write fails and
88 // the log is closed and finalized. A |byte_limit| of 0 means no limit.
89 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
90 size_t byte_limit) override;
91
Åsa Persson4bece9a2017-10-06 10:04:04 +020092 void StopPermanentlyAndGetRtpStates(RtpStateMap* rtp_state_map,
93 RtpPayloadStateMap* payload_state_map);
Per83d09102016-04-15 14:59:13 +020094
nisse284542b2017-01-10 08:58:32 -080095 void SetTransportOverhead(size_t transport_overhead_per_packet);
michaelt79e05882016-11-08 02:50:09 -080096
pbos@webrtc.org29d58392013-05-16 12:08:03 +000097 private:
perkj26091b12016-09-01 01:17:40 -070098 class ConstructionTask;
99 class DestructAndGetRtpStateTask;
perkjbc75d972016-05-02 06:31:25 -0700100
perkj26091b12016-09-01 01:17:40 -0700101 rtc::ThreadChecker thread_checker_;
102 rtc::TaskQueue* const worker_queue_;
103 rtc::Event thread_sync_event_;
Peter Boström373284d2015-11-03 13:53:06 +0100104
105 SendStatisticsProxy stats_proxy_;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000106 const VideoSendStream::Config config_;
sprangf24a0642017-02-28 13:23:26 -0800107 const VideoEncoderConfig::ContentType content_type_;
perkj26091b12016-09-01 01:17:40 -0700108 std::unique_ptr<VideoSendStreamImpl> send_stream_;
mflodmancc3d4422017-08-03 08:27:51 -0700109 std::unique_ptr<VideoStreamEncoder> video_stream_encoder_;
perkj8eb37a32016-08-16 02:40:55 -0700110};
perkj26091b12016-09-01 01:17:40 -0700111
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000112} // namespace internal
113} // namespace webrtc
114
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200115#endif // VIDEO_VIDEO_SEND_STREAM_H_