0026-Omxdec-Add-flush-callback-of-sf-omx-decoder.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From b8af55868ea8b2b68ef06fee2eb8a19b16fdb79d Mon Sep 17 00:00:00 2001
  2. From: Som Qin <som.qin@starfivetech.com>
  3. Date: Fri, 4 Aug 2023 13:53:57 +0800
  4. Subject: [PATCH 5/8] Omxdec: Add flush callback of sf omx decoder
  5. Signed-off-by: Som Qin <som.qin@starfivetech.com>
  6. ---
  7. libavcodec/omxdec.c | 22 ++++++++++++++++++++++
  8. 1 file changed, 22 insertions(+)
  9. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  10. index 05e37d0..d268454 100755
  11. --- a/libavcodec/omxdec.c
  12. +++ b/libavcodec/omxdec.c
  13. @@ -365,6 +365,7 @@ typedef struct OMXCodecContext {
  14. OMX_U32 scale_height;
  15. OMX_U32 rotation;
  16. OMX_U32 mirror;
  17. + OMX_U32 skip;
  18. char *crop_expr;
  19. struct {
  20. int x;
  21. @@ -1310,6 +1311,11 @@ static int omx_decode_frame(AVCodecContext *avctx, void *data,
  22. }
  23. break;
  24. }
  25. +
  26. + if(s->skip) {
  27. + s->skip--;
  28. + goto end;
  29. + }
  30. //if (!buffer)
  31. // break;
  32. // if(!s->first_get_outbuffer)
  33. @@ -1401,6 +1407,18 @@ end:
  34. return ret;
  35. }
  36. +static void omx_decode_flush(AVCodecContext *avctx)
  37. +{
  38. + OMXCodecContext *s = avctx->priv_data;
  39. +
  40. + av_log(avctx, AV_LOG_VERBOSE, "Flushing buffer\n");
  41. +
  42. + while(!OMXDecodeQueueEmpty(&s->decode_pts_queue)) {
  43. + OMXDecodeQueuePop(&s->decode_pts_queue);
  44. + s->skip++;
  45. + }
  46. +}
  47. +
  48. static av_cold int omx_decode_end(AVCodecContext *avctx)
  49. {
  50. OMXCodecContext *s = avctx->priv_data;
  51. @@ -1465,6 +1483,7 @@ AVCodec ff_mpeg4_omx_decoder = {
  52. .init = omx_decode_init,
  53. .decode = omx_decode_frame,
  54. .close = omx_decode_end,
  55. + .flush = omx_decode_flush,
  56. .capabilities = AV_CODEC_CAP_DELAY,
  57. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  58. .priv_class = &omx_mpeg4dec_class,
  59. @@ -1485,6 +1504,7 @@ AVCodec ff_h264_omx_decoder = {
  60. .init = omx_decode_init,
  61. .decode = omx_decode_frame,
  62. .close = omx_decode_end,
  63. + .flush = omx_decode_flush,
  64. .capabilities = AV_CODEC_CAP_DELAY,
  65. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  66. .priv_class = &omx_h264dec_class,
  67. @@ -1506,6 +1526,7 @@ AVCodec ff_hevc_omx_decoder = {
  68. .init = omx_decode_init,
  69. .decode = omx_decode_frame,
  70. .close = omx_decode_end,
  71. + .flush = omx_decode_flush,
  72. .profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
  73. .capabilities = AV_CODEC_CAP_DELAY,
  74. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  75. @@ -1528,6 +1549,7 @@ AVCodec ff_mjpeg_omx_decoder = {
  76. .init = omx_decode_init,
  77. .decode = omx_decode_frame,
  78. .close = omx_decode_end,
  79. + .flush = omx_decode_flush,
  80. .capabilities = AV_CODEC_CAP_DR1,
  81. .max_lowres = 3,
  82. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  83. --
  84. 2.25.1