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/avstring.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 
32 #include "avcodec.h"
33 #include "bsf.h"
34 #include "codec_internal.h"
35 #include "encode.h"
36 #include "hwconfig.h"
37 #include "jni.h"
38 #include "mediacodec.h"
39 #include "mediacodec_wrapper.h"
40 #include "mediacodecdec_common.h"
41 #include "profiles.h"
42 
43 #define INPUT_DEQUEUE_TIMEOUT_US 8000
44 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
45 
47  /* Constant quality mode */
49  /* Variable bitrate mode */
51  /* Constant bitrate mode */
53  /* Constant bitrate mode with frame drops */
55 };
56 
57 typedef struct MediaCodecEncContext {
61  const char *name;
63 
64  int fps;
65  int width;
66  int height;
67 
68  uint8_t *extradata;
70  int eof_sent;
71 
74 
76  int level;
80 
81 enum {
84  COLOR_FormatSurface = 0x7F000789,
85 };
86 
87 static const struct {
90 } color_formats[] = {
94 };
95 
96 static const enum AVPixelFormat avc_pix_fmts[] = {
101 };
102 
104 {
105  MediaCodecEncContext *s = avctx->priv_data;
106  char *name = ff_AMediaCodec_getName(s->codec);
107  FFAMediaFormat *out_format = ff_AMediaCodec_getOutputFormat(s->codec);
108  char *str = ff_AMediaFormat_toString(out_format);
109 
110  av_log(avctx, AV_LOG_DEBUG, "MediaCodec encoder %s output format %s\n",
111  name ? name : "unknown", str);
112  av_free(name);
113  av_free(str);
114  ff_AMediaFormat_delete(out_format);
115 }
116 
118 {
119  const AVBitStreamFilter *bsf = av_bsf_get_by_name("extract_extradata");
120 
121  if (!bsf) {
122  av_log(avctx, AV_LOG_WARNING, "extract_extradata bsf not found\n");
123  return 0;
124  }
125 
126  for (int i = 0; bsf->codec_ids[i] != AV_CODEC_ID_NONE; i++) {
127  if (bsf->codec_ids[i] == avctx->codec_id)
128  return 1;
129  }
130 
131  return 0;
132 }
133 
135 {
136  MediaCodecEncContext *s = avctx->priv_data;
137  char str[128];
138  int ret;
139  int crop_right = s->width - avctx->width;
140  int crop_bottom = s->height - avctx->height;
141 
142  /* Nothing can be done for this format now */
143  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC)
144  return 0;
145 
146  s->extract_extradata = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) &&
148  if (!crop_right && !crop_bottom && !s->extract_extradata)
149  return 0;
150 
151  ret = 0;
152  if (crop_right || crop_bottom) {
153  if (avctx->codec_id == AV_CODEC_ID_H264)
154  ret = snprintf(str, sizeof(str), "h264_metadata=crop_right=%d:crop_bottom=%d",
155  crop_right, crop_bottom);
156  else if (avctx->codec_id == AV_CODEC_ID_HEVC)
157  /* Encoder can use CTU size larger than 16x16, so the real crop
158  * margin can be larger than crop_right/crop_bottom. Let bsf figure
159  * out the real crop margin.
160  */
161  ret = snprintf(str, sizeof(str), "hevc_metadata=width=%d:height=%d",
162  avctx->width, avctx->height);
163  if (ret >= sizeof(str))
165  }
166 
167  if (s->extract_extradata) {
168  ret = av_strlcatf(str, sizeof(str), "%sextract_extradata", ret ? "," : "");
169  if (ret >= sizeof(str))
171  }
172 
173  ret = av_bsf_list_parse_str(str, &s->bsf);
174  if (ret < 0)
175  return ret;
176 
177  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
178  if (ret < 0)
179  return ret;
180  s->bsf->time_base_in = avctx->time_base;
181  ret = av_bsf_init(s->bsf);
182 
183  return ret;
184 }
185 
187 
189 {
190  const char *codec_mime = NULL;
191  MediaCodecEncContext *s = avctx->priv_data;
193  int ret;
194  int gop;
195 
196  if (s->use_ndk_codec < 0)
197  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
198 
199  switch (avctx->codec_id) {
200  case AV_CODEC_ID_H264:
201  codec_mime = "video/avc";
202  break;
203  case AV_CODEC_ID_HEVC:
204  codec_mime = "video/hevc";
205  break;
206  case AV_CODEC_ID_VP8:
207  codec_mime = "video/x-vnd.on2.vp8";
208  break;
209  case AV_CODEC_ID_VP9:
210  codec_mime = "video/x-vnd.on2.vp9";
211  break;
212  case AV_CODEC_ID_MPEG4:
213  codec_mime = "video/mp4v-es";
214  break;
215  case AV_CODEC_ID_AV1:
216  codec_mime = "video/av01";
217  break;
218  default:
219  av_assert0(0);
220  }
221 
222  if (s->name)
223  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
224  else
225  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
226  if (!s->codec) {
227  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
228  codec_mime);
229  return AVERROR_EXTERNAL;
230  }
231 
232  format = ff_AMediaFormat_new(s->use_ndk_codec);
233  if (!format) {
234  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
235  return AVERROR_EXTERNAL;
236  }
237 
238  ff_AMediaFormat_setString(format, "mime", codec_mime);
239  // Workaround the alignment requirement of mediacodec. We can't do it
240  // silently for AV_PIX_FMT_MEDIACODEC.
241  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
242  (avctx->codec_id == AV_CODEC_ID_H264 ||
243  avctx->codec_id == AV_CODEC_ID_HEVC)) {
244  s->width = FFALIGN(avctx->width, 16);
245  s->height = FFALIGN(avctx->height, 16);
246  } else {
247  s->width = avctx->width;
248  s->height = avctx->height;
249  if (s->width % 16 || s->height % 16)
250  av_log(avctx, AV_LOG_WARNING,
251  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
252  s->width, s->height);
253  }
254  ff_AMediaFormat_setInt32(format, "width", s->width);
255  ff_AMediaFormat_setInt32(format, "height", s->height);
256 
257  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
258  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
259  if (avctx->hw_device_ctx) {
260  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
261  AVMediaCodecDeviceContext *dev_ctx;
262 
263  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
264  ret = AVERROR(EINVAL);
265  goto bailout;
266  }
267  dev_ctx = device_ctx->hwctx;
268  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
269  }
270 
271  if (!s->window && user_ctx && user_ctx->surface)
272  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
273 
274  if (!s->window) {
275  ret = AVERROR(EINVAL);
276  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
277  goto bailout;
278  }
279  /* Although there is a method ANativeWindow_toSurface() introduced in
280  * API level 26, it's easier and safe to always require a Surface for
281  * Java MediaCodec.
282  */
283  if (!s->use_ndk_codec && !s->window->surface) {
284  ret = AVERROR(EINVAL);
285  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
286  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
287  goto bailout;
288  }
289  }
290 
291  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
292  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
293  ff_AMediaFormat_setInt32(format, "color-format",
295  break;
296  }
297  }
298 
301  ff_AMediaFormat_setInt32(format, "color-range", ret);
304  ff_AMediaFormat_setInt32(format, "color-standard", ret);
307  ff_AMediaFormat_setInt32(format, "color-transfer", ret);
308 
309  if (avctx->bit_rate)
310  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
311  if (s->bitrate_mode >= 0) {
312  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
313  if (s->bitrate_mode == BITRATE_MODE_CQ && avctx->global_quality > 0)
314  ff_AMediaFormat_setInt32(format, "quality", avctx->global_quality);
315  }
316  // frame-rate and i-frame-interval are required to configure codec
317  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
318  s->fps = avctx->framerate.num / avctx->framerate.den;
319  } else {
320  s->fps = 30;
321  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
322  }
323  gop = round(avctx->gop_size / s->fps);
324  if (gop == 0) {
325  gop = 1;
326  av_log(avctx, AV_LOG_INFO,
327  "Use %d as the default MediaFormat i-frame-interval, "
328  "please set gop_size properly (>= fps)\n", gop);
329  } else {
330  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
331  }
332 
333  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
334  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
335 
337  if (ret > 0) {
338  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
339  ff_AMediaFormat_setInt32(format, "profile", ret);
340  }
341  if (s->level > 0) {
342  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
343  ff_AMediaFormat_setInt32(format, "level", s->level);
344  }
345  if (avctx->max_b_frames > 0) {
347  av_log(avctx, AV_LOG_ERROR,
348  "Enabling B frames will produce packets with no DTS. "
349  "Use -strict experimental to use it anyway.\n");
350  ret = AVERROR(EINVAL);
351  goto bailout;
352  }
353  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
354  }
355  if (s->pts_as_dts == -1)
356  s->pts_as_dts = avctx->max_b_frames <= 0;
357 
359  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
360  if (ret) {
361  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
362  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
363  av_log(avctx, AV_LOG_ERROR, "Please try -pix_fmt nv12, some devices don't "
364  "support yuv420p as encoder input format.\n");
365  goto bailout;
366  }
367 
368  ret = ff_AMediaCodec_start(s->codec);
369  if (ret) {
370  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n", av_err2str(ret));
371  goto bailout;
372  }
373 
374  ret = mediacodec_init_bsf(avctx);
375  if (ret)
376  goto bailout;
377 
379 
380  s->frame = av_frame_alloc();
381  if (!s->frame) {
382  ret = AVERROR(ENOMEM);
383  goto bailout;
384  }
385 
387 
388 bailout:
389  if (format)
391  return ret;
392 }
393 
395 {
396  MediaCodecEncContext *s = avctx->priv_data;
397  FFAMediaCodec *codec = s->codec;
398  FFAMediaCodecBufferInfo out_info = {0};
399  uint8_t *out_buf;
400  size_t out_size = 0;
401  int ret;
402  int extradata_size = 0;
403  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
404  ssize_t index = ff_AMediaCodec_dequeueOutputBuffer(codec, &out_info, timeout_us);
405 
407  return AVERROR(EAGAIN);
408 
411  return AVERROR(EAGAIN);
412  }
413 
416  return AVERROR(EAGAIN);
417  }
418 
419  if (index < 0)
420  return AVERROR_EXTERNAL;
421 
422  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
423  return AVERROR_EOF;
424 
425  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
426  if (!out_buf) {
428  goto bailout;
429  }
430 
431  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
432  ret = av_reallocp(&s->extradata, out_info.size);
433  if (ret)
434  goto bailout;
435 
436  s->extradata_size = out_info.size;
437  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
439  // try immediately
440  return mediacodec_receive(avctx, pkt);
441  }
442 
443  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
444  if (ret < 0)
445  goto bailout;
446 
447  if (s->extradata_size) {
448  extradata_size = s->extradata_size;
449  s->extradata_size = 0;
450  memcpy(pkt->data, s->extradata, extradata_size);
451  }
452  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
454  if (s->pts_as_dts)
455  pkt->dts = pkt->pts;
456  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
458  ret = 0;
459 
460  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
461  " flags %d extradata %d\n",
462  pkt->pts, pkt->dts, pkt->flags, extradata_size);
463 
464 bailout:
466  return ret;
467 }
468 
469 static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
470 {
471  MediaCodecEncContext *s = avctx->priv_data;
472  uint8_t *dst_data[4] = {};
473  int dst_linesize[4] = {};
474 
475  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
476  dst_data[0] = dst;
477  dst_data[1] = dst + s->width * s->height;
478  dst_data[2] = dst_data[1] + s->width * s->height / 4;
479 
480  dst_linesize[0] = s->width;
481  dst_linesize[1] = dst_linesize[2] = s->width / 2;
482  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
483  dst_data[0] = dst;
484  dst_data[1] = dst + s->width * s->height;
485 
486  dst_linesize[0] = s->width;
487  dst_linesize[1] = s->width;
488  } else {
489  av_assert0(0);
490  }
491 
492  av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
493  avctx->pix_fmt, avctx->width, avctx->height);
494 }
495 
496 static int mediacodec_send(AVCodecContext *avctx,
497  const AVFrame *frame) {
498  MediaCodecEncContext *s = avctx->priv_data;
499  FFAMediaCodec *codec = s->codec;
500  ssize_t index;
501  uint8_t *input_buf = NULL;
502  size_t input_size = 0;
503  int64_t pts = 0;
504  uint32_t flags = 0;
505  int64_t timeout_us;
506 
507  if (s->eof_sent)
508  return 0;
509 
510  if (s->window) {
511  if (!frame) {
512  s->eof_sent = 1;
514  }
515 
516  if (frame->data[3])
517  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
518  return 0;
519  }
520 
521  timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
522  index = ff_AMediaCodec_dequeueInputBuffer(codec, timeout_us);
524  return AVERROR(EAGAIN);
525 
526  if (index < 0) {
527  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
528  return AVERROR_EXTERNAL;
529  }
530 
531  if (frame) {
532  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
533  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
534 
535  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
536  } else {
538  s->eof_sent = 1;
539  }
540 
541  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
542  return 0;
543 }
544 
546 {
547  MediaCodecEncContext *s = avctx->priv_data;
548  int ret;
549 
550  // Return on three case:
551  // 1. Serious error
552  // 2. Got a packet success
553  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
554  while (1) {
555  if (s->bsf) {
556  ret = av_bsf_receive_packet(s->bsf, pkt);
557  if (!ret)
558  return 0;
559  if (ret != AVERROR(EAGAIN))
560  return ret;
561  }
562 
563  ret = mediacodec_receive(avctx, pkt);
564  if (s->bsf) {
565  if (!ret || ret == AVERROR_EOF)
566  ret = av_bsf_send_packet(s->bsf, pkt);
567  } else {
568  if (!ret)
569  return 0;
570  }
571 
572  if (ret < 0 && ret != AVERROR(EAGAIN))
573  return ret;
574 
575  if (!s->frame->buf[0]) {
576  ret = ff_encode_get_frame(avctx, s->frame);
577  if (ret && ret != AVERROR_EOF)
578  return ret;
579  }
580 
581  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
582  if (!ret)
583  av_frame_unref(s->frame);
584  else if (ret != AVERROR(EAGAIN))
585  return ret;
586  }
587 
588  return 0;
589 }
590 
592 {
593  MediaCodecEncContext *s = avctx->priv_data;
594  int ret;
595 
596  s->frame->width = avctx->width;
597  s->frame->height = avctx->height;
598  s->frame->format = avctx->pix_fmt;
599  s->frame->pts = 0;
600 
601  ret = av_frame_get_buffer(s->frame, 0);
602  if (ret < 0)
603  return ret;
604 
605  do {
606  ret = mediacodec_send(avctx, s->frame);
607  } while (ret == AVERROR(EAGAIN));
608  av_frame_unref(s->frame);
609 
610  if (ret < 0)
611  return ret;
612 
613  ret = mediacodec_send(avctx, NULL);
614  if (ret < 0) {
615  av_log(avctx, AV_LOG_ERROR, "Flush failed: %s\n", av_err2str(ret));
616  return ret;
617  }
618 
619  return 0;
620 }
621 
623 {
624  MediaCodecEncContext *s = avctx->priv_data;
625  int ret;
626 
627  do {
628  ret = mediacodec_receive(avctx, pkt);
629  } while (ret == AVERROR(EAGAIN));
630 
631  if (ret < 0)
632  return ret;
633 
634  do {
635  ret = av_bsf_send_packet(s->bsf, pkt);
636  if (ret < 0)
637  return ret;
638  ret = av_bsf_receive_packet(s->bsf, pkt);
639  } while (ret == AVERROR(EAGAIN));
640 
641  return ret;
642 }
643 
645 {
646  MediaCodecEncContext *s = avctx->priv_data;
647  AVPacket *pkt = NULL;
648  int ret;
649  size_t side_size;
650  uint8_t *side;
651 
652  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
653  return 0;
654 
655  if (!s->extract_extradata) {
656  av_log(avctx, AV_LOG_WARNING,
657  "Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. "
658  "Use extract_extradata bsf when necessary.\n");
659  return 0;
660  }
661 
662  pkt = av_packet_alloc();
663  if (!pkt)
664  return AVERROR(ENOMEM);
665 
667  if (ret < 0)
668  goto bailout;
670  if (ret < 0)
671  goto bailout;
672 
674  if (side && side_size > 0) {
675  avctx->extradata = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
676  if (!avctx->extradata) {
677  ret = AVERROR(ENOMEM);
678  goto bailout;
679  }
680 
681  memcpy(avctx->extradata, side, side_size);
682  avctx->extradata_size = side_size;
683  }
684 
685 bailout:
686  if (s->eof_sent) {
687  s->eof_sent = 0;
688  ff_AMediaCodec_flush(s->codec);
689  }
690  av_bsf_flush(s->bsf);
692  return ret;
693 }
694 
696 {
697  MediaCodecEncContext *s = avctx->priv_data;
698  if (s->codec) {
699  ff_AMediaCodec_stop(s->codec);
700  ff_AMediaCodec_delete(s->codec);
701  s->codec = NULL;
702  }
703 
704  if (s->window) {
705  ff_mediacodec_surface_unref(s->window, avctx);
706  s->window = NULL;
707  }
708 
709  av_bsf_free(&s->bsf);
710  av_frame_free(&s->frame);
711 
712  return 0;
713 }
714 
716 {
717  MediaCodecEncContext *s = avctx->priv_data;
718  if (s->bsf)
719  av_bsf_flush(s->bsf);
720  av_frame_unref(s->frame);
721  ff_AMediaCodec_flush(s->codec);
722 }
723 
725  &(const AVCodecHWConfigInternal) {
726  .public = {
730  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
731  },
732  .hwaccel = NULL,
733  },
734  NULL
735 };
736 
737 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
738 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
739 #define COMMON_OPTION \
740  { "ndk_codec", "Use MediaCodec from NDK", \
741  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
742  { "codec_name", "Select codec by name", \
743  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
744  { "bitrate_mode", "Bitrate control method", \
745  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode" }, \
746  { "cq", "Constant quality mode", \
747  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, .unit = "bitrate_mode" }, \
748  { "vbr", "Variable bitrate mode", \
749  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
750  { "cbr", "Constant bitrate mode", \
751  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
752  { "cbr_fd", "Constant bitrate mode with frame drops", \
753  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, .unit = "bitrate_mode" }, \
754  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
755  "since most of Android devices don't output B frames by default.", \
756  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
757 
758 
759 #define MEDIACODEC_ENCODER_CLASS(name) \
760 static const AVClass name ## _mediacodec_class = { \
761  .class_name = #name "_mediacodec", \
762  .item_name = av_default_item_name, \
763  .option = name ## _options, \
764  .version = LIBAVUTIL_VERSION_INT, \
765 }; \
766 
767 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
768 MEDIACODEC_ENCODER_CLASS(short_name) \
769 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
770  .p.name = #short_name "_mediacodec", \
771  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
772  .p.type = AVMEDIA_TYPE_VIDEO, \
773  .p.id = codec_id, \
774  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
775  AV_CODEC_CAP_HARDWARE | \
776  AV_CODEC_CAP_ENCODER_FLUSH, \
777  .priv_data_size = sizeof(MediaCodecEncContext), \
778  .p.pix_fmts = avc_pix_fmts, \
779  .init = mediacodec_init, \
780  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
781  .close = mediacodec_close, \
782  .flush = mediacodec_flush, \
783  .p.priv_class = &short_name ## _mediacodec_class, \
784  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
785  .p.wrapper_name = "mediacodec", \
786  .hw_configs = mediacodec_hw_configs, \
787 }; \
788 
789 #if CONFIG_H264_MEDIACODEC_ENCODER
790 
791 enum MediaCodecAvcLevel {
792  AVCLevel1 = 0x01,
793  AVCLevel1b = 0x02,
794  AVCLevel11 = 0x04,
795  AVCLevel12 = 0x08,
796  AVCLevel13 = 0x10,
797  AVCLevel2 = 0x20,
798  AVCLevel21 = 0x40,
799  AVCLevel22 = 0x80,
800  AVCLevel3 = 0x100,
801  AVCLevel31 = 0x200,
802  AVCLevel32 = 0x400,
803  AVCLevel4 = 0x800,
804  AVCLevel41 = 0x1000,
805  AVCLevel42 = 0x2000,
806  AVCLevel5 = 0x4000,
807  AVCLevel51 = 0x8000,
808  AVCLevel52 = 0x10000,
809  AVCLevel6 = 0x20000,
810  AVCLevel61 = 0x40000,
811  AVCLevel62 = 0x80000,
812 };
813 
814 static const AVOption h264_options[] = {
816 
818  FF_AVCTX_PROFILE_OPTION("constrained_baseline", NULL, VIDEO, AV_PROFILE_H264_CONSTRAINED_BASELINE)
825 
826  { "level", "Specify level",
827  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
828  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, .unit = "level" },
829  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, .unit = "level" },
830  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, .unit = "level" },
831  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, .unit = "level" },
832  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, .unit = "level" },
833  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, .unit = "level" },
834  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, .unit = "level" },
835  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, .unit = "level" },
836  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, .unit = "level" },
837  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, .unit = "level" },
838  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, .unit = "level" },
839  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, .unit = "level" },
840  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, .unit = "level" },
841  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, .unit = "level" },
842  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, .unit = "level" },
843  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, .unit = "level" },
844  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, .unit = "level" },
845  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, .unit = "level" },
846  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, .unit = "level" },
847  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, .unit = "level" },
848  { NULL, }
849 };
850 
852 
853 #endif // CONFIG_H264_MEDIACODEC_ENCODER
854 
855 #if CONFIG_HEVC_MEDIACODEC_ENCODER
856 
857 enum MediaCodecHevcLevel {
858  HEVCMainTierLevel1 = 0x1,
859  HEVCHighTierLevel1 = 0x2,
860  HEVCMainTierLevel2 = 0x4,
861  HEVCHighTierLevel2 = 0x8,
862  HEVCMainTierLevel21 = 0x10,
863  HEVCHighTierLevel21 = 0x20,
864  HEVCMainTierLevel3 = 0x40,
865  HEVCHighTierLevel3 = 0x80,
866  HEVCMainTierLevel31 = 0x100,
867  HEVCHighTierLevel31 = 0x200,
868  HEVCMainTierLevel4 = 0x400,
869  HEVCHighTierLevel4 = 0x800,
870  HEVCMainTierLevel41 = 0x1000,
871  HEVCHighTierLevel41 = 0x2000,
872  HEVCMainTierLevel5 = 0x4000,
873  HEVCHighTierLevel5 = 0x8000,
874  HEVCMainTierLevel51 = 0x10000,
875  HEVCHighTierLevel51 = 0x20000,
876  HEVCMainTierLevel52 = 0x40000,
877  HEVCHighTierLevel52 = 0x80000,
878  HEVCMainTierLevel6 = 0x100000,
879  HEVCHighTierLevel6 = 0x200000,
880  HEVCMainTierLevel61 = 0x400000,
881  HEVCHighTierLevel61 = 0x800000,
882  HEVCMainTierLevel62 = 0x1000000,
883  HEVCHighTierLevel62 = 0x2000000,
884 };
885 
886 static const AVOption hevc_options[] = {
888 
891 
892  { "level", "Specify tier and level",
893  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
894  { "m1", "Main tier level 1",
895  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, .unit = "level" },
896  { "h1", "High tier level 1",
897  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, .unit = "level" },
898  { "m2", "Main tier level 2",
899  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, .unit = "level" },
900  { "h2", "High tier level 2",
901  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, .unit = "level" },
902  { "m2.1", "Main tier level 2.1",
903  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, .unit = "level" },
904  { "h2.1", "High tier level 2.1",
905  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, .unit = "level" },
906  { "m3", "Main tier level 3",
907  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, .unit = "level" },
908  { "h3", "High tier level 3",
909  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, .unit = "level" },
910  { "m3.1", "Main tier level 3.1",
911  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, .unit = "level" },
912  { "h3.1", "High tier level 3.1",
913  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, .unit = "level" },
914  { "m4", "Main tier level 4",
915  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, .unit = "level" },
916  { "h4", "High tier level 4",
917  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, .unit = "level" },
918  { "m4.1", "Main tier level 4.1",
919  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, .unit = "level" },
920  { "h4.1", "High tier level 4.1",
921  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, .unit = "level" },
922  { "m5", "Main tier level 5",
923  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, .unit = "level" },
924  { "h5", "High tier level 5",
925  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, .unit = "level" },
926  { "m5.1", "Main tier level 5.1",
927  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, .unit = "level" },
928  { "h5.1", "High tier level 5.1",
929  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, .unit = "level" },
930  { "m5.2", "Main tier level 5.2",
931  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, .unit = "level" },
932  { "h5.2", "High tier level 5.2",
933  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, .unit = "level" },
934  { "m6", "Main tier level 6",
935  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, .unit = "level" },
936  { "h6", "High tier level 6",
937  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, .unit = "level" },
938  { "m6.1", "Main tier level 6.1",
939  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, .unit = "level" },
940  { "h6.1", "High tier level 6.1",
941  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, .unit = "level" },
942  { "m6.2", "Main tier level 6.2",
943  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, .unit = "level" },
944  { "h6.2", "High tier level 6.2",
945  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, .unit = "level" },
946  { NULL, }
947 };
948 
950 
951 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
952 
953 #if CONFIG_VP8_MEDIACODEC_ENCODER
954 
955 enum MediaCodecVP8Level {
956  VP8Level_Version0 = 0x01,
957  VP8Level_Version1 = 0x02,
958  VP8Level_Version2 = 0x04,
959  VP8Level_Version3 = 0x08,
960 };
961 
962 static const AVOption vp8_options[] = {
964  { "level", "Specify tier and level",
965  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
966  { "V0", "Level Version 0",
967  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version0 }, 0, 0, VE, .unit = "level" },
968  { "V1", "Level Version 1",
969  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version1 }, 0, 0, VE, .unit = "level" },
970  { "V2", "Level Version 2",
971  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version2 }, 0, 0, VE, .unit = "level" },
972  { "V3", "Level Version 3",
973  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version3 }, 0, 0, VE, .unit = "level" },
974  { NULL, }
975 };
976 
978 
979 #endif // CONFIG_VP8_MEDIACODEC_ENCODER
980 
981 #if CONFIG_VP9_MEDIACODEC_ENCODER
982 
983 enum MediaCodecVP9Level {
984  VP9Level1 = 0x1,
985  VP9Level11 = 0x2,
986  VP9Level2 = 0x4,
987  VP9Level21 = 0x8,
988  VP9Level3 = 0x10,
989  VP9Level31 = 0x20,
990  VP9Level4 = 0x40,
991  VP9Level41 = 0x80,
992  VP9Level5 = 0x100,
993  VP9Level51 = 0x200,
994  VP9Level52 = 0x400,
995  VP9Level6 = 0x800,
996  VP9Level61 = 0x1000,
997  VP9Level62 = 0x2000,
998 };
999 
1000 static const AVOption vp9_options[] = {
1002 
1003  FF_AVCTX_PROFILE_OPTION("profile0", NULL, VIDEO, AV_PROFILE_VP9_0)
1004  FF_AVCTX_PROFILE_OPTION("profile1", NULL, VIDEO, AV_PROFILE_VP9_1)
1005  FF_AVCTX_PROFILE_OPTION("profile2", NULL, VIDEO, AV_PROFILE_VP9_2)
1006  FF_AVCTX_PROFILE_OPTION("profile3", NULL, VIDEO, AV_PROFILE_VP9_3)
1007 
1008  { "level", "Specify tier and level",
1009  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1010  { "1", "Level 1",
1011  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, .unit = "level" },
1012  { "1.1", "Level 1.1",
1013  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, .unit = "level" },
1014  { "2", "Level 2",
1015  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, .unit = "level" },
1016  { "2.1", "Level 2.1",
1017  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, .unit = "level" },
1018  { "3", "Level 3",
1019  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, .unit = "level" },
1020  { "3.1", "Level 3.1",
1021  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, .unit = "level" },
1022  { "4", "Level 4",
1023  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, .unit = "level" },
1024  { "4.1", "Level 4.1",
1025  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, .unit = "level" },
1026  { "5", "Level 5",
1027  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, .unit = "level" },
1028  { "5.1", "Level 5.1",
1029  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, .unit = "level" },
1030  { "5.2", "Level 5.2",
1031  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, .unit = "level" },
1032  { "6", "Level 6",
1033  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, .unit = "level" },
1034  { "6.1", "Level 4.1",
1035  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, .unit = "level" },
1036  { "6.2", "Level 6.2",
1037  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, .unit = "level" },
1038  { NULL, }
1039 };
1040 
1042 
1043 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
1044 
1045 #if CONFIG_MPEG4_MEDIACODEC_ENCODER
1046 
1047 enum MediaCodecMpeg4Level {
1048  MPEG4Level0 = 0x01,
1049  MPEG4Level0b = 0x02,
1050  MPEG4Level1 = 0x04,
1051  MPEG4Level2 = 0x08,
1052  MPEG4Level3 = 0x10,
1053  MPEG4Level3b = 0x18,
1054  MPEG4Level4 = 0x20,
1055  MPEG4Level4a = 0x40,
1056  MPEG4Level5 = 0x80,
1057  MPEG4Level6 = 0x100,
1058 };
1059 
1060 static const AVOption mpeg4_options[] = {
1062 
1064 
1065  { "level", "Specify tier and level",
1066  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1067  { "0", "Level 0",
1068  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, .unit = "level" },
1069  { "0b", "Level 0b",
1070  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, .unit = "level" },
1071  { "1", "Level 1",
1072  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, .unit = "level" },
1073  { "2", "Level 2",
1074  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, .unit = "level" },
1075  { "3", "Level 3",
1076  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, .unit = "level" },
1077  { "3b", "Level 3b",
1078  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, .unit = "level" },
1079  { "4", "Level 4",
1080  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, .unit = "level" },
1081  { "4a", "Level 4a",
1082  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, .unit = "level" },
1083  { "5", "Level 5",
1084  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, .unit = "level" },
1085  { "6", "Level 6",
1086  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, .unit = "level" },
1087  { NULL, }
1088 };
1089 
1091 
1092 #endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
1093 
1094 #if CONFIG_AV1_MEDIACODEC_ENCODER
1095 
1096 enum MediaCodecAV1Level {
1097  AV1Level2 = 0x1,
1098  AV1Level21 = 0x2,
1099  AV1Level22 = 0x4,
1100  AV1Level23 = 0x8,
1101  AV1Level3 = 0x10,
1102  AV1Level31 = 0x20,
1103  AV1Level32 = 0x40,
1104  AV1Level33 = 0x80,
1105  AV1Level4 = 0x100,
1106  AV1Level41 = 0x200,
1107  AV1Level42 = 0x400,
1108  AV1Level43 = 0x800,
1109  AV1Level5 = 0x1000,
1110  AV1Level51 = 0x2000,
1111  AV1Level52 = 0x4000,
1112  AV1Level53 = 0x8000,
1113  AV1Level6 = 0x10000,
1114  AV1Level61 = 0x20000,
1115  AV1Level62 = 0x40000,
1116  AV1Level63 = 0x80000,
1117  AV1Level7 = 0x100000,
1118  AV1Level71 = 0x200000,
1119  AV1Level72 = 0x400000,
1120  AV1Level73 = 0x800000,
1121 };
1122 
1123 static const AVOption av1_options[] = {
1125 
1127 
1128  { "level", "Specify tier and level",
1129  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1130  { "2", "Level 2",
1131  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, .unit = "level" },
1132  { "2.1", "Level 2.1",
1133  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, .unit = "level" },
1134  { "2.2", "Level 2.2",
1135  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, .unit = "level" },
1136  { "2.3", "Level 2.3",
1137  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, .unit = "level" },
1138  { "3", "Level 3",
1139  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, .unit = "level" },
1140  { "3.1", "Level 3.1",
1141  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, .unit = "level" },
1142  { "3.2", "Level 3.2",
1143  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, .unit = "level" },
1144  { "3.3", "Level 3.3",
1145  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, .unit = "level" },
1146  { "4", "Level 4",
1147  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, .unit = "level" },
1148  { "4.1", "Level 4.1",
1149  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, .unit = "level" },
1150  { "4.2", "Level 4.2",
1151  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, .unit = "level" },
1152  { "4.3", "Level 4.3",
1153  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, .unit = "level" },
1154  { "5", "Level 5",
1155  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, .unit = "level" },
1156  { "5.1", "Level 5.1",
1157  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, .unit = "level" },
1158  { "5.2", "Level 5.2",
1159  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, .unit = "level" },
1160  { "5.3", "Level 5.3",
1161  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, .unit = "level" },
1162  { "6", "Level 6",
1163  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, .unit = "level" },
1164  { "6.1", "Level 6.1",
1165  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, .unit = "level" },
1166  { "6.2", "Level 6.2",
1167  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, .unit = "level" },
1168  { "6.3", "Level 6.3",
1169  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, .unit = "level" },
1170  { "7", "Level 7",
1171  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, .unit = "level" },
1172  { "7.1", "Level 7.1",
1173  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, .unit = "level" },
1174  { "7.2", "Level 7.2",
1175  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, .unit = "level" },
1176  { "7.3", "Level 7.3",
1177  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, .unit = "level" },
1178  { NULL, }
1179 };
1180 
1182 
1183 #endif // CONFIG_AV1_MEDIACODEC_ENCODER
MediaCodecEncContext
Definition: mediacodecenc.c:57
ff_AMediaCodec_getInputBuffer
static uint8_t * ff_AMediaCodec_getInputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:261
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:82
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:1451
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:186
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:256
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
MediaCodecEncContext::pts_as_dts
int pts_as_dts
Definition: mediacodecenc.c:77
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
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
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:288
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:767
ff_AMediaCodec_start
static int ff_AMediaCodec_start(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:241
FFAMediaCodecBufferInfo::offset
int32_t offset
Definition: mediacodec_wrapper.h:173
MediaCodecEncContext::avclass
AVClass * avclass
Definition: mediacodecenc.c:58
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:78
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:84
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:88
BITRATE_MODE_VBR
@ BITRATE_MODE_VBR
Definition: mediacodecenc.c:50
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
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:64
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
ff_AMediaCodec_signalEndOfInputStream
static int ff_AMediaCodec_signalEndOfInputStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:341
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:62
AVPacket::data
uint8_t * data
Definition: packet.h:520
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:46
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:311
AVOption
AVOption.
Definition: opt.h:357
encode.h
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:306
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:276
extract_extradata_support
static int extract_extradata_support(AVCodecContext *avctx)
Definition: mediacodecenc.c:117
MediaCodecEncContext::eof_sent
int eof_sent
Definition: mediacodecenc.c:70
COMMON_OPTION
#define COMMON_OPTION
Definition: mediacodecenc.c:739
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:545
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
hwcontext_mediacodec.h
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:575
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:74
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
mediacodec_send_dummy_frame
static int mediacodec_send_dummy_frame(AVCodecContext *avctx)
Definition: mediacodecenc.c:591
VE
#define VE
Definition: mediacodecenc.c:738
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:103
ff_AMediaCodec_configure
static int ff_AMediaCodec_configure(FFAMediaCodec *codec, const FFAMediaFormat *format, FFANativeWindow *surface, void *crypto, uint32_t flags)
Definition: mediacodec_wrapper.h:233
AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_H264_EXTENDED
Definition: defs.h:113
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
bsf.h
mediacodec_flush
static av_cold void mediacodec_flush(AVCodecContext *avctx)
Definition: mediacodecenc.c:715
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1546
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:695
MediaCodecEncContext::extradata
uint8_t * extradata
Definition: mediacodecenc.c:68
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:502
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecenc.c:89
COLOR_RANGE_UNSPECIFIED
@ COLOR_RANGE_UNSPECIFIED
Definition: mediacodec_wrapper.h:349
AVERROR_BUFFER_TOO_SMALL
#define AVERROR_BUFFER_TOO_SMALL
Buffer too small.
Definition: error.h:53
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:2401
AVRational::num
int num
Numerator.
Definition: rational.h:59
mediacodecdec_common.h
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:148
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:496
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
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:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
MediaCodecEncContext::bitrate_mode
int bitrate_mode
Definition: mediacodecenc.c:75
ff_AMediaCodec_getName
static char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:224
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:321
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:331
s
#define s(width, name)
Definition: cbs_vp9.c:198
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2932
BITRATE_MODE_CQ
@ BITRATE_MODE_CQ
Definition: mediacodecenc.c:48
AVCodecContext::global_quality
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1239
av_bsf_flush
void av_bsf_flush(AVBSFContext *ctx)
Reset the internal bitstream filter state.
Definition: bsf.c:190
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:220
color_formats
static const struct @160 color_formats[]
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
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:201
OFFSET
#define OFFSET(x)
Definition: mediacodecenc.c:737
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:343
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:455
MediaCodecEncContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecenc.c:60
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:644
ff_AMediaFormatColorStandard_from_AVColorSpace
int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space)
Map AVColorSpace to MediaFormat color standard.
Definition: mediacodec_wrapper.c:2526
OUTPUT_DEQUEUE_TIMEOUT_US
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:44
ff_AMediaCodec_getOutputFormat
static FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:286
MediaCodecEncContext::level
int level
Definition: mediacodecenc.c:76
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:66
ff_AMediaCodec_createCodecByName
FFAMediaCodec * ff_AMediaCodec_createCodecByName(const char *name, int ndk)
Definition: mediacodec_wrapper.c:2408
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2509
NULL
#define NULL
Definition: coverity.c:32
ff_AMediaCodec_flush
static int ff_AMediaCodec_flush(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:251
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:280
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:495
profiles.h
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2422
ff_AMediaCodec_stop
static int ff_AMediaCodec_stop(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:246
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:83
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:54
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:326
mpeg4_options
static const AVOption mpeg4_options[]
Definition: v4l2_m2m_enc.c:397
BITRATE_MODE_CBR
@ BITRATE_MODE_CBR
Definition: mediacodecenc.c:52
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
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:544
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1031
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1107
codec_internal.h
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:363
avc_pix_fmts
static enum AVPixelFormat avc_pix_fmts[]
Definition: mediacodecenc.c:96
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:622
ff_AMediaFormatColorTransfer_from_AVColorTransfer
int ff_AMediaFormatColorTransfer_from_AVColorTransfer(enum AVColorTransferCharacteristic color_transfer)
Map AVColorTransferCharacteristic to MediaFormat color transfer.
Definition: mediacodec_wrapper.c:2554
AVCodecHWConfigInternal
Definition: hwconfig.h:25
MediaCodecEncContext::bsf
AVBSFContext * bsf
Definition: mediacodecenc.c:73
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:519
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
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:526
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:61
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
MediaCodecEncContext::width
int width
Definition: mediacodecenc.c:65
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:331
MediaCodecEncContext::codec
FFAMediaCodec * codec
Definition: mediacodecenc.c:59
FFANativeWindow
Definition: mediacodec_surface.h:28
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:513
COLOR_STANDARD_UNSPECIFIED
@ COLOR_STANDARD_UNSPECIFIED
Definition: mediacodec_wrapper.h:355
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
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:252
FFAMediaCodec
Definition: mediacodec_wrapper.h:181
MediaCodecEncContext::height
int height
Definition: mediacodecenc.c:66
MediaCodecEncContext::extradata_size
int extradata_size
Definition: mediacodecenc.c:69
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:606
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:1497
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:72
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:43
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
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:271
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
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1379
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:110
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_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:445
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:188
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
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
Definition: opt.h:245
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:316
AV_PROFILE_VP9_0
#define AV_PROFILE_VP9_0
Definition: defs.h:154
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:795
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:266
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:336
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:497
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:301
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
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:302
ff_AMediaCodec_releaseOutputBuffer
static int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h:291
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
avstring.h
jni.h
mediacodec_hw_configs
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
Definition: mediacodecenc.c:724
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:281
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:254
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:469
mediacodec_init_bsf
static int mediacodec_init_bsf(AVCodecContext *avctx)
Definition: mediacodecenc.c:134
mediacodec_receive
static int mediacodec_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:394
mediacodec.h
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:86