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 | |
| 43 | protected: |
| 44 | virtual ~NuPlayer(); |
| 45 | |
| 46 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 47 | |
| 48 | private: |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 49 | struct Decoder; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame^] | 50 | struct HTTPLiveSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 51 | struct NuPlayerStreamListener; |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame^] | 52 | struct Renderer; |
| 53 | struct Source; |
| 54 | struct StreamingSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 55 | |
| 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 Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame^] | 69 | sp<Source> mSource; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 70 | sp<Surface> mSurface; |
| 71 | sp<MediaPlayerBase::AudioSink> mAudioSink; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 72 | sp<Decoder> mVideoDecoder; |
| 73 | sp<Decoder> mAudioDecoder; |
| 74 | sp<Renderer> mRenderer; |
| 75 | |
| 76 | bool mEOS; |
| 77 | bool mAudioEOS; |
| 78 | bool mVideoEOS; |
| 79 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame^] | 80 | bool mScanSourcesPending; |
| 81 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 82 | enum FlushStatus { |
| 83 | NONE, |
| 84 | AWAITING_DISCONTINUITY, |
| 85 | FLUSHING_DECODER, |
Andreas Huber | 53df1a4 | 2010-12-22 10:03:04 -0800 | [diff] [blame] | 86 | FLUSHING_DECODER_FORMATCHANGE, |
Andreas Huber | 3831a06 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 87 | SHUTTING_DOWN_DECODER, |
| 88 | FLUSHED, |
| 89 | SHUT_DOWN, |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | FlushStatus mFlushingAudio; |
| 93 | FlushStatus mFlushingVideo; |
| 94 | |
Andreas Huber | 5bc087c | 2010-12-23 10:27:40 -0800 | [diff] [blame^] | 95 | status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 96 | |
| 97 | status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); |
| 98 | void renderBuffer(bool audio, const sp<AMessage> &msg); |
| 99 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 100 | void notifyListener(int msg, int ext1, int ext2); |
| 101 | |
Andreas Huber | 3831a06 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 102 | void finishFlushIfPossible(); |
| 103 | |
Andreas Huber | 53df1a4 | 2010-12-22 10:03:04 -0800 | [diff] [blame] | 104 | static bool IsFlushingState(FlushStatus state, bool *formatChange = NULL); |
| 105 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 106 | DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); |
| 107 | }; |
| 108 | |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // NU_PLAYER_H_ |