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  ret = snprintf(str, sizeof(str), "hevc_metadata=crop_right=%d:crop_bottom=%d",
158  crop_right, crop_bottom);
159  if (ret >= sizeof(str))
161  }
162 
163  if (s->extract_extradata) {
164  ret = av_strlcatf(str, sizeof(str), "%sextract_extradata", ret ? "," : "");
165  if (ret >= sizeof(str))
167  }
168 
169  ret = av_bsf_list_parse_str(str, &s->bsf);
170  if (ret < 0)
171  return ret;
172 
173  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
174  if (ret < 0)
175  return ret;
176  s->bsf->time_base_in = avctx->time_base;
177  ret = av_bsf_init(s->bsf);
178 
179  return ret;
180 }
181 
183 
185 {
186  const char *codec_mime = NULL;
187  MediaCodecEncContext *s = avctx->priv_data;
189  int ret;
190  int gop;
191 
192  if (s->use_ndk_codec < 0)
193  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
194 
195  switch (avctx->codec_id) {
196  case AV_CODEC_ID_H264:
197  codec_mime = "video/avc";
198  break;
199  case AV_CODEC_ID_HEVC:
200  codec_mime = "video/hevc";
201  break;
202  case AV_CODEC_ID_VP8:
203  codec_mime = "video/x-vnd.on2.vp8";
204  break;
205  case AV_CODEC_ID_VP9:
206  codec_mime = "video/x-vnd.on2.vp9";
207  break;
208  case AV_CODEC_ID_MPEG4:
209  codec_mime = "video/mp4v-es";
210  break;
211  case AV_CODEC_ID_AV1:
212  codec_mime = "video/av01";
213  break;
214  default:
215  av_assert0(0);
216  }
217 
218  if (s->name)
219  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
220  else
221  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
222  if (!s->codec) {
223  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
224  codec_mime);
225  return AVERROR_EXTERNAL;
226  }
227 
228  format = ff_AMediaFormat_new(s->use_ndk_codec);
229  if (!format) {
230  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
231  return AVERROR_EXTERNAL;
232  }
233 
234  ff_AMediaFormat_setString(format, "mime", codec_mime);
235  // Workaround the alignment requirement of mediacodec. We can't do it
236  // silently for AV_PIX_FMT_MEDIACODEC.
237  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) {
238  s->width = FFALIGN(avctx->width, 16);
239  s->height = FFALIGN(avctx->height, 16);
240  } else {
241  s->width = avctx->width;
242  s->height = avctx->height;
243  if (s->width % 16 || s->height % 16)
244  av_log(avctx, AV_LOG_WARNING,
245  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
246  s->width, s->height);
247  }
248  ff_AMediaFormat_setInt32(format, "width", s->width);
249  ff_AMediaFormat_setInt32(format, "height", s->height);
250 
251  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
252  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
253  if (avctx->hw_device_ctx) {
254  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
255  AVMediaCodecDeviceContext *dev_ctx;
256 
257  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
258  ret = AVERROR(EINVAL);
259  goto bailout;
260  }
261  dev_ctx = device_ctx->hwctx;
262  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
263  }
264 
265  if (!s->window && user_ctx && user_ctx->surface)
266  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
267 
268  if (!s->window) {
269  ret = AVERROR(EINVAL);
270  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
271  goto bailout;
272  }
273  /* Although there is a method ANativeWindow_toSurface() introduced in
274  * API level 26, it's easier and safe to always require a Surface for
275  * Java MediaCodec.
276  */
277  if (!s->use_ndk_codec && !s->window->surface) {
278  ret = AVERROR(EINVAL);
279  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
280  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
281  goto bailout;
282  }
283  }
284 
285  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
286  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
287  ff_AMediaFormat_setInt32(format, "color-format",
289  break;
290  }
291  }
292 
295  ff_AMediaFormat_setInt32(format, "color-range", ret);
298  ff_AMediaFormat_setInt32(format, "color-standard", ret);
301  ff_AMediaFormat_setInt32(format, "color-transfer", ret);
302 
303  if (avctx->bit_rate)
304  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
305  if (s->bitrate_mode >= 0) {
306  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
307  if (s->bitrate_mode == BITRATE_MODE_CQ && avctx->global_quality > 0)
308  ff_AMediaFormat_setInt32(format, "quality", avctx->global_quality);
309  }
310  // frame-rate and i-frame-interval are required to configure codec
311  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
312  s->fps = avctx->framerate.num / avctx->framerate.den;
313  } else {
314  s->fps = 30;
315  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
316  }
317  gop = round(avctx->gop_size / s->fps);
318  if (gop == 0) {
319  gop = 1;
320  av_log(avctx, AV_LOG_INFO,
321  "Use %d as the default MediaFormat i-frame-interval, "
322  "please set gop_size properly (>= fps)\n", gop);
323  } else {
324  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
325  }
326 
327  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
328  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
329 
331  if (ret > 0) {
332  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
333  ff_AMediaFormat_setInt32(format, "profile", ret);
334  }
335  if (s->level > 0) {
336  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
337  ff_AMediaFormat_setInt32(format, "level", s->level);
338  }
339  if (avctx->max_b_frames > 0) {
341  av_log(avctx, AV_LOG_ERROR,
342  "Enabling B frames will produce packets with no DTS. "
343  "Use -strict experimental to use it anyway.\n");
344  ret = AVERROR(EINVAL);
345  goto bailout;
346  }
347  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
348  }
349  if (s->pts_as_dts == -1)
350  s->pts_as_dts = avctx->max_b_frames <= 0;
351 
353  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
354  if (ret) {
355  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
356  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
357  av_log(avctx, AV_LOG_ERROR, "Please try -pix_fmt nv12, some devices don't "
358  "support yuv420p as encoder input format.\n");
359  goto bailout;
360  }
361 
362  ret = ff_AMediaCodec_start(s->codec);
363  if (ret) {
364  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n", av_err2str(ret));
365  goto bailout;
366  }
367 
368  ret = mediacodec_init_bsf(avctx);
369  if (ret)
370  goto bailout;
371 
373 
374  s->frame = av_frame_alloc();
375  if (!s->frame) {
376  ret = AVERROR(ENOMEM);
377  goto bailout;
378  }
379 
381 
382 bailout:
383  if (format)
385  return ret;
386 }
387 
389 {
390  MediaCodecEncContext *s = avctx->priv_data;
391  FFAMediaCodec *codec = s->codec;
392  FFAMediaCodecBufferInfo out_info = {0};
393  uint8_t *out_buf;
394  size_t out_size = 0;
395  int ret;
396  int extradata_size = 0;
397  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
398  ssize_t index = ff_AMediaCodec_dequeueOutputBuffer(codec, &out_info, timeout_us);
399 
401  return AVERROR(EAGAIN);
402 
405  return AVERROR(EAGAIN);
406  }
407 
410  return AVERROR(EAGAIN);
411  }
412 
413  if (index < 0)
414  return AVERROR_EXTERNAL;
415 
416  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
417  return AVERROR_EOF;
418 
419  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
420  if (!out_buf) {
422  goto bailout;
423  }
424 
425  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
426  ret = av_reallocp(&s->extradata, out_info.size);
427  if (ret)
428  goto bailout;
429 
430  s->extradata_size = out_info.size;
431  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
433  // try immediately
434  return mediacodec_receive(avctx, pkt);
435  }
436 
437  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
438  if (ret < 0)
439  goto bailout;
440 
441  if (s->extradata_size) {
442  extradata_size = s->extradata_size;
443  s->extradata_size = 0;
444  memcpy(pkt->data, s->extradata, extradata_size);
445  }
446  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
448  if (s->pts_as_dts)
449  pkt->dts = pkt->pts;
450  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
452  ret = 0;
453 
454  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
455  " flags %d extradata %d\n",
456  pkt->pts, pkt->dts, pkt->flags, extradata_size);
457 
458 bailout:
460  return ret;
461 }
462 
463 static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
464 {
465  MediaCodecEncContext *s = avctx->priv_data;
466  uint8_t *dst_data[4] = {};
467  int dst_linesize[4] = {};
468 
469  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
470  dst_data[0] = dst;
471  dst_data[1] = dst + s->width * s->height;
472  dst_data[2] = dst_data[1] + s->width * s->height / 4;
473 
474  dst_linesize[0] = s->width;
475  dst_linesize[1] = dst_linesize[2] = s->width / 2;
476  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
477  dst_data[0] = dst;
478  dst_data[1] = dst + s->width * s->height;
479 
480  dst_linesize[0] = s->width;
481  dst_linesize[1] = s->width;
482  } else {
483  av_assert0(0);
484  }
485 
486  av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
487  avctx->pix_fmt, avctx->width, avctx->height);
488 }
489 
490 static int mediacodec_send(AVCodecContext *avctx,
491  const AVFrame *frame) {
492  MediaCodecEncContext *s = avctx->priv_data;
493  FFAMediaCodec *codec = s->codec;
494  ssize_t index;
495  uint8_t *input_buf = NULL;
496  size_t input_size = 0;
497  int64_t pts = 0;
498  uint32_t flags = 0;
499  int64_t timeout_us;
500 
501  if (s->eof_sent)
502  return 0;
503 
504  if (s->window) {
505  if (!frame) {
506  s->eof_sent = 1;
508  }
509 
510  if (frame->data[3])
511  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
512  return 0;
513  }
514 
515  timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
516  index = ff_AMediaCodec_dequeueInputBuffer(codec, timeout_us);
518  return AVERROR(EAGAIN);
519 
520  if (index < 0) {
521  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
522  return AVERROR_EXTERNAL;
523  }
524 
525  if (frame) {
526  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
527  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
528 
529  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
530  } else {
532  s->eof_sent = 1;
533  }
534 
535  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
536  return 0;
537 }
538 
540 {
541  MediaCodecEncContext *s = avctx->priv_data;
542  int ret;
543 
544  // Return on three case:
545  // 1. Serious error
546  // 2. Got a packet success
547  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
548  while (1) {
549  if (s->bsf) {
550  ret = av_bsf_receive_packet(s->bsf, pkt);
551  if (!ret)
552  return 0;
553  if (ret != AVERROR(EAGAIN))
554  return ret;
555  }
556 
557  ret = mediacodec_receive(avctx, pkt);
558  if (s->bsf) {
559  if (!ret || ret == AVERROR_EOF)
560  ret = av_bsf_send_packet(s->bsf, pkt);
561  } else {
562  if (!ret)
563  return 0;
564  }
565 
566  if (ret < 0 && ret != AVERROR(EAGAIN))
567  return ret;
568 
569  if (!s->frame->buf[0]) {
570  ret = ff_encode_get_frame(avctx, s->frame);
571  if (ret && ret != AVERROR_EOF)
572  return ret;
573  }
574 
575  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
576  if (!ret)
577  av_frame_unref(s->frame);
578  else if (ret != AVERROR(EAGAIN))
579  return ret;
580  }
581 
582  return 0;
583 }
584 
586 {
587  MediaCodecEncContext *s = avctx->priv_data;
588  int ret;
589 
590  s->frame->width = avctx->width;
591  s->frame->height = avctx->height;
592  s->frame->format = avctx->pix_fmt;
593  s->frame->pts = 0;
594 
595  ret = av_frame_get_buffer(s->frame, 0);
596  if (ret < 0)
597  return ret;
598 
599  do {
600  ret = mediacodec_send(avctx, s->frame);
601  } while (ret == AVERROR(EAGAIN));
602  av_frame_unref(s->frame);
603 
604  if (ret < 0)
605  return ret;
606 
607  ret = mediacodec_send(avctx, NULL);
608  if (ret < 0) {
609  av_log(avctx, AV_LOG_ERROR, "Flush failed: %s\n", av_err2str(ret));
610  return ret;
611  }
612 
613  return 0;
614 }
615 
617 {
618  MediaCodecEncContext *s = avctx->priv_data;
619  int ret;
620 
621  do {
622  ret = mediacodec_receive(avctx, pkt);
623  } while (ret == AVERROR(EAGAIN));
624 
625  if (ret < 0)
626  return ret;
627 
628  do {
629  ret = av_bsf_send_packet(s->bsf, pkt);
630  if (ret < 0)
631  return ret;
632  ret = av_bsf_receive_packet(s->bsf, pkt);
633  } while (ret == AVERROR(EAGAIN));
634 
635  return ret;
636 }
637 
639 {
640  MediaCodecEncContext *s = avctx->priv_data;
641  AVPacket *pkt = NULL;
642  int ret;
643  size_t side_size;
644  uint8_t *side;
645 
646  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
647  return 0;
648 
649  if (!s->extract_extradata) {
650  av_log(avctx, AV_LOG_WARNING,
651  "Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. "
652  "Use extract_extradata bsf when necessary.\n");
653  return 0;
654  }
655 
656  pkt = av_packet_alloc();
657  if (!pkt)
658  return AVERROR(ENOMEM);
659 
661  if (ret < 0)
662  goto bailout;
664  if (ret < 0)
665  goto bailout;
666 
668  if (side && side_size > 0) {
669  avctx->extradata = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
670  if (!avctx->extradata) {
671  ret = AVERROR(ENOMEM);
672  goto bailout;
673  }
674 
675  memcpy(avctx->extradata, side, side_size);
676  avctx->extradata_size = side_size;
677  }
678 
679 bailout:
680  if (s->eof_sent) {
681  s->eof_sent = 0;
682  ff_AMediaCodec_flush(s->codec);
683  }
685  return ret;
686 }
687 
689 {
690  MediaCodecEncContext *s = avctx->priv_data;
691  if (s->codec) {
692  ff_AMediaCodec_stop(s->codec);
693  ff_AMediaCodec_delete(s->codec);
694  s->codec = NULL;
695  }
696 
697  if (s->window) {
698  ff_mediacodec_surface_unref(s->window, avctx);
699  s->window = NULL;
700  }
701 
702  av_bsf_free(&s->bsf);
703  av_frame_free(&s->frame);
704 
705  return 0;
706 }
707 
709 {
710  MediaCodecEncContext *s = avctx->priv_data;
711  if (s->bsf)
712  av_bsf_flush(s->bsf);
713  av_frame_unref(s->frame);
714  ff_AMediaCodec_flush(s->codec);
715 }
716 
718  &(const AVCodecHWConfigInternal) {
719  .public = {
723  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
724  },
725  .hwaccel = NULL,
726  },
727  NULL
728 };
729 
730 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
731 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
732 #define COMMON_OPTION \
733  { "ndk_codec", "Use MediaCodec from NDK", \
734  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
735  { "codec_name", "Select codec by name", \
736  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
737  { "bitrate_mode", "Bitrate control method", \
738  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode" }, \
739  { "cq", "Constant quality mode", \
740  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, .unit = "bitrate_mode" }, \
741  { "vbr", "Variable bitrate mode", \
742  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
743  { "cbr", "Constant bitrate mode", \
744  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
745  { "cbr_fd", "Constant bitrate mode with frame drops", \
746  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, .unit = "bitrate_mode" }, \
747  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
748  "since most of Android devices don't output B frames by default.", \
749  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
750 
751 
752 #define MEDIACODEC_ENCODER_CLASS(name) \
753 static const AVClass name ## _mediacodec_class = { \
754  .class_name = #name "_mediacodec", \
755  .item_name = av_default_item_name, \
756  .option = name ## _options, \
757  .version = LIBAVUTIL_VERSION_INT, \
758 }; \
759 
760 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
761 MEDIACODEC_ENCODER_CLASS(short_name) \
762 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
763  .p.name = #short_name "_mediacodec", \
764  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
765  .p.type = AVMEDIA_TYPE_VIDEO, \
766  .p.id = codec_id, \
767  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
768  AV_CODEC_CAP_HARDWARE | \
769  AV_CODEC_CAP_ENCODER_FLUSH, \
770  .priv_data_size = sizeof(MediaCodecEncContext), \
771  .p.pix_fmts = avc_pix_fmts, \
772  .init = mediacodec_init, \
773  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
774  .close = mediacodec_close, \
775  .flush = mediacodec_flush, \
776  .p.priv_class = &short_name ## _mediacodec_class, \
777  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
778  .p.wrapper_name = "mediacodec", \
779  .hw_configs = mediacodec_hw_configs, \
780 }; \
781 
782 #if CONFIG_H264_MEDIACODEC_ENCODER
783 
784 enum MediaCodecAvcLevel {
785  AVCLevel1 = 0x01,
786  AVCLevel1b = 0x02,
787  AVCLevel11 = 0x04,
788  AVCLevel12 = 0x08,
789  AVCLevel13 = 0x10,
790  AVCLevel2 = 0x20,
791  AVCLevel21 = 0x40,
792  AVCLevel22 = 0x80,
793  AVCLevel3 = 0x100,
794  AVCLevel31 = 0x200,
795  AVCLevel32 = 0x400,
796  AVCLevel4 = 0x800,
797  AVCLevel41 = 0x1000,
798  AVCLevel42 = 0x2000,
799  AVCLevel5 = 0x4000,
800  AVCLevel51 = 0x8000,
801  AVCLevel52 = 0x10000,
802  AVCLevel6 = 0x20000,
803  AVCLevel61 = 0x40000,
804  AVCLevel62 = 0x80000,
805 };
806 
807 static const AVOption h264_options[] = {
809 
811  FF_AVCTX_PROFILE_OPTION("constrained_baseline", NULL, VIDEO, AV_PROFILE_H264_CONSTRAINED_BASELINE)
818 
819  { "level", "Specify level",
820  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
821  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, .unit = "level" },
822  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, .unit = "level" },
823  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, .unit = "level" },
824  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, .unit = "level" },
825  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, .unit = "level" },
826  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, .unit = "level" },
827  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, .unit = "level" },
828  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, .unit = "level" },
829  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, .unit = "level" },
830  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, .unit = "level" },
831  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, .unit = "level" },
832  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, .unit = "level" },
833  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, .unit = "level" },
834  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, .unit = "level" },
835  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, .unit = "level" },
836  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, .unit = "level" },
837  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, .unit = "level" },
838  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, .unit = "level" },
839  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, .unit = "level" },
840  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, .unit = "level" },
841  { NULL, }
842 };
843 
845 
846 #endif // CONFIG_H264_MEDIACODEC_ENCODER
847 
848 #if CONFIG_HEVC_MEDIACODEC_ENCODER
849 
850 enum MediaCodecHevcLevel {
851  HEVCMainTierLevel1 = 0x1,
852  HEVCHighTierLevel1 = 0x2,
853  HEVCMainTierLevel2 = 0x4,
854  HEVCHighTierLevel2 = 0x8,
855  HEVCMainTierLevel21 = 0x10,
856  HEVCHighTierLevel21 = 0x20,
857  HEVCMainTierLevel3 = 0x40,
858  HEVCHighTierLevel3 = 0x80,
859  HEVCMainTierLevel31 = 0x100,
860  HEVCHighTierLevel31 = 0x200,
861  HEVCMainTierLevel4 = 0x400,
862  HEVCHighTierLevel4 = 0x800,
863  HEVCMainTierLevel41 = 0x1000,
864  HEVCHighTierLevel41 = 0x2000,
865  HEVCMainTierLevel5 = 0x4000,
866  HEVCHighTierLevel5 = 0x8000,
867  HEVCMainTierLevel51 = 0x10000,
868  HEVCHighTierLevel51 = 0x20000,
869  HEVCMainTierLevel52 = 0x40000,
870  HEVCHighTierLevel52 = 0x80000,
871  HEVCMainTierLevel6 = 0x100000,
872  HEVCHighTierLevel6 = 0x200000,
873  HEVCMainTierLevel61 = 0x400000,
874  HEVCHighTierLevel61 = 0x800000,
875  HEVCMainTierLevel62 = 0x1000000,
876  HEVCHighTierLevel62 = 0x2000000,
877 };
878 
879 static const AVOption hevc_options[] = {
881 
884 
885  { "level", "Specify tier and level",
886  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
887  { "m1", "Main tier level 1",
888  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, .unit = "level" },
889  { "h1", "High tier level 1",
890  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, .unit = "level" },
891  { "m2", "Main tier level 2",
892  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, .unit = "level" },
893  { "h2", "High tier level 2",
894  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, .unit = "level" },
895  { "m2.1", "Main tier level 2.1",
896  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, .unit = "level" },
897  { "h2.1", "High tier level 2.1",
898  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, .unit = "level" },
899  { "m3", "Main tier level 3",
900  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, .unit = "level" },
901  { "h3", "High tier level 3",
902  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, .unit = "level" },
903  { "m3.1", "Main tier level 3.1",
904  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, .unit = "level" },
905  { "h3.1", "High tier level 3.1",
906  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, .unit = "level" },
907  { "m4", "Main tier level 4",
908  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, .unit = "level" },
909  { "h4", "High tier level 4",
910  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, .unit = "level" },
911  { "m4.1", "Main tier level 4.1",
912  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, .unit = "level" },
913  { "h4.1", "High tier level 4.1",
914  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, .unit = "level" },
915  { "m5", "Main tier level 5",
916  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, .unit = "level" },
917  { "h5", "High tier level 5",
918  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, .unit = "level" },
919  { "m5.1", "Main tier level 5.1",
920  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, .unit = "level" },
921  { "h5.1", "High tier level 5.1",
922  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, .unit = "level" },
923  { "m5.2", "Main tier level 5.2",
924  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, .unit = "level" },
925  { "h5.2", "High tier level 5.2",
926  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, .unit = "level" },
927  { "m6", "Main tier level 6",
928  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, .unit = "level" },
929  { "h6", "High tier level 6",
930  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, .unit = "level" },
931  { "m6.1", "Main tier level 6.1",
932  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, .unit = "level" },
933  { "h6.1", "High tier level 6.1",
934  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, .unit = "level" },
935  { "m6.2", "Main tier level 6.2",
936  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, .unit = "level" },
937  { "h6.2", "High tier level 6.2",
938  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, .unit = "level" },
939  { NULL, }
940 };
941 
943 
944 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
945 
946 #if CONFIG_VP8_MEDIACODEC_ENCODER
947 
948 enum MediaCodecVP8Level {
949  VP8Level_Version0 = 0x01,
950  VP8Level_Version1 = 0x02,
951  VP8Level_Version2 = 0x04,
952  VP8Level_Version3 = 0x08,
953 };
954 
955 static const AVOption vp8_options[] = {
957  { "level", "Specify tier and level",
958  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
959  { "V0", "Level Version 0",
960  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version0 }, 0, 0, VE, .unit = "level" },
961  { "V1", "Level Version 1",
962  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version1 }, 0, 0, VE, .unit = "level" },
963  { "V2", "Level Version 2",
964  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version2 }, 0, 0, VE, .unit = "level" },
965  { "V3", "Level Version 3",
966  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version3 }, 0, 0, VE, .unit = "level" },
967  { NULL, }
968 };
969 
971 
972 #endif // CONFIG_VP8_MEDIACODEC_ENCODER
973 
974 #if CONFIG_VP9_MEDIACODEC_ENCODER
975 
976 enum MediaCodecVP9Level {
977  VP9Level1 = 0x1,
978  VP9Level11 = 0x2,
979  VP9Level2 = 0x4,
980  VP9Level21 = 0x8,
981  VP9Level3 = 0x10,
982  VP9Level31 = 0x20,
983  VP9Level4 = 0x40,
984  VP9Level41 = 0x80,
985  VP9Level5 = 0x100,
986  VP9Level51 = 0x200,
987  VP9Level52 = 0x400,
988  VP9Level6 = 0x800,
989  VP9Level61 = 0x1000,
990  VP9Level62 = 0x2000,
991 };
992 
993 static const AVOption vp9_options[] = {
995 
996  FF_AVCTX_PROFILE_OPTION("profile0", NULL, VIDEO, AV_PROFILE_VP9_0)
997  FF_AVCTX_PROFILE_OPTION("profile1", NULL, VIDEO, AV_PROFILE_VP9_1)
998  FF_AVCTX_PROFILE_OPTION("profile2", NULL, VIDEO, AV_PROFILE_VP9_2)
999  FF_AVCTX_PROFILE_OPTION("profile3", NULL, VIDEO, AV_PROFILE_VP9_3)
1000 
1001  { "level", "Specify tier and level",
1002  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1003  { "1", "Level 1",
1004  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, .unit = "level" },
1005  { "1.1", "Level 1.1",
1006  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, .unit = "level" },
1007  { "2", "Level 2",
1008  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, .unit = "level" },
1009  { "2.1", "Level 2.1",
1010  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, .unit = "level" },
1011  { "3", "Level 3",
1012  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, .unit = "level" },
1013  { "3.1", "Level 3.1",
1014  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, .unit = "level" },
1015  { "4", "Level 4",
1016  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, .unit = "level" },
1017  { "4.1", "Level 4.1",
1018  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, .unit = "level" },
1019  { "5", "Level 5",
1020  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, .unit = "level" },
1021  { "5.1", "Level 5.1",
1022  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, .unit = "level" },
1023  { "5.2", "Level 5.2",
1024  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, .unit = "level" },
1025  { "6", "Level 6",
1026  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, .unit = "level" },
1027  { "6.1", "Level 4.1",
1028  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, .unit = "level" },
1029  { "6.2", "Level 6.2",
1030  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, .unit = "level" },
1031  { NULL, }
1032 };
1033 
1035 
1036 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
1037 
1038 #if CONFIG_MPEG4_MEDIACODEC_ENCODER
1039 
1040 enum MediaCodecMpeg4Level {
1041  MPEG4Level0 = 0x01,
1042  MPEG4Level0b = 0x02,
1043  MPEG4Level1 = 0x04,
1044  MPEG4Level2 = 0x08,
1045  MPEG4Level3 = 0x10,
1046  MPEG4Level3b = 0x18,
1047  MPEG4Level4 = 0x20,
1048  MPEG4Level4a = 0x40,
1049  MPEG4Level5 = 0x80,
1050  MPEG4Level6 = 0x100,
1051 };
1052 
1053 static const AVOption mpeg4_options[] = {
1055 
1057 
1058  { "level", "Specify tier and level",
1059  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1060  { "0", "Level 0",
1061  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, .unit = "level" },
1062  { "0b", "Level 0b",
1063  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, .unit = "level" },
1064  { "1", "Level 1",
1065  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, .unit = "level" },
1066  { "2", "Level 2",
1067  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, .unit = "level" },
1068  { "3", "Level 3",
1069  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, .unit = "level" },
1070  { "3b", "Level 3b",
1071  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, .unit = "level" },
1072  { "4", "Level 4",
1073  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, .unit = "level" },
1074  { "4a", "Level 4a",
1075  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, .unit = "level" },
1076  { "5", "Level 5",
1077  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, .unit = "level" },
1078  { "6", "Level 6",
1079  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, .unit = "level" },
1080  { NULL, }
1081 };
1082 
1084 
1085 #endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
1086 
1087 #if CONFIG_AV1_MEDIACODEC_ENCODER
1088 
1089 enum MediaCodecAV1Level {
1090  AV1Level2 = 0x1,
1091  AV1Level21 = 0x2,
1092  AV1Level22 = 0x4,
1093  AV1Level23 = 0x8,
1094  AV1Level3 = 0x10,
1095  AV1Level31 = 0x20,
1096  AV1Level32 = 0x40,
1097  AV1Level33 = 0x80,
1098  AV1Level4 = 0x100,
1099  AV1Level41 = 0x200,
1100  AV1Level42 = 0x400,
1101  AV1Level43 = 0x800,
1102  AV1Level5 = 0x1000,
1103  AV1Level51 = 0x2000,
1104  AV1Level52 = 0x4000,
1105  AV1Level53 = 0x8000,
1106  AV1Level6 = 0x10000,
1107  AV1Level61 = 0x20000,
1108  AV1Level62 = 0x40000,
1109  AV1Level63 = 0x80000,
1110  AV1Level7 = 0x100000,
1111  AV1Level71 = 0x200000,
1112  AV1Level72 = 0x400000,
1113  AV1Level73 = 0x800000,
1114 };
1115 
1116 static const AVOption av1_options[] = {
1118 
1120 
1121  { "level", "Specify tier and level",
1122  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1123  { "2", "Level 2",
1124  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, .unit = "level" },
1125  { "2.1", "Level 2.1",
1126  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, .unit = "level" },
1127  { "2.2", "Level 2.2",
1128  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, .unit = "level" },
1129  { "2.3", "Level 2.3",
1130  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, .unit = "level" },
1131  { "3", "Level 3",
1132  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, .unit = "level" },
1133  { "3.1", "Level 3.1",
1134  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, .unit = "level" },
1135  { "3.2", "Level 3.2",
1136  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, .unit = "level" },
1137  { "3.3", "Level 3.3",
1138  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, .unit = "level" },
1139  { "4", "Level 4",
1140  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, .unit = "level" },
1141  { "4.1", "Level 4.1",
1142  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, .unit = "level" },
1143  { "4.2", "Level 4.2",
1144  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, .unit = "level" },
1145  { "4.3", "Level 4.3",
1146  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, .unit = "level" },
1147  { "5", "Level 5",
1148  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, .unit = "level" },
1149  { "5.1", "Level 5.1",
1150  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, .unit = "level" },
1151  { "5.2", "Level 5.2",
1152  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, .unit = "level" },
1153  { "5.3", "Level 5.3",
1154  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, .unit = "level" },
1155  { "6", "Level 6",
1156  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, .unit = "level" },
1157  { "6.1", "Level 6.1",
1158  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, .unit = "level" },
1159  { "6.2", "Level 6.2",
1160  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, .unit = "level" },
1161  { "6.3", "Level 6.3",
1162  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, .unit = "level" },
1163  { "7", "Level 7",
1164  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, .unit = "level" },
1165  { "7.1", "Level 7.1",
1166  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, .unit = "level" },
1167  { "7.2", "Level 7.2",
1168  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, .unit = "level" },
1169  { "7.3", "Level 7.3",
1170  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, .unit = "level" },
1171  { NULL, }
1172 };
1173 
1175 
1176 #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
hwconfig.h
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
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:760
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
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
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:154
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:55
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:64
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:158
out_size
int out_size
Definition: movenc.c:56
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
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:524
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:150
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
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:346
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:732
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:539
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:579
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:585
VE
#define VE
Definition: mediacodecenc.c:731
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:112
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
bsf.h
mediacodec_flush
static av_cold void mediacodec_flush(AVCodecContext *avctx)
Definition: mediacodecenc.c:708
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1533
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:688
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:156
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:490
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
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:82
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
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
AV_PROFILE_H264_HIGH_10
#define AV_PROFILE_H264_HIGH_10
Definition: defs.h:114
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:730
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:117
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:638
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
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:159
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
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:83
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:121
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:616
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:523
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:530
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:41
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:331
color_formats
static const struct @147 color_formats[]
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:517
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:155
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:109
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:113
mediacodec_init
static av_cold int mediacodec_init(AVCodecContext *avctx)
Definition: mediacodecenc.c:184
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:235
AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition: defs.h:110
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:153
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:120
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:501
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
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:717
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:244
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:463
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:84
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:388
mediacodec.h
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:86