Skip to content

Commit

Permalink
Fix simulcast using hardware encoder on Android (#7)
Browse files Browse the repository at this point in the history
* Fix simulcast using hardware encoder on Android

* Revert disabling apply_alignment_to_all_simulcast_layers

* Update HardwareVideoEncoder.java

---------

Co-authored-by: Angelika Serwa <[email protected]>
  • Loading branch information
kanat and graszka22 authored Sep 20, 2023
1 parent fcb7b09 commit 48dc75a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class HardwareVideoEncoder implements VideoEncoder {
private static final int MEDIA_CODEC_RELEASE_TIMEOUT_MS = 5000;
private static final int DEQUEUE_OUTPUT_BUFFER_TIMEOUT_US = 100000;

// Size of the input frames should be multiple of 16 for the H/W encoder.
private static final int REQUIRED_RESOLUTION_ALIGNMENT = 16;
// Size of the input frames should be multiple of 2 for the H/W encoder.
private static final int REQUIRED_RESOLUTION_ALIGNMENT = 2;

/**
* Keeps track of the number of output buffers that have been passed down the pipeline and not yet
Expand Down Expand Up @@ -210,6 +210,11 @@ public VideoCodecStatus initEncode(Settings settings, Callback callback) {
this.callback = callback;
automaticResizeOn = settings.automaticResizeOn;

if (settings.width % REQUIRED_RESOLUTION_ALIGNMENT != 0
|| settings.height % REQUIRED_RESOLUTION_ALIGNMENT != 0) {
Logging.e(TAG, "MediaCodec requires 2x2 alignment.");
return VideoCodecStatus.ERR_SIZE;
}
this.width = settings.width;
this.height = settings.height;
useSurfaceMode = canUseSurface();
Expand Down Expand Up @@ -533,6 +538,12 @@ private VideoCodecStatus resetCodec(int newWidth, int newHeight, boolean newUseS
if (status != VideoCodecStatus.OK) {
return status;
}

if (newWidth % REQUIRED_RESOLUTION_ALIGNMENT != 0
|| newHeight % REQUIRED_RESOLUTION_ALIGNMENT != 0) {
Logging.e(TAG, "MediaCodec requires 2x2 alignment.");
return VideoCodecStatus.ERR_SIZE;
}
width = newWidth;
height = newHeight;
useSurfaceMode = newUseSurfaceMode;
Expand Down

0 comments on commit 48dc75a

Please sign in to comment.