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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "content/common/gpu/gpu_channel.h" | 12 #include "content/common/gpu/gpu_channel.h" |
13 #include "content/common/gpu/media/vaapi_picture.h" | 13 #include "content/common/gpu/media/vaapi_picture.h" |
14 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 14 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
16 #include "media/video/picture.h" | 16 #include "media/video/picture.h" |
17 #include "ui/gl/gl_bindings.h" | 17 #include "ui/gl/gl_bindings.h" |
| 18 #include "ui/gl/gl_image.h" |
18 | 19 |
19 static void ReportToUMA( | 20 static void ReportToUMA( |
20 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { | 21 content::VaapiH264Decoder::VAVDAH264DecoderFailure failure) { |
21 UMA_HISTOGRAM_ENUMERATION( | 22 UMA_HISTOGRAM_ENUMERATION( |
22 "Media.VAVDAH264.DecoderFailure", | 23 "Media.VAVDAH264.DecoderFailure", |
23 failure, | 24 failure, |
24 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); | 25 content::VaapiH264Decoder::VAVDA_H264_DECODER_FAILURES_MAX); |
25 } | 26 } |
26 | 27 |
27 namespace content { | 28 namespace content { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 Pictures::iterator it = pictures_.find(picture_buffer_id); | 66 Pictures::iterator it = pictures_.find(picture_buffer_id); |
66 if (it == pictures_.end()) { | 67 if (it == pictures_.end()) { |
67 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; | 68 LOG(ERROR) << "Picture id " << picture_buffer_id << " does not exist"; |
68 return NULL; | 69 return NULL; |
69 } | 70 } |
70 | 71 |
71 return it->second.get(); | 72 return it->second.get(); |
72 } | 73 } |
73 | 74 |
74 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( | 75 VaapiVideoDecodeAccelerator::VaapiVideoDecodeAccelerator( |
75 const base::Callback<bool(void)>& make_context_current) | 76 const base::Callback<bool(void)>& make_context_current, |
| 77 const base::Callback<void(uint32, uint32, scoped_refptr<gfx::GLImage>)>& |
| 78 bind_image) |
76 : make_context_current_(make_context_current), | 79 : make_context_current_(make_context_current), |
77 state_(kUninitialized), | 80 state_(kUninitialized), |
78 input_ready_(&lock_), | 81 input_ready_(&lock_), |
79 surfaces_available_(&lock_), | 82 surfaces_available_(&lock_), |
80 message_loop_(base::MessageLoop::current()), | 83 message_loop_(base::MessageLoop::current()), |
81 decoder_thread_("VaapiDecoderThread"), | 84 decoder_thread_("VaapiDecoderThread"), |
82 num_frames_at_client_(0), | 85 num_frames_at_client_(0), |
83 num_stream_bufs_at_decoder_(0), | 86 num_stream_bufs_at_decoder_(0), |
84 finish_flush_pending_(false), | 87 finish_flush_pending_(false), |
85 awaiting_va_surfaces_recycle_(false), | 88 awaiting_va_surfaces_recycle_(false), |
86 requested_num_pics_(0), | 89 requested_num_pics_(0), |
| 90 bind_image_(bind_image), |
87 weak_this_factory_(this) { | 91 weak_this_factory_(this) { |
88 weak_this_ = weak_this_factory_.GetWeakPtr(); | 92 weak_this_ = weak_this_factory_.GetWeakPtr(); |
89 va_surface_release_cb_ = media::BindToCurrentLoop( | 93 va_surface_release_cb_ = media::BindToCurrentLoop( |
90 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 94 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
91 } | 95 } |
92 | 96 |
93 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 97 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
94 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 98 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
95 } | 99 } |
96 | 100 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 PLATFORM_FAILURE, ); | 183 PLATFORM_FAILURE, ); |
180 | 184 |
181 // Notify the client a picture is ready to be displayed. | 185 // Notify the client a picture is ready to be displayed. |
182 ++num_frames_at_client_; | 186 ++num_frames_at_client_; |
183 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); | 187 TRACE_COUNTER1("Video Decoder", "Textures at client", num_frames_at_client_); |
184 DVLOG(4) << "Notifying output picture id " << output_id | 188 DVLOG(4) << "Notifying output picture id " << output_id |
185 << " for input "<< input_id << " is ready"; | 189 << " for input "<< input_id << " is ready"; |
186 // TODO(posciak): Use visible size from decoder here instead | 190 // TODO(posciak): Use visible size from decoder here instead |
187 // (crbug.com/402760). | 191 // (crbug.com/402760). |
188 if (client_) | 192 if (client_) |
189 client_->PictureReady( | 193 client_->PictureReady(media::Picture(output_id, input_id, |
190 media::Picture(output_id, input_id, gfx::Rect(picture->size()), false)); | 194 gfx::Rect(picture->size()), |
| 195 picture->AllowOverlay())); |
191 } | 196 } |
192 | 197 |
193 void VaapiVideoDecodeAccelerator::TryOutputSurface() { | 198 void VaapiVideoDecodeAccelerator::TryOutputSurface() { |
194 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 199 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
195 | 200 |
196 // Handle Destroy() arriving while pictures are queued for output. | 201 // Handle Destroy() arriving while pictures are queued for output. |
197 if (!client_) | 202 if (!client_) |
198 return; | 203 return; |
199 | 204 |
200 if (pending_output_cbs_.empty() || output_buffers_.empty()) | 205 if (pending_output_cbs_.empty() || output_buffers_.empty()) |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 523 |
519 for (size_t i = 0; i < buffers.size(); ++i) { | 524 for (size_t i = 0; i < buffers.size(); ++i) { |
520 DVLOG(2) << "Assigning picture id: " << buffers[i].id() | 525 DVLOG(2) << "Assigning picture id: " << buffers[i].id() |
521 << " to texture id: " << buffers[i].texture_id() | 526 << " to texture id: " << buffers[i].texture_id() |
522 << " VASurfaceID: " << va_surface_ids[i]; | 527 << " VASurfaceID: " << va_surface_ids[i]; |
523 | 528 |
524 linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture( | 529 linked_ptr<VaapiPicture> picture(VaapiPicture::CreatePicture( |
525 vaapi_wrapper_.get(), make_context_current_, buffers[i].id(), | 530 vaapi_wrapper_.get(), make_context_current_, buffers[i].id(), |
526 buffers[i].texture_id(), requested_pic_size_)); | 531 buffers[i].texture_id(), requested_pic_size_)); |
527 | 532 |
| 533 scoped_refptr<gfx::GLImage> image = picture->GetImageToBind(); |
| 534 if (image) { |
| 535 bind_image_.Run(buffers[i].internal_texture_id(), |
| 536 VaapiPicture::GetGLTextureTarget(), image); |
| 537 } |
| 538 |
528 RETURN_AND_NOTIFY_ON_FAILURE( | 539 RETURN_AND_NOTIFY_ON_FAILURE( |
529 picture.get(), "Failed assigning picture buffer to a texture.", | 540 picture.get(), "Failed assigning picture buffer to a texture.", |
530 PLATFORM_FAILURE, ); | 541 PLATFORM_FAILURE, ); |
531 | 542 |
532 bool inserted = | 543 bool inserted = |
533 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; | 544 pictures_.insert(std::make_pair(buffers[i].id(), picture)).second; |
534 DCHECK(inserted); | 545 DCHECK(inserted); |
535 | 546 |
536 output_buffers_.push(buffers[i].id()); | 547 output_buffers_.push(buffers[i].id()); |
537 available_va_surfaces_.push_back(va_surface_ids[i]); | 548 available_va_surfaces_.push_back(va_surface_ids[i]); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 742 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
732 Cleanup(); | 743 Cleanup(); |
733 delete this; | 744 delete this; |
734 } | 745 } |
735 | 746 |
736 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { | 747 bool VaapiVideoDecodeAccelerator::CanDecodeOnIOThread() { |
737 return false; | 748 return false; |
738 } | 749 } |
739 | 750 |
740 } // namespace content | 751 } // namespace content |
OLD | NEW |