WebRTC: How to enable hardware acceleration for the video encoder

3.5k Views Asked by At

I'm trying to send video of screen capture to mediasoup with the help of WebRTC. There is a class for it in the WebRTC library: ScreenCapturerAndroid. It works, but the performance on the some devices is really bad. Especially if I use HD or better display resolutions.

On stackoverflow I've found a suggestion to call setEnableVideoHwAcceleration(true) and setVideoHwAccelerationOptions(). But in the newer versions of WebRTC library the methods have been removed .

Here is my code:

  // ...
PeerConnectionFactory.Builder builder = PeerConnectionFactory.builder();
builder.setOptions(null);

EglBase.Context eglContext = EglUtils.getRootEglBaseContext();

VideoEncoderFactory encoderFactory =
    new DefaultVideoEncoderFactory(
        eglContext, true /* enableIntelVp8Encoder */, true);


PeerConnectionFactory.InitializationOptions initializationOptions =
PeerConnectionFactory.InitializationOptions.builder(context)
//        .setEnableVideoHwAcceleration(true)  // <-- does not work any more 
        .createInitializationOptions();
PeerConnectionFactory.initialize(initializationOptions);

mPeerConnectionFactory =
    builder
        .setVideoEncoderFactory(encoderFactory)
        .createPeerConnectionFactory();

My question is: how can be video hardware acceleration enabled for screen capturing using the newer WebRTC library versions.

1

There are 1 best solutions below

0
On

it's depend on your device and what version of libwebrtc you used. So you can check webrtc source code to know HW support or not. That's mean the hardware acceleration of video encoder will not be support if your libwebrtc don't do some work for it in there source code. :P

So if your libwebrtc don't support it, then cannot see any thing fast even your setting in application level is correct.

So, let talk about how to check hardware acceleration of video encoder in libwebrtc.

Check this source code https://chromium.googlesource.com/external/webrtc/+/HEAD/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java

You can search the keyword in HardwareVideoEncoderFactory.java:
"isHardwareSupportedInCurrentSdk"

Today is Jan. 12 and I screen capture the code.

enter image description here

From the source code, they really show clear information.

By the way, you can also download some Media Codec Info App in GooglePlay to check different kind of encoder/decoder for different kind of android phone. That's would be helpful too.