blob: ffc710ee05c13cab7ee99160aa649a7a42b5e8c7 [file] [log] [blame]
Andreas Hubera1587462010-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 Kastencc562a32011-02-08 17:26:17 -080023#include <media/stagefright/NativeWindowWrapper.h>
24#include <gui/SurfaceTextureClient.h>
25#include <surfaceflinger/Surface.h>
Andreas Hubera1587462010-12-15 15:17:42 -080026
Andreas Hubera1587462010-12-15 15:17:42 -080027namespace android {
28
29struct ACodec;
30struct MetaData;
Andreas Huber08e10cb2011-01-05 12:17:08 -080031struct NuPlayerDriver;
Andreas Hubera1587462010-12-15 15:17:42 -080032
33struct NuPlayer : public AHandler {
34 NuPlayer();
35
Andreas Huber603d7392011-06-30 15:47:02 -070036 void setUID(uid_t uid);
37
Andreas Huber08e10cb2011-01-05 12:17:08 -080038 void setDriver(const wp<NuPlayerDriver> &driver);
Andreas Hubera1587462010-12-15 15:17:42 -080039
40 void setDataSource(const sp<IStreamSource> &source);
Andreas Huber54e66492010-12-23 10:27:40 -080041
42 void setDataSource(
43 const char *url, const KeyedVector<String8, String8> *headers);
44
Glenn Kastencc562a32011-02-08 17:26:17 -080045 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Hubera1587462010-12-15 15:17:42 -080046 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
47 void start();
48
Andreas Huber08e10cb2011-01-05 12:17:08 -080049 void pause();
50 void resume();
51
52 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Hubercbeaca72011-01-04 14:01:29 -080053 void resetAsync();
54
Andreas Huber08e10cb2011-01-05 12:17:08 -080055 // Will notify the driver through "notifySeekComplete" once finished.
56 void seekToAsync(int64_t seekTimeUs);
57
Andreas Hubera1587462010-12-15 15:17:42 -080058protected:
59 virtual ~NuPlayer();
60
61 virtual void onMessageReceived(const sp<AMessage> &msg);
62
63private:
Andreas Hubera1587462010-12-15 15:17:42 -080064 struct Decoder;
Andreas Huber54e66492010-12-23 10:27:40 -080065 struct HTTPLiveSource;
Andreas Hubera1587462010-12-15 15:17:42 -080066 struct NuPlayerStreamListener;
Andreas Huber54e66492010-12-23 10:27:40 -080067 struct Renderer;
68 struct Source;
69 struct StreamingSource;
Andreas Hubera6be6dc2011-10-11 15:24:07 -070070 struct RTSPSource;
Andreas Hubera1587462010-12-15 15:17:42 -080071
72 enum {
Andreas Huber115cac82011-09-15 12:25:04 -070073 kWhatSetDataSource = '=DaS',
74 kWhatSetVideoNativeWindow = '=NaW',
75 kWhatSetAudioSink = '=AuS',
76 kWhatMoreDataQueued = 'more',
77 kWhatStart = 'strt',
78 kWhatScanSources = 'scan',
79 kWhatVideoNotify = 'vidN',
80 kWhatAudioNotify = 'audN',
81 kWhatRendererNotify = 'renN',
82 kWhatReset = 'rset',
83 kWhatSeek = 'seek',
84 kWhatPause = 'paus',
85 kWhatResume = 'rsme',
Andreas Hubera1587462010-12-15 15:17:42 -080086 };
87
Andreas Huber08e10cb2011-01-05 12:17:08 -080088 wp<NuPlayerDriver> mDriver;
Andreas Huber603d7392011-06-30 15:47:02 -070089 bool mUIDValid;
90 uid_t mUID;
Andreas Huber54e66492010-12-23 10:27:40 -080091 sp<Source> mSource;
Glenn Kastencc562a32011-02-08 17:26:17 -080092 sp<NativeWindowWrapper> mNativeWindow;
Andreas Hubera1587462010-12-15 15:17:42 -080093 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Hubera1587462010-12-15 15:17:42 -080094 sp<Decoder> mVideoDecoder;
Andreas Huber950fc9d2011-09-16 15:09:22 -070095 bool mVideoIsAVC;
Andreas Hubera1587462010-12-15 15:17:42 -080096 sp<Decoder> mAudioDecoder;
97 sp<Renderer> mRenderer;
98
Andreas Hubera1587462010-12-15 15:17:42 -080099 bool mAudioEOS;
100 bool mVideoEOS;
101
Andreas Huber54e66492010-12-23 10:27:40 -0800102 bool mScanSourcesPending;
Andreas Hubercbeaca72011-01-04 14:01:29 -0800103 int32_t mScanSourcesGeneration;
Andreas Huber54e66492010-12-23 10:27:40 -0800104
Andreas Hubera1587462010-12-15 15:17:42 -0800105 enum FlushStatus {
106 NONE,
107 AWAITING_DISCONTINUITY,
108 FLUSHING_DECODER,
Andreas Hubercbeaca72011-01-04 14:01:29 -0800109 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber41c3f742010-12-21 10:22:33 -0800110 SHUTTING_DOWN_DECODER,
111 FLUSHED,
112 SHUT_DOWN,
Andreas Hubera1587462010-12-15 15:17:42 -0800113 };
114
Andreas Huber66a051a2011-11-28 12:36:11 -0800115 // Once the current flush is complete this indicates whether the
116 // notion of time has changed.
117 bool mTimeDiscontinuityPending;
118
Andreas Hubera1587462010-12-15 15:17:42 -0800119 FlushStatus mFlushingAudio;
120 FlushStatus mFlushingVideo;
Andreas Hubercbeaca72011-01-04 14:01:29 -0800121 bool mResetInProgress;
122 bool mResetPostponed;
Andreas Hubera1587462010-12-15 15:17:42 -0800123
Andreas Huber669ad132011-03-02 15:34:46 -0800124 int64_t mSkipRenderingAudioUntilMediaTimeUs;
125 int64_t mSkipRenderingVideoUntilMediaTimeUs;
126
Andreas Huber950fc9d2011-09-16 15:09:22 -0700127 int64_t mVideoLateByUs;
128 int64_t mNumFramesTotal, mNumFramesDropped;
129
Andreas Huber54e66492010-12-23 10:27:40 -0800130 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Hubera1587462010-12-15 15:17:42 -0800131
132 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
133 void renderBuffer(bool audio, const sp<AMessage> &msg);
134
Andreas Hubera1587462010-12-15 15:17:42 -0800135 void notifyListener(int msg, int ext1, int ext2);
136
Andreas Huber41c3f742010-12-21 10:22:33 -0800137 void finishFlushIfPossible();
138
Andreas Hubercbeaca72011-01-04 14:01:29 -0800139 void flushDecoder(bool audio, bool needShutdown);
140
141 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
142
143 void finishReset();
144 void postScanSources();
Andreas Huber222e6892010-12-22 10:03:04 -0800145
Andreas Hubera1587462010-12-15 15:17:42 -0800146 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
147};
148
149} // namespace android
150
151#endif // NU_PLAYER_H_