blob: ff52c031af73b491cbbf41d8e9880edca3d40052 [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"
pbos14fe7082016-04-20 06:35:56 -070019#include "webrtc/base/criticalsection.h"
perkj26091b12016-09-01 01:17:40 -070020#include "webrtc/base/event.h"
21#include "webrtc/base/task_queue.h"
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000022#include "webrtc/call.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000023#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
Per69b332d2016-06-02 15:45:42 +020024#include "webrtc/modules/video_coding/protection_bitrate_calculator.h"
mflodman15d83572016-10-06 08:35:11 -070025#include "webrtc/video/encoder_rtcp_feedback.h"
Peter Boström1d04ac62016-02-05 11:25:46 +010026#include "webrtc/video/payload_router.h"
asapersson35151f32016-05-02 23:44:01 -070027#include "webrtc/video/send_delay_stats.h"
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000028#include "webrtc/video/send_statistics_proxy.h"
Peter Boström8c66a002016-02-11 13:51:10 +010029#include "webrtc/video/vie_encoder.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000030#include "webrtc/video_receive_stream.h"
31#include "webrtc/video_send_stream.h"
pbos@webrtc.org29d58392013-05-16 12:08:03 +000032
33namespace webrtc {
34
mflodman0e7e2592015-11-12 21:02:42 -080035class BitrateAllocator;
mflodmane3787022015-10-21 13:24:28 +020036class CallStats;
mflodman0c478b32015-10-21 15:52:16 +020037class CongestionController;
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;
Stefan Holmer58c664c2016-02-08 14:31:30 +010041class VieRemb;
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
50// VieEncoder. VideoSendStreamInternal is created and deleted on |worker_queue|.
51class VideoSendStream : public webrtc::VideoSendStream {
pbos@webrtc.org29d58392013-05-16 12:08:03 +000052 public:
solenberge5269742015-09-08 05:13:22 -070053 VideoSendStream(int num_cpu_cores,
Peter Boströmf16fcbe2015-04-30 12:16:05 +020054 ProcessThread* module_process_thread,
perkj26091b12016-09-01 01:17:40 -070055 rtc::TaskQueue* worker_queue,
mflodmane3787022015-10-21 13:24:28 +020056 CallStats* call_stats,
mflodman0c478b32015-10-21 15:52:16 +020057 CongestionController* congestion_controller,
mflodman0e7e2592015-11-12 21:02:42 -080058 BitrateAllocator* bitrate_allocator,
asapersson35151f32016-05-02 23:44:01 -070059 SendDelayStats* send_delay_stats,
mflodman86aabb22016-03-11 15:44:32 +010060 VieRemb* remb,
tereliusadafe0b2016-05-26 01:58:40 -070061 RtcEventLog* event_log,
perkj26091b12016-09-01 01:17:40 -070062 VideoSendStream::Config config,
63 VideoEncoderConfig encoder_config,
Peter Boström45553ae2015-05-08 13:54:38 +020064 const std::map<uint32_t, RtpState>& suspended_ssrcs);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000065
Jelena Marusiccd670222015-07-16 09:30:09 +020066 ~VideoSendStream() override;
pbos@webrtc.org29d58392013-05-16 12:08:03 +000067
pbos1ba8d392016-05-01 20:18:34 -070068 void SignalNetworkState(NetworkState state);
69 bool DeliverRtcp(const uint8_t* packet, size_t length);
pbos@webrtc.org29d58392013-05-16 12:08:03 +000070
Jelena Marusiccd670222015-07-16 09:30:09 +020071 // webrtc::VideoSendStream implementation.
pbos1ba8d392016-05-01 20:18:34 -070072 void Start() override;
73 void Stop() override;
perkja49cbd32016-09-16 07:53:41 -070074
perkj803d97f2016-11-01 11:45:46 -070075 void SetSource(rtc::VideoSourceInterface<webrtc::VideoFrame>* source,
76 const DegradationPreference& degradation_preference) override;
perkja49cbd32016-09-16 07:53:41 -070077
perkj26091b12016-09-01 01:17:40 -070078 void ReconfigureVideoEncoder(VideoEncoderConfig) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000079 Stats GetStats() override;
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000080
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +000081 typedef std::map<uint32_t, RtpState> RtpStateMap;
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
perkj26091b12016-09-01 01:17:40 -070092 RtpStateMap StopPermanentlyAndGetRtpStates();
Per83d09102016-04-15 14:59:13 +020093
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_;
perkj26091b12016-09-01 01:17:40 -0700104 std::unique_ptr<VideoSendStreamImpl> send_stream_;
105 std::unique_ptr<ViEEncoder> vie_encoder_;
perkj8eb37a32016-08-16 02:40:55 -0700106};
perkj26091b12016-09-01 01:17:40 -0700107
pbos@webrtc.org29d58392013-05-16 12:08:03 +0000108} // namespace internal
109} // namespace webrtc
110
mflodman@webrtc.orgf3973e82013-12-13 09:40:45 +0000111#endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_