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

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