blob: 339b628c49a1477779ace97da2e1305535624ccb [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 Huberf9334412010-12-15 15:17:42 -080078 };
79
Andreas Huber43c3e6c2011-01-05 12:17:08 -080080 wp<NuPlayerDriver> mDriver;
Andreas Huber5bc087c2010-12-23 10:27:40 -080081 sp<Source> mSource;
Andreas Huberf9334412010-12-15 15:17:42 -080082 sp<Surface> mSurface;
83 sp<MediaPlayerBase::AudioSink> mAudioSink;
Andreas Huberf9334412010-12-15 15:17:42 -080084 sp<Decoder> mVideoDecoder;
85 sp<Decoder> mAudioDecoder;
86 sp<Renderer> mRenderer;
87
Andreas Huberf9334412010-12-15 15:17:42 -080088 bool mAudioEOS;
89 bool mVideoEOS;
90
Andreas Huber5bc087c2010-12-23 10:27:40 -080091 bool mScanSourcesPending;
Andreas Huber1aef2112011-01-04 14:01:29 -080092 int32_t mScanSourcesGeneration;
Andreas Huber5bc087c2010-12-23 10:27:40 -080093
Andreas Huberf9334412010-12-15 15:17:42 -080094 enum FlushStatus {
95 NONE,
96 AWAITING_DISCONTINUITY,
97 FLUSHING_DECODER,
Andreas Huber1aef2112011-01-04 14:01:29 -080098 FLUSHING_DECODER_SHUTDOWN,
Andreas Huber3831a062010-12-21 10:22:33 -080099 SHUTTING_DOWN_DECODER,
100 FLUSHED,
101 SHUT_DOWN,
Andreas Huberf9334412010-12-15 15:17:42 -0800102 };
103
104 FlushStatus mFlushingAudio;
105 FlushStatus mFlushingVideo;
Andreas Huber1aef2112011-01-04 14:01:29 -0800106 bool mResetInProgress;
107 bool mResetPostponed;
Andreas Huberf9334412010-12-15 15:17:42 -0800108
Andreas Huber5bc087c2010-12-23 10:27:40 -0800109 status_t instantiateDecoder(bool audio, sp<Decoder> *decoder);
Andreas Huberf9334412010-12-15 15:17:42 -0800110
111 status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg);
112 void renderBuffer(bool audio, const sp<AMessage> &msg);
113
Andreas Huberf9334412010-12-15 15:17:42 -0800114 void notifyListener(int msg, int ext1, int ext2);
115
Andreas Huber3831a062010-12-21 10:22:33 -0800116 void finishFlushIfPossible();
117
Andreas Huber1aef2112011-01-04 14:01:29 -0800118 void flushDecoder(bool audio, bool needShutdown);
119
120 static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL);
121
122 void finishReset();
123 void postScanSources();
Andreas Huber53df1a42010-12-22 10:03:04 -0800124
Andreas Huberf9334412010-12-15 15:17:42 -0800125 DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
126};
127
128} // namespace android
129
130#endif // NU_PLAYER_H_