MediaPlayer2: remove factory
Test: MediaPlayer2 plays
Bug: 63934228
Change-Id: Idc6fb33b4bb69bb65dca34d2b8fc9e3595a05774
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index 28684da..1377005 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -318,9 +318,7 @@
srcs: [
"JAudioTrack.cpp",
- "MediaPlayer2Factory.cpp",
"MediaPlayer2Manager.cpp",
- "TestPlayerStub.cpp",
"mediaplayer2.cpp",
],
diff --git a/media/libmedia/MediaPlayer2Factory.cpp b/media/libmedia/MediaPlayer2Factory.cpp
deleted file mode 100644
index ac115f6..0000000
--- a/media/libmedia/MediaPlayer2Factory.cpp
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
-**
-** Copyright 2017, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "MediaPlayer2Factory"
-#include <utils/Log.h>
-
-#include <cutils/properties.h>
-#include <media/DataSource.h>
-#include <media/MediaPlayer2Engine.h>
-#include <media/stagefright/foundation/ADebug.h>
-#include <utils/Errors.h>
-#include <utils/misc.h>
-
-#include "MediaPlayer2Factory.h"
-
-#include "TestPlayerStub.h"
-#include "nuplayer2/NuPlayer2Driver.h"
-
-namespace android {
-
-Mutex MediaPlayer2Factory::sLock;
-MediaPlayer2Factory::tFactoryMap *MediaPlayer2Factory::sFactoryMap;
-bool MediaPlayer2Factory::sInitComplete = false;
-
-// static
-bool MediaPlayer2Factory::ensureInit_l() {
- if (sFactoryMap == NULL) {
- sFactoryMap = new (std::nothrow) tFactoryMap();
- }
- return (sFactoryMap != NULL);
-}
-
-status_t MediaPlayer2Factory::registerFactory_l(IFactory* factory,
- player2_type type) {
- if (NULL == factory) {
- ALOGE("Failed to register MediaPlayer2Factory of type %d, factory is"
- " NULL.", type);
- return BAD_VALUE;
- }
-
- if (!ensureInit_l()) {
- return NO_INIT;
- }
-
- if (sFactoryMap->indexOfKey(type) >= 0) {
- ALOGE("Failed to register MediaPlayer2Factory of type %d, type is"
- " already registered.", type);
- return ALREADY_EXISTS;
- }
-
- if (sFactoryMap->add(type, factory) < 0) {
- ALOGE("Failed to register MediaPlayer2Factory of type %d, failed to add"
- " to map.", type);
- return UNKNOWN_ERROR;
- }
-
- return OK;
-}
-
-static player2_type getDefaultPlayerType() {
- return PLAYER2_NU_PLAYER2;
-}
-
-#define GET_PLAYER_TYPE_IMPL(a...) \
- Mutex::Autolock lock_(&sLock); \
- \
- player2_type ret = PLAYER2_STAGEFRIGHT_PLAYER; \
- float bestScore = 0.0; \
- \
- if (!ensureInit_l()) { \
- return ret; \
- } \
- \
- for (size_t i = 0; i < sFactoryMap->size(); ++i) { \
- \
- IFactory* v = sFactoryMap->valueAt(i); \
- float thisScore; \
- CHECK(v != NULL); \
- thisScore = v->scoreFactory(a, bestScore); \
- if (thisScore > bestScore) { \
- ret = sFactoryMap->keyAt(i); \
- bestScore = thisScore; \
- } \
- } \
- \
- if (0.0 == bestScore) { \
- ret = getDefaultPlayerType(); \
- } \
- \
- return ret;
-
-player2_type MediaPlayer2Factory::getPlayerType(const sp<MediaPlayer2Engine>& client,
- const char* url) {
- GET_PLAYER_TYPE_IMPL(client, url);
-}
-
-player2_type MediaPlayer2Factory::getPlayerType(const sp<MediaPlayer2Engine>& client,
- int fd,
- int64_t offset,
- int64_t length) {
- GET_PLAYER_TYPE_IMPL(client, fd, offset, length);
-}
-
-player2_type MediaPlayer2Factory::getPlayerType(const sp<MediaPlayer2Engine>& client,
- const sp<IStreamSource> &source) {
- GET_PLAYER_TYPE_IMPL(client, source);
-}
-
-player2_type MediaPlayer2Factory::getPlayerType(const sp<MediaPlayer2Engine>& client,
- const sp<DataSource> &source) {
- GET_PLAYER_TYPE_IMPL(client, source);
-}
-
-#undef GET_PLAYER_TYPE_IMPL
-
-sp<MediaPlayer2Base> MediaPlayer2Factory::createPlayer(
- player2_type playerType,
- const wp<MediaPlayer2Engine> &client,
- MediaPlayer2Base::NotifyCallback notifyFunc,
- pid_t pid) {
- sp<MediaPlayer2Base> p;
- IFactory* factory;
- status_t init_result;
- Mutex::Autolock lock_(&sLock);
-
- if (!ensureInit_l()) {
- return NULL;
- }
-
- if (sFactoryMap->indexOfKey(playerType) < 0) {
- ALOGE("Failed to create player object of type %d, no registered"
- " factory", playerType);
- return p;
- }
-
- factory = sFactoryMap->valueFor(playerType);
- CHECK(NULL != factory);
- p = factory->createPlayer(pid);
-
- if (p == NULL) {
- ALOGE("Failed to create player object of type %d, create failed",
- playerType);
- return p;
- }
-
- init_result = p->initCheck();
- if (init_result == NO_ERROR) {
- p->setNotifyCallback(client, notifyFunc);
- } else {
- ALOGE("Failed to create player object of type %d, initCheck failed"
- " (res = %d)", playerType, init_result);
- p.clear();
- }
-
- return p;
-}
-
-/*****************************************************************************
- * *
- * Built-In Factory Implementations *
- * *
- *****************************************************************************/
-
-class NuPlayer2Factory : public MediaPlayer2Factory::IFactory {
- public:
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const char* url,
- float curScore) {
- static const float kOurScore = 0.8;
-
- if (kOurScore <= curScore) {
- return 0.0;
- }
-
- if (!strncasecmp("http://", url, 7)
- || !strncasecmp("https://", url, 8)
- || !strncasecmp("file://", url, 7)) {
- size_t len = strlen(url);
- if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
- return kOurScore;
- }
-
- if (strstr(url,"m3u8")) {
- return kOurScore;
- }
-
- if ((len >= 4 && !strcasecmp(".sdp", &url[len - 4])) || strstr(url, ".sdp?")) {
- return kOurScore;
- }
- }
-
- if (!strncasecmp("rtsp://", url, 7)) {
- return kOurScore;
- }
-
- return 0.0;
- }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const sp<IStreamSource>& /*source*/,
- float /*curScore*/) {
- return 1.0;
- }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const sp<DataSource>& /*source*/,
- float /*curScore*/) {
- // Only NuPlayer2 supports setting a DataSource source directly.
- return 1.0;
- }
-
- virtual sp<MediaPlayer2Base> createPlayer(pid_t pid) {
- ALOGV(" create NuPlayer2");
- return new NuPlayer2Driver(pid);
- }
-};
-
-class TestPlayerFactory : public MediaPlayer2Factory::IFactory {
- public:
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const char* url,
- float /*curScore*/) {
- if (TestPlayerStub::canBeUsed(url)) {
- return 1.0;
- }
-
- return 0.0;
- }
-
- virtual sp<MediaPlayer2Base> createPlayer(pid_t /* pid */) {
- ALOGV("Create Test Player stub");
- return new TestPlayerStub();
- }
-};
-
-void MediaPlayer2Factory::registerBuiltinFactories() {
- Mutex::Autolock lock_(&sLock);
-
- if (sInitComplete) {
- return;
- }
-
- IFactory* factory = new NuPlayer2Factory();
- if (registerFactory_l(factory, PLAYER2_NU_PLAYER2) != OK) {
- delete factory;
- }
- factory = new TestPlayerFactory();
- if (registerFactory_l(factory, PLAYER2_TEST_PLAYER) != OK) {
- delete factory;
- }
-
- sInitComplete = true;
-}
-
-} // namespace android
diff --git a/media/libmedia/MediaPlayer2Factory.h b/media/libmedia/MediaPlayer2Factory.h
deleted file mode 100644
index 416d241..0000000
--- a/media/libmedia/MediaPlayer2Factory.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
-**
-** Copyright 2017, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-** http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#ifndef ANDROID_MEDIAPLAYER2FACTORY_H
-#define ANDROID_MEDIAPLAYER2FACTORY_H
-
-#include <media/MediaPlayer2Interface.h>
-#include <media/stagefright/foundation/ABase.h>
-
-namespace android {
-
-class MediaPlayer2Factory {
- public:
- class IFactory {
- public:
- virtual ~IFactory() { }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const char* /*url*/,
- float /*curScore*/) { return 0.0; }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- int /*fd*/,
- int64_t /*offset*/,
- int64_t /*length*/,
- float /*curScore*/) { return 0.0; }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const sp<IStreamSource> &/*source*/,
- float /*curScore*/) { return 0.0; }
-
- virtual float scoreFactory(const sp<MediaPlayer2Engine>& /*client*/,
- const sp<DataSource> &/*source*/,
- float /*curScore*/) { return 0.0; }
-
- virtual sp<MediaPlayer2Base> createPlayer(pid_t pid) = 0;
- };
-
- static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
- const char* url);
- static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
- int fd,
- int64_t offset,
- int64_t length);
- static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
- const sp<IStreamSource> &source);
- static player2_type getPlayerType(const sp<MediaPlayer2Engine>& client,
- const sp<DataSource> &source);
-
- static sp<MediaPlayer2Base> createPlayer(player2_type playerType,
- const wp<MediaPlayer2Engine> &client,
- MediaPlayer2Base::NotifyCallback notifyFunc,
- pid_t pid);
-
- static void registerBuiltinFactories();
-
- private:
- typedef KeyedVector<player2_type, IFactory*> tFactoryMap;
-
- MediaPlayer2Factory() { }
-
- static bool ensureInit_l();
-
- static status_t registerFactory_l(IFactory* factory,
- player2_type type);
-
- static Mutex sLock;
- static tFactoryMap *sFactoryMap;
- static bool sInitComplete;
-
- DISALLOW_EVIL_CONSTRUCTORS(MediaPlayer2Factory);
-};
-
-} // namespace android
-#endif // ANDROID_MEDIAPLAYER2FACTORY_H
diff --git a/media/libmedia/MediaPlayer2Manager.cpp b/media/libmedia/MediaPlayer2Manager.cpp
index c119750..76b51f3 100644
--- a/media/libmedia/MediaPlayer2Manager.cpp
+++ b/media/libmedia/MediaPlayer2Manager.cpp
@@ -68,8 +68,8 @@
#include <private/android_filesystem_config.h>
+#include <nuplayer2/NuPlayer2Driver.h>
#include "MediaPlayer2Manager.h"
-#include "MediaPlayer2Factory.h"
static const int kDumpLockRetries = 50;
static const int kDumpLockSleepUs = 20000;
@@ -269,8 +269,6 @@
mPid = IPCThreadState::self()->getCallingPid();
mUid = IPCThreadState::self()->getCallingUid();
mNextConnId = 1;
-
- MediaPlayer2Factory::registerBuiltinFactories();
}
MediaPlayer2Manager::~MediaPlayer2Manager() {
@@ -562,16 +560,17 @@
IPCThreadState::self()->flushCommands();
}
-sp<MediaPlayer2Base> MediaPlayer2Manager::Client::createPlayer(player2_type playerType)
-{
- // determine if we have the right player type
+sp<MediaPlayer2Base> MediaPlayer2Manager::Client::createPlayer() {
sp<MediaPlayer2Base> p = getPlayer();
- if ((p != NULL) && (p->playerType() != playerType)) {
- ALOGV("delete player");
- p.clear();
- }
if (p == NULL) {
- p = MediaPlayer2Factory::createPlayer(playerType, this, notify, mPid);
+ p = new NuPlayer2Driver(mPid);
+ status_t init_result = p->initCheck();
+ if (init_result == NO_ERROR) {
+ p->setNotifyCallback(this, notify);
+ } else {
+ ALOGE("Failed to create player, initCheck failed(res = %d)", init_result);
+ p.clear();
+ }
}
if (p != NULL) {
@@ -592,13 +591,8 @@
}
}
-sp<MediaPlayer2Base> MediaPlayer2Manager::Client::setDataSource_pre(
- player2_type playerType)
-{
- ALOGV("player type = %d", playerType);
-
- // create the right type of player
- sp<MediaPlayer2Base> p = createPlayer(playerType);
+sp<MediaPlayer2Base> MediaPlayer2Manager::Client::setDataSource_pre() {
+ sp<MediaPlayer2Base> p = createPlayer();
if (p == NULL) {
return p;
}
@@ -663,8 +657,7 @@
mStatus = UNKNOWN_ERROR;
return mStatus;
} else {
- player2_type playerType = MediaPlayer2Factory::getPlayerType(this, url);
- sp<MediaPlayer2Base> p = setDataSource_pre(playerType);
+ sp<MediaPlayer2Base> p = setDataSource_pre();
if (p == NULL) {
return NO_INIT;
}
@@ -701,11 +694,7 @@
ALOGV("calculated length = %lld", (long long)length);
}
- player2_type playerType = MediaPlayer2Factory::getPlayerType(this,
- fd,
- offset,
- length);
- sp<MediaPlayer2Base> p = setDataSource_pre(playerType);
+ sp<MediaPlayer2Base> p = setDataSource_pre();
if (p == NULL) {
return NO_INIT;
}
@@ -716,9 +705,7 @@
status_t MediaPlayer2Manager::Client::setDataSource(
const sp<IStreamSource> &source) {
- // create the right type of player
- player2_type playerType = MediaPlayer2Factory::getPlayerType(this, source);
- sp<MediaPlayer2Base> p = setDataSource_pre(playerType);
+ sp<MediaPlayer2Base> p = setDataSource_pre();
if (p == NULL) {
return NO_INIT;
}
@@ -729,8 +716,7 @@
status_t MediaPlayer2Manager::Client::setDataSource(
const sp<DataSource> &source) {
- player2_type playerType = MediaPlayer2Factory::getPlayerType(this, source);
- sp<MediaPlayer2Base> p = setDataSource_pre(playerType);
+ sp<MediaPlayer2Base> p = setDataSource_pre();
if (p == NULL) {
return NO_INIT;
}
diff --git a/media/libmedia/MediaPlayer2Manager.h b/media/libmedia/MediaPlayer2Manager.h
index b42cbbb..1265155 100644
--- a/media/libmedia/MediaPlayer2Manager.h
+++ b/media/libmedia/MediaPlayer2Manager.h
@@ -287,7 +287,7 @@
const sp<media::VolumeShaper::Operation>& operation) override;
virtual sp<media::VolumeShaper::State> getVolumeShaperState(int id) override;
- sp<MediaPlayer2Base> createPlayer(player2_type playerType);
+ sp<MediaPlayer2Base> createPlayer();
virtual status_t setDataSource(
const sp<MediaHTTPService> &httpService,
@@ -300,7 +300,7 @@
virtual status_t setDataSource(const sp<DataSource> &source);
- sp<MediaPlayer2Base> setDataSource_pre(player2_type playerType);
+ sp<MediaPlayer2Base> setDataSource_pre();
status_t setDataSource_post(const sp<MediaPlayer2Base>& p,
status_t status);
diff --git a/media/libmedia/TestPlayerStub.cpp b/media/libmedia/TestPlayerStub.cpp
deleted file mode 100644
index 3548793..0000000
--- a/media/libmedia/TestPlayerStub.cpp
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//#define LOG_NDEBUG 0
-#define LOG_TAG "TestPlayerStub"
-#include "utils/Log.h"
-
-#include "TestPlayerStub.h"
-
-#include <dlfcn.h> // for dlopen/dlclose
-#include <stdlib.h>
-#include <string.h>
-#include <cutils/properties.h>
-#include <utils/Errors.h> // for status_t
-
-#include "media/MediaPlayer2Interface.h"
-
-
-namespace {
-using android::status_t;
-using android::MediaPlayer2Base;
-
-const char *kTestUrlScheme = "test:";
-const char *kUrlParam = "url=";
-
-const char *kBuildTypePropName = "ro.build.type";
-const char *kEngBuild = "eng";
-const char *kTestBuild = "test";
-
-// @return true if the current build is 'eng' or 'test'.
-bool isTestBuild()
-{
- char prop[PROPERTY_VALUE_MAX] = { '\0', };
-
- property_get(kBuildTypePropName, prop, "\0");
- return strcmp(prop, kEngBuild) == 0 || strcmp(prop, kTestBuild) == 0;
-}
-
-// @return true if the url scheme is 'test:'
-bool isTestUrl(const char *url)
-{
- return url && strncmp(url, kTestUrlScheme, strlen(kTestUrlScheme)) == 0;
-}
-
-} // anonymous namespace
-
-namespace android {
-
-TestPlayerStub::TestPlayerStub()
- :mUrl(NULL), mFilename(NULL), mContentUrl(NULL),
- mHandle(NULL), mNewPlayer(NULL), mDeletePlayer(NULL),
- mPlayer(NULL) { }
-
-TestPlayerStub::~TestPlayerStub()
-{
- resetInternal();
-}
-
-status_t TestPlayerStub::initCheck()
-{
- return isTestBuild() ? OK : INVALID_OPERATION;
-}
-
-// Parse mUrl to get:
-// * The library to be dlopened.
-// * The url to be passed to the real setDataSource impl.
-//
-// mUrl is expected to be in following format:
-//
-// test:<name of the .so>?url=<url for setDataSource>
-//
-// The value of the url parameter is treated as a string (no
-// unescaping of illegal charaters).
-status_t TestPlayerStub::parseUrl()
-{
- if (strlen(mUrl) < strlen(kTestUrlScheme)) {
- resetInternal();
- return BAD_VALUE;
- }
-
- char *i = mUrl + strlen(kTestUrlScheme);
-
- mFilename = i;
-
- while (*i != '\0' && *i != '?') {
- ++i;
- }
-
- if (*i == '\0' || strncmp(i + 1, kUrlParam, strlen(kUrlParam)) != 0) {
- resetInternal();
- return BAD_VALUE;
- }
- *i = '\0'; // replace '?' to nul-terminate mFilename
-
- mContentUrl = i + 1 + strlen(kUrlParam);
- return OK;
-}
-
-// Load the dynamic library.
-// Create the test player.
-// Call setDataSource on the test player with the url in param.
-status_t TestPlayerStub::setDataSource(
- const sp<MediaHTTPService> &httpService,
- const char *url,
- const KeyedVector<String8, String8> *headers) {
- if (!isTestUrl(url) || NULL != mHandle) {
- return INVALID_OPERATION;
- }
-
- mUrl = strdup(url);
-
- status_t status = parseUrl();
-
- if (OK != status) {
- resetInternal();
- return status;
- }
-
- ::dlerror(); // Clears any pending error.
-
- // Load the test player from the url. dlopen will fail if the lib
- // is not there. dls are under /system/lib
- // None of the entry points should be NULL.
- mHandle = ::dlopen(mFilename, RTLD_NOW | RTLD_GLOBAL);
- if (!mHandle) {
- ALOGE("dlopen failed: %s", ::dlerror());
- resetInternal();
- return UNKNOWN_ERROR;
- }
-
- // Load the 2 entry points to create and delete instances.
- const char *err;
- mNewPlayer = reinterpret_cast<NEW_PLAYER>(dlsym(mHandle,
- "newPlayer"));
- err = ::dlerror();
- if (err || mNewPlayer == NULL) {
- // if err is NULL the string <null> is inserted in the logs =>
- // mNewPlayer was NULL.
- ALOGE("dlsym for newPlayer failed %s", err);
- resetInternal();
- return UNKNOWN_ERROR;
- }
-
- mDeletePlayer = reinterpret_cast<DELETE_PLAYER>(dlsym(mHandle,
- "deletePlayer"));
- err = ::dlerror();
- if (err || mDeletePlayer == NULL) {
- ALOGE("dlsym for deletePlayer failed %s", err);
- resetInternal();
- return UNKNOWN_ERROR;
- }
-
- mPlayer = (*mNewPlayer)();
- return mPlayer->setDataSource(httpService, mContentUrl, headers);
-}
-
-// Internal cleanup.
-status_t TestPlayerStub::resetInternal()
-{
- if(mUrl) {
- free(mUrl);
- mUrl = NULL;
- }
- mFilename = NULL;
- mContentUrl = NULL;
-
- if (mPlayer) {
- ALOG_ASSERT(mDeletePlayer != NULL, "mDeletePlayer is null");
- (*mDeletePlayer)(mPlayer);
- mPlayer = NULL;
- }
-
- if (mHandle) {
- ::dlclose(mHandle);
- mHandle = NULL;
- }
- return OK;
-}
-
-/* static */ bool TestPlayerStub::canBeUsed(const char *url)
-{
- return isTestBuild() && isTestUrl(url);
-}
-
-} // namespace android
diff --git a/media/libmedia/TestPlayerStub.h b/media/libmedia/TestPlayerStub.h
deleted file mode 100644
index 27c8bf4..0000000
--- a/media/libmedia/TestPlayerStub.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIA_TESTPLAYERSTUB_H__
-#define ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIA_TESTPLAYERSTUB_H__
-
-#include <media/MediaPlayer2Interface.h>
-#include <utils/Errors.h>
-
-namespace android {
-class MediaPlayer2Base; // in media/MediaPlayer2Interface.h
-
-// Wrapper around a test media player that gets dynamically loaded.
-//
-// The URL passed to setDataSource has this format:
-//
-// test:<name of the .so>?url=<url for the real setDataSource impl.>
-//
-// e.g:
-// test:invoke_test_media_player.so?url=http://youtube.com/
-// test:invoke_test_media_player.so?url=speedtest
-//
-// TestPlayerStub::setDataSource loads the library in the test url. 2
-// entry points with C linkage are expected. One to create the test
-// player and one to destroy it.
-//
-// extern "C" android::MediaPlayer2Base* newPlayer();
-// extern "C" android::status_t deletePlayer(android::MediaPlayer2Base *p);
-//
-// Once the test player has been loaded, its setDataSource
-// implementation is called with the value of the 'url' parameter.
-//
-// typical usage in a java test:
-// ============================
-//
-// MediaPlayer2 p = new MediaPlayer2();
-// p.setDataSource("test:invoke_mock_media_player.so?url=http://youtube.com");
-// p.prepare();
-// ...
-// p.release();
-
-class TestPlayerStub : public MediaPlayer2Interface {
- public:
- typedef MediaPlayer2Base* (*NEW_PLAYER)();
- typedef status_t (*DELETE_PLAYER)(MediaPlayer2Base *);
-
- TestPlayerStub();
- virtual ~TestPlayerStub();
-
- // Called right after the constructor. Check if the current build
- // allows test players.
- virtual status_t initCheck();
-
- // @param url Should be a test url. See class comment.
- virtual status_t setDataSource(
- const sp<MediaHTTPService> &httpService,
- const char* url,
- const KeyedVector<String8, String8> *headers);
-
- // Test player for a file descriptor source is not supported.
- virtual status_t setDataSource(int, int64_t, int64_t) {
- return INVALID_OPERATION;
- }
-
-
- // All the methods below wrap the mPlayer instance.
- virtual status_t setVideoSurfaceTexture(
- const android::sp<android::ANativeWindowWrapper>& st) {
- return mPlayer->setVideoSurfaceTexture(st);
- }
- virtual status_t prepare() {return mPlayer->prepare();}
- virtual status_t prepareAsync() {return mPlayer->prepareAsync();}
- virtual status_t start() {return mPlayer->start();}
- virtual status_t stop() {return mPlayer->stop();}
- virtual status_t pause() {return mPlayer->pause();}
- virtual bool isPlaying() {return mPlayer->isPlaying();}
- virtual status_t seekTo(
- int msec,
- MediaPlayer2SeekMode mode = MediaPlayer2SeekMode::SEEK_PREVIOUS_SYNC) {
- return mPlayer->seekTo(msec, mode);
- }
- virtual status_t getCurrentPosition(int *p) {
- return mPlayer->getCurrentPosition(p);
- }
- virtual status_t getDuration(int *d) {return mPlayer->getDuration(d);}
- virtual status_t reset() {return mPlayer->reset();}
- virtual status_t setLooping(int b) {return mPlayer->setLooping(b);}
- virtual player2_type playerType() {return mPlayer->playerType();}
- virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
- return mPlayer->invoke(in, out);
- }
- virtual status_t setParameter(int key, const Parcel &request) {
- return mPlayer->setParameter(key, request);
- }
- virtual status_t getParameter(int key, Parcel *reply) {
- return mPlayer->getParameter(key, reply);
- }
-
-
- // @return true if the current build is 'eng' or 'test' and the
- // url's scheme is 'test:'
- static bool canBeUsed(const char *url);
-
- private:
- // Release the player, dlclose the library.
- status_t resetInternal();
- status_t parseUrl();
-
- char *mUrl; // test:foo.so?url=http://bar
- char *mFilename; // foo.so
- char *mContentUrl; // http://bar
- void *mHandle; // returned by dlopen
- NEW_PLAYER mNewPlayer;
- DELETE_PLAYER mDeletePlayer;
- MediaPlayer2Base *mPlayer; // wrapped player
-};
-
-} // namespace android
-
-#endif // ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIA_TESTPLAYERSTUB_H__
diff --git a/media/libmedia/include/media/MediaPlayer2Interface.h b/media/libmedia/include/media/MediaPlayer2Interface.h
index 931a110..88012ac 100644
--- a/media/libmedia/include/media/MediaPlayer2Interface.h
+++ b/media/libmedia/include/media/MediaPlayer2Interface.h
@@ -47,16 +47,6 @@
template<typename T> class SortedVector;
-enum player2_type {
- PLAYER2_STAGEFRIGHT_PLAYER = 3,
- PLAYER2_NU_PLAYER2 = 4,
- // Test players are available only in the 'test' and 'eng' builds.
- // The shared library with the test player is passed passed as an
- // argument to the 'test:' url in the setDataSource call.
- PLAYER2_TEST_PLAYER = 5,
-};
-
-
#define DEFAULT_AUDIOSINK_BUFFERCOUNT 4
#define DEFAULT_AUDIOSINK_BUFFERSIZE 1200
#define DEFAULT_AUDIOSINK_SAMPLERATE 44100
@@ -234,7 +224,6 @@
return INVALID_OPERATION;
}
virtual status_t setLooping(int loop) = 0;
- virtual player2_type playerType() = 0;
virtual status_t setParameter(int key, const Parcel &request) = 0;
virtual status_t getParameter(int key, Parcel *reply) = 0;
diff --git a/media/libmedia/nuplayer2/NuPlayer2Driver.cpp b/media/libmedia/nuplayer2/NuPlayer2Driver.cpp
index ccfcc47..233ba0a 100644
--- a/media/libmedia/nuplayer2/NuPlayer2Driver.cpp
+++ b/media/libmedia/nuplayer2/NuPlayer2Driver.cpp
@@ -736,10 +736,6 @@
return OK;
}
-player2_type NuPlayer2Driver::playerType() {
- return PLAYER2_NU_PLAYER2;
-}
-
status_t NuPlayer2Driver::invoke(const Parcel &request, Parcel *reply) {
if (reply == NULL) {
ALOGE("reply is a NULL pointer");
diff --git a/media/libmedia/nuplayer2/NuPlayer2Driver.h b/media/libmedia/nuplayer2/NuPlayer2Driver.h
index d393f9d..7bbb367 100644
--- a/media/libmedia/nuplayer2/NuPlayer2Driver.h
+++ b/media/libmedia/nuplayer2/NuPlayer2Driver.h
@@ -66,7 +66,6 @@
virtual status_t reset();
virtual status_t notifyAt(int64_t mediaTimeUs) override;
virtual status_t setLooping(int loop);
- virtual player2_type playerType();
virtual status_t invoke(const Parcel &request, Parcel *reply);
virtual void setAudioSink(const sp<AudioSink> &audioSink);
virtual status_t setParameter(int key, const Parcel &request);