| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/gpu/media/vaapi_video_encode_accelerator.h" | 5 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 DCHECK_EQ(x & (x - 1), 0u); | 135 DCHECK_EQ(x & (x - 1), 0u); |
| 136 | 136 |
| 137 int log = 0; | 137 int log = 0; |
| 138 while (x) { | 138 while (x) { |
| 139 x >>= 1; | 139 x >>= 1; |
| 140 ++log; | 140 ++log; |
| 141 } | 141 } |
| 142 return log; | 142 return log; |
| 143 } | 143 } |
| 144 | 144 |
| 145 VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator(Display* x_display) | 145 VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator() |
| 146 : profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN), | 146 : profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN), |
| 147 mb_width_(0), | 147 mb_width_(0), |
| 148 mb_height_(0), | 148 mb_height_(0), |
| 149 output_buffer_byte_size_(0), | 149 output_buffer_byte_size_(0), |
| 150 x_display_(x_display), | |
| 151 state_(kUninitialized), | 150 state_(kUninitialized), |
| 152 frame_num_(0), | 151 frame_num_(0), |
| 153 last_idr_frame_num_(0), | 152 last_idr_frame_num_(0), |
| 154 bitrate_(0), | 153 bitrate_(0), |
| 155 framerate_(0), | 154 framerate_(0), |
| 156 cpb_size_(0), | 155 cpb_size_(0), |
| 157 encoding_parameters_changed_(false), | 156 encoding_parameters_changed_(false), |
| 158 encoder_thread_("VAVEAEncoderThread"), | 157 encoder_thread_("VAVEAEncoderThread"), |
| 159 child_message_loop_proxy_(base::MessageLoopProxy::current()), | 158 child_message_loop_proxy_(base::MessageLoopProxy::current()), |
| 160 weak_this_ptr_factory_(this) { | 159 weak_this_ptr_factory_(this) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 coded_size_ = gfx::Size(RoundUpToPowerOf2(visible_size_.width(), 16), | 212 coded_size_ = gfx::Size(RoundUpToPowerOf2(visible_size_.width(), 16), |
| 214 RoundUpToPowerOf2(visible_size_.height(), 16)); | 213 RoundUpToPowerOf2(visible_size_.height(), 16)); |
| 215 mb_width_ = coded_size_.width() / 16; | 214 mb_width_ = coded_size_.width() / 16; |
| 216 mb_height_ = coded_size_.height() / 16; | 215 mb_height_ = coded_size_.height() / 16; |
| 217 output_buffer_byte_size_ = coded_size_.GetArea(); | 216 output_buffer_byte_size_ = coded_size_.GetArea(); |
| 218 | 217 |
| 219 UpdateRates(initial_bitrate, kDefaultFramerate); | 218 UpdateRates(initial_bitrate, kDefaultFramerate); |
| 220 | 219 |
| 221 vaapi_wrapper_ = VaapiWrapper::Create(VaapiWrapper::kEncode, | 220 vaapi_wrapper_ = VaapiWrapper::Create(VaapiWrapper::kEncode, |
| 222 output_profile, | 221 output_profile, |
| 223 x_display_, | |
| 224 base::Bind(&ReportToUMA, VAAPI_ERROR)); | 222 base::Bind(&ReportToUMA, VAAPI_ERROR)); |
| 225 if (!vaapi_wrapper_) { | 223 if (!vaapi_wrapper_) { |
| 226 DVLOGF(1) << "Failed initializing VAAPI"; | 224 DVLOGF(1) << "Failed initializing VAAPI"; |
| 227 return false; | 225 return false; |
| 228 } | 226 } |
| 229 | 227 |
| 230 if (!encoder_thread_.Start()) { | 228 if (!encoder_thread_.Start()) { |
| 231 DVLOGF(1) << "Failed to start encoder thread"; | 229 DVLOGF(1) << "Failed to start encoder thread"; |
| 232 return false; | 230 return false; |
| 233 } | 231 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 599 |
| 602 DCHECK(!current_encode_job_); | 600 DCHECK(!current_encode_job_); |
| 603 current_encode_job_.reset(new EncodeJob()); | 601 current_encode_job_.reset(new EncodeJob()); |
| 604 | 602 |
| 605 if (!vaapi_wrapper_->CreateCodedBuffer(output_buffer_byte_size_, | 603 if (!vaapi_wrapper_->CreateCodedBuffer(output_buffer_byte_size_, |
| 606 ¤t_encode_job_->coded_buffer)) { | 604 ¤t_encode_job_->coded_buffer)) { |
| 607 NOTIFY_ERROR(kPlatformFailureError, "Failed creating coded buffer"); | 605 NOTIFY_ERROR(kPlatformFailureError, "Failed creating coded buffer"); |
| 608 return false; | 606 return false; |
| 609 } | 607 } |
| 610 | 608 |
| 611 current_encode_job_->input_surface = | 609 current_encode_job_->input_surface = new VASurface( |
| 612 new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_); | 610 available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_); |
| 613 available_va_surface_ids_.pop_back(); | 611 available_va_surface_ids_.pop_back(); |
| 614 | 612 |
| 615 current_encode_job_->recon_surface = | 613 current_encode_job_->recon_surface = new VASurface( |
| 616 new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_); | 614 available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_); |
| 617 available_va_surface_ids_.pop_back(); | 615 available_va_surface_ids_.pop_back(); |
| 618 | 616 |
| 619 // Reference surfaces are needed until the job is done, but they get | 617 // Reference surfaces are needed until the job is done, but they get |
| 620 // removed from ref_pic_list0_ when it's full at the end of job submission. | 618 // removed from ref_pic_list0_ when it's full at the end of job submission. |
| 621 // Keep refs to them along with the job and only release after sync. | 619 // Keep refs to them along with the job and only release after sync. |
| 622 current_encode_job_->reference_surfaces = ref_pic_list0_; | 620 current_encode_job_->reference_surfaces = ref_pic_list0_; |
| 623 | 621 |
| 624 return true; | 622 return true; |
| 625 } | 623 } |
| 626 | 624 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 } | 1060 } |
| 1063 | 1061 |
| 1064 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob() | 1062 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob() |
| 1065 : coded_buffer(VA_INVALID_ID), keyframe(false) { | 1063 : coded_buffer(VA_INVALID_ID), keyframe(false) { |
| 1066 } | 1064 } |
| 1067 | 1065 |
| 1068 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() { | 1066 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() { |
| 1069 } | 1067 } |
| 1070 | 1068 |
| 1071 } // namespace content | 1069 } // namespace content |
| OLD | NEW |