Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: content/common/gpu/media/vaapi_video_encode_accelerator.cc

Issue 817023005: Reland: Refactor Vaapi video decoder/encoder in preparation of Freon support (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Remove refcounting on VaapiWrapper Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 std::vector<media::VideoEncodeAccelerator::SupportedProfile> 107 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
108 VaapiVideoEncodeAccelerator::GetSupportedProfiles() { 108 VaapiVideoEncodeAccelerator::GetSupportedProfiles() {
109 std::vector<SupportedProfile> profiles; 109 std::vector<SupportedProfile> profiles;
110 110
111 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 111 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
112 if (cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) 112 if (cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode))
113 return profiles; 113 return profiles;
114 114
115 std::vector<media::VideoCodecProfile> hw_profiles = 115 std::vector<media::VideoCodecProfile> hw_profiles =
116 VaapiWrapper::GetSupportedEncodeProfiles( 116 VaapiWrapper::GetSupportedEncodeProfiles(base::Bind(&base::DoNothing));
117 x_display_, base::Bind(&base::DoNothing));
118 117
119 media::VideoEncodeAccelerator::SupportedProfile profile; 118 media::VideoEncodeAccelerator::SupportedProfile profile;
120 profile.max_resolution.SetSize(1920, 1088); 119 profile.max_resolution.SetSize(1920, 1088);
121 profile.max_framerate_numerator = kDefaultFramerate; 120 profile.max_framerate_numerator = kDefaultFramerate;
122 profile.max_framerate_denominator = 1; 121 profile.max_framerate_denominator = 1;
123 for (size_t i = 0; i < hw_profiles.size(); i++) { 122 for (size_t i = 0; i < hw_profiles.size(); i++) {
124 profile.profile = hw_profiles[i]; 123 profile.profile = hw_profiles[i];
125 profiles.push_back(profile); 124 profiles.push_back(profile);
126 } 125 }
127 return profiles; 126 return profiles;
128 } 127 }
129 128
130 static unsigned int Log2OfPowerOf2(unsigned int x) { 129 static unsigned int Log2OfPowerOf2(unsigned int x) {
131 CHECK_GT(x, 0u); 130 CHECK_GT(x, 0u);
132 DCHECK_EQ(x & (x - 1), 0u); 131 DCHECK_EQ(x & (x - 1), 0u);
133 132
134 int log = 0; 133 int log = 0;
135 while (x) { 134 while (x) {
136 x >>= 1; 135 x >>= 1;
137 ++log; 136 ++log;
138 } 137 }
139 return log; 138 return log;
140 } 139 }
141 140
142 VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator(Display* x_display) 141 VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator()
143 : profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN), 142 : profile_(media::VIDEO_CODEC_PROFILE_UNKNOWN),
144 mb_width_(0), 143 mb_width_(0),
145 mb_height_(0), 144 mb_height_(0),
146 output_buffer_byte_size_(0), 145 output_buffer_byte_size_(0),
147 x_display_(x_display),
148 state_(kUninitialized), 146 state_(kUninitialized),
149 frame_num_(0), 147 frame_num_(0),
150 last_idr_frame_num_(0), 148 last_idr_frame_num_(0),
151 bitrate_(0), 149 bitrate_(0),
152 framerate_(0), 150 framerate_(0),
153 cpb_size_(0), 151 cpb_size_(0),
154 encoding_parameters_changed_(false), 152 encoding_parameters_changed_(false),
155 encoder_thread_("VAVEAEncoderThread"), 153 encoder_thread_("VAVEAEncoderThread"),
156 child_message_loop_proxy_(base::MessageLoopProxy::current()), 154 child_message_loop_proxy_(base::MessageLoopProxy::current()),
157 weak_this_ptr_factory_(this) { 155 weak_this_ptr_factory_(this) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 coded_size_ = gfx::Size(RoundUpToPowerOf2(visible_size_.width(), 16), 208 coded_size_ = gfx::Size(RoundUpToPowerOf2(visible_size_.width(), 16),
211 RoundUpToPowerOf2(visible_size_.height(), 16)); 209 RoundUpToPowerOf2(visible_size_.height(), 16));
212 mb_width_ = coded_size_.width() / 16; 210 mb_width_ = coded_size_.width() / 16;
213 mb_height_ = coded_size_.height() / 16; 211 mb_height_ = coded_size_.height() / 16;
214 output_buffer_byte_size_ = coded_size_.GetArea(); 212 output_buffer_byte_size_ = coded_size_.GetArea();
215 213
216 UpdateRates(initial_bitrate, kDefaultFramerate); 214 UpdateRates(initial_bitrate, kDefaultFramerate);
217 215
218 vaapi_wrapper_ = VaapiWrapper::Create(VaapiWrapper::kEncode, 216 vaapi_wrapper_ = VaapiWrapper::Create(VaapiWrapper::kEncode,
219 output_profile, 217 output_profile,
220 x_display_,
221 base::Bind(&ReportToUMA, VAAPI_ERROR)); 218 base::Bind(&ReportToUMA, VAAPI_ERROR));
222 if (!vaapi_wrapper_) { 219 if (!vaapi_wrapper_.get()) {
223 LOG(ERROR) << "Failed initializing VAAPI"; 220 LOG(ERROR) << "Failed initializing VAAPI";
224 return false; 221 return false;
225 } 222 }
226 223
227 if (!encoder_thread_.Start()) { 224 if (!encoder_thread_.Start()) {
228 LOG(ERROR) << "Failed to start encoder thread"; 225 LOG(ERROR) << "Failed to start encoder thread";
229 return false; 226 return false;
230 } 227 }
231 encoder_thread_proxy_ = encoder_thread_.message_loop_proxy(); 228 encoder_thread_proxy_ = encoder_thread_.message_loop_proxy();
232 229
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 594
598 DCHECK(!current_encode_job_); 595 DCHECK(!current_encode_job_);
599 current_encode_job_.reset(new EncodeJob()); 596 current_encode_job_.reset(new EncodeJob());
600 597
601 if (!vaapi_wrapper_->CreateCodedBuffer(output_buffer_byte_size_, 598 if (!vaapi_wrapper_->CreateCodedBuffer(output_buffer_byte_size_,
602 &current_encode_job_->coded_buffer)) { 599 &current_encode_job_->coded_buffer)) {
603 NOTIFY_ERROR(kPlatformFailureError, "Failed creating coded buffer"); 600 NOTIFY_ERROR(kPlatformFailureError, "Failed creating coded buffer");
604 return false; 601 return false;
605 } 602 }
606 603
607 current_encode_job_->input_surface = 604 current_encode_job_->input_surface = new VASurface(
608 new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_); 605 available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_);
609 available_va_surface_ids_.pop_back(); 606 available_va_surface_ids_.pop_back();
610 607
611 current_encode_job_->recon_surface = 608 current_encode_job_->recon_surface = new VASurface(
612 new VASurface(available_va_surface_ids_.back(), va_surface_release_cb_); 609 available_va_surface_ids_.back(), coded_size_, va_surface_release_cb_);
613 available_va_surface_ids_.pop_back(); 610 available_va_surface_ids_.pop_back();
614 611
615 // Reference surfaces are needed until the job is done, but they get 612 // Reference surfaces are needed until the job is done, but they get
616 // removed from ref_pic_list0_ when it's full at the end of job submission. 613 // removed from ref_pic_list0_ when it's full at the end of job submission.
617 // Keep refs to them along with the job and only release after sync. 614 // Keep refs to them along with the job and only release after sync.
618 current_encode_job_->reference_surfaces = ref_pic_list0_; 615 current_encode_job_->reference_surfaces = ref_pic_list0_;
619 616
620 return true; 617 return true;
621 } 618 }
622 619
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1055 }
1059 1056
1060 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob() 1057 VaapiVideoEncodeAccelerator::EncodeJob::EncodeJob()
1061 : coded_buffer(VA_INVALID_ID), keyframe(false) { 1058 : coded_buffer(VA_INVALID_ID), keyframe(false) {
1062 } 1059 }
1063 1060
1064 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() { 1061 VaapiVideoEncodeAccelerator::EncodeJob::~EncodeJob() {
1065 } 1062 }
1066 1063
1067 } // namespace content 1064 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_encode_accelerator.h ('k') | content/common/gpu/media/vaapi_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698