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] = {0};
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  if (avctx->codec_id == AV_CODEC_ID_AV1) {
433  // Skip AV1CodecConfigurationRecord without configOBUs
434  if (out_info.size <= 4) {
436  return mediacodec_receive(avctx, pkt);
437  }
438  out_info.size -= 4;
439  out_info.offset += 4;
440  }
441 
442  ret = av_reallocp(&s->extradata, out_info.size);
443  if (ret)
444  goto bailout;
445 
446  s->extradata_size = out_info.size;
447  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
449  // try immediately
450  return mediacodec_receive(avctx, pkt);
451  }
452 
453  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
454  if (ret < 0)
455  goto bailout;
456 
457  if (s->extradata_size) {
458  extradata_size = s->extradata_size;
459  s->extradata_size = 0;
460  memcpy(pkt->data, s->extradata, extradata_size);
461  }
462  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
464  if (s->pts_as_dts)
465  pkt->dts = pkt->pts;
466  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
468  ret = 0;
469 
470  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
471  " flags %d extradata %d\n",
472  pkt->pts, pkt->dts, pkt->flags, extradata_size);
473 
474 bailout:
476  return ret;
477 }
478 
479 static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
480 {
481  MediaCodecEncContext *s = avctx->priv_data;
482  uint8_t *dst_data[4] = {};
483  int dst_linesize[4] = {};
484 
485  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
486  dst_data[0] = dst;
487  dst_data[1] = dst + s->width * s->height;
488  dst_data[2] = dst_data[1] + s->width * s->height / 4;
489 
490  dst_linesize[0] = s->width;
491  dst_linesize[1] = dst_linesize[2] = s->width / 2;
492  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
493  dst_data[0] = dst;
494  dst_data[1] = dst + s->width * s->height;
495 
496  dst_linesize[0] = s->width;
497  dst_linesize[1] = s->width;
498  } else {
499  av_assert0(0);
500  }
501 
502  av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
503  avctx->pix_fmt, avctx->width, avctx->height);
504 }
505 
506 static int mediacodec_send(AVCodecContext *avctx,
507  const AVFrame *frame) {
508  MediaCodecEncContext *s = avctx->priv_data;
509  FFAMediaCodec *codec = s->codec;
510  ssize_t index;
511  uint8_t *input_buf = NULL;
512  size_t input_size = 0;
513  int64_t pts = 0;
514  uint32_t flags = 0;
515  int64_t timeout_us;
516 
517  if (s->eof_sent)
518  return 0;
519 
520  if (s->window) {
521  if (!frame) {
522  s->eof_sent = 1;
524  }
525 
526  if (frame->data[3])
527  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
528  return 0;
529  }
530 
531  timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
532  index = ff_AMediaCodec_dequeueInputBuffer(codec, timeout_us);
534  return AVERROR(EAGAIN);
535 
536  if (index < 0) {
537  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
538  return AVERROR_EXTERNAL;
539  }
540 
541  if (frame) {
542  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
543  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
544 
545  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
546  } else {
548  s->eof_sent = 1;
549  }
550 
551  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
552  return 0;
553 }
554 
556 {
557  MediaCodecEncContext *s = avctx->priv_data;
558  int ret;
559 
560  // Return on three case:
561  // 1. Serious error
562  // 2. Got a packet success
563  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
564  while (1) {
565  if (s->bsf) {
566  ret = av_bsf_receive_packet(s->bsf, pkt);
567  if (!ret)
568  return 0;
569  if (ret != AVERROR(EAGAIN))
570  return ret;
571  }
572 
573  ret = mediacodec_receive(avctx, pkt);
574  if (s->bsf) {
575  if (!ret || ret == AVERROR_EOF)
576  ret = av_bsf_send_packet(s->bsf, pkt);
577  } else {
578  if (!ret)
579  return 0;
580  }
581 
582  if (ret < 0 && ret != AVERROR(EAGAIN))
583  return ret;
584 
585  if (!s->frame->buf[0]) {
586  ret = ff_encode_get_frame(avctx, s->frame);
587  if (ret && ret != AVERROR_EOF)
588  return ret;
589  }
590 
591  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
592  if (!ret)
593  av_frame_unref(s->frame);
594  else if (ret != AVERROR(EAGAIN))
595  return ret;
596  }
597 
598  return 0;
599 }
600 
602 {
603  MediaCodecEncContext *s = avctx->priv_data;
604  int ret;
605 
606  s->frame->width = avctx->width;
607  s->frame->height = avctx->height;
608  s->frame->format = avctx->pix_fmt;
609  s->frame->pts = 0;
610 
611  ret = av_frame_get_buffer(s->frame, 0);
612  if (ret < 0)
613  return ret;
614 
615  do {
616  ret = mediacodec_send(avctx, s->frame);
617  } while (ret == AVERROR(EAGAIN));
618  av_frame_unref(s->frame);
619 
620  if (ret < 0)
621  return ret;
622 
623  ret = mediacodec_send(avctx, NULL);
624  if (ret < 0) {
625  av_log(avctx, AV_LOG_ERROR, "Flush failed: %s\n", av_err2str(ret));
626  return ret;
627  }
628 
629  return 0;
630 }
631 
633 {
634  MediaCodecEncContext *s = avctx->priv_data;
635  int ret;
636 
637  do {
638  ret = mediacodec_receive(avctx, pkt);
639  } while (ret == AVERROR(EAGAIN));
640 
641  if (ret < 0)
642  return ret;
643 
644  do {
645  ret = av_bsf_send_packet(s->bsf, pkt);
646  if (ret < 0)
647  return ret;
648  ret = av_bsf_receive_packet(s->bsf, pkt);
649  } while (ret == AVERROR(EAGAIN));
650 
651  return ret;
652 }
653 
655 {
656  MediaCodecEncContext *s = avctx->priv_data;
657  AVPacket *pkt = NULL;
658  int ret;
659  size_t side_size;
660  uint8_t *side;
661 
662  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
663  return 0;
664 
665  if (!s->extract_extradata) {
666  av_log(avctx, AV_LOG_WARNING,
667  "Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. "
668  "Use extract_extradata bsf when necessary.\n");
669  return 0;
670  }
671 
672  pkt = av_packet_alloc();
673  if (!pkt)
674  return AVERROR(ENOMEM);
675 
677  if (ret < 0)
678  goto bailout;
680  if (ret < 0)
681  goto bailout;
682 
684  if (side && side_size > 0) {
685  avctx->extradata = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
686  if (!avctx->extradata) {
687  ret = AVERROR(ENOMEM);
688  goto bailout;
689  }
690 
691  memcpy(avctx->extradata, side, side_size);
692  avctx->extradata_size = side_size;
693  }
694 
695 bailout:
696  if (s->eof_sent) {
697  s->eof_sent = 0;
698  ff_AMediaCodec_flush(s->codec);
699  }
700  av_bsf_flush(s->bsf);
702  return ret;
703 }
704 
706 {
707  MediaCodecEncContext *s = avctx->priv_data;
708  if (s->codec) {
709  ff_AMediaCodec_stop(s->codec);
710  ff_AMediaCodec_delete(s->codec);
711  s->codec = NULL;
712  }
713 
714  if (s->window) {
715  ff_mediacodec_surface_unref(s->window, avctx);
716  s->window = NULL;
717  }
718 
719  av_bsf_free(&s->bsf);
720  av_frame_free(&s->frame);
721 
722  return 0;
723 }
724 
726 {
727  MediaCodecEncContext *s = avctx->priv_data;
728  if (s->bsf)
729  av_bsf_flush(s->bsf);
730  av_frame_unref(s->frame);
731  ff_AMediaCodec_flush(s->codec);
732 }
733 
735  &(const AVCodecHWConfigInternal) {
736  .public = {
740  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
741  },
742  .hwaccel = NULL,
743  },
744  NULL
745 };
746 
747 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
748 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
749 #define COMMON_OPTION \
750  { "ndk_codec", "Use MediaCodec from NDK", \
751  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
752  { "codec_name", "Select codec by name", \
753  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
754  { "bitrate_mode", "Bitrate control method", \
755  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode" }, \
756  { "cq", "Constant quality mode", \
757  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, .unit = "bitrate_mode" }, \
758  { "vbr", "Variable bitrate mode", \
759  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
760  { "cbr", "Constant bitrate mode", \
761  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
762  { "cbr_fd", "Constant bitrate mode with frame drops", \
763  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, .unit = "bitrate_mode" }, \
764  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
765  "since most of Android devices don't output B frames by default.", \
766  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
767 
768 
769 #define MEDIACODEC_ENCODER_CLASS(name) \
770 static const AVClass name ## _mediacodec_class = { \
771  .class_name = #name "_mediacodec", \
772  .item_name = av_default_item_name, \
773  .option = name ## _options, \
774  .version = LIBAVUTIL_VERSION_INT, \
775 }; \
776 
777 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
778 MEDIACODEC_ENCODER_CLASS(short_name) \
779 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
780  .p.name = #short_name "_mediacodec", \
781  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
782  .p.type = AVMEDIA_TYPE_VIDEO, \
783  .p.id = codec_id, \
784  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
785  AV_CODEC_CAP_HARDWARE | \
786  AV_CODEC_CAP_ENCODER_FLUSH, \
787  .priv_data_size = sizeof(MediaCodecEncContext), \
788  .p.pix_fmts = avc_pix_fmts, \
789  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
790  .init = mediacodec_init, \
791  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
792  .close = mediacodec_close, \
793  .flush = mediacodec_flush, \
794  .p.priv_class = &short_name ## _mediacodec_class, \
795  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
796  .p.wrapper_name = "mediacodec", \
797  .hw_configs = mediacodec_hw_configs, \
798 }; \
799 
800 #if CONFIG_H264_MEDIACODEC_ENCODER
801 
802 enum MediaCodecAvcLevel {
803  AVCLevel1 = 0x01,
804  AVCLevel1b = 0x02,
805  AVCLevel11 = 0x04,
806  AVCLevel12 = 0x08,
807  AVCLevel13 = 0x10,
808  AVCLevel2 = 0x20,
809  AVCLevel21 = 0x40,
810  AVCLevel22 = 0x80,
811  AVCLevel3 = 0x100,
812  AVCLevel31 = 0x200,
813  AVCLevel32 = 0x400,
814  AVCLevel4 = 0x800,
815  AVCLevel41 = 0x1000,
816  AVCLevel42 = 0x2000,
817  AVCLevel5 = 0x4000,
818  AVCLevel51 = 0x8000,
819  AVCLevel52 = 0x10000,
820  AVCLevel6 = 0x20000,
821  AVCLevel61 = 0x40000,
822  AVCLevel62 = 0x80000,
823 };
824 
825 static const AVOption h264_options[] = {
827 
829  FF_AVCTX_PROFILE_OPTION("constrained_baseline", NULL, VIDEO, AV_PROFILE_H264_CONSTRAINED_BASELINE)
836 
837  { "level", "Specify level",
838  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
839  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, .unit = "level" },
840  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, .unit = "level" },
841  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, .unit = "level" },
842  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, .unit = "level" },
843  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, .unit = "level" },
844  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, .unit = "level" },
845  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, .unit = "level" },
846  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, .unit = "level" },
847  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, .unit = "level" },
848  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, .unit = "level" },
849  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, .unit = "level" },
850  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, .unit = "level" },
851  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, .unit = "level" },
852  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, .unit = "level" },
853  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, .unit = "level" },
854  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, .unit = "level" },
855  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, .unit = "level" },
856  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, .unit = "level" },
857  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, .unit = "level" },
858  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, .unit = "level" },
859  { NULL, }
860 };
861 
863 
864 #endif // CONFIG_H264_MEDIACODEC_ENCODER
865 
866 #if CONFIG_HEVC_MEDIACODEC_ENCODER
867 
868 enum MediaCodecHevcLevel {
869  HEVCMainTierLevel1 = 0x1,
870  HEVCHighTierLevel1 = 0x2,
871  HEVCMainTierLevel2 = 0x4,
872  HEVCHighTierLevel2 = 0x8,
873  HEVCMainTierLevel21 = 0x10,
874  HEVCHighTierLevel21 = 0x20,
875  HEVCMainTierLevel3 = 0x40,
876  HEVCHighTierLevel3 = 0x80,
877  HEVCMainTierLevel31 = 0x100,
878  HEVCHighTierLevel31 = 0x200,
879  HEVCMainTierLevel4 = 0x400,
880  HEVCHighTierLevel4 = 0x800,
881  HEVCMainTierLevel41 = 0x1000,
882  HEVCHighTierLevel41 = 0x2000,
883  HEVCMainTierLevel5 = 0x4000,
884  HEVCHighTierLevel5 = 0x8000,
885  HEVCMainTierLevel51 = 0x10000,
886  HEVCHighTierLevel51 = 0x20000,
887  HEVCMainTierLevel52 = 0x40000,
888  HEVCHighTierLevel52 = 0x80000,
889  HEVCMainTierLevel6 = 0x100000,
890  HEVCHighTierLevel6 = 0x200000,
891  HEVCMainTierLevel61 = 0x400000,
892  HEVCHighTierLevel61 = 0x800000,
893  HEVCMainTierLevel62 = 0x1000000,
894  HEVCHighTierLevel62 = 0x2000000,
895 };
896 
897 static const AVOption hevc_options[] = {
899 
902 
903  { "level", "Specify tier and level",
904  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
905  { "m1", "Main tier level 1",
906  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, .unit = "level" },
907  { "h1", "High tier level 1",
908  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, .unit = "level" },
909  { "m2", "Main tier level 2",
910  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, .unit = "level" },
911  { "h2", "High tier level 2",
912  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, .unit = "level" },
913  { "m2.1", "Main tier level 2.1",
914  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, .unit = "level" },
915  { "h2.1", "High tier level 2.1",
916  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, .unit = "level" },
917  { "m3", "Main tier level 3",
918  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, .unit = "level" },
919  { "h3", "High tier level 3",
920  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, .unit = "level" },
921  { "m3.1", "Main tier level 3.1",
922  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, .unit = "level" },
923  { "h3.1", "High tier level 3.1",
924  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, .unit = "level" },
925  { "m4", "Main tier level 4",
926  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, .unit = "level" },
927  { "h4", "High tier level 4",
928  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, .unit = "level" },
929  { "m4.1", "Main tier level 4.1",
930  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, .unit = "level" },
931  { "h4.1", "High tier level 4.1",
932  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, .unit = "level" },
933  { "m5", "Main tier level 5",
934  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, .unit = "level" },
935  { "h5", "High tier level 5",
936  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, .unit = "level" },
937  { "m5.1", "Main tier level 5.1",
938  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, .unit = "level" },
939  { "h5.1", "High tier level 5.1",
940  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, .unit = "level" },
941  { "m5.2", "Main tier level 5.2",
942  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, .unit = "level" },
943  { "h5.2", "High tier level 5.2",
944  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, .unit = "level" },
945  { "m6", "Main tier level 6",
946  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, .unit = "level" },
947  { "h6", "High tier level 6",
948  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, .unit = "level" },
949  { "m6.1", "Main tier level 6.1",
950  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, .unit = "level" },
951  { "h6.1", "High tier level 6.1",
952  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, .unit = "level" },
953  { "m6.2", "Main tier level 6.2",
954  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, .unit = "level" },
955  { "h6.2", "High tier level 6.2",
956  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, .unit = "level" },
957  { NULL, }
958 };
959 
961 
962 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
963 
964 #if CONFIG_VP8_MEDIACODEC_ENCODER
965 
966 enum MediaCodecVP8Level {
967  VP8Level_Version0 = 0x01,
968  VP8Level_Version1 = 0x02,
969  VP8Level_Version2 = 0x04,
970  VP8Level_Version3 = 0x08,
971 };
972 
973 static const AVOption vp8_options[] = {
975  { "level", "Specify tier and level",
976  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
977  { "V0", "Level Version 0",
978  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version0 }, 0, 0, VE, .unit = "level" },
979  { "V1", "Level Version 1",
980  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version1 }, 0, 0, VE, .unit = "level" },
981  { "V2", "Level Version 2",
982  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version2 }, 0, 0, VE, .unit = "level" },
983  { "V3", "Level Version 3",
984  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version3 }, 0, 0, VE, .unit = "level" },
985  { NULL, }
986 };
987 
989 
990 #endif // CONFIG_VP8_MEDIACODEC_ENCODER
991 
992 #if CONFIG_VP9_MEDIACODEC_ENCODER
993 
994 enum MediaCodecVP9Level {
995  VP9Level1 = 0x1,
996  VP9Level11 = 0x2,
997  VP9Level2 = 0x4,
998  VP9Level21 = 0x8,
999  VP9Level3 = 0x10,
1000  VP9Level31 = 0x20,
1001  VP9Level4 = 0x40,
1002  VP9Level41 = 0x80,
1003  VP9Level5 = 0x100,
1004  VP9Level51 = 0x200,
1005  VP9Level52 = 0x400,
1006  VP9Level6 = 0x800,
1007  VP9Level61 = 0x1000,
1008  VP9Level62 = 0x2000,
1009 };
1010 
1011 static const AVOption vp9_options[] = {
1013 
1014  FF_AVCTX_PROFILE_OPTION("profile0", NULL, VIDEO, AV_PROFILE_VP9_0)
1015  FF_AVCTX_PROFILE_OPTION("profile1", NULL, VIDEO, AV_PROFILE_VP9_1)
1016  FF_AVCTX_PROFILE_OPTION("profile2", NULL, VIDEO, AV_PROFILE_VP9_2)
1017  FF_AVCTX_PROFILE_OPTION("profile3", NULL, VIDEO, AV_PROFILE_VP9_3)
1018 
1019  { "level", "Specify tier and level",
1020  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1021  { "1", "Level 1",
1022  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, .unit = "level" },
1023  { "1.1", "Level 1.1",
1024  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, .unit = "level" },
1025  { "2", "Level 2",
1026  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, .unit = "level" },
1027  { "2.1", "Level 2.1",
1028  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, .unit = "level" },
1029  { "3", "Level 3",
1030  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, .unit = "level" },
1031  { "3.1", "Level 3.1",
1032  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, .unit = "level" },
1033  { "4", "Level 4",
1034  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, .unit = "level" },
1035  { "4.1", "Level 4.1",
1036  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, .unit = "level" },
1037  { "5", "Level 5",
1038  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, .unit = "level" },
1039  { "5.1", "Level 5.1",
1040  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, .unit = "level" },
1041  { "5.2", "Level 5.2",
1042  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, .unit = "level" },
1043  { "6", "Level 6",
1044  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, .unit = "level" },
1045  { "6.1", "Level 4.1",
1046  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, .unit = "level" },
1047  { "6.2", "Level 6.2",
1048  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, .unit = "level" },
1049  { NULL, }
1050 };
1051 
1053 
1054 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
1055 
1056 #if CONFIG_MPEG4_MEDIACODEC_ENCODER
1057 
1058 enum MediaCodecMpeg4Level {
1059  MPEG4Level0 = 0x01,
1060  MPEG4Level0b = 0x02,
1061  MPEG4Level1 = 0x04,
1062  MPEG4Level2 = 0x08,
1063  MPEG4Level3 = 0x10,
1064  MPEG4Level3b = 0x18,
1065  MPEG4Level4 = 0x20,
1066  MPEG4Level4a = 0x40,
1067  MPEG4Level5 = 0x80,
1068  MPEG4Level6 = 0x100,
1069 };
1070 
1071 static const AVOption mpeg4_options[] = {
1073 
1075 
1076  { "level", "Specify tier and level",
1077  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1078  { "0", "Level 0",
1079  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, .unit = "level" },
1080  { "0b", "Level 0b",
1081  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, .unit = "level" },
1082  { "1", "Level 1",
1083  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, .unit = "level" },
1084  { "2", "Level 2",
1085  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, .unit = "level" },
1086  { "3", "Level 3",
1087  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, .unit = "level" },
1088  { "3b", "Level 3b",
1089  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, .unit = "level" },
1090  { "4", "Level 4",
1091  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, .unit = "level" },
1092  { "4a", "Level 4a",
1093  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, .unit = "level" },
1094  { "5", "Level 5",
1095  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, .unit = "level" },
1096  { "6", "Level 6",
1097  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, .unit = "level" },
1098  { NULL, }
1099 };
1100 
1102 
1103 #endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
1104 
1105 #if CONFIG_AV1_MEDIACODEC_ENCODER
1106 
1107 enum MediaCodecAV1Level {
1108  AV1Level2 = 0x1,
1109  AV1Level21 = 0x2,
1110  AV1Level22 = 0x4,
1111  AV1Level23 = 0x8,
1112  AV1Level3 = 0x10,
1113  AV1Level31 = 0x20,
1114  AV1Level32 = 0x40,
1115  AV1Level33 = 0x80,
1116  AV1Level4 = 0x100,
1117  AV1Level41 = 0x200,
1118  AV1Level42 = 0x400,
1119  AV1Level43 = 0x800,
1120  AV1Level5 = 0x1000,
1121  AV1Level51 = 0x2000,
1122  AV1Level52 = 0x4000,
1123  AV1Level53 = 0x8000,
1124  AV1Level6 = 0x10000,
1125  AV1Level61 = 0x20000,
1126  AV1Level62 = 0x40000,
1127  AV1Level63 = 0x80000,
1128  AV1Level7 = 0x100000,
1129  AV1Level71 = 0x200000,
1130  AV1Level72 = 0x400000,
1131  AV1Level73 = 0x800000,
1132 };
1133 
1134 static const AVOption av1_options[] = {
1136 
1138 
1139  { "level", "Specify tier and level",
1140  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1141  { "2", "Level 2",
1142  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, .unit = "level" },
1143  { "2.1", "Level 2.1",
1144  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, .unit = "level" },
1145  { "2.2", "Level 2.2",
1146  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, .unit = "level" },
1147  { "2.3", "Level 2.3",
1148  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, .unit = "level" },
1149  { "3", "Level 3",
1150  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, .unit = "level" },
1151  { "3.1", "Level 3.1",
1152  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, .unit = "level" },
1153  { "3.2", "Level 3.2",
1154  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, .unit = "level" },
1155  { "3.3", "Level 3.3",
1156  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, .unit = "level" },
1157  { "4", "Level 4",
1158  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, .unit = "level" },
1159  { "4.1", "Level 4.1",
1160  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, .unit = "level" },
1161  { "4.2", "Level 4.2",
1162  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, .unit = "level" },
1163  { "4.3", "Level 4.3",
1164  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, .unit = "level" },
1165  { "5", "Level 5",
1166  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, .unit = "level" },
1167  { "5.1", "Level 5.1",
1168  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, .unit = "level" },
1169  { "5.2", "Level 5.2",
1170  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, .unit = "level" },
1171  { "5.3", "Level 5.3",
1172  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, .unit = "level" },
1173  { "6", "Level 6",
1174  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, .unit = "level" },
1175  { "6.1", "Level 6.1",
1176  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, .unit = "level" },
1177  { "6.2", "Level 6.2",
1178  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, .unit = "level" },
1179  { "6.3", "Level 6.3",
1180  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, .unit = "level" },
1181  { "7", "Level 7",
1182  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, .unit = "level" },
1183  { "7.1", "Level 7.1",
1184  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, .unit = "level" },
1185  { "7.2", "Level 7.2",
1186  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, .unit = "level" },
1187  { "7.3", "Level 7.3",
1188  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, .unit = "level" },
1189  { NULL, }
1190 };
1191 
1193 
1194 #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
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:1461
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:92
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h: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:691
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:292
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:777
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: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
int64_t
long long int64_t
Definition: coverity.c:34
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:162
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
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:684
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:62
AVPacket::data
uint8_t * data
Definition: packet.h:539
ff_AMediaFormat_setString
static void ff_AMediaFormat_setString(FFAMediaFormat *format, const char *name, const char *value)
Definition: mediacodec_wrapper.h:150
BitrateMode
BitrateMode
Definition: mediacodecenc.c:46
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:311
AVOption
AVOption.
Definition: opt.h:429
encode.h
ff_AMediaCodec_infoOutputBuffersChanged
static int ff_AMediaCodec_infoOutputBuffersChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h: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:749
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:555
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:594
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c: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:601
VE
#define VE
Definition: mediacodecenc.c:748
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:566
bsf.h
mediacodec_flush
static av_cold void mediacodec_flush(AVCodecContext *avctx)
Definition: mediacodecenc.c:725
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1561
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:705
MediaCodecEncContext::extradata
uint8_t * extradata
Definition: mediacodecenc.c:68
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
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
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:342
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:506
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
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:530
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:2970
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:1249
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:222
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:230
OFFSET
#define OFFSET(x)
Definition: mediacodecenc.c:747
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:354
AVBitStreamFilter::codec_ids
enum AVCodecID * codec_ids
A list of codec ids supported by the filter, terminated by AV_CODEC_ID_NONE.
Definition: bsf.h:119
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AV_PROFILE_H264_HIGH_422
#define AV_PROFILE_H264_HIGH_422
Definition: defs.h:118
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
MediaCodecEncContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecenc.c:60
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:316
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:83
mediacodec_generate_extradata
static int mediacodec_generate_extradata(AVCodecContext *avctx)
Definition: mediacodecenc.c:654
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:75
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
color_formats
static const struct @178 color_formats[]
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:701
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
FFAMediaCodecBufferInfo::size
int32_t size
Definition: mediacodec_wrapper.h:174
AVMediaCodecContext
This structure holds a reference to a android/view/Surface object that will be used as output by the ...
Definition: mediacodec.h:33
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:501
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
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:313
mpeg4_options
static const AVOption mpeg4_options[]
Definition: v4l2_m2m_enc.c:397
BITRATE_MODE_CBR
@ BITRATE_MODE_CBR
Definition: mediacodecenc.c: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:550
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1037
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1107
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h: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:632
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:538
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_AMediaCodecProfile_getProfileFromAVCodecContext
int ff_AMediaCodecProfile_getProfileFromAVCodecContext(AVCodecContext *avctx)
The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since ...
Definition: mediacodec_wrapper.c:309
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:61
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
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:532
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:529
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:228
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:610
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:1507
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:624
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:663
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:1389
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:451
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:114
mediacodec_init
static av_cold int mediacodec_init(AVCodecContext *avctx)
Definition: mediacodecenc.c: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
Underlying C type is int.
Definition: opt.h:259
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
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:82
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:801
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:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
ff_AMediaCodec_infoTryAgainLater
static int ff_AMediaCodec_infoTryAgainLater(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:301
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:624
imgutils.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_AMediaCodec_releaseOutputBuffer
static int ff_AMediaCodec_releaseOutputBuffer(FFAMediaCodec *codec, size_t idx, int render)
Definition: mediacodec_wrapper.h: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:734
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
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
copy_frame_to_buffer
static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
Definition: mediacodecenc.c:479
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:394
mediacodec.h
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:87