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 ~MockVideoDecodeAcceleratorClient() override
{}
39 // VideoDecodeAccelerator::Client implementation.
40 void ProvidePictureBuffers(uint32 requested_num_of_buffers
,
41 const gfx::Size
& dimensions
,
42 uint32 texture_target
) override
{}
43 void DismissPictureBuffer(int32 picture_buffer_id
) override
{}
44 void PictureReady(const media::Picture
& picture
) override
{}
45 void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id
) override
{}
46 void NotifyFlushDone() override
{}
47 void NotifyResetDone() override
{}
48 void NotifyError(media::VideoDecodeAccelerator::Error error
) override
{}
51 class AndroidVideoDecodeAcceleratorTest
: public testing::Test
{
53 ~AndroidVideoDecodeAcceleratorTest() override
{}
56 void SetUp() override
{
57 JNIEnv
* env
= base::android::AttachCurrentThread();
58 media::RegisterJni(env
);
59 // TODO(felipeg): fix GL bindings, so that the decoder can perform GL
61 scoped_ptr
<gpu::gles2::MockGLES2Decoder
> decoder(
62 new gpu::gles2::MockGLES2Decoder());
63 scoped_ptr
<MockVideoDecodeAcceleratorClient
> client(
64 new MockVideoDecodeAcceleratorClient());
65 accelerator_
.reset(new AndroidVideoDecodeAccelerator(
66 decoder
->AsWeakPtr(), base::Bind(&MockMakeContextCurrent
)));
69 bool Configure(media::VideoCodec codec
) {
70 AndroidVideoDecodeAccelerator
* accelerator
=
71 static_cast<AndroidVideoDecodeAccelerator
*>(accelerator_
.get());
72 accelerator
->surface_texture_
= gfx::SurfaceTexture::Create(0);
73 accelerator
->codec_
= codec
;
74 return accelerator
->ConfigureMediaCodec();
78 scoped_ptr
<media::VideoDecodeAccelerator
> accelerator_
;
81 TEST_F(AndroidVideoDecodeAcceleratorTest
, ConfigureUnsupportedCodec
) {
82 EXPECT_FALSE(Configure(media::kUnknownVideoCodec
));
85 TEST_F(AndroidVideoDecodeAcceleratorTest
, ConfigureSupportedCodec
) {
86 if (!media::MediaCodecBridge::IsAvailable())
88 EXPECT_TRUE(Configure(media::kCodecVP8
));
91 } // namespace content
93 int main(int argc
, char **argv
) {
94 testing::InitGoogleTest(&argc
, argv
);
95 return RUN_ALL_TESTS();