NuPlayerDecoder.h revision b86e68f834b7040518b99d1d0245d5f2e5cb9c86
1/* 2 * Copyright (C) 2010 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 19#define NUPLAYER_DECODER_H_ 20 21#include "NuPlayer.h" 22 23#include <media/stagefright/foundation/AHandler.h> 24 25namespace android { 26 27struct ABuffer; 28struct MediaCodec; 29struct MediaBuffer; 30 31struct NuPlayer::Decoder : public AHandler { 32 Decoder(const sp<AMessage> ¬ify, 33 const sp<NativeWindowWrapper> &nativeWindow = NULL); 34 35 virtual void configure(const sp<AMessage> &format); 36 virtual void init(); 37 38 status_t getInputBuffers(Vector<sp<ABuffer> > *dstBuffers) const; 39 virtual void signalFlush(const sp<AMessage> &format = NULL); 40 virtual void signalUpdateFormat(const sp<AMessage> &format); 41 virtual void signalResume(); 42 virtual void initiateShutdown(); 43 44 virtual bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; 45 46 enum { 47 kWhatFillThisBuffer = 'flTB', 48 kWhatDrainThisBuffer = 'drTB', 49 kWhatOutputFormatChanged = 'fmtC', 50 kWhatFlushCompleted = 'flsC', 51 kWhatShutdownCompleted = 'shDC', 52 kWhatEOS = 'eos ', 53 kWhatError = 'err ', 54 }; 55 56protected: 57 58 virtual ~Decoder(); 59 60 virtual void onMessageReceived(const sp<AMessage> &msg); 61 62private: 63 enum { 64 kWhatCodecNotify = 'cdcN', 65 kWhatConfigure = 'conf', 66 kWhatGetInputBuffers = 'gInB', 67 kWhatInputBufferFilled = 'inpF', 68 kWhatRenderBuffer = 'rndr', 69 kWhatFlush = 'flus', 70 kWhatShutdown = 'shuD', 71 kWhatUpdateFormat = 'uFmt', 72 }; 73 74 sp<AMessage> mNotify; 75 sp<NativeWindowWrapper> mNativeWindow; 76 77 sp<AMessage> mInputFormat; 78 sp<AMessage> mOutputFormat; 79 sp<MediaCodec> mCodec; 80 sp<ALooper> mCodecLooper; 81 sp<ALooper> mDecoderLooper; 82 83 Vector<sp<ABuffer> > mInputBuffers; 84 Vector<sp<ABuffer> > mOutputBuffers; 85 Vector<sp<ABuffer> > mCSDsForCurrentFormat; 86 Vector<sp<ABuffer> > mCSDsToSubmit; 87 Vector<bool> mInputBufferIsDequeued; 88 Vector<MediaBuffer *> mMediaBuffers; 89 90 void handleError(int32_t err); 91 bool handleAnInputBuffer(); 92 bool handleAnOutputBuffer(); 93 94 void releaseAndResetMediaBuffers(); 95 void requestCodecNotification(); 96 bool isStaleReply(const sp<AMessage> &msg); 97 98 void onConfigure(const sp<AMessage> &format); 99 void onFlush(); 100 void onResume(); 101 void onInputBufferFilled(const sp<AMessage> &msg); 102 void onRenderBuffer(const sp<AMessage> &msg); 103 void onShutdown(); 104 105 int32_t mBufferGeneration; 106 bool mPaused; 107 AString mComponentName; 108 109 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; 110 void rememberCodecSpecificData(const sp<AMessage> &format); 111 112 DISALLOW_EVIL_CONSTRUCTORS(Decoder); 113}; 114 115struct NuPlayer::CCDecoder : public RefBase { 116 enum { 117 kWhatClosedCaptionData, 118 kWhatTrackAdded, 119 }; 120 121 CCDecoder(const sp<AMessage> ¬ify); 122 123 size_t getTrackCount() const; 124 sp<AMessage> getTrackInfo(size_t index) const; 125 status_t selectTrack(size_t index, bool select); 126 bool isSelected() const; 127 void decode(const sp<ABuffer> &accessUnit); 128 void display(int64_t timeUs); 129 void flush(); 130 131private: 132 sp<AMessage> mNotify; 133 KeyedVector<int64_t, sp<ABuffer> > mCCMap; 134 size_t mCurrentChannel; 135 int32_t mSelectedTrack; 136 int32_t mTrackIndices[4]; 137 Vector<size_t> mFoundChannels; 138 139 bool isTrackValid(size_t index) const; 140 int32_t getTrackIndex(size_t channel) const; 141 bool extractFromSEI(const sp<ABuffer> &accessUnit); 142 sp<ABuffer> filterCCBuf(const sp<ABuffer> &ccBuf, size_t index); 143 144 DISALLOW_EVIL_CONSTRUCTORS(CCDecoder); 145}; 146 147} // namespace android 148 149#endif // NUPLAYER_DECODER_H_ 150