FFmpeg
mediacodecenc.c
Go to the documentation of this file.
1 /*
2  * Android MediaCodec encoders
3  *
4  * Copyright (c) 2022 Zhao Zhili <zhilizhao@tencent.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 "config_components.h"
24 
25 #include "libavutil/avassert.h"
26 #include "libavutil/fifo.h"
27 #include "libavutil/avstring.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/thread.h"
33 
34 #include "avcodec.h"
35 #include "bsf.h"
36 #include "codec_internal.h"
37 #include "encode.h"
38 #include "hwconfig.h"
39 #include "jni.h"
40 #include "mediacodec.h"
41 #include "mediacodec_wrapper.h"
42 #include "mediacodecdec_common.h"
43 #include "profiles.h"
44 
45 #define INPUT_DEQUEUE_TIMEOUT_US 8000
46 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
47 
49  /* Constant quality mode */
51  /* Variable bitrate mode */
53  /* Constant bitrate mode */
55  /* Constant bitrate mode with frame drops */
57 };
58 
59 typedef struct MediaCodecAsyncOutput {
63 
64 typedef struct MediaCodecEncContext {
68  const char *name;
70 
71  int fps;
72  int width;
73  int height;
74 
75  uint8_t *extradata;
77  int eof_sent;
78 
81 
83  int level;
86  // Ref. MediaFormat KEY_OPERATING_RATE
89 
93 
98 
99  int qp_i_min;
100  int qp_p_min;
101  int qp_b_min;
102  int qp_i_max;
103  int qp_p_max;
104  int qp_b_max;
106 
107 enum {
110  COLOR_FormatSurface = 0x7F000789,
111 };
112 
113 static const struct {
116 } color_formats[] = {
120 };
121 
122 static const enum AVPixelFormat avc_pix_fmts[] = {
127 };
128 
130  FFAMediaFormat *out_format)
131 {
132  MediaCodecEncContext *s = avctx->priv_data;
133  const char *name = s->name;
134  char *str = ff_AMediaFormat_toString(out_format);
135 
136  av_log(avctx, AV_LOG_DEBUG, "MediaCodec encoder %s output format %s\n",
137  name ? name : "unknown", str);
138  av_free(str);
139 }
140 
142 {
143  MediaCodecEncContext *s = avctx->priv_data;
144  FFAMediaFormat *out_format = ff_AMediaCodec_getOutputFormat(s->codec);
145 
146  if (!s->name)
147  s->name = ff_AMediaCodec_getName(s->codec);
148  mediacodec_dump_format(avctx, out_format);
149  ff_AMediaFormat_delete(out_format);
150 }
151 
153 {
154  const AVBitStreamFilter *bsf = av_bsf_get_by_name("extract_extradata");
155 
156  if (!bsf) {
157  av_log(avctx, AV_LOG_WARNING, "extract_extradata bsf not found\n");
158  return 0;
159  }
160 
161  for (int i = 0; bsf->codec_ids[i] != AV_CODEC_ID_NONE; i++) {
162  if (bsf->codec_ids[i] == avctx->codec_id)
163  return 1;
164  }
165 
166  return 0;
167 }
168 
170 {
171  MediaCodecEncContext *s = avctx->priv_data;
172  char str[128] = {0};
173  int ret;
174  int crop_right = s->width - avctx->width;
175  int crop_bottom = s->height - avctx->height;
176 
177  /* Nothing can be done for this format now */
178  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC)
179  return 0;
180 
181  s->extract_extradata = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) &&
183  if (!crop_right && !crop_bottom && !s->extract_extradata)
184  return 0;
185 
186  ret = 0;
187  if (crop_right || crop_bottom) {
188  if (avctx->codec_id == AV_CODEC_ID_H264)
189  ret = snprintf(str, sizeof(str), "h264_metadata=crop_right=%d:crop_bottom=%d",
190  crop_right, crop_bottom);
191  else if (avctx->codec_id == AV_CODEC_ID_HEVC)
192  /* Encoder can use CTU size larger than 16x16, so the real crop
193  * margin can be larger than crop_right/crop_bottom. Let bsf figure
194  * out the real crop margin.
195  */
196  ret = snprintf(str, sizeof(str), "hevc_metadata=width=%d:height=%d",
197  avctx->width, avctx->height);
198  if (ret >= sizeof(str))
200  }
201 
202  if (s->extract_extradata) {
203  ret = av_strlcatf(str, sizeof(str), "%sextract_extradata", ret ? "," : "");
204  if (ret >= sizeof(str))
206  }
207 
208  ret = av_bsf_list_parse_str(str, &s->bsf);
209  if (ret < 0)
210  return ret;
211 
212  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
213  if (ret < 0)
214  return ret;
215  s->bsf->time_base_in = avctx->time_base;
216  ret = av_bsf_init(s->bsf);
217 
218  return ret;
219 }
220 
222  uint8_t *dst, size_t size)
223 {
224  MediaCodecEncContext *s = avctx->priv_data;
225  uint8_t *dst_data[4] = {};
226  int dst_linesize[4] = {};
227 
228  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
229  dst_data[0] = dst;
230  dst_data[1] = dst + s->width * s->height;
231  dst_data[2] = dst_data[1] + s->width * s->height / 4;
232 
233  dst_linesize[0] = s->width;
234  dst_linesize[1] = dst_linesize[2] = s->width / 2;
235  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
236  dst_data[0] = dst;
237  dst_data[1] = dst + s->width * s->height;
238 
239  dst_linesize[0] = s->width;
240  dst_linesize[1] = s->width;
241  } else {
242  av_assert0(0);
243  }
244 
245  av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
246  avctx->pix_fmt, avctx->width, avctx->height);
247 }
248 
249 
250 static void on_error(FFAMediaCodec *codec, void *userdata, int error,
251  const char *detail)
252 {
253  AVCodecContext *avctx = userdata;
254  MediaCodecEncContext *s = avctx->priv_data;
255 
256  if (error == AVERROR(EAGAIN))
257  return;
258 
259  av_log(avctx, AV_LOG_ERROR, "On error, %s, %s\n", av_err2str(error), detail);
260 
261  ff_mutex_lock(&s->input_mutex);
262  ff_mutex_lock(&s->output_mutex);
263  s->encode_status = error;
264  ff_mutex_unlock(&s->output_mutex);
265  ff_mutex_unlock(&s->input_mutex);
266 
267  ff_cond_signal(&s->output_cond);
268  ff_cond_signal(&s->input_cond);
269 }
270 
271 static void on_input_available(FFAMediaCodec *codec, void *userdata,
272  int32_t index)
273 {
274  AVCodecContext *avctx = userdata;
275  MediaCodecEncContext *s = avctx->priv_data;
276  int ret;
277 
278  ff_mutex_lock(&s->input_mutex);
279  ret = av_fifo_write(s->input_index, &index, 1);
280  if (ret >= 0)
281  ff_cond_signal(&s->input_cond);
282  ff_mutex_unlock(&s->input_mutex);
283 
284  if (ret < 0)
285  on_error(codec, userdata, ret, "av_fifo_write failed");
286 }
287 
288 static void on_output_available(FFAMediaCodec *codec, void *userdata,
289  int32_t index,
290  FFAMediaCodecBufferInfo *out_info)
291 {
292  AVCodecContext *avctx = userdata;
293  MediaCodecEncContext *s = avctx->priv_data;
295  .index = index,
296  .buf_info = *out_info,
297  };
298  int ret;
299 
300  ff_mutex_lock(&s->output_mutex);
301  ret = av_fifo_write(s->async_output, &output, 1);
302  if (ret >= 0)
303  ff_cond_signal(&s->output_cond);
304  ff_mutex_unlock(&s->output_mutex);
305 
306  if (ret < 0)
307  on_error(codec, userdata, ret, "av_fifo_write failed");
308 }
309 
310 static void on_format_changed(FFAMediaCodec *codec, void *userdata,
312 {
313  mediacodec_dump_format(userdata, format);
314 }
315 
317 {
318  MediaCodecEncContext *s = avctx->priv_data;
319  size_t fifo_size = 16;
320 
321  if (!s->async_mode)
322  return 0;
323 
324  ff_mutex_init(&s->input_mutex, NULL);
325  ff_cond_init(&s->input_cond, NULL);
326 
327  ff_mutex_init(&s->output_mutex, NULL);
328  ff_cond_init(&s->output_cond, NULL);
329 
330  s->input_index = av_fifo_alloc2(fifo_size, sizeof(int32_t), AV_FIFO_FLAG_AUTO_GROW);
331  s->async_output = av_fifo_alloc2(fifo_size, sizeof(MediaCodecAsyncOutput),
333 
334  if (!s->input_index || !s->async_output)
335  return AVERROR(ENOMEM);
336 
337  return 0;
338 }
339 
341 {
342  MediaCodecEncContext *s = avctx->priv_data;
343 
344  if (!s->async_mode)
345  return;
346 
347  ff_mutex_destroy(&s->input_mutex);
348  ff_cond_destroy(&s->input_cond);
349 
350  ff_mutex_destroy(&s->output_mutex);
351  ff_cond_destroy(&s->output_cond);
352 
353  av_fifo_freep2(&s->input_index);
354  av_fifo_freep2(&s->async_output);
355 
356  s->async_mode = 0;
357 }
358 
360 
363 {
364  MediaCodecEncContext *s = avctx->priv_data;
365 
366  // Handle common options in AVCodecContext first.
367  if (avctx->qmin >= 0) {
368  ff_AMediaFormat_setInt32(format, "video-qp-i-min", avctx->qmin);
369  ff_AMediaFormat_setInt32(format, "video-qp-p-min", avctx->qmin);
370  ff_AMediaFormat_setInt32(format, "video-qp-b-min", avctx->qmin);
371  }
372 
373  if (avctx->qmax >= 0) {
374  ff_AMediaFormat_setInt32(format, "video-qp-i-max", avctx->qmax);
375  ff_AMediaFormat_setInt32(format, "video-qp-p-max", avctx->qmax);
376  ff_AMediaFormat_setInt32(format, "video-qp-b-max", avctx->qmax);
377  }
378 
379  if (s->qp_i_min >= 0)
380  ff_AMediaFormat_setInt32(format, "video-qp-i-min", s->qp_i_min);
381  if (s->qp_p_min >= 0)
382  ff_AMediaFormat_setInt32(format, "video-qp-p-min", s->qp_p_min);
383  if (s->qp_b_min >= 0)
384  ff_AMediaFormat_setInt32(format, "video-qp-b-min", s->qp_b_min);
385 
386  if (s->qp_i_max >= 0)
387  ff_AMediaFormat_setInt32(format, "video-qp-i-max", s->qp_i_max);
388  if (s->qp_p_max >= 0)
389  ff_AMediaFormat_setInt32(format, "video-qp-p-max", s->qp_p_max);
390  if (s->qp_b_max >= 0)
391  ff_AMediaFormat_setInt32(format, "video-qp-b-max", s->qp_b_max);
392 }
393 
395 {
396  const char *codec_mime = NULL;
397  MediaCodecEncContext *s = avctx->priv_data;
399  int ret;
400  int gop;
401 
402  // Init async state first, so we can do cleanup safely on error path.
404  if (ret < 0)
405  return ret;
406 
407  if (s->use_ndk_codec < 0)
408  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
409 
410  switch (avctx->codec_id) {
411  case AV_CODEC_ID_H264:
412  codec_mime = "video/avc";
413  break;
414  case AV_CODEC_ID_HEVC:
415  codec_mime = "video/hevc";
416  break;
417  case AV_CODEC_ID_VP8:
418  codec_mime = "video/x-vnd.on2.vp8";
419  break;
420  case AV_CODEC_ID_VP9:
421  codec_mime = "video/x-vnd.on2.vp9";
422  break;
423  case AV_CODEC_ID_MPEG4:
424  codec_mime = "video/mp4v-es";
425  break;
426  case AV_CODEC_ID_AV1:
427  codec_mime = "video/av01";
428  break;
429  default:
430  av_assert0(0);
431  }
432 
433  if (s->name)
434  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
435  else
436  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
437  if (!s->codec) {
438  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
439  codec_mime);
440  return AVERROR_EXTERNAL;
441  }
442 
443  format = ff_AMediaFormat_new(s->use_ndk_codec);
444  if (!format) {
445  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
446  return AVERROR_EXTERNAL;
447  }
448 
449  ff_AMediaFormat_setString(format, "mime", codec_mime);
450  // Workaround the alignment requirement of mediacodec. We can't do it
451  // silently for AV_PIX_FMT_MEDIACODEC.
452  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
453  (avctx->codec_id == AV_CODEC_ID_H264 ||
454  avctx->codec_id == AV_CODEC_ID_HEVC)) {
455  s->width = FFALIGN(avctx->width, 16);
456  s->height = FFALIGN(avctx->height, 16);
457  } else {
458  s->width = avctx->width;
459  s->height = avctx->height;
460  if (s->width % 16 || s->height % 16)
461  av_log(avctx, AV_LOG_WARNING,
462  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
463  s->width, s->height);
464  }
465  ff_AMediaFormat_setInt32(format, "width", s->width);
466  ff_AMediaFormat_setInt32(format, "height", s->height);
467 
468  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
469  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
470  if (avctx->hw_device_ctx) {
471  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
472  AVMediaCodecDeviceContext *dev_ctx;
473 
474  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
475  ret = AVERROR(EINVAL);
476  goto bailout;
477  }
478  dev_ctx = device_ctx->hwctx;
479  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
480  }
481 
482  if (!s->window && user_ctx && user_ctx->surface)
483  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
484 
485  if (!s->window) {
486  ret = AVERROR(EINVAL);
487  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
488  goto bailout;
489  }
490  /* Although there is a method ANativeWindow_toSurface() introduced in
491  * API level 26, it's easier and safe to always require a Surface for
492  * Java MediaCodec.
493  */
494  if (!s->use_ndk_codec && !s->window->surface) {
495  ret = AVERROR(EINVAL);
496  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
497  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
498  goto bailout;
499  }
500  }
501 
502  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
503  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
504  ff_AMediaFormat_setInt32(format, "color-format",
506  break;
507  }
508  }
509 
512  ff_AMediaFormat_setInt32(format, "color-range", ret);
515  ff_AMediaFormat_setInt32(format, "color-standard", ret);
518  ff_AMediaFormat_setInt32(format, "color-transfer", ret);
519 
520  if (avctx->bit_rate)
521  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
522  if (s->bitrate_mode >= 0) {
523  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
524  if (s->bitrate_mode == BITRATE_MODE_CQ && avctx->global_quality > 0)
525  ff_AMediaFormat_setInt32(format, "quality", avctx->global_quality);
526  }
528 
529  // frame-rate and i-frame-interval are required to configure codec
530  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
531  s->fps = avctx->framerate.num / avctx->framerate.den;
532  } else {
533  s->fps = 30;
534  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
535  }
536  gop = round(avctx->gop_size / s->fps);
537  if (gop == 0) {
538  gop = 1;
539  av_log(avctx, AV_LOG_INFO,
540  "Use %d as the default MediaFormat i-frame-interval, "
541  "please set gop_size properly (>= fps)\n", gop);
542  } else {
543  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
544  }
545 
546  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
547  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
548 
550  if (ret > 0) {
551  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
552  ff_AMediaFormat_setInt32(format, "profile", ret);
553  }
554  if (s->level > 0) {
555  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
556  ff_AMediaFormat_setInt32(format, "level", s->level);
557  }
558  if (avctx->max_b_frames > 0) {
560  av_log(avctx, AV_LOG_ERROR,
561  "Enabling B frames will produce packets with no DTS. "
562  "Use -strict experimental to use it anyway.\n");
563  ret = AVERROR(EINVAL);
564  goto bailout;
565  }
566  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
567  }
568  if (s->pts_as_dts == -1)
569  s->pts_as_dts = avctx->max_b_frames <= 0;
570  if (s->operating_rate > 0)
571  ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate);
572 
574  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
575  if (ret) {
576  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
577  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
578  av_log(avctx, AV_LOG_ERROR, "Please try -pix_fmt nv12, some devices don't "
579  "support yuv420p as encoder input format.\n");
580  goto bailout;
581  }
582 
583  if (s->async_mode) {
585  .onAsyncInputAvailable = on_input_available,
586  .onAsyncOutputAvailable = on_output_available,
587  .onAsyncFormatChanged = on_format_changed,
588  .onAsyncError = on_error,
589  };
590 
591  ret = ff_AMediaCodec_setAsyncNotifyCallback(s->codec, &cb, avctx);
592  if (ret < 0) {
593  av_log(avctx, AV_LOG_WARNING,
594  "Try MediaCodec async mode failed, %s, switch to sync mode\n",
595  av_err2str(ret));
597  }
598  }
599 
600  ret = mediacodec_init_bsf(avctx);
601  if (ret)
602  goto bailout;
603 
605 
606  s->frame = av_frame_alloc();
607  if (!s->frame) {
608  ret = AVERROR(ENOMEM);
609  goto bailout;
610  }
611 
612  ret = ff_AMediaCodec_start(s->codec);
613  if (ret) {
614  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n",
615  av_err2str(ret));
616  goto bailout;
617  }
618 
620 
621 bailout:
622  if (format)
624  return ret;
625 }
626 
628  FFAMediaCodecBufferInfo *out_info)
629 {
630  MediaCodecEncContext *s = avctx->priv_data;
631  FFAMediaCodec *codec = s->codec;
632  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
633  MediaCodecAsyncOutput output = { .index = -1 };
634  int ret;
635 
636  if (!s->async_mode) {
637  *index = ff_AMediaCodec_dequeueOutputBuffer(codec, out_info, timeout_us);
638  return 0;
639  }
640 
641  ff_mutex_lock(&s->output_mutex);
642 
643  while (!s->encode_status) {
644  if (av_fifo_read(s->async_output, &output, 1) >= 0)
645  break;
646 
647  // Only wait after signalEndOfInputStream
648  if (s->eof_sent && !s->encode_status)
649  ff_cond_wait(&s->output_cond, &s->output_mutex);
650  else
651  break;
652  }
653 
654  ret = s->encode_status;
655  ff_mutex_unlock(&s->output_mutex);
656 
657  // Get output index success
658  if (output.index >= 0) {
659  *index = output.index;
660  *out_info = output.buf_info;
661  return 0;
662  }
663 
664  return ret ? ret : AVERROR(EAGAIN);
665 }
666 
668 {
669  MediaCodecEncContext *s = avctx->priv_data;
670  FFAMediaCodec *codec = s->codec;
671  ssize_t index;
672  FFAMediaCodecBufferInfo out_info = {0};
673  uint8_t *out_buf;
674  size_t out_size = 0;
675  int ret;
676  int extradata_size = 0;
677 
678  ret = mediacodec_get_output_index(avctx, &index, &out_info);
679  if (ret < 0)
680  return ret;
681 
683  return AVERROR(EAGAIN);
684 
687  return AVERROR(EAGAIN);
688  }
689 
692  return AVERROR(EAGAIN);
693  }
694 
695  if (index < 0)
696  return AVERROR_EXTERNAL;
697 
698  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
699  return AVERROR_EOF;
700 
701  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
702  if (!out_buf) {
704  goto bailout;
705  }
706 
707  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
708  if (avctx->codec_id == AV_CODEC_ID_AV1) {
709  // Skip AV1CodecConfigurationRecord without configOBUs
710  if (out_info.size <= 4) {
712  return mediacodec_receive(avctx, pkt);
713  }
714  out_info.size -= 4;
715  out_info.offset += 4;
716  }
717 
718  ret = av_reallocp(&s->extradata, out_info.size);
719  if (ret)
720  goto bailout;
721 
722  s->extradata_size = out_info.size;
723  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
725  // try immediately
726  return mediacodec_receive(avctx, pkt);
727  }
728 
729  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
730  if (ret < 0)
731  goto bailout;
732 
733  if (s->extradata_size) {
734  extradata_size = s->extradata_size;
735  s->extradata_size = 0;
736  memcpy(pkt->data, s->extradata, extradata_size);
737  }
738  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
740  if (s->pts_as_dts)
741  pkt->dts = pkt->pts;
742  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
744  ret = 0;
745 
746  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
747  " flags %d extradata %d\n",
748  pkt->pts, pkt->dts, pkt->flags, extradata_size);
749 
750 bailout:
752  return ret;
753 }
754 
755 static int mediacodec_get_input_index(AVCodecContext *avctx, ssize_t *index)
756 {
757  MediaCodecEncContext *s = avctx->priv_data;
758  FFAMediaCodec *codec = s->codec;
759  int ret = 0;
760  int32_t n;
761 
762  if (!s->async_mode) {
764  return 0;
765  }
766 
767  ff_mutex_lock(&s->input_mutex);
768 
769  n = -1;
770  while (n < 0 && !s->encode_status) {
771  if (av_fifo_can_read(s->input_index) > 0) {
772  av_fifo_read(s->input_index, &n, 1);
773  break;
774  }
775 
776  if (n < 0 && !s->encode_status)
777  ff_cond_wait(&s->input_cond, &s->input_mutex);
778  }
779 
780  ret = s->encode_status;
781  *index = n;
782  ff_mutex_unlock(&s->input_mutex);
783 
784  return ret;
785 }
786 
787 
788 static int mediacodec_send(AVCodecContext *avctx,
789  const AVFrame *frame) {
790  MediaCodecEncContext *s = avctx->priv_data;
791  FFAMediaCodec *codec = s->codec;
792  ssize_t index;
793  uint8_t *input_buf = NULL;
794  size_t input_size = 0;
795  int64_t pts = 0;
796  uint32_t flags = 0;
797  int ret;
798 
799  if (s->eof_sent)
800  return 0;
801 
802  if (s->window) {
803  if (!frame) {
804  s->eof_sent = 1;
806  }
807 
808  if (frame->data[3])
809  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
810  return 0;
811  }
812 
814  if (ret < 0)
815  return ret;
816 
818  return AVERROR(EAGAIN);
819 
820  if (index < 0) {
821  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
822  return AVERROR_EXTERNAL;
823  }
824 
825  if (frame) {
826  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
827  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
828 
829  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
830  } else {
832  s->eof_sent = 1;
833  }
834 
835  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
836  return 0;
837 }
838 
840 {
841  MediaCodecEncContext *s = avctx->priv_data;
842  int ret;
843 
844  // Return on three case:
845  // 1. Serious error
846  // 2. Got a packet success
847  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
848  while (1) {
849  if (s->bsf) {
850  ret = av_bsf_receive_packet(s->bsf, pkt);
851  if (!ret)
852  return 0;
853  if (ret != AVERROR(EAGAIN))
854  return ret;
855  }
856 
857  ret = mediacodec_receive(avctx, pkt);
858  if (s->bsf) {
859  if (!ret || ret == AVERROR_EOF)
860  ret = av_bsf_send_packet(s->bsf, pkt);
861  } else {
862  if (!ret)
863  return 0;
864  }
865 
866  if (ret < 0 && ret != AVERROR(EAGAIN))
867  return ret;
868 
869  if (!s->frame->buf[0]) {
870  ret = ff_encode_get_frame(avctx, s->frame);
871  if (ret && ret != AVERROR_EOF)
872  return ret;
873  }
874 
875  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
876  if (!ret)
877  av_frame_unref(s->frame);
878  else if (ret != AVERROR(EAGAIN))
879  return ret;
880  }
881 
882  return 0;
883 }
884 
886 {
887  MediaCodecEncContext *s = avctx->priv_data;
888  int ret;
889 
890  s->frame->width = avctx->width;
891  s->frame->height = avctx->height;
892  s->frame->format = avctx->pix_fmt;
893  s->frame->pts = 0;
894 
895  ret = av_frame_get_buffer(s->frame, 0);
896  if (ret < 0)
897  return ret;
898 
899  do {
900  ret = mediacodec_send(avctx, s->frame);
901  } while (ret == AVERROR(EAGAIN));
902  av_frame_unref(s->frame);
903 
904  if (ret < 0)
905  return ret;
906 
907  ret = mediacodec_send(avctx, NULL);
908  if (ret < 0) {
909  av_log(avctx, AV_LOG_ERROR, "Flush failed: %s\n", av_err2str(ret));
910  return ret;
911  }
912 
913  return 0;
914 }
915 
917 {
918  MediaCodecEncContext *s = avctx->priv_data;
919  int ret;
920 
921  do {
922  ret = mediacodec_receive(avctx, pkt);
923  } while (ret == AVERROR(EAGAIN));
924 
925  if (ret < 0)
926  return ret;
927 
928  do {
929  ret = av_bsf_send_packet(s->bsf, pkt);
930  if (ret < 0)
931  return ret;
932  ret = av_bsf_receive_packet(s->bsf, pkt);
933  } while (ret == AVERROR(EAGAIN));
934 
935  return ret;
936 }
937 
939 {
940  MediaCodecEncContext *s = avctx->priv_data;
941  AVPacket *pkt = NULL;
942  int ret;
943  size_t side_size;
944  uint8_t *side;
945 
946  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
947  return 0;
948 
949  // Send dummy frame and receive a packet doesn't work in async mode
950  if (s->async_mode || !s->extract_extradata) {
951  av_log(avctx, AV_LOG_WARNING,
952  "Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. "
953  "Use extract_extradata bsf when necessary.\n");
954  return 0;
955  }
956 
957  pkt = av_packet_alloc();
958  if (!pkt)
959  return AVERROR(ENOMEM);
960 
962  if (ret < 0)
963  goto bailout;
965  if (ret < 0)
966  goto bailout;
967 
969  if (side && side_size > 0) {
970  avctx->extradata = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
971  if (!avctx->extradata) {
972  ret = AVERROR(ENOMEM);
973  goto bailout;
974  }
975 
976  memcpy(avctx->extradata, side, side_size);
977  avctx->extradata_size = side_size;
978  }
979 
980 bailout:
981  if (s->eof_sent) {
982  s->eof_sent = 0;
983  ff_AMediaCodec_flush(s->codec);
984  }
985  av_bsf_flush(s->bsf);
987  return ret;
988 }
989 
991 {
992  MediaCodecEncContext *s = avctx->priv_data;
993  if (s->codec) {
994  ff_AMediaCodec_stop(s->codec);
995  ff_AMediaCodec_delete(s->codec);
996  s->codec = NULL;
997  }
998 
999  if (s->window) {
1000  ff_mediacodec_surface_unref(s->window, avctx);
1001  s->window = NULL;
1002  }
1003 
1004  av_bsf_free(&s->bsf);
1005  av_frame_free(&s->frame);
1006 
1008 
1009  return 0;
1010 }
1011 
1013 {
1014  MediaCodecEncContext *s = avctx->priv_data;
1015  if (s->bsf)
1016  av_bsf_flush(s->bsf);
1017  av_frame_unref(s->frame);
1018  ff_AMediaCodec_flush(s->codec);
1019 }
1020 
1022  &(const AVCodecHWConfigInternal) {
1023  .public = {
1027  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
1028  },
1029  .hwaccel = NULL,
1030  },
1031  NULL
1032 };
1033 
1035  {"qmin", "-1"},
1036  {"qmax", "-1"},
1037  {NULL},
1038 };
1039 
1040 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
1041 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1042 #define COMMON_OPTION \
1043  { "ndk_codec", "Use MediaCodec from NDK", \
1044  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
1045  { "ndk_async", "Try NDK MediaCodec in async mode", \
1046  OFFSET(async_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE }, \
1047  { "codec_name", "Select codec by name", \
1048  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
1049  { "bitrate_mode", "Bitrate control method", \
1050  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode" }, \
1051  { "cq", "Constant quality mode", \
1052  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, .unit = "bitrate_mode" }, \
1053  { "vbr", "Variable bitrate mode", \
1054  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
1055  { "cbr", "Constant bitrate mode", \
1056  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
1057  { "cbr_fd", "Constant bitrate mode with frame drops", \
1058  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, .unit = "bitrate_mode" }, \
1059  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
1060  "since most of Android devices don't output B frames by default.", \
1061  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
1062  { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified", \
1063  OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE }, \
1064  { "qp_i_min", "minimum quantization parameter for I frame", \
1065  OFFSET(qp_i_min), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1066  { "qp_p_min", "minimum quantization parameter for P frame", \
1067  OFFSET(qp_p_min), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1068  { "qp_b_min", "minimum quantization parameter for B frame", \
1069  OFFSET(qp_b_min), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1070  { "qp_i_max", "maximum quantization parameter for I frame", \
1071  OFFSET(qp_i_max), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1072  { "qp_p_max", "maximum quantization parameter for P frame", \
1073  OFFSET(qp_p_max), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1074  { "qp_b_max", "maximum quantization parameter for B frame", \
1075  OFFSET(qp_b_max), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE }, \
1076 
1077 
1078 #define MEDIACODEC_ENCODER_CLASS(name) \
1079 static const AVClass name ## _mediacodec_class = { \
1080  .class_name = #name "_mediacodec", \
1081  .item_name = av_default_item_name, \
1082  .option = name ## _options, \
1083  .version = LIBAVUTIL_VERSION_INT, \
1084 }; \
1085 
1086 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
1087 MEDIACODEC_ENCODER_CLASS(short_name) \
1088 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
1089  .p.name = #short_name "_mediacodec", \
1090  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
1091  .p.type = AVMEDIA_TYPE_VIDEO, \
1092  .p.id = codec_id, \
1093  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
1094  AV_CODEC_CAP_HARDWARE | \
1095  AV_CODEC_CAP_ENCODER_FLUSH, \
1096  .priv_data_size = sizeof(MediaCodecEncContext), \
1097  .p.pix_fmts = avc_pix_fmts, \
1098  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
1099  .defaults = mediacodec_defaults, \
1100  .init = mediacodec_init, \
1101  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
1102  .close = mediacodec_close, \
1103  .flush = mediacodec_flush, \
1104  .p.priv_class = &short_name ## _mediacodec_class, \
1105  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
1106  .p.wrapper_name = "mediacodec", \
1107  .hw_configs = mediacodec_hw_configs, \
1108 }; \
1109 
1110 #if CONFIG_H264_MEDIACODEC_ENCODER
1111 
1112 enum MediaCodecAvcLevel {
1113  AVCLevel1 = 0x01,
1114  AVCLevel1b = 0x02,
1115  AVCLevel11 = 0x04,
1116  AVCLevel12 = 0x08,
1117  AVCLevel13 = 0x10,
1118  AVCLevel2 = 0x20,
1119  AVCLevel21 = 0x40,
1120  AVCLevel22 = 0x80,
1121  AVCLevel3 = 0x100,
1122  AVCLevel31 = 0x200,
1123  AVCLevel32 = 0x400,
1124  AVCLevel4 = 0x800,
1125  AVCLevel41 = 0x1000,
1126  AVCLevel42 = 0x2000,
1127  AVCLevel5 = 0x4000,
1128  AVCLevel51 = 0x8000,
1129  AVCLevel52 = 0x10000,
1130  AVCLevel6 = 0x20000,
1131  AVCLevel61 = 0x40000,
1132  AVCLevel62 = 0x80000,
1133 };
1134 
1135 static const AVOption h264_options[] = {
1137 
1139  FF_AVCTX_PROFILE_OPTION("constrained_baseline", NULL, VIDEO, AV_PROFILE_H264_CONSTRAINED_BASELINE)
1146 
1147  { "level", "Specify level",
1148  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1149  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, .unit = "level" },
1150  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, .unit = "level" },
1151  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, .unit = "level" },
1152  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, .unit = "level" },
1153  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, .unit = "level" },
1154  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, .unit = "level" },
1155  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, .unit = "level" },
1156  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, .unit = "level" },
1157  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, .unit = "level" },
1158  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, .unit = "level" },
1159  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, .unit = "level" },
1160  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, .unit = "level" },
1161  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, .unit = "level" },
1162  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, .unit = "level" },
1163  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, .unit = "level" },
1164  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, .unit = "level" },
1165  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, .unit = "level" },
1166  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, .unit = "level" },
1167  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, .unit = "level" },
1168  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, .unit = "level" },
1169  { NULL, }
1170 };
1171 
1173 
1174 #endif // CONFIG_H264_MEDIACODEC_ENCODER
1175 
1176 #if CONFIG_HEVC_MEDIACODEC_ENCODER
1177 
1178 enum MediaCodecHevcLevel {
1179  HEVCMainTierLevel1 = 0x1,
1180  HEVCHighTierLevel1 = 0x2,
1181  HEVCMainTierLevel2 = 0x4,
1182  HEVCHighTierLevel2 = 0x8,
1183  HEVCMainTierLevel21 = 0x10,
1184  HEVCHighTierLevel21 = 0x20,
1185  HEVCMainTierLevel3 = 0x40,
1186  HEVCHighTierLevel3 = 0x80,
1187  HEVCMainTierLevel31 = 0x100,
1188  HEVCHighTierLevel31 = 0x200,
1189  HEVCMainTierLevel4 = 0x400,
1190  HEVCHighTierLevel4 = 0x800,
1191  HEVCMainTierLevel41 = 0x1000,
1192  HEVCHighTierLevel41 = 0x2000,
1193  HEVCMainTierLevel5 = 0x4000,
1194  HEVCHighTierLevel5 = 0x8000,
1195  HEVCMainTierLevel51 = 0x10000,
1196  HEVCHighTierLevel51 = 0x20000,
1197  HEVCMainTierLevel52 = 0x40000,
1198  HEVCHighTierLevel52 = 0x80000,
1199  HEVCMainTierLevel6 = 0x100000,
1200  HEVCHighTierLevel6 = 0x200000,
1201  HEVCMainTierLevel61 = 0x400000,
1202  HEVCHighTierLevel61 = 0x800000,
1203  HEVCMainTierLevel62 = 0x1000000,
1204  HEVCHighTierLevel62 = 0x2000000,
1205 };
1206 
1207 static const AVOption hevc_options[] = {
1209 
1212 
1213  { "level", "Specify tier and level",
1214  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1215  { "m1", "Main tier level 1",
1216  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, .unit = "level" },
1217  { "h1", "High tier level 1",
1218  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, .unit = "level" },
1219  { "m2", "Main tier level 2",
1220  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, .unit = "level" },
1221  { "h2", "High tier level 2",
1222  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, .unit = "level" },
1223  { "m2.1", "Main tier level 2.1",
1224  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, .unit = "level" },
1225  { "h2.1", "High tier level 2.1",
1226  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, .unit = "level" },
1227  { "m3", "Main tier level 3",
1228  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, .unit = "level" },
1229  { "h3", "High tier level 3",
1230  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, .unit = "level" },
1231  { "m3.1", "Main tier level 3.1",
1232  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, .unit = "level" },
1233  { "h3.1", "High tier level 3.1",
1234  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, .unit = "level" },
1235  { "m4", "Main tier level 4",
1236  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, .unit = "level" },
1237  { "h4", "High tier level 4",
1238  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, .unit = "level" },
1239  { "m4.1", "Main tier level 4.1",
1240  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, .unit = "level" },
1241  { "h4.1", "High tier level 4.1",
1242  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, .unit = "level" },
1243  { "m5", "Main tier level 5",
1244  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, .unit = "level" },
1245  { "h5", "High tier level 5",
1246  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, .unit = "level" },
1247  { "m5.1", "Main tier level 5.1",
1248  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, .unit = "level" },
1249  { "h5.1", "High tier level 5.1",
1250  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, .unit = "level" },
1251  { "m5.2", "Main tier level 5.2",
1252  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, .unit = "level" },
1253  { "h5.2", "High tier level 5.2",
1254  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, .unit = "level" },
1255  { "m6", "Main tier level 6",
1256  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, .unit = "level" },
1257  { "h6", "High tier level 6",
1258  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, .unit = "level" },
1259  { "m6.1", "Main tier level 6.1",
1260  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, .unit = "level" },
1261  { "h6.1", "High tier level 6.1",
1262  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, .unit = "level" },
1263  { "m6.2", "Main tier level 6.2",
1264  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, .unit = "level" },
1265  { "h6.2", "High tier level 6.2",
1266  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, .unit = "level" },
1267  { NULL, }
1268 };
1269 
1271 
1272 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
1273 
1274 #if CONFIG_VP8_MEDIACODEC_ENCODER
1275 
1276 enum MediaCodecVP8Level {
1277  VP8Level_Version0 = 0x01,
1278  VP8Level_Version1 = 0x02,
1279  VP8Level_Version2 = 0x04,
1280  VP8Level_Version3 = 0x08,
1281 };
1282 
1283 static const AVOption vp8_options[] = {
1285  { "level", "Specify tier and level",
1286  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1287  { "V0", "Level Version 0",
1288  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version0 }, 0, 0, VE, .unit = "level" },
1289  { "V1", "Level Version 1",
1290  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version1 }, 0, 0, VE, .unit = "level" },
1291  { "V2", "Level Version 2",
1292  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version2 }, 0, 0, VE, .unit = "level" },
1293  { "V3", "Level Version 3",
1294  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version3 }, 0, 0, VE, .unit = "level" },
1295  { NULL, }
1296 };
1297 
1299 
1300 #endif // CONFIG_VP8_MEDIACODEC_ENCODER
1301 
1302 #if CONFIG_VP9_MEDIACODEC_ENCODER
1303 
1304 enum MediaCodecVP9Level {
1305  VP9Level1 = 0x1,
1306  VP9Level11 = 0x2,
1307  VP9Level2 = 0x4,
1308  VP9Level21 = 0x8,
1309  VP9Level3 = 0x10,
1310  VP9Level31 = 0x20,
1311  VP9Level4 = 0x40,
1312  VP9Level41 = 0x80,
1313  VP9Level5 = 0x100,
1314  VP9Level51 = 0x200,
1315  VP9Level52 = 0x400,
1316  VP9Level6 = 0x800,
1317  VP9Level61 = 0x1000,
1318  VP9Level62 = 0x2000,
1319 };
1320 
1321 static const AVOption vp9_options[] = {
1323 
1324  FF_AVCTX_PROFILE_OPTION("profile0", NULL, VIDEO, AV_PROFILE_VP9_0)
1325  FF_AVCTX_PROFILE_OPTION("profile1", NULL, VIDEO, AV_PROFILE_VP9_1)
1326  FF_AVCTX_PROFILE_OPTION("profile2", NULL, VIDEO, AV_PROFILE_VP9_2)
1327  FF_AVCTX_PROFILE_OPTION("profile3", NULL, VIDEO, AV_PROFILE_VP9_3)
1328 
1329  { "level", "Specify tier and level",
1330  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1331  { "1", "Level 1",
1332  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, .unit = "level" },
1333  { "1.1", "Level 1.1",
1334  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, .unit = "level" },
1335  { "2", "Level 2",
1336  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, .unit = "level" },
1337  { "2.1", "Level 2.1",
1338  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, .unit = "level" },
1339  { "3", "Level 3",
1340  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, .unit = "level" },
1341  { "3.1", "Level 3.1",
1342  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, .unit = "level" },
1343  { "4", "Level 4",
1344  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, .unit = "level" },
1345  { "4.1", "Level 4.1",
1346  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, .unit = "level" },
1347  { "5", "Level 5",
1348  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, .unit = "level" },
1349  { "5.1", "Level 5.1",
1350  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, .unit = "level" },
1351  { "5.2", "Level 5.2",
1352  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, .unit = "level" },
1353  { "6", "Level 6",
1354  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, .unit = "level" },
1355  { "6.1", "Level 4.1",
1356  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, .unit = "level" },
1357  { "6.2", "Level 6.2",
1358  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, .unit = "level" },
1359  { NULL, }
1360 };
1361 
1363 
1364 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
1365 
1366 #if CONFIG_MPEG4_MEDIACODEC_ENCODER
1367 
1368 enum MediaCodecMpeg4Level {
1369  MPEG4Level0 = 0x01,
1370  MPEG4Level0b = 0x02,
1371  MPEG4Level1 = 0x04,
1372  MPEG4Level2 = 0x08,
1373  MPEG4Level3 = 0x10,
1374  MPEG4Level3b = 0x18,
1375  MPEG4Level4 = 0x20,
1376  MPEG4Level4a = 0x40,
1377  MPEG4Level5 = 0x80,
1378  MPEG4Level6 = 0x100,
1379 };
1380 
1381 static const AVOption mpeg4_options[] = {
1383 
1385 
1386  { "level", "Specify tier and level",
1387  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1388  { "0", "Level 0",
1389  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, .unit = "level" },
1390  { "0b", "Level 0b",
1391  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, .unit = "level" },
1392  { "1", "Level 1",
1393  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, .unit = "level" },
1394  { "2", "Level 2",
1395  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, .unit = "level" },
1396  { "3", "Level 3",
1397  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, .unit = "level" },
1398  { "3b", "Level 3b",
1399  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, .unit = "level" },
1400  { "4", "Level 4",
1401  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, .unit = "level" },
1402  { "4a", "Level 4a",
1403  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, .unit = "level" },
1404  { "5", "Level 5",
1405  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, .unit = "level" },
1406  { "6", "Level 6",
1407  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, .unit = "level" },
1408  { NULL, }
1409 };
1410 
1412 
1413 #endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
1414 
1415 #if CONFIG_AV1_MEDIACODEC_ENCODER
1416 
1417 enum MediaCodecAV1Level {
1418  AV1Level2 = 0x1,
1419  AV1Level21 = 0x2,
1420  AV1Level22 = 0x4,
1421  AV1Level23 = 0x8,
1422  AV1Level3 = 0x10,
1423  AV1Level31 = 0x20,
1424  AV1Level32 = 0x40,
1425  AV1Level33 = 0x80,
1426  AV1Level4 = 0x100,
1427  AV1Level41 = 0x200,
1428  AV1Level42 = 0x400,
1429  AV1Level43 = 0x800,
1430  AV1Level5 = 0x1000,
1431  AV1Level51 = 0x2000,
1432  AV1Level52 = 0x4000,
1433  AV1Level53 = 0x8000,
1434  AV1Level6 = 0x10000,
1435  AV1Level61 = 0x20000,
1436  AV1Level62 = 0x40000,
1437  AV1Level63 = 0x80000,
1438  AV1Level7 = 0x100000,
1439  AV1Level71 = 0x200000,
1440  AV1Level72 = 0x400000,
1441  AV1Level73 = 0x800000,
1442 };
1443 
1444 static const AVOption av1_options[] = {
1446 
1448 
1449  { "level", "Specify tier and level",
1450  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1451  { "2", "Level 2",
1452  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, .unit = "level" },
1453  { "2.1", "Level 2.1",
1454  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, .unit = "level" },
1455  { "2.2", "Level 2.2",
1456  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, .unit = "level" },
1457  { "2.3", "Level 2.3",
1458  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, .unit = "level" },
1459  { "3", "Level 3",
1460  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, .unit = "level" },
1461  { "3.1", "Level 3.1",
1462  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, .unit = "level" },
1463  { "3.2", "Level 3.2",
1464  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, .unit = "level" },
1465  { "3.3", "Level 3.3",
1466  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, .unit = "level" },
1467  { "4", "Level 4",
1468  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, .unit = "level" },
1469  { "4.1", "Level 4.1",
1470  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, .unit = "level" },
1471  { "4.2", "Level 4.2",
1472  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, .unit = "level" },
1473  { "4.3", "Level 4.3",
1474  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, .unit = "level" },
1475  { "5", "Level 5",
1476  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, .unit = "level" },
1477  { "5.1", "Level 5.1",
1478  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, .unit = "level" },
1479  { "5.2", "Level 5.2",
1480  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, .unit = "level" },
1481  { "5.3", "Level 5.3",
1482  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, .unit = "level" },
1483  { "6", "Level 6",
1484  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, .unit = "level" },
1485  { "6.1", "Level 6.1",
1486  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, .unit = "level" },
1487  { "6.2", "Level 6.2",
1488  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, .unit = "level" },
1489  { "6.3", "Level 6.3",
1490  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, .unit = "level" },
1491  { "7", "Level 7",
1492  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, .unit = "level" },
1493  { "7.1", "Level 7.1",
1494  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, .unit = "level" },
1495  { "7.2", "Level 7.2",
1496  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, .unit = "level" },
1497  { "7.3", "Level 7.3",
1498  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, .unit = "level" },
1499  { NULL, }
1500 };
1501 
1503 
1504 #endif // CONFIG_AV1_MEDIACODEC_ENCODER
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
MediaCodecEncContext
Definition: mediacodecenc.c:64
MediaCodecEncContext::output_cond
AVCond output_cond
Definition: mediacodecenc.c:95
ff_AMediaCodec_getInputBuffer
static uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:282
hwconfig.h
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:85
AVCodecContext::hwaccel_context
void * hwaccel_context
Legacy hardware accelerator context.
Definition: avcodec.h:1469
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:92
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:277
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
level
uint8_t level
Definition: svq3.c:205
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:109
mediacodec_init_async_state
static int mediacodec_init_async_state(AVCodecContext *avctx)
Definition: mediacodecenc.c:316
ff_mutex_init
static int ff_mutex_init(AVMutex *mutex, const void *attr)
Definition: thread.h:187
MediaCodecEncContext::pts_as_dts
int pts_as_dts
Definition: mediacodecenc.c:84
MediaCodecAsyncOutput::index
int32_t index
Definition: mediacodecenc.c:60
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:110
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
opt.h
on_input_available
static void on_input_available(FFAMediaCodec *codec, void *userdata, int32_t index)
Definition: mediacodecenc.c:271
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:699
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:305
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:1086
ff_AMediaCodec_start
static int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:262
FFAMediaCodecBufferInfo::offset
int32_t offset
Definition: mediacodec_wrapper.h:173
MediaCodecEncContext::input_mutex
AVMutex input_mutex
Definition: mediacodecenc.c:90
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:247
MediaCodecEncContext::avclass
AVClass * avclass
Definition: mediacodecenc.c:65
thread.h
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
MediaCodecEncContext::extract_extradata
int extract_extradata
Definition: mediacodecenc.c:85
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:112
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
color_format
int color_format
Definition: mediacodecenc.c:114
int64_t
long long int64_t
Definition: coverity.c:34
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
BITRATE_MODE_VBR
@ BITRATE_MODE_VBR
Definition: mediacodecenc.c:52
AV_PROFILE_VP9_1
#define AV_PROFILE_VP9_1
Definition: defs.h:155
AVMediaCodecDeviceContext::surface
void * surface
android/view/Surface handle, to be filled by the user.
Definition: hwcontext_mediacodec.h:33
FF_AV1_PROFILE_OPTS
#define FF_AV1_PROFILE_OPTS
Definition: profiles.h:56
mediacodec_get_input_index
static int mediacodec_get_input_index(AVCodecContext *avctx, ssize_t *index)
Definition: mediacodecenc.c:755
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:71
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:159
out_size
int out_size
Definition: movenc.c:56
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:403
MediaCodecEncContext::qp_p_min
int qp_p_min
Definition: mediacodecenc.c:100
ff_AMediaCodec_signalEndOfInputStream
static int ff_AMediaCodec_signalEndOfInputStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:362
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:692
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:69
AVPacket::data
uint8_t * data
Definition: packet.h:539
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:150
BitrateMode
BitrateMode
Definition: mediacodecenc.c:48
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:332
AVOption
AVOption.
Definition: opt.h:429
encode.h
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:327
AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_MEDIACODEC
Definition: hwcontext.h:38
ff_AMediaCodec_queueInputBuffer
static int ff_AMediaCodec_queueInputBuffer(FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
Definition: mediacodec_wrapper.h:297
extract_extradata_support
static int extract_extradata_support(AVCodecContext *avctx)
Definition: mediacodecenc.c:152
MediaCodecEncContext::eof_sent
int eof_sent
Definition: mediacodecenc.c:77
COMMON_OPTION
#define COMMON_OPTION
Definition: mediacodecenc.c:1042
MediaCodecEncContext::qp_i_min
int qp_i_min
Definition: mediacodecenc.c:99
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:839
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
AVCodecContext::qmax
int qmax
maximum quantizer
Definition: avcodec.h:1281
hwcontext_mediacodec.h
mediacodec_defaults
static const FFCodecDefault mediacodec_defaults[]
Definition: mediacodecenc.c:1034
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:75
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
mediacodec_send_dummy_frame
static int mediacodec_send_dummy_frame(AVCodecContext *avctx)
Definition: mediacodecenc.c:885
VE
#define VE
Definition: mediacodecenc.c:1041
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:338
mediacodec_output_format
static void mediacodec_output_format(AVCodecContext *avctx)
Definition: mediacodecenc.c:141
ff_AMediaCodec_configure
static int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:254
ff_mutex_unlock
static int ff_mutex_unlock(AVMutex *mutex)
Definition: thread.h:189
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:108
AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_H264_EXTENDED
Definition: defs.h:113
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:574
fifo.h
FFCodecDefault
Definition: codec_internal.h:97
bsf.h
mediacodec_flush
static av_cold void mediacodec_flush(AVCodecContext *avctx)
Definition: mediacodecenc.c:1012
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1569
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:990
av_fifo_write
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
Definition: fifo.c:188
MediaCodecEncContext::extradata
uint8_t * extradata
Definition: mediacodecenc.c:75
MediaCodecEncContext::async_mode
int async_mode
Definition: mediacodecenc.c:88
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecenc.c:115
COLOR_RANGE_UNSPECIFIED
@ COLOR_RANGE_UNSPECIFIED
Definition: mediacodec_wrapper.h:377
AVERROR_BUFFER_TOO_SMALL
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:53
mediacodec_set_qp_range
static void mediacodec_set_qp_range(AVCodecContext *avctx, FFAMediaFormat *format)
Definition: mediacodecenc.c:361
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_PROFILE_VP9_3
#define AV_PROFILE_VP9_3
Definition: defs.h:157
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2531
AVRational::num
int num
Numerator.
Definition: rational.h:59
mediacodecdec_common.h
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:342
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:151
on_output_available
static void on_output_available(FFAMediaCodec *codec, void *userdata, int32_t index, FFAMediaCodecBufferInfo *out_info)
Definition: mediacodecenc.c:288
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:788
mediacodec_uninit_async_state
static void mediacodec_uninit_async_state(AVCodecContext *avctx)
Definition: mediacodecenc.c:340
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
av_fifo_read
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
Definition: fifo.c:240
MediaCodecEncContext::bitrate_mode
int bitrate_mode
Definition: mediacodecenc.c:82
AVMutex
#define AVMutex
Definition: thread.h:184
ff_AMediaCodec_getName
static char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:245
MediaCodecEncContext::qp_b_min
int qp_b_min
Definition: mediacodecenc.c:101
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:342
color_formats
static const struct @179 color_formats[]
s
#define s(width, name)
Definition: cbs_vp9.c:198
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2970
BITRATE_MODE_CQ
@ BITRATE_MODE_CQ
Definition: mediacodecenc.c:50
AVCodecContext::global_quality
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1257
av_bsf_flush
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition: bsf.c:190
MediaCodecEncContext::qp_p_max
int qp_p_max
Definition: mediacodecenc.c:103
on_error
static void on_error(FFAMediaCodec *codec, void *userdata, int error, const char *detail)
Definition: mediacodecenc.c:250
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_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
on_format_changed
static void on_format_changed(FFAMediaCodec *codec, void *userdata, FFAMediaFormat *format)
Definition: mediacodecenc.c:310
AV_PROFILE_H264_HIGH_10
#define AV_PROFILE_H264_HIGH_10
Definition: defs.h:115
FF_AVCTX_PROFILE_OPTION
#define FF_AVCTX_PROFILE_OPTION(name, description, type, value)
Definition: profiles.h:26
ff_cond_wait
static int ff_cond_wait(AVCond *cond, AVMutex *mutex)
Definition: thread.h:198
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
MediaCodecAsyncOutput
Definition: mediacodecenc.c:59
mediacodec_dump_format
static void mediacodec_dump_format(AVCodecContext *avctx, FFAMediaFormat *out_format)
Definition: mediacodecenc.c:129
OFFSET
#define OFFSET(x)
Definition: mediacodecenc.c:1040
AVCond
#define AVCond
Definition: thread.h:192
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:354
FFAMediaCodecOnAsyncNotifyCallback
Definition: mediacodec_wrapper.h:182
AVBitStreamFilter::codec_ids
enum AVCodecID * codec_ids
A list of codec ids supported by the filter, terminated by AV_CODEC_ID_NONE.
Definition: bsf.h:119
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AV_PROFILE_H264_HIGH_422
#define AV_PROFILE_H264_HIGH_422
Definition: defs.h:118
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
MediaCodecEncContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecenc.c:67
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:316
mediacodec_generate_extradata
static int mediacodec_generate_extradata(AVCodecContext *avctx)
Definition: mediacodecenc.c:938
ff_AMediaFormatColorStandard_from_AVColorSpace
int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space)
Map AVColorSpace to MediaFormat color standard.
Definition: mediacodec_wrapper.c:2656
OUTPUT_DEQUEUE_TIMEOUT_US
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:46
ff_AMediaCodec_getOutputFormat
static FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:307
MediaCodecEncContext::encode_status
int encode_status
Definition: mediacodecenc.c:96
MediaCodecEncContext::level
int level
Definition: mediacodecenc.c:83
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:149
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2538
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2639
NULL
#define NULL
Definition: coverity.c:32
ff_AMediaCodec_flush
static int ff_AMediaCodec_flush(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:272
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:709
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
MediaCodecEncContext::input_index
AVFifo * input_index
Definition: mediacodecenc.c:92
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
FFAMediaCodecBufferInfo::size
int32_t size
Definition: mediacodec_wrapper.h:174
AVMediaCodecContext
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
Definition: mediacodec.h:33
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:501
ff_AMediaCodec_setAsyncNotifyCallback
static int ff_AMediaCodec_setAsyncNotifyCallback(FFAMediaCodec *codec, const FFAMediaCodecOnAsyncNotifyCallback *callback, void *userdata)
Definition: mediacodec_wrapper.h:367
profiles.h
av_fifo_can_read
size_t av_fifo_can_read(const AVFifo *f)
Definition: fifo.c:87
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2552
ff_AMediaCodec_stop
static int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:267
ff_mediacodec_surface_unref
int ff_mediacodec_surface_unref(FFANativeWindow *window, void *log_ctx)
Definition: mediacodec_surface.c:59
BITRATE_MODE_CBR_FD
@ BITRATE_MODE_CBR_FD
Definition: mediacodecenc.c:56
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:347
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:313
mpeg4_options
static const AVOption mpeg4_options[]
Definition: v4l2_m2m_enc.c:397
BITRATE_MODE_CBR
@ BITRATE_MODE_CBR
Definition: mediacodecenc.c:54
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
index
int index
Definition: gxfenc.c:90
AVMediaCodecDeviceContext
MediaCodec details.
Definition: hwcontext_mediacodec.h:27
ff_AMediaFormat_toString
static char * ff_AMediaFormat_toString(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:97
ff_mutex_destroy
static int ff_mutex_destroy(AVMutex *mutex)
Definition: thread.h:190
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:558
AVFifo
Definition: fifo.c:35
MediaCodecEncContext::input_cond
AVCond input_cond
Definition: mediacodecenc.c:91
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1045
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1107
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h:391
avc_pix_fmts
static enum AVPixelFormat avc_pix_fmts[]
Definition: mediacodecenc.c:122
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:188
mediacodec_receive_dummy_pkt
static int mediacodec_receive_dummy_pkt(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:916
ff_AMediaFormatColorTransfer_from_AVColorTransfer
int ff_AMediaFormatColorTransfer_from_AVColorTransfer(enum AVColorTransferCharacteristic color_transfer)
Map AVColorTransferCharacteristic to MediaFormat color transfer.
Definition: mediacodec_wrapper.c:2684
AVCodecHWConfigInternal
Definition: hwconfig.h:25
MediaCodecEncContext::bsf
AVBSFContext * bsf
Definition: mediacodecenc.c:80
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_AMediaCodecProfile_getProfileFromAVCodecContext
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
Definition: mediacodec_wrapper.c:309
ff_mutex_lock
static int ff_mutex_lock(AVMutex *mutex)
Definition: thread.h:188
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:64
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:68
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
MediaCodecEncContext::width
int width
Definition: mediacodecenc.c:72
FF_MPEG4_PROFILE_OPTS
#define FF_MPEG4_PROFILE_OPTS
Definition: profiles.h:42
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:352
MediaCodecEncContext::codec
FFAMediaCodec * codec
Definition: mediacodecenc.c:66
FFANativeWindow
Definition: mediacodec_surface.h:28
MediaCodecEncContext::operating_rate
int operating_rate
Definition: mediacodecenc.c:87
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
mediacodec_wrapper.h
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
COLOR_STANDARD_UNSPECIFIED
@ COLOR_STANDARD_UNSPECIFIED
Definition: mediacodec_wrapper.h:383
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:537
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:253
FFAMediaCodec
Definition: mediacodec_wrapper.h:197
MediaCodecEncContext::height
int height
Definition: mediacodecenc.c:73
MediaCodecEncContext::extradata_size
int extradata_size
Definition: mediacodecenc.c:76
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:623
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:176
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1515
AVMediaCodecContext::surface
void * surface
android/view/Surface object reference.
Definition: mediacodec.h:38
ff_mediacodec_surface_ref
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
Definition: mediacodec_surface.c:30
MediaCodecEncContext::frame
AVFrame * frame
Definition: mediacodecenc.c:79
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:45
AVCodecContext::height
int height
Definition: avcodec.h:632
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:671
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:75
AVMediaCodecDeviceContext::native_window
void * native_window
Pointer to ANativeWindow.
Definition: hwcontext_mediacodec.h:45
FFAMediaCodecBufferInfo::presentationTimeUs
int64_t presentationTimeUs
Definition: mediacodec_wrapper.h:175
ff_AMediaCodec_dequeueInputBuffer
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:292
avcodec.h
AV_PROFILE_VP9_2
#define AV_PROFILE_VP9_2
Definition: defs.h:156
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:72
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
MediaCodecEncContext::output_mutex
AVMutex output_mutex
Definition: mediacodecenc.c:94
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1397
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:110
MediaCodecEncContext::qp_b_max
int qp_b_max
Definition: mediacodecenc.c:104
av_mediacodec_release_buffer
int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render)
Release a MediaCodec buffer and render it to the surface that is associated with the decoder.
Definition: mediacodec.c:138
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:114
mediacodec_init
static av_cold int mediacodec_init(AVCodecContext *avctx)
Definition: mediacodecenc.c:394
AVBitStreamFilter
Definition: bsf.h:111
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:106
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
AVCodecContext::qmin
int qmin
minimum quantizer
Definition: avcodec.h:1274
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
mediacodec_get_output_index
static int mediacodec_get_output_index(AVCodecContext *avctx, ssize_t *index, FFAMediaCodecBufferInfo *out_info)
Definition: mediacodecenc.c:627
ff_cond_signal
static int ff_cond_signal(AVCond *cond)
Definition: thread.h:196
MediaCodecAsyncOutput::buf_info
FFAMediaCodecBufferInfo buf_info
Definition: mediacodecenc.c:61
AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition: defs.h:111
ff_AMediaCodec_getBufferFlagCodecConfig
static int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:337
AV_PROFILE_VP9_0
#define AV_PROFILE_VP9_0
Definition: defs.h:154
MediaCodecEncContext::qp_i_max
int qp_i_max
Definition: mediacodecenc.c:102
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:526
AV_PROFILE_H264_HIGH_444
#define AV_PROFILE_H264_HIGH_444
Definition: defs.h:121
mem.h
AVCodecContext::max_b_frames
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:809
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:205
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:287
avcodec_parameters_from_context
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:137
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ff_AMediaCodec_cleanOutputBuffers
static int ff_AMediaCodec_cleanOutputBuffers(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:357
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ff_cond_destroy
static int ff_cond_destroy(AVCond *cond)
Definition: thread.h:195
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:322
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:632
int32_t
int32_t
Definition: audioconvert.c:56
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_AMediaCodec_releaseOutputBuffer
static int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h:312
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_fifo_freep2
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
Definition: fifo.c:286
ff_cond_init
static int ff_cond_init(AVCond *cond, const void *attr)
Definition: thread.h:194
avstring.h
jni.h
mediacodec_hw_configs
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
Definition: mediacodecenc.c:1021
MediaCodecEncContext::async_output
AVFifo * async_output
Definition: mediacodecenc.c:97
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:30
FFAMediaFormat
Definition: mediacodec_wrapper.h:63
ff_AMediaCodec_dequeueOutputBuffer
static ssize_t ff_AMediaCodec_dequeueOutputBuffer(FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:302
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
copy_frame_to_buffer
static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
Definition: mediacodecenc.c:221
fifo_size
size_t fifo_size
Definition: dts2pts.c:371
AV_FIFO_FLAG_AUTO_GROW
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
Definition: fifo.h:63
mediacodec_init_bsf
static int mediacodec_init_bsf(AVCodecContext *avctx)
Definition: mediacodecenc.c:169
mediacodec_receive
static int mediacodec_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:667
mediacodec.h
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:87