| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 if (profile == media::VP8PROFILE_MAIN) { | 78 if (profile == media::VP8PROFILE_MAIN) { |
| 79 codec_ = media::kCodecVP8; | 79 codec_ = media::kCodecVP8; |
| 80 } else { | 80 } else { |
| 81 // TODO(dwkang): enable H264 once b/8125974 is fixed. | 81 // TODO(dwkang): enable H264 once b/8125974 is fixed. |
| 82 LOG(ERROR) << "Unsupported profile: " << profile; | 82 LOG(ERROR) << "Unsupported profile: " << profile; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Only consider using MediaCodec if it's likely backed by hardware. | 86 // Only consider using MediaCodec if it's likely backed by hardware. |
| 87 if (media::VideoCodecBridge::IsKnownUnaccelerated(codec_)) | 87 if (media::VideoCodecBridge::IsKnownUnaccelerated( |
| 88 codec_, media::MEDIA_CODEC_DECODER)) { |
| 88 return false; | 89 return false; |
| 90 } |
| 89 | 91 |
| 90 if (!make_context_current_.Run()) { | 92 if (!make_context_current_.Run()) { |
| 91 LOG(ERROR) << "Failed to make this decoder's GL context current."; | 93 LOG(ERROR) << "Failed to make this decoder's GL context current."; |
| 92 return false; | 94 return false; |
| 93 } | 95 } |
| 94 | 96 |
| 95 if (!gl_decoder_) { | 97 if (!gl_decoder_) { |
| 96 LOG(ERROR) << "Failed to get gles2 decoder instance."; | 98 LOG(ERROR) << "Failed to get gles2 decoder instance."; |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 205 } |
| 204 | 206 |
| 205 bool eos = false; | 207 bool eos = false; |
| 206 base::TimeDelta timestamp; | 208 base::TimeDelta timestamp; |
| 207 int32 buf_index = 0; | 209 int32 buf_index = 0; |
| 208 do { | 210 do { |
| 209 size_t offset = 0; | 211 size_t offset = 0; |
| 210 size_t size = 0; | 212 size_t size = 0; |
| 211 | 213 |
| 212 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( | 214 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( |
| 213 NoWaitTimeOut(), &buf_index, &offset, &size, ×tamp, &eos); | 215 NoWaitTimeOut(), &buf_index, &offset, &size, ×tamp, &eos, NULL); |
| 214 switch (status) { | 216 switch (status) { |
| 215 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: | 217 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: |
| 216 case media::MEDIA_CODEC_ERROR: | 218 case media::MEDIA_CODEC_ERROR: |
| 217 return; | 219 return; |
| 218 | 220 |
| 219 case media::MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { | 221 case media::MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { |
| 220 int32 width, height; | 222 int32 width, height; |
| 221 media_codec_->GetOutputFormat(&width, &height); | 223 media_codec_->GetOutputFormat(&width, &height); |
| 222 | 224 |
| 223 if (!picturebuffers_requested_) { | 225 if (!picturebuffers_requested_) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 } | 394 } |
| 393 | 395 |
| 394 void AndroidVideoDecodeAccelerator::Flush() { | 396 void AndroidVideoDecodeAccelerator::Flush() { |
| 395 DCHECK(thread_checker_.CalledOnValidThread()); | 397 DCHECK(thread_checker_.CalledOnValidThread()); |
| 396 | 398 |
| 397 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); | 399 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); |
| 398 } | 400 } |
| 399 | 401 |
| 400 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { | 402 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { |
| 401 DCHECK(surface_texture_.get()); | 403 DCHECK(surface_texture_.get()); |
| 402 media_codec_.reset(media::VideoCodecBridge::Create(codec_, false)); | |
| 403 | 404 |
| 405 gfx::ScopedJavaSurface surface(surface_texture_.get()); |
| 406 |
| 407 // Pass a dummy 320x240 canvas size and let the codec signal the real size |
| 408 // when it's known from the bitstream. |
| 409 media_codec_.reset(media::VideoCodecBridge::CreateDecoder( |
| 410 codec_, false, gfx::Size(320, 240), surface.j_surface().obj(), NULL)); |
| 404 if (!media_codec_) | 411 if (!media_codec_) |
| 405 return false; | 412 return false; |
| 406 | 413 |
| 407 gfx::ScopedJavaSurface surface(surface_texture_.get()); | |
| 408 // Pass a dummy 320x240 canvas size and let the codec signal the real size | |
| 409 // when it's known from the bitstream. | |
| 410 if (!media_codec_->Start( | |
| 411 codec_, gfx::Size(320, 240), surface.j_surface().obj(), NULL)) { | |
| 412 return false; | |
| 413 } | |
| 414 io_timer_.Start(FROM_HERE, | 414 io_timer_.Start(FROM_HERE, |
| 415 DecodePollDelay(), | 415 DecodePollDelay(), |
| 416 this, | 416 this, |
| 417 &AndroidVideoDecodeAccelerator::DoIOTask); | 417 &AndroidVideoDecodeAccelerator::DoIOTask); |
| 418 return media_codec_->GetOutputBuffers(); | 418 return true; |
| 419 } | 419 } |
| 420 | 420 |
| 421 void AndroidVideoDecodeAccelerator::Reset() { | 421 void AndroidVideoDecodeAccelerator::Reset() { |
| 422 DCHECK(thread_checker_.CalledOnValidThread()); | 422 DCHECK(thread_checker_.CalledOnValidThread()); |
| 423 | 423 |
| 424 while (!pending_bitstream_buffers_.empty()) { | 424 while (!pending_bitstream_buffers_.empty()) { |
| 425 int32 bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); | 425 int32 bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); |
| 426 pending_bitstream_buffers_.pop(); | 426 pending_bitstream_buffers_.pop(); |
| 427 | 427 |
| 428 if (bitstream_buffer_id != -1) { | 428 if (bitstream_buffer_id != -1) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 void AndroidVideoDecodeAccelerator::NotifyResetDone() { | 497 void AndroidVideoDecodeAccelerator::NotifyResetDone() { |
| 498 client_->NotifyResetDone(); | 498 client_->NotifyResetDone(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void AndroidVideoDecodeAccelerator::NotifyError( | 501 void AndroidVideoDecodeAccelerator::NotifyError( |
| 502 media::VideoDecodeAccelerator::Error error) { | 502 media::VideoDecodeAccelerator::Error error) { |
| 503 client_->NotifyError(error); | 503 client_->NotifyError(error); |
| 504 } | 504 } |
| 505 | 505 |
| 506 } // namespace content | 506 } // namespace content |
| OLD | NEW |