blob: 3060df253ae16410933fa146a84f9c8c5a431dff [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//#define LOG_NDEBUG 0
18#define LOG_TAG "TestPlayerStub"
19#include "utils/Log.h"
20
21#include <string.h>
22
niko89948372009-07-16 16:39:53 -070023#include <binder/Parcel.h>
24#include <media/MediaPlayerInterface.h>
25#include <utils/Errors.h>
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070026
niko89948372009-07-16 16:39:53 -070027using android::INVALID_OPERATION;
Andreas Hubere3c01832010-08-16 08:49:37 -070028using android::Surface;
Andy McFaddend47f7d82012-12-18 09:48:38 -080029using android::IGraphicBufferProducer;
Andreas Huberd2506a52014-01-29 10:32:46 -080030using android::IMediaHTTPService;
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070031using android::MediaPlayerBase;
32using android::OK;
33using android::Parcel;
niko89948372009-07-16 16:39:53 -070034using android::SortedVector;
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070035using android::TEST_PLAYER;
36using android::UNKNOWN_ERROR;
37using android::player_type;
38using android::sp;
39using android::status_t;
Andreas Huber25643002010-01-28 11:19:57 -080040using android::String8;
41using android::KeyedVector;
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070042
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
47namespace {
48const char *kPing = "ping";
49
50class Player: public MediaPlayerBase
51{
52 public:
53 enum TestType {TEST_UNKNOWN, PING};
54 Player() {}
55 virtual ~Player() {}
56
57 virtual status_t initCheck() {return OK;}
58 virtual bool hardwareOutput() {return true;}
59
Andreas Huber25643002010-01-28 11:19:57 -080060 virtual status_t setDataSource(
Andreas Gampea4a13482014-11-10 18:44:43 -080061 const sp<IMediaHTTPService>& /* httpService */,
Andreas Huber25643002010-01-28 11:19:57 -080062 const char *url,
63 const KeyedVector<String8, String8> *) {
Steve Block71f2cf12011-10-20 11:56:00 +010064 ALOGV("setDataSource %s", url);
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070065 mTest = TEST_UNKNOWN;
66 if (strncmp(url, kPing, strlen(kPing)) == 0) {
67 mTest = PING;
68 }
69 return OK;
70 }
71
Andreas Gampea4a13482014-11-10 18:44:43 -080072 virtual status_t setDataSource(int /* fd */, int64_t /* offset */, int64_t /* length */) {
73 return OK;
74 }
Glenn Kastencc562a32011-02-08 17:26:17 -080075 virtual status_t setVideoSurfaceTexture(
Andreas Gampea4a13482014-11-10 18:44:43 -080076 const sp<IGraphicBufferProducer>& /* bufferProducer */) {
77 return OK;
78 }
79 virtual status_t prepare() { return OK; }
80 virtual status_t prepareAsync() { return OK; }
81 virtual status_t start() { return OK; }
82 virtual status_t stop() { return OK; }
83 virtual status_t pause() { return OK; }
84 virtual bool isPlaying() { return true; }
Wei Jia008fb022016-11-18 10:26:00 -080085 virtual status_t seekTo(int /* msec */, android::MediaPlayerSeekMode /* mode */) { return OK; }
Andreas Gampea4a13482014-11-10 18:44:43 -080086 virtual status_t getCurrentPosition(int* /* msec */) { return OK; }
87 virtual status_t getDuration(int* /* msec */) { return OK; }
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070088 virtual status_t reset() {return OK;}
Andreas Gampea4a13482014-11-10 18:44:43 -080089 virtual status_t setLooping(int /* loop */) { return OK; }
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070090 virtual player_type playerType() {return TEST_PLAYER;}
91 virtual status_t invoke(const Parcel& request, Parcel *reply);
Andreas Gampea4a13482014-11-10 18:44:43 -080092 virtual status_t setParameter(int /* key */, const Parcel& /* request */) { return OK; }
93 virtual status_t getParameter(int /* key */, Parcel* /* reply */) { return OK; }
Gloria Wangd01ec6e2011-04-25 17:28:22 -070094
niko89948372009-07-16 16:39:53 -070095
Nicolas Catania8f5fcab2009-07-13 14:37:49 -070096 private:
97 // Take a request, copy it to the reply.
98 void ping(const Parcel& request, Parcel *reply);
99
100 status_t mStatus;
101 TestType mTest;
102};
103
104status_t Player::invoke(const Parcel& request, Parcel *reply)
105{
106 switch (mTest) {
107 case PING:
108 ping(request, reply);
109 break;
110 default: mStatus = UNKNOWN_ERROR;
111 }
112 return mStatus;
113}
114
115void Player::ping(const Parcel& request, Parcel *reply)
116{
117 const size_t len = request.dataAvail();
118
119 reply->setData(static_cast<const uint8_t*>(request.readInplace(len)), len);
120 mStatus = OK;
121}
122
123}
124
125extern "C" android::MediaPlayerBase* newPlayer()
126{
Steve Block5baa3a62011-12-20 16:23:08 +0000127 ALOGD("New invoke test player");
Nicolas Catania8f5fcab2009-07-13 14:37:49 -0700128 return new Player();
129}
130
131extern "C" android::status_t deletePlayer(android::MediaPlayerBase *player)
132{
Steve Block5baa3a62011-12-20 16:23:08 +0000133 ALOGD("Delete invoke test player");
Nicolas Catania8f5fcab2009-07-13 14:37:49 -0700134 delete player;
135 return OK;
136}