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 <jni.h> | |
8 | |
9 #include "base/android/jni_android.h" | |
10 #include "base/android/scoped_java_ref.h" | |
11 #include "base/bind.h" | 7 #include "base/bind.h" |
12 #include "base/logging.h" | 8 #include "base/logging.h" |
13 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
14 #include "content/common/android/surface_callback.h" | 10 #include "content/common/android/scoped_java_surface.h" |
15 #include "content/common/gpu/gpu_channel.h" | 11 #include "content/common/gpu/gpu_channel.h" |
16 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 12 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
17 #include "media/base/bitstream_buffer.h" | 13 #include "media/base/bitstream_buffer.h" |
18 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
19 #include "media/video/picture.h" | 15 #include "media/video/picture.h" |
20 #include "ui/gl/gl_bindings.h" | 16 #include "ui/gl/gl_bindings.h" |
21 | 17 |
22 using base::android::MethodID; | |
23 using base::android::ScopedJavaLocalRef; | |
24 | |
25 namespace content { | 18 namespace content { |
26 | 19 |
27 // Helper macros for dealing with failure. If |result| evaluates false, emit | 20 // Helper macros for dealing with failure. If |result| evaluates false, emit |
28 // |log| to ERROR, register |error| with the decoder, and return. | 21 // |log| to ERROR, register |error| with the decoder, and return. |
29 #define RETURN_ON_FAILURE(result, log, error) \ | 22 #define RETURN_ON_FAILURE(result, log, error) \ |
30 do { \ | 23 do { \ |
31 if (!(result)) { \ | 24 if (!(result)) { \ |
32 DLOG(ERROR) << log; \ | 25 DLOG(ERROR) << log; \ |
33 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( \ | 26 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( \ |
34 &AndroidVideoDecodeAccelerator::NotifyError, \ | 27 &AndroidVideoDecodeAccelerator::NotifyError, \ |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 DCHECK(thread_checker_.CalledOnValidThread()); | 371 DCHECK(thread_checker_.CalledOnValidThread()); |
379 | 372 |
380 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); | 373 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); |
381 } | 374 } |
382 | 375 |
383 void AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { | 376 void AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { |
384 DCHECK(surface_texture_.get()); | 377 DCHECK(surface_texture_.get()); |
385 | 378 |
386 media_codec_.reset(new media::MediaCodecBridge(codec_)); | 379 media_codec_.reset(new media::MediaCodecBridge(codec_)); |
387 | 380 |
388 JNIEnv* env = base::android::AttachCurrentThread(); | 381 ScopedJavaSurface surface(surface_texture_.get()); |
389 CHECK(env); | |
390 ScopedJavaLocalRef<jclass> cls( | |
391 base::android::GetClass(env, "android/view/Surface")); | |
392 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( | |
393 env, cls.obj(), "<init>", "(Landroid/graphics/SurfaceTexture;)V"); | |
394 ScopedJavaLocalRef<jobject> j_surface( | |
395 env, env->NewObject( | |
396 cls.obj(), constructor, | |
397 surface_texture_->j_surface_texture().obj())); | |
398 | |
399 // VDA does not pass the container indicated resolution in the initialization | 382 // VDA does not pass the container indicated resolution in the initialization |
400 // phase. Here, we set 720p by default. | 383 // phase. Here, we set 720p by default. |
401 // TODO(dwkang): find out a way to remove the following hard-coded value. | 384 // TODO(dwkang): find out a way to remove the following hard-coded value. |
402 media_codec_->StartVideo(codec_, gfx::Size(1280, 720), j_surface.obj()); | 385 media_codec_->StartVideo( |
403 content::ReleaseSurface(j_surface.obj()); | 386 codec_, gfx::Size(1280, 720), surface.j_surface().obj()); |
404 media_codec_->GetOutputBuffers(); | 387 media_codec_->GetOutputBuffers(); |
405 } | 388 } |
406 | 389 |
407 void AndroidVideoDecodeAccelerator::Reset() { | 390 void AndroidVideoDecodeAccelerator::Reset() { |
408 DCHECK(thread_checker_.CalledOnValidThread()); | 391 DCHECK(thread_checker_.CalledOnValidThread()); |
409 | 392 |
410 while(!pending_bitstream_buffers_.empty()) { | 393 while(!pending_bitstream_buffers_.empty()) { |
411 media::BitstreamBuffer& bitstream_buffer = | 394 media::BitstreamBuffer& bitstream_buffer = |
412 pending_bitstream_buffers_.front(); | 395 pending_bitstream_buffers_.front(); |
413 pending_bitstream_buffers_.pop(); | 396 pending_bitstream_buffers_.pop(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 void AndroidVideoDecodeAccelerator::NotifyResetDone() { | 456 void AndroidVideoDecodeAccelerator::NotifyResetDone() { |
474 client_->NotifyResetDone(); | 457 client_->NotifyResetDone(); |
475 } | 458 } |
476 | 459 |
477 void AndroidVideoDecodeAccelerator::NotifyError( | 460 void AndroidVideoDecodeAccelerator::NotifyError( |
478 media::VideoDecodeAccelerator::Error error) { | 461 media::VideoDecodeAccelerator::Error error) { |
479 client_->NotifyError(error); | 462 client_->NotifyError(error); |
480 } | 463 } |
481 | 464 |
482 } // namespace content | 465 } // namespace content |
OLD | NEW |