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/encoded_frame_callback_adapter.h" | 25 #include "webrtc/video/encoded_frame_callback_adapter.h" |
24 #include "webrtc/video/encoder_state_feedback.h" | 26 #include "webrtc/video/encoder_state_feedback.h" |
25 #include "webrtc/video/payload_router.h" | 27 #include "webrtc/video/payload_router.h" |
26 #include "webrtc/video/send_delay_stats.h" | 28 #include "webrtc/video/send_delay_stats.h" |
27 #include "webrtc/video/send_statistics_proxy.h" | 29 #include "webrtc/video/send_statistics_proxy.h" |
28 #include "webrtc/video/video_capture_input.h" | 30 #include "webrtc/video/video_capture_input.h" |
29 #include "webrtc/video/vie_encoder.h" | 31 #include "webrtc/video/vie_encoder.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
41 class ViEEncoder; | 43 class ViEEncoder; |
42 class VieRemb; | 44 class VieRemb; |
43 class RtcEventLog; | 45 class RtcEventLog; |
44 | 46 |
45 namespace vcm { | 47 namespace vcm { |
46 class VideoSender; | 48 class VideoSender; |
47 } // namespace vcm | 49 } // namespace vcm |
48 | 50 |
49 namespace internal { | 51 namespace internal { |
50 | 52 |
51 class VideoSendStream : public webrtc::VideoSendStream, | 53 class VideoSendStreamInternal; |
52 public webrtc::CpuOveruseObserver, | 54 |
53 public webrtc::BitrateAllocatorObserver, | 55 // VideoSendStream implements webrtc::VideoSendStream. |
54 public webrtc::VCMProtectionCallback, | 56 // Internally, it delegates all public methods to VideoSendStreamInternal. |
55 public EncodedImageCallback { | 57 // VideoSendStreamInternal in created and destructed on |worker_queu|. |
58 class VideoSendStream : public webrtc::VideoSendStream { | |
56 public: | 59 public: |
57 VideoSendStream(int num_cpu_cores, | 60 VideoSendStream(int num_cpu_cores, |
58 ProcessThread* module_process_thread, | 61 ProcessThread* module_process_thread, |
62 rtc::TaskQueue* worker_queu, | |
tommi
2016/06/17 07:59:01
worker_queue
perkj_webrtc
2016/06/27 14:34:35
Done.
| |
59 CallStats* call_stats, | 63 CallStats* call_stats, |
60 CongestionController* congestion_controller, | 64 CongestionController* congestion_controller, |
61 BitrateAllocator* bitrate_allocator, | 65 BitrateAllocator* bitrate_allocator, |
62 SendDelayStats* send_delay_stats, | 66 SendDelayStats* send_delay_stats, |
63 VieRemb* remb, | 67 VieRemb* remb, |
64 RtcEventLog* event_log, | 68 RtcEventLog* event_log, |
65 const VideoSendStream::Config& config, | 69 const VideoSendStream::Config& config, |
66 const VideoEncoderConfig& encoder_config, | 70 const VideoEncoderConfig& encoder_config, |
67 const std::map<uint32_t, RtpState>& suspended_ssrcs); | 71 const std::map<uint32_t, RtpState>& suspended_ssrcs); |
68 | 72 |
69 ~VideoSendStream() override; | 73 ~VideoSendStream() override; |
70 | 74 |
71 void SignalNetworkState(NetworkState state); | 75 void SignalNetworkState(NetworkState state); |
72 bool DeliverRtcp(const uint8_t* packet, size_t length); | 76 bool DeliverRtcp(const uint8_t* packet, size_t length); |
73 | 77 |
74 // webrtc::VideoSendStream implementation. | 78 // webrtc::VideoSendStream implementation. |
75 void Start() override; | 79 void Start() override; |
76 void Stop() override; | 80 void Stop() override; |
77 VideoCaptureInput* Input() override; | 81 VideoCaptureInput* Input() override; |
78 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; | 82 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; |
79 Stats GetStats() override; | 83 Stats GetStats() override; |
80 | 84 |
85 typedef std::map<uint32_t, RtpState> RtpStateMap; | |
86 RtpStateMap StopPermanentlyAndGetRtpStates(); | |
87 | |
88 private: | |
89 class ConstructionTask; | |
90 class DestructAndGetRTPStateTask; | |
91 | |
92 rtc::ThreadChecker thread_checker_; | |
93 rtc::TaskQueue* const worker_queu_; | |
tommi
2016/06/17 07:59:01
worker_queue_
perkj_webrtc
2016/06/27 14:34:35
Done.
| |
94 std::unique_ptr<VideoSendStreamInternal> send_stream_; | |
95 rtc::Event thread_sync_event_; | |
96 }; | |
97 | |
98 class VideoSendStreamInternal : public webrtc::CpuOveruseObserver, | |
99 public webrtc::BitrateAllocatorObserver, | |
100 public webrtc::VCMProtectionCallback, | |
101 public EncodedImageCallback { | |
102 public: | |
103 VideoSendStreamInternal(int num_cpu_cores, | |
104 rtc::TaskQueue* worker_queu, | |
tommi
2016/06/17 07:59:02
worker_queue :)
perkj_webrtc
2016/06/27 14:34:35
Done.
| |
105 CallStats* call_stats, | |
106 CongestionController* congestion_controller, | |
107 BitrateAllocator* bitrate_allocator, | |
108 SendDelayStats* send_delay_stats, | |
109 VieRemb* remb, | |
110 RtcEventLog* event_log, | |
111 const VideoSendStream::Config& config, | |
112 const VideoEncoderConfig& encoder_config, | |
113 const std::map<uint32_t, RtpState>& suspended_ssrcs); | |
tommi
2016/06/17 07:59:01
should any of these more expensive parameters be p
perkj_webrtc
2016/06/27 14:34:35
Done.
| |
114 | |
115 ~VideoSendStreamInternal() override; | |
116 | |
117 // RegisterProcessThread register |module_process_thread| with those objects | |
118 // that use it. Registration have to happen on the thread where | |
119 // |module_process_thread| where created (libjingles worker thread). | |
120 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue, | |
121 // maybe |worker_queu|. | |
122 void RegisterProcessThread(ProcessThread* module_process_thread); | |
123 void DeRegisterProcessThread(); | |
124 | |
125 void SignalNetworkState(NetworkState state); | |
126 bool DeliverRtcp(const uint8_t* packet, size_t length); | |
127 | |
128 // webrtc::VideoSendStream implementation. | |
tommi
2016/06/17 07:59:01
are the below methods overrides?
perkj_webrtc
2016/06/27 14:34:35
No, not after splitting VideoSendStream in two. Vi
| |
129 void Start(); | |
130 void Stop(); | |
131 VideoCaptureInput* Input(); | |
132 void ReconfigureVideoEncoder(const VideoEncoderConfig& config); | |
133 VideoSendStream::Stats GetStats(); | |
134 VideoSendStream::RtpStateMap GetRtpStates() const; | |
135 | |
81 // webrtc::CpuOveruseObserver implementation. | 136 // webrtc::CpuOveruseObserver implementation. |
82 void OveruseDetected() override; | 137 void OveruseDetected() override; |
83 void NormalUsage() override; | 138 void NormalUsage() override; |
84 | 139 |
85 typedef std::map<uint32_t, RtpState> RtpStateMap; | |
86 RtpStateMap GetRtpStates() const; | |
87 | |
88 int GetPaddingNeededBps() const; | |
89 | |
90 // Implements BitrateAllocatorObserver. | 140 // Implements BitrateAllocatorObserver. |
91 void OnBitrateUpdated(uint32_t bitrate_bps, | 141 void OnBitrateUpdated(uint32_t bitrate_bps, |
92 uint8_t fraction_loss, | 142 uint8_t fraction_loss, |
93 int64_t rtt) override; | 143 int64_t rtt) override; |
94 | 144 |
95 protected: | 145 protected: |
96 // Implements webrtc::VCMProtectionCallback. | 146 // Implements webrtc::VCMProtectionCallback. |
97 int ProtectionRequest(const FecProtectionParams* delta_params, | 147 int ProtectionRequest(const FecProtectionParams* delta_params, |
98 const FecProtectionParams* key_params, | 148 const FecProtectionParams* key_params, |
99 uint32_t* sent_video_rate_bps, | 149 uint32_t* sent_video_rate_bps, |
100 uint32_t* sent_nack_rate_bps, | 150 uint32_t* sent_nack_rate_bps, |
101 uint32_t* sent_fec_rate_bps) override; | 151 uint32_t* sent_fec_rate_bps) override; |
102 | 152 |
103 private: | 153 private: |
104 struct EncoderSettings { | 154 class CheckEncoderActivityTask; |
105 VideoCodec video_codec; | |
106 VideoEncoderConfig config; | |
107 }; | |
108 | 155 |
109 // Implements EncodedImageCallback. The implementation routes encoded frames | 156 // Implements EncodedImageCallback. The implementation routes encoded frames |
110 // to the |payload_router_| and |config.pre_encode_callback| if set. | 157 // to the |payload_router_| and |config.pre_encode_callback| if set. |
111 // Called on an arbitrary encoder callback thread. | 158 // Called on an arbitrary encoder callback thread. |
112 int32_t Encoded(const EncodedImage& encoded_image, | 159 int32_t Encoded(const EncodedImage& encoded_image, |
113 const CodecSpecificInfo* codec_specific_info, | 160 const CodecSpecificInfo* codec_specific_info, |
114 const RTPFragmentationHeader* fragmentation) override; | 161 const RTPFragmentationHeader* fragmentation) override; |
115 | 162 |
116 static bool EncoderThreadFunction(void* obj); | 163 static bool EncoderThreadFunction(void* obj); |
117 void EncoderProcess(); | 164 void EncoderProcess(); |
118 | 165 |
119 void ConfigureProtection(); | 166 void ConfigureProtection(); |
120 void ConfigureSsrcs(); | 167 void ConfigureSsrcs(); |
168 void CheckEncoderActivity(); | |
121 | 169 |
122 SendStatisticsProxy stats_proxy_; | 170 SendStatisticsProxy stats_proxy_; |
123 EncodedFrameCallbackAdapter encoded_frame_proxy_; | 171 EncodedFrameCallbackAdapter encoded_frame_proxy_; |
124 const VideoSendStream::Config config_; | 172 const VideoSendStream::Config config_; |
125 std::map<uint32_t, RtpState> suspended_ssrcs_; | 173 std::map<uint32_t, RtpState> suspended_ssrcs_; |
126 | 174 |
127 ProcessThread* const module_process_thread_; | 175 ProcessThread* module_process_thread_; |
176 rtc::ThreadChecker module_process_thread_checker_; | |
177 rtc::TaskQueue* const worker_queu_; | |
tommi
2016/06/17 07:59:02
ditto
perkj_webrtc
2016/06/27 14:34:35
Done.
| |
178 CheckEncoderActivityTask* check_encoder_activity_task_; | |
128 CallStats* const call_stats_; | 179 CallStats* const call_stats_; |
129 CongestionController* const congestion_controller_; | 180 CongestionController* const congestion_controller_; |
130 BitrateAllocator* const bitrate_allocator_; | 181 BitrateAllocator* const bitrate_allocator_; |
131 VieRemb* const remb_; | 182 VieRemb* const remb_; |
132 | 183 |
133 static const bool kEnableFrameRecording = false; | 184 static const bool kEnableFrameRecording = false; |
134 static const int kMaxLayers = 3; | 185 static const int kMaxLayers = 3; |
135 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; | 186 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; |
136 | 187 |
137 rtc::PlatformThread encoder_thread_; | 188 rtc::PlatformThread encoder_thread_; |
138 rtc::Event encoder_wakeup_event_; | 189 rtc::Event encoder_wakeup_event_; |
139 volatile int stop_encoder_thread_; | 190 volatile int stop_encoder_thread_; |
140 rtc::CriticalSection encoder_settings_crit_; | 191 rtc::CriticalSection encoder_settings_crit_; |
141 std::unique_ptr<EncoderSettings> pending_encoder_settings_ | 192 std::unique_ptr<VideoCodec> pending_encoder_settings_ |
142 GUARDED_BY(encoder_settings_crit_); | 193 GUARDED_BY(encoder_settings_crit_); |
143 // Only used on the encoder thread. | 194 |
144 bool send_stream_registered_as_observer_; | 195 bool send_stream_registered_as_observer_; |
145 std::unique_ptr<EncoderSettings> current_encoder_settings_; | 196 VideoCodec current_video_codec_; |
197 int max_padding_bitrate_; | |
198 // The time we last received an encoded frame. This is used to | |
199 // track when video is stopped long enough that we also want to stop sending | |
200 // padding. | |
201 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(encoder_settings_crit_); | |
202 uint32_t last_set_encoder_bitrate_bps_; | |
146 | 203 |
147 OveruseFrameDetector overuse_detector_; | 204 OveruseFrameDetector overuse_detector_; |
148 ViEEncoder vie_encoder_; | 205 ViEEncoder vie_encoder_; |
149 EncoderStateFeedback encoder_feedback_; | 206 EncoderStateFeedback encoder_feedback_; |
150 ProtectionBitrateCalculator protection_bitrate_calculator_; | 207 ProtectionBitrateCalculator protection_bitrate_calculator_; |
151 | 208 |
152 vcm::VideoSender* const video_sender_; | 209 vcm::VideoSender* const video_sender_; |
153 | 210 |
154 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; | 211 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; |
155 // RtpRtcp modules, declared here as they use other members on construction. | 212 // RtpRtcp modules, declared here as they use other members on construction. |
156 const std::vector<RtpRtcp*> rtp_rtcp_modules_; | 213 const std::vector<RtpRtcp*> rtp_rtcp_modules_; |
157 PayloadRouter payload_router_; | 214 PayloadRouter payload_router_; |
158 VideoCaptureInput input_; | 215 VideoCaptureInput input_; |
159 }; | 216 }; |
160 } // namespace internal | 217 } // namespace internal |
161 } // namespace webrtc | 218 } // namespace webrtc |
162 | 219 |
163 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ | 220 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ |
OLD | NEW |