Skip to content

Commit

Permalink
AudioDecoderHW Registration / DVDCodecAudioAndroidMediaCodec
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d authored and popcornmix committed Jul 9, 2017
1 parent db58f53 commit a6bee13
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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;
Expand Down
54 changes: 41 additions & 13 deletions xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.cpp
Expand Up @@ -53,9 +53,11 @@
//------------------------------------------------------------------------------

std::map<std::string, CreateHWVideoCodec> CDVDFactoryCodec::m_hwVideoCodecs;
std::map<std::string, CreateHWAudioCodec> CDVDFactoryCodec::m_hwAudioCodecs;

std::map<std::string, CreateHWAccel> CDVDFactoryCodec::m_hwAccels;

CCriticalSection videoCodecSection;
CCriticalSection videoCodecSection, audioCodecSection;

CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, CProcessInfo &processInfo)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -268,12 +305,3 @@ CDVDOverlayCodec* CDVDFactoryCodec::CreateOverlayCodec( CDVDStreamInfo &hint )
return nullptr;
}

//------------------------------------------------------------------------------
// Stubs for platform specific overrides
//------------------------------------------------------------------------------


CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodecHW(CProcessInfo &processInfo)
{
return nullptr;
}
8 changes: 7 additions & 1 deletion xbmc/cores/VideoPlayer/DVDCodecs/DVDFactoryCodec.h
Expand Up @@ -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
{
Expand All @@ -66,12 +67,17 @@ class CDVDFactoryCodec
static std::vector<std::string> 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<std::string, CreateHWVideoCodec> m_hwVideoCodecs;
static std::map<std::string, CreateHWAccel> m_hwAccels;
static std::map<std::string, CreateHWAudioCodec> m_hwAudioCodecs;
};

3 changes: 3 additions & 0 deletions xbmc/windowing/android/WinSystemAndroid.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -71,6 +72,8 @@ bool CWinSystemAndroid::InitWindowSystem()
m_android = new CAndroidUtils();

CDVDVideoCodecAndroidMediaCodec::Register();
CDVDAudioCodecAndroidMediaCodec::Register();

CRendererMediaCodec::Register();
CRendererMediaCodecSurface::Register();

Expand Down

0 comments on commit a6bee13

Please sign in to comment.