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