blob: 172a962157e1d1209b3a36b033535026711a521c [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;
28
29struct NuPlayer : public AHandler {
30 NuPlayer();
31
32 void setListener(const wp<MediaPlayerBase> &listener);
33
34 void setDataSource(const sp<IStreamSource> &source);
Andreas Huber5bc087c2010-12-23 10:27:40 -080035
36 void setDataSource(
37 const char *url, const KeyedVector<String8, String8> *headers);
38
Andreas Huberf9334412010-12-15 15:17:42 -080039 void setVideoSurface(const sp<Surface> &surface);
40 void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink);
41 void start();
42
43protected:
44 virtual ~NuPlayer();
45
46 virtual void onMessageReceived(const sp<AMessage> &msg);
47
48private:
Andreas Huberf9334412010-12-15 15:17:42 -080049 struct Decoder;
Andreas Huber5bc087c2010-12-23 10:27:40 -080050 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080051 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080052 struct Renderer;
53 struct Source;
54 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080055
56 enum {
57 kWhatSetDataSource,
58 kWhatSetVideoSurface,
59 kWhatSetAudioSink,
60 kWhatMoreDataQueued,
61 kWhatStart,
62 kWhatScanSources,
63 kWhatVideoNotify,
64 kWhatAudioNotify,
65 kWhatRendererNotify,
66 };
67
68 wp<MediaPlayerBase> mListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080069 sp<Source> mSource;
Andreas Huberf9334412010-12-15 15:17:42 -080070 sp<Surface> mSurface;
71 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080072 sp<Decoder> mVideoDecoder;
73 sp<Decoder> mAudioDecoder;
74 sp<Renderer> mRenderer;
75
76 bool mEOS;
77 bool mAudioEOS;
78 bool mVideoEOS;
79
Andreas Huber5bc087c2010-12-23 10:27:40 -080080 bool mScanSourcesPending;
81
Andreas Huberf9334412010-12-15 15:17:42 -080082 enum FlushStatus {
83 NONE,
84 AWAITING_DISCONTINUITY,
85 FLUSHING_DECODER,
Andreas Huber53df1a42010-12-22 10:03:04 -080086 FLUSHING_DECODER_FORMATCHANGE,
Andreas Huber3831a062010-12-21 10:22:33 -080087 SHUTTING_DOWN_DECODER,
88 FLUSHED,
89 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -080090 };
91
92 FlushStatus mFlushingAudio;
93 FlushStatus mFlushingVideo;
94
Andreas Huber5bc087c2010-12-23 10:27:40 -080095 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -080096
97 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
98 void renderBuffer(bool audio, const sp<AMessage> &msg);
99
Andreas Huberf9334412010-12-15 15:17:42 -0800100 void notifyListener(int msg, int ext1, int ext2);
101
Andreas Huber3831a062010-12-21 10:22:33 -0800102 void finishFlushIfPossible();
103
Andreas Huber53df1a42010-12-22 10:03:04 -0800104 static bool IsFlushingState(FlushStatus state, bool *formatChange = NULL);
105
Andreas Huberf9334412010-12-15 15:17:42 -0800106 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
107};
108
109} // namespace android
110
111#endif // NU_PLAYER_H_