Skip to content

Commit

Permalink
Avoid warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jul 31, 2024
1 parent 227976c commit b28d332
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 135 deletions.
1 change: 1 addition & 0 deletions interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ file(GLOB INTERFACES_HEADERS ${INTERFACES_PATTERNS})
ProxyStubGenerator(INPUT "${INTERFACES_HEADERS}" OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/generated" INCLUDE_PATH ${GENERATOR_SEARCH_PATH})

file(GLOB JSON_HEADERS json/*.h)
list(APPEND INTERFACES_HEADERS DRMHelper.h)
list(APPEND INTERFACES_HEADERS Portability.h)
list(APPEND INTERFACES_HEADERS Module.h)

Expand Down
144 changes: 144 additions & 0 deletions interfaces/DRMHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2021 Metrological
*
* 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.
*/
/*
* Metrological has done changes to the original interface definition
* from Fraunhofer FOKUS
*/
/*
* Copyright 2014 Fraunhofer FOKUS
*
* 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

class BufferReader {
private:
BufferReader() = delete;
BufferReader(const BufferReader&) = delete;
BufferReader& operator=(const BufferReader&) = delete;

// Internal implementation of multi-byte reads
template <typename T>
bool Read(T* v)
{
if ((v != nullptr) && (HasBytes(sizeof(T)) == true)) {
T tmp = 0;
for (size_t i = 0; i < sizeof(T); i++) {
tmp <<= 8;
tmp += buf_[pos_++];
}
*v = tmp;
return true;
}
return false;
}

public:
inline BufferReader(const uint8_t* buf, size_t size)
: buf_(buf)
, size_(buf != NULL ? size : 0)
, pos_(0)
{
}
inline ~BufferReader() = default;

public:
inline bool HasBytes(size_t count) const { return pos_ + count <= size_; }
inline bool IsEOF() const { return pos_ >= size_; }
inline const uint8_t* data() const { return buf_; }
inline size_t size() const { return size_; }
inline size_t pos() const { return pos_; }

// Read a value from the stream, performing endian correction,
// and advance the stream pointer.
inline bool Read1(uint8_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read2(uint16_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read2s(int16_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read4(uint32_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read4s(int32_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read8(uint64_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read8s(int64_t* v) WARNING_RESULT_NOT_USED { return Read(v); }

inline bool ReadString(std::string* str, size_t count) WARNING_RESULT_NOT_USED
{
if ((str != nullptr) && (HasBytes(count) == true)) {
str->assign(buf_ + pos_, buf_ + pos_ + count);
pos_ += count;
return true;
}
return false;
}
inline bool ReadVec(std::vector<uint8_t>* vec, size_t count) WARNING_RESULT_NOT_USED
{
if ((vec != nullptr) && (HasBytes(count) == true)) {
vec->clear();
vec->insert(vec->end(), buf_ + pos_, buf_ + pos_ + count);
pos_ += count;
return true;
}
return false;
}

// These variants read a 4-byte integer of the corresponding signedness and
// store it in the 8-byte return type.
inline bool Read4Into8(uint64_t* v) WARNING_RESULT_NOT_USED
{
uint32_t tmp;
if ((v != nullptr) && (Read4(&tmp) == true)) {
*v = tmp;
return true;
}
return false;
}
inline bool Read4sInto8s(int64_t* v) WARNING_RESULT_NOT_USED
{
int32_t tmp;
if ((v != nullptr) && (Read4s(&tmp) == true)) {
*v = tmp;
return true;
}
return false;
}

// Advance the stream by this many bytes.
inline bool SkipBytes(size_t bytes) WARNING_RESULT_NOT_USED
{
if (HasBytes(bytes) == true) {
pos_ += bytes;
return true;
}
return false;
}

private:
const uint8_t* buf_;
size_t size_;
size_t pos_;
};
147 changes: 22 additions & 125 deletions interfaces/IDRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#pragma once

// @stubgen:skip
// @stubgen:omit

// For the support of portable data types such as uint8_t.
#include <stdint.h>
Expand All @@ -48,111 +48,7 @@
#include <vector>

#include <interfaces/Portability.h>

class BufferReader {
private:
BufferReader() = delete;
BufferReader(const BufferReader&) = delete;
BufferReader& operator=(const BufferReader&) = delete;

// Internal implementation of multi-byte reads
template <typename T>
bool Read(T* v)
{
if ((v != nullptr) && (HasBytes(sizeof(T)) == true)) {
T tmp = 0;
for (size_t i = 0; i < sizeof(T); i++) {
tmp <<= 8;
tmp += buf_[pos_++];
}
*v = tmp;
return true;
}
return false;
}

public:
inline BufferReader(const uint8_t* buf, size_t size)
: buf_(buf)
, size_(buf != NULL ? size : 0)
, pos_(0)
{
}
inline ~BufferReader() = default;

public:
inline bool HasBytes(size_t count) const { return pos_ + count <= size_; }
inline bool IsEOF() const { return pos_ >= size_; }
inline const uint8_t* data() const { return buf_; }
inline size_t size() const { return size_; }
inline size_t pos() const { return pos_; }

// Read a value from the stream, performing endian correction,
// and advance the stream pointer.
inline bool Read1(uint8_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read2(uint16_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read2s(int16_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read4(uint32_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read4s(int32_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read8(uint64_t* v) WARNING_RESULT_NOT_USED { return Read(v); }
inline bool Read8s(int64_t* v) WARNING_RESULT_NOT_USED { return Read(v); }

inline bool ReadString(std::string* str, size_t count) WARNING_RESULT_NOT_USED
{
if ((str != nullptr) && (HasBytes(count) == true)) {
str->assign(buf_ + pos_, buf_ + pos_ + count);
pos_ += count;
return true;
}
return false;
}
inline bool ReadVec(std::vector<uint8_t>* vec, size_t count) WARNING_RESULT_NOT_USED
{
if ((vec != nullptr) && (HasBytes(count) == true)) {
vec->clear();
vec->insert(vec->end(), buf_ + pos_, buf_ + pos_ + count);
pos_ += count;
return true;
}
return false;
}

// These variants read a 4-byte integer of the corresponding signedness and
// store it in the 8-byte return type.
inline bool Read4Into8(uint64_t* v) WARNING_RESULT_NOT_USED
{
uint32_t tmp;
if ((v != nullptr) && (Read4(&tmp) == true)) {
*v = tmp;
return true;
}
return false;
}
inline bool Read4sInto8s(int64_t* v) WARNING_RESULT_NOT_USED
{
int32_t tmp;
if ((v != nullptr) && (Read4s(&tmp) == true)) {
*v = tmp;
return true;
}
return false;
}

// Advance the stream by this many bytes.
inline bool SkipBytes(size_t bytes) WARNING_RESULT_NOT_USED
{
if (HasBytes(bytes) == true) {
pos_ += bytes;
return true;
}
return false;
}

private:
const uint8_t* buf_;
size_t size_;
size_t pos_;
};
#include <interfaces/DRMHelper.h>

namespace Thunder
{
Expand Down Expand Up @@ -189,7 +85,7 @@ namespace CDMi {
#define MEDIA_KEY_STATUS_KEY_STATUS_PENDING 5
#define MEDIA_KEY_STATUS_KEY_STATUS_MAX KEY_STATUS_PENDING

typedef enum {
enum CDMi_RESULT {
CDMi_SUCCESS = 0,
CDMi_S_FALSE = 1,
CDMi_MORE_DATA_AVAILABLE = 2,
Expand All @@ -207,57 +103,56 @@ typedef enum {
CDMi_SERVER_INVALID_MESSAGE = 0x8004C601,
CDMi_SERVER_SERVICE_SPECIFIC = 0x8004C604,
CDMi_BUSY_CANNOT_INITIALIZE = 0x8004DD00,
} CDMi_RESULT;
};

typedef enum {
enum LicenseType {
Temporary,
PersistentUsageRecord,
PersistentLicense
} LicenseType;
};

typedef enum {
enum LicenseTypeExt {
Invalid = 0,
LimitedDuration,
Standard
} LicenseTypeExt;
};

typedef enum {
enum SessionStateExt {
LicenseAcquisitionState = 0,
InactiveDecryptionState,
ActiveDecryptionState,
InvalidState
} SessionStateExt;
};

typedef enum
{
enum MediaType {
Unknown = 0,
Video,
Audio,
Data
} MediaType;
};

// ISO/IEC 23001-7 defines two Common Encryption Schemes with Full Sample and Subsample modes
typedef enum : uint8_t {
enum EncryptionScheme : uint8_t {
Clear = 0,
AesCtr_Cenc, // AES-CTR mode and Sub-Sample encryption
AesCbc_Cbc1, // AES-CBC mode and Sub-Sample encryption
AesCtr_Cens, // AES-CTR mode and Sub-Sample + patterned encryption
AesCbc_Cbcs // AES-CBC mode and Sub-Sample + patterned encryption + Constant IV
} EncryptionScheme;
};

// CBCS & CENC3.0 pattern is a number of encrypted blocks followed a number of clear
// blocks after which the pattern repeats.
typedef struct {
struct EncryptionPattern {
uint32_t clear_blocks;
uint32_t encrypted_blocks;
} EncryptionPattern;
};

typedef struct {
struct SubSampleInfo {
uint16_t clear_bytes;
uint32_t encrypted_bytes;
} SubSampleInfo;
};

typedef struct {
struct SampleInfo {
EncryptionScheme scheme; // Encryption scheme used in this sample
EncryptionPattern pattern; // Encryption Pattern used in this sample
uint8_t* iv; // Initialization vector(IV) to decrypt this sample
Expand All @@ -266,7 +161,7 @@ typedef struct {
uint8_t keyIdLength; // Length of KeyId
uint8_t subSampleCount; // Number or Sub-Samples in this sample
SubSampleInfo* subSample; // SubSample mapping - Repeating pair of Clear bytes and Encrypted Bytes representing each subsample.
} SampleInfo;
};

// IStreamProperties to provide information about the current stream
class IStreamProperties {
Expand Down Expand Up @@ -513,6 +408,7 @@ struct IMediaSessionMetrics {
virtual CDMi_RESULT Metrics (uint32_t& bufferLength, uint8_t buffer[]) const = 0;
};

// @stop
struct ISystemFactory {
virtual ~ISystemFactory() = default;
virtual IMediaKeys* Instance() = 0;
Expand Down Expand Up @@ -654,6 +550,7 @@ class SystemFactoryType : public ISystemFactory {
const std::vector<std::string> _mimes;
IMPLEMENTATION _instance;
};
// @stop

} // namespace CDMi

Expand Down
Loading

0 comments on commit b28d332

Please sign in to comment.