Skip to content

Commit dc3a0a4

Browse files
committed
feat: encode VP9 with VA-API on Linux without turning it on
webrtc.hardware.vp9Encoder now only turns on the Media Foundation VP9 encoder on Windows, which is still untested.
1 parent 0139725 commit dc3a0a4

7 files changed

Lines changed: 19 additions & 27 deletions

File tree

‎docs/guide/advanced/video-codecs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ PeerConnectionFactory factory = PeerConnectionFactory.builder()
3232

3333
Hardware encoders produce a single layer. A stream that asks for SVC, such as an AV1 stream with a scalability mode like `L1T3`, is encoded in software.
3434

35-
VP9 can be encoded in hardware too, with the VP9 encoder of the GPU driver, which Intel GPUs have: through Media Foundation on Windows and VA-API on Linux. It is off by default, since it has not been tested on such a GPU yet; turn it on with a system property before the factory is created:
35+
VP9 can be encoded in hardware too, with the VP9 encoder of the GPU driver, which Intel GPUs have: through VA-API on Linux, and through Media Foundation on Windows. On Windows it is off by default, since it has not been tested on such a GPU yet; turn it on with a system property before the factory is created:
3636

3737
```java
3838
System.setProperty("webrtc.hardware.vp9Encoder", "true");

‎webrtc-jni/src/main/cpp/include/media/video/codec/HardwareCodecOptions.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
namespace jni
2121
{
22-
// The Java system property that turns on hardware VP9 encoding, which is
23-
// off by default: only Intel GPUs encode VP9, and the encoder has not been
24-
// tested on one.
22+
// The Java system property that turns on hardware VP9 encoding on
23+
// Windows, which is off by default: only Intel GPUs encode VP9, and the
24+
// Media Foundation encoder has not been tested on one. VA-API encodes VP9
25+
// on Linux regardless.
2526
constexpr const char * kHardwareVp9EncoderProperty = "webrtc.hardware.vp9Encoder";
2627

2728
// Whether hardware VP9 encoding is turned on: the Java system property

‎webrtc-jni/src/main/cpp/include/media/video/codec/linux/VaapiVideoEncoderFactory.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ namespace jni
3232
// Creates VA-API encoders on the GPU whose driver encodes H.264, as Intel
3333
// and AMD drivers do. It offers H.264 in the profiles WebRTC's software
3434
// encoder offers too, and only with packetization mode 1: mode 0 needs
35-
// each NAL unit to fit a packet. It offers H.265 Main as well where the
36-
// driver encodes it, and VP9 profile 0 where the driver encodes it and
37-
// hardware VP9 encoding is turned on.
35+
// each NAL unit to fit a packet. It offers H.265 Main and VP9 profile 0
36+
// as well where the driver encodes them.
3837
class VaapiVideoEncoderFactory : public webrtc::VideoEncoderFactory
3938
{
4039
public:
4140
// Returns a factory, or null if no GPU driver encodes H.264
4241
// through VA-API.
43-
static std::unique_ptr<VaapiVideoEncoderFactory> Create(bool vp9Enabled);
42+
static std::unique_ptr<VaapiVideoEncoderFactory> Create();
4443

4544
~VaapiVideoEncoderFactory() override = default;
4645

‎webrtc-jni/src/main/cpp/src/media/video/codec/linux/LinuxHardwareVideoCodecFactories.cpp‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "media/video/codec/HardwareCodecOptions.h"
1817
#include "media/video/codec/HardwareVideoDecoderFactory.h"
1918
#include "media/video/codec/HardwareVideoEncoderFactory.h"
2019
#include "media/video/codec/linux/VaapiVideoDecoderFactory.h"
@@ -33,10 +32,7 @@ namespace jni
3332
if (auto nvenc = NvencVideoEncoderFactory::Create()) {
3433
factories.push_back(std::move(nvenc));
3534
}
36-
// VP9 only if asked for: it has not been tested on an Intel GPU yet.
37-
auto vaapi = VaapiVideoEncoderFactory::Create(IsHardwareVp9EncoderEnabled());
38-
39-
if (vaapi) {
35+
if (auto vaapi = VaapiVideoEncoderFactory::Create()) {
4036
factories.push_back(std::move(vaapi));
4137
}
4238

‎webrtc-jni/src/main/cpp/src/media/video/codec/linux/VaapiVideoEncoderFactory.cpp‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace jni
2929
{
30-
std::unique_ptr<VaapiVideoEncoderFactory> VaapiVideoEncoderFactory::Create(bool vp9Enabled)
30+
std::unique_ptr<VaapiVideoEncoderFactory> VaapiVideoEncoderFactory::Create()
3131
{
3232
VaapiLibrary * library = VaapiLibrary::Get();
3333

@@ -39,13 +39,10 @@ namespace jni
3939
const bool h265 = library->EncodeEntrypoint(VAProfileHEVCMain, &h265Entrypoint);
4040

4141
VAEntrypoint vp9Entrypoint = VAEntrypointEncSlice;
42-
const bool vp9 = vp9Enabled && library->EncodeEntrypoint(VAProfileVP9Profile0, &vp9Entrypoint);
42+
const bool vp9 = library->EncodeEntrypoint(VAProfileVP9Profile0, &vp9Entrypoint);
4343

44-
RTC_LOG(LS_INFO) << "VA-API (" << library->Vendor() << ") H.265 encoding: " << h265;
45-
46-
if (vp9Enabled) {
47-
RTC_LOG(LS_INFO) << "VA-API (" << library->Vendor() << ") VP9 encoding: " << vp9;
48-
}
44+
RTC_LOG(LS_INFO) << "VA-API (" << library->Vendor() << ") H.265 encoding: " << h265 << ", VP9 encoding: "
45+
<< vp9;
4946

5047
return std::unique_ptr<VaapiVideoEncoderFactory>(
5148
new VaapiVideoEncoderFactory(*library, h265, h265Entrypoint, vp9, vp9Entrypoint));

‎webrtc/src/main/java/dev/onvoid/webrtc/media/video/codec/HardwareVideoEncoderFactory.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
* stream that asks for SVC is encoded in software. H.265 (Main profile) is
4242
* encoded with NVENC or Media Foundation on GPUs that have an H.265 encoder.
4343
* VP9 (profile 0) is encoded on GPUs that have a VP9 encoder, which are
44-
* Intel's, with Media Foundation on Windows and VA-API on Linux, but only
45-
* with the system property
46-
* {@code webrtc.hardware.vp9Encoder} set to {@code true} when the factory is
47-
* created: the encoder has not been tested on such a GPU yet. Without it, VP9
48-
* is encoded with libvpx. On Linux, H.265 is encoded with NVENC on NVIDIA
44+
* Intel's: with VA-API on Linux, and with Media Foundation on Windows only
45+
* with the system property {@code webrtc.hardware.vp9Encoder} set to
46+
* {@code true} when the factory is created, since that encoder has not been
47+
* tested on such a GPU yet. Otherwise VP9 is encoded with libvpx. On Linux, H.265 is encoded with NVENC on NVIDIA
4948
* GPUs and with VA-API on the GPUs of Intel and AMD whose driver encodes it.
5049
* A hardware encoder that fails to start, for example because the GPU has no
5150
* encoder sessions left, or fails while encoding, is replaced by the next one

‎webrtc/src/test/java/dev/onvoid/webrtc/HardwareVideoEncoderIntegrationTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ private PeerConnectionFactory hardwareCallFactory() {
275275

276276
@Test
277277
void vp9HardwareEncodingIsOptIn() throws Exception {
278-
assumeTrue(OS.contains("win") || OS.contains("linux"),
279-
"hardware encoders are implemented on Windows and Linux only");
278+
// On Linux, VA-API encodes VP9 without it.
279+
assumeTrue(OS.contains("win"), "hardware VP9 encoding is opt-in on Windows only");
280280
assumeTrue(System.getProperty(VP9_ENCODER_PROPERTY) == null, VP9_ENCODER_PROPERTY + " is set");
281281

282282
PeerConnectionFactory hardware = hardwareFactory();

0 commit comments

Comments
 (0)