blob: 842793afb750c5526bde27b304536815be1c778a [file] [edit]
From aefd93708c95d1ff2f7ac74d20d5d5a37e89d5bc Mon Sep 17 00:00:00 2001
From: svemur170 <srikanth_vemuri@comcast.com>
Date: Fri, 26 Aug 2022 11:33:25 -0400
Subject: [PATCH] DELIA-57501 : Fix Warnings in RDKServices builds and enable
warnings as errors
---
OpenCDMi/CMakeLists.txt | 1 +
OpenCDMi/CapsParser.cpp | 200 ++++++++++++++++++++++++++++++++++++++
OpenCDMi/CapsParser.h | 63 ++++++++++++
OpenCDMi/FrameworkRPC.cpp | 23 ++++-
4 files changed, 284 insertions(+), 3 deletions(-)
create mode 100644 OpenCDMi/CapsParser.cpp
create mode 100644 OpenCDMi/CapsParser.h
diff --git a/OpenCDMi/CMakeLists.txt b/OpenCDMi/CMakeLists.txt
index 406035f8..f8bbe409 100644
--- a/OpenCDMi/CMakeLists.txt
+++ b/OpenCDMi/CMakeLists.txt
@@ -42,6 +42,7 @@ add_library(${MODULE_NAME} SHARED
add_library(${PLUGIN_OCDM_IMPLEMENTATION} SHARED
CENCParser.cpp
FrameworkRPC.cpp
+ CapsParser.cpp
Module.cpp)
add_dependencies(${MODULE_NAME} ${PLUGIN_OCDM_IMPLEMENTATION})
diff --git a/OpenCDMi/CapsParser.cpp b/OpenCDMi/CapsParser.cpp
new file mode 100644
index 00000000..e4a1a75e
--- /dev/null
+++ b/OpenCDMi/CapsParser.cpp
@@ -0,0 +1,200 @@
+/*
+ * If not stated otherwise in this file or this component's LICENSE file the
+ * following copyright and licenses apply:
+ *
+ * Copyright 2020 RDK Management
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CapsParser.h"
+
+#define START_CHAR ")"
+#define END_CHAR ","
+
+#undef LOG
+#define LOG(level, ...) DebugLogging(level, __FUNCTION__, __LINE__, __VA_ARGS__)
+static bool s_bLogTrace = false;
+
+typedef enum eLogLevel_
+{
+ eTrace,
+ eWarning,
+ eError
+} eLogLevel;
+
+void DebugLogging(eLogLevel level, const char* function, int line, const char * format, ...)
+{
+#define LOG_MESSAGE_SIZE 4096
+
+ if(!s_bLogTrace && level < eWarning) {
+ // Do not log
+ return;
+ }
+
+ char logMessage[LOG_MESSAGE_SIZE];
+ // Generate the log string
+ va_list ap;
+ va_start(ap, format);
+ vsnprintf(logMessage, LOG_MESSAGE_SIZE, format, ap);
+ va_end(ap);
+
+ FILE* fpOut = stdout;
+ if(level == eError) {
+ fpOut = stderr;
+ }
+
+ // printf for now.
+ fprintf(fpOut, "CapParser: %s(%d) : %s", function, line, logMessage);
+ fflush(fpOut);
+ return;
+}
+
+//#define ALWAYS_LOG 1
+static void _SetLogLevelTrace(bool bTrace)
+{
+#ifndef ALWAYS_LOG
+ if(s_bLogTrace != bTrace) {
+ LOG(eError, "Setting s_bLogTrace to %d\n", bTrace);
+ s_bLogTrace = bTrace;
+ }
+#else
+ s_bLogTrace = true;
+#endif
+}
+static inline bool _GetLogLevelTrace()
+{
+ return s_bLogTrace;
+}
+
+namespace WPEFramework {
+ namespace Plugin {
+
+ CapsParser::CapsParser()
+ : _lastHash(0)
+ , _mediaTag("original-media-type")
+ , _widthTag("width")
+ , _heightTag("height")
+ {
+ char* envTraceLog = getenv("GSTCAPS_ENABLE_TRACE_LOGGING");
+ if(envTraceLog && strcasecmp(envTraceLog, "true") == 0) {
+ _SetLogLevelTrace(true);
+ LOG(eWarning, "using GSTCAPS_ENABLE_TRACE_LOGGING set TRACE Logging to %d\n", _GetLogLevelTrace());
+ }
+ else {
+ _SetLogLevelTrace(false);
+ }
+ }
+
+ CapsParser::~CapsParser()
+ {
+ }
+
+ void CapsParser::Parse(const uint8_t* info, uint16_t infoLength) /* override */
+ {
+ LOG(eTrace, "Got a new info string size %d (%p)\n", infoLength, info);
+ if(infoLength > 0) {
+ ::string infoStr((char*)info, (size_t)infoLength);
+
+ std::hash<::string> hash_fn;
+ size_t info_hash = hash_fn(infoStr);
+ if(_lastHash != info_hash) {
+ LOG(eTrace, "Got a new info string %s hash = %ld\n", infoStr.c_str(), info_hash);
+ _lastHash = info_hash;
+
+ // Parse the data
+ ::string result = FindMarker(infoStr, _mediaTag);
+ if(!result.empty()) {
+ SetMediaType(result);
+ }
+ else {
+ LOG(eError, "No result for media type\n");
+ }
+ if(_mediaType == CDMi::Video) {
+ result = FindMarker(infoStr, _widthTag);
+ if(!result.empty()) {
+ SetWidth(result);
+ }
+ else {
+ LOG(eError, "No result for width\n");
+ }
+ result = FindMarker(infoStr, _heightTag);
+ if(!result.empty()) {
+ SetHeight(result);
+ }
+ else {
+ LOG(eError, "No result for height\n");
+ }
+ }
+ else {
+ // Audio
+ _width = 0;
+ _height = 0;
+ }
+ }
+ }
+ }
+
+ void CapsParser::SetMediaType(::string& media)
+ {
+ if(media.find("video") != ::string::npos) {
+ _mediaType = CDMi::Video;
+ }
+ else if(media.find("audio") != ::string::npos) {
+ _mediaType = CDMi::Audio;
+ }
+ else {
+ LOG(eError, "Found and unknown media type %s\n", media);
+ _mediaType = CDMi::Unknown;
+ }
+ }
+
+ void CapsParser::SetWidth(::string& width)
+ {
+ LOG(eTrace, "Setting width to %s\n", width.length() > 0 ? width.c_str() : "NULL");
+ if(width.length() > 0) {
+ _width = (uint16_t)stoi(width, NULL, 10);
+ }
+ }
+
+ void CapsParser::SetHeight(::string& height)
+ {
+ LOG(eTrace, "Setting height to %s\n", height.length() > 0 ? height.c_str() : "NULL");
+ if(height.length() > 0) {
+ _height = (uint16_t)stoi(height, NULL, 10);
+ }
+ }
+
+ ::string CapsParser::FindMarker(::string& data, ::string& tag) const
+ {
+ ::string retVal;
+
+ size_t found = data.find(tag);
+ LOG(eTrace, "Found tag <%s> in <%s> at location %d\n",
+ tag.c_str(), data.c_str(), (int)found);
+ if(found != ::string::npos) {
+ // Found the marker
+ // Find the end of the gst caps type identifier
+ size_t start = data.find(START_CHAR, found) + 1; // step over the ")"
+ size_t end = data.find(END_CHAR, start);
+ if(end == ::string::npos) {
+ // Went past the end of the string
+ end = data.length();
+ }
+ retVal = data.substr(start, end - start);
+ LOG(eTrace, "Found substr <%s>\n", retVal.c_str());
+ }
+ return retVal;
+ }
+ }
+}
diff --git a/OpenCDMi/CapsParser.h b/OpenCDMi/CapsParser.h
new file mode 100644
index 00000000..9ad148dc
--- /dev/null
+++ b/OpenCDMi/CapsParser.h
@@ -0,0 +1,63 @@
+/*
+ * If not stated otherwise in this file or this component's LICENSE file the
+ * following copyright and licenses apply:
+ *
+ * Copyright 2020 RDK Management
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <functional>
+
+#include "Module.h"
+
+#include <interfaces/IDRM.h>
+
+namespace WPEFramework {
+ namespace Plugin {
+
+ class CapsParser : public CDMi::ICapsParser {
+ public:
+ CapsParser(const CapsParser&) = delete;
+ CapsParser& operator= (const CapsParser&) = delete;
+
+ CapsParser();
+ ~CapsParser() override;
+
+ public:
+ void Parse(const uint8_t* info, uint16_t infoLength) override;
+
+ const uint16_t GetHeight() const { return _height; }
+ const uint16_t GetWidth() const { return _width; }
+
+ virtual const CDMi::MediaType GetMediaType() const { return _mediaType; }
+
+ private:
+ virtual ::string FindMarker(::string& data, ::string& tag) const;
+ virtual void SetMediaType(::string& media);
+ virtual void SetWidth(::string& width);
+ virtual void SetHeight(::string& height);
+ private:
+ size_t _lastHash;
+ ::string _mediaTag;
+ ::string _widthTag;
+ ::string _heightTag;
+ CDMi::MediaType _mediaType;
+ uint16_t _width;
+ uint16_t _height;
+ };
+ }
+}
diff --git a/OpenCDMi/FrameworkRPC.cpp b/OpenCDMi/FrameworkRPC.cpp
index 37a28d37..6fafd4b2 100644
--- a/OpenCDMi/FrameworkRPC.cpp
+++ b/OpenCDMi/FrameworkRPC.cpp
@@ -23,6 +23,7 @@
#include "Module.h"
#include "CENCParser.h"
+#include "CapsParser.h"
// Get in the definitions required for access to the sepcific
// DRM engines.
@@ -242,14 +243,16 @@ namespace Plugin {
DataExchange& operator=(const DataExchange&) = delete;
public:
- DataExchange(CDMi::IMediaKeySession* mediaKeys, const string& name, const uint32_t defaultSize)
+ DataExchange(CDMi::IMediaKeySession* mediaKeys, const string& name, const uint32_t defaultSize, CDMi::ICapsParser* parser)
: ::OCDM::DataExchange(name, defaultSize)
, Core::Thread(Core::Thread::DefaultStackSize(), _T("DRMSessionThread"))
, _mediaKeys(mediaKeys)
, _mediaKeysExt(dynamic_cast<CDMi::IMediaKeySessionExt*>(mediaKeys))
, _sessionKey(nullptr)
, _sessionKeyLength(0)
+ , _parser(parser)
{
+ ASSERT(parser != nullptr);
Core::Thread::Run();
TRACE(Trace::Information, (_T("Constructing buffer server side: %p - %s"), this, name.c_str()));
}
@@ -280,6 +283,9 @@ namespace Plugin {
uint8_t keyIdLength = 0;
const uint8_t* keyIdData = KeyId(keyIdLength);
+ _parser->Parse(StreamInfo(), StreamInfoLength());
+ _mediaKeys->SetCapsParser(_parser);
+
int cr = _mediaKeys->Decrypt(
_sessionKey,
_sessionKeyLength,
@@ -294,6 +300,7 @@ namespace Plugin {
keyIdLength,
keyIdData,
InitWithLast15());
+
if ((cr == 0) && (clearContentSize != 0)) {
if (clearContentSize != BytesWritten()) {
TRACE(Trace::Information, (_T("Returned clear sample size (%d) differs from encrypted buffer size (%d)"), clearContentSize, BytesWritten()));
@@ -320,6 +327,7 @@ namespace Plugin {
CDMi::IMediaKeySessionExt* _mediaKeysExt;
uint8_t* _sessionKey;
uint32_t _sessionKeyLength;
+ CDMi::ICapsParser* _parser;
};
// IMediaKeys defines the MediaKeys interface.
@@ -446,6 +454,7 @@ namespace Plugin {
, _sink(this, callback)
, _buffer(nullptr)
, _cencData(*sessionData)
+ , _parser()
{
ASSERT(parent != nullptr);
ASSERT(sessionData != nullptr);
@@ -482,6 +491,8 @@ namespace Plugin {
TRACE(Trace::Information, (_T("Constructed the Session Server side: %p"), this));
_mediaKeySession->Run(&_sink);
TRACE(Trace::Information, (_T("Constructed the Session Server side: %p"), this));
+
+ _mediaKeySession->SetCapsParser(&_parser);
}
#ifdef __WINDOWS__
#pragma warning(default : 4355)
@@ -489,6 +500,7 @@ namespace Plugin {
virtual ~SessionImplementation()
{
+ _mediaKeySession->SetCapsParser(nullptr);
TRACE(Trace::Information, (_T("Destructing the Session Server side: %p"), this));
// this needs to be done in a thread safe way. Leave it up to
@@ -538,7 +550,7 @@ namespace Plugin {
if (_parent._administrator.AquireBuffer(bufferID) == true)
{
- _buffer = new DataExchange(_mediaKeySession, bufferID, _parent.DefaultSize());
+ _buffer = new DataExchange(_mediaKeySession, bufferID, _parent.DefaultSize(), &_parser);
_adminLock.Unlock();
TRACE(Trace::Information, ("Server::Session::CreateSessionBuffer(%s,%s,%s) => %p", _keySystem.c_str(), _sessionId.c_str(), BufferId().c_str(), this));
} else {
@@ -607,6 +619,11 @@ namespace Plugin {
_mediaKeySession->ResetOutputProtection();
}
+ virtual void SetParameter(const std::string& name, const std::string& value) override {
+ TRACE(Trace::Information, (_T("SetParameter! %p"), this));
+ _mediaKeySession->SetParameter(name, value);
+ }
+
virtual void Revoke(OCDM::ISession::ICallback* callback) override
{
_sink.Revoke(callback);
@@ -652,7 +669,6 @@ namespace Plugin {
INTERFACE_RELAY(::OCDM::ISessionExt, _mediaKeySessionExt)
END_INTERFACE_MAP
- private:
private:
AccessorOCDM& _parent;
mutable Core::CriticalSection _adminLock;
@@ -664,6 +680,7 @@ namespace Plugin {
Core::Sink<Sink> _sink;
DataExchange* _buffer;
CommonEncryptionData _cencData;
+ CapsParser _parser;
};
public:
--
2.32.1 (Apple Git-133)