Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 1 | /* |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 2 | * Copyright 2014 The Android Open Source Project |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 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 NUPLAYER_DECODER_H_ |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 18 | #define NUPLAYER_DECODER_H_ |
| 19 | |
| 20 | #include "NuPlayer.h" |
| 21 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 22 | #include "NuPlayerDecoderBase.h" |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
Wonsik Kim | 7e34bf5 | 2016-08-23 00:09:18 +0900 | [diff] [blame] | 26 | class MediaCodecBuffer; |
| 27 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 28 | struct NuPlayer::Decoder : public DecoderBase { |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 29 | Decoder(const sp<AMessage> ¬ify, |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 30 | const sp<Source> &source, |
Ronghua Wu | 68845c1 | 2015-07-21 09:50:48 -0700 | [diff] [blame] | 31 | pid_t pid, |
Wei Jia | f2ae3e1 | 2016-10-27 17:10:59 -0700 | [diff] [blame] | 32 | uid_t uid, |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 33 | const sp<Renderer> &renderer = NULL, |
Lajos Molnar | 1de1e25 | 2015-04-30 18:18:34 -0700 | [diff] [blame] | 34 | const sp<Surface> &surface = NULL, |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 35 | const sp<CCDecoder> &ccDecoder = NULL); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 36 | |
Ray Essick | 83f56b0 | 2019-06-23 15:13:46 -0700 | [diff] [blame] | 37 | virtual sp<AMessage> getStats(); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 38 | |
Lajos Molnar | a81c622 | 2015-07-10 19:17:45 -0700 | [diff] [blame] | 39 | // sets the output surface of video decoders. |
| 40 | virtual status_t setVideoSurface(const sp<Surface> &surface); |
| 41 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 42 | virtual status_t releaseCrypto(); |
| 43 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 44 | protected: |
| 45 | virtual ~Decoder(); |
| 46 | |
| 47 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 48 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 49 | virtual void onConfigure(const sp<AMessage> &format); |
Ronghua Wu | 8db8813 | 2015-04-22 13:51:35 -0700 | [diff] [blame] | 50 | virtual void onSetParameters(const sp<AMessage> ¶ms); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 51 | virtual void onSetRenderer(const sp<Renderer> &renderer); |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 52 | virtual void onResume(bool notifyComplete); |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 53 | virtual void onFlush(); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 54 | virtual void onShutdown(bool notifyComplete); |
Chong Zhang | 3b032b3 | 2015-04-17 15:49:06 -0700 | [diff] [blame] | 55 | virtual bool doRequestBuffers(); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 56 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 57 | private: |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 58 | enum { |
| 59 | kWhatCodecNotify = 'cdcN', |
| 60 | kWhatRenderBuffer = 'rndr', |
Wei Jia | 9a3101b | 2016-11-08 14:34:24 -0800 | [diff] [blame] | 61 | kWhatSetVideoSurface = 'sSur', |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 62 | kWhatAudioOutputFormatChanged = 'aofc', |
| 63 | kWhatDrmReleaseCrypto = 'rDrm', |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Praveen Chavan | bbaa144 | 2016-04-08 13:33:49 -0700 | [diff] [blame] | 66 | enum { |
| 67 | kMaxNumVideoTemporalLayers = 32, |
| 68 | }; |
| 69 | |
Lajos Molnar | 1de1e25 | 2015-04-30 18:18:34 -0700 | [diff] [blame] | 70 | sp<Surface> mSurface; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 71 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 72 | sp<Source> mSource; |
| 73 | sp<Renderer> mRenderer; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 74 | sp<CCDecoder> mCCDecoder; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 75 | |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 76 | sp<AMessage> mInputFormat; |
| 77 | sp<AMessage> mOutputFormat; |
| 78 | sp<MediaCodec> mCodec; |
Andreas Huber | 078cfcf | 2011-09-15 12:25:04 -0700 | [diff] [blame] | 79 | sp<ALooper> mCodecLooper; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 80 | |
Wei Jia | 2245fc6 | 2014-10-02 15:12:25 -0700 | [diff] [blame] | 81 | List<sp<AMessage> > mPendingInputMessages; |
| 82 | |
Wonsik Kim | 7e34bf5 | 2016-08-23 00:09:18 +0900 | [diff] [blame] | 83 | Vector<sp<MediaCodecBuffer> > mInputBuffers; |
| 84 | Vector<sp<MediaCodecBuffer> > mOutputBuffers; |
Lajos Molnar | 87603c0 | 2014-08-20 19:25:30 -0700 | [diff] [blame] | 85 | Vector<sp<ABuffer> > mCSDsForCurrentFormat; |
| 86 | Vector<sp<ABuffer> > mCSDsToSubmit; |
Lajos Molnar | 0952483 | 2014-07-17 14:29:51 -0700 | [diff] [blame] | 87 | Vector<bool> mInputBufferIsDequeued; |
| 88 | Vector<MediaBuffer *> mMediaBuffers; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 89 | Vector<size_t> mDequeuedInputBuffers; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 90 | |
Ronghua Wu | 68845c1 | 2015-07-21 09:50:48 -0700 | [diff] [blame] | 91 | const pid_t mPid; |
Wei Jia | f2ae3e1 | 2016-10-27 17:10:59 -0700 | [diff] [blame] | 92 | const uid_t mUid; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 93 | int64_t mSkipRenderingUntilMediaTimeUs; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 94 | int64_t mNumFramesTotal; |
Praveen Chavan | e1e5d7a | 2015-05-19 19:09:48 -0700 | [diff] [blame] | 95 | int64_t mNumInputFramesDropped; |
| 96 | int64_t mNumOutputFramesDropped; |
| 97 | int32_t mVideoWidth; |
| 98 | int32_t mVideoHeight; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 99 | bool mIsAudio; |
| 100 | bool mIsVideoAVC; |
| 101 | bool mIsSecure; |
Hassan Shojania | 62dec95 | 2017-05-18 10:45:27 -0700 | [diff] [blame] | 102 | bool mIsEncrypted; |
| 103 | bool mIsEncryptedObservedEarlier; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 104 | bool mFormatChangePending; |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 105 | bool mTimeChangePending; |
Praveen Chavan | bbaa144 | 2016-04-08 13:33:49 -0700 | [diff] [blame] | 106 | float mFrameRateTotal; |
| 107 | float mPlaybackSpeed; |
| 108 | int32_t mNumVideoTemporalLayerTotal; |
| 109 | int32_t mNumVideoTemporalLayerAllowed; |
| 110 | int32_t mCurrentMaxVideoTemporalLayerId; |
| 111 | float mVideoTemporalLayerAggregateFps[kMaxNumVideoTemporalLayers]; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 112 | |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 113 | bool mResumePending; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 114 | AString mComponentName; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 115 | |
Marco Nelissen | 421f47c | 2015-03-25 14:40:32 -0700 | [diff] [blame] | 116 | void handleError(int32_t err); |
| 117 | bool handleAnInputBuffer(size_t index); |
| 118 | bool handleAnOutputBuffer( |
| 119 | size_t index, |
| 120 | size_t offset, |
| 121 | size_t size, |
| 122 | int64_t timeUs, |
| 123 | int32_t flags); |
| 124 | void handleOutputFormatChange(const sp<AMessage> &format); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 125 | |
Lajos Molnar | 0952483 | 2014-07-17 14:29:51 -0700 | [diff] [blame] | 126 | void releaseAndResetMediaBuffers(); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 127 | void requestCodecNotification(); |
| 128 | bool isStaleReply(const sp<AMessage> &msg); |
| 129 | |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 130 | void doFlush(bool notifyComplete); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 131 | status_t fetchInputData(sp<AMessage> &reply); |
| 132 | bool onInputBufferFetched(const sp<AMessage> &msg); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 133 | void onRenderBuffer(const sp<AMessage> &msg); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 134 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 135 | bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; |
Robert Shih | 6d0a94e | 2014-01-23 16:18:22 -0800 | [diff] [blame] | 136 | bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; |
Lajos Molnar | 87603c0 | 2014-08-20 19:25:30 -0700 | [diff] [blame] | 137 | void rememberCodecSpecificData(const sp<AMessage> &format); |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 138 | bool isDiscontinuityPending() const; |
| 139 | void finishHandleDiscontinuity(bool flushOnTimeChange); |
Robert Shih | 6d0a94e | 2014-01-23 16:18:22 -0800 | [diff] [blame] | 140 | |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 141 | void notifyResumeCompleteIfNecessary(); |
| 142 | |
Hassan Shojania | cefac14 | 2017-02-06 21:02:02 -0800 | [diff] [blame] | 143 | void onReleaseCrypto(const sp<AMessage>& msg); |
| 144 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 145 | DISALLOW_EVIL_CONSTRUCTORS(Decoder); |
| 146 | }; |
| 147 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 148 | } // namespace android |
| 149 | |
| 150 | #endif // NUPLAYER_DECODER_H_ |