• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <codec2/hidl/1.2/types.h>
23 #include <C2Work.h>
24 
25 struct C2_HIDE _C2BlockPoolData;
26 class C2SurfaceSyncMemory;
27 
28 namespace android {
29 namespace hardware {
30 namespace media {
31 namespace c2 {
32 
33 
34 // BufferQueue-Based Block Operations
35 // ==================================
36 
37 // Manage BufferQueue and graphic blocks for both component and codec.
38 // Manage graphic blocks ownership consistently during surface change.
39 struct OutputBufferQueue {
40 
41     OutputBufferQueue();
42 
43     ~OutputBufferQueue();
44 
45     // Configure a new surface to render graphic blocks.
46     // Graphic blocks from older surface will be migrated to new surface.
47     bool configure(const sp<IGraphicBufferProducer>& igbp,
48                    uint32_t generation,
49                    uint64_t bqId,
50                    int maxDequeueBufferCount,
51                    std::shared_ptr<V1_2::SurfaceSyncObj> *syncObj);
52 
53     // Stop using the current output surface. Pending buffer opeations will not
54     // perform anymore.
55     void stop();
56 
57     // Render a graphic block to current surface.
58     status_t outputBuffer(
59             const C2ConstGraphicBlock& block,
60             const BnGraphicBufferProducer::QueueBufferInput& input,
61             BnGraphicBufferProducer::QueueBufferOutput* output);
62 
63     // Call holdBufferQueueBlock() on output blocks in the given workList.
64     // The OutputBufferQueue will take the ownership of output blocks.
65     //
66     // Note: This function should be called after WorkBundle has been received
67     // from another process.
68     void holdBufferQueueBlocks(
69             const std::list<std::unique_ptr<C2Work>>& workList);
70 
71     // Update # of max dequeue buffer from BQ. If # of max dequeued buffer is shared
72     // via shared memory between HAL and framework, Update # of max dequeued buffer
73     // and synchronize.
74     void updateMaxDequeueBufferCount(int maxDequeueBufferCount);
75 
76 private:
77 
78     std::mutex mMutex;
79     sp<IGraphicBufferProducer> mIgbp;
80     uint32_t mGeneration;
81     uint64_t mBqId;
82     int32_t mMaxDequeueBufferCount;
83     std::shared_ptr<int> mOwner;
84     // To migrate existing buffers
85     sp<GraphicBuffer> mBuffers[BufferQueueDefs::NUM_BUFFER_SLOTS]; // find a better way
86     std::weak_ptr<_C2BlockPoolData> mPoolDatas[BufferQueueDefs::NUM_BUFFER_SLOTS];
87     std::shared_ptr<C2SurfaceSyncMemory> mSyncMem;
88     bool mStopped;
89 
90     bool registerBuffer(const C2ConstGraphicBlock& block);
91 };
92 
93 }  // namespace c2
94 }  // namespace media
95 }  // namespace hardware
96 }  // namespace android
97 
98 #endif  // CODEC2_HIDL_V1_0_UTILS_OUTPUT_BUFFER_QUEUE
99