OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <inttypes.h> | 5 #include <inttypes.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1754 header.frame_size = static_cast<uint32_t>(frame_size); | 1754 header.frame_size = static_cast<uint32_t>(frame_size); |
1755 header.timestamp = frame_index; | 1755 header.timestamp = frame_index; |
1756 header.ByteSwap(); | 1756 header.ByteSwap(); |
1757 EXPECT_TRUE(base::AppendToFile( | 1757 EXPECT_TRUE(base::AppendToFile( |
1758 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1758 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
1759 reinterpret_cast<char*>(&header), sizeof(header))); | 1759 reinterpret_cast<char*>(&header), sizeof(header))); |
1760 } | 1760 } |
1761 | 1761 |
1762 // This client is only used to make sure the encoder does not return an encoded | 1762 // This client is only used to make sure the encoder does not return an encoded |
1763 // frame before getting any input. | 1763 // frame before getting any input. |
1764 class VEANoInputClient : public VideoEncodeAccelerator::Client { | 1764 class VEANoInputClient : public VideoEncodeAccelerator::Client { |
wuchengli
2016/11/23 14:43:33
There are some boilerplate code in every VEAXxxCli
hywu1
2016/11/24 06:01:29
Done.
| |
1765 public: | |
Owen Lin
2016/11/24 03:00:52
Did you change the code here on purpose?
I think
hywu1
2016/11/24 06:01:29
Done.
| |
1766 explicit VEANoInputClient(ClientStateNotification<ClientState>* note); | |
1767 ~VEANoInputClient() override; | |
1768 void CreateEncoder(); | |
1769 void DestroyEncoder(); | |
1770 | |
1771 // VideoDecodeAccelerator::Client implementation. | |
1772 void RequireBitstreamBuffers(unsigned int input_count, | |
1773 const gfx::Size& input_coded_size, | |
1774 size_t output_buffer_size) override; | |
1775 void BitstreamBufferReady(int32_t bitstream_buffer_id, | |
1776 size_t payload_size, | |
1777 bool key_frame, | |
1778 base::TimeDelta timestamp) override; | |
1779 void NotifyError(VideoEncodeAccelerator::Error error) override; | |
1780 | |
1781 private: | |
1782 bool has_encoder() { return encoder_.get(); } | |
1783 | |
1784 void SetState(ClientState new_state); | |
1785 | |
1786 // Provide the encoder with a new output buffer. | |
1787 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); | |
1788 | |
1789 std::unique_ptr<VideoEncodeAccelerator> encoder_; | |
1790 | |
1791 // Used to notify another thread about the state. VEAClient does not own thi s. | |
wuchengli
2016/11/23 14:43:33
Please run git cl format to check the style.
hywu1
2016/11/24 06:01:29
Done.
| |
1792 ClientStateNotification<ClientState>* note_; | |
1793 | |
1794 // All methods of this class should be run on the same thread. | |
1795 base::ThreadChecker thread_checker_; | |
1796 | |
1797 // Ids for output BitstreamBuffers. | |
1798 ScopedVector<base::SharedMemory> output_shms_; | |
1799 int32_t next_output_buffer_id_; | |
1800 | |
1801 // The timer used to monitor the encoder doesn't return an output buffer in | |
1802 // a period of time. | |
1803 std::unique_ptr<base::Timer> timer_; | |
1804 }; | |
1805 | |
1806 VEANoInputClient::VEANoInputClient(ClientStateNotification<ClientState>* note) | |
1807 : note_(note), next_output_buffer_id_(0) { | |
1808 thread_checker_.DetachFromThread(); | |
1809 } | |
1810 | |
1811 VEANoInputClient::~VEANoInputClient() { | |
1812 LOG_ASSERT(!has_encoder()); | |
1813 } | |
1814 | |
1815 void VEANoInputClient::CreateEncoder() { | |
1816 DCHECK(thread_checker_.CalledOnValidThread()); | |
1817 LOG_ASSERT(!has_encoder()); | |
1818 LOG_ASSERT(g_env->test_streams_.size()); | |
1819 | |
1820 const int kDefaultWidth = 320; | |
1821 const int kDefaultHeight = 240; | |
1822 const int kDefaultBitrate = 200000; | |
1823 const int kDefaultFps = 30; | |
1824 | |
1825 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | |
1826 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | |
1827 CreateMFVEA()}; | |
1828 | |
1829 // The test case is no input. Use default visible size, bitrate, and fps. | |
1830 gfx::Size visible_size(kDefaultWidth, kDefaultHeight); | |
1831 for (auto& encoder : encoders) { | |
1832 if (!encoder) | |
1833 continue; | |
1834 encoder_ = std::move(encoder); | |
1835 if (encoder_->Initialize(kInputFormat, visible_size, | |
1836 g_env->test_streams_[0]->requested_profile, | |
1837 kDefaultBitrate, this)) { | |
1838 encoder_->RequestEncodingParametersChange(kDefaultBitrate, kDefaultFps); | |
1839 SetState(CS_INITIALIZED); | |
1840 return; | |
1841 } | |
1842 } | |
1843 encoder_.reset(); | |
1844 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | |
1845 SetState(CS_ERROR); | |
1846 } | |
1847 | |
1848 void VEANoInputClient::DestroyEncoder() { | |
1849 DCHECK(thread_checker_.CalledOnValidThread()); | |
1850 if (!has_encoder()) | |
1851 return; | |
1852 // Clear the objects that should be destroyed on the same thread as creation. | |
1853 encoder_.reset(); | |
1854 timer_.reset(); | |
1855 } | |
1856 | |
1857 void VEANoInputClient::RequireBitstreamBuffers( | |
1858 unsigned int input_count, | |
1859 const gfx::Size& input_coded_size, | |
1860 size_t output_size) { | |
1861 DCHECK(thread_checker_.CalledOnValidThread()); | |
1862 SetState(CS_ENCODING); | |
1863 ASSERT_GT(output_size, 0UL); | |
1864 | |
1865 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | |
1866 base::SharedMemory* shm = new base::SharedMemory(); | |
1867 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); | |
1868 output_shms_.push_back(shm); | |
1869 FeedEncoderWithOutput(shm, output_size); | |
1870 } | |
1871 // Timer is used to make sure there is no output frame in 100ms. | |
1872 timer_.reset(new base::Timer(FROM_HERE, | |
1873 base::TimeDelta::FromMilliseconds(100), | |
1874 base::Bind(&VEANoInputClient::SetState, | |
1875 base::Unretained(this), CS_FINISHED), | |
1876 false)); | |
1877 timer_->Reset(); | |
1878 } | |
1879 | |
1880 void VEANoInputClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | |
1881 size_t payload_size, | |
1882 bool key_frame, | |
1883 base::TimeDelta timestamp) { | |
1884 DCHECK(thread_checker_.CalledOnValidThread()); | |
1885 SetState(CS_ERROR); | |
1886 } | |
1887 | |
1888 void VEANoInputClient::NotifyError(VideoEncodeAccelerator::Error error) { | |
1889 DCHECK(thread_checker_.CalledOnValidThread()); | |
1890 SetState(CS_ERROR); | |
1891 } | |
1892 | |
1893 void VEANoInputClient::SetState(ClientState new_state) { | |
1894 DVLOG(4) << "Changing state to " << new_state; | |
1895 note_->Notify(new_state); | |
1896 } | |
1897 | |
1898 void VEANoInputClient::FeedEncoderWithOutput(base::SharedMemory* shm, | |
1899 size_t output_size) { | |
1900 if (!has_encoder()) | |
1901 return; | |
1902 | |
1903 base::SharedMemoryHandle dup_handle; | |
1904 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | |
1905 | |
1906 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | |
1907 output_size); | |
1908 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | |
1909 } | |
1910 | |
1911 /* This client is only used to test input frame with the size of U and V planes | |
1912 unaligned to cache line. | |
1913 To have both width and height divisible by 16 but not 32 will make the size | |
1914 of U/V plane (width * height / 4) unaligned to 128-byte cache line. */ | |
1915 class VEACacheLineUnalignedInputClient : public VideoEncodeAccelerator::Client { | |
1765 public: | 1916 public: |
1766 explicit VEANoInputClient(ClientStateNotification<ClientState>* note); | 1917 explicit VEACacheLineUnalignedInputClient( |
1767 ~VEANoInputClient() override; | 1918 ClientStateNotification<ClientState>* note); |
1919 ~VEACacheLineUnalignedInputClient() override; | |
1768 void CreateEncoder(); | 1920 void CreateEncoder(); |
1769 void DestroyEncoder(); | 1921 void DestroyEncoder(); |
1770 | 1922 |
1771 // VideoDecodeAccelerator::Client implementation. | 1923 // VideoDecodeAccelerator::Client implementation. |
1772 void RequireBitstreamBuffers(unsigned int input_count, | 1924 void RequireBitstreamBuffers(unsigned int input_count, |
1773 const gfx::Size& input_coded_size, | 1925 const gfx::Size& input_coded_size, |
1774 size_t output_buffer_size) override; | 1926 size_t output_buffer_size) override; |
1775 void BitstreamBufferReady(int32_t bitstream_buffer_id, | 1927 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
1776 size_t payload_size, | 1928 size_t payload_size, |
1777 bool key_frame, | 1929 bool key_frame, |
1778 base::TimeDelta timestamp) override; | 1930 base::TimeDelta timestamp) override; |
1779 void NotifyError(VideoEncodeAccelerator::Error error) override; | 1931 void NotifyError(VideoEncodeAccelerator::Error error) override; |
1780 | 1932 |
1781 private: | 1933 private: |
1782 bool has_encoder() { return encoder_.get(); } | 1934 bool has_encoder() { return encoder_.get(); } |
1783 | 1935 |
1784 void SetState(ClientState new_state); | 1936 void SetState(ClientState new_state); |
1785 | 1937 |
1786 // Provide the encoder with a new output buffer. | 1938 // Provide the encoder with a new output buffer. |
1787 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); | 1939 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); |
1788 | 1940 |
1941 // Feed the encoder with one input frame. | |
1942 void FeedEncoderWithOneInput(const gfx::Size& input_coded_size); | |
1943 | |
1789 std::unique_ptr<VideoEncodeAccelerator> encoder_; | 1944 std::unique_ptr<VideoEncodeAccelerator> encoder_; |
1790 | 1945 |
1791 // Used to notify another thread about the state. VEAClient does not own this. | 1946 // Used to notify another thread about the state. VEAClient does not own this. |
1792 ClientStateNotification<ClientState>* note_; | 1947 ClientStateNotification<ClientState>* note_; |
1793 | 1948 |
1794 // All methods of this class should be run on the same thread. | 1949 // All methods of this class should be run on the same thread. |
1795 base::ThreadChecker thread_checker_; | 1950 base::ThreadChecker thread_checker_; |
1796 | 1951 |
1797 // Ids for output BitstreamBuffers. | 1952 // Ids for output BitstreamBuffers. |
1798 ScopedVector<base::SharedMemory> output_shms_; | 1953 ScopedVector<base::SharedMemory> output_shms_; |
1799 int32_t next_output_buffer_id_; | 1954 int32_t next_output_buffer_id_; |
1800 | 1955 |
1801 // The timer used to monitor the encoder doesn't return an output buffer in | 1956 const int default_width_; |
1802 // a period of time. | 1957 const int default_height_; |
1803 std::unique_ptr<base::Timer> timer_; | 1958 const int default_bitrate_; |
1959 const int default_fps_; | |
1804 }; | 1960 }; |
1805 | 1961 |
1806 VEANoInputClient::VEANoInputClient(ClientStateNotification<ClientState>* note) | 1962 VEACacheLineUnalignedInputClient::VEACacheLineUnalignedInputClient( |
1807 : note_(note), next_output_buffer_id_(0) { | 1963 ClientStateNotification<ClientState>* note) |
1964 : note_(note), | |
1965 next_output_buffer_id_(0), | |
1966 default_width_(368), // divisible by 16 but not 32 | |
1967 default_height_(368), // divisible by 16 but not 32 | |
1968 default_bitrate_(200000), | |
1969 default_fps_(30) { | |
1808 thread_checker_.DetachFromThread(); | 1970 thread_checker_.DetachFromThread(); |
1809 } | 1971 } |
1810 | 1972 |
1811 VEANoInputClient::~VEANoInputClient() { | 1973 VEACacheLineUnalignedInputClient::~VEACacheLineUnalignedInputClient() { |
1812 LOG_ASSERT(!has_encoder()); | 1974 LOG_ASSERT(!has_encoder()); |
1813 } | 1975 } |
1814 | 1976 |
1815 void VEANoInputClient::CreateEncoder() { | 1977 void VEACacheLineUnalignedInputClient::CreateEncoder() { |
1816 DCHECK(thread_checker_.CalledOnValidThread()); | 1978 DCHECK(thread_checker_.CalledOnValidThread()); |
1817 LOG_ASSERT(!has_encoder()); | 1979 LOG_ASSERT(!has_encoder()); |
1818 LOG_ASSERT(g_env->test_streams_.size()); | |
1819 | |
1820 const int kDefaultWidth = 320; | |
1821 const int kDefaultHeight = 240; | |
1822 const int kDefaultBitrate = 200000; | |
1823 const int kDefaultFps = 30; | |
1824 | 1980 |
1825 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1981 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
1826 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | 1982 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
1827 CreateMFVEA()}; | 1983 CreateMFVEA()}; |
1828 | 1984 |
1829 // The test case is no input. Use default visible size, bitrate, and fps. | 1985 gfx::Size visible_size(default_width_, default_height_); |
1830 gfx::Size visible_size(kDefaultWidth, kDefaultHeight); | |
1831 for (auto& encoder : encoders) { | 1986 for (auto& encoder : encoders) { |
1832 if (!encoder) | 1987 if (!encoder) |
1833 continue; | 1988 continue; |
1834 encoder_ = std::move(encoder); | 1989 encoder_ = std::move(encoder); |
1835 if (encoder_->Initialize(kInputFormat, visible_size, | 1990 if (encoder_->Initialize(kInputFormat, visible_size, |
1836 g_env->test_streams_[0]->requested_profile, | 1991 g_env->test_streams_[0]->requested_profile, |
1837 kDefaultBitrate, this)) { | 1992 default_bitrate_, this)) { |
1838 encoder_->RequestEncodingParametersChange(kDefaultBitrate, kDefaultFps); | 1993 encoder_->RequestEncodingParametersChange(default_bitrate_, default_fps_); |
1839 SetState(CS_INITIALIZED); | 1994 SetState(CS_INITIALIZED); |
1840 return; | 1995 return; |
1841 } | 1996 } |
1842 } | 1997 } |
1843 encoder_.reset(); | 1998 encoder_.reset(); |
1844 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | 1999 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; |
1845 SetState(CS_ERROR); | 2000 SetState(CS_ERROR); |
1846 } | 2001 } |
1847 | 2002 |
1848 void VEANoInputClient::DestroyEncoder() { | 2003 void VEACacheLineUnalignedInputClient::DestroyEncoder() { |
1849 DCHECK(thread_checker_.CalledOnValidThread()); | 2004 DCHECK(thread_checker_.CalledOnValidThread()); |
1850 if (!has_encoder()) | 2005 if (!has_encoder()) |
1851 return; | 2006 return; |
1852 // Clear the objects that should be destroyed on the same thread as creation. | 2007 // Clear the objects that should be destroyed on the same thread as creation. |
1853 encoder_.reset(); | 2008 encoder_.reset(); |
1854 timer_.reset(); | |
1855 } | 2009 } |
1856 | 2010 |
1857 void VEANoInputClient::RequireBitstreamBuffers( | 2011 void VEACacheLineUnalignedInputClient::RequireBitstreamBuffers( |
1858 unsigned int input_count, | 2012 unsigned int input_count, |
1859 const gfx::Size& input_coded_size, | 2013 const gfx::Size& input_coded_size, |
1860 size_t output_size) { | 2014 size_t output_size) { |
1861 DCHECK(thread_checker_.CalledOnValidThread()); | 2015 DCHECK(thread_checker_.CalledOnValidThread()); |
1862 SetState(CS_ENCODING); | 2016 SetState(CS_ENCODING); |
1863 ASSERT_GT(output_size, 0UL); | 2017 ASSERT_GT(output_size, 0UL); |
1864 | 2018 |
1865 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | 2019 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { |
1866 base::SharedMemory* shm = new base::SharedMemory(); | 2020 base::SharedMemory* shm = new base::SharedMemory(); |
1867 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); | 2021 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); |
1868 output_shms_.push_back(shm); | 2022 output_shms_.push_back(shm); |
1869 FeedEncoderWithOutput(shm, output_size); | 2023 FeedEncoderWithOutput(shm, output_size); |
1870 } | 2024 } |
1871 // Timer is used to make sure there is no output frame in 100ms. | 2025 FeedEncoderWithOneInput(input_coded_size); |
1872 timer_.reset(new base::Timer(FROM_HERE, | |
1873 base::TimeDelta::FromMilliseconds(100), | |
1874 base::Bind(&VEANoInputClient::SetState, | |
1875 base::Unretained(this), CS_FINISHED), | |
1876 false)); | |
1877 timer_->Reset(); | |
1878 } | 2026 } |
1879 | 2027 |
1880 void VEANoInputClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | 2028 void VEACacheLineUnalignedInputClient::BitstreamBufferReady( |
1881 size_t payload_size, | 2029 int32_t bitstream_buffer_id, |
1882 bool key_frame, | 2030 size_t payload_size, |
1883 base::TimeDelta timestamp) { | 2031 bool key_frame, |
2032 base::TimeDelta timestamp) { | |
2033 DCHECK(thread_checker_.CalledOnValidThread()); | |
2034 // It's enough to encode just one frame | |
2035 SetState(CS_FINISHED); | |
2036 } | |
2037 | |
2038 void VEACacheLineUnalignedInputClient::NotifyError( | |
2039 VideoEncodeAccelerator::Error error) { | |
1884 DCHECK(thread_checker_.CalledOnValidThread()); | 2040 DCHECK(thread_checker_.CalledOnValidThread()); |
1885 SetState(CS_ERROR); | 2041 SetState(CS_ERROR); |
1886 } | 2042 } |
1887 | 2043 |
1888 void VEANoInputClient::NotifyError(VideoEncodeAccelerator::Error error) { | 2044 void VEACacheLineUnalignedInputClient::SetState(ClientState new_state) { |
1889 DCHECK(thread_checker_.CalledOnValidThread()); | |
1890 SetState(CS_ERROR); | |
1891 } | |
1892 | |
1893 void VEANoInputClient::SetState(ClientState new_state) { | |
1894 DVLOG(4) << "Changing state to " << new_state; | 2045 DVLOG(4) << "Changing state to " << new_state; |
1895 note_->Notify(new_state); | 2046 note_->Notify(new_state); |
1896 } | 2047 } |
1897 | 2048 |
1898 void VEANoInputClient::FeedEncoderWithOutput(base::SharedMemory* shm, | 2049 void VEACacheLineUnalignedInputClient::FeedEncoderWithOutput( |
1899 size_t output_size) { | 2050 base::SharedMemory* shm, |
2051 size_t output_size) { | |
1900 if (!has_encoder()) | 2052 if (!has_encoder()) |
1901 return; | 2053 return; |
1902 | 2054 |
1903 base::SharedMemoryHandle dup_handle; | 2055 base::SharedMemoryHandle dup_handle; |
1904 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | 2056 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); |
1905 | 2057 |
1906 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | 2058 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, |
1907 output_size); | 2059 output_size); |
1908 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | 2060 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); |
1909 } | 2061 } |
1910 | 2062 |
2063 void VEACacheLineUnalignedInputClient::FeedEncoderWithOneInput( | |
2064 const gfx::Size& input_coded_size) { | |
2065 if (!has_encoder()) | |
2066 return; | |
2067 | |
2068 std::vector<char, AlignedAllocator<char, kPlatformBufferAlignment>> | |
2069 aligned_in_file_data(VideoFrame::AllocationSize(PIXEL_FORMAT_I420, | |
2070 input_coded_size)); | |
2071 | |
2072 uint8_t* frame_data_y = reinterpret_cast<uint8_t*>(&aligned_in_file_data[0]); | |
2073 uint8_t* frame_data_u = frame_data_y + | |
2074 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, 0, input_coded_size).GetArea(); | |
2075 uint8_t* frame_data_v = frame_data_u + | |
2076 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, 1, input_coded_size).GetArea(); | |
2077 | |
2078 scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalYuvData( | |
2079 PIXEL_FORMAT_I420, input_coded_size, gfx::Rect(input_coded_size), | |
2080 input_coded_size, input_coded_size.width(), | |
2081 input_coded_size.width() / 2, input_coded_size.width() / 2, | |
2082 frame_data_y, frame_data_u, frame_data_v, | |
2083 base::TimeDelta().FromMilliseconds( | |
2084 base::Time::kMillisecondsPerSecond / default_fps_)); | |
2085 | |
2086 encoder_->Encode(video_frame, false); | |
2087 } | |
2088 | |
1911 // Test parameters: | 2089 // Test parameters: |
1912 // - Number of concurrent encoders. The value takes effect when there is only | 2090 // - Number of concurrent encoders. The value takes effect when there is only |
1913 // one input stream; otherwise, one encoder per input stream will be | 2091 // one input stream; otherwise, one encoder per input stream will be |
1914 // instantiated. | 2092 // instantiated. |
1915 // - If true, save output to file (provided an output filename was supplied). | 2093 // - If true, save output to file (provided an output filename was supplied). |
1916 // - Force a keyframe every n frames. | 2094 // - Force a keyframe every n frames. |
1917 // - Force bitrate; the actual required value is provided as a property | 2095 // - Force bitrate; the actual required value is provided as a property |
1918 // of the input stream, because it depends on stream type/resolution/etc. | 2096 // of the input stream, because it depends on stream type/resolution/etc. |
1919 // - If true, measure performance. | 2097 // - If true, measure performance. |
1920 // - If true, switch bitrate mid-stream. | 2098 // - If true, switch bitrate mid-stream. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2069 } | 2247 } |
2070 | 2248 |
2071 encoder_thread.task_runner()->PostTask( | 2249 encoder_thread.task_runner()->PostTask( |
2072 FROM_HERE, base::Bind(&VEANoInputClient::DestroyEncoder, | 2250 FROM_HERE, base::Bind(&VEANoInputClient::DestroyEncoder, |
2073 base::Unretained(client.get()))); | 2251 base::Unretained(client.get()))); |
2074 | 2252 |
2075 // This ensures all tasks have finished. | 2253 // This ensures all tasks have finished. |
2076 encoder_thread.Stop(); | 2254 encoder_thread.Stop(); |
2077 } | 2255 } |
2078 | 2256 |
2257 TEST(VEACacheLineUnalignedInputTest, CheckOutput) { | |
2258 std::unique_ptr<ClientStateNotification<ClientState>> note( | |
2259 new ClientStateNotification<ClientState>()); | |
2260 std::unique_ptr<VEACacheLineUnalignedInputClient> client( | |
2261 new VEACacheLineUnalignedInputClient(note.get())); | |
2262 base::Thread encoder_thread("EncoderThread"); | |
2263 ASSERT_TRUE(encoder_thread.Start()); | |
2264 | |
2265 encoder_thread.task_runner()->PostTask( | |
2266 FROM_HERE, base::Bind(&VEACacheLineUnalignedInputClient::CreateEncoder, | |
2267 base::Unretained(client.get()))); | |
2268 | |
2269 // Encoder must pass through states in this order. | |
2270 enum ClientState state_transitions[] = {CS_INITIALIZED, CS_ENCODING, | |
2271 CS_FINISHED}; | |
2272 | |
2273 ClientState expected_state, wait_state; | |
2274 for (const auto& state : state_transitions) { | |
2275 expected_state = state; | |
2276 wait_state = note->Wait(); | |
2277 if (expected_state != wait_state) { | |
2278 break; | |
2279 } | |
2280 } | |
2281 | |
2282 encoder_thread.task_runner()->PostTask( | |
2283 FROM_HERE, base::Bind(&VEACacheLineUnalignedInputClient::DestroyEncoder, | |
2284 base::Unretained(client.get()))); | |
2285 | |
2286 // This ensures all tasks have finished. | |
2287 encoder_thread.Stop(); | |
2288 | |
2289 ASSERT_EQ(expected_state, wait_state); | |
2290 } | |
2291 | |
2079 #elif defined(OS_MACOSX) || defined(OS_WIN) | 2292 #elif defined(OS_MACOSX) || defined(OS_WIN) |
2080 INSTANTIATE_TEST_CASE_P( | 2293 INSTANTIATE_TEST_CASE_P( |
2081 SimpleEncode, | 2294 SimpleEncode, |
2082 VideoEncodeAcceleratorTest, | 2295 VideoEncodeAcceleratorTest, |
2083 ::testing::Values( | 2296 ::testing::Values( |
2084 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 2297 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
2085 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 2298 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
2086 | 2299 |
2087 INSTANTIATE_TEST_CASE_P( | 2300 INSTANTIATE_TEST_CASE_P( |
2088 EncoderPerf, | 2301 EncoderPerf, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2199 | 2412 |
2200 media::g_env = | 2413 media::g_env = |
2201 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2414 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
2202 testing::AddGlobalTestEnvironment( | 2415 testing::AddGlobalTestEnvironment( |
2203 new media::VideoEncodeAcceleratorTestEnvironment( | 2416 new media::VideoEncodeAcceleratorTestEnvironment( |
2204 std::move(test_stream_data), log_path, run_at_fps, | 2417 std::move(test_stream_data), log_path, run_at_fps, |
2205 needs_encode_latency, verify_all_output))); | 2418 needs_encode_latency, verify_all_output))); |
2206 | 2419 |
2207 return RUN_ALL_TESTS(); | 2420 return RUN_ALL_TESTS(); |
2208 } | 2421 } |
OLD | NEW |