1 /*
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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "TestPlayerStub"
19 #include "utils/Log.h"
20
21 #include <string.h>
22
23 #include <binder/Parcel.h>
24 #include <media/MediaPlayerInterface.h>
25 #include <utils/Errors.h>
26
27 using android::INVALID_OPERATION;
28 using android::Surface;
29 using android::IGraphicBufferProducer;
30 using android::IMediaHTTPService;
31 using android::MediaPlayerBase;
32 using android::OK;
33 using android::Parcel;
34 using android::SortedVector;
35 using android::TEST_PLAYER;
36 using android::UNKNOWN_ERROR;
37 using android::player_type;
38 using android::sp;
39 using android::status_t;
40 using android::String8;
41 using android::KeyedVector;
42
43 // This file contains a test player that is loaded via the
44 // TestPlayerStub class. The player contains various implementation
45 // of the invoke method that java tests can use.
46
47 namespace {
48 const char *kPing = "ping";
49
50 class Player: public MediaPlayerBase
51 {
52 public:
53 enum TestType {TEST_UNKNOWN, PING};
Player()54 Player() {}
~Player()55 virtual ~Player() {}
56
initCheck()57 virtual status_t initCheck() {return OK;}
hardwareOutput()58 virtual bool hardwareOutput() {return true;}
59
setDataSource(const sp<IMediaHTTPService> & httpService,const char * url,const KeyedVector<String8,String8> *)60 virtual status_t setDataSource(
61 const sp<IMediaHTTPService> &httpService,
62 const char *url,
63 const KeyedVector<String8, String8> *) {
64 ALOGV("setDataSource %s", url);
65 mTest = TEST_UNKNOWN;
66 if (strncmp(url, kPing, strlen(kPing)) == 0) {
67 mTest = PING;
68 }
69 return OK;
70 }
71
setDataSource(int fd,int64_t offset,int64_t length)72 virtual status_t setDataSource(int fd, int64_t offset, int64_t length) {return OK;}
setVideoSurfaceTexture(const sp<IGraphicBufferProducer> & bufferProducer)73 virtual status_t setVideoSurfaceTexture(
74 const sp<IGraphicBufferProducer>& bufferProducer) {return OK;}
prepare()75 virtual status_t prepare() {return OK;}
prepareAsync()76 virtual status_t prepareAsync() {return OK;}
start()77 virtual status_t start() {return OK;}
stop()78 virtual status_t stop() {return OK;}
pause()79 virtual status_t pause() {return OK;}
isPlaying()80 virtual bool isPlaying() {return true;}
seekTo(int msec)81 virtual status_t seekTo(int msec) {return OK;}
getCurrentPosition(int * msec)82 virtual status_t getCurrentPosition(int *msec) {return OK;}
getDuration(int * msec)83 virtual status_t getDuration(int *msec) {return OK;}
reset()84 virtual status_t reset() {return OK;}
setLooping(int loop)85 virtual status_t setLooping(int loop) {return OK;}
playerType()86 virtual player_type playerType() {return TEST_PLAYER;}
87 virtual status_t invoke(const Parcel& request, Parcel *reply);
setParameter(int key,const Parcel & request)88 virtual status_t setParameter(int key, const Parcel &request) {return OK;}
getParameter(int key,Parcel * reply)89 virtual status_t getParameter(int key, Parcel *reply) {return OK;}
90
91
92 private:
93 // Take a request, copy it to the reply.
94 void ping(const Parcel& request, Parcel *reply);
95
96 status_t mStatus;
97 TestType mTest;
98 };
99
invoke(const Parcel & request,Parcel * reply)100 status_t Player::invoke(const Parcel& request, Parcel *reply)
101 {
102 switch (mTest) {
103 case PING:
104 ping(request, reply);
105 break;
106 default: mStatus = UNKNOWN_ERROR;
107 }
108 return mStatus;
109 }
110
ping(const Parcel & request,Parcel * reply)111 void Player::ping(const Parcel& request, Parcel *reply)
112 {
113 const size_t len = request.dataAvail();
114
115 reply->setData(static_cast<const uint8_t*>(request.readInplace(len)), len);
116 mStatus = OK;
117 }
118
119 }
120
newPlayer()121 extern "C" android::MediaPlayerBase* newPlayer()
122 {
123 ALOGD("New invoke test player");
124 return new Player();
125 }
126
deletePlayer(android::MediaPlayerBase * player)127 extern "C" android::status_t deletePlayer(android::MediaPlayerBase *player)
128 {
129 ALOGD("Delete invoke test player");
130 delete player;
131 return OK;
132 }
133