Chromium Code Reviews| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 320 |
| 321 bool VideoTrackRecorder::Encoder::CanEncodeAlphaChannel() { | 321 bool VideoTrackRecorder::Encoder::CanEncodeAlphaChannel() { |
| 322 return false; | 322 return false; |
| 323 } | 323 } |
| 324 | 324 |
| 325 // static | 325 // static |
| 326 VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() { | 326 VideoTrackRecorder::CodecId VideoTrackRecorder::GetPreferredCodecId() { |
| 327 return GetCodecEnumerator()->GetPreferredCodecId(); | 327 return GetCodecEnumerator()->GetPreferredCodecId(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 // static | |
| 331 bool VideoTrackRecorder::IsEncodingLikelyAccelerated(CodecId codec, | |
| 332 size_t width, | |
| 333 size_t height) { | |
| 334 return GetCodecEnumerator()->CodecIdToVEAProfile(codec) != | |
| 335 media::VIDEO_CODEC_PROFILE_UNKNOWN && | |
| 336 width >= kVEAEncoderMinResolutionWidth && | |
| 337 height >= kVEAEncoderMinResolutionHeight; | |
| 338 } | |
| 339 | |
| 330 VideoTrackRecorder::VideoTrackRecorder( | 340 VideoTrackRecorder::VideoTrackRecorder( |
| 331 CodecId codec, | 341 CodecId codec, |
| 332 const blink::WebMediaStreamTrack& track, | 342 const blink::WebMediaStreamTrack& track, |
| 333 const OnEncodedVideoCB& on_encoded_video_callback, | 343 const OnEncodedVideoCB& on_encoded_video_callback, |
| 334 int32_t bits_per_second) | 344 int32_t bits_per_second) |
| 335 : track_(track), | 345 : track_(track), |
| 336 paused_before_init_(false), | 346 paused_before_init_(false), |
| 337 weak_ptr_factory_(this) { | 347 weak_ptr_factory_(this) { |
| 338 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 348 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 339 DCHECK(!track_.IsNull()); | 349 DCHECK(!track_.IsNull()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 DCHECK(main_render_thread_checker_.CalledOnValidThread()); | 408 DCHECK(main_render_thread_checker_.CalledOnValidThread()); |
| 399 | 409 |
| 400 // Avoid reinitializing |encoder_| when there are multiple frames sent to the | 410 // Avoid reinitializing |encoder_| when there are multiple frames sent to the |
| 401 // sink to initialize, https://crbug.com/698441. | 411 // sink to initialize, https://crbug.com/698441. |
| 402 if (encoder_) | 412 if (encoder_) |
| 403 return; | 413 return; |
| 404 | 414 |
| 405 MediaStreamVideoSink::DisconnectFromTrack(); | 415 MediaStreamVideoSink::DisconnectFromTrack(); |
| 406 | 416 |
| 407 const gfx::Size& input_size = frame->visible_rect().size(); | 417 const gfx::Size& input_size = frame->visible_rect().size(); |
| 408 const auto& vea_supported_profile = | |
| 409 GetCodecEnumerator()->CodecIdToVEAProfile(codec); | |
| 410 if (allow_vea_encoder && | 418 if (allow_vea_encoder && |
| 411 vea_supported_profile != media::VIDEO_CODEC_PROFILE_UNKNOWN && | 419 IsEncodingLikelyAccelerated(codec, input_size.width(), |
|
emircan
2017/04/25 02:04:30
This serves as a decision mechanism of accelerated
mcasas
2017/04/25 18:16:07
CanUseAcceleratedEncoder() ?
| |
| 412 input_size.width() >= kVEAEncoderMinResolutionWidth && | 420 input_size.height())) { |
| 413 input_size.height() >= kVEAEncoderMinResolutionHeight) { | 421 const auto vea_profile = GetCodecEnumerator()->CodecIdToVEAProfile(codec); |
| 414 encoder_ = new VEAEncoder( | 422 encoder_ = new VEAEncoder( |
| 415 on_encoded_video_callback, | 423 on_encoded_video_callback, |
| 416 media::BindToCurrentLoop(base::Bind(&VideoTrackRecorder::OnError, | 424 media::BindToCurrentLoop(base::Bind(&VideoTrackRecorder::OnError, |
| 417 weak_ptr_factory_.GetWeakPtr())), | 425 weak_ptr_factory_.GetWeakPtr())), |
| 418 bits_per_second, vea_supported_profile, input_size); | 426 bits_per_second, vea_profile, input_size); |
| 419 } else { | 427 } else { |
| 420 switch (codec) { | 428 switch (codec) { |
| 421 #if BUILDFLAG(RTC_USE_H264) | 429 #if BUILDFLAG(RTC_USE_H264) |
| 422 case CodecId::H264: | 430 case CodecId::H264: |
| 423 encoder_ = | 431 encoder_ = |
| 424 new H264Encoder(on_encoded_video_callback, bits_per_second); | 432 new H264Encoder(on_encoded_video_callback, bits_per_second); |
| 425 break; | 433 break; |
| 426 #endif | 434 #endif |
| 427 case CodecId::VP8: | 435 case CodecId::VP8: |
| 428 case CodecId::VP9: | 436 case CodecId::VP9: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 453 MediaStreamVideoSink::DisconnectFromTrack(); | 461 MediaStreamVideoSink::DisconnectFromTrack(); |
| 454 encoder_ = nullptr; | 462 encoder_ = nullptr; |
| 455 MediaStreamVideoSink::ConnectToTrack( | 463 MediaStreamVideoSink::ConnectToTrack( |
| 456 track_, | 464 track_, |
| 457 media::BindToCurrentLoop(base::Bind(initialize_encoder_callback_, | 465 media::BindToCurrentLoop(base::Bind(initialize_encoder_callback_, |
| 458 false /*allow_vea_encoder*/)), | 466 false /*allow_vea_encoder*/)), |
| 459 false); | 467 false); |
| 460 } | 468 } |
| 461 | 469 |
| 462 } // namespace content | 470 } // namespace content |
| OLD | NEW |