blob: bb651629bbd1f3095da5b5082bd21aa8310759d2 [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>
23
Andreas Huberf9334412010-12-15 15:17:42 -080024namespace android {
25
26struct ACodec;
27struct MetaData;
Andreas Huber43c3e6c2011-01-05 12:17:08 -080028struct NuPlayerDriver;
Andreas Huberf9334412010-12-15 15:17:42 -080029
30struct NuPlayer : public AHandler {
31 NuPlayer();
32
Andreas Huber43c3e6c2011-01-05 12:17:08 -080033 void setDriver(const wp<NuPlayerDriver> &driver);
Andreas Huberf9334412010-12-15 15:17:42 -080034
35 void setDataSource(const sp<IStreamSource> &source);
Andreas Huber5bc087c2010-12-23 10:27:40 -080036
37 void setDataSource(
38 const char *url, const KeyedVector<String8, String8> *headers);
39
Andreas Huberf9334412010-12-15 15:17:42 -080040 void setVideoSurface(const sp<Surface> &surface);
41 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
42 void start();
43
Andreas Huber43c3e6c2011-01-05 12:17:08 -080044 void pause();
45 void resume();
46
47 // Will notify the driver through "notifyResetComplete" once finished.
Andreas Huber1aef2112011-01-04 14:01:29 -080048 void resetAsync();
49
Andreas Huber43c3e6c2011-01-05 12:17:08 -080050 // Will notify the driver through "notifySeekComplete" once finished.
51 void seekToAsync(int64_t seekTimeUs);
52
Andreas Huberf9334412010-12-15 15:17:42 -080053protected:
54 virtual ~NuPlayer();
55
56 virtual void onMessageReceived(const sp<AMessage> &msg);
57
58private:
Andreas Huberf9334412010-12-15 15:17:42 -080059 struct Decoder;
Andreas Huber5bc087c2010-12-23 10:27:40 -080060 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080061 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080062 struct Renderer;
63 struct Source;
64 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080065
66 enum {
67 kWhatSetDataSource,
68 kWhatSetVideoSurface,
69 kWhatSetAudioSink,
70 kWhatMoreDataQueued,
71 kWhatStart,
72 kWhatScanSources,
73 kWhatVideoNotify,
74 kWhatAudioNotify,
75 kWhatRendererNotify,
Andreas Huber1aef2112011-01-04 14:01:29 -080076 kWhatReset,
Andreas Huber43c3e6c2011-01-05 12:17:08 -080077 kWhatSeek,
Andreas Huberb4082222011-01-20 15:23:04 -080078 kWhatPause,
79 kWhatResume,
Andreas Huberf9334412010-12-15 15:17:42 -080080 };
81
Andreas Huber43c3e6c2011-01-05 12:17:08 -080082 wp<NuPlayerDriver> mDriver;
Andreas Huber5bc087c2010-12-23 10:27:40 -080083 sp<Source> mSource;
Andreas Huberf9334412010-12-15 15:17:42 -080084 sp<Surface> mSurface;
85 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080086 sp<Decoder> mVideoDecoder;
87 sp<Decoder> mAudioDecoder;
88 sp<Renderer> mRenderer;
89
Andreas Huberf9334412010-12-15 15:17:42 -080090 bool mAudioEOS;
91 bool mVideoEOS;
92
Andreas Huber5bc087c2010-12-23 10:27:40 -080093 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -080094 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -080095
Andreas Huberf9334412010-12-15 15:17:42 -080096 enum FlushStatus {
97 NONE,
98 AWAITING_DISCONTINUITY,
99 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -0800100 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -0800101 SHUTTING_DOWN_DECODER,
102 FLUSHED,
103 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800104 };
105
106 FlushStatus mFlushingAudio;
107 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800108 bool mResetInProgress;
109 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800110
Andreas Huber5bc087c2010-12-23 10:27:40 -0800111 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800112
113 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
114 void renderBuffer(bool audio, const sp<AMessage> &msg);
115
Andreas Huberf9334412010-12-15 15:17:42 -0800116 void notifyListener(int msg, int ext1, int ext2);
117
Andreas Huber3831a062010-12-21 10:22:33 -0800118 void finishFlushIfPossible();
119
Andreas Huber1aef2112011-01-04 14:01:29 -0800120 void flushDecoder(bool audio, bool needShutdown);
121
122 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
123
124 void finishReset();
125 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800126
Andreas Huberf9334412010-12-15 15:17:42 -0800127 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
128};
129
130} // namespace android
131
132#endif // NU_PLAYER_H_