NuPlayerDecoder.h revision 421f47ca9c2dcc78584b2bb609c3755483b55155
1/* 2 * Copyright 2014 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 NUPLAYER_DECODER_H_ 18#define NUPLAYER_DECODER_H_ 19 20#include "NuPlayer.h" 21 22#include "NuPlayerDecoderBase.h" 23 24namespace android { 25 26struct NuPlayer::Decoder : public DecoderBase { 27 Decoder(const sp<AMessage> ¬ify, 28 const sp<Source> &source, 29 const sp<Renderer> &renderer = NULL, 30 const sp<NativeWindowWrapper> &nativeWindow = NULL, 31 const sp<CCDecoder> &ccDecoder = NULL); 32 33 virtual void getStats( 34 int64_t *mNumFramesTotal, 35 int64_t *mNumFramesDropped) const; 36 37protected: 38 virtual ~Decoder(); 39 40 virtual void onMessageReceived(const sp<AMessage> &msg); 41 42 virtual void onConfigure(const sp<AMessage> &format); 43 virtual void onSetRenderer(const sp<Renderer> &renderer); 44 virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers); 45 virtual void onResume(bool notifyComplete); 46 virtual void onFlush(); 47 virtual void onShutdown(bool notifyComplete); 48 virtual void doRequestBuffers(); 49 50private: 51 enum { 52 kWhatCodecNotify = 'cdcN', 53 kWhatRenderBuffer = 'rndr', 54 }; 55 56 sp<NativeWindowWrapper> mNativeWindow; 57 58 sp<Source> mSource; 59 sp<Renderer> mRenderer; 60 sp<CCDecoder> mCCDecoder; 61 62 sp<AMessage> mInputFormat; 63 sp<AMessage> mOutputFormat; 64 sp<MediaCodec> mCodec; 65 sp<ALooper> mCodecLooper; 66 67 List<sp<AMessage> > mPendingInputMessages; 68 69 Vector<sp<ABuffer> > mInputBuffers; 70 Vector<sp<ABuffer> > mOutputBuffers; 71 Vector<sp<ABuffer> > mCSDsForCurrentFormat; 72 Vector<sp<ABuffer> > mCSDsToSubmit; 73 Vector<bool> mInputBufferIsDequeued; 74 Vector<MediaBuffer *> mMediaBuffers; 75 Vector<size_t> mDequeuedInputBuffers; 76 77 int64_t mSkipRenderingUntilMediaTimeUs; 78 int64_t mNumFramesTotal; 79 int64_t mNumFramesDropped; 80 bool mIsAudio; 81 bool mIsVideoAVC; 82 bool mIsSecure; 83 bool mFormatChangePending; 84 bool mTimeChangePending; 85 86 bool mPaused; 87 bool mResumePending; 88 AString mComponentName; 89 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); 99 100 void releaseAndResetMediaBuffers(); 101 void requestCodecNotification(); 102 bool isStaleReply(const sp<AMessage> &msg); 103 104 void doFlush(bool notifyComplete); 105 status_t fetchInputData(sp<AMessage> &reply); 106 bool onInputBufferFetched(const sp<AMessage> &msg); 107 void onRenderBuffer(const sp<AMessage> &msg); 108 109 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; 110 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; 111 void rememberCodecSpecificData(const sp<AMessage> &format); 112 bool isDiscontinuityPending() const; 113 void finishHandleDiscontinuity(bool flushOnTimeChange); 114 115 void notifyResumeCompleteIfNecessary(); 116 117 DISALLOW_EVIL_CONSTRUCTORS(Decoder); 118}; 119 120} // namespace android 121 122#endif // NUPLAYER_DECODER_H_ 123