blob: cf9185b814d942c8026ce3d492153d8403c7cfb2 [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
Andreas Hubera1587462010-12-15 15:17:42 -080045 void setVideoSurface(const sp<Surface> &surface);
Glenn Kastencc562a32011-02-08 17:26:17 -080046 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Hubera1587462010-12-15 15:17:42 -080047 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
48 void start();
49
Andreas Huber08e10cb2011-01-05 12:17:08 -080050 void pause();
51 void resume();
52
53 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Hubercbeaca72011-01-04 14:01:29 -080054 void resetAsync();
55
Andreas Huber08e10cb2011-01-05 12:17:08 -080056 // Will notify the driver through "notifySeekComplete" once finished.
57 void seekToAsync(int64_t seekTimeUs);
58
Andreas Hubera1587462010-12-15 15:17:42 -080059protected:
60 virtual ~NuPlayer();
61
62 virtual void onMessageReceived(const sp<AMessage> &msg);
63
64private:
Andreas Hubera1587462010-12-15 15:17:42 -080065 struct Decoder;
Andreas Huber54e66492010-12-23 10:27:40 -080066 struct HTTPLiveSource;
Andreas Hubera1587462010-12-15 15:17:42 -080067 struct NuPlayerStreamListener;
Andreas Huber54e66492010-12-23 10:27:40 -080068 struct Renderer;
69 struct Source;
70 struct StreamingSource;
Andreas Hubera1587462010-12-15 15:17:42 -080071
72 enum {
73 kWhatSetDataSource,
Glenn Kastencc562a32011-02-08 17:26:17 -080074 kWhatSetVideoNativeWindow,
Andreas Hubera1587462010-12-15 15:17:42 -080075 kWhatSetAudioSink,
76 kWhatMoreDataQueued,
77 kWhatStart,
78 kWhatScanSources,
79 kWhatVideoNotify,
80 kWhatAudioNotify,
81 kWhatRendererNotify,
Andreas Hubercbeaca72011-01-04 14:01:29 -080082 kWhatReset,
Andreas Huber08e10cb2011-01-05 12:17:08 -080083 kWhatSeek,
Andreas Huber601fe0e2011-01-20 15:23:04 -080084 kWhatPause,
85 kWhatResume,
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;
95 sp<Decoder> mAudioDecoder;
96 sp<Renderer> mRenderer;
97
Andreas Hubera1587462010-12-15 15:17:42 -080098 bool mAudioEOS;
99 bool mVideoEOS;
100
Andreas Huber54e66492010-12-23 10:27:40 -0800101 bool mScanSourcesPending;
Andreas Hubercbeaca72011-01-04 14:01:29 -0800102 int32_t mScanSourcesGeneration;
Andreas Huber54e66492010-12-23 10:27:40 -0800103
Andreas Hubera1587462010-12-15 15:17:42 -0800104 enum FlushStatus {
105 NONE,
106 AWAITING_DISCONTINUITY,
107 FLUSHING_DECODER,
Andreas Hubercbeaca72011-01-04 14:01:29 -0800108 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber41c3f742010-12-21 10:22:33 -0800109 SHUTTING_DOWN_DECODER,
110 FLUSHED,
111 SHUT_DOWN,
Andreas Hubera1587462010-12-15 15:17:42 -0800112 };
113
114 FlushStatus mFlushingAudio;
115 FlushStatus mFlushingVideo;
Andreas Hubercbeaca72011-01-04 14:01:29 -0800116 bool mResetInProgress;
117 bool mResetPostponed;
Andreas Hubera1587462010-12-15 15:17:42 -0800118
Andreas Huber669ad132011-03-02 15:34:46 -0800119 int64_t mSkipRenderingAudioUntilMediaTimeUs;
120 int64_t mSkipRenderingVideoUntilMediaTimeUs;
121
Andreas Huber54e66492010-12-23 10:27:40 -0800122 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Hubera1587462010-12-15 15:17:42 -0800123
124 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
125 void renderBuffer(bool audio, const sp<AMessage> &msg);
126
Andreas Hubera1587462010-12-15 15:17:42 -0800127 void notifyListener(int msg, int ext1, int ext2);
128
Andreas Huber41c3f742010-12-21 10:22:33 -0800129 void finishFlushIfPossible();
130
Andreas Hubercbeaca72011-01-04 14:01:29 -0800131 void flushDecoder(bool audio, bool needShutdown);
132
133 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
134
135 void finishReset();
136 void postScanSources();
Andreas Huber222e6892010-12-22 10:03:04 -0800137
Andreas Hubera1587462010-12-15 15:17:42 -0800138 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
139};
140
141} // namespace android
142
143#endif // NU_PLAYER_H_