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