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