| 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_decode_accelerator.h" | 5 #include "media/gpu/vaapi_jpeg_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "content/common/gpu/media/shared_memory_region.h" | |
| 19 #include "content/common/gpu/media/vaapi_picture.h" | |
| 20 #include "gpu/ipc/service/gpu_channel.h" | 18 #include "gpu/ipc/service/gpu_channel.h" |
| 21 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
| 22 #include "media/filters/jpeg_parser.h" | 20 #include "media/filters/jpeg_parser.h" |
| 21 #include "media/gpu/shared_memory_region.h" |
| 22 #include "media/gpu/vaapi_picture.h" |
| 23 #include "third_party/libyuv/include/libyuv.h" | 23 #include "third_party/libyuv/include/libyuv.h" |
| 24 | 24 |
| 25 namespace content { | 25 namespace media { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 // UMA errors that the VaapiJpegDecodeAccelerator class reports. | 28 // UMA errors that the VaapiJpegDecodeAccelerator class reports. |
| 29 enum VAJDADecoderFailure { | 29 enum VAJDADecoderFailure { |
| 30 VAAPI_ERROR = 0, | 30 VAAPI_ERROR = 0, |
| 31 // UMA requires that max must be greater than 1. | 31 VAJDA_DECODER_FAILURES_MAX, |
| 32 VAJDA_DECODER_FAILURES_MAX = 2, | |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 static void ReportToUMA(VAJDADecoderFailure failure) { | 34 static void ReportToUMA(VAJDADecoderFailure failure) { |
| 36 UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure, | 35 UMA_HISTOGRAM_ENUMERATION("Media.VAJDA.DecoderFailure", failure, |
| 37 VAJDA_DECODER_FAILURES_MAX); | 36 VAJDA_DECODER_FAILURES_MAX + 1); |
| 38 } | 37 } |
| 39 | 38 |
| 40 static unsigned int VaSurfaceFormatForJpeg( | 39 static unsigned int VaSurfaceFormatForJpeg( |
| 41 const media::JpegFrameHeader& frame_header) { | 40 const media::JpegFrameHeader& frame_header) { |
| 42 // The range of sampling factor is [1, 4]. Pack them into integer to make the | 41 // The range of sampling factor is [1, 4]. Pack them into integer to make the |
| 43 // matching code simpler. For example, 0x211 means the sampling factor are 2, | 42 // matching code simpler. For example, 0x211 means the sampling factor are 2, |
| 44 // 1, 1 for 3 components. | 43 // 1, 1 for 3 components. |
| 45 unsigned int h = 0, v = 0; | 44 unsigned int h = 0, v = 0; |
| 46 for (int i = 0; i < frame_header.num_components; i++) { | 45 for (int i = 0; i < frame_header.num_components; i++) { |
| 47 DCHECK_LE(frame_header.components[i].horizontal_sampling_factor, 4); | 46 DCHECK_LE(frame_header.components[i].horizontal_sampling_factor, 4); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } // namespace | 78 } // namespace |
| 80 | 79 |
| 81 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest( | 80 VaapiJpegDecodeAccelerator::DecodeRequest::DecodeRequest( |
| 82 int32_t bitstream_buffer_id, | 81 int32_t bitstream_buffer_id, |
| 83 std::unique_ptr<SharedMemoryRegion> shm, | 82 std::unique_ptr<SharedMemoryRegion> shm, |
| 84 const scoped_refptr<media::VideoFrame>& video_frame) | 83 const scoped_refptr<media::VideoFrame>& video_frame) |
| 85 : bitstream_buffer_id(bitstream_buffer_id), | 84 : bitstream_buffer_id(bitstream_buffer_id), |
| 86 shm(std::move(shm)), | 85 shm(std::move(shm)), |
| 87 video_frame(video_frame) {} | 86 video_frame(video_frame) {} |
| 88 | 87 |
| 89 VaapiJpegDecodeAccelerator::DecodeRequest::~DecodeRequest() { | 88 VaapiJpegDecodeAccelerator::DecodeRequest::~DecodeRequest() {} |
| 90 } | |
| 91 | 89 |
| 92 void VaapiJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id, | 90 void VaapiJpegDecodeAccelerator::NotifyError(int32_t bitstream_buffer_id, |
| 93 Error error) { | 91 Error error) { |
| 94 DCHECK(task_runner_->BelongsToCurrentThread()); | 92 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 95 DLOG(ERROR) << "Notifying of error " << error; | 93 DLOG(ERROR) << "Notifying of error " << error; |
| 96 DCHECK(client_); | 94 DCHECK(client_); |
| 97 client_->NotifyError(bitstream_buffer_id, error); | 95 client_->NotifyError(bitstream_buffer_id, error); |
| 98 } | 96 } |
| 99 | 97 |
| 100 void VaapiJpegDecodeAccelerator::NotifyErrorFromDecoderThread( | 98 void VaapiJpegDecodeAccelerator::NotifyErrorFromDecoderThread( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 312 |
| 315 decoder_task_runner_->PostTask( | 313 decoder_task_runner_->PostTask( |
| 316 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask, | 314 FROM_HERE, base::Bind(&VaapiJpegDecodeAccelerator::DecodeTask, |
| 317 base::Unretained(this), base::Passed(&request))); | 315 base::Unretained(this), base::Passed(&request))); |
| 318 } | 316 } |
| 319 | 317 |
| 320 bool VaapiJpegDecodeAccelerator::IsSupported() { | 318 bool VaapiJpegDecodeAccelerator::IsSupported() { |
| 321 return VaapiWrapper::IsJpegDecodeSupported(); | 319 return VaapiWrapper::IsJpegDecodeSupported(); |
| 322 } | 320 } |
| 323 | 321 |
| 324 } // namespace content | 322 } // namespace media |
| OLD | NEW |