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.h" | 9 #include "base/message_loop.h" |
10 #include "content/common/gpu/gpu_channel.h" | 10 #include "content/common/gpu/gpu_channel.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 97 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
98 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, | 98 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, |
99 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 99 GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
100 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, | 100 glTexParameteri(GL_TEXTURE_EXTERNAL_OES, |
101 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 101 GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
102 gl_decoder_->RestoreTextureUnitBindings(0); | 102 gl_decoder_->RestoreTextureUnitBindings(0); |
103 gl_decoder_->RestoreActiveTexture(); | 103 gl_decoder_->RestoreActiveTexture(); |
104 | 104 |
105 surface_texture_ = new gfx::SurfaceTextureBridge(surface_texture_id_); | 105 surface_texture_ = new gfx::SurfaceTextureBridge(surface_texture_id_); |
106 | 106 |
107 ConfigureMediaCodec(); | 107 if (!ConfigureMediaCodec()) { |
| 108 LOG(ERROR) << "Failed to create MediaCodec instance."; |
| 109 return false; |
| 110 } |
108 | 111 |
109 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 112 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
110 &AndroidVideoDecodeAccelerator::NotifyInitializeDone, | 113 &AndroidVideoDecodeAccelerator::NotifyInitializeDone, |
111 base::AsWeakPtr(this))); | 114 base::AsWeakPtr(this))); |
112 return true; | 115 return true; |
113 } | 116 } |
114 | 117 |
115 void AndroidVideoDecodeAccelerator::DoIOTask() { | 118 void AndroidVideoDecodeAccelerator::DoIOTask() { |
116 io_task_is_posted_ = false; | 119 io_task_is_posted_ = false; |
117 if (state_ == ERROR) { | 120 if (state_ == ERROR) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (!io_task_is_posted_) | 372 if (!io_task_is_posted_) |
370 DoIOTask(); | 373 DoIOTask(); |
371 } | 374 } |
372 | 375 |
373 void AndroidVideoDecodeAccelerator::Flush() { | 376 void AndroidVideoDecodeAccelerator::Flush() { |
374 DCHECK(thread_checker_.CalledOnValidThread()); | 377 DCHECK(thread_checker_.CalledOnValidThread()); |
375 | 378 |
376 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); | 379 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); |
377 } | 380 } |
378 | 381 |
379 void AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { | 382 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { |
380 DCHECK(surface_texture_.get()); | 383 DCHECK(surface_texture_.get()); |
| 384 media_codec_.reset(media::VideoCodecBridge::Create(codec_)); |
381 | 385 |
382 media_codec_.reset(new media::VideoCodecBridge(codec_)); | 386 if (!media_codec_) |
| 387 return false; |
383 | 388 |
384 gfx::ScopedJavaSurface surface(surface_texture_.get()); | 389 gfx::ScopedJavaSurface surface(surface_texture_.get()); |
385 // VDA does not pass the container indicated resolution in the initialization | 390 // VDA does not pass the container indicated resolution in the initialization |
386 // phase. Here, we set 720p by default. | 391 // phase. Here, we set 720p by default. |
387 // TODO(dwkang): find out a way to remove the following hard-coded value. | 392 // TODO(dwkang): find out a way to remove the following hard-coded value. |
388 media_codec_->Start( | 393 media_codec_->Start( |
389 codec_, gfx::Size(1280, 720), surface.j_surface().obj()); | 394 codec_, gfx::Size(1280, 720), surface.j_surface().obj()); |
390 media_codec_->GetOutputBuffers(); | 395 media_codec_->GetOutputBuffers(); |
| 396 return true; |
391 } | 397 } |
392 | 398 |
393 void AndroidVideoDecodeAccelerator::Reset() { | 399 void AndroidVideoDecodeAccelerator::Reset() { |
394 DCHECK(thread_checker_.CalledOnValidThread()); | 400 DCHECK(thread_checker_.CalledOnValidThread()); |
395 | 401 |
396 while(!pending_bitstream_buffers_.empty()) { | 402 while(!pending_bitstream_buffers_.empty()) { |
397 media::BitstreamBuffer& bitstream_buffer = | 403 media::BitstreamBuffer& bitstream_buffer = |
398 pending_bitstream_buffers_.front(); | 404 pending_bitstream_buffers_.front(); |
399 pending_bitstream_buffers_.pop(); | 405 pending_bitstream_buffers_.pop(); |
400 | 406 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 void AndroidVideoDecodeAccelerator::NotifyResetDone() { | 465 void AndroidVideoDecodeAccelerator::NotifyResetDone() { |
460 client_->NotifyResetDone(); | 466 client_->NotifyResetDone(); |
461 } | 467 } |
462 | 468 |
463 void AndroidVideoDecodeAccelerator::NotifyError( | 469 void AndroidVideoDecodeAccelerator::NotifyError( |
464 media::VideoDecodeAccelerator::Error error) { | 470 media::VideoDecodeAccelerator::Error error) { |
465 client_->NotifyError(error); | 471 client_->NotifyError(error); |
466 } | 472 } |
467 | 473 |
468 } // namespace content | 474 } // namespace content |
OLD | NEW |