invoke_mock_media_player.cpp revision cc562a3576a6a8096626387472e05e8bee03352a
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::Surface;
29using android::ISurfaceTexture;
30using android::MediaPlayerBase;
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;
39using android::String8;
40using android::KeyedVector;
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
46namespace {
47const char *kPing = "ping";
48
49class 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
59    virtual status_t    setDataSource(
60            const char *url,
61            const KeyedVector<String8, String8> *) {
62        LOGV("setDataSource %s", url);
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;}
71    virtual status_t    setVideoSurface(const sp<Surface>& surface) {return OK;}
72    virtual status_t    setVideoSurfaceTexture(
73                                const sp<ISurfaceTexture>& surfaceTexture) {return OK;}
74    virtual status_t    prepare() {return OK;}
75    virtual status_t    prepareAsync() {return OK;}
76    virtual status_t    start() {return OK;}
77    virtual status_t    stop() {return OK;}
78    virtual status_t    pause() {return OK;}
79    virtual bool        isPlaying() {return true;}
80    virtual status_t    seekTo(int msec) {return OK;}
81    virtual status_t    getCurrentPosition(int *msec) {return OK;}
82    virtual status_t    getDuration(int *msec) {return OK;}
83    virtual status_t    reset() {return OK;}
84    virtual status_t    setLooping(int loop) {return OK;}
85    virtual player_type playerType() {return TEST_PLAYER;}
86    virtual status_t    invoke(const Parcel& request, Parcel *reply);
87
88  private:
89    // Take a request, copy it to the reply.
90    void ping(const Parcel& request, Parcel *reply);
91
92    status_t mStatus;
93    TestType mTest;
94};
95
96status_t Player::invoke(const Parcel& request, Parcel *reply)
97{
98    switch (mTest) {
99        case PING:
100            ping(request, reply);
101            break;
102        default: mStatus = UNKNOWN_ERROR;
103    }
104    return mStatus;
105}
106
107void Player::ping(const Parcel& request, Parcel *reply)
108{
109    const size_t len = request.dataAvail();
110
111    reply->setData(static_cast<const uint8_t*>(request.readInplace(len)), len);
112    mStatus = OK;
113}
114
115}
116
117extern "C" android::MediaPlayerBase* newPlayer()
118{
119    LOGD("New invoke test player");
120    return new Player();
121}
122
123extern "C" android::status_t deletePlayer(android::MediaPlayerBase *player)
124{
125    LOGD("Delete invoke test player");
126    delete player;
127    return OK;
128}
129