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