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 #ifndef NU_PLAYER_H_
     18 
     19 #define NU_PLAYER_H_
     20 
     21 #include <media/MediaPlayerInterface.h>
     22 #include <media/stagefright/foundation/AHandler.h>
     23 #include <media/stagefright/NativeWindowWrapper.h>
     24 #include <gui/SurfaceTextureClient.h>
     25 #include <surfaceflinger/Surface.h>
     26 
     27 namespace android {
     28 
     29 struct ACodec;
     30 struct MetaData;
     31 struct NuPlayerDriver;
     32 
     33 struct NuPlayer : public AHandler {
     34     NuPlayer();
     35 
     36     void setUID(uid_t uid);
     37 
     38     void setDriver(const wp<NuPlayerDriver> &driver);
     39 
     40     void setDataSource(const sp<IStreamSource> &source);
     41 
     42     void setDataSource(
     43             const char *url, const KeyedVector<String8, String8> *headers);
     44 
     45     void setVideoSurface(const sp<Surface> &surface);
     46     void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
     47     void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
     48     void start();
     49 
     50     void pause();
     51     void resume();
     52 
     53     // Will notify the driver through "notifyResetComplete" once finished.
     54     void resetAsync();
     55 
     56     // Will notify the driver through "notifySeekComplete" once finished.
     57     void seekToAsync(int64_t seekTimeUs);
     58 
     59 protected:
     60     virtual ~NuPlayer();
     61 
     62     virtual void onMessageReceived(const sp<AMessage> &msg);
     63 
     64 private:
     65     struct Decoder;
     66     struct HTTPLiveSource;
     67     struct NuPlayerStreamListener;
     68     struct Renderer;
     69     struct Source;
     70     struct StreamingSource;
     71 
     72     enum {
     73         kWhatSetDataSource              = '=DaS',
     74         kWhatSetVideoNativeWindow       = '=NaW',
     75         kWhatSetAudioSink               = '=AuS',
     76         kWhatMoreDataQueued             = 'more',
     77         kWhatStart                      = 'strt',
     78         kWhatScanSources                = 'scan',
     79         kWhatVideoNotify                = 'vidN',
     80         kWhatAudioNotify                = 'audN',
     81         kWhatRendererNotify             = 'renN',
     82         kWhatReset                      = 'rset',
     83         kWhatSeek                       = 'seek',
     84         kWhatPause                      = 'paus',
     85         kWhatResume                     = 'rsme',
     86     };
     87 
     88     wp<NuPlayerDriver> mDriver;
     89     bool mUIDValid;
     90     uid_t mUID;
     91     sp<Source> mSource;
     92     sp<NativeWindowWrapper> mNativeWindow;
     93     sp<MediaPlayerBase::AudioSink> mAudioSink;
     94     sp<Decoder> mVideoDecoder;
     95     bool mVideoIsAVC;
     96     sp<Decoder> mAudioDecoder;
     97     sp<Renderer> mRenderer;
     98 
     99     bool mAudioEOS;
    100     bool mVideoEOS;
    101 
    102     bool mScanSourcesPending;
    103     int32_t mScanSourcesGeneration;
    104 
    105     enum FlushStatus {
    106         NONE,
    107         AWAITING_DISCONTINUITY,
    108         FLUSHING_DECODER,
    109         FLUSHING_DECODER_SHUTDOWN,
    110         SHUTTING_DOWN_DECODER,
    111         FLUSHED,
    112         SHUT_DOWN,
    113     };
    114 
    115     FlushStatus mFlushingAudio;
    116     FlushStatus mFlushingVideo;
    117     bool mResetInProgress;
    118     bool mResetPostponed;
    119 
    120     int64_t mSkipRenderingAudioUntilMediaTimeUs;
    121     int64_t mSkipRenderingVideoUntilMediaTimeUs;
    122 
    123     int64_t mVideoLateByUs;
    124     int64_t mNumFramesTotal, mNumFramesDropped;
    125 
    126     status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
    127 
    128     status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
    129     void renderBuffer(bool audio, const sp<AMessage> &msg);
    130 
    131     void notifyListener(int msg, int ext1, int ext2);
    132 
    133     void finishFlushIfPossible();
    134 
    135     void flushDecoder(bool audio, bool needShutdown);
    136 
    137     static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
    138 
    139     void finishReset();
    140     void postScanSources();
    141 
    142     DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
    143 };
    144 
    145 }  // namespace android
    146 
    147 #endif  // NU_PLAYER_H_
    148