Home | History | Annotate | Download | only in nuplayer
      1 /*
      2  * Copyright (C) 2010 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 #include <media/MediaPlayerInterface.h>
     18 
     19 #include <media/stagefright/foundation/ABase.h>
     20 
     21 namespace android {
     22 
     23 struct ALooper;
     24 struct NuPlayer;
     25 
     26 struct NuPlayerDriver : public MediaPlayerInterface {
     27     NuPlayerDriver();
     28 
     29     virtual status_t initCheck();
     30 
     31     virtual status_t setUID(uid_t uid);
     32 
     33     virtual status_t setDataSource(
     34             const char *url, const KeyedVector<String8, String8> *headers);
     35 
     36     virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
     37 
     38     virtual status_t setDataSource(const sp<IStreamSource> &source);
     39 
     40     virtual status_t setVideoSurfaceTexture(
     41             const sp<IGraphicBufferProducer> &bufferProducer);
     42     virtual status_t prepare();
     43     virtual status_t prepareAsync();
     44     virtual status_t start();
     45     virtual status_t stop();
     46     virtual status_t pause();
     47     virtual bool isPlaying();
     48     virtual status_t seekTo(int msec);
     49     virtual status_t getCurrentPosition(int *msec);
     50     virtual status_t getDuration(int *msec);
     51     virtual status_t reset();
     52     virtual status_t setLooping(int loop);
     53     virtual player_type playerType();
     54     virtual status_t invoke(const Parcel &request, Parcel *reply);
     55     virtual void setAudioSink(const sp<AudioSink> &audioSink);
     56     virtual status_t setParameter(int key, const Parcel &request);
     57     virtual status_t getParameter(int key, Parcel *reply);
     58 
     59     virtual status_t getMetadata(
     60             const media::Metadata::Filter& ids, Parcel *records);
     61 
     62     virtual status_t dump(int fd, const Vector<String16> &args) const;
     63 
     64     void notifySetDataSourceCompleted(status_t err);
     65     void notifyPrepareCompleted(status_t err);
     66     void notifyResetComplete();
     67     void notifySetSurfaceComplete();
     68     void notifyDuration(int64_t durationUs);
     69     void notifyPosition(int64_t positionUs);
     70     void notifySeekComplete();
     71     void notifyFrameStats(int64_t numFramesTotal, int64_t numFramesDropped);
     72     void notifyListener(int msg, int ext1 = 0, int ext2 = 0);
     73     void notifyFlagsChanged(uint32_t flags);
     74 
     75 protected:
     76     virtual ~NuPlayerDriver();
     77 
     78 private:
     79     enum State {
     80         STATE_IDLE,
     81         STATE_SET_DATASOURCE_PENDING,
     82         STATE_UNPREPARED,
     83         STATE_PREPARING,
     84         STATE_PREPARED,
     85         STATE_RUNNING,
     86         STATE_PAUSED,
     87         STATE_RESET_IN_PROGRESS,
     88     };
     89 
     90     mutable Mutex mLock;
     91     Condition mCondition;
     92 
     93     State mState;
     94 
     95     bool mIsAsyncPrepare;
     96     status_t mAsyncResult;
     97 
     98     // The following are protected through "mLock"
     99     // >>>
    100     bool mSetSurfaceInProgress;
    101     int64_t mDurationUs;
    102     int64_t mPositionUs;
    103     int64_t mNumFramesTotal;
    104     int64_t mNumFramesDropped;
    105     // <<<
    106 
    107     sp<ALooper> mLooper;
    108     sp<NuPlayer> mPlayer;
    109     uint32_t mPlayerFlags;
    110 
    111     bool mAtEOS;
    112 
    113     int64_t mStartupSeekTimeUs;
    114 
    115     status_t prepare_l();
    116 
    117     DISALLOW_EVIL_CONSTRUCTORS(NuPlayerDriver);
    118 };
    119 
    120 }  // namespace android
    121 
    122 
    123