OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 11 #ifndef WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
12 #define WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 12 #define WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <memory> | 15 #include <memory> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/call/bitrate_allocator.h" | 18 #include "webrtc/call/bitrate_allocator.h" |
19 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/event.h" | |
21 #include "webrtc/base/task_queue.h" | |
20 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
22 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" | 24 #include "webrtc/modules/video_coding/protection_bitrate_calculator.h" |
23 #include "webrtc/video/encoder_state_feedback.h" | 25 #include "webrtc/video/encoder_state_feedback.h" |
24 #include "webrtc/video/payload_router.h" | 26 #include "webrtc/video/payload_router.h" |
25 #include "webrtc/video/send_delay_stats.h" | 27 #include "webrtc/video/send_delay_stats.h" |
26 #include "webrtc/video/send_statistics_proxy.h" | 28 #include "webrtc/video/send_statistics_proxy.h" |
27 #include "webrtc/video/video_capture_input.h" | |
28 #include "webrtc/video/vie_encoder.h" | 29 #include "webrtc/video/vie_encoder.h" |
29 #include "webrtc/video_receive_stream.h" | 30 #include "webrtc/video_receive_stream.h" |
30 #include "webrtc/video_send_stream.h" | 31 #include "webrtc/video_send_stream.h" |
31 | 32 |
32 namespace webrtc { | 33 namespace webrtc { |
33 | 34 |
34 class BitrateAllocator; | 35 class BitrateAllocator; |
35 class CallStats; | 36 class CallStats; |
36 class CongestionController; | 37 class CongestionController; |
37 class IvfFileWriter; | 38 class IvfFileWriter; |
38 class ProcessThread; | 39 class ProcessThread; |
39 class RtpRtcp; | 40 class RtpRtcp; |
40 class ViEEncoder; | |
41 class VieRemb; | 41 class VieRemb; |
42 class RtcEventLog; | 42 class RtcEventLog; |
43 | 43 |
44 namespace vcm { | |
45 class VideoSender; | |
46 } // namespace vcm | |
47 | |
48 namespace internal { | 44 namespace internal { |
49 | 45 |
50 class VideoSendStream : public webrtc::VideoSendStream, | 46 class VideoSendStreamInternal; |
51 public webrtc::CpuOveruseObserver, | 47 |
52 public webrtc::BitrateAllocatorObserver, | 48 // VideoSendStream implements webrtc::VideoSendStream. |
53 public webrtc::VCMProtectionCallback, | 49 // Internally, it delegates all public methods to VideoSendStreamInternal. |
54 public EncodedImageCallback { | 50 // VideoSendStreamInternal is created and deleted on |worker_queue|. |
51 class VideoSendStream : public webrtc::VideoSendStream { | |
55 public: | 52 public: |
56 VideoSendStream(int num_cpu_cores, | 53 VideoSendStream(int num_cpu_cores, |
57 ProcessThread* module_process_thread, | 54 ProcessThread* module_process_thread, |
55 rtc::TaskQueue* worker_queue, | |
58 CallStats* call_stats, | 56 CallStats* call_stats, |
59 CongestionController* congestion_controller, | 57 CongestionController* congestion_controller, |
60 BitrateAllocator* bitrate_allocator, | 58 BitrateAllocator* bitrate_allocator, |
61 SendDelayStats* send_delay_stats, | 59 SendDelayStats* send_delay_stats, |
62 VieRemb* remb, | 60 VieRemb* remb, |
63 RtcEventLog* event_log, | 61 RtcEventLog* event_log, |
64 const VideoSendStream::Config& config, | 62 VideoSendStream::Config config, |
65 const VideoEncoderConfig& encoder_config, | 63 VideoEncoderConfig encoder_config, |
66 const std::map<uint32_t, RtpState>& suspended_ssrcs); | 64 const std::map<uint32_t, RtpState>& suspended_ssrcs); |
67 | 65 |
68 ~VideoSendStream() override; | 66 ~VideoSendStream() override; |
69 | 67 |
70 void SignalNetworkState(NetworkState state); | 68 void SignalNetworkState(NetworkState state); |
71 bool DeliverRtcp(const uint8_t* packet, size_t length); | 69 bool DeliverRtcp(const uint8_t* packet, size_t length); |
72 | 70 |
73 // webrtc::VideoSendStream implementation. | 71 // webrtc::VideoSendStream implementation. |
74 void Start() override; | 72 void Start() override; |
75 void Stop() override; | 73 void Stop() override; |
76 VideoCaptureInput* Input() override; | 74 VideoCaptureInput* Input() override; |
77 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; | 75 void ReconfigureVideoEncoder(VideoEncoderConfig) override; |
78 Stats GetStats() override; | 76 Stats GetStats() override; |
79 | 77 |
80 // webrtc::CpuOveruseObserver implementation. | 78 typedef std::map<uint32_t, RtpState> RtpStateMap; |
81 void OveruseDetected() override; | 79 RtpStateMap StopPermanentlyAndGetRtpStates(); |
82 void NormalUsage() override; | |
83 | 80 |
84 typedef std::map<uint32_t, RtpState> RtpStateMap; | 81 private: |
85 RtpStateMap GetRtpStates() const; | 82 class ConstructionTask; |
83 class DestructAndGetRTPStateTask; | |
86 | 84 |
87 int GetPaddingNeededBps() const; | 85 rtc::ThreadChecker thread_checker_; |
86 rtc::TaskQueue* const worker_queue_; | |
87 rtc::Event thread_sync_event_; | |
88 | |
89 SendStatisticsProxy stats_proxy_; | |
90 const VideoSendStream::Config config_; | |
91 std::unique_ptr<VideoSendStreamInternal> send_stream_; | |
92 std::unique_ptr<ViEEncoder> vie_encoder_; | |
93 }; | |
94 | |
95 class VideoSendStreamInternal : public webrtc::BitrateAllocatorObserver, | |
96 public webrtc::VCMProtectionCallback, | |
97 public EncodedImageCallback { | |
98 public: | |
99 VideoSendStreamInternal(SendStatisticsProxy* stats_proxy, | |
100 rtc::TaskQueue* worker_queue, | |
101 CallStats* call_stats, | |
102 CongestionController* congestion_controller, | |
103 BitrateAllocator* bitrate_allocator, | |
104 SendDelayStats* send_delay_stats, | |
105 VieRemb* remb, | |
106 ViEEncoder* vie_encoder, | |
107 RtcEventLog* event_log, | |
108 const VideoSendStream::Config* config, | |
109 std::map<uint32_t, RtpState> suspended_ssrcs); | |
tommi
2016/07/06 11:15:02
will be the map be passed in via move()?
perkj_webrtc
2016/07/06 13:08:54
yes
| |
110 ~VideoSendStreamInternal() override; | |
111 | |
112 // RegisterProcessThread register |module_process_thread| with those objects | |
113 // that use it. Registration have to happen on the thread where | |
114 // |module_process_thread| where created (libjingles worker thread). | |
115 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, | |
116 // maybe |worker_queue|. | |
117 void RegisterProcessThread(ProcessThread* module_process_thread); | |
118 void DeRegisterProcessThread(); | |
119 | |
120 void SignalNetworkState(NetworkState state); | |
121 bool DeliverRtcp(const uint8_t* packet, size_t length); | |
122 void Start(); | |
123 void Stop(); | |
124 | |
125 void ReconfigureVideoEncoder(const VideoEncoderConfig& config); | |
126 VideoSendStream::RtpStateMap GetRtpStates() const; | |
tommi
2016/07/06 11:15:02
by-value on purpose?
perkj_webrtc
2016/07/06 13:08:54
Yes, same as before. See VideoSendStream::GetRtpSt
| |
88 | 127 |
89 // Implements BitrateAllocatorObserver. | 128 // Implements BitrateAllocatorObserver. |
90 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, | 129 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, |
91 uint8_t fraction_loss, | 130 uint8_t fraction_loss, |
92 int64_t rtt) override; | 131 int64_t rtt) override; |
93 | 132 |
94 protected: | 133 protected: |
95 // Implements webrtc::VCMProtectionCallback. | 134 // Implements webrtc::VCMProtectionCallback. |
96 int ProtectionRequest(const FecProtectionParams* delta_params, | 135 int ProtectionRequest(const FecProtectionParams* delta_params, |
97 const FecProtectionParams* key_params, | 136 const FecProtectionParams* key_params, |
98 uint32_t* sent_video_rate_bps, | 137 uint32_t* sent_video_rate_bps, |
99 uint32_t* sent_nack_rate_bps, | 138 uint32_t* sent_nack_rate_bps, |
100 uint32_t* sent_fec_rate_bps) override; | 139 uint32_t* sent_fec_rate_bps) override; |
101 | 140 |
102 private: | 141 private: |
103 struct EncoderSettings { | 142 class CheckEncoderActivityTask; |
104 VideoCodec video_codec; | |
105 VideoEncoderConfig config; | |
106 }; | |
107 | 143 |
108 // Implements EncodedImageCallback. The implementation routes encoded frames | 144 // Implements EncodedImageCallback. The implementation routes encoded frames |
109 // to the |payload_router_| and |config.pre_encode_callback| if set. | 145 // to the |payload_router_| and |config.pre_encode_callback| if set. |
110 // Called on an arbitrary encoder callback thread. | 146 // Called on an arbitrary encoder callback thread. |
111 int32_t Encoded(const EncodedImage& encoded_image, | 147 int32_t Encoded(const EncodedImage& encoded_image, |
112 const CodecSpecificInfo* codec_specific_info, | 148 const CodecSpecificInfo* codec_specific_info, |
113 const RTPFragmentationHeader* fragmentation) override; | 149 const RTPFragmentationHeader* fragmentation) override; |
114 | 150 |
115 static bool EncoderThreadFunction(void* obj); | |
116 void EncoderProcess(); | |
117 | |
118 void ConfigureProtection(); | 151 void ConfigureProtection(); |
119 void ConfigureSsrcs(); | 152 void ConfigureSsrcs(); |
153 void EncoderTimedOut(); | |
154 void EncoderIsActive(); | |
120 | 155 |
121 SendStatisticsProxy stats_proxy_; | 156 SendStatisticsProxy* const stats_proxy_; |
122 const VideoSendStream::Config config_; | 157 const VideoSendStream::Config* const config_; |
123 std::map<uint32_t, RtpState> suspended_ssrcs_; | 158 std::map<uint32_t, RtpState> suspended_ssrcs_; |
124 | 159 |
125 ProcessThread* const module_process_thread_; | 160 ProcessThread* module_process_thread_; |
161 rtc::ThreadChecker module_process_thread_checker_; | |
162 rtc::TaskQueue* const worker_queue_; | |
163 | |
164 rtc::CriticalSection encoder_activity_crit_sect_; | |
165 CheckEncoderActivityTask* check_encoder_activity_task_ | |
166 GUARDED_BY(encoder_activity_crit_sect_); | |
126 CallStats* const call_stats_; | 167 CallStats* const call_stats_; |
127 CongestionController* const congestion_controller_; | 168 CongestionController* const congestion_controller_; |
128 BitrateAllocator* const bitrate_allocator_; | 169 BitrateAllocator* const bitrate_allocator_; |
129 VieRemb* const remb_; | 170 VieRemb* const remb_; |
130 | 171 |
131 static const bool kEnableFrameRecording = false; | 172 static const bool kEnableFrameRecording = false; |
132 static const int kMaxLayers = 3; | 173 static const int kMaxLayers = 3; |
133 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; | 174 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; |
134 | 175 |
135 rtc::PlatformThread encoder_thread_; | 176 int max_padding_bitrate_; |
136 rtc::Event encoder_wakeup_event_; | 177 int encoder_min_bitrate_bps_; |
137 volatile int stop_encoder_thread_; | 178 int encoder_max_bitrate_bps_; |
138 rtc::CriticalSection encoder_settings_crit_; | 179 uint32_t encoder_target_rate_; |
139 std::unique_ptr<EncoderSettings> pending_encoder_settings_ | |
140 GUARDED_BY(encoder_settings_crit_); | |
141 | 180 |
142 enum class State { | 181 ViEEncoder* const vie_encoder_; |
143 kStopped, // VideoSendStream::Start has not yet been called. | |
144 kStarted, // VideoSendStream::Start has been called. | |
145 // VideoSendStream::Start has been called but the encoder have timed out. | |
146 kEncoderTimedOut, | |
147 }; | |
148 rtc::Optional<State> pending_state_change_ GUARDED_BY(encoder_settings_crit_); | |
149 | |
150 // Only used on the encoder thread. | |
151 rtc::ThreadChecker encoder_thread_checker_; | |
152 State state_ ACCESS_ON(&encoder_thread_checker_); | |
153 std::unique_ptr<EncoderSettings> current_encoder_settings_ | |
154 ACCESS_ON(&encoder_thread_checker_); | |
155 | |
156 OveruseFrameDetector overuse_detector_; | |
157 ViEEncoder vie_encoder_; | |
158 EncoderStateFeedback encoder_feedback_; | 182 EncoderStateFeedback encoder_feedback_; |
159 ProtectionBitrateCalculator protection_bitrate_calculator_; | 183 ProtectionBitrateCalculator protection_bitrate_calculator_; |
160 | 184 |
161 vcm::VideoSender* const video_sender_; | |
162 | |
163 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 185 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
164 // RtpRtcp modules, declared here as they use other members on construction. | 186 // RtpRtcp modules, declared here as they use other members on construction. |
165 const std::vector<RtpRtcp*> rtp_rtcp_modules_; | 187 const std::vector<RtpRtcp*> rtp_rtcp_modules_; |
166 PayloadRouter payload_router_; | 188 PayloadRouter payload_router_; |
167 VideoCaptureInput input_; | |
168 }; | 189 }; |
169 } // namespace internal | 190 } // namespace internal |
170 } // namespace webrtc | 191 } // namespace webrtc |
171 | 192 |
172 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 193 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
OLD | NEW |