blob: 802a11b0eff3761aace196a541829774a02907fe [file] [log] [blame]
Nicolas Catania8f5fcab2009-07-13 14:37:49 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
18#define ANDROID_FRAMEWORKS_BASE_MEDIA_LIBMEDIAPLAYERSERVICE_TESTPLAYERSTUB_H__
19
20#include <media/MediaPlayerInterface.h>
21#include <utils/Errors.h>
22
23namespace android {
24class MediaPlayerBase; // in media/MediaPlayerInterface.h
25
26// Wrapper around a test media player that gets dynamically loaded.
27//
28// The URL passed to setDataSource has this format:
29//
30// test:<name of the .so>?url=<url for the real setDataSource impl.>
31//
32// e.g:
33// test:invoke_test_media_player.so?url=http://youtube.com/
34// test:invoke_test_media_player.so?url=speedtest
35//
36// TestPlayerStub::setDataSource loads the library in the test url. 2
37// entry points with C linkage are expected. One to create the test
38// player and one to destroy it.
39//
40// extern "C" android::MediaPlayerBase* newPlayer();
41// extern "C" android::status_t deletePlayer(android::MediaPlayerBase *p);
42//
43// Once the test player has been loaded, its setDataSource
44// implementation is called with the value of the 'url' parameter.
45//
46// typical usage in a java test:
47// ============================
48//
49// MediaPlayer p = new MediaPlayer();
50// p.setDataSource("test:invoke_mock_media_player.so?url=http://youtube.com");
51// p.prepare();
52// ...
53// p.release();
54
55class TestPlayerStub : public MediaPlayerInterface {
56 public:
57 typedef MediaPlayerBase* (*NEW_PLAYER)();
58 typedef status_t (*DELETE_PLAYER)(MediaPlayerBase *);
59
60 TestPlayerStub();
61 virtual ~TestPlayerStub();
62
63 // Called right after the constructor. Check if the current build
64 // allows test players.
65 virtual status_t initCheck();
66
67 // @param url Should be a test url. See class comment.
Andreas Huber25643002010-01-28 11:19:57 -080068 virtual status_t setDataSource(
69 const char* url, const KeyedVector<String8, String8> *headers);
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070070
71 // Test player for a file descriptor source is not supported.
72 virtual status_t setDataSource(int, int64_t, int64_t) {
73 return INVALID_OPERATION;
74 }
75
76
77 // All the methods below wrap the mPlayer instance.
Andreas Hubere3c01832010-08-16 08:49:37 -070078 virtual status_t setVideoSurface(const android::sp<android::Surface>& s) {
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070079 return mPlayer->setVideoSurface(s);
80 }
Glenn Kastencc562a32011-02-08 17:26:17 -080081 virtual status_t setVideoSurfaceTexture(
82 const android::sp<android::ISurfaceTexture>& st) {
83 return mPlayer->setVideoSurfaceTexture(st);
84 }
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070085 virtual status_t prepare() {return mPlayer->prepare();}
86 virtual status_t prepareAsync() {return mPlayer->prepareAsync();}
87 virtual status_t start() {return mPlayer->start();}
88 virtual status_t stop() {return mPlayer->stop();}
89 virtual status_t pause() {return mPlayer->pause();}
90 virtual bool isPlaying() {return mPlayer->isPlaying();}
91 virtual status_t seekTo(int msec) {return mPlayer->seekTo(msec);}
92 virtual status_t getCurrentPosition(int *p) {
93 return mPlayer->getCurrentPosition(p);
94 }
95 virtual status_t getDuration(int *d) {return mPlayer->getDuration(d);}
96 virtual status_t reset() {return mPlayer->reset();}
97 virtual status_t setLooping(int b) {return mPlayer->setLooping(b);}
98 virtual player_type playerType() {return mPlayer->playerType();}
99 virtual status_t invoke(const android::Parcel& in, android::Parcel *out) {
100 return mPlayer->invoke(in, out);
101 }
Gloria Wangd01ec6e2011-04-25 17:28:22 -0700102 virtual status_t setParameter(int key, const Parcel &request) {
103 return mPlayer->setParameter(key, request);
104 }
105 virtual status_t getParameter(int key, Parcel *reply) {
106 return mPlayer->getParameter(key, reply);
107 }
Nicolas Catania8f5fcab2009-07-13 14:37:49 -0700108
109
110 // @return true if the current build is 'eng' or 'test' and the
111 // url's scheme is 'test:'
112 static bool canBeUsed(const char *url);
113
114 private:
115 // Release the player, dlclose the library.
116 status_t resetInternal();
117 status_t parseUrl();
118
119 char *mUrl; // test:foo.so?url=http://bar
120 char *mFilename; // foo.so
121 char *mContentUrl; // http://bar
122 void *mHandle; // returned by dlopen
123 NEW_PLAYER mNewPlayer;
124 DELETE_PLAYER mDeletePlayer;
125 MediaPlayerBase *mPlayer; // wrapped player
126};
127
128} // namespace android
129
130#endif