-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mediaplayer): imple mediaPlayerDCA
Signed-off-by: pingkai <[email protected]>
- Loading branch information
1 parent
2e948b8
commit bd9dae7
Showing
7 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Created by moqi on 2020/6/24. | ||
// | ||
#include "SMP_DCAManager.h" | ||
#include "SuperMediaPlayer.h" | ||
#include <utils/CicadaJSON.h> | ||
using namespace std; | ||
using namespace Cicada; | ||
void SMP_DCAObserver::onEvent(int level, const string &content) | ||
{ | ||
CicadaJSONItem item; | ||
item.addValue("name", mName); | ||
item.addValue("obj", to_string((uint64_t) mObj)); | ||
item.addValue("level", level); | ||
item.addValue("content", content); | ||
if (mListener) { | ||
mListener->onEvent(item.printJSON()); | ||
} | ||
} | ||
void SMP_DCAObserver::setListener(mediaPlayerDCAObserverListener *listener) | ||
{ | ||
mListener = listener; | ||
} | ||
void SMP_DCAManager::createObservers() | ||
{ | ||
if (mDemuxerObserver == nullptr && mPlayer.mDemuxerService && mPlayer.mDemuxerService->getDemuxerHandle()) { | ||
mDemuxerObserver = static_cast<unique_ptr<SMP_DCAObserver>>(new SMP_DCAObserver("demuxer", mPlayer.mDemuxerService)); | ||
mDemuxerObserver->setListener(this); | ||
mPlayer.mDemuxerService->getDemuxerHandle()->setDCAObserver(mDemuxerObserver.get()); | ||
} | ||
} | ||
int SMP_DCAManager::invoke(const string &content) | ||
{ | ||
CicadaJSONItem item(content); | ||
string name = item.getString("name"); | ||
if (name == "demuxer" && mDemuxerObserver != nullptr) { | ||
if ((void *) atoll(item.getString("obj").c_str()) == (void *) mPlayer.mDemuxerService) { | ||
assert(mPlayer.mDemuxerService->getDemuxerHandle()); | ||
return mPlayer.mDemuxerService->getDemuxerHandle()->invoke(item.getInt("cmd", -1), item.getString("content")); | ||
} | ||
} | ||
// TODO: error code | ||
return 0; | ||
} | ||
void SMP_DCAManager::onEvent(const string &content) | ||
{ | ||
std::lock_guard<std::mutex> guard(mMutex); | ||
mEventQue.push(content); | ||
} | ||
string SMP_DCAManager::getEvent() | ||
{ | ||
std::lock_guard<std::mutex> guard(mMutex); | ||
if (!mEventQue.empty()) { | ||
string event = std::move(mEventQue.front()); | ||
mEventQue.pop(); | ||
return event; | ||
} | ||
return string(); | ||
} | ||
void SMP_DCAManager::reset() | ||
{ | ||
std::lock_guard<std::mutex> guard(mMutex); | ||
while (!mEventQue.empty()) { | ||
mEventQue.pop(); | ||
} | ||
mDemuxerObserver = nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Created by moqi on 2020/6/24. | ||
// | ||
|
||
#ifndef CICADAMEDIA_SMP_DCAMANAGER_H | ||
#define CICADAMEDIA_SMP_DCAMANAGER_H | ||
|
||
#include <base/IDCA.h> | ||
|
||
#include <memory> | ||
#include <mutex> | ||
#include <queue> | ||
|
||
namespace Cicada { | ||
class SuperMediaPlayer; | ||
|
||
class mediaPlayerDCAObserverListener { | ||
public: | ||
virtual void onEvent(const std::string &content) = 0; | ||
}; | ||
class SMP_DCAObserver : public IDCAObserver { | ||
public: | ||
explicit SMP_DCAObserver(std::string name, void *obj) : mName(std::move(name)), mObj(obj) | ||
{} | ||
void setListener(mediaPlayerDCAObserverListener *listener); | ||
|
||
private: | ||
void onEvent(int level, const std::string &content) override; | ||
|
||
private: | ||
std::string mName{}; | ||
void *mObj{nullptr}; | ||
mediaPlayerDCAObserverListener *mListener{nullptr}; | ||
}; | ||
class SMP_DCAManager : public mediaPlayerDCAObserverListener { | ||
public: | ||
explicit SMP_DCAManager(SuperMediaPlayer &player) : mPlayer(player) | ||
{} | ||
|
||
void createObservers(); | ||
|
||
int invoke(const std::string &content); | ||
|
||
std::string getEvent(); | ||
|
||
void reset(); | ||
|
||
private: | ||
void onEvent(const std::string &content) override; | ||
|
||
private: | ||
SuperMediaPlayer &mPlayer; | ||
std::unique_ptr<SMP_DCAObserver> mDemuxerObserver{nullptr}; | ||
std::queue<std::string> mEventQue; | ||
std::mutex mMutex; | ||
}; | ||
}// namespace Cicada | ||
|
||
|
||
#endif//CICADAMEDIA_SMP_DCAMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters