NuPlayerDecoder.h revision e1e5d7a3d3d4d6d644e6c731f977422e004140d5
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<Surface> &surface = NULL, 31 const sp<CCDecoder> &ccDecoder = NULL); 32 33 virtual sp<AMessage> getStats() const; 34 35protected: 36 virtual ~Decoder(); 37 38 virtual void onMessageReceived(const sp<AMessage> &msg); 39 40 virtual void onConfigure(const sp<AMessage> &format); 41 virtual void onSetParameters(const sp<AMessage> ¶ms); 42 virtual void onSetRenderer(const sp<Renderer> &renderer); 43 virtual void onGetInputBuffers(Vector<sp<ABuffer> > *dstBuffers); 44 virtual void onResume(bool notifyComplete); 45 virtual void onFlush(); 46 virtual void onShutdown(bool notifyComplete); 47 virtual bool doRequestBuffers(); 48 49private: 50 enum { 51 kWhatCodecNotify = 'cdcN', 52 kWhatRenderBuffer = 'rndr', 53 }; 54 55 sp<Surface> mSurface; 56 57 sp<Source> mSource; 58 sp<Renderer> mRenderer; 59 sp<CCDecoder> mCCDecoder; 60 61 sp<AMessage> mInputFormat; 62 sp<AMessage> mOutputFormat; 63 sp<MediaCodec> mCodec; 64 sp<ALooper> mCodecLooper; 65 66 List<sp<AMessage> > mPendingInputMessages; 67 68 Vector<sp<ABuffer> > mInputBuffers; 69 Vector<sp<ABuffer> > mOutputBuffers; 70 Vector<sp<ABuffer> > mCSDsForCurrentFormat; 71 Vector<sp<ABuffer> > mCSDsToSubmit; 72 Vector<bool> mInputBufferIsDequeued; 73 Vector<MediaBuffer *> mMediaBuffers; 74 Vector<size_t> mDequeuedInputBuffers; 75 76 int64_t mSkipRenderingUntilMediaTimeUs; 77 int64_t mNumFramesTotal; 78 int64_t mNumInputFramesDropped; 79 int64_t mNumOutputFramesDropped; 80 int32_t mVideoWidth; 81 int32_t mVideoHeight; 82 bool mIsAudio; 83 bool mIsVideoAVC; 84 bool mIsSecure; 85 bool mFormatChangePending; 86 bool mTimeChangePending; 87 88 bool mPaused; 89 bool mResumePending; 90 AString mComponentName; 91 92 void handleError(int32_t err); 93 bool handleAnInputBuffer(size_t index); 94 bool handleAnOutputBuffer( 95 size_t index, 96 size_t offset, 97 size_t size, 98 int64_t timeUs, 99 int32_t flags); 100 void handleOutputFormatChange(const sp<AMessage> &format); 101 102 void releaseAndResetMediaBuffers(); 103 void requestCodecNotification(); 104 bool isStaleReply(const sp<AMessage> &msg); 105 106 void doFlush(bool notifyComplete); 107 status_t fetchInputData(sp<AMessage> &reply); 108 bool onInputBufferFetched(const sp<AMessage> &msg); 109 void onRenderBuffer(const sp<AMessage> &msg); 110 111 bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; 112 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; 113 void rememberCodecSpecificData(const sp<AMessage> &format); 114 bool isDiscontinuityPending() const; 115 void finishHandleDiscontinuity(bool flushOnTimeChange); 116 117 void notifyResumeCompleteIfNecessary(); 118 119 DISALLOW_EVIL_CONSTRUCTORS(Decoder); 120}; 121 122} // namespace android 123 124#endif // NUPLAYER_DECODER_H_ 125