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

Side by Side Diff: webrtc/media/base/videoframe_unittest.h

Issue 1688953003: Revert of Initial cleanup of cricket::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 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 | « webrtc/media/base/videoframe.cc ('k') | webrtc/media/webrtc/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 new rtc::MemoryStream()); 156 new rtc::MemoryStream());
157 rtc::StreamResult res = Flow(fs.get(), buf, sizeof(buf), ms.get()); 157 rtc::StreamResult res = Flow(fs.get(), buf, sizeof(buf), ms.get());
158 if (res != rtc::SR_SUCCESS) { 158 if (res != rtc::SR_SUCCESS) {
159 LOG(LS_ERROR) << "Could not load test file path: " << path.pathname(); 159 LOG(LS_ERROR) << "Could not load test file path: " << path.pathname();
160 return NULL; 160 return NULL;
161 } 161 }
162 162
163 return ms.release(); 163 return ms.release();
164 } 164 }
165 165
166 // Write an I420 frame out to disk.
167 bool DumpFrame(const std::string& prefix,
168 const cricket::VideoFrame& frame) {
169 char filename[256];
170 rtc::sprintfn(filename, sizeof(filename), "%s.%dx%d_P420.yuv",
171 prefix.c_str(), frame.GetWidth(), frame.GetHeight());
172 size_t out_size = cricket::VideoFrame::SizeOf(frame.GetWidth(),
173 frame.GetHeight());
174 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size]);
175 frame.CopyToBuffer(out.get(), out_size);
176 return DumpSample(filename, out.get(), out_size);
177 }
178
166 bool DumpSample(const std::string& filename, const void* buffer, int size) { 179 bool DumpSample(const std::string& filename, const void* buffer, int size) {
167 rtc::Pathname path(filename); 180 rtc::Pathname path(filename);
168 rtc::scoped_ptr<rtc::FileStream> fs( 181 rtc::scoped_ptr<rtc::FileStream> fs(
169 rtc::Filesystem::OpenFile(path, "wb")); 182 rtc::Filesystem::OpenFile(path, "wb"));
170 if (!fs.get()) { 183 if (!fs.get()) {
171 return false; 184 return false;
172 } 185 }
173 186
174 return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS); 187 return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS);
175 } 188 }
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 rtc::scoped_ptr<cricket::VideoFrame> target; 1824 rtc::scoped_ptr<cricket::VideoFrame> target;
1812 ASSERT_TRUE(LoadFrameNoRepeat(source.get())); 1825 ASSERT_TRUE(LoadFrameNoRepeat(source.get()));
1813 target.reset(source->Copy()); 1826 target.reset(source->Copy());
1814 EXPECT_TRUE(target->MakeExclusive()); 1827 EXPECT_TRUE(target->MakeExclusive());
1815 EXPECT_TRUE(IsEqual(*source, *target, 0)); 1828 EXPECT_TRUE(IsEqual(*source, *target, 0));
1816 EXPECT_NE(target->GetYPlane(), source->GetYPlane()); 1829 EXPECT_NE(target->GetYPlane(), source->GetYPlane());
1817 EXPECT_NE(target->GetUPlane(), source->GetUPlane()); 1830 EXPECT_NE(target->GetUPlane(), source->GetUPlane());
1818 EXPECT_NE(target->GetVPlane(), source->GetVPlane()); 1831 EXPECT_NE(target->GetVPlane(), source->GetVPlane());
1819 } 1832 }
1820 1833
1834 void CopyToBuffer() {
1835 T frame;
1836 rtc::scoped_ptr<rtc::MemoryStream> ms(
1837 LoadSample(kImageFilename));
1838 ASSERT_TRUE(ms.get() != NULL);
1839 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight,
1840 &frame));
1841 size_t out_size = kWidth * kHeight * 3 / 2;
1842 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size]);
1843 for (int i = 0; i < repeat_; ++i) {
1844 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size));
1845 }
1846 EXPECT_EQ(0, memcmp(out.get(), ms->GetBuffer(), out_size));
1847 }
1848
1821 void CopyToFrame() { 1849 void CopyToFrame() {
1822 T source; 1850 T source;
1823 rtc::scoped_ptr<rtc::MemoryStream> ms( 1851 rtc::scoped_ptr<rtc::MemoryStream> ms(
1824 LoadSample(kImageFilename)); 1852 LoadSample(kImageFilename));
1825 ASSERT_TRUE(ms.get() != NULL); 1853 ASSERT_TRUE(ms.get() != NULL);
1826 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, 1854 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight,
1827 &source)); 1855 &source));
1828 1856
1829 // Create the target frame by loading from a file. 1857 // Create the target frame by loading from a file.
1830 T target; 1858 T target;
1831 ASSERT_TRUE(LoadFrameNoRepeat(&target)); 1859 ASSERT_TRUE(LoadFrameNoRepeat(&target));
1832 EXPECT_FALSE(IsBlack(target)); 1860 EXPECT_FALSE(IsBlack(target));
1833 1861
1834 // Stretch and check if the stretched target is black. 1862 // Stretch and check if the stretched target is black.
1835 source.CopyToFrame(&target); 1863 source.CopyToFrame(&target);
1836 1864
1837 EXPECT_TRUE(IsEqual(source, target, 0)); 1865 EXPECT_TRUE(IsEqual(source, target, 0));
1838 } 1866 }
1839 1867
1868 void Write() {
1869 T frame;
1870 rtc::scoped_ptr<rtc::MemoryStream> ms(
1871 LoadSample(kImageFilename));
1872 ASSERT_TRUE(ms.get() != NULL);
1873 rtc::MemoryStream ms2;
1874 size_t size;
1875 ASSERT_TRUE(ms->GetSize(&size));
1876 ASSERT_TRUE(ms2.ReserveSize(size));
1877 ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight,
1878 &frame));
1879 for (int i = 0; i < repeat_; ++i) {
1880 ms2.SetPosition(0u); // Useful when repeat_ > 1.
1881 int error;
1882 EXPECT_EQ(rtc::SR_SUCCESS, frame.Write(&ms2, &error));
1883 }
1884 size_t out_size = cricket::VideoFrame::SizeOf(kWidth, kHeight);
1885 EXPECT_EQ(0, memcmp(ms2.GetBuffer(), ms->GetBuffer(), out_size));
1886 }
1887
1888 void CopyToBuffer1Pixel() {
1889 size_t out_size = 3;
1890 rtc::scoped_ptr<uint8_t[]> out(new uint8_t[out_size + 1]);
1891 memset(out.get(), 0xfb, out_size + 1); // Fill buffer
1892 uint8_t pixel[3] = {1, 2, 3};
1893 T frame;
1894 EXPECT_TRUE(frame.Init(cricket::FOURCC_I420, 1, 1, 1, 1, pixel,
1895 sizeof(pixel), 0,
1896 webrtc::kVideoRotation_0));
1897 for (int i = 0; i < repeat_; ++i) {
1898 EXPECT_EQ(out_size, frame.CopyToBuffer(out.get(), out_size));
1899 }
1900 EXPECT_EQ(1, out.get()[0]); // Check Y. Should be 1.
1901 EXPECT_EQ(2, out.get()[1]); // Check U. Should be 2.
1902 EXPECT_EQ(3, out.get()[2]); // Check V. Should be 3.
1903 EXPECT_EQ(0xfb, out.get()[3]); // Check sentinel is still intact.
1904 }
1905
1840 void StretchToFrame() { 1906 void StretchToFrame() {
1841 // Create the source frame as a black frame. 1907 // Create the source frame as a black frame.
1842 T source; 1908 T source;
1843 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0)); 1909 EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0));
1844 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); 1910 EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2));
1845 1911
1846 // Create the target frame by loading from a file. 1912 // Create the target frame by loading from a file.
1847 T target1; 1913 T target1;
1848 ASSERT_TRUE(LoadFrameNoRepeat(&target1)); 1914 ASSERT_TRUE(LoadFrameNoRepeat(&target1));
1849 EXPECT_FALSE(IsBlack(target1)); 1915 EXPECT_FALSE(IsBlack(target1));
1850 1916
1851 // Stretch and check if the stretched target is black. 1917 // Stretch and check if the stretched target is black.
1852 source.StretchToFrame(&target1, true, false); 1918 source.StretchToFrame(&target1, true, false);
1853 EXPECT_TRUE(IsBlack(target1)); 1919 EXPECT_TRUE(IsBlack(target1));
1854 1920
1855 // Crop and stretch and check if the stretched target is black. 1921 // Crop and stretch and check if the stretched target is black.
1856 T target2; 1922 T target2;
1857 ASSERT_TRUE(LoadFrameNoRepeat(&target2)); 1923 ASSERT_TRUE(LoadFrameNoRepeat(&target2));
1858 source.StretchToFrame(&target2, true, true); 1924 source.StretchToFrame(&target2, true, true);
1859 EXPECT_TRUE(IsBlack(target2)); 1925 EXPECT_TRUE(IsBlack(target2));
1860 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); 1926 EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp());
1861 } 1927 }
1862 1928
1863 int repeat_; 1929 int repeat_;
1864 }; 1930 };
1865 1931
1866 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ 1932 #endif // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_
OLDNEW
« no previous file with comments | « webrtc/media/base/videoframe.cc ('k') | webrtc/media/webrtc/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698