Pawin Vongmasa | 3665390 | 2018-11-15 00:10:25 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 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 STAGEFRIGHT_CODEC2_BQ_BUFFER_PRIV_H_ |
| 18 | #define STAGEFRIGHT_CODEC2_BQ_BUFFER_PRIV_H_ |
| 19 | |
| 20 | #include <functional> |
| 21 | |
| 22 | #include <C2Buffer.h> |
| 23 | #include <media/stagefright/bqhelper/WGraphicBufferProducer.h> |
| 24 | |
| 25 | class C2BufferQueueBlockPool : public C2BlockPool { |
| 26 | public: |
| 27 | C2BufferQueueBlockPool(const std::shared_ptr<C2Allocator> &allocator, const local_id_t localId); |
| 28 | |
| 29 | virtual ~C2BufferQueueBlockPool() override; |
| 30 | |
| 31 | virtual C2Allocator::id_t getAllocatorId() const override { |
| 32 | return mAllocator->getId(); |
| 33 | }; |
| 34 | |
| 35 | virtual local_id_t getLocalId() const override { |
| 36 | return mLocalId; |
| 37 | }; |
| 38 | |
| 39 | virtual c2_status_t fetchGraphicBlock( |
| 40 | uint32_t width, |
| 41 | uint32_t height, |
| 42 | uint32_t format, |
| 43 | C2MemoryUsage usage, |
| 44 | std::shared_ptr<C2GraphicBlock> *block /* nonnull */) override; |
| 45 | |
| 46 | typedef std::function<void(uint64_t producer, int32_t slot, int64_t nsecs)> OnRenderCallback; |
| 47 | |
| 48 | /** |
| 49 | * Sets render callback. |
| 50 | * |
| 51 | * \param renderCallbak callback to call for all dequeue buffer. |
| 52 | */ |
| 53 | virtual void setRenderCallback(const OnRenderCallback &renderCallback = OnRenderCallback()); |
| 54 | |
| 55 | /** |
| 56 | * Configures an IGBP in order to create blocks. A newly created block is |
| 57 | * dequeued from the configured IGBP. Unique Id of IGBP and the slot number of |
| 58 | * blocks are passed via native_handle. Managing IGBP is responsibility of caller. |
| 59 | * When IGBP is not configured, block will be created via allocator. |
| 60 | * Since zero is not used for Unique Id of IGBP, if IGBP is not configured or producer |
| 61 | * is configured as nullptr, unique id which is bundled in native_handle is zero. |
| 62 | * |
| 63 | * \param producer the IGBP, which will be used to fetch blocks |
| 64 | */ |
| 65 | virtual void configureProducer(const android::sp<android::HGraphicBufferProducer> &producer); |
| 66 | |
| 67 | private: |
| 68 | const std::shared_ptr<C2Allocator> mAllocator; |
| 69 | const local_id_t mLocalId; |
| 70 | |
| 71 | class Impl; |
| 72 | std::shared_ptr<Impl> mImpl; |
| 73 | |
| 74 | friend struct C2BufferQueueBlockPoolData; |
| 75 | }; |
| 76 | |
| 77 | #endif // STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_ |