0006-ffmpeg-fix-omx-decode-setting-pix_fmt-bug.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From b2d8aa7d8ad754f9e4a203c6931476335f0e15b6 Mon Sep 17 00:00:00 2001
  2. From: sw.multimedia <sw.multimedia@starfivetech.com>
  3. Date: Wed, 26 Jan 2022 16:40:10 +0800
  4. Subject: [PATCH] ffmpeg: fix omx decode setting pix_fmt bug
  5. ---
  6. libavcodec/omxdec.c | 38 ++++++++++++++++++++++++++++++++++++--
  7. 1 file changed, 36 insertions(+), 2 deletions(-)
  8. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  9. index 27a7949..f5da60d 100755
  10. --- a/libavcodec/omxdec.c
  11. +++ b/libavcodec/omxdec.c
  12. @@ -28,6 +28,7 @@
  13. #include <dlfcn.h>
  14. #include <OMX_Core.h>
  15. #include <OMX_Component.h>
  16. +#include <OMX_IVCommon.h>
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. @@ -79,6 +80,8 @@ static int64_t from_omx_ticks(OMX_TICKS value)
  21. return AVERROR_UNKNOWN; \
  22. } \
  23. } while (0)
  24. +
  25. +#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
  26. typedef struct OMXContext {
  27. void *lib;
  28. @@ -93,6 +96,37 @@ typedef struct OMXContext {
  29. void (*host_init)(void);
  30. } OMXContext;
  31. +
  32. +static const struct {
  33. +
  34. + int color_format;
  35. + enum AVPixelFormat pix_fmt;
  36. +
  37. +} color_formats[] = {
  38. +
  39. + { OMX_COLOR_FormatYUV420Planar, AV_PIX_FMT_YUV420P },
  40. + { OMX_COLOR_FormatYUV420SemiPlanar, AV_PIX_FMT_NV12 },
  41. + { OMX_COLOR_FormatYUV420PackedSemiPlanar, AV_PIX_FMT_NV21 },
  42. + { 0 }
  43. +};
  44. +
  45. +static enum AVPixelFormat omx_map_color_format(AVCodecContext *avctx, int color_format)
  46. +{
  47. + int i;
  48. + enum AVPixelFormat ret = AV_PIX_FMT_NONE;
  49. +
  50. + for (i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
  51. + if (color_formats[i].color_format == color_format) {
  52. + return color_formats[i].pix_fmt;
  53. + }
  54. + }
  55. +
  56. + av_log(avctx, AV_LOG_ERROR, "Output color format 0x%x (value=%d) is not supported\n",
  57. + color_format, color_format);
  58. +
  59. + return ret;
  60. +}
  61. +
  62. static av_cold void *dlsym_prefixed(void *handle, const char *symbol, const char *prefix)
  63. {
  64. char buf[50];
  65. @@ -635,6 +669,7 @@ static av_cold void cleanup(OMXCodecContext *s)
  66. av_freep(&s->output_buf);
  67. }
  68. +
  69. static av_cold int omx_decode_init(AVCodecContext *avctx)
  70. {
  71. OMXCodecContext *s = avctx->priv_data;
  72. @@ -782,10 +817,9 @@ static int omx_decode_frame(AVCodecContext *avctx, void *data,
  73. }
  74. avctx->width = dec_out_width;
  75. avctx->height = dec_out_height;
  76. - avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  77. + avctx->pix_fmt = omx_map_color_format(avctx, dec_pix_fmt);
  78. s->stride = avctx->width;
  79. s->plane_size = avctx->height;
  80. - //avctx->pix_fmt = dec_pix_fmt;
  81. if (buffer->nFlags & OMX_BUFFERFLAG_EOS)
  82. s->got_eos = 1;
  83. --
  84. 2.17.1