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

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_capturer_adapter_unittest.cc

Issue 183113004: Make sure MediaStreamVideoSource support cropping. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implement cropping using media::VideoFrame::view_rect() Created 6 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
8 #include "media/base/video_frame.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace content {
12
13 class WebRtcVideoCapturerAdapterTest
14 : public sigslot::has_slots<>,
15 public ::testing::Test {
16 public:
17 WebRtcVideoCapturerAdapterTest()
18 :adapter_(false),
19 captured_frame_(NULL) {
20 adapter_.SignalFrameCaptured.connect(
21 this, &WebRtcVideoCapturerAdapterTest::OnFrameCaptured);
22 }
23 virtual ~WebRtcVideoCapturerAdapterTest() {}
24
25 void TestSourceCropFrame(int capture_w,
26 int capture_h,
27 int extpected_w,
28 int expected_h) {
29 const int visible_width = std::min(capture_w, extpected_w);
30 const int horiz_crop = ((capture_w - visible_width) / 2) & ~1;
31 const int visible_height = std::min(capture_h, expected_h);
32 const int vert_crop = ((expected_h - visible_height) / 2) & ~1;
33
34 gfx::Size coded_size(capture_w, capture_h);
35 gfx::Rect view_rect(horiz_crop, vert_crop, visible_width, visible_height);
36 scoped_refptr<media::VideoFrame> frame =
37 media::VideoFrame::CreateFrame(media::VideoFrame::I420,
38 coded_size, view_rect, coded_size,
39 base::TimeDelta());
40 adapter_.OnFrameCaptured(frame);
41 ASSERT_TRUE(captured_frame_ != NULL);
42 EXPECT_EQ(extpected_w, captured_frame_->width);
43 EXPECT_EQ(expected_h, captured_frame_->height);
44 }
45 protected:
46 void OnFrameCaptured(cricket::VideoCapturer* capturer,
47 const cricket::CapturedFrame* frame) {
48 captured_frame_ = frame;
49 }
50
51 private:
52 WebRtcVideoCapturerAdapter adapter_;
53 const cricket::CapturedFrame* captured_frame_;
54 };
55
56 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) {
57 TestSourceCropFrame(640, 480, 640, 360);
58 }
59
60 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo732489) {
61 TestSourceCropFrame(1280, 720, 731, 489);
62 }
63
64 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698