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 "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 state_(kUninitialized), | 242 state_(kUninitialized), |
243 input_ready_(&lock_), | 243 input_ready_(&lock_), |
244 surfaces_available_(&lock_), | 244 surfaces_available_(&lock_), |
245 message_loop_(base::MessageLoop::current()), | 245 message_loop_(base::MessageLoop::current()), |
246 decoder_thread_("VaapiDecoderThread"), | 246 decoder_thread_("VaapiDecoderThread"), |
247 num_frames_at_client_(0), | 247 num_frames_at_client_(0), |
248 num_stream_bufs_at_decoder_(0), | 248 num_stream_bufs_at_decoder_(0), |
249 finish_flush_pending_(false), | 249 finish_flush_pending_(false), |
250 awaiting_va_surfaces_recycle_(false), | 250 awaiting_va_surfaces_recycle_(false), |
251 requested_num_pics_(0), | 251 requested_num_pics_(0), |
| 252 min_picture_count_(0), |
252 bind_image_(bind_image), | 253 bind_image_(bind_image), |
253 weak_this_factory_(this) { | 254 weak_this_factory_(this) { |
254 weak_this_ = weak_this_factory_.GetWeakPtr(); | 255 weak_this_ = weak_this_factory_.GetWeakPtr(); |
255 va_surface_release_cb_ = media::BindToCurrentLoop( | 256 va_surface_release_cb_ = media::BindToCurrentLoop( |
256 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); | 257 base::Bind(&VaapiVideoDecodeAccelerator::RecycleVASurfaceID, weak_this_)); |
257 } | 258 } |
258 | 259 |
259 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { | 260 VaapiVideoDecodeAccelerator::~VaapiVideoDecodeAccelerator() { |
260 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 261 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
261 } | 262 } |
262 | 263 |
263 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 264 bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 265 uint32 min_picture_count, |
264 Client* client) { | 266 Client* client) { |
265 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 267 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
266 | 268 |
267 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); | 269 client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); |
268 client_ = client_ptr_factory_->GetWeakPtr(); | 270 client_ = client_ptr_factory_->GetWeakPtr(); |
269 | 271 |
270 base::AutoLock auto_lock(lock_); | 272 base::AutoLock auto_lock(lock_); |
271 DCHECK_EQ(state_, kUninitialized); | 273 DCHECK_EQ(state_, kUninitialized); |
272 DVLOG(2) << "Initializing VAVDA, profile: " << profile; | 274 DVLOG(2) << "Initializing VAVDA, profile: " << profile; |
273 | 275 |
(...skipping 27 matching lines...) Expand all Loading... |
301 profile <= media::VP8PROFILE_MAX) { | 303 profile <= media::VP8PROFILE_MAX) { |
302 vp8_accelerator_.reset(new VaapiVP8Accelerator(this, vaapi_wrapper_.get())); | 304 vp8_accelerator_.reset(new VaapiVP8Accelerator(this, vaapi_wrapper_.get())); |
303 decoder_.reset(new VP8Decoder(vp8_accelerator_.get())); | 305 decoder_.reset(new VP8Decoder(vp8_accelerator_.get())); |
304 } else { | 306 } else { |
305 DLOG(ERROR) << "Unsupported profile " << profile; | 307 DLOG(ERROR) << "Unsupported profile " << profile; |
306 return false; | 308 return false; |
307 } | 309 } |
308 | 310 |
309 CHECK(decoder_thread_.Start()); | 311 CHECK(decoder_thread_.Start()); |
310 decoder_thread_task_runner_ = decoder_thread_.task_runner(); | 312 decoder_thread_task_runner_ = decoder_thread_.task_runner(); |
| 313 min_picture_count_ = min_picture_count; |
311 | 314 |
312 state_ = kIdle; | 315 state_ = kIdle; |
313 return true; | 316 return true; |
314 } | 317 } |
315 | 318 |
316 void VaapiVideoDecodeAccelerator::OutputPicture( | 319 void VaapiVideoDecodeAccelerator::OutputPicture( |
317 const scoped_refptr<VASurface>& va_surface, | 320 const scoped_refptr<VASurface>& va_surface, |
318 int32 input_id, | 321 int32 input_id, |
319 VaapiPicture* picture) { | 322 VaapiPicture* picture) { |
320 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 323 DCHECK_EQ(message_loop_, base::MessageLoop::current()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // of having a separate decoder thread. | 504 // of having a separate decoder thread. |
502 base::AutoUnlock auto_unlock(lock_); | 505 base::AutoUnlock auto_unlock(lock_); |
503 res = decoder_->Decode(); | 506 res = decoder_->Decode(); |
504 } | 507 } |
505 | 508 |
506 switch (res) { | 509 switch (res) { |
507 case AcceleratedVideoDecoder::kAllocateNewSurfaces: | 510 case AcceleratedVideoDecoder::kAllocateNewSurfaces: |
508 DVLOG(1) << "Decoder requesting a new set of surfaces"; | 511 DVLOG(1) << "Decoder requesting a new set of surfaces"; |
509 message_loop_->PostTask(FROM_HERE, base::Bind( | 512 message_loop_->PostTask(FROM_HERE, base::Bind( |
510 &VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange, weak_this_, | 513 &VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange, weak_this_, |
511 decoder_->GetRequiredNumOfPictures(), | 514 std::max(min_picture_count_, |
| 515 static_cast<uint32_t>( |
| 516 decoder_->GetRequiredNumOfPictures())), |
512 decoder_->GetPicSize())); | 517 decoder_->GetPicSize())); |
513 // We'll get rescheduled once ProvidePictureBuffers() finishes. | 518 // We'll get rescheduled once ProvidePictureBuffers() finishes. |
514 return; | 519 return; |
515 | 520 |
516 case AcceleratedVideoDecoder::kRanOutOfStreamData: | 521 case AcceleratedVideoDecoder::kRanOutOfStreamData: |
517 ReturnCurrInputBuffer_Locked(); | 522 ReturnCurrInputBuffer_Locked(); |
518 break; | 523 break; |
519 | 524 |
520 case AcceleratedVideoDecoder::kRanOutOfSurfaces: | 525 case AcceleratedVideoDecoder::kRanOutOfSurfaces: |
521 // No more output buffers in the decoder, try getting more or go to | 526 // No more output buffers in the decoder, try getting more or go to |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 return vaapi_pic->dec_surface(); | 1517 return vaapi_pic->dec_surface(); |
1513 } | 1518 } |
1514 | 1519 |
1515 // static | 1520 // static |
1516 media::VideoDecodeAccelerator::SupportedProfiles | 1521 media::VideoDecodeAccelerator::SupportedProfiles |
1517 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { | 1522 VaapiVideoDecodeAccelerator::GetSupportedProfiles() { |
1518 return VaapiWrapper::GetSupportedDecodeProfiles(); | 1523 return VaapiWrapper::GetSupportedDecodeProfiles(); |
1519 } | 1524 } |
1520 | 1525 |
1521 } // namespace content | 1526 } // namespace content |
OLD | NEW |