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 <stdbool.h>
26 #include <media/NdkMediaFormat.h>
27 #include <media/NdkMediaCodec.h>
28 #include <android/native_window_jni.h>
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/avstring.h"
33 
34 #include "avcodec.h"
35 #include "ffjni.h"
36 #include "mediacodec_wrapper.h"
37 
39 
41  jmethodID init_id;
43 
44  jmethodID get_codec_count_id;
46 
48  jmethodID get_name_id;
51  jmethodID is_encoder_id;
53 
55  jfieldID color_formats_id;
57 
59  jfieldID profile_id;
60  jfieldID level_id;
61 };
62 
63 #define OFFSET(x) offsetof(struct JNIAMediaCodecListFields, x)
64 static const struct FFJniField jni_amediacodeclist_mapping[] = {
65  { "android/media/MediaCodecList", NULL, NULL, FF_JNI_CLASS, OFFSET(mediacodec_list_class), 1 },
66  { "android/media/MediaCodecList", "<init>", "(I)V", FF_JNI_METHOD, OFFSET(init_id), 0 },
67  { "android/media/MediaCodecList", "findDecoderForFormat", "(Landroid/media/MediaFormat;)Ljava/lang/String;", FF_JNI_METHOD, OFFSET(find_decoder_for_format_id), 0 },
68 
69  { "android/media/MediaCodecList", "getCodecCount", "()I", FF_JNI_STATIC_METHOD, OFFSET(get_codec_count_id), 1 },
70  { "android/media/MediaCodecList", "getCodecInfoAt", "(I)Landroid/media/MediaCodecInfo;", FF_JNI_STATIC_METHOD, OFFSET(get_codec_info_at_id), 1 },
71 
72  { "android/media/MediaCodecInfo", NULL, NULL, FF_JNI_CLASS, OFFSET(mediacodec_info_class), 1 },
73  { "android/media/MediaCodecInfo", "getName", "()Ljava/lang/String;", FF_JNI_METHOD, OFFSET(get_name_id), 1 },
74  { "android/media/MediaCodecInfo", "getCapabilitiesForType", "(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", FF_JNI_METHOD, OFFSET(get_codec_capabilities_id), 1 },
75  { "android/media/MediaCodecInfo", "getSupportedTypes", "()[Ljava/lang/String;", FF_JNI_METHOD, OFFSET(get_supported_types_id), 1 },
76  { "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, OFFSET(is_encoder_id), 1 },
77  { "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", FF_JNI_METHOD, OFFSET(is_software_only_id), 0 },
78 
79  { "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, FF_JNI_CLASS, OFFSET(codec_capabilities_class), 1 },
80  { "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", "[I", FF_JNI_FIELD, OFFSET(color_formats_id), 1 },
81  { "android/media/MediaCodecInfo$CodecCapabilities", "profileLevels", "[Landroid/media/MediaCodecInfo$CodecProfileLevel;", FF_JNI_FIELD, OFFSET(profile_levels_id), 1 },
82 
83  { "android/media/MediaCodecInfo$CodecProfileLevel", NULL, NULL, FF_JNI_CLASS, OFFSET(codec_profile_level_class), 1 },
84  { "android/media/MediaCodecInfo$CodecProfileLevel", "profile", "I", FF_JNI_FIELD, OFFSET(profile_id), 1 },
85  { "android/media/MediaCodecInfo$CodecProfileLevel", "level", "I", FF_JNI_FIELD, OFFSET(level_id), 1 },
86 
87  { NULL }
88 };
89 #undef OFFSET
90 
92 
94 
95  jmethodID init_id;
96 
97  jmethodID contains_key_id;
98 
99  jmethodID get_integer_id;
100  jmethodID get_long_id;
101  jmethodID get_float_id;
102  jmethodID get_bytebuffer_id;
103  jmethodID get_string_id;
104 
105  jmethodID set_integer_id;
106  jmethodID set_long_id;
107  jmethodID set_float_id;
108  jmethodID set_bytebuffer_id;
109  jmethodID set_string_id;
110 
111  jmethodID to_string_id;
112 
113 };
114 
115 #define OFFSET(x) offsetof(struct JNIAMediaFormatFields, x)
116 static const struct FFJniField jni_amediaformat_mapping[] = {
117  { "android/media/MediaFormat", NULL, NULL, FF_JNI_CLASS, OFFSET(mediaformat_class), 1 },
118 
119  { "android/media/MediaFormat", "<init>", "()V", FF_JNI_METHOD, OFFSET(init_id), 1 },
120 
121  { "android/media/MediaFormat", "containsKey", "(Ljava/lang/String;)Z", FF_JNI_METHOD, OFFSET(contains_key_id), 1 },
122 
123  { "android/media/MediaFormat", "getInteger", "(Ljava/lang/String;)I", FF_JNI_METHOD, OFFSET(get_integer_id), 1 },
124  { "android/media/MediaFormat", "getLong", "(Ljava/lang/String;)J", FF_JNI_METHOD, OFFSET(get_long_id), 1 },
125  { "android/media/MediaFormat", "getFloat", "(Ljava/lang/String;)F", FF_JNI_METHOD, OFFSET(get_float_id), 1 },
126  { "android/media/MediaFormat", "getByteBuffer", "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_bytebuffer_id), 1 },
127  { "android/media/MediaFormat", "getString", "(Ljava/lang/String;)Ljava/lang/String;", FF_JNI_METHOD, OFFSET(get_string_id), 1 },
128 
129  { "android/media/MediaFormat", "setInteger", "(Ljava/lang/String;I)V", FF_JNI_METHOD, OFFSET(set_integer_id), 1 },
130  { "android/media/MediaFormat", "setLong", "(Ljava/lang/String;J)V", FF_JNI_METHOD, OFFSET(set_long_id), 1 },
131  { "android/media/MediaFormat", "setFloat", "(Ljava/lang/String;F)V", FF_JNI_METHOD, OFFSET(set_float_id), 1 },
132  { "android/media/MediaFormat", "setByteBuffer", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V", FF_JNI_METHOD, OFFSET(set_bytebuffer_id), 1 },
133  { "android/media/MediaFormat", "setString", "(Ljava/lang/String;Ljava/lang/String;)V", FF_JNI_METHOD, OFFSET(set_string_id), 1 },
134 
135  { "android/media/MediaFormat", "toString", "()Ljava/lang/String;", FF_JNI_METHOD, OFFSET(to_string_id), 1 },
136 
137  { NULL }
138 };
139 #undef OFFSET
140 
141 static const AVClass amediaformat_class = {
142  .class_name = "amediaformat",
143  .item_name = av_default_item_name,
144  .version = LIBAVUTIL_VERSION_INT,
145 };
146 
147 typedef struct FFAMediaFormatJni {
149 
151  jobject object;
153 
155 
157 
159 
163 
167 
169 
173 
174  jmethodID get_name_id;
175 
176  jmethodID configure_id;
177  jmethodID start_id;
178  jmethodID flush_id;
179  jmethodID stop_id;
180  jmethodID release_id;
181 
183 
188 
194 
197 
199 
200  jmethodID init_id;
201 
202  jfieldID flags_id;
203  jfieldID offset_id;
205  jfieldID size_id;
206 
207 };
208 
209 #define OFFSET(x) offsetof(struct JNIAMediaCodecFields, x)
210 static const struct FFJniField jni_amediacodec_mapping[] = {
211  { "android/media/MediaCodec", NULL, NULL, FF_JNI_CLASS, OFFSET(mediacodec_class), 1 },
212 
213  { "android/media/MediaCodec", "INFO_TRY_AGAIN_LATER", "I", FF_JNI_STATIC_FIELD, OFFSET(info_try_again_later_id), 1 },
214  { "android/media/MediaCodec", "INFO_OUTPUT_BUFFERS_CHANGED", "I", FF_JNI_STATIC_FIELD, OFFSET(info_output_buffers_changed_id), 1 },
215  { "android/media/MediaCodec", "INFO_OUTPUT_FORMAT_CHANGED", "I", FF_JNI_STATIC_FIELD, OFFSET(info_output_format_changed_id), 1 },
216 
217  { "android/media/MediaCodec", "BUFFER_FLAG_CODEC_CONFIG", "I", FF_JNI_STATIC_FIELD, OFFSET(buffer_flag_codec_config_id), 1 },
218  { "android/media/MediaCodec", "BUFFER_FLAG_END_OF_STREAM", "I", FF_JNI_STATIC_FIELD, OFFSET(buffer_flag_end_of_stream_id), 1 },
219  { "android/media/MediaCodec", "BUFFER_FLAG_KEY_FRAME", "I", FF_JNI_STATIC_FIELD, OFFSET(buffer_flag_key_frame_id), 0 },
220 
221  { "android/media/MediaCodec", "CONFIGURE_FLAG_ENCODE", "I", FF_JNI_STATIC_FIELD, OFFSET(configure_flag_encode_id), 1 },
222 
223  { "android/media/MediaCodec", "createByCodecName", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, OFFSET(create_by_codec_name_id), 1 },
224  { "android/media/MediaCodec", "createDecoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, OFFSET(create_decoder_by_type_id), 1 },
225  { "android/media/MediaCodec", "createEncoderByType", "(Ljava/lang/String;)Landroid/media/MediaCodec;", FF_JNI_STATIC_METHOD, OFFSET(create_encoder_by_type_id), 1 },
226 
227  { "android/media/MediaCodec", "getName", "()Ljava/lang/String;", FF_JNI_METHOD, OFFSET(get_name_id), 1 },
228 
229  { "android/media/MediaCodec", "configure", "(Landroid/media/MediaFormat;Landroid/view/Surface;Landroid/media/MediaCrypto;I)V", FF_JNI_METHOD, OFFSET(configure_id), 1 },
230  { "android/media/MediaCodec", "start", "()V", FF_JNI_METHOD, OFFSET(start_id), 1 },
231  { "android/media/MediaCodec", "flush", "()V", FF_JNI_METHOD, OFFSET(flush_id), 1 },
232  { "android/media/MediaCodec", "stop", "()V", FF_JNI_METHOD, OFFSET(stop_id), 1 },
233  { "android/media/MediaCodec", "release", "()V", FF_JNI_METHOD, OFFSET(release_id), 1 },
234 
235  { "android/media/MediaCodec", "getOutputFormat", "()Landroid/media/MediaFormat;", FF_JNI_METHOD, OFFSET(get_output_format_id), 1 },
236 
237  { "android/media/MediaCodec", "dequeueInputBuffer", "(J)I", FF_JNI_METHOD, OFFSET(dequeue_input_buffer_id), 1 },
238  { "android/media/MediaCodec", "queueInputBuffer", "(IIIJI)V", FF_JNI_METHOD, OFFSET(queue_input_buffer_id), 1 },
239  { "android/media/MediaCodec", "getInputBuffer", "(I)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_input_buffer_id), 0 },
240  { "android/media/MediaCodec", "getInputBuffers", "()[Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_input_buffers_id), 1 },
241 
242  { "android/media/MediaCodec", "dequeueOutputBuffer", "(Landroid/media/MediaCodec$BufferInfo;J)I", FF_JNI_METHOD, OFFSET(dequeue_output_buffer_id), 1 },
243  { "android/media/MediaCodec", "getOutputBuffer", "(I)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_output_buffer_id), 0 },
244  { "android/media/MediaCodec", "getOutputBuffers", "()[Ljava/nio/ByteBuffer;", FF_JNI_METHOD, OFFSET(get_output_buffers_id), 1 },
245  { "android/media/MediaCodec", "releaseOutputBuffer", "(IZ)V", FF_JNI_METHOD, OFFSET(release_output_buffer_id), 1 },
246  { "android/media/MediaCodec", "releaseOutputBuffer", "(IJ)V", FF_JNI_METHOD, OFFSET(release_output_buffer_at_time_id), 0 },
247 
248  { "android/media/MediaCodec", "setInputSurface", "(Landroid/view/Surface;)V", FF_JNI_METHOD, OFFSET(set_input_surface_id), 0 },
249  { "android/media/MediaCodec", "signalEndOfInputStream", "()V", FF_JNI_METHOD, OFFSET(signal_end_of_input_stream_id), 0 },
250 
251  { "android/media/MediaCodec$BufferInfo", NULL, NULL, FF_JNI_CLASS, OFFSET(mediainfo_class), 1 },
252 
253  { "android/media/MediaCodec.BufferInfo", "<init>", "()V", FF_JNI_METHOD, OFFSET(init_id), 1 },
254  { "android/media/MediaCodec.BufferInfo", "flags", "I", FF_JNI_FIELD, OFFSET(flags_id), 1 },
255  { "android/media/MediaCodec.BufferInfo", "offset", "I", FF_JNI_FIELD, OFFSET(offset_id), 1 },
256  { "android/media/MediaCodec.BufferInfo", "presentationTimeUs", "J", FF_JNI_FIELD, OFFSET(presentation_time_us_id), 1 },
257  { "android/media/MediaCodec.BufferInfo", "size", "I", FF_JNI_FIELD, OFFSET(size_id), 1 },
258 
259  { NULL }
260 };
261 #undef OFFSET
262 
263 static const AVClass amediacodec_class = {
264  .class_name = "amediacodec",
265  .item_name = av_default_item_name,
266  .version = LIBAVUTIL_VERSION_INT,
267 };
268 
269 typedef struct FFAMediaCodecJni {
271 
273 
274  jobject object;
275  jobject buffer_info;
276 
277  jobject input_buffers;
278  jobject output_buffers;
279 
283 
287 
289 
292 
294 
295 #define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret) do { \
296  (env) = ff_jni_get_env(log_ctx); \
297  if (!(env)) { \
298  return ret; \
299  } \
300 } while (0)
301 
302 #define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx) do { \
303  (env) = ff_jni_get_env(log_ctx); \
304  if (!(env)) { \
305  return; \
306  } \
307 } while (0)
308 
310 {
311  // Copy and modified from MediaCodecInfo.java
312  static const int AVCProfileBaseline = 0x01;
313  static const int AVCProfileMain = 0x02;
314  static const int AVCProfileExtended = 0x04;
315  static const int AVCProfileHigh = 0x08;
316  static const int AVCProfileHigh10 = 0x10;
317  static const int AVCProfileHigh422 = 0x20;
318  static const int AVCProfileHigh444 = 0x40;
319  static const int AVCProfileConstrainedBaseline = 0x10000;
320  static const int AVCProfileConstrainedHigh = 0x80000;
321 
322  static const int HEVCProfileMain = 0x01;
323  static const int HEVCProfileMain10 = 0x02;
324  static const int HEVCProfileMainStill = 0x04;
325  static const int HEVCProfileMain10HDR10 = 0x1000;
326  static const int HEVCProfileMain10HDR10Plus = 0x2000;
327 
328  static const int VP9Profile0 = 0x01;
329  static const int VP9Profile1 = 0x02;
330  static const int VP9Profile2 = 0x04;
331  static const int VP9Profile3 = 0x08;
332  static const int VP9Profile2HDR = 0x1000;
333  static const int VP9Profile3HDR = 0x2000;
334  static const int VP9Profile2HDR10Plus = 0x4000;
335  static const int VP9Profile3HDR10Plus = 0x8000;
336 
337  static const int MPEG4ProfileSimple = 0x01;
338  static const int MPEG4ProfileSimpleScalable = 0x02;
339  static const int MPEG4ProfileCore = 0x04;
340  static const int MPEG4ProfileMain = 0x08;
341  static const int MPEG4ProfileNbit = 0x10;
342  static const int MPEG4ProfileScalableTexture = 0x20;
343  static const int MPEG4ProfileSimpleFBA = 0x80;
344  static const int MPEG4ProfileSimpleFace = 0x40;
345  static const int MPEG4ProfileBasicAnimated = 0x100;
346  static const int MPEG4ProfileHybrid = 0x200;
347  static const int MPEG4ProfileAdvancedRealTime = 0x400;
348  static const int MPEG4ProfileCoreScalable = 0x800;
349  static const int MPEG4ProfileAdvancedCoding = 0x1000;
350  static const int MPEG4ProfileAdvancedCore = 0x2000;
351  static const int MPEG4ProfileAdvancedScalable = 0x4000;
352  static const int MPEG4ProfileAdvancedSimple = 0x8000;
353 
354 
355  static const int AV1ProfileMain8 = 0x1;
356  static const int AV1ProfileMain10 = 0x2;
357  static const int AV1ProfileMain10HDR10 = 0x1000;
358  static const int AV1ProfileMain10HDR10Plus = 0x2000;
359 
360  // Unused yet.
361  (void)AVCProfileConstrainedHigh;
362  (void)HEVCProfileMain10HDR10;
363  (void)HEVCProfileMain10HDR10Plus;
364  (void)VP9Profile2HDR;
365  (void)VP9Profile3HDR;
366  (void)VP9Profile2HDR10Plus;
367  (void)VP9Profile3HDR10Plus;
368  (void)AV1ProfileMain10;
369  (void)AV1ProfileMain10HDR10;
370  (void)AV1ProfileMain10HDR10Plus;
371 
372  if (avctx->codec_id == AV_CODEC_ID_H264) {
373  switch(avctx->profile) {
375  return AVCProfileBaseline;
377  return AVCProfileConstrainedBaseline;
379  return AVCProfileMain;
380  break;
382  return AVCProfileExtended;
384  return AVCProfileHigh;
387  return AVCProfileHigh10;
390  return AVCProfileHigh422;
394  return AVCProfileHigh444;
395  }
396  } else if (avctx->codec_id == AV_CODEC_ID_HEVC) {
397  switch (avctx->profile) {
399  return HEVCProfileMain;
401  return HEVCProfileMainStill;
403  return HEVCProfileMain10;
404  }
405  } else if (avctx->codec_id == AV_CODEC_ID_VP9) {
406  switch (avctx->profile) {
407  case AV_PROFILE_VP9_0:
408  return VP9Profile0;
409  case AV_PROFILE_VP9_1:
410  return VP9Profile1;
411  case AV_PROFILE_VP9_2:
412  return VP9Profile2;
413  case AV_PROFILE_VP9_3:
414  return VP9Profile3;
415  }
416  } else if(avctx->codec_id == AV_CODEC_ID_MPEG4) {
417  switch (avctx->profile)
418  {
420  return MPEG4ProfileSimple;
422  return MPEG4ProfileSimpleScalable;
424  return MPEG4ProfileCore;
426  return MPEG4ProfileMain;
428  return MPEG4ProfileNbit;
430  return MPEG4ProfileScalableTexture;
432  return MPEG4ProfileSimpleFBA;
434  return MPEG4ProfileBasicAnimated;
436  return MPEG4ProfileHybrid;
438  return MPEG4ProfileAdvancedRealTime;
440  return MPEG4ProfileCoreScalable;
442  return MPEG4ProfileAdvancedCoding;
444  return MPEG4ProfileAdvancedCore;
446  return MPEG4ProfileAdvancedScalable;
448  return MPEG4ProfileAdvancedSimple;
450  // Studio profiles are not supported by mediacodec.
451  default:
452  break;
453  }
454  } else if(avctx->codec_id == AV_CODEC_ID_AV1) {
455  switch (avctx->profile)
456  {
457  case AV_PROFILE_AV1_MAIN:
458  return AV1ProfileMain8;
459  case AV_PROFILE_AV1_HIGH:
461  default:
462  break;
463  }
464  }
465 
466  return -1;
467 }
468 
469 char *ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
470 {
471  int ret;
472  int i;
473  int codec_count;
474  int found_codec = 0;
475  char *name = NULL;
476  char *supported_type = NULL;
477 
478  JNIEnv *env = NULL;
479  struct JNIAMediaCodecListFields jfields = { 0 };
480  struct JNIAMediaFormatFields mediaformat_jfields = { 0 };
481 
482  jobject codec_name = NULL;
483 
484  jobject info = NULL;
485  jobject type = NULL;
486  jobjectArray types = NULL;
487 
488  jobject capabilities = NULL;
489  jobject profile_level = NULL;
490  jobjectArray profile_levels = NULL;
491 
492  JNI_GET_ENV_OR_RETURN(env, log_ctx, NULL);
493 
494  if ((ret = ff_jni_init_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx)) < 0) {
495  goto done;
496  }
497 
498  if ((ret = ff_jni_init_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx)) < 0) {
499  goto done;
500  }
501 
502  codec_count = (*env)->CallStaticIntMethod(env, jfields.mediacodec_list_class, jfields.get_codec_count_id);
503  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
504  goto done;
505  }
506 
507  for(i = 0; i < codec_count; i++) {
508  int j;
509  int type_count;
510  int is_encoder;
511 
512  info = (*env)->CallStaticObjectMethod(env, jfields.mediacodec_list_class, jfields.get_codec_info_at_id, i);
513  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
514  goto done;
515  }
516 
517  types = (*env)->CallObjectMethod(env, info, jfields.get_supported_types_id);
518  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
519  goto done;
520  }
521 
522  is_encoder = (*env)->CallBooleanMethod(env, info, jfields.is_encoder_id);
523  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
524  goto done;
525  }
526 
527  if (is_encoder != encoder) {
528  goto done_with_info;
529  }
530 
531  if (jfields.is_software_only_id) {
532  int is_software_only = (*env)->CallBooleanMethod(env, info, jfields.is_software_only_id);
533  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
534  goto done;
535  }
536 
537  if (is_software_only) {
538  goto done_with_info;
539  }
540  }
541 
542  codec_name = (*env)->CallObjectMethod(env, info, jfields.get_name_id);
543  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
544  goto done;
545  }
546 
547  name = ff_jni_jstring_to_utf_chars(env, codec_name, log_ctx);
548  if (!name) {
549  goto done;
550  }
551 
552  (*env)->DeleteLocalRef(env, codec_name);
553  codec_name = NULL;
554 
555  /* Skip software decoders */
556  if (
557  strstr(name, "OMX.google") ||
558  strstr(name, "OMX.ffmpeg") ||
559  (strstr(name, "OMX.SEC") && strstr(name, ".sw.")) ||
560  !strcmp(name, "OMX.qcom.video.decoder.hevcswvdec")) {
561  goto done_with_info;
562  }
563 
564  type_count = (*env)->GetArrayLength(env, types);
565  for (j = 0; j < type_count; j++) {
566  int k;
567  int profile_count;
568 
569  type = (*env)->GetObjectArrayElement(env, types, j);
570  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
571  goto done;
572  }
573 
574  supported_type = ff_jni_jstring_to_utf_chars(env, type, log_ctx);
575  if (!supported_type) {
576  goto done;
577  }
578 
579  if (av_strcasecmp(supported_type, mime)) {
580  goto done_with_type;
581  }
582 
583  capabilities = (*env)->CallObjectMethod(env, info, jfields.get_codec_capabilities_id, type);
584  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
585  goto done;
586  }
587 
588  profile_levels = (*env)->GetObjectField(env, capabilities, jfields.profile_levels_id);
589  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
590  goto done;
591  }
592 
593  profile_count = (*env)->GetArrayLength(env, profile_levels);
594  if (!profile_count) {
595  found_codec = 1;
596  }
597  for (k = 0; k < profile_count; k++) {
598  int supported_profile = 0;
599 
600  if (profile < 0) {
601  found_codec = 1;
602  break;
603  }
604 
605  profile_level = (*env)->GetObjectArrayElement(env, profile_levels, k);
606  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
607  goto done;
608  }
609 
610  supported_profile = (*env)->GetIntField(env, profile_level, jfields.profile_id);
611  if (ff_jni_exception_check(env, 1, log_ctx) < 0) {
612  goto done;
613  }
614 
615  found_codec = profile == supported_profile;
616 
617  (*env)->DeleteLocalRef(env, profile_level);
618  profile_level = NULL;
619 
620  if (found_codec) {
621  break;
622  }
623  }
624 
625 done_with_type:
626  (*env)->DeleteLocalRef(env, profile_levels);
627  profile_levels = NULL;
628 
629  (*env)->DeleteLocalRef(env, capabilities);
630  capabilities = NULL;
631 
632  (*env)->DeleteLocalRef(env, type);
633  type = NULL;
634 
635  av_freep(&supported_type);
636 
637  if (found_codec) {
638  break;
639  }
640  }
641 
642 done_with_info:
643  (*env)->DeleteLocalRef(env, info);
644  info = NULL;
645 
646  (*env)->DeleteLocalRef(env, types);
647  types = NULL;
648 
649  if (found_codec) {
650  break;
651  }
652 
653  av_freep(&name);
654  }
655 
656 done:
657  (*env)->DeleteLocalRef(env, codec_name);
658  (*env)->DeleteLocalRef(env, info);
659  (*env)->DeleteLocalRef(env, type);
660  (*env)->DeleteLocalRef(env, types);
661  (*env)->DeleteLocalRef(env, capabilities);
662  (*env)->DeleteLocalRef(env, profile_level);
663  (*env)->DeleteLocalRef(env, profile_levels);
664 
665  av_freep(&supported_type);
666 
667  ff_jni_reset_jfields(env, &jfields, jni_amediacodeclist_mapping, 0, log_ctx);
668  ff_jni_reset_jfields(env, &mediaformat_jfields, jni_amediaformat_mapping, 0, log_ctx);
669 
670  if (!found_codec) {
671  av_freep(&name);
672  }
673 
674  return name;
675 }
676 
678 {
679  JNIEnv *env = NULL;
681  jobject object = NULL;
682 
683  format = av_mallocz(sizeof(*format));
684  if (!format) {
685  return NULL;
686  }
687  format->api = media_format_jni;
688 
689  env = ff_jni_get_env(format);
690  if (!env) {
691  av_freep(&format);
692  return NULL;
693  }
694 
695  if (ff_jni_init_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format) < 0) {
696  goto fail;
697  }
698 
699  object = (*env)->NewObject(env, format->jfields.mediaformat_class, format->jfields.init_id);
700  if (!object) {
701  goto fail;
702  }
703 
704  format->object = (*env)->NewGlobalRef(env, object);
705  if (!format->object) {
706  goto fail;
707  }
708 
709 fail:
710  (*env)->DeleteLocalRef(env, object);
711 
712  if (!format->object) {
714  av_freep(&format);
715  }
716 
717  return (FFAMediaFormat *)format;
718 }
719 
721 {
722  JNIEnv *env = NULL;
724 
725  format = av_mallocz(sizeof(*format));
726  if (!format) {
727  return NULL;
728  }
729  format->api = media_format_jni;
730 
731  env = ff_jni_get_env(format);
732  if (!env) {
733  av_freep(&format);
734  return NULL;
735  }
736 
737  if (ff_jni_init_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format) < 0) {
738  goto fail;
739  }
740 
741  format->object = (*env)->NewGlobalRef(env, object);
742  if (!format->object) {
743  goto fail;
744  }
745 
746  return (FFAMediaFormat *)format;
747 fail:
749 
750  av_freep(&format);
751 
752  return NULL;
753 }
754 
756 {
757  int ret = 0;
759  JNIEnv *env = NULL;
760 
761  if (!format) {
762  return 0;
763  }
764 
766 
767  (*env)->DeleteGlobalRef(env, format->object);
768  format->object = NULL;
769 
771 
772  av_freep(&format);
773 
774  return ret;
775 }
776 
778 {
779  char *ret = NULL;
781  JNIEnv *env = NULL;
782  jstring description = NULL;
783 
784  av_assert0(format != NULL);
785 
787 
788  description = (*env)->CallObjectMethod(env, format->object, format->jfields.to_string_id);
789  if (ff_jni_exception_check(env, 1, NULL) < 0) {
790  goto fail;
791  }
792 
794 fail:
795  (*env)->DeleteLocalRef(env, description);
796 
797  return ret;
798 }
799 
801 {
802  int ret = 1;
804  JNIEnv *env = NULL;
805  jstring key = NULL;
806  jboolean contains_key;
807 
808  av_assert0(format != NULL);
809 
810  JNI_GET_ENV_OR_RETURN(env, format, 0);
811 
813  if (!key) {
814  ret = 0;
815  goto fail;
816  }
817 
818  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
819  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
820  ret = 0;
821  goto fail;
822  }
823 
824  *out = (*env)->CallIntMethod(env, format->object, format->jfields.get_integer_id, key);
825  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
826  ret = 0;
827  goto fail;
828  }
829 
830  ret = 1;
831 fail:
832  (*env)->DeleteLocalRef(env, key);
833 
834  return ret;
835 }
836 
837 static int mediaformat_jni_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
838 {
839  int ret = 1;
841  JNIEnv *env = NULL;
842  jstring key = NULL;
843  jboolean contains_key;
844 
845  av_assert0(format != NULL);
846 
847  JNI_GET_ENV_OR_RETURN(env, format, 0);
848 
850  if (!key) {
851  ret = 0;
852  goto fail;
853  }
854 
855  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
856  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
857  ret = 0;
858  goto fail;
859  }
860 
861  *out = (*env)->CallLongMethod(env, format->object, format->jfields.get_long_id, key);
862  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
863  ret = 0;
864  goto fail;
865  }
866 
867  ret = 1;
868 fail:
869  (*env)->DeleteLocalRef(env, key);
870 
871  return ret;
872 }
873 
874 static int mediaformat_jni_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
875 {
876  int ret = 1;
878  JNIEnv *env = NULL;
879  jstring key = NULL;
880  jboolean contains_key;
881 
882  av_assert0(format != NULL);
883 
884  JNI_GET_ENV_OR_RETURN(env, format, 0);
885 
887  if (!key) {
888  ret = 0;
889  goto fail;
890  }
891 
892  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
893  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
894  ret = 0;
895  goto fail;
896  }
897 
898  *out = (*env)->CallFloatMethod(env, format->object, format->jfields.get_float_id, key);
899  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
900  ret = 0;
901  goto fail;
902  }
903 
904  ret = 1;
905 fail:
906  (*env)->DeleteLocalRef(env, key);
907 
908  return ret;
909 }
910 
911 static int mediaformat_jni_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
912 {
913  int ret = 1;
915  JNIEnv *env = NULL;
916  jstring key = NULL;
917  jboolean contains_key;
918  jobject result = NULL;
919 
920  av_assert0(format != NULL);
921 
922  JNI_GET_ENV_OR_RETURN(env, format, 0);
923 
925  if (!key) {
926  ret = 0;
927  goto fail;
928  }
929 
930  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
931  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
932  ret = 0;
933  goto fail;
934  }
935 
936  result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_bytebuffer_id, key);
937  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
938  ret = 0;
939  goto fail;
940  }
941 
942  *data = (*env)->GetDirectBufferAddress(env, result);
943  *size = (*env)->GetDirectBufferCapacity(env, result);
944 
945  if (*data && *size) {
946  void *src = *data;
947  *data = av_malloc(*size);
948  if (!*data) {
949  ret = 0;
950  goto fail;
951  }
952 
953  memcpy(*data, src, *size);
954  }
955 
956  ret = 1;
957 fail:
958  (*env)->DeleteLocalRef(env, key);
959  (*env)->DeleteLocalRef(env, result);
960 
961  return ret;
962 }
963 
964 static int mediaformat_jni_getString(FFAMediaFormat* ctx, const char *name, const char **out)
965 {
966  int ret = 1;
968  JNIEnv *env = NULL;
969  jstring key = NULL;
970  jboolean contains_key;
971  jstring result = NULL;
972 
973  av_assert0(format != NULL);
974 
975  JNI_GET_ENV_OR_RETURN(env, format, 0);
976 
978  if (!key) {
979  ret = 0;
980  goto fail;
981  }
982 
983  contains_key = (*env)->CallBooleanMethod(env, format->object, format->jfields.contains_key_id, key);
984  if (!contains_key || (ret = ff_jni_exception_check(env, 1, format)) < 0) {
985  ret = 0;
986  goto fail;
987  }
988 
989  result = (*env)->CallObjectMethod(env, format->object, format->jfields.get_string_id, key);
990  if ((ret = ff_jni_exception_check(env, 1, format)) < 0) {
991  ret = 0;
992  goto fail;
993  }
994 
996  if (!*out) {
997  ret = 0;
998  goto fail;
999  }
1000 
1001  ret = 1;
1002 fail:
1003  (*env)->DeleteLocalRef(env, key);
1004  (*env)->DeleteLocalRef(env, result);
1005 
1006  return ret;
1007 }
1008 
1010 {
1011  JNIEnv *env = NULL;
1012  jstring key = NULL;
1014 
1015  av_assert0(format != NULL);
1016 
1018 
1020  if (!key) {
1021  goto fail;
1022  }
1023 
1024  (*env)->CallVoidMethod(env, format->object, format->jfields.set_integer_id, key, value);
1025  if (ff_jni_exception_check(env, 1, format) < 0) {
1026  goto fail;
1027  }
1028 
1029 fail:
1030  (*env)->DeleteLocalRef(env, key);
1031 }
1032 
1033 static void mediaformat_jni_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
1034 {
1035  JNIEnv *env = NULL;
1036  jstring key = NULL;
1038 
1039  av_assert0(format != NULL);
1040 
1042 
1044  if (!key) {
1045  goto fail;
1046  }
1047 
1048  (*env)->CallVoidMethod(env, format->object, format->jfields.set_long_id, key, value);
1049  if (ff_jni_exception_check(env, 1, format) < 0) {
1050  goto fail;
1051  }
1052 
1053 fail:
1054  (*env)->DeleteLocalRef(env, key);
1055 }
1056 
1057 static void mediaformat_jni_setFloat(FFAMediaFormat* ctx, const char* name, float value)
1058 {
1059  JNIEnv *env = NULL;
1060  jstring key = NULL;
1062 
1063  av_assert0(format != NULL);
1064 
1066 
1068  if (!key) {
1069  goto fail;
1070  }
1071 
1072  (*env)->CallVoidMethod(env, format->object, format->jfields.set_float_id, key, value);
1073  if (ff_jni_exception_check(env, 1, format) < 0) {
1074  goto fail;
1075  }
1076 
1077 fail:
1078  (*env)->DeleteLocalRef(env, key);
1079 }
1080 
1081 static void mediaformat_jni_setString(FFAMediaFormat* ctx, const char* name, const char* value)
1082 {
1083  JNIEnv *env = NULL;
1084  jstring key = NULL;
1085  jstring string = NULL;
1087 
1088  av_assert0(format != NULL);
1089 
1091 
1093  if (!key) {
1094  goto fail;
1095  }
1096 
1097  string = ff_jni_utf_chars_to_jstring(env, value, format);
1098  if (!string) {
1099  goto fail;
1100  }
1101 
1102  (*env)->CallVoidMethod(env, format->object, format->jfields.set_string_id, key, string);
1103  if (ff_jni_exception_check(env, 1, format) < 0) {
1104  goto fail;
1105  }
1106 
1107 fail:
1108  (*env)->DeleteLocalRef(env, key);
1109  (*env)->DeleteLocalRef(env, string);
1110 }
1111 
1112 static void mediaformat_jni_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
1113 {
1114  JNIEnv *env = NULL;
1115  jstring key = NULL;
1116  jobject buffer = NULL;
1117  void *buffer_data = NULL;
1119 
1120  av_assert0(format != NULL);
1121 
1123 
1125  if (!key) {
1126  goto fail;
1127  }
1128 
1129  if (!data || !size) {
1130  goto fail;
1131  }
1132 
1134  if (!buffer_data) {
1135  goto fail;
1136  }
1137 
1138  memcpy(buffer_data, data, size);
1139 
1140  buffer = (*env)->NewDirectByteBuffer(env, buffer_data, size);
1141  if (!buffer) {
1142  goto fail;
1143  }
1144 
1145  (*env)->CallVoidMethod(env, format->object, format->jfields.set_bytebuffer_id, key, buffer);
1146  if (ff_jni_exception_check(env, 1, format) < 0) {
1147  goto fail;
1148  }
1149 
1150 fail:
1151  (*env)->DeleteLocalRef(env, key);
1152  (*env)->DeleteLocalRef(env, buffer);
1153 }
1154 
1156 {
1157  int ret = 0;
1158  JNIEnv *env = NULL;
1159 
1161 
1162  codec->INFO_TRY_AGAIN_LATER = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_try_again_later_id);
1163  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1164  goto fail;
1165  }
1166 
1167  codec->BUFFER_FLAG_CODEC_CONFIG = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_codec_config_id);
1168  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1169  goto fail;
1170  }
1171 
1172  codec->BUFFER_FLAG_END_OF_STREAM = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_end_of_stream_id);
1173  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1174  goto fail;
1175  }
1176 
1177  if (codec->jfields.buffer_flag_key_frame_id) {
1178  codec->BUFFER_FLAG_KEY_FRAME = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.buffer_flag_key_frame_id);
1179  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1180  goto fail;
1181  }
1182  }
1183 
1184  codec->CONFIGURE_FLAG_ENCODE = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.configure_flag_encode_id);
1185  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1186  goto fail;
1187  }
1188 
1189  codec->INFO_TRY_AGAIN_LATER = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_try_again_later_id);
1190  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1191  goto fail;
1192  }
1193 
1194  codec->INFO_OUTPUT_BUFFERS_CHANGED = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_output_buffers_changed_id);
1195  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1196  goto fail;
1197  }
1198 
1199  codec->INFO_OUTPUT_FORMAT_CHANGED = (*env)->GetStaticIntField(env, codec->jfields.mediacodec_class, codec->jfields.info_output_format_changed_id);
1200  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1201  goto fail;
1202  }
1203 
1204 fail:
1205 
1206  return ret;
1207 }
1208 
1209 #define CREATE_CODEC_BY_NAME 0
1210 #define CREATE_DECODER_BY_TYPE 1
1211 #define CREATE_ENCODER_BY_TYPE 2
1212 
1213 static inline FFAMediaCodec *codec_create(int method, const char *arg)
1214 {
1215  int ret = -1;
1216  JNIEnv *env = NULL;
1217  FFAMediaCodecJni *codec = NULL;
1218  jstring jarg = NULL;
1219  jobject object = NULL;
1220  jobject buffer_info = NULL;
1221  jmethodID create_id = NULL;
1222 
1223  codec = av_mallocz(sizeof(*codec));
1224  if (!codec) {
1225  return NULL;
1226  }
1227  codec->api = media_codec_jni;
1228 
1229  env = ff_jni_get_env(codec);
1230  if (!env) {
1231  av_freep(&codec);
1232  return NULL;
1233  }
1234 
1235  if (ff_jni_init_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec) < 0) {
1236  goto fail;
1237  }
1238 
1239  jarg = ff_jni_utf_chars_to_jstring(env, arg, codec);
1240  if (!jarg) {
1241  goto fail;
1242  }
1243 
1244  switch (method) {
1245  case CREATE_CODEC_BY_NAME: create_id = codec->jfields.create_by_codec_name_id; break;
1246  case CREATE_DECODER_BY_TYPE: create_id = codec->jfields.create_decoder_by_type_id; break;
1247  case CREATE_ENCODER_BY_TYPE: create_id = codec->jfields.create_encoder_by_type_id; break;
1248  default:
1249  av_assert0(0);
1250  }
1251 
1252  object = (*env)->CallStaticObjectMethod(env,
1253  codec->jfields.mediacodec_class,
1254  create_id,
1255  jarg);
1256  if (ff_jni_exception_check(env, 1, codec) < 0) {
1257  goto fail;
1258  }
1259 
1260  codec->object = (*env)->NewGlobalRef(env, object);
1261  if (!codec->object) {
1262  goto fail;
1263  }
1264 
1265  if (codec_init_static_fields(codec) < 0) {
1266  goto fail;
1267  }
1268 
1270  codec->has_get_i_o_buffer = 1;
1271  }
1272 
1273  buffer_info = (*env)->NewObject(env, codec->jfields.mediainfo_class, codec->jfields.init_id);
1274  if (ff_jni_exception_check(env, 1, codec) < 0) {
1275  goto fail;
1276  }
1277 
1278  codec->buffer_info = (*env)->NewGlobalRef(env, buffer_info);
1279  if (!codec->buffer_info) {
1280  goto fail;
1281  }
1282 
1283  ret = 0;
1284 fail:
1285  (*env)->DeleteLocalRef(env, jarg);
1286  (*env)->DeleteLocalRef(env, object);
1287  (*env)->DeleteLocalRef(env, buffer_info);
1288 
1289  if (ret < 0) {
1290  (*env)->DeleteGlobalRef(env, codec->object);
1291  (*env)->DeleteGlobalRef(env, codec->buffer_info);
1292 
1293  ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec);
1294  av_freep(&codec);
1295  }
1296 
1297  return (FFAMediaCodec *)codec;
1298 }
1299 
1300 #define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method) \
1301 static FFAMediaCodec *mediacodec_jni_##name(const char *arg) \
1302 { \
1303  return codec_create(method, arg); \
1304 } \
1305 
1309 
1311 {
1312  int ret = 0;
1314  JNIEnv *env = NULL;
1315 
1316  if (!codec) {
1317  return 0;
1318  }
1319 
1321 
1322  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_id);
1323  if (ff_jni_exception_check(env, 1, codec) < 0) {
1325  }
1326 
1327  (*env)->DeleteGlobalRef(env, codec->input_buffers);
1328  codec->input_buffers = NULL;
1329 
1330  (*env)->DeleteGlobalRef(env, codec->output_buffers);
1331  codec->output_buffers = NULL;
1332 
1333  (*env)->DeleteGlobalRef(env, codec->object);
1334  codec->object = NULL;
1335 
1336  (*env)->DeleteGlobalRef(env, codec->buffer_info);
1337  codec->buffer_info = NULL;
1338 
1339  ff_jni_reset_jfields(env, &codec->jfields, jni_amediacodec_mapping, 1, codec);
1340 
1341  av_freep(&codec);
1342 
1343  return ret;
1344 }
1345 
1347 {
1348  char *ret = NULL;
1349  JNIEnv *env = NULL;
1350  jobject *name = NULL;
1352 
1353  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1354 
1355  name = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_name_id);
1356  if (ff_jni_exception_check(env, 1, codec) < 0) {
1357  goto fail;
1358  }
1359 
1360  ret = ff_jni_jstring_to_utf_chars(env, name, codec);
1361 
1362 fail:
1363  if (name) {
1364  (*env)->DeleteLocalRef(env, name);
1365  }
1366 
1367  return ret;
1368 }
1369 
1371  const FFAMediaFormat* format_ctx,
1373  void *crypto,
1374  uint32_t flags)
1375 {
1376  int ret = 0;
1377  JNIEnv *env = NULL;
1379  const FFAMediaFormatJni *format = (FFAMediaFormatJni *)format_ctx;
1380  jobject *surface = window ? window->surface : NULL;
1381 
1383 
1384  if (flags & codec->CONFIGURE_FLAG_ENCODE) {
1385  if (surface && !codec->jfields.set_input_surface_id) {
1386  av_log(ctx, AV_LOG_ERROR, "System doesn't support setInputSurface\n");
1387  return AVERROR_EXTERNAL;
1388  }
1389 
1390  (*env)->CallVoidMethod(env, codec->object, codec->jfields.configure_id, format->object, NULL, NULL, flags);
1391  if (ff_jni_exception_check(env, 1, codec) < 0)
1392  return AVERROR_EXTERNAL;
1393 
1394  if (!surface)
1395  return 0;
1396 
1397  (*env)->CallVoidMethod(env, codec->object, codec->jfields.set_input_surface_id, surface);
1398  if (ff_jni_exception_check(env, 1, codec) < 0)
1399  return AVERROR_EXTERNAL;
1400  return 0;
1401  } else {
1402  (*env)->CallVoidMethod(env, codec->object, codec->jfields.configure_id, format->object, surface, NULL, flags);
1403  }
1404  if (ff_jni_exception_check(env, 1, codec) < 0) {
1406  goto fail;
1407  }
1408 
1409 fail:
1410  return ret;
1411 }
1412 
1414 {
1415  int ret = 0;
1416  JNIEnv *env = NULL;
1418 
1420 
1421  (*env)->CallVoidMethod(env, codec->object, codec->jfields.start_id);
1422  if (ff_jni_exception_check(env, 1, codec) < 0) {
1424  goto fail;
1425  }
1426 
1427 fail:
1428  return ret;
1429 }
1430 
1432 {
1433  int ret = 0;
1434  JNIEnv *env = NULL;
1436 
1438 
1439  (*env)->CallVoidMethod(env, codec->object, codec->jfields.stop_id);
1440  if (ff_jni_exception_check(env, 1, codec) < 0) {
1442  goto fail;
1443  }
1444 
1445 fail:
1446  return ret;
1447 }
1448 
1450 {
1451  int ret = 0;
1452  JNIEnv *env = NULL;
1454 
1456 
1457  (*env)->CallVoidMethod(env, codec->object, codec->jfields.flush_id);
1458  if (ff_jni_exception_check(env, 1, codec) < 0) {
1460  goto fail;
1461  }
1462 
1463 fail:
1464  return ret;
1465 }
1466 
1467 static int mediacodec_jni_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, int render)
1468 {
1469  int ret = 0;
1470  JNIEnv *env = NULL;
1472 
1474 
1475  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_output_buffer_id, (jint)idx, (jboolean)render);
1476  if (ff_jni_exception_check(env, 1, codec) < 0) {
1478  goto fail;
1479  }
1480 
1481 fail:
1482  return ret;
1483 }
1484 
1485 static int mediacodec_jni_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
1486 {
1487  int ret = 0;
1488  JNIEnv *env = NULL;
1490 
1492 
1493  (*env)->CallVoidMethod(env, codec->object, codec->jfields.release_output_buffer_at_time_id, (jint)idx, (jlong)timestampNs);
1494  if (ff_jni_exception_check(env, 1, codec) < 0) {
1496  goto fail;
1497  }
1498 
1499 fail:
1500  return ret;
1501 }
1502 
1503 static ssize_t mediacodec_jni_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
1504 {
1505  int ret = 0;
1506  JNIEnv *env = NULL;
1508 
1510 
1511  ret = (*env)->CallIntMethod(env, codec->object, codec->jfields.dequeue_input_buffer_id, timeoutUs);
1512  if (ff_jni_exception_check(env, 1, codec) < 0) {
1514  goto fail;
1515  }
1516 
1517 fail:
1518  return ret;
1519 }
1520 
1521 static int mediacodec_jni_queueInputBuffer(FFAMediaCodec* ctx, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
1522 {
1523  int ret = 0;
1524  JNIEnv *env = NULL;
1526 
1528 
1529  (*env)->CallVoidMethod(env, codec->object, codec->jfields.queue_input_buffer_id, (jint)idx, (jint)offset, (jint)size, time, flags);
1530  if ((ret = ff_jni_exception_check(env, 1, codec)) < 0) {
1532  goto fail;
1533  }
1534 
1535 fail:
1536  return ret;
1537 }
1538 
1540 {
1541  int ret = 0;
1542  JNIEnv *env = NULL;
1544 
1546 
1547  ret = (*env)->CallIntMethod(env, codec->object, codec->jfields.dequeue_output_buffer_id, codec->buffer_info, timeoutUs);
1548  if (ff_jni_exception_check(env, 1, codec) < 0) {
1549  return AVERROR_EXTERNAL;
1550  }
1551 
1552  info->flags = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.flags_id);
1553  if (ff_jni_exception_check(env, 1, codec) < 0) {
1554  return AVERROR_EXTERNAL;
1555  }
1556 
1557  info->offset = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.offset_id);
1558  if (ff_jni_exception_check(env, 1, codec) < 0) {
1559  return AVERROR_EXTERNAL;
1560  }
1561 
1562  info->presentationTimeUs = (*env)->GetLongField(env, codec->buffer_info, codec->jfields.presentation_time_us_id);
1563  if (ff_jni_exception_check(env, 1, codec) < 0) {
1564  return AVERROR_EXTERNAL;
1565  }
1566 
1567  info->size = (*env)->GetIntField(env, codec->buffer_info, codec->jfields.size_id);
1568  if (ff_jni_exception_check(env, 1, codec) < 0) {
1569  return AVERROR_EXTERNAL;
1570  }
1571 
1572  return ret;
1573 }
1574 
1575 static uint8_t* mediacodec_jni_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
1576 {
1577  uint8_t *ret = NULL;
1578  JNIEnv *env = NULL;
1580  jobject buffer = NULL;
1581  jobject input_buffers = NULL;
1582 
1583  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1584 
1585  if (codec->has_get_i_o_buffer) {
1586  buffer = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffer_id, (jint)idx);
1587  if (ff_jni_exception_check(env, 1, codec) < 0) {
1588  goto fail;
1589  }
1590  } else {
1591  if (!codec->input_buffers) {
1592  input_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffers_id);
1593  if (ff_jni_exception_check(env, 1, codec) < 0) {
1594  goto fail;
1595  }
1596 
1597  codec->input_buffers = (*env)->NewGlobalRef(env, input_buffers);
1598  if (ff_jni_exception_check(env, 1, codec) < 0) {
1599  goto fail;
1600  }
1601  }
1602 
1603  buffer = (*env)->GetObjectArrayElement(env, codec->input_buffers, idx);
1604  if (ff_jni_exception_check(env, 1, codec) < 0) {
1605  goto fail;
1606  }
1607  }
1608 
1609  ret = (*env)->GetDirectBufferAddress(env, buffer);
1610  *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
1611 fail:
1612  (*env)->DeleteLocalRef(env, buffer);
1613  (*env)->DeleteLocalRef(env, input_buffers);
1614 
1615  return ret;
1616 }
1617 
1618 static uint8_t* mediacodec_jni_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
1619 {
1620  uint8_t *ret = NULL;
1621  JNIEnv *env = NULL;
1623  jobject buffer = NULL;
1624  jobject output_buffers = NULL;
1625 
1626  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1627 
1628  if (codec->has_get_i_o_buffer) {
1629  buffer = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffer_id, (jint)idx);
1630  if (ff_jni_exception_check(env, 1, codec) < 0) {
1631  goto fail;
1632  }
1633  } else {
1634  if (!codec->output_buffers) {
1635  output_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffers_id);
1636  if (ff_jni_exception_check(env, 1, codec) < 0) {
1637  goto fail;
1638  }
1639 
1640  codec->output_buffers = (*env)->NewGlobalRef(env, output_buffers);
1641  if (ff_jni_exception_check(env, 1, codec) < 0) {
1642  goto fail;
1643  }
1644  }
1645 
1646  buffer = (*env)->GetObjectArrayElement(env, codec->output_buffers, idx);
1647  if (ff_jni_exception_check(env, 1, codec) < 0) {
1648  goto fail;
1649  }
1650  }
1651 
1652  ret = (*env)->GetDirectBufferAddress(env, buffer);
1653  *out_size = (*env)->GetDirectBufferCapacity(env, buffer);
1654 fail:
1655  (*env)->DeleteLocalRef(env, buffer);
1656  (*env)->DeleteLocalRef(env, output_buffers);
1657 
1658  return ret;
1659 }
1660 
1662 {
1663  FFAMediaFormat *ret = NULL;
1664  JNIEnv *env = NULL;
1666 
1667  jobject mediaformat = NULL;
1668 
1669  JNI_GET_ENV_OR_RETURN(env, codec, NULL);
1670 
1671  mediaformat = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_format_id);
1672  if (ff_jni_exception_check(env, 1, codec) < 0) {
1673  goto fail;
1674  }
1675 
1676  ret = mediaformat_jni_newFromObject(mediaformat);
1677 fail:
1678  (*env)->DeleteLocalRef(env, mediaformat);
1679 
1680  return ret;
1681 }
1682 
1684 {
1686  return idx == codec->INFO_TRY_AGAIN_LATER;
1687 }
1688 
1690 {
1692  return idx == codec->INFO_OUTPUT_BUFFERS_CHANGED;
1693 }
1694 
1696 {
1698  return idx == codec->INFO_OUTPUT_FORMAT_CHANGED;
1699 }
1700 
1702 {
1704  return codec->BUFFER_FLAG_CODEC_CONFIG;
1705 }
1706 
1708 {
1710  return codec->BUFFER_FLAG_END_OF_STREAM;
1711 }
1712 
1714 {
1716  return codec->BUFFER_FLAG_KEY_FRAME;
1717 }
1718 
1720 {
1722  return codec->CONFIGURE_FLAG_ENCODE;
1723 }
1724 
1726 {
1727  int ret = 0;
1729 
1730  if (!codec->has_get_i_o_buffer) {
1731  if (codec->output_buffers) {
1732  JNIEnv *env = NULL;
1733 
1734  env = ff_jni_get_env(codec);
1735  if (!env) {
1737  goto fail;
1738  }
1739 
1740  (*env)->DeleteGlobalRef(env, codec->output_buffers);
1741  codec->output_buffers = NULL;
1742  }
1743  }
1744 
1745 fail:
1746  return ret;
1747 }
1748 
1750 {
1751  JNIEnv *env = NULL;
1753 
1755 
1756  (*env)->CallVoidMethod(env, codec->object, codec->jfields.signal_end_of_input_stream_id);
1757  if (ff_jni_exception_check(env, 1, codec) < 0) {
1758  return AVERROR_EXTERNAL;
1759  }
1760 
1761  return 0;
1762 }
1763 
1764 static const FFAMediaFormat media_format_jni = {
1766 
1767  .create = mediaformat_jni_new,
1769 
1770  .toString = mediaformat_jni_toString,
1771 
1772  .getInt32 = mediaformat_jni_getInt32,
1773  .getInt64 = mediaformat_jni_getInt64,
1774  .getFloat = mediaformat_jni_getFloat,
1775  .getBuffer = mediaformat_jni_getBuffer,
1776  .getString = mediaformat_jni_getString,
1777 
1778  .setInt32 = mediaformat_jni_setInt32,
1779  .setInt64 = mediaformat_jni_setInt64,
1780  .setFloat = mediaformat_jni_setFloat,
1781  .setString = mediaformat_jni_setString,
1782  .setBuffer = mediaformat_jni_setBuffer,
1783 };
1784 
1785 static const FFAMediaCodec media_codec_jni = {
1787 
1788  .getName = mediacodec_jni_getName,
1789 
1790  .createCodecByName = mediacodec_jni_createCodecByName,
1791  .createDecoderByType = mediacodec_jni_createDecoderByType,
1792  .createEncoderByType = mediacodec_jni_createEncoderByType,
1793  .delete = mediacodec_jni_delete,
1794 
1795  .configure = mediacodec_jni_configure,
1796  .start = mediacodec_jni_start,
1797  .stop = mediacodec_jni_stop,
1798  .flush = mediacodec_jni_flush,
1799 
1800  .getInputBuffer = mediacodec_jni_getInputBuffer,
1801  .getOutputBuffer = mediacodec_jni_getOutputBuffer,
1802 
1803  .dequeueInputBuffer = mediacodec_jni_dequeueInputBuffer,
1804  .queueInputBuffer = mediacodec_jni_queueInputBuffer,
1805 
1806  .dequeueOutputBuffer = mediacodec_jni_dequeueOutputBuffer,
1807  .getOutputFormat = mediacodec_jni_getOutputFormat,
1808 
1809  .releaseOutputBuffer = mediacodec_jni_releaseOutputBuffer,
1810  .releaseOutputBufferAtTime = mediacodec_jni_releaseOutputBufferAtTime,
1811 
1812  .infoTryAgainLater = mediacodec_jni_infoTryAgainLater,
1813  .infoOutputBuffersChanged = mediacodec_jni_infoOutputBuffersChanged,
1814  .infoOutputFormatChanged = mediacodec_jni_infoOutputFormatChanged,
1815 
1816  .getBufferFlagCodecConfig = mediacodec_jni_getBufferFlagCodecConfig,
1817  .getBufferFlagEndOfStream = mediacodec_jni_getBufferFlagEndOfStream,
1818  .getBufferFlagKeyFrame = mediacodec_jni_getBufferFlagKeyFrame,
1819 
1820  .getConfigureFlagEncode = mediacodec_jni_getConfigureFlagEncode,
1821  .cleanOutputBuffers = mediacodec_jni_cleanOutputBuffers,
1822  .signalEndOfInputStream = mediacodec_jni_signalEndOfInputStream,
1823 };
1824 
1825 typedef struct FFAMediaFormatNdk {
1827 
1828  void *libmedia;
1829  AMediaFormat *impl;
1830 
1831  AMediaFormat *(*new)(void);
1832  media_status_t (*delete)(AMediaFormat*);
1833 
1834  const char* (*toString)(AMediaFormat*);
1835 
1836  bool (*getInt32)(AMediaFormat*, const char *name, int32_t *out);
1837  bool (*getInt64)(AMediaFormat*, const char *name, int64_t *out);
1838  bool (*getFloat)(AMediaFormat*, const char *name, float *out);
1839  bool (*getSize)(AMediaFormat*, const char *name, size_t *out);
1840  bool (*getBuffer)(AMediaFormat*, const char *name, void** data, size_t *size);
1841  bool (*getString)(AMediaFormat*, const char *name, const char **out);
1842  bool (*getRect)(AMediaFormat *, const char *name,
1843  int32_t *left, int32_t *top, int32_t *right, int32_t *bottom);
1844 
1845  void (*setInt32)(AMediaFormat*, const char* name, int32_t value);
1846  void (*setInt64)(AMediaFormat*, const char* name, int64_t value);
1847  void (*setFloat)(AMediaFormat*, const char* name, float value);
1848  void (*setString)(AMediaFormat*, const char* name, const char* value);
1849  void (*setBuffer)(AMediaFormat*, const char* name, const void* data, size_t size);
1850  void (*setRect)(AMediaFormat *, const char *name,
1851  int32_t left, int32_t top, int32_t right, int32_t bottom);
1853 
1854 typedef struct FFAMediaCodecNdk {
1856 
1857  void *libmedia;
1858  AMediaCodec *impl;
1859  ANativeWindow *window;
1860 
1861  AMediaCodec* (*createCodecByName)(const char *name);
1862  AMediaCodec* (*createDecoderByType)(const char *mime_type);
1863  AMediaCodec* (*createEncoderByType)(const char *mime_type);
1864  media_status_t (*delete)(AMediaCodec*);
1865 
1866  media_status_t (*configure)(AMediaCodec *,
1867  const AMediaFormat *format,
1868  ANativeWindow *surface,
1869  AMediaCrypto *crypto,
1870  uint32_t flags);
1871  media_status_t (*start)(AMediaCodec*);
1872  media_status_t (*stop)(AMediaCodec*);
1873  media_status_t (*flush)(AMediaCodec*);
1874 
1875  uint8_t* (*getInputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
1876  uint8_t* (*getOutputBuffer)(AMediaCodec*, size_t idx, size_t *out_size);
1877 
1878  ssize_t (*dequeueInputBuffer)(AMediaCodec*, int64_t timeoutUs);
1879  media_status_t (*queueInputBuffer)(AMediaCodec*, size_t idx,
1880  long offset, size_t size,
1881  uint64_t time, uint32_t flags);
1882 
1883  ssize_t (*dequeueOutputBuffer)(AMediaCodec*, AMediaCodecBufferInfo *info, int64_t timeoutUs);
1884  AMediaFormat* (*getOutputFormat)(AMediaCodec*);
1885 
1886  media_status_t (*releaseOutputBuffer)(AMediaCodec*, size_t idx, bool render);
1887  media_status_t (*releaseOutputBufferAtTime)(AMediaCodec *mData, size_t idx, int64_t timestampNs);
1888 
1889  // Available since API level 28.
1890  media_status_t (*getName)(AMediaCodec*, char** out_name);
1891  void (*releaseName)(AMediaCodec*, char* name);
1892 
1893  // Available since API level 26.
1894  media_status_t (*setInputSurface)(AMediaCodec*, ANativeWindow *);
1895  media_status_t (*signalEndOfInputStream)(AMediaCodec *);
1897 
1900 
1902  .class_name = "amediaformat_ndk",
1903  .item_name = av_default_item_name,
1904  .version = LIBAVUTIL_VERSION_INT,
1905 };
1906 
1908  .class_name = "amediacodec_ndk",
1909  .item_name = av_default_item_name,
1910  .version = LIBAVUTIL_VERSION_INT,
1911 };
1912 
1913 static FFAMediaFormat *mediaformat_ndk_create(AMediaFormat *impl)
1914 {
1916  if (!format)
1917  return NULL;
1918 
1919  format->api = media_format_ndk;
1920 
1921  format->libmedia = dlopen("libmediandk.so", RTLD_NOW);
1922  if (!format->libmedia)
1923  goto error;
1924 
1925 #define GET_OPTIONAL_SYMBOL(sym) \
1926  format->sym = dlsym(format->libmedia, "AMediaFormat_" #sym);
1927 
1928 #define GET_SYMBOL(sym) \
1929  GET_OPTIONAL_SYMBOL(sym) \
1930  if (!format->sym) \
1931  goto error;
1932 
1933  GET_SYMBOL(new)
1934  GET_SYMBOL(delete)
1935 
1936  GET_SYMBOL(toString)
1937 
1938  GET_SYMBOL(getInt32)
1939  GET_SYMBOL(getInt64)
1940  GET_SYMBOL(getFloat)
1941  GET_SYMBOL(getSize)
1942  GET_SYMBOL(getBuffer)
1943  GET_SYMBOL(getString)
1944  GET_OPTIONAL_SYMBOL(getRect)
1945 
1946  GET_SYMBOL(setInt32)
1947  GET_SYMBOL(setInt64)
1948  GET_SYMBOL(setFloat)
1949  GET_SYMBOL(setString)
1950  GET_SYMBOL(setBuffer)
1951  GET_OPTIONAL_SYMBOL(setRect)
1952 
1953 #undef GET_SYMBOL
1954 #undef GET_OPTIONAL_SYMBOL
1955 
1956  if (impl) {
1957  format->impl = impl;
1958  } else {
1959  format->impl = format->new();
1960  if (!format->impl)
1961  goto error;
1962  }
1963 
1964  return (FFAMediaFormat *)format;
1965 
1966 error:
1967  if (format->libmedia)
1968  dlclose(format->libmedia);
1969  av_freep(&format);
1970  return NULL;
1971 }
1972 
1974 {
1975  return mediaformat_ndk_create(NULL);
1976 }
1977 
1979 {
1981  int ret = 0;
1982  if (!format)
1983  return 0;
1984 
1985  av_assert0(format->api.class == &amediaformat_ndk_class);
1986 
1987  if (format->impl && (format->delete(format->impl) != AMEDIA_OK))
1989  if (format->libmedia)
1990  dlclose(format->libmedia);
1991  av_free(format);
1992 
1993  return ret;
1994 }
1995 
1997 {
1999  const char *str = format->toString(format->impl);
2000  return av_strdup(str);
2001 }
2002 
2004 {
2006  return format->getInt32(format->impl, name, out);
2007 }
2008 
2009 static int mediaformat_ndk_getInt64(FFAMediaFormat* ctx, const char *name, int64_t *out)
2010 {
2012  return format->getInt64(format->impl, name, out);
2013 }
2014 
2015 static int mediaformat_ndk_getFloat(FFAMediaFormat* ctx, const char *name, float *out)
2016 {
2018  return format->getFloat(format->impl, name, out);
2019 }
2020 
2021 static int mediaformat_ndk_getBuffer(FFAMediaFormat* ctx, const char *name, void** data, size_t *size)
2022 {
2024  return format->getBuffer(format->impl, name, data, size);
2025 }
2026 
2027 static int mediaformat_ndk_getString(FFAMediaFormat* ctx, const char *name, const char **out)
2028 {
2030  const char *tmp = NULL;
2031  int ret = format->getString(format->impl, name, &tmp);
2032 
2033  if (tmp)
2034  *out = av_strdup(tmp);
2035  return ret;
2036 }
2037 
2039  int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
2040 {
2042  if (!format->getRect)
2043  return AVERROR_EXTERNAL;
2044  return format->getRect(format->impl, name, left, top, right, bottom);
2045 }
2046 
2048 {
2050  format->setInt32(format->impl, name, value);
2051 }
2052 
2053 static void mediaformat_ndk_setInt64(FFAMediaFormat* ctx, const char* name, int64_t value)
2054 {
2056  format->setInt64(format->impl, name, value);
2057 }
2058 
2059 static void mediaformat_ndk_setFloat(FFAMediaFormat* ctx, const char* name, float value)
2060 {
2062  format->setFloat(format->impl, name, value);
2063 }
2064 
2065 static void mediaformat_ndk_setString(FFAMediaFormat* ctx, const char* name, const char* value)
2066 {
2068  format->setString(format->impl, name, value);
2069 }
2070 
2071 static void mediaformat_ndk_setBuffer(FFAMediaFormat* ctx, const char* name, void* data, size_t size)
2072 {
2074  format->setBuffer(format->impl, name, data, size);
2075 }
2076 
2078  int32_t left, int32_t top, int32_t right, int32_t bottom)
2079 {
2081  if (!format->setRect) {
2082  av_log(ctx, AV_LOG_WARNING, "Doesn't support setRect\n");
2083  return;
2084  }
2085  format->setRect(format->impl, name, left, top, right, bottom);
2086 }
2087 
2089 {
2091  char *ret = NULL;
2092  char *name = NULL;
2093 
2094  if (!codec->getName || !codec->releaseName) {
2095  av_log(ctx, AV_LOG_DEBUG, "getName() unavailable\n");
2096  return ret;
2097  }
2098 
2099  codec->getName(codec->impl, &name);
2100  if (name) {
2101  ret = av_strdup(name);
2102  codec->releaseName(codec->impl, name);
2103  }
2104 
2105  return ret;
2106 }
2107 
2108 static inline FFAMediaCodec *ndk_codec_create(int method, const char *arg) {
2109  FFAMediaCodecNdk *codec = av_mallocz(sizeof(*codec));
2110  const char *lib_name = "libmediandk.so";
2111 
2112  if (!codec)
2113  return NULL;
2114 
2115  codec->api = media_codec_ndk;
2116  codec->libmedia = dlopen(lib_name, RTLD_NOW);
2117  if (!codec->libmedia)
2118  goto error;
2119 
2120 #define GET_SYMBOL(sym, required) \
2121  codec->sym = dlsym(codec->libmedia, "AMediaCodec_" #sym); \
2122  if (!codec->sym) { \
2123  av_log(codec, required ? AV_LOG_ERROR : AV_LOG_INFO, \
2124  #sym "() unavailable from %s\n", lib_name); \
2125  if (required) \
2126  goto error; \
2127  }
2128 
2129  GET_SYMBOL(createCodecByName, 1)
2130  GET_SYMBOL(createDecoderByType, 1)
2131  GET_SYMBOL(createEncoderByType, 1)
2132  GET_SYMBOL(delete, 1)
2133 
2134  GET_SYMBOL(configure, 1)
2135  GET_SYMBOL(start, 1)
2136  GET_SYMBOL(stop, 1)
2137  GET_SYMBOL(flush, 1)
2138 
2139  GET_SYMBOL(getInputBuffer, 1)
2140  GET_SYMBOL(getOutputBuffer, 1)
2141 
2142  GET_SYMBOL(dequeueInputBuffer, 1)
2143  GET_SYMBOL(queueInputBuffer, 1)
2144 
2145  GET_SYMBOL(dequeueOutputBuffer, 1)
2146  GET_SYMBOL(getOutputFormat, 1)
2147 
2148  GET_SYMBOL(releaseOutputBuffer, 1)
2149  GET_SYMBOL(releaseOutputBufferAtTime, 1)
2150 
2151  GET_SYMBOL(getName, 0)
2152  GET_SYMBOL(releaseName, 0)
2153 
2154  GET_SYMBOL(setInputSurface, 0)
2155  GET_SYMBOL(signalEndOfInputStream, 0)
2156 
2157 #undef GET_SYMBOL
2158 
2159  switch (method) {
2160  case CREATE_CODEC_BY_NAME:
2161  codec->impl = codec->createCodecByName(arg);
2162  break;
2164  codec->impl = codec->createDecoderByType(arg);
2165  break;
2167  codec->impl = codec->createEncoderByType(arg);
2168  break;
2169  default:
2170  av_assert0(0);
2171  }
2172  if (!codec->impl)
2173  goto error;
2174 
2175  return (FFAMediaCodec *)codec;
2176 
2177 error:
2178  if (codec->libmedia)
2179  dlclose(codec->libmedia);
2180  av_freep(&codec);
2181  return NULL;
2182 }
2183 
2184 #define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC(name, method) \
2185 static FFAMediaCodec *mediacodec_ndk_##name(const char *arg) \
2186 { \
2187  return ndk_codec_create(method, arg); \
2188 } \
2189 
2193 
2195 {
2197  int ret = 0;
2198 
2199  if (!codec)
2200  return 0;
2201 
2203 
2204  if (codec->impl && (codec->delete(codec->impl) != AMEDIA_OK))
2206  if (codec->window)
2207  ANativeWindow_release(codec->window);
2208  if (codec->libmedia)
2209  dlclose(codec->libmedia);
2210  av_free(codec);
2211 
2212  return ret;
2213 }
2214 
2216  const FFAMediaFormat* format_ctx,
2218  void *crypto,
2219  uint32_t flags)
2220 {
2222  FFAMediaFormatNdk *format = (FFAMediaFormatNdk *)format_ctx;
2223  media_status_t status;
2224  ANativeWindow *native_window = NULL;
2225 
2226  if (window) {
2227  if (window->surface) {
2228  JNIEnv *env = NULL;
2229  JNI_GET_ENV_OR_RETURN(env, ctx, -1);
2230  native_window = ANativeWindow_fromSurface(env, window->surface);
2231  // Save for release
2232  codec->window = native_window;
2233  } else if (window->native_window) {
2234  native_window = window->native_window;
2235  }
2236  }
2237 
2238  if (format_ctx->class != &amediaformat_ndk_class) {
2239  av_log(ctx, AV_LOG_ERROR, "invalid media format\n");
2240  return AVERROR(EINVAL);
2241  }
2242 
2243  if (flags & AMEDIACODEC_CONFIGURE_FLAG_ENCODE) {
2244  if (native_window && !codec->setInputSurface) {
2245  av_log(ctx, AV_LOG_ERROR, "System doesn't support setInputSurface\n");
2246  return AVERROR_EXTERNAL;
2247  }
2248 
2249  status = codec->configure(codec->impl, format->impl, NULL, NULL, flags);
2250  if (status != AMEDIA_OK) {
2251  av_log(codec, AV_LOG_ERROR, "Encoder configure failed, %d\n", status);
2252  return AVERROR_EXTERNAL;
2253  }
2254 
2255  if (!native_window)
2256  return 0;
2257 
2258  status = codec->setInputSurface(codec->impl, native_window);
2259  if (status != AMEDIA_OK) {
2260  av_log(codec, AV_LOG_ERROR, "Encoder set input surface failed, %d\n", status);
2261  return AVERROR_EXTERNAL;
2262  }
2263  } else {
2264  status = codec->configure(codec->impl, format->impl, native_window, NULL, flags);
2265  if (status != AMEDIA_OK) {
2266  av_log(codec, AV_LOG_ERROR, "Decoder configure failed, %d\n", status);
2267  return AVERROR_EXTERNAL;
2268  }
2269  }
2270 
2271  return 0;
2272 }
2273 
2274 #define MEDIACODEC_NDK_WRAPPER(method) \
2275 static int mediacodec_ndk_ ## method(FFAMediaCodec* ctx) \
2276 { \
2277  FFAMediaCodecNdk *codec = (FFAMediaCodecNdk *)ctx; \
2278  media_status_t status = codec->method(codec->impl); \
2279  \
2280  if (status != AMEDIA_OK) { \
2281  av_log(codec, AV_LOG_ERROR, #method " failed, %d\n", status); \
2282  return AVERROR_EXTERNAL; \
2283  } \
2284  \
2285  return 0; \
2286 } \
2287 
2291 
2292 static uint8_t* mediacodec_ndk_getInputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
2293 {
2295  return codec->getInputBuffer(codec->impl, idx, out_size);
2296 }
2297 
2298 static uint8_t* mediacodec_ndk_getOutputBuffer(FFAMediaCodec* ctx, size_t idx, size_t *out_size)
2299 {
2301  return codec->getOutputBuffer(codec->impl, idx, out_size);
2302 }
2303 
2304 static ssize_t mediacodec_ndk_dequeueInputBuffer(FFAMediaCodec* ctx, int64_t timeoutUs)
2305 {
2307  return codec->dequeueInputBuffer(codec->impl, timeoutUs);
2308 }
2309 
2311  off_t offset, size_t size,
2312  uint64_t time, uint32_t flags)
2313 {
2315  return codec->queueInputBuffer(codec->impl, idx, offset, size, time, flags);
2316 }
2317 
2319 {
2321  AMediaCodecBufferInfo buf_info = {0};
2322  ssize_t ret;
2323 
2324  ret = codec->dequeueOutputBuffer(codec->impl, &buf_info, timeoutUs);
2325  info->offset = buf_info.offset;
2326  info->size = buf_info.size;
2327  info->presentationTimeUs = buf_info.presentationTimeUs;
2328  info->flags = buf_info.flags;
2329 
2330  return ret;
2331 }
2332 
2334 {
2336  AMediaFormat *format = codec->getOutputFormat(codec->impl);
2337 
2338  if (!format)
2339  return NULL;
2341 }
2342 
2343 static int mediacodec_ndk_releaseOutputBuffer(FFAMediaCodec* ctx, size_t idx, int render)
2344 {
2346  media_status_t status;
2347 
2348  status = codec->releaseOutputBuffer(codec->impl, idx, render);
2349  if (status != AMEDIA_OK) {
2350  av_log(codec, AV_LOG_ERROR, "release output buffer failed, %d\n", status);
2351  return AVERROR_EXTERNAL;
2352  }
2353 
2354  return 0;
2355 }
2356 
2357 static int mediacodec_ndk_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
2358 {
2360  media_status_t status;
2361 
2362  status = codec->releaseOutputBufferAtTime(codec->impl, idx, timestampNs);
2363  if (status != AMEDIA_OK) {
2364  av_log(codec, AV_LOG_ERROR, "releaseOutputBufferAtTime failed, %d\n", status);
2365  return AVERROR_EXTERNAL;
2366  }
2367 
2368  return 0;
2369 }
2370 
2372 {
2373  return idx == AMEDIACODEC_INFO_TRY_AGAIN_LATER;
2374 }
2375 
2377 {
2378  return idx == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED;
2379 }
2380 
2382 {
2383  return idx == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED;
2384 }
2385 
2387 {
2388  return AMEDIACODEC_BUFFER_FLAG_CODEC_CONFIG;
2389 }
2390 
2392 {
2393  return AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM;
2394 }
2395 
2397 {
2398  return 1;
2399 }
2400 
2402 {
2403  return AMEDIACODEC_CONFIGURE_FLAG_ENCODE;
2404 }
2405 
2407 {
2408  return 0;
2409 }
2410 
2412 {
2414  media_status_t status;
2415 
2416  if (!codec->signalEndOfInputStream) {
2417  av_log(codec, AV_LOG_ERROR, "signalEndOfInputStream unavailable\n");
2418  return AVERROR_EXTERNAL;
2419  }
2420 
2421  status = codec->signalEndOfInputStream(codec->impl);
2422  if (status != AMEDIA_OK) {
2423  av_log(codec, AV_LOG_ERROR, "signalEndOfInputStream failed, %d\n", status);
2424  return AVERROR_EXTERNAL;
2425  }
2426  av_log(codec, AV_LOG_DEBUG, "signalEndOfInputStream success\n");
2427 
2428  return 0;
2429 }
2430 
2431 static const FFAMediaFormat media_format_ndk = {
2433 
2434  .create = mediaformat_ndk_new,
2436 
2437  .toString = mediaformat_ndk_toString,
2438 
2439  .getInt32 = mediaformat_ndk_getInt32,
2440  .getInt64 = mediaformat_ndk_getInt64,
2441  .getFloat = mediaformat_ndk_getFloat,
2442  .getBuffer = mediaformat_ndk_getBuffer,
2443  .getString = mediaformat_ndk_getString,
2444  .getRect = mediaformat_ndk_getRect,
2445 
2446  .setInt32 = mediaformat_ndk_setInt32,
2447  .setInt64 = mediaformat_ndk_setInt64,
2448  .setFloat = mediaformat_ndk_setFloat,
2449  .setString = mediaformat_ndk_setString,
2450  .setBuffer = mediaformat_ndk_setBuffer,
2451  .setRect = mediaformat_ndk_setRect,
2452 };
2453 
2454 static const FFAMediaCodec media_codec_ndk = {
2456 
2457  .getName = mediacodec_ndk_getName,
2458 
2459  .createCodecByName = mediacodec_ndk_createCodecByName,
2460  .createDecoderByType = mediacodec_ndk_createDecoderByType,
2461  .createEncoderByType = mediacodec_ndk_createEncoderByType,
2462  .delete = mediacodec_ndk_delete,
2463 
2464  .configure = mediacodec_ndk_configure,
2465  .start = mediacodec_ndk_start,
2466  .stop = mediacodec_ndk_stop,
2467  .flush = mediacodec_ndk_flush,
2468 
2469  .getInputBuffer = mediacodec_ndk_getInputBuffer,
2470  .getOutputBuffer = mediacodec_ndk_getOutputBuffer,
2471 
2472  .dequeueInputBuffer = mediacodec_ndk_dequeueInputBuffer,
2473  .queueInputBuffer = mediacodec_ndk_queueInputBuffer,
2474 
2475  .dequeueOutputBuffer = mediacodec_ndk_dequeueOutputBuffer,
2476  .getOutputFormat = mediacodec_ndk_getOutputFormat,
2477 
2478  .releaseOutputBuffer = mediacodec_ndk_releaseOutputBuffer,
2479  .releaseOutputBufferAtTime = mediacodec_ndk_releaseOutputBufferAtTime,
2480 
2481  .infoTryAgainLater = mediacodec_ndk_infoTryAgainLater,
2482  .infoOutputBuffersChanged = mediacodec_ndk_infoOutputBuffersChanged,
2483  .infoOutputFormatChanged = mediacodec_ndk_infoOutputFormatChanged,
2484 
2485  .getBufferFlagCodecConfig = mediacodec_ndk_getBufferFlagCodecConfig,
2486  .getBufferFlagEndOfStream = mediacodec_ndk_getBufferFlagEndOfStream,
2487  .getBufferFlagKeyFrame = mediacodec_ndk_getBufferFlagKeyFrame,
2488 
2489  .getConfigureFlagEncode = mediacodec_ndk_getConfigureFlagEncode,
2490  .cleanOutputBuffers = mediacodec_ndk_cleanOutputBuffers,
2491  .signalEndOfInputStream = mediacodec_ndk_signalEndOfInputStream,
2492 };
2493 
2495 {
2496  if (ndk)
2497  return media_format_ndk.create();
2498  return media_format_jni.create();
2499 }
2500 
2502 {
2503  if (ndk)
2506 }
2507 
2508 FFAMediaCodec* ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk)
2509 {
2510  if (ndk)
2511  return media_codec_ndk.createDecoderByType(mime_type);
2512  return media_codec_jni.createDecoderByType(mime_type);
2513 }
2514 
2515 FFAMediaCodec* ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
2516 {
2517  if (ndk)
2518  return media_codec_ndk.createEncoderByType(mime_type);
2519  return media_codec_jni.createEncoderByType(mime_type);
2520 }
2521 
2523 {
2524  int ret = -1;
2525 
2526 #if __ANDROID_API__ >= 24
2527  // android_get_device_api_level() is a static inline before API level 29.
2528  // dlsym() might doesn't work.
2529  //
2530  // We can implement android_get_device_api_level() by
2531  // __system_property_get(), but __system_property_get() has created a lot of
2532  // troubles and is deprecated. So avoid using __system_property_get() for
2533  // now.
2534  //
2535  // Hopy we can remove the conditional compilation finally by bumping the
2536  // required API level.
2537  //
2538  ret = android_get_device_api_level();
2539 #else
2540  JNIEnv *env = NULL;
2541  jclass versionClass;
2542  jfieldID sdkIntFieldID;
2543  JNI_GET_ENV_OR_RETURN(env, avctx, -1);
2544 
2545  versionClass = (*env)->FindClass(env, "android/os/Build$VERSION");
2546  sdkIntFieldID = (*env)->GetStaticFieldID(env, versionClass, "SDK_INT", "I");
2547  ret = (*env)->GetStaticIntField(env, versionClass, sdkIntFieldID);
2548  (*env)->DeleteLocalRef(env, versionClass);
2549 #endif
2550  av_log(avctx, AV_LOG_DEBUG, "device api level %d\n", ret);
2551 
2552  return ret;
2553 }
2554 
2555 static struct {
2558 } color_range_map[] = {
2561 };
2562 
2563 static struct {
2566 } color_space_map[] = {
2571 };
2572 
2573 static struct {
2576 } color_primaries_map[] = {
2581 };
2582 
2583 static struct {
2586 } color_transfer_map[] = {
2591 };
2592 
2594 {
2595  for (int i = 0; i < FF_ARRAY_ELEMS(color_range_map); i++)
2597  return color_range_map[i].range;
2598 
2599  return AVCOL_RANGE_UNSPECIFIED;
2600 }
2601 
2603 {
2604  for (int i = 0; i < FF_ARRAY_ELEMS(color_range_map); i++)
2606  return color_range_map[i].mf_range;
2607  return COLOR_RANGE_UNSPECIFIED;
2608 }
2609 
2611 {
2612  for (int i = 0; i < FF_ARRAY_ELEMS(color_space_map); i++)
2613  if (color_space_map[i].mf_standard == color_standard)
2614  return color_space_map[i].space;
2615 
2616  return AVCOL_SPC_UNSPECIFIED;
2617 }
2618 
2620 {
2621  for (int i = 0; i < FF_ARRAY_ELEMS(color_space_map); i++)
2622  if (color_space_map[i].space == color_space)
2623  return color_space_map[i].mf_standard;
2624 
2626 }
2627 
2629 {
2630  for (int i = 0; i < FF_ARRAY_ELEMS(color_primaries_map); i++)
2631  if (color_primaries_map[i].mf_standard == color_standard)
2632  return color_primaries_map[i].primaries;
2633 
2634  return AVCOL_PRI_UNSPECIFIED;
2635 }
2636 
2639 {
2640  for (int i = 0; i < FF_ARRAY_ELEMS(color_transfer_map); i++)
2641  if (color_transfer_map[i].mf_transfer == color_transfer)
2642  return color_transfer_map[i].transfer;
2643 
2644  return AVCOL_TRC_UNSPECIFIED;
2645 }
2646 
2648  enum AVColorTransferCharacteristic color_transfer)
2649 {
2650  for (int i = 0; i < FF_ARRAY_ELEMS(color_transfer_map); i++)
2651  if (color_transfer_map[i].transfer == color_transfer)
2652  return color_transfer_map[i].mf_transfer;
2653 
2655 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
JNIAMediaCodecFields::create_by_codec_name_id
jmethodID create_by_codec_name_id
Definition: mediacodec_wrapper.c:170
JNIAMediaCodecListFields::get_codec_info_at_id
jmethodID get_codec_info_at_id
Definition: mediacodec_wrapper.c:45
FFAMediaCodecJni::jfields
struct JNIAMediaCodecFields jfields
Definition: mediacodec_wrapper.c:272
JNIAMediaCodecFields::get_output_buffer_id
jmethodID get_output_buffer_id
Definition: mediacodec_wrapper.c:190
mf_range
enum FFAMediaFormatColorRange mf_range
Definition: mediacodec_wrapper.c:2556
JNIAMediaCodecListFields::is_software_only_id
jmethodID is_software_only_id
Definition: mediacodec_wrapper.c:52
mediaformat_ndk_setRect
static void mediaformat_ndk_setRect(FFAMediaFormat *ctx, const char *name, int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition: mediacodec_wrapper.c:2077
FFAMediaCodecJni::api
FFAMediaCodec api
Definition: mediacodec_wrapper.c:270
ff_AMediaCodecList_getCodecNameByType
char * ff_AMediaCodecList_getCodecNameByType(const char *mime, int profile, int encoder, void *log_ctx)
Definition: mediacodec_wrapper.c:469
JNIAMediaFormatFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:95
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
JNIAMediaFormatFields
Definition: mediacodec_wrapper.c:91
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:2027
AV_PROFILE_H264_HIGH_10_INTRA
#define AV_PROFILE_H264_HIGH_10_INTRA
Definition: defs.h:115
mediacodec_ndk_getBufferFlagKeyFrame
static int mediacodec_ndk_getBufferFlagKeyFrame(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2396
mediacodec_ndk_releaseOutputBuffer
static int mediacodec_ndk_releaseOutputBuffer(FFAMediaCodec *ctx, size_t idx, int render)
Definition: mediacodec_wrapper.c:2343
AV_PROFILE_MPEG4_ADVANCED_SIMPLE
#define AV_PROFILE_MPEG4_ADVANCED_SIMPLE
Definition: defs.h:145
amediacodec_ndk_class
static const AVClass amediacodec_ndk_class
Definition: mediacodec_wrapper.c:1907
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:1009
AV_PROFILE_MPEG4_N_BIT
#define AV_PROFILE_MPEG4_N_BIT
Definition: defs.h:134
JNIAMediaCodecFields::size_id
jfieldID size_id
Definition: mediacodec_wrapper.c:205
FFAMediaCodecNdk::dequeueInputBuffer
ssize_t(* dequeueInputBuffer)(AMediaCodec *, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1878
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:580
mediacodec_jni_cleanOutputBuffers
static int mediacodec_jni_cleanOutputBuffers(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1725
out
FILE * out
Definition: movenc.c:55
AV_PROFILE_MPEG4_SIMPLE_SCALABLE
#define AV_PROFILE_MPEG4_SIMPLE_SCALABLE
Definition: defs.h:131
FFAMediaCodecNdk::getOutputFormat
AMediaFormat *(* getOutputFormat)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1884
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:129
FFAMediaFormatNdk::setString
void(* setString)(AMediaFormat *, const char *name, const char *value)
Definition: mediacodec_wrapper.c:1848
FFAMediaFormatNdk::impl
AMediaFormat * impl
Definition: mediacodec_wrapper.c:1829
mediacodec_ndk_infoOutputBuffersChanged
static int mediacodec_ndk_infoOutputBuffersChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2376
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:589
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
ff_AMediaFormatColorStandard_to_AVColorSpace
enum AVColorSpace ff_AMediaFormatColorStandard_to_AVColorSpace(int color_standard)
Map MediaFormat color standard to AVColorSpace.
Definition: mediacodec_wrapper.c:2610
mediacodec_ndk_getInputBuffer
static uint8_t * mediacodec_ndk_getInputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:2292
mediaformat_jni_delete
static int mediaformat_jni_delete(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:755
JNIAMediaCodecFields::flush_id
jmethodID flush_id
Definition: mediacodec_wrapper.c:178
JNIAMediaCodecFields::get_name_id
jmethodID get_name_id
Definition: mediacodec_wrapper.c:174
JNIAMediaFormatFields::get_float_id
jmethodID get_float_id
Definition: mediacodec_wrapper.c:101
mediaformat_jni_new
static FFAMediaFormat * mediaformat_jni_new(void)
Definition: mediacodec_wrapper.c:677
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
AV_PROFILE_VP9_1
#define AV_PROFILE_VP9_1
Definition: defs.h:154
FFAMediaCodecNdk::createCodecByName
AMediaCodec *(* createCodecByName)(const char *name)
Definition: mediacodec_wrapper.c:1861
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:158
out_size
int out_size
Definition: movenc.c:56
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
JNIAMediaCodecListFields::mediacodec_list_class
jclass mediacodec_list_class
Definition: mediacodec_wrapper.c:40
JNIAMediaCodecFields::mediainfo_class
jclass mediainfo_class
Definition: mediacodec_wrapper.c:198
jni_amediacodec_mapping
static const struct FFJniField jni_amediacodec_mapping[]
Definition: mediacodec_wrapper.c:210
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:1521
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:686
mediaformat_jni_setBuffer
static void mediaformat_jni_setBuffer(FFAMediaFormat *ctx, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.c:1112
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:368
JNIAMediaCodecListFields::get_supported_types_id
jmethodID get_supported_types_id
Definition: mediacodec_wrapper.c:50
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:583
data
const char data[16]
Definition: mxf.c:148
AV_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE
#define AV_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE
Definition: defs.h:137
FFAMediaFormatNdk
Definition: mediacodec_wrapper.c:1825
amediacodec_class
static const AVClass amediacodec_class
Definition: mediacodec_wrapper.c:263
COLOR_TRANSFER_LINEAR
@ COLOR_TRANSFER_LINEAR
Definition: mediacodec_wrapper.h:364
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:1879
JNIAMediaCodecFields::info_try_again_later_id
jfieldID info_try_again_later_id
Definition: mediacodec_wrapper.c:160
FFAMediaCodecNdk::delete
media_status_t(* delete)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1864
mediacodec_jni_infoTryAgainLater
static int mediacodec_jni_infoTryAgainLater(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1683
mediacodec_jni_getBufferFlagEndOfStream
static int mediacodec_jni_getBufferFlagEndOfStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1707
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:555
mediacodec_ndk_getConfigureFlagEncode
static int mediacodec_ndk_getConfigureFlagEncode(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2401
mediacodec_jni_start
static int mediacodec_jni_start(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1413
AV_PROFILE_AV1_PROFESSIONAL
#define AV_PROFILE_AV1_PROFESSIONAL
Definition: defs.h:169
mediaformat_jni_getString
static int mediaformat_jni_getString(FFAMediaFormat *ctx, const char *name, const char **out)
Definition: mediacodec_wrapper.c:964
mf_standard
enum FFAMediaFormatColorStandard mf_standard
Definition: mediacodec_wrapper.c:2564
AV_PROFILE_MPEG4_CORE_SCALABLE
#define AV_PROFILE_MPEG4_CORE_SCALABLE
Definition: defs.h:140
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:837
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:279
FFAMediaCodecNdk
Definition: mediacodec_wrapper.c:1854
JNIAMediaCodecFields::presentation_time_us_id
jfieldID presentation_time_us_id
Definition: mediacodec_wrapper.c:204
AV_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE
#define AV_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE
Definition: defs.h:143
JNIAMediaCodecListFields::get_name_id
jmethodID get_name_id
Definition: mediacodec_wrapper.c:48
mediacodec_ndk_cleanOutputBuffers
static int mediacodec_ndk_cleanOutputBuffers(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2406
mediaformat_jni_getInt32
static int mediaformat_jni_getInt32(FFAMediaFormat *ctx, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:800
AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_H264_EXTENDED
Definition: defs.h:112
mediacodec_jni_getOutputFormat
static FFAMediaFormat * mediacodec_jni_getOutputFormat(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1661
primaries
enum AVColorPrimaries primaries
Definition: mediacodec_wrapper.c:2575
AVCOL_SPC_BT470BG
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
Definition: pixfmt.h:615
JNIAMediaCodecListFields::is_encoder_id
jmethodID is_encoder_id
Definition: mediacodec_wrapper.c:51
window
static SDL_Window * window
Definition: ffplay.c:361
color_transfer_map
static struct @128 color_transfer_map[]
mediacodec_jni_delete
static int mediacodec_jni_delete(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1310
JNIAMediaCodecListFields::get_codec_count_id
jmethodID get_codec_count_id
Definition: mediacodec_wrapper.c:44
jni_amediacodeclist_mapping
static const struct FFJniField jni_amediacodeclist_mapping[]
Definition: mediacodec_wrapper.c:64
FFAMediaCodecNdk::libmedia
void * libmedia
Definition: mediacodec_wrapper.c:1857
JNIAMediaFormatFields::set_long_id
jmethodID set_long_id
Definition: mediacodec_wrapper.c:106
mediaformat_ndk_getInt32
static int mediaformat_ndk_getInt32(FFAMediaFormat *ctx, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:2003
fail
#define fail()
Definition: checkasm.h:179
mediaformat_jni_setString
static void mediaformat_jni_setString(FFAMediaFormat *ctx, const char *name, const char *value)
Definition: mediacodec_wrapper.c:1081
JNIAMediaCodecFields::set_input_surface_id
jmethodID set_input_surface_id
Definition: mediacodec_wrapper.c:195
mediacodec_ndk_infoTryAgainLater
static int mediacodec_ndk_infoTryAgainLater(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2371
AV_PROFILE_MPEG4_SCALABLE_TEXTURE
#define AV_PROFILE_MPEG4_SCALABLE_TEXTURE
Definition: defs.h:135
FFAMediaCodecJni::INFO_OUTPUT_FORMAT_CHANGED
int INFO_OUTPUT_FORMAT_CHANGED
Definition: mediacodec_wrapper.c:282
JNIAMediaFormatFields::set_float_id
jmethodID set_float_id
Definition: mediacodec_wrapper.c:107
JNIAMediaCodecListFields::mediacodec_info_class
jclass mediacodec_info_class
Definition: mediacodec_wrapper.c:47
mediacodec_jni_releaseOutputBufferAtTime
static int mediacodec_jni_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:1485
JNIAMediaFormatFields::to_string_id
jmethodID to_string_id
Definition: mediacodec_wrapper.c:111
FFAMediaFormatNdk::setInt64
void(* setInt64)(AMediaFormat *, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:1846
FF_JNI_CLASS
@ FF_JNI_CLASS
Definition: ffjni.h:91
COLOR_RANGE_UNSPECIFIED
@ COLOR_RANGE_UNSPECIFIED
Definition: mediacodec_wrapper.h:349
color_space_map
static struct @126 color_space_map[]
AV_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION
#define AV_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION
Definition: defs.h:136
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:180
FFAMediaFormatJni::api
FFAMediaFormat api
Definition: mediacodec_wrapper.c:148
COLOR_TRANSFER_HLG
@ COLOR_TRANSFER_HLG
Definition: mediacodec_wrapper.h:367
AV_PROFILE_VP9_3
#define AV_PROFILE_VP9_3
Definition: defs.h:156
JNIAMediaCodecFields::get_output_buffers_id
jmethodID get_output_buffers_id
Definition: mediacodec_wrapper.c:191
JNIAMediaCodecFields::release_output_buffer_at_time_id
jmethodID release_output_buffer_at_time_id
Definition: mediacodec_wrapper.c:193
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2494
mediacodec_jni_dequeueOutputBuffer
static ssize_t mediacodec_jni_dequeueOutputBuffer(FFAMediaCodec *ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1539
CREATE_CODEC_BY_NAME
#define CREATE_CODEC_BY_NAME
Definition: mediacodec_wrapper.c:1209
FFAMediaFormatNdk::getFloat
bool(* getFloat)(AMediaFormat *, const char *name, float *out)
Definition: mediacodec_wrapper.c:1838
FFAMediaCodecNdk::start
media_status_t(* start)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1871
JNIAMediaCodecFields::buffer_flag_codec_config_id
jfieldID buffer_flag_codec_config_id
Definition: mediacodec_wrapper.c:164
FFAMediaFormat::delete
int(* delete)(FFAMediaFormat *)
Definition: mediacodec_wrapper.h:67
mediacodec_ndk_getName
static char * mediacodec_ndk_getName(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2088
avassert.h
mediaformat_ndk_getInt64
static int mediaformat_ndk_getInt64(FFAMediaFormat *ctx, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:2009
description
Tag description
Definition: snow.txt:206
mediacodec_jni_infoOutputBuffersChanged
static int mediacodec_jni_infoOutputBuffersChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1689
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
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:2310
FFAMediaCodecNdk::signalEndOfInputStream
media_status_t(* signalEndOfInputStream)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1895
JNIAMediaCodecListFields::profile_id
jfieldID profile_id
Definition: mediacodec_wrapper.c:59
FFAMediaCodecJni::output_buffers
jobject output_buffers
Definition: mediacodec_wrapper.c:278
ff_Build_SDK_INT
int ff_Build_SDK_INT(AVCodecContext *avctx)
Definition: mediacodec_wrapper.c:2522
JNIAMediaCodecListFields::codec_profile_level_class
jclass codec_profile_level_class
Definition: mediacodec_wrapper.c:58
mediacodec_ndk_getBufferFlagCodecConfig
static int mediacodec_ndk_getBufferFlagCodecConfig(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2386
mediaformat_jni_setInt64
static void mediaformat_jni_setInt64(FFAMediaFormat *ctx, const char *name, int64_t value)
Definition: mediacodec_wrapper.c:1033
JNIAMediaCodecFields::create_decoder_by_type_id
jmethodID create_decoder_by_type_id
Definition: mediacodec_wrapper.c:171
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
AV_PROFILE_MPEG4_HYBRID
#define AV_PROFILE_MPEG4_HYBRID
Definition: defs.h:138
JNIAMediaCodecFields::get_output_format_id
jmethodID get_output_format_id
Definition: mediacodec_wrapper.c:182
AVCOL_SPC_SMPTE170M
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
Definition: pixfmt.h:616
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
mediacodec_ndk_dequeueInputBuffer
static ssize_t mediacodec_ndk_dequeueInputBuffer(FFAMediaCodec *ctx, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:2304
JNI_GET_ENV_OR_RETURN_VOID
#define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx)
Definition: mediacodec_wrapper.c:302
AV_PROFILE_H264_HIGH_10
#define AV_PROFILE_H264_HIGH_10
Definition: defs.h:114
info
MIPS optimizations info
Definition: mips.txt:2
JNIAMediaCodecFields::get_input_buffer_id
jmethodID get_input_buffer_id
Definition: mediacodec_wrapper.c:186
ff_jni_jstring_to_utf_chars
char * ff_jni_jstring_to_utf_chars(JNIEnv *env, jstring string, void *log_ctx)
Definition: ffjni.c:99
FFAMediaCodecNdk::setInputSurface
media_status_t(* setInputSurface)(AMediaCodec *, ANativeWindow *)
Definition: mediacodec_wrapper.c:1894
FFAMediaFormatNdk::getInt64
bool(* getInt64)(AMediaFormat *, const char *name, int64_t *out)
Definition: mediacodec_wrapper.c:1837
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
JNIAMediaCodecFields::offset_id
jfieldID offset_id
Definition: mediacodec_wrapper.c:203
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:49
AV_PROFILE_H264_HIGH_422_INTRA
#define AV_PROFILE_H264_HIGH_422_INTRA
Definition: defs.h:118
mediaformat_jni_newFromObject
static FFAMediaFormat * mediaformat_jni_newFromObject(void *object)
Definition: mediacodec_wrapper.c:720
JNIAMediaCodecListFields::find_decoder_for_format_id
jmethodID find_decoder_for_format_id
Definition: mediacodec_wrapper.c:42
mediaformat_ndk_getFloat
static int mediaformat_ndk_getFloat(FFAMediaFormat *ctx, const char *name, float *out)
Definition: mediacodec_wrapper.c:2015
key
const char * key
Definition: hwcontext_opencl.c:189
color_range
color_range
Definition: vf_selectivecolor.c:43
JNIAMediaCodecFields::dequeue_input_buffer_id
jmethodID dequeue_input_buffer_id
Definition: mediacodec_wrapper.c:184
mediacodec_jni_getBufferFlagKeyFrame
static int mediacodec_jni_getBufferFlagKeyFrame(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1713
FFAMediaFormatNdk::getString
bool(* getString)(AMediaFormat *, const char *name, const char **out)
Definition: mediacodec_wrapper.c:1841
mf_transfer
enum FFAMediaFormatColorTransfer mf_transfer
Definition: mediacodec_wrapper.c:2584
FFAMediaCodecJni::CONFIGURE_FLAG_ENCODE
int CONFIGURE_FLAG_ENCODE
Definition: mediacodec_wrapper.c:288
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:558
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCOL_PRI_BT470BG
@ AVCOL_PRI_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:562
AV_PROFILE_H264_HIGH_422
#define AV_PROFILE_H264_HIGH_422
Definition: defs.h:117
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
arg
const char * arg
Definition: jacosubdec.c:67
FFAMediaFormatNdk::setFloat
void(* setFloat)(AMediaFormat *, const char *name, float value)
Definition: mediacodec_wrapper.c:1847
AVCOL_PRI_SMPTE170M
@ AVCOL_PRI_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:563
COLOR_RANGE_LIMITED
@ COLOR_RANGE_LIMITED
Definition: mediacodec_wrapper.h:351
mediaformat_ndk_setBuffer
static void mediaformat_ndk_setBuffer(FFAMediaFormat *ctx, const char *name, void *data, size_t size)
Definition: mediacodec_wrapper.c:2071
ff_AMediaFormatColorStandard_from_AVColorSpace
int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space)
Map AVColorSpace to MediaFormat color standard.
Definition: mediacodec_wrapper.c:2619
JNIAMediaCodecFields::queue_input_buffer_id
jmethodID queue_input_buffer_id
Definition: mediacodec_wrapper.c:185
mediaformat_ndk_setInt32
static void mediaformat_ndk_setInt32(FFAMediaFormat *ctx, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:2047
JNIAMediaFormatFields::get_string_id
jmethodID get_string_id
Definition: mediacodec_wrapper.c:103
GET_SYMBOL
#define GET_SYMBOL(sym)
mediaformat_ndk_getRect
static int mediaformat_ndk_getRect(FFAMediaFormat *ctx, const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
Definition: mediacodec_wrapper.c:2038
JNIAMediaCodecListFields
Definition: mediacodec_wrapper.c:38
jni_amediaformat_mapping
static const struct FFJniField jni_amediaformat_mapping[]
Definition: mediacodec_wrapper.c:116
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:172
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
color_primaries_map
static struct @127 color_primaries_map[]
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2501
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2602
FF_JNI_METHOD
@ FF_JNI_METHOD
Definition: ffjni.h:94
JNIAMediaCodecFields::stop_id
jmethodID stop_id
Definition: mediacodec_wrapper.c:179
NULL
#define NULL
Definition: coverity.c:32
mediacodec_ndk_getBufferFlagEndOfStream
static int mediacodec_ndk_getBufferFlagEndOfStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2391
FFAMediaCodecJni::input_buffers
jobject input_buffers
Definition: mediacodec_wrapper.c:277
JNIAMediaCodecFields::release_output_buffer_id
jmethodID release_output_buffer_id
Definition: mediacodec_wrapper.c:192
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:280
FFAMediaCodecJni::has_get_i_o_buffer
int has_get_i_o_buffer
Definition: mediacodec_wrapper.c:290
FFAMediaCodecJni::BUFFER_FLAG_KEY_FRAME
int BUFFER_FLAG_KEY_FRAME
Definition: mediacodec_wrapper.c:286
FFJniField
Definition: ffjni.h:103
AV_PROFILE_HEVC_MAIN_STILL_PICTURE
#define AV_PROFILE_HEVC_MAIN_STILL_PICTURE
Definition: defs.h:160
GET_OPTIONAL_SYMBOL
#define GET_OPTIONAL_SYMBOL(sym)
media_codec_ndk
static const FFAMediaCodec media_codec_ndk
Definition: mediacodec_wrapper.c:1899
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:557
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:1855
mediacodec_jni_releaseOutputBuffer
static int mediacodec_jni_releaseOutputBuffer(FFAMediaCodec *ctx, size_t idx, int render)
Definition: mediacodec_wrapper.c:1467
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2515
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:368
COLOR_STANDARD_BT709
@ COLOR_STANDARD_BT709
Definition: mediacodec_wrapper.h:356
mediacodec_jni_getName
static char * mediacodec_jni_getName(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1346
JNIAMediaCodecFields::get_input_buffers_id
jmethodID get_input_buffers_id
Definition: mediacodec_wrapper.c:187
FFAMediaFormatNdk::setInt32
void(* setInt32)(AMediaFormat *, const char *name, int32_t value)
Definition: mediacodec_wrapper.c:1845
FFAMediaCodecJni::INFO_OUTPUT_BUFFERS_CHANGED
int INFO_OUTPUT_BUFFERS_CHANGED
Definition: mediacodec_wrapper.c:281
JNIAMediaCodecFields::buffer_flag_end_of_stream_id
jfieldID buffer_flag_end_of_stream_id
Definition: mediacodec_wrapper.c:165
JNIAMediaCodecFields::info_output_format_changed_id
jfieldID info_output_format_changed_id
Definition: mediacodec_wrapper.c:162
mediaformat_ndk_getBuffer
static int mediaformat_ndk_getBuffer(FFAMediaFormat *ctx, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:2021
DECLARE_FF_AMEDIACODEC_CREATE_FUNC
#define DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method)
Definition: mediacodec_wrapper.c:1300
JNIAMediaCodecFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:200
mediacodec_jni_dequeueInputBuffer
static ssize_t mediacodec_jni_dequeueInputBuffer(FFAMediaCodec *ctx, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1503
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:159
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:652
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:566
JNIAMediaCodecListFields::get_codec_capabilities_id
jmethodID get_codec_capabilities_id
Definition: mediacodec_wrapper.c:49
FFAMediaCodecNdk::getName
media_status_t(* getName)(AMediaCodec *, char **out_name)
Definition: mediacodec_wrapper.c:1890
FFAMediaFormatNdk::getRect
bool(* getRect)(AMediaFormat *, const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom)
Definition: mediacodec_wrapper.c:1842
JNIAMediaCodecFields
Definition: mediacodec_wrapper.c:156
mediaformat_jni_getFloat
static int mediaformat_jni_getFloat(FFAMediaFormat *ctx, const char *name, float *out)
Definition: mediacodec_wrapper.c:874
AV_PROFILE_MPEG4_ADVANCED_CORE
#define AV_PROFILE_MPEG4_ADVANCED_CORE
Definition: defs.h:142
ff_AMediaFormatColorStandard_to_AVColorPrimaries
enum AVColorPrimaries ff_AMediaFormatColorStandard_to_AVColorPrimaries(int color_standard)
Map MediaFormat color standard to AVColorPrimaries.
Definition: mediacodec_wrapper.c:2628
JNIAMediaCodecFields::configure_id
jmethodID configure_id
Definition: mediacodec_wrapper.c:176
JNIAMediaCodecFields::configure_flag_encode_id
jfieldID configure_flag_encode_id
Definition: mediacodec_wrapper.c:168
JNIAMediaFormatFields::mediaformat_class
jclass mediaformat_class
Definition: mediacodec_wrapper.c:93
FFAMediaCodecNdk::createEncoderByType
AMediaCodec *(* createEncoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.c:1863
FFAMediaCodecNdk::getInputBuffer
uint8_t *(* getInputBuffer)(AMediaCodec *, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1875
AVCOL_TRC_SMPTEST2084
@ AVCOL_TRC_SMPTEST2084
Definition: pixfmt.h:598
FFAMediaFormatNdk::setBuffer
void(* setBuffer)(AMediaFormat *, const char *name, const void *data, size_t size)
Definition: mediacodec_wrapper.c:1849
media_format_jni
static const FFAMediaFormat media_format_jni
Definition: mediacodec_wrapper.c:154
FFAMediaCodec::createDecoderByType
FFAMediaCodec *(* createDecoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.h:187
COLOR_TRANSFER_SDR_VIDEO
@ COLOR_TRANSFER_SDR_VIDEO
Definition: mediacodec_wrapper.h:365
FFAMediaCodec::createCodecByName
FFAMediaCodec *(* createCodecByName)(const char *name)
Definition: mediacodec_wrapper.h:186
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h:363
size
int size
Definition: twinvq_data.h:10344
JNIAMediaFormatFields::get_long_id
jmethodID get_long_id
Definition: mediacodec_wrapper.c:100
media_format_ndk
static const FFAMediaFormat media_format_ndk
Definition: mediacodec_wrapper.c:1898
ff_AMediaFormatColorTransfer_from_AVColorTransfer
int ff_AMediaFormatColorTransfer_from_AVColorTransfer(enum AVColorTransferCharacteristic color_transfer)
Map AVColorTransferCharacteristic to MediaFormat color transfer.
Definition: mediacodec_wrapper.c:2647
CREATE_ENCODER_BY_TYPE
#define CREATE_ENCODER_BY_TYPE
Definition: mediacodec_wrapper.c:1211
JNIAMediaFormatFields::set_bytebuffer_id
jmethodID set_bytebuffer_id
Definition: mediacodec_wrapper.c:108
DECLARE_NDK_AMEDIACODEC_CREATE_FUNC
#define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC(name, method)
Definition: mediacodec_wrapper.c:2184
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2557
mediacodec_ndk_dequeueOutputBuffer
static ssize_t mediacodec_ndk_dequeueOutputBuffer(FFAMediaCodec *ctx, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:2318
AV_PROFILE_MPEG4_ADVANCED_CODING
#define AV_PROFILE_MPEG4_ADVANCED_CODING
Definition: defs.h:141
FFAMediaCodecNdk::releaseOutputBufferAtTime
media_status_t(* releaseOutputBufferAtTime)(AMediaCodec *mData, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:1887
JNIAMediaCodecFields::start_id
jmethodID start_id
Definition: mediacodec_wrapper.c:177
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:309
COLOR_RANGE_FULL
@ COLOR_RANGE_FULL
Definition: mediacodec_wrapper.h:350
mediacodec_jni_infoOutputFormatChanged
static int mediacodec_jni_infoOutputFormatChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:1695
JNIAMediaFormatFields::get_integer_id
jmethodID get_integer_id
Definition: mediacodec_wrapper.c:99
AV_PROFILE_AV1_HIGH
#define AV_PROFILE_AV1_HIGH
Definition: defs.h:168
space
enum AVColorSpace space
Definition: mediacodec_wrapper.c:2565
amediaformat_ndk_class
static const AVClass amediaformat_ndk_class
Definition: mediacodec_wrapper.c:1901
ff_AMediaCodec_createDecoderByType
FFAMediaCodec * ff_AMediaCodec_createDecoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2508
FFAMediaCodecNdk::impl
AMediaCodec * impl
Definition: mediacodec_wrapper.c:1858
COLOR_TRANSFER_ST2084
@ COLOR_TRANSFER_ST2084
Definition: mediacodec_wrapper.h:366
FFAMediaCodec::class
const AVClass * class
Definition: mediacodec_wrapper.h:182
mediaformat_ndk_new
static FFAMediaFormat * mediaformat_ndk_new(void)
Definition: mediacodec_wrapper.c:1973
FFAMediaCodecNdk::stop
media_status_t(* stop)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1872
JNIAMediaCodecListFields::color_formats_id
jfieldID color_formats_id
Definition: mediacodec_wrapper.c:55
CREATE_DECODER_BY_TYPE
#define CREATE_DECODER_BY_TYPE
Definition: mediacodec_wrapper.c:1210
JNIAMediaFormatFields::set_integer_id
jmethodID set_integer_id
Definition: mediacodec_wrapper.c:105
AV_PROFILE_MPEG4_SIMPLE
#define AV_PROFILE_MPEG4_SIMPLE
Definition: defs.h:130
FF_JNI_FIELD
@ FF_JNI_FIELD
Definition: ffjni.h:92
mediaformat_ndk_create
static FFAMediaFormat * mediaformat_ndk_create(AMediaFormat *impl)
Definition: mediacodec_wrapper.c:1913
mediacodec_jni_flush
static int mediacodec_jni_flush(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1449
buffer_data
Definition: avio_read_callback.c:37
OFFSET
#define OFFSET(x)
Definition: mediacodec_wrapper.c:209
COLOR_STANDARD_BT2020
@ COLOR_STANDARD_BT2020
Definition: mediacodec_wrapper.h:359
FFANativeWindow
Definition: mediacodec_surface.h:28
ff_jni_exception_check
int ff_jni_exception_check(JNIEnv *env, int log, void *log_ctx)
Definition: ffjni.c:246
ff_AMediaFormatColorTransfer_to_AVColorTransfer
enum AVColorTransferCharacteristic ff_AMediaFormatColorTransfer_to_AVColorTransfer(int color_transfer)
Map MediaFormat color transfer to AVColorTransferCharacteristic.
Definition: mediacodec_wrapper.c:2638
mediacodec_ndk_delete
static int mediacodec_ndk_delete(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2194
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
mediacodec_wrapper.h
COLOR_STANDARD_UNSPECIFIED
@ COLOR_STANDARD_UNSPECIFIED
Definition: mediacodec_wrapper.h:355
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:620
ffjni.h
FFAMediaCodec
Definition: mediacodec_wrapper.h:181
transfer
enum AVColorTransferCharacteristic transfer
Definition: mediacodec_wrapper.c:2585
mediacodec_ndk_getOutputFormat
static FFAMediaFormat * mediacodec_ndk_getOutputFormat(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2333
color_range_map
static struct @125 color_range_map[]
FFAMediaCodecNdk::getOutputBuffer
uint8_t *(* getOutputBuffer)(AMediaCodec *, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1876
mediacodec_ndk_signalEndOfInputStream
static int mediacodec_ndk_signalEndOfInputStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:2411
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:609
FFAMediaCodecNdk::window
ANativeWindow * window
Definition: mediacodec_wrapper.c:1859
FFAMediaFormatJni::jfields
struct JNIAMediaFormatFields jfields
Definition: mediacodec_wrapper.c:150
JNIAMediaCodecFields::buffer_flag_key_frame_id
jfieldID buffer_flag_key_frame_id
Definition: mediacodec_wrapper.c:166
JNIAMediaCodecFields::signal_end_of_input_stream_id
jmethodID signal_end_of_input_stream_id
Definition: mediacodec_wrapper.c:196
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:285
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:256
AV_PROFILE_MPEG4_MAIN
#define AV_PROFILE_MPEG4_MAIN
Definition: defs.h:133
FFAMediaCodecJni::INFO_TRY_AGAIN_LATER
int INFO_TRY_AGAIN_LATER
Definition: mediacodec_wrapper.c:280
FFAMediaFormatNdk::getInt32
bool(* getInt32)(AMediaFormat *, const char *name, int32_t *out)
Definition: mediacodec_wrapper.c:1836
AV_PROFILE_MPEG4_SIMPLE_STUDIO
#define AV_PROFILE_MPEG4_SIMPLE_STUDIO
Definition: defs.h:144
FFAMediaCodecNdk::dequeueOutputBuffer
ssize_t(* dequeueOutputBuffer)(AMediaCodec *, AMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.c:1883
profile
int profile
Definition: mxfenc.c:2227
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:669
COLOR_STANDARD_BT601_PAL
@ COLOR_STANDARD_BT601_PAL
Definition: mediacodec_wrapper.h:357
FFAMediaCodec::createEncoderByType
FFAMediaCodec *(* createEncoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.h:188
avcodec.h
FFAMediaFormatColorStandard
FFAMediaFormatColorStandard
Definition: mediacodec_wrapper.h:354
FFAMediaCodecNdk::createDecoderByType
AMediaCodec *(* createDecoderByType)(const char *mime_type)
Definition: mediacodec_wrapper.c:1862
mediaformat_ndk_setFloat
static void mediaformat_ndk_setFloat(FFAMediaFormat *ctx, const char *name, float value)
Definition: mediacodec_wrapper.c:2059
JNIAMediaCodecFields::mediacodec_class
jclass mediacodec_class
Definition: mediacodec_wrapper.c:158
ff_AMediaFormatColorRange_to_AVColorRange
enum AVColorRange ff_AMediaFormatColorRange_to_AVColorRange(int color_range)
Map MediaFormat color range to AVColorRange.
Definition: mediacodec_wrapper.c:2593
AV_PROFILE_H264_HIGH_444_PREDICTIVE
#define AV_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: defs.h:121
AV_PROFILE_VP9_2
#define AV_PROFILE_VP9_2
Definition: defs.h:155
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:1155
mediacodec_jni_getBufferFlagCodecConfig
static int mediacodec_jni_getBufferFlagCodecConfig(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1701
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:109
AV_PROFILE_MPEG4_CORE
#define AV_PROFILE_MPEG4_CORE
Definition: defs.h:132
JNIAMediaFormatFields::get_bytebuffer_id
jmethodID get_bytebuffer_id
Definition: mediacodec_wrapper.c:102
FFAMediaFormatNdk::getSize
bool(* getSize)(AMediaFormat *, const char *name, size_t *out)
Definition: mediacodec_wrapper.c:1839
FF_JNI_STATIC_FIELD
@ FF_JNI_STATIC_FIELD
Definition: ffjni.h:93
FFAMediaFormatColorRange
FFAMediaFormatColorRange
Definition: mediacodec_wrapper.h:348
FFAMediaFormatNdk::setRect
void(* setRect)(AMediaFormat *, const char *name, int32_t left, int32_t top, int32_t right, int32_t bottom)
Definition: mediacodec_wrapper.c:1850
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
mediacodec_jni_getInputBuffer
static uint8_t * mediacodec_jni_getInputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1575
FFAMediaCodecJni::buffer_info
jobject buffer_info
Definition: mediacodec_wrapper.c:275
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:601
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:113
status
ov_status_e status
Definition: dnn_backend_openvino.c:121
mediacodec_jni_getConfigureFlagEncode
static int mediacodec_jni_getConfigureFlagEncode(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1719
JNI_GET_ENV_OR_RETURN
#define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret)
Definition: mediacodec_wrapper.c:295
JNIAMediaCodecListFields::profile_levels_id
jfieldID profile_levels_id
Definition: mediacodec_wrapper.c:56
FFAMediaFormatColorTransfer
FFAMediaFormatColorTransfer
Definition: mediacodec_wrapper.h:362
FFAMediaCodecJni::object
jobject object
Definition: mediacodec_wrapper.c:274
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:1639
AV_PROFILE_MPEG4_ADVANCED_REAL_TIME
#define AV_PROFILE_MPEG4_ADVANCED_REAL_TIME
Definition: defs.h:139
mediacodec_ndk_getOutputBuffer
static uint8_t * mediacodec_ndk_getOutputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:2298
mediacodec_jni_signalEndOfInputStream
static int mediacodec_jni_signalEndOfInputStream(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1749
FFAMediaFormatNdk::libmedia
void * libmedia
Definition: mediacodec_wrapper.c:1828
AVCOL_TRC_SMPTE170M
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:587
AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition: defs.h:110
ff_jni_get_env
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:53
amediaformat_class
static const AVClass amediaformat_class
Definition: mediacodec_wrapper.c:141
AV_PROFILE_VP9_0
#define AV_PROFILE_VP9_0
Definition: defs.h:153
JNIAMediaCodecListFields::init_id
jmethodID init_id
Definition: mediacodec_wrapper.c:41
FFAMediaCodecJni::BUFFER_FLAG_CODEC_CONFIG
int BUFFER_FLAG_CODEC_CONFIG
Definition: mediacodec_wrapper.c:284
FFAMediaFormatJni
Definition: mediacodec_wrapper.c:147
mediaformat_ndk_toString
static char * mediaformat_ndk_toString(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:1996
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
COLOR_STANDARD_BT601_NTSC
@ COLOR_STANDARD_BT601_NTSC
Definition: mediacodec_wrapper.h:358
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:1370
AV_PROFILE_H264_HIGH_444
#define AV_PROFILE_H264_HIGH_444
Definition: defs.h:120
mem.h
AV_PROFILE_H264_HIGH_444_INTRA
#define AV_PROFILE_H264_HIGH_444_INTRA
Definition: defs.h:122
FFAMediaFormatNdk::getBuffer
bool(* getBuffer)(AMediaFormat *, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:1840
mediaformat_jni_getBuffer
static int mediaformat_jni_getBuffer(FFAMediaFormat *ctx, const char *name, void **data, size_t *size)
Definition: mediacodec_wrapper.c:911
JNIAMediaCodecListFields::level_id
jfieldID level_id
Definition: mediacodec_wrapper.c:60
JNIAMediaCodecFields::dequeue_output_buffer_id
jmethodID dequeue_output_buffer_id
Definition: mediacodec_wrapper.c:189
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:2053
mediacodec_jni_stop
static int mediacodec_jni_stop(FFAMediaCodec *ctx)
Definition: mediacodec_wrapper.c:1431
FF_JNI_STATIC_METHOD
@ FF_JNI_STATIC_METHOD
Definition: ffjni.h:95
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
ndk_codec_create
static FFAMediaCodec * ndk_codec_create(int method, const char *arg)
Definition: mediacodec_wrapper.c:2108
JNIAMediaCodecFields::info_output_buffers_changed_id
jfieldID info_output_buffers_changed_id
Definition: mediacodec_wrapper.c:161
int32_t
int32_t
Definition: audioconvert.c:56
MEDIACODEC_NDK_WRAPPER
#define MEDIACODEC_NDK_WRAPPER(method)
Definition: mediacodec_wrapper.c:2274
FFAMediaCodecNdk::configure
media_status_t(* configure)(AMediaCodec *, const AMediaFormat *format, ANativeWindow *surface, AMediaCrypto *crypto, uint32_t flags)
Definition: mediacodec_wrapper.c:1866
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
FFAMediaCodecJni
Definition: mediacodec_wrapper.c:269
mediacodec_jni_getOutputBuffer
static uint8_t * mediacodec_jni_getOutputBuffer(FFAMediaCodec *ctx, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.c:1618
mediacodec_ndk_releaseOutputBufferAtTime
static int mediacodec_ndk_releaseOutputBufferAtTime(FFAMediaCodec *ctx, size_t idx, int64_t timestampNs)
Definition: mediacodec_wrapper.c:2357
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
JNIAMediaCodecFields::flags_id
jfieldID flags_id
Definition: mediacodec_wrapper.c:202
FFAMediaCodecNdk::releaseName
void(* releaseName)(AMediaCodec *, char *name)
Definition: mediacodec_wrapper.c:1891
FFAMediaFormatNdk::api
FFAMediaFormat api
Definition: mediacodec_wrapper.c:1826
avstring.h
jni.h
media_codec_jni
static const FFAMediaCodec media_codec_jni
Definition: mediacodec_wrapper.c:293
JNIAMediaFormatFields::contains_key_id
jmethodID contains_key_id
Definition: mediacodec_wrapper.c:97
AV_PROFILE_AV1_MAIN
#define AV_PROFILE_AV1_MAIN
Definition: defs.h:167
mediacodec_ndk_infoOutputFormatChanged
static int mediacodec_ndk_infoOutputFormatChanged(FFAMediaCodec *ctx, ssize_t idx)
Definition: mediacodec_wrapper.c:2381
FFAMediaCodecNdk::flush
media_status_t(* flush)(AMediaCodec *)
Definition: mediacodec_wrapper.c:1873
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:611
mediaformat_jni_toString
static char * mediaformat_jni_toString(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:777
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:651
JNIAMediaCodecListFields::codec_capabilities_class
jclass codec_capabilities_class
Definition: mediacodec_wrapper.c:54
mediaformat_ndk_setString
static void mediaformat_ndk_setString(FFAMediaFormat *ctx, const char *name, const char *value)
Definition: mediacodec_wrapper.c:2065
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
JNIAMediaFormatFields::set_string_id
jmethodID set_string_id
Definition: mediacodec_wrapper.c:109
mediaformat_ndk_delete
static int mediaformat_ndk_delete(FFAMediaFormat *ctx)
Definition: mediacodec_wrapper.c:1978
codec_create
static FFAMediaCodec * codec_create(int method, const char *arg)
Definition: mediacodec_wrapper.c:1213
FFAMediaFormatJni::object
jobject object
Definition: mediacodec_wrapper.c:151
FFAMediaCodecNdk::releaseOutputBuffer
media_status_t(* releaseOutputBuffer)(AMediaCodec *, size_t idx, bool render)
Definition: mediacodec_wrapper.c:1886
mediaformat_jni_setFloat
static void mediaformat_jni_setFloat(FFAMediaFormat *ctx, const char *name, float value)
Definition: mediacodec_wrapper.c:1057
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:2215