1 /* 2 * Copyright 2018 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 CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 18 #define CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 19 20 #include <gui/IGraphicBufferProducer.h> 21 #include <codec2/hidl/1.0/types.h> 22 #include <C2Work.h> 23 24 struct C2_HIDE _C2BlockPoolData; 25 26 namespace android { 27 namespace hardware { 28 namespace media { 29 namespace c2 { 30 namespace V1_0 { 31 namespace utils { 32 33 // BufferQueue-Based Block Operations 34 // ================================== 35 36 // Manage BufferQueue and graphic blocks for both component and codec. 37 // Manage graphic blocks ownership consistently during surface change. 38 struct OutputBufferQueue { 39 40 OutputBufferQueue(); 41 42 ~OutputBufferQueue(); 43 44 // Configure a new surface to render graphic blocks. 45 // Graphic blocks from older surface will be migrated to new surface. 46 bool configure(const sp<IGraphicBufferProducer>& igbp, 47 uint32_t generation, 48 uint64_t bqId); 49 50 // Render a graphic block to current surface. 51 status_t outputBuffer( 52 const C2ConstGraphicBlock& block, 53 const BnGraphicBufferProducer::QueueBufferInput& input, 54 BnGraphicBufferProducer::QueueBufferOutput* output); 55 56 // Call holdBufferQueueBlock() on output blocks in the given workList. 57 // The OutputBufferQueue will take the ownership of output blocks. 58 // 59 // Note: This function should be called after WorkBundle has been received 60 // from another process. 61 void holdBufferQueueBlocks( 62 const std::list<std::unique_ptr<C2Work>>& workList); 63 64 private: 65 66 std::mutex mMutex; 67 sp<IGraphicBufferProducer> mIgbp; 68 uint32_t mGeneration; 69 uint64_t mBqId; 70 std::shared_ptr<int> mOwner; 71 // To migrate existing buffers 72 sp<GraphicBuffer> mBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; // find a better way 73 std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS]; 74 75 bool registerBuffer(const C2ConstGraphicBlock& block); 76 }; 77 78 } // namespace utils 79 } // namespace V1_0 80 } // namespace c2 81 } // namespace media 82 } // namespace hardware 83 } // namespace android 84 85 #endif // CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE 86