mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-12-24 12:27:57 +08:00
Fixing execution on Android
This commit is contained in:
121
docker/termux/ffmpeg_mediacodec_set_parameters.patch
Normal file
121
docker/termux/ffmpeg_mediacodec_set_parameters.patch
Normal file
@@ -0,0 +1,121 @@
|
||||
commit e01e33bde9fe5cc6bed67dd3e445a386d2d40608
|
||||
Author: Dmitrii Okunev <xaionaro@dx.center>
|
||||
Date: Sun Apr 20 17:54:21 2025 +0100
|
||||
|
||||
Add MediaCodec function setParameters
|
||||
|
||||
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
|
||||
index 283bbe72d6..660adf4d40 100644
|
||||
--- a/libavcodec/mediacodec_wrapper.c
|
||||
+++ b/libavcodec/mediacodec_wrapper.c
|
||||
@@ -192,6 +192,8 @@ struct JNIAMediaCodecFields {
|
||||
jmethodID release_output_buffer_id;
|
||||
jmethodID release_output_buffer_at_time_id;
|
||||
|
||||
+ jmethodID set_parameters_id;
|
||||
+
|
||||
jmethodID set_input_surface_id;
|
||||
jmethodID signal_end_of_input_stream_id;
|
||||
|
||||
@@ -234,6 +236,8 @@ static const struct FFJniField jni_amediacodec_mapping[] = {
|
||||
|
||||
{ "android/media/MediaCodec", "getOutputFormat", "()Landroid/media/MediaFormat;", FF_JNI_METHOD, OFFSET(get_output_format_id), 1 },
|
||||
|
||||
+ { "android/media/MediaCodec", "setParameters", "(Landroid/media/MediaFormat;)V", FF_JNI_METHOD, OFFSET(set_parameters_id), 1 },
|
||||
+
|
||||
{ "android/media/MediaCodec", "dequeueInputBuffer", "(J)I", FF_JNI_METHOD, OFFSET(dequeue_input_buffer_id), 1 },
|
||||
{ "android/media/MediaCodec", "queueInputBuffer", "(IIIJI)V", FF_JNI_METHOD, OFFSET(queue_input_buffer_id), 1 },
|
||||
{ "android/media/MediaCodec", "getInputBuffer", "(I)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_input_buffer_id), 0 },
|
||||
@@ -1411,6 +1415,25 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+static int mediacodec_jni_setParameters(FFAMediaCodec *ctx,
|
||||
+ const FFAMediaFormat *format_ctx)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+ JNIEnv *env = NULL;
|
||||
+ FFAMediaCodecJni *codec = (FFAMediaCodecJni *)ctx;
|
||||
+ const FFAMediaFormatJni *format = (FFAMediaFormatJni *)format_ctx;
|
||||
+
|
||||
+ JNI_GET_ENV_OR_RETURN(env, codec, AVERROR_EXTERNAL);
|
||||
+
|
||||
+ (*env)->CallVoidMethod(env, codec->object, codec->jfields.set_parameters_id, format->object);
|
||||
+
|
||||
+ if (ff_jni_exception_check(env, 1, codec) < 0) {
|
||||
+ ret = AVERROR_EXTERNAL;
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
static int mediacodec_jni_start(FFAMediaCodec* ctx)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -1826,6 +1849,8 @@ static const FFAMediaCodec media_codec_jni = {
|
||||
.getBufferFlagEndOfStream = mediacodec_jni_getBufferFlagEndOfStream,
|
||||
.getBufferFlagKeyFrame = mediacodec_jni_getBufferFlagKeyFrame,
|
||||
|
||||
+ .setParameters = mediacodec_jni_setParameters,
|
||||
+
|
||||
.getConfigureFlagEncode = mediacodec_jni_getConfigureFlagEncode,
|
||||
.cleanOutputBuffers = mediacodec_jni_cleanOutputBuffers,
|
||||
.signalEndOfInputStream = mediacodec_jni_signalEndOfInputStream,
|
||||
@@ -2219,6 +2244,21 @@ static int mediacodec_ndk_configure(FFAMediaCodec* ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int mediacodec_ndk_setParameters(FFAMediaCodec *ctx,
|
||||
+ const FFAMediaFormat *format_ctx)
|
||||
+{
|
||||
+ FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx;
|
||||
+ FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)format_ctx;
|
||||
+
|
||||
+ int status = AMediaCodec_setParameters(codec->impl, format->impl);
|
||||
+ if (status != AMEDIA_OK) {
|
||||
+ av_log(codec, AV_LOG_ERROR, "codec setParameters failed, %d\n", status);
|
||||
+ return AVERROR_EXTERNAL;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
#define MEDIACODEC_NDK_WRAPPER(method) \
|
||||
static int mediacodec_ndk_ ## method(FFAMediaCodec* ctx) \
|
||||
{ \
|
||||
@@ -2522,6 +2562,8 @@ static const FFAMediaCodec media_codec_ndk = {
|
||||
.getBufferFlagEndOfStream = mediacodec_ndk_getBufferFlagEndOfStream,
|
||||
.getBufferFlagKeyFrame = mediacodec_ndk_getBufferFlagKeyFrame,
|
||||
|
||||
+ .setParameters = mediacodec_ndk_setParameters,
|
||||
+
|
||||
.getConfigureFlagEncode = mediacodec_ndk_getConfigureFlagEncode,
|
||||
.cleanOutputBuffers = mediacodec_ndk_cleanOutputBuffers,
|
||||
.signalEndOfInputStream = mediacodec_ndk_signalEndOfInputStream,
|
||||
diff --git a/libavcodec/mediacodec_wrapper.h b/libavcodec/mediacodec_wrapper.h
|
||||
index 18d0796445..e8feb6bf8e 100644
|
||||
--- a/libavcodec/mediacodec_wrapper.h
|
||||
+++ b/libavcodec/mediacodec_wrapper.h
|
||||
@@ -233,6 +233,9 @@ struct FFAMediaCodec {
|
||||
|
||||
int (*cleanOutputBuffers)(FFAMediaCodec *codec);
|
||||
|
||||
+ // Introduced in Android API 26
|
||||
+ int (*setParameters)(FFAMediaCodec* codec, const FFAMediaFormat* format);
|
||||
+
|
||||
// For encoder with FFANativeWindow as input.
|
||||
int (*signalEndOfInputStream)(FFAMediaCodec *);
|
||||
|
||||
@@ -259,6 +262,12 @@ static inline int ff_AMediaCodec_configure(FFAMediaCodec *codec,
|
||||
return codec->configure(codec, format, surface, crypto, flags);
|
||||
}
|
||||
|
||||
+static inline int ff_AMediaCodec_setParameters(FFAMediaCodec *codec,
|
||||
+ const FFAMediaFormat *format)
|
||||
+{
|
||||
+ return codec->setParameters(codec, format);
|
||||
+}
|
||||
+
|
||||
static inline int ff_AMediaCodec_start(FFAMediaCodec* codec)
|
||||
{
|
||||
return codec->start(codec);
|
||||
Reference in New Issue
Block a user