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

Side by Side Diff: talk/media/webrtc/webrtcvideoframefactory_unittest.cc

Issue 1587193006: Move talk/media to webrtc/media (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased to b647aca12a884a13c1728118586245399b55fa3d (#11493) Created 4 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 | « talk/media/webrtc/webrtcvideoframefactory.cc ('k') | talk/media/webrtc/webrtcvoe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <string.h>
29
30 #include "talk/media/base/videoframe_unittest.h"
31 #include "talk/media/webrtc/webrtcvideoframe.h"
32 #include "talk/media/webrtc/webrtcvideoframefactory.h"
33
34 class WebRtcVideoFrameFactoryTest
35 : public VideoFrameTest<cricket::WebRtcVideoFrameFactory> {
36 public:
37 WebRtcVideoFrameFactoryTest() {}
38
39 void InitFrame(webrtc::VideoRotation frame_rotation) {
40 const int frame_width = 1920;
41 const int frame_height = 1080;
42
43 // Build the CapturedFrame.
44 captured_frame_.fourcc = cricket::FOURCC_I420;
45 captured_frame_.pixel_width = 1;
46 captured_frame_.pixel_height = 1;
47 captured_frame_.time_stamp = 5678;
48 captured_frame_.rotation = frame_rotation;
49 captured_frame_.width = frame_width;
50 captured_frame_.height = frame_height;
51 captured_frame_.data_size =
52 (frame_width * frame_height) +
53 ((frame_width + 1) / 2) * ((frame_height + 1) / 2) * 2;
54 captured_frame_buffer_.reset(new uint8_t[captured_frame_.data_size]);
55 // Initialize memory to satisfy DrMemory tests.
56 memset(captured_frame_buffer_.get(), 0, captured_frame_.data_size);
57 captured_frame_.data = captured_frame_buffer_.get();
58 }
59
60 void VerifyFrame(cricket::VideoFrame* dest_frame,
61 webrtc::VideoRotation src_rotation,
62 int src_width,
63 int src_height,
64 bool apply_rotation) {
65 if (!apply_rotation) {
66 EXPECT_EQ(dest_frame->GetRotation(), src_rotation);
67 EXPECT_EQ(dest_frame->GetWidth(), src_width);
68 EXPECT_EQ(dest_frame->GetHeight(), src_height);
69 } else {
70 EXPECT_EQ(dest_frame->GetRotation(), webrtc::kVideoRotation_0);
71 if (src_rotation == webrtc::kVideoRotation_90 ||
72 src_rotation == webrtc::kVideoRotation_270) {
73 EXPECT_EQ(dest_frame->GetWidth(), src_height);
74 EXPECT_EQ(dest_frame->GetHeight(), src_width);
75 } else {
76 EXPECT_EQ(dest_frame->GetWidth(), src_width);
77 EXPECT_EQ(dest_frame->GetHeight(), src_height);
78 }
79 }
80 }
81
82 void TestCreateAliasedFrame(bool apply_rotation) {
83 cricket::VideoFrameFactory& factory = factory_;
84 factory.SetApplyRotation(apply_rotation);
85 InitFrame(webrtc::kVideoRotation_270);
86 const cricket::CapturedFrame& captured_frame = get_captured_frame();
87 // Create the new frame from the CapturedFrame.
88 rtc::scoped_ptr<cricket::VideoFrame> frame;
89 int new_width = captured_frame.width / 2;
90 int new_height = captured_frame.height / 2;
91 frame.reset(factory.CreateAliasedFrame(&captured_frame, new_width,
92 new_height, new_width, new_height));
93 VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width, new_height,
94 apply_rotation);
95
96 frame.reset(factory.CreateAliasedFrame(
97 &captured_frame, new_width, new_height, new_width / 2, new_height / 2));
98 VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width / 2,
99 new_height / 2, apply_rotation);
100
101 // Reset the frame first so it's exclusive hence we could go through the
102 // StretchToFrame code path in CreateAliasedFrame.
103 frame.reset();
104 frame.reset(factory.CreateAliasedFrame(
105 &captured_frame, new_width, new_height, new_width / 2, new_height / 2));
106 VerifyFrame(frame.get(), webrtc::kVideoRotation_270, new_width / 2,
107 new_height / 2, apply_rotation);
108 }
109
110 const cricket::CapturedFrame& get_captured_frame() { return captured_frame_; }
111
112 private:
113 cricket::CapturedFrame captured_frame_;
114 rtc::scoped_ptr<uint8_t[]> captured_frame_buffer_;
115 cricket::WebRtcVideoFrameFactory factory_;
116 };
117
118 TEST_F(WebRtcVideoFrameFactoryTest, NoApplyRotation) {
119 TestCreateAliasedFrame(false);
120 }
121
122 TEST_F(WebRtcVideoFrameFactoryTest, ApplyRotation) {
123 TestCreateAliasedFrame(true);
124 }
OLDNEW
« no previous file with comments | « talk/media/webrtc/webrtcvideoframefactory.cc ('k') | talk/media/webrtc/webrtcvoe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698