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_copying_backing_strategy.h"
12 #include "content/common/gpu/media/android_video_decode_accelerator.h"
13 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
14 #include "media/base/android/media_codec_bridge.h"
15 #include "media/base/android/media_jni_registrar.h"
16 #include "media/video/picture.h"
17 #include "media/video/video_decode_accelerator.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gl/android/surface_texture.h"
23 bool MockMakeContextCurrent() {
31 // TODO(felipeg): Add more unit tests to test the ordinary behavior of
32 // AndroidVideoDecodeAccelerator.
33 // http://crbug.com/178647
34 class MockVideoDecodeAcceleratorClient
35 : public media::VideoDecodeAccelerator::Client
{
37 MockVideoDecodeAcceleratorClient() {}
38 ~MockVideoDecodeAcceleratorClient() override
{}
40 // VideoDecodeAccelerator::Client implementation.
41 void ProvidePictureBuffers(uint32 requested_num_of_buffers
,
42 const gfx::Size
& dimensions
,
43 uint32 texture_target
) override
{}
44 void DismissPictureBuffer(int32 picture_buffer_id
) override
{}
45 void PictureReady(const media::Picture
& picture
) override
{}
46 void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id
) override
{}
47 void NotifyFlushDone() override
{}
48 void NotifyResetDone() override
{}
49 void NotifyError(media::VideoDecodeAccelerator::Error error
) override
{}
52 class AndroidVideoDecodeAcceleratorTest
: public testing::Test
{
54 ~AndroidVideoDecodeAcceleratorTest() override
{}
57 void SetUp() override
{
58 JNIEnv
* env
= base::android::AttachCurrentThread();
59 media::RegisterJni(env
);
60 // TODO(felipeg): fix GL bindings, so that the decoder can perform GL
62 scoped_ptr
<gpu::gles2::MockGLES2Decoder
> decoder(
63 new gpu::gles2::MockGLES2Decoder());
64 scoped_ptr
<MockVideoDecodeAcceleratorClient
> client(
65 new MockVideoDecodeAcceleratorClient());
66 accelerator_
.reset(new AndroidVideoDecodeAccelerator(
67 decoder
->AsWeakPtr(), base::Bind(&MockMakeContextCurrent
),
68 make_scoped_ptr(new AndroidCopyingBackingStrategy())));
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();