NuPlayerDecoder.h revision 095248375e29adde961ec2a44989ecb3a6dda6a2
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(); 40 virtual void signalResume(); 41 virtual void initiateShutdown(); 42 43 virtual bool supportsSeamlessFormatChange(const sp<AMessage> &to) const; 44 45 enum { 46 kWhatFillThisBuffer = 'flTB', 47 kWhatDrainThisBuffer = 'drTB', 48 kWhatOutputFormatChanged = 'fmtC', 49 kWhatFlushCompleted = 'flsC', 50 kWhatShutdownCompleted = 'shDC', 51 kWhatEOS = 'eos ', 52 kWhatError = 'err ', 53 }; 54 55protected: 56 57 virtual ~Decoder(); 58 59 virtual void onMessageReceived(const sp<AMessage> &msg); 60 61private: 62 enum { 63 kWhatCodecNotify = 'cdcN', 64 kWhatConfigure = 'conf', 65 kWhatGetInputBuffers = 'gInB', 66 kWhatInputBufferFilled = 'inpF', 67 kWhatRenderBuffer = 'rndr', 68 kWhatFlush = 'flus', 69 kWhatShutdown = 'shuD', 70 }; 71 72 sp<AMessage> mNotify; 73 sp<NativeWindowWrapper> mNativeWindow; 74 75 sp<AMessage> mInputFormat; 76 sp<AMessage> mOutputFormat; 77 sp<MediaCodec> mCodec; 78 sp<ALooper> mCodecLooper; 79 sp<ALooper> mDecoderLooper; 80 81 Vector<sp<ABuffer> > mInputBuffers; 82 Vector<sp<ABuffer> > mOutputBuffers; 83 Vector<bool> mInputBufferIsDequeued; 84 Vector<MediaBuffer *> mMediaBuffers; 85 86 void handleError(int32_t err); 87 bool handleAnInputBuffer(); 88 bool handleAnOutputBuffer(); 89 90 void releaseAndResetMediaBuffers(); 91 void requestCodecNotification(); 92 bool isStaleReply(const sp<AMessage> &msg); 93 94 void onConfigure(const sp<AMessage> &format); 95 void onFlush(); 96 void onResume(); 97 void onInputBufferFilled(const sp<AMessage> &msg); 98 void onRenderBuffer(const sp<AMessage> &msg); 99 void onShutdown(); 100 101 int32_t mBufferGeneration; 102 bool mPaused; 103 AString mComponentName; 104 105 bool supportsSeamlessAudioFormatChange(const sp<AMessage> &targetFormat) const; 106 107 DISALLOW_EVIL_CONSTRUCTORS(Decoder); 108}; 109 110struct NuPlayer::CCDecoder : public RefBase { 111 enum { 112 kWhatClosedCaptionData, 113 kWhatTrackAdded, 114 }; 115 116 CCDecoder(const sp<AMessage> ¬ify); 117 118 size_t getTrackCount() const; 119 sp<AMessage> getTrackInfo(size_t index) const; 120 status_t selectTrack(size_t index, bool select); 121 bool isSelected() const; 122 void decode(const sp<ABuffer> &accessUnit); 123 void display(int64_t timeUs); 124 125private: 126 struct CCData; 127 128 sp<AMessage> mNotify; 129 KeyedVector<int64_t, sp<ABuffer> > mCCMap; 130 size_t mTrackCount; 131 int32_t mSelectedTrack; 132 133 bool isNullPad(CCData *cc) const; 134 void dumpBytePair(const sp<ABuffer> &ccBuf) const; 135 bool extractFromSEI(const sp<ABuffer> &accessUnit); 136 137 DISALLOW_EVIL_CONSTRUCTORS(CCDecoder); 138}; 139 140} // namespace android 141 142#endif // NUPLAYER_DECODER_H_ 143