0008-fix-omx-decoder-setting-pix-fmt-bug.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 39a500044fe9216453960529ae9320fda2ef73e4 Mon Sep 17 00:00:00 2001
  2. From: "sw.multimedia" <se.multimedia@starfivetech.com>
  3. Date: Wed, 25 May 2022 20:58:57 +0800
  4. Subject: [PATCH 6/8] fix omx decoder setting pix-fmt bug
  5. Signed-off-by: sw.multimedia <se.multimedia@starfivetech.com>
  6. ---
  7. libavcodec/omxdec.c | 36 ++++++++++++++++++++++++++++++++++--
  8. 1 file changed, 34 insertions(+), 2 deletions(-)
  9. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  10. index 9eb5dca..8d00b86 100644
  11. --- a/libavcodec/omxdec.c
  12. +++ b/libavcodec/omxdec.c
  13. @@ -28,6 +28,7 @@
  14. #include <dlfcn.h>
  15. #include <OMX_Core.h>
  16. #include <OMX_Component.h>
  17. +#include <OMX_IVCommon.h>
  18. #include <pthread.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. @@ -80,6 +81,8 @@ static int64_t from_omx_ticks(OMX_TICKS value)
  22. } \
  23. } while (0)
  24. +#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
  25. +
  26. typedef struct OMXContext {
  27. void *lib;
  28. void *lib2;
  29. @@ -93,6 +96,36 @@ typedef struct OMXContext {
  30. void (*host_init)(void);
  31. } OMXContext;
  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. @@ -835,10 +868,9 @@ static int omx_decode_frame(AVCodecContext *avctx, void *data,
  66. avctx->width = dec_out_width;
  67. avctx->height = dec_out_height;
  68. - avctx->pix_fmt = AV_PIX_FMT_YUV420P;
  69. + avctx->pix_fmt = omx_map_color_format(avctx, dec_pix_fmt);
  70. s->stride = avctx->width;
  71. s->plane_size = avctx->height;
  72. - //avctx->pix_fmt = dec_pix_fmt;
  73. if (buffer->nFlags & OMX_BUFFERFLAG_EOS)
  74. s->got_eos = 1;
  75. --
  76. 2.17.1