OLD | NEW |
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_decoder.h" | 5 #include "content/common/gpu/media/vaapi_jpeg_decoder.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/filters/jpeg_parser.h" | 8 #include "media/filters/jpeg_parser.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 jpeg.frame_header.visible_height < 1) { | 94 jpeg.frame_header.visible_height < 1) { |
95 DLOG(ERROR) << "width(" << jpeg.frame_header.visible_width | 95 DLOG(ERROR) << "width(" << jpeg.frame_header.visible_width |
96 << ") and height(" << jpeg.frame_header.visible_height | 96 << ") and height(" << jpeg.frame_header.visible_height |
97 << ") should be at least 1"; | 97 << ") should be at least 1"; |
98 return false; | 98 return false; |
99 } | 99 } |
100 | 100 |
101 // Size 64k*64k is the maximum in the JPEG standard. VAAPI doesn't support | 101 // Size 64k*64k is the maximum in the JPEG standard. VAAPI doesn't support |
102 // resolutions larger than 16k*16k. | 102 // resolutions larger than 16k*16k. |
103 const int kMaxDimension = 16384; | 103 const int kMaxDimension = 16384; |
104 if (jpeg.frame_header.visible_width > kMaxDimension || | 104 if (jpeg.frame_header.coded_width > kMaxDimension || |
105 jpeg.frame_header.visible_height > kMaxDimension) { | 105 jpeg.frame_header.coded_height > kMaxDimension) { |
106 DLOG(ERROR) << "VAAPI doesn't support size(" | 106 DLOG(ERROR) << "VAAPI doesn't support size(" |
107 << jpeg.frame_header.visible_width << "*" | 107 << jpeg.frame_header.coded_width << "*" |
108 << jpeg.frame_header.visible_height << ") larger than " | 108 << jpeg.frame_header.coded_height << ") larger than " |
109 << kMaxDimension << "*" << kMaxDimension; | 109 << kMaxDimension << "*" << kMaxDimension; |
110 return false; | 110 return false; |
111 } | 111 } |
112 | 112 |
113 if (jpeg.frame_header.num_components != 3) { | 113 if (jpeg.frame_header.num_components != 3) { |
114 DLOG(ERROR) << "VAAPI doesn't support num_components(" | 114 DLOG(ERROR) << "VAAPI doesn't support num_components(" |
115 << static_cast<int>(jpeg.frame_header.num_components) | 115 << static_cast<int>(jpeg.frame_header.num_components) |
116 << ") != 3"; | 116 << ") != 3"; |
117 return false; | 117 return false; |
118 } | 118 } |
(...skipping 16 matching lines...) Expand all Loading... |
135 return false; | 135 return false; |
136 } | 136 } |
137 | 137 |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 static void FillPictureParameters( | 141 static void FillPictureParameters( |
142 const media::JpegFrameHeader& frame_header, | 142 const media::JpegFrameHeader& frame_header, |
143 VAPictureParameterBufferJPEGBaseline* pic_param) { | 143 VAPictureParameterBufferJPEGBaseline* pic_param) { |
144 memset(pic_param, 0, sizeof(*pic_param)); | 144 memset(pic_param, 0, sizeof(*pic_param)); |
145 pic_param->picture_width = frame_header.visible_width; | 145 pic_param->picture_width = frame_header.coded_width; |
146 pic_param->picture_height = frame_header.visible_height; | 146 pic_param->picture_height = frame_header.coded_height; |
147 pic_param->num_components = frame_header.num_components; | 147 pic_param->num_components = frame_header.num_components; |
148 | 148 |
149 for (int i = 0; i < pic_param->num_components; i++) { | 149 for (int i = 0; i < pic_param->num_components; i++) { |
150 pic_param->components[i].component_id = frame_header.components[i].id; | 150 pic_param->components[i].component_id = frame_header.components[i].id; |
151 pic_param->components[i].h_sampling_factor = | 151 pic_param->components[i].h_sampling_factor = |
152 frame_header.components[i].horizontal_sampling_factor; | 152 frame_header.components[i].horizontal_sampling_factor; |
153 pic_param->components[i].v_sampling_factor = | 153 pic_param->components[i].v_sampling_factor = |
154 frame_header.components[i].vertical_sampling_factor; | 154 frame_header.components[i].vertical_sampling_factor; |
155 pic_param->components[i].quantiser_table_selector = | 155 pic_param->components[i].quantiser_table_selector = |
156 frame_header.components[i].quantization_table_selector; | 156 frame_header.components[i].quantization_table_selector; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 slice_param->components[i].ac_table_selector = | 237 slice_param->components[i].ac_table_selector = |
238 parse_result.scan.components[i].ac_selector; | 238 parse_result.scan.components[i].ac_selector; |
239 } | 239 } |
240 slice_param->restart_interval = parse_result.restart_interval; | 240 slice_param->restart_interval = parse_result.restart_interval; |
241 | 241 |
242 // Cast to int to prevent overflow. | 242 // Cast to int to prevent overflow. |
243 int max_h_factor = | 243 int max_h_factor = |
244 parse_result.frame_header.components[0].horizontal_sampling_factor; | 244 parse_result.frame_header.components[0].horizontal_sampling_factor; |
245 int max_v_factor = | 245 int max_v_factor = |
246 parse_result.frame_header.components[0].vertical_sampling_factor; | 246 parse_result.frame_header.components[0].vertical_sampling_factor; |
247 int visible_width = parse_result.frame_header.visible_width; | 247 int mcu_cols = parse_result.frame_header.coded_width / (max_h_factor * 8); |
248 int visible_height = parse_result.frame_header.visible_height; | |
249 int mcu_cols = (visible_width + max_h_factor * 8 - 1) / (max_h_factor * 8); | |
250 DCHECK_GT(mcu_cols, 0); | 248 DCHECK_GT(mcu_cols, 0); |
251 int mcu_rows = (visible_height + max_v_factor * 8 - 1) / (max_v_factor * 8); | 249 int mcu_rows = parse_result.frame_header.coded_height / (max_v_factor * 8); |
252 DCHECK_GT(mcu_rows, 0); | 250 DCHECK_GT(mcu_rows, 0); |
253 slice_param->num_mcus = mcu_rows * mcu_cols; | 251 slice_param->num_mcus = mcu_rows * mcu_cols; |
254 } | 252 } |
255 | 253 |
256 // static | 254 // static |
257 bool VaapiJpegDecoder::Decode(VaapiWrapper* vaapi_wrapper, | 255 bool VaapiJpegDecoder::Decode(VaapiWrapper* vaapi_wrapper, |
258 const media::JpegParseResult& parse_result, | 256 const media::JpegParseResult& parse_result, |
259 VASurfaceID va_surface) { | 257 VASurfaceID va_surface) { |
260 DCHECK_NE(va_surface, VA_INVALID_SURFACE); | 258 DCHECK_NE(va_surface, VA_INVALID_SURFACE); |
261 if (!IsVaapiSupportedJpeg(parse_result)) | 259 if (!IsVaapiSupportedJpeg(parse_result)) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 const_cast<char*>(parse_result.data))) | 294 const_cast<char*>(parse_result.data))) |
297 return false; | 295 return false; |
298 | 296 |
299 if (!vaapi_wrapper->ExecuteAndDestroyPendingBuffers(va_surface)) | 297 if (!vaapi_wrapper->ExecuteAndDestroyPendingBuffers(va_surface)) |
300 return false; | 298 return false; |
301 | 299 |
302 return true; | 300 return true; |
303 } | 301 } |
304 | 302 |
305 } // namespace content | 303 } // namespace content |
OLD | NEW |