mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-22 16:26:41 +00:00
Only throw the codec exception on the last configuration attempt
This commit is contained in:
@@ -385,10 +385,35 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryConfigureDecoder(MediaCodecInfo selectedDecoderInfo, MediaFormat format) throws IOException {
|
private boolean tryConfigureDecoder(MediaCodecInfo selectedDecoderInfo, MediaFormat format, boolean throwOnCodecError) {
|
||||||
videoDecoder = MediaCodec.createByCodecName(selectedDecoderInfo.getName());
|
boolean configured = false;
|
||||||
configureAndStartDecoder(format);
|
try {
|
||||||
LimeLog.info("Using codec " + selectedDecoderInfo.getName() + " for hardware decoding " + format.getString(MediaFormat.KEY_MIME));
|
videoDecoder = MediaCodec.createByCodecName(selectedDecoderInfo.getName());
|
||||||
|
configureAndStartDecoder(format);
|
||||||
|
LimeLog.info("Using codec " + selectedDecoderInfo.getName() + " for hardware decoding " + format.getString(MediaFormat.KEY_MIME));
|
||||||
|
configured = true;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
if (throwOnCodecError) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
if (throwOnCodecError) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
if (throwOnCodecError) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (!configured && videoDecoder != null) {
|
||||||
|
videoDecoder.release();
|
||||||
|
videoDecoder = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return configured;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int initializeDecoder(boolean throwOnCodecError) {
|
public int initializeDecoder(boolean throwOnCodecError) {
|
||||||
@@ -449,8 +474,7 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
adaptivePlayback = MediaCodecHelper.decoderSupportsAdaptivePlayback(selectedDecoderInfo, mimeType);
|
adaptivePlayback = MediaCodecHelper.decoderSupportsAdaptivePlayback(selectedDecoderInfo, mimeType);
|
||||||
fusedIdrFrame = MediaCodecHelper.decoderSupportsFusedIdrFrame(selectedDecoderInfo, mimeType);
|
fusedIdrFrame = MediaCodecHelper.decoderSupportsFusedIdrFrame(selectedDecoderInfo, mimeType);
|
||||||
|
|
||||||
boolean configured = false;
|
for (int tryNumber = 0;; tryNumber++) {
|
||||||
for (int tryNumber = 0; !configured; tryNumber++) {
|
|
||||||
LimeLog.info("Decoder configuration try: "+tryNumber);
|
LimeLog.info("Decoder configuration try: "+tryNumber);
|
||||||
|
|
||||||
MediaFormat mediaFormat = createBaseMediaFormat(mimeType);
|
MediaFormat mediaFormat = createBaseMediaFormat(mimeType);
|
||||||
@@ -458,32 +482,13 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
|
|||||||
// This will try low latency options until we find one that works (or we give up).
|
// This will try low latency options until we find one that works (or we give up).
|
||||||
boolean newFormat = MediaCodecHelper.setDecoderLowLatencyOptions(mediaFormat, selectedDecoderInfo, tryNumber);
|
boolean newFormat = MediaCodecHelper.setDecoderLowLatencyOptions(mediaFormat, selectedDecoderInfo, tryNumber);
|
||||||
|
|
||||||
try {
|
// Throw the underlying codec exception on the last attempt if the caller requested it
|
||||||
tryConfigureDecoder(selectedDecoderInfo, mediaFormat);
|
if (tryConfigureDecoder(selectedDecoderInfo, mediaFormat, !newFormat && throwOnCodecError)) {
|
||||||
configured = true;
|
// Success!
|
||||||
} catch (IllegalArgumentException e) {
|
break;
|
||||||
e.printStackTrace();
|
|
||||||
if (throwOnCodecError) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
if (throwOnCodecError) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
if (throwOnCodecError) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (!configured && videoDecoder != null) {
|
|
||||||
videoDecoder.release();
|
|
||||||
videoDecoder = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configured && !newFormat) {
|
if (!newFormat) {
|
||||||
// We couldn't even configure a decoder without any low latency options
|
// We couldn't even configure a decoder without any low latency options
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user