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