MediaFilter.h revision d291c222357303b9611cab89d0c3b047584ef377
1/* 2 * Copyright (C) 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 MEDIA_FILTER_H_ 18#define MEDIA_FILTER_H_ 19 20#include <media/stagefright/CodecBase.h> 21 22namespace android { 23 24struct ABuffer; 25struct GraphicBufferListener; 26struct MemoryDealer; 27struct SimpleFilter; 28 29struct MediaFilter : public CodecBase { 30 MediaFilter(); 31 32 virtual void setNotificationMessage(const sp<AMessage> &msg); 33 34 virtual void initiateAllocateComponent(const sp<AMessage> &msg); 35 virtual void initiateConfigureComponent(const sp<AMessage> &msg); 36 virtual void initiateCreateInputSurface(); 37 virtual void initiateUsePersistentInputSurface( 38 const sp<PersistentSurface> &surface); 39 40 virtual void initiateStart(); 41 virtual void initiateShutdown(bool keepComponentAllocated = false); 42 43 virtual void signalFlush(); 44 virtual void signalResume(); 45 46 virtual void signalRequestIDRFrame(); 47 virtual void signalSetParameters(const sp<AMessage> &msg); 48 virtual void signalEndOfInputStream(); 49 50 virtual void onMessageReceived(const sp<AMessage> &msg); 51 52 struct PortDescription : public CodecBase::PortDescription { 53 virtual size_t countBuffers(); 54 virtual IOMX::buffer_id bufferIDAt(size_t index) const; 55 virtual sp<ABuffer> bufferAt(size_t index) const; 56 57 protected: 58 PortDescription(); 59 60 private: 61 friend struct MediaFilter; 62 63 Vector<IOMX::buffer_id> mBufferIDs; 64 Vector<sp<ABuffer> > mBuffers; 65 66 void addBuffer(IOMX::buffer_id id, const sp<ABuffer> &buffer); 67 68 DISALLOW_EVIL_CONSTRUCTORS(PortDescription); 69 }; 70 71protected: 72 virtual ~MediaFilter(); 73 74private: 75 struct BufferInfo { 76 enum Status { 77 OWNED_BY_US, 78 OWNED_BY_UPSTREAM, 79 }; 80 81 IOMX::buffer_id mBufferID; 82 int32_t mGeneration; 83 int32_t mOutputFlags; 84 Status mStatus; 85 86 sp<ABuffer> mData; 87 }; 88 89 enum State { 90 UNINITIALIZED, 91 INITIALIZED, 92 CONFIGURED, 93 STARTED, 94 }; 95 96 enum { 97 kWhatInputBufferFilled = 'inpF', 98 kWhatOutputBufferDrained = 'outD', 99 kWhatShutdown = 'shut', 100 kWhatFlush = 'flus', 101 kWhatResume = 'resm', 102 kWhatAllocateComponent = 'allo', 103 kWhatConfigureComponent = 'conf', 104 kWhatCreateInputSurface = 'cisf', 105 kWhatSignalEndOfInputStream = 'eois', 106 kWhatStart = 'star', 107 kWhatSetParameters = 'setP', 108 kWhatProcessBuffers = 'proc', 109 }; 110 111 enum { 112 kPortIndexInput = 0, 113 kPortIndexOutput = 1 114 }; 115 116 // member variables 117 AString mComponentName; 118 State mState; 119 status_t mInputEOSResult; 120 int32_t mWidth, mHeight; 121 int32_t mStride, mSliceHeight; 122 int32_t mColorFormatIn, mColorFormatOut; 123 size_t mMaxInputSize, mMaxOutputSize; 124 int32_t mGeneration; 125 sp<AMessage> mNotify; 126 sp<AMessage> mInputFormat; 127 sp<AMessage> mOutputFormat; 128 129 sp<MemoryDealer> mDealer[2]; 130 Vector<BufferInfo> mBuffers[2]; 131 Vector<BufferInfo*> mAvailableInputBuffers; 132 Vector<BufferInfo*> mAvailableOutputBuffers; 133 bool mPortEOS[2]; 134 135 sp<SimpleFilter> mFilter; 136 sp<GraphicBufferListener> mGraphicBufferListener; 137 138 // helper functions 139 void signalProcessBuffers(); 140 void signalError(status_t error); 141 142 status_t allocateBuffersOnPort(OMX_U32 portIndex); 143 BufferInfo *findBufferByID( 144 uint32_t portIndex, IOMX::buffer_id bufferID, 145 ssize_t *index = NULL); 146 void postFillThisBuffer(BufferInfo *info); 147 void postDrainThisBuffer(BufferInfo *info); 148 void postEOS(); 149 void sendFormatChange(); 150 void requestFillEmptyInput(); 151 void processBuffers(); 152 153 void onAllocateComponent(const sp<AMessage> &msg); 154 void onConfigureComponent(const sp<AMessage> &msg); 155 void onStart(); 156 void onInputBufferFilled(const sp<AMessage> &msg); 157 void onOutputBufferDrained(const sp<AMessage> &msg); 158 void onShutdown(const sp<AMessage> &msg); 159 void onFlush(); 160 void onSetParameters(const sp<AMessage> &msg); 161 void onCreateInputSurface(); 162 void onInputFrameAvailable(); 163 void onSignalEndOfInputStream(); 164 165 DISALLOW_EVIL_CONSTRUCTORS(MediaFilter); 166}; 167 168} // namespace android 169 170#endif // MEDIA_FILTER_H_ 171