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