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