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

Side by Side Diff: webrtc/modules/video_coding/video_coding_impl.h

Issue 2764573002: Deliver video frames on Android, on the decode thread. (Closed)
Patch Set: Update comments Created 3 years, 8 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 17 matching lines...) Expand all
28 #include "webrtc/modules/video_coding/generic_encoder.h" 28 #include "webrtc/modules/video_coding/generic_encoder.h"
29 #include "webrtc/modules/video_coding/jitter_buffer.h" 29 #include "webrtc/modules/video_coding/jitter_buffer.h"
30 #include "webrtc/modules/video_coding/media_optimization.h" 30 #include "webrtc/modules/video_coding/media_optimization.h"
31 #include "webrtc/modules/video_coding/qp_parser.h" 31 #include "webrtc/modules/video_coding/qp_parser.h"
32 #include "webrtc/modules/video_coding/receiver.h" 32 #include "webrtc/modules/video_coding/receiver.h"
33 #include "webrtc/modules/video_coding/timing.h" 33 #include "webrtc/modules/video_coding/timing.h"
34 #include "webrtc/system_wrappers/include/clock.h" 34 #include "webrtc/system_wrappers/include/clock.h"
35 35
36 namespace webrtc { 36 namespace webrtc {
37 37
38 class ProcessThread;
38 class VideoBitrateAllocator; 39 class VideoBitrateAllocator;
39 class VideoBitrateAllocationObserver; 40 class VideoBitrateAllocationObserver;
40 41
41 namespace vcm { 42 namespace vcm {
42 43
43 class VCMProcessTimer { 44 class VCMProcessTimer {
44 public: 45 public:
45 static const int64_t kDefaultProcessIntervalMs = 1000; 46 static const int64_t kDefaultProcessIntervalMs = 1000;
46 47
47 VCMProcessTimer(int64_t periodMs, Clock* clock) 48 VCMProcessTimer(int64_t periodMs, Clock* clock)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 }; 144 };
144 145
145 class VideoReceiver : public Module { 146 class VideoReceiver : public Module {
146 public: 147 public:
147 VideoReceiver(Clock* clock, 148 VideoReceiver(Clock* clock,
148 EventFactory* event_factory, 149 EventFactory* event_factory,
149 EncodedImageCallback* pre_decode_image_callback, 150 EncodedImageCallback* pre_decode_image_callback,
150 VCMTiming* timing, 151 VCMTiming* timing,
151 NackSender* nack_sender = nullptr, 152 NackSender* nack_sender = nullptr,
152 KeyFrameRequestSender* keyframe_request_sender = nullptr); 153 KeyFrameRequestSender* keyframe_request_sender = nullptr);
153 ~VideoReceiver(); 154 ~VideoReceiver() override;
154 155
155 int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec, 156 int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
156 int32_t numberOfCores, 157 int32_t numberOfCores,
157 bool requireKeyFrame); 158 bool requireKeyFrame);
158 159
159 void RegisterExternalDecoder(VideoDecoder* externalDecoder, 160 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
160 uint8_t payloadType); 161 uint8_t payloadType);
161 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback); 162 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
162 int32_t RegisterReceiveStatisticsCallback( 163 int32_t RegisterReceiveStatisticsCallback(
163 VCMReceiveStatisticsCallback* receiveStats); 164 VCMReceiveStatisticsCallback* receiveStats);
164 int32_t RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback); 165 int32_t RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
165 int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback); 166 int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
166 167
167 int32_t Decode(uint16_t maxWaitTimeMs); 168 int32_t Decode(uint16_t maxWaitTimeMs);
168 169
169 int32_t Decode(const webrtc::VCMEncodedFrame* frame); 170 int32_t Decode(const webrtc::VCMEncodedFrame* frame);
170 171
171 // Called on the decoder thread when thread is exiting. 172 #if defined(WEBRTC_ANDROID)
172 void DecodingStopped(); 173 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
174 void PollDecodedFrames();
175 #endif
173 176
174 int32_t IncomingPacket(const uint8_t* incomingPayload, 177 int32_t IncomingPacket(const uint8_t* incomingPayload,
175 size_t payloadLength, 178 size_t payloadLength,
176 const WebRtcRTPHeader& rtpInfo); 179 const WebRtcRTPHeader& rtpInfo);
177 int32_t SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs); 180 int32_t SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs);
178 int32_t SetRenderDelay(uint32_t timeMS); 181 int32_t SetRenderDelay(uint32_t timeMS);
179 int32_t Delay() const; 182 int32_t Delay() const;
180 183
181 // DEPRECATED. 184 // DEPRECATED.
182 int SetReceiverRobustnessMode( 185 int SetReceiverRobustnessMode(
183 VideoCodingModule::ReceiverRobustness robustnessMode, 186 VideoCodingModule::ReceiverRobustness robustnessMode,
184 VCMDecodeErrorMode errorMode); 187 VCMDecodeErrorMode errorMode);
185 188
186 void SetNackSettings(size_t max_nack_list_size, 189 void SetNackSettings(size_t max_nack_list_size,
187 int max_packet_age_to_nack, 190 int max_packet_age_to_nack,
188 int max_incomplete_time_ms); 191 int max_incomplete_time_ms);
189 192
190 void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode); 193 void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
191 int SetMinReceiverDelay(int desired_delay_ms); 194 int SetMinReceiverDelay(int desired_delay_ms);
192 195
193 int32_t SetReceiveChannelParameters(int64_t rtt); 196 int32_t SetReceiveChannelParameters(int64_t rtt);
194 int32_t SetVideoProtection(VCMVideoProtection videoProtection, bool enable); 197 int32_t SetVideoProtection(VCMVideoProtection videoProtection, bool enable);
195 198
196 int64_t TimeUntilNextProcess() override; 199 int64_t TimeUntilNextProcess() override;
197 void Process() override; 200 void Process() override;
201 void ProcessThreadAttached(ProcessThread* process_thread) override;
198 202
199 void TriggerDecoderShutdown(); 203 void TriggerDecoderShutdown();
204 void DecoderThreadStarting();
205 void DecoderThreadStopped();
200 206
201 protected: 207 protected:
202 int32_t Decode(const webrtc::VCMEncodedFrame& frame) 208 int32_t Decode(const webrtc::VCMEncodedFrame& frame);
203 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
204 int32_t RequestKeyFrame(); 209 int32_t RequestKeyFrame();
205 210
206 private: 211 private:
212 // Used for DCHECKing thread correctness.
213 // In build where DCHECKs are enabled, will return false before
214 // DecoderThreadStarting is called, then true until DecoderThreadStopped
215 // is called.
216 // In builds where DCHECKs aren't enabled, it will return true.
217 bool IsDecoderThreadRunning();
218
207 rtc::ThreadChecker construction_thread_; 219 rtc::ThreadChecker construction_thread_;
220 rtc::ThreadChecker decoder_thread_;
221 rtc::ThreadChecker module_thread_;
208 Clock* const clock_; 222 Clock* const clock_;
209 rtc::CriticalSection process_crit_; 223 rtc::CriticalSection process_crit_;
210 rtc::CriticalSection receive_crit_;
211 VCMTiming* _timing; 224 VCMTiming* _timing;
212 VCMReceiver _receiver; 225 VCMReceiver _receiver;
213 VCMDecodedFrameCallback _decodedFrameCallback; 226 VCMDecodedFrameCallback _decodedFrameCallback;
214 VCMFrameTypeCallback* _frameTypeCallback GUARDED_BY(process_crit_);
215 VCMReceiveStatisticsCallback* _receiveStatsCallback GUARDED_BY(process_crit_);
216 VCMPacketRequestCallback* _packetRequestCallback GUARDED_BY(process_crit_);
217 227
218 VCMFrameBuffer _frameFromFile; 228 // These callbacks are set on the construction thread before being attached
229 // to the module thread or decoding started, so a lock is not required.
230 VCMFrameTypeCallback* _frameTypeCallback;
231 VCMReceiveStatisticsCallback* _receiveStatsCallback;
232 VCMPacketRequestCallback* _packetRequestCallback;
233
234 // Used on both the module and decoder thread.
219 bool _scheduleKeyRequest GUARDED_BY(process_crit_); 235 bool _scheduleKeyRequest GUARDED_BY(process_crit_);
220 bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_); 236 bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_);
221 size_t max_nack_list_size_ GUARDED_BY(process_crit_);
222 237
223 VCMCodecDataBase _codecDataBase GUARDED_BY(receive_crit_); 238 // Modified on the construction thread while not attached to the process
224 EncodedImageCallback* pre_decode_image_callback_; 239 // thread. Once attached to the process thread, its value is only read
240 // so a lock is not required.
241 size_t max_nack_list_size_;
225 242
226 VCMProcessTimer _receiveStatsTimer; 243 // Callbacks are set before the decoder thread starts.
227 VCMProcessTimer _retransmissionTimer; 244 // Once the decoder thread has been started, usage of |_codecDataBase| moves
228 VCMProcessTimer _keyRequestTimer; 245 // over to the decoder thread.
229 QpParser qp_parser_; 246 VCMCodecDataBase _codecDataBase;
230 ThreadUnsafeOneTimeEvent first_frame_received_; 247 EncodedImageCallback* const pre_decode_image_callback_;
248
249 VCMProcessTimer _receiveStatsTimer ACCESS_ON(module_thread_);
250 VCMProcessTimer _retransmissionTimer ACCESS_ON(module_thread_);
251 VCMProcessTimer _keyRequestTimer ACCESS_ON(module_thread_);
252 QpParser qp_parser_ ACCESS_ON(decoder_thread_);
253 ThreadUnsafeOneTimeEvent first_frame_received_ ACCESS_ON(decoder_thread_);
254 // Modified on the construction thread. Can be read without a lock and assumed
255 // to be non-null on the module and decoder threads.
256 ProcessThread* process_thread_ = nullptr;
257 bool is_attached_to_process_thread_ ACCESS_ON(construction_thread_) = false;
258 #if RTC_DCHECK_IS_ON
259 bool decoder_thread_is_running_ = false;
260 #endif
231 }; 261 };
232 262
233 } // namespace vcm 263 } // namespace vcm
234 } // namespace webrtc 264 } // namespace webrtc
235 #endif // WEBRTC_MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_ 265 #endif // WEBRTC_MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/generic_decoder.cc ('k') | webrtc/modules/video_coding/video_receiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698