TestPlayerStub.h revision 14d2747c7e54037e267bcff78b29e65b2181f0fa
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.
6814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t setDataSource(const char* url);
6914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
7014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // Test player for a file descriptor source is not supported.
7114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t setDataSource(int, int64_t, int64_t)  {
7214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania        return INVALID_OPERATION;
7314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    }
7414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
7514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
7614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // All the methods below wrap the mPlayer instance.
7714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t setVideoSurface(const android::sp<android::ISurface>& s)  {
7814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania        return mPlayer->setVideoSurface(s);
7914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    }
8014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t prepare() {return mPlayer->prepare();}
8114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t prepareAsync()  {return mPlayer->prepareAsync();}
8214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t start()  {return mPlayer->start();}
8314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t stop()  {return mPlayer->stop();}
8414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t pause()  {return mPlayer->pause();}
8514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual bool isPlaying() {return mPlayer->isPlaying();}
8614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t seekTo(int msec) {return mPlayer->seekTo(msec);}
8714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t getCurrentPosition(int *p)  {
8814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania        return mPlayer->getCurrentPosition(p);
8914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    }
9014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t getDuration(int *d)  {return mPlayer->getDuration(d);}
9114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t reset() {return mPlayer->reset();}
9214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t setLooping(int b)  {return mPlayer->setLooping(b);}
9314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual player_type playerType() {return mPlayer->playerType();}
9414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
9514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania        return mPlayer->invoke(in, out);
9614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    }
9714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
9814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
9914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // @return true if the current build is 'eng' or 'test' and the
10014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    //              url's scheme is 'test:'
10114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    static bool canBeUsed(const char *url);
10214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
10314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania  private:
10414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    // Release the player, dlclose the library.
10514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    status_t resetInternal();
10614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    status_t parseUrl();
10714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
10814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    char *mUrl;                // test:foo.so?url=http://bar
10914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    char *mFilename;           // foo.so
11014d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    char *mContentUrl;         // http://bar
11114d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    void *mHandle;             // returned by dlopen
11214d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    NEW_PLAYER    mNewPlayer;
11314d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    DELETE_PLAYER mDeletePlayer;
11414d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania    MediaPlayerBase *mPlayer;  // wrapped player
11514d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania};
11614d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
11714d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania}  // namespace android
11814d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania
11914d2747c7e54037e267bcff78b29e65b2181f0faNicolas Catania#endif
120