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

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"
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|.
stefan-webrtc 2016/07/08 15:56:42 Hm, so now we have webrtc::VideoSendStream, webrtc
perkj_webrtc 2016/07/11 11:41:08 VideoSendStreamImpl ?
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,
stefan-webrtc 2016/07/08 15:56:42 Move this to the .cc file
perkj_webrtc 2016/07/11 11:41:08 Done.
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);
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;
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 SignalEncoderTimedOut();
154 void SignalEncoderActive();
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 uint32_t encoder_max_bitrate_bps_;
138 rtc::CriticalSection encoder_settings_crit_; 179 uint32_t encoder_target_rate_bps_;
139 std::unique_ptr<EncoderSettings> pending_encoder_settings_
140 GUARDED_BY(encoder_settings_crit_);
141 uint32_t encoder_max_bitrate_bps_ GUARDED_BY(encoder_settings_crit_);
142 uint32_t encoder_target_rate_bps_ GUARDED_BY(encoder_settings_crit_);
143 180
144 enum class State { 181 ViEEncoder* const vie_encoder_;
145 kStopped, // VideoSendStream::Start has not yet been called.
146 kStarted, // VideoSendStream::Start has been called.
147 // VideoSendStream::Start has been called but the encoder have timed out.
148 kEncoderTimedOut,
149 };
150 rtc::Optional<State> pending_state_change_ GUARDED_BY(encoder_settings_crit_);
151
152 // Only used on the encoder thread.
153 rtc::ThreadChecker encoder_thread_checker_;
154 State state_ ACCESS_ON(&encoder_thread_checker_);
155 std::unique_ptr<EncoderSettings> current_encoder_settings_
156 ACCESS_ON(&encoder_thread_checker_);
157
158 OveruseFrameDetector overuse_detector_;
159 ViEEncoder vie_encoder_;
160 EncoderStateFeedback encoder_feedback_; 182 EncoderStateFeedback encoder_feedback_;
161 ProtectionBitrateCalculator protection_bitrate_calculator_; 183 ProtectionBitrateCalculator protection_bitrate_calculator_;
162 184
163 vcm::VideoSender* const video_sender_;
164
165 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_; 185 const std::unique_ptr<RtcpBandwidthObserver> bandwidth_observer_;
166 // RtpRtcp modules, declared here as they use other members on construction. 186 // RtpRtcp modules, declared here as they use other members on construction.
167 const std::vector<RtpRtcp*> rtp_rtcp_modules_; 187 const std::vector<RtpRtcp*> rtp_rtcp_modules_;
168 PayloadRouter payload_router_; 188 PayloadRouter payload_router_;
169 VideoCaptureInput input_;
170 }; 189 };
171 } // namespace internal 190 } // namespace internal
172 } // namespace webrtc 191 } // namespace webrtc
173 192
174 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_ 193 #endif // WEBRTC_VIDEO_VIDEO_SEND_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698