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

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.h

Issue 1695263002: Move direct use of VideoCapturer::VideoAdapter to VideoSinkWants. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed test for screencast from videocapturer Created 4 years, 9 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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_
12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "webrtc/base/asyncinvoker.h"
20 #include "webrtc/base/criticalsection.h" 21 #include "webrtc/base/criticalsection.h"
21 #include "webrtc/base/thread_annotations.h" 22 #include "webrtc/base/thread_annotations.h"
22 #include "webrtc/base/thread_checker.h" 23 #include "webrtc/base/thread_checker.h"
23 #include "webrtc/media/base/videosinkinterface.h" 24 #include "webrtc/media/base/videosinkinterface.h"
24 #include "webrtc/media/base/videosourceinterface.h" 25 #include "webrtc/media/base/videosourceinterface.h"
25 #include "webrtc/call.h" 26 #include "webrtc/call.h"
26 #include "webrtc/media/base/mediaengine.h" 27 #include "webrtc/media/base/mediaengine.h"
27 #include "webrtc/media/engine/webrtcvideochannelfactory.h" 28 #include "webrtc/media/engine/webrtcvideochannelfactory.h"
28 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" 29 #include "webrtc/media/engine/webrtcvideodecoderfactory.h"
29 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 30 #include "webrtc/media/engine/webrtcvideoencoderfactory.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 std::vector<VideoCodec> video_codecs_; 124 std::vector<VideoCodec> video_codecs_;
124 125
125 bool initialized_; 126 bool initialized_;
126 127
127 WebRtcVideoDecoderFactory* external_decoder_factory_; 128 WebRtcVideoDecoderFactory* external_decoder_factory_;
128 WebRtcVideoEncoderFactory* external_encoder_factory_; 129 WebRtcVideoEncoderFactory* external_encoder_factory_;
129 std::unique_ptr<WebRtcVideoEncoderFactory> simulcast_encoder_factory_; 130 std::unique_ptr<WebRtcVideoEncoderFactory> simulcast_encoder_factory_;
130 }; 131 };
131 132
132 class WebRtcVideoChannel2 : public VideoMediaChannel, 133 class WebRtcVideoChannel2 : public VideoMediaChannel, public webrtc::Transport {
133 public webrtc::Transport,
134 public webrtc::LoadObserver {
135 public: 134 public:
136 WebRtcVideoChannel2(webrtc::Call* call, 135 WebRtcVideoChannel2(webrtc::Call* call,
137 const MediaConfig& config, 136 const MediaConfig& config,
138 const VideoOptions& options, 137 const VideoOptions& options,
139 const std::vector<VideoCodec>& recv_codecs, 138 const std::vector<VideoCodec>& recv_codecs,
140 WebRtcVideoEncoderFactory* external_encoder_factory, 139 WebRtcVideoEncoderFactory* external_encoder_factory,
141 WebRtcVideoDecoderFactory* external_decoder_factory); 140 WebRtcVideoDecoderFactory* external_decoder_factory);
142 ~WebRtcVideoChannel2() override; 141 ~WebRtcVideoChannel2() override;
143 142
144 // VideoMediaChannel implementation 143 // VideoMediaChannel implementation
(...skipping 16 matching lines...) Expand all
161 bool GetStats(VideoMediaInfo* info) override; 160 bool GetStats(VideoMediaInfo* info) override;
162 bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) override; 161 bool SetCapturer(uint32_t ssrc, VideoCapturer* capturer) override;
163 162
164 void OnPacketReceived(rtc::Buffer* packet, 163 void OnPacketReceived(rtc::Buffer* packet,
165 const rtc::PacketTime& packet_time) override; 164 const rtc::PacketTime& packet_time) override;
166 void OnRtcpReceived(rtc::Buffer* packet, 165 void OnRtcpReceived(rtc::Buffer* packet,
167 const rtc::PacketTime& packet_time) override; 166 const rtc::PacketTime& packet_time) override;
168 void OnReadyToSend(bool ready) override; 167 void OnReadyToSend(bool ready) override;
169 void SetInterface(NetworkInterface* iface) override; 168 void SetInterface(NetworkInterface* iface) override;
170 169
171 void OnLoadUpdate(Load load) override;
172
173 // Implemented for VideoMediaChannelTest. 170 // Implemented for VideoMediaChannelTest.
174 bool sending() const { return sending_; } 171 bool sending() const { return sending_; }
175 uint32_t GetDefaultSendChannelSsrc() { return default_send_ssrc_; } 172 uint32_t GetDefaultSendChannelSsrc() { return default_send_ssrc_; }
176 173
177 private: 174 private:
178 class WebRtcVideoReceiveStream; 175 class WebRtcVideoReceiveStream;
179 struct VideoCodecSettings { 176 struct VideoCodecSettings {
180 VideoCodecSettings(); 177 VideoCodecSettings();
181 178
182 bool operator==(const VideoCodecSettings& other) const; 179 bool operator==(const VideoCodecSettings& other) const;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); 220 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
224 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) 221 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
225 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); 222 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
226 223
227 static std::string CodecSettingsVectorToString( 224 static std::string CodecSettingsVectorToString(
228 const std::vector<VideoCodecSettings>& codecs); 225 const std::vector<VideoCodecSettings>& codecs);
229 226
230 // Wrapper for the sender part, this is where the capturer is connected and 227 // Wrapper for the sender part, this is where the capturer is connected and
231 // frames are then converted from cricket frames to webrtc frames. 228 // frames are then converted from cricket frames to webrtc frames.
232 class WebRtcVideoSendStream 229 class WebRtcVideoSendStream
233 : public rtc::VideoSinkInterface<cricket::VideoFrame> { 230 : public rtc::VideoSinkInterface<cricket::VideoFrame>,
231 public webrtc::LoadObserver {
234 public: 232 public:
235 WebRtcVideoSendStream( 233 WebRtcVideoSendStream(
236 webrtc::Call* call, 234 webrtc::Call* call,
237 const StreamParams& sp, 235 const StreamParams& sp,
238 const webrtc::VideoSendStream::Config& config, 236 const webrtc::VideoSendStream::Config& config,
239 WebRtcVideoEncoderFactory* external_encoder_factory, 237 WebRtcVideoEncoderFactory* external_encoder_factory,
238 bool enable_cpu_overuse_detection,
240 int max_bitrate_bps, 239 int max_bitrate_bps,
241 const rtc::Optional<VideoCodecSettings>& codec_settings, 240 const rtc::Optional<VideoCodecSettings>& codec_settings,
242 const std::vector<webrtc::RtpExtension>& rtp_extensions, 241 const std::vector<webrtc::RtpExtension>& rtp_extensions,
243 const VideoSendParameters& send_params); 242 const VideoSendParameters& send_params);
244 virtual ~WebRtcVideoSendStream(); 243 virtual ~WebRtcVideoSendStream();
245 244
246 void SetOptions(const VideoOptions& options); 245 void SetOptions(const VideoOptions& options);
247 // TODO(pbos): Move logic from SetOptions into this method. 246 // TODO(pbos): Move logic from SetOptions into this method.
248 void SetSendParameters(const ChangedSendParameters& send_params); 247 void SetSendParameters(const ChangedSendParameters& send_params);
249 248
250 void OnFrame(const cricket::VideoFrame& frame) override; 249 void OnFrame(const cricket::VideoFrame& frame) override;
251 bool SetCapturer(VideoCapturer* capturer); 250 bool SetCapturer(VideoCapturer* capturer);
252 void MuteStream(bool mute); 251 void MuteStream(bool mute);
253 bool DisconnectCapturer(); 252 bool DisconnectCapturer();
254 253
255 void Start(); 254 void Start();
256 void Stop(); 255 void Stop();
257 256
257 // Implements webrtc::LoadObserver.
258 void OnLoadUpdate(Load load) override;
259
258 const std::vector<uint32_t>& GetSsrcs() const; 260 const std::vector<uint32_t>& GetSsrcs() const;
259 VideoSenderInfo GetVideoSenderInfo(); 261 VideoSenderInfo GetVideoSenderInfo();
260 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); 262 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info);
261 263
262 private: 264 private:
263 // Parameters needed to reconstruct the underlying stream. 265 // Parameters needed to reconstruct the underlying stream.
264 // webrtc::VideoSendStream doesn't support setting a lot of options on the 266 // webrtc::VideoSendStream doesn't support setting a lot of options on the
265 // fly, so when those need to be changed we tear down and reconstruct with 267 // fly, so when those need to be changed we tear down and reconstruct with
266 // similar parameters depending on which options changed etc. 268 // similar parameters depending on which options changed etc.
267 struct VideoSendStreamParameters { 269 struct VideoSendStreamParameters {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void SetCodecAndOptions(const VideoCodecSettings& codec, 336 void SetCodecAndOptions(const VideoCodecSettings& codec,
335 const VideoOptions& options) 337 const VideoOptions& options)
336 EXCLUSIVE_LOCKS_REQUIRED(lock_); 338 EXCLUSIVE_LOCKS_REQUIRED(lock_);
337 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_); 339 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_);
338 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( 340 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
339 const Dimensions& dimensions, 341 const Dimensions& dimensions,
340 const VideoCodec& codec) const EXCLUSIVE_LOCKS_REQUIRED(lock_); 342 const VideoCodec& codec) const EXCLUSIVE_LOCKS_REQUIRED(lock_);
341 void SetDimensions(int width, int height, bool is_screencast) 343 void SetDimensions(int width, int height, bool is_screencast)
342 EXCLUSIVE_LOCKS_REQUIRED(lock_); 344 EXCLUSIVE_LOCKS_REQUIRED(lock_);
343 345
346 rtc::ThreadChecker thread_checker_;
347 rtc::AsyncInvoker invoker_;
348 rtc::Thread* thread_;
344 const std::vector<uint32_t> ssrcs_; 349 const std::vector<uint32_t> ssrcs_;
345 const std::vector<SsrcGroup> ssrc_groups_; 350 const std::vector<SsrcGroup> ssrc_groups_;
346 webrtc::Call* const call_; 351 webrtc::Call* const call_;
347 rtc::VideoSinkWants sink_wants_; 352 rtc::VideoSinkWants sink_wants_;
353 int cpu_restricted_counter_;
354 int number_of_cpu_adapt_changes_;
355 VideoCapturer* capturer_;
348 WebRtcVideoEncoderFactory* const external_encoder_factory_ 356 WebRtcVideoEncoderFactory* const external_encoder_factory_
349 GUARDED_BY(lock_); 357 GUARDED_BY(lock_);
350 358
351 rtc::CriticalSection lock_; 359 rtc::CriticalSection lock_;
352 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); 360 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_);
353 VideoSendStreamParameters parameters_ GUARDED_BY(lock_); 361 VideoSendStreamParameters parameters_ GUARDED_BY(lock_);
354 bool pending_encoder_reconfiguration_ GUARDED_BY(lock_); 362 bool pending_encoder_reconfiguration_ GUARDED_BY(lock_);
355 VideoEncoderSettings encoder_settings_ GUARDED_BY(lock_); 363 VideoEncoderSettings encoder_settings_ GUARDED_BY(lock_);
356 AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_); 364 AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_);
357 Dimensions last_dimensions_ GUARDED_BY(lock_); 365 Dimensions last_dimensions_ GUARDED_BY(lock_);
358 webrtc::VideoRotation last_rotation_ GUARDED_BY(lock_) = 366 webrtc::VideoRotation last_rotation_ GUARDED_BY(lock_) =
359 webrtc::kVideoRotation_0; 367 webrtc::kVideoRotation_0;
360 368
361 VideoCapturer* capturer_ GUARDED_BY(lock_); 369 bool capturer_is_screencast_ GUARDED_BY(lock_);
362 bool sending_ GUARDED_BY(lock_); 370 bool sending_ GUARDED_BY(lock_);
363 bool muted_ GUARDED_BY(lock_); 371 bool muted_ GUARDED_BY(lock_);
364 int old_adapt_changes_ GUARDED_BY(lock_);
365 372
366 // The timestamp of the first frame received 373 // The timestamp of the first frame received
367 // Used to generate the timestamps of subsequent frames 374 // Used to generate the timestamps of subsequent frames
368 int64_t first_frame_timestamp_ms_ GUARDED_BY(lock_); 375 int64_t first_frame_timestamp_ms_ GUARDED_BY(lock_);
369 376
370 // The timestamp of the last frame received 377 // The timestamp of the last frame received
371 // Used to generate timestamp for the black frame when capturer is removed 378 // Used to generate timestamp for the black frame when capturer is removed
372 int64_t last_frame_timestamp_ms_ GUARDED_BY(lock_); 379 int64_t last_frame_timestamp_ms_ GUARDED_BY(lock_);
373 }; 380 };
374 381
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 webrtc::Call* const call_; 491 webrtc::Call* const call_;
485 492
486 uint32_t default_send_ssrc_; 493 uint32_t default_send_ssrc_;
487 494
488 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_; 495 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
489 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_; 496 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
490 497
491 const bool signal_cpu_adaptation_; 498 const bool signal_cpu_adaptation_;
492 const bool disable_prerenderer_smoothing_; 499 const bool disable_prerenderer_smoothing_;
493 500
494 // Separate list of set capturers used to signal CPU adaptation. These should
495 // not be locked while calling methods that take other locks to prevent
496 // lock-order inversions.
497 rtc::CriticalSection capturer_crit_;
498 std::map<uint32_t, VideoCapturer*> capturers_ GUARDED_BY(capturer_crit_);
499
500 rtc::CriticalSection stream_crit_; 501 rtc::CriticalSection stream_crit_;
501 // Using primary-ssrc (first ssrc) as key. 502 // Using primary-ssrc (first ssrc) as key.
502 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_ 503 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
503 GUARDED_BY(stream_crit_); 504 GUARDED_BY(stream_crit_);
504 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_ 505 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
505 GUARDED_BY(stream_crit_); 506 GUARDED_BY(stream_crit_);
506 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_); 507 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_);
507 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_); 508 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_);
508 509
509 rtc::Optional<VideoCodecSettings> send_codec_; 510 rtc::Optional<VideoCodecSettings> send_codec_;
510 std::vector<webrtc::RtpExtension> send_rtp_extensions_; 511 std::vector<webrtc::RtpExtension> send_rtp_extensions_;
511 512
512 WebRtcVideoEncoderFactory* const external_encoder_factory_; 513 WebRtcVideoEncoderFactory* const external_encoder_factory_;
513 WebRtcVideoDecoderFactory* const external_decoder_factory_; 514 WebRtcVideoDecoderFactory* const external_decoder_factory_;
514 std::vector<VideoCodecSettings> recv_codecs_; 515 std::vector<VideoCodecSettings> recv_codecs_;
515 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 516 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
516 webrtc::Call::Config::BitrateConfig bitrate_config_; 517 webrtc::Call::Config::BitrateConfig bitrate_config_;
517 // TODO(deadbeef): Don't duplicate information between 518 // TODO(deadbeef): Don't duplicate information between
518 // send_params/recv_params, rtp_extensions, options, etc. 519 // send_params/recv_params, rtp_extensions, options, etc.
519 VideoSendParameters send_params_; 520 VideoSendParameters send_params_;
520 VideoRecvParameters recv_params_; 521 VideoRecvParameters recv_params_;
521 }; 522 };
522 523
523 } // namespace cricket 524 } // namespace cricket
524 525
525 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ 526 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698