blob: 6be14be6c8d72a40d8746222a8cdf552c95a7d4a [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
Glenn Kasten11731182011-02-08 17:26:17 -080043 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Huberf9334412010-12-15 15:17:42 -080044 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
45 void start();
46
Andreas Huber43c3e6c2011-01-05 12:17:08 -080047 void pause();
48 void resume();
49
50 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Huber1aef2112011-01-04 14:01:29 -080051 void resetAsync();
52
Andreas Huber43c3e6c2011-01-05 12:17:08 -080053 // Will notify the driver through "notifySeekComplete" once finished.
54 void seekToAsync(int64_t seekTimeUs);
55
Andreas Huberf9334412010-12-15 15:17:42 -080056protected:
57 virtual ~NuPlayer();
58
59 virtual void onMessageReceived(const sp<AMessage> &msg);
60
61private:
Andreas Huberf9334412010-12-15 15:17:42 -080062 struct Decoder;
Andreas Huber5bc087c2010-12-23 10:27:40 -080063 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080064 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080065 struct Renderer;
66 struct Source;
67 struct StreamingSource;
Andreas Huber2bfdd422011-10-11 15:24:07 -070068 struct RTSPSource;
Andreas Huberf9334412010-12-15 15:17:42 -080069
70 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070071 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',
Andreas Huberf9334412010-12-15 15:17:42 -080084 };
85
Andreas Huber43c3e6c2011-01-05 12:17:08 -080086 wp<NuPlayerDriver> mDriver;
Andreas Huber9b80c2b2011-06-30 15:47:02 -070087 bool mUIDValid;
88 uid_t mUID;
Andreas Huber5bc087c2010-12-23 10:27:40 -080089 sp<Source> mSource;
Glenn Kasten11731182011-02-08 17:26:17 -080090 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080091 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080092 sp<Decoder> mVideoDecoder;
Andreas Huber3fe62152011-09-16 15:09:22 -070093 bool mVideoIsAVC;
Andreas Huberf9334412010-12-15 15:17:42 -080094 sp<Decoder> mAudioDecoder;
95 sp<Renderer> mRenderer;
96
Andreas Huberf9334412010-12-15 15:17:42 -080097 bool mAudioEOS;
98 bool mVideoEOS;
99
Andreas Huber5bc087c2010-12-23 10:27:40 -0800100 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -0800101 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800102
Andreas Huberf9334412010-12-15 15:17:42 -0800103 enum FlushStatus {
104 NONE,
105 AWAITING_DISCONTINUITY,
106 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800107 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800108 SHUTTING_DOWN_DECODER,
109 FLUSHED,
110 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800111 };
112
Andreas Huber6e3d3112011-11-28 12:36:11 -0800113 // Once the current flush is complete this indicates whether the
114 // notion of time has changed.
115 bool mTimeDiscontinuityPending;
116
Andreas Huberf9334412010-12-15 15:17:42 -0800117 FlushStatus mFlushingAudio;
118 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800119 bool mResetInProgress;
120 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800121
Andreas Huber32f3cef2011-03-02 15:34:46 -0800122 int64_t mSkipRenderingAudioUntilMediaTimeUs;
123 int64_t mSkipRenderingVideoUntilMediaTimeUs;
124
Andreas Huber3fe62152011-09-16 15:09:22 -0700125 int64_t mVideoLateByUs;
126 int64_t mNumFramesTotal, mNumFramesDropped;
127
Andreas Huber5bc087c2010-12-23 10:27:40 -0800128 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800129
130 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
131 void renderBuffer(bool audio, const sp<AMessage> &msg);
132
Andreas Huberf9334412010-12-15 15:17:42 -0800133 void notifyListener(int msg, int ext1, int ext2);
134
Andreas Huber3831a062010-12-21 10:22:33 -0800135 void finishFlushIfPossible();
136
Andreas Huber1aef2112011-01-04 14:01:29 -0800137 void flushDecoder(bool audio, bool needShutdown);
138
139 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
140
141 void finishReset();
142 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800143
Andreas Huberf9334412010-12-15 15:17:42 -0800144 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
145};
146
147} // namespace android
148
149#endif // NU_PLAYER_H_