Reputation: 65
I'm making WebRTC-node.js service based on this source. I want to make video chat between PC(Chrome) and mobile(Android Chrome) at HD resolution(1280x720).
When I set the constraints to 1280x720, bandwidth to 2000 and tested, the video from mobile has good quality(1280x720) at first but fall to low quality after few seconds while the video from PC maintain good quality.
I read this QnA: Why does video resolution change when streaming from Android via WebRTC
It says:
The degradation you're seeing is in the PeerConnection layer, not in the getUserMedia layer. Degradation is triggered by the webrtc implementation when hardware and bandwidth statistics are indicative of low performance, and is negotiated by both sides.
For some bandwidth suspicions, I tested in local network too, but the result was same. And instead node.js, I tried XSockets.WebRTC but the result was same.
So, how can I maintain HD resolution from android mobile? Is that a Chrome-vp8 issue?
I need your help. Thank you.
Upvotes: 2
Views: 5189
Reputation: 187
WebRTC has introduced RTCDegradationPreference ref: https://w3c.github.io/mst-content-hint/#dom-rtcrtpsendparameters-degradationpreference
With this, developers can choose how WebRTC should behave when the device's condition (bandwidth, CPU) degrades. To use this in Android, one might do something like so:
RtpParameters parameters = localPeer.getSenders().get(0).getParameters();
parameters.degradationPreference = RtpParameters.DegradationPreference.MAINTAIN_RESOLUTION;
Make sure to use the latest version of WebRTC to have access to this API. If, for some reasons, you are stuck with older version of WebRTC, use this alternative hack to disable CPU Overuse detection (assuming this is the reason why your resolution goes down, if it is because of bandwidth, then your only option is to reduce the FPS)
MediaConstraints constraints = new MediaConstraints();
constraints.optional.add(new MediaConstraints.KeyValuePair("googCpuOveruseDetection", "false"));
localPeer.createAnswer(new SdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
}
@Override
public void onSetSuccess() {
}
@Override
public void onCreateFailure(String s) {
}
@Override
public void onSetFailure(String s) {
}
}, constraints);
Hope that helps
Upvotes: 1
Reputation: 5662
To maintain stable video quality you have to set enableCpuOveruseDetection
flag to false
in RTCConfiguration
of PeerConnection
and make sure VideoCapture
set desire video resolution using startCapture
method (you can use getSupportedFormats
of CameraEnumerator
to get reasonable supported video resolution of phone camera).
This give you stable HD video resolution (if you set it by startCapture
) and higher (unless bandwidth is sufficient), but downside it may increase battery consumption and may lead to cpu overheat (especially for some old Android phones).
factory.createPeerConnection(PeerConnection.RTCConfiguration(iceServers).apply {
...
enableCpuOveruseDetection = false
}, object : PeerConnection.Observer {
...
})
Upvotes: 4
Reputation: 341
In WebRTC official repository https://chromium.googlesource.com/external/webrtc/
The file /talk/media/base/videoadapter.cc shows that WebRTC would reduce video resolution according to device CPU load. This feature is enabled by default.
I built the native iOS app with video adapter disabled, but the 720p video is not smoothly enough in iPhone 6s.
Upvotes: 0