Repository navigation
Automatically retry with a lower definition on MediaCodec error - #2947
Conversation
|
There is a problem with the initial size: if the device downsize the video stream before the first frame, the window initial size will also be scaled down. I will work on it. |
I fixed it and updated the binaries in the thread. Please test :) |
3a0a68f to
8af00e8
Compare
|
I updated to downsize on error only before the first frame. The purpose of automatic downscaling on error is to make mirroring work by just starting scrcpy without an explicit -m value, even if the encoder could not encode at the screen definition. If it fails later, just fail, resizing at any time might be unexpected, so disable it. |
|
Hi rom1v, Following this commit, I wonder if it will helps on my phone. I have a Pixel 2 XL, and trying to use an encoder that is listed which is the "OMX.google.h264.encoder" encoder. When trying to launch scrcpy and get the frames, I'm having this error :
Looking at some issues and the FAQ, it looks a lot like this problem : https://github.com/Genymobile/scrcpy/blob/master/FAQ.md#exception If I understand well, this commit is potentially "correcting" this problem by lowering the definition. Am I right ? Thanks |
The change is mainly in the server (which will retry), so yes, it will help (you need both the client and server) :D |
The optimal initial size was computed from the expected dimensions, sent immediately by the server before encoding any video frame. However, the actual frame size may be different, for example when the device encoder does not support the requested size. To always handle this case properly, position and size the window only once the first frame size is known. PR #2947 <#2947>
The purpose of automatic downscaling on error is to make mirroring work by just starting scrcpy without an explicit -m value, even if the encoder could not encode at the screen definition. It is only useful when we detect an encoding failure before the first frame. Downsizing later could be surprising, so disable it. PR #2947 <#2947>
8af00e8 to
2eb6fe7
Compare
|
This change has fixed an issue with Galaxy A32 that always failed to mirror. |
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
ERROR: Exception on thread Thread[main,5,main]
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
The new retry mechanism with a lower definition only worked if the error
occurred during encode(). For example:
java.lang.IllegalStateException
at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method)
at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:3452)
at com.genymobile.scrcpy.ScreenEncoder.encode(ScreenEncoder.java:114)
at com.genymobile.scrcpy.ScreenEncoder.internalStreamScreen(ScreenEncoder.java:95)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:61)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:80)
at com.genymobile.scrcpy.Server.main(Server.java:255)
However, MediaCodec may also fail before encoding, during configure() or
start(). For example:
android.media.MediaCodec$CodecException: Error 0xfffffc0e
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:1956)
at android.media.MediaCodec.configure(MediaCodec.java:1885)
at com.genymobile.scrcpy.ScreenEncoder.configure(ScreenEncoder.java:158)
at com.genymobile.scrcpy.ScreenEncoder.streamScreen(ScreenEncoder.java:68)
at com.genymobile.scrcpy.Server.scrcpy(Server.java:28)
at com.genymobile.scrcpy.Server.main(Server.java:110)
Also downscale and retry in these cases.
Refs #2947 <#2947>
Refs #2988 <#2988>
PR #2990 <#2990>
A mechanism was introduced to retry capture at a lower resolution to support devices unable to encode at the device screen resolution. While useful, this approach is inherentlylimited and will not be able to handle the dynamic resizing required for resizable virtual displays. Disable this mechanism entirely. Further commits will add support for adjusting the size in advance according to video encoder capababilities. Refs #2947 <#2947>
A mechanism was introduced to retry capture at a lower resolution to support devices unable to encode at the device screen resolution. While useful, this approach is inherently limited and will not be able to handle the dynamic resizing required for resizable virtual displays. Disable this mechanism entirely. Further commits will add support for adjusting the size in advance according to video encoder capababilities. Refs #2947 <#2947>
A mechanism was introduced to retry capture at a lower resolution to support devices unable to encode at the device screen resolution. While useful, this approach is inherently limited and will not be able to handle the dynamic resizing required for resizable virtual displays. Disable this mechanism entirely. Further commits will add support for adjusting the size in advance according to video encoder capabilities. Refs #2947 <#2947>
A mechanism was introduced to retry capture at a lower resolution to support devices unable to encode at the device screen resolution. While useful, this approach is inherently limited and will not be able to handle the dynamic resizing required for resizable virtual displays. Disable this mechanism entirely. Further commits will add support for adjusting the size in advance according to video encoder capabilities. Refs #2947 <#2947> PR #6766 <#6766>
The mechanism to retry capture at a lower resolution on error was removed in favor of using video encoder capabilities instead. However, an encoder configuration that is compatible with the declared capabilities may still fail, either because the declared capabilities are incorrect or because some resources are unavailable. Restore the downsize-on-error behavior for such cases. This reverts commit 4f97e2e. Refs #2947 <#2947> Refs #6766 <#6766>
The mechanism to retry capture at a lower resolution on error was removed in favor of using video encoder capabilities instead. However, an encoder configuration that is compatible with the declared capabilities may still fail, either because the declared capabilities are incorrect or because some resources are unavailable. Restore the downsize-on-error behavior for such cases. This reverts commit 4f97e2e. Refs #2947 <#2947> Refs #6766 <#6766> PR #6822 <#6822>
Some devices are not able to encode at the device screen definition.
Instead of just failing, automatically try with a lower definition (fallback) on any MediaCodec error.
This is a recurrent issue for new users. The solution is explained in the FAQ (and sometimes in the error message, depending on the error), but it will help a lot if scrcpy automatically retries with different "max size" values.
An option
--no-downsize-on-erroris also added to disable this behavior.Here are binaries (replace in your v1.21 release):
scrcpy.exesha256:bdf50503f7f0f2771758abd877344e10a7cd37d3b3539bef2d80c7323807a41escrcpy-serversha256:c2edcdb775776d5bca93fe04ca37159c7dc2cd36a6b7619e583c702e75eaa855v2 (obsolete)
scrcpy.exesha256:9f43f1ef5452b0a826cce78740fd2b93582b36accd5b9295796322c1ee02c5f8scrcpy-serversha256:86d9c13a88f9523150017c50061bf04b5ad234808139df31b337c2701e6b3791v1 (obsolete)
scrcpy.exesha256:d5043a52eb572b445ffc4410d8327bb363258d0303dd645bc56423805296694dscrcpy-serversha256:86d9c13a88f9523150017c50061bf04b5ad234808139df31b337c2701e6b3791I don't have any device which actually fails, so tests and feedback are welcome.