MediaCodec: add mp3 and opus codecs

This commit is contained in:
Julian Winkler
2025-01-26 22:27:19 +01:00
parent 0091fd6b59
commit 68e32eab45
3 changed files with 34 additions and 12 deletions

View File

@@ -54,14 +54,18 @@ public class MediaCodec {
outputBuffers = new ByteBuffer[2];
freeOutputBuffers = new ArrayDeque<>(outputBuffers.length);
for (int i = 0; i < outputBuffers.length; i++) {
outputBuffers[i] = ByteBuffer.allocate(4096).order(ByteOrder.LITTLE_ENDIAN);
outputBuffers[i] = ByteBuffer.allocate(8192).order(ByteOrder.LITTLE_ENDIAN);
freeOutputBuffers.add(i);
}
if ("aac".equals(codecName)) {
if ("aac".equals(codecName) || "mp3".equals(codecName) || "opus".equals(codecName)) {
native_configure_audio(native_codec, format.getByteBuffer("csd-0"), format.getInteger("sample-rate"), format.getInteger("channel-count"));
} else if ("h264".equals(codecName)) {
native_configure_video(native_codec, format.getByteBuffer("csd-0"), format.getByteBuffer("csd-1"), surface);
} else {
System.out.println("configure: format " + format + " not implemented");
Thread.dumpStack();
System.exit(1);
}
}

View File

@@ -3,7 +3,7 @@ package android.media;
public class MediaCodecList {
public static int getCodecCount() {
return 2;
return 4;
}
public static MediaCodecInfo getCodecInfoAt(int index) {
@@ -12,6 +12,10 @@ public class MediaCodecList {
return new MediaCodecInfo("aac", "audio/mp4a-latm");
case 1:
return new MediaCodecInfo("h264", "video/avc");
case 2:
return new MediaCodecInfo("mp3", "audio/mpeg");
case 3:
return new MediaCodecInfo("opus", "audio/opus");
default:
return null;
}