OLD | NEW |
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 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) | 234 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) |
235 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | 235 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); |
236 | 236 |
237 static std::string CodecSettingsVectorToString( | 237 static std::string CodecSettingsVectorToString( |
238 const std::vector<VideoCodecSettings>& codecs); | 238 const std::vector<VideoCodecSettings>& codecs); |
239 | 239 |
240 // Wrapper for the sender part, this is where the source is connected and | 240 // Wrapper for the sender part, this is where the source is connected and |
241 // frames are then converted from cricket frames to webrtc frames. | 241 // frames are then converted from cricket frames to webrtc frames. |
242 class WebRtcVideoSendStream | 242 class WebRtcVideoSendStream |
243 : public rtc::VideoSinkInterface<cricket::VideoFrame>, | 243 : public rtc::VideoSinkInterface<cricket::VideoFrame>, |
244 public rtc::VideoSourceInterface<webrtc::VideoFrame>, | 244 public rtc::VideoSourceInterface<webrtc::VideoFrame> { |
245 public webrtc::LoadObserver { | |
246 public: | 245 public: |
247 WebRtcVideoSendStream( | 246 WebRtcVideoSendStream( |
248 webrtc::Call* call, | 247 webrtc::Call* call, |
249 const StreamParams& sp, | 248 const StreamParams& sp, |
250 webrtc::VideoSendStream::Config config, | 249 webrtc::VideoSendStream::Config config, |
251 const VideoOptions& options, | 250 const VideoOptions& options, |
252 WebRtcVideoEncoderFactory* external_encoder_factory, | 251 WebRtcVideoEncoderFactory* external_encoder_factory, |
253 bool enable_cpu_overuse_detection, | 252 bool enable_cpu_overuse_detection, |
254 int max_bitrate_bps, | 253 int max_bitrate_bps, |
255 const rtc::Optional<VideoCodecSettings>& codec_settings, | 254 const rtc::Optional<VideoCodecSettings>& codec_settings, |
(...skipping 12 matching lines...) Expand all Loading... |
268 // TODO(perkj, nisse): Refactor WebRtcVideoSendStream to directly connect | 267 // TODO(perkj, nisse): Refactor WebRtcVideoSendStream to directly connect |
269 // the camera input |source_| | 268 // the camera input |source_| |
270 void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink, | 269 void AddOrUpdateSink(VideoSinkInterface<webrtc::VideoFrame>* sink, |
271 const rtc::VideoSinkWants& wants) override; | 270 const rtc::VideoSinkWants& wants) override; |
272 void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override; | 271 void RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) override; |
273 | 272 |
274 void OnFrame(const cricket::VideoFrame& frame) override; | 273 void OnFrame(const cricket::VideoFrame& frame) override; |
275 bool SetVideoSend(bool mute, | 274 bool SetVideoSend(bool mute, |
276 const VideoOptions* options, | 275 const VideoOptions* options, |
277 rtc::VideoSourceInterface<cricket::VideoFrame>* source); | 276 rtc::VideoSourceInterface<cricket::VideoFrame>* source); |
278 void DisconnectSource(); | |
279 | 277 |
280 void SetSend(bool send); | 278 void SetSend(bool send); |
281 | 279 |
282 // Implements webrtc::LoadObserver. | |
283 void OnLoadUpdate(Load load) override; | |
284 | |
285 const std::vector<uint32_t>& GetSsrcs() const; | 280 const std::vector<uint32_t>& GetSsrcs() const; |
286 VideoSenderInfo GetVideoSenderInfo(bool log_stats); | 281 VideoSenderInfo GetVideoSenderInfo(bool log_stats); |
287 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); | 282 void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); |
288 | 283 |
289 private: | 284 private: |
290 // Parameters needed to reconstruct the underlying stream. | 285 // Parameters needed to reconstruct the underlying stream. |
291 // webrtc::VideoSendStream doesn't support setting a lot of options on the | 286 // webrtc::VideoSendStream doesn't support setting a lot of options on the |
292 // fly, so when those need to be changed we tear down and reconstruct with | 287 // fly, so when those need to be changed we tear down and reconstruct with |
293 // similar parameters depending on which options changed etc. | 288 // similar parameters depending on which options changed etc. |
294 struct VideoSendStreamParameters { | 289 struct VideoSendStreamParameters { |
(...skipping 16 matching lines...) Expand all Loading... |
311 struct AllocatedEncoder { | 306 struct AllocatedEncoder { |
312 AllocatedEncoder(webrtc::VideoEncoder* encoder, | 307 AllocatedEncoder(webrtc::VideoEncoder* encoder, |
313 webrtc::VideoCodecType type, | 308 webrtc::VideoCodecType type, |
314 bool external); | 309 bool external); |
315 webrtc::VideoEncoder* encoder; | 310 webrtc::VideoEncoder* encoder; |
316 webrtc::VideoEncoder* external_encoder; | 311 webrtc::VideoEncoder* external_encoder; |
317 webrtc::VideoCodecType type; | 312 webrtc::VideoCodecType type; |
318 bool external; | 313 bool external; |
319 }; | 314 }; |
320 | 315 |
321 // TODO(perkj): VideoFrameInfo is currently used for CPU adaptation since | 316 // TODO(perkj): VideoFrameInfo is currently used for sending a black frame |
322 // we currently do not express CPU overuse using SinkWants in lower | 317 // when the video source is removed. Consider moving that logic to |
323 // layers. This will be fixed in an upcoming cl. | 318 // VieEncoder or remove it. |
324 struct VideoFrameInfo { | 319 struct VideoFrameInfo { |
325 VideoFrameInfo() | 320 VideoFrameInfo() |
326 : width(0), | 321 : width(0), |
327 height(0), | 322 height(0), |
328 rotation(webrtc::kVideoRotation_0), | 323 rotation(webrtc::kVideoRotation_0), |
329 is_texture(false) {} | 324 is_texture(false) {} |
330 int width; | 325 int width; |
331 int height; | 326 int height; |
332 webrtc::VideoRotation rotation; | 327 webrtc::VideoRotation rotation; |
333 bool is_texture; | 328 bool is_texture; |
334 }; | 329 }; |
335 | 330 |
336 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> | 331 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> |
337 ConfigureVideoEncoderSettings(const VideoCodec& codec); | 332 ConfigureVideoEncoderSettings(const VideoCodec& codec); |
338 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec); | 333 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec); |
339 void DestroyVideoEncoder(AllocatedEncoder* encoder); | 334 void DestroyVideoEncoder(AllocatedEncoder* encoder); |
340 void SetCodec(const VideoCodecSettings& codec); | 335 void SetCodec(const VideoCodecSettings& codec); |
341 void RecreateWebRtcStream(); | 336 void RecreateWebRtcStream(); |
342 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( | 337 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( |
343 const VideoCodec& codec) const; | 338 const VideoCodec& codec) const; |
344 void ReconfigureEncoder(); | 339 void ReconfigureEncoder(); |
345 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); | 340 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); |
346 | 341 |
347 // Calls Start or Stop according to whether or not |sending_| is true, | 342 // Calls Start or Stop according to whether or not |sending_| is true, |
348 // and whether or not the encoding in |rtp_parameters_| is active. | 343 // and whether or not the encoding in |rtp_parameters_| is active. |
349 void UpdateSendState(); | 344 void UpdateSendState(); |
350 | 345 |
351 void UpdateHistograms() const EXCLUSIVE_LOCKS_REQUIRED(lock_); | |
352 | |
353 rtc::ThreadChecker thread_checker_; | 346 rtc::ThreadChecker thread_checker_; |
354 rtc::AsyncInvoker invoker_; | 347 rtc::AsyncInvoker invoker_; |
355 rtc::Thread* worker_thread_; | 348 rtc::Thread* worker_thread_; |
356 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); | 349 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); |
357 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); | 350 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); |
358 webrtc::Call* const call_; | 351 webrtc::Call* const call_; |
359 rtc::VideoSinkWants sink_wants_ ACCESS_ON(&thread_checker_); | 352 const bool enable_cpu_overuse_detection_; |
360 // Counter used for deciding if the video resolution is currently | |
361 // restricted by CPU usage. It is reset if |source_| is changed. | |
362 int cpu_restricted_counter_; | |
363 // Total number of times resolution as been requested to be changed due to | |
364 // CPU adaptation. | |
365 int number_of_cpu_adapt_changes_ ACCESS_ON(&thread_checker_); | |
366 // Total number of frames sent to |stream_|. | |
367 int frame_count_ GUARDED_BY(lock_); | |
368 // Total number of cpu restricted frames sent to |stream_|. | |
369 int cpu_restricted_frame_count_ GUARDED_BY(lock_); | |
370 rtc::VideoSourceInterface<cricket::VideoFrame>* source_ | 353 rtc::VideoSourceInterface<cricket::VideoFrame>* source_ |
371 ACCESS_ON(&thread_checker_); | 354 ACCESS_ON(&thread_checker_); |
372 WebRtcVideoEncoderFactory* const external_encoder_factory_ | 355 WebRtcVideoEncoderFactory* const external_encoder_factory_ |
373 ACCESS_ON(&thread_checker_); | 356 ACCESS_ON(&thread_checker_); |
374 | 357 |
375 rtc::CriticalSection lock_; | 358 rtc::CriticalSection lock_; |
376 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); | 359 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); |
377 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ | 360 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ |
378 GUARDED_BY(lock_); | 361 GUARDED_BY(lock_); |
379 // Contains settings that are the same for all streams in the MediaChannel, | 362 // Contains settings that are the same for all streams in the MediaChannel, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 VideoSendParameters send_params_; | 520 VideoSendParameters send_params_; |
538 VideoOptions default_send_options_; | 521 VideoOptions default_send_options_; |
539 VideoRecvParameters recv_params_; | 522 VideoRecvParameters recv_params_; |
540 bool red_disabled_by_remote_side_; | 523 bool red_disabled_by_remote_side_; |
541 int64_t last_stats_log_ms_; | 524 int64_t last_stats_log_ms_; |
542 }; | 525 }; |
543 | 526 |
544 } // namespace cricket | 527 } // namespace cricket |
545 | 528 |
546 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 529 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
OLD | NEW |