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

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

Issue 1209033018: Create VA surface with correct VA RT format for MJPEG decode acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 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/common/gpu/media/vaapi_jpeg_decode_accelerator.h" 5 #include "content/common/gpu/media/vaapi_jpeg_decode_accelerator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 10 matching lines...) Expand all
21 // UMA errors that the VaapiJpegDecodeAccelerator class reports. 21 // UMA errors that the VaapiJpegDecodeAccelerator class reports.
22 enum VAJDADecoderFailure { 22 enum VAJDADecoderFailure {
23 VAAPI_ERROR = 0, 23 VAAPI_ERROR = 0,
24 VAJDA_DECODER_FAILURES_MAX, 24 VAJDA_DECODER_FAILURES_MAX,
25 }; 25 };
26 26
27 static void ReportToUMA(VAJDADecoderFailure failure) { 27 static void ReportToUMA(VAJDADecoderFailure failure) {
28 UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure, 28 UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure,
29 VAJDA_DECODER_FAILURES_MAX); 29 VAJDA_DECODER_FAILURES_MAX);
30 } 30 }
31
32 static unsigned int VaSurfaceFormatForJpeg(
33 const media::JpegFrameHeader& frame_header) {
34 // The range of sampling factor is [1, 4]. Pack them into integer to make the
35 // matching code simpler. For example, 0x211 means the sampling factor are 2,
36 // 1, 1 for 3 components.
37 unsigned int h = 0, v = 0;
38 for (int i = 0; i < frame_header.num_components; i++) {
39 DCHECK_LE(frame_header.components[i].horizontal_sampling_factor, 4);
40 DCHECK_LE(frame_header.components[i].vertical_sampling_factor, 4);
41 h = h << 4 | frame_header.components[i].horizontal_sampling_factor;
42 v = v << 4 | frame_header.components[i].vertical_sampling_factor;
43 }
44
45 switch (frame_header.num_components) {
46 case 1: // Grey image
47 return VA_RT_FORMAT_YUV400;
48
49 case 3: // Y Cb Cr color image
50 // See https://en.wikipedia.org/wiki/Chroma_subsampling for the
51 // definition of these numbers.
52 if (h == 0x211 && v == 0x211)
53 return VA_RT_FORMAT_YUV420;
54
55 if (h == 0x211 && v == 0x111)
56 return VA_RT_FORMAT_YUV422;
57
58 if (h == 0x111 && v == 0x111)
59 return VA_RT_FORMAT_YUV444;
60
61 if (h == 0x411 && v == 0x111)
62 return VA_RT_FORMAT_YUV411;
63 }
64 DVLOG(1) << "Unsupported sampling factor: num_components="
65 << frame_header.num_components << ", h=" << std::hex << h
66 << ", v=" << v;
67
68 return 0;
69 }
70
31 } // namespace 71 } // namespace
32 72
33 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest( 73 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest(
34 const media::BitstreamBuffer& bitstream_buffer, 74 const media::BitstreamBuffer& bitstream_buffer,
35 scoped_ptr<base::SharedMemory> shm, 75 scoped_ptr<base::SharedMemory> shm,
36 const scoped_refptr<media::VideoFrame>& video_frame) 76 const scoped_refptr<media::VideoFrame>& video_frame)
37 : bitstream_buffer(bitstream_buffer), 77 : bitstream_buffer(bitstream_buffer),
38 shm(shm.Pass()), 78 shm(shm.Pass()),
39 video_frame(video_frame) { 79 video_frame(video_frame) {
40 } 80 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 const scoped_ptr<DecodeRequest>& request) { 217 const scoped_ptr<DecodeRequest>& request) {
178 DVLOG(3) << __func__; 218 DVLOG(3) << __func__;
179 DCHECK(decoder_task_runner_->BelongsToCurrentThread()); 219 DCHECK(decoder_task_runner_->BelongsToCurrentThread());
180 TRACE_EVENT0("jpeg", "DecodeTask"); 220 TRACE_EVENT0("jpeg", "DecodeTask");
181 221
182 media::JpegParseResult parse_result; 222 media::JpegParseResult parse_result;
183 if (!media::ParseJpegPicture( 223 if (!media::ParseJpegPicture(
184 reinterpret_cast<const uint8_t*>(request->shm->memory()), 224 reinterpret_cast<const uint8_t*>(request->shm->memory()),
185 request->bitstream_buffer.size(), &parse_result)) { 225 request->bitstream_buffer.size(), &parse_result)) {
186 DLOG(ERROR) << "ParseJpegPicture failed"; 226 DLOG(ERROR) << "ParseJpegPicture failed";
187 NotifyErrorFromDecoderThread( 227 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
188 request->bitstream_buffer.id(), 228 PARSE_JPEG_FAILED);
189 media::JpegDecodeAccelerator::PARSE_JPEG_FAILED); 229 return;
230 }
231
232 unsigned int new_va_rt_format =
233 VaSurfaceFormatForJpeg(parse_result.frame_header);
234 if (!new_va_rt_format) {
235 DLOG(ERROR) << "Unsupported subsampling";
236 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
237 UNSUPPORTED_JPEG);
190 return; 238 return;
191 } 239 }
192 240
193 // Reuse VASurface if size doesn't change. 241 // Reuse VASurface if size doesn't change.
194 gfx::Size new_coded_size(parse_result.frame_header.coded_width, 242 gfx::Size new_coded_size(parse_result.frame_header.coded_width,
195 parse_result.frame_header.coded_height); 243 parse_result.frame_header.coded_height);
196 if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE) { 244 if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE ||
245 new_va_rt_format != va_rt_format_) {
197 vaapi_wrapper_->DestroySurfaces(); 246 vaapi_wrapper_->DestroySurfaces();
198 va_surface_id_ = VA_INVALID_SURFACE; 247 va_surface_id_ = VA_INVALID_SURFACE;
248 va_rt_format_ = new_va_rt_format;
199 249
200 std::vector<VASurfaceID> va_surfaces; 250 std::vector<VASurfaceID> va_surfaces;
201 if (!vaapi_wrapper_->CreateSurfaces(new_coded_size, 1, &va_surfaces)) { 251 if (!vaapi_wrapper_->CreateSurfaces(va_rt_format_, new_coded_size, 1,
252 &va_surfaces)) {
202 LOG(ERROR) << "Create VA surface failed"; 253 LOG(ERROR) << "Create VA surface failed";
203 NotifyErrorFromDecoderThread( 254 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
204 request->bitstream_buffer.id(), 255 PLATFORM_FAILURE);
205 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
206 return; 256 return;
207 } 257 }
208 va_surface_id_ = va_surfaces[0]; 258 va_surface_id_ = va_surfaces[0];
209 coded_size_ = new_coded_size; 259 coded_size_ = new_coded_size;
210 } 260 }
211 261
212 if (!VaapiJpegDecoder::Decode(vaapi_wrapper_.get(), parse_result, 262 if (!VaapiJpegDecoder::Decode(vaapi_wrapper_.get(), parse_result,
213 va_surface_id_)) { 263 va_surface_id_)) {
214 LOG(ERROR) << "Decode JPEG failed"; 264 LOG(ERROR) << "Decode JPEG failed";
215 NotifyErrorFromDecoderThread( 265 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
216 request->bitstream_buffer.id(), 266 PLATFORM_FAILURE);
217 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
218 return; 267 return;
219 } 268 }
220 269
221 if (!OutputPicture(va_surface_id_, request->bitstream_buffer.id(), 270 if (!OutputPicture(va_surface_id_, request->bitstream_buffer.id(),
222 request->video_frame)) { 271 request->video_frame)) {
223 LOG(ERROR) << "Output picture failed"; 272 LOG(ERROR) << "Output picture failed";
224 NotifyErrorFromDecoderThread( 273 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
225 request->bitstream_buffer.id(), 274 PLATFORM_FAILURE);
226 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
227 return; 275 return;
228 } 276 }
229 } 277 }
230 278
231 void VaapiJpegDecodeAccelerator::Decode( 279 void VaapiJpegDecodeAccelerator::Decode(
232 const media::BitstreamBuffer& bitstream_buffer, 280 const media::BitstreamBuffer& bitstream_buffer,
233 const scoped_refptr<media::VideoFrame>& video_frame) { 281 const scoped_refptr<media::VideoFrame>& video_frame) {
234 DVLOG(3) << __func__; 282 DVLOG(3) << __func__;
235 DCHECK(io_task_runner_->BelongsToCurrentThread()); 283 DCHECK(io_task_runner_->BelongsToCurrentThread());
236 TRACE_EVENT1("jpeg", "Decode", "input_id", bitstream_buffer.id()); 284 TRACE_EVENT1("jpeg", "Decode", "input_id", bitstream_buffer.id());
(...skipping 11 matching lines...) Expand all
248 296
249 scoped_ptr<DecodeRequest> request( 297 scoped_ptr<DecodeRequest> request(
250 new DecodeRequest(bitstream_buffer, shm.Pass(), video_frame)); 298 new DecodeRequest(bitstream_buffer, shm.Pass(), video_frame));
251 299
252 decoder_task_runner_->PostTask( 300 decoder_task_runner_->PostTask(
253 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask, 301 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask,
254 base::Unretained(this), base::Passed(&request))); 302 base::Unretained(this), base::Passed(&request)));
255 } 303 }
256 304
257 } // namespace content 305 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_jpeg_decode_accelerator.h ('k') | content/common/gpu/media/vaapi_jpeg_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698