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