Skip to content

Commit

Permalink
[Android] MediaDrm JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Apr 2, 2018
1 parent c759106 commit f1c71f9
Show file tree
Hide file tree
Showing 32 changed files with 4,306 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -21,6 +21,7 @@ set(ADP_SOURCES
src/TSReader.cpp
src/aes_decrypter.cpp
src/ADTSReader.cpp
src/md5.cpp
)

set(ADP_HEADERS
Expand All @@ -38,6 +39,7 @@ set(ADP_HEADERS
src/log.h
src/aes_decrypter.h
src/ADTSReader.h
src/md5.h
)

if(WIN32)
Expand Down
2 changes: 1 addition & 1 deletion inputstream.adaptive/resources/settings.xml.in
Expand Up @@ -4,7 +4,7 @@
<setting id="MINBANDWIDTH" type="number" default="0" label="30101" />
<setting id="MAXBANDWIDTH" type="number" default = "0" label="30102" />
<setting id="MAXRESOLUTION" type="enum" label="30110" default = "0" values="Max|480p|720p|1080p" />
<setting id="MAXRESOLUTIONSECURE" type="enum" label="30113" default = "2" values="Max|480p|720p|1080p" />
<setting id="MAXRESOLUTIONSECURE" type="enum" label="30113" default = "3" values="Max|480p|640p|720p|1080p" />

This comment has been minimized.

Copy link
@dagwieers

dagwieers May 8, 2019

Contributor

This introduced a problem where if you selected 720p, you would get a lower quality stream. And if you selected 1080p you would get the 720p stream. It is fixed in #259

<setting id="STREAMSELECTION" type="enum" label="30111" default = "0" values="Auto|Manual" />
<setting id="MEDIATYPE" type="enum" label="30112" default = "0" values="All|Audio|Video" />
<setting id="HDCPOVERRIDE" type="bool" label="30114" default="false" />
Expand Down
7 changes: 5 additions & 2 deletions src/SSD_dll.h
Expand Up @@ -17,8 +17,11 @@ namespace SSD
OPTION_PROTOCOL,
OPTION_HEADER
};
static const uint32_t version = 9;

static const uint32_t version = 10;
#if defined(ANDROID)
virtual void* GetJNIEnv() = 0;
virtual int GetSDKVersion() = 0;
#endif
virtual const char *GetLibraryPath() const = 0;
virtual const char *GetProfilePath() const = 0;
virtual void* CURLCreate(const char* strURL) = 0;
Expand Down
46 changes: 40 additions & 6 deletions src/main.cpp
Expand Up @@ -46,6 +46,10 @@
#include <dlfcn.h> // linux+osx
#endif

#if defined(ANDROID)
#include <kodi/platform/android/System.h>
#endif

#define DVD_TIME_BASE 1000000

#undef CreateDirectory
Expand Down Expand Up @@ -74,6 +78,18 @@ kodi host - interface for decrypter libraries
class KodiHost : public SSD::SSD_HOST
{
public:
#if defined(ANDROID)
virtual void *GetJNIEnv() override
{
return m_androidSystem.GetJNIEnv();
};

virtual int GetSDKVersion() override
{
return m_androidSystem.GetSDKVersion();
};

#endif
virtual const char *GetLibraryPath() const override
{
return m_strLibraryPath.c_str();
Expand Down Expand Up @@ -170,7 +186,11 @@ class KodiHost : public SSD::SSD_HOST

private:
std::string m_strProfilePath, m_strLibraryPath;
}kodihost;

#if defined(ANDROID)
kodi::platform::CInterfaceAndroidSystem m_androidSystem;
#endif
}*kodihost;

/*******************************************************
Bento4 Streams
Expand Down Expand Up @@ -1642,7 +1662,7 @@ void Session::GetSupportedDecrypterURN(std::string &key_system)
kodi::Log(ADDON_LOG_DEBUG, "DECRYPTERPATH not specified in settings.xml");
return;
}
kodihost.SetLibraryPath(kodi::vfs::TranslateSpecialProtocol(specialpath).c_str());
kodihost->SetLibraryPath(kodi::vfs::TranslateSpecialProtocol(specialpath).c_str());

std::vector<std::string> searchPaths(2);
#ifdef ANDROID
Expand Down Expand Up @@ -1672,7 +1692,7 @@ void Session::GetSupportedDecrypterURN(std::string &key_system)
CreateDecryptorInstanceFunc startup;
if ((startup = (CreateDecryptorInstanceFunc)dlsym(mod, "CreateDecryptorInstance")))
{
SSD::SSD_DECRYPTER *decrypter = startup(&kodihost, SSD::SSD_HOST::version);
SSD::SSD_DECRYPTER *decrypter = startup(kodihost, SSD::SSD_HOST::version);
const char *suppUrn(0);

if (decrypter && (suppUrn = decrypter->SelectKeySytem(license_type_.c_str())))
Expand Down Expand Up @@ -2252,9 +2272,12 @@ std::uint16_t Session::GetVideoWidth() const
if (ret > 640) ret = 640;
break;
case 2:
if (ret > 1280) ret = 1280;
if (ret > 960) ret = 960;
break;
case 3:
if (ret > 1280) ret = 1280;
break;
case 4:
if (ret > 1920) ret = 1920;
break;
default:
Expand All @@ -2272,9 +2295,12 @@ std::uint16_t Session::GetVideoHeight() const
if (ret > 480) ret = 480;
break;
case 2:
if (ret > 720) ret = 720;
if (ret > 640) ret = 640;
break;
case 3:
if (ret > 720) ret = 720;
break;
case 4:
if (ret > 1080) ret = 1080;
break;
default:
Expand Down Expand Up @@ -2468,7 +2494,7 @@ bool CInputStreamAdaptive::Open(INPUTSTREAM& props)
mpd_url = mpd_url.substr(0, posHeader);
}

kodihost.SetProfilePath(props.m_profileFolder);
kodihost->SetProfilePath(props.m_profileFolder);

m_session = std::shared_ptr<Session>(new Session(manifest, mpd_url.c_str(), mfup, lt, lk, ld, lsc, manh, medh, props.m_profileFolder, m_width, m_height));
m_session->SetVideoResolution(m_width, m_height);
Expand Down Expand Up @@ -2940,18 +2966,26 @@ class CMyAddon
{
public:
CMyAddon();
virtual ~CMyAddon();
virtual ADDON_STATUS CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance) override;
};

CMyAddon::CMyAddon()
{
kodihost = nullptr;;
}

CMyAddon::~CMyAddon()
{
delete kodihost;
}

ADDON_STATUS CMyAddon::CreateInstance(int instanceType, std::string instanceID, KODI_HANDLE instance, KODI_HANDLE& addonInstance)
{
if (instanceType == ADDON_INSTANCE_INPUTSTREAM)
{
addonInstance = new CInputStreamAdaptive(instance);
kodihost = new KodiHost();
return ADDON_STATUS_OK;
}
return ADDON_STATUS_NOT_IMPLEMENTED;
Expand Down

0 comments on commit f1c71f9

Please sign in to comment.