1a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber/*
2a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * Copyright (C) 2010 The Android Open Source Project
3a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber *
4a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * you may not use this file except in compliance with the License.
6a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * You may obtain a copy of the License at
7a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber *
8a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber *
10a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * Unless required by applicable law or agreed to in writing, software
11a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * See the License for the specific language governing permissions and
14a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber * limitations under the License.
15a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber */
16a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
17a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber#include <media/MediaPlayerInterface.h>
18a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
19a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber#include <media/stagefright/foundation/ABase.h>
20a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
21a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Hubernamespace android {
22a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
23a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huberstruct ALooper;
24a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huberstruct NuPlayer;
25a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
26a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huberstruct NuPlayerDriver : public MediaPlayerInterface {
27a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    NuPlayerDriver();
28a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
29a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t initCheck();
30a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
31603d739b5a444c52b63f1ec7cd2098034151ad25Andreas Huber    virtual status_t setUID(uid_t uid);
32603d739b5a444c52b63f1ec7cd2098034151ad25Andreas Huber
33a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t setDataSource(
34a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber            const char *url, const KeyedVector<String8, String8> *headers);
35a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
36a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
37a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
38a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t setDataSource(const sp<IStreamSource> &source);
39a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
40cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten    virtual status_t setVideoSurfaceTexture(
41cc562a3576a6a8096626387472e05e8bee03352aGlenn Kasten            const sp<ISurfaceTexture> &surfaceTexture);
42a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t prepare();
43a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t prepareAsync();
44a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t start();
45a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t stop();
46a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t pause();
47a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual bool isPlaying();
48a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t seekTo(int msec);
49a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t getCurrentPosition(int *msec);
50a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t getDuration(int *msec);
51a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t reset();
52a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t setLooping(int loop);
53a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual player_type playerType();
54a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t invoke(const Parcel &request, Parcel *reply);
55a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual void setAudioSink(const sp<AudioSink> &audioSink);
56d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang    virtual status_t setParameter(int key, const Parcel &request);
57d01ec6eab019e46398975202e9e4a198a603ad99Gloria Wang    virtual status_t getParameter(int key, Parcel *reply);
58a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
59a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual status_t getMetadata(
60a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber            const media::Metadata::Filter& ids, Parcel *records);
61a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
62950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber    virtual status_t dump(int fd, const Vector<String16> &args) const;
63950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber
6408e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    void notifyResetComplete();
6508e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    void notifyDuration(int64_t durationUs);
6608e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    void notifyPosition(int64_t positionUs);
6708e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    void notifySeekComplete();
68950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber    void notifyFrameStats(int64_t numFramesTotal, int64_t numFramesDropped);
69e96e84b577244d74f79a449d720b0f8224b4b937Andreas Huber    void notifyListener(int msg, int ext1 = 0, int ext2 = 0);
70cbeaca7a819cc11724f6f34457dabf5bd55a84a1Andreas Huber
71a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huberprotected:
72a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    virtual ~NuPlayerDriver();
73a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
74a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huberprivate:
75950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber    mutable Mutex mLock;
76cbeaca7a819cc11724f6f34457dabf5bd55a84a1Andreas Huber    Condition mCondition;
7708e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber
7808e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    // The following are protected through "mLock"
7908e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    // >>>
80cbeaca7a819cc11724f6f34457dabf5bd55a84a1Andreas Huber    bool mResetInProgress;
8108e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    int64_t mDurationUs;
8208e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    int64_t mPositionUs;
83950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber    int64_t mNumFramesTotal;
84950fc9d1159bfc38e2b58a2ccf4465c630573126Andreas Huber    int64_t mNumFramesDropped;
8508e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    // <<<
86cbeaca7a819cc11724f6f34457dabf5bd55a84a1Andreas Huber
87a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    sp<ALooper> mLooper;
88a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    sp<NuPlayer> mPlayer;
8908e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber
9008e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    enum State {
9108e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber        UNINITIALIZED,
9208e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber        STOPPED,
9308e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber        PLAYING,
9408e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber        PAUSED
9508e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    };
9608e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber
9708e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    State mState;
98e96e84b577244d74f79a449d720b0f8224b4b937Andreas Huber    bool mAtEOS;
9908e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber
10008e10cb404c0f1620ca9db7494ccbb8adcca5ee5Andreas Huber    int64_t mStartupSeekTimeUs;
101a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
102a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber    DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
103a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber};
104a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
105a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber}  // namespace android
106a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
107a15874665fa785c82afa9f2e8cb3512470c297cbAndreas Huber
108