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(codec_, false)) |
Ken Russell (switch to Gerrit)
2013/11/27 00:18:20
It would be better to use an enum for this new arg
Ami GONE FROM CHROMIUM
2013/11/27 01:13:13
It's a PITA but I agree it's an improvement. Done
Ken Russell (switch to Gerrit)
2013/11/27 01:16:37
Thanks.
| |
88 return false; | 88 return false; |
89 | 89 |
90 if (!make_context_current_.Run()) { | 90 if (!make_context_current_.Run()) { |
91 LOG(ERROR) << "Failed to make this decoder's GL context current."; | 91 LOG(ERROR) << "Failed to make this decoder's GL context current."; |
92 return false; | 92 return false; |
93 } | 93 } |
94 | 94 |
95 if (!gl_decoder_) { | 95 if (!gl_decoder_) { |
96 LOG(ERROR) << "Failed to get gles2 decoder instance."; | 96 LOG(ERROR) << "Failed to get gles2 decoder instance."; |
97 return false; | 97 return false; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 } | 203 } |
204 | 204 |
205 bool eos = false; | 205 bool eos = false; |
206 base::TimeDelta timestamp; | 206 base::TimeDelta timestamp; |
207 int32 buf_index = 0; | 207 int32 buf_index = 0; |
208 do { | 208 do { |
209 size_t offset = 0; | 209 size_t offset = 0; |
210 size_t size = 0; | 210 size_t size = 0; |
211 | 211 |
212 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( | 212 media::MediaCodecStatus status = media_codec_->DequeueOutputBuffer( |
213 NoWaitTimeOut(), &buf_index, &offset, &size, ×tamp, &eos); | 213 NoWaitTimeOut(), &buf_index, &offset, &size, ×tamp, &eos, NULL); |
214 switch (status) { | 214 switch (status) { |
215 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: | 215 case media::MEDIA_CODEC_DEQUEUE_OUTPUT_AGAIN_LATER: |
216 case media::MEDIA_CODEC_ERROR: | 216 case media::MEDIA_CODEC_ERROR: |
217 return; | 217 return; |
218 | 218 |
219 case media::MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { | 219 case media::MEDIA_CODEC_OUTPUT_FORMAT_CHANGED: { |
220 int32 width, height; | 220 int32 width, height; |
221 media_codec_->GetOutputFormat(&width, &height); | 221 media_codec_->GetOutputFormat(&width, &height); |
222 | 222 |
223 if (!picturebuffers_requested_) { | 223 if (!picturebuffers_requested_) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 } | 392 } |
393 | 393 |
394 void AndroidVideoDecodeAccelerator::Flush() { | 394 void AndroidVideoDecodeAccelerator::Flush() { |
395 DCHECK(thread_checker_.CalledOnValidThread()); | 395 DCHECK(thread_checker_.CalledOnValidThread()); |
396 | 396 |
397 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); | 397 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); |
398 } | 398 } |
399 | 399 |
400 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { | 400 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { |
401 DCHECK(surface_texture_.get()); | 401 DCHECK(surface_texture_.get()); |
402 media_codec_.reset(media::VideoCodecBridge::Create(codec_, false)); | |
403 | 402 |
403 gfx::ScopedJavaSurface surface(surface_texture_.get()); | |
404 | |
405 // Pass a dummy 320x240 canvas size and let the codec signal the real size | |
406 // when it's known from the bitstream. | |
407 media_codec_.reset(media::VideoCodecBridge::CreateDecoder( | |
408 codec_, false, gfx::Size(320, 240), surface.j_surface().obj(), NULL)); | |
404 if (!media_codec_) | 409 if (!media_codec_) |
405 return false; | 410 return false; |
406 | 411 |
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, | 412 io_timer_.Start(FROM_HERE, |
415 DecodePollDelay(), | 413 DecodePollDelay(), |
416 this, | 414 this, |
417 &AndroidVideoDecodeAccelerator::DoIOTask); | 415 &AndroidVideoDecodeAccelerator::DoIOTask); |
418 return media_codec_->GetOutputBuffers(); | 416 return true; |
419 } | 417 } |
420 | 418 |
421 void AndroidVideoDecodeAccelerator::Reset() { | 419 void AndroidVideoDecodeAccelerator::Reset() { |
422 DCHECK(thread_checker_.CalledOnValidThread()); | 420 DCHECK(thread_checker_.CalledOnValidThread()); |
423 | 421 |
424 while (!pending_bitstream_buffers_.empty()) { | 422 while (!pending_bitstream_buffers_.empty()) { |
425 int32 bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); | 423 int32 bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); |
426 pending_bitstream_buffers_.pop(); | 424 pending_bitstream_buffers_.pop(); |
427 | 425 |
428 if (bitstream_buffer_id != -1) { | 426 if (bitstream_buffer_id != -1) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 void AndroidVideoDecodeAccelerator::NotifyResetDone() { | 495 void AndroidVideoDecodeAccelerator::NotifyResetDone() { |
498 client_->NotifyResetDone(); | 496 client_->NotifyResetDone(); |
499 } | 497 } |
500 | 498 |
501 void AndroidVideoDecodeAccelerator::NotifyError( | 499 void AndroidVideoDecodeAccelerator::NotifyError( |
502 media::VideoDecodeAccelerator::Error error) { | 500 media::VideoDecodeAccelerator::Error error) { |
503 client_->NotifyError(error); | 501 client_->NotifyError(error); |
504 } | 502 } |
505 | 503 |
506 } // namespace content | 504 } // namespace content |
OLD | NEW |