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