blob: a5382b498909e3922a4e44b92b429bfdabb4360b [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 {
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
115 FlushStatus mFlushingAudio;
116 FlushStatus mFlushingVideo;
Andreas Hubercbeaca72011-01-04 14:01:29 -0800117 bool mResetInProgress;
118 bool mResetPostponed;
Andreas Hubera1587462010-12-15 15:17:42 -0800119
Andreas Huber669ad132011-03-02 15:34:46 -0800120 int64_t mSkipRenderingAudioUntilMediaTimeUs;
121 int64_t mSkipRenderingVideoUntilMediaTimeUs;
122
Andreas Huber950fc9d2011-09-16 15:09:22 -0700123 int64_t mVideoLateByUs;
124 int64_t mNumFramesTotal, mNumFramesDropped;
125
Andreas Huber54e66492010-12-23 10:27:40 -0800126 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Hubera1587462010-12-15 15:17:42 -0800127
128 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
129 void renderBuffer(bool audio, const sp<AMessage> &msg);
130
Andreas Hubera1587462010-12-15 15:17:42 -0800131 void notifyListener(int msg, int ext1, int ext2);
132
Andreas Huber41c3f742010-12-21 10:22:33 -0800133 void finishFlushIfPossible();
134
Andreas Hubercbeaca72011-01-04 14:01:29 -0800135 void flushDecoder(bool audio, bool needShutdown);
136
137 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
138
139 void finishReset();
140 void postScanSources();
Andreas Huber222e6892010-12-22 10:03:04 -0800141
Andreas Hubera1587462010-12-15 15:17:42 -0800142 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
143};
144
145} // namespace android
146
147#endif // NU_PLAYER_H_