Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 1 | /* |
| 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 Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | struct ACodec; |
| 27 | struct MetaData; |
| 28 | |
| 29 | struct NuPlayer : public AHandler { |
| 30 | NuPlayer(); |
| 31 | |
| 32 | void setListener(const wp<MediaPlayerBase> &listener); |
| 33 | |
| 34 | void setDataSource(const sp<IStreamSource> &source); |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 35 | |
| 36 | void setDataSource( |
| 37 | const char *url, const KeyedVector<String8, String8> *headers); |
| 38 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 39 | void setVideoSurface(const sp<Surface> &surface); |
| 40 | void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); |
| 41 | void start(); |
| 42 | |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 43 | // Will notify the listener that reset() has completed |
| 44 | // with code MEDIA_RESET_COMPLETE. |
| 45 | void resetAsync(); |
| 46 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 47 | protected: |
| 48 | virtual ~NuPlayer(); |
| 49 | |
| 50 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 51 | |
| 52 | private: |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 53 | struct Decoder; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 54 | struct HTTPLiveSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 55 | struct NuPlayerStreamListener; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 56 | struct Renderer; |
| 57 | struct Source; |
| 58 | struct StreamingSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 59 | |
| 60 | enum { |
| 61 | kWhatSetDataSource, |
| 62 | kWhatSetVideoSurface, |
| 63 | kWhatSetAudioSink, |
| 64 | kWhatMoreDataQueued, |
| 65 | kWhatStart, |
| 66 | kWhatScanSources, |
| 67 | kWhatVideoNotify, |
| 68 | kWhatAudioNotify, |
| 69 | kWhatRendererNotify, |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 70 | kWhatReset, |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | wp<MediaPlayerBase> mListener; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 74 | sp<Source> mSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 75 | sp<Surface> mSurface; |
| 76 | sp<MediaPlayerBase::AudioSink> mAudioSink; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 77 | sp<Decoder> mVideoDecoder; |
| 78 | sp<Decoder> mAudioDecoder; |
| 79 | sp<Renderer> mRenderer; |
| 80 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 81 | bool mAudioEOS; |
| 82 | bool mVideoEOS; |
| 83 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 84 | bool mScanSourcesPending; |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 85 | int32_t mScanSourcesGeneration; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 86 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 87 | enum FlushStatus { |
| 88 | NONE, |
| 89 | AWAITING_DISCONTINUITY, |
| 90 | FLUSHING_DECODER, |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 91 | FLUSHING_DECODER_SHUTDOWN, |
Andreas Huber | 3831a06 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 92 | SHUTTING_DOWN_DECODER, |
| 93 | FLUSHED, |
| 94 | SHUT_DOWN, |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | FlushStatus mFlushingAudio; |
| 98 | FlushStatus mFlushingVideo; |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 99 | bool mResetInProgress; |
| 100 | bool mResetPostponed; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 101 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 102 | status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 103 | |
| 104 | status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); |
| 105 | void renderBuffer(bool audio, const sp<AMessage> &msg); |
| 106 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 107 | void notifyListener(int msg, int ext1, int ext2); |
| 108 | |
Andreas Huber | 3831a06 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 109 | void finishFlushIfPossible(); |
| 110 | |
Andreas Huber | 1aef211 | 2011-01-04 14:01:29 -0800 | [diff] [blame^] | 111 | void flushDecoder(bool audio, bool needShutdown); |
| 112 | |
| 113 | static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); |
| 114 | |
| 115 | void finishReset(); |
| 116 | void postScanSources(); |
Andreas Huber | 53df1a4 | 2010-12-22 10:03:04 -0800 | [diff] [blame] | 117 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 118 | DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); |
| 119 | }; |
| 120 | |
| 121 | } // namespace android |
| 122 | |
| 123 | #endif // NU_PLAYER_H_ |