summaryrefslogtreecommitdiffstats
path: root/media/tests/players/invoke_mock_media_player.cpp
blob: d1fed7bb95d978ed83120eff5f01d8c3e35974ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "TestPlayerStub"
#include "utils/Log.h"

#include <string.h>

#include <binder/Parcel.h>
#include <media/MediaPlayerInterface.h>
#include <utils/Errors.h>

using android::INVALID_OPERATION;
using android::Surface;
using android::IGraphicBufferProducer;
using android::IMediaHTTPService;
using android::MediaPlayerBase;
using android::OK;
using android::Parcel;
using android::SortedVector;
using android::TEST_PLAYER;
using android::UNKNOWN_ERROR;
using android::player_type;
using android::sp;
using android::status_t;
using android::String8;
using android::KeyedVector;

// This file contains a test player that is loaded via the
// TestPlayerStub class.  The player contains various implementation
// of the invoke method that java tests can use.

namespace {
const char *kPing = "ping";

class Player: public MediaPlayerBase
{
  public:
    enum TestType {TEST_UNKNOWN, PING};
    Player() {}
    virtual ~Player() {}

    virtual status_t    initCheck() {return OK;}
    virtual bool        hardwareOutput() {return true;}

    virtual status_t    setDataSource(
            const sp<IMediaHTTPService> &httpService,
            const char *url,
            const KeyedVector<String8, String8> *) {
        ALOGV("setDataSource %s", url);
        mTest = TEST_UNKNOWN;
        if (strncmp(url, kPing, strlen(kPing)) == 0) {
            mTest = PING;
        }
        return OK;
    }

    virtual status_t    setDataSource(int fd, int64_t offset, int64_t length) {return OK;}
    virtual status_t    setVideoSurfaceTexture(
                                const sp<IGraphicBufferProducer>& bufferProducer) {return OK;}
    virtual status_t    prepare() {return OK;}
    virtual status_t    prepareAsync() {return OK;}
    virtual status_t    start() {return OK;}
    virtual status_t    stop() {return OK;}
    virtual status_t    pause() {return OK;}
    virtual bool        isPlaying() {return true;}
    virtual status_t    seekTo(int msec) {return OK;}
    virtual status_t    getCurrentPosition(int *msec) {return OK;}
    virtual status_t    getDuration(int *msec) {return OK;}
    virtual status_t    reset() {return OK;}
    virtual status_t    setLooping(int loop) {return OK;}
    virtual player_type playerType() {return TEST_PLAYER;}
    virtual status_t    invoke(const Parcel& request, Parcel *reply);
    virtual status_t    setParameter(int key, const Parcel &request) {return OK;}
    virtual status_t    getParameter(int key, Parcel *reply) {return OK;}


  private:
    // Take a request, copy it to the reply.
    void ping(const Parcel& request, Parcel *reply);

    status_t mStatus;
    TestType mTest;
};

status_t Player::invoke(const Parcel& request, Parcel *reply)
{
    switch (mTest) {
        case PING:
            ping(request, reply);
            break;
        default: mStatus = UNKNOWN_ERROR;
    }
    return mStatus;
}

void Player::ping(const Parcel& request, Parcel *reply)
{
    const size_t len = request.dataAvail();

    reply->setData(static_cast<const uint8_t*>(request.readInplace(len)), len);
    mStatus = OK;
}

}

extern "C" android::MediaPlayerBase* newPlayer()
{
    ALOGD("New invoke test player");
    return new Player();
}

extern "C" android::status_t deletePlayer(android::MediaPlayerBase *player)
{
    ALOGD("Delete invoke test player");
    delete player;
    return OK;
}