FFmpeg
mediacodec_wrapper.c
Go to the documentation of this file.
1 /*
2  * Android MediaCodec Wrapper
3  *
4  * Copyright (c) 2015-2016 Matthieu Bouron <matthieu.bouron stupeflix.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <dlfcn.h>
24 #include <jni.h>
25 #include <media/NdkMediaFormat.h>
26 #include <media/NdkMediaCodec.h>
27 #include <android/native_window_jni.h>
28 
29 #include "libavutil/avassert.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/avstring.h"
32 
33 #include "avcodec.h"
34 #include "ffjni.h"
35 #include "mediacodec_wrapper.h"
36 
38 
40  jmethodID init_id;
42 
43  jmethodID get_codec_count_id;
45 
47  jmethodID get_name_id;
50  jmethodID is_encoder_id;
52 
54  jfieldID color_formats_id;
56 
58  jfieldID profile_id;
59  jfieldID level_id;
60 
68 
72 
73 };
74 
75 static const struct FFJniField jni_amediacodeclist_mapping[] = {
76  { "android/media/MediaCodecList", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, mediacodec_list_class), 1 },
77  { "android/media/MediaCodecList", "<init>", "(I)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, init_id), 0 },
78  { "android/media/MediaCodecList", "findDecoderForFormat", "(Landroid/media/MediaFormat;)Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, find_decoder_for_format_id), 0 },
79 
80  { "android/media/MediaCodecList", "getCodecCount", "()I", FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_count_id), 1 },
81  { "android/media/MediaCodecList", "getCodecInfoAt", "(I)Landroid/media/MediaCodecInfo;", FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_info_at_id), 1 },
82 
83  { "android/media/MediaCodecInfo", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, mediacodec_info_class), 1 },
84  { "android/media/MediaCodecInfo", "getName", "()Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_name_id), 1 },
85  { "android/media/MediaCodecInfo", "getCapabilitiesForType", "(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_codec_capabilities_id), 1 },
86  { "android/media/MediaCodecInfo", "getSupportedTypes", "()[Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_supported_types_id), 1 },
87  { "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_encoder_id), 1 },
88  { "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_software_only_id), 0 },
89 
90  { "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, codec_capabilities_class), 1 },
91  { "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", "[I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, color_formats_id), 1 },
92  { "android/media/MediaCodecInfo$CodecCapabilities", "profileLevels", "[Landroid/media/MediaCodecInfo$CodecProfileLevel;", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, profile_levels_id), 1 },
93 
94  { "android/media/MediaCodecInfo$CodecProfileLevel", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, codec_profile_level_class), 1 },
95  { "android/media/MediaCodecInfo$CodecProfileLevel", "profile", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, profile_id), 1 },
96  { "android/media/MediaCodecInfo$CodecProfileLevel", "level", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, level_id), 1 },
97 
98  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileBaseline", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_baseline_id), 1 },
99  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileMain", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_main_id), 1 },
100  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileExtended", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_extended_id), 1 },
101  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high_id), 1 },
102  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high10_id), 1 },
103  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh422", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high422_id), 1 },
104  { "android/media/MediaCodecInfo$CodecProfileLevel", "AVCProfileHigh444", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, avc_profile_high444_id), 1 },
105 
106  { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main_id), 0 },
107  { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main10_id), 0 },
108  { "android/media/MediaCodecInfo$CodecProfileLevel", "HEVCProfileMain10HDR10", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecListFields, hevc_profile_main10_hdr10_id), 0 },
109 
110  { NULL }
111 };
112 
114 
116 
117  jmethodID init_id;
118 
119  jmethodID contains_key_id;
120 
121  jmethodID get_integer_id;
122  jmethodID get_long_id;
123  jmethodID get_float_id;
124  jmethodID get_bytebuffer_id;
125  jmethodID get_string_id;
126 
127  jmethodID set_integer_id;
128  jmethodID set_long_id;
129  jmethodID set_float_id;
130  jmethodID set_bytebuffer_id;
131  jmethodID set_string_id;
132 
133  jmethodID to_string_id;
134 
135 };
136 
137 static const struct FFJniField jni_amediaformat_mapping[] = {
138  { "android/media/MediaFormat", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaFormatFields, mediaformat_class), 1 },
139 
140  { "android/media/MediaFormat", "<init>", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, init_id), 1 },
141 
142  { "android/media/MediaFormat", "containsKey", "(Ljava/lang/String;)Z", FF_JNI_METHOD,offsetof(struct JNIAMediaFormatFields, contains_key_id), 1 },
143 
144  { "android/media/MediaFormat", "getInteger", "(Ljava/lang/String;)I", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_integer_id), 1 },
145  { "android/media/MediaFormat", "getLong", "(Ljava/lang/String;)J", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_long_id), 1 },
146  { "android/media/MediaFormat", "getFloat", "(Ljava/lang/String;)F", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_float_id), 1 },
147  { "android/media/MediaFormat", "getByteBuffer", "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_bytebuffer_id), 1 },
148  { "android/media/MediaFormat", "getString", "(Ljava/lang/String;)Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, get_string_id), 1 },
149 
150  { "android/media/MediaFormat", "setInteger", "(Ljava/lang/String;I)V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, set_integer_id), 1 },
151  { "android/media/MediaFormat", "setLong", "(Ljava/lang/String;J)V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, set_long_id), 1 },
152  { "android/media/MediaFormat", "setFloat", "(Ljava/lang/String;F)V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, set_float_id), 1 },
153  { "android/media/MediaFormat", "setByteBuffer", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, set_bytebuffer_id), 1 },
154  { "android/media/MediaFormat", "setString", "(Ljava/lang/String;Ljava/lang/String;)V", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, set_string_id), 1 },
155 
156  { "android/media/MediaFormat", "toString", "()Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaFormatFields, to_string_id), 1 },
157 
158  { NULL }
159 };
160 
161 static const AVClass amediaformat_class = {
162  .class_name = "amediaformat",
163  .item_name = av_default_item_name,
164  .version = LIBAVUTIL_VERSION_INT,
165 };
166 
167 typedef struct FFAMediaFormatJni {
169 
171  jobject object;
173 
175 
177 
179 
183 
187 
189 
193 
194  jmethodID get_name_id;
195 
196  jmethodID configure_id;
197  jmethodID start_id;
198  jmethodID flush_id;
199  jmethodID stop_id;
200  jmethodID release_id;
201 
203 
208 
214 
217 
219 
220  jmethodID init_id;
221 
222  jfieldID flags_id;
223  jfieldID offset_id;
225  jfieldID size_id;
226 
227 };
228 
229 static const struct FFJniField jni_amediacodec_mapping[] = {
230  { "android/media/MediaCodec", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecFields, mediacodec_class), 1 },
231 
232  { "android/media/MediaCodec", "INFO_TRY_AGAIN_LATER", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, info_try_again_later_id), 1 },
233  { "android/media/MediaCodec", "INFO_OUTPUT_BUFFERS_CHANGED", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, info_output_buffers_changed_id), 1 },
234  { "android/media/MediaCodec", "INFO_OUTPUT_FORMAT_CHANGED", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, info_output_format_changed_id), 1 },
235 
236  { "android/media/MediaCodec", "BUFFER_FLAG_CODEC_CONFIG", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, buffer_flag_codec_config_id), 1 },
237  { "android/media/MediaCodec", "BUFFER_FLAG_END_OF_STREAM", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, buffer_flag_end_of_stream_id), 1 },
238  { "android/media/MediaCodec", "BUFFER_FLAG_KEY_FRAME", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, buffer_flag_key_frame_id), 0 },
239 
240  { "android/media/MediaCodec", "CONFIGURE_FLAG_ENCODE", "I", FF_JNI_STATIC_FIELD, offsetof(struct JNIAMediaCodecFields, configure_flag_encode_id), 1 },
241 
242  { "android/media/MediaCodec", "createByCodecName", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecFields, create_by_codec_name_id), 1 },
243  { "android/media/MediaCodec", "createDecoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecFields, create_decoder_by_type_id), 1 },
244  { "android/media/MediaCodec", "createEncoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecFields, create_encoder_by_type_id), 1 },
245 
246  { "android/media/MediaCodec", "getName", "()Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_name_id), 1 },
247 
248  { "android/media/MediaCodec", "configure", "(Landroid/media/MediaFormat;Landroid/view/Surface;Landroid/media/MediaCrypto;I)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, configure_id), 1 },
249  { "android/media/MediaCodec", "start", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, start_id), 1 },
250  { "android/media/MediaCodec", "flush", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, flush_id), 1 },
251  { "android/media/MediaCodec", "stop", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, stop_id), 1 },
252  { "android/media/MediaCodec", "release", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, release_id), 1 },
253 
254  { "android/media/MediaCodec", "getOutputFormat", "()Landroid/media/MediaFormat;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_output_format_id), 1 },
255 
256  { "android/media/MediaCodec", "dequeueInputBuffer", "(J)I", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, dequeue_input_buffer_id), 1 },
257  { "android/media/MediaCodec", "queueInputBuffer", "(IIIJI)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, queue_input_buffer_id), 1 },
258  { "android/media/MediaCodec", "getInputBuffer", "(I)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_input_buffer_id), 0 },
259  { "android/media/MediaCodec", "getInputBuffers", "()[Ljava/nio/ByteBuffer;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_input_buffers_id), 1 },
260 
261  { "android/media/MediaCodec", "dequeueOutputBuffer", "(Landroid/media/MediaCodec$BufferInfo;J)I", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, dequeue_output_buffer_id), 1 },
262  { "android/media/MediaCodec", "getOutputBuffer", "(I)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_output_buffer_id), 0 },
263  { "android/media/MediaCodec", "getOutputBuffers", "()[Ljava/nio/ByteBuffer;", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, get_output_buffers_id), 1 },
264  { "android/media/MediaCodec", "releaseOutputBuffer", "(IZ)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, release_output_buffer_id), 1 },
265  { "android/media/MediaCodec", "releaseOutputBuffer", "(IJ)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, release_output_buffer_at_time_id), 0 },
266 
267  { "android/media/MediaCodec", "setInputSurface", "(Landroid/view/Surface;)V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, set_input_surface_id), 0 },
268  { "android/media/MediaCodec", "signalEndOfInputStream", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, signal_end_of_input_stream_id), 0 },
269 
270  { "android/media/MediaCodec$BufferInfo", NULL, NULL, FF_JNI_CLASS, offsetof(struct JNIAMediaCodecFields, mediainfo_class), 1 },
271 
272  { "android/media/MediaCodec.BufferInfo", "<init>", "()V", FF_JNI_METHOD, offsetof(struct JNIAMediaCodecFields, init_id), 1 },
273  { "android/media/MediaCodec.BufferInfo", "flags", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecFields, flags_id), 1 },
274  { "android/media/MediaCodec.BufferInfo", "offset", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecFields, offset_id), 1 },
275  { "android/media/MediaCodec.BufferInfo", "presentationTimeUs", "J", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecFields, presentation_time_us_id), 1 },
276  { "android/media/MediaCodec.BufferInfo", "size", "I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecFields, size_id), 1 },
277 
278  { NULL }
279 };
280 
281 static const AVClass amediacodec_class = {
282  .class_name = "amediacodec",
283  .item_name = av_default_item_name,
284  .version = LIBAVUTIL_VERSION_INT,
285 };
286 
287 typedef struct FFAMediaCodecJni {
289 
291 
292  jobject object;
293  jobject buffer_info;
294 
295  jobject input_buffers;
296  jobject output_buffers;
297 
301 
305 
307 
310 
312 
313 #define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret) do { \
314  (env) = ff_jni_get_env(log_ctx); \
315  if (!(env)) { \
316  return ret; \
317  } \
318 } while (0)
319 
320 #define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx) do { \
321  (env) = ff_jni_get_env(log_ctx); \
322  if (!(env)) { \
323  return; \
324  } \
325 } while (0)
326 
328 {
329  int ret = -1;
330 
331  JNIEnv *env = NULL;
332  struct JNIAMediaCodecListFields jfields = { 0 };
333  jfieldID field_id = 0;
334 
335  JNI_GET_ENV_OR_RETURN(env, avctx, -1);
336 
337  if (ff_jni_init_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, avctx) < 0) {
338  goto done;
339  }
340 
341  if (avctx->codec_id == AV_CODEC_ID_H264) {
342  switch(avctx->profile) {
345  field_id = jfields.avc_profile_baseline_id;
346  break;
348  field_id = jfields.avc_profile_main_id;
349  break;
351  field_id = jfields.avc_profile_extended_id;
352  break;
354  field_id = jfields.avc_profile_high_id;
355  break;
358  field_id = jfields.avc_profile_high10_id;
359  break;
362  field_id = jfields.avc_profile_high422_id;
363  break;
367  field_id = jfields.avc_profile_high444_id;
368  break;
369  }
370  } else if (avctx->codec_id == AV_CODEC_ID_HEVC) {
371  switch (avctx->profile) {
374  field_id = jfields.hevc_profile_main_id;
375  break;
377  field_id = jfields.hevc_profile_main10_id;
378  break;
379  }
380  }
381 
382  if (field_id) {
383  ret = (*env)->GetStaticIntField(env, jfields.codec_profile_level_class, field_id);
384  if (ff_jni_exception_check(env, 1, avctx) < 0) {
385  ret = -1;
386  goto done;
387  }
388  }
389 
390 done:
391  ff_jni_reset_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, avctx);
392 
393  return ret;
394 }
395 
396 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
397 {
398  int ret;
399  int i;
400  int codec_count;
401  int found_codec = 0;
402  char *name = NULL;
403  char *supported_type = NULL;
404 
405  JNIEnv *env = NULL;
406  struct JNIAMediaCodecListFields jfields = { 0 };
407  struct JNIAMediaFormatFields mediaformat_jfields = { 0 };
408 
409  jobject codec_name = NULL;
410 
411  jobject info = NULL;
412  jobject type = NULL;
413  jobjectArray types = NULL;
414 
415  jobject capabilities = NULL;
416  jobject profile_level = NULL;
417  jobjectArray profile_levels = NULL;
418 
419  JNI_GET_ENV_OR_RETURN(env, log_ctx, NULL);
420 
421  if ((ret = ff_jni_init_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx)) < 0) {
422  goto done;
423  }
424 
425  if ((ret = ff_jni_init_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx)) < 0) {
426  goto done;
427  }
428 
429  codec_count = (*env)->CallStaticIntMethod(env, jfields.mediacodec_list_class, jfields.get_codec_count_id);
430  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
431  goto done;
432  }
433 
434  for(i = 0; i < codec_count; i++) {
435  int j;
436  int type_count;
437  int is_encoder;
438 
439  info = (*env)->CallStaticObjectMethod(env, jfields.mediacodec_list_class, jfields.get_codec_info_at_id, i);
440  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
441  goto done;
442  }
443 
444  types = (*env)->CallObjectMethod(env, info, jfields.get_supported_types_id);
445  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
446  goto done;
447  }
448 
449  is_encoder = (*env)->CallBooleanMethod(env, info, jfields.is_encoder_id);
450  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
451  goto done;
452  }
453 
454  if (is_encoder != encoder) {
455  goto done_with_info;
456  }
457 
458  if (jfields.is_software_only_id) {
459  int is_software_only = (*env)->CallBooleanMethod(env, info, jfields.is_software_only_id);
460  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
461  goto done;
462  }
463 
464  if (is_software_only) {
465  goto done_with_info;
466  }
467  }
468 
469  codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id);
470  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
471  goto done;
472  }
473 
474  name = ff_jni_jstring_to_utf_chars(env, codec_name, log_ctx);
475  if (!name) {
476  goto done;
477  }
478 
479  if (codec_name) {
480  (*env)->DeleteLocalRef(env, codec_name);
481  codec_name = NULL;
482  }
483 
484  /* Skip software decoders */
485  if (
486  strstr(name, "OMX.google") ||
487  strstr(name, "OMX.ffmpeg") ||
488  (strstr(name, "OMX.SEC") && strstr(name, ".sw.")) ||
489  !strcmp(name, "OMX.qcom.video.decoder.hevcswvdec")) {
490  goto done_with_info;
491  }
492 
493  type_count = (*env)->GetArrayLength(env, types);
494  for (j = 0; j < type_count; j++) {
495  int k;
496  int profile_count;
497 
498  type = (*env)->GetObjectArrayElement(env, types, j);
499  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
500  goto done;
501  }
502 
503  supported_type = ff_jni_jstring_to_utf_chars(env, type, log_ctx);
504  if (!supported_type) {
505  goto done;
506  }
507 
508  if (av_strcasecmp(supported_type, mime)) {
509  goto done_with_type;
510  }
511 
512  capabilities = (*env)->CallObjectMethod(env, info, jfields.get_codec_capabilities_id, type);
513  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
514  goto done;
515  }
516 
517  profile_levels = (*env)->GetObjectField(env, capabilities, jfields.profile_levels_id);
518  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
519  goto done;
520  }
521 
522  profile_count = (*env)->GetArrayLength(env, profile_levels);
523  if (!profile_count) {
524  found_codec = 1;
525  }
526  for (k = 0; k < profile_count; k++) {
527  int supported_profile = 0;
528 
529  if (profile < 0) {
530  found_codec = 1;
531  break;
532  }
533 
534  profile_level = (*env)->GetObjectArrayElement(env, profile_levels, k);
535  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
536  goto done;
537  }
538 
539  supported_profile = (*env)->GetIntField(env, profile_level, jfields.profile_id);
540  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
541  goto done;
542  }
543 
544  found_codec = profile == supported_profile;
545 
546  if (profile_level) {
547  (*env)->DeleteLocalRef(env, profile_level);
548  profile_level = NULL;
549  }
550 
551  if (found_codec) {
552  break;
553  }
554  }
555 
556 done_with_type:
557  if (profile_levels) {
558  (*env)->DeleteLocalRef(env, profile_levels);
559  profile_levels = NULL;
560  }
561 
562  if (capabilities) {
563  (*env)->DeleteLocalRef(env, capabilities);
564  capabilities = NULL;
565  }
566 
567  if (type) {
568  (*env)->DeleteLocalRef(env, type);
569  type = NULL;
570  }
571 
572  av_freep(&supported_type);
573 
574  if (found_codec) {
575  break;
576  }
577  }
578 
579 done_with_info:
580  if (info) {
581  (*env)->DeleteLocalRef(env, info);
582  info = NULL;
583  }
584 
585  if (types) {
586  (*env)->DeleteLocalRef(env, types);
587  types = NULL;
588  }
589 
590  if (found_codec) {
591  break;
592  }
593 
594  av_freep(&name);
595  }
596 
597 done:
598  if (codec_name) {
599  (*env)->DeleteLocalRef(env, codec_name);
600  }
601 
602  if (info) {
603  (*env)->DeleteLocalRef(env, info);
604  }
605 
606  if (type) {
607  (*env)->DeleteLocalRef(env, type);
608  }
609 
610  if (types) {
611  (*env)->DeleteLocalRef(env, types);
612  }
613 
614  if (capabilities) {
615  (*env)->DeleteLocalRef(env, capabilities);
616  }
617 
618  if (profile_level) {
619  (*env)->DeleteLocalRef(env, profile_level);
620  }
621 
622  if (profile_levels) {
623  (*env)->DeleteLocalRef(env, profile_levels);
624  }
625 
626  av_freep(&supported_type);
627 
628  ff_jni_reset_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx);
629  ff_jni_reset_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx);
630 
631  if (!found_codec) {
632  av_freep(&name);
633  }
634 
635  return name;
636 }
637 
639 {
640  JNIEnv *env = NULL;
642  jobject object = NULL;
643 
644  format = av_mallocz(sizeof(*format));
645  if (!format) {
646  return NULL;
647  }
648  format->api = media_format_jni;
649 
650  env = ff_jni_get_env(format);
651  if (!env) {
652  av_freep(&format);
653  return NULL;
654  }
655 
656  if (ff_jni_init_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format) < 0) {
657  goto fail;
658  }
659 
660  object = (*env)->NewObject(env, format->jfields.mediaformat_class, format->jfields.init_id);
661  if (!object) {
662  goto fail;
663  }
664 
665  format->object = (*env)->NewGlobalRef(env, object);
666  if (!format->object) {
667  goto fail;
668  }
669 
670 fail:
671  if (object) {
672  (*env)->DeleteLocalRef(env, object);
673  }
674 
675  if (!format->object) {
677  av_freep(&format);
678  }
679 
680  return (FFAMediaFormat *)format;
681 }
682 
684 {
685  JNIEnv *env = NULL;
687 
688  format = av_mallocz(sizeof(*format));
689  if (!format) {
690  return NULL;
691  }
692  format->api = media_format_jni;
693 
694  env = ff_jni_get_env(format);
695  if (!env) {
696  av_freep(&format);
697  return NULL;
698  }
699 
700  if (ff_jni_init_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format) < 0) {
701  goto fail;
702  }
703 
704  format->object = (*env)->NewGlobalRef(env, object);
705  if (!format->object) {
706  goto fail;
707  }
708 
709  return (FFAMediaFormat *)format;
710 fail:
712 
713  av_freep(&format);
714 
715  return NULL;
716 }
717 
719 {
720  int ret = 0;
722  JNIEnv *env = NULL;
723 
724  if (!format) {
725  return 0;
726  }
727 
729 
730  (*env)->DeleteGlobalRef(env, format->object);
731  format->object = NULL;
732 
734 
735  av_freep(&format);
736 
737  return ret;
738 }
739 
741 {
742  char *ret = NULL;
744  JNIEnv *env = NULL;
745  jstring description = NULL;
746 
747  av_assert0(format != NULL);
748 
750 
751  description = (*env)->CallObjectMethod(env, format->object, format->jfields.to_string_id);
752  if (ff_jni_exception_check(env, 1, NULL) < 0) {
753  goto fail;
754  }
755 
757 fail:
758  if (description) {
759  (*env)->DeleteLocalRef(env, description);
760  }
761 
762  return ret;
763 }
764 
766 {
767  int ret = 1;
769  JNIEnv *env = NULL;
770  jstring key = NULL;
771  jboolean contains_key;
772 
773  av_assert0(format != NULL);
774 
775  JNI_GET_ENV_OR_RETURN(env, format, 0);
776 
778  if (!key) {
779  ret = 0;
780  goto fail;
781  }
782 
783  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
784  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
785  ret = 0;
786  goto fail;
787  }
788 
789  *out = (*env)->CallIntMethod(env, format->object, format->jfields.get_integer_id, key);
790  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
791  ret = 0;
792  goto fail;
793  }
794 
795  ret = 1;
796 fail:
797  if (key) {
798  (*env)->DeleteLocalRef(env, key);
799  }
800 
801  return ret;
802 }
803 
804 static int mediaformat_jni_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
805 {
806  int ret = 1;
808  JNIEnv *env = NULL;
809  jstring key = NULL;
810  jboolean contains_key;
811 
812  av_assert0(format != NULL);
813 
814  JNI_GET_ENV_OR_RETURN(env, format, 0);
815 
817  if (!key) {
818  ret = 0;
819  goto fail;
820  }
821 
822  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
823  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
824  ret = 0;
825  goto fail;
826  }
827 
828  *out = (*env)->CallLongMethod(env, format->object, format->jfields.get_long_id, key);
829  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
830  ret = 0;
831  goto fail;
832  }
833 
834  ret = 1;
835 fail:
836  if (key) {
837  (*env)->DeleteLocalRef(env, key);
838  }
839 
840  return ret;
841 }
842 
843 static int mediaformat_jni_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
844 {
845  int ret = 1;
847  JNIEnv *env = NULL;
848  jstring key = NULL;
849  jboolean contains_key;
850 
851  av_assert0(format != NULL);
852 
853  JNI_GET_ENV_OR_RETURN(env, format, 0);
854 
856  if (!key) {
857  ret = 0;
858  goto fail;
859  }
860 
861  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
862  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
863  ret = 0;
864  goto fail;
865  }
866 
867  *out = (*env)->CallFloatMethod(env, format->object, format->jfields.get_float_id, key);
868  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
869  ret = 0;
870  goto fail;
871  }
872 
873  ret = 1;
874 fail:
875  if (key) {
876  (*env)->DeleteLocalRef(env, key);
877  }
878 
879  return ret;
880 }
881 
882 static int mediaformat_jni_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
883 {
884  int ret = 1;
886  JNIEnv *env = NULL;
887  jstring key = NULL;
888  jboolean contains_key;
889  jobject result = NULL;
890 
891  av_assert0(format != NULL);
892 
893  JNI_GET_ENV_OR_RETURN(env, format, 0);
894 
896  if (!key) {
897  ret = 0;
898  goto fail;
899  }
900 
901  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
902  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
903  ret = 0;
904  goto fail;
905  }
906 
907  result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_bytebuffer_id, key);
908  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
909  ret = 0;
910  goto fail;
911  }
912 
913  *data = (*env)->GetDirectBufferAddress(env, result);
914  *size = (*env)->GetDirectBufferCapacity(env, result);
915 
916  if (*data && *size) {
917  void *src = *data;
918  *data = av_malloc(*size);
919  if (!*data) {
920  ret = 0;
921  goto fail;
922  }
923 
924  memcpy(*data, src, *size);
925  }
926 
927  ret = 1;
928 fail:
929  if (key) {
930  (*env)->DeleteLocalRef(env, key);
931  }
932 
933  if (result) {
934  (*env)->DeleteLocalRef(env, result);
935  }
936 
937  return ret;
938 }
939 
940 static int mediaformat_jni_getString(FFAMediaFormat* ctx, const char *name, const char **out)
941 {
942  int ret = 1;
944  JNIEnv *env = NULL;
945  jstring key = NULL;
946  jboolean contains_key;
947  jstring result = NULL;
948 
949  av_assert0(format != NULL);
950 
951  JNI_GET_ENV_OR_RETURN(env, format, 0);
952 
954  if (!key) {
955  ret = 0;
956  goto fail;
957  }
958 
959  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
960  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
961  ret = 0;
962  goto fail;
963  }
964 
965  result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_string_id, key);
966  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
967  ret = 0;
968  goto fail;
969  }
970 
972  if (!*out) {
973  ret = 0;
974  goto fail;
975  }
976 
977  ret = 1;
978 fail:
979  if (key) {
980  (*env)->DeleteLocalRef(env, key);
981  }
982 
983  if (result) {
984  (*env)->DeleteLocalRef(env, result);
985  }
986 
987  return ret;
988 }
989 
991 {
992  JNIEnv *env = NULL;
993  jstring key = NULL;
995 
996  av_assert0(format != NULL);
997 
999 
1001  if (!key) {
1002  goto fail;
1003  }
1004 
1005  (*env)->CallVoidMethod(env, format->object, format->jfields.set_integer_id, key, value);
1006  if (ff_jni_exception_check(env, 1, format) < 0) {
1007  goto fail;
1008  }
1009 
1010 fail:
1011  if (key) {
1012  (*env)->DeleteLocalRef(env, key);
1013  }
1014 }
1015 
1016 static void mediaformat_jni_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
1017 {
1018  JNIEnv *env = NULL;
1019  jstring key = NULL;
1021 
1022  av_assert0(format != NULL);
1023 
1025 
1027  if (!key) {
1028  goto fail;
1029  }
1030 
1031  (*env)->CallVoidMethod(env, format->object, format->jfields.set_long_id, key, value);
1032  if (ff_jni_exception_check(env, 1, format) < 0) {
1033  goto fail;
1034  }
1035 
1036 fail:
1037  if (key) {
1038  (*env)->DeleteLocalRef(env, key);
1039  }
1040 }
1041 
1042 static void mediaformat_jni_setFloat(FFAMediaFormat* ctx, const char* name, float value)
1043 {
1044  JNIEnv *env = NULL;
1045  jstring key = NULL;
1047 
1048  av_assert0(format != NULL);
1049 
1051 
1053  if (!key) {
1054  goto fail;
1055  }
1056 
1057  (*env)->CallVoidMethod(env, format->object, format->jfields.set_float_id, key, value);
1058  if (ff_jni_exception_check(env, 1, format) < 0) {
1059  goto fail;
1060  }
1061 
1062 fail:
1063  if (key) {
1064  (*env)->DeleteLocalRef(env, key);
1065  }
1066 }
1067 
1068 static void mediaformat_jni_setString(FFAMediaFormat* ctx, const char* name, const char* value)
1069 {
1070  JNIEnv *env = NULL;
1071  jstring key = NULL;
1072  jstring string = NULL;
1074 
1075  av_assert0(format != NULL);
1076 
1078 
1080  if (!key) {
1081  goto fail;
1082  }
1083 
1084  string = ff_jni_utf_chars_to_jstring(env, value, format);
1085  if (!string) {
1086  goto fail;
1087  }
1088 
1089  (*env)->CallVoidMethod(env, format->object, format->jfields.set_string_id, key, string);
1090  if (ff_jni_exception_check(env, 1, format) < 0) {
1091  goto fail;
1092  }
1093 
1094 fail:
1095  if (key) {
1096  (*env)->DeleteLocalRef(env, key);
1097  }
1098 
1099  if (string) {
1100  (*env)->DeleteLocalRef(env, string);
1101  }
1102 }
1103 
1104 static void mediaformat_jni_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
1105 {
1106  JNIEnv *env = NULL;
1107  jstring key = NULL;
1108  jobject buffer = NULL;
1109  void *buffer_data = NULL;
1111 
1112  av_assert0(format != NULL);
1113 
1115 
1117  if (!key) {
1118  goto fail;
1119  }
1120 
1121  if (!data || !size) {
1122  goto fail;
1123  }
1124 
1126  if (!buffer_data) {
1127  goto fail;
1128  }
1129 
1130  memcpy(buffer_data, data, size);
1131 
1132  buffer = (*env)->NewDirectByteBuffer(env, buffer_data, size);
1133  if (!buffer) {
1134  goto fail;
1135  }
1136 
1137  (*env)->CallVoidMethod(env, format->object, format->jfields.set_bytebuffer_id, key, buffer);
1138  if (ff_jni_exception_check(env, 1, format) < 0) {
1139  goto fail;
1140  }
1141 
1142 fail:
1143  if (key) {
1144  (*env)->DeleteLocalRef(env, key);
1145  }
1146 
1147  if (buffer) {
1148  (*env)->DeleteLocalRef(env, buffer);
1149  }
1150 }
1151 
1153 {
1154  int ret = 0;
1155  JNIEnv *env = NULL;
1156 
1158 
1159  codec->INFO_TRY_AGAIN_LATER = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_try_again_later_id);
1160  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1161  goto fail;
1162  }
1163 
1164  codec->BUFFER_FLAG_CODEC_CONFIG = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_codec_config_id);
1165  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1166  goto fail;
1167  }
1168 
1169  codec->BUFFER_FLAG_END_OF_STREAM = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_end_of_stream_id);
1170  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1171  goto fail;
1172  }
1173 
1174  if (codec->jfields.buffer_flag_key_frame_id) {
1175  codec->BUFFER_FLAG_KEY_FRAME = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_key_frame_id);
1176  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1177  goto fail;
1178  }
1179  }
1180 
1181  codec->CONFIGURE_FLAG_ENCODE = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.configure_flag_encode_id);
1182  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1183  goto fail;
1184  }
1185 
1186  codec->INFO_TRY_AGAIN_LATER = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_try_again_later_id);
1187  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1188  goto fail;
1189  }
1190 
1191  codec->INFO_OUTPUT_BUFFERS_CHANGED = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_output_buffers_changed_id);
1192  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1193  goto fail;
1194  }
1195 
1196  codec->INFO_OUTPUT_FORMAT_CHANGED = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_output_format_changed_id);
1197  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1198  goto fail;
1199  }
1200 
1201 fail:
1202 
1203  return ret;
1204 }
1205 
1206 #define CREATE_CODEC_BY_NAME 0
1207 #define CREATE_DECODER_BY_TYPE 1
1208 #define CREATE_ENCODER_BY_TYPE 2
1209 
1210 static inline FFAMediaCodec *codec_create(int method, const char *arg)
1211 {
1212  int ret = -1;
1213  JNIEnv *env = NULL;
1214  FFAMediaCodecJni *codec = NULL;
1215  jstring jarg = NULL;
1216  jobject object = NULL;
1217  jobject buffer_info = NULL;
1218  jmethodID create_id = NULL;
1219 
1220  codec = av_mallocz(sizeof(*codec));
1221  if (!codec) {
1222  return NULL;
1223  }
1224  codec->api = media_codec_jni;
1225 
1226  env = ff_jni_get_env(codec);
1227  if (!env) {
1228  av_freep(&codec);
1229  return NULL;
1230  }
1231 
1232  if (ff_jni_init_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec) < 0) {
1233  goto fail;
1234  }
1235 
1236  jarg = ff_jni_utf_chars_to_jstring(env, arg, codec);
1237  if (!jarg) {
1238  goto fail;
1239  }
1240 
1241  switch (method) {
1242  case CREATE_CODEC_BY_NAME: create_id = codec->jfields.create_by_codec_name_id; break;
1243  case CREATE_DECODER_BY_TYPE: create_id = codec->jfields.create_decoder_by_type_id; break;
1244  case CREATE_ENCODER_BY_TYPE: create_id = codec->jfields.create_encoder_by_type_id; break;
1245  default:
1246  av_assert0(0);
1247  }
1248 
1249  object = (*env)->CallStaticObjectMethod(env,
1250  codec->jfields.mediacodec_class,
1251  create_id,
1252  jarg);
1253  if (ff_jni_exception_check(env, 1, codec) < 0) {
1254  goto fail;
1255  }
1256 
1257  codec->object = (*env)->NewGlobalRef(env, object);
1258  if (!codec->object) {
1259  goto fail;
1260  }
1261 
1262  if (codec_init_static_fields(codec) < 0) {
1263  goto fail;
1264  }
1265 
1267  codec->has_get_i_o_buffer = 1;
1268  }
1269 
1270  buffer_info = (*env)->NewObject(env, codec->jfields.mediainfo_class, codec->jfields.init_id);
1271  if (ff_jni_exception_check(env, 1, codec) < 0) {
1272  goto fail;
1273  }
1274 
1275  codec->buffer_info = (*env)->NewGlobalRef(env, buffer_info);
1276  if (!codec->buffer_info) {
1277  goto fail;
1278  }
1279 
1280  ret = 0;
1281 fail:
1282  if (jarg) {
1283  (*env)->DeleteLocalRef(env, jarg);
1284  }
1285 
1286  if (object) {
1287  (*env)->DeleteLocalRef(env, object);
1288  }
1289 
1290  if (buffer_info) {
1291  (*env)->DeleteLocalRef(env, buffer_info);
1292  }
1293 
1294  if (ret < 0) {
1295  if (codec->object) {
1296  (*env)->DeleteGlobalRef(env, codec->object);
1297  }
1298 
1299  if (codec->buffer_info) {
1300  (*env)->DeleteGlobalRef(env, codec->buffer_info);
1301  }
1302 
1303  ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec);
1304  av_freep(&codec);
1305  }
1306 
1307  return (FFAMediaCodec *)codec;
1308 }
1309 
1310 #define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method) \
1311 static FFAMediaCodec *mediacodec_jni_##name(const char *arg) \
1312 { \
1313  return codec_create(method, arg); \
1314 } \
1315 
1319 
1321 {
1322  int ret = 0;
1324  JNIEnv *env = NULL;
1325 
1326  if (!codec) {
1327  return 0;
1328  }
1329 
1331 
1332  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_id);
1333  if (ff_jni_exception_check(env, 1, codec) < 0) {
1335  }
1336 
1337  (*env)->DeleteGlobalRef(env, codec->input_buffers);
1338  codec->input_buffers = NULL;
1339 
1340  (*env)->DeleteGlobalRef(env, codec->output_buffers);
1341  codec->output_buffers = NULL;
1342 
1343  (*env)->DeleteGlobalRef(env, codec->object);
1344  codec->object = NULL;
1345 
1346  (*env)->DeleteGlobalRef(env, codec->buffer_info);
1347  codec->buffer_info = NULL;
1348 
1349  ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec);
1350 
1351  av_freep(&codec);
1352 
1353  return ret;
1354 }
1355 
1357 {
1358  char *ret = NULL;
1359  JNIEnv *env = NULL;
1360  jobject *name = NULL;
1362 
1363  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1364 
1365  name = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_name_id);
1366  if (ff_jni_exception_check(env, 1, codec) < 0) {
1367  goto fail;
1368  }
1369 
1370  ret = ff_jni_jstring_to_utf_chars(env, name, codec);
1371 
1372 fail:
1373  if (name) {
1374  (*env)->DeleteLocalRef(env, name);
1375  }
1376 
1377  return ret;
1378 }
1379 
1381  const FFAMediaFormat* format_ctx,
1383  void *crypto,
1384  uint32_t flags)
1385 {
1386  int ret = 0;
1387  JNIEnv *env = NULL;
1389  const FFAMediaFormatJni *format = (FFAMediaFormatJni *)format_ctx;
1390  jobject *surface = window ? window->surface : NULL;
1391 
1393 
1394  if (flags & codec->CONFIGURE_FLAG_ENCODE) {
1395  if (surface && !codec->jfields.set_input_surface_id) {
1396  av_log(ctx, AV_LOG_ERROR, "System doesn't support setInputSurface\n");
1397  return AVERROR_EXTERNAL;
1398  }
1399 
1400  (*env)->CallVoidMethod(env, codec->object, codec->jfields.configure_id, format->object, NULL, NULL, flags);
1401  if (ff_jni_exception_check(env, 1, codec) < 0)
1402  return AVERROR_EXTERNAL;
1403 
1404  if (!surface)
1405  return 0;
1406 
1407  (*env)->CallVoidMethod(env, codec->object, codec->jfields.set_input_surface_id, surface);
1408  if (ff_jni_exception_check(env, 1, codec) < 0)
1409  return AVERROR_EXTERNAL;
1410  return 0;
1411  } else {
1412  (*env)->CallVoidMethod(env, codec->object, codec->jfields.configure_id, format->object, surface, NULL, flags);
1413  }
1414  if (ff_jni_exception_check(env, 1, codec) < 0) {
1416  goto fail;
1417  }
1418 
1419 fail:
1420  return ret;
1421 }
1422 
1424 {
1425  int ret = 0;
1426  JNIEnv *env = NULL;
1428 
1430 
1431  (*env)->CallVoidMethod(env, codec->object, codec->jfields.start_id);
1432  if (ff_jni_exception_check(env, 1, codec) < 0) {
1434  goto fail;
1435  }
1436 
1437 fail:
1438  return ret;
1439 }
1440 
1442 {
1443  int ret = 0;
1444  JNIEnv *env = NULL;
1446 
1448 
1449  (*env)->CallVoidMethod(env, codec->object, codec->jfields.stop_id);
1450  if (ff_jni_exception_check(env, 1, codec) < 0) {
1452  goto fail;
1453  }
1454 
1455 fail:
1456  return ret;
1457 }
1458 
1460 {
1461  int ret = 0;
1462  JNIEnv *env = NULL;
1464 
1466 
1467  (*env)->CallVoidMethod(env, codec->object, codec->jfields.flush_id);
1468  if (ff_jni_exception_check(env, 1, codec) < 0) {
1470  goto fail;
1471  }
1472 
1473 fail:
1474  return ret;
1475 }
1476 
1477 static int mediacodec_jni_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, int render)
1478 {
1479  int ret = 0;
1480  JNIEnv *env = NULL;
1482 
1484 
1485  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_output_buffer_id, (jint)idx, (jboolean)render);
1486  if (ff_jni_exception_check(env, 1, codec) < 0) {
1488  goto fail;
1489  }
1490 
1491 fail:
1492  return ret;
1493 }
1494 
1495 static int mediacodec_jni_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
1496 {
1497  int ret = 0;
1498  JNIEnv *env = NULL;
1500 
1502 
1503  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_output_buffer_at_time_id, (jint)idx, (jlong)timestampNs);
1504  if (ff_jni_exception_check(env, 1, codec) < 0) {
1506  goto fail;
1507  }
1508 
1509 fail:
1510  return ret;
1511 }
1512 
1513 static ssize_t mediacodec_jni_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
1514 {
1515  int ret = 0;
1516  JNIEnv *env = NULL;
1518 
1520 
1521  ret = (*env)->CallIntMethod(env, codec->object, codec->jfields.dequeue_input_buffer_id, timeoutUs);
1522  if (ff_jni_exception_check(env, 1, codec) < 0) {
1524  goto fail;
1525  }
1526 
1527 fail:
1528  return ret;
1529 }
1530 
1531 static int mediacodec_jni_queueInputBuffer(FFAMediaCodec* ctx, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
1532 {
1533  int ret = 0;
1534  JNIEnv *env = NULL;
1536 
1538 
1539  (*env)->CallVoidMethod(env, codec->object, codec->jfields.queue_input_buffer_id, (jint)idx, (jint)offset, (jint)size, time, flags);
1540  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1542  goto fail;
1543  }
1544 
1545 fail:
1546  return ret;
1547 }
1548 
1550 {
1551  int ret = 0;
1552  JNIEnv *env = NULL;
1554 
1556 
1557  ret = (*env)->CallIntMethod(env, codec->object, codec->jfields.dequeue_output_buffer_id, codec->buffer_info, timeoutUs);
1558  if (ff_jni_exception_check(env, 1, codec) < 0) {
1559  return AVERROR_EXTERNAL;
1560  }
1561 
1562  info->flags = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.flags_id);
1563  if (ff_jni_exception_check(env, 1, codec) < 0) {
1564  return AVERROR_EXTERNAL;
1565  }
1566 
1567  info->offset = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.offset_id);
1568  if (ff_jni_exception_check(env, 1, codec) < 0) {
1569  return AVERROR_EXTERNAL;
1570  }
1571 
1572  info->presentationTimeUs = (*env)->GetLongField(env, codec->buffer_info, codec->jfields.presentation_time_us_id);
1573  if (ff_jni_exception_check(env, 1, codec) < 0) {
1574  return AVERROR_EXTERNAL;
1575  }
1576 
1577  info->size = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.size_id);
1578  if (ff_jni_exception_check(env, 1, codec) < 0) {
1579  return AVERROR_EXTERNAL;
1580  }
1581 
1582  return ret;
1583 }
1584 
1585 static uint8_t* mediacodec_jni_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
1586 {
1587  uint8_t *ret = NULL;
1588  JNIEnv *env = NULL;
1590  jobject buffer = NULL;
1591  jobject input_buffers = NULL;
1592 
1593  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1594 
1595  if (codec->has_get_i_o_buffer) {
1596  buffer = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffer_id, (jint)idx);
1597  if (ff_jni_exception_check(env, 1, codec) < 0) {
1598  goto fail;
1599  }
1600  } else {
1601  if (!codec->input_buffers) {
1602  input_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffers_id);
1603  if (ff_jni_exception_check(env, 1, codec) < 0) {
1604  goto fail;
1605  }
1606 
1607  codec->input_buffers = (*env)->NewGlobalRef(env, input_buffers);
1608  if (ff_jni_exception_check(env, 1, codec) < 0) {
1609  goto fail;
1610  }
1611  }
1612 
1613  buffer = (*env)->GetObjectArrayElement(env, codec->input_buffers, idx);
1614  if (ff_jni_exception_check(env, 1, codec) < 0) {
1615  goto fail;
1616  }
1617  }
1618 
1619  ret = (*env)->GetDirectBufferAddress(env, buffer);
1620  *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
1621 fail:
1622  if (buffer) {
1623  (*env)->DeleteLocalRef(env, buffer);
1624  }
1625 
1626  if (input_buffers) {
1627  (*env)->DeleteLocalRef(env, input_buffers);
1628  }
1629 
1630  return ret;
1631 }
1632 
1633 static uint8_t* mediacodec_jni_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
1634 {
1635  uint8_t *ret = NULL;
1636  JNIEnv *env = NULL;
1638  jobject buffer = NULL;
1639  jobject output_buffers = NULL;
1640 
1641  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1642 
1643  if (codec->has_get_i_o_buffer) {
1644  buffer = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffer_id, (jint)idx);
1645  if (ff_jni_exception_check(env, 1, codec) < 0) {
1646  goto fail;
1647  }
1648  } else {
1649  if (!codec->output_buffers) {
1650  output_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffers_id);
1651  if (ff_jni_exception_check(env, 1, codec) < 0) {
1652  goto fail;
1653  }
1654 
1655  codec->output_buffers = (*env)->NewGlobalRef(env, output_buffers);
1656  if (ff_jni_exception_check(env, 1, codec) < 0) {
1657  goto fail;
1658  }
1659  }
1660 
1661  buffer = (*env)->GetObjectArrayElement(env, codec->output_buffers, idx);
1662  if (ff_jni_exception_check(env, 1, codec) < 0) {
1663  goto fail;
1664  }
1665  }
1666 
1667  ret = (*env)->GetDirectBufferAddress(env, buffer);
1668  *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
1669 fail:
1670  if (buffer) {
1671  (*env)->DeleteLocalRef(env, buffer);
1672  }
1673 
1674  if (output_buffers) {
1675  (*env)->DeleteLocalRef(env, output_buffers);
1676  }
1677 
1678  return ret;
1679 }
1680 
1682 {
1683  FFAMediaFormat *ret = NULL;
1684  JNIEnv *env = NULL;
1686 
1687  jobject mediaformat = NULL;
1688 
1689  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1690 
1691  mediaformat = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_format_id);
1692  if (ff_jni_exception_check(env, 1, codec) < 0) {
1693  goto fail;
1694  }
1695 
1696  ret = mediaformat_jni_newFromObject(mediaformat);
1697 fail:
1698  if (mediaformat) {
1699  (*env)->DeleteLocalRef(env, mediaformat);
1700  }
1701 
1702  return ret;
1703 }
1704 
1706 {
1708  return idx == codec->INFO_TRY_AGAIN_LATER;
1709 }
1710 
1712 {
1714  return idx == codec->INFO_OUTPUT_BUFFERS_CHANGED;
1715 }
1716 
1718 {
1720  return idx == codec->INFO_OUTPUT_FORMAT_CHANGED;
1721 }
1722 
1724 {
1726  return codec->BUFFER_FLAG_CODEC_CONFIG;
1727 }
1728 
1730 {
1732  return codec->BUFFER_FLAG_END_OF_STREAM;
1733 }
1734 
1736 {
1738  return codec->BUFFER_FLAG_KEY_FRAME;
1739 }
1740 
1742 {
1744  return codec->CONFIGURE_FLAG_ENCODE;
1745 }
1746 
1748 {
1749  int ret = 0;
1751 
1752  if (!codec->has_get_i_o_buffer) {
1753  if (codec->output_buffers) {
1754  JNIEnv *env = NULL;
1755 
1756  env = ff_jni_get_env(codec);
1757  if (!env) {
1759  goto fail;
1760  }
1761 
1762  (*env)->DeleteGlobalRef(env, codec->output_buffers);
1763  codec->output_buffers = NULL;
1764  }
1765  }
1766 
1767 fail:
1768  return ret;
1769 }
1770 
1772 {
1773  JNIEnv *env = NULL;
1775 
1777 
1778  (*env)->CallVoidMethod(env, codec->object, codec->jfields.signal_end_of_input_stream_id);
1779  if (ff_jni_exception_check(env, 1, codec) < 0) {
1780  return AVERROR_EXTERNAL;
1781  }
1782 
1783  return 0;
1784 }
1785 
1786 static const FFAMediaFormat media_format_jni = {
1788 
1789  .create = mediaformat_jni_new,
1791 
1792  .toString = mediaformat_jni_toString,
1793 
1794  .getInt32 = mediaformat_jni_getInt32,
1795  .getInt64 = mediaformat_jni_getInt64,
1796  .getFloat = mediaformat_jni_getFloat,
1797  .getBuffer = mediaformat_jni_getBuffer,
1798  .getString = mediaformat_jni_getString,
1799 
1800  .setInt32 = mediaformat_jni_setInt32,
1801  .setInt64 = mediaformat_jni_setInt64,
1802  .setFloat = mediaformat_jni_setFloat,
1803  .setString = mediaformat_jni_setString,
1804  .setBuffer = mediaformat_jni_setBuffer,
1805 };
1806 
1807 static const FFAMediaCodec media_codec_jni = {
1809 
1810  .getName = mediacodec_jni_getName,
1811 
1812  .createCodecByName = mediacodec_jni_createCodecByName,
1813  .createDecoderByType = mediacodec_jni_createDecoderByType,
1814  .createEncoderByType = mediacodec_jni_createEncoderByType,
1815  .delete = mediacodec_jni_delete,
1816 
1817  .configure = mediacodec_jni_configure,
1818  .start = mediacodec_jni_start,
1819  .stop = mediacodec_jni_stop,
1820  .flush = mediacodec_jni_flush,
1821 
1822  .getInputBuffer = mediacodec_jni_getInputBuffer,
1823  .getOutputBuffer = mediacodec_jni_getOutputBuffer,
1824 
1825  .dequeueInputBuffer = mediacodec_jni_dequeueInputBuffer,
1826  .queueInputBuffer = mediacodec_jni_queueInputBuffer,
1827 
1828  .dequeueOutputBuffer = mediacodec_jni_dequeueOutputBuffer,
1829  .getOutputFormat = mediacodec_jni_getOutputFormat,
1830 
1831  .releaseOutputBuffer = mediacodec_jni_releaseOutputBuffer,
1832  .releaseOutputBufferAtTime = mediacodec_jni_releaseOutputBufferAtTime,
1833 
1834  .infoTryAgainLater = mediacodec_jni_infoTryAgainLater,
1835  .infoOutputBuffersChanged = mediacodec_jni_infoOutputBuffersChanged,
1836  .infoOutputFormatChanged = mediacodec_jni_infoOutputFormatChanged,
1837 
1838  .getBufferFlagCodecConfig = mediacodec_jni_getBufferFlagCodecConfig,
1839  .getBufferFlagEndOfStream = mediacodec_jni_getBufferFlagEndOfStream,
1840  .getBufferFlagKeyFrame = mediacodec_jni_getBufferFlagKeyFrame,
1841 
1842  .getConfigureFlagEncode = mediacodec_jni_getConfigureFlagEncode,
1843  .cleanOutputBuffers = mediacodec_jni_cleanOutputBuffers,
1844  .signalEndOfInputStream = mediacodec_jni_signalEndOfInputStream,
1845 };
1846 
1847 typedef struct FFAMediaFormatNdk {
1849 
1850  void *libmedia;
1851  AMediaFormat *impl;
1852 
1853  AMediaFormat *(*new)(void);
1854  media_status_t (*delete)(AMediaFormat*);
1855 
1856  const char* (*toString)(AMediaFormat*);
1857 
1858  bool (*getInt32)(AMediaFormat*, const char *name, int32_t *out);
1859  bool (*getInt64)(AMediaFormat*, const char *name, int64_t *out);
1860  bool (*getFloat)(AMediaFormat*, const char *name, float *out);
1861  bool (*getSize)(AMediaFormat*, const char *name, size_t *out);
1862  bool (*getBuffer)(AMediaFormat*, const char *name, void** data, size_t *size);
1863  bool (*getString)(AMediaFormat*, const char *name, const char **out);
1864 
1865  void (*setInt32)(AMediaFormat*, const char* name, int32_t value);
1866  void (*setInt64)(AMediaFormat*, const char* name, int64_t value);
1867  void (*setFloat)(AMediaFormat*, const char* name, float value);
1868  void (*setString)(AMediaFormat*, const char* name, const char* value);
1869  void (*setBuffer)(AMediaFormat*, const char* name, const void* data, size_t size);
1871 
1872 typedef struct FFAMediaCodecNdk {
1874 
1875  void *libmedia;
1876  AMediaCodec *impl;
1877  ANativeWindow *window;
1878 
1879  AMediaCodec* (*createCodecByName)(const char *name);
1880  AMediaCodec* (*createDecoderByType)(const char *mime_type);
1881  AMediaCodec* (*createEncoderByType)(const char *mime_type);
1882  media_status_t (*delete)(AMediaCodec*);
1883 
1884  media_status_t (*configure)(AMediaCodec *,
1885  const AMediaFormat *format,
1886  ANativeWindow *surface,
1887  AMediaCrypto *crypto,
1888  uint32_t flags);
1889  media_status_t (*start)(AMediaCodec*);
1890  media_status_t (*stop)(AMediaCodec*);
1891  media_status_t (*flush)(AMediaCodec*);
1892 
1893  uint8_t* (*getInputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
1894  uint8_t* (*getOutputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
1895 
1896  ssize_t (*dequeueInputBuffer)(AMediaCodec*, int64_t timeoutUs);
1897  media_status_t (*queueInputBuffer)(AMediaCodec*, size_t idx,
1898  long offset, size_t size,
1899  uint64_t time, uint32_t flags);
1900 
1901  ssize_t (*dequeueOutputBuffer)(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
1902  AMediaFormat* (*getOutputFormat)(AMediaCodec*);
1903 
1904  media_status_t (*releaseOutputBuffer)(AMediaCodec*, size_t idx, bool render);
1905  media_status_t (*releaseOutputBufferAtTime)(AMediaCodec *mData, size_t idx, int64_t timestampNs);
1906 
1907  // Available since API level 28.
1908  media_status_t (*getName)(AMediaCodec*, char** out_name);
1909  void (*releaseName)(AMediaCodec*, char* name);
1910 
1911  // Available since API level 26.
1912  media_status_t (*setInputSurface)(AMediaCodec*, ANativeWindow *);
1913  media_status_t (*signalEndOfInputStream)(AMediaCodec *);
1915 
1918 
1920  .class_name = "amediaformat_ndk",
1921  .item_name = av_default_item_name,
1922  .version = LIBAVUTIL_VERSION_INT,
1923 };
1924 
1926  .class_name = "amediacodec_ndk",
1927  .item_name = av_default_item_name,
1928  .version = LIBAVUTIL_VERSION_INT,
1929 };
1930 
1931 static FFAMediaFormat *mediaformat_ndk_create(AMediaFormat *impl)
1932 {
1934  if (!format)
1935  return NULL;
1936 
1937  format->api = media_format_ndk;
1938 
1939  format->libmedia = dlopen("libmediandk.so", RTLD_NOW);
1940  if (!format->libmedia)
1941  goto error;
1942 
1943 #define GET_SYMBOL(sym) \
1944  format->sym = dlsym(format->libmedia, "AMediaFormat_" #sym); \
1945  if (!format->sym) \
1946  goto error;
1947 
1948  GET_SYMBOL(new)
1949  GET_SYMBOL(delete)
1950 
1951  GET_SYMBOL(toString)
1952 
1953  GET_SYMBOL(getInt32)
1954  GET_SYMBOL(getInt64)
1955  GET_SYMBOL(getFloat)
1956  GET_SYMBOL(getSize)
1957  GET_SYMBOL(getBuffer)
1958  GET_SYMBOL(getString)
1959 
1960  GET_SYMBOL(setInt32)
1961  GET_SYMBOL(setInt64)
1962  GET_SYMBOL(setFloat)
1963  GET_SYMBOL(setString)
1964  GET_SYMBOL(setBuffer)
1965 
1966 #undef GET_SYMBOL
1967 
1968  if (impl) {
1969  format->impl = impl;
1970  } else {
1971  format->impl = format->new();
1972  if (!format->impl)
1973  goto error;
1974  }
1975 
1976  return (FFAMediaFormat *)format;
1977 
1978 error:
1979  if (format->libmedia)
1980  dlclose(format->libmedia);
1981  av_freep(&format);
1982  return NULL;
1983 }
1984 
1986 {
1987  return mediaformat_ndk_create(NULL);
1988 }
1989 
1991 {
1993  int ret = 0;
1994  if (!format)
1995  return 0;
1996 
1997  av_assert0(format->api.class == &amediaformat_ndk_class);
1998 
1999  if (format->impl && (format->delete(format->impl) != AMEDIA_OK))
2001  if (format->libmedia)
2002  dlclose(format->libmedia);
2003  av_free(format);
2004 
2005  return ret;
2006 }
2007 
2009 {
2011  const char *str = format->toString(format->impl);
2012  return av_strdup(str);
2013 }
2014 
2016 {
2018  return format->getInt32(format->impl, name, out);
2019 }
2020 
2021 static int mediaformat_ndk_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
2022 {
2024  return format->getInt64(format->impl, name, out);
2025 }
2026 
2027 static int mediaformat_ndk_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
2028 {
2030  return format->getFloat(format->impl, name, out);
2031 }
2032 
2033 static int mediaformat_ndk_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
2034 {
2036  return format->getBuffer(format->impl, name, data, size);
2037 }
2038 
2039 static int mediaformat_ndk_getString(FFAMediaFormat* ctx, const char *name, const char **out)
2040 {
2042  const char *tmp = NULL;
2043  int ret = format->getString(format->impl, name, &tmp);
2044 
2045  if (tmp)
2046  *out = av_strdup(tmp);
2047  return ret;
2048 }
2049 
2051 {
2053  format->setInt32(format->impl, name, value);
2054 }
2055 
2056 static void mediaformat_ndk_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
2057 {
2059  format->setInt64(format->impl, name, value);
2060 }
2061 
2062 static void mediaformat_ndk_setFloat(FFAMediaFormat* ctx, const char* name, float value)
2063 {
2065  format->setFloat(format->impl, name, value);
2066 }
2067 
2068 static void mediaformat_ndk_setString(FFAMediaFormat* ctx, const char* name, const char* value)
2069 {
2071  format->setString(format->impl, name, value);
2072 }
2073 
2074 static void mediaformat_ndk_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
2075 {
2077  format->setBuffer(format->impl, name, data, size);
2078 }
2079 
2081 {
2083  char *ret = NULL;
2084  char *name = NULL;
2085 
2086  if (!codec->getName || !codec->releaseName) {
2087  av_log(ctx, AV_LOG_DEBUG, "getName() unavailable\n");
2088  return ret;
2089  }
2090 
2091  codec->getName(codec->impl, &name);
2092  if (name) {
2093  ret = av_strdup(name);
2094  codec->releaseName(codec->impl, name);
2095  }
2096 
2097  return ret;
2098 }
2099 
2100 static inline FFAMediaCodec *ndk_codec_create(int method, const char *arg) {
2101  FFAMediaCodecNdk *codec = av_mallocz(sizeof(*codec));
2102  const char *lib_name = "libmediandk.so";
2103 
2104  if (!codec)
2105  return NULL;
2106 
2107  codec->api = media_codec_ndk;
2108  codec->libmedia = dlopen(lib_name, RTLD_NOW);
2109  if (!codec->libmedia)
2110  goto error;
2111 
2112 #define GET_SYMBOL(sym, required) \
2113  codec->sym = dlsym(codec->libmedia, "AMediaCodec_" #sym); \
2114  if (!codec->sym) { \
2115  av_log(codec, required ? AV_LOG_ERROR : AV_LOG_INFO, \
2116  #sym "() unavailable from %s\n", lib_name); \
2117  if (required) \
2118  goto error; \
2119  }
2120 
2121  GET_SYMBOL(createCodecByName, 1)
2122  GET_SYMBOL(createDecoderByType, 1)
2123  GET_SYMBOL(createEncoderByType, 1)
2124  GET_SYMBOL(delete, 1)
2125 
2126  GET_SYMBOL(configure, 1)
2127  GET_SYMBOL(start, 1)
2128  GET_SYMBOL(stop, 1)
2129  GET_SYMBOL(flush, 1)
2130 
2131  GET_SYMBOL(getInputBuffer, 1)
2132  GET_SYMBOL(getOutputBuffer, 1)
2133 
2134  GET_SYMBOL(dequeueInputBuffer, 1)
2135  GET_SYMBOL(queueInputBuffer, 1)
2136 
2137  GET_SYMBOL(dequeueOutputBuffer, 1)
2138  GET_SYMBOL(getOutputFormat, 1)
2139 
2140  GET_SYMBOL(releaseOutputBuffer, 1)
2141  GET_SYMBOL(releaseOutputBufferAtTime, 1)
2142 
2143  GET_SYMBOL(getName, 0)
2144  GET_SYMBOL(releaseName, 0)
2145 
2146  GET_SYMBOL(setInputSurface, 0)
2147  GET_SYMBOL(signalEndOfInputStream, 0)
2148 
2149 #undef GET_SYMBOL
2150 
2151  switch (method) {
2152  case CREATE_CODEC_BY_NAME:
2153  codec->impl = codec->createCodecByName(arg);
2154  break;
2156  codec->impl = codec->createDecoderByType(arg);
2157  break;
2159  codec->impl = codec->createEncoderByType(arg);
2160  break;
2161  default:
2162  av_assert0(0);
2163  }
2164  if (!codec->impl)
2165  goto error;
2166 
2167  return (FFAMediaCodec *)codec;
2168 
2169 error:
2170  if (codec->libmedia)
2171  dlclose(codec->libmedia);
2172  av_freep(&codec);
2173  return NULL;
2174 }
2175 
2176 #define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC(name, method) \
2177 static FFAMediaCodec *mediacodec_ndk_##name(const char *arg) \
2178 { \
2179  return ndk_codec_create(method, arg); \
2180 } \
2181 
2185 
2187 {
2189  int ret = 0;
2190 
2191  if (!codec)
2192  return 0;
2193 
2195 
2196  if (codec->impl && (codec->delete(codec->impl) != AMEDIA_OK))
2198  if (codec->window)
2199  ANativeWindow_release(codec->window);
2200  if (codec->libmedia)
2201  dlclose(codec->libmedia);
2202  av_free(codec);
2203 
2204  return ret;
2205 }
2206 
2208  const FFAMediaFormat* format_ctx,
2210  void *crypto,
2211  uint32_t flags)
2212 {
2214  FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)format_ctx;
2215  media_status_t status;
2216  ANativeWindow *native_window = NULL;
2217 
2218  if (window) {
2219  if (window->surface) {
2220  JNIEnv *env = NULL;
2221  JNI_GET_ENV_OR_RETURN(env, ctx, -1);
2222  native_window = ANativeWindow_fromSurface(env, window->surface);
2223  // Save for release
2224  codec->window = native_window;
2225  } else if (window->native_window) {
2226  native_window = window->native_window;
2227  }
2228  }
2229 
2230  if (format_ctx->class != &amediaformat_ndk_class) {
2231  av_log(ctx, AV_LOG_ERROR, "invalid media format\n");
2232  return AVERROR(EINVAL);
2233  }
2234 
2235  if (flags & AMEDIACODEC_CONFIGURE_FLAG_ENCODE) {
2236  if (native_window && !codec->setInputSurface) {
2237  av_log(ctx, AV_LOG_ERROR, "System doesn't support setInputSurface\n");
2238  return AVERROR_EXTERNAL;
2239  }
2240 
2241  status = codec->configure(codec->impl, format->impl, NULL, NULL, flags);
2242  if (status != AMEDIA_OK) {
2243  av_log(codec, AV_LOG_ERROR, "Encoder configure failed, %d\n", status);
2244  return AVERROR_EXTERNAL;
2245  }
2246 
2247  if (!native_window)
2248  return 0;
2249 
2250  status = codec->setInputSurface(codec->impl, native_window);
2251  if (status != AMEDIA_OK) {
2252  av_log(codec, AV_LOG_ERROR, "Encoder set input surface failed, %d\n", status);
2253  return AVERROR_EXTERNAL;
2254  }
2255  } else {
2256  status = codec->configure(codec->impl, format->impl, native_window, NULL, flags);
2257  if (status != AMEDIA_OK) {
2258  av_log(codec, AV_LOG_ERROR, "Decoder configure failed, %d\n", status);
2259  return AVERROR_EXTERNAL;
2260  }
2261  }
2262 
2263  return 0;
2264 }
2265 
2266 #define MEDIACODEC_NDK_WRAPPER(method) \
2267 static int mediacodec_ndk_ ## method(FFAMediaCodec* ctx) \
2268 { \
2269  FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx; \
2270  media_status_t status = codec->method(codec->impl); \
2271  \
2272  if (status != AMEDIA_OK) { \
2273  av_log(codec, AV_LOG_ERROR, #method " failed, %d\n", status); \
2274  return AVERROR_EXTERNAL; \
2275  } \
2276  \
2277  return 0; \
2278 } \
2279 
2283 
2284 static uint8_t* mediacodec_ndk_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
2285 {
2287  return codec->getInputBuffer(codec->impl, idx, out_size);
2288 }
2289 
2290 static uint8_t* mediacodec_ndk_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
2291 {
2293  return codec->getOutputBuffer(codec->impl, idx, out_size);
2294 }
2295 
2296 static ssize_t mediacodec_ndk_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
2297 {
2299  return codec->dequeueInputBuffer(codec->impl, timeoutUs);
2300 }
2301 
2303  off_t offset, size_t size,
2304  uint64_t time, uint32_t flags)
2305 {
2307  return codec->queueInputBuffer(codec->impl, idx, offset, size, time, flags);
2308 }
2309 
2311 {
2313  AMediaCodecBufferInfo buf_info = {0};
2314  ssize_t ret;
2315 
2316  ret = codec->dequeueOutputBuffer(codec->impl, &buf_info, timeoutUs);
2317  info->offset = buf_info.offset;
2318  info->size = buf_info.size;
2319  info->presentationTimeUs = buf_info.presentationTimeUs;
2320  info->flags = buf_info.flags;
2321 
2322  return ret;
2323 }
2324 
2326 {
2328  AMediaFormat *format = codec->getOutputFormat(codec->impl);
2329 
2330  if (!format)
2331  return NULL;
2333 }
2334 
2335 static int mediacodec_ndk_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, int render)
2336 {
2338  media_status_t status;
2339 
2340  status = codec->releaseOutputBuffer(codec->impl, idx, render);
2341  if (status != AMEDIA_OK) {
2342  av_log(codec, AV_LOG_ERROR, "release output buffer failed, %d\n", status);
2343  return AVERROR_EXTERNAL;
2344  }
2345 
2346  return 0;
2347 }
2348 
2349 static int mediacodec_ndk_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
2350 {
2352  media_status_t status;
2353 
2354  status = codec->releaseOutputBufferAtTime(codec->impl, idx, timestampNs);
2355  if (status != AMEDIA_OK) {
2356  av_log(codec, AV_LOG_ERROR, "releaseOutputBufferAtTime failed, %d\n", status);
2357  return AVERROR_EXTERNAL;
2358  }
2359 
2360  return 0;
2361 }
2362 
2364 {
2365  return idx == AMEDIACODEC_INFO_TRY_AGAIN_LATER;
2366 }
2367 
2369 {
2370  return idx == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED;
2371 }
2372 
2374 {
2375  return idx == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED;
2376 }
2377 
2379 {
2380  return AMEDIACODEC_BUFFER_FLAG_CODEC_CONFIG;
2381 }
2382 
2384 {
2385  return AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM;
2386 }
2387 
2389 {
2390  return 1;
2391 }
2392 
2394 {
2395  return AMEDIACODEC_CONFIGURE_FLAG_ENCODE;
2396 }
2397 
2399 {
2400  return 0;
2401 }
2402 
2404 {
2406  media_status_t status;
2407 
2408  if (!codec->signalEndOfInputStream) {
2409  av_log(codec, AV_LOG_ERROR, "signalEndOfInputStream unavailable\n");
2410  return AVERROR_EXTERNAL;
2411  }
2412 
2413  status = codec->signalEndOfInputStream(codec->impl);
2414  if (status != AMEDIA_OK) {
2415  av_log(codec, AV_LOG_ERROR, "signalEndOfInputStream failed, %d\n", status);
2416  return AVERROR_EXTERNAL;
2417  }
2418  av_log(codec, AV_LOG_DEBUG, "signalEndOfInputStream success\n");
2419 
2420  return 0;
2421 }
2422 
2423 static const FFAMediaFormat media_format_ndk = {
2425 
2426  .create = mediaformat_ndk_new,
2428 
2429  .toString = mediaformat_ndk_toString,
2430 
2431  .getInt32 = mediaformat_ndk_getInt32,
2432  .getInt64 = mediaformat_ndk_getInt64,
2433  .getFloat = mediaformat_ndk_getFloat,
2434  .getBuffer = mediaformat_ndk_getBuffer,
2435  .getString = mediaformat_ndk_getString,
2436 
2437  .setInt32 = mediaformat_ndk_setInt32,
2438  .setInt64 = mediaformat_ndk_setInt64,
2439  .setFloat = mediaformat_ndk_setFloat,
2440  .setString = mediaformat_ndk_setString,
2441  .setBuffer = mediaformat_ndk_setBuffer,
2442 };
2443 
2444 static const FFAMediaCodec media_codec_ndk = {
2446 
2447  .getName = mediacodec_ndk_getName,
2448 
2449  .createCodecByName = mediacodec_ndk_createCodecByName,
2450  .createDecoderByType = mediacodec_ndk_createDecoderByType,
2451  .createEncoderByType = mediacodec_ndk_createEncoderByType,
2452  .delete = mediacodec_ndk_delete,
2453 
2454  .configure = mediacodec_ndk_configure,
2455  .start = mediacodec_ndk_start,
2456  .stop = mediacodec_ndk_stop,
2457  .flush = mediacodec_ndk_flush,
2458 
2459  .getInputBuffer = mediacodec_ndk_getInputBuffer,
2460  .getOutputBuffer = mediacodec_ndk_getOutputBuffer,
2461 
2462  .dequeueInputBuffer = mediacodec_ndk_dequeueInputBuffer,
2463  .queueInputBuffer = mediacodec_ndk_queueInputBuffer,
2464 
2465  .dequeueOutputBuffer = mediacodec_ndk_dequeueOutputBuffer,
2466  .getOutputFormat = mediacodec_ndk_getOutputFormat,
2467 
2468  .releaseOutputBuffer = mediacodec_ndk_releaseOutputBuffer,
2469  .releaseOutputBufferAtTime = mediacodec_ndk_releaseOutputBufferAtTime,
2470 
2471  .infoTryAgainLater = mediacodec_ndk_infoTryAgainLater,
2472  .infoOutputBuffersChanged = mediacodec_ndk_infoOutputBuffersChanged,
2473  .infoOutputFormatChanged = mediacodec_ndk_infoOutputFormatChanged,
2474 
2475  .getBufferFlagCodecConfig = mediacodec_ndk_getBufferFlagCodecConfig,
2476  .getBufferFlagEndOfStream = mediacodec_ndk_getBufferFlagEndOfStream,
2477  .getBufferFlagKeyFrame = mediacodec_ndk_getBufferFlagKeyFrame,
2478 
2479  .getConfigureFlagEncode = mediacodec_ndk_getConfigureFlagEncode,
2480  .cleanOutputBuffers = mediacodec_ndk_cleanOutputBuffers,
2481  .signalEndOfInputStream = mediacodec_ndk_signalEndOfInputStream,
2482 };
2483 
2485 {
2486  if (ndk)
2487  return media_format_ndk.create();
2488  return media_format_jni.create();
2489 }
2490 
2492 {
2493  if (ndk)
2496 }
2497 
2498 FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk)
2499 {
2500  if (ndk)
2501  return media_codec_ndk.createDecoderByType(mime_type);
2502  return media_codec_jni.createDecoderByType(mime_type);
2503 }
2504 
2505 FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
2506 {
2507  if (ndk)
2508  return media_codec_ndk.createEncoderByType(mime_type);
2509  return media_codec_jni.createEncoderByType(mime_type);
2510 }
2511 
2513 {
2514  int ret = -1;
2515  JNIEnv *env = NULL;
2516  jclass versionClass;
2517  jfieldID sdkIntFieldID;
2518  JNI_GET_ENV_OR_RETURN(env, avctx, -1);
2519 
2520  versionClass = (*env)->FindClass(env, "android/os/Build$VERSION");
2521  sdkIntFieldID = (*env)->GetStaticFieldID(env, versionClass, "SDK_INT", "I");
2522  ret = (*env)->GetStaticIntField(env, versionClass, sdkIntFieldID);
2523  (*env)->DeleteLocalRef(env, versionClass);
2524  return ret;
2525 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
JNIAMediaCodecFields::create_by_codec_name_id
jmethodID create_by_codec_name_id
Definition: mediacodec_wrapper.c:190
JNIAMediaCodecListFields::get_codec_info_at_id
jmethodID get_codec_info_at_id
Definition: mediacodec_wrapper.c:44
FFAMediaCodecJni::jfields
struct JNIAMediaCodecFields jfields
Definition: mediacodec_wrapper.c:290
JNIAMediaCodecFields::get_output_buffer_id
jmethodID get_output_buffer_id
Definition: mediacodec_wrapper.c:210
JNIAMediaCodecListFields::is_software_only_id
jmethodID is_software_only_id
Definition: mediacodec_wrapper.c:51
FFAMediaCodecJni::api
FFAMediaCodec api
Definition: mediacodec_wrapper.c:288
ff_AMediaCodecList_getCodecNameByType
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
Definition: mediacodec_wrapper.c:396
JNIAMediaFormatFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:117
JNIAMediaFormatFields
Definition: mediacodec_wrapper.c:113
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
mediaformat_ndk_getString
static int mediaformat_ndk_getString(FFAMediaFormat *ctx, const char *name, const char **out)
Definition: mediacodec_wrapper.c:2039
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
mediacodec_ndk_getBufferFlagKeyFrame
static int mediacodec_ndk_getBufferFlagKeyFrame(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2388
mediacodec_ndk_releaseOutputBuffer
static int mediacodec_ndk_releaseOutputBuffer(FFAMediaCodec *ctx, size_t idx, int render)
Definition: mediacodec_wrapper.c:2335
amediacodec_ndk_class
static const AVClass amediacodec_ndk_class
Definition: mediacodec_wrapper.c:1925
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
mediaformat_jni_setInt32
static void mediaformat_jni_setInt32(FFAMediaFormat *ctx, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:990
JNIAMediaCodecFields::size_id
jfieldID size_id
Definition: mediacodec_wrapper.c:225
FFAMediaCodecNdk::dequeueInputBuffer
ssize_t(* dequeueInputBuffer)(AMediaCodec *, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1896
mediacodec_jni_cleanOutputBuffers
static int mediacodec_jni_cleanOutputBuffers(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1747
out
FILE * out
Definition: movenc.c:54
FFAMediaCodecNdk::getOutputFormat
AMediaFormat *(* getOutputFormat)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1902
FFAMediaFormatNdk::setString
void(* setString)(AMediaFormat *, const char *name, const char *value)
Definition: mediacodec_wrapper.c:1868
FFAMediaFormatNdk::impl
AMediaFormat * impl
Definition: mediacodec_wrapper.c:1851
mediacodec_ndk_infoOutputBuffersChanged
static int mediacodec_ndk_infoOutputBuffersChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2368
FF_PROFILE_H264_BASELINE
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:1589
mediacodec_ndk_getInputBuffer
static uint8_t * mediacodec_ndk_getInputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:2284
mediaformat_jni_delete
static int mediaformat_jni_delete(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:718
JNIAMediaCodecFields::flush_id
jmethodID flush_id
Definition: mediacodec_wrapper.c:198
JNIAMediaCodecFields::get_name_id
jmethodID get_name_id
Definition: mediacodec_wrapper.c:194
JNIAMediaFormatFields::get_float_id
jmethodID get_float_id
Definition: mediacodec_wrapper.c:123
mediaformat_jni_new
static FFAMediaFormat * mediaformat_jni_new(void)
Definition: mediacodec_wrapper.c:638
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:218
FF_PROFILE_H264_CONSTRAINED_BASELINE
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
Definition: avcodec.h:1590
FFAMediaCodecNdk::createCodecByName
AMediaCodec *(* createCodecByName)(const char *name)
Definition: mediacodec_wrapper.c:1879
out_size
int out_size
Definition: movenc.c:55
JNIAMediaCodecListFields::mediacodec_list_class
jclass mediacodec_list_class
Definition: mediacodec_wrapper.c:39
JNIAMediaCodecFields::mediainfo_class
jclass mediainfo_class
Definition: mediacodec_wrapper.c:218
jni_amediacodec_mapping
static const struct FFJniField jni_amediacodec_mapping[]
Definition: mediacodec_wrapper.c:229
mediacodec_jni_queueInputBuffer
static int mediacodec_jni_queueInputBuffer(FFAMediaCodec *ctx, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.c:1531
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
mediaformat_jni_setBuffer
static void mediaformat_jni_setBuffer(FFAMediaFormat *ctx, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.c:1104
JNIAMediaCodecListFields::get_supported_types_id
jmethodID get_supported_types_id
Definition: mediacodec_wrapper.c:49
data
const char data[16]
Definition: mxf.c:146
FF_PROFILE_H264_HIGH_444_PREDICTIVE
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:1601
FFAMediaFormatNdk
Definition: mediacodec_wrapper.c:1847
amediacodec_class
static const AVClass amediacodec_class
Definition: mediacodec_wrapper.c:281
FFAMediaCodecNdk::queueInputBuffer
media_status_t(* queueInputBuffer)(AMediaCodec *, size_t idx, long offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.c:1897
JNIAMediaCodecFields::info_try_again_later_id
jfieldID info_try_again_later_id
Definition: mediacodec_wrapper.c:180
FFAMediaCodecNdk::delete
media_status_t(* delete)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1882
mediacodec_jni_infoTryAgainLater
static int mediacodec_jni_infoTryAgainLater(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1705
mediacodec_jni_getBufferFlagEndOfStream
static int mediacodec_jni_getBufferFlagEndOfStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1729
ff_jni_reset_jfields
int ff_jni_reset_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
Definition: ffjni.c:375
mediacodec_ndk_getConfigureFlagEncode
static int mediacodec_ndk_getConfigureFlagEncode(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2393
mediacodec_jni_start
static int mediacodec_jni_start(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1423
mediaformat_jni_getString
static int mediaformat_jni_getString(FFAMediaFormat *ctx, const char *name, const char **out)
Definition: mediacodec_wrapper.c:940
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
mediaformat_jni_getInt64
static int mediaformat_jni_getInt64(FFAMediaFormat *ctx, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:804
FFAMediaCodecNdk
Definition: mediacodec_wrapper.c:1872
JNIAMediaCodecFields::presentation_time_us_id
jfieldID presentation_time_us_id
Definition: mediacodec_wrapper.c:224
JNIAMediaCodecListFields::get_name_id
jmethodID get_name_id
Definition: mediacodec_wrapper.c:47
mediacodec_ndk_cleanOutputBuffers
static int mediacodec_ndk_cleanOutputBuffers(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2398
mediaformat_jni_getInt32
static int mediaformat_jni_getInt32(FFAMediaFormat *ctx, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:765
mediacodec_jni_getOutputFormat
static FFAMediaFormat * mediacodec_jni_getOutputFormat(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1681
JNIAMediaCodecListFields::is_encoder_id
jmethodID is_encoder_id
Definition: mediacodec_wrapper.c:50
window
static SDL_Window * window
Definition: ffplay.c:365
mediacodec_jni_delete
static int mediacodec_jni_delete(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1320
JNIAMediaCodecListFields::get_codec_count_id
jmethodID get_codec_count_id
Definition: mediacodec_wrapper.c:43
jni_amediacodeclist_mapping
static const struct FFJniField jni_amediacodeclist_mapping[]
Definition: mediacodec_wrapper.c:75
FFAMediaCodecNdk::libmedia
void * libmedia
Definition: mediacodec_wrapper.c:1875
JNIAMediaFormatFields::set_long_id
jmethodID set_long_id
Definition: mediacodec_wrapper.c:128
mediaformat_ndk_getInt32
static int mediaformat_ndk_getInt32(FFAMediaFormat *ctx, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:2015
fail
#define fail()
Definition: checkasm.h:134
mediaformat_jni_setString
static void mediaformat_jni_setString(FFAMediaFormat *ctx, const char *name, const char *value)
Definition: mediacodec_wrapper.c:1068
JNIAMediaCodecListFields::hevc_profile_main10_hdr10_id
jfieldID hevc_profile_main10_hdr10_id
Definition: mediacodec_wrapper.c:71
JNIAMediaCodecFields::set_input_surface_id
jmethodID set_input_surface_id
Definition: mediacodec_wrapper.c:215
mediacodec_ndk_infoTryAgainLater
static int mediacodec_ndk_infoTryAgainLater(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2363
FFAMediaCodecJni::INFO_OUTPUT_FORMAT_CHANGED
int INFO_OUTPUT_FORMAT_CHANGED
Definition: mediacodec_wrapper.c:300
JNIAMediaFormatFields::set_float_id
jmethodID set_float_id
Definition: mediacodec_wrapper.c:129
JNIAMediaCodecListFields::mediacodec_info_class
jclass mediacodec_info_class
Definition: mediacodec_wrapper.c:46
mediacodec_jni_releaseOutputBufferAtTime
static int mediacodec_jni_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:1495
JNIAMediaFormatFields::to_string_id
jmethodID to_string_id
Definition: mediacodec_wrapper.c:133
FFAMediaFormatNdk::setInt64
void(* setInt64)(AMediaFormat *, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:1866
FF_JNI_CLASS
@ FF_JNI_CLASS
Definition: ffjni.h:90
FF_PROFILE_H264_HIGH
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:1593
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
JNIAMediaCodecFields::release_id
jmethodID release_id
Definition: mediacodec_wrapper.c:200
FFAMediaFormatJni::api
FFAMediaFormat api
Definition: mediacodec_wrapper.c:168
JNIAMediaCodecFields::get_output_buffers_id
jmethodID get_output_buffers_id
Definition: mediacodec_wrapper.c:211
JNIAMediaCodecFields::release_output_buffer_at_time_id
jmethodID release_output_buffer_at_time_id
Definition: mediacodec_wrapper.c:213
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2484
mediacodec_jni_dequeueOutputBuffer
static ssize_t mediacodec_jni_dequeueOutputBuffer(FFAMediaCodec *ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1549
CREATE_CODEC_BY_NAME
#define CREATE_CODEC_BY_NAME
Definition: mediacodec_wrapper.c:1206
FFAMediaFormatNdk::getFloat
bool(* getFloat)(AMediaFormat *, const char *name, float *out)
Definition: mediacodec_wrapper.c:1860
FFAMediaCodecNdk::start
media_status_t(* start)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1889
JNIAMediaCodecFields::buffer_flag_codec_config_id
jfieldID buffer_flag_codec_config_id
Definition: mediacodec_wrapper.c:184
ff_jni_utf_chars_to_jstring
jstring ff_jni_utf_chars_to_jstring(JNIEnv *env, const char *utf_chars, void *log_ctx)
Definition: ffjni.c:128
FFAMediaFormat::delete
int(* delete)(FFAMediaFormat *)
Definition: mediacodec_wrapper.h:67
mediacodec_ndk_getName
static char * mediacodec_ndk_getName(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2080
avassert.h
mediaformat_ndk_getInt64
static int mediaformat_ndk_getInt64(FFAMediaFormat *ctx, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:2021
description
Tag description
Definition: snow.txt:206
mediacodec_jni_infoOutputBuffersChanged
static int mediacodec_jni_infoOutputBuffersChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1711
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
mediacodec_ndk_queueInputBuffer
static int mediacodec_ndk_queueInputBuffer(FFAMediaCodec *ctx, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.c:2302
FF_PROFILE_HEVC_MAIN
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:1638
FFAMediaCodecNdk::signalEndOfInputStream
media_status_t(* signalEndOfInputStream)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1913
JNIAMediaCodecListFields::profile_id
jfieldID profile_id
Definition: mediacodec_wrapper.c:58
FFAMediaCodecJni::output_buffers
jobject output_buffers
Definition: mediacodec_wrapper.c:296
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:2512
JNIAMediaCodecListFields::codec_profile_level_class
jclass codec_profile_level_class
Definition: mediacodec_wrapper.c:57
mediacodec_ndk_getBufferFlagCodecConfig
static int mediacodec_ndk_getBufferFlagCodecConfig(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2378
mediaformat_jni_setInt64
static void mediaformat_jni_setInt64(FFAMediaFormat *ctx, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:1016
JNIAMediaCodecFields::create_decoder_by_type_id
jmethodID create_decoder_by_type_id
Definition: mediacodec_wrapper.c:191
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
JNIAMediaCodecFields::get_output_format_id
jmethodID get_output_format_id
Definition: mediacodec_wrapper.c:202
FF_PROFILE_H264_EXTENDED
#define FF_PROFILE_H264_EXTENDED
Definition: avcodec.h:1592
mediacodec_ndk_dequeueInputBuffer
static ssize_t mediacodec_ndk_dequeueInputBuffer(FFAMediaCodec *ctx, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:2296
JNI_GET_ENV_OR_RETURN_VOID
#define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx)
Definition: mediacodec_wrapper.c:320
info
MIPS optimizations info
Definition: mips.txt:2
JNIAMediaCodecFields::get_input_buffer_id
jmethodID get_input_buffer_id
Definition: mediacodec_wrapper.c:206
FFAMediaCodecNdk::setInputSurface
media_status_t(* setInputSurface)(AMediaCodec *, ANativeWindow *)
Definition: mediacodec_wrapper.c:1912
FFAMediaFormatNdk::getInt64
bool(* getInt64)(AMediaFormat *, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:1859
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
JNIAMediaCodecFields::offset_id
jfieldID offset_id
Definition: mediacodec_wrapper.c:223
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
JNIAMediaCodecListFields::hevc_profile_main10_id
jfieldID hevc_profile_main10_id
Definition: mediacodec_wrapper.c:70
mediaformat_jni_newFromObject
static FFAMediaFormat * mediaformat_jni_newFromObject(void *object)
Definition: mediacodec_wrapper.c:683
JNIAMediaCodecListFields::find_decoder_for_format_id
jmethodID find_decoder_for_format_id
Definition: mediacodec_wrapper.c:41
mediaformat_ndk_getFloat
static int mediaformat_ndk_getFloat(FFAMediaFormat *ctx, const char *name, float *out)
Definition: mediacodec_wrapper.c:2027
key
const char * key
Definition: hwcontext_opencl.c:174
JNIAMediaCodecFields::dequeue_input_buffer_id
jmethodID dequeue_input_buffer_id
Definition: mediacodec_wrapper.c:204
mediacodec_jni_getBufferFlagKeyFrame
static int mediacodec_jni_getBufferFlagKeyFrame(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1735
FFAMediaFormatNdk::getString
bool(* getString)(AMediaFormat *, const char *name, const char **out)
Definition: mediacodec_wrapper.c:1863
FFAMediaCodecJni::CONFIGURE_FLAG_ENCODE
int CONFIGURE_FLAG_ENCODE
Definition: mediacodec_wrapper.c:306
ff_jni_init_jfields
int ff_jni_init_jfields(JNIEnv *env, void *jfields, const struct FFJniField *jfields_mapping, int global, void *log_ctx)
Definition: ffjni.c:286
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:408
arg
const char * arg
Definition: jacosubdec.c:67
FFAMediaFormatNdk::setFloat
void(* setFloat)(AMediaFormat *, const char *name, float value)
Definition: mediacodec_wrapper.c:1867
mediaformat_ndk_setBuffer
static void mediaformat_ndk_setBuffer(FFAMediaFormat *ctx, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.c:2074
JNIAMediaCodecFields::queue_input_buffer_id
jmethodID queue_input_buffer_id
Definition: mediacodec_wrapper.c:205
mediaformat_ndk_setInt32
static void mediaformat_ndk_setInt32(FFAMediaFormat *ctx, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:2050
JNIAMediaFormatFields::get_string_id
jmethodID get_string_id
Definition: mediacodec_wrapper.c:125
GET_SYMBOL
#define GET_SYMBOL(sym)
JNIAMediaCodecListFields
Definition: mediacodec_wrapper.c:37
jni_amediaformat_mapping
static const struct FFJniField jni_amediaformat_mapping[]
Definition: mediacodec_wrapper.c:137
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
JNIAMediaCodecFields::create_encoder_by_type_id
jmethodID create_encoder_by_type_id
Definition: mediacodec_wrapper.c:192
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2491
FF_JNI_METHOD
@ FF_JNI_METHOD
Definition: ffjni.h:93
JNIAMediaCodecFields::stop_id
jmethodID stop_id
Definition: mediacodec_wrapper.c:199
NULL
#define NULL
Definition: coverity.c:32
mediacodec_ndk_getBufferFlagEndOfStream
static int mediacodec_ndk_getBufferFlagEndOfStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2383
FFAMediaCodecJni::input_buffers
jobject input_buffers
Definition: mediacodec_wrapper.c:295
JNIAMediaCodecFields::release_output_buffer_id
jmethodID release_output_buffer_id
Definition: mediacodec_wrapper.c:212
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:148
FFAMediaCodecJni::has_get_i_o_buffer
int has_get_i_o_buffer
Definition: mediacodec_wrapper.c:308
JNIAMediaCodecListFields::avc_profile_extended_id
jfieldID avc_profile_extended_id
Definition: mediacodec_wrapper.c:63
FFAMediaCodecJni::BUFFER_FLAG_KEY_FRAME
int BUFFER_FLAG_KEY_FRAME
Definition: mediacodec_wrapper.c:304
FFJniField
Definition: ffjni.h:102
media_codec_ndk
static const FFAMediaCodec media_codec_ndk
Definition: mediacodec_wrapper.c:1917
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
FFAMediaCodecNdk::api
FFAMediaCodec api
Definition: mediacodec_wrapper.c:1873
mediacodec_jni_releaseOutputBuffer
static int mediacodec_jni_releaseOutputBuffer(FFAMediaCodec *ctx, size_t idx, int render)
Definition: mediacodec_wrapper.c:1477
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2505
FF_PROFILE_HEVC_MAIN_10
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:1639
mediacodec_jni_getName
static char * mediacodec_jni_getName(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1356
ff_jni_get_env
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:52
JNIAMediaCodecFields::get_input_buffers_id
jmethodID get_input_buffers_id
Definition: mediacodec_wrapper.c:207
FFAMediaFormatNdk::setInt32
void(* setInt32)(AMediaFormat *, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:1865
FFAMediaCodecJni::INFO_OUTPUT_BUFFERS_CHANGED
int INFO_OUTPUT_BUFFERS_CHANGED
Definition: mediacodec_wrapper.c:299
JNIAMediaCodecFields::buffer_flag_end_of_stream_id
jfieldID buffer_flag_end_of_stream_id
Definition: mediacodec_wrapper.c:185
JNIAMediaCodecFields::info_output_format_changed_id
jfieldID info_output_format_changed_id
Definition: mediacodec_wrapper.c:182
mediaformat_ndk_getBuffer
static int mediaformat_ndk_getBuffer(FFAMediaFormat *ctx, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:2033
DECLARE_FF_AMEDIACODEC_CREATE_FUNC
#define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method)
Definition: mediacodec_wrapper.c:1310
JNIAMediaCodecFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:220
mediacodec_jni_dequeueInputBuffer
static ssize_t mediacodec_jni_dequeueInputBuffer(FFAMediaCodec *ctx, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1513
JNIAMediaCodecListFields::get_codec_capabilities_id
jmethodID get_codec_capabilities_id
Definition: mediacodec_wrapper.c:48
FFAMediaCodecNdk::getName
media_status_t(* getName)(AMediaCodec *, char **out_name)
Definition: mediacodec_wrapper.c:1908
JNIAMediaCodecFields
Definition: mediacodec_wrapper.c:176
mediaformat_jni_getFloat
static int mediaformat_jni_getFloat(FFAMediaFormat *ctx, const char *name, float *out)
Definition: mediacodec_wrapper.c:843
JNIAMediaCodecFields::configure_id
jmethodID configure_id
Definition: mediacodec_wrapper.c:196
JNIAMediaCodecFields::configure_flag_encode_id
jfieldID configure_flag_encode_id
Definition: mediacodec_wrapper.c:188
JNIAMediaFormatFields::mediaformat_class
jclass mediaformat_class
Definition: mediacodec_wrapper.c:115
FFAMediaCodecNdk::createEncoderByType
AMediaCodec *(* createEncoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.c:1881
FF_PROFILE_H264_HIGH_422
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:1597
FFAMediaCodecNdk::getInputBuffer
uint8_t *(* getInputBuffer)(AMediaCodec *, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1893
FFAMediaFormatNdk::setBuffer
void(* setBuffer)(AMediaFormat *, const char *name, const void *data, size_t size)
Definition: mediacodec_wrapper.c:1869
media_format_jni
static const FFAMediaFormat media_format_jni
Definition: mediacodec_wrapper.c:174
FFAMediaCodec::createDecoderByType
FFAMediaCodec *(* createDecoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.h:163
FFAMediaCodec::createCodecByName
FFAMediaCodec *(* createCodecByName)(const char *name)
Definition: mediacodec_wrapper.h:162
size
int size
Definition: twinvq_data.h:10344
JNIAMediaFormatFields::get_long_id
jmethodID get_long_id
Definition: mediacodec_wrapper.c:122
media_format_ndk
static const FFAMediaFormat media_format_ndk
Definition: mediacodec_wrapper.c:1916
CREATE_ENCODER_BY_TYPE
#define CREATE_ENCODER_BY_TYPE
Definition: mediacodec_wrapper.c:1208
JNIAMediaCodecListFields::hevc_profile_main_id
jfieldID hevc_profile_main_id
Definition: mediacodec_wrapper.c:69
JNIAMediaFormatFields::set_bytebuffer_id
jmethodID set_bytebuffer_id
Definition: mediacodec_wrapper.c:130
DECLARE_NDK_AMEDIACODEC_CREATE_FUNC
#define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC(name, method)
Definition: mediacodec_wrapper.c:2176
mediacodec_ndk_dequeueOutputBuffer
static ssize_t mediacodec_ndk_dequeueOutputBuffer(FFAMediaCodec *ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:2310
FFAMediaCodecNdk::releaseOutputBufferAtTime
media_status_t(* releaseOutputBufferAtTime)(AMediaCodec *mData, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:1905
JNIAMediaCodecFields::start_id
jmethodID start_id
Definition: mediacodec_wrapper.c:197
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
ff_AMediaCodecProfile_getProfileFromAVCodecContext
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
Definition: mediacodec_wrapper.c:327
mediacodec_jni_infoOutputFormatChanged
static int mediacodec_jni_infoOutputFormatChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1717
JNIAMediaFormatFields::get_integer_id
jmethodID get_integer_id
Definition: mediacodec_wrapper.c:121
amediaformat_ndk_class
static const AVClass amediaformat_ndk_class
Definition: mediacodec_wrapper.c:1919
ff_AMediaCodec_createDecoderByType
FFAMediaCodec * ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2498
ff_jni_jstring_to_utf_chars
char * ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx)
Definition: ffjni.c:98
FFAMediaCodecNdk::impl
AMediaCodec * impl
Definition: mediacodec_wrapper.c:1876
FFAMediaCodec::class
const AVClass * class
Definition: mediacodec_wrapper.h:158
mediaformat_ndk_new
static FFAMediaFormat * mediaformat_ndk_new(void)
Definition: mediacodec_wrapper.c:1985
FFAMediaCodecNdk::stop
media_status_t(* stop)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1890
JNIAMediaCodecListFields::color_formats_id
jfieldID color_formats_id
Definition: mediacodec_wrapper.c:54
CREATE_DECODER_BY_TYPE
#define CREATE_DECODER_BY_TYPE
Definition: mediacodec_wrapper.c:1207
JNIAMediaFormatFields::set_integer_id
jmethodID set_integer_id
Definition: mediacodec_wrapper.c:127
FF_JNI_FIELD
@ FF_JNI_FIELD
Definition: ffjni.h:91
mediaformat_ndk_create
static FFAMediaFormat * mediaformat_ndk_create(AMediaFormat *impl)
Definition: mediacodec_wrapper.c:1931
mediacodec_jni_flush
static int mediacodec_jni_flush(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1459
buffer_data
Definition: avio_reading.c:37
FFANativeWindow
Definition: mediacodec_surface.h:28
mediacodec_ndk_delete
static int mediacodec_ndk_delete(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2186
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
mediacodec_wrapper.h
FF_PROFILE_HEVC_MAIN_STILL_PICTURE
#define FF_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: avcodec.h:1640
ffjni.h
FFAMediaCodec
Definition: mediacodec_wrapper.h:157
mediacodec_ndk_getOutputFormat
static FFAMediaFormat * mediacodec_ndk_getOutputFormat(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2325
FFAMediaCodecNdk::getOutputBuffer
uint8_t *(* getOutputBuffer)(AMediaCodec *, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1894
mediacodec_ndk_signalEndOfInputStream
static int mediacodec_ndk_signalEndOfInputStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2403
FFAMediaCodecNdk::window
ANativeWindow * window
Definition: mediacodec_wrapper.c:1877
FFAMediaFormatJni::jfields
struct JNIAMediaFormatFields jfields
Definition: mediacodec_wrapper.c:170
JNIAMediaCodecFields::buffer_flag_key_frame_id
jfieldID buffer_flag_key_frame_id
Definition: mediacodec_wrapper.c:186
JNIAMediaCodecListFields::avc_profile_high10_id
jfieldID avc_profile_high10_id
Definition: mediacodec_wrapper.c:65
JNIAMediaCodecFields::signal_end_of_input_stream_id
jmethodID signal_end_of_input_stream_id
Definition: mediacodec_wrapper.c:216
JNIAMediaCodecListFields::avc_profile_main_id
jfieldID avc_profile_main_id
Definition: mediacodec_wrapper.c:62
ff_jni_exception_check
int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx)
Definition: ffjni.c:253
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFAMediaCodecJni::BUFFER_FLAG_END_OF_STREAM
int BUFFER_FLAG_END_OF_STREAM
Definition: mediacodec_wrapper.c:303
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
FFAMediaCodecJni::INFO_TRY_AGAIN_LATER
int INFO_TRY_AGAIN_LATER
Definition: mediacodec_wrapper.c:298
FFAMediaFormatNdk::getInt32
bool(* getInt32)(AMediaFormat *, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:1858
FFAMediaCodecNdk::dequeueOutputBuffer
ssize_t(* dequeueOutputBuffer)(AMediaCodec *, AMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1901
profile
int profile
Definition: mxfenc.c:2006
JNIAMediaCodecListFields::avc_profile_high422_id
jfieldID avc_profile_high422_id
Definition: mediacodec_wrapper.c:66
FF_PROFILE_H264_HIGH_10_INTRA
#define FF_PROFILE_H264_HIGH_10_INTRA
Definition: avcodec.h:1595
JNIAMediaCodecListFields::avc_profile_high_id
jfieldID avc_profile_high_id
Definition: mediacodec_wrapper.c:64
FFAMediaCodec::createEncoderByType
FFAMediaCodec *(* createEncoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.h:164
avcodec.h
FFAMediaCodecNdk::createDecoderByType
AMediaCodec *(* createDecoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.c:1880
mediaformat_ndk_setFloat
static void mediaformat_ndk_setFloat(FFAMediaFormat *ctx, const char *name, float value)
Definition: mediacodec_wrapper.c:2062
FF_PROFILE_H264_HIGH_444_INTRA
#define FF_PROFILE_H264_HIGH_444_INTRA
Definition: avcodec.h:1602
JNIAMediaCodecFields::mediacodec_class
jclass mediacodec_class
Definition: mediacodec_wrapper.c:178
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
FFAMediaFormat::create
FFAMediaFormat *(* create)(void)
Definition: mediacodec_wrapper.h:66
codec_init_static_fields
static int codec_init_static_fields(FFAMediaCodecJni *codec)
Definition: mediacodec_wrapper.c:1152
mediacodec_jni_getBufferFlagCodecConfig
static int mediacodec_jni_getBufferFlagCodecConfig(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1723
JNIAMediaFormatFields::get_bytebuffer_id
jmethodID get_bytebuffer_id
Definition: mediacodec_wrapper.c:124
FFAMediaFormatNdk::getSize
bool(* getSize)(AMediaFormat *, const char *name, size_t *out)
Definition: mediacodec_wrapper.c:1861
FF_PROFILE_H264_HIGH_444
#define FF_PROFILE_H264_HIGH_444
Definition: avcodec.h:1600
FF_JNI_STATIC_FIELD
@ FF_JNI_STATIC_FIELD
Definition: ffjni.h:92
mediacodec_jni_getInputBuffer
static uint8_t * mediacodec_jni_getInputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1585
FFAMediaCodecJni::buffer_info
jobject buffer_info
Definition: mediacodec_wrapper.c:293
FF_PROFILE_H264_HIGH_422_INTRA
#define FF_PROFILE_H264_HIGH_422_INTRA
Definition: avcodec.h:1598
AVCodecContext
main external API structure.
Definition: avcodec.h:398
mediacodec_jni_getConfigureFlagEncode
static int mediacodec_jni_getConfigureFlagEncode(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1741
JNI_GET_ENV_OR_RETURN
#define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret)
Definition: mediacodec_wrapper.c:313
JNIAMediaCodecListFields::profile_levels_id
jfieldID profile_levels_id
Definition: mediacodec_wrapper.c:55
FFAMediaCodecJni::object
jobject object
Definition: mediacodec_wrapper.c:292
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1550
mediacodec_ndk_getOutputBuffer
static uint8_t * mediacodec_ndk_getOutputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:2290
mediacodec_jni_signalEndOfInputStream
static int mediacodec_jni_signalEndOfInputStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1771
FFAMediaFormatNdk::libmedia
void * libmedia
Definition: mediacodec_wrapper.c:1850
FF_PROFILE_H264_MAIN
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:1591
amediaformat_class
static const AVClass amediaformat_class
Definition: mediacodec_wrapper.c:161
JNIAMediaCodecListFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:40
FFAMediaCodecJni::BUFFER_FLAG_CODEC_CONFIG
int BUFFER_FLAG_CODEC_CONFIG
Definition: mediacodec_wrapper.c:302
FFAMediaFormatJni
Definition: mediacodec_wrapper.c:167
mediaformat_ndk_toString
static char * mediaformat_ndk_toString(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:2008
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:280
mediacodec_jni_configure
static int mediacodec_jni_configure(FFAMediaCodec *ctx, const FFAMediaFormat *format_ctx, FFANativeWindow *window, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:1380
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
mem.h
JNIAMediaCodecListFields::avc_profile_high444_id
jfieldID avc_profile_high444_id
Definition: mediacodec_wrapper.c:67
FFAMediaFormatNdk::getBuffer
bool(* getBuffer)(AMediaFormat *, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:1862
mediaformat_jni_getBuffer
static int mediaformat_jni_getBuffer(FFAMediaFormat *ctx, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:882
JNIAMediaCodecListFields::level_id
jfieldID level_id
Definition: mediacodec_wrapper.c:59
JNIAMediaCodecFields::dequeue_output_buffer_id
jmethodID dequeue_output_buffer_id
Definition: mediacodec_wrapper.c:209
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
mediaformat_ndk_setInt64
static void mediaformat_ndk_setInt64(FFAMediaFormat *ctx, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:2056
mediacodec_jni_stop
static int mediacodec_jni_stop(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1441
FF_JNI_STATIC_METHOD
@ FF_JNI_STATIC_METHOD
Definition: ffjni.h:94
FFAMediaFormat::class
const AVClass * class
Definition: mediacodec_wrapper.h:64
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
FF_PROFILE_H264_HIGH_10
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:1594
ndk_codec_create
static FFAMediaCodec * ndk_codec_create(int method, const char *arg)
Definition: mediacodec_wrapper.c:2100
JNIAMediaCodecFields::info_output_buffers_changed_id
jfieldID info_output_buffers_changed_id
Definition: mediacodec_wrapper.c:181
int32_t
int32_t
Definition: audioconvert.c:56
convert_header.str
string str
Definition: convert_header.py:20
MEDIACODEC_NDK_WRAPPER
#define MEDIACODEC_NDK_WRAPPER(method)
Definition: mediacodec_wrapper.c:2266
FFAMediaCodecNdk::configure
media_status_t(* configure)(AMediaCodec *, const AMediaFormat *format, ANativeWindow *surface, AMediaCrypto *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:1884
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
FFAMediaCodecJni
Definition: mediacodec_wrapper.c:287
mediacodec_jni_getOutputBuffer
static uint8_t * mediacodec_jni_getOutputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1633
mediacodec_ndk_releaseOutputBufferAtTime
static int mediacodec_ndk_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:2349
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
JNIAMediaCodecFields::flags_id
jfieldID flags_id
Definition: mediacodec_wrapper.c:222
FFAMediaCodecNdk::releaseName
void(* releaseName)(AMediaCodec *, char *name)
Definition: mediacodec_wrapper.c:1909
FFAMediaFormatNdk::api
FFAMediaFormat api
Definition: mediacodec_wrapper.c:1848
JNIAMediaCodecListFields::avc_profile_baseline_id
jfieldID avc_profile_baseline_id
Definition: mediacodec_wrapper.c:61
avstring.h
jni.h
media_codec_jni
static const FFAMediaCodec media_codec_jni
Definition: mediacodec_wrapper.c:311
JNIAMediaFormatFields::contains_key_id
jmethodID contains_key_id
Definition: mediacodec_wrapper.c:119
mediacodec_ndk_infoOutputFormatChanged
static int mediacodec_ndk_infoOutputFormatChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2373
FFAMediaCodecNdk::flush
media_status_t(* flush)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1891
mediaformat_jni_toString
static char * mediaformat_jni_toString(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:740
JNIAMediaCodecListFields::codec_capabilities_class
jclass codec_capabilities_class
Definition: mediacodec_wrapper.c:53
mediaformat_ndk_setString
static void mediaformat_ndk_setString(FFAMediaFormat *ctx, const char *name, const char *value)
Definition: mediacodec_wrapper.c:2068
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
JNIAMediaFormatFields::set_string_id
jmethodID set_string_id
Definition: mediacodec_wrapper.c:131
mediaformat_ndk_delete
static int mediaformat_ndk_delete(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:1990
codec_create
static FFAMediaCodec * codec_create(int method, const char *arg)
Definition: mediacodec_wrapper.c:1210
FFAMediaFormatJni::object
jobject object
Definition: mediacodec_wrapper.c:171
FFAMediaCodecNdk::releaseOutputBuffer
media_status_t(* releaseOutputBuffer)(AMediaCodec *, size_t idx, bool render)
Definition: mediacodec_wrapper.c:1904
mediaformat_jni_setFloat
static void mediaformat_jni_setFloat(FFAMediaFormat *ctx, const char *name, float value)
Definition: mediacodec_wrapper.c:1042
mediacodec_ndk_configure
static int mediacodec_ndk_configure(FFAMediaCodec *ctx, const FFAMediaFormat *format_ctx, FFANativeWindow *window, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:2207