Skip to content

Commit

Permalink
Merge pull request #12428 from peak3d/secure_decoder
Browse files Browse the repository at this point in the history
[Inputstream] add CryptoSession flags field
  • Loading branch information
peak3d committed Jul 6, 2017
2 parents 04126fc + dd459fb commit 42c731a
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 88 deletions.
8 changes: 6 additions & 2 deletions xbmc/addons/kodi-addon-dev-kit/include/kodi/StreamCrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@

typedef struct CRYPTO_INFO
{
enum CRYPTO_KEY_SYSTEM : uint16_t
enum CRYPTO_KEY_SYSTEM : uint8_t
{
CRYPTO_KEY_SYSTEM_NONE = 0,
CRYPTO_KEY_SYSTEM_WIDEVINE,
CRYPTO_KEY_SYSTEM_PLAYREADY,
CRYPTO_KEY_SYSTEM_COUNT
} m_CryptoKeySystem; /*!< @brief keysystem for encrypted media, KEY_SYSTEM_NONE for unencrypted media */
const char *m_CryptoSessionId; /*!< @brief The crypto session key id */

static const uint8_t FLAG_SECURE_DECODER = 1; /*!< @brief is set in flags if decoding has to be done in TEE environment */

uint8_t flags;
uint16_t m_CryptoSessionIdSize; /*!< @brief The size of the crypto session key id */
const char *m_CryptoSessionId; /*!< @brief The crypto session key id */
} CRYPTO_INFO;
4 changes: 2 additions & 2 deletions xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
#define ADDON_INSTANCE_VERSION_IMAGEDECODER_XML_ID "kodi.binary.instance.imagedecoder"
#define ADDON_INSTANCE_VERSION_IMAGEDECODER_DEPENDS "addon-instance/ImageDecoder.h"

#define ADDON_INSTANCE_VERSION_INPUTSTREAM "2.0.0"
#define ADDON_INSTANCE_VERSION_INPUTSTREAM_MIN "2.0.0"
#define ADDON_INSTANCE_VERSION_INPUTSTREAM "2.0.1"
#define ADDON_INSTANCE_VERSION_INPUTSTREAM_MIN "2.0.1"
#define ADDON_INSTANCE_VERSION_INPUTSTREAM_XML_ID "kodi.binary.instance.inputstream"
#define ADDON_INSTANCE_VERSION_INPUTSTREAM_DEPENDS "addon-instance/Inputstream.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ std::atomic<bool> CDVDVideoCodecAndroidMediaCodec::m_InstanceGuard(false);
bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options)
{
int num_codecs;
bool needSecureDecoder;
bool needSecureDecoder(false);

m_opened = false;
// allow only 1 instance here
Expand Down Expand Up @@ -603,6 +603,7 @@ bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptio
CLog::Log(LOGERROR, "MediaCrypto::ExceptionCheck: <init>");
goto FAIL;
}
needSecureDecoder = AMediaCrypto_requiresSecureDecoderComponent(m_mime.c_str()) && (m_hints.cryptoSession->flags & DemuxCryptoSession::FLAG_SECURE_DECODER) != 0;
}

if (m_render_surface)
Expand Down Expand Up @@ -630,7 +631,6 @@ bool CDVDVideoCodecAndroidMediaCodec::Open(CDVDStreamInfo &hints, CDVDCodecOptio
}
m_colorFormat = -1;
num_codecs = CJNIMediaCodecList::getCodecCount();
needSecureDecoder = m_crypto && AMediaCrypto_requiresSecureDecoderComponent(m_mime.c_str());

