Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: webrtc/video/video_send_stream.h

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Rebased. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 29 #include "webrtc/video/video_capture_input.h"
28 #include "webrtc/video/vie_encoder.h" 30 #include "webrtc/video/vie_encoder.h"
29 #include "webrtc/video_receive_stream.h" 31 #include "webrtc/video_receive_stream.h"
(...skipping 10 matching lines...) Expand all
40 class ViEEncoder; 42 class ViEEncoder;
41 class VieRemb; 43 class VieRemb;
42 class RtcEventLog; 44 class RtcEventLog;
43 45
44 namespace vcm { 46 namespace vcm {
45 class VideoSender; 47 class VideoSender;
46 } // namespace vcm 48 } // namespace vcm
47 49
48 namespace internal { 50 namespace internal {
49 51
50 class VideoSendStream : public webrtc::VideoSendStream, 52 class VideoSendStreamInternal;
51 public webrtc::CpuOveruseObserver, 53
52 public webrtc::BitrateAllocatorObserver, 54 // VideoSendStream implements webrtc::VideoSendStream.
53 public webrtc::VCMProtectionCallback, 55 // Internally, it delegates all public methods to VideoSendStreamInternal.
54 public EncodedImageCallback { 56 // VideoSendStreamInternal in created and destructed on |worker_queu|.
57 class VideoSendStream : public webrtc::VideoSendStream {
55 public: 58 public:
56 VideoSendStream(int num_cpu_cores, 59 VideoSendStream(int num_cpu_cores,
57 ProcessThread* module_process_thread, 60 ProcessThread* module_process_thread,
61 rtc::TaskQueue* worker_queu,
58 CallStats* call_stats, 62 CallStats* call_stats,
59 CongestionController* congestion_controller, 63 CongestionController* congestion_controller,
60 BitrateAllocator* bitrate_allocator, 64 BitrateAllocator* bitrate_allocator,
61 SendDelayStats* send_delay_stats, 65 SendDelayStats* send_delay_stats,
62 VieRemb* remb, 66 VieRemb* remb,
63 RtcEventLog* event_log, 67 RtcEventLog* event_log,
64 const VideoSendStream::Config& config, 68 const VideoSendStream::Config& config,
65 const VideoEncoderConfig& encoder_config, 69 const VideoEncoderConfig& encoder_config,
66 const std::map<uint32_t, RtpState>& suspended_ssrcs); 70 const std::map<uint32_t, RtpState>& suspended_ssrcs);
67 71
68 ~VideoSendStream() override; 72 ~VideoSendStream() override;
69 73
70 void SignalNetworkState(NetworkState state); 74 void SignalNetworkState(NetworkState state);
71 bool DeliverRtcp(const uint8_t* packet, size_t length); 75 bool DeliverRtcp(const uint8_t* packet, size_t length);
72 76
73 // webrtc::VideoSendStream implementation. 77 // webrtc::VideoSendStream implementation.
74 void Start() override; 78 void Start() override;
75 void Stop() override; 79 void Stop() override;
76 VideoCaptureInput* Input() override; 80 VideoCaptureInput* Input() override;
77 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override; 81 void ReconfigureVideoEncoder(const VideoEncoderConfig& config) override;
78 Stats GetStats() override; 82 Stats GetStats() override;
79 83
84 typedef std::map<uint32_t, RtpState> RtpStateMap;
85 RtpStateMap StopPermanentlyAndGetRtpStates();
86
87 private:
88 class ConstructionTask;
89 class DestructAndGetRTPStateTask;
90
91 rtc::ThreadChecker thread_checker_;
92 rtc::TaskQueue* const worker_queu_;
93 std::unique_ptr<VideoSendStreamInternal> send_stream_;
94 rtc::Event thread_sync_event_;
95 };
96
97 class VideoSendStreamInternal : public webrtc::CpuOveruseObserver,
98 public webrtc::BitrateAllocatorObserver,
99 public webrtc::VCMProtectionCallback,
100 public EncodedImageCallback {
101 public:
102 VideoSendStreamInternal(int num_cpu_cores,
103 rtc::TaskQueue* worker_queu,
104 CallStats* call_stats,
105 CongestionController* congestion_controller,
106 BitrateAllocator* bitrate_allocator,
107 SendDelayStats* send_delay_stats,
108 VieRemb* remb,
109 RtcEventLog* event_log,
110 const VideoSendStream::Config& config,
111 const VideoEncoderConfig& encoder_config,
112 const std::map<uint32_t, RtpState>& suspended_ssrcs);
113
114 ~VideoSendStreamInternal() override;
115
116 // RegisterProcessThread register |module_process_thread| with those objects
117 // that use it. Registration have to happen on the thread where
118 // |module_process_thread| where created (libjingles worker thread).
119 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue,
120 // maybe |worker_queu|.
121 void RegisterProcessThread(ProcessThread* module_process_thread);
122 void DeRegisterProcessThread();
123
124 void SignalNetworkState(NetworkState state);
125 bool DeliverRtcp(const uint8_t* packet, size_t length);
126
127 // webrtc::VideoSendStream implementation.
128 void Start();
129 void Stop();
130 VideoCaptureInput* Input();
131 void ReconfigureVideoEncoder(const VideoEncoderConfig& config);
132 VideoSendStream::Stats GetStats();
133 VideoSendStream::RtpStateMap GetRtpStates() const;
134
80 // webrtc::CpuOveruseObserver implementation. 135 // webrtc::CpuOveruseObserver implementation.
81 void OveruseDetected() override; 136 void OveruseDetected() override;
82 void NormalUsage() override; 137 void NormalUsage() override;
83 138
84 typedef std::map<uint32_t, RtpState> RtpStateMap;
85 RtpStateMap GetRtpStates() const;
86
87 int GetPaddingNeededBps() const;
88
89 // Implements BitrateAllocatorObserver. 139 // Implements BitrateAllocatorObserver.
90 void OnBitrateUpdated(uint32_t bitrate_bps, 140 void OnBitrateUpdated(uint32_t bitrate_bps,
91 uint8_t fraction_loss, 141 uint8_t fraction_loss,
92 int64_t rtt) override; 142 int64_t rtt) override;
93 143
94 protected: 144 protected:
95 // Implements webrtc::VCMProtectionCallback. 145 // Implements webrtc::VCMProtectionCallback.
96 int ProtectionRequest(const FecProtectionParams* delta_params, 146 int ProtectionRequest(const FecProtectionParams* delta_params,
97 const FecProtectionParams* key_params, 147 const FecProtectionParams* key_params,
98 uint32_t* sent_video_rate_bps, 148 uint32_t* sent_video_rate_bps,
99 uint32_t* sent_nack_rate_bps, 149 uint32_t* sent_nack_rate_bps,
100 uint32_t* sent_fec_rate_bps) override; 150 uint32_t* sent_fec_rate_bps) override;
101 151
102 private: 152 private:
103 struct EncoderSettings { 153 class CheckEncoderActivityTask;
104 VideoCodec video_codec;
105 VideoEncoderConfig config;
106 };
107 154
108 // Implements EncodedImageCallback. The implementation routes encoded frames 155 // Implements EncodedImageCallback. The implementation routes encoded frames
109 // to the |payload_router_| and |config.pre_encode_callback| if set. 156 // to the |payload_router_| and |config.pre_encode_callback| if set.
110 // Called on an arbitrary encoder callback thread. 157 // Called on an arbitrary encoder callback thread.
111 int32_t Encoded(const EncodedImage& encoded_image, 158 int32_t Encoded(const EncodedImage& encoded_image,
112 const CodecSpecificInfo* codec_specific_info, 159 const CodecSpecificInfo* codec_specific_info,
113 const RTPFragmentationHeader* fragmentation) override; 160 const RTPFragmentationHeader* fragmentation) override;
114 161
115 static bool EncoderThreadFunction(void* obj); 162 static bool EncoderThreadFunction(void* obj);
116 void EncoderProcess(); 163 void EncoderProcess();
117 164
118 void ConfigureProtection(); 165 void ConfigureProtection();
119 void ConfigureSsrcs(); 166 void ConfigureSsrcs();
167 void EncoderTimedOut();
168 void EncoderIsActive();
120 169
121 SendStatisticsProxy stats_proxy_; 170 SendStatisticsProxy stats_proxy_;
122 const VideoSendStream::Config config_; 171 const VideoSendStream::Config config_;
123 std::map<uint32_t, RtpState> suspended_ssrcs_; 172 std::map<uint32_t, RtpState> suspended_ssrcs_;
124 173
125 ProcessThread* const module_process_thread_; 174 ProcessThread* module_process_thread_;
175 rtc::ThreadChecker module_process_thread_checker_;
176 rtc::TaskQueue* const worker_queu_;
177 CheckEncoderActivityTask* check_encoder_activity_task_
178 GUARDED_BY(encoder_settings_crit_);
126 CallStats* const call_stats_; 179 CallStats* const call_stats_;
127 CongestionController* const congestion_controller_; 180 CongestionController* const congestion_controller_;
128 BitrateAllocator* const bitrate_allocator_; 181 BitrateAllocator* const bitrate_allocator_;
129 VieRemb* const remb_; 182 VieRemb* const remb_;
130 183
131 static const bool kEnableFrameRecording = false; 184 static const bool kEnableFrameRecording = false;
132 static const int kMaxLayers = 3; 185 static const int kMaxLayers = 3;
133 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers]; 186 std::unique_ptr<IvfFileWriter> file_writers_[kMaxLayers];
134 187
135 rtc::PlatformThread encoder_thread_; 188 rtc::PlatformThread encoder_thread_;
189 rtc::ThreadChecker encoder_thread_checker_;
136 rtc::Event encoder_wakeup_event_; 190 rtc::Event encoder_wakeup_event_;
137 volatile int stop_encoder_thread_; 191 volatile int stop_encoder_thread_;
138 rtc::CriticalSection encoder_settings_crit_; 192 rtc::CriticalSection encoder_settings_crit_;
139 std::unique_ptr<EncoderSettings> pending_encoder_settings_ 193 std::unique_ptr<VideoCodec> pending_encoder_settings_
140 GUARDED_BY(encoder_settings_crit_); 194 GUARDED_BY(encoder_settings_crit_);
141 195
142 enum class State { 196 VideoCodec current_video_codec_;
143 kStopped, // VideoSendStream::Start has not yet been called. 197 int max_padding_bitrate_;
144 kStarted, // VideoSendStream::Start has been called. 198 uint32_t encoder_target_rate_;
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 199
156 OveruseFrameDetector overuse_detector_; 200 OveruseFrameDetector overuse_detector_;
157 ViEEncoder vie_encoder_; 201 ViEEncoder vie_encoder_;
158 EncoderStateFeedback encoder_feedback_; 202 EncoderStateFeedback encoder_feedback_;
159 ProtectionBitrateCalculator protection_bitrate_calculator_; 203 ProtectionBitrateCalculator protection_bitrate_calculator_;
160 204
161 vcm::VideoSender* const video_sender_; 205 vcm::VideoSender* const video_sender_;
162 206
163 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; 207 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
164 // RtpRtcp modules, declared here as they use other members on construction. 208 // RtpRtcp modules, declared here as they use other members on construction.
165 const std::vector<RtpRtcp*> rtp_rtcp_modules_; 209 const std::vector<RtpRtcp*> rtp_rtcp_modules_;
166 PayloadRouter payload_router_; 210 PayloadRouter payload_router_;
167 VideoCaptureInput input_; 211 VideoCaptureInput input_;
168 }; 212 };
169 } // namespace internal 213 } // namespace internal
170 } // namespace webrtc 214 } // namespace webrtc
171 215
172 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ 216 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698