From 201f88aa2580f12f349fec64e8efd5a2741115fb Mon Sep 17 00:00:00 2001 From: Matthias Reichl Date: Mon, 15 Jun 2020 12:08:45 +0200 Subject: [PATCH] kodi (RPi): support HEVC decode with upstream kodi Signed-off-by: Matthias Reichl --- packages/mediacenter/kodi/package.mk | 4 ++ .../rpi-hevc/001-support-zero-copy.patch | 49 +++++++++++++++ .../rpi-hevc/002-add-hevc-support.patch | 62 +++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 packages/mediacenter/kodi/patches/rpi-hevc/001-support-zero-copy.patch create mode 100644 packages/mediacenter/kodi/patches/rpi-hevc/002-add-hevc-support.patch diff --git a/packages/mediacenter/kodi/package.mk b/packages/mediacenter/kodi/package.mk index f551cbcf44..72aa84ad44 100644 --- a/packages/mediacenter/kodi/package.mk +++ b/packages/mediacenter/kodi/package.mk @@ -26,6 +26,10 @@ case $KODI_VENDOR in ;; esac +if [ "$KODIPLAYER_DRIVER" = bcm2835-driver -a "$KODI_VENDOR" = "default" ]; then + PKG_PATCH_DIRS+=" rpi-hevc" +fi + configure_package() { # Single threaded LTO is very slow so rely on Kodi for parallel LTO support if [ "$LTO_SUPPORT" = "yes" ] && ! build_with_debug; then diff --git a/packages/mediacenter/kodi/patches/rpi-hevc/001-support-zero-copy.patch b/packages/mediacenter/kodi/patches/rpi-hevc/001-support-zero-copy.patch new file mode 100644 index 0000000000..5d2edd31e3 --- /dev/null +++ b/packages/mediacenter/kodi/patches/rpi-hevc/001-support-zero-copy.patch @@ -0,0 +1,49 @@ +From 372718db53f3397dc0e972985202416fffe15ff4 Mon Sep 17 00:00:00 2001 +From: popcornmix +Date: Thu, 7 May 2015 15:35:43 +0100 +Subject: [PATCH] rbp: Support zero copy interface with hevc acceleration + +--- + .../VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp | 9 +++++++++ + xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp | 5 +++-- + 2 files changed, 12 insertions(+), 2 deletions(-) + +diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp +index 0af254029e..e1263012aa 100644 +--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp ++++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp +@@ -366,6 +366,15 @@ bool CDVDVideoCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options + if (m_decoderState == STATE_NONE) + { + m_decoderState = STATE_HW_SINGLE; ++#ifdef TARGET_RASPBERRY_PI ++ int num_threads = CServiceBroker::GetCPUInfo()->GetCPUCount() * 3 / 2; ++ num_threads = std::max(1, std::min(num_threads, 16)); ++ if (pCodec->id == AV_CODEC_ID_HEVC) ++ num_threads = 8; ++ m_pCodecContext->thread_count = num_threads; ++ m_pCodecContext->thread_safe_callbacks = 0; ++ CLog::Log(LOGDEBUG, "CDVDVideoCodecFFmpeg - open frame threaded with %d threads", num_threads); ++#endif + } + else + { +diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp +index 28eff23f16..779a839690 100644 +--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp ++++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp +@@ -298,8 +298,9 @@ CDVDVideoCodec::VCReturn CDecoder::Decode(AVCodecContext* avctx, AVFrame* frame) + + CGPUMEM *m_gmem = (CGPUMEM *)av_buffer_get_opaque(frame->buf[0]); + assert(m_gmem); +- // need to flush ARM cache so GPU can see it +- m_gmem->Flush(); ++ // need to flush ARM cache so GPU can see it (HEVC will have already done this) ++ if (avctx->codec_id != AV_CODEC_ID_HEVC) ++ m_gmem->Flush(); + m_renderBuffer = static_cast(m_gmem->m_opaque); + assert(m_renderBuffer && m_renderBuffer->mmal_buffer); + if (m_renderBuffer) +-- +2.20.1 + diff --git a/packages/mediacenter/kodi/patches/rpi-hevc/002-add-hevc-support.patch b/packages/mediacenter/kodi/patches/rpi-hevc/002-add-hevc-support.patch new file mode 100644 index 0000000000..e50f825e22 --- /dev/null +++ b/packages/mediacenter/kodi/patches/rpi-hevc/002-add-hevc-support.patch @@ -0,0 +1,62 @@ +From 115a3328123c060b9e4d5f35c3774aa17c73276a Mon Sep 17 00:00:00 2001 +From: popcornmix +Date: Mon, 26 Jun 2017 20:17:09 +0100 +Subject: [PATCH] MMAL: Add hevc support by allowing 4 planes + +--- + xbmc/cores/VideoPlayer/Buffers/VideoBuffer.h | 2 +- + xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp | 3 +++ + .../VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp | 3 +++ + 3 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/xbmc/cores/VideoPlayer/Buffers/VideoBuffer.h b/xbmc/cores/VideoPlayer/Buffers/VideoBuffer.h +index 1c1ba21c48..86a71bb558 100644 +--- a/xbmc/cores/VideoPlayer/Buffers/VideoBuffer.h ++++ b/xbmc/cores/VideoPlayer/Buffers/VideoBuffer.h +@@ -23,7 +23,7 @@ extern "C" { + + struct YuvImage + { +- static const int MAX_PLANES = 3; ++ static const int MAX_PLANES = 4; + + uint8_t* plane[MAX_PLANES]; + int planesize[MAX_PLANES]; +diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp +index 779a839690..a1a1ab1795 100644 +--- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp ++++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALFFmpeg.cpp +@@ -77,6 +77,8 @@ void CMMALYUVBuffer::GetStrides(int(&strides)[YuvImage::MAX_PLANES]) + strides[0] = geo.getStrideY(); + strides[1] = geo.getStrideC(); + strides[2] = geo.getStrideC(); ++ if (geo.getStripes() > 1) ++ strides[3] = geo.getHeightY() + geo.getHeightC(); // abuse: strides[3] = stripe stride + } + + void CMMALYUVBuffer::SetDimensions(int width, int height, const int (&strides)[YuvImage::MAX_PLANES], const int (&planeOffsets)[YuvImage::MAX_PLANES]) +@@ -284,6 +286,7 @@ CDVDVideoCodec::VCReturn CDecoder::Decode(AVCodecContext* avctx, AVFrame* frame) + if (frame) + { + if ((frame->format != AV_PIX_FMT_YUV420P && frame->format != AV_PIX_FMT_YUV420P10 && frame->format != AV_PIX_FMT_YUV420P12 && frame->format != AV_PIX_FMT_YUV420P14 && frame->format != AV_PIX_FMT_YUV420P16 && ++ frame->format != AV_PIX_FMT_SAND128 && frame->format != AV_PIX_FMT_SAND64_10 && frame->format != AV_PIX_FMT_SAND64_16 && + frame->format != AV_PIX_FMT_BGR0 && frame->format != AV_PIX_FMT_RGB565LE) || + frame->buf[1] != nullptr || frame->buf[0] == nullptr) + { +diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp +index 9b23ddb7fa..e55babf4d3 100644 +--- a/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp ++++ b/xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/MMALRenderer.cpp +@@ -192,6 +192,9 @@ std::vector CMMALPool::mmal_encoding_table = + { AV_PIX_FMT_YUV420P12,MMAL_ENCODING_I420_16, }, + { AV_PIX_FMT_YUV420P14,MMAL_ENCODING_I420_16, }, + { AV_PIX_FMT_YUV420P16,MMAL_ENCODING_I420_16, }, ++ { AV_PIX_FMT_SAND128, MMAL_ENCODING_YUVUV128 }, ++ { AV_PIX_FMT_SAND64_10,MMAL_ENCODING_YUVUV64_16 }, ++ { AV_PIX_FMT_SAND64_16,MMAL_ENCODING_YUVUV64_16 }, + { AV_PIX_FMT_RGBA, MMAL_ENCODING_RGBA, }, + { AV_PIX_FMT_BGRA, MMAL_ENCODING_BGRA }, + { AV_PIX_FMT_RGB0, MMAL_ENCODING_RGBA }, +-- +2.20.1 +