Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: media/gpu/android_video_decode_accelerator_unittest.cc

Issue 2662173002: media: Don't create a new MediaCodec during AVDA teardown (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/android_video_decode_accelerator.cc ('k') | media/gpu/avda_codec_allocator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "media/gpu/android_video_decode_accelerator.h" 5 #include "media/gpu/android_video_decode_accelerator.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/android/jni_android.h" 11 #include "base/android/jni_android.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h"
15 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" 17 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
16 #include "media/base/android/media_codec_util.h" 18 #include "media/base/android/media_codec_util.h"
17 #include "media/base/android/media_jni_registrar.h" 19 #include "media/base/android/media_jni_registrar.h"
18 #include "media/gpu/android_video_decode_accelerator.h" 20 #include "media/gpu/android_video_decode_accelerator.h"
21 #include "media/gpu/avda_codec_allocator.h"
19 #include "media/video/picture.h" 22 #include "media/video/picture.h"
20 #include "media/video/video_decode_accelerator.h" 23 #include "media/video/video_decode_accelerator.h"
24 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/gl/gl_context.h" 26 #include "ui/gl/gl_context.h"
23 #include "ui/gl/gl_surface.h" 27 #include "ui/gl/gl_surface.h"
24 #include "ui/gl/init/gl_factory.h" 28 #include "ui/gl/init/gl_factory.h"
25 29
30 using ::testing::_;
31 using ::testing::NiceMock;
32
33 namespace media {
26 namespace { 34 namespace {
27 35
36 #define SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE() \
37 do { \
38 if (!MediaCodecUtil::IsMediaCodecAvailable()) \
39 return; \
40 } while (false)
41
28 bool MakeContextCurrent() { 42 bool MakeContextCurrent() {
29 return true; 43 return true;
30 } 44 }
31 45
32 base::WeakPtr<gpu::gles2::GLES2Decoder> GetGLES2Decoder( 46 base::WeakPtr<gpu::gles2::GLES2Decoder> GetGLES2Decoder(
33 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder) { 47 const base::WeakPtr<gpu::gles2::GLES2Decoder>& decoder) {
34 return decoder; 48 return decoder;
35 } 49 }
36 50
51 ACTION(PostNullCodec) {
52 base::ThreadTaskRunnerHandle::Get()->PostTask(
53 FROM_HERE, base::Bind(&media::AVDACodecAllocatorClient::OnCodecConfigured,
54 arg0, nullptr));
55 }
56
37 } // namespace 57 } // namespace
38 58
39 namespace media { 59 class MockVDAClient : public VideoDecodeAccelerator::Client {
60 public:
61 MOCK_METHOD1(NotifyInitializationComplete, void(bool));
62 MOCK_METHOD5(
63 ProvidePictureBuffers,
64 void(uint32_t, VideoPixelFormat, uint32_t, const gfx::Size&, uint32_t));
65 MOCK_METHOD1(DismissPictureBuffer, void(int32_t));
66 MOCK_METHOD1(PictureReady, void(const Picture&));
67 MOCK_METHOD1(NotifyEndOfBitstreamBuffer, void(int32_t));
68 MOCK_METHOD0(NotifyFlushDone, void());
69 MOCK_METHOD0(NotifyResetDone, void());
70 MOCK_METHOD1(NotifyError, void(VideoDecodeAccelerator::Error));
71 };
40 72
41 class MockVideoDecodeAcceleratorClient : public VideoDecodeAccelerator::Client { 73 class MockCodecAllocator : public AVDACodecAllocator {
42 public: 74 public:
43 MockVideoDecodeAcceleratorClient() {} 75 MOCK_METHOD2(CreateMediaCodecAsync,
44 ~MockVideoDecodeAcceleratorClient() override {} 76 void(base::WeakPtr<AVDACodecAllocatorClient>,
45 77 scoped_refptr<CodecConfig>));
46 // VideoDecodeAccelerator::Client implementation.
47 void ProvidePictureBuffers(uint32_t requested_num_of_buffers,
48 VideoPixelFormat format,
49 uint32_t textures_per_buffer,
50 const gfx::Size& dimensions,
51 uint32_t texture_target) override {}
52 void DismissPictureBuffer(int32_t picture_buffer_id) override {}
53 void PictureReady(const Picture& picture) override {}
54 void NotifyEndOfBitstreamBuffer(int32_t bitstream_buffer_id) override {}
55 void NotifyFlushDone() override {}
56 void NotifyResetDone() override {}
57 void NotifyError(VideoDecodeAccelerator::Error error) override {}
58 }; 78 };
59 79
60 class AndroidVideoDecodeAcceleratorTest : public testing::Test { 80 class AndroidVideoDecodeAcceleratorTest : public testing::Test {
61 public: 81 public:
62 ~AndroidVideoDecodeAcceleratorTest() override {} 82 ~AndroidVideoDecodeAcceleratorTest() override {}
63 83
64 protected:
65 void SetUp() override { 84 void SetUp() override {
66 JNIEnv* env = base::android::AttachCurrentThread(); 85 JNIEnv* env = base::android::AttachCurrentThread();
67 RegisterJni(env); 86 RegisterJni(env);
68 87
69 gl::init::ShutdownGL(); 88 gl::init::ShutdownGL();
70 ASSERT_TRUE(gl::init::InitializeGLOneOff()); 89 ASSERT_TRUE(gl::init::InitializeGLOneOff());
71 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size(1024, 1024)); 90 surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size(16, 16));
72 context_ = gl::init::CreateGLContext(nullptr, surface_.get(), 91 context_ = gl::init::CreateGLContext(nullptr, surface_.get(),
73 gl::GLContextAttribs()); 92 gl::GLContextAttribs());
74 context_->MakeCurrent(surface_.get()); 93 context_->MakeCurrent(surface_.get());
75 94
76 // Start a message loop because AVDA starts a timer task.
77 message_loop_.reset(new base::MessageLoop());
78 gl_decoder_.reset(new testing::NiceMock<gpu::gles2::MockGLES2Decoder>());
79 client_.reset(new MockVideoDecodeAcceleratorClient());
80
81 vda_.reset(new AndroidVideoDecodeAccelerator( 95 vda_.reset(new AndroidVideoDecodeAccelerator(
82 base::Bind(&MakeContextCurrent), 96 &codec_allocator_, base::Bind(&MakeContextCurrent),
83 base::Bind(&GetGLES2Decoder, gl_decoder_->AsWeakPtr()))); 97 base::Bind(&GetGLES2Decoder, gl_decoder_.AsWeakPtr())));
84 } 98 }
85 99
86 bool Initialize(VideoCodecProfile profile) { 100 base::MessageLoop message_loop_;
87 return vda_->Initialize(VideoDecodeAccelerator::Config(profile),
88 client_.get());
89 }
90
91 private:
92 std::unique_ptr<base::MessageLoop> message_loop_;
93 scoped_refptr<gl::GLSurface> surface_; 101 scoped_refptr<gl::GLSurface> surface_;
94 scoped_refptr<gl::GLContext> context_; 102 scoped_refptr<gl::GLContext> context_;
95 std::unique_ptr<gpu::gles2::MockGLES2Decoder> gl_decoder_; 103 NiceMock<gpu::gles2::MockGLES2Decoder> gl_decoder_;
96 std::unique_ptr<MockVideoDecodeAcceleratorClient> client_; 104 NiceMock<MockVDAClient> client_;
105 NiceMock<MockCodecAllocator> codec_allocator_;
97 106
98 // This must be a unique pointer to a VDA and not an AVDA to ensure the 107 // This must be a unique pointer to a VDA, not an AVDA, to ensure the
99 // the default_delete specialization that calls Destroy() will be used. 108 // the default_delete specialization that calls Destroy() will be used.
100 std::unique_ptr<VideoDecodeAccelerator> vda_; 109 std::unique_ptr<VideoDecodeAccelerator> vda_;
101 }; 110 };
102 111
103 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureUnsupportedCodec) { 112 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureUnsupportedCodec) {
104 ASSERT_FALSE(Initialize(VIDEO_CODEC_PROFILE_UNKNOWN)); 113 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE();
114
115 ASSERT_FALSE(vda_->Initialize(
116 VideoDecodeAccelerator::Config(VIDEO_CODEC_PROFILE_UNKNOWN), &client_));
105 } 117 }
106 118
107 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureSupportedCodec) { 119 TEST_F(AndroidVideoDecodeAcceleratorTest, ConfigureSupportedCodec) {
108 if (!MediaCodecUtil::IsMediaCodecAvailable()) 120 SKIP_IF_MEDIACODEC_IS_NOT_AVAILABLE();
109 return; 121
110 // H264 is always supported by AVDA. 122 // H264 is always supported by AVDA.
111 ASSERT_TRUE(Initialize(H264PROFILE_BASELINE)); 123 ASSERT_TRUE(vda_->Initialize(
124 VideoDecodeAccelerator::Config(H264PROFILE_BASELINE), &client_));
125 }
126
127 TEST_F(AndroidVideoDecodeAcceleratorTest, FailingToCreateACodecIsAnError) {
128 EXPECT_CALL(codec_allocator_, CreateMediaCodecAsync(_, _))
129 .WillOnce(PostNullCodec());
130 EXPECT_CALL(client_, NotifyInitializationComplete(false));
131
132 VideoDecodeAccelerator::Config config(H264PROFILE_BASELINE);
133 config.is_deferred_initialization_allowed = true;
134 vda_->Initialize(config, &client_);
135 base::RunLoop().RunUntilIdle();
136 }
137
138 TEST_F(AndroidVideoDecodeAcceleratorTest, NoCodecsAreCreatedDuringDestruction) {
139 // Assert that there's only one call to CreateMediaCodecAsync. And since it
140 // replies with a null codec, AVDA will be in an error state when it shuts
141 // down.
142 EXPECT_CALL(codec_allocator_, CreateMediaCodecAsync(_, _))
143 .WillOnce(PostNullCodec());
144
145 VideoDecodeAccelerator::Config config(H264PROFILE_BASELINE);
146 config.is_deferred_initialization_allowed = true;
147 vda_->Initialize(config, &client_);
148 base::RunLoop().RunUntilIdle();
112 } 149 }
113 150
114 } // namespace media 151 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/android_video_decode_accelerator.cc ('k') | media/gpu/avda_codec_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698