| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/android_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/android_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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 | 64 |
| 65 static inline const base::TimeDelta NoWaitTimeOut() { | 65 static inline const base::TimeDelta NoWaitTimeOut() { |
| 66 return base::TimeDelta::FromMicroseconds(0); | 66 return base::TimeDelta::FromMicroseconds(0); |
| 67 } | 67 } |
| 68 | 68 |
| 69 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( | 69 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( |
| 70 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, | 70 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, |
| 71 const base::Callback<bool(void)>& make_context_current) | 71 const base::Callback<bool(void)>& make_context_current) |
| 72 : client_(NULL), | 72 : client_(NULL), |
| 73 num_picture_buffers_(kNumPictureBuffers), |
| 73 make_context_current_(make_context_current), | 74 make_context_current_(make_context_current), |
| 74 codec_(media::kCodecH264), | 75 codec_(media::kCodecH264), |
| 75 state_(NO_ERROR), | 76 state_(NO_ERROR), |
| 76 surface_texture_id_(0), | 77 surface_texture_id_(0), |
| 77 picturebuffers_requested_(false), | 78 picturebuffers_requested_(false), |
| 78 gl_decoder_(decoder), | 79 gl_decoder_(decoder), |
| 79 weak_this_factory_(this) {} | 80 weak_this_factory_(this) {} |
| 80 | 81 |
| 81 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { | 82 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, | 86 bool AndroidVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, |
| 87 uint32 min_picture_count, |
| 86 Client* client) { | 88 Client* client) { |
| 87 DCHECK(!media_codec_); | 89 DCHECK(!media_codec_); |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 | 91 |
| 90 client_ = client; | 92 client_ = client; |
| 93 num_picture_buffers_ = std::max(min_picture_count, |
| 94 static_cast<uint32>(kNumPictureBuffers)); |
| 91 | 95 |
| 92 if (profile == media::VP8PROFILE_ANY) { | 96 if (profile == media::VP8PROFILE_ANY) { |
| 93 codec_ = media::kCodecVP8; | 97 codec_ = media::kCodecVP8; |
| 94 } else { | 98 } else { |
| 95 // TODO(dwkang): enable H264 once b/8125974 is fixed. | 99 // TODO(dwkang): enable H264 once b/8125974 is fixed. |
| 96 LOG(ERROR) << "Unsupported profile: " << profile; | 100 LOG(ERROR) << "Unsupported profile: " << profile; |
| 97 return false; | 101 return false; |
| 98 } | 102 } |
| 99 | 103 |
| 100 // Only consider using MediaCodec if it's likely backed by hardware. | 104 // Only consider using MediaCodec if it's likely backed by hardware. |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 INVALID_ARGUMENT); | 412 INVALID_ARGUMENT); |
| 409 int32 id = buffers[i].id(); | 413 int32 id = buffers[i].id(); |
| 410 output_picture_buffers_.insert(std::make_pair(id, buffers[i])); | 414 output_picture_buffers_.insert(std::make_pair(id, buffers[i])); |
| 411 free_picture_ids_.push(id); | 415 free_picture_ids_.push(id); |
| 412 // Since the client might be re-using |picture_buffer_id| values, forget | 416 // Since the client might be re-using |picture_buffer_id| values, forget |
| 413 // about previously-dismissed IDs now. See ReusePictureBuffer() comment | 417 // about previously-dismissed IDs now. See ReusePictureBuffer() comment |
| 414 // about "zombies" for why we maintain this set in the first place. | 418 // about "zombies" for why we maintain this set in the first place. |
| 415 dismissed_picture_ids_.erase(id); | 419 dismissed_picture_ids_.erase(id); |
| 416 } | 420 } |
| 417 | 421 |
| 418 RETURN_ON_FAILURE(output_picture_buffers_.size() == kNumPictureBuffers, | 422 RETURN_ON_FAILURE(output_picture_buffers_.size() == num_picture_buffers_, |
| 419 "Invalid picture buffers were passed.", | 423 "Invalid picture buffers were passed.", |
| 420 INVALID_ARGUMENT); | 424 INVALID_ARGUMENT); |
| 421 | 425 |
| 422 DoIOTask(); | 426 DoIOTask(); |
| 423 } | 427 } |
| 424 | 428 |
| 425 void AndroidVideoDecodeAccelerator::ReusePictureBuffer( | 429 void AndroidVideoDecodeAccelerator::ReusePictureBuffer( |
| 426 int32 picture_buffer_id) { | 430 int32 picture_buffer_id) { |
| 427 DCHECK(thread_checker_.CalledOnValidThread()); | 431 DCHECK(thread_checker_.CalledOnValidThread()); |
| 428 | 432 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 if (copier_) | 525 if (copier_) |
| 522 copier_->Destroy(); | 526 copier_->Destroy(); |
| 523 delete this; | 527 delete this; |
| 524 } | 528 } |
| 525 | 529 |
| 526 bool AndroidVideoDecodeAccelerator::CanDecodeOnIOThread() { | 530 bool AndroidVideoDecodeAccelerator::CanDecodeOnIOThread() { |
| 527 return false; | 531 return false; |
| 528 } | 532 } |
| 529 | 533 |
| 530 void AndroidVideoDecodeAccelerator::RequestPictureBuffers() { | 534 void AndroidVideoDecodeAccelerator::RequestPictureBuffers() { |
| 531 client_->ProvidePictureBuffers(kNumPictureBuffers, size_, GL_TEXTURE_2D); | 535 client_->ProvidePictureBuffers(num_picture_buffers_, size_, GL_TEXTURE_2D); |
| 532 } | 536 } |
| 533 | 537 |
| 534 void AndroidVideoDecodeAccelerator::NotifyPictureReady( | 538 void AndroidVideoDecodeAccelerator::NotifyPictureReady( |
| 535 const media::Picture& picture) { | 539 const media::Picture& picture) { |
| 536 client_->PictureReady(picture); | 540 client_->PictureReady(picture); |
| 537 } | 541 } |
| 538 | 542 |
| 539 void AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( | 543 void AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer( |
| 540 int input_buffer_id) { | 544 int input_buffer_id) { |
| 541 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); | 545 client_->NotifyEndOfBitstreamBuffer(input_buffer_id); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 564 } | 568 } |
| 565 SupportedProfile profile; | 569 SupportedProfile profile; |
| 566 profile.profile = media::VP8PROFILE_ANY; | 570 profile.profile = media::VP8PROFILE_ANY; |
| 567 profile.min_resolution.SetSize(16, 16); | 571 profile.min_resolution.SetSize(16, 16); |
| 568 profile.max_resolution.SetSize(1920, 1088); | 572 profile.max_resolution.SetSize(1920, 1088); |
| 569 profiles.push_back(profile); | 573 profiles.push_back(profile); |
| 570 return profiles; | 574 return profiles; |
| 571 } | 575 } |
| 572 | 576 |
| 573 } // namespace content | 577 } // namespace content |
| OLD | NEW |