blob: 1cf2f60a2e69cdaa1e9f626e500263ab53189dcf [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
Andreas Huber1aef2112011-01-04 14:01:29 -080043 // Will notify the listener that reset() has completed
44 // with code MEDIA_RESET_COMPLETE.
45 void resetAsync();
46
Andreas Huberf9334412010-12-15 15:17:42 -080047protected:
48 virtual ~NuPlayer();
49
50 virtual void onMessageReceived(const sp<AMessage> &msg);
51
52private:
Andreas Huberf9334412010-12-15 15:17:42 -080053 struct Decoder;
Andreas Huber5bc087c2010-12-23 10:27:40 -080054 struct HTTPLiveSource;
Andreas Huberf9334412010-12-15 15:17:42 -080055 struct NuPlayerStreamListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080056 struct Renderer;
57 struct Source;
58 struct StreamingSource;
Andreas Huberf9334412010-12-15 15:17:42 -080059
60 enum {
61 kWhatSetDataSource,
62 kWhatSetVideoSurface,
63 kWhatSetAudioSink,
64 kWhatMoreDataQueued,
65 kWhatStart,
66 kWhatScanSources,
67 kWhatVideoNotify,
68 kWhatAudioNotify,
69 kWhatRendererNotify,
Andreas Huber1aef2112011-01-04 14:01:29 -080070 kWhatReset,
Andreas Huberf9334412010-12-15 15:17:42 -080071 };
72
73 wp<MediaPlayerBase> mListener;
Andreas Huber5bc087c2010-12-23 10:27:40 -080074 sp<Source> mSource;
Andreas Huberf9334412010-12-15 15:17:42 -080075 sp<Surface> mSurface;
76 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080077 sp<Decoder> mVideoDecoder;
78 sp<Decoder> mAudioDecoder;
79 sp<Renderer> mRenderer;
80
Andreas Huberf9334412010-12-15 15:17:42 -080081 bool mAudioEOS;
82 bool mVideoEOS;
83
Andreas Huber5bc087c2010-12-23 10:27:40 -080084 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -080085 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -080086
Andreas Huberf9334412010-12-15 15:17:42 -080087 enum FlushStatus {
88 NONE,
89 AWAITING_DISCONTINUITY,
90 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -080091 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -080092 SHUTTING_DOWN_DECODER,
93 FLUSHED,
94 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -080095 };
96
97 FlushStatus mFlushingAudio;
98 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -080099 bool mResetInProgress;
100 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800101
Andreas Huber5bc087c2010-12-23 10:27:40 -0800102 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800103
104 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
105 void renderBuffer(bool audio, const sp<AMessage> &msg);
106
Andreas Huberf9334412010-12-15 15:17:42 -0800107 void notifyListener(int msg, int ext1, int ext2);
108
Andreas Huber3831a062010-12-21 10:22:33 -0800109 void finishFlushIfPossible();
110
Andreas Huber1aef2112011-01-04 14:01:29 -0800111 void flushDecoder(bool audio, bool needShutdown);
112
113 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
114
115 void finishReset();
116 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800117
Andreas Huberf9334412010-12-15 15:17:42 -0800118 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
119};
120
121} // namespace android
122
123#endif // NU_PLAYER_H_