114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania/* 214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * Copyright (C) 2009 The Android Open Source Project 314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * 414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * Licensed under the Apache License, Version 2.0 (the "License"); 514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * you may not use this file except in compliance with the License. 614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * You may obtain a copy of the License at 714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * 814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * http://www.apache.org/licenses/LICENSE-2.0 914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * 1014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * Unless required by applicable law or agreed to in writing, software 1114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * distributed under the License is distributed on an "AS IS" BASIS, 1214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * See the License for the specific language governing permissions and 1414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania * limitations under the License. 1514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania */ 1614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 1714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#ifndef ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__ 1814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#define ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__ 1914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 2014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#include <media/MediaPlayerInterface.h> 2114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#include <utils/Errors.h> 2214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 2314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catanianamespace android { 2414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Cataniaclass MediaPlayerBase; // in media/MediaPlayerInterface.h 2514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 2614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// Wrapper around a test media player that gets dynamically loaded. 2714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 2814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// The URL passed to setDataSource has this format: 2914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 3014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// test:<name of the .so>?url=<url for the real setDataSource impl.> 3114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 3214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// e.g: 3314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// test:invoke_test_media_player.so?url=http://youtube.com/ 3414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// test:invoke_test_media_player.so?url=speedtest 3514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 3614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// TestPlayerStub::setDataSource loads the library in the test url. 2 3714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// entry points with C linkage are expected. One to create the test 3814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// player and one to destroy it. 3914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 4014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// extern "C" android::MediaPlayerBase* newPlayer(); 4114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// extern "C" android::status_t deletePlayer(android::MediaPlayerBase *p); 4214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 4314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// Once the test player has been loaded, its setDataSource 4414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// implementation is called with the value of the 'url' parameter. 4514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 4614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// typical usage in a java test: 4714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// ============================ 4814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// 4914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// MediaPlayer p = new MediaPlayer(); 5014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// p.setDataSource("test:invoke_mock_media_player.so?url=http://youtube.com"); 5114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// p.prepare(); 5214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// ... 5314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania// p.release(); 5414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 5514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Cataniaclass TestPlayerStub : public MediaPlayerInterface { 5614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania public: 5714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania typedef MediaPlayerBase* (*NEW_PLAYER)(); 5814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania typedef status_t (*DELETE_PLAYER)(MediaPlayerBase *); 5914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 6014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania TestPlayerStub(); 6114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual ~TestPlayerStub(); 6214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 6314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // Called right after the constructor. Check if the current build 6414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // allows test players. 6514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t initCheck(); 6614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 6714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // @param url Should be a test url. See class comment. 682db8455d8f4468a637109d31f319ce02d9d743ecAndreas Huber virtual status_t setDataSource( 691b86fe063badb5f28c467ade39be0f4008688947Andreas Huber const sp<IMediaHTTPService> &httpService, 701b86fe063badb5f28c467ade39be0f4008688947Andreas Huber const char* url, 711b86fe063badb5f28c467ade39be0f4008688947Andreas Huber const KeyedVector<String8, String8> *headers); 7214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 7314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // Test player for a file descriptor source is not supported. 7414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t setDataSource(int, int64_t, int64_t) { 7514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania return INVALID_OPERATION; 7614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania } 7714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 7814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 7914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // All the methods below wrap the mPlayer instance. 801173118eace0e9e347cb007f0da817cee87579edGlenn Kasten virtual status_t setVideoSurfaceTexture( 818ba01021b573889802e67e029225a96f0dfa471aAndy McFadden const android::sp<android::IGraphicBufferProducer>& st) { 821173118eace0e9e347cb007f0da817cee87579edGlenn Kasten return mPlayer->setVideoSurfaceTexture(st); 831173118eace0e9e347cb007f0da817cee87579edGlenn Kasten } 8414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t prepare() {return mPlayer->prepare();} 8514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t prepareAsync() {return mPlayer->prepareAsync();} 8614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t start() {return mPlayer->start();} 8714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t stop() {return mPlayer->stop();} 8814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t pause() {return mPlayer->pause();} 8914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual bool isPlaying() {return mPlayer->isPlaying();} 9014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t seekTo(int msec) {return mPlayer->seekTo(msec);} 9114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t getCurrentPosition(int *p) { 9214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania return mPlayer->getCurrentPosition(p); 9314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania } 9414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t getDuration(int *d) {return mPlayer->getDuration(d);} 9514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t reset() {return mPlayer->reset();} 9614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t setLooping(int b) {return mPlayer->setLooping(b);} 9714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual player_type playerType() {return mPlayer->playerType();} 9814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania virtual status_t invoke(const android::Parcel& in, android::Parcel *out) { 9914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania return mPlayer->invoke(in, out); 10014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania } 1014f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang virtual status_t setParameter(int key, const Parcel &request) { 1024f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang return mPlayer->setParameter(key, request); 1034f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang } 1044f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang virtual status_t getParameter(int key, Parcel *reply) { 1054f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang return mPlayer->getParameter(key, reply); 1064f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang } 10714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 10814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 10914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // @return true if the current build is 'eng' or 'test' and the 11014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // url's scheme is 'test:' 11114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania static bool canBeUsed(const char *url); 11214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 11314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania private: 11414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania // Release the player, dlclose the library. 11514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania status_t resetInternal(); 11614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania status_t parseUrl(); 11714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 11814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania char *mUrl; // test:foo.so?url=http://bar 11914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania char *mFilename; // foo.so 12014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania char *mContentUrl; // http://bar 12114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania void *mHandle; // returned by dlopen 12214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania NEW_PLAYER mNewPlayer; 12314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania DELETE_PLAYER mDeletePlayer; 12414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania MediaPlayerBase *mPlayer; // wrapped player 12514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania}; 12614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 12714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania} // namespace android 12814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania 12914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#endif 130