| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
| 9 #include <poll.h> | 9 #include <poll.h> |
| 10 #include <sys/eventfd.h> | 10 #include <sys/eventfd.h> |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 440 } |
| 441 | 441 |
| 442 delete this; | 442 delete this; |
| 443 } | 443 } |
| 444 | 444 |
| 445 bool V4L2VideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } | 445 bool V4L2VideoDecodeAccelerator::CanDecodeOnIOThread() { return true; } |
| 446 | 446 |
| 447 // static | 447 // static |
| 448 media::VideoDecodeAccelerator::SupportedProfiles | 448 media::VideoDecodeAccelerator::SupportedProfiles |
| 449 V4L2VideoDecodeAccelerator::GetSupportedProfiles() { | 449 V4L2VideoDecodeAccelerator::GetSupportedProfiles() { |
| 450 SupportedProfiles profiles; | |
| 451 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 450 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 452 if (!device) | 451 if (!device) |
| 453 return profiles; | 452 return SupportedProfiles(); |
| 454 | 453 |
| 455 SupportedProfile profile; | 454 const uint32_t supported_formats[] = { |
| 456 profile.min_resolution.SetSize(16, 16); | 455 V4L2_PIX_FMT_H264, V4L2_PIX_FMT_VP8, V4L2_PIX_FMT_VP9}; |
| 457 // NOTE: additional autodetection logic may require updating input buffer size | 456 return device->GetSupportedDecodeProfiles(arraysize(supported_formats), |
| 458 // selection. | 457 supported_formats); |
| 459 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 460 switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode)) | |
| 461 profile.max_resolution.SetSize(4096, 2160); | |
| 462 else | |
| 463 profile.max_resolution.SetSize(1920, 1088); | |
| 464 | |
| 465 v4l2_fmtdesc fmtdesc; | |
| 466 memset(&fmtdesc, 0, sizeof(fmtdesc)); | |
| 467 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
| 468 for (; device->Ioctl(VIDIOC_ENUM_FMT, &fmtdesc) == 0; ++fmtdesc.index) { | |
| 469 switch (fmtdesc.pixelformat) { | |
| 470 case V4L2_PIX_FMT_H264: | |
| 471 for (uint32 media_profile = media::H264PROFILE_MIN; | |
| 472 media_profile <= media::H264PROFILE_MAX; ++media_profile) { | |
| 473 profile.profile = | |
| 474 static_cast<media::VideoCodecProfile>(media_profile); | |
| 475 profiles.push_back(profile); | |
| 476 } | |
| 477 break; | |
| 478 case V4L2_PIX_FMT_VP8: | |
| 479 profile.profile = media::VP8PROFILE_ANY; | |
| 480 profiles.push_back(profile); | |
| 481 break; | |
| 482 case V4L2_PIX_FMT_VP9: | |
| 483 profile.profile = media::VP9PROFILE_ANY; | |
| 484 profiles.push_back(profile); | |
| 485 break; | |
| 486 } | |
| 487 } | |
| 488 | |
| 489 return profiles; | |
| 490 } | 458 } |
| 491 | 459 |
| 492 void V4L2VideoDecodeAccelerator::DecodeTask( | 460 void V4L2VideoDecodeAccelerator::DecodeTask( |
| 493 const media::BitstreamBuffer& bitstream_buffer) { | 461 const media::BitstreamBuffer& bitstream_buffer) { |
| 494 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); | 462 DVLOG(3) << "DecodeTask(): input_id=" << bitstream_buffer.id(); |
| 495 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); | 463 DCHECK_EQ(decoder_thread_.message_loop(), base::MessageLoop::current()); |
| 496 DCHECK_NE(decoder_state_, kUninitialized); | 464 DCHECK_NE(decoder_state_, kUninitialized); |
| 497 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id", | 465 TRACE_EVENT1("Video Decoder", "V4L2VDA::DecodeTask", "input_id", |
| 498 bitstream_buffer.id()); | 466 bitstream_buffer.id()); |
| 499 | 467 |
| (...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 DCHECK(!output_streamon_); | 1760 DCHECK(!output_streamon_); |
| 1793 | 1761 |
| 1794 __u32 input_format_fourcc = | 1762 __u32 input_format_fourcc = |
| 1795 V4L2Device::VideoCodecProfileToV4L2PixFmt(video_profile_, false); | 1763 V4L2Device::VideoCodecProfileToV4L2PixFmt(video_profile_, false); |
| 1796 if (!input_format_fourcc) { | 1764 if (!input_format_fourcc) { |
| 1797 NOTREACHED(); | 1765 NOTREACHED(); |
| 1798 return false; | 1766 return false; |
| 1799 } | 1767 } |
| 1800 | 1768 |
| 1801 size_t input_size; | 1769 size_t input_size; |
| 1802 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1770 gfx::Size max_resolution, min_resolution; |
| 1803 switches::kIgnoreResolutionLimitsForAcceleratedVideoDecode)) | 1771 device_->GetSupportedResolution(input_format_fourcc, &max_resolution, |
| 1772 &min_resolution); |
| 1773 if (max_resolution.width() > 1920 && max_resolution.height() > 1088) |
| 1804 input_size = kInputBufferMaxSizeFor4k; | 1774 input_size = kInputBufferMaxSizeFor4k; |
| 1805 else | 1775 else |
| 1806 input_size = kInputBufferMaxSizeFor1080p; | 1776 input_size = kInputBufferMaxSizeFor1080p; |
| 1807 | 1777 |
| 1808 struct v4l2_format format; | 1778 struct v4l2_format format; |
| 1809 memset(&format, 0, sizeof(format)); | 1779 memset(&format, 0, sizeof(format)); |
| 1810 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | 1780 format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1811 format.fmt.pix_mp.pixelformat = input_format_fourcc; | 1781 format.fmt.pix_mp.pixelformat = input_format_fourcc; |
| 1812 format.fmt.pix_mp.plane_fmt[0].sizeimage = input_size; | 1782 format.fmt.pix_mp.plane_fmt[0].sizeimage = input_size; |
| 1813 format.fmt.pix_mp.num_planes = 1; | 1783 format.fmt.pix_mp.num_planes = 1; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 gfx::Size new_coded_size(base::checked_cast<int>(format.fmt.pix_mp.width), | 2027 gfx::Size new_coded_size(base::checked_cast<int>(format.fmt.pix_mp.width), |
| 2058 base::checked_cast<int>(format.fmt.pix_mp.height)); | 2028 base::checked_cast<int>(format.fmt.pix_mp.height)); |
| 2059 if (coded_size_ != new_coded_size) { | 2029 if (coded_size_ != new_coded_size) { |
| 2060 DVLOG(3) << "IsResolutionChangeNecessary(): Resolution change detected"; | 2030 DVLOG(3) << "IsResolutionChangeNecessary(): Resolution change detected"; |
| 2061 return true; | 2031 return true; |
| 2062 } | 2032 } |
| 2063 return false; | 2033 return false; |
| 2064 } | 2034 } |
| 2065 | 2035 |
| 2066 } // namespace content | 2036 } // namespace content |
| OLD | NEW |