Skip to content

Commit

Permalink
feat(mediaplayer): imple mediaPlayerDCA
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai authored and I-m-SuperMan committed Jun 28, 2020
1 parent 2e948b8 commit bd9dae7
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 12 deletions.
3 changes: 2 additions & 1 deletion mediaPlayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ set(SOURCE_FILES
mediaPlayerSubTitleListener.cpp
mediaPlayerSubTitleListener.h
playerOptions.cpp
playerOptions.h)
playerOptions.h
SMP_DCAManager.cpp)
if (TARGET_PLATFORM STREQUAL "Android")
set(SOURCE_FILES ${SOURCE_FILES}
TrafficStats.c
Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/EventCodeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ void EventCodeMap::init()
codeMap.insert(pair<int, int>(MEDIA_PLAYER_EVENT_NETWORK_RETRY_SUCCESS, 113));
codeMap.insert(pair<int, int>(MEDIA_PLAYER_EVENT_SUBTITLE_SELECT_ERROR, 114));
codeMap.insert(pair<int, int>(MEDIA_PLAYER_EVENT_DECODER_RECOVER_SIZE, 115));
codeMap.insert(pair<int, int>(MEDIA_PLAYER_EVENT_DIRECT_COMPONENT_MSG, 116));
}
67 changes: 67 additions & 0 deletions mediaPlayer/SMP_DCAManager.cpp
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;
}
60 changes: 60 additions & 0 deletions mediaPlayer/SMP_DCAManager.h
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
13 changes: 9 additions & 4 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ namespace Cicada {
const int64_t SuperMediaPlayer::SEEK_ACCURATE_MAX = 11 * 1000 * 1000;

SuperMediaPlayer::SuperMediaPlayer()
: mMessageControl(*this),
mAudioRenderCB(*this),
mApsaraThread([this]() -> int { return this->mainService(); }, LOG_TAG),
mSourceListener(*this)
: mMessageControl(*this), mAudioRenderCB(*this), mApsaraThread([this]() -> int { return this->mainService(); }, LOG_TAG),
mSourceListener(*this), mDcaManager(*this)
{
AF_LOGD("SuperMediaPlayer()");
mPNotifier = new PlayerNotifier();
Expand Down Expand Up @@ -1085,6 +1083,11 @@ namespace Cicada {
{
int64_t curTime = af_gettime_relative();
mUtil.notifyPlayerLoop(curTime);
string event = mDcaManager.getEvent();
while (!event.empty()) {
mPNotifier->NotifyEvent(MEDIA_PLAYER_EVENT_DIRECT_COMPONENT_MSG, event.c_str());
event = mDcaManager.getEvent();
}

if (mMessageControl.empty() || (0 == mMessageControl.processMsg())) {
ProcessVideoLoop();
Expand Down Expand Up @@ -3301,6 +3304,7 @@ namespace Cicada {
mBSSeekCb = nullptr;
mBSCbArg = nullptr;
mUtil.reset();
mDcaManager.reset();
mVideoInterlaced = InterlacedType_UNKNOWN;
mVideoParserTimes = 0;
mVideoPtsRevert = mAudioPtsRevert = false;
Expand Down Expand Up @@ -3451,6 +3455,7 @@ namespace Cicada {
mDataSource->Get_config(config);
mDemuxerService->getDemuxerHandle()->setDataSourceConfig(config);
}
mDcaManager.createObservers();
}

//step2: Demuxer init and getstream index
Expand Down
11 changes: 7 additions & 4 deletions mediaPlayer/SuperMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ using namespace std;
#include <deque>
#include "system_refer_clock.h"

#include "SMP_DCAManager.h"
#include "SuperMediaPlayerDataSourceListener.h"
#include "codec/videoDecoderFactory.h"
#include "hls_adaptive_manager.h"
#include "player_types.h"
#include "player_notifier.h"
#include "player_types.h"
#include "render/video/IVideoRender.h"
#include <filter/IAudioFilter.h>
#include <utils/bitStreamParser.h>
#include <queue>
#include <render/audio/IAudioRender.h>
#include "codec/videoDecoderFactory.h"
#include "SuperMediaPlayerDataSourceListener.h"
#include <utils/bitStreamParser.h>

#include <cacheModule/CacheModule.h>
#include <cacheModule/cache/CacheConfig.h>
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace Cicada {
private PlayerMessageControllerListener {

friend class SuperMediaPlayerDataSourceListener;
friend class SMP_DCAManager;

public:

Expand Down Expand Up @@ -476,6 +478,7 @@ namespace Cicada {
MediaPlayerUtil mUtil;

SuperMediaPlayerDataSourceListener mSourceListener;
SMP_DCAManager mDcaManager;

std::unique_ptr<IAFPacket> mVideoPacket{};
std::unique_ptr<IAFPacket> mAudioPacket{};
Expand Down
8 changes: 5 additions & 3 deletions mediaPlayer/media_player_error_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace Cicada{
MEDIA_PLAYER_ERROR_UNKNOWN = 0x30000000 - 1,
};

enum MediaPlayerEventType {
enum MediaPlayerEventType {
MEDIA_PLAYER_EVENT_START = 0,
MEDIA_PLAYER_EVENT_SW_VIDEO_DECODER = MEDIA_PLAYER_EVENT_START,
MEDIA_PLAYER_EVENT_AUDIO_CODEC_NOT_SUPPORT,
Expand All @@ -80,8 +80,10 @@ namespace Cicada{
MEDIA_PLAYER_EVENT_DEMUXER_STARTUP_INFO,

MEDIA_PLAYER_EVENT_SUBTITLE_SELECT_ERROR,
MEDIA_PLAYER_EVENT_DECODER_RECOVER_SIZE,
};
MEDIA_PLAYER_EVENT_DECODER_RECOVER_SIZE,

MEDIA_PLAYER_EVENT_DIRECT_COMPONENT_MSG,
};
}

#endif //MEDIA_PLAYER_ERROR_DEF_H

0 comments on commit bd9dae7

Please sign in to comment.