From a6bee13d95ca204624bc4a22e0522b467db4c1cb Mon Sep 17 00:00:00 2001 From: peak3d Date: Sun, 2 Jul 2017 18:01:41 +0200 Subject: [PATCH] AudioDecoderHW Registration / DVDCodecAudioAndroidMediaCodec --- .../Audio/DVDAudioCodecAndroidMediaCodec.cpp | 12 +++++ .../Audio/DVDAudioCodecAndroidMediaCodec.h | 4 ++ .../VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp | 54 ++++++++++++++----- .../VideoPlayer/DVDCodecs/DVDFactoryCodec.h | 8 ++- xbmc/windowing/android/WinSystemAndroid.cpp | 3 ++ 5 files changed, 67 insertions(+), 14 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.cpp index bcd26a27e5015..2bb9acdfc2b49 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.cpp @@ -29,6 +29,7 @@ #include "DVDAudioCodecAndroidMediaCodec.h" #include "DVDCodecs/DVDCodecs.h" +#include "DVDCodecs/DVDFactoryCodec.h" #include "utils/log.h" #include "settings/AdvancedSettings.h" #include "cores/VideoPlayer/DVDDemuxers/DemuxCrypto.h" @@ -71,6 +72,17 @@ CDVDAudioCodecAndroidMediaCodec::~CDVDAudioCodecAndroidMediaCodec() Dispose(); } +CDVDAudioCodec* CDVDAudioCodecAndroidMediaCodec::Create(CProcessInfo &processInfo) +{ + return new CDVDAudioCodecAndroidMediaCodec(processInfo); +} + +bool CDVDAudioCodecAndroidMediaCodec::Register() +{ + CDVDFactoryCodec::RegisterHWAudioCodec("mediacodec_dec", &CDVDAudioCodecAndroidMediaCodec::Create); + return true; +} + bool CDVDAudioCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) { if (!hints.cryptoSession) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.h b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.h index 61b6ffca58b8e..529bf4e00a11c 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.h @@ -42,6 +42,10 @@ class CDVDAudioCodecAndroidMediaCodec : public CDVDAudioCodec CDVDAudioCodecAndroidMediaCodec(CProcessInfo &processInfo); virtual ~CDVDAudioCodecAndroidMediaCodec(); + // registration + static CDVDAudioCodec* Create(CProcessInfo &processInfo); + static bool Register(); + // required overrides public: virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) override; diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp index 13a526388fc89..175ee78a6199a 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp @@ -53,9 +53,11 @@ //------------------------------------------------------------------------------ std::map CDVDFactoryCodec::m_hwVideoCodecs; +std::map CDVDFactoryCodec::m_hwAudioCodecs; + std::map CDVDFactoryCodec::m_hwAccels; -CCriticalSection videoCodecSection; +CCriticalSection videoCodecSection, audioCodecSection; CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, CProcessInfo &processInfo) { @@ -185,10 +187,18 @@ CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec(CDVDStreamInfo &hint, CProces CDVDCodecOptions options; // platform specifig audio decoders - pCodec.reset(CreateAudioCodecHW(processInfo)); - if (pCodec && pCodec->Open(hint, options)) + if (!(hint.codecOptions & CODEC_FORCE_SOFTWARE)) { - return pCodec.release(); + for (auto &codec : m_hwAudioCodecs) + { + pCodec.reset(CreateAudioCodecHW(codec.first, processInfo)); + if (pCodec && pCodec->Open(hint, options)) + { + return pCodec.release(); + } + } + if (!(hint.codecOptions & CODEC_ALLOW_FALLBACK)) + return nullptr; } if (!allowdtshddecode) @@ -213,6 +223,33 @@ CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec(CDVDStreamInfo &hint, CProces return nullptr; } +void CDVDFactoryCodec::RegisterHWAudioCodec(std::string id, CreateHWAudioCodec createFunc) +{ + CSingleLock lock(audioCodecSection); + + m_hwAudioCodecs[id] = createFunc; +} + +void CDVDFactoryCodec::ClearHWAudioCodecs() +{ + CSingleLock lock(audioCodecSection); + + m_hwAudioCodecs.clear(); +} + +CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodecHW(std::string id, CProcessInfo &processInfo) +{ + CSingleLock lock(audioCodecSection); + + auto it = m_hwAudioCodecs.find(id); + if (it != m_hwAudioCodecs.end()) + { + return it->second(processInfo); + } + + return nullptr; +} + //------------------------------------------------------------------------------ // Overlay //------------------------------------------------------------------------------ @@ -268,12 +305,3 @@ CDVDOverlayCodec* CDVDFactoryCodec::CreateOverlayCodec( CDVDStreamInfo &hint ) return nullptr; } -//------------------------------------------------------------------------------ -// Stubs for platform specific overrides -//------------------------------------------------------------------------------ - - -CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodecHW(CProcessInfo &processInfo) -{ - return nullptr; -} diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h b/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h index 35bb60600073a..d52369311c778 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h @@ -43,6 +43,7 @@ class CDVDCodecOptions; typedef CDVDVideoCodec* (*CreateHWVideoCodec)(CProcessInfo &processInfo); typedef IHardwareDecoder* (*CreateHWAccel)(CDVDStreamInfo &hint, CProcessInfo &processInfo, AVPixelFormat fmt); +typedef CDVDAudioCodec* (*CreateHWAudioCodec)(CProcessInfo &processInfo); class CDVDFactoryCodec { @@ -66,12 +67,17 @@ class CDVDFactoryCodec static std::vector GetHWAccels(); static void ClearHWAccels(); + static void RegisterHWAudioCodec(std::string id, CreateHWAudioCodec createFunc); + static void ClearHWAudioCodecs(); + + protected: static CDVDVideoCodec* CreateVideoCodecHW(std::string id, CProcessInfo &processInfo); - static CDVDAudioCodec* CreateAudioCodecHW(CProcessInfo &processInfo); + static CDVDAudioCodec* CreateAudioCodecHW(std::string id, CProcessInfo &processInfo); static std::map m_hwVideoCodecs; static std::map m_hwAccels; + static std::map m_hwAudioCodecs; }; diff --git a/xbmc/windowing/android/WinSystemAndroid.cpp b/xbmc/windowing/android/WinSystemAndroid.cpp index d1f35a30cc6f5..d2de0a994add7 100644 --- a/xbmc/windowing/android/WinSystemAndroid.cpp +++ b/xbmc/windowing/android/WinSystemAndroid.cpp @@ -34,6 +34,7 @@ #include "platform/android/activity/XBMCApp.h" #include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecAndroidMediaCodec.h" +#include "cores/VideoPlayer/DVDCodecs/Audio/DVDAudioCodecAndroidMediaCodec.h" #include "cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodec.h" #include "cores/VideoPlayer/VideoRenderers/HwDecRender/RendererMediaCodecSurface.h" @@ -71,6 +72,8 @@ bool CWinSystemAndroid::InitWindowSystem() m_android = new CAndroidUtils(); CDVDVideoCodecAndroidMediaCodec::Register(); + CDVDAudioCodecAndroidMediaCodec::Register(); + CRendererMediaCodec::Register(); CRendererMediaCodecSurface::Register();