FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
omx.c
Go to the documentation of this file.
1 /*
2  * OMX Video encoder
3  * Copyright (C) 2011 Martin Storsjo
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 
24 #if CONFIG_OMX_RPI
25 #define OMX_SKIP64BIT
26 #endif
27 
28 #include <dlfcn.h>
29 #include <OMX_Core.h>
30 #include <OMX_Component.h>
31 #include <pthread.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <sys/time.h>
35 
36 #include "libavutil/avstring.h"
37 #include "libavutil/avutil.h"
38 #include "libavutil/common.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/log.h"
41 #include "libavutil/opt.h"
42 
43 #include "avcodec.h"
44 #include "h264.h"
45 #include "internal.h"
46 
47 #ifdef OMX_SKIP64BIT
48 static OMX_TICKS to_omx_ticks(int64_t value)
49 {
50  OMX_TICKS s;
51  s.nLowPart = value & 0xffffffff;
52  s.nHighPart = value >> 32;
53  return s;
54 }
55 static int64_t from_omx_ticks(OMX_TICKS value)
56 {
57  return (((int64_t)value.nHighPart) << 32) | value.nLowPart;
58 }
59 #else
60 #define to_omx_ticks(x) (x)
61 #define from_omx_ticks(x) (x)
62 #endif
63 
64 #define INIT_STRUCT(x) do { \
65  x.nSize = sizeof(x); \
66  x.nVersion = s->version; \
67  } while (0)
68 #define CHECK(x) do { \
69  if (x != OMX_ErrorNone) { \
70  av_log(avctx, AV_LOG_ERROR, \
71  "err %x (%d) on line %d\n", x, x, __LINE__); \
72  return AVERROR_UNKNOWN; \
73  } \
74  } while (0)
75 
76 typedef struct OMXContext {
77  void *lib;
78  void *lib2;
79  OMX_ERRORTYPE (*ptr_Init)(void);
80  OMX_ERRORTYPE (*ptr_Deinit)(void);
81  OMX_ERRORTYPE (*ptr_ComponentNameEnum)(OMX_STRING, OMX_U32, OMX_U32);
82  OMX_ERRORTYPE (*ptr_GetHandle)(OMX_HANDLETYPE*, OMX_STRING, OMX_PTR, OMX_CALLBACKTYPE*);
83  OMX_ERRORTYPE (*ptr_FreeHandle)(OMX_HANDLETYPE);
84  OMX_ERRORTYPE (*ptr_GetComponentsOfRole)(OMX_STRING, OMX_U32*, OMX_U8**);
85  OMX_ERRORTYPE (*ptr_GetRolesOfComponent)(OMX_STRING, OMX_U32*, OMX_U8**);
87 } OMXContext;
88 
89 static av_cold void *dlsym_prefixed(void *handle, const char *symbol, const char *prefix)
90 {
91  char buf[50];
92  snprintf(buf, sizeof(buf), "%s%s", prefix ? prefix : "", symbol);
93  return dlsym(handle, buf);
94 }
95 
96 static av_cold int omx_try_load(OMXContext *s, void *logctx,
97  const char *libname, const char *prefix,
98  const char *libname2)
99 {
100  if (libname2) {
101  s->lib2 = dlopen(libname2, RTLD_NOW | RTLD_GLOBAL);
102  if (!s->lib2) {
103  av_log(logctx, AV_LOG_WARNING, "%s not found\n", libname);
105  }
106  s->host_init = dlsym(s->lib2, "bcm_host_init");
107  if (!s->host_init) {
108  av_log(logctx, AV_LOG_WARNING, "bcm_host_init not found\n");
109  dlclose(s->lib2);
110  s->lib2 = NULL;
112  }
113  }
114  s->lib = dlopen(libname, RTLD_NOW | RTLD_GLOBAL);
115  if (!s->lib) {
116  av_log(logctx, AV_LOG_WARNING, "%s not found\n", libname);
118  }
119  s->ptr_Init = dlsym_prefixed(s->lib, "OMX_Init", prefix);
120  s->ptr_Deinit = dlsym_prefixed(s->lib, "OMX_Deinit", prefix);
121  s->ptr_ComponentNameEnum = dlsym_prefixed(s->lib, "OMX_ComponentNameEnum", prefix);
122  s->ptr_GetHandle = dlsym_prefixed(s->lib, "OMX_GetHandle", prefix);
123  s->ptr_FreeHandle = dlsym_prefixed(s->lib, "OMX_FreeHandle", prefix);
124  s->ptr_GetComponentsOfRole = dlsym_prefixed(s->lib, "OMX_GetComponentsOfRole", prefix);
125  s->ptr_GetRolesOfComponent = dlsym_prefixed(s->lib, "OMX_GetRolesOfComponent", prefix);
126  if (!s->ptr_Init || !s->ptr_Deinit || !s->ptr_ComponentNameEnum ||
127  !s->ptr_GetHandle || !s->ptr_FreeHandle ||
129  av_log(logctx, AV_LOG_WARNING, "Not all functions found in %s\n", libname);
130  dlclose(s->lib);
131  s->lib = NULL;
132  if (s->lib2)
133  dlclose(s->lib2);
134  s->lib2 = NULL;
136  }
137  return 0;
138 }
139 
140 static av_cold OMXContext *omx_init(void *logctx, const char *libname, const char *prefix)
141 {
142  static const char * const libnames[] = {
143 #if CONFIG_OMX_RPI
144  "/opt/vc/lib/libopenmaxil.so", "/opt/vc/lib/libbcm_host.so",
145 #else
146  "libOMX_Core.so", NULL,
147  "libOmxCore.so", NULL,
148 #endif
149  NULL
150  };
151  const char* const* nameptr;
152  int ret = AVERROR_ENCODER_NOT_FOUND;
153  OMXContext *omx_context;
154 
155  omx_context = av_mallocz(sizeof(*omx_context));
156  if (!omx_context)
157  return NULL;
158  if (libname) {
159  ret = omx_try_load(omx_context, logctx, libname, prefix, NULL);
160  if (ret < 0) {
161  av_free(omx_context);
162  return NULL;
163  }
164  } else {
165  for (nameptr = libnames; *nameptr; nameptr += 2)
166  if (!(ret = omx_try_load(omx_context, logctx, nameptr[0], prefix, nameptr[1])))
167  break;
168  if (!*nameptr) {
169  av_free(omx_context);
170  return NULL;
171  }
172  }
173 
174  if (omx_context->host_init)
175  omx_context->host_init();
176  omx_context->ptr_Init();
177  return omx_context;
178 }
179 
180 static av_cold void omx_deinit(OMXContext *omx_context)
181 {
182  if (!omx_context)
183  return;
184  omx_context->ptr_Deinit();
185  dlclose(omx_context->lib);
186  av_free(omx_context);
187 }
188 
189 typedef struct OMXCodecContext {
190  const AVClass *class;
191  char *libname;
192  char *libprefix;
194 
196 
197  char component_name[OMX_MAX_STRINGNAME_SIZE];
198  OMX_VERSIONTYPE version;
199  OMX_HANDLETYPE handle;
201  OMX_COLOR_FORMATTYPE color_format;
203 
205  OMX_BUFFERHEADERTYPE **in_buffer_headers;
206  OMX_BUFFERHEADERTYPE **out_buffer_headers;
208  OMX_BUFFERHEADERTYPE **free_in_buffers;
210  OMX_BUFFERHEADERTYPE **done_out_buffers;
215 
218  OMX_STATETYPE state;
219  OMX_ERRORTYPE error;
220 
222 
224 
227 
230 
232  int* array_size, OMX_BUFFERHEADERTYPE **array,
233  OMX_BUFFERHEADERTYPE *buffer)
234 {
235  pthread_mutex_lock(mutex);
236  array[(*array_size)++] = buffer;
238  pthread_mutex_unlock(mutex);
239 }
240 
241 static OMX_BUFFERHEADERTYPE *get_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond,
242  int* array_size, OMX_BUFFERHEADERTYPE **array,
243  int wait)
244 {
245  OMX_BUFFERHEADERTYPE *buffer;
246  pthread_mutex_lock(mutex);
247  if (wait) {
248  while (!*array_size)
249  pthread_cond_wait(cond, mutex);
250  }
251  if (*array_size > 0) {
252  buffer = array[0];
253  (*array_size)--;
254  memmove(&array[0], &array[1], (*array_size) * sizeof(OMX_BUFFERHEADERTYPE*));
255  } else {
256  buffer = NULL;
257  }
258  pthread_mutex_unlock(mutex);
259  return buffer;
260 }
261 
262 static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_EVENTTYPE event,
263  OMX_U32 data1, OMX_U32 data2, OMX_PTR event_data)
264 {
265  OMXCodecContext *s = app_data;
266  // This uses casts in the printfs, since OMX_U32 actually is a typedef for
267  // unsigned long in official header versions (but there are also modified
268  // versions where it is something else).
269  switch (event) {
270  case OMX_EventError:
272  av_log(s->avctx, AV_LOG_ERROR, "OMX error %"PRIx32"\n", (uint32_t) data1);
273  s->error = data1;
276  break;
277  case OMX_EventCmdComplete:
278  if (data1 == OMX_CommandStateSet) {
280  s->state = data2;
281  av_log(s->avctx, AV_LOG_VERBOSE, "OMX state changed to %"PRIu32"\n", (uint32_t) data2);
284  } else if (data1 == OMX_CommandPortDisable) {
285  av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" disabled\n", (uint32_t) data2);
286  } else if (data1 == OMX_CommandPortEnable) {
287  av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" enabled\n", (uint32_t) data2);
288  } else {
289  av_log(s->avctx, AV_LOG_VERBOSE, "OMX command complete, command %"PRIu32", value %"PRIu32"\n",
290  (uint32_t) data1, (uint32_t) data2);
291  }
292  break;
293  case OMX_EventPortSettingsChanged:
294  av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" settings changed\n", (uint32_t) data1);
295  break;
296  default:
297  av_log(s->avctx, AV_LOG_VERBOSE, "OMX event %d %"PRIx32" %"PRIx32"\n",
298  event, (uint32_t) data1, (uint32_t) data2);
299  break;
300  }
301  return OMX_ErrorNone;
302 }
303 
304 static OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
305  OMX_BUFFERHEADERTYPE *buffer)
306 {
307  OMXCodecContext *s = app_data;
308  if (s->input_zerocopy) {
309  if (buffer->pAppPrivate) {
310  if (buffer->pOutputPortPrivate)
311  av_free(buffer->pAppPrivate);
312  else
313  av_frame_free((AVFrame**)&buffer->pAppPrivate);
314  buffer->pAppPrivate = NULL;
315  }
316  }
318  &s->num_free_in_buffers, s->free_in_buffers, buffer);
319  return OMX_ErrorNone;
320 }
321 
322 static OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
323  OMX_BUFFERHEADERTYPE *buffer)
324 {
325  OMXCodecContext *s = app_data;
327  &s->num_done_out_buffers, s->done_out_buffers, buffer);
328  return OMX_ErrorNone;
329 }
330 
331 static const OMX_CALLBACKTYPE callbacks = {
335 };
336 
337 static av_cold int find_component(OMXContext *omx_context, void *logctx,
338  const char *role, char *str, int str_size)
339 {
340  OMX_U32 i, num = 0;
341  char **components;
342  int ret = 0;
343 
344 #if CONFIG_OMX_RPI
345  if (av_strstart(role, "video_encoder.", NULL)) {
346  av_strlcpy(str, "OMX.broadcom.video_encode", str_size);
347  return 0;
348  }
349 #endif
350  omx_context->ptr_GetComponentsOfRole((OMX_STRING) role, &num, NULL);
351  if (!num) {
352  av_log(logctx, AV_LOG_WARNING, "No component for role %s found\n", role);
354  }
355  components = av_mallocz(sizeof(char*) * num);
356  if (!components)
357  return AVERROR(ENOMEM);
358  for (i = 0; i < num; i++) {
359  components[i] = av_mallocz(OMX_MAX_STRINGNAME_SIZE);
360  if (!components) {
361  ret = AVERROR(ENOMEM);
362  goto end;
363  }
364  }
365  omx_context->ptr_GetComponentsOfRole((OMX_STRING) role, &num, (OMX_U8**) components);
366  av_strlcpy(str, components[0], str_size);
367 end:
368  for (i = 0; i < num; i++)
369  av_free(components[i]);
370  av_free(components);
371  return ret;
372 }
373 
374 static av_cold int wait_for_state(OMXCodecContext *s, OMX_STATETYPE state)
375 {
376  int ret = 0;
378  while (s->state != state && s->error == OMX_ErrorNone)
380  if (s->error != OMX_ErrorNone)
383  return ret;
384 }
385 
386 static av_cold int omx_component_init(AVCodecContext *avctx, const char *role)
387 {
388  OMXCodecContext *s = avctx->priv_data;
389  OMX_PARAM_COMPONENTROLETYPE role_params = { 0 };
390  OMX_PORT_PARAM_TYPE video_port_params = { 0 };
391  OMX_PARAM_PORTDEFINITIONTYPE in_port_params = { 0 }, out_port_params = { 0 };
392  OMX_VIDEO_PARAM_PORTFORMATTYPE video_port_format = { 0 };
393  OMX_VIDEO_PARAM_BITRATETYPE vid_param_bitrate = { 0 };
394  OMX_ERRORTYPE err;
395  int i;
396 
397  s->version.s.nVersionMajor = 1;
398  s->version.s.nVersionMinor = 1;
399  s->version.s.nRevision = 2;
400 
401  err = s->omx_context->ptr_GetHandle(&s->handle, s->component_name, s, (OMX_CALLBACKTYPE*) &callbacks);
402  if (err != OMX_ErrorNone) {
403  av_log(avctx, AV_LOG_ERROR, "OMX_GetHandle(%s) failed: %x\n", s->component_name, err);
404  return AVERROR_UNKNOWN;
405  }
406 
407  // This one crashes the mediaserver on qcom, if used over IOMX
408  INIT_STRUCT(role_params);
409  av_strlcpy(role_params.cRole, role, sizeof(role_params.cRole));
410  // Intentionally ignore errors on this one
411  OMX_SetParameter(s->handle, OMX_IndexParamStandardComponentRole, &role_params);
412 
413  INIT_STRUCT(video_port_params);
414  err = OMX_GetParameter(s->handle, OMX_IndexParamVideoInit, &video_port_params);
415  CHECK(err);
416 
417  s->in_port = s->out_port = -1;
418  for (i = 0; i < video_port_params.nPorts; i++) {
419  int port = video_port_params.nStartPortNumber + i;
420  OMX_PARAM_PORTDEFINITIONTYPE port_params = { 0 };
421  INIT_STRUCT(port_params);
422  port_params.nPortIndex = port;
423  err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &port_params);
424  if (err != OMX_ErrorNone) {
425  av_log(avctx, AV_LOG_WARNING, "port %d error %x\n", port, err);
426  break;
427  }
428  if (port_params.eDir == OMX_DirInput && s->in_port < 0) {
429  in_port_params = port_params;
430  s->in_port = port;
431  } else if (port_params.eDir == OMX_DirOutput && s->out_port < 0) {
432  out_port_params = port_params;
433  s->out_port = port;
434  }
435  }
436  if (s->in_port < 0 || s->out_port < 0) {
437  av_log(avctx, AV_LOG_ERROR, "No in or out port found (in %d out %d)\n", s->in_port, s->out_port);
438  return AVERROR_UNKNOWN;
439  }
440 
441  s->color_format = 0;
442  for (i = 0; ; i++) {
443  INIT_STRUCT(video_port_format);
444  video_port_format.nIndex = i;
445  video_port_format.nPortIndex = s->in_port;
446  if (OMX_GetParameter(s->handle, OMX_IndexParamVideoPortFormat, &video_port_format) != OMX_ErrorNone)
447  break;
448  if (video_port_format.eColorFormat == OMX_COLOR_FormatYUV420Planar ||
449  video_port_format.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar) {
450  s->color_format = video_port_format.eColorFormat;
451  break;
452  }
453  }
454  if (s->color_format == 0) {
455  av_log(avctx, AV_LOG_ERROR, "No supported pixel formats (%d formats available)\n", i);
456  return AVERROR_UNKNOWN;
457  }
458 
459  in_port_params.bEnabled = OMX_TRUE;
460  in_port_params.bPopulated = OMX_FALSE;
461  in_port_params.eDomain = OMX_PortDomainVideo;
462 
463  in_port_params.format.video.pNativeRender = NULL;
464  in_port_params.format.video.bFlagErrorConcealment = OMX_FALSE;
465  in_port_params.format.video.eColorFormat = s->color_format;
466  s->stride = avctx->width;
467  s->plane_size = avctx->height;
468  // If specific codecs need to manually override the stride/plane_size,
469  // that can be done here.
470  in_port_params.format.video.nStride = s->stride;
471  in_port_params.format.video.nSliceHeight = s->plane_size;
472  in_port_params.format.video.nFrameWidth = avctx->width;
473  in_port_params.format.video.nFrameHeight = avctx->height;
474  if (avctx->framerate.den > 0 && avctx->framerate.num > 0)
475  in_port_params.format.video.xFramerate = (1 << 16) * avctx->framerate.num / avctx->framerate.den;
476  else
477  in_port_params.format.video.xFramerate = (1 << 16) * avctx->time_base.den / avctx->time_base.num;
478 
479  err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, &in_port_params);
480  CHECK(err);
481  err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &in_port_params);
482  CHECK(err);
483  s->stride = in_port_params.format.video.nStride;
484  s->plane_size = in_port_params.format.video.nSliceHeight;
485  s->num_in_buffers = in_port_params.nBufferCountActual;
486 
487  err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
488  out_port_params.bEnabled = OMX_TRUE;
489  out_port_params.bPopulated = OMX_FALSE;
490  out_port_params.eDomain = OMX_PortDomainVideo;
491  out_port_params.format.video.pNativeRender = NULL;
492  out_port_params.format.video.nFrameWidth = avctx->width;
493  out_port_params.format.video.nFrameHeight = avctx->height;
494  out_port_params.format.video.nStride = 0;
495  out_port_params.format.video.nSliceHeight = 0;
496  out_port_params.format.video.nBitrate = avctx->bit_rate;
497  out_port_params.format.video.xFramerate = in_port_params.format.video.xFramerate;
498  out_port_params.format.video.bFlagErrorConcealment = OMX_FALSE;
499  if (avctx->codec->id == AV_CODEC_ID_MPEG4)
500  out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
501  else if (avctx->codec->id == AV_CODEC_ID_H264)
502  out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
503 
504  err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
505  CHECK(err);
506  err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
507  CHECK(err);
508  s->num_out_buffers = out_port_params.nBufferCountActual;
509 
510  INIT_STRUCT(vid_param_bitrate);
511  vid_param_bitrate.nPortIndex = s->out_port;
512  vid_param_bitrate.eControlRate = OMX_Video_ControlRateVariable;
513  vid_param_bitrate.nTargetBitrate = avctx->bit_rate;
514  err = OMX_SetParameter(s->handle, OMX_IndexParamVideoBitrate, &vid_param_bitrate);
515  if (err != OMX_ErrorNone)
516  av_log(avctx, AV_LOG_WARNING, "Unable to set video bitrate parameter\n");
517 
518  if (avctx->codec->id == AV_CODEC_ID_H264) {
519  OMX_VIDEO_PARAM_AVCTYPE avc = { 0 };
520  INIT_STRUCT(avc);
521  avc.nPortIndex = s->out_port;
522  err = OMX_GetParameter(s->handle, OMX_IndexParamVideoAvc, &avc);
523  CHECK(err);
524  avc.nBFrames = 0;
525  avc.nPFrames = avctx->gop_size - 1;
526  err = OMX_SetParameter(s->handle, OMX_IndexParamVideoAvc, &avc);
527  CHECK(err);
528  }
529 
530  err = OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
531  CHECK(err);
532 
533  s->in_buffer_headers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_in_buffers);
534  s->free_in_buffers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_in_buffers);
535  s->out_buffer_headers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_out_buffers);
536  s->done_out_buffers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_out_buffers);
538  return AVERROR(ENOMEM);
539  for (i = 0; i < s->num_in_buffers && err == OMX_ErrorNone; i++) {
540  if (s->input_zerocopy)
541  err = OMX_UseBuffer(s->handle, &s->in_buffer_headers[i], s->in_port, s, in_port_params.nBufferSize, NULL);
542  else
543  err = OMX_AllocateBuffer(s->handle, &s->in_buffer_headers[i], s->in_port, s, in_port_params.nBufferSize);
544  if (err == OMX_ErrorNone)
545  s->in_buffer_headers[i]->pAppPrivate = s->in_buffer_headers[i]->pOutputPortPrivate = NULL;
546  }
547  CHECK(err);
548  s->num_in_buffers = i;
549  for (i = 0; i < s->num_out_buffers && err == OMX_ErrorNone; i++)
550  err = OMX_AllocateBuffer(s->handle, &s->out_buffer_headers[i], s->out_port, s, out_port_params.nBufferSize);
551  CHECK(err);
552  s->num_out_buffers = i;
553 
554  if (wait_for_state(s, OMX_StateIdle) < 0) {
555  av_log(avctx, AV_LOG_ERROR, "Didn't get OMX_StateIdle\n");
556  return AVERROR_UNKNOWN;
557  }
558  err = OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
559  CHECK(err);
560  if (wait_for_state(s, OMX_StateExecuting) < 0) {
561  av_log(avctx, AV_LOG_ERROR, "Didn't get OMX_StateExecuting\n");
562  return AVERROR_UNKNOWN;
563  }
564 
565  for (i = 0; i < s->num_out_buffers && err == OMX_ErrorNone; i++)
566  err = OMX_FillThisBuffer(s->handle, s->out_buffer_headers[i]);
567  if (err != OMX_ErrorNone) {
568  for (; i < s->num_out_buffers; i++)
570  }
571  for (i = 0; i < s->num_in_buffers; i++)
573  return err != OMX_ErrorNone ? AVERROR_UNKNOWN : 0;
574 }
575 
577 {
578  int i, executing;
579 
581  executing = s->state == OMX_StateExecuting;
583 
584  if (executing) {
585  OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
586  wait_for_state(s, OMX_StateIdle);
587  OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
588  for (i = 0; i < s->num_in_buffers; i++) {
589  OMX_BUFFERHEADERTYPE *buffer = get_buffer(&s->input_mutex, &s->input_cond,
591  if (s->input_zerocopy)
592  buffer->pBuffer = NULL;
593  OMX_FreeBuffer(s->handle, s->in_port, buffer);
594  }
595  for (i = 0; i < s->num_out_buffers; i++) {
596  OMX_BUFFERHEADERTYPE *buffer = get_buffer(&s->output_mutex, &s->output_cond,
598  OMX_FreeBuffer(s->handle, s->out_port, buffer);
599  }
600  wait_for_state(s, OMX_StateLoaded);
601  }
602  if (s->handle) {
604  s->handle = NULL;
605  }
606 
608  s->omx_context = NULL;
609  if (s->mutex_cond_inited) {
616  s->mutex_cond_inited = 0;
617  }
622  av_freep(&s->output_buf);
623 }
624 
626 {
627  OMXCodecContext *s = avctx->priv_data;
628  int ret = AVERROR_ENCODER_NOT_FOUND;
629  const char *role;
630  OMX_BUFFERHEADERTYPE *buffer;
631  OMX_ERRORTYPE err;
632 
633 #if CONFIG_OMX_RPI
634  s->input_zerocopy = 1;
635 #endif
636 
637  s->omx_context = omx_init(avctx, s->libname, s->libprefix);
638  if (!s->omx_context)
640 
647  s->mutex_cond_inited = 1;
648  s->avctx = avctx;
649  s->state = OMX_StateLoaded;
650  s->error = OMX_ErrorNone;
651 
652  switch (avctx->codec->id) {
653  case AV_CODEC_ID_MPEG4:
654  role = "video_encoder.mpeg4";
655  break;
656  case AV_CODEC_ID_H264:
657  role = "video_encoder.avc";
658  break;
659  default:
660  return AVERROR(ENOSYS);
661  }
662 
663  if ((ret = find_component(s->omx_context, avctx, role, s->component_name, sizeof(s->component_name))) < 0)
664  goto fail;
665 
666  av_log(avctx, AV_LOG_INFO, "Using %s\n", s->component_name);
667 
668  if ((ret = omx_component_init(avctx, role)) < 0)
669  goto fail;
670 
671  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
672  while (1) {
673  buffer = get_buffer(&s->output_mutex, &s->output_cond,
675  if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
676  if ((ret = av_reallocp(&avctx->extradata, avctx->extradata_size + buffer->nFilledLen + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {
677  avctx->extradata_size = 0;
678  goto fail;
679  }
680  memcpy(avctx->extradata + avctx->extradata_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen);
681  avctx->extradata_size += buffer->nFilledLen;
682  memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
683  }
684  err = OMX_FillThisBuffer(s->handle, buffer);
685  if (err != OMX_ErrorNone) {
687  &s->num_done_out_buffers, s->done_out_buffers, buffer);
688  av_log(avctx, AV_LOG_ERROR, "OMX_FillThisBuffer failed: %x\n", err);
689  ret = AVERROR_UNKNOWN;
690  goto fail;
691  }
692  if (avctx->codec->id == AV_CODEC_ID_H264) {
693  // For H.264, the extradata can be returned in two separate buffers
694  // (the videocore encoder on raspberry pi does this);
695  // therefore check that we have got both SPS and PPS before continuing.
696  int nals[32] = { 0 };
697  int i;
698  for (i = 0; i + 4 < avctx->extradata_size; i++) {
699  if (!avctx->extradata[i + 0] &&
700  !avctx->extradata[i + 1] &&
701  !avctx->extradata[i + 2] &&
702  avctx->extradata[i + 3] == 1) {
703  nals[avctx->extradata[i + 4] & 0x1f]++;
704  }
705  }
706  if (nals[H264_NAL_SPS] && nals[H264_NAL_PPS])
707  break;
708  } else {
709  if (avctx->extradata_size > 0)
710  break;
711  }
712  }
713  }
714 
715  return 0;
716 fail:
717  return ret;
718 }
719 
720 
722  const AVFrame *frame, int *got_packet)
723 {
724  OMXCodecContext *s = avctx->priv_data;
725  int ret = 0;
726  OMX_BUFFERHEADERTYPE* buffer;
727  OMX_ERRORTYPE err;
728 
729  if (frame) {
730  uint8_t *dst[4];
731  int linesize[4];
732  int need_copy;
733  buffer = get_buffer(&s->input_mutex, &s->input_cond,
735 
736  buffer->nFilledLen = av_image_fill_arrays(dst, linesize, buffer->pBuffer, avctx->pix_fmt, s->stride, s->plane_size, 1);
737 
738  if (s->input_zerocopy) {
739  uint8_t *src[4] = { NULL };
740  int src_linesize[4];
741  av_image_fill_arrays(src, src_linesize, frame->data[0], avctx->pix_fmt, s->stride, s->plane_size, 1);
742  if (frame->linesize[0] == src_linesize[0] &&
743  frame->linesize[1] == src_linesize[1] &&
744  frame->linesize[2] == src_linesize[2] &&
745  frame->data[1] == src[1] &&
746  frame->data[2] == src[2]) {
747  // If the input frame happens to have all planes stored contiguously,
748  // with the right strides, just clone the frame and set the OMX
749  // buffer header to point to it
750  AVFrame *local = av_frame_clone(frame);
751  if (!local) {
752  // Return the buffer to the queue so it's not lost
754  return AVERROR(ENOMEM);
755  } else {
756  buffer->pAppPrivate = local;
757  buffer->pOutputPortPrivate = NULL;
758  buffer->pBuffer = local->data[0];
759  need_copy = 0;
760  }
761  } else {
762  // If not, we need to allocate a new buffer with the right
763  // size and copy the input frame into it.
765  if (!buf) {
766  // Return the buffer to the queue so it's not lost
768  return AVERROR(ENOMEM);
769  } else {
770  buffer->pAppPrivate = buf;
771  // Mark that pAppPrivate is an av_malloc'ed buffer, not an AVFrame
772  buffer->pOutputPortPrivate = (void*) 1;
773  buffer->pBuffer = buf;
774  need_copy = 1;
775  buffer->nFilledLen = av_image_fill_arrays(dst, linesize, buffer->pBuffer, avctx->pix_fmt, s->stride, s->plane_size, 1);
776  }
777  }
778  } else {
779  need_copy = 1;
780  }
781  if (need_copy)
782  av_image_copy(dst, linesize, (const uint8_t**) frame->data, frame->linesize, avctx->pix_fmt, avctx->width, avctx->height);
783  buffer->nFlags = OMX_BUFFERFLAG_ENDOFFRAME;
784  buffer->nOffset = 0;
785  // Convert the timestamps to microseconds; some encoders can ignore
786  // the framerate and do VFR bit allocation based on timestamps.
787  buffer->nTimeStamp = to_omx_ticks(av_rescale_q(frame->pts, avctx->time_base, AV_TIME_BASE_Q));
788  err = OMX_EmptyThisBuffer(s->handle, buffer);
789  if (err != OMX_ErrorNone) {
791  av_log(avctx, AV_LOG_ERROR, "OMX_EmptyThisBuffer failed: %x\n", err);
792  return AVERROR_UNKNOWN;
793  }
794  s->num_in_frames++;
795  }
796 
797  while (!*got_packet && ret == 0) {
798  // Only wait for output if flushing and not all frames have been output
799  buffer = get_buffer(&s->output_mutex, &s->output_cond,
801  !frame && s->num_out_frames < s->num_in_frames);
802  if (!buffer)
803  break;
804 
805  if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG && avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
806  if ((ret = av_reallocp(&avctx->extradata, avctx->extradata_size + buffer->nFilledLen + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {
807  avctx->extradata_size = 0;
808  goto end;
809  }
810  memcpy(avctx->extradata + avctx->extradata_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen);
811  avctx->extradata_size += buffer->nFilledLen;
812  memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
813  } else {
814  if (buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME)
815  s->num_out_frames++;
816  if (!(buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) || !pkt->data) {
817  // If the output packet isn't preallocated, just concatenate everything in our
818  // own buffer
819  int newsize = s->output_buf_size + buffer->nFilledLen + AV_INPUT_BUFFER_PADDING_SIZE;
820  if ((ret = av_reallocp(&s->output_buf, newsize)) < 0) {
821  s->output_buf_size = 0;
822  goto end;
823  }
824  memcpy(s->output_buf + s->output_buf_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen);
825  s->output_buf_size += buffer->nFilledLen;
826  if (buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) {
827  if ((ret = av_packet_from_data(pkt, s->output_buf, s->output_buf_size)) < 0) {
828  av_freep(&s->output_buf);
829  s->output_buf_size = 0;
830  goto end;
831  }
832  s->output_buf = NULL;
833  s->output_buf_size = 0;
834  }
835  } else {
836  // End of frame, and the caller provided a preallocated frame
837  if ((ret = ff_alloc_packet2(avctx, pkt, s->output_buf_size + buffer->nFilledLen, 0)) < 0) {
838  av_log(avctx, AV_LOG_ERROR, "Error getting output packet of size %d.\n",
839  (int)(s->output_buf_size + buffer->nFilledLen));
840  goto end;
841  }
842  memcpy(pkt->data, s->output_buf, s->output_buf_size);
843  memcpy(pkt->data + s->output_buf_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen);
844  av_freep(&s->output_buf);
845  s->output_buf_size = 0;
846  }
847  if (buffer->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) {
848  pkt->pts = av_rescale_q(from_omx_ticks(buffer->nTimeStamp), AV_TIME_BASE_Q, avctx->time_base);
849  // We don't currently enable B-frames for the encoders, so set
850  // pkt->dts = pkt->pts. (The calling code behaves worse if the encoder
851  // doesn't set the dts).
852  pkt->dts = pkt->pts;
853  if (buffer->nFlags & OMX_BUFFERFLAG_SYNCFRAME)
854  pkt->flags |= AV_PKT_FLAG_KEY;
855  *got_packet = 1;
856  }
857  }
858 end:
859  err = OMX_FillThisBuffer(s->handle, buffer);
860  if (err != OMX_ErrorNone) {
862  av_log(avctx, AV_LOG_ERROR, "OMX_FillThisBuffer failed: %x\n", err);
863  ret = AVERROR_UNKNOWN;
864  }
865  }
866  return ret;
867 }
868 
870 {
871  OMXCodecContext *s = avctx->priv_data;
872 
873  cleanup(s);
874  return 0;
875 }
876 
877 #define OFFSET(x) offsetof(OMXCodecContext, x)
878 #define VDE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM
879 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
880 static const AVOption options[] = {
881  { "omx_libname", "OpenMAX library name", OFFSET(libname), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
882  { "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
883  { "zerocopy", "Try to avoid copying input frames if possible", OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
884  { NULL }
885 };
886 
887 static const enum AVPixelFormat omx_encoder_pix_fmts[] = {
889 };
890 
891 static const AVClass omx_mpeg4enc_class = {
892  .class_name = "mpeg4_omx",
893  .item_name = av_default_item_name,
894  .option = options,
895  .version = LIBAVUTIL_VERSION_INT,
896 };
898  .name = "mpeg4_omx",
899  .long_name = NULL_IF_CONFIG_SMALL("OpenMAX IL MPEG-4 video encoder"),
900  .type = AVMEDIA_TYPE_VIDEO,
901  .id = AV_CODEC_ID_MPEG4,
902  .priv_data_size = sizeof(OMXCodecContext),
904  .encode2 = omx_encode_frame,
905  .close = omx_encode_end,
906  .pix_fmts = omx_encoder_pix_fmts,
907  .capabilities = AV_CODEC_CAP_DELAY,
909  .priv_class = &omx_mpeg4enc_class,
910 };
911 
912 static const AVClass omx_h264enc_class = {
913  .class_name = "h264_omx",
914  .item_name = av_default_item_name,
915  .option = options,
916  .version = LIBAVUTIL_VERSION_INT,
917 };
919  .name = "h264_omx",
920  .long_name = NULL_IF_CONFIG_SMALL("OpenMAX IL H.264 video encoder"),
921  .type = AVMEDIA_TYPE_VIDEO,
922  .id = AV_CODEC_ID_H264,
923  .priv_data_size = sizeof(OMXCodecContext),
925  .encode2 = omx_encode_frame,
926  .close = omx_encode_end,
927  .pix_fmts = omx_encoder_pix_fmts,
928  .capabilities = AV_CODEC_CAP_DELAY,
930  .priv_class = &omx_h264enc_class,
931 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:54
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1685
AVRational framerate
Definition: avcodec.h:3375
const char * s
Definition: avisynth_c.h:768
#define VE
Definition: omx.c:879
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
Definition: os2threads.h:106
void(* host_init)(void)
Definition: omx.c:86
#define to_omx_ticks(x)
Definition: omx.c:60
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
Definition: os2threads.h:164
AVOption.
Definition: opt.h:245
static av_cold int find_component(OMXContext *omx_context, void *logctx, const char *role, char *str, int str_size)
Definition: omx.c:337
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1741
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
OMX_BUFFERHEADERTYPE ** in_buffer_headers
Definition: omx.c:205
int num
Numerator.
Definition: rational.h:59
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array...
Definition: imgutils.c:341
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1904
Convenience header that includes libavutil's core.
static OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
Definition: omx.c:322
static av_cold int omx_encode_end(AVCodecContext *avctx)
Definition: omx.c:869
static OMX_BUFFERHEADERTYPE * get_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond, int *array_size, OMX_BUFFERHEADERTYPE **array, int wait)
Definition: omx.c:241
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:252
static AVPacket pkt
AVCodec.
Definition: avcodec.h:3600
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
Definition: os2threads.h:138
void * lib
Definition: omx.c:77
static OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_BUFFERHEADERTYPE *buffer)
Definition: omx.c:304
int num_out_buffers
Definition: omx.c:204
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1813
void * lib2
Definition: omx.c:78
OMX_ERRORTYPE(* ptr_ComponentNameEnum)(OMX_STRING, OMX_U32, OMX_U32)
Definition: omx.c:81
static enum AVPixelFormat omx_encoder_pix_fmts[]
Definition: omx.c:887
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:984
OMX_ERRORTYPE(* ptr_GetRolesOfComponent)(OMX_STRING, OMX_U32 *, OMX_U8 **)
Definition: omx.c:85
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
HMTX pthread_mutex_t
Definition: os2threads.h:49
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
pthread_cond_t input_cond
Definition: omx.c:212
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
OMX_BUFFERHEADERTYPE ** done_out_buffers
Definition: omx.c:210
int num_in_buffers
Definition: omx.c:204
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:268
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition: avpacket.c:152
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1791
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1601
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
OMX_ERRORTYPE error
Definition: omx.c:219
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1633
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
H.264 common definitions.
enum AVCodecID id
Definition: avcodec.h:3614
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
Definition: imgutils.c:361
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
pthread_cond_t state_cond
Definition: omx.c:217
OMXContext * omx_context
Definition: omx.c:193
int out_port
Definition: omx.c:200
av_default_item_name
int mutex_cond_inited
Definition: omx.c:221
#define AVERROR(e)
Definition: error.h:43
AVCodecContext * avctx
Definition: omx.c:195
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:158
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static av_cold int wait_for_state(OMXCodecContext *s, OMX_STATETYPE state)
Definition: omx.c:374
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1771
pthread_mutex_t output_mutex
Definition: omx.c:213
#define VDE
Definition: omx.c:878
const char * name
Name of the codec implementation.
Definition: avcodec.h:3607
OMX_COLOR_FORMATTYPE color_format
Definition: omx.c:201
OMX_HANDLETYPE handle
Definition: omx.c:199
static void append_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond, int *array_size, OMX_BUFFERHEADERTYPE **array, OMX_BUFFERHEADERTYPE *buffer)
Definition: omx.c:231
AVCodec ff_mpeg4_omx_encoder
Definition: omx.c:897
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
#define fail()
Definition: checkasm.h:83
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:302
static int omx_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: omx.c:721
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1607
static av_cold void * dlsym_prefixed(void *handle, const char *symbol, const char *prefix)
Definition: omx.c:89
OMX_BUFFERHEADERTYPE ** out_buffer_headers
Definition: omx.c:206
OMX_ERRORTYPE(* ptr_GetHandle)(OMX_HANDLETYPE *, OMX_STRING, OMX_PTR, OMX_CALLBACKTYPE *)
Definition: omx.c:82
char * libname
Definition: omx.c:191
OMX_BUFFERHEADERTYPE ** free_in_buffers
Definition: omx.c:208
#define CHECK(x)
Definition: omx.c:68
int num_done_out_buffers
Definition: omx.c:209
int width
picture width / height.
Definition: avcodec.h:1863
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
static av_cold int omx_encode_init(AVCodecContext *avctx)
Definition: omx.c:625
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
Definition: os2threads.h:98
static const AVOption options[]
Definition: omx.c:880
pthread_cond_t output_cond
Definition: omx.c:214
int output_buf_size
Definition: omx.c:226
static av_cold int omx_try_load(OMXContext *s, void *logctx, const char *libname, const char *prefix, const char *libname2)
Definition: omx.c:96
#define src
Definition: vp9dsp.c:530
static pthread_mutex_t * mutex
Definition: w32pthreads.h:258
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:480
static const AVClass omx_mpeg4enc_class
Definition: omx.c:891
OMX_VERSIONTYPE version
Definition: omx.c:198
int input_zerocopy
Definition: omx.c:228
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
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:187
Libavcodec external API header.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:254
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
main external API structure.
Definition: avcodec.h:1676
static struct @246 state
void * buf
Definition: avisynth_c.h:690
int extradata_size
Definition: avcodec.h:1792
Describe the class of an AVClass context structure.
Definition: log.h:67
int num_out_frames
Definition: omx.c:223
#define OFFSET(x)
Definition: omx.c:877
char component_name[OMX_MAX_STRINGNAME_SIZE]
Definition: omx.c:197
static av_cold void omx_deinit(OMXContext *omx_context)
Definition: omx.c:180
#define snprintf
Definition: snprintf.h:34
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1722
static av_cold int omx_component_init(AVCodecContext *avctx, const char *role)
Definition: omx.c:386
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:882
static const OMX_CALLBACKTYPE callbacks
Definition: omx.c:331
static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2, OMX_PTR event_data)
Definition: omx.c:262
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1889
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:34
OMX_STATETYPE state
Definition: omx.c:218
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
common internal api header.
common internal and external API header
int plane_size
Definition: omx.c:202
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
Definition: os2threads.h:127
int in_port
Definition: omx.c:200
int den
Denominator.
Definition: rational.h:60
pthread_mutex_t input_mutex
Definition: omx.c:211
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
int stride
Definition: omx.c:202
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:734
void * priv_data
Definition: avcodec.h:1718
pthread_mutex_t state_mutex
Definition: omx.c:216
#define av_free(p)
#define from_omx_ticks(x)
Definition: omx.c:61
#define INIT_STRUCT(x)
Definition: omx.c:64
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
Definition: os2threads.h:156
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
Definition: os2threads.h:120
static const AVClass omx_h264enc_class
Definition: omx.c:912
OMX_ERRORTYPE(* ptr_FreeHandle)(OMX_HANDLETYPE)
Definition: omx.c:83
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1600
#define av_freep(p)
int num_free_in_buffers
Definition: omx.c:207
int num_in_frames
Definition: omx.c:223
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
Definition: os2threads.h:113
OMX_ERRORTYPE(* ptr_Deinit)(void)
Definition: omx.c:80
char * libprefix
Definition: omx.c:192
static av_cold void cleanup(OMXCodecContext *s)
Definition: omx.c:576
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1578
AVCodec ff_h264_omx_encoder
Definition: omx.c:918
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1594
OMX_ERRORTYPE(* ptr_Init)(void)
Definition: omx.c:79
uint8_t * output_buf
Definition: omx.c:225
OMX_ERRORTYPE(* ptr_GetComponentsOfRole)(OMX_STRING, OMX_U32 *, OMX_U8 **)
Definition: omx.c:84
Definition: omx.c:76
GLuint buffer
Definition: opengl_enc.c:102
static av_cold OMXContext * omx_init(void *logctx, const char *libname, const char *prefix)
Definition: omx.c:140