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

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..63ed9933358921bf84cca8e962bf7cee8cb7cc07 100644
--- a/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
+++ b/content/common/gpu/media/vaapi_jpeg_decode_accelerator.cc
@@ -28,6 +28,46 @@ static void ReportToUMA(VAJDADecoderFailure failure) {
UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure,
VAJDA_DECODER_FAILURES_MAX);
}
+
+static unsigned int VaSurfaceFormatForJpeg(
+ const media::JpegFrameHeader& frame_header) {
+ // 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 < frame_header.num_components; i++) {
+ DCHECK_LE(frame_header.components[i].horizontal_sampling_factor, 4);
+ DCHECK_LE(frame_header.components[i].vertical_sampling_factor, 4);
+ h = h << 4 | frame_header.components[i].horizontal_sampling_factor;
+ v = v << 4 | frame_header.components[i].vertical_sampling_factor;
+ }
+
+ switch (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;
+ }
+ DVLOG(1) << "Unsupported sampling factor: num_components="
+ << frame_header.num_components << ", h=" << std::hex << h
+ << ", v=" << v;
+
+ return 0;
+}
+
} // namespace
VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest(
@@ -184,25 +224,35 @@ void VaapiJpegDecodeAccelerator::DecodeTask(
reinterpret_cast<const uint8_t*>(request->shm->memory()),
request->bitstream_buffer.size(), &parse_result)) {
DLOG(ERROR) << "ParseJpegPicture failed";
- NotifyErrorFromDecoderThread(
- request->bitstream_buffer.id(),
- media::JpegDecodeAccelerator::PARSE_JPEG_FAILED);
+ NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
+ PARSE_JPEG_FAILED);
+ return;
+ }
+
+ unsigned int new_va_rt_format =
+ VaSurfaceFormatForJpeg(parse_result.frame_header);
+ if (!new_va_rt_format) {
+ DLOG(ERROR) << "Unsupported subsampling";
+ NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
+ UNSUPPORTED_JPEG);
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(),
- media::JpegDecodeAccelerator::PLATFORM_FAILURE);
+ NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
+ PLATFORM_FAILURE);
return;
}
va_surface_id_ = va_surfaces[0];
@@ -212,18 +262,16 @@ void VaapiJpegDecodeAccelerator::DecodeTask(
if (!VaapiJpegDecoder::Decode(vaapi_wrapper_.get(), parse_result,
va_surface_id_)) {
LOG(ERROR) << "Decode JPEG failed";
- NotifyErrorFromDecoderThread(
- request->bitstream_buffer.id(),
- media::JpegDecodeAccelerator::PLATFORM_FAILURE);
+ NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
+ PLATFORM_FAILURE);
return;
}
if (!OutputPicture(va_surface_id_, request->bitstream_buffer.id(),
request->video_frame)) {
LOG(ERROR) << "Output picture failed";
- NotifyErrorFromDecoderThread(
- request->bitstream_buffer.id(),
- media::JpegDecodeAccelerator::PLATFORM_FAILURE);
+ NotifyErrorFromDecoderThread(request->bitstream_buffer.id(),
+ PLATFORM_FAILURE);
return;
}
}
« 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