Skip to content

Commit

Permalink
feat(mediaplayer): use Prototype
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 Jul 20, 2020
1 parent e00d4e4 commit 0bfd9b9
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 16 deletions.
3 changes: 2 additions & 1 deletion mediaPlayer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ set(SOURCE_FILES
mediaPlayerSubTitleListener.h
playerOptions.cpp
playerOptions.h
SMP_DCAManager.cpp)
SMP_DCAManager.cpp
CicadaPlayerPrototype.cpp)
if (TARGET_PLATFORM STREQUAL "Android")
set(SOURCE_FILES ${SOURCE_FILES}
TrafficStats.c
Expand Down
38 changes: 38 additions & 0 deletions mediaPlayer/CicadaPlayerPrototype.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by moqi on 2020/7/20.
//

#include "CicadaPlayerPrototype.h"
#include "SuperMediaPlayer.h"
using namespace Cicada;
CicadaPlayerPrototype *CicadaPlayerPrototype::playerQueue[];
int CicadaPlayerPrototype::_nextSlot;
void CicadaPlayerPrototype::addPrototype(Cicada::CicadaPlayerPrototype *se)
{
playerQueue[_nextSlot++] = se;
}
ICicadaPlayer *CicadaPlayerPrototype::create(const options *opts = nullptr)
{
int score_res = 0;
CicadaPlayerPrototype *playerType = nullptr;

for (int i = 0; i < _nextSlot; ++i) {
int score = playerQueue[i]->probeScore(opts);

if (score > score_res) {
score_res = score;
playerType = playerQueue[i];

if (score >= SUPPORT_MAX) {
break;
}
}
}

if (playerType && score_res > SUPPORT_NOT) {
ICicadaPlayer *player = playerType->clone();
return player;
}

return new SuperMediaPlayer();
}
38 changes: 38 additions & 0 deletions mediaPlayer/CicadaPlayerPrototype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by moqi on 2020/7/20.
//

#ifndef CICADAMEDIA_CICADAPLAYERPROTOTYPE_H
#define CICADAMEDIA_CICADAPLAYERPROTOTYPE_H
#include "ICicadaPlayer.h"
#include <base/options.h>
#include <base/prototype.h>
#include <utils/CicadaType.h>
namespace Cicada {
class CICADA_CPLUS_EXTERN CicadaPlayerPrototype {
static CicadaPlayerPrototype *playerQueue[10];
static int _nextSlot;

public:
virtual ~CicadaPlayerPrototype() = default;

virtual ICicadaPlayer *clone() = 0;

virtual bool is_supported(const options *opts) = 0;

virtual int probeScore(const options *opts)
{
if (is_supported(opts)) {
return SUPPORT_DEFAULT;
}
return 0;
}

static void addPrototype(CicadaPlayerPrototype *se);

static ICicadaPlayer *create(const options *opts);
};
}// namespace Cicada


#endif//CICADAMEDIA_CICADAPLAYERPROTOTYPE_H
8 changes: 3 additions & 5 deletions mediaPlayer/MediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ namespace Cicada {
MediaPlayer *mPlayer = nullptr;
};

MediaPlayer::MediaPlayer()
: MediaPlayer(*(AnalyticsCollectorFactory::Instance()))
MediaPlayer::MediaPlayer(const char *opt) : MediaPlayer(*(AnalyticsCollectorFactory::Instance()), opt)
{
}

MediaPlayer::MediaPlayer(IAnalyticsCollectorFactory &factory)
: mCollectorFactory(factory)
MediaPlayer::MediaPlayer(IAnalyticsCollectorFactory &factory, const char *opt) : mCollectorFactory(factory)
{
playerHandle *handle = CicadaCreatePlayer();
playerHandle *handle = CicadaCreatePlayer("");
mPlayerHandle = (void *) handle;
playerListener listener{nullptr};
listener.userData = this;
Expand Down
4 changes: 2 additions & 2 deletions mediaPlayer/MediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ namespace Cicada {

class MediaPlayer {
public:
MediaPlayer();
explicit MediaPlayer(const char *opt = nullptr);

MediaPlayer(IAnalyticsCollectorFactory &factory);
explicit MediaPlayer(IAnalyticsCollectorFactory &factory, const char *opt = nullptr);

~MediaPlayer();

Expand Down
1 change: 1 addition & 0 deletions mediaPlayer/SuperMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static int MAX_DECODE_ERROR_FRAME = 100;
#define PTS_REVERTING (mVideoPtsRevert != mAudioPtsRevert)

namespace Cicada {
SuperMediaPlayer SuperMediaPlayer::se(1);

static MsgParam dummyMsg{{nullptr}};

Expand Down
22 changes: 20 additions & 2 deletions mediaPlayer/SuperMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace std;
#include <render/audio/IAudioRender.h>
#include <utils/bitStreamParser.h>

#include "CicadaPlayerPrototype.h"
#include <cacheModule/CacheModule.h>
#include <cacheModule/cache/CacheConfig.h>

Expand Down Expand Up @@ -64,8 +65,7 @@ namespace Cicada {
} APP_STATUS;


class SuperMediaPlayer : public ICicadaPlayer,
private PlayerMessageControllerListener {
class SuperMediaPlayer : public ICicadaPlayer, private PlayerMessageControllerListener, private CicadaPlayerPrototype {

friend class SuperMediaPlayerDataSourceListener;
friend class SMP_DCAManager;
Expand Down Expand Up @@ -375,6 +375,24 @@ namespace Cicada {

static IVideoRender::Flip convertMirrorMode(MirrorMode mode);

private:
explicit SuperMediaPlayer(int dummy)
: mMessageControl(*this), mAudioRenderCB(*this), mApsaraThread([this]() -> int { return this->mainService(); }, LOG_TAG),
mSourceListener(*this), mDcaManager(*this)
{
addPrototype(this);
}
ICicadaPlayer *clone() override
{
return new SuperMediaPlayer();
};
bool is_supported(const options *opts) override
{
return true;
}

static SuperMediaPlayer se;


private:
IDataSource *mDataSource{nullptr};
Expand Down
9 changes: 4 additions & 5 deletions mediaPlayer/media_player_api.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "media_player_api.h"
#include "CicadaPlayerPrototype.h"
#include <complex>
#include <utils/af_string.h>
#include <utils/frame_work_log.h>
#include "media_player_api.h"
#include "ICicadaPlayer.h"
#include "SuperMediaPlayer.h"

using namespace Cicada;

Expand All @@ -13,10 +12,10 @@ typedef struct playerHandle_t {

#define GET_PLAYER ICicadaPlayer *player = pHandle->pPlayer

playerHandle *CicadaCreatePlayer()
playerHandle *CicadaCreatePlayer(const char *opts)
{
playerHandle *pHandle = new playerHandle();
pHandle->pPlayer = new SuperMediaPlayer();
pHandle->pPlayer = CicadaPlayerPrototype::create(nullptr);
return pHandle;
}

Expand Down
2 changes: 1 addition & 1 deletion mediaPlayer/media_player_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef struct playerHandle_t playerHandle;
/*
*create the Cicada player
*/
playerHandle *CicadaCreatePlayer();
playerHandle *CicadaCreatePlayer(const char *opts);

/*
* release Cicada player
Expand Down

0 comments on commit 0bfd9b9

Please sign in to comment.