blob: e7c6a4262933a48520347e9f8f5a0f378eb30cc9 [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>
24#include <gui/SurfaceTextureClient.h>
25#include <surfaceflinger/Surface.h>
Andreas Huberf9334412010-12-15 15:17:42 -080026
Andreas Huberf9334412010-12-15 15:17:42 -080027namespace android {
28
29struct ACodec;
30struct MetaData;
Andreas Huber43c3e6c2011-01-05 12:17:08 -080031struct NuPlayerDriver;
Andreas Huberf9334412010-12-15 15:17:42 -080032
33struct NuPlayer : public AHandler {
34 NuPlayer();
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 Huberf9334412010-12-15 15:17:42 -080043 void setVideoSurface(const sp<Surface> &surface);
Glenn Kasten11731182011-02-08 17:26:17 -080044 void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture);
Andreas Huberf9334412010-12-15 15:17:42 -080045 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
46 void start();
47
Andreas Huber43c3e6c2011-01-05 12:17:08 -080048 void pause();
49 void resume();
50
51 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Huber1aef2112011-01-04 14:01:29 -080052 void resetAsync();
53
Andreas Huber43c3e6c2011-01-05 12:17:08 -080054 // Will notify the driver through "notifySeekComplete" once finished.
55 void seekToAsync(int64_t seekTimeUs);
56
Andreas Huberf9334412010-12-15 15:17:42 -080057protected:
58 virtual ~NuPlayer();
59
60 virtual void onMessageReceived(const sp<AMessage> &msg);
61
62private:
Andreas Huberf9334412010-12-15 15:17:42 -080063 struct Decoder;
Andreas Huber5bc087c2010-12-23 10:27:40 -080064 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080065 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080066 struct Renderer;
67 struct Source;
68 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080069
70 enum {
71 kWhatSetDataSource,
Glenn Kasten11731182011-02-08 17:26:17 -080072 kWhatSetVideoNativeWindow,
Andreas Huberf9334412010-12-15 15:17:42 -080073 kWhatSetAudioSink,
74 kWhatMoreDataQueued,
75 kWhatStart,
76 kWhatScanSources,
77 kWhatVideoNotify,
78 kWhatAudioNotify,
79 kWhatRendererNotify,
Andreas Huber1aef2112011-01-04 14:01:29 -080080 kWhatReset,
Andreas Huber43c3e6c2011-01-05 12:17:08 -080081 kWhatSeek,
Andreas Huberb4082222011-01-20 15:23:04 -080082 kWhatPause,
83 kWhatResume,
Andreas Huberf9334412010-12-15 15:17:42 -080084 };
85
Andreas Huber43c3e6c2011-01-05 12:17:08 -080086 wp<NuPlayerDriver> mDriver;
Andreas Huber5bc087c2010-12-23 10:27:40 -080087 sp<Source> mSource;
Glenn Kasten11731182011-02-08 17:26:17 -080088 sp<NativeWindowWrapper> mNativeWindow;
Andreas Huberf9334412010-12-15 15:17:42 -080089 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080090 sp<Decoder> mVideoDecoder;
91 sp<Decoder> mAudioDecoder;
92 sp<Renderer> mRenderer;
93
Andreas Huberf9334412010-12-15 15:17:42 -080094 bool mAudioEOS;
95 bool mVideoEOS;
96
Andreas Huber5bc087c2010-12-23 10:27:40 -080097 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -080098 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -080099
Andreas Huberf9334412010-12-15 15:17:42 -0800100 enum FlushStatus {
101 NONE,
102 AWAITING_DISCONTINUITY,
103 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800104 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800105 SHUTTING_DOWN_DECODER,
106 FLUSHED,
107 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800108 };
109
110 FlushStatus mFlushingAudio;
111 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800112 bool mResetInProgress;
113 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800114
Andreas Huber5bc087c2010-12-23 10:27:40 -0800115 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800116
117 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
118 void renderBuffer(bool audio, const sp<AMessage> &msg);
119
Andreas Huberf9334412010-12-15 15:17:42 -0800120 void notifyListener(int msg, int ext1, int ext2);
121
Andreas Huber3831a062010-12-21 10:22:33 -0800122 void finishFlushIfPossible();
123
Andreas Huber1aef2112011-01-04 14:01:29 -0800124 void flushDecoder(bool audio, bool needShutdown);
125
126 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
127
128 void finishReset();
129 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800130
Andreas Huberf9334412010-12-15 15:17:42 -0800131 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
132};
133
134} // namespace android
135
136#endif // NU_PLAYER_H_