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

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

Issue 2150203002: Apply rotation for texture backed VideoFrames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "content/public/renderer/media_stream_renderer_factory.h" 8 #include "content/public/renderer/media_stream_renderer_factory.h"
9 #include "content/renderer/media/webmediaplayer_ms.h" 9 #include "content/renderer/media/webmediaplayer_ms.h"
10 #include "content/renderer/media/webmediaplayer_ms_compositor.h" 10 #include "content/renderer/media/webmediaplayer_ms_compositor.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Implementation of MediaStreamVideoRenderer 130 // Implementation of MediaStreamVideoRenderer
131 void Start() override; 131 void Start() override;
132 void Stop() override; 132 void Stop() override;
133 void Resume() override; 133 void Resume() override;
134 void Pause() override; 134 void Pause() override;
135 135
136 // Methods for test use 136 // Methods for test use
137 void QueueFrames(const std::vector<int>& timestamps_or_frame_type, 137 void QueueFrames(const std::vector<int>& timestamps_or_frame_type,
138 bool opaque_frame = true, 138 bool opaque_frame = true,
139 bool odd_size_frame = false, 139 bool odd_size_frame = false,
140 int double_size_index = -1); 140 int double_size_index = -1,
141 media::VideoRotation rotation = media::VIDEO_ROTATION_0);
141 bool Started() { return started_; } 142 bool Started() { return started_; }
142 bool Paused() { return paused_; } 143 bool Paused() { return paused_; }
143 144
144 private: 145 private:
145 ~MockMediaStreamVideoRenderer() override {} 146 ~MockMediaStreamVideoRenderer() override {}
146 147
147 // Main function that pushes a frame into WebMediaPlayerMS 148 // Main function that pushes a frame into WebMediaPlayerMS
148 void InjectFrame(); 149 void InjectFrame();
149 150
150 // Methods for test use 151 // Methods for test use
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void MockMediaStreamVideoRenderer::AddFrame( 191 void MockMediaStreamVideoRenderer::AddFrame(
191 FrameType category, 192 FrameType category,
192 const scoped_refptr<media::VideoFrame>& frame) { 193 const scoped_refptr<media::VideoFrame>& frame) {
193 frames_.push_back(std::make_pair(category, frame)); 194 frames_.push_back(std::make_pair(category, frame));
194 } 195 }
195 196
196 void MockMediaStreamVideoRenderer::QueueFrames( 197 void MockMediaStreamVideoRenderer::QueueFrames(
197 const std::vector<int>& timestamp_or_frame_type, 198 const std::vector<int>& timestamp_or_frame_type,
198 bool opaque_frame, 199 bool opaque_frame,
199 bool odd_size_frame, 200 bool odd_size_frame,
200 int double_size_index) { 201 int double_size_index,
202 media::VideoRotation rotation) {
201 gfx::Size standard_size = gfx::Size(kStandardWidth, kStandardHeight); 203 gfx::Size standard_size = gfx::Size(kStandardWidth, kStandardHeight);
202 for (size_t i = 0; i < timestamp_or_frame_type.size(); i++) { 204 for (size_t i = 0; i < timestamp_or_frame_type.size(); i++) {
203 const int token = timestamp_or_frame_type[i]; 205 const int token = timestamp_or_frame_type[i];
204 if (static_cast<int>(i) == double_size_index) { 206 if (static_cast<int>(i) == double_size_index) {
205 standard_size = gfx::Size(kStandardWidth * 2, kStandardHeight * 2); 207 standard_size = gfx::Size(kStandardWidth * 2, kStandardHeight * 2);
206 } 208 }
207 if (token < static_cast<int>(FrameType::MIN_TYPE)) { 209 if (token < static_cast<int>(FrameType::MIN_TYPE)) {
208 CHECK(false) << "Unrecognized frame type: " << token; 210 CHECK(false) << "Unrecognized frame type: " << token;
209 return; 211 return;
210 } 212 }
211 213
212 if (token < 0) { 214 if (token < 0) {
213 AddFrame(static_cast<FrameType>(token), nullptr); 215 AddFrame(static_cast<FrameType>(token), nullptr);
214 continue; 216 continue;
215 } 217 }
216 218
217 if (token >= 0) { 219 if (token >= 0) {
218 gfx::Size frame_size; 220 gfx::Size frame_size;
219 if (odd_size_frame) { 221 if (odd_size_frame) {
220 frame_size.SetSize(standard_size.width() - kOddSizeOffset, 222 frame_size.SetSize(standard_size.width() - kOddSizeOffset,
221 standard_size.height() - kOddSizeOffset); 223 standard_size.height() - kOddSizeOffset);
222 } else { 224 } else {
223 frame_size.SetSize(standard_size.width(), standard_size.height()); 225 frame_size.SetSize(standard_size.width(), standard_size.height());
224 } 226 }
227
225 auto frame = media::VideoFrame::CreateZeroInitializedFrame( 228 auto frame = media::VideoFrame::CreateZeroInitializedFrame(
226 opaque_frame ? media::PIXEL_FORMAT_YV12 : media::PIXEL_FORMAT_YV12A, 229 opaque_frame ? media::PIXEL_FORMAT_YV12 : media::PIXEL_FORMAT_YV12A,
227 frame_size, gfx::Rect(frame_size), frame_size, 230 frame_size, gfx::Rect(frame_size), frame_size,
228 base::TimeDelta::FromMilliseconds(token)); 231 base::TimeDelta::FromMilliseconds(token));
229 232
233 frame->metadata()->SetRotation(media::VideoFrameMetadata::ROTATION,
234 rotation);
230 frame->metadata()->SetTimeTicks( 235 frame->metadata()->SetTimeTicks(
231 media::VideoFrameMetadata::Key::REFERENCE_TIME, 236 media::VideoFrameMetadata::Key::REFERENCE_TIME,
232 base::TimeTicks::Now() + base::TimeDelta::FromMilliseconds(token)); 237 base::TimeTicks::Now() + base::TimeDelta::FromMilliseconds(token));
233 238
234 AddFrame(FrameType::NORMAL_FRAME, frame); 239 AddFrame(FrameType::NORMAL_FRAME, frame);
235 continue; 240 continue;
236 } 241 }
237 } 242 }
238 } 243 }
239 244
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 EXPECT_CALL(*this, DoSetWebLayer(true)); 573 EXPECT_CALL(*this, DoSetWebLayer(true));
569 EXPECT_CALL(*this, DoStartRendering()); 574 EXPECT_CALL(*this, DoStartRendering());
570 EXPECT_CALL(*this, DoReadyStateChanged( 575 EXPECT_CALL(*this, DoReadyStateChanged(
571 blink::WebMediaPlayer::ReadyStateHaveMetadata)); 576 blink::WebMediaPlayer::ReadyStateHaveMetadata));
572 EXPECT_CALL(*this, DoReadyStateChanged( 577 EXPECT_CALL(*this, DoReadyStateChanged(
573 blink::WebMediaPlayer::ReadyStateHaveEnoughData)); 578 blink::WebMediaPlayer::ReadyStateHaveEnoughData));
574 EXPECT_CALL(*this, 579 EXPECT_CALL(*this,
575 CheckSizeChanged(gfx::Size(kStandardWidth, kStandardHeight))); 580 CheckSizeChanged(gfx::Size(kStandardWidth, kStandardHeight)));
576 message_loop_controller_.RunAndWaitForStatus( 581 message_loop_controller_.RunAndWaitForStatus(
577 media::PipelineStatus::PIPELINE_OK); 582 media::PipelineStatus::PIPELINE_OK);
583 const blink::WebSize& natural_size = player_->naturalSize();
584 EXPECT_EQ(kStandardWidth, natural_size.width);
585 EXPECT_EQ(kStandardHeight, natural_size.height);
578 testing::Mock::VerifyAndClearExpectations(this); 586 testing::Mock::VerifyAndClearExpectations(this);
579 587
580 EXPECT_CALL(*this, DoSetWebLayer(false)); 588 EXPECT_CALL(*this, DoSetWebLayer(false));
581 EXPECT_CALL(*this, DoStopRendering()); 589 EXPECT_CALL(*this, DoStopRendering());
582 } 590 }
583 591
584 TEST_F(WebMediaPlayerMSTest, Playing_ErrorFrame) { 592 TEST_F(WebMediaPlayerMSTest, Playing_ErrorFrame) {
585 // This tests sends a broken frame to WebMediaPlayerMS, and verifies 593 // This tests sends a broken frame to WebMediaPlayerMS, and verifies
586 // OnSourceError function works as expected. 594 // OnSourceError function works as expected.
587 595
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 710
703 EXPECT_CALL(*this, DoSetWebLayer(false)); 711 EXPECT_CALL(*this, DoSetWebLayer(false));
704 EXPECT_CALL(*this, DoStopRendering()); 712 EXPECT_CALL(*this, DoStopRendering());
705 } 713 }
706 714
707 INSTANTIATE_TEST_CASE_P(, 715 INSTANTIATE_TEST_CASE_P(,
708 WebMediaPlayerMSTest, 716 WebMediaPlayerMSTest,
709 ::testing::Combine(::testing::Bool(), 717 ::testing::Combine(::testing::Bool(),
710 ::testing::Bool())); 718 ::testing::Bool()));
711 719
720 TEST_F(WebMediaPlayerMSTest, RotatedVideoFrame) {
721 // During this test, we check that when we send rotated video frames, it
722 // applies to player's natural size.
mcasas 2016/07/15 01:57:34 nit: This is a TEST comment, move it to l.719
emircan 2016/07/15 18:43:13 Done.
723 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true);
724
725 int tokens[] = {0, 33, 66};
726 std::vector<int> timestamps(tokens, tokens + sizeof(tokens) / sizeof(int));
mcasas 2016/07/15 01:57:34 If |tokens| is constant, make it static int kToke
emircan 2016/07/15 18:43:13 Done.
727 provider->QueueFrames(timestamps, false, false, 17, media::VIDEO_ROTATION_90);
728
729 EXPECT_CALL(*this, DoSetWebLayer(true));
730 EXPECT_CALL(*this, DoStartRendering());
731 EXPECT_CALL(*this, DoReadyStateChanged(
732 blink::WebMediaPlayer::ReadyStateHaveMetadata));
733 EXPECT_CALL(*this, DoReadyStateChanged(
734 blink::WebMediaPlayer::ReadyStateHaveEnoughData));
735 EXPECT_CALL(*this,
736 CheckSizeChanged(gfx::Size(kStandardWidth, kStandardHeight)));
737 message_loop_controller_.RunAndWaitForStatus(
738 media::PipelineStatus::PIPELINE_OK);
739 const blink::WebSize& natural_size = player_->naturalSize();
740 // Check that height and width are flipped.
741 EXPECT_EQ(kStandardHeight, natural_size.width);
742 EXPECT_EQ(kStandardWidth, natural_size.height);
743 testing::Mock::VerifyAndClearExpectations(this);
744
745 EXPECT_CALL(*this, DoSetWebLayer(false));
746 EXPECT_CALL(*this, DoStopRendering());
747 }
748
712 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) { 749 TEST_F(WebMediaPlayerMSTest, BackgroundRendering) {
713 // During this test, we will switch to background rendering mode, in which 750 // During this test, we will switch to background rendering mode, in which
714 // WebMediaPlayerMS::pause does not get called, but 751 // WebMediaPlayerMS::pause does not get called, but
715 // cc::VideoFrameProviderClient simply stops asking frames from 752 // cc::VideoFrameProviderClient simply stops asking frames from
716 // WebMediaPlayerMS without an explicit notification. We should expect that 753 // WebMediaPlayerMS without an explicit notification. We should expect that
717 // WebMediaPlayerMS can digest old frames, rather than piling frames up and 754 // WebMediaPlayerMS can digest old frames, rather than piling frames up and
718 // explode. 755 // explode.
719 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true); 756 MockMediaStreamVideoRenderer* provider = LoadAndGetFrameProvider(true);
720 757
721 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE); 758 const int kTestBrake = static_cast<int>(FrameType::TEST_BRAKE);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // OnShown() should restart after a forced suspension. 869 // OnShown() should restart after a forced suspension.
833 player_->OnShown(); 870 player_->OnShown();
834 EXPECT_FALSE(player_->paused()); 871 EXPECT_FALSE(player_->paused());
835 EXPECT_CALL(*this, DoSetWebLayer(false)); 872 EXPECT_CALL(*this, DoSetWebLayer(false));
836 873
837 message_loop_.RunUntilIdle(); 874 message_loop_.RunUntilIdle();
838 } 875 }
839 #endif 876 #endif
840 877
841 } // namespace content 878 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698