18f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania/*
28f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Copyright (C) 2009 The Android Open Source Project
38f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
48f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Licensed under the Apache License, Version 2.0 (the "License");
58f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * you may not use this file except in compliance with the License.
68f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * You may obtain a copy of the License at
78f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
88f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *      http://www.apache.org/licenses/LICENSE-2.0
98f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania *
108f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * Unless required by applicable law or agreed to in writing, software
118f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * distributed under the License is distributed on an "AS IS" BASIS,
128f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * See the License for the specific language governing permissions and
148f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania * limitations under the License.
158f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania */
168f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
178f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania//#define LOG_NDEBUG 0
188f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#define LOG_TAG "TestPlayerStub"
198f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#include "utils/Log.h"
208f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
218f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania#include <string.h>
228f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
238994837f27e783a10f5cc038a7ae7595aabffdb6niko#include <binder/Parcel.h>
248994837f27e783a10f5cc038a7ae7595aabffdb6niko#include <media/MediaPlayerInterface.h>
258994837f27e783a10f5cc038a7ae7595aabffdb6niko#include <utils/Errors.h>
268f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
278994837f27e783a10f5cc038a7ae7595aabffdb6nikousing android::INVALID_OPERATION;
28e3c01832fc741e9908f047d86cd40db1ea5d78c8Andreas Huberusing android::Surface;
29d47f7d8b5fe3a3861d7cbdc5f912235407823c8eAndy McFaddenusing android::IGraphicBufferProducer;
30d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huberusing android::IMediaHTTPService;
318f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::MediaPlayerBase;
328f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::OK;
338f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::Parcel;
348994837f27e783a10f5cc038a7ae7595aabffdb6nikousing android::SortedVector;
358f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::TEST_PLAYER;
368f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::UNKNOWN_ERROR;
378f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::player_type;
388f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::sp;
398f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniausing android::status_t;
40256430093679e1d62b54fb0c852126e54d162f6fAndreas Huberusing android::String8;
41256430093679e1d62b54fb0c852126e54d162f6fAndreas Huberusing android::KeyedVector;
428f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
438f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// This file contains a test player that is loaded via the
448f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// TestPlayerStub class.  The player contains various implementation
458f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania// of the invoke method that java tests can use.
468f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
478f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catanianamespace {
488f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaconst char *kPing = "ping";
498f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
508f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaclass Player: public MediaPlayerBase
518f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania{
528f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania  public:
538f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    enum TestType {TEST_UNKNOWN, PING};
548f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    Player() {}
558f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual ~Player() {}
568f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
578f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t    initCheck() {return OK;}
588f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual bool        hardwareOutput() {return true;}
598f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
60256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber    virtual status_t    setDataSource(
61a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe            const sp<IMediaHTTPService>& /* httpService */,
62256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber            const char *url,
63256430093679e1d62b54fb0c852126e54d162f6fAndreas Huber            const KeyedVector<String8, String8> *) {
6471f2cf116aab893e224056c38ab146bd1538dd3eSteve Block        ALOGV("setDataSource %s", url);
658f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        mTest = TEST_UNKNOWN;
668f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        if (strncmp(url, kPing, strlen(kPing)) == 0) {
678f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania            mTest = PING;
688f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        }
698f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        return OK;
708f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
718f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
72a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    setDataSource(int /* fd */, int64_t /* offset */, int64_t /* length */) {
73a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe        return OK;
74a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    }
75cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten    virtual status_t    setVideoSurfaceTexture(
76a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe                                const sp<IGraphicBufferProducer>& /* bufferProducer */) {
77a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe        return OK;
78a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    }
79a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    prepare() { return OK; }
80a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    prepareAsync() { return OK; }
81a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    start() { return OK; }
82a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    stop() { return OK; }
83a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    pause() { return OK; }
84a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual bool        isPlaying() { return true; }
85008fb02824775f3ed715737c9450ba2014cd919aWei Jia    virtual status_t    seekTo(int /* msec */, android::MediaPlayerSeekMode /* mode */) { return OK; }
86a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    getCurrentPosition(int* /* msec */) { return OK; }
87a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    getDuration(int* /* msec */) { return OK; }
888f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t    reset() {return OK;}
89a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    setLooping(int /* loop */) { return OK; }
908f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual player_type playerType() {return TEST_PLAYER;}
918f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    virtual status_t    invoke(const Parcel& request, Parcel *reply);
92a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    setParameter(int /* key */, const Parcel& /* request */) { return OK; }
93a4a13480dd056f4109d74fc43c9453adf7fd35fdAndreas Gampe    virtual status_t    getParameter(int /* key */, Parcel* /* reply */) { return OK; }
94d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang
958994837f27e783a10f5cc038a7ae7595aabffdb6niko
968f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania  private:
978f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    // Take a request, copy it to the reply.
988f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    void ping(const Parcel& request, Parcel *reply);
998f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1008f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    status_t mStatus;
1018f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    TestType mTest;
1028f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania};
1038f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1048f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniastatus_t Player::invoke(const Parcel& request, Parcel *reply)
1058f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania{
1068f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    switch (mTest) {
1078f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        case PING:
1088f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania            ping(request, reply);
1098f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania            break;
1108f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania        default: mStatus = UNKNOWN_ERROR;
1118f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    }
1128f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    return mStatus;
1138f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}
1148f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1158f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniavoid Player::ping(const Parcel& request, Parcel *reply)
1168f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania{
1178f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    const size_t len = request.dataAvail();
1188f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1198f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    reply->setData(static_cast<const uint8_t*>(request.readInplace(len)), len);
1208f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    mStatus = OK;
1218f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}
1228f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1238f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}
1248f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1258f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaextern "C" android::MediaPlayerBase* newPlayer()
1268f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania{
1275baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("New invoke test player");
1288f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    return new Player();
1298f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}
1308f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania
1318f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Cataniaextern "C" android::status_t deletePlayer(android::MediaPlayerBase *player)
1328f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania{
1335baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    ALOGD("Delete invoke test player");
1348f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    delete player;
1358f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania    return OK;
1368f5fcab05f1d6f644a9c30f012b8ff302f24a118Nicolas Catania}
137