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