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