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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
diff --git a/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
index 6d51d27f52636b67b6fec665357fca2dae890bbd..b0dba9a0f2cc956d9210c27d7a8504527c3e43d4 100644
--- a/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
@@ -28,6 +28,47 @@ static void ReportToUMA(VAJDADecoderFailure failure) {
UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure,
VAJDA_DECODER_FAILURES_MAX);
}
+
+unsigned int VaSurfaceFormatForJpeg(
wuchengli 2015/07/13 07:26:22 static
kcwu 2015/07/13 07:39:40 Done.
+ const media::JpegParseResult& parse_result) {
henryhsu 2015/07/09 06:56:26 Can we pass JpegFrameHeader directly since we don'
kcwu 2015/07/13 05:45:16 Done.
+ // The range of sampling factor is [1, 4]. Pack them into integer to make the
+ // matching code simpler. For example, 0x211 means the sampling factor are 2,
+ // 1, 1 for 3 components.
+ unsigned int h = 0, v = 0;
+ for (int i = 0; i < parse_result.frame_header.num_components; i++) {
+ DCHECK_LE(
+ parse_result.frame_header.components[i].horizontal_sampling_factor, 4);
wuchengli 2015/07/13 07:26:22 Is this a bug or invalid jpeg? If it's an invalid
kcwu 2015/07/13 07:39:40 Invalid jpeg should already be handled by jpeg par
+ DCHECK_LE(parse_result.frame_header.components[i].vertical_sampling_factor,
+ 4);
+ h = h << 4 |
+ parse_result.frame_header.components[i].horizontal_sampling_factor;
+ v = v << 4 |
+ parse_result.frame_header.components[i].vertical_sampling_factor;
+ }
+
+ switch (parse_result.frame_header.num_components) {
+ case 1: // Grey image
+ return VA_RT_FORMAT_YUV400;
+
+ case 3: // Y Cb Cr color image
+ // See https://en.wikipedia.org/wiki/Chroma_subsampling for the
+ // definition of these numbers.
+ if (h == 0x211 && v == 0x211)
+ return VA_RT_FORMAT_YUV420;
+
+ if (h == 0x211 && v == 0x111)
+ return VA_RT_FORMAT_YUV422;
+
+ if (h == 0x111 && v == 0x111)
+ return VA_RT_FORMAT_YUV444;
+
+ if (h == 0x411 && v == 0x111)
+ return VA_RT_FORMAT_YUV411;
+ }
wuchengli 2015/07/13 07:26:22 DVLOG the values of h and v here.
kcwu 2015/07/13 07:39:40 Done.
+
+ return 0;
+}
+
} // namespace
VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest(
@@ -190,15 +231,27 @@ void VaapiJpegDecodeAccelerator::DecodeTask(
return;
}
+ unsigned int new_va_rt_format = VaSurfaceFormatForJpeg(parse_result);
+ if (!new_va_rt_format) {
+ DLOG(ERROR) << "Unsupported subsampling";
+ NotifyErrorFromDecoderThread(
+ request->bitstream_buffer.id(),
+ media::JpegDecodeAccelerator::UNSUPPORTED_JPEG);
henryhsu 2015/07/09 06:56:26 You don't need "media::JpegDecodeAccelerator::" si
kcwu 2015/07/13 05:45:16 Done.
+ return;
+ }
+
// Reuse VASurface if size doesn't change.
gfx::Size new_coded_size(parse_result.frame_header.coded_width,
parse_result.frame_header.coded_height);
- if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE) {
+ if (new_coded_size != coded_size_ || va_surface_id_ == VA_INVALID_SURFACE ||
+ new_va_rt_format != va_rt_format_) {
vaapi_wrapper_->DestroySurfaces();
va_surface_id_ = VA_INVALID_SURFACE;
+ va_rt_format_ = new_va_rt_format;
std::vector<VASurfaceID> va_surfaces;
- if (!vaapi_wrapper_->CreateSurfaces(new_coded_size, 1, &va_surfaces)) {
+ if (!vaapi_wrapper_->CreateSurfaces(va_rt_format_, new_coded_size, 1,
+ &va_surfaces)) {
LOG(ERROR) << "Create VA surface failed";
NotifyErrorFromDecoderThread(
request->bitstream_buffer.id(),

Powered by Google App Engine
This is Rietveld 408576698