1f933441648ef6a71dee783d733aac17b9508b452Andreas Huber/*
2f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Copyright (C) 2010 The Android Open Source Project
3f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
4f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * you may not use this file except in compliance with the License.
6f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * You may obtain a copy of the License at
7f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
8f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9f933441648ef6a71dee783d733aac17b9508b452Andreas Huber *
10f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * Unless required by applicable law or agreed to in writing, software
11f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * See the License for the specific language governing permissions and
14f933441648ef6a71dee783d733aac17b9508b452Andreas Huber * limitations under the License.
15f933441648ef6a71dee783d733aac17b9508b452Andreas Huber */
16f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
17f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/MediaPlayerInterface.h>
18f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
19f933441648ef6a71dee783d733aac17b9508b452Andreas Huber#include <media/stagefright/foundation/ABase.h>
20f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
21f933441648ef6a71dee783d733aac17b9508b452Andreas Hubernamespace android {
22f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
23f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct ALooper;
24f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct NuPlayer;
25f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
26f933441648ef6a71dee783d733aac17b9508b452Andreas Huberstruct NuPlayerDriver : public MediaPlayerInterface {
27f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    NuPlayerDriver();
28f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
29f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t initCheck();
30f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
319b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber    virtual status_t setUID(uid_t uid);
329b80c2bdb205bc143104f54d0743b6eedd67b14eAndreas Huber
33f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t setDataSource(
34f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            const char *url, const KeyedVector<String8, String8> *headers);
35f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
36f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
37f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
38f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t setDataSource(const sp<IStreamSource> &source);
39f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
401173118eace0e9e347cb007f0da817cee87579edGlenn Kasten    virtual status_t setVideoSurfaceTexture(
411173118eace0e9e347cb007f0da817cee87579edGlenn Kasten            const sp<ISurfaceTexture> &surfaceTexture);
42f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t prepare();
43f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t prepareAsync();
44f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t start();
45f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t stop();
46f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t pause();
47f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual bool isPlaying();
48f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t seekTo(int msec);
49f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t getCurrentPosition(int *msec);
50f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t getDuration(int *msec);
51f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t reset();
52f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t setLooping(int loop);
53f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual player_type playerType();
54f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t invoke(const Parcel &request, Parcel *reply);
55f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual void setAudioSink(const sp<AudioSink> &audioSink);
564f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    virtual status_t setParameter(int key, const Parcel &request);
574f9e47f2c03ce36261c4717cd7e131d7940bb068Gloria Wang    virtual status_t getParameter(int key, Parcel *reply);
58f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
59f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual status_t getMetadata(
60f933441648ef6a71dee783d733aac17b9508b452Andreas Huber            const media::Metadata::Filter& ids, Parcel *records);
61f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
623fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    virtual status_t dump(int fd, const Vector<String16> &args) const;
633fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber
6443c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void notifyResetComplete();
6543c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void notifyDuration(int64_t durationUs);
6643c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void notifyPosition(int64_t positionUs);
6743c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    void notifySeekComplete();
683fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    void notifyFrameStats(int64_t numFramesTotal, int64_t numFramesDropped);
69a4af2143ecbd630e946647c1b5f90fda8f61ebb3Andreas Huber    void notifyListener(int msg, int ext1 = 0, int ext2 = 0);
701aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber
71f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprotected:
72f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    virtual ~NuPlayerDriver();
73f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
74f933441648ef6a71dee783d733aac17b9508b452Andreas Huberprivate:
753fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    mutable Mutex mLock;
761aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    Condition mCondition;
7743c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
7843c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    // The following are protected through "mLock"
7943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    // >>>
801aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber    bool mResetInProgress;
8143c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    int64_t mDurationUs;
8243c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    int64_t mPositionUs;
833fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    int64_t mNumFramesTotal;
843fe62150fa3dd6d25cb84aad80bc9e27ddd16c45Andreas Huber    int64_t mNumFramesDropped;
8543c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    // <<<
861aef211b4e5dc952081727bfd2318b2cb5ca4506Andreas Huber
87f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<ALooper> mLooper;
88f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    sp<NuPlayer> mPlayer;
8943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
9043c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    enum State {
9143c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        UNINITIALIZED,
9243c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        STOPPED,
9343c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        PLAYING,
9443c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber        PAUSED
9543c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    };
9643c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
9743c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    State mState;
98a4af2143ecbd630e946647c1b5f90fda8f61ebb3Andreas Huber    bool mAtEOS;
9943c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber
10043c3e6ce02215ca99d506458f596cb1211639f29Andreas Huber    int64_t mStartupSeekTimeUs;
101f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
102f933441648ef6a71dee783d733aac17b9508b452Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
103f933441648ef6a71dee783d733aac17b9508b452Andreas Huber};
104f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
105f933441648ef6a71dee783d733aac17b9508b452Andreas Huber}  // namespace android
106f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
107f933441648ef6a71dee783d733aac17b9508b452Andreas Huber
108