| 1 | #include "benchmark_vaapi.h" |
| 2 | |
| 3 | #include "api/environment/environment_factory.h" |
| 4 | #include "modules/video_coding/codecs/h264/include/h264.h" |
| 5 | #include "fileutils.h" |
| 6 | |
| 7 | using namespace webrtc; |
| 8 | |
| 9 | VaapiBenchmark::VaapiBenchmark() |
| 10 | : Benchmark("VaapiBenchmark", |
| 11 | "VAAPI benchmark over a range of test cases", |
| 12 | webrtc::test::OutputPath() + "VaapiBenchmark.txt", |
| 13 | "vaapi_bitstream_output.h264") {} |
| 14 | |
| 15 | VaapiBenchmark::VaapiBenchmark(std::string name, std::string description) |
| 16 | : Benchmark(name, |
| 17 | description, |
| 18 | webrtc::test::OutputPath() + "VaapiBenchmark.txt", |
| 19 | "vaapi_bitstream_output.h264") {} |
| 20 | |
| 21 | VaapiBenchmark::VaapiBenchmark(std::string name, |
| 22 | std::string description, |
| 23 | std::string resultsFileName) |
| 24 | : Benchmark(name, description, resultsFileName, "vaapi_bitstream_output.h264") {} |
| 25 | |
| 26 | VideoEncoder* VaapiBenchmark::GetNewEncoder(webrtc::Environment &env) { |
| 27 | if (!VAAPIVideoEncoderFactory::IsSupported()) { |
| 28 | fprintf(stderr, "VAAPI is not supported on this system.\n"); |
| 29 | return nullptr; |
| 30 | } |
| 31 | if (!_factory) { |
| 32 | _factory = std::make_unique<VAAPIVideoEncoderFactory>(); |
| 33 | } |
| 34 | std::map<std::string, std::string> baselineParameters = { |
| 35 | {"profile-level-id", "4d0032"}, |
| 36 | {"level-asymmetry-allowed", "1"}, |
| 37 | {"packetization-mode", "1"}, |
| 38 | }; |
| 39 | auto format = SdpVideoFormat("H264", baselineParameters); |
| 40 | |
| 41 | auto enc = _factory->Create(env, format); |
| 42 | if (!enc) { |
| 43 | fprintf(stderr, "Failed to create H264 encoder.\n"); |
| 44 | return nullptr; |
| 45 | } |
| 46 | _encoder = std::move(enc); |
| 47 | |
| 48 | return _encoder.get(); |
| 49 | } |