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