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