0029-Omxdec-optimize-buffer-method-for-mjpg-decoder.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. From cc356de583854b257b52b8bf79eb519b7da34c9d Mon Sep 17 00:00:00 2001
  2. From: Som Qin <som.qin@starfivetech.com>
  3. Date: Fri, 4 Aug 2023 14:02:26 +0800
  4. Subject: [PATCH 8/8] Omxdec: optimize buffer method for mjpg decoder
  5. Signed-off-by: Som Qin <som.qin@starfivetech.com>
  6. ---
  7. libavcodec/omxdec.c | 88 +++++++++++++++------------------------------
  8. 1 file changed, 28 insertions(+), 60 deletions(-)
  9. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  10. index 47fb482..b38e3b9 100755
  11. --- a/libavcodec/omxdec.c
  12. +++ b/libavcodec/omxdec.c
  13. @@ -437,7 +437,8 @@ static OMX_ERRORTYPE event_handler(OMX_HANDLETYPE component, OMX_PTR app_data, O
  14. if (data1 == OMX_CommandStateSet) {
  15. pthread_mutex_lock(&s->state_mutex);
  16. s->state = data2;
  17. - av_log(s->avctx, AV_LOG_VERBOSE, "OMX state changed to %"PRIu32"\n", (uint32_t) data2);
  18. + if (!s->has_cleanup)
  19. + av_log(s->avctx, AV_LOG_VERBOSE, "OMX state changed to %"PRIu32"\n", (uint32_t) data2);
  20. pthread_cond_broadcast(&s->state_cond);
  21. pthread_mutex_unlock(&s->state_mutex);
  22. } else if (data1 == OMX_CommandPortDisable) {
  23. @@ -1180,11 +1181,14 @@ static int omx_buf_to_swframe(OMXCodecContext *s, AVFrame *frame, OMX_BUFFERHEAD
  24. switch (s->avctx->pix_fmt) {
  25. case AV_PIX_FMT_NV12:
  26. case AV_PIX_FMT_NV21:
  27. + case AV_PIX_FMT_NV16:
  28. frame->linesize[1] = linesize[1];
  29. frame->data[1] = dst[1];
  30. break;
  31. case AV_PIX_FMT_YUV420P:
  32. + case AV_PIX_FMT_YUV422P:
  33. + case AV_PIX_FMT_YUV444P:
  34. frame->linesize[1] = linesize[1];
  35. frame->linesize[2] = linesize[2];
  36. frame->data[1] = dst[1];
  37. @@ -1279,9 +1283,6 @@ static int omx_decode_frame(AVCodecContext *avctx, void *data,
  38. !pkt || had_partial);
  39. if (!buffer) {
  40. - if( avctx->codec_id == AV_CODEC_ID_MJPEG ) {
  41. - continue;
  42. - }
  43. break;
  44. }
  45. @@ -1308,66 +1309,33 @@ static int omx_decode_frame(AVCodecContext *avctx, void *data,
  46. if (buffer->nFlags & OMX_BUFFERFLAG_EOS)
  47. s->got_eos = 1;
  48. - if (avctx->codec->id == AV_CODEC_ID_HEVC ||
  49. - avctx->codec->id == AV_CODEC_ID_H264) {
  50. - avframe->width = avctx->width;
  51. - avframe->height = avctx->height;
  52. -
  53. - ret = ff_decode_frame_props(avctx, avframe);
  54. - if(ret < 0) {
  55. - av_log(avctx, AV_LOG_ERROR, "Unable to fill buffer props\n");
  56. - goto end;
  57. - }
  58. -
  59. - ret = omx_buf_to_swframe(s, avframe, buffer);
  60. - if(ret < 0) {
  61. - av_log(avctx, AV_LOG_ERROR, "Unable to alloce frame\n");
  62. - goto end;
  63. - }
  64. -
  65. - if (pkt->pts) {
  66. - if (OMXDecodeQueueEmpty(&s->decode_pts_queue) != 0){
  67. - av_log(avctx, AV_LOG_ERROR, "The queue of decode pts is empty.\n");
  68. - return AVERROR_INVALIDDATA;
  69. - }
  70. - avframe->pts = OMXDecodeQueueFront(&s->decode_pts_queue);
  71. - OMXDecodeQueuePop(&s->decode_pts_queue);
  72. - }
  73. - s->decode_flag += 1;
  74. - *got_packet = 1;
  75. -
  76. - return ret;
  77. -
  78. - } else if (avctx->codec->id == AV_CODEC_ID_MPEG4 ||
  79. - avctx->codec->id == AV_CODEC_ID_MJPEG) {
  80. + avframe->width = avctx->width;
  81. + avframe->height = avctx->height;
  82. - uint8_t *dst[4];
  83. - int linesize[4];
  84. - if ((ret = ff_get_buffer(avctx, avframe, 0)) < 0) {
  85. - av_log(avctx, AV_LOG_ERROR, "Unable to allocate buffer\n");
  86. - goto end;
  87. - }
  88. + ret = ff_decode_frame_props(avctx, avframe);
  89. + if(ret < 0) {
  90. + av_log(avctx, AV_LOG_ERROR, "Unable to fill buffer props\n");
  91. + goto end;
  92. + }
  93. - ret = av_image_fill_arrays(dst, linesize, buffer->pBuffer,
  94. - avctx->pix_fmt, s->stride, s->plane_size, 1);
  95. - if (ret < 0){
  96. - av_log(avctx, AV_LOG_ERROR, "av_image_fill_arrays ret:%d\n", ret);
  97. - goto end;
  98. - }
  99. + ret = omx_buf_to_swframe(s, avframe, buffer);
  100. + if(ret < 0) {
  101. + av_log(avctx, AV_LOG_ERROR, "Unable to alloce frame\n");
  102. + goto end;
  103. + }
  104. - av_image_copy(avframe->data, avframe->linesize, (const uint8_t**)dst, linesize,
  105. - avctx->pix_fmt, avctx->width, avctx->height);
  106. - if (pkt->pts) {
  107. - if (OMXDecodeQueueEmpty(&s->decode_pts_queue) != 0){
  108. - av_log(avctx, AV_LOG_ERROR, "The queue of decode pts is empty.\n");
  109. - return AVERROR_INVALIDDATA;
  110. - }
  111. - avframe->pts = OMXDecodeQueueFront(&s->decode_pts_queue);
  112. - OMXDecodeQueuePop(&s->decode_pts_queue);
  113. + if (pkt->pts) {
  114. + if (OMXDecodeQueueEmpty(&s->decode_pts_queue) != 0){
  115. + av_log(avctx, AV_LOG_ERROR, "The queue of decode pts is empty.\n");
  116. + return AVERROR_INVALIDDATA;
  117. }
  118. - s->decode_flag += 1;
  119. - *got_packet = 1;
  120. + avframe->pts = OMXDecodeQueueFront(&s->decode_pts_queue);
  121. + OMXDecodeQueuePop(&s->decode_pts_queue);
  122. }
  123. + s->decode_flag += 1;
  124. + *got_packet = 1;
  125. +
  126. + return ret;
  127. end:
  128. err = OMX_FillThisBuffer(s->handle, buffer);
  129. @@ -1523,7 +1491,7 @@ AVCodec ff_mjpeg_omx_decoder = {
  130. .decode = omx_decode_frame,
  131. .close = omx_decode_end,
  132. .flush = omx_decode_flush,
  133. - .capabilities = AV_CODEC_CAP_DR1,
  134. + .capabilities = AV_CODEC_CAP_DELAY,
  135. .max_lowres = 3,
  136. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  137. .priv_class = &omx_mjpegdec_class,
  138. --
  139. 2.25.1