blob: f917f642cbbdf6c20dce417cac314230909476d2 [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;
Marco Nelissen4110c102012-03-29 09:31:28 -070030class SkipCutBuffer;
Andreas Huberf9334412010-12-15 15:17:42 -080031
32struct NuPlayer : public AHandler {
33 NuPlayer();
34
Andreas Huber9b80c2b2011-06-30 15:47:02 -070035 void setUID(uid_t uid);
36
Andreas Huber43c3e6c2011-01-05 12:17:08 -080037 void setDriver(const wp<NuPlayerDriver> &driver);
Andreas Huberf9334412010-12-15 15:17:42 -080038
39 void setDataSource(const sp<IStreamSource> &source);
Andreas Huber5bc087c2010-12-23 10:27:40 -080040
41 void setDataSource(
42 const char *url, const KeyedVector<String8, String8> *headers);
43
Andreas Huberafed0e12011-09-20 15:39:58 -070044 void setDataSource(int fd, int64_t offset, int64_t length);
45
Glenn Kasten11731182011-02-08 17:26:17 -080046 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Huberf9334412010-12-15 15:17:42 -080047 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
48 void start();
49
Andreas Huber43c3e6c2011-01-05 12:17:08 -080050 void pause();
51 void resume();
52
53 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Huber1aef2112011-01-04 14:01:29 -080054 void resetAsync();
55
Andreas Huber43c3e6c2011-01-05 12:17:08 -080056 // Will notify the driver through "notifySeekComplete" once finished.
57 void seekToAsync(int64_t seekTimeUs);
58
Andreas Huberf9334412010-12-15 15:17:42 -080059protected:
60 virtual ~NuPlayer();
61
62 virtual void onMessageReceived(const sp<AMessage> &msg);
63
64private:
Andreas Huberf9334412010-12-15 15:17:42 -080065 struct Decoder;
Andreas Huberafed0e12011-09-20 15:39:58 -070066 struct GenericSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080067 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080068 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080069 struct Renderer;
Andreas Huberafed0e12011-09-20 15:39:58 -070070 struct RTSPSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080071 struct Source;
72 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080073
74 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070075 kWhatSetDataSource = '=DaS',
76 kWhatSetVideoNativeWindow = '=NaW',
77 kWhatSetAudioSink = '=AuS',
78 kWhatMoreDataQueued = 'more',
79 kWhatStart = 'strt',
80 kWhatScanSources = 'scan',
81 kWhatVideoNotify = 'vidN',
82 kWhatAudioNotify = 'audN',
83 kWhatRendererNotify = 'renN',
84 kWhatReset = 'rset',
85 kWhatSeek = 'seek',
86 kWhatPause = 'paus',
87 kWhatResume = 'rsme',
Andreas Huberf9334412010-12-15 15:17:42 -080088 };
89
Andreas Huber43c3e6c2011-01-05 12:17:08 -080090 wp<NuPlayerDriver> mDriver;
Andreas Huber9b80c2b2011-06-30 15:47:02 -070091 bool mUIDValid;
92 uid_t mUID;
Andreas Huber5bc087c2010-12-23 10:27:40 -080093 sp<Source> mSource;
Glenn Kasten11731182011-02-08 17:26:17 -080094 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080095 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080096 sp<Decoder> mVideoDecoder;
Andreas Huber3fe62152011-09-16 15:09:22 -070097 bool mVideoIsAVC;
Andreas Huberf9334412010-12-15 15:17:42 -080098 sp<Decoder> mAudioDecoder;
99 sp<Renderer> mRenderer;
100
Andreas Huberf9334412010-12-15 15:17:42 -0800101 bool mAudioEOS;
102 bool mVideoEOS;
103
Andreas Huber5bc087c2010-12-23 10:27:40 -0800104 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -0800105 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800106
Andreas Huberf9334412010-12-15 15:17:42 -0800107 enum FlushStatus {
108 NONE,
109 AWAITING_DISCONTINUITY,
110 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800111 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800112 SHUTTING_DOWN_DECODER,
113 FLUSHED,
114 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800115 };
116
Andreas Huber6e3d3112011-11-28 12:36:11 -0800117 // Once the current flush is complete this indicates whether the
118 // notion of time has changed.
119 bool mTimeDiscontinuityPending;
120
Andreas Huberf9334412010-12-15 15:17:42 -0800121 FlushStatus mFlushingAudio;
122 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800123 bool mResetInProgress;
124 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800125
Andreas Huber32f3cef2011-03-02 15:34:46 -0800126 int64_t mSkipRenderingAudioUntilMediaTimeUs;
127 int64_t mSkipRenderingVideoUntilMediaTimeUs;
128
Andreas Huber3fe62152011-09-16 15:09:22 -0700129 int64_t mVideoLateByUs;
130 int64_t mNumFramesTotal, mNumFramesDropped;
131
Marco Nelissen4110c102012-03-29 09:31:28 -0700132 SkipCutBuffer *mSkipCutBuffer;
133
Andreas Huber5bc087c2010-12-23 10:27:40 -0800134 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800135
136 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
137 void renderBuffer(bool audio, const sp<AMessage> &msg);
138
Andreas Huberf9334412010-12-15 15:17:42 -0800139 void notifyListener(int msg, int ext1, int ext2);
140
Andreas Huber3831a062010-12-21 10:22:33 -0800141 void finishFlushIfPossible();
142
Andreas Huber1aef2112011-01-04 14:01:29 -0800143 void flushDecoder(bool audio, bool needShutdown);
144
145 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
146
147 void finishReset();
148 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800149
Andreas Huberf9334412010-12-15 15:17:42 -0800150 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
151};
152
153} // namespace android
154
155#endif // NU_PLAYER_H_