blob: 25766e0038873ae5c5973a9b65511d04f1ea26df [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
Andreas Huberf9334412010-12-15 15:17:42 -080058protected:
59 virtual ~NuPlayer();
60
61 virtual void onMessageReceived(const sp<AMessage> &msg);
62
63private:
Andreas Huberf9334412010-12-15 15:17:42 -080064 struct Decoder;
Andreas Huberafed0e12011-09-20 15:39:58 -070065 struct GenericSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080066 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080067 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080068 struct Renderer;
Andreas Huberafed0e12011-09-20 15:39:58 -070069 struct RTSPSource;
Andreas Huber5bc087c2010-12-23 10:27:40 -080070 struct Source;
71 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080072
73 enum {
Andreas Huber078cfcf2011-09-15 12:25:04 -070074 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',
Andreas Huberf9334412010-12-15 15:17:42 -080087 };
88
Andreas Huber43c3e6c2011-01-05 12:17:08 -080089 wp<NuPlayerDriver> mDriver;
Andreas Huber9b80c2b2011-06-30 15:47:02 -070090 bool mUIDValid;
91 uid_t mUID;
Andreas Huber5bc087c2010-12-23 10:27:40 -080092 sp<Source> mSource;
Glenn Kasten11731182011-02-08 17:26:17 -080093 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080094 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080095 sp<Decoder> mVideoDecoder;
Andreas Huber3fe62152011-09-16 15:09:22 -070096 bool mVideoIsAVC;
Andreas Huberf9334412010-12-15 15:17:42 -080097 sp<Decoder> mAudioDecoder;
98 sp<Renderer> mRenderer;
99
Andreas Huberf9334412010-12-15 15:17:42 -0800100 bool mAudioEOS;
101 bool mVideoEOS;
102
Andreas Huber5bc087c2010-12-23 10:27:40 -0800103 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -0800104 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -0800105
Andreas Huberf9334412010-12-15 15:17:42 -0800106 enum FlushStatus {
107 NONE,
108 AWAITING_DISCONTINUITY,
109 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800110 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800111 SHUTTING_DOWN_DECODER,
112 FLUSHED,
113 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800114 };
115
Andreas Huber6e3d3112011-11-28 12:36:11 -0800116 // Once the current flush is complete this indicates whether the
117 // notion of time has changed.
118 bool mTimeDiscontinuityPending;
119
Andreas Huberf9334412010-12-15 15:17:42 -0800120 FlushStatus mFlushingAudio;
121 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800122 bool mResetInProgress;
123 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800124
Andreas Huber32f3cef2011-03-02 15:34:46 -0800125 int64_t mSkipRenderingAudioUntilMediaTimeUs;
126 int64_t mSkipRenderingVideoUntilMediaTimeUs;
127
Andreas Huber3fe62152011-09-16 15:09:22 -0700128 int64_t mVideoLateByUs;
129 int64_t mNumFramesTotal, mNumFramesDropped;
130
Andreas Huber5bc087c2010-12-23 10:27:40 -0800131 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800132
133 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
134 void renderBuffer(bool audio, const sp<AMessage> &msg);
135
Andreas Huberf9334412010-12-15 15:17:42 -0800136 void notifyListener(int msg, int ext1, int ext2);
137
Andreas Huber3831a062010-12-21 10:22:33 -0800138 void finishFlushIfPossible();
139
Andreas Huber1aef2112011-01-04 14:01:29 -0800140 void flushDecoder(bool audio, bool needShutdown);
141
142 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
143
144 void finishReset();
145 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800146
Andreas Huberf9334412010-12-15 15:17:42 -0800147 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
148};
149
150} // namespace android
151
152#endif // NU_PLAYER_H_