OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/gpu/vaapi_video_decode_accelerator.h" | 5 #include "media/gpu/vaapi_video_decode_accelerator.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 } while (0) | 60 } while (0) |
61 | 61 |
62 class VaapiVideoDecodeAccelerator::VaapiDecodeSurface | 62 class VaapiVideoDecodeAccelerator::VaapiDecodeSurface |
63 : public base::RefCountedThreadSafe<VaapiDecodeSurface> { | 63 : public base::RefCountedThreadSafe<VaapiDecodeSurface> { |
64 public: | 64 public: |
65 VaapiDecodeSurface(int32_t bitstream_id, | 65 VaapiDecodeSurface(int32_t bitstream_id, |
66 const scoped_refptr<VASurface>& va_surface); | 66 const scoped_refptr<VASurface>& va_surface); |
67 | 67 |
68 int32_t bitstream_id() const { return bitstream_id_; } | 68 int32_t bitstream_id() const { return bitstream_id_; } |
69 scoped_refptr<VASurface> va_surface() { return va_surface_; } | 69 scoped_refptr<VASurface> va_surface() { return va_surface_; } |
| 70 gfx::Rect visible_rect() const { return visible_rect_; } |
| 71 |
| 72 void set_visible_rect(const gfx::Rect& visible_rect) { |
| 73 visible_rect_ = visible_rect; |
| 74 } |
70 | 75 |
71 private: | 76 private: |
72 friend class base::RefCountedThreadSafe<VaapiDecodeSurface>; | 77 friend class base::RefCountedThreadSafe<VaapiDecodeSurface>; |
73 ~VaapiDecodeSurface(); | 78 ~VaapiDecodeSurface(); |
74 | 79 |
75 int32_t bitstream_id_; | 80 int32_t bitstream_id_; |
76 scoped_refptr<VASurface> va_surface_; | 81 scoped_refptr<VASurface> va_surface_; |
| 82 gfx::Rect visible_rect_; |
77 }; | 83 }; |
78 | 84 |
79 VaapiVideoDecodeAccelerator::VaapiDecodeSurface::VaapiDecodeSurface( | 85 VaapiVideoDecodeAccelerator::VaapiDecodeSurface::VaapiDecodeSurface( |
80 int32_t bitstream_id, | 86 int32_t bitstream_id, |
81 const scoped_refptr<VASurface>& va_surface) | 87 const scoped_refptr<VASurface>& va_surface) |
82 : bitstream_id_(bitstream_id), va_surface_(va_surface) {} | 88 : bitstream_id_(bitstream_id), va_surface_(va_surface) {} |
83 | 89 |
84 VaapiVideoDecodeAccelerator::VaapiDecodeSurface::~VaapiDecodeSurface() {} | 90 VaapiVideoDecodeAccelerator::VaapiDecodeSurface::~VaapiDecodeSurface() {} |
85 | 91 |
86 class VaapiH264Picture : public H264Picture { | 92 class VaapiH264Picture : public H264Picture { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 decoder_thread_task_runner_ = decoder_thread_.task_runner(); | 408 decoder_thread_task_runner_ = decoder_thread_.task_runner(); |
403 | 409 |
404 state_ = kIdle; | 410 state_ = kIdle; |
405 output_mode_ = config.output_mode; | 411 output_mode_ = config.output_mode; |
406 return true; | 412 return true; |
407 } | 413 } |
408 | 414 |
409 void VaapiVideoDecodeAccelerator::OutputPicture( | 415 void VaapiVideoDecodeAccelerator::OutputPicture( |
410 const scoped_refptr<VASurface>& va_surface, | 416 const scoped_refptr<VASurface>& va_surface, |
411 int32_t input_id, | 417 int32_t input_id, |
| 418 gfx::Rect visible_rect, |
412 VaapiPicture* picture) { | 419 VaapiPicture* picture) { |
413 DCHECK(task_runner_->BelongsToCurrentThread()); | 420 DCHECK(task_runner_->BelongsToCurrentThread()); |
414 | 421 |
415 int32_t output_id = picture->picture_buffer_id(); | 422 int32_t output_id = picture->picture_buffer_id(); |
416 | 423 |
417 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", "input_id", input_id, | 424 TRACE_EVENT2("Video Decoder", "VAVDA::OutputSurface", "input_id", input_id, |
418 "output_id", output_id); | 425 "output_id", output_id); |
419 | 426 |
420 DVLOG(3) << "Outputting VASurface " << va_surface->id() | 427 DVLOG(3) << "Outputting VASurface " << va_surface->id() |
421 << " into pixmap bound to picture buffer id " << output_id; | 428 << " into pixmap bound to picture buffer id " << output_id; |
422 | 429 |
423 RETURN_AND_NOTIFY_ON_FAILURE(picture->DownloadFromSurface(va_surface), | 430 RETURN_AND_NOTIFY_ON_FAILURE(picture->DownloadFromSurface(va_surface), |
424 "Failed putting surface into pixmap", | 431 "Failed putting surface into pixmap", |
425 PLATFORM_FAILURE, ); | 432 PLATFORM_FAILURE, ); |
426 | 433 |
427 // Notify the client a picture is ready to be displayed. | 434 // Notify the client a picture is ready to be displayed. |
428 ++num_frames_at_client_; | 435 ++num_frames_at_client_; |
429 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 436 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
430 DVLOG(4) << "Notifying output picture id " << output_id | 437 DVLOG(4) << "Notifying output picture id " << output_id << " for input " |
431 << " for input " << input_id << " is ready"; | 438 << input_id |
432 // TODO(posciak): Use visible size from decoder here instead | 439 << " is ready. visible rect: " << visible_rect.ToString(); |
433 // (crbug.com/402760). Passing (0, 0) results in the client using the | |
434 // visible size extracted from the container instead. | |
435 // TODO(hubbe): Use the correct color space. http://crbug.com/647725 | 440 // TODO(hubbe): Use the correct color space. http://crbug.com/647725 |
436 if (client_) | 441 if (client_) |
437 client_->PictureReady(Picture(output_id, input_id, gfx::Rect(0, 0), | 442 client_->PictureReady(Picture(output_id, input_id, visible_rect, |
438 gfx::ColorSpace(), picture->AllowOverlay())); | 443 gfx::ColorSpace(), picture->AllowOverlay())); |
439 } | 444 } |
440 | 445 |
441 void VaapiVideoDecodeAccelerator::TryOutputSurface() { | 446 void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
442 DCHECK(task_runner_->BelongsToCurrentThread()); | 447 DCHECK(task_runner_->BelongsToCurrentThread()); |
443 | 448 |
444 // Handle Destroy() arriving while pictures are queued for output. | 449 // Handle Destroy() arriving while pictures are queued for output. |
445 if (!client_) | 450 if (!client_) |
446 return; | 451 return; |
447 | 452 |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 | 1141 |
1137 { | 1142 { |
1138 base::AutoLock auto_lock(lock_); | 1143 base::AutoLock auto_lock(lock_); |
1139 // Drop any requests to output if we are resetting or being destroyed. | 1144 // Drop any requests to output if we are resetting or being destroyed. |
1140 if (state_ == kResetting || state_ == kDestroying) | 1145 if (state_ == kResetting || state_ == kDestroying) |
1141 return; | 1146 return; |
1142 } | 1147 } |
1143 | 1148 |
1144 pending_output_cbs_.push( | 1149 pending_output_cbs_.push( |
1145 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, weak_this_, | 1150 base::Bind(&VaapiVideoDecodeAccelerator::OutputPicture, weak_this_, |
1146 dec_surface->va_surface(), dec_surface->bitstream_id())); | 1151 dec_surface->va_surface(), dec_surface->bitstream_id(), |
| 1152 dec_surface->visible_rect())); |
1147 | 1153 |
1148 TryOutputSurface(); | 1154 TryOutputSurface(); |
1149 } | 1155 } |
1150 | 1156 |
1151 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> | 1157 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> |
1152 VaapiVideoDecodeAccelerator::CreateSurface() { | 1158 VaapiVideoDecodeAccelerator::CreateSurface() { |
1153 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); | 1159 DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); |
1154 base::AutoLock auto_lock(lock_); | 1160 base::AutoLock auto_lock(lock_); |
1155 | 1161 |
1156 if (available_va_surfaces_.empty()) | 1162 if (available_va_surfaces_.empty()) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1425 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1420 H264PictureToVaapiDecodeSurface(pic); | 1426 H264PictureToVaapiDecodeSurface(pic); |
1421 | 1427 |
1422 return vaapi_dec_->DecodeSurface(dec_surface); | 1428 return vaapi_dec_->DecodeSurface(dec_surface); |
1423 } | 1429 } |
1424 | 1430 |
1425 bool VaapiVideoDecodeAccelerator::VaapiH264Accelerator::OutputPicture( | 1431 bool VaapiVideoDecodeAccelerator::VaapiH264Accelerator::OutputPicture( |
1426 const scoped_refptr<H264Picture>& pic) { | 1432 const scoped_refptr<H264Picture>& pic) { |
1427 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1433 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1428 H264PictureToVaapiDecodeSurface(pic); | 1434 H264PictureToVaapiDecodeSurface(pic); |
1429 | 1435 dec_surface->set_visible_rect(pic->visible_rect); |
1430 vaapi_dec_->SurfaceReady(dec_surface); | 1436 vaapi_dec_->SurfaceReady(dec_surface); |
1431 | 1437 |
1432 return true; | 1438 return true; |
1433 } | 1439 } |
1434 | 1440 |
1435 void VaapiVideoDecodeAccelerator::VaapiH264Accelerator::Reset() { | 1441 void VaapiVideoDecodeAccelerator::VaapiH264Accelerator::Reset() { |
1436 vaapi_wrapper_->DestroyPendingBuffers(); | 1442 vaapi_wrapper_->DestroyPendingBuffers(); |
1437 } | 1443 } |
1438 | 1444 |
1439 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> | 1445 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1712 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1707 VP8PictureToVaapiDecodeSurface(pic); | 1713 VP8PictureToVaapiDecodeSurface(pic); |
1708 | 1714 |
1709 return vaapi_dec_->DecodeSurface(dec_surface); | 1715 return vaapi_dec_->DecodeSurface(dec_surface); |
1710 } | 1716 } |
1711 | 1717 |
1712 bool VaapiVideoDecodeAccelerator::VaapiVP8Accelerator::OutputPicture( | 1718 bool VaapiVideoDecodeAccelerator::VaapiVP8Accelerator::OutputPicture( |
1713 const scoped_refptr<VP8Picture>& pic) { | 1719 const scoped_refptr<VP8Picture>& pic) { |
1714 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1720 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1715 VP8PictureToVaapiDecodeSurface(pic); | 1721 VP8PictureToVaapiDecodeSurface(pic); |
1716 | 1722 dec_surface->set_visible_rect(pic->visible_rect); |
1717 vaapi_dec_->SurfaceReady(dec_surface); | 1723 vaapi_dec_->SurfaceReady(dec_surface); |
1718 return true; | 1724 return true; |
1719 } | 1725 } |
1720 | 1726 |
1721 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> | 1727 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> |
1722 VaapiVideoDecodeAccelerator::VaapiVP8Accelerator:: | 1728 VaapiVideoDecodeAccelerator::VaapiVP8Accelerator:: |
1723 VP8PictureToVaapiDecodeSurface(const scoped_refptr<VP8Picture>& pic) { | 1729 VP8PictureToVaapiDecodeSurface(const scoped_refptr<VP8Picture>& pic) { |
1724 VaapiVP8Picture* vaapi_pic = pic->AsVaapiVP8Picture(); | 1730 VaapiVP8Picture* vaapi_pic = pic->AsVaapiVP8Picture(); |
1725 CHECK(vaapi_pic); | 1731 CHECK(vaapi_pic); |
1726 return vaapi_pic->dec_surface(); | 1732 return vaapi_pic->dec_surface(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1876 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1871 VP9PictureToVaapiDecodeSurface(pic); | 1877 VP9PictureToVaapiDecodeSurface(pic); |
1872 | 1878 |
1873 return vaapi_dec_->DecodeSurface(dec_surface); | 1879 return vaapi_dec_->DecodeSurface(dec_surface); |
1874 } | 1880 } |
1875 | 1881 |
1876 bool VaapiVideoDecodeAccelerator::VaapiVP9Accelerator::OutputPicture( | 1882 bool VaapiVideoDecodeAccelerator::VaapiVP9Accelerator::OutputPicture( |
1877 const scoped_refptr<VP9Picture>& pic) { | 1883 const scoped_refptr<VP9Picture>& pic) { |
1878 scoped_refptr<VaapiDecodeSurface> dec_surface = | 1884 scoped_refptr<VaapiDecodeSurface> dec_surface = |
1879 VP9PictureToVaapiDecodeSurface(pic); | 1885 VP9PictureToVaapiDecodeSurface(pic); |
1880 | 1886 dec_surface->set_visible_rect(pic->visible_rect); |
1881 vaapi_dec_->SurfaceReady(dec_surface); | 1887 vaapi_dec_->SurfaceReady(dec_surface); |
1882 return true; | 1888 return true; |
1883 } | 1889 } |
1884 | 1890 |
1885 bool VaapiVideoDecodeAccelerator::VaapiVP9Accelerator::GetFrameContext( | 1891 bool VaapiVideoDecodeAccelerator::VaapiVP9Accelerator::GetFrameContext( |
1886 const scoped_refptr<VP9Picture>& pic, | 1892 const scoped_refptr<VP9Picture>& pic, |
1887 Vp9FrameContext* frame_ctx) { | 1893 Vp9FrameContext* frame_ctx) { |
1888 NOTIMPLEMENTED() << "Frame context update not supported"; | 1894 NOTIMPLEMENTED() << "Frame context update not supported"; |
1889 return false; | 1895 return false; |
1890 } | 1896 } |
1891 | 1897 |
1892 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> | 1898 scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> |
1893 VaapiVideoDecodeAccelerator::VaapiVP9Accelerator:: | 1899 VaapiVideoDecodeAccelerator::VaapiVP9Accelerator:: |
1894 VP9PictureToVaapiDecodeSurface(const scoped_refptr<VP9Picture>& pic) { | 1900 VP9PictureToVaapiDecodeSurface(const scoped_refptr<VP9Picture>& pic) { |
1895 VaapiVP9Picture* vaapi_pic = pic->AsVaapiVP9Picture(); | 1901 VaapiVP9Picture* vaapi_pic = pic->AsVaapiVP9Picture(); |
1896 CHECK(vaapi_pic); | 1902 CHECK(vaapi_pic); |
1897 return vaapi_pic->dec_surface(); | 1903 return vaapi_pic->dec_surface(); |
1898 } | 1904 } |
1899 | 1905 |
1900 // static | 1906 // static |
1901 VideoDecodeAccelerator::SupportedProfiles | 1907 VideoDecodeAccelerator::SupportedProfiles |
1902 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { | 1908 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { |
1903 return VaapiWrapper::GetSupportedDecodeProfiles(); | 1909 return VaapiWrapper::GetSupportedDecodeProfiles(); |
1904 } | 1910 } |
1905 | 1911 |
1906 } // namespace media | 1912 } // namespace media |
OLD | NEW |