for (int i = 0; i < num_codecs; i++)
{
Expand Down
166 changes: 85 additions & 81 deletions xbmc/cores/VideoPlayer/DVDDemuxers/DemuxCrypto.h
Original file line number Diff line number Diff line change
@@ -1,81 +1,85 @@
/*
* Copyright (C) 2005-2016 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include <inttypes.h>
#include <string.h>

//CryptoSession is usually obtained once per stream, but could change if an key expires

enum CryptoSessionSystem :uint16_t
{
CRYPTO_SESSION_SYSTEM_NONE,
CRYPTO_SESSION_SYSTEM_WIDEVINE,
CRYPTO_SESSION_SYSTEM_PLAYREADY
};

struct DemuxCryptoSession
{
DemuxCryptoSession(const CryptoSessionSystem sys, const uint16_t sSize, const char *sData)
: sessionId(new char[sSize])
, sessionIdSize(sSize)
, keySystem(sys)
{
memcpy(sessionId, sData, sSize);
};

~DemuxCryptoSession()
{
delete[] sessionId;
}

// encryped stream infos
char * sessionId;
uint16_t sessionIdSize;
CryptoSessionSystem keySystem;
};

//CryptoInfo stores the information to decrypt a sample

struct DemuxCryptoInfo
{
DemuxCryptoInfo(const unsigned int numSubs)
: numSubSamples(numSubs)
, flags(0)
, clearBytes(new uint16_t[numSubs])
, cipherBytes(new uint32_t[numSubs])
{};

~DemuxCryptoInfo()
{
delete[] clearBytes;
delete[] cipherBytes;
}

uint16_t numSubSamples; //number of subsamples
uint16_t flags; //flags for later use

uint16_t *clearBytes; // numSubSamples uint16_t's wich define the size of clear size of a subsample
uint32_t *cipherBytes; // numSubSamples uint32_t's wich define the size of cipher size of a subsample

uint8_t iv[16]; // initialization vector
uint8_t kid[16]; // key id
};
/*
* Copyright (C) 2005-2016 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include <inttypes.h>
#include <string.h>

//CryptoSession is usually obtained once per stream, but could change if an key expires

enum CryptoSessionSystem :uint8_t
{
CRYPTO_SESSION_SYSTEM_NONE,
CRYPTO_SESSION_SYSTEM_WIDEVINE,
CRYPTO_SESSION_SYSTEM_PLAYREADY
};

struct DemuxCryptoSession
{
DemuxCryptoSession(const CryptoSessionSystem sys, const uint16_t sSize, const char *sData, const uint8_t flags)
: sessionId(new char[sSize])
, sessionIdSize(sSize)
, keySystem(sys)
, flags(flags)
{
memcpy(sessionId, sData, sSize);
};

~DemuxCryptoSession()
{
delete[] sessionId;
}

// encryped stream infos
char * sessionId;
uint16_t sessionIdSize;
CryptoSessionSystem keySystem;

static const uint8_t FLAG_SECURE_DECODER = 1;
uint8_t flags;
};

//CryptoInfo stores the information to decrypt a sample

struct DemuxCryptoInfo
{
DemuxCryptoInfo(const unsigned int numSubs)
: numSubSamples(numSubs)
, flags(0)
, clearBytes(new uint16_t[numSubs])
, cipherBytes(new uint32_t[numSubs])
{};

~DemuxCryptoInfo()
{
delete[] clearBytes;
delete[] cipherBytes;
}

uint16_t numSubSamples; //number of subsamples
uint16_t flags; //flags for later use

uint16_t *clearBytes; // numSubSamples uint16_t's wich define the size of clear size of a subsample
uint32_t *cipherBytes; // numSubSamples uint32_t's wich define the size of cipher size of a subsample

uint8_t iv[16]; // initialization vector
uint8_t kid[16]; // key id
};
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ void CInputStreamAddon::UpdateStreams()
CRYPTO_SESSION_SYSTEM_PLAYREADY
};
demuxStream->cryptoSession = std::shared_ptr<DemuxCryptoSession>(new DemuxCryptoSession(
map[stream.m_cryptoInfo.m_CryptoKeySystem], stream.m_cryptoInfo.m_CryptoSessionIdSize, stream.m_cryptoInfo.m_CryptoSessionId));
map[stream.m_cryptoInfo.m_CryptoKeySystem], stream.m_cryptoInfo.m_CryptoSessionIdSize, stream.m_cryptoInfo.m_CryptoSessionId, stream.m_cryptoInfo.flags));

if ((stream.m_features & INPUTSTREAM_INFO::FEATURE_DECODE) != 0)
{
Expand Down

0 comments on commit 42c731a

Please sign in to comment.