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

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

Issue 1239443003: Revert of 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
71 } // namespace 31 } // namespace
72 32
73 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest( 33 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest(
74 const media::BitstreamBuffer& bitstream_buffer, 34 const media::BitstreamBuffer& bitstream_buffer,
75 scoped_ptr<base::SharedMemory> shm, 35 scoped_ptr<base::SharedMemory> shm,
76 const scoped_refptr<media::VideoFrame>& video_frame) 36 const scoped_refptr<media::VideoFrame>& video_frame)
77 : bitstream_buffer(bitstream_buffer), 37 : bitstream_buffer(bitstream_buffer),
78 shm(shm.Pass()), 38 shm(shm.Pass()),
79 video_frame(video_frame) { 39 video_frame(video_frame) {
80 } 40 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 const scoped_ptr<DecodeRequest>& request) { 177 const scoped_ptr<DecodeRequest>& request) {
218 DVLOG(3) << __func__; 178 DVLOG(3) << __func__;
219 DCHECK(decoder_task_runner_->BelongsToCurrentThread()); 179 DCHECK(decoder_task_runner_->BelongsToCurrentThread());
220 TRACE_EVENT0("jpeg", "DecodeTask"); 180 TRACE_EVENT0("jpeg", "DecodeTask");
221 181
222 media::JpegParseResult parse_result; 182 media::JpegParseResult parse_result;
223 if (!media::ParseJpegPicture( 183 if (!media::ParseJpegPicture(
224 reinterpret_cast<const uint8_t*>(request->shm->memory()), 184 reinterpret_cast<const uint8_t*>(request->shm->memory()),
225 request->bitstream_buffer.size(), &parse_result)) { 185 request->bitstream_buffer.size(), &parse_result)) {
226 DLOG(ERROR) << "ParseJpegPicture failed"; 186 DLOG(ERROR) << "ParseJpegPicture failed";
227 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(), 187 NotifyErrorFromDecoderThread(
228 PARSE_JPEG_FAILED); 188 request->bitstream_buffer.id(),
229 return; 189 media::JpegDecodeAccelerator::PARSE_JPEG_FAILED);
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);
238 return; 190 return;
239 } 191 }
240 192
241 // Reuse VASurface if size doesn't change. 193 // Reuse VASurface if size doesn't change.
242 gfx::Size new_coded_size(parse_result.frame_header.coded_width, 194 gfx::Size new_coded_size(parse_result.frame_header.coded_width,
243 parse_result.frame_header.coded_height); 195 parse_result.frame_header.coded_height);
244 if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE || 196 if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE) {
245 new_va_rt_format != va_rt_format_) {
246 vaapi_wrapper_->DestroySurfaces(); 197 vaapi_wrapper_->DestroySurfaces();
247 va_surface_id_ = VA_INVALID_SURFACE; 198 va_surface_id_ = VA_INVALID_SURFACE;
248 va_rt_format_ = new_va_rt_format;
249 199
250 std::vector<VASurfaceID> va_surfaces; 200 std::vector<VASurfaceID> va_surfaces;
251 if (!vaapi_wrapper_->CreateSurfaces(va_rt_format_, new_coded_size, 1, 201 if (!vaapi_wrapper_->CreateSurfaces(new_coded_size, 1, &va_surfaces)) {
252 &va_surfaces)) {
253 LOG(ERROR) << "Create VA surface failed"; 202 LOG(ERROR) << "Create VA surface failed";
254 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(), 203 NotifyErrorFromDecoderThread(
255 PLATFORM_FAILURE); 204 request->bitstream_buffer.id(),
205 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
256 return; 206 return;
257 } 207 }
258 va_surface_id_ = va_surfaces[0]; 208 va_surface_id_ = va_surfaces[0];
259 coded_size_ = new_coded_size; 209 coded_size_ = new_coded_size;
260 } 210 }
261 211
262 if (!VaapiJpegDecoder::Decode(vaapi_wrapper_.get(), parse_result, 212 if (!VaapiJpegDecoder::Decode(vaapi_wrapper_.get(), parse_result,
263 va_surface_id_)) { 213 va_surface_id_)) {
264 LOG(ERROR) << "Decode JPEG failed"; 214 LOG(ERROR) << "Decode JPEG failed";
265 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(), 215 NotifyErrorFromDecoderThread(
266 PLATFORM_FAILURE); 216 request->bitstream_buffer.id(),
217 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
267 return; 218 return;
268 } 219 }
269 220
270 if (!OutputPicture(va_surface_id_, request->bitstream_buffer.id(), 221 if (!OutputPicture(va_surface_id_, request->bitstream_buffer.id(),
271 request->video_frame)) { 222 request->video_frame)) {
272 LOG(ERROR) << "Output picture failed"; 223 LOG(ERROR) << "Output picture failed";
273 NotifyErrorFromDecoderThread(request->bitstream_buffer.id(), 224 NotifyErrorFromDecoderThread(
274 PLATFORM_FAILURE); 225 request->bitstream_buffer.id(),
226 media::JpegDecodeAccelerator::PLATFORM_FAILURE);
275 return; 227 return;
276 } 228 }
277 } 229 }
278 230
279 void VaapiJpegDecodeAccelerator::Decode( 231 void VaapiJpegDecodeAccelerator::Decode(
280 const media::BitstreamBuffer& bitstream_buffer, 232 const media::BitstreamBuffer& bitstream_buffer,
281 const scoped_refptr<media::VideoFrame>& video_frame) { 233 const scoped_refptr<media::VideoFrame>& video_frame) {
282 DVLOG(3) << __func__; 234 DVLOG(3) << __func__;
283 DCHECK(io_task_runner_->BelongsToCurrentThread()); 235 DCHECK(io_task_runner_->BelongsToCurrentThread());
284 TRACE_EVENT1("jpeg", "Decode", "input_id", bitstream_buffer.id()); 236 TRACE_EVENT1("jpeg", "Decode", "input_id", bitstream_buffer.id());
(...skipping 11 matching lines...) Expand all
296 248
297 scoped_ptr<DecodeRequest> request( 249 scoped_ptr<DecodeRequest> request(
298 new DecodeRequest(bitstream_buffer, shm.Pass(), video_frame)); 250 new DecodeRequest(bitstream_buffer, shm.Pass(), video_frame));
299 251
300 decoder_task_runner_->PostTask( 252 decoder_task_runner_->PostTask(
301 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask, 253 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask,
302 base::Unretained(this), base::Passed(&request))); 254 base::Unretained(this), base::Passed(&request)));
303 } 255 }
304 256
305 } // namespace content 257 } // 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