Chromium Code Reviews| 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 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 | 825 |
| 826 // Divide the difference by the size of frame. | 826 // Divide the difference by the size of frame. |
| 827 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); | 827 difference /= VideoFrame::AllocationSize(kInputFormat, visible_size); |
| 828 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) | 828 EXPECT_TRUE(difference <= kDecodeSimilarityThreshold) |
| 829 << "difference = " << difference << " > decode similarity threshold"; | 829 << "difference = " << difference << " > decode similarity threshold"; |
| 830 } | 830 } |
| 831 | 831 |
| 832 class VEAClient : public VideoEncodeAccelerator::Client { | 832 class VEAClientBase : public VideoEncodeAccelerator::Client { |
| 833 public: | |
| 834 VEAClientBase(); | |
| 835 ~VEAClientBase() override; | |
| 836 | |
| 837 // VideoDecodeAccelerator::Client implementation. | |
| 838 virtual void RequireBitstreamBuffers(unsigned int input_count, | |
|
Owen Lin
2016/11/04 03:38:50
There is no need to list these pure virtual functi
henryhsu
2016/11/04 04:15:17
Done.
| |
| 839 const gfx::Size& input_coded_size, | |
| 840 size_t output_buffer_size) = 0; | |
| 841 virtual void BitstreamBufferReady(int32_t bitstream_buffer_id, | |
| 842 size_t payload_size, | |
| 843 bool key_frame, | |
| 844 base::TimeDelta timestamp) = 0; | |
| 845 virtual void NotifyError(VideoEncodeAccelerator::Error error) = 0; | |
| 846 | |
| 847 protected: | |
| 848 bool has_encoder() { return encoder_.get(); } | |
| 849 | |
| 850 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); | |
|
Owen Lin
2016/11/04 03:38:50
Why these functions need to be a member of VEAClie
henryhsu
2016/11/04 04:15:17
Hmm...If so, then we don't have VEAClientBase clas
| |
| 851 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); | |
| 852 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); | |
| 853 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); | |
| 854 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); | |
| 855 | |
| 856 std::unique_ptr<VideoEncodeAccelerator> encoder_; | |
| 857 }; | |
| 858 | |
| 859 VEAClientBase::VEAClientBase() { | |
|
Owen Lin
2016/11/04 03:38:51
Please run gl cl format to check style issue.
henryhsu
2016/11/04 04:15:17
Done.
| |
| 860 } | |
| 861 | |
| 862 VEAClientBase::~VEAClientBase() { | |
| 863 LOG_ASSERT(!has_encoder()); | |
| 864 } | |
| 865 | |
| 866 std::unique_ptr<VideoEncodeAccelerator> VEAClientBase::CreateFakeVEA() { | |
| 867 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 868 if (g_fake_encoder) { | |
| 869 encoder.reset(new FakeVideoEncodeAccelerator( | |
| 870 scoped_refptr<base::SingleThreadTaskRunner>( | |
| 871 base::ThreadTaskRunnerHandle::Get()))); | |
| 872 } | |
| 873 return encoder; | |
| 874 } | |
| 875 | |
| 876 std::unique_ptr<VideoEncodeAccelerator> VEAClientBase::CreateV4L2VEA() { | |
| 877 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 878 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 879 scoped_refptr<V4L2Device> device = V4L2Device::Create(); | |
| 880 if (device) | |
| 881 encoder.reset(new V4L2VideoEncodeAccelerator(device)); | |
| 882 #endif | |
| 883 return encoder; | |
| 884 } | |
| 885 | |
| 886 std::unique_ptr<VideoEncodeAccelerator> VEAClientBase::CreateVaapiVEA() { | |
| 887 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 888 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 889 encoder.reset(new VaapiVideoEncodeAccelerator()); | |
| 890 #endif | |
| 891 return encoder; | |
| 892 } | |
| 893 | |
| 894 std::unique_ptr<VideoEncodeAccelerator> VEAClientBase::CreateVTVEA() { | |
| 895 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 896 #if defined(OS_MACOSX) | |
| 897 encoder.reset(new VTVideoEncodeAccelerator()); | |
| 898 #endif | |
| 899 return encoder; | |
| 900 } | |
| 901 | |
| 902 std::unique_ptr<VideoEncodeAccelerator> VEAClientBase::CreateMFVEA() { | |
| 903 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 904 #if defined(OS_WIN) | |
| 905 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); | |
| 906 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); | |
| 907 #endif | |
| 908 return encoder; | |
| 909 } | |
| 910 | |
| 911 class VEAClient : public VEAClientBase { | |
| 833 public: | 912 public: |
| 834 VEAClient(TestStream* test_stream, | 913 VEAClient(TestStream* test_stream, |
| 835 ClientStateNotification<ClientState>* note, | 914 ClientStateNotification<ClientState>* note, |
| 836 bool save_to_file, | 915 bool save_to_file, |
| 837 unsigned int keyframe_period, | 916 unsigned int keyframe_period, |
| 838 bool force_bitrate, | 917 bool force_bitrate, |
| 839 bool test_perf, | 918 bool test_perf, |
| 840 bool mid_stream_bitrate_switch, | 919 bool mid_stream_bitrate_switch, |
| 841 bool mid_stream_framerate_switch, | 920 bool mid_stream_framerate_switch, |
| 842 bool verify_output, | 921 bool verify_output, |
| 843 bool verify_output_timestamp); | 922 bool verify_output_timestamp); |
| 844 ~VEAClient() override; | 923 ~VEAClient() override; |
| 845 void CreateEncoder(); | 924 void CreateEncoder(); |
| 846 void DestroyEncoder(); | 925 void DestroyEncoder(); |
| 847 | 926 |
| 848 // VideoDecodeAccelerator::Client implementation. | 927 // VideoDecodeAccelerator::Client implementation. |
| 849 void RequireBitstreamBuffers(unsigned int input_count, | 928 void RequireBitstreamBuffers(unsigned int input_count, |
| 850 const gfx::Size& input_coded_size, | 929 const gfx::Size& input_coded_size, |
| 851 size_t output_buffer_size) override; | 930 size_t output_buffer_size) override; |
| 852 void BitstreamBufferReady(int32_t bitstream_buffer_id, | 931 void BitstreamBufferReady(int32_t bitstream_buffer_id, |
| 853 size_t payload_size, | 932 size_t payload_size, |
| 854 bool key_frame, | 933 bool key_frame, |
| 855 base::TimeDelta timestamp) override; | 934 base::TimeDelta timestamp) override; |
| 856 void NotifyError(VideoEncodeAccelerator::Error error) override; | 935 void NotifyError(VideoEncodeAccelerator::Error error) override; |
| 857 | 936 |
| 858 private: | 937 private: |
| 859 bool has_encoder() { return encoder_.get(); } | |
| 860 | |
| 861 // Return the number of encoded frames per second. | 938 // Return the number of encoded frames per second. |
| 862 double frames_per_second(); | 939 double frames_per_second(); |
| 863 | 940 |
| 864 std::unique_ptr<VideoEncodeAccelerator> CreateFakeVEA(); | |
| 865 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA(); | |
| 866 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA(); | |
| 867 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA(); | |
| 868 std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA(); | |
| 869 | |
| 870 void SetState(ClientState new_state); | 941 void SetState(ClientState new_state); |
| 871 | 942 |
| 872 // Set current stream parameters to given |bitrate| at |framerate|. | 943 // Set current stream parameters to given |bitrate| at |framerate|. |
| 873 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); | 944 void SetStreamParameters(unsigned int bitrate, unsigned int framerate); |
| 874 | 945 |
| 875 // Called when encoder is done with a VideoFrame. | 946 // Called when encoder is done with a VideoFrame. |
| 876 void InputNoLongerNeededCallback(int32_t input_id); | 947 void InputNoLongerNeededCallback(int32_t input_id); |
| 877 | 948 |
| 878 // Feed the encoder with one input frame. | 949 // Feed the encoder with one input frame. |
| 879 void FeedEncoderWithOneInput(); | 950 void FeedEncoderWithOneInput(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 // Called when the quality validator has decoded all the frames. | 996 // Called when the quality validator has decoded all the frames. |
| 926 void DecodeCompleted(); | 997 void DecodeCompleted(); |
| 927 | 998 |
| 928 // Called when the quality validator fails to decode a frame. | 999 // Called when the quality validator fails to decode a frame. |
| 929 void DecodeFailed(); | 1000 void DecodeFailed(); |
| 930 | 1001 |
| 931 // Verify that the output timestamp matches input timestamp. | 1002 // Verify that the output timestamp matches input timestamp. |
| 932 void VerifyOutputTimestamp(base::TimeDelta timestamp); | 1003 void VerifyOutputTimestamp(base::TimeDelta timestamp); |
| 933 | 1004 |
| 934 ClientState state_; | 1005 ClientState state_; |
| 935 std::unique_ptr<VideoEncodeAccelerator> encoder_; | |
| 936 | 1006 |
| 937 TestStream* test_stream_; | 1007 TestStream* test_stream_; |
| 938 | 1008 |
| 939 // Used to notify another thread about the state. VEAClient does not own this. | 1009 // Used to notify another thread about the state. VEAClient does not own this. |
| 940 ClientStateNotification<ClientState>* note_; | 1010 ClientStateNotification<ClientState>* note_; |
| 941 | 1011 |
| 942 // Ids assigned to VideoFrames. | 1012 // Ids assigned to VideoFrames. |
| 943 std::set<int32_t> inputs_at_client_; | 1013 std::set<int32_t> inputs_at_client_; |
| 944 int32_t next_input_id_; | 1014 int32_t next_input_id_; |
| 945 | 1015 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); | 1178 EXPECT_EQ(0, base::WriteFile(out_filename, NULL, 0)); |
| 1109 } | 1179 } |
| 1110 | 1180 |
| 1111 // Initialize the parameters of the test streams. | 1181 // Initialize the parameters of the test streams. |
| 1112 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); | 1182 UpdateTestStreamData(mid_stream_bitrate_switch, mid_stream_framerate_switch); |
| 1113 | 1183 |
| 1114 thread_checker_.DetachFromThread(); | 1184 thread_checker_.DetachFromThread(); |
| 1115 } | 1185 } |
| 1116 | 1186 |
| 1117 VEAClient::~VEAClient() { | 1187 VEAClient::~VEAClient() { |
| 1118 LOG_ASSERT(!has_encoder()); | |
| 1119 } | |
| 1120 | |
| 1121 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateFakeVEA() { | |
| 1122 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 1123 if (g_fake_encoder) { | |
| 1124 encoder.reset(new FakeVideoEncodeAccelerator( | |
| 1125 scoped_refptr<base::SingleThreadTaskRunner>( | |
| 1126 base::ThreadTaskRunnerHandle::Get()))); | |
| 1127 } | |
| 1128 return encoder; | |
| 1129 } | |
| 1130 | |
| 1131 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateV4L2VEA() { | |
| 1132 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 1133 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 1134 scoped_refptr<V4L2Device> device = V4L2Device::Create(); | |
| 1135 if (device) | |
| 1136 encoder.reset(new V4L2VideoEncodeAccelerator(device)); | |
| 1137 #endif | |
| 1138 return encoder; | |
| 1139 } | |
| 1140 | |
| 1141 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVaapiVEA() { | |
| 1142 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 1143 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 1144 encoder.reset(new VaapiVideoEncodeAccelerator()); | |
| 1145 #endif | |
| 1146 return encoder; | |
| 1147 } | |
| 1148 | |
| 1149 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateVTVEA() { | |
| 1150 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 1151 #if defined(OS_MACOSX) | |
| 1152 encoder.reset(new VTVideoEncodeAccelerator()); | |
| 1153 #endif | |
| 1154 return encoder; | |
| 1155 } | |
| 1156 | |
| 1157 std::unique_ptr<VideoEncodeAccelerator> VEAClient::CreateMFVEA() { | |
| 1158 std::unique_ptr<VideoEncodeAccelerator> encoder; | |
| 1159 #if defined(OS_WIN) | |
| 1160 MediaFoundationVideoEncodeAccelerator::PreSandboxInitialization(); | |
| 1161 encoder.reset(new MediaFoundationVideoEncodeAccelerator()); | |
| 1162 #endif | |
| 1163 return encoder; | |
| 1164 } | 1188 } |
| 1165 | 1189 |
| 1166 void VEAClient::CreateEncoder() { | 1190 void VEAClient::CreateEncoder() { |
| 1167 DCHECK(thread_checker_.CalledOnValidThread()); | 1191 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1168 LOG_ASSERT(!has_encoder()); | 1192 LOG_ASSERT(!has_encoder()); |
| 1169 | 1193 |
| 1170 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | 1194 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { |
| 1171 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | 1195 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), |
| 1172 CreateMFVEA()}; | 1196 CreateMFVEA()}; |
| 1173 | 1197 |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1669 IvfFrameHeader header = {}; | 1693 IvfFrameHeader header = {}; |
| 1670 | 1694 |
| 1671 header.frame_size = static_cast<uint32_t>(frame_size); | 1695 header.frame_size = static_cast<uint32_t>(frame_size); |
| 1672 header.timestamp = frame_index; | 1696 header.timestamp = frame_index; |
| 1673 header.ByteSwap(); | 1697 header.ByteSwap(); |
| 1674 EXPECT_TRUE(base::AppendToFile( | 1698 EXPECT_TRUE(base::AppendToFile( |
| 1675 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), | 1699 base::FilePath::FromUTF8Unsafe(test_stream_->out_filename), |
| 1676 reinterpret_cast<char*>(&header), sizeof(header))); | 1700 reinterpret_cast<char*>(&header), sizeof(header))); |
| 1677 } | 1701 } |
| 1678 | 1702 |
| 1703 // This client is only used to test crbug.com/641600 to make sure the encoder | |
| 1704 // does not return an encoded frame before getting any input. | |
| 1705 class VEANoInputClient : public VEAClientBase { | |
| 1706 public: | |
| 1707 VEANoInputClient(ClientStateNotification<ClientState>* note); | |
|
Owen Lin
2016/11/04 03:38:50
explicit
henryhsu
2016/11/04 04:15:17
Done.
| |
| 1708 ~VEANoInputClient() = default; | |
| 1709 void CreateEncoder(); | |
| 1710 void DestroyEncoder(); | |
| 1711 | |
| 1712 // VideoDecodeAccelerator::Client implementation. | |
| 1713 void RequireBitstreamBuffers(unsigned int input_count, | |
| 1714 const gfx::Size& input_coded_size, | |
| 1715 size_t output_buffer_size) override; | |
| 1716 void BitstreamBufferReady(int32_t bitstream_buffer_id, | |
| 1717 size_t payload_size, | |
| 1718 bool key_frame, | |
| 1719 base::TimeDelta timestamp) override; | |
| 1720 void NotifyError(VideoEncodeAccelerator::Error error) override; | |
| 1721 | |
| 1722 private: | |
| 1723 void SetState(ClientState new_state); | |
| 1724 | |
| 1725 // Provide the encoder with a new output buffer. | |
| 1726 void FeedEncoderWithOutput(base::SharedMemory* shm, size_t output_size); | |
| 1727 | |
| 1728 ClientState state_; | |
| 1729 | |
| 1730 // Used to notify another thread about the state. VEAClient does not own this. | |
| 1731 ClientStateNotification<ClientState>* note_; | |
| 1732 | |
| 1733 // All methods of this class should be run on the same thread. | |
| 1734 base::ThreadChecker thread_checker_; | |
| 1735 | |
| 1736 // Ids for output BitstreamBuffers. | |
| 1737 ScopedVector<base::SharedMemory> output_shms_; | |
| 1738 int32_t next_output_buffer_id_; | |
| 1739 | |
| 1740 // The timer used to monitor the encoder doesn't return an output buffer in | |
| 1741 // a period of time. | |
| 1742 std::unique_ptr<base::Timer> timer_; | |
| 1743 }; | |
| 1744 | |
| 1745 VEANoInputClient::VEANoInputClient(ClientStateNotification<ClientState>* note) | |
| 1746 : state_(CS_CREATED), | |
| 1747 note_(note), | |
| 1748 next_output_buffer_id_(0) { | |
| 1749 } | |
| 1750 | |
| 1751 void VEANoInputClient::CreateEncoder() { | |
| 1752 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1753 LOG_ASSERT(!has_encoder()); | |
| 1754 | |
| 1755 std::unique_ptr<VideoEncodeAccelerator> encoders[] = { | |
| 1756 CreateFakeVEA(), CreateV4L2VEA(), CreateVaapiVEA(), CreateVTVEA(), | |
| 1757 CreateMFVEA()}; | |
| 1758 | |
| 1759 // The test case is no input. Use default visible size, bitrate, and fps. | |
| 1760 gfx::Size visible_size(320, 200); | |
|
Owen Lin
2016/11/04 03:38:51
How about making them static const variable.
henryhsu
2016/11/04 04:15:17
Done.
| |
| 1761 for (size_t i = 0; i < arraysize(encoders); ++i) { | |
|
Owen Lin
2016/11/04 03:38:51
for (const auto& encoder : encoders) {
}
henryhsu
2016/11/04 04:15:17
Done.
| |
| 1762 if (!encoders[i]) | |
| 1763 continue; | |
| 1764 encoder_ = std::move(encoders[i]); | |
| 1765 if (encoder_->Initialize(kInputFormat, visible_size, | |
| 1766 VP8PROFILE_ANY, | |
| 1767 200000, this)) { | |
| 1768 encoder_->RequestEncodingParametersChange(200000, 30); | |
| 1769 SetState(CS_INITIALIZED); | |
| 1770 return; | |
| 1771 } | |
| 1772 } | |
| 1773 encoder_.reset(); | |
| 1774 LOG(ERROR) << "VideoEncodeAccelerator::Initialize() failed"; | |
| 1775 SetState(CS_ERROR); | |
| 1776 } | |
| 1777 | |
| 1778 void VEANoInputClient::DestroyEncoder() { | |
| 1779 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1780 if (!has_encoder()) | |
| 1781 return; | |
| 1782 // Clear the objects that should be destroyed on the same thread as creation. | |
| 1783 encoder_.reset(); | |
| 1784 timer_.reset(); | |
| 1785 } | |
| 1786 | |
| 1787 void VEANoInputClient::RequireBitstreamBuffers( | |
| 1788 unsigned int input_count, | |
| 1789 const gfx::Size& input_coded_size, | |
| 1790 size_t output_size) { | |
| 1791 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1792 SetState(CS_ENCODING); | |
| 1793 ASSERT_GT(output_size, 0UL); | |
| 1794 | |
| 1795 for (unsigned int i = 0; i < kNumOutputBuffers; ++i) { | |
| 1796 base::SharedMemory* shm = new base::SharedMemory(); | |
| 1797 LOG_ASSERT(shm->CreateAndMapAnonymous(output_size)); | |
| 1798 output_shms_.push_back(shm); | |
| 1799 FeedEncoderWithOutput(shm, output_size); | |
| 1800 } | |
| 1801 timer_.reset(new base::Timer( | |
| 1802 FROM_HERE, base::TimeDelta::FromMilliseconds(100), | |
|
Owen Lin
2016/11/04 03:38:51
Why 100 ms?
henryhsu
2016/11/04 04:15:17
frame rate is usually 30. 100 ms is about 3 frames
Owen Lin
2016/11/04 07:24:26
Acknowledged.
| |
| 1803 base::Bind(&VEANoInputClient::SetState, | |
| 1804 base::Unretained(this), CS_FINISHED), | |
| 1805 false)); | |
| 1806 timer_->Reset(); | |
| 1807 } | |
| 1808 | |
| 1809 void VEANoInputClient::BitstreamBufferReady(int32_t bitstream_buffer_id, | |
| 1810 size_t payload_size, | |
| 1811 bool key_frame, | |
| 1812 base::TimeDelta timestamp) { | |
| 1813 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1814 SetState(CS_ERROR); | |
| 1815 } | |
| 1816 | |
| 1817 void VEANoInputClient::NotifyError(VideoEncodeAccelerator::Error error) { | |
| 1818 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1819 SetState(CS_ERROR); | |
| 1820 } | |
| 1821 | |
| 1822 void VEANoInputClient::SetState(ClientState new_state) { | |
| 1823 DVLOG(4) << "Changing state " << state_ << "->" << new_state; | |
| 1824 note_->Notify(new_state); | |
| 1825 state_ = new_state; | |
| 1826 } | |
| 1827 | |
| 1828 void VEANoInputClient::FeedEncoderWithOutput(base::SharedMemory* shm, | |
| 1829 size_t output_size) { | |
| 1830 if (!has_encoder()) | |
| 1831 return; | |
| 1832 | |
| 1833 base::SharedMemoryHandle dup_handle; | |
| 1834 LOG_ASSERT(shm->ShareToProcess(base::GetCurrentProcessHandle(), &dup_handle)); | |
| 1835 | |
| 1836 BitstreamBuffer bitstream_buffer(next_output_buffer_id_++, dup_handle, | |
| 1837 output_size); | |
| 1838 encoder_->UseOutputBitstreamBuffer(bitstream_buffer); | |
| 1839 } | |
| 1840 | |
| 1679 // Test parameters: | 1841 // Test parameters: |
| 1680 // - Number of concurrent encoders. The value takes effect when there is only | 1842 // - Number of concurrent encoders. The value takes effect when there is only |
| 1681 // one input stream; otherwise, one encoder per input stream will be | 1843 // one input stream; otherwise, one encoder per input stream will be |
| 1682 // instantiated. | 1844 // instantiated. |
| 1683 // - If true, save output to file (provided an output filename was supplied). | 1845 // - If true, save output to file (provided an output filename was supplied). |
| 1684 // - Force a keyframe every n frames. | 1846 // - Force a keyframe every n frames. |
| 1685 // - Force bitrate; the actual required value is provided as a property | 1847 // - Force bitrate; the actual required value is provided as a property |
| 1686 // of the input stream, because it depends on stream type/resolution/etc. | 1848 // of the input stream, because it depends on stream type/resolution/etc. |
| 1687 // - If true, measure performance. | 1849 // - If true, measure performance. |
| 1688 // - If true, switch bitrate mid-stream. | 1850 // - If true, switch bitrate mid-stream. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1811 std::make_tuple(3, false, 0, false, false, false, false, false, false), | 1973 std::make_tuple(3, false, 0, false, false, false, false, false, false), |
| 1812 std::make_tuple(3, false, 0, true, false, false, true, false, false), | 1974 std::make_tuple(3, false, 0, true, false, false, true, false, false), |
| 1813 std::make_tuple(3, false, 0, true, false, true, false, false, false))); | 1975 std::make_tuple(3, false, 0, true, false, true, false, false, false))); |
| 1814 | 1976 |
| 1815 INSTANTIATE_TEST_CASE_P( | 1977 INSTANTIATE_TEST_CASE_P( |
| 1816 VerifyTimestamp, | 1978 VerifyTimestamp, |
| 1817 VideoEncodeAcceleratorTest, | 1979 VideoEncodeAcceleratorTest, |
| 1818 ::testing::Values( | 1980 ::testing::Values( |
| 1819 std::make_tuple(1, false, 0, false, false, false, false, false, true))); | 1981 std::make_tuple(1, false, 0, false, false, false, false, false, true))); |
| 1820 | 1982 |
| 1983 TEST(VEANoInputTest, CheckOutput) { | |
| 1984 std::unique_ptr<ClientStateNotification<ClientState>> note; | |
| 1985 std::unique_ptr<VEANoInputClient> client; | |
| 1986 base::Thread encoder_thread("EncoderThread"); | |
| 1987 ASSERT_TRUE(encoder_thread.Start()); | |
| 1988 | |
| 1989 // Create encoder. | |
| 1990 note.reset(new ClientStateNotification<ClientState>()); | |
|
Owen Lin
2016/11/04 03:38:51
why not merge the line with declaration.
henryhsu
2016/11/04 04:15:17
Done.
| |
| 1991 client.reset(new VEANoInputClient(note.get())); | |
| 1992 | |
| 1993 encoder_thread.task_runner()->PostTask( | |
| 1994 FROM_HERE, base::Bind(&VEANoInputClient::CreateEncoder, | |
| 1995 base::Unretained(client.get()))); | |
| 1996 | |
| 1997 // All encoders must pass through states in this order. | |
| 1998 enum ClientState state_transitions[] = { | |
| 1999 CS_INITIALIZED, CS_ENCODING, CS_FINISHED}; | |
| 2000 | |
| 2001 for (size_t state_no = 0; state_no < arraysize(state_transitions); | |
|
Owen Lin
2016/11/04 03:38:51
can we use range based for loop here as well.
henryhsu
2016/11/04 04:15:17
Done.
| |
| 2002 ++state_no) { | |
| 2003 ASSERT_EQ(note->Wait(), state_transitions[state_no]); | |
| 2004 } | |
| 2005 | |
| 2006 encoder_thread.task_runner()->PostTask( | |
| 2007 FROM_HERE, base::Bind(&VEANoInputClient::DestroyEncoder, | |
| 2008 base::Unretained(client.get()))); | |
| 2009 | |
| 2010 // This ensures all tasks have finished. | |
| 2011 encoder_thread.Stop(); | |
| 2012 } | |
| 2013 | |
| 1821 #elif defined(OS_MACOSX) || defined(OS_WIN) | 2014 #elif defined(OS_MACOSX) || defined(OS_WIN) |
| 1822 INSTANTIATE_TEST_CASE_P( | 2015 INSTANTIATE_TEST_CASE_P( |
| 1823 SimpleEncode, | 2016 SimpleEncode, |
| 1824 VideoEncodeAcceleratorTest, | 2017 VideoEncodeAcceleratorTest, |
| 1825 ::testing::Values( | 2018 ::testing::Values( |
| 1826 std::make_tuple(1, true, 0, false, false, false, false, false, false), | 2019 std::make_tuple(1, true, 0, false, false, false, false, false, false), |
| 1827 std::make_tuple(1, true, 0, false, false, false, false, true, false))); | 2020 std::make_tuple(1, true, 0, false, false, false, false, true, false))); |
| 1828 | 2021 |
| 1829 INSTANTIATE_TEST_CASE_P( | 2022 INSTANTIATE_TEST_CASE_P( |
| 1830 EncoderPerf, | 2023 EncoderPerf, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1941 | 2134 |
| 1942 media::g_env = | 2135 media::g_env = |
| 1943 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( | 2136 reinterpret_cast<media::VideoEncodeAcceleratorTestEnvironment*>( |
| 1944 testing::AddGlobalTestEnvironment( | 2137 testing::AddGlobalTestEnvironment( |
| 1945 new media::VideoEncodeAcceleratorTestEnvironment( | 2138 new media::VideoEncodeAcceleratorTestEnvironment( |
| 1946 std::move(test_stream_data), log_path, run_at_fps, | 2139 std::move(test_stream_data), log_path, run_at_fps, |
| 1947 needs_encode_latency, verify_all_output))); | 2140 needs_encode_latency, verify_all_output))); |
| 1948 | 2141 |
| 1949 return RUN_ALL_TESTS(); | 2142 return RUN_ALL_TESTS(); |
| 1950 } | 2143 } |
| OLD | NEW |