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
3 // found in the LICENSE file.
5 #include "content/common/gpu/media/android_video_decode_accelerator.h"
7 #include "base/android/jni_android.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/common/gpu/media/android_video_decode_accelerator.h"
12 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
13 #include "media/base/android/media_codec_bridge.h"
14 #include "media/base/android/media_jni_registrar.h"
15 #include "media/video/picture.h"
16 #include "media/video/video_decode_accelerator.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gl/android/surface_texture.h"
22 bool MockMakeContextCurrent() {
30 // TODO(felipeg): Add more unit tests to test the ordinary behavior of
31 // AndroidVideoDecodeAccelerator.
32 // http://crbug.com/178647
33 class MockVideoDecodeAcceleratorClient
34 : public media::VideoDecodeAccelerator::Client
{
36 MockVideoDecodeAcceleratorClient() {};
37 virtual ~MockVideoDecodeAcceleratorClient() {};
39 // VideoDecodeAccelerator::Client implementation.
40 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers
,
41 const gfx::Size
& dimensions
,
42 uint32 texture_target
) override
{};
43 virtual void DismissPictureBuffer(int32 picture_buffer_id
) override
{};
44 virtual void PictureReady(const media::Picture
& picture
) override
{};
45 virtual void NotifyEndOfBitstreamBuffer(
46 int32 bitstream_buffer_id
) override
{};
47 virtual void NotifyFlushDone() override
{};
48 virtual void NotifyResetDone() override
{};
49 virtual void NotifyError(
50 media::VideoDecodeAccelerator::Error error
) override
{};
53 class AndroidVideoDecodeAcceleratorTest
: public testing::Test
{
55 virtual ~AndroidVideoDecodeAcceleratorTest() {}
58 virtual void SetUp() override
{
59 JNIEnv
* env
= base::android::AttachCurrentThread();
60 media::RegisterJni(env
);
61 // TODO(felipeg): fix GL bindings, so that the decoder can perform GL
63 scoped_ptr
<gpu::gles2::MockGLES2Decoder
> decoder(
64 new gpu::gles2::MockGLES2Decoder());
65 scoped_ptr
<MockVideoDecodeAcceleratorClient
> client(
66 new MockVideoDecodeAcceleratorClient());
67 accelerator_
.reset(new AndroidVideoDecodeAccelerator(
68 decoder
->AsWeakPtr(), base::Bind(&MockMakeContextCurrent
)));
71 bool Configure(media::VideoCodec codec
) {
72 AndroidVideoDecodeAccelerator
* accelerator
=
73 static_cast<AndroidVideoDecodeAccelerator
*>(accelerator_
.get());
74 accelerator
->surface_texture_
= gfx::SurfaceTexture::Create(0);
75 accelerator
->codec_
= codec
;
76 return accelerator
->ConfigureMediaCodec();
80 scoped_ptr
<media::VideoDecodeAccelerator
> accelerator_
;
83 TEST_F(AndroidVideoDecodeAcceleratorTest
, ConfigureUnsupportedCodec
) {
84 EXPECT_FALSE(Configure(media::kUnknownVideoCodec
));
87 TEST_F(AndroidVideoDecodeAcceleratorTest
, ConfigureSupportedCodec
) {
88 if (!media::MediaCodecBridge::IsAvailable())
90 EXPECT_TRUE(Configure(media::kCodecVP8
));
93 } // namespace content
95 int main(int argc
, char **argv
) {
96 testing::InitGoogleTest(&argc
, argv
);
97 return RUN_ALL_TESTS();