blob: 6e174e0acab4f953042c6c56ba06a4c654bca24d [file] [log] [blame]
Andreas Huberf9334412010-12-15 15:17:42 -08001/*
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>
Glenn Kasten11731182011-02-08 17:26:17 -080023#include <media/stagefright/NativeWindowWrapper.h>
Andreas Huberf9334412010-12-15 15:17:42 -080024
Andreas Huberf9334412010-12-15 15:17:42 -080025namespace android {
26
27struct ACodec;
28struct MetaData;
Andreas Huber43c3e6c2011-01-05 12:17:08 -080029struct NuPlayerDriver;
Andreas Huberf9334412010-12-15 15:17:42 -080030
31struct NuPlayer : public AHandler {
32 NuPlayer();
33
Andreas Huber9b80c2b2011-06-30 15:47:02 -070034 void setUID(uid_t uid);
35
Andreas Huber43c3e6c2011-01-05 12:17:08 -080036 void setDriver(const wp<NuPlayerDriver> &driver);
Andreas Huberf9334412010-12-15 15:17:42 -080037
38 void setDataSource(const sp<IStreamSource> &source);
Andreas Huber5bc087c2010-12-23 10:27:40 -080039
40 void setDataSource(
41 const char *url, const KeyedVector<String8, String8> *headers);
42
Andreas Huberafed0e12011-09-20 15:39:58 -070043 void setDataSource(int fd, int64_t offset, int64_t length);
44
Glenn Kasten11731182011-02-08 17:26:17 -080045 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Huberf9334412010-12-15 15:17:42 -080046 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
47 void start();
48
Andreas Huber43c3e6c2011-01-05 12:17:08 -080049 void pause();
50 void resume();
51
52 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Huber1aef2112011-01-04 14:01:29 -080053 void resetAsync();
54
Andreas Huber43c3e6c2011-01-05 12:17:08 -080055 // Will notify the driver through "notifySeekComplete" once finished.
56 void seekToAsync(int64_t seekTimeUs);
57
James Dong0d268a32012-08-31 12:18:27 -070058 status_t setVideoScalingMode(int32_t mode);
59
Andreas Huberf9334412010-12-15 15:17:42 -080060protected:
61 virtual ~NuPlayer();
62
63 virtual void onMessageReceived(const sp<AMessage> &msg);
64
Andreas Huber84066782011-08-16 09:34:26 -070065public:
66 struct NuPlayerStreamListener;
67 struct Source;
68
Andreas Huberf9334412010-12-15 15:17:42 -080069private:
Andreas Huberf9334412010-12-15 15:17:42 -080070 struct Decoder;
Andreas Huberafed0e12011-09-20 15:39:58 -070071 struct GenericSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080072 struct HTTPLiveSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080073 struct Renderer;
Andreas Huberafed0e12011-09-20 15:39:58 -070074 struct RTSPSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080075 struct StreamingSource;
Andreas Hubera1f8ab02012-11-30 10:53:22 -080076 struct Action;
77 struct SeekAction;
78 struct SimpleAction;
Andreas Huberf9334412010-12-15 15:17:42 -080079
80 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070081 kWhatSetDataSource = '=DaS',
82 kWhatSetVideoNativeWindow = '=NaW',
83 kWhatSetAudioSink = '=AuS',
84 kWhatMoreDataQueued = 'more',
85 kWhatStart = 'strt',
86 kWhatScanSources = 'scan',
87 kWhatVideoNotify = 'vidN',
88 kWhatAudioNotify = 'audN',
89 kWhatRendererNotify = 'renN',
90 kWhatReset = 'rset',
91 kWhatSeek = 'seek',
92 kWhatPause = 'paus',
93 kWhatResume = 'rsme',
Andreas Huberb7c8e912012-11-27 15:02:53 -080094 kWhatPollDuration = 'polD',
Andreas Huberf9334412010-12-15 15:17:42 -080095 };
96
Andreas Huber43c3e6c2011-01-05 12:17:08 -080097 wp<NuPlayerDriver> mDriver;
Andreas Huber9b80c2b2011-06-30 15:47:02 -070098 bool mUIDValid;
99 uid_t mUID;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800100 sp<Source> mSource;
Glenn Kasten11731182011-02-08 17:26:17 -0800101 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -0800102 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -0800103 sp<Decoder> mVideoDecoder;
Andreas Huber3fe62152011-09-16 15:09:22 -0700104 bool mVideoIsAVC;
Andreas Huberf9334412010-12-15 15:17:42 -0800105 sp<Decoder> mAudioDecoder;
106 sp<Renderer> mRenderer;
107
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800108 List<sp<Action> > mDeferredActions;
109
Andreas Huberf9334412010-12-15 15:17:42 -0800110 bool mAudioEOS;
111 bool mVideoEOS;
112
Andreas Huber5bc087c2010-12-23 10:27:40 -0800113 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -0800114 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800115
Andreas Huberb7c8e912012-11-27 15:02:53 -0800116 int32_t mPollDurationGeneration;
117
Andreas Huberf9334412010-12-15 15:17:42 -0800118 enum FlushStatus {
119 NONE,
120 AWAITING_DISCONTINUITY,
121 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800122 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800123 SHUTTING_DOWN_DECODER,
124 FLUSHED,
125 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800126 };
127
Andreas Huber6e3d3112011-11-28 12:36:11 -0800128 // Once the current flush is complete this indicates whether the
129 // notion of time has changed.
130 bool mTimeDiscontinuityPending;
131
Andreas Huberf9334412010-12-15 15:17:42 -0800132 FlushStatus mFlushingAudio;
133 FlushStatus mFlushingVideo;
134
Andreas Huber32f3cef2011-03-02 15:34:46 -0800135 int64_t mSkipRenderingAudioUntilMediaTimeUs;
136 int64_t mSkipRenderingVideoUntilMediaTimeUs;
137
Andreas Huber3fe62152011-09-16 15:09:22 -0700138 int64_t mVideoLateByUs;
139 int64_t mNumFramesTotal, mNumFramesDropped;
140
James Dong0d268a32012-08-31 12:18:27 -0700141 int32_t mVideoScalingMode;
142
Andreas Huber5bc087c2010-12-23 10:27:40 -0800143 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800144
145 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
146 void renderBuffer(bool audio, const sp<AMessage> &msg);
147
Andreas Huberf9334412010-12-15 15:17:42 -0800148 void notifyListener(int msg, int ext1, int ext2);
149
Andreas Huber3831a062010-12-21 10:22:33 -0800150 void finishFlushIfPossible();
151
Andreas Huber1aef2112011-01-04 14:01:29 -0800152 void flushDecoder(bool audio, bool needShutdown);
153
154 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
155
Andreas Huber1aef2112011-01-04 14:01:29 -0800156 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800157
Andreas Huberb7c8e912012-11-27 15:02:53 -0800158 void schedulePollDuration();
159 void cancelPollDuration();
160
Andreas Hubera1f8ab02012-11-30 10:53:22 -0800161 void processDeferredActions();
162
163 void performSeek(int64_t seekTimeUs);
164 void performDecoderFlush();
165 void performDecoderShutdown();
166 void performReset();
167 void performScanSources();
168
Andreas Huberf9334412010-12-15 15:17:42 -0800169 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
170};
171
172} // namespace android
173
174#endif // NU_PLAYER_H_