You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
MediaCodec: throw IOException for unimplemented codecs
fixes SEGFAULT when libavcodec is built without aac decoder
This commit is contained in:
@@ -60,6 +60,8 @@ JNIEXPORT jlong JNICALL Java_android_media_MediaCodec_native_1constructor(JNIEnv
|
|||||||
const char *name = (*env)->GetStringUTFChars(env, codec_name, NULL);
|
const char *name = (*env)->GetStringUTFChars(env, codec_name, NULL);
|
||||||
const AVCodec *codec = avcodec_find_decoder_by_name(name);
|
const AVCodec *codec = avcodec_find_decoder_by_name(name);
|
||||||
(*env)->ReleaseStringUTFChars(env, codec_name, name);
|
(*env)->ReleaseStringUTFChars(env, codec_name, name);
|
||||||
|
if (!codec)
|
||||||
|
return 0;
|
||||||
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
|
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
|
||||||
|
|
||||||
struct ATL_codec_context *ctx = calloc(1, sizeof(struct ATL_codec_context));
|
struct ATL_codec_context *ctx = calloc(1, sizeof(struct ATL_codec_context));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package android.media;
|
package android.media;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@@ -20,9 +21,12 @@ public class MediaCodec {
|
|||||||
private Queue<Integer> queuedInputBuffers;
|
private Queue<Integer> queuedInputBuffers;
|
||||||
private Queue<Integer> freeInputBuffers;
|
private Queue<Integer> freeInputBuffers;
|
||||||
|
|
||||||
private MediaCodec(String codecName) {
|
private MediaCodec(String codecName) throws IOException {
|
||||||
this.codecName = codecName;
|
this.codecName = codecName;
|
||||||
native_codec = native_constructor(codecName);
|
native_codec = native_constructor(codecName);
|
||||||
|
if (native_codec == 0) {
|
||||||
|
throw new IOException("Unable to create MediaCodec: " + codecName);
|
||||||
|
}
|
||||||
inputBuffers = new ByteBuffer[1];
|
inputBuffers = new ByteBuffer[1];
|
||||||
inputBufferTimestamps = new long[inputBuffers.length];
|
inputBufferTimestamps = new long[inputBuffers.length];
|
||||||
freeInputBuffers = new ArrayDeque<>(inputBuffers.length);
|
freeInputBuffers = new ArrayDeque<>(inputBuffers.length);
|
||||||
@@ -39,7 +43,7 @@ public class MediaCodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaCodec createByCodecName(String codecName) {
|
public static MediaCodec createByCodecName(String codecName) throws IOException {
|
||||||
return new MediaCodec(codecName);
|
return new MediaCodec(codecName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user