1 /* 2 * Copyright (C) 2019 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 FRAME_CAPTURE_LAYER_H_ 18 #define FRAME_CAPTURE_LAYER_H_ 19 20 #include <media/stagefright/foundation/ABase.h> 21 #include <gui/IConsumerListener.h> 22 #include <ui/GraphicTypes.h> 23 #include <utils/Mutex.h> 24 #include <utils/Condition.h> 25 26 namespace android { 27 28 class GraphicBuffer; 29 class IGraphicBufferConsumer; 30 class Rect; 31 class Surface; 32 33 /* 34 * This class is a simple BufferQueue consumer implementation to 35 * obtain a decoded buffer output from MediaCodec. The output 36 * buffer is then sent to FrameCaptureProcessor to be converted 37 * to sRGB properly. 38 */ 39 struct FrameCaptureLayer : public ConsumerListener { 40 FrameCaptureLayer(); 41 ~FrameCaptureLayer() = default; 42 43 // ConsumerListener 44 void onFrameAvailable(const BufferItem& /*item*/) override; 45 void onBuffersReleased() override; 46 void onSidebandStreamChanged() override; 47 48 status_t init(); 49 getSurfaceFrameCaptureLayer50 sp<Surface> getSurface() { return mSurface; } 51 52 status_t capture(const ui::PixelFormat reqPixelFormat, 53 const Rect &sourceCrop, sp<GraphicBuffer> *outBuffer); 54 55 private: 56 struct BufferLayer; 57 // Note: do not hold any sp ref to GraphicBufferSource 58 // GraphicBufferSource is holding an sp to us, holding any sp ref 59 // to GraphicBufferSource will cause circular dependency and both 60 // object will not be released. 61 sp<IGraphicBufferConsumer> mConsumer; 62 sp<Surface> mSurface; 63 std::map<int32_t, sp<GraphicBuffer> > mSlotToBufferMap; 64 65 Mutex mLock; 66 Condition mCondition; 67 bool mFrameAvailable GUARDED_BY(mLock); 68 69 status_t acquireBuffer(BufferItem *bi); 70 status_t releaseBuffer(const BufferItem &bi); 71 72 DISALLOW_EVIL_CONSTRUCTORS(FrameCaptureLayer); 73 }; 74 75 } // namespace android 76 77 #endif // FRAME_CAPTURE_LAYER_H_ 78