Skip to content

Commit

Permalink
Create MF session & improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDaChicken committed Oct 21, 2023
1 parent 6168bb2 commit 52100ab
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 287 deletions.
2 changes: 2 additions & 0 deletions lib/mfcdm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ project(mfcdm_library)

add_library(mfcdm_library STATIC
mfcdm/MediaFoundationCdm.h
mfcdm/MediaFoundationCdmConfig.h
mfcdm/MediaFoundationCdmTypes.h
mfcdm/MediaFoundationCdm.cpp
mfcdm/MediaFoundationCdmFactory.cpp
mfcdm/MediaFoundationCdmSession.cpp
Expand Down
38 changes: 20 additions & 18 deletions lib/mfcdm/mfcdm/MediaFoundationCdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

#include "MediaFoundationCdm.h"

#include "Log.h"
#include "MediaFoundationCdmFactory.h"
#include "MediaFoundationCdmModule.h"
#include "MediaFoundationCdmSession.h"
#include "Log.h"

#include "utils/PMPHostWrapper.h"

MediaFoundationCdm::MediaFoundationCdm() = default;
MediaFoundationCdm::~MediaFoundationCdm() = default;

bool MediaFoundationCdm::Initialize(const std::string &keySystem,
const std::string &basePath,
const media::CdmConfig &cdmConfig,
media::CdmAdapterClient* client)
bool MediaFoundationCdm::Initialize(const MediaFoundationCdmConfig& cdmConfig,
std::string_view keySystem,
std::string_view basePath)
{
bool ret = true;

Expand Down Expand Up @@ -52,8 +52,6 @@ bool MediaFoundationCdm::Initialize(const std::string &keySystem,
Log(MFCDM::MFLOG_DEBUG, "MF CDM created.");

SetupPMPServer();

m_client = client;
return true;
}

Expand Down Expand Up @@ -82,32 +80,36 @@ void MediaFoundationCdm::SetupPMPServer() const
m_module->SetPMPHostApp(spIMFPMPHostApp.get());
}

void MediaFoundationCdm::SetServerCertificate(uint32_t promise_id,
const uint8_t* serverCertificateData,
bool MediaFoundationCdm::SetServerCertificate(const uint8_t* serverCertificateData,
uint32_t serverCertificateDataSize) const
{
m_module->SetServerCertificate(serverCertificateData, serverCertificateDataSize);
return true;
}

void MediaFoundationCdm::CreateSessionAndGenerateRequest(uint32_t promise_id, cdm::SessionType sessionType,
cdm::InitDataType initDataType, const uint8_t *init_data,
uint32_t init_data_size)
bool MediaFoundationCdm::CreateSessionAndGenerateRequest(SessionType sessionType,
InitDataType initDataType,
const std::vector<uint8_t>& initData,
SessionClient* client)
{
auto session = std::make_unique<MediaFoundationCdmSession>();
auto session = std::make_unique<MediaFoundationCdmSession>(client);

if (!session->Initialize(sessionType, m_module.get()))
if (!session->Initialize(m_module.get(), sessionType))
{
Log(MFCDM::MFLOG_ERROR, "Failed to create session.");
return;
return false;
}

int session_token = next_session_token_++;
session->GenerateRequest(initDataType, init_data, init_data_size);
if (!session->GenerateRequest(initDataType, initData))
{
return false;
}

m_cdm_sessions.emplace(session_token, std::move(session));
return true;
}

void MediaFoundationCdm::LoadSession(cdm::SessionType session_type,
void MediaFoundationCdm::LoadSession(SessionType session_type,
const std::string &session_id)
{

Expand Down
37 changes: 15 additions & 22 deletions lib/mfcdm/mfcdm/MediaFoundationCdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,45 @@
#pragma once

#include "MediaFoundationSession.h"
#include "MediaFoundationCdmConfig.h"
#include "MediaFoundationCdmTypes.h"

#include <string>
#include <map>
#include <memory>

#include "cdm/media/base/cdm_config.h"
#include "cdm/media/cdm/api/content_decryption_module.h"
#include "cdm/media/cdm/cdm_adapter.h"
#include <vector>

class MediaFoundationCdmSession;
class MediaFoundationCdmFactory;
class MediaFoundationCdmModule;

class MediaFoundationCdm {
public:
MediaFoundationCdm();
~MediaFoundationCdm();

bool IsInitialized() const { return m_module != nullptr; }

bool Initialize(const std::string& keySystem,
const std::string &basePath,
const media::CdmConfig &cdmConfig,
media::CdmAdapterClient* client);
bool Initialize(const MediaFoundationCdmConfig& cdmConfig,
std::string_view keySystem,
std::string_view basePath);

void SetServerCertificate(uint32_t promise_id,
const uint8_t* serverCertificateData,
bool SetServerCertificate(const uint8_t* serverCertificateData,
uint32_t serverCertificateDataSize) const;

void CreateSessionAndGenerateRequest(uint32_t promise_id,
cdm::SessionType sessionType,
cdm::InitDataType initDataType,
const uint8_t* init_data,
uint32_t init_data_size);

void LoadSession(cdm::SessionType session_type, const std::string& session_id);
bool CreateSessionAndGenerateRequest(SessionType sessionType,
InitDataType initDataType,
const std::vector<uint8_t>& initData,
SessionClient* client);

void LoadSession(SessionType session_type, const std::string& session_id);
void UpdateSession(const std::string& session_id);

private:
void SetupPMPServer() const;

MediaFoundationSession m_session;

std::unique_ptr<MediaFoundationCdmModule> m_module{nullptr};
std::unique_ptr<MediaFoundationCdmModule> m_module;

int next_session_token_{0};
std::map<int, std::unique_ptr<MediaFoundationCdmSession>> m_cdm_sessions;

media::CdmAdapterClient* m_client{nullptr};
};
Loading

0 comments on commit 52100ab

Please sign in to comment.