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 MediaCodecEncContext {
63  const char *name;
65 
66  int fps;
67  int width;
68  int height;
69 
70  uint8_t *extradata;
72  int eof_sent;
73 
76 
78  int level;
81  // Ref. MediaFormat KEY_OPERATING_RATE
84 
88 
95 
96 enum {
99  COLOR_FormatSurface = 0x7F000789,
100 };
101 
102 static const struct {
105 } color_formats[] = {
109 };
110 
111 static const enum AVPixelFormat avc_pix_fmts[] = {
116 };
117 
119  FFAMediaFormat *out_format)
120 {
121  MediaCodecEncContext *s = avctx->priv_data;
122  const char *name = s->name;
123  char *str = ff_AMediaFormat_toString(out_format);
124 
125  av_log(avctx, AV_LOG_DEBUG, "MediaCodec encoder %s output format %s\n",
126  name ? name : "unknown", str);
127  av_free(str);
128 }
129 
131 {
132  MediaCodecEncContext *s = avctx->priv_data;
133  FFAMediaFormat *out_format = ff_AMediaCodec_getOutputFormat(s->codec);
134 
135  if (!s->name)
136  s->name = ff_AMediaCodec_getName(s->codec);
137  mediacodec_dump_format(avctx, out_format);
138  ff_AMediaFormat_delete(out_format);
139 }
140 
142 {
143  const AVBitStreamFilter *bsf = av_bsf_get_by_name("extract_extradata");
144 
145  if (!bsf) {
146  av_log(avctx, AV_LOG_WARNING, "extract_extradata bsf not found\n");
147  return 0;
148  }
149 
150  for (int i = 0; bsf->codec_ids[i] != AV_CODEC_ID_NONE; i++) {
151  if (bsf->codec_ids[i] == avctx->codec_id)
152  return 1;
153  }
154 
155  return 0;
156 }
157 
159 {
160  MediaCodecEncContext *s = avctx->priv_data;
161  char str[128] = {0};
162  int ret;
163  int crop_right = s->width - avctx->width;
164  int crop_bottom = s->height - avctx->height;
165 
166  /* Nothing can be done for this format now */
167  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC)
168  return 0;
169 
170  s->extract_extradata = (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) &&
172  if (!crop_right && !crop_bottom && !s->extract_extradata)
173  return 0;
174 
175  ret = 0;
176  if (crop_right || crop_bottom) {
177  if (avctx->codec_id == AV_CODEC_ID_H264)
178  ret = snprintf(str, sizeof(str), "h264_metadata=crop_right=%d:crop_bottom=%d",
179  crop_right, crop_bottom);
180  else if (avctx->codec_id == AV_CODEC_ID_HEVC)
181  /* Encoder can use CTU size larger than 16x16, so the real crop
182  * margin can be larger than crop_right/crop_bottom. Let bsf figure
183  * out the real crop margin.
184  */
185  ret = snprintf(str, sizeof(str), "hevc_metadata=width=%d:height=%d",
186  avctx->width, avctx->height);
187  if (ret >= sizeof(str))
189  }
190 
191  if (s->extract_extradata) {
192  ret = av_strlcatf(str, sizeof(str), "%sextract_extradata", ret ? "," : "");
193  if (ret >= sizeof(str))
195  }
196 
197  ret = av_bsf_list_parse_str(str, &s->bsf);
198  if (ret < 0)
199  return ret;
200 
201  ret = avcodec_parameters_from_context(s->bsf->par_in, avctx);
202  if (ret < 0)
203  return ret;
204  s->bsf->time_base_in = avctx->time_base;
205  ret = av_bsf_init(s->bsf);
206 
207  return ret;
208 }
209 
211  uint8_t *dst, size_t size)
212 {
213  MediaCodecEncContext *s = avctx->priv_data;
214  uint8_t *dst_data[4] = {};
215  int dst_linesize[4] = {};
216 
217  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
218  dst_data[0] = dst;
219  dst_data[1] = dst + s->width * s->height;
220  dst_data[2] = dst_data[1] + s->width * s->height / 4;
221 
222  dst_linesize[0] = s->width;
223  dst_linesize[1] = dst_linesize[2] = s->width / 2;
224  } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
225  dst_data[0] = dst;
226  dst_data[1] = dst + s->width * s->height;
227 
228  dst_linesize[0] = s->width;
229  dst_linesize[1] = s->width;
230  } else {
231  av_assert0(0);
232  }
233 
234  av_image_copy2(dst_data, dst_linesize, frame->data, frame->linesize,
235  avctx->pix_fmt, avctx->width, avctx->height);
236 }
237 
238 static void on_input_available(FFAMediaCodec *codec, void *userdata,
239  int32_t index)
240 {
241  AVCodecContext *avctx = userdata;
242  MediaCodecEncContext *s = avctx->priv_data;
243 
244  ff_mutex_lock(&s->input_mutex);
245 
246  av_fifo_write(s->input_index, &index, 1);
247 
248  ff_mutex_unlock(&s->input_mutex);
249  ff_cond_signal(&s->input_cond);
250 }
251 
252 static void on_output_available(FFAMediaCodec *codec, void *userdata,
253  int32_t index,
254  FFAMediaCodecBufferInfo *out_info)
255 {
256  AVCodecContext *avctx = userdata;
257  MediaCodecEncContext *s = avctx->priv_data;
258 
259  ff_mutex_lock(&s->output_mutex);
260 
261  av_fifo_write(s->output_index, &index, 1);
262  av_fifo_write(s->output_buf_info, out_info, 1);
263 
264  ff_mutex_unlock(&s->output_mutex);
265  ff_cond_signal(&s->output_cond);
266 }
267 
268 static void on_format_changed(FFAMediaCodec *codec, void *userdata,
270 {
271  mediacodec_dump_format(userdata, format);
272 }
273 
274 static void on_error(FFAMediaCodec *codec, void *userdata, int error,
275  const char *detail)
276 {
277  AVCodecContext *avctx = userdata;
278  MediaCodecEncContext *s = avctx->priv_data;
279 
280  if (error == AVERROR(EAGAIN))
281  return;
282 
283  av_log(avctx, AV_LOG_ERROR, "On error, %s, %s\n", av_err2str(error), detail);
284 
285  ff_mutex_lock(&s->input_mutex);
286  ff_mutex_lock(&s->output_mutex);
287  s->encode_status = error;
288  ff_mutex_unlock(&s->output_mutex);
289  ff_mutex_unlock(&s->input_mutex);
290 
291  ff_cond_signal(&s->output_cond);
292  ff_cond_signal(&s->input_cond);
293 }
294 
296 {
297  MediaCodecEncContext *s = avctx->priv_data;
298  size_t fifo_size = 16;
299 
300  if (!s->async_mode)
301  return 0;
302 
303  ff_mutex_init(&s->input_mutex, NULL);
304  ff_cond_init(&s->input_cond, NULL);
305 
306  ff_mutex_init(&s->output_mutex, NULL);
307  ff_cond_init(&s->output_cond, NULL);
308 
309  s->input_index = av_fifo_alloc2(fifo_size, sizeof(int32_t), AV_FIFO_FLAG_AUTO_GROW);
310  s->output_index = av_fifo_alloc2(fifo_size, sizeof(int32_t), AV_FIFO_FLAG_AUTO_GROW);
312 
313  if (!s->input_index || !s->output_index || !s->output_buf_info)
314  return AVERROR(ENOMEM);
315 
316  return 0;
317 }
318 
320 {
321  MediaCodecEncContext *s = avctx->priv_data;
322 
323  if (!s->async_mode)
324  return;
325 
326  ff_mutex_destroy(&s->input_mutex);
327  ff_cond_destroy(&s->input_cond);
328 
329  ff_mutex_destroy(&s->output_mutex);
330  ff_cond_destroy(&s->output_cond);
331 
332  av_fifo_freep2(&s->input_index);
333  av_fifo_freep2(&s->output_index);
334  av_fifo_freep2(&s->output_buf_info);
335 
336  s->async_mode = 0;
337 }
338 
340 
342 {
343  const char *codec_mime = NULL;
344  MediaCodecEncContext *s = avctx->priv_data;
346  int ret;
347  int gop;
348 
349  // Init async state first, so we can do cleanup safely on error path.
351  if (ret < 0)
352  return ret;
353 
354  if (s->use_ndk_codec < 0)
355  s->use_ndk_codec = !av_jni_get_java_vm(avctx);
356 
357  switch (avctx->codec_id) {
358  case AV_CODEC_ID_H264:
359  codec_mime = "video/avc";
360  break;
361  case AV_CODEC_ID_HEVC:
362  codec_mime = "video/hevc";
363  break;
364  case AV_CODEC_ID_VP8:
365  codec_mime = "video/x-vnd.on2.vp8";
366  break;
367  case AV_CODEC_ID_VP9:
368  codec_mime = "video/x-vnd.on2.vp9";
369  break;
370  case AV_CODEC_ID_MPEG4:
371  codec_mime = "video/mp4v-es";
372  break;
373  case AV_CODEC_ID_AV1:
374  codec_mime = "video/av01";
375  break;
376  default:
377  av_assert0(0);
378  }
379 
380  if (s->name)
381  s->codec = ff_AMediaCodec_createCodecByName(s->name, s->use_ndk_codec);
382  else
383  s->codec = ff_AMediaCodec_createEncoderByType(codec_mime, s->use_ndk_codec);
384  if (!s->codec) {
385  av_log(avctx, AV_LOG_ERROR, "Failed to create encoder for type %s\n",
386  codec_mime);
387  return AVERROR_EXTERNAL;
388  }
389 
390  format = ff_AMediaFormat_new(s->use_ndk_codec);
391  if (!format) {
392  av_log(avctx, AV_LOG_ERROR, "Failed to create media format\n");
393  return AVERROR_EXTERNAL;
394  }
395 
396  ff_AMediaFormat_setString(format, "mime", codec_mime);
397  // Workaround the alignment requirement of mediacodec. We can't do it
398  // silently for AV_PIX_FMT_MEDIACODEC.
399  if (avctx->pix_fmt != AV_PIX_FMT_MEDIACODEC &&
400  (avctx->codec_id == AV_CODEC_ID_H264 ||
401  avctx->codec_id == AV_CODEC_ID_HEVC)) {
402  s->width = FFALIGN(avctx->width, 16);
403  s->height = FFALIGN(avctx->height, 16);
404  } else {
405  s->width = avctx->width;
406  s->height = avctx->height;
407  if (s->width % 16 || s->height % 16)
408  av_log(avctx, AV_LOG_WARNING,
409  "Video size %dx%d isn't align to 16, it may have device compatibility issue\n",
410  s->width, s->height);
411  }
412  ff_AMediaFormat_setInt32(format, "width", s->width);
413  ff_AMediaFormat_setInt32(format, "height", s->height);
414 
415  if (avctx->pix_fmt == AV_PIX_FMT_MEDIACODEC) {
416  AVMediaCodecContext *user_ctx = avctx->hwaccel_context;
417  if (avctx->hw_device_ctx) {
418  AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)(avctx->hw_device_ctx->data);
419  AVMediaCodecDeviceContext *dev_ctx;
420 
421  if (device_ctx->type != AV_HWDEVICE_TYPE_MEDIACODEC || !device_ctx->hwctx) {
422  ret = AVERROR(EINVAL);
423  goto bailout;
424  }
425  dev_ctx = device_ctx->hwctx;
426  s->window = ff_mediacodec_surface_ref(dev_ctx->surface, dev_ctx->native_window, avctx);
427  }
428 
429  if (!s->window && user_ctx && user_ctx->surface)
430  s->window = ff_mediacodec_surface_ref(user_ctx->surface, NULL, avctx);
431 
432  if (!s->window) {
433  ret = AVERROR(EINVAL);
434  av_log(avctx, AV_LOG_ERROR, "Missing hw_device_ctx or hwaccel_context for AV_PIX_FMT_MEDIACODEC\n");
435  goto bailout;
436  }
437  /* Although there is a method ANativeWindow_toSurface() introduced in
438  * API level 26, it's easier and safe to always require a Surface for
439  * Java MediaCodec.
440  */
441  if (!s->use_ndk_codec && !s->window->surface) {
442  ret = AVERROR(EINVAL);
443  av_log(avctx, AV_LOG_ERROR, "Missing jobject Surface for AV_PIX_FMT_MEDIACODEC. "
444  "Please note that Java MediaCodec doesn't work with ANativeWindow.\n");
445  goto bailout;
446  }
447  }
448 
449  for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
450  if (avctx->pix_fmt == color_formats[i].pix_fmt) {
451  ff_AMediaFormat_setInt32(format, "color-format",
453  break;
454  }
455  }
456 
459  ff_AMediaFormat_setInt32(format, "color-range", ret);
462  ff_AMediaFormat_setInt32(format, "color-standard", ret);
465  ff_AMediaFormat_setInt32(format, "color-transfer", ret);
466 
467  if (avctx->bit_rate)
468  ff_AMediaFormat_setInt32(format, "bitrate", avctx->bit_rate);
469  if (s->bitrate_mode >= 0) {
470  ff_AMediaFormat_setInt32(format, "bitrate-mode", s->bitrate_mode);
471  if (s->bitrate_mode == BITRATE_MODE_CQ && avctx->global_quality > 0)
472  ff_AMediaFormat_setInt32(format, "quality", avctx->global_quality);
473  }
474  // frame-rate and i-frame-interval are required to configure codec
475  if (avctx->framerate.num >= avctx->framerate.den && avctx->framerate.den > 0) {
476  s->fps = avctx->framerate.num / avctx->framerate.den;
477  } else {
478  s->fps = 30;
479  av_log(avctx, AV_LOG_INFO, "Use %d as the default MediaFormat frame-rate\n", s->fps);
480  }
481  gop = round(avctx->gop_size / s->fps);
482  if (gop == 0) {
483  gop = 1;
484  av_log(avctx, AV_LOG_INFO,
485  "Use %d as the default MediaFormat i-frame-interval, "
486  "please set gop_size properly (>= fps)\n", gop);
487  } else {
488  av_log(avctx, AV_LOG_DEBUG, "Set i-frame-interval to %d\n", gop);
489  }
490 
491  ff_AMediaFormat_setInt32(format, "frame-rate", s->fps);
492  ff_AMediaFormat_setInt32(format, "i-frame-interval", gop);
493 
495  if (ret > 0) {
496  av_log(avctx, AV_LOG_DEBUG, "set profile to 0x%x\n", ret);
497  ff_AMediaFormat_setInt32(format, "profile", ret);
498  }
499  if (s->level > 0) {
500  av_log(avctx, AV_LOG_DEBUG, "set level to 0x%x\n", s->level);
501  ff_AMediaFormat_setInt32(format, "level", s->level);
502  }
503  if (avctx->max_b_frames > 0) {
505  av_log(avctx, AV_LOG_ERROR,
506  "Enabling B frames will produce packets with no DTS. "
507  "Use -strict experimental to use it anyway.\n");
508  ret = AVERROR(EINVAL);
509  goto bailout;
510  }
511  ff_AMediaFormat_setInt32(format, "max-bframes", avctx->max_b_frames);
512  }
513  if (s->pts_as_dts == -1)
514  s->pts_as_dts = avctx->max_b_frames <= 0;
515  if (s->operating_rate > 0)
516  ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate);
517 
519  ret = ff_AMediaCodec_configure(s->codec, format, s->window, NULL, ret);
520  if (ret) {
521  av_log(avctx, AV_LOG_ERROR, "MediaCodec configure failed, %s\n", av_err2str(ret));
522  if (avctx->pix_fmt == AV_PIX_FMT_YUV420P)
523  av_log(avctx, AV_LOG_ERROR, "Please try -pix_fmt nv12, some devices don't "
524  "support yuv420p as encoder input format.\n");
525  goto bailout;
526  }
527 
528  if (s->async_mode) {
530  .onAsyncInputAvailable = on_input_available,
531  .onAsyncOutputAvailable = on_output_available,
532  .onAsyncFormatChanged = on_format_changed,
533  .onAsyncError = on_error,
534  };
535 
536  ret = ff_AMediaCodec_setAsyncNotifyCallback(s->codec, &cb, avctx);
537  if (ret < 0) {
538  av_log(avctx, AV_LOG_WARNING,
539  "Try MediaCodec async mode failed, %s, switch to sync mode\n",
540  av_err2str(ret));
542  }
543  }
544 
545  ret = mediacodec_init_bsf(avctx);
546  if (ret)
547  goto bailout;
548 
550 
551  s->frame = av_frame_alloc();
552  if (!s->frame) {
553  ret = AVERROR(ENOMEM);
554  goto bailout;
555  }
556 
557  ret = ff_AMediaCodec_start(s->codec);
558  if (ret) {
559  av_log(avctx, AV_LOG_ERROR, "MediaCodec failed to start, %s\n",
560  av_err2str(ret));
561  goto bailout;
562  }
563 
565 
566 bailout:
567  if (format)
569  return ret;
570 }
571 
573  FFAMediaCodecBufferInfo *out_info)
574 {
575  MediaCodecEncContext *s = avctx->priv_data;
576  FFAMediaCodec *codec = s->codec;
577  int64_t timeout_us = s->eof_sent ? OUTPUT_DEQUEUE_TIMEOUT_US : 0;
578  int n;
579  int ret;
580 
581  if (!s->async_mode) {
582  *index = ff_AMediaCodec_dequeueOutputBuffer(codec, out_info, timeout_us);
583  return 0;
584  }
585 
586  ff_mutex_lock(&s->output_mutex);
587 
588  n = -1;
589  while (n < 0 && !s->encode_status) {
590  if (av_fifo_can_read(s->output_index)) {
591  av_fifo_read(s->output_index, &n, 1);
592  av_fifo_read(s->output_buf_info, out_info, 1);
593  break;
594  }
595 
596  // Only wait after signalEndOfInputStream
597  if (n < 0 && s->eof_sent && !s->encode_status)
598  ff_cond_wait(&s->output_cond, &s->output_mutex);
599  else
600  break;
601  }
602 
603  ret = s->encode_status;
604  *index = n;
605  ff_mutex_unlock(&s->output_mutex);
606 
607  // Get output index success
608  if (*index >= 0)
609  return 0;
610 
611  return ret ? ret : AVERROR(EAGAIN);
612 }
613 
615 {
616  MediaCodecEncContext *s = avctx->priv_data;
617  FFAMediaCodec *codec = s->codec;
618  ssize_t index;
619  FFAMediaCodecBufferInfo out_info = {0};
620  uint8_t *out_buf;
621  size_t out_size = 0;
622  int ret;
623  int extradata_size = 0;
624 
625  ret = mediacodec_get_output_index(avctx, &index, &out_info);
626  if (ret < 0)
627  return ret;
628 
630  return AVERROR(EAGAIN);
631 
634  return AVERROR(EAGAIN);
635  }
636 
639  return AVERROR(EAGAIN);
640  }
641 
642  if (index < 0)
643  return AVERROR_EXTERNAL;
644 
645  if (out_info.flags & ff_AMediaCodec_getBufferFlagEndOfStream(codec))
646  return AVERROR_EOF;
647 
648  out_buf = ff_AMediaCodec_getOutputBuffer(codec, index, &out_size);
649  if (!out_buf) {
651  goto bailout;
652  }
653 
654  if (out_info.flags & ff_AMediaCodec_getBufferFlagCodecConfig(codec)) {
655  if (avctx->codec_id == AV_CODEC_ID_AV1) {
656  // Skip AV1CodecConfigurationRecord without configOBUs
657  if (out_info.size <= 4) {
659  return mediacodec_receive(avctx, pkt);
660  }
661  out_info.size -= 4;
662  out_info.offset += 4;
663  }
664 
665  ret = av_reallocp(&s->extradata, out_info.size);
666  if (ret)
667  goto bailout;
668 
669  s->extradata_size = out_info.size;
670  memcpy(s->extradata, out_buf + out_info.offset, out_info.size);
672  // try immediately
673  return mediacodec_receive(avctx, pkt);
674  }
675 
676  ret = ff_get_encode_buffer(avctx, pkt, out_info.size + s->extradata_size, 0);
677  if (ret < 0)
678  goto bailout;
679 
680  if (s->extradata_size) {
681  extradata_size = s->extradata_size;
682  s->extradata_size = 0;
683  memcpy(pkt->data, s->extradata, extradata_size);
684  }
685  memcpy(pkt->data + extradata_size, out_buf + out_info.offset, out_info.size);
687  if (s->pts_as_dts)
688  pkt->dts = pkt->pts;
689  if (out_info.flags & ff_AMediaCodec_getBufferFlagKeyFrame(codec))
691  ret = 0;
692 
693  av_log(avctx, AV_LOG_TRACE, "receive packet pts %" PRId64 " dts %" PRId64
694  " flags %d extradata %d\n",
695  pkt->pts, pkt->dts, pkt->flags, extradata_size);
696 
697 bailout:
699  return ret;
700 }
701 
702 static int mediacodec_get_input_index(AVCodecContext *avctx, ssize_t *index)
703 {
704  MediaCodecEncContext *s = avctx->priv_data;
705  FFAMediaCodec *codec = s->codec;
706  int ret = 0;
707  int32_t n;
708 
709  if (!s->async_mode) {
711  return 0;
712  }
713 
714  ff_mutex_lock(&s->input_mutex);
715 
716  n = -1;
717  while (n < 0 && !s->encode_status) {
718  if (av_fifo_can_read(s->input_index) > 0) {
719  av_fifo_read(s->input_index, &n, 1);
720  break;
721  }
722 
723  if (n < 0 && !s->encode_status)
724  ff_cond_wait(&s->input_cond, &s->input_mutex);
725  }
726 
727  ret = s->encode_status;
728  *index = n;
729  ff_mutex_unlock(&s->input_mutex);
730 
731  return ret;
732 }
733 
734 
735 static int mediacodec_send(AVCodecContext *avctx,
736  const AVFrame *frame) {
737  MediaCodecEncContext *s = avctx->priv_data;
738  FFAMediaCodec *codec = s->codec;
739  ssize_t index;
740  uint8_t *input_buf = NULL;
741  size_t input_size = 0;
742  int64_t pts = 0;
743  uint32_t flags = 0;
744  int ret;
745 
746  if (s->eof_sent)
747  return 0;
748 
749  if (s->window) {
750  if (!frame) {
751  s->eof_sent = 1;
753  }
754 
755  if (frame->data[3])
756  av_mediacodec_release_buffer((AVMediaCodecBuffer *)frame->data[3], 1);
757  return 0;
758  }
759 
761  if (ret < 0)
762  return ret;
763 
765  return AVERROR(EAGAIN);
766 
767  if (index < 0) {
768  av_log(avctx, AV_LOG_ERROR, "dequeue input buffer failed, %zd", index);
769  return AVERROR_EXTERNAL;
770  }
771 
772  if (frame) {
773  input_buf = ff_AMediaCodec_getInputBuffer(codec, index, &input_size);
774  copy_frame_to_buffer(avctx, frame, input_buf, input_size);
775 
776  pts = av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q);
777  } else {
779  s->eof_sent = 1;
780  }
781 
782  ff_AMediaCodec_queueInputBuffer(codec, index, 0, input_size, pts, flags);
783  return 0;
784 }
785 
787 {
788  MediaCodecEncContext *s = avctx->priv_data;
789  int ret;
790 
791  // Return on three case:
792  // 1. Serious error
793  // 2. Got a packet success
794  // 3. No AVFrame is available yet (don't return if get_frame return EOF)
795  while (1) {
796  if (s->bsf) {
797  ret = av_bsf_receive_packet(s->bsf, pkt);
798  if (!ret)
799  return 0;
800  if (ret != AVERROR(EAGAIN))
801  return ret;
802  }
803 
804  ret = mediacodec_receive(avctx, pkt);
805  if (s->bsf) {
806  if (!ret || ret == AVERROR_EOF)
807  ret = av_bsf_send_packet(s->bsf, pkt);
808  } else {
809  if (!ret)
810  return 0;
811  }
812 
813  if (ret < 0 && ret != AVERROR(EAGAIN))
814  return ret;
815 
816  if (!s->frame->buf[0]) {
817  ret = ff_encode_get_frame(avctx, s->frame);
818  if (ret && ret != AVERROR_EOF)
819  return ret;
820  }
821 
822  ret = mediacodec_send(avctx, s->frame->buf[0] ? s->frame : NULL);
823  if (!ret)
824  av_frame_unref(s->frame);
825  else if (ret != AVERROR(EAGAIN))
826  return ret;
827  }
828 
829  return 0;
830 }
831 
833 {
834  MediaCodecEncContext *s = avctx->priv_data;
835  int ret;
836 
837  s->frame->width = avctx->width;
838  s->frame->height = avctx->height;
839  s->frame->format = avctx->pix_fmt;
840  s->frame->pts = 0;
841 
842  ret = av_frame_get_buffer(s->frame, 0);
843  if (ret < 0)
844  return ret;
845 
846  do {
847  ret = mediacodec_send(avctx, s->frame);
848  } while (ret == AVERROR(EAGAIN));
849  av_frame_unref(s->frame);
850 
851  if (ret < 0)
852  return ret;
853 
854  ret = mediacodec_send(avctx, NULL);
855  if (ret < 0) {
856  av_log(avctx, AV_LOG_ERROR, "Flush failed: %s\n", av_err2str(ret));
857  return ret;
858  }
859 
860  return 0;
861 }
862 
864 {
865  MediaCodecEncContext *s = avctx->priv_data;
866  int ret;
867 
868  do {
869  ret = mediacodec_receive(avctx, pkt);
870  } while (ret == AVERROR(EAGAIN));
871 
872  if (ret < 0)
873  return ret;
874 
875  do {
876  ret = av_bsf_send_packet(s->bsf, pkt);
877  if (ret < 0)
878  return ret;
879  ret = av_bsf_receive_packet(s->bsf, pkt);
880  } while (ret == AVERROR(EAGAIN));
881 
882  return ret;
883 }
884 
886 {
887  MediaCodecEncContext *s = avctx->priv_data;
888  AVPacket *pkt = NULL;
889  int ret;
890  size_t side_size;
891  uint8_t *side;
892 
893  if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER))
894  return 0;
895 
896  // Send dummy frame and receive a packet doesn't work in async mode
897  if (s->async_mode || !s->extract_extradata) {
898  av_log(avctx, AV_LOG_WARNING,
899  "Mediacodec encoder doesn't support AV_CODEC_FLAG_GLOBAL_HEADER. "
900  "Use extract_extradata bsf when necessary.\n");
901  return 0;
902  }
903 
904  pkt = av_packet_alloc();
905  if (!pkt)
906  return AVERROR(ENOMEM);
907 
909  if (ret < 0)
910  goto bailout;
912  if (ret < 0)
913  goto bailout;
914 
916  if (side && side_size > 0) {
917  avctx->extradata = av_mallocz(side_size + AV_INPUT_BUFFER_PADDING_SIZE);
918  if (!avctx->extradata) {
919  ret = AVERROR(ENOMEM);
920  goto bailout;
921  }
922 
923  memcpy(avctx->extradata, side, side_size);
924  avctx->extradata_size = side_size;
925  }
926 
927 bailout:
928  if (s->eof_sent) {
929  s->eof_sent = 0;
930  ff_AMediaCodec_flush(s->codec);
931  }
932  av_bsf_flush(s->bsf);
934  return ret;
935 }
936 
938 {
939  MediaCodecEncContext *s = avctx->priv_data;
940  if (s->codec) {
941  ff_AMediaCodec_stop(s->codec);
942  ff_AMediaCodec_delete(s->codec);
943  s->codec = NULL;
944  }
945 
946  if (s->window) {
947  ff_mediacodec_surface_unref(s->window, avctx);
948  s->window = NULL;
949  }
950 
951  av_bsf_free(&s->bsf);
952  av_frame_free(&s->frame);
953 
955 
956  return 0;
957 }
958 
960 {
961  MediaCodecEncContext *s = avctx->priv_data;
962  if (s->bsf)
963  av_bsf_flush(s->bsf);
964  av_frame_unref(s->frame);
965  ff_AMediaCodec_flush(s->codec);
966 }
967 
969  &(const AVCodecHWConfigInternal) {
970  .public = {
974  .device_type = AV_HWDEVICE_TYPE_MEDIACODEC,
975  },
976  .hwaccel = NULL,
977  },
978  NULL
979 };
980 
981 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
982 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
983 #define COMMON_OPTION \
984  { "ndk_codec", "Use MediaCodec from NDK", \
985  OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
986  { "ndk_async", "Try NDK MediaCodec in async mode", \
987  OFFSET(async_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE }, \
988  { "codec_name", "Select codec by name", \
989  OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE }, \
990  { "bitrate_mode", "Bitrate control method", \
991  OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, .unit = "bitrate_mode" }, \
992  { "cq", "Constant quality mode", \
993  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, .unit = "bitrate_mode" }, \
994  { "vbr", "Variable bitrate mode", \
995  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
996  { "cbr", "Constant bitrate mode", \
997  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, .unit = "bitrate_mode" }, \
998  { "cbr_fd", "Constant bitrate mode with frame drops", \
999  0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, .unit = "bitrate_mode" }, \
1000  { "pts_as_dts", "Use PTS as DTS. It is enabled automatically if avctx max_b_frames <= 0, " \
1001  "since most of Android devices don't output B frames by default.", \
1002  OFFSET(pts_as_dts), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE }, \
1003  { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified", \
1004  OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE }, \
1005 
1006 #define MEDIACODEC_ENCODER_CLASS(name) \
1007 static const AVClass name ## _mediacodec_class = { \
1008  .class_name = #name "_mediacodec", \
1009  .item_name = av_default_item_name, \
1010  .option = name ## _options, \
1011  .version = LIBAVUTIL_VERSION_INT, \
1012 }; \
1013 
1014 #define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id) \
1015 MEDIACODEC_ENCODER_CLASS(short_name) \
1016 const FFCodec ff_ ## short_name ## _mediacodec_encoder = { \
1017  .p.name = #short_name "_mediacodec", \
1018  CODEC_LONG_NAME(long_name " Android MediaCodec encoder"), \
1019  .p.type = AVMEDIA_TYPE_VIDEO, \
1020  .p.id = codec_id, \
1021  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | \
1022  AV_CODEC_CAP_HARDWARE | \
1023  AV_CODEC_CAP_ENCODER_FLUSH, \
1024  .priv_data_size = sizeof(MediaCodecEncContext), \
1025  .p.pix_fmts = avc_pix_fmts, \
1026  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG, \
1027  .init = mediacodec_init, \
1028  FF_CODEC_RECEIVE_PACKET_CB(mediacodec_encode), \
1029  .close = mediacodec_close, \
1030  .flush = mediacodec_flush, \
1031  .p.priv_class = &short_name ## _mediacodec_class, \
1032  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
1033  .p.wrapper_name = "mediacodec", \
1034  .hw_configs = mediacodec_hw_configs, \
1035 }; \
1036 
1037 #if CONFIG_H264_MEDIACODEC_ENCODER
1038 
1039 enum MediaCodecAvcLevel {
1040  AVCLevel1 = 0x01,
1041  AVCLevel1b = 0x02,
1042  AVCLevel11 = 0x04,
1043  AVCLevel12 = 0x08,
1044  AVCLevel13 = 0x10,
1045  AVCLevel2 = 0x20,
1046  AVCLevel21 = 0x40,
1047  AVCLevel22 = 0x80,
1048  AVCLevel3 = 0x100,
1049  AVCLevel31 = 0x200,
1050  AVCLevel32 = 0x400,
1051  AVCLevel4 = 0x800,
1052  AVCLevel41 = 0x1000,
1053  AVCLevel42 = 0x2000,
1054  AVCLevel5 = 0x4000,
1055  AVCLevel51 = 0x8000,
1056  AVCLevel52 = 0x10000,
1057  AVCLevel6 = 0x20000,
1058  AVCLevel61 = 0x40000,
1059  AVCLevel62 = 0x80000,
1060 };
1061 
1062 static const AVOption h264_options[] = {
1064 
1066  FF_AVCTX_PROFILE_OPTION("constrained_baseline", NULL, VIDEO, AV_PROFILE_H264_CONSTRAINED_BASELINE)
1073 
1074  { "level", "Specify level",
1075  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1076  { "1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1 }, 0, 0, VE, .unit = "level" },
1077  { "1b", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel1b }, 0, 0, VE, .unit = "level" },
1078  { "1.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel11 }, 0, 0, VE, .unit = "level" },
1079  { "1.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel12 }, 0, 0, VE, .unit = "level" },
1080  { "1.3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel13 }, 0, 0, VE, .unit = "level" },
1081  { "2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel2 }, 0, 0, VE, .unit = "level" },
1082  { "2.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel21 }, 0, 0, VE, .unit = "level" },
1083  { "2.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel22 }, 0, 0, VE, .unit = "level" },
1084  { "3", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel3 }, 0, 0, VE, .unit = "level" },
1085  { "3.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel31 }, 0, 0, VE, .unit = "level" },
1086  { "3.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel32 }, 0, 0, VE, .unit = "level" },
1087  { "4", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel4 }, 0, 0, VE, .unit = "level" },
1088  { "4.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel41 }, 0, 0, VE, .unit = "level" },
1089  { "4.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel42 }, 0, 0, VE, .unit = "level" },
1090  { "5", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel5 }, 0, 0, VE, .unit = "level" },
1091  { "5.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel51 }, 0, 0, VE, .unit = "level" },
1092  { "5.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel52 }, 0, 0, VE, .unit = "level" },
1093  { "6.0", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel6 }, 0, 0, VE, .unit = "level" },
1094  { "6.1", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel61 }, 0, 0, VE, .unit = "level" },
1095  { "6.2", "", 0, AV_OPT_TYPE_CONST, { .i64 = AVCLevel62 }, 0, 0, VE, .unit = "level" },
1096  { NULL, }
1097 };
1098 
1100 
1101 #endif // CONFIG_H264_MEDIACODEC_ENCODER
1102 
1103 #if CONFIG_HEVC_MEDIACODEC_ENCODER
1104 
1105 enum MediaCodecHevcLevel {
1106  HEVCMainTierLevel1 = 0x1,
1107  HEVCHighTierLevel1 = 0x2,
1108  HEVCMainTierLevel2 = 0x4,
1109  HEVCHighTierLevel2 = 0x8,
1110  HEVCMainTierLevel21 = 0x10,
1111  HEVCHighTierLevel21 = 0x20,
1112  HEVCMainTierLevel3 = 0x40,
1113  HEVCHighTierLevel3 = 0x80,
1114  HEVCMainTierLevel31 = 0x100,
1115  HEVCHighTierLevel31 = 0x200,
1116  HEVCMainTierLevel4 = 0x400,
1117  HEVCHighTierLevel4 = 0x800,
1118  HEVCMainTierLevel41 = 0x1000,
1119  HEVCHighTierLevel41 = 0x2000,
1120  HEVCMainTierLevel5 = 0x4000,
1121  HEVCHighTierLevel5 = 0x8000,
1122  HEVCMainTierLevel51 = 0x10000,
1123  HEVCHighTierLevel51 = 0x20000,
1124  HEVCMainTierLevel52 = 0x40000,
1125  HEVCHighTierLevel52 = 0x80000,
1126  HEVCMainTierLevel6 = 0x100000,
1127  HEVCHighTierLevel6 = 0x200000,
1128  HEVCMainTierLevel61 = 0x400000,
1129  HEVCHighTierLevel61 = 0x800000,
1130  HEVCMainTierLevel62 = 0x1000000,
1131  HEVCHighTierLevel62 = 0x2000000,
1132 };
1133 
1134 static const AVOption hevc_options[] = {
1136 
1139 
1140  { "level", "Specify tier and level",
1141  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1142  { "m1", "Main tier level 1",
1143  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel1 }, 0, 0, VE, .unit = "level" },
1144  { "h1", "High tier level 1",
1145  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel1 }, 0, 0, VE, .unit = "level" },
1146  { "m2", "Main tier level 2",
1147  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel2 }, 0, 0, VE, .unit = "level" },
1148  { "h2", "High tier level 2",
1149  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel2 }, 0, 0, VE, .unit = "level" },
1150  { "m2.1", "Main tier level 2.1",
1151  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel21 }, 0, 0, VE, .unit = "level" },
1152  { "h2.1", "High tier level 2.1",
1153  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel21 }, 0, 0, VE, .unit = "level" },
1154  { "m3", "Main tier level 3",
1155  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel3 }, 0, 0, VE, .unit = "level" },
1156  { "h3", "High tier level 3",
1157  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel3 }, 0, 0, VE, .unit = "level" },
1158  { "m3.1", "Main tier level 3.1",
1159  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel31 }, 0, 0, VE, .unit = "level" },
1160  { "h3.1", "High tier level 3.1",
1161  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel31 }, 0, 0, VE, .unit = "level" },
1162  { "m4", "Main tier level 4",
1163  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel4 }, 0, 0, VE, .unit = "level" },
1164  { "h4", "High tier level 4",
1165  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel4 }, 0, 0, VE, .unit = "level" },
1166  { "m4.1", "Main tier level 4.1",
1167  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel41 }, 0, 0, VE, .unit = "level" },
1168  { "h4.1", "High tier level 4.1",
1169  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel41 }, 0, 0, VE, .unit = "level" },
1170  { "m5", "Main tier level 5",
1171  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel5 }, 0, 0, VE, .unit = "level" },
1172  { "h5", "High tier level 5",
1173  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel5 }, 0, 0, VE, .unit = "level" },
1174  { "m5.1", "Main tier level 5.1",
1175  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel51 }, 0, 0, VE, .unit = "level" },
1176  { "h5.1", "High tier level 5.1",
1177  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel51 }, 0, 0, VE, .unit = "level" },
1178  { "m5.2", "Main tier level 5.2",
1179  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel52 }, 0, 0, VE, .unit = "level" },
1180  { "h5.2", "High tier level 5.2",
1181  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel52 }, 0, 0, VE, .unit = "level" },
1182  { "m6", "Main tier level 6",
1183  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel6 }, 0, 0, VE, .unit = "level" },
1184  { "h6", "High tier level 6",
1185  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel6 }, 0, 0, VE, .unit = "level" },
1186  { "m6.1", "Main tier level 6.1",
1187  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel61 }, 0, 0, VE, .unit = "level" },
1188  { "h6.1", "High tier level 6.1",
1189  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel61 }, 0, 0, VE, .unit = "level" },
1190  { "m6.2", "Main tier level 6.2",
1191  0, AV_OPT_TYPE_CONST, { .i64 = HEVCMainTierLevel62 }, 0, 0, VE, .unit = "level" },
1192  { "h6.2", "High tier level 6.2",
1193  0, AV_OPT_TYPE_CONST, { .i64 = HEVCHighTierLevel62 }, 0, 0, VE, .unit = "level" },
1194  { NULL, }
1195 };
1196 
1198 
1199 #endif // CONFIG_HEVC_MEDIACODEC_ENCODER
1200 
1201 #if CONFIG_VP8_MEDIACODEC_ENCODER
1202 
1203 enum MediaCodecVP8Level {
1204  VP8Level_Version0 = 0x01,
1205  VP8Level_Version1 = 0x02,
1206  VP8Level_Version2 = 0x04,
1207  VP8Level_Version3 = 0x08,
1208 };
1209 
1210 static const AVOption vp8_options[] = {
1212  { "level", "Specify tier and level",
1213  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1214  { "V0", "Level Version 0",
1215  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version0 }, 0, 0, VE, .unit = "level" },
1216  { "V1", "Level Version 1",
1217  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version1 }, 0, 0, VE, .unit = "level" },
1218  { "V2", "Level Version 2",
1219  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version2 }, 0, 0, VE, .unit = "level" },
1220  { "V3", "Level Version 3",
1221  0, AV_OPT_TYPE_CONST, { .i64 = VP8Level_Version3 }, 0, 0, VE, .unit = "level" },
1222  { NULL, }
1223 };
1224 
1226 
1227 #endif // CONFIG_VP8_MEDIACODEC_ENCODER
1228 
1229 #if CONFIG_VP9_MEDIACODEC_ENCODER
1230 
1231 enum MediaCodecVP9Level {
1232  VP9Level1 = 0x1,
1233  VP9Level11 = 0x2,
1234  VP9Level2 = 0x4,
1235  VP9Level21 = 0x8,
1236  VP9Level3 = 0x10,
1237  VP9Level31 = 0x20,
1238  VP9Level4 = 0x40,
1239  VP9Level41 = 0x80,
1240  VP9Level5 = 0x100,
1241  VP9Level51 = 0x200,
1242  VP9Level52 = 0x400,
1243  VP9Level6 = 0x800,
1244  VP9Level61 = 0x1000,
1245  VP9Level62 = 0x2000,
1246 };
1247 
1248 static const AVOption vp9_options[] = {
1250 
1251  FF_AVCTX_PROFILE_OPTION("profile0", NULL, VIDEO, AV_PROFILE_VP9_0)
1252  FF_AVCTX_PROFILE_OPTION("profile1", NULL, VIDEO, AV_PROFILE_VP9_1)
1253  FF_AVCTX_PROFILE_OPTION("profile2", NULL, VIDEO, AV_PROFILE_VP9_2)
1254  FF_AVCTX_PROFILE_OPTION("profile3", NULL, VIDEO, AV_PROFILE_VP9_3)
1255 
1256  { "level", "Specify tier and level",
1257  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1258  { "1", "Level 1",
1259  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level1 }, 0, 0, VE, .unit = "level" },
1260  { "1.1", "Level 1.1",
1261  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level11 }, 0, 0, VE, .unit = "level" },
1262  { "2", "Level 2",
1263  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level2 }, 0, 0, VE, .unit = "level" },
1264  { "2.1", "Level 2.1",
1265  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level21 }, 0, 0, VE, .unit = "level" },
1266  { "3", "Level 3",
1267  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level3 }, 0, 0, VE, .unit = "level" },
1268  { "3.1", "Level 3.1",
1269  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level31 }, 0, 0, VE, .unit = "level" },
1270  { "4", "Level 4",
1271  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level4 }, 0, 0, VE, .unit = "level" },
1272  { "4.1", "Level 4.1",
1273  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level41 }, 0, 0, VE, .unit = "level" },
1274  { "5", "Level 5",
1275  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level5 }, 0, 0, VE, .unit = "level" },
1276  { "5.1", "Level 5.1",
1277  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level51 }, 0, 0, VE, .unit = "level" },
1278  { "5.2", "Level 5.2",
1279  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level52 }, 0, 0, VE, .unit = "level" },
1280  { "6", "Level 6",
1281  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level6 }, 0, 0, VE, .unit = "level" },
1282  { "6.1", "Level 4.1",
1283  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level61 }, 0, 0, VE, .unit = "level" },
1284  { "6.2", "Level 6.2",
1285  0, AV_OPT_TYPE_CONST, { .i64 = VP9Level62 }, 0, 0, VE, .unit = "level" },
1286  { NULL, }
1287 };
1288 
1290 
1291 #endif // CONFIG_VP9_MEDIACODEC_ENCODER
1292 
1293 #if CONFIG_MPEG4_MEDIACODEC_ENCODER
1294 
1295 enum MediaCodecMpeg4Level {
1296  MPEG4Level0 = 0x01,
1297  MPEG4Level0b = 0x02,
1298  MPEG4Level1 = 0x04,
1299  MPEG4Level2 = 0x08,
1300  MPEG4Level3 = 0x10,
1301  MPEG4Level3b = 0x18,
1302  MPEG4Level4 = 0x20,
1303  MPEG4Level4a = 0x40,
1304  MPEG4Level5 = 0x80,
1305  MPEG4Level6 = 0x100,
1306 };
1307 
1308 static const AVOption mpeg4_options[] = {
1310 
1312 
1313  { "level", "Specify tier and level",
1314  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1315  { "0", "Level 0",
1316  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0 }, 0, 0, VE, .unit = "level" },
1317  { "0b", "Level 0b",
1318  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level0b }, 0, 0, VE, .unit = "level" },
1319  { "1", "Level 1",
1320  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level1 }, 0, 0, VE, .unit = "level" },
1321  { "2", "Level 2",
1322  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level2 }, 0, 0, VE, .unit = "level" },
1323  { "3", "Level 3",
1324  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3 }, 0, 0, VE, .unit = "level" },
1325  { "3b", "Level 3b",
1326  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level3b }, 0, 0, VE, .unit = "level" },
1327  { "4", "Level 4",
1328  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4 }, 0, 0, VE, .unit = "level" },
1329  { "4a", "Level 4a",
1330  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level4a }, 0, 0, VE, .unit = "level" },
1331  { "5", "Level 5",
1332  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level5 }, 0, 0, VE, .unit = "level" },
1333  { "6", "Level 6",
1334  0, AV_OPT_TYPE_CONST, { .i64 = MPEG4Level6 }, 0, 0, VE, .unit = "level" },
1335  { NULL, }
1336 };
1337 
1339 
1340 #endif // CONFIG_MPEG4_MEDIACODEC_ENCODER
1341 
1342 #if CONFIG_AV1_MEDIACODEC_ENCODER
1343 
1344 enum MediaCodecAV1Level {
1345  AV1Level2 = 0x1,
1346  AV1Level21 = 0x2,
1347  AV1Level22 = 0x4,
1348  AV1Level23 = 0x8,
1349  AV1Level3 = 0x10,
1350  AV1Level31 = 0x20,
1351  AV1Level32 = 0x40,
1352  AV1Level33 = 0x80,
1353  AV1Level4 = 0x100,
1354  AV1Level41 = 0x200,
1355  AV1Level42 = 0x400,
1356  AV1Level43 = 0x800,
1357  AV1Level5 = 0x1000,
1358  AV1Level51 = 0x2000,
1359  AV1Level52 = 0x4000,
1360  AV1Level53 = 0x8000,
1361  AV1Level6 = 0x10000,
1362  AV1Level61 = 0x20000,
1363  AV1Level62 = 0x40000,
1364  AV1Level63 = 0x80000,
1365  AV1Level7 = 0x100000,
1366  AV1Level71 = 0x200000,
1367  AV1Level72 = 0x400000,
1368  AV1Level73 = 0x800000,
1369 };
1370 
1371 static const AVOption av1_options[] = {
1373 
1375 
1376  { "level", "Specify tier and level",
1377  OFFSET(level), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VE, .unit = "level" },
1378  { "2", "Level 2",
1379  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level2 }, 0, 0, VE, .unit = "level" },
1380  { "2.1", "Level 2.1",
1381  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level21 }, 0, 0, VE, .unit = "level" },
1382  { "2.2", "Level 2.2",
1383  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level22 }, 0, 0, VE, .unit = "level" },
1384  { "2.3", "Level 2.3",
1385  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level23 }, 0, 0, VE, .unit = "level" },
1386  { "3", "Level 3",
1387  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level3 }, 0, 0, VE, .unit = "level" },
1388  { "3.1", "Level 3.1",
1389  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level31 }, 0, 0, VE, .unit = "level" },
1390  { "3.2", "Level 3.2",
1391  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level32 }, 0, 0, VE, .unit = "level" },
1392  { "3.3", "Level 3.3",
1393  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level33 }, 0, 0, VE, .unit = "level" },
1394  { "4", "Level 4",
1395  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level4 }, 0, 0, VE, .unit = "level" },
1396  { "4.1", "Level 4.1",
1397  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level41 }, 0, 0, VE, .unit = "level" },
1398  { "4.2", "Level 4.2",
1399  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level42 }, 0, 0, VE, .unit = "level" },
1400  { "4.3", "Level 4.3",
1401  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level43 }, 0, 0, VE, .unit = "level" },
1402  { "5", "Level 5",
1403  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level5 }, 0, 0, VE, .unit = "level" },
1404  { "5.1", "Level 5.1",
1405  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level51 }, 0, 0, VE, .unit = "level" },
1406  { "5.2", "Level 5.2",
1407  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level52 }, 0, 0, VE, .unit = "level" },
1408  { "5.3", "Level 5.3",
1409  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level53 }, 0, 0, VE, .unit = "level" },
1410  { "6", "Level 6",
1411  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level6 }, 0, 0, VE, .unit = "level" },
1412  { "6.1", "Level 6.1",
1413  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level61 }, 0, 0, VE, .unit = "level" },
1414  { "6.2", "Level 6.2",
1415  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level62 }, 0, 0, VE, .unit = "level" },
1416  { "6.3", "Level 6.3",
1417  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level63 }, 0, 0, VE, .unit = "level" },
1418  { "7", "Level 7",
1419  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level7 }, 0, 0, VE, .unit = "level" },
1420  { "7.1", "Level 7.1",
1421  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level71 }, 0, 0, VE, .unit = "level" },
1422  { "7.2", "Level 7.2",
1423  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level72 }, 0, 0, VE, .unit = "level" },
1424  { "7.3", "Level 7.3",
1425  0, AV_OPT_TYPE_CONST, { .i64 = AV1Level73 }, 0, 0, VE, .unit = "level" },
1426  { NULL, }
1427 };
1428 
1430 
1431 #endif // CONFIG_AV1_MEDIACODEC_ENCODER
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
MediaCodecEncContext
Definition: mediacodecenc.c:59
MediaCodecEncContext::output_cond
AVCond output_cond
Definition: mediacodecenc.c:90
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:1461
ff_AMediaFormat_delete
static int ff_AMediaFormat_delete(FFAMediaFormat *format)
Definition: mediacodec_wrapper.h:92
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
ff_AMediaCodec_delete
static int ff_AMediaCodec_delete(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h: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
mediacodec_init_async_state
static int mediacodec_init_async_state(AVCodecContext *avctx)
Definition: mediacodecenc.c:295
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:79
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:238
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:691
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:292
DECLARE_MEDIACODEC_ENCODER
#define DECLARE_MEDIACODEC_ENCODER(short_name, long_name, codec_id)
Definition: mediacodecenc.c:1014
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:85
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:247
MediaCodecEncContext::avclass
AVClass * avclass
Definition: mediacodecenc.c:60
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:80
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:103
int64_t
long long int64_t
Definition: coverity.c:34
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:702
MediaCodecEncContext::fps
int fps
Definition: mediacodecenc.c:66
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:684
MediaCodecEncContext::window
FFANativeWindow * window
Definition: mediacodecenc.c:64
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:141
MediaCodecEncContext::eof_sent
int eof_sent
Definition: mediacodecenc.c:72
COMMON_OPTION
#define COMMON_OPTION
Definition: mediacodecenc.c:983
mediacodec_encode
static int mediacodec_encode(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:786
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
hwcontext_mediacodec.h
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
ff_AMediaFormat_setInt32
static void ff_AMediaFormat_setInt32(FFAMediaFormat *format, const char *name, int32_t value)
Definition: mediacodec_wrapper.h:135
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
mediacodec_send_dummy_frame
static int mediacodec_send_dummy_frame(AVCodecContext *avctx)
Definition: mediacodecenc.c:832
VE
#define VE
Definition: mediacodecenc.c:982
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:130
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
AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_H264_EXTENDED
Definition: defs.h:113
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:566
fifo.h
bsf.h
mediacodec_flush
static av_cold void mediacodec_flush(AVCodecContext *avctx)
Definition: mediacodecenc.c:959
av1_options
static const AVOption av1_options[]
Definition: av1dec.c:1561
mediacodec_close
static av_cold int mediacodec_close(AVCodecContext *avctx)
Definition: mediacodecenc.c:937
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:70
MediaCodecEncContext::async_mode
int async_mode
Definition: mediacodecenc.c:83
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
pix_fmt
enum AVPixelFormat pix_fmt
Definition: mediacodecenc.c:104
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:252
mediacodec_send
static int mediacodec_send(AVCodecContext *avctx, const AVFrame *frame)
Definition: mediacodecenc.c:735
mediacodec_uninit_async_state
static void mediacodec_uninit_async_state(AVCodecContext *avctx)
Definition: mediacodecenc.c:319
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:77
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:530
ff_AMediaCodec_getBufferFlagEndOfStream
static int ff_AMediaCodec_getBufferFlagEndOfStream(FFAMediaCodec *codec)
Definition: mediacodec_wrapper.h:342
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:1249
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:274
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:268
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
mediacodec_dump_format
static void mediacodec_dump_format(AVCodecContext *avctx, FFAMediaFormat *out_format)
Definition: mediacodecenc.c:118
OFFSET
#define OFFSET(x)
Definition: mediacodecenc.c:981
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:62
AV_PIX_FMT_MEDIACODEC
@ AV_PIX_FMT_MEDIACODEC
hardware decoding through MediaCodec
Definition: pixfmt.h:316
COLOR_FormatYUV420SemiPlanar
@ COLOR_FormatYUV420SemiPlanar
Definition: mediacodecenc.c:98
mediacodec_generate_extradata
static int mediacodec_generate_extradata(AVCodecContext *avctx)
Definition: mediacodecenc.c:885
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:91
MediaCodecEncContext::level
int level
Definition: mediacodecenc.c:78
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
color_formats
static const struct @178 color_formats[]
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:701
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
MediaCodecEncContext::input_index
AVFifo * input_index
Definition: mediacodecenc.c:87
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
MediaCodecEncContext::output_index
AVFifo * output_index
Definition: mediacodecenc.c:92
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:550
AVFifo
Definition: fifo.c:35
MediaCodecEncContext::input_cond
AVCond input_cond
Definition: mediacodecenc.c:86
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1037
h264_options
static const AVOption h264_options[]
Definition: h264dec.c:1107
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
COLOR_TRANSFER_UNSPECIFIED
@ COLOR_TRANSFER_UNSPECIFIED
Definition: mediacodec_wrapper.h:391
avc_pix_fmts
static enum AVPixelFormat avc_pix_fmts[]
Definition: mediacodecenc.c:111
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:863
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:75
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:63
MediaCodecEncContext::name
const char * name
Definition: mediacodecenc.c:63
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
MediaCodecEncContext::width
int width
Definition: mediacodecenc.c:67
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:61
FFANativeWindow
Definition: mediacodec_surface.h:28
MediaCodecEncContext::operating_rate
int operating_rate
Definition: mediacodecenc.c:82
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
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:529
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:252
FFAMediaCodec
Definition: mediacodec_wrapper.h:197
MediaCodecEncContext::height
int height
Definition: mediacodecenc.c:68
MediaCodecEncContext::extradata_size
int extradata_size
Definition: mediacodecenc.c:71
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:610
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
FFAMediaCodecBufferInfo::flags
uint32_t flags
Definition: mediacodec_wrapper.h:176
AVCodecContext::hw_device_ctx
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
Definition: avcodec.h:1507
AVMediaCodecContext::surface
void * surface
android/view/Surface object reference.
Definition: mediacodec.h:38
ff_mediacodec_surface_ref
FFANativeWindow * ff_mediacodec_surface_ref(void *surface, void *native_window, void *log_ctx)
Definition: mediacodec_surface.c:30
MediaCodecEncContext::frame
AVFrame * frame
Definition: mediacodecenc.c:74
INPUT_DEQUEUE_TIMEOUT_US
#define INPUT_DEQUEUE_TIMEOUT_US
Definition: mediacodecenc.c:45
AVCodecContext::height
int height
Definition: avcodec.h:624
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:663
av_jni_get_java_vm
void * av_jni_get_java_vm(void *log_ctx)
Definition: jni.c:75
AVMediaCodecDeviceContext::native_window
void * native_window
Pointer to ANativeWindow.
Definition: hwcontext_mediacodec.h:45
FFAMediaCodecBufferInfo::presentationTimeUs
int64_t presentationTimeUs
Definition: mediacodec_wrapper.h:175
ff_AMediaCodec_dequeueInputBuffer
static ssize_t ff_AMediaCodec_dequeueInputBuffer(FFAMediaCodec *codec, int64_t timeoutUs)
Definition: mediacodec_wrapper.h:292
avcodec.h
MediaCodecEncContext::output_buf_info
AVFifo * output_buf_info
Definition: mediacodecenc.c:93
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:89
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1389
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:110
av_mediacodec_release_buffer
int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render)
Release a MediaCodec buffer and render it to the surface that is associated with the decoder.
Definition: mediacodec.c:138
av_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:341
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:572
ff_cond_signal
static int ff_cond_signal(AVCond *cond)
Definition: thread.h:196
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
COLOR_FormatYUV420Planar
@ COLOR_FormatYUV420Planar
Definition: mediacodecenc.c:97
AV_PROFILE_H264_HIGH_444
#define AV_PROFILE_H264_HIGH_444
Definition: defs.h:121
mem.h
AVCodecContext::max_b_frames
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
Definition: avcodec.h:801
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:205
ff_AMediaCodec_getOutputBuffer
static uint8_t * ff_AMediaCodec_getOutputBuffer(FFAMediaCodec *codec, size_t idx, size_t *out_size)
Definition: mediacodec_wrapper.h: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:624
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:968
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:210
COLOR_FormatSurface
@ COLOR_FormatSurface
Definition: mediacodecenc.c:99
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:158
mediacodec_receive
static int mediacodec_receive(AVCodecContext *avctx, AVPacket *pkt)
Definition: mediacodecenc.c:614
mediacodec.h
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:87