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