Switch encoder on any critical frame encode error (returncode < 0)

Before this change encoder switch was triggered only if encode() returns WEBRTC_VIDEO_CODEC_ENCODER_FAILURE. Android HW encoder wrapper never return this error code. It returns WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE [1, 2] or WEBRTC_VIDEO_CODEC_ERROR [3].

Change value of WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT from -14 to 5 to avoid it to be interpreted as a critical error.

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/sdk/android/src/jni/video_encoder_wrapper.cc;drc=c05a1be5b49f5c03b6955b05bcbf47609e1b0381;l=324

[2] https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/sdk/android/src/jni/video_encoder_wrapper.cc;drc=c05a1be5b49f5c03b6955b05bcbf47609e1b0381;l=335

[3] https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/sdk/android/src/jni/video_encoder_wrapper.cc;drc=c05a1be5b49f5c03b6955b05bcbf47609e1b0381;l=331

Bug: b/243402636
Change-Id: Iaf0129f3f9d71c07bb06804fe1f92a1f84f6da26
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/274402
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38060}
This commit is contained in:
Sergey Silkin 2022-09-12 11:40:04 +02:00 committed by WebRTC LUCI CQ
parent a22c2a0c58
commit ceb71cd557
3 changed files with 6 additions and 12 deletions

View File

@ -15,6 +15,7 @@
// Define return values // Define return values
#define WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT 5
#define WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME 4 #define WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME 4
#define WEBRTC_VIDEO_CODEC_NO_OUTPUT 1 #define WEBRTC_VIDEO_CODEC_NO_OUTPUT 1
#define WEBRTC_VIDEO_CODEC_OK 0 #define WEBRTC_VIDEO_CODEC_OK 0
@ -23,7 +24,6 @@
#define WEBRTC_VIDEO_CODEC_ERR_PARAMETER -4 #define WEBRTC_VIDEO_CODEC_ERR_PARAMETER -4
#define WEBRTC_VIDEO_CODEC_UNINITIALIZED -7 #define WEBRTC_VIDEO_CODEC_UNINITIALIZED -7
#define WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE -13 #define WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE -13
#define WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT -14
#define WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED -15 #define WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED -15
#define WEBRTC_VIDEO_CODEC_ENCODER_FAILURE -16 #define WEBRTC_VIDEO_CODEC_ENCODER_FAILURE -16

View File

@ -15,6 +15,7 @@ package org.webrtc;
* video_error_codes.h. * video_error_codes.h.
*/ */
public enum VideoCodecStatus { public enum VideoCodecStatus {
TARGET_BITRATE_OVERSHOOT(5),
REQUEST_SLI(2), REQUEST_SLI(2),
NO_OUTPUT(1), NO_OUTPUT(1),
OK(0), OK(0),
@ -26,8 +27,7 @@ public enum VideoCodecStatus {
TIMEOUT(-6), TIMEOUT(-6),
UNINITIALIZED(-7), UNINITIALIZED(-7),
ERR_REQUEST_SLI(-12), ERR_REQUEST_SLI(-12),
FALLBACK_SOFTWARE(-13), FALLBACK_SOFTWARE(-13);
TARGET_BITRATE_OVERSHOOT(-14);
private final int number; private final int number;

View File

@ -1894,15 +1894,9 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
was_encode_called_since_last_initialization_ = true; was_encode_called_since_last_initialization_ = true;
if (encode_status < 0) { if (encode_status < 0) {
if (encode_status == WEBRTC_VIDEO_CODEC_ENCODER_FAILURE) { RTC_LOG(LS_ERROR) << "Encoder failed, failing encoder format: "
RTC_LOG(LS_ERROR) << "Encoder failed, failing encoder format: " << encoder_config_.video_format.ToString();
<< encoder_config_.video_format.ToString(); RequestEncoderSwitch();
RequestEncoderSwitch();
} else {
RTC_LOG(LS_ERROR) << "Failed to encode frame. Error code: "
<< encode_status;
}
return; return;
} }