Andreas Huber | a158746 | 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> |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 23 | #include <media/stagefright/NativeWindowWrapper.h> |
| 24 | #include <gui/SurfaceTextureClient.h> |
| 25 | #include <surfaceflinger/Surface.h> |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 26 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | struct ACodec; |
| 30 | struct MetaData; |
Andreas Huber | 08e10cb | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 31 | struct NuPlayerDriver; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 32 | |
| 33 | struct NuPlayer : public AHandler { |
| 34 | NuPlayer(); |
| 35 | |
Andreas Huber | 603d739 | 2011-06-30 15:47:02 -0700 | [diff] [blame] | 36 | void setUID(uid_t uid); |
| 37 | |
Andreas Huber | 08e10cb | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 38 | void setDriver(const wp<NuPlayerDriver> &driver); |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 39 | |
| 40 | void setDataSource(const sp<IStreamSource> &source); |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 41 | |
| 42 | void setDataSource( |
| 43 | const char *url, const KeyedVector<String8, String8> *headers); |
| 44 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 45 | void setVideoSurface(const sp<Surface> &surface); |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 46 | void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture); |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 47 | void setAudioSink(const sp<MediaPlayerBase::AudioSink> &sink); |
| 48 | void start(); |
| 49 | |
Andreas Huber | 08e10cb | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 50 | void pause(); |
| 51 | void resume(); |
| 52 | |
| 53 | // Will notify the driver through "notifyResetComplete" once finished. |
Andreas Huber | cbeaca7 | 2011-01-04 14:01:29 -0800 | [diff] [blame] | 54 | void resetAsync(); |
| 55 | |
Andreas Huber | 08e10cb | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 56 | // Will notify the driver through "notifySeekComplete" once finished. |
| 57 | void seekToAsync(int64_t seekTimeUs); |
| 58 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 59 | protected: |
| 60 | virtual ~NuPlayer(); |
| 61 | |
| 62 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 63 | |
| 64 | private: |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 65 | struct Decoder; |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 66 | struct HTTPLiveSource; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 67 | struct NuPlayerStreamListener; |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 68 | struct Renderer; |
| 69 | struct Source; |
| 70 | struct StreamingSource; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 71 | |
| 72 | enum { |
Andreas Huber | 115cac8 | 2011-09-15 12:25:04 -0700 | [diff] [blame] | 73 | kWhatSetDataSource = '=DaS', |
| 74 | kWhatSetVideoNativeWindow = '=NaW', |
| 75 | kWhatSetAudioSink = '=AuS', |
| 76 | kWhatMoreDataQueued = 'more', |
| 77 | kWhatStart = 'strt', |
| 78 | kWhatScanSources = 'scan', |
| 79 | kWhatVideoNotify = 'vidN', |
| 80 | kWhatAudioNotify = 'audN', |
| 81 | kWhatRendererNotify = 'renN', |
| 82 | kWhatReset = 'rset', |
| 83 | kWhatSeek = 'seek', |
| 84 | kWhatPause = 'paus', |
| 85 | kWhatResume = 'rsme', |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Andreas Huber | 08e10cb | 2011-01-05 12:17:08 -0800 | [diff] [blame] | 88 | wp<NuPlayerDriver> mDriver; |
Andreas Huber | 603d739 | 2011-06-30 15:47:02 -0700 | [diff] [blame] | 89 | bool mUIDValid; |
| 90 | uid_t mUID; |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 91 | sp<Source> mSource; |
Glenn Kasten | cc562a3 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 92 | sp<NativeWindowWrapper> mNativeWindow; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 93 | sp<MediaPlayerBase::AudioSink> mAudioSink; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 94 | sp<Decoder> mVideoDecoder; |
Andreas Huber | 950fc9d | 2011-09-16 15:09:22 -0700 | [diff] [blame] | 95 | bool mVideoIsAVC; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 96 | sp<Decoder> mAudioDecoder; |
| 97 | sp<Renderer> mRenderer; |
| 98 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 99 | bool mAudioEOS; |
| 100 | bool mVideoEOS; |
| 101 | |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 102 | bool mScanSourcesPending; |
Andreas Huber | cbeaca7 | 2011-01-04 14:01:29 -0800 | [diff] [blame] | 103 | int32_t mScanSourcesGeneration; |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 104 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 105 | enum FlushStatus { |
| 106 | NONE, |
| 107 | AWAITING_DISCONTINUITY, |
| 108 | FLUSHING_DECODER, |
Andreas Huber | cbeaca7 | 2011-01-04 14:01:29 -0800 | [diff] [blame] | 109 | FLUSHING_DECODER_SHUTDOWN, |
Andreas Huber | 41c3f74 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 110 | SHUTTING_DOWN_DECODER, |
| 111 | FLUSHED, |
| 112 | SHUT_DOWN, |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | FlushStatus mFlushingAudio; |
| 116 | FlushStatus mFlushingVideo; |
Andreas Huber | cbeaca7 | 2011-01-04 14:01:29 -0800 | [diff] [blame] | 117 | bool mResetInProgress; |
| 118 | bool mResetPostponed; |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 119 | |
Andreas Huber | 669ad13 | 2011-03-02 15:34:46 -0800 | [diff] [blame] | 120 | int64_t mSkipRenderingAudioUntilMediaTimeUs; |
| 121 | int64_t mSkipRenderingVideoUntilMediaTimeUs; |
| 122 | |
Andreas Huber | 950fc9d | 2011-09-16 15:09:22 -0700 | [diff] [blame] | 123 | int64_t mVideoLateByUs; |
| 124 | int64_t mNumFramesTotal, mNumFramesDropped; |
| 125 | |
Andreas Huber | 54e6649 | 2010-12-23 10:27:40 -0800 | [diff] [blame] | 126 | status_t instantiateDecoder(bool audio, sp<Decoder> *decoder); |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 127 | |
| 128 | status_t feedDecoderInputData(bool audio, const sp<AMessage> &msg); |
| 129 | void renderBuffer(bool audio, const sp<AMessage> &msg); |
| 130 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 131 | void notifyListener(int msg, int ext1, int ext2); |
| 132 | |
Andreas Huber | 41c3f74 | 2010-12-21 10:22:33 -0800 | [diff] [blame] | 133 | void finishFlushIfPossible(); |
| 134 | |
Andreas Huber | cbeaca7 | 2011-01-04 14:01:29 -0800 | [diff] [blame] | 135 | void flushDecoder(bool audio, bool needShutdown); |
| 136 | |
| 137 | static bool IsFlushingState(FlushStatus state, bool *needShutdown = NULL); |
| 138 | |
| 139 | void finishReset(); |
| 140 | void postScanSources(); |
Andreas Huber | 222e689 | 2010-12-22 10:03:04 -0800 | [diff] [blame] | 141 | |
Andreas Huber | a158746 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 142 | DISALLOW_EVIL_CONSTRUCTORS(NuPlayer); |
| 143 | }; |
| 144 | |
| 145 | } // namespace android |
| 146 | |
| 147 | #endif // NU_PLAYER_H_ |