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

Side by Side Diff: content/renderer/media/video_frame_compositor_unittest.cc

Issue 251733005: Remove dropped frame counting and task posting from VideoFrameCompositor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "cc/layers/video_frame_provider.h" 6 #include "cc/layers/video_frame_provider.h"
8 #include "content/renderer/media/video_frame_compositor.h" 7 #include "content/renderer/media/video_frame_compositor.h"
9 #include "media/base/video_frame.h" 8 #include "media/base/video_frame.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 namespace content { 11 namespace content {
13 12
14 using media::VideoFrame; 13 using media::VideoFrame;
15 14
16 class VideoFrameCompositorTest : public testing::Test, 15 class VideoFrameCompositorTest : public testing::Test,
17 public cc::VideoFrameProvider::Client { 16 public cc::VideoFrameProvider::Client {
18 public: 17 public:
19 VideoFrameCompositorTest() 18 VideoFrameCompositorTest()
20 : compositor_(new VideoFrameCompositor( 19 : compositor_(new VideoFrameCompositor(
21 message_loop_.message_loop_proxy(),
22 base::Bind(&VideoFrameCompositorTest::NaturalSizeChanged, 20 base::Bind(&VideoFrameCompositorTest::NaturalSizeChanged,
23 base::Unretained(this)), 21 base::Unretained(this)),
24 base::Bind(&VideoFrameCompositorTest::OpacityChanged, 22 base::Bind(&VideoFrameCompositorTest::OpacityChanged,
25 base::Unretained(this)))), 23 base::Unretained(this)))),
26 did_receive_frame_count_(0), 24 did_receive_frame_count_(0),
27 natural_size_changed_count_(0), 25 natural_size_changed_count_(0),
28 opacity_changed_count_(0), 26 opacity_changed_count_(0),
29 opaque_(false) { 27 opaque_(false) {
30 provider()->SetVideoFrameProviderClient(this); 28 compositor_->SetVideoFrameProviderClient(this);
31 } 29 }
32 30
33 virtual ~VideoFrameCompositorTest() { 31 virtual ~VideoFrameCompositorTest() {
34 provider()->SetVideoFrameProviderClient(NULL); 32 compositor_->SetVideoFrameProviderClient(NULL);
35 compositor_.reset();
36 message_loop_.RunUntilIdle();
37 } 33 }
38 34
39 base::MessageLoop* message_loop() { return &message_loop_; }
40 VideoFrameCompositor* compositor() { return compositor_.get(); } 35 VideoFrameCompositor* compositor() { return compositor_.get(); }
41 cc::VideoFrameProvider* provider() {
42 return compositor_->GetVideoFrameProvider();
43 }
44 int did_receive_frame_count() { return did_receive_frame_count_; } 36 int did_receive_frame_count() { return did_receive_frame_count_; }
45 int natural_size_changed_count() { return natural_size_changed_count_; } 37 int natural_size_changed_count() { return natural_size_changed_count_; }
46 gfx::Size natural_size() { return natural_size_; } 38 gfx::Size natural_size() { return natural_size_; }
47 39
48 int opacity_changed_count() { return opacity_changed_count_; } 40 int opacity_changed_count() { return opacity_changed_count_; }
49 bool opaque() { return opaque_; } 41 bool opaque() { return opaque_; }
50 42
51 private: 43 private:
52 // cc::VideoFrameProvider::Client implementation. 44 // cc::VideoFrameProvider::Client implementation.
53 virtual void StopUsingProvider() OVERRIDE {} 45 virtual void StopUsingProvider() OVERRIDE {}
54 virtual void DidReceiveFrame() OVERRIDE { 46 virtual void DidReceiveFrame() OVERRIDE {
55 ++did_receive_frame_count_; 47 ++did_receive_frame_count_;
56 } 48 }
57 virtual void DidUpdateMatrix(const float* matrix) OVERRIDE {} 49 virtual void DidUpdateMatrix(const float* matrix) OVERRIDE {}
58 50
59 void NaturalSizeChanged(gfx::Size natural_size) { 51 void NaturalSizeChanged(gfx::Size natural_size) {
60 ++natural_size_changed_count_; 52 ++natural_size_changed_count_;
61 natural_size_ = natural_size; 53 natural_size_ = natural_size;
62 } 54 }
63 55
64 void OpacityChanged(bool opaque) { 56 void OpacityChanged(bool opaque) {
65 ++opacity_changed_count_; 57 ++opacity_changed_count_;
66 opaque_ = opaque; 58 opaque_ = opaque;
67 } 59 }
68 60
69 base::MessageLoop message_loop_;
70 scoped_ptr<VideoFrameCompositor> compositor_; 61 scoped_ptr<VideoFrameCompositor> compositor_;
71 int did_receive_frame_count_; 62 int did_receive_frame_count_;
72 int natural_size_changed_count_; 63 int natural_size_changed_count_;
73 gfx::Size natural_size_; 64 gfx::Size natural_size_;
74 int opacity_changed_count_; 65 int opacity_changed_count_;
75 bool opaque_; 66 bool opaque_;
76 67
77 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest); 68 DISALLOW_COPY_AND_ASSIGN(VideoFrameCompositorTest);
78 }; 69 };
79 70
80 TEST_F(VideoFrameCompositorTest, InitialValues) { 71 TEST_F(VideoFrameCompositorTest, InitialValues) {
81 EXPECT_TRUE(compositor()->GetVideoFrameProvider());
82 EXPECT_FALSE(compositor()->GetCurrentFrame()); 72 EXPECT_FALSE(compositor()->GetCurrentFrame());
83 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified());
84 } 73 }
85 74
86 TEST_F(VideoFrameCompositorTest, UpdateCurrentFrame) { 75 TEST_F(VideoFrameCompositorTest, UpdateCurrentFrame) {
87 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame(); 76 scoped_refptr<VideoFrame> expected = VideoFrame::CreateEOSFrame();
88 77
78 // Should notify compositor synchronously.
79 EXPECT_EQ(0, did_receive_frame_count());
89 compositor()->UpdateCurrentFrame(expected); 80 compositor()->UpdateCurrentFrame(expected);
90 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame(); 81 scoped_refptr<VideoFrame> actual = compositor()->GetCurrentFrame();
91 EXPECT_EQ(expected, actual); 82 EXPECT_EQ(expected, actual);
92
93 // Should notify compositor asynchronously.
94 EXPECT_EQ(0, did_receive_frame_count());
95 message_loop()->RunUntilIdle();
96 EXPECT_EQ(1, did_receive_frame_count()); 83 EXPECT_EQ(1, did_receive_frame_count());
97 } 84 }
98 85
99 TEST_F(VideoFrameCompositorTest, NaturalSizeChanged) { 86 TEST_F(VideoFrameCompositorTest, NaturalSizeChanged) {
100 gfx::Size initial_size(8, 8); 87 gfx::Size initial_size(8, 8);
101 scoped_refptr<VideoFrame> initial_frame = 88 scoped_refptr<VideoFrame> initial_frame =
102 VideoFrame::CreateBlackFrame(initial_size); 89 VideoFrame::CreateBlackFrame(initial_size);
103 90
104 gfx::Size larger_size(16, 16); 91 gfx::Size larger_size(16, 16);
105 scoped_refptr<VideoFrame> larger_frame = 92 scoped_refptr<VideoFrame> larger_frame =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 compositor()->UpdateCurrentFrame(opaque_frame); 152 compositor()->UpdateCurrentFrame(opaque_frame);
166 EXPECT_TRUE(opaque()); 153 EXPECT_TRUE(opaque());
167 EXPECT_EQ(2, opacity_changed_count()); 154 EXPECT_EQ(2, opacity_changed_count());
168 155
169 // Callback shouldn't be first subsequent times with same opaqueness. 156 // Callback shouldn't be first subsequent times with same opaqueness.
170 compositor()->UpdateCurrentFrame(opaque_frame); 157 compositor()->UpdateCurrentFrame(opaque_frame);
171 EXPECT_TRUE(opaque()); 158 EXPECT_TRUE(opaque());
172 EXPECT_EQ(2, opacity_changed_count()); 159 EXPECT_EQ(2, opacity_changed_count());
173 } 160 }
174 161
175 TEST_F(VideoFrameCompositorTest, GetFramesDroppedBeforeCompositorWasNotified) {
176 scoped_refptr<VideoFrame> frame = VideoFrame::CreateEOSFrame();
177
178 compositor()->UpdateCurrentFrame(frame);
179 EXPECT_EQ(0, did_receive_frame_count());
180 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified());
181
182 // Should not increment if we finished notifying the compositor.
183 //
184 // This covers the normal scenario where the compositor is getting
185 // notifications in a timely manner.
186 message_loop()->RunUntilIdle();
187 compositor()->UpdateCurrentFrame(frame);
188 EXPECT_EQ(1, did_receive_frame_count());
189 EXPECT_EQ(0u, compositor()->GetFramesDroppedBeforeCompositorWasNotified());
190
191 // Should increment if we didn't notify the compositor.
192 //
193 // This covers the scenario where the compositor is falling behind.
194 // Consider it dropped.
195 message_loop()->RunUntilIdle();
196 compositor()->UpdateCurrentFrame(frame);
197 compositor()->UpdateCurrentFrame(frame);
198 EXPECT_EQ(2, did_receive_frame_count());
199 EXPECT_EQ(1u, compositor()->GetFramesDroppedBeforeCompositorWasNotified());
200
201 // Shouldn't overflow.
202 compositor()->SetFramesDroppedBeforeCompositorWasNotifiedForTesting(
203 kuint32max);
204 compositor()->UpdateCurrentFrame(frame);
205 EXPECT_EQ(kuint32max,
206 compositor()->GetFramesDroppedBeforeCompositorWasNotified());
207 }
208
209 } // namespace content 162 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698