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"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/opt.h"
29 
30 #include "avcodec.h"
31 #include "bsf.h"
32 #include "codec_internal.h"
33 #include "encode.h"
34 #include "hwconfig.h"
35 #include "jni.h"
36 #include "mediacodec.h"
37 #include "mediacodec_wrapper.h"
38 #include "mediacodecdec_common.h"
39 
40 #define INPUT_DEQUEUE_TIMEOUT_US 8000
41 #define OUTPUT_DEQUEUE_TIMEOUT_US 8000
42 
44  /* Constant quality mode */
46  /* Variable bitrate mode */
48  /* Constant bitrate mode */
50  /* Constant bitrate mode with frame drops */
52 };
53 
54 typedef struct MediaCodecEncContext {
58  const char *name;
60 
61  int fps;
62  int width;
63  int height;
64 
65  uint8_t *extradata;
67  int eof_sent;
68 
71 
73  int level;
76 
77 enum {
80  COLOR_FormatSurface = 0x7F000789,
81 };
82 
83 static const struct {
86 } color_formats[] = {
90 };
91 
92 static const enum AVPixelFormat avc_pix_fmts[] = {
97 };
98 
100 {
101  MediaCodecEncContext *s = avctx->priv_data;
102  char *name = ff_AMediaCodec_getName(s->codec);
103  FFAMediaFormat *out_format = ff_AMediaCodec_getOutputFormat(s->codec);
104  char *str = ff_AMediaFormat_toString(out_format);
105 
106  av_log(avctx, AV_LOG_DEBUG, "MediaCodec encoder %s output format %s\n",
107  name ? name : "unknown", str);
108  av_free(name);
109  av_free(str);
110  ff_AMediaFormat_delete(out_format);
111 }
112 
114 {
115  MediaCodecEncContext *s = avctx->priv_data;
116  char str[128];
117  int ret;
118  int crop_right = s->width - avctx->width;
119  int crop_bottom = s->height - avctx->height;
120 
121  if (!crop_right && !crop_bottom)
122  return 0;
123 
124  if (avctx->codec_id == AV_CODEC_ID_H264)
125  ret = snprintf(str, sizeof(str), "h264_metadata=crop_right=%d:crop_bottom=%d",
126  crop_right, crop_bottom);
127  else if (avctx->codec_id == AV_CODEC_ID_HEVC)
128  ret = snprintf(str, sizeof(str), "hevc_metadata=crop_right=%d:crop_bottom=%d",
129  crop_right, crop_bottom);
130  else
131  return 0;
132 
133  if (ret >= sizeof(str))
135 
136  ret = av_bsf_list_parse_str(str, &s->bsf);
137  if (ret < 0)
138  return ret;
139 
140  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
141  if (ret < 0)
142  return ret;
143  s->bsf->time_base_in = avctx->time_base;
144  ret = av_bsf_init(s->bsf);
145 
146  return ret;
147 }
148 
150 {
151  const char *codec_mime = NULL;
152  MediaCodecEncContext *s = avctx->priv_data;
154  int ret;
155  int gop;
156 
157  if (s->use_ndk_codec < 0)
158  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
159 
160  switch (avctx->codec_id) {
161  case AV_CODEC_ID_H264:
162  codec_mime = "video/avc";
163  break;
164  case AV_CODEC_ID_HEVC:
165  codec_mime = "video/hevc";
166  break;
167  default:
168  av_assert0(0);
169  }
170 
171  if (s->name)
172  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
173  else
174  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
175  if (!s->codec) {
176  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
177  codec_mime);
178  return AVERROR_EXTERNAL;
179  }
180 
181  format = ff_AMediaFormat_new(s->use_ndk_codec);
182  if (!format) {
183  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
184  return AVERROR_EXTERNAL;
185  }
186 
187  ff_AMediaFormat_setString(format, "mime", codec_mime);
188  // Workaround the alignment requirement of mediacodec. We can't do it
189  // silently for AV_PIX_FMT_MEDIACODEC.
190  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC) {
191  s->width = FFALIGN(avctx->width, 16);
192  s->height = FFALIGN(avctx->height, 16);
193  } else {
194  s->width = avctx->width;
195  s->height = avctx->height;
196  if (s->width % 16 || s->height % 16)
197  av_log(avctx, AV_LOG_WARNING,
198  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
199  s->width, s->height);
200  }
201  ff_AMediaFormat_setInt32(format, "width", s->width);
202  ff_AMediaFormat_setInt32(format, "height", s->height);
203 
204  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
205  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
206  if (avctx->hw_device_ctx) {
207  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
208  AVMediaCodecDeviceContext *dev_ctx;
209 
210  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
211  ret = AVERROR(EINVAL);
212  goto bailout;
213  }
214  dev_ctx = device_ctx->hwctx;
215  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
216  }
217 
218  if (!s->window && user_ctx && user_ctx->surface)
219  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
220 
221  if (!s->window) {
222  ret = AVERROR(EINVAL);
223  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
224  goto bailout;
225  }
226  /* Although there is a method ANativeWindow_toSurface() introduced in
227  * API level 26, it's easier and safe to always require a Surface for
228  * Java MediaCodec.
229  */
230  if (!s->use_ndk_codec && !s->window->surface) {
231  ret = AVERROR(EINVAL);
232  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
233  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
234  goto bailout;
235  }
236  }
237 
238  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
239  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
240  ff_AMediaFormat_setInt32(format, "color-format",
242  break;
243  }
244  }
245 
248  ff_AMediaFormat_setInt32(format, "color-range", ret);
251  ff_AMediaFormat_setInt32(format, "color-standard", ret);
254  ff_AMediaFormat_setInt32(format, "color-transfer", ret);
255 
256  if (avctx->bit_rate)
257  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
258  if (s->bitrate_mode >= 0)
259  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
260  // frame-rate and i-frame-interval are required to configure codec
261  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
262  s->fps = avctx->framerate.num / avctx->framerate.den;
263  } else {
264  s->fps = 30;
265  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
266  }
267  gop = round(avctx->gop_size / s->fps);
268  if (gop == 0) {
269  gop = 1;
270  av_log(avctx, AV_LOG_INFO,
271  "Use %d as the default MediaFormat i-frame-interval, "
272  "please set gop_size properly (>= fps)\n", gop);
273  } else {
274  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
275  }
276 
277  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
278  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
279 
281  if (ret > 0) {
282  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
283  ff_AMediaFormat_setInt32(format, "profile", ret);
284  }
285  if (s->level > 0) {
286  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
287  ff_AMediaFormat_setInt32(format, "level", s->level);
288  }
289  if (avctx->max_b_frames > 0) {
291  av_log(avctx, AV_LOG_ERROR,
292  "Enabling B frames will produce packets with no DTS. "
293  "Use -strict experimental to use it anyway.\n");
294  ret = AVERROR(EINVAL);
295  goto bailout;
296  }
297  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
298  }
299  if (s->pts_as_dts == -1)
300  s->pts_as_dts = avctx->max_b_frames <= 0;
301 
303  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
304  if (ret) {
305  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
306  goto bailout;
307  }
308 
309  ret = ff_AMediaCodec_start(s->codec);
310  if (ret) {
311  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n", av_err2str(ret));
312  goto bailout;
313  }
314 
315  ret = mediacodec_init_bsf(avctx);
316  if (ret)
317  goto bailout;
318 
320 
321  s->frame = av_frame_alloc();
322  if (!s->frame)
323  ret = AVERROR(ENOMEM);
324 
325 bailout:
326  if (format)
328  return ret;
329 }
330 
332  AVPacket *pkt,
333  int *got_packet)
334 {
335  MediaCodecEncContext *s = avctx->priv_data;
336  FFAMediaCodec *codec = s->codec;
337  FFAMediaCodecBufferInfo out_info = {0};
338  uint8_t *out_buf;
339  size_t out_size = 0;
340  int ret;
341  int extradata_size = 0;
342  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
343  ssize_t index = ff_AMediaCodec_dequeueOutputBuffer(codec, &out_info, timeout_us);
344 
346  return AVERROR(EAGAIN);
347 
350  return AVERROR(EAGAIN);
351  }
352 
355  return AVERROR(EAGAIN);
356  }
357 
358  if (index < 0)
359  return AVERROR_EXTERNAL;
360 
361  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
362  return AVERROR_EOF;
363 
364  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
365  if (!out_buf) {
367  goto bailout;
368  }
369 
370  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
371  ret = av_reallocp(&s->extradata, out_info.size);
372  if (ret)
373  goto bailout;
374 
375  s->extradata_size = out_info.size;
376  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
378  // try immediately
379  return mediacodec_receive(avctx, pkt, got_packet);
380  }
381 
382  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
383  if (ret < 0)
384  goto bailout;
385 
386  if (s->extradata_size) {
387  extradata_size = s->extradata_size;
388  s->extradata_size = 0;
389  memcpy(pkt->data, s->extradata, extradata_size);
390  }
391  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
393  if (s->pts_as_dts)
394  pkt->dts = pkt->pts;
395  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
397  ret = 0;
398  *got_packet = 1;
399 
400  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
401  " flags %d extradata %d\n",
402  pkt->pts, pkt->dts, pkt->flags, extradata_size);
403 
404 bailout:
406  return ret;
407 }
408 
409 static void copy_frame_to_buffer(AVCodecContext *avctx, const AVFrame *frame, uint8_t *dst, size_t size)
410 {
411  MediaCodecEncContext *s = avctx->priv_data;
412  uint8_t *dst_data[4] = {};
413  int dst_linesize[4] = {};
414  const uint8_t *src_data[4] = {
415  frame->data[0], frame->data[1], frame->data[2], frame->data[3]
416  };
417 
418  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
419  dst_data[0] = dst;
420  dst_data[1] = dst + s->width * s->height;
421  dst_data[2] = dst_data[1] + s->width * s->height / 4;
422 
423  dst_linesize[0] = s->width;
424  dst_linesize[1] = dst_linesize[2] = s->width / 2;
425  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
426  dst_data[0] = dst;
427  dst_data[1] = dst + s->width * s->height;
428 
429  dst_linesize[0] = s->width;
430  dst_linesize[1] = s->width;
431  } else {
432  av_assert0(0);
433  }
434 
435  av_image_copy(dst_data, dst_linesize, src_data, frame->linesize,
436  avctx->pix_fmt, avctx->width, avctx->height);
437 }
438 
439 static int mediacodec_send(AVCodecContext *avctx,
440  const AVFrame *frame) {
441  MediaCodecEncContext *s = avctx->priv_data;
442  FFAMediaCodec *codec = s->codec;
443  ssize_t index;
444  uint8_t *input_buf = NULL;
445  size_t input_size = 0;
446  int64_t pts = 0;
447  uint32_t flags = 0;
448  int64_t timeout_us;
449 
450  if (s->eof_sent)
451  return 0;
452 
453  if (s->window) {
454  if (!frame) {
455  s->eof_sent = 1;
457  }
458 
459  if (frame->data[3])
460  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
461  return 0;
462  }
463 
464  timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
465  index = ff_AMediaCodec_dequeueInputBuffer(codec, timeout_us);
467  return AVERROR(EAGAIN);
468 
469  if (index < 0) {
470  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
471  return AVERROR_EXTERNAL;
472  }
473 
474  if (frame) {
475  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
476  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
477 
478  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
479  } else {
481  s->eof_sent = 1;
482  }
483 
484  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
485  return 0;
486 }
487 
489 {
490  MediaCodecEncContext *s = avctx->priv_data;
491  int ret;
492  int got_packet = 0;
493 
494  // Return on three case:
495  // 1. Serious error
496  // 2. Got a packet success
497  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
498  while (1) {
499  if (s->bsf) {
500  ret = av_bsf_receive_packet(s->bsf, pkt);
501  if (!ret)
502  return 0;
503  if (ret != AVERROR(EAGAIN))
504  return ret;
505  }
506 
507  ret = mediacodec_receive(avctx, pkt, &got_packet);
508  if (s->bsf) {
509  if (!ret || ret == AVERROR_EOF)
510  ret = av_bsf_send_packet(s->bsf, pkt);
511  } else {
512  if (!ret)
513  return 0;
514  }
515 
516  if (ret != AVERROR(EAGAIN))
517  return ret;
518 
519  if (!s->frame->buf[0]) {
520  ret = ff_encode_get_frame(avctx, s->frame);
521  if (ret && ret != AVERROR_EOF)
522  return ret;
523  }
524 
525  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
526  if (!ret)
527  av_frame_unref(s->frame);
528  else if (ret != AVERROR(EAGAIN))
529  return ret;
530  }
531 
532  return 0;
533 }
534 
536 {
537  MediaCodecEncContext *s = avctx->priv_data;
538  if (s->codec) {
539  ff_AMediaCodec_stop(s->codec);
540  ff_AMediaCodec_delete(s->codec);
541  s->codec = NULL;
542  }
543 
544  if (s->window) {
545  ff_mediacodec_surface_unref(s->window, avctx);
546  s->window = NULL;
547  }
548 
549  av_bsf_free(&s->bsf);
550  av_frame_free(&s->frame);
551 
552  return 0;
553 }
554 
556  &(const AVCodecHWConfigInternal) {
557  .public = {
561  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
562  },
563  .hwaccel = NULL,
564  },
565  NULL
566 };
567 
568 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
569 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
570 #define COMMON_OPTION \
571  { "ndk_codec", "Use MediaCodec from NDK", \
572  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
573  { "codec_name", "Select codec by name", \
574  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
575  { "bitrate_mode", "Bitrate control method", \
576  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" }, \
577  { "cq", "Constant quality mode", \
578  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" }, \
579  { "vbr", "Variable bitrate mode", \
580  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" }, \
581  { "cbr", "Constant bitrate mode", \
582  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" }, \
583  { "cbr_fd", "Constant bitrate mode with frame drops", \
584  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" }, \
585  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
586  "since most of Android devices don't output B frames by default.", \
587  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
588 
589 
590 #define MEDIACODEC_ENCODER_CLASS(name) \
591 static const AVClass name ## _mediacodec_class = { \
592  .class_name = #name "_mediacodec", \
593  .item_name = av_default_item_name, \
594  .option = name ## _options, \
595  .version = LIBAVUTIL_VERSION_INT, \
596 }; \
597 
598 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
599 MEDIACODEC_ENCODER_CLASS(short_name) \
600 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
601  .p.name = #short_name "_mediacodec", \
602  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
603  .p.type = AVMEDIA_TYPE_VIDEO, \
604  .p.id = codec_id, \
605  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY \
606  | AV_CODEC_CAP_HARDWARE, \
607  .priv_data_size = sizeof(MediaCodecEncContext), \
608  .p.pix_fmts = avc_pix_fmts, \
609  .init = mediacodec_init, \
610  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
611  .close = mediacodec_close, \
612  .p.priv_class = &short_name ## _mediacodec_class, \
613  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
614  .p.wrapper_name = "mediacodec", \
615  .hw_configs = mediacodec_hw_configs, \
616 }; \
617 
618 #if CONFIG_H264_MEDIACODEC_ENCODER
619 
620 enum MediaCodecAvcLevel {
621  AVCLevel1 = 0x01,
622  AVCLevel1b = 0x02,
623  AVCLevel11 = 0x04,
624  AVCLevel12 = 0x08,
625  AVCLevel13 = 0x10,
626  AVCLevel2 = 0x20,
627  AVCLevel21 = 0x40,
628  AVCLevel22 = 0x80,
629  AVCLevel3 = 0x100,
630  AVCLevel31 = 0x200,
631  AVCLevel32 = 0x400,
632  AVCLevel4 = 0x800,
633  AVCLevel41 = 0x1000,
634  AVCLevel42 = 0x2000,
635  AVCLevel5 = 0x4000,
636  AVCLevel51 = 0x8000,
637  AVCLevel52 = 0x10000,
638  AVCLevel6 = 0x20000,
639  AVCLevel61 = 0x40000,
640  AVCLevel62 = 0x80000,
641 };
642 
643 static const AVOption h264_options[] = {
645  { "level", "Specify level",
646  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
647  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, "level" },
648  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, "level" },
649  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, "level" },
650  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, "level" },
651  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, "level" },
652  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, "level" },
653  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, "level" },
654  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, "level" },
655  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, "level" },
656  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, "level" },
657  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, "level" },
658  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, "level" },
659  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, "level" },
660  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, "level" },
661  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, "level" },
662  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, "level" },
663  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, "level" },
664  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, "level" },
665  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, "level" },
666  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, "level" },
667  { NULL, }
668 };
669 
671 
672 #endif // CONFIG_H264_MEDIACODEC_ENCODER
673 
674 #if CONFIG_HEVC_MEDIACODEC_ENCODER
675 
676 enum MediaCodecHevcLevel {
677  HEVCMainTierLevel1 = 0x1,
678  HEVCHighTierLevel1 = 0x2,
679  HEVCMainTierLevel2 = 0x4,
680  HEVCHighTierLevel2 = 0x8,
681  HEVCMainTierLevel21 = 0x10,
682  HEVCHighTierLevel21 = 0x20,
683  HEVCMainTierLevel3 = 0x40,
684  HEVCHighTierLevel3 = 0x80,
685  HEVCMainTierLevel31 = 0x100,
686  HEVCHighTierLevel31 = 0x200,
687  HEVCMainTierLevel4 = 0x400,
688  HEVCHighTierLevel4 = 0x800,
689  HEVCMainTierLevel41 = 0x1000,
690  HEVCHighTierLevel41 = 0x2000,
691  HEVCMainTierLevel5 = 0x4000,
692  HEVCHighTierLevel5 = 0x8000,
693  HEVCMainTierLevel51 = 0x10000,
694  HEVCHighTierLevel51 = 0x20000,
695  HEVCMainTierLevel52 = 0x40000,
696  HEVCHighTierLevel52 = 0x80000,
697  HEVCMainTierLevel6 = 0x100000,
698  HEVCHighTierLevel6 = 0x200000,
699  HEVCMainTierLevel61 = 0x400000,
700  HEVCHighTierLevel61 = 0x800000,
701  HEVCMainTierLevel62 = 0x1000000,
702  HEVCHighTierLevel62 = 0x2000000,
703 };
704 
705 static const AVOption hevc_options[] = {
707  { "level", "Specify tier and level",
708  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, "level" },
709  { "m1", "Main tier level 1",
710  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, "level" },
711  { "h1", "High tier level 1",
712  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, "level" },
713  { "m2", "Main tier level 2",
714  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, "level" },
715  { "h2", "High tier level 2",
716  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, "level" },
717  { "m2.1", "Main tier level 2.1",
718  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, "level" },
719  { "h2.1", "High tier level 2.1",
720  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, "level" },
721  { "m3", "Main tier level 3",
722  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, "level" },
723  { "h3", "High tier level 3",
724  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, "level" },
725  { "m3.1", "Main tier level 3.1",
726  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, "level" },
727  { "h3.1", "High tier level 3.1",
728  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, "level" },
729  { "m4", "Main tier level 4",
730  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, "level" },
731  { "h4", "High tier level 4",
732  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, "level" },
733  { "m4.1", "Main tier level 4.1",
734  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, "level" },
735  { "h4.1", "High tier level 4.1",
736  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, "level" },
737  { "m5", "Main tier level 5",
738  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, "level" },
739  { "h5", "High tier level 5",
740  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, "level" },
741  { "m5.1", "Main tier level 5.1",
742  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, "level" },
743  { "h5.1", "High tier level 5.1",
744  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, "level" },
745  { "m5.2", "Main tier level 5.2",
746  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, "level" },
747  { "h5.2", "High tier level 5.2",
748  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, "level" },
749  { "m6", "Main tier level 6",
750  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, "level" },
751  { "h6", "High tier level 6",
752  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, "level" },
753  { "m6.1", "Main tier level 6.1",
754  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, "level" },
755  { "h6.1", "High tier level 6.1",
756  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, "level" },
757  { "m6.2", "Main tier level 6.2",
758  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, "level" },
759  { "h6.2", "High tier level 6.2",
760  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, "level" },
761  { NULL, }
762 };
763 
765 
766 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
MediaCodecEncContext
Definition: mediacodecenc.c:54
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:92
AVCodecContext::hwaccel_context
void * hwaccel_context
Legacy hardware accelerator context.
Definition: avcodec.h:1433
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:64
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:204
MediaCodecEncContext::pts_as_dts
int pts_as_dts
Definition: mediacodecenc.c:74
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:1006
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:598
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:55
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
color_format
int color_format
Definition: mediacodecenc.c:84
BITRATE_MODE_VBR
@ BITRATE_MODE_VBR
Definition: mediacodecenc.c:47
AVMediaCodecDeviceContext::surface
void * surface
android/view/Surface handle, to be filled by the user.
Definition: hwcontext_mediacodec.h:33
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:61
out_size
int out_size
Definition: movenc.c:55
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:101
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
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:999
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:59
AVPacket::data
uint8_t * data
Definition: packet.h:374
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:43
ff_AMediaCodec_infoOutputFormatChanged
static int ff_AMediaCodec_infoOutputFormatChanged(FFAMediaCodec *codec, ssize_t idx)
Definition: mediacodec_wrapper.h:311
AVOption
AVOption.
Definition: opt.h:251
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
MediaCodecEncContext::eof_sent
int eof_sent
Definition: mediacodecenc.c:67
COMMON_OPTION
#define COMMON_OPTION
Definition: mediacodecenc.c:570
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:488
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:53
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
VE
#define VE
Definition: mediacodecenc.c:569
mediacodec_output_format
static void mediacodec_output_format(AVCodecContext *avctx)
Definition: mediacodecenc.c:99
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
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1762
bsf.h
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:535
MediaCodecEncContext::extradata
uint8_t * extradata
Definition: mediacodecenc.c:65
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecenc.c:85
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:653
ff_AMediaFormat_new
FFAMediaFormat * ff_AMediaFormat_new(int ndk)
Definition: mediacodec_wrapper.c:2485
AVRational::num
int num
Numerator.
Definition: rational.h:59
mediacodecdec_common.h
mediacodec_receive
static int mediacodec_receive(AVCodecContext *avctx, AVPacket *pkt, int *got_packet)
Definition: mediacodecenc.c:331
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:89
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:439
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:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
MediaCodecEncContext::bitrate_mode
int bitrate_mode
Definition: mediacodecenc.c:72
ff_AMediaCodec_getName
static char * ff_AMediaCodec_getName(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:224
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:321
s
#define s(width, name)
Definition: cbs_vp9.c:256
hevc_options
static const AVOption hevc_options[]
Definition: videotoolboxenc.c:2778
BITRATE_MODE_CQ
@ BITRATE_MODE_CQ
Definition: mediacodecenc.c:45
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_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
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:568
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:347
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:66
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:436
MediaCodecEncContext::use_ndk_codec
int use_ndk_codec
Definition: mediacodecenc.c:57
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:313
ff_AMediaFormatColorStandard_from_AVColorSpace
int ff_AMediaFormatColorStandard_from_AVColorSpace(enum AVColorSpace color_space)
Map AVColorSpace to MediaFormat color standard.
Definition: mediacodec_wrapper.c:2610
OUTPUT_DEQUEUE_TIMEOUT_US
#define OUTPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:41
ff_AMediaCodec_getOutputFormat
static FFAMediaFormat * ff_AMediaCodec_getOutputFormat(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:286
MediaCodecEncContext::level
int level
Definition: mediacodecenc.c:73
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:150
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:2492
ff_AMediaFormatColorRange_from_AVColorRange
int ff_AMediaFormatColorRange_from_AVColorRange(enum AVColorRange color_range)
Map AVColorRange to MediaFormat color range.
Definition: mediacodec_wrapper.c:2593
NULL
#define NULL
Definition: coverity.c:32
FFAMediaCodecBufferInfo
Definition: mediacodec_wrapper.h:172
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1013
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:231
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:476
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:79
ff_AMediaCodec_createEncoderByType
FFAMediaCodec * ff_AMediaCodec_createEncoderByType(const char *mime_type, int ndk)
Definition: mediacodec_wrapper.c:2506
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:51
ff_AMediaCodec_getBufferFlagKeyFrame
static int ff_AMediaCodec_getBufferFlagKeyFrame(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:326
BITRATE_MODE_CBR
@ BITRATE_MODE_CBR
Definition: mediacodecenc.c:49
index
int index
Definition: gxfenc.c:89
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:548
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:620
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1048
codec_internal.h
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:203
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:92
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:186
ff_AMediaFormatColorTransfer_from_AVColorTransfer
int ff_AMediaFormatColorTransfer_from_AVColorTransfer(enum AVColorTransferCharacteristic color_transfer)
Map AVColorTransferCharacteristic to MediaFormat color transfer.
Definition: mediacodec_wrapper.c:2638
AVCodecHWConfigInternal
Definition: hwconfig.h:29
MediaCodecEncContext::bsf
AVBSFContext * bsf
Definition: mediacodecenc.c:70
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:373
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:303
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:58
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
MediaCodecEncContext::width
int width
Definition: mediacodecenc.c:62
ff_AMediaCodec_getConfigureFlagEncode
static int ff_AMediaCodec_getConfigureFlagEncode(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:331
MediaCodecEncContext::codec
FFAMediaCodec * codec
Definition: mediacodecenc.c:56
FFANativeWindow
Definition: mediacodec_surface.h:28
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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:367
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
FFAMediaCodec
Definition: mediacodec_wrapper.h:181
MediaCodecEncContext::height
int height
Definition: mediacodecenc.c:63
MediaCodecEncContext::extradata_size
int extradata_size
Definition: mediacodecenc.c:66
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:484
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:1940
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:69
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:40
AVCodecContext::height
int height
Definition: avcodec.h:598
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:635
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:74
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
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:79
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:89
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:78
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
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:335
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1345
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:80
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
color_formats
static const struct @112 color_formats[]
AVCodecContext
main external API structure.
Definition: avcodec.h:426
av_image_copy
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:422
mediacodec_init
static av_cold int mediacodec_init(AVCodecContext *avctx)
Definition: mediacodecenc.c:149
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:79
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
ff_AMediaCodec_getBufferFlagCodecConfig
static int ff_AMediaCodec_getBufferFlagCodecConfig(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:316
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:527
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:697
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:183
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h:266
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:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:453
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:598
convert_header.str
string str
Definition: convert_header.py:20
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
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:306
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
jni.h
mediacodec_hw_configs
static const AVCodecHWConfigInternal *const mediacodec_hw_configs[]
Definition: mediacodecenc.c:555
AVCodecHWConfigInternal::public
AVCodecHWConfig public
This is the structure which will be returned to the user by avcodec_get_hw_config().
Definition: hwconfig.h:34
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:234
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:409
mediacodec_init_bsf
static int mediacodec_init_bsf(AVCodecContext *avctx)
Definition: mediacodecenc.c:113
mediacodec.h