diff options
author | Alwin Esch <alwin.esch@web.de> | 2020-09-13 17:17:04 +0200 |
---|---|---|
committer | Alwin Esch <alwin.esch@web.de> | 2020-10-28 22:53:45 +0100 |
commit | 1ab39e1c289806999ff3745d85ef88cc12cc6cc8 (patch) | |
tree | aac00c928ddd653085e466b219d1f0d739614088 | |
parent | 16effb107ad6b6eb6445bffcbd6114e36f421a77 (diff) |
[addons][inputstream] make StreamCrypto.h in own folder and improve
There is the "C" part about moved to "kodi/c-api/addon-instance/inputstream/stream_crypto.h"
and parts renamed to have more clean. Further is the C++ helper class
"kodi::addon::StreamCryptoSession" added to use C++ on addons about.
10 files changed, 158 insertions, 67 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/CMakeLists.txt index ff0c548e52..298b5de1ce 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/CMakeLists.txt +++ b/xbmc/addons/kodi-dev-kit/include/kodi/CMakeLists.txt @@ -3,7 +3,6 @@ set(HEADERS AddonBase.h Filesystem.h General.h Network.h - StreamCrypto.h versions.h) if(CORE_SYSTEM_NAME STREQUAL android) diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/StreamCrypto.h b/xbmc/addons/kodi-dev-kit/include/kodi/StreamCrypto.h deleted file mode 100644 index dbeaab8d3d..0000000000 --- a/xbmc/addons/kodi-dev-kit/include/kodi/StreamCrypto.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include <inttypes.h> -#include <string.h> - -#define STREAMCRYPTO_VERSION_LEVEL 1 - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - - enum CRYPTO_KEY_SYSTEM - { - CRYPTO_KEY_SYSTEM_NONE = 0, - CRYPTO_KEY_SYSTEM_WIDEVINE, - CRYPTO_KEY_SYSTEM_PLAYREADY, - CRYPTO_KEY_SYSTEM_WISEPLAY, - CRYPTO_KEY_SYSTEM_COUNT - }; - - enum CRYPTO_FLAGS - { - CRYPTO_FLAG_NONE = 0, - - /// @brief is set in flags if decoding has to be done in TEE environment - CRYPTO_FLAG_SECURE_DECODER = (1 << 0) - }; - - struct CRYPTO_INFO - { - CRYPTO_KEY_SYSTEM - m_CryptoKeySystem; /*!< @brief keysystem for encrypted media, KEY_SYSTEM_NONE for unencrypted media */ - 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 */ - }; - -#ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h index 6a41597a91..cbf8250663 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h @@ -9,10 +9,10 @@ #pragma once #include "../AddonBase.h" -#include "../StreamCrypto.h" #include "../c-api/addon-instance/inputstream.h" #include "inputstream/StreamCodec.h" #include "inputstream/StreamConstants.h" +#include "inputstream/StreamCrypto.h" #include "inputstream/TimingConstants.h" #ifdef __cplusplus @@ -339,9 +339,15 @@ public: unsigned int GetBlockAlign() const { return m_cStructure->m_BlockAlign; } - void SetCryptoInfo(const CRYPTO_INFO& cryptoInfo) { m_cStructure->m_cryptoInfo = cryptoInfo; } + void SetCryptoSession(const kodi::addon::StreamCryptoSession& cryptoSession) + { + m_cryptoSession = cryptoSession; + m_cryptoSession.SetSessionId(cryptoSession.GetSessionId()); + memcpy(&m_cStructure->m_cryptoSession, m_cryptoSession.GetCStructure(), + sizeof(STREAM_CRYPTO_SESSION)); + } - const CRYPTO_INFO& GetCryptoInfo() const { return m_cStructure->m_cryptoInfo; } + const kodi::addon::StreamCryptoSession& GetCryptoSession() const { return m_cryptoSession; } void SetCodecFourCC(unsigned int codecFourCC) { m_cStructure->m_codecFourCC = codecFourCC; } @@ -416,6 +422,7 @@ private: m_contentLightMetadata = m_cStructure->m_contentLightMetadata; } std::vector<uint8_t> m_extraData; + StreamCryptoSession m_cryptoSession; InputstreamMasteringMetadata m_masteringMetadata; InputstreamContentlightMetadata m_contentLightMetadata; }; diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h index bf6c7a7c23..e9211b6987 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h @@ -9,8 +9,8 @@ #pragma once #include "../AddonBase.h" -#include "../StreamCrypto.h" #include "inputstream/StreamCodec.h" +#include "inputstream/StreamCrypto.h" #ifdef BUILD_KODI_ADDON #include "../DemuxPacket.h" @@ -48,7 +48,7 @@ extern "C" const uint8_t *extraData; unsigned int extraDataSize; - CRYPTO_INFO cryptoInfo; + struct STREAM_CRYPTO_SESSION cryptoSession; }; struct VIDEOCODEC_PICTURE diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/inputstream/StreamCrypto.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/inputstream/StreamCrypto.h new file mode 100644 index 0000000000..114b127108 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/inputstream/StreamCrypto.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2005-2020 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "../../c-api/addon-instance/inputstream/stream_crypto.h" + +#ifdef __cplusplus + +namespace kodi +{ +namespace addon +{ + +class CInstanceInputStream; +class InputstreamInfo; + +class ATTRIBUTE_HIDDEN StreamCryptoSession + : public CStructHdl<StreamCryptoSession, STREAM_CRYPTO_SESSION> +{ + friend class CInstanceInputStream; + friend class InputstreamInfo; + +public: + /*! \cond PRIVATE */ + StreamCryptoSession() { memset(m_cStructure, 0, sizeof(STREAM_CRYPTO_SESSION)); } + StreamCryptoSession(const StreamCryptoSession& session) + : CStructHdl(session), m_sessionId(session.m_sessionId) + { + } + /*! \endcond */ + + void SetKeySystem(STREAM_CRYPTO_KEY_SYSTEM keySystem) { m_cStructure->keySystem = keySystem; } + + STREAM_CRYPTO_KEY_SYSTEM GetKeySystem() const { return m_cStructure->keySystem; } + + void SetFlags(uint8_t flags) { m_cStructure->flags = flags; } + + uint8_t GetFlags() const { return m_cStructure->flags; } + + void SetSessionId(const std::string& sessionId) + { + m_sessionId = sessionId; + if (!m_sessionId.empty()) + { + m_cStructure->sessionId = m_sessionId.c_str(); + m_cStructure->sessionIdSize = m_sessionId.size(); + } + else + { + m_cStructure->sessionId = nullptr; + m_cStructure->sessionIdSize = 0; + } + } + + std::string GetSessionId() const { return m_sessionId; } + +private: + StreamCryptoSession(const STREAM_CRYPTO_SESSION* session) + : CStructHdl(session), m_sessionId(session->sessionId) + { + } + StreamCryptoSession(STREAM_CRYPTO_SESSION* session) + : CStructHdl(session), m_sessionId(session->sessionId) + { + } + + std::string m_sessionId; +}; + +} /* namespace addon */ +} /* namespace kodi */ + +#endif /* __cplusplus */ diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream.h b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream.h index 9baf5baa2c..5ee2457903 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream.h +++ b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream.h @@ -11,10 +11,10 @@ #ifndef C_API_ADDONINSTANCE_INPUTSTREAM_H #define C_API_ADDONINSTANCE_INPUTSTREAM_H -#include "../../StreamCrypto.h" #include "../addon_base.h" #include "inputstream/stream_codec.h" #include "inputstream/stream_constants.h" +#include "inputstream/stream_crypto.h" #include "inputstream/timing_constants.h" #ifdef BUILD_KODI_ADDON #include "../../DemuxPacket.h" @@ -303,7 +303,7 @@ extern "C" //@} - struct CRYPTO_INFO m_cryptoInfo; + struct STREAM_CRYPTO_SESSION m_cryptoSession; // new in API version 2.0.8 //@{ diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/CMakeLists.txt b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/CMakeLists.txt index 1eb62ecfe0..1d317feb5e 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/CMakeLists.txt +++ b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/CMakeLists.txt @@ -1,5 +1,6 @@ set(HEADERS stream_codec.h stream_constants.h + stream_crypto.h timing_constants.h) if(NOT ENABLE_STATIC_LIBS) diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/stream_crypto.h b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/stream_crypto.h new file mode 100644 index 0000000000..fc13abda92 --- /dev/null +++ b/xbmc/addons/kodi-dev-kit/include/kodi/c-api/addon-instance/inputstream/stream_crypto.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#ifndef C_API_ADDONINSTANCE_INPUTSTREAM_STREAMCRYPTO_H +#define C_API_ADDONINSTANCE_INPUTSTREAM_STREAMCRYPTO_H + +#include <stdint.h> +#include <string.h> + +#define STREAMCRYPTO_VERSION_LEVEL 1 + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + enum STREAM_CRYPTO_KEY_SYSTEM + { + STREAM_CRYPTO_KEY_SYSTEM_NONE = 0, + STREAM_CRYPTO_KEY_SYSTEM_WIDEVINE, + STREAM_CRYPTO_KEY_SYSTEM_PLAYREADY, + STREAM_CRYPTO_KEY_SYSTEM_WISEPLAY, + STREAM_CRYPTO_KEY_SYSTEM_COUNT + }; + + enum STREAM_CRYPTO_FLAGS + { + STREAM_CRYPTO_FLAG_NONE = 0, + + /// @brief is set in flags if decoding has to be done in TEE environment + STREAM_CRYPTO_FLAG_SECURE_DECODER = (1 << 0) + }; + + struct STREAM_CRYPTO_SESSION + { + enum STREAM_CRYPTO_KEY_SYSTEM keySystem; /*!< @brief keysystem for encrypted media, + KEY_SYSTEM_NONE for unencrypted media */ + uint8_t flags; + uint16_t sessionIdSize; /*!< @brief The size of the crypto session key id */ + const char* sessionId; /*!< @brief The crypto session key id */ + }; + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* !C_API_ADDONINSTANCE_INPUTSTREAM_STREAMCRYPTO_H */ diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AddonVideoCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AddonVideoCodec.cpp index 834d5e570a..6c7fe045a9 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/AddonVideoCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/AddonVideoCodec.cpp @@ -122,23 +122,23 @@ bool CAddonVideoCodec::CopyToInitData(VIDEOCODEC_INITDATA &initData, CDVDStreamI switch (hints.cryptoSession->keySystem) { case CRYPTO_SESSION_SYSTEM_NONE: - initData.cryptoInfo.m_CryptoKeySystem = CRYPTO_KEY_SYSTEM_NONE; + initData.cryptoSession.keySystem = STREAM_CRYPTO_KEY_SYSTEM_NONE; break; case CRYPTO_SESSION_SYSTEM_WIDEVINE: - initData.cryptoInfo.m_CryptoKeySystem = CRYPTO_KEY_SYSTEM_WIDEVINE; + initData.cryptoSession.keySystem = STREAM_CRYPTO_KEY_SYSTEM_WIDEVINE; break; case CRYPTO_SESSION_SYSTEM_PLAYREADY: - initData.cryptoInfo.m_CryptoKeySystem = CRYPTO_KEY_SYSTEM_PLAYREADY; + initData.cryptoSession.keySystem = STREAM_CRYPTO_KEY_SYSTEM_PLAYREADY; break; case CRYPTO_SESSION_SYSTEM_WISEPLAY: - initData.cryptoInfo.m_CryptoKeySystem = CRYPTO_KEY_SYSTEM_WISEPLAY; + initData.cryptoSession.keySystem = STREAM_CRYPTO_KEY_SYSTEM_WISEPLAY; break; default: return false; } - initData.cryptoInfo.m_CryptoSessionIdSize = hints.cryptoSession->sessionIdSize; + initData.cryptoSession.sessionIdSize = hints.cryptoSession->sessionIdSize; //We assume that we need this sessionid only for the directly following call - initData.cryptoInfo.m_CryptoSessionId = hints.cryptoSession->sessionId; + initData.cryptoSession.sessionId = hints.cryptoSession->sessionId; } initData.extraData = reinterpret_cast<const uint8_t*>(hints.extradata); diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp index 675783fc60..4c7f7caef5 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamAddon.cpp @@ -524,8 +524,8 @@ KODI_HANDLE CInputStreamAddon::cb_get_stream_transfer(KODI_HANDLE handle, demuxStream->ExtraData[j] = stream->m_ExtraData[j]; } - if (stream->m_cryptoInfo.m_CryptoKeySystem != CRYPTO_KEY_SYSTEM_NONE && - stream->m_cryptoInfo.m_CryptoKeySystem < CRYPTO_KEY_SYSTEM_COUNT) + if (stream->m_cryptoSession.keySystem != STREAM_CRYPTO_KEY_SYSTEM_NONE && + stream->m_cryptoSession.keySystem < STREAM_CRYPTO_KEY_SYSTEM_COUNT) { static const CryptoSessionSystem map[] = { CRYPTO_SESSION_SYSTEM_NONE, @@ -534,8 +534,8 @@ KODI_HANDLE CInputStreamAddon::cb_get_stream_transfer(KODI_HANDLE handle, CRYPTO_SESSION_SYSTEM_WISEPLAY, }; demuxStream->cryptoSession = std::shared_ptr<DemuxCryptoSession>(new DemuxCryptoSession( - map[stream->m_cryptoInfo.m_CryptoKeySystem], stream->m_cryptoInfo.m_CryptoSessionIdSize, - stream->m_cryptoInfo.m_CryptoSessionId, stream->m_cryptoInfo.flags)); + map[stream->m_cryptoSession.keySystem], stream->m_cryptoSession.sessionIdSize, + stream->m_cryptoSession.sessionId, stream->m_cryptoSession.flags)); if ((stream->m_features & INPUTSTREAM_FEATURE_DECODE) != 0) demuxStream->externalInterfaces = thisClass->m_subAddonProvider; |