| 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/video_track_recorder.h" | 5 #include "content/renderer/media/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 using media::VideoFrame; | 46 using media::VideoFrame; |
| 47 using media::VideoFrameMetadata; | 47 using media::VideoFrameMetadata; |
| 48 using video_track_recorder::kVEAEncoderMinResolutionWidth; | 48 using video_track_recorder::kVEAEncoderMinResolutionWidth; |
| 49 using video_track_recorder::kVEAEncoderMinResolutionHeight; | 49 using video_track_recorder::kVEAEncoderMinResolutionHeight; |
| 50 | 50 |
| 51 namespace content { | 51 namespace content { |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 // HW encoders expect a nonzero bitrate, so |kVEADefaultBitratePerPixel| is used |
| 56 // to estimate bits per second for ~30 fps with ~1/16 compression rate. |
| 57 const int kVEADefaultBitratePerPixel = 2; |
| 58 // Number of output buffers used to copy the encoded data coming from HW |
| 59 // encoders. |
| 55 const int kVEAEncoderOutputBufferCount = 4; | 60 const int kVEAEncoderOutputBufferCount = 4; |
| 56 | 61 |
| 57 static struct { | 62 static struct { |
| 58 VideoTrackRecorder::CodecId codec_id; | 63 VideoTrackRecorder::CodecId codec_id; |
| 59 media::VideoCodecProfile min_profile; | 64 media::VideoCodecProfile min_profile; |
| 60 media::VideoCodecProfile max_profile; | 65 media::VideoCodecProfile max_profile; |
| 61 } const kSupportedVideoCodecIdToProfile[] = { | 66 } const kSupportedVideoCodecIdToProfile[] = { |
| 62 {VideoTrackRecorder::CodecId::VP8, | 67 {VideoTrackRecorder::CodecId::VP8, |
| 63 media::VP8PROFILE_MIN, | 68 media::VP8PROFILE_MIN, |
| 64 media::VP8PROFILE_MAX}, | 69 media::VP8PROFILE_MAX}, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 }; | 500 }; |
| 496 | 501 |
| 497 #endif // #if BUILDFLAG(RTC_USE_H264) | 502 #endif // #if BUILDFLAG(RTC_USE_H264) |
| 498 | 503 |
| 499 VEAEncoder::VEAEncoder( | 504 VEAEncoder::VEAEncoder( |
| 500 const VideoTrackRecorder::OnEncodedVideoCB& on_encoded_video_callback, | 505 const VideoTrackRecorder::OnEncodedVideoCB& on_encoded_video_callback, |
| 501 int32_t bits_per_second, | 506 int32_t bits_per_second, |
| 502 media::VideoCodecProfile codec, | 507 media::VideoCodecProfile codec, |
| 503 const gfx::Size& size) | 508 const gfx::Size& size) |
| 504 : Encoder(on_encoded_video_callback, | 509 : Encoder(on_encoded_video_callback, |
| 505 bits_per_second, | 510 bits_per_second > 0 ? bits_per_second |
| 511 : size.GetArea() * kVEADefaultBitratePerPixel, |
| 506 RenderThreadImpl::current()->GetGpuFactories()->GetTaskRunner()), | 512 RenderThreadImpl::current()->GetGpuFactories()->GetTaskRunner()), |
| 507 gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()), | 513 gpu_factories_(RenderThreadImpl::current()->GetGpuFactories()), |
| 508 codec_(codec), | 514 codec_(codec), |
| 509 error_notified_(false) { | 515 error_notified_(false) { |
| 510 DCHECK(gpu_factories_); | 516 DCHECK(gpu_factories_); |
| 511 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); | 517 DCHECK_GE(size.width(), kVEAEncoderMinResolutionWidth); |
| 512 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight); | 518 DCHECK_GE(size.height(), kVEAEncoderMinResolutionHeight); |
| 513 | 519 |
| 514 encoding_task_runner_->PostTask( | 520 encoding_task_runner_->PostTask( |
| 515 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner, | 521 FROM_HERE, base::Bind(&VEAEncoder::ConfigureEncoderOnEncodingTaskRunner, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 encoding_task_runner_->PostTask( | 684 encoding_task_runner_->PostTask( |
| 679 FROM_HERE, | 685 FROM_HERE, |
| 680 base::Bind(&media::VideoEncodeAccelerator::Encode, | 686 base::Bind(&media::VideoEncodeAccelerator::Encode, |
| 681 base::Unretained(video_encoder_.get()), video_frame, false)); | 687 base::Unretained(video_encoder_.get()), video_frame, false)); |
| 682 } | 688 } |
| 683 | 689 |
| 684 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { | 690 void VEAEncoder::ConfigureEncoderOnEncodingTaskRunner(const gfx::Size& size) { |
| 685 DVLOG(3) << __func__; | 691 DVLOG(3) << __func__; |
| 686 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); | 692 DCHECK(encoding_task_runner_->BelongsToCurrentThread()); |
| 687 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); | 693 DCHECK(gpu_factories_->GetTaskRunner()->BelongsToCurrentThread()); |
| 694 DCHECK_GT(bits_per_second_, 0); |
| 688 | 695 |
| 689 input_size_ = size; | 696 input_size_ = size; |
| 690 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator(); | 697 video_encoder_ = gpu_factories_->CreateVideoEncodeAccelerator(); |
| 691 if (!video_encoder_ || | 698 if (!video_encoder_ || |
| 692 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_, | 699 !video_encoder_->Initialize(media::PIXEL_FORMAT_I420, input_size_, codec_, |
| 693 bits_per_second_, this)) { | 700 bits_per_second_, this)) { |
| 694 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 701 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 695 } | 702 } |
| 696 } | 703 } |
| 697 | 704 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 encoder_->SetPaused(paused_before_init_); | 1156 encoder_->SetPaused(paused_before_init_); |
| 1150 | 1157 |
| 1151 // StartFrameEncode() will be called on Render IO thread. | 1158 // StartFrameEncode() will be called on Render IO thread. |
| 1152 MediaStreamVideoSink::ConnectToTrack( | 1159 MediaStreamVideoSink::ConnectToTrack( |
| 1153 track_, | 1160 track_, |
| 1154 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), | 1161 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), |
| 1155 false); | 1162 false); |
| 1156 } | 1163 } |
| 1157 | 1164 |
| 1158 } // namespace content | 1165 } // namespace content |
| OLD | NEW |