| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media_recorder/video_track_recorder.h" | 5 #include "content/renderer/media_recorder/video_track_recorder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 bool VideoTrackRecorder::Encoder::CanEncodeAlphaChannel() { | 326 bool VideoTrackRecorder::Encoder::CanEncodeAlphaChannel() { |
| 327 return false; | 327 return false; |
| 328 } | 328 } |
| 329 | 329 |
| 330 // static | 330 // static |
| 331 VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() { | 331 VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() { |
| 332 return GetCodecEnumerator()->GetPreferredCodecId(); | 332 return GetCodecEnumerator()->GetPreferredCodecId(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 // static |
| 336 bool VideoTrackRecorder::CanUseAcceleratedEncoder(CodecId codec, |
| 337 size_t width, |
| 338 size_t height) { |
| 339 return GetCodecEnumerator()->CodecIdToVEAProfile(codec) != |
| 340 media::VIDEO_CODEC_PROFILE_UNKNOWN && |
| 341 width >= kVEAEncoderMinResolutionWidth && |
| 342 height >= kVEAEncoderMinResolutionHeight; |
| 343 } |
| 344 |
| 335 VideoTrackRecorder::VideoTrackRecorder( | 345 VideoTrackRecorder::VideoTrackRecorder( |
| 336 CodecId codec, | 346 CodecId codec, |
| 337 const blink::WebMediaStreamTrack& track, | 347 const blink::WebMediaStreamTrack& track, |
| 338 const OnEncodedVideoCB& on_encoded_video_callback, | 348 const OnEncodedVideoCB& on_encoded_video_callback, |
| 339 int32_t bits_per_second) | 349 int32_t bits_per_second) |
| 340 : track_(track), | 350 : track_(track), |
| 341 paused_before_init_(false), | 351 paused_before_init_(false), |
| 342 weak_ptr_factory_(this) { | 352 weak_ptr_factory_(this) { |
| 343 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 353 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 344 DCHECK(!track_.IsNull()); | 354 DCHECK(!track_.IsNull()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 413 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 404 | 414 |
| 405 // Avoid reinitializing |encoder_| when there are multiple frames sent to the | 415 // Avoid reinitializing |encoder_| when there are multiple frames sent to the |
| 406 // sink to initialize, https://crbug.com/698441. | 416 // sink to initialize, https://crbug.com/698441. |
| 407 if (encoder_) | 417 if (encoder_) |
| 408 return; | 418 return; |
| 409 | 419 |
| 410 MediaStreamVideoSink::DisconnectFromTrack(); | 420 MediaStreamVideoSink::DisconnectFromTrack(); |
| 411 | 421 |
| 412 const gfx::Size& input_size = frame->visible_rect().size(); | 422 const gfx::Size& input_size = frame->visible_rect().size(); |
| 413 const auto& vea_supported_profile = | 423 if (allow_vea_encoder && CanUseAcceleratedEncoder(codec, input_size.width(), |
| 414 GetCodecEnumerator()->CodecIdToVEAProfile(codec); | 424 input_size.height())) { |
| 415 if (allow_vea_encoder && | 425 const auto vea_profile = GetCodecEnumerator()->CodecIdToVEAProfile(codec); |
| 416 vea_supported_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN && | |
| 417 input_size.width() >= kVEAEncoderMinResolutionWidth && | |
| 418 input_size.height() >= kVEAEncoderMinResolutionHeight) { | |
| 419 encoder_ = new VEAEncoder( | 426 encoder_ = new VEAEncoder( |
| 420 on_encoded_video_callback, | 427 on_encoded_video_callback, |
| 421 media::BindToCurrentLoop(base::Bind(&VideoTrackRecorder::OnError, | 428 media::BindToCurrentLoop(base::Bind(&VideoTrackRecorder::OnError, |
| 422 weak_ptr_factory_.GetWeakPtr())), | 429 weak_ptr_factory_.GetWeakPtr())), |
| 423 bits_per_second, vea_supported_profile, input_size); | 430 bits_per_second, vea_profile, input_size); |
| 424 } else { | 431 } else { |
| 425 switch (codec) { | 432 switch (codec) { |
| 426 #if BUILDFLAG(RTC_USE_H264) | 433 #if BUILDFLAG(RTC_USE_H264) |
| 427 case CodecId::H264: | 434 case CodecId::H264: |
| 428 encoder_ = | 435 encoder_ = |
| 429 new H264Encoder(on_encoded_video_callback, bits_per_second); | 436 new H264Encoder(on_encoded_video_callback, bits_per_second); |
| 430 break; | 437 break; |
| 431 #endif | 438 #endif |
| 432 case CodecId::VP8: | 439 case CodecId::VP8: |
| 433 case CodecId::VP9: | 440 case CodecId::VP9: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 458 MediaStreamVideoSink::DisconnectFromTrack(); | 465 MediaStreamVideoSink::DisconnectFromTrack(); |
| 459 encoder_ = nullptr; | 466 encoder_ = nullptr; |
| 460 MediaStreamVideoSink::ConnectToTrack( | 467 MediaStreamVideoSink::ConnectToTrack( |
| 461 track_, | 468 track_, |
| 462 media::BindToCurrentLoop(base::Bind(initialize_encoder_callback_, | 469 media::BindToCurrentLoop(base::Bind(initialize_encoder_callback_, |
| 463 false /*allow_vea_encoder*/)), | 470 false /*allow_vea_encoder*/)), |
| 464 false); | 471 false); |
| 465 } | 472 } |
| 466 | 473 |
| 467 } // namespace content | 474 } // namespace content |
| OLD | NEW |