NuPlayer.h revision 43c3e6ce02215ca99d506458f596cb1211639f29
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
24namespace android {
25
26struct ACodec;
27struct MetaData;
28struct NuPlayerDriver;
29
30struct NuPlayer : public AHandler {
31    NuPlayer();
32
33    void setDriver(const wp<NuPlayerDriver> &driver);
34
35    void setDataSource(const sp<IStreamSource> &source);
36
37    void setDataSource(
38            const char *url, const KeyedVector<String8, String8> *headers);
39
40    void setVideoSurface(const sp<Surface> &surface);
41    void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
42    void start();
43
44    void pause();
45    void resume();
46
47    // Will notify the driver through "notifyResetComplete" once finished.
48    void resetAsync();
49
50    // Will notify the driver through "notifySeekComplete" once finished.
51    void seekToAsync(int64_t seekTimeUs);
52
53protected:
54    virtual ~NuPlayer();
55
56    virtual void onMessageReceived(const sp<AMessage> &msg);
57
58private:
59    struct Decoder;
60    struct HTTPLiveSource;
61    struct NuPlayerStreamListener;
62    struct Renderer;
63    struct Source;
64    struct StreamingSource;
65
66    enum {
67        kWhatSetDataSource,
68        kWhatSetVideoSurface,
69        kWhatSetAudioSink,
70        kWhatMoreDataQueued,
71        kWhatStart,
72        kWhatScanSources,
73        kWhatVideoNotify,
74        kWhatAudioNotify,
75        kWhatRendererNotify,
76        kWhatReset,
77        kWhatSeek,
78    };
79
80    wp<NuPlayerDriver> mDriver;
81    sp<Source> mSource;
82    sp<Surface> mSurface;
83    sp<MediaPlayerBase::AudioSink> mAudioSink;
84    sp<Decoder> mVideoDecoder;
85    sp<Decoder> mAudioDecoder;
86    sp<Renderer> mRenderer;
87
88    bool mAudioEOS;
89    bool mVideoEOS;
90
91    bool mScanSourcesPending;
92    int32_t mScanSourcesGeneration;
93
94    enum FlushStatus {
95        NONE,
96        AWAITING_DISCONTINUITY,
97        FLUSHING_DECODER,
98        FLUSHING_DECODER_SHUTDOWN,
99        SHUTTING_DOWN_DECODER,
100        FLUSHED,
101        SHUT_DOWN,
102    };
103
104    FlushStatus mFlushingAudio;
105    FlushStatus mFlushingVideo;
106    bool mResetInProgress;
107    bool mResetPostponed;
108
109    status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
110
111    status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
112    void renderBuffer(bool audio, const sp<AMessage> &msg);
113
114    void notifyListener(int msg, int ext1, int ext2);
115
116    void finishFlushIfPossible();
117
118    void flushDecoder(bool audio, bool needShutdown);
119
120    static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
121
122    void finishReset();
123    void postScanSources();
124
125    DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
126};
127
128}  // namespace android
129
130#endif  // NU_PLAYER_H_
131