| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 bool MockMakeContextCurrent() { | 26 bool MockMakeContextCurrent() { |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 // TODO(felipeg): Add more unit tests to test the ordinary behavior of | |
| 35 // AndroidVideoDecodeAccelerator. | |
| 36 // http://crbug.com/178647 | |
| 37 class MockVideoDecodeAcceleratorClient | 34 class MockVideoDecodeAcceleratorClient |
| 38 : public media::VideoDecodeAccelerator::Client { | 35 : public media::VideoDecodeAccelerator::Client { |
| 39 public: | 36 public: |
| 40 MockVideoDecodeAcceleratorClient() {} | 37 MockVideoDecodeAcceleratorClient() {} |
| 41 ~MockVideoDecodeAcceleratorClient() override {} | 38 ~MockVideoDecodeAcceleratorClient() override {} |
| 42 | 39 |
| 43 // VideoDecodeAccelerator::Client implementation. | 40 // VideoDecodeAccelerator::Client implementation. |
| 44 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, | 41 void ProvidePictureBuffers(uint32_t requested_num_of_buffers, |
| 45 const gfx::Size& dimensions, | 42 const gfx::Size& dimensions, |
| 46 uint32_t texture_target) override {} | 43 uint32_t texture_target) override {} |
| 47 void DismissPictureBuffer(int32_t picture_buffer_id) override {} | 44 void DismissPictureBuffer(int32_t picture_buffer_id) override {} |
| 48 void PictureReady(const media::Picture& picture) override {} | 45 void PictureReady(const media::Picture& picture) override {} |
| 49 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override {} | 46 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override {} |
| 50 void NotifyFlushDone() override {} | 47 void NotifyFlushDone() override {} |
| 51 void NotifyResetDone() override {} | 48 void NotifyResetDone() override {} |
| 52 void NotifyError(media::VideoDecodeAccelerator::Error error) override {} | 49 void NotifyError(media::VideoDecodeAccelerator::Error error) override {} |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 class AndroidVideoDecodeAcceleratorTest : public testing::Test { | 52 class AndroidVideoDecodeAcceleratorTest : public testing::Test { |
| 56 public: | 53 public: |
| 57 ~AndroidVideoDecodeAcceleratorTest() override {} | 54 ~AndroidVideoDecodeAcceleratorTest() override {} |
| 58 | 55 |
| 59 protected: | 56 protected: |
| 60 void SetUp() override { | 57 void SetUp() override { |
| 61 JNIEnv* env = base::android::AttachCurrentThread(); | 58 JNIEnv* env = base::android::AttachCurrentThread(); |
| 62 media::RegisterJni(env); | 59 media::RegisterJni(env); |
| 63 // TODO(felipeg): fix GL bindings, so that the decoder can perform GL | |
| 64 // calls. | |
| 65 | 60 |
| 66 // Start message loop because | 61 // Start message loop because |
| 67 // AndroidVideoDecodeAccelerator::ConfigureMediaCodec() starts a timer task. | 62 // AndroidVideoDecodeAccelerator::ConfigureMediaCodec() starts a timer task. |
| 68 message_loop_.reset(new base::MessageLoop()); | 63 message_loop_.reset(new base::MessageLoop()); |
| 69 | 64 |
| 70 scoped_ptr<gpu::gles2::MockGLES2Decoder> decoder( | 65 scoped_ptr<gpu::gles2::MockGLES2Decoder> decoder( |
| 71 new gpu::gles2::MockGLES2Decoder()); | 66 new gpu::gles2::MockGLES2Decoder()); |
| 72 scoped_ptr<MockVideoDecodeAcceleratorClient> client( | 67 scoped_ptr<MockVideoDecodeAcceleratorClient> client( |
| 73 new MockVideoDecodeAcceleratorClient()); | 68 new MockVideoDecodeAcceleratorClient()); |
| 74 accelerator_.reset(new AndroidVideoDecodeAccelerator( | 69 accelerator_.reset(new AndroidVideoDecodeAccelerator( |
| 75 decoder->AsWeakPtr(), base::Bind(&MockMakeContextCurrent))); | 70 decoder->AsWeakPtr(), base::Bind(&MockMakeContextCurrent))); |
| 76 } | 71 } |
| 77 | 72 |
| 78 bool Configure(media::VideoCodec codec) { | 73 bool Configure(media::VideoCodec codec) { |
| 79 AndroidVideoDecodeAccelerator* accelerator = | 74 AndroidVideoDecodeAccelerator* accelerator = |
| 80 static_cast<AndroidVideoDecodeAccelerator*>(accelerator_.get()); | 75 static_cast<AndroidVideoDecodeAccelerator*>(accelerator_.get()); |
| 81 accelerator->surface_texture_ = gfx::SurfaceTexture::Create(0); | 76 scoped_refptr<gfx::SurfaceTexture> surface_texture = |
| 77 gfx::SurfaceTexture::Create(0); |
| 78 accelerator->surface_ = gfx::ScopedJavaSurface(surface_texture.get()); |
| 82 accelerator->codec_ = codec; | 79 accelerator->codec_ = codec; |
| 83 return accelerator->ConfigureMediaCodec(); | 80 return accelerator->ConfigureMediaCodec(); |
| 84 } | 81 } |
| 85 | 82 |
| 86 private: | 83 private: |
| 87 scoped_ptr<media::VideoDecodeAccelerator> accelerator_; | 84 scoped_ptr<media::VideoDecodeAccelerator> accelerator_; |
| 88 scoped_ptr<base::MessageLoop> message_loop_; | 85 scoped_ptr<base::MessageLoop> message_loop_; |
| 89 }; | 86 }; |
| 90 | 87 |
| 91 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureUnsupportedCodec) { | 88 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureUnsupportedCodec) { |
| 92 EXPECT_FALSE(Configure(media::kUnknownVideoCodec)); | 89 EXPECT_FALSE(Configure(media::kUnknownVideoCodec)); |
| 93 } | 90 } |
| 94 | 91 |
| 95 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureSupportedCodec) { | 92 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureSupportedCodec) { |
| 96 if (!media::MediaCodecUtil::IsMediaCodecAvailable()) | 93 if (!media::MediaCodecUtil::IsMediaCodecAvailable()) |
| 97 return; | 94 return; |
| 98 EXPECT_TRUE(Configure(media::kCodecVP8)); | 95 EXPECT_TRUE(Configure(media::kCodecVP8)); |
| 99 } | 96 } |
| 100 | 97 |
| 101 } // namespace content | 98 } // namespace content |
| 102 | 99 |
| 103 int main(int argc, char **argv) { | 100 int main(int argc, char **argv) { |
| 104 testing::InitGoogleTest(&argc, argv); | 101 testing::InitGoogleTest(&argc, argv); |
| 105 return RUN_ALL_TESTS(); | 102 return RUN_ALL_TESTS(); |
| 106 } | 103 } |
| OLD | NEW |