| OLD | NEW | 
|---|
| 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  Loading... | 
| 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 |  | 
| 179   bool DumpSample(const std::string& filename, const void* buffer, int size) { | 166   bool DumpSample(const std::string& filename, const void* buffer, int size) { | 
| 180     rtc::Pathname path(filename); | 167     rtc::Pathname path(filename); | 
| 181     rtc::scoped_ptr<rtc::FileStream> fs( | 168     rtc::scoped_ptr<rtc::FileStream> fs( | 
| 182         rtc::Filesystem::OpenFile(path, "wb")); | 169         rtc::Filesystem::OpenFile(path, "wb")); | 
| 183     if (!fs.get()) { | 170     if (!fs.get()) { | 
| 184       return false; | 171       return false; | 
| 185     } | 172     } | 
| 186 | 173 | 
| 187     return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS); | 174     return (fs->Write(buffer, size, NULL, NULL) == rtc::SR_SUCCESS); | 
| 188   } | 175   } | 
| (...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1824     rtc::scoped_ptr<cricket::VideoFrame> target; | 1811     rtc::scoped_ptr<cricket::VideoFrame> target; | 
| 1825     ASSERT_TRUE(LoadFrameNoRepeat(source.get())); | 1812     ASSERT_TRUE(LoadFrameNoRepeat(source.get())); | 
| 1826     target.reset(source->Copy()); | 1813     target.reset(source->Copy()); | 
| 1827     EXPECT_TRUE(target->MakeExclusive()); | 1814     EXPECT_TRUE(target->MakeExclusive()); | 
| 1828     EXPECT_TRUE(IsEqual(*source, *target, 0)); | 1815     EXPECT_TRUE(IsEqual(*source, *target, 0)); | 
| 1829     EXPECT_NE(target->GetYPlane(), source->GetYPlane()); | 1816     EXPECT_NE(target->GetYPlane(), source->GetYPlane()); | 
| 1830     EXPECT_NE(target->GetUPlane(), source->GetUPlane()); | 1817     EXPECT_NE(target->GetUPlane(), source->GetUPlane()); | 
| 1831     EXPECT_NE(target->GetVPlane(), source->GetVPlane()); | 1818     EXPECT_NE(target->GetVPlane(), source->GetVPlane()); | 
| 1832   } | 1819   } | 
| 1833 | 1820 | 
| 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 |  | 
| 1849   void CopyToFrame() { | 1821   void CopyToFrame() { | 
| 1850     T source; | 1822     T source; | 
| 1851     rtc::scoped_ptr<rtc::MemoryStream> ms( | 1823     rtc::scoped_ptr<rtc::MemoryStream> ms( | 
| 1852         LoadSample(kImageFilename)); | 1824         LoadSample(kImageFilename)); | 
| 1853     ASSERT_TRUE(ms.get() != NULL); | 1825     ASSERT_TRUE(ms.get() != NULL); | 
| 1854     ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, | 1826     ASSERT_TRUE(LoadFrame(ms.get(), cricket::FOURCC_I420, kWidth, kHeight, | 
| 1855                           &source)); | 1827                           &source)); | 
| 1856 | 1828 | 
| 1857     // Create the target frame by loading from a file. | 1829     // Create the target frame by loading from a file. | 
| 1858     T target; | 1830     T target; | 
| 1859     ASSERT_TRUE(LoadFrameNoRepeat(&target)); | 1831     ASSERT_TRUE(LoadFrameNoRepeat(&target)); | 
| 1860     EXPECT_FALSE(IsBlack(target)); | 1832     EXPECT_FALSE(IsBlack(target)); | 
| 1861 | 1833 | 
| 1862     // Stretch and check if the stretched target is black. | 1834     // Stretch and check if the stretched target is black. | 
| 1863     source.CopyToFrame(&target); | 1835     source.CopyToFrame(&target); | 
| 1864 | 1836 | 
| 1865     EXPECT_TRUE(IsEqual(source, target, 0)); | 1837     EXPECT_TRUE(IsEqual(source, target, 0)); | 
| 1866   } | 1838   } | 
| 1867 | 1839 | 
| 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 |  | 
| 1906   void StretchToFrame() { | 1840   void StretchToFrame() { | 
| 1907     // Create the source frame as a black frame. | 1841     // Create the source frame as a black frame. | 
| 1908     T source; | 1842     T source; | 
| 1909     EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0)); | 1843     EXPECT_TRUE(source.InitToBlack(kWidth * 2, kHeight * 2, 0)); | 
| 1910     EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); | 1844     EXPECT_TRUE(IsSize(source, kWidth * 2, kHeight * 2)); | 
| 1911 | 1845 | 
| 1912     // Create the target frame by loading from a file. | 1846     // Create the target frame by loading from a file. | 
| 1913     T target1; | 1847     T target1; | 
| 1914     ASSERT_TRUE(LoadFrameNoRepeat(&target1)); | 1848     ASSERT_TRUE(LoadFrameNoRepeat(&target1)); | 
| 1915     EXPECT_FALSE(IsBlack(target1)); | 1849     EXPECT_FALSE(IsBlack(target1)); | 
| 1916 | 1850 | 
| 1917     // Stretch and check if the stretched target is black. | 1851     // Stretch and check if the stretched target is black. | 
| 1918     source.StretchToFrame(&target1, true, false); | 1852     source.StretchToFrame(&target1, true, false); | 
| 1919     EXPECT_TRUE(IsBlack(target1)); | 1853     EXPECT_TRUE(IsBlack(target1)); | 
| 1920 | 1854 | 
| 1921     // Crop and stretch and check if the stretched target is black. | 1855     // Crop and stretch and check if the stretched target is black. | 
| 1922     T target2; | 1856     T target2; | 
| 1923     ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 1857     ASSERT_TRUE(LoadFrameNoRepeat(&target2)); | 
| 1924     source.StretchToFrame(&target2, true, true); | 1858     source.StretchToFrame(&target2, true, true); | 
| 1925     EXPECT_TRUE(IsBlack(target2)); | 1859     EXPECT_TRUE(IsBlack(target2)); | 
| 1926     EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 1860     EXPECT_EQ(source.GetTimeStamp(), target2.GetTimeStamp()); | 
| 1927   } | 1861   } | 
| 1928 | 1862 | 
| 1929   int repeat_; | 1863   int repeat_; | 
| 1930 }; | 1864 }; | 
| 1931 | 1865 | 
| 1932 #endif  // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 1866 #endif  // WEBRTC_MEDIA_BASE_VIDEOFRAME_UNITTEST_H_ | 
| OLD | NEW | 
|---|