@@ -45,8 +45,8 @@ class HardwareVideoEncoder implements VideoEncoder {
4545 private static final int MEDIA_CODEC_RELEASE_TIMEOUT_MS = 5000 ;
4646 private static final int DEQUEUE_OUTPUT_BUFFER_TIMEOUT_US = 100000 ;
4747
48- // Size of the input frames should be multiple of 16 for the H/W encoder.
49- private static final int REQUIRED_RESOLUTION_ALIGNMENT = 16 ;
48+ // Size of the input frames should be multiple of 2 for the H/W encoder.
49+ private static final int REQUIRED_RESOLUTION_ALIGNMENT = 2 ;
5050
5151 /**
5252 * Keeps track of the number of output buffers that have been passed down the pipeline and not yet
@@ -210,6 +210,11 @@ public VideoCodecStatus initEncode(Settings settings, Callback callback) {
210210 this .callback = callback ;
211211 automaticResizeOn = settings .automaticResizeOn ;
212212
213+ if (settings .width % REQUIRED_RESOLUTION_ALIGNMENT != 0
214+ || settings .height % REQUIRED_RESOLUTION_ALIGNMENT != 0 ) {
215+ Logging .e (TAG , "MediaCodec requires 2x2 alignment." );
216+ return VideoCodecStatus .ERR_SIZE ;
217+ }
213218 this .width = settings .width ;
214219 this .height = settings .height ;
215220 useSurfaceMode = canUseSurface ();
@@ -533,6 +538,12 @@ private VideoCodecStatus resetCodec(int newWidth, int newHeight, boolean newUseS
533538 if (status != VideoCodecStatus .OK ) {
534539 return status ;
535540 }
541+
542+ if (newWidth % REQUIRED_RESOLUTION_ALIGNMENT != 0
543+ || newHeight % REQUIRED_RESOLUTION_ALIGNMENT != 0 ) {
544+ Logging .e (TAG , "MediaCodec requires 2x2 alignment." );
545+ return VideoCodecStatus .ERR_SIZE ;
546+ }
536547 width = newWidth ;
537548 height = newHeight ;
538549 useSurfaceMode = newUseSurfaceMode ;
0 commit comments