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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 struct AllocatedEncoder { | 312 struct AllocatedEncoder { |
313 AllocatedEncoder(webrtc::VideoEncoder* encoder, | 313 AllocatedEncoder(webrtc::VideoEncoder* encoder, |
314 webrtc::VideoCodecType type, | 314 webrtc::VideoCodecType type, |
315 bool external); | 315 bool external); |
316 webrtc::VideoEncoder* encoder; | 316 webrtc::VideoEncoder* encoder; |
317 webrtc::VideoEncoder* external_encoder; | 317 webrtc::VideoEncoder* external_encoder; |
318 webrtc::VideoCodecType type; | 318 webrtc::VideoCodecType type; |
319 bool external; | 319 bool external; |
320 }; | 320 }; |
321 | 321 |
| 322 // TODO(perkj): VideoFrameInfo is currently used for CPU adaptation since |
| 323 // we currently do not express CPU overuse using SinkWants in lower |
| 324 // layers. This will be fixed in an upcoming cl. |
322 struct VideoFrameInfo { | 325 struct VideoFrameInfo { |
323 // Initial encoder configuration (QCIF, 176x144) frame (to ensure that | |
324 // hardware encoders can be initialized). This gives us low memory usage | |
325 // but also makes it so configuration errors are discovered at the time we | |
326 // apply the settings rather than when we get the first frame (waiting for | |
327 // the first frame to know that you gave a bad codec parameter could make | |
328 // debugging hard). | |
329 // TODO(pbos): Consider setting up encoders lazily. | |
330 VideoFrameInfo() | 326 VideoFrameInfo() |
331 : width(176), | 327 : width(0), |
332 height(144), | 328 height(0), |
333 rotation(webrtc::kVideoRotation_0), | 329 rotation(webrtc::kVideoRotation_0), |
334 is_texture(false) {} | 330 is_texture(false) {} |
335 int width; | 331 int width; |
336 int height; | 332 int height; |
337 webrtc::VideoRotation rotation; | 333 webrtc::VideoRotation rotation; |
338 bool is_texture; | 334 bool is_texture; |
339 }; | 335 }; |
340 | 336 |
341 static std::vector<webrtc::VideoStream> CreateVideoStreams( | |
342 const VideoCodec& codec, | |
343 const VideoOptions& options, | |
344 int max_bitrate_bps, | |
345 size_t num_streams); | |
346 static std::vector<webrtc::VideoStream> CreateSimulcastVideoStreams( | |
347 const VideoCodec& codec, | |
348 const VideoOptions& options, | |
349 int max_bitrate_bps, | |
350 size_t num_streams); | |
351 | |
352 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> | 337 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> |
353 ConfigureVideoEncoderSettings(const VideoCodec& codec) | 338 ConfigureVideoEncoderSettings(const VideoCodec& codec); |
354 EXCLUSIVE_LOCKS_REQUIRED(lock_); | 339 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec); |
355 | 340 void DestroyVideoEncoder(AllocatedEncoder* encoder); |
356 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec) | 341 void SetCodec(const VideoCodecSettings& codec); |
357 EXCLUSIVE_LOCKS_REQUIRED(lock_); | 342 void RecreateWebRtcStream(); |
358 void DestroyVideoEncoder(AllocatedEncoder* encoder) | |
359 EXCLUSIVE_LOCKS_REQUIRED(lock_); | |
360 void SetCodec(const VideoCodecSettings& codec) | |
361 EXCLUSIVE_LOCKS_REQUIRED(lock_); | |
362 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_); | |
363 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( | 343 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( |
364 const VideoCodec& codec) const EXCLUSIVE_LOCKS_REQUIRED(lock_); | 344 const VideoCodec& codec) const; |
365 void ReconfigureEncoder() EXCLUSIVE_LOCKS_REQUIRED(lock_); | 345 void ReconfigureEncoder(); |
366 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); | 346 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); |
367 | 347 |
368 // Calls Start or Stop according to whether or not |sending_| is true, | 348 // Calls Start or Stop according to whether or not |sending_| is true, |
369 // and whether or not the encoding in |rtp_parameters_| is active. | 349 // and whether or not the encoding in |rtp_parameters_| is active. |
370 void UpdateSendState() EXCLUSIVE_LOCKS_REQUIRED(lock_); | 350 void UpdateSendState(); |
371 | 351 |
372 void UpdateHistograms() const EXCLUSIVE_LOCKS_REQUIRED(lock_); | 352 void UpdateHistograms() const EXCLUSIVE_LOCKS_REQUIRED(lock_); |
373 | 353 |
374 rtc::ThreadChecker thread_checker_; | 354 rtc::ThreadChecker thread_checker_; |
375 rtc::AsyncInvoker invoker_; | 355 rtc::AsyncInvoker invoker_; |
376 rtc::Thread* worker_thread_; | 356 rtc::Thread* worker_thread_; |
377 const std::vector<uint32_t> ssrcs_; | 357 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); |
378 const std::vector<SsrcGroup> ssrc_groups_; | 358 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); |
379 webrtc::Call* const call_; | 359 webrtc::Call* const call_; |
380 rtc::VideoSinkWants sink_wants_; | 360 rtc::VideoSinkWants sink_wants_ ACCESS_ON(&thread_checker_); |
381 // Counter used for deciding if the video resolution is currently | 361 // Counter used for deciding if the video resolution is currently |
382 // restricted by CPU usage. It is reset if |source_| is changed. | 362 // restricted by CPU usage. It is reset if |source_| is changed. |
383 int cpu_restricted_counter_; | 363 int cpu_restricted_counter_; |
384 // Total number of times resolution as been requested to be changed due to | 364 // Total number of times resolution as been requested to be changed due to |
385 // CPU adaptation. | 365 // CPU adaptation. |
386 int number_of_cpu_adapt_changes_; | 366 int number_of_cpu_adapt_changes_ ACCESS_ON(&thread_checker_); |
387 // Total number of frames sent to |stream_|. | 367 // Total number of frames sent to |stream_|. |
388 int frame_count_ GUARDED_BY(lock_); | 368 int frame_count_ GUARDED_BY(lock_); |
389 // Total number of cpu restricted frames sent to |stream_|. | 369 // Total number of cpu restricted frames sent to |stream_|. |
390 int cpu_restricted_frame_count_ GUARDED_BY(lock_); | 370 int cpu_restricted_frame_count_ GUARDED_BY(lock_); |
391 rtc::VideoSourceInterface<cricket::VideoFrame>* source_; | 371 rtc::VideoSourceInterface<cricket::VideoFrame>* source_ |
| 372 ACCESS_ON(&thread_checker_); |
392 WebRtcVideoEncoderFactory* const external_encoder_factory_ | 373 WebRtcVideoEncoderFactory* const external_encoder_factory_ |
393 GUARDED_BY(lock_); | 374 ACCESS_ON(&thread_checker_); |
394 | 375 |
395 rtc::CriticalSection lock_; | 376 rtc::CriticalSection lock_; |
396 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); | 377 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); |
397 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ | 378 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ |
398 GUARDED_BY(lock_); | 379 GUARDED_BY(lock_); |
399 // Contains settings that are the same for all streams in the MediaChannel, | 380 // Contains settings that are the same for all streams in the MediaChannel, |
400 // such as codecs, header extensions, and the global bitrate limit for the | 381 // such as codecs, header extensions, and the global bitrate limit for the |
401 // entire channel. | 382 // entire channel. |
402 VideoSendStreamParameters parameters_ GUARDED_BY(lock_); | 383 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); |
403 // Contains settings that are unique for each stream, such as max_bitrate. | 384 // Contains settings that are unique for each stream, such as max_bitrate. |
404 // Does *not* contain codecs, however. | 385 // Does *not* contain codecs, however. |
405 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. | 386 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. |
406 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only | 387 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only |
407 // one stream per MediaChannel. | 388 // one stream per MediaChannel. |
408 webrtc::RtpParameters rtp_parameters_ GUARDED_BY(lock_); | 389 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); |
409 bool pending_encoder_reconfiguration_ GUARDED_BY(lock_); | 390 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); |
410 AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_); | |
411 VideoFrameInfo last_frame_info_ GUARDED_BY(lock_); | 391 VideoFrameInfo last_frame_info_ GUARDED_BY(lock_); |
412 | 392 |
413 bool sending_ GUARDED_BY(lock_); | 393 bool sending_ ACCESS_ON(&thread_checker_); |
414 | 394 |
415 // The timestamp of the last frame received | 395 // The timestamp of the last frame received |
416 // Used to generate timestamp for the black frame when source is removed | 396 // Used to generate timestamp for the black frame when source is removed |
417 int64_t last_frame_timestamp_us_ GUARDED_BY(lock_); | 397 int64_t last_frame_timestamp_us_ GUARDED_BY(lock_); |
418 }; | 398 }; |
419 | 399 |
420 // Wrapper for the receiver part, contains configs etc. that are needed to | 400 // Wrapper for the receiver part, contains configs etc. that are needed to |
421 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper | 401 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
422 // between rtc::VideoSinkInterface<webrtc::VideoFrame> and | 402 // between rtc::VideoSinkInterface<webrtc::VideoFrame> and |
423 // rtc::VideoSinkInterface<cricket::VideoFrame>. | 403 // rtc::VideoSinkInterface<cricket::VideoFrame>. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 VideoSendParameters send_params_; | 538 VideoSendParameters send_params_; |
559 VideoOptions default_send_options_; | 539 VideoOptions default_send_options_; |
560 VideoRecvParameters recv_params_; | 540 VideoRecvParameters recv_params_; |
561 bool red_disabled_by_remote_side_; | 541 bool red_disabled_by_remote_side_; |
562 int64_t last_stats_log_ms_; | 542 int64_t last_stats_log_ms_; |
563 }; | 543 }; |
564 | 544 |
565 } // namespace cricket | 545 } // namespace cricket |
566 | 546 |
567 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 547 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
OLD | NEW |