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