| 1 | #include "benchmark_nvidia.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 | NvidiaBenchmark::NvidiaBenchmark() |
| 10 | : Benchmark("NvidiaBenchmark", |
| 11 | "Nvidia benchmark over a range of test cases", |
| 12 | webrtc::test::OutputPath() + "NvidiaBenchmark.txt", |
| 13 | "nvidia_bitstream_output.h264") {} |
| 14 | |
| 15 | NvidiaBenchmark::NvidiaBenchmark(std::string name, std::string description) |
| 16 | : Benchmark(name, |
| 17 | description, |
| 18 | webrtc::test::OutputPath() + "NvidiaBenchmark.txt", |
| 19 | "nvidia_bitstream_output.h264") {} |
| 20 | |
| 21 | NvidiaBenchmark::NvidiaBenchmark(std::string name, |
| 22 | std::string description, |
| 23 | std::string resultsFileName) |
| 24 | : Benchmark(name, description, resultsFileName, "nvidia_bitstream_output.h264") {} |
| 25 | |
| 26 | |
| 27 | VideoEncoder* NvidiaBenchmark::GetNewEncoder(webrtc::Environment &env) { |
| 28 | if (!NvidiaVideoEncoderFactory::IsSupported()) { |
| 29 | fprintf(stderr, "NVIDIA is not supported on this system.\n"); |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
| 33 | if (!_factory) { |
| 34 | _factory = std::make_unique<NvidiaVideoEncoderFactory>(); |
| 35 | } |
| 36 | std::map<std::string, std::string> baselineParameters = { |
| 37 | {"profile-level-id", "42e01f"}, |
| 38 | {"level-asymmetry-allowed", "1"}, |
| 39 | {"packetization-mode", "1"}, |
| 40 | }; |
| 41 | auto format = SdpVideoFormat("H264", baselineParameters); |
| 42 | |
| 43 | auto enc = _factory->Create(env, format); |
| 44 | if (!enc) { |
| 45 | fprintf(stderr, "Failed to create H264 encoder.\n"); |
| 46 | return nullptr; |
| 47 | } |
| 48 | _encoder = std::move(enc); |
| 49 | |
| 50 | return _encoder.get(); |
| 51 | } |