18f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania/*
28f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Copyright (C) 2009 The Android Open Source Project
38f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
48f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Licensed under the Apache License, Version 2.0 (the "License");
58f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * you may not use this file except in compliance with the License.
68f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * You may obtain a copy of the License at
78f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
88f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *      http://www.apache.org/licenses/LICENSE-2.0
98f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
108f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Unless required by applicable law or agreed to in writing, software
118f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * distributed under the License is distributed on an "AS IS" BASIS,
128f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * See the License for the specific language governing permissions and
148f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * limitations under the License.
158f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania */
168f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
178f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#ifndef ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
188f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#define ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
198f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
208f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#include <media/MediaPlayerInterface.h>
218f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#include <utils/Errors.h>
228f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
238f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catanianamespace android {
248f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaclass MediaPlayerBase;  // in media/MediaPlayerInterface.h
258f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
268f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// Wrapper around a test media player that gets dynamically loaded.
278f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
288f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// The URL passed to setDataSource has this format:
298f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
308f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//   test:<name of the .so>?url=<url for the real setDataSource impl.>
318f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
328f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// e.g:
338f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//   test:invoke_test_media_player.so?url=http://youtube.com/
348f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//   test:invoke_test_media_player.so?url=speedtest
358f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
368f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// TestPlayerStub::setDataSource loads the library in the test url. 2
378f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// entry points with C linkage are expected. One to create the test
388f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// player and one to destroy it.
398f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
408f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// extern "C" android::MediaPlayerBase* newPlayer();
418f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// extern "C" android::status_t deletePlayer(android::MediaPlayerBase *p);
428f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
438f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// Once the test player has been loaded, its setDataSource
448f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// implementation is called with the value of the 'url' parameter.
458f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
468f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// typical usage in a java test:
478f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// ============================
488f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//
498f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//  MediaPlayer p = new MediaPlayer();
508f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//  p.setDataSource("test:invoke_mock_media_player.so?url=http://youtube.com");
518f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//  p.prepare();
528f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//  ...
538f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//  p.release();
548f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
558f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaclass TestPlayerStub : public MediaPlayerInterface {
568f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania  public:
578f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    typedef MediaPlayerBase* (*NEW_PLAYER)();
588f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    typedef status_t (*DELETE_PLAYER)(MediaPlayerBase *);
598f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
608f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    TestPlayerStub();
618f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual ~TestPlayerStub();
628f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
638f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // Called right after the constructor. Check if the current build
648f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // allows test players.
658f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t initCheck();
668f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
678f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // @param url Should be a test url. See class comment.
68256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber    virtual status_t setDataSource(
69256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber            const char* url, const KeyedVector<String8, String8> *headers);
708f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
718f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // Test player for a file descriptor source is not supported.
728f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t setDataSource(int, int64_t, int64_t)  {
738f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        return INVALID_OPERATION;
748f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
758f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
768f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
778f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // All the methods below wrap the mPlayer instance.
788f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t setVideoSurface(const android::sp<android::ISurface>& s)  {
798f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        return mPlayer->setVideoSurface(s);
808f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
818f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t prepare() {return mPlayer->prepare();}
828f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t prepareAsync()  {return mPlayer->prepareAsync();}
838f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t start()  {return mPlayer->start();}
848f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t stop()  {return mPlayer->stop();}
858f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t pause()  {return mPlayer->pause();}
868f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual bool isPlaying() {return mPlayer->isPlaying();}
878f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t seekTo(int msec) {return mPlayer->seekTo(msec);}
888f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t getCurrentPosition(int *p)  {
898f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        return mPlayer->getCurrentPosition(p);
908f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
918f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t getDuration(int *d)  {return mPlayer->getDuration(d);}
928f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t reset() {return mPlayer->reset();}
938f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t setLooping(int b)  {return mPlayer->setLooping(b);}
948f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual player_type playerType() {return mPlayer->playerType();}
958f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
968f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        return mPlayer->invoke(in, out);
978f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
988f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
998f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1008f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // @return true if the current build is 'eng' or 'test' and the
1018f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    //              url's scheme is 'test:'
1028f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    static bool canBeUsed(const char *url);
1038f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1048f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania  private:
1058f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // Release the player, dlclose the library.
1068f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    status_t resetInternal();
1078f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    status_t parseUrl();
1088f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1098f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    char *mUrl;                // test:foo.so?url=http://bar
1108f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    char *mFilename;           // foo.so
1118f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    char *mContentUrl;         // http://bar
1128f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    void *mHandle;             // returned by dlopen
1138f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    NEW_PLAYER    mNewPlayer;
1148f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    DELETE_PLAYER mDeletePlayer;
1158f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    MediaPlayerBase *mPlayer;  // wrapped player
1168f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania};
1178f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1188f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}  // namespace android
1198f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1208f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#endif
121