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