0005-avcodec-add-omx-decoder-support.patch 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. From a47ead72e315cdd497af174e81eb72aa9361d598 Mon Sep 17 00:00:00 2001
  2. From: "sw.multimedia" <se.multimedia@starfivetech.com>
  3. Date: Wed, 25 May 2022 20:05:11 +0800
  4. Subject: [PATCH 1/8] avcodec add omx decoder support
  5. Signed-off-by: sw.multimedia <se.multimedia@starfivetech.com>
  6. ---
  7. configure | 1 +
  8. libavcodec/Makefile | 1 +
  9. libavcodec/allcodecs.c | 1 +
  10. libavcodec/omxdec.c | 893 +++++++++++++++++++++++++++++++++++++++++
  11. 4 files changed, 896 insertions(+)
  12. create mode 100644 libavcodec/omxdec.c
  13. diff --git a/configure b/configure
  14. index cdf6bb1..e3976df 100755
  15. --- a/configure
  16. +++ b/configure
  17. @@ -3084,6 +3084,7 @@ h264_mmal_decoder_deps="mmal"
  18. h264_nvenc_encoder_deps="nvenc"
  19. h264_nvenc_encoder_select="atsc_a53"
  20. h264_omx_encoder_deps="omx"
  21. +h264_omx_decoder_deps="omx"
  22. h264_qsv_decoder_select="h264_mp4toannexb_bsf qsvdec"
  23. h264_qsv_encoder_select="atsc_a53 qsvenc"
  24. h264_rkmpp_decoder_deps="rkmpp"
  25. diff --git a/libavcodec/Makefile b/libavcodec/Makefile
  26. index 33a280c..372d7de 100644
  27. --- a/libavcodec/Makefile
  28. +++ b/libavcodec/Makefile
  29. @@ -379,6 +379,7 @@ OBJS-$(CONFIG_H264_NVENC_ENCODER) += nvenc_h264.o
  30. OBJS-$(CONFIG_NVENC_ENCODER) += nvenc_h264.o
  31. OBJS-$(CONFIG_NVENC_H264_ENCODER) += nvenc_h264.o
  32. OBJS-$(CONFIG_H264_OMX_ENCODER) += omx.o
  33. +OBJS-$(CONFIG_H264_OMX_DECODER) += omxdec.o
  34. OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec.o
  35. OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o
  36. OBJS-$(CONFIG_H264_RKMPP_DECODER) += rkmppdec.o
  37. diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
  38. index 2e9a358..e42fa30 100644
  39. --- a/libavcodec/allcodecs.c
  40. +++ b/libavcodec/allcodecs.c
  41. @@ -792,6 +792,7 @@ extern AVCodec ff_h264_cuvid_decoder;
  42. extern AVCodec ff_h264_mf_encoder;
  43. extern AVCodec ff_h264_nvenc_encoder;
  44. extern AVCodec ff_h264_omx_encoder;
  45. +extern AVCodec ff_h264_omx_decoder;
  46. extern AVCodec ff_h264_qsv_encoder;
  47. extern AVCodec ff_h264_v4l2m2m_encoder;
  48. extern AVCodec ff_h264_vaapi_encoder;
  49. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  50. new file mode 100644
  51. index 0000000..7f76ec3
  52. --- /dev/null
  53. +++ b/libavcodec/omxdec.c
  54. @@ -0,0 +1,893 @@
  55. +/*
  56. + * OMX Video encoder
  57. + * Copyright (C) 2011 Martin Storsjo
  58. + *
  59. + * This file is part of FFmpeg.
  60. + *
  61. + * FFmpeg is free software; you can redistribute it and/or
  62. + * modify it under the terms of the GNU Lesser General Public
  63. + * License as published by the Free Software Foundation; either
  64. + * version 2.1 of the License, or (at your option) any later version.
  65. + *
  66. + * FFmpeg is distributed in the hope that it will be useful,
  67. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  68. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  69. + * Lesser General Public License for more details.
  70. + *
  71. + * You should have received a copy of the GNU Lesser General Public
  72. + * License along with FFmpeg; if not, write to the Free Software
  73. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  74. + */
  75. +
  76. +#include "config.h"
  77. +
  78. +#if CONFIG_OMX_RPI
  79. +#define OMX_SKIP64BIT
  80. +#endif
  81. +
  82. +#include <dlfcn.h>
  83. +#include <OMX_Core.h>
  84. +#include <OMX_Component.h>
  85. +#include <pthread.h>
  86. +#include <stdio.h>
  87. +#include <stdlib.h>
  88. +#include <sys/time.h>
  89. +
  90. +#include "libavutil/avstring.h"
  91. +#include "libavutil/avutil.h"
  92. +#include "libavutil/common.h"
  93. +#include "libavutil/imgutils.h"
  94. +#include "libavutil/log.h"
  95. +#include "libavutil/opt.h"
  96. +#include "libavutil/time.h"
  97. +
  98. +#include "avcodec.h"
  99. +#include "h264.h"
  100. +#include "internal.h"
  101. +
  102. +#ifdef OMX_SKIP64BIT
  103. +static OMX_TICKS to_omx_ticks(int64_t value)
  104. +{
  105. + OMX_TICKS s;
  106. + s.nLowPart = value & 0xffffffff;
  107. + s.nHighPart = value >> 32;
  108. + return s;
  109. +}
  110. +static int64_t from_omx_ticks(OMX_TICKS value)
  111. +{
  112. + return (((int64_t)value.nHighPart) << 32) | value.nLowPart;
  113. +}
  114. +#else
  115. +#define to_omx_ticks(x) (x)
  116. +#define from_omx_ticks(x) (x)
  117. +#endif
  118. +
  119. +#define INIT_STRUCT(x) do { \
  120. + x.nSize = sizeof(x); \
  121. + x.nVersion = s->version; \
  122. + } while (0)
  123. +#define CHECK(x) do { \
  124. + if (x != OMX_ErrorNone) { \
  125. + av_log(avctx, AV_LOG_ERROR, \
  126. + "err %x (%d) on line %d\n", x, x, __LINE__); \
  127. + return AVERROR_UNKNOWN; \
  128. + } \
  129. + } while (0)
  130. +
  131. +typedef struct OMXContext {
  132. + void *lib;
  133. + void *lib2;
  134. + OMX_ERRORTYPE (*ptr_Init)(void);
  135. + OMX_ERRORTYPE (*ptr_Deinit)(void);
  136. + OMX_ERRORTYPE (*ptr_ComponentNameEnum)(OMX_STRING, OMX_U32, OMX_U32);
  137. + OMX_ERRORTYPE (*ptr_GetHandle)(OMX_HANDLETYPE*, OMX_STRING, OMX_PTR, OMX_CALLBACKTYPE*);
  138. + OMX_ERRORTYPE (*ptr_FreeHandle)(OMX_HANDLETYPE);
  139. + OMX_ERRORTYPE (*ptr_GetComponentsOfRole)(OMX_STRING, OMX_U32*, OMX_U8**);
  140. + OMX_ERRORTYPE (*ptr_GetRolesOfComponent)(OMX_STRING, OMX_U32*, OMX_U8**);
  141. + void (*host_init)(void);
  142. +} OMXContext;
  143. +
  144. +static av_cold void *dlsym_prefixed(void *handle, const char *symbol, const char *prefix)
  145. +{
  146. + char buf[50];
  147. + snprintf(buf, sizeof(buf), "%s%s", prefix ? prefix : "", symbol);
  148. + return dlsym(handle, buf);
  149. +}
  150. +
  151. +static av_cold int omx_try_load(OMXContext *s, void *logctx,
  152. + const char *libname, const char *prefix,
  153. + const char *libname2)
  154. +{
  155. + if (libname2) {
  156. + s->lib2 = dlopen(libname2, RTLD_NOW | RTLD_GLOBAL);
  157. + if (!s->lib2) {
  158. + av_log(logctx, AV_LOG_WARNING, "%s not found\n", libname2);
  159. + return AVERROR_ENCODER_NOT_FOUND;
  160. + }
  161. + s->host_init = dlsym(s->lib2, "bcm_host_init");
  162. + if (!s->host_init) {
  163. + av_log(logctx, AV_LOG_WARNING, "bcm_host_init not found\n");
  164. + dlclose(s->lib2);
  165. + s->lib2 = NULL;
  166. + return AVERROR_ENCODER_NOT_FOUND;
  167. + }
  168. + }
  169. + s->lib = dlopen(libname, RTLD_NOW | RTLD_GLOBAL);
  170. + if (!s->lib) {
  171. + av_log(logctx, AV_LOG_WARNING, "%s not found\n", libname);
  172. + return AVERROR_ENCODER_NOT_FOUND;
  173. + }
  174. + s->ptr_Init = dlsym_prefixed(s->lib, "OMX_Init", prefix);
  175. + s->ptr_Deinit = dlsym_prefixed(s->lib, "OMX_Deinit", prefix);
  176. + s->ptr_ComponentNameEnum = dlsym_prefixed(s->lib, "OMX_ComponentNameEnum", prefix);
  177. + s->ptr_GetHandle = dlsym_prefixed(s->lib, "OMX_GetHandle", prefix);
  178. + s->ptr_FreeHandle = dlsym_prefixed(s->lib, "OMX_FreeHandle", prefix);
  179. + s->ptr_GetComponentsOfRole = dlsym_prefixed(s->lib, "OMX_GetComponentsOfRole", prefix);
  180. + s->ptr_GetRolesOfComponent = dlsym_prefixed(s->lib, "OMX_GetRolesOfComponent", prefix);
  181. + if (!s->ptr_Init || !s->ptr_Deinit || !s->ptr_ComponentNameEnum ||
  182. + !s->ptr_GetHandle || !s->ptr_FreeHandle ||
  183. + !s->ptr_GetComponentsOfRole || !s->ptr_GetRolesOfComponent) {
  184. + av_log(logctx, AV_LOG_WARNING, "Not all functions found in %s\n", libname);
  185. + dlclose(s->lib);
  186. + s->lib = NULL;
  187. + if (s->lib2)
  188. + dlclose(s->lib2);
  189. + s->lib2 = NULL;
  190. + return AVERROR_ENCODER_NOT_FOUND;
  191. + }
  192. + return 0;
  193. +}
  194. +
  195. +static av_cold OMXContext *omx_init(void *logctx, const char *libname, const char *prefix)
  196. +{
  197. + static const char * const libnames[] = {
  198. +#if CONFIG_OMX_RPI
  199. + "/opt/vc/lib/libopenmaxil.so", "/opt/vc/lib/libbcm_host.so",
  200. +#else
  201. + "libOMX_Core.so", NULL,
  202. + "libOmxCore.so", NULL,
  203. +#endif
  204. + NULL
  205. + };
  206. + const char* const* nameptr;
  207. + int ret = AVERROR_DECODER_NOT_FOUND;
  208. + OMXContext *omx_context;
  209. +
  210. + omx_context = av_mallocz(sizeof(*omx_context));
  211. + if (!omx_context)
  212. + return NULL;
  213. + if (libname) {
  214. + ret = omx_try_load(omx_context, logctx, libname, prefix, NULL);
  215. + if (ret < 0) {
  216. + av_free(omx_context);
  217. + return NULL;
  218. + }
  219. + } else {
  220. + for (nameptr = libnames; *nameptr; nameptr += 2)
  221. + if (!(ret = omx_try_load(omx_context, logctx, nameptr[0], prefix, nameptr[1])))
  222. + break;
  223. + if (!*nameptr) {
  224. + av_free(omx_context);
  225. + return NULL;
  226. + }
  227. + }
  228. +
  229. + if (omx_context->host_init)
  230. + omx_context->host_init();
  231. + omx_context->ptr_Init();
  232. + return omx_context;
  233. +}
  234. +
  235. +static av_cold void omx_deinit(OMXContext *omx_context)
  236. +{
  237. + if (!omx_context)
  238. + return;
  239. +
  240. + omx_context->ptr_Deinit();
  241. + dlclose(omx_context->lib);
  242. + av_free(omx_context);
  243. +}
  244. +
  245. +typedef struct OMXCodecContext {
  246. + const AVClass *class;
  247. + char *libname;
  248. + char *libprefix;
  249. + OMXContext *omx_context;
  250. +
  251. + AVCodecContext *avctx;
  252. +
  253. + char component_name[OMX_MAX_STRINGNAME_SIZE];
  254. + OMX_VERSIONTYPE version;
  255. + OMX_HANDLETYPE handle;
  256. + int in_port, out_port;
  257. + OMX_COLOR_FORMATTYPE color_format;
  258. + int stride, plane_size;
  259. +
  260. + int num_in_buffers, num_out_buffers;
  261. + OMX_BUFFERHEADERTYPE **in_buffer_headers;
  262. + OMX_BUFFERHEADERTYPE **out_buffer_headers;
  263. + int num_free_in_buffers;
  264. + OMX_BUFFERHEADERTYPE **free_in_buffers;
  265. + int num_done_out_buffers;
  266. + OMX_BUFFERHEADERTYPE **done_out_buffers;
  267. + pthread_mutex_t input_mutex;
  268. + pthread_cond_t input_cond;
  269. + pthread_mutex_t output_mutex;
  270. + pthread_cond_t output_cond;
  271. +
  272. + pthread_mutex_t state_mutex;
  273. + pthread_cond_t state_cond;
  274. + OMX_STATETYPE state;
  275. + OMX_ERRORTYPE error;
  276. +
  277. + int mutex_cond_inited;
  278. +
  279. + int eos_sent, got_eos, first_get_outbuffer;
  280. +
  281. + int extradata_sent;
  282. +
  283. + uint8_t *output_buf;
  284. + int output_buf_size;
  285. +
  286. + int input_zerocopy;
  287. + int profile;
  288. +} OMXCodecContext;
  289. +
  290. +static void append_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond,
  291. + int* array_size, OMX_BUFFERHEADERTYPE **array,
  292. + OMX_BUFFERHEADERTYPE *buffer)
  293. +{
  294. + pthread_mutex_lock(mutex);
  295. + array[(*array_size)++] = buffer;
  296. + pthread_cond_broadcast(cond);
  297. + pthread_mutex_unlock(mutex);
  298. +}
  299. +
  300. +static OMX_BUFFERHEADERTYPE *get_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond,
  301. + int* array_size, OMX_BUFFERHEADERTYPE **array,
  302. + int wait)
  303. +{
  304. + OMX_BUFFERHEADERTYPE *buffer;
  305. + pthread_mutex_lock(mutex);
  306. + if (wait) {
  307. + while (!*array_size)
  308. + {
  309. + pthread_cond_wait(cond, mutex);
  310. + }
  311. + }
  312. + if (*array_size > 0) {
  313. + buffer = array[0];
  314. + (*array_size)--;
  315. + memmove(&array[0], &array[1], (*array_size) * sizeof(OMX_BUFFERHEADERTYPE*));
  316. + } else {
  317. + buffer = NULL;
  318. + }
  319. + pthread_mutex_unlock(mutex);
  320. + return buffer;
  321. +}
  322. +
  323. +static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, OMX_EVENTTYPE event,
  324. + OMX_U32 data1, OMX_U32 data2, OMX_PTR event_data)
  325. +{
  326. + OMXCodecContext *s = app_data;
  327. + // This uses casts in the printfs, since OMX_U32 actually is a typedef for
  328. + // unsigned long in official header versions (but there are also modified
  329. + // versions where it is something else).
  330. + switch (event) {
  331. + case OMX_EventError:
  332. + pthread_mutex_lock(&s->state_mutex);
  333. + av_log(s->avctx, AV_LOG_ERROR, "OMX error %"PRIx32"\n", (uint32_t) data1);
  334. + s->error = data1;
  335. + pthread_cond_broadcast(&s->state_cond);
  336. + pthread_mutex_unlock(&s->state_mutex);
  337. + break;
  338. + case OMX_EventCmdComplete:
  339. + if (data1 == OMX_CommandStateSet) {
  340. + pthread_mutex_lock(&s->state_mutex);
  341. + s->state = data2;
  342. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX state changed to %"PRIu32"\n", (uint32_t) data2);
  343. + pthread_cond_broadcast(&s->state_cond);
  344. + pthread_mutex_unlock(&s->state_mutex);
  345. + } else if (data1 == OMX_CommandPortDisable) {
  346. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" disabled\n", (uint32_t) data2);
  347. + } else if (data1 == OMX_CommandPortEnable) {
  348. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" enabled\n", (uint32_t) data2);
  349. + } else {
  350. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX command complete, command %"PRIu32", value %"PRIu32"\n",
  351. + (uint32_t) data1, (uint32_t) data2);
  352. + }
  353. + break;
  354. + case OMX_EventPortSettingsChanged:
  355. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX port %"PRIu32" settings changed\n", (uint32_t) data1);
  356. + break;
  357. + default:
  358. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX event %d %"PRIx32" %"PRIx32"\n",
  359. + event, (uint32_t) data1, (uint32_t) data2);
  360. + break;
  361. + }
  362. + return OMX_ErrorNone;
  363. +}
  364. +
  365. +static OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
  366. + OMX_BUFFERHEADERTYPE *buffer)
  367. +{
  368. +
  369. + OMXCodecContext *s = app_data;
  370. + if (s->input_zerocopy) {
  371. + if (buffer->pAppPrivate) {
  372. + if (buffer->pOutputPortPrivate)
  373. + av_free(buffer->pAppPrivate);
  374. + else
  375. + av_frame_free((AVFrame**)&buffer->pAppPrivate);
  376. + buffer->pAppPrivate = NULL;
  377. + }
  378. + }
  379. + append_buffer(&s->input_mutex, &s->input_cond,
  380. + &s->num_free_in_buffers, s->free_in_buffers, buffer);
  381. + return OMX_ErrorNone;
  382. +}
  383. +
  384. +static OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE component, OMX_PTR app_data,
  385. + OMX_BUFFERHEADERTYPE *buffer)
  386. +{
  387. + OMXCodecContext *s = app_data;
  388. + append_buffer(&s->output_mutex, &s->output_cond,
  389. + &s->num_done_out_buffers, s->done_out_buffers, buffer);
  390. + return OMX_ErrorNone;
  391. +}
  392. +
  393. +static const OMX_CALLBACKTYPE callbacks = {
  394. + event_handler,
  395. + empty_buffer_done,
  396. + fill_buffer_done
  397. +};
  398. +
  399. +static av_cold int find_component(OMXContext *omx_context, void *logctx,
  400. + const char *role, char *str, int str_size)
  401. +{
  402. + OMX_U32 i, num = 0;
  403. + char **components;
  404. + int ret = 0;
  405. +
  406. +#if CONFIG_OMX_RPI
  407. + if (av_strstart(role, "video_decoder.", NULL)) {
  408. + av_strlcpy(str, "OMX.broadcom.video_decode", str_size);
  409. + return 0;
  410. + }
  411. +#endif
  412. + omx_context->ptr_GetComponentsOfRole((OMX_STRING) role, &num, NULL);
  413. + if (!num) {
  414. + av_log(logctx, AV_LOG_WARNING, "No component for role %s found\n", role);
  415. + return AVERROR_DECODER_NOT_FOUND;
  416. + }
  417. + components = av_mallocz_array(num, sizeof(*components));
  418. + if (!components)
  419. + return AVERROR(ENOMEM);
  420. + for (i = 0; i < num; i++) {
  421. + components[i] = av_mallocz(OMX_MAX_STRINGNAME_SIZE);
  422. + if (!components[i]) {
  423. + ret = AVERROR(ENOMEM);
  424. + goto end;
  425. + }
  426. + }
  427. + omx_context->ptr_GetComponentsOfRole((OMX_STRING) role, &num, (OMX_U8**) components);
  428. + av_strlcpy(str, components[0], str_size);
  429. +end:
  430. + for (i = 0; i < num; i++)
  431. + av_free(components[i]);
  432. + av_free(components);
  433. + return ret;
  434. +}
  435. +
  436. +static av_cold int wait_for_state(OMXCodecContext *s, OMX_STATETYPE state)
  437. +{
  438. + int ret = 0;
  439. + pthread_mutex_lock(&s->state_mutex);
  440. + while (s->state != state && s->error == OMX_ErrorNone)
  441. + pthread_cond_wait(&s->state_cond, &s->state_mutex);
  442. + if (s->error != OMX_ErrorNone)
  443. + ret = AVERROR_DECODER_NOT_FOUND;
  444. + pthread_mutex_unlock(&s->state_mutex);
  445. + return ret;
  446. +}
  447. +
  448. +static av_cold int omx_component_init(AVCodecContext *avctx, const char *role)
  449. +{
  450. + OMXCodecContext *s = avctx->priv_data;
  451. + OMX_PARAM_COMPONENTROLETYPE role_params = { 0 };
  452. + OMX_PORT_PARAM_TYPE video_port_params = { 0 };
  453. + OMX_PARAM_PORTDEFINITIONTYPE in_port_params = { 0 }, out_port_params = { 0 };
  454. + //OMX_VIDEO_PARAM_PORTFORMATTYPE video_port_format = { 0 };
  455. + //OMX_VIDEO_PARAM_BITRATETYPE vid_param_bitrate = { 0 };
  456. + OMX_ERRORTYPE err;
  457. + int i;
  458. +
  459. + s->version.s.nVersionMajor = 1;
  460. + s->version.s.nVersionMinor = 1;
  461. + s->version.s.nRevision = 2;
  462. +
  463. + err = s->omx_context->ptr_GetHandle(&s->handle, s->component_name, s, (OMX_CALLBACKTYPE*) &callbacks);
  464. + if (err != OMX_ErrorNone) {
  465. + av_log(avctx, AV_LOG_ERROR, "OMX_GetHandle(%s) failed: %x\n", s->component_name, err);
  466. + return AVERROR_UNKNOWN;
  467. + }
  468. +
  469. + // This one crashes the mediaserver on qcom, if used over IOMX
  470. + INIT_STRUCT(role_params);
  471. + av_strlcpy(role_params.cRole, role, sizeof(role_params.cRole));
  472. + // Intentionally ignore errors on this one
  473. + OMX_SetParameter(s->handle, OMX_IndexParamStandardComponentRole, &role_params);
  474. +
  475. + INIT_STRUCT(video_port_params);
  476. + err = OMX_GetParameter(s->handle, OMX_IndexParamVideoInit, &video_port_params);
  477. + CHECK(err);
  478. +
  479. + s->in_port = s->out_port = -1;
  480. + for (i = 0; i < video_port_params.nPorts; i++) {
  481. + int port = video_port_params.nStartPortNumber + i;
  482. + OMX_PARAM_PORTDEFINITIONTYPE port_params = { 0 };
  483. + INIT_STRUCT(port_params);
  484. + port_params.nPortIndex = port;
  485. + err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &port_params);
  486. + if (err != OMX_ErrorNone) {
  487. + av_log(avctx, AV_LOG_WARNING, "port %d error %x\n", port, err);
  488. + break;
  489. + }
  490. + if (port_params.eDir == OMX_DirInput && s->in_port < 0) {
  491. + in_port_params = port_params;
  492. + s->in_port = port;
  493. + } else if (port_params.eDir == OMX_DirOutput && s->out_port < 0) {
  494. + out_port_params = port_params;
  495. + s->out_port = port;
  496. + }
  497. + }
  498. + if (s->in_port < 0 || s->out_port < 0) {
  499. + av_log(avctx, AV_LOG_ERROR, "No in or out port found (in %d out %d)\n", s->in_port, s->out_port);
  500. + return AVERROR_UNKNOWN;
  501. + }
  502. +
  503. + in_port_params.bEnabled = OMX_TRUE;
  504. + in_port_params.bPopulated = OMX_FALSE;
  505. + in_port_params.eDomain = OMX_PortDomainVideo;
  506. +
  507. + in_port_params.format.video.pNativeRender = NULL;
  508. + in_port_params.format.video.bFlagErrorConcealment = OMX_FALSE;
  509. + //in_port_params.format.video.eColorFormat = s->color_format;
  510. + s->stride = avctx->width;
  511. + s->plane_size = avctx->height;
  512. + // If specific codecs need to manually override the stride/plane_size,
  513. + // that can be done here.
  514. + in_port_params.format.video.nStride = s->stride;
  515. + in_port_params.format.video.nSliceHeight = s->plane_size;
  516. + in_port_params.format.video.nFrameWidth = avctx->width;
  517. + in_port_params.format.video.nFrameHeight = avctx->height;
  518. +
  519. + if (avctx->framerate.den > 0 && avctx->framerate.num > 0)
  520. + in_port_params.format.video.xFramerate = (1LL << 16) * avctx->framerate.num / avctx->framerate.den;
  521. + else
  522. + in_port_params.format.video.xFramerate = (1LL << 16) * avctx->time_base.den / avctx->time_base.num;
  523. +
  524. + err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, &in_port_params);
  525. + CHECK(err);
  526. + err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &in_port_params);
  527. + CHECK(err);
  528. +
  529. +#if 1
  530. + s->stride = in_port_params.format.video.nStride;
  531. + s->plane_size = in_port_params.format.video.nSliceHeight;
  532. + s->num_in_buffers = in_port_params.nBufferCountActual;
  533. +#endif
  534. + err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
  535. + out_port_params.bEnabled = OMX_TRUE;
  536. + out_port_params.bPopulated = OMX_FALSE;
  537. + out_port_params.eDomain = OMX_PortDomainVideo;
  538. + out_port_params.format.video.pNativeRender = NULL;
  539. + out_port_params.format.video.bFlagErrorConcealment = OMX_FALSE;
  540. + out_port_params.format.video.nFrameWidth = avctx->width;
  541. + out_port_params.format.video.nFrameHeight = avctx->height;
  542. + out_port_params.format.video.nStride = 0;
  543. + out_port_params.format.video.nSliceHeight = 0;
  544. + out_port_params.format.video.nBitrate = avctx->bit_rate;
  545. + out_port_params.format.video.xFramerate = in_port_params.format.video.xFramerate;
  546. + out_port_params.format.video.bFlagErrorConcealment = OMX_FALSE;
  547. + if (avctx->codec->id == AV_CODEC_ID_MPEG4)
  548. + out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
  549. + else if (avctx->codec->id == AV_CODEC_ID_H264)
  550. + out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
  551. +
  552. + err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
  553. + CHECK(err);
  554. + err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
  555. + CHECK(err);
  556. + s->num_out_buffers = out_port_params.nBufferCountActual;
  557. +
  558. +
  559. + err = OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
  560. + CHECK(err);
  561. +
  562. + s->in_buffer_headers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_in_buffers);
  563. + s->free_in_buffers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_in_buffers);
  564. + s->out_buffer_headers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_out_buffers);
  565. + s->done_out_buffers = av_mallocz(sizeof(OMX_BUFFERHEADERTYPE*) * s->num_out_buffers);
  566. + if (!s->in_buffer_headers || !s->free_in_buffers || !s->out_buffer_headers || !s->done_out_buffers)
  567. + return AVERROR(ENOMEM);
  568. + for (i = 0; i < s->num_in_buffers && err == OMX_ErrorNone; i++) {
  569. + if (s->input_zerocopy)
  570. + err = OMX_UseBuffer(s->handle, &s->in_buffer_headers[i], s->in_port, s, in_port_params.nBufferSize, NULL);
  571. + else
  572. + err = OMX_AllocateBuffer(s->handle, &s->in_buffer_headers[i], s->in_port, s, in_port_params.nBufferSize);
  573. + if (err == OMX_ErrorNone)
  574. + s->in_buffer_headers[i]->pAppPrivate = s->in_buffer_headers[i]->pOutputPortPrivate = NULL;
  575. + }
  576. + CHECK(err);
  577. + s->num_in_buffers = i;
  578. + for (i = 0; i < s->num_out_buffers && err == OMX_ErrorNone; i++)
  579. + err = OMX_AllocateBuffer(s->handle, &s->out_buffer_headers[i], s->out_port, s, out_port_params.nBufferSize);
  580. + CHECK(err);
  581. + s->num_out_buffers = i;
  582. +
  583. + if (wait_for_state(s, OMX_StateIdle) < 0) {
  584. + av_log(avctx, AV_LOG_ERROR, "Didn't get OMX_StateIdle\n");
  585. + return AVERROR_UNKNOWN;
  586. + }
  587. + err = OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
  588. + CHECK(err);
  589. + if (wait_for_state(s, OMX_StateExecuting) < 0) {
  590. + av_log(avctx, AV_LOG_ERROR, "Didn't get OMX_StateExecuting\n");
  591. + return AVERROR_UNKNOWN;
  592. + }
  593. +
  594. + for (i = 0; i < s->num_out_buffers && err == OMX_ErrorNone; i++)
  595. + err = OMX_FillThisBuffer(s->handle, s->out_buffer_headers[i]);
  596. + if (err != OMX_ErrorNone) {
  597. + for (; i < s->num_out_buffers; i++)
  598. + s->done_out_buffers[s->num_done_out_buffers++] = s->out_buffer_headers[i];
  599. + }
  600. + for (i = 0; i < s->num_in_buffers; i++)
  601. + s->free_in_buffers[s->num_free_in_buffers++] = s->in_buffer_headers[i];
  602. + return err != OMX_ErrorNone ? AVERROR_UNKNOWN : 0;
  603. +}
  604. +
  605. +static av_cold void cleanup(OMXCodecContext *s)
  606. +{
  607. + int i, executing;
  608. +
  609. + pthread_mutex_lock(&s->state_mutex);
  610. + executing = s->state == OMX_StateExecuting;
  611. + pthread_mutex_unlock(&s->state_mutex);
  612. +
  613. + if (executing) {
  614. + OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
  615. + wait_for_state(s, OMX_StateIdle);
  616. + OMX_SendCommand(s->handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
  617. + for (i = 0; i < s->num_in_buffers; i++) {
  618. + OMX_BUFFERHEADERTYPE *buffer = get_buffer(&s->input_mutex, &s->input_cond,
  619. + &s->num_free_in_buffers, s->free_in_buffers, 1);
  620. + if (s->input_zerocopy)
  621. + buffer->pBuffer = NULL;
  622. + OMX_FreeBuffer(s->handle, s->in_port, buffer);
  623. + }
  624. + for (i = 0; i < s->num_out_buffers; i++) {
  625. + OMX_BUFFERHEADERTYPE *buffer = get_buffer(&s->output_mutex, &s->output_cond,
  626. + &s->num_done_out_buffers, s->done_out_buffers, 1);
  627. + OMX_FreeBuffer(s->handle, s->out_port, buffer);
  628. + }
  629. + wait_for_state(s, OMX_StateLoaded);
  630. + }
  631. + if (s->handle) {
  632. + s->omx_context->ptr_FreeHandle(s->handle);
  633. + s->handle = NULL;
  634. + }
  635. +
  636. + omx_deinit(s->omx_context);
  637. + s->omx_context = NULL;
  638. + if (s->mutex_cond_inited) {
  639. + pthread_cond_destroy(&s->state_cond);
  640. + pthread_mutex_destroy(&s->state_mutex);
  641. + pthread_cond_destroy(&s->input_cond);
  642. + pthread_mutex_destroy(&s->input_mutex);
  643. + pthread_cond_destroy(&s->output_cond);
  644. + pthread_mutex_destroy(&s->output_mutex);
  645. + s->mutex_cond_inited = 0;
  646. + }
  647. + av_freep(&s->in_buffer_headers);
  648. + av_freep(&s->out_buffer_headers);
  649. + av_freep(&s->free_in_buffers);
  650. + av_freep(&s->done_out_buffers);
  651. + av_freep(&s->output_buf);
  652. +}
  653. +
  654. +static av_cold int omx_decode_init(AVCodecContext *avctx)
  655. +{
  656. + OMXCodecContext *s = avctx->priv_data;
  657. + int ret = AVERROR_ENCODER_NOT_FOUND;
  658. + const char *role;
  659. + //OMX_BUFFERHEADERTYPE *buffer;
  660. + //OMX_ERRORTYPE err;
  661. +
  662. + s->omx_context = omx_init(avctx, s->libname, s->libprefix);
  663. + if (!s->omx_context)
  664. + return AVERROR_ENCODER_NOT_FOUND;
  665. +
  666. + pthread_mutex_init(&s->state_mutex, NULL);
  667. + pthread_cond_init(&s->state_cond, NULL);
  668. + pthread_mutex_init(&s->input_mutex, NULL);
  669. + pthread_cond_init(&s->input_cond, NULL);
  670. + pthread_mutex_init(&s->output_mutex, NULL);
  671. + pthread_cond_init(&s->output_cond, NULL);
  672. + s->mutex_cond_inited = 1;
  673. + s->avctx = avctx;
  674. + s->state = OMX_StateLoaded;
  675. + s->error = OMX_ErrorNone;
  676. +
  677. + switch (avctx->codec->id) {
  678. + case AV_CODEC_ID_MPEG4:
  679. + role = "video_decoder.mpeg4";
  680. + break;
  681. + case AV_CODEC_ID_H264:
  682. + role = "video_decoder.avc";
  683. + break;
  684. + default:
  685. + return AVERROR(ENOSYS);
  686. + }
  687. +
  688. + if ((ret = find_component(s->omx_context, avctx, role, s->component_name, sizeof(s->component_name))) < 0)
  689. + goto fail;
  690. +
  691. + av_log(avctx, AV_LOG_INFO, "Using %s\n", s->component_name);
  692. +
  693. + if ((ret = omx_component_init(avctx, role)) < 0)
  694. + goto fail;
  695. +
  696. +#if 0
  697. + if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
  698. + while (1) {
  699. + buffer = get_buffer(&s->output_mutex, &s->output_cond,
  700. + &s->num_done_out_buffers, s->done_out_buffers, 1);
  701. + if (buffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG) {
  702. + if ((ret = av_reallocp(&avctx->extradata, avctx->extradata_size + buffer->nFilledLen + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {
  703. + avctx->extradata_size = 0;
  704. + goto fail;
  705. + }
  706. + memcpy(avctx->extradata + avctx->extradata_size, buffer->pBuffer + buffer->nOffset, buffer->nFilledLen);
  707. + avctx->extradata_size += buffer->nFilledLen;
  708. + memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
  709. + }
  710. + err = OMX_FillThisBuffer(s->handle, buffer);
  711. + if (err != OMX_ErrorNone) {
  712. + append_buffer(&s->output_mutex, &s->output_cond,
  713. + &s->num_done_out_buffers, s->done_out_buffers, buffer);
  714. + av_log(avctx, AV_LOG_ERROR, "OMX_FillThisBuffer failed: %x\n", err);
  715. + ret = AVERROR_UNKNOWN;
  716. + goto fail;
  717. + }
  718. + if (avctx->codec->id == AV_CODEC_ID_H264) {
  719. + // For H.264, the extradata can be returned in two separate buffers
  720. + // (the videocore encoder on raspberry pi does this);
  721. + // therefore check that we have got both SPS and PPS before continuing.
  722. + int nals[32] = { 0 };
  723. + int i;
  724. + for (i = 0; i + 4 < avctx->extradata_size; i++) {
  725. + if (!avctx->extradata[i + 0] &&
  726. + !avctx->extradata[i + 1] &&
  727. + !avctx->extradata[i + 2] &&
  728. + avctx->extradata[i + 3] == 1) {
  729. + nals[avctx->extradata[i + 4] & 0x1f]++;
  730. + }
  731. + }
  732. + if (nals[H264_NAL_SPS] && nals[H264_NAL_PPS])
  733. + break;
  734. + } else {
  735. + if (avctx->extradata_size > 0)
  736. + break;
  737. + }
  738. + }
  739. + }
  740. +#endif
  741. +
  742. + return 0;
  743. +fail:
  744. + return ret;
  745. +}
  746. +
  747. +
  748. +static int omx_decode_frame(AVCodecContext *avctx, void *data,
  749. + int *got_packet, AVPacket *pkt)
  750. +{
  751. + OMXCodecContext *s = avctx->priv_data;
  752. + int ret = 0;
  753. + OMX_BUFFERHEADERTYPE* buffer;
  754. + OMX_ERRORTYPE err;
  755. + int had_partial = 0;
  756. +
  757. + AVFrame *avframe = data;
  758. +
  759. + uint8_t *dst[4];
  760. + int linesize[4];
  761. +
  762. + if (pkt->size) {
  763. +
  764. + //VPU init and fill buffer slow, so empty buf sleep to send before get vpu fill buf.
  765. + if(!s->first_get_outbuffer)
  766. + av_usleep(100000);
  767. +
  768. + buffer = get_buffer(&s->input_mutex, &s->input_cond,
  769. + &s->num_free_in_buffers, s->free_in_buffers, 1);
  770. +
  771. + if (!buffer) {
  772. + av_log(avctx, AV_LOG_ERROR, "get_buffer NULL\n");
  773. + return AVERROR(ENOMEM);
  774. + }
  775. +
  776. + //cpy the extradata
  777. + if(!s->extradata_sent) {
  778. +
  779. + memcpy(buffer->pBuffer + buffer->nOffset, avctx->extradata, avctx->extradata_size);
  780. + memcpy(buffer->pBuffer + buffer->nOffset + avctx->extradata_size, pkt->data, pkt->size);
  781. + buffer->nFilledLen = pkt->size + avctx->extradata_size;
  782. + s->extradata_sent = 1;
  783. +
  784. + }
  785. + else {
  786. + memcpy(buffer->pBuffer + buffer->nOffset, pkt->data, pkt->size);
  787. + buffer->nFilledLen = pkt->size;
  788. + }
  789. +
  790. + /* reduce memcpy. point it addr*/
  791. + //buffer->pAppPrivate = pkt;
  792. + //buffer->pBuffer = pkt->data;
  793. + //buffer->nFilledLen = pkt->size;
  794. +
  795. + buffer->pOutputPortPrivate = NULL;
  796. + buffer->pAppPrivate = avctx->priv_data;
  797. +
  798. + err = OMX_EmptyThisBuffer(s->handle, buffer);
  799. + if (err != OMX_ErrorNone) {
  800. + append_buffer(&s->input_mutex, &s->input_cond, &s->num_free_in_buffers, s->free_in_buffers, buffer);
  801. + av_log(avctx, AV_LOG_ERROR, "OMX_EmptyThisBuffer failed: %x\n", err);
  802. + return AVERROR_UNKNOWN;
  803. + }
  804. + } else if (!s->eos_sent) {
  805. +
  806. + if(!s->first_get_outbuffer)
  807. + av_usleep(1000000);
  808. +
  809. + buffer = get_buffer(&s->input_mutex, &s->input_cond,
  810. + &s->num_free_in_buffers, s->free_in_buffers, 1);
  811. +
  812. + buffer->nFilledLen = 0;
  813. + buffer->nFlags = OMX_BUFFERFLAG_EOS;
  814. + buffer->pAppPrivate = buffer->pOutputPortPrivate = NULL;
  815. + err = OMX_EmptyThisBuffer(s->handle, buffer);
  816. + if (err != OMX_ErrorNone) {
  817. + append_buffer(&s->input_mutex, &s->input_cond, &s->num_free_in_buffers, s->free_in_buffers, buffer);
  818. + av_log(avctx, AV_LOG_ERROR, "OMX_EmptyThisBuffer failed: %x\n", err);
  819. + return AVERROR_UNKNOWN;
  820. + }
  821. + s->eos_sent = 1;
  822. + }
  823. +
  824. + while (!*got_packet && ret == 0 && !s->got_eos) {
  825. + // If not flushing, just poll the queue if there's finished packets.
  826. + // If flushing, do a blocking wait until we either get a completed
  827. + // packet, or get EOS.
  828. + buffer = get_buffer(&s->output_mutex, &s->output_cond,
  829. + &s->num_done_out_buffers, s->done_out_buffers,
  830. + !pkt || had_partial);
  831. +
  832. + if (!buffer) {
  833. + /*eos is sent but fill buf still can't get then continue*/
  834. + if(!s->first_get_outbuffer && s->eos_sent)
  835. + continue;
  836. + else
  837. + break;
  838. + }
  839. + //if (!buffer)
  840. + // break;
  841. +
  842. + if(!buffer->nFilledLen)
  843. + goto end;
  844. +
  845. + if(!s->first_get_outbuffer)
  846. + s->first_get_outbuffer = 1;
  847. +
  848. + if (buffer->nFlags & OMX_BUFFERFLAG_EOS)
  849. + s->got_eos = 1;
  850. +
  851. + if ((ret = ff_get_buffer(avctx, avframe, 0)) < 0) {
  852. + av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n");
  853. + goto end;
  854. + }
  855. +
  856. + ret = av_image_fill_arrays(dst, linesize, buffer->pBuffer,
  857. + avctx->pix_fmt, s->stride, s->plane_size, 1);
  858. + if (ret < 0)
  859. + goto end;
  860. + av_image_copy(avframe->data, avframe->linesize, (const uint8_t**)dst, linesize,
  861. + avctx->pix_fmt, avctx->width, avctx->height);
  862. +
  863. + //avframe->pts = buffer->nTimeStamp;
  864. + //avframe->pkt_dts = AV_NOPTS_VALUE;
  865. + //avframe->pict_type= AV_PICTURE_TYPE_I;
  866. + //avframe->key_frame= 1;
  867. +
  868. + *got_packet = 1;
  869. +
  870. + /*
  871. + if ((ret = av_frame_ref(data, avframe)) < 0)
  872. + goto end;
  873. + */
  874. +
  875. +end:
  876. + err = OMX_FillThisBuffer(s->handle, buffer);
  877. + if (err != OMX_ErrorNone) {
  878. + append_buffer(&s->output_mutex, &s->output_cond, &s->num_done_out_buffers, s->done_out_buffers, buffer);
  879. + av_log(avctx, AV_LOG_ERROR, "OMX_FillThisBuffer failed: %x\n", err);
  880. + ret = AVERROR_UNKNOWN;
  881. + }
  882. + }
  883. + return ret;
  884. +}
  885. +
  886. +static av_cold int omx_decode_end(AVCodecContext *avctx)
  887. +{
  888. + OMXCodecContext *s = avctx->priv_data;
  889. +
  890. + cleanup(s);
  891. + return 0;
  892. +}
  893. +
  894. +#define OFFSET(x) offsetof(OMXCodecContext, x)
  895. +#define VDE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  896. +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  897. +static const AVOption options[] = {
  898. + { "omx_libname", "OpenMAX library name", OFFSET(libname), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
  899. + { "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
  900. + { "zerocopy", "Try to avoid copying input frames if possible", OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = CONFIG_OMX_RPI }, 0, 1, VE },
  901. + { "profile", "Set the encoding profile", OFFSET(profile), AV_OPT_TYPE_INT, { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, FF_PROFILE_H264_HIGH, VE, "profile" },
  902. + { "baseline", "", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_H264_BASELINE }, 0, 0, VE, "profile" },
  903. + { "main", "", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_H264_MAIN }, 0, 0, VE, "profile" },
  904. + { "high", "", 0, AV_OPT_TYPE_CONST, { .i64 = FF_PROFILE_H264_HIGH }, 0, 0, VE, "profile" },
  905. + { NULL }
  906. +};
  907. +
  908. +
  909. +static const AVClass omx_mpeg4dec_class = {
  910. + .class_name = "mpeg4_omx",
  911. + .item_name = av_default_item_name,
  912. + .option = options,
  913. + .version = LIBAVUTIL_VERSION_INT,
  914. +};
  915. +AVCodec ff_mpeg4_omx_decoder = {
  916. + .name = "mpeg4_omx",
  917. + .long_name = NULL_IF_CONFIG_SMALL("OpenMAX IL MPEG-4 video decoder"),
  918. + .type = AVMEDIA_TYPE_VIDEO,
  919. + .id = AV_CODEC_ID_MPEG4,
  920. + .priv_data_size = sizeof(OMXCodecContext),
  921. + .init = omx_decode_init,
  922. + .decode = omx_decode_frame,
  923. + .close = omx_decode_end,
  924. + .capabilities = AV_CODEC_CAP_DELAY,
  925. + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  926. + .priv_class = &omx_mpeg4dec_class,
  927. +};
  928. +
  929. +static const AVClass omx_h264dec_class = {
  930. + .class_name = "h264_omx",
  931. + .item_name = av_default_item_name,
  932. + .option = options,
  933. + .version = LIBAVUTIL_VERSION_INT,
  934. +};
  935. +AVCodec ff_h264_omx_decoder = {
  936. + .name = "h264_omx",
  937. + .long_name = NULL_IF_CONFIG_SMALL("OpenMAX IL H.264 video decoder"),
  938. + .type = AVMEDIA_TYPE_VIDEO,
  939. + .id = AV_CODEC_ID_H264,
  940. + .priv_data_size = sizeof(OMXCodecContext),
  941. + .init = omx_decode_init,
  942. + .decode = omx_decode_frame,
  943. + .close = omx_decode_end,
  944. + .capabilities = AV_CODEC_CAP_DELAY,
  945. + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  946. + .priv_class = &omx_h264dec_class,
  947. +};
  948. --
  949. 2.17.1