diff --git a/mediaPlayer/CMakeLists.txt b/mediaPlayer/CMakeLists.txt
index 44cf5f11a..1306d3ad6 100644
--- a/mediaPlayer/CMakeLists.txt
+++ b/mediaPlayer/CMakeLists.txt
@@ -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
diff --git a/mediaPlayer/CicadaPlayerPrototype.cpp b/mediaPlayer/CicadaPlayerPrototype.cpp
new file mode 100644
index 000000000..1356a68ee
--- /dev/null
+++ b/mediaPlayer/CicadaPlayerPrototype.cpp
@@ -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();
+}
diff --git a/mediaPlayer/CicadaPlayerPrototype.h b/mediaPlayer/CicadaPlayerPrototype.h
new file mode 100644
index 000000000..c819a33e5
--- /dev/null
+++ b/mediaPlayer/CicadaPlayerPrototype.h
@@ -0,0 +1,38 @@
+//
+// Created by moqi on 2020/7/20.
+//
+
+#ifndef CICADAMEDIA_CICADAPLAYERPROTOTYPE_H
+#define CICADAMEDIA_CICADAPLAYERPROTOTYPE_H
+#include "ICicadaPlayer.h"
+#include
+#include
+#include
+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
diff --git a/mediaPlayer/MediaPlayer.cpp b/mediaPlayer/MediaPlayer.cpp
index ed211055e..3a26cd82b 100644
--- a/mediaPlayer/MediaPlayer.cpp
+++ b/mediaPlayer/MediaPlayer.cpp
@@ -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;
diff --git a/mediaPlayer/MediaPlayer.h b/mediaPlayer/MediaPlayer.h
index 066537860..695970c76 100644
--- a/mediaPlayer/MediaPlayer.h
+++ b/mediaPlayer/MediaPlayer.h
@@ -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();
diff --git a/mediaPlayer/SuperMediaPlayer.cpp b/mediaPlayer/SuperMediaPlayer.cpp
index de97115b9..d2dd5ac32 100644
--- a/mediaPlayer/SuperMediaPlayer.cpp
+++ b/mediaPlayer/SuperMediaPlayer.cpp
@@ -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}};
diff --git a/mediaPlayer/SuperMediaPlayer.h b/mediaPlayer/SuperMediaPlayer.h
index 5ef9590f2..612af73e1 100644
--- a/mediaPlayer/SuperMediaPlayer.h
+++ b/mediaPlayer/SuperMediaPlayer.h
@@ -28,6 +28,7 @@ using namespace std;
#include
#include
+#include "CicadaPlayerPrototype.h"
#include
#include
@@ -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;
@@ -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};
diff --git a/mediaPlayer/media_player_api.cpp b/mediaPlayer/media_player_api.cpp
index fa8f9e254..e47c0f11a 100644
--- a/mediaPlayer/media_player_api.cpp
+++ b/mediaPlayer/media_player_api.cpp
@@ -1,9 +1,8 @@
+#include "media_player_api.h"
+#include "CicadaPlayerPrototype.h"
#include
#include
#include
-#include "media_player_api.h"
-#include "ICicadaPlayer.h"
-#include "SuperMediaPlayer.h"
using namespace Cicada;
@@ -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;
}
diff --git a/mediaPlayer/media_player_api.h b/mediaPlayer/media_player_api.h
index a675e1865..347fc16b6 100644
--- a/mediaPlayer/media_player_api.h
+++ b/mediaPlayer/media_player_api.h
@@ -13,7 +13,7 @@ typedef struct playerHandle_t playerHandle;
/*
*create the Cicada player
*/
-playerHandle *CicadaCreatePlayer();
+playerHandle *CicadaCreatePlayer(const char *opts);
/*
* release Cicada player