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 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 26 | struct NuPlayer::Decoder : public DecoderBase { |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 27 | Decoder(const sp<AMessage> ¬ify, |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 28 | const sp<Source> &source, |
| 29 | const sp<Renderer> &renderer = NULL, |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 30 | const sp<NativeWindowWrapper> &nativeWindow = NULL, |
| 31 | const sp<CCDecoder> &ccDecoder = NULL); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 32 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 33 | virtual void getStats( |
| 34 | int64_t *mNumFramesTotal, |
| 35 | int64_t *mNumFramesDropped) const; |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 36 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 37 | protected: |
| 38 | virtual ~Decoder(); |
| 39 | |
| 40 | virtual void onMessageReceived(const sp<AMessage> &msg); |
| 41 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 42 | virtual void onConfigure(const sp<AMessage> &format); |
| 43 | virtual void onSetRenderer(const sp<Renderer> &renderer); |
| 44 | virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers); |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 45 | virtual void onResume(bool notifyComplete); |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 46 | virtual void onFlush(); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 47 | virtual void onShutdown(bool notifyComplete); |
| 48 | virtual void doRequestBuffers(); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 49 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 50 | private: |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 51 | enum { |
| 52 | kWhatCodecNotify = 'cdcN', |
| 53 | kWhatRenderBuffer = 'rndr', |
| 54 | }; |
| 55 | |
Glenn Kasten | 1173118 | 2011-02-08 17:26:17 -0800 | [diff] [blame] | 56 | sp<NativeWindowWrapper> mNativeWindow; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 57 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 58 | sp<Source> mSource; |
| 59 | sp<Renderer> mRenderer; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 60 | sp<CCDecoder> mCCDecoder; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 61 | |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 62 | sp<AMessage> mInputFormat; |
| 63 | sp<AMessage> mOutputFormat; |
| 64 | sp<MediaCodec> mCodec; |
Andreas Huber | 078cfcf | 2011-09-15 12:25:04 -0700 | [diff] [blame] | 65 | sp<ALooper> mCodecLooper; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 66 | |
Wei Jia | 2245fc6 | 2014-10-02 15:12:25 -0700 | [diff] [blame] | 67 | List<sp<AMessage> > mPendingInputMessages; |
| 68 | |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 69 | Vector<sp<ABuffer> > mInputBuffers; |
| 70 | Vector<sp<ABuffer> > mOutputBuffers; |
Lajos Molnar | 87603c0 | 2014-08-20 19:25:30 -0700 | [diff] [blame] | 71 | Vector<sp<ABuffer> > mCSDsForCurrentFormat; |
| 72 | Vector<sp<ABuffer> > mCSDsToSubmit; |
Lajos Molnar | 0952483 | 2014-07-17 14:29:51 -0700 | [diff] [blame] | 73 | Vector<bool> mInputBufferIsDequeued; |
| 74 | Vector<MediaBuffer *> mMediaBuffers; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 75 | Vector<size_t> mDequeuedInputBuffers; |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 76 | |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 77 | int64_t mSkipRenderingUntilMediaTimeUs; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 78 | int64_t mNumFramesTotal; |
| 79 | int64_t mNumFramesDropped; |
| 80 | bool mIsAudio; |
| 81 | bool mIsVideoAVC; |
| 82 | bool mIsSecure; |
| 83 | bool mFormatChangePending; |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 84 | bool mTimeChangePending; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 85 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 86 | bool mPaused; |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 87 | bool mResumePending; |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 88 | AString mComponentName; |
Wei Jia | c6cfd70 | 2014-11-11 16:33:20 -0800 | [diff] [blame] | 89 | |
Marco Nelissen | 421f47c | 2015-03-25 14:40:32 -0700 | [diff] [blame] | 90 | void handleError(int32_t err); |
| 91 | bool handleAnInputBuffer(size_t index); |
| 92 | bool handleAnOutputBuffer( |
| 93 | size_t index, |
| 94 | size_t offset, |
| 95 | size_t size, |
| 96 | int64_t timeUs, |
| 97 | int32_t flags); |
| 98 | void handleOutputFormatChange(const sp<AMessage> &format); |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 99 | |
Lajos Molnar | 0952483 | 2014-07-17 14:29:51 -0700 | [diff] [blame] | 100 | void releaseAndResetMediaBuffers(); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 101 | void requestCodecNotification(); |
| 102 | bool isStaleReply(const sp<AMessage> &msg); |
| 103 | |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 104 | void doFlush(bool notifyComplete); |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 105 | status_t fetchInputData(sp<AMessage> &reply); |
| 106 | bool onInputBufferFetched(const sp<AMessage> &msg); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 107 | void onRenderBuffer(const sp<AMessage> &msg); |
Lajos Molnar | 1cd1398 | 2014-01-17 15:12:51 -0800 | [diff] [blame] | 108 | |
Chong Zhang | 7137ec7 | 2014-11-12 16:41:05 -0800 | [diff] [blame] | 109 | bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; |
Robert Shih | 6d0a94e | 2014-01-23 16:18:22 -0800 | [diff] [blame] | 110 | bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; |
Lajos Molnar | 87603c0 | 2014-08-20 19:25:30 -0700 | [diff] [blame] | 111 | void rememberCodecSpecificData(const sp<AMessage> &format); |
Chong Zhang | 66704af | 2015-03-03 19:32:35 -0800 | [diff] [blame] | 112 | bool isDiscontinuityPending() const; |
| 113 | void finishHandleDiscontinuity(bool flushOnTimeChange); |
Robert Shih | 6d0a94e | 2014-01-23 16:18:22 -0800 | [diff] [blame] | 114 | |
Chong Zhang | f8d7177 | 2014-11-26 15:08:34 -0800 | [diff] [blame] | 115 | void notifyResumeCompleteIfNecessary(); |
| 116 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 117 | DISALLOW_EVIL_CONSTRUCTORS(Decoder); |
| 118 | }; |
| 119 | |
Andreas Huber | f933441 | 2010-12-15 15:17:42 -0800 | [diff] [blame] | 120 | } // namespace android |
| 121 | |
| 122 | #endif // NUPLAYER_DECODER_H_ |