• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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_BUFFER_PRIV_H_
18 #define STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_
19 
20 #include <functional>
21 
22 #include <C2Buffer.h>
23 #include <android/hardware/media/bufferpool/2.0/IAccessor.h>
24 
25 class C2BasicLinearBlockPool : public C2BlockPool {
26 public:
27     explicit C2BasicLinearBlockPool(const std::shared_ptr<C2Allocator> &allocator);
28 
29     virtual ~C2BasicLinearBlockPool() override = default;
30 
getAllocatorId()31     virtual C2Allocator::id_t getAllocatorId() const override {
32         return mAllocator->getId();
33     }
34 
getLocalId()35     virtual local_id_t getLocalId() const override {
36         return BASIC_LINEAR;
37     }
38 
39     virtual c2_status_t fetchLinearBlock(
40             uint32_t capacity,
41             C2MemoryUsage usage,
42             std::shared_ptr<C2LinearBlock> *block /* nonnull */) override;
43 
44     // TODO: fetchCircularBlock
45 
46 private:
47     const std::shared_ptr<C2Allocator> mAllocator;
48 };
49 
50 class C2BasicGraphicBlockPool : public C2BlockPool {
51 public:
52     explicit C2BasicGraphicBlockPool(const std::shared_ptr<C2Allocator> &allocator);
53 
54     virtual ~C2BasicGraphicBlockPool() override = default;
55 
getAllocatorId()56     virtual C2Allocator::id_t getAllocatorId() const override {
57         return mAllocator->getId();
58     }
59 
getLocalId()60     virtual local_id_t getLocalId() const override {
61         return BASIC_GRAPHIC;
62     }
63 
64     virtual c2_status_t fetchGraphicBlock(
65             uint32_t width,
66             uint32_t height,
67             uint32_t format,
68             C2MemoryUsage usage,
69             std::shared_ptr<C2GraphicBlock> *block /* nonnull */) override;
70 
71 private:
72     const std::shared_ptr<C2Allocator> mAllocator;
73 };
74 
75 class C2PooledBlockPool : public C2BlockPool {
76 public:
77     enum BufferPoolVer : int {
78         VER_HIDL = 0,
79         VER_AIDL2
80     };
81     C2PooledBlockPool(
82             const std::shared_ptr<C2Allocator> &allocator,
83             const local_id_t localId,
84             BufferPoolVer ver = VER_HIDL);
85 
86     virtual ~C2PooledBlockPool() override;
87 
getAllocatorId()88     virtual C2Allocator::id_t getAllocatorId() const override {
89         return mAllocator->getId();
90     }
91 
getLocalId()92     virtual local_id_t getLocalId() const override {
93         return mLocalId;
94     }
95 
96     virtual c2_status_t fetchLinearBlock(
97             uint32_t capacity,
98             C2MemoryUsage usage,
99             std::shared_ptr<C2LinearBlock> *block /* nonnull */) override;
100 
101     virtual c2_status_t fetchGraphicBlock(
102             uint32_t width,
103             uint32_t height,
104             uint32_t format,
105             C2MemoryUsage usage,
106             std::shared_ptr<C2GraphicBlock> *block) override;
107 
108     /**
109      * Retrieves the connection Id for underlying bufferpool
110      */
111     int64_t getConnectionId();
112 
113     /**
114      * Retrieves the accessor which is used by underlying bufferpool. (It can be
115      * passed to receiving process.)
116      *
117      * \param accessor          IAccessor will be written to this out parameter.
118      *
119      * \return true             IAcessor is writen successfully.
120      * \return false            IAccessor is not written.
121      */
122     bool getAccessor(android::sp<android::hardware::media::bufferpool::V2_0::IAccessor> *accessor);
123 
124 private:
125     const std::shared_ptr<C2Allocator> mAllocator;
126     const local_id_t mLocalId;
127     const BufferPoolVer mBufferPoolVer;
128 
129     class Impl; // HIDL BufferPool VER_HIDL
130     std::unique_ptr<Impl> mImpl;
131     class Impl2; // AIDL BufferPool(bufferpool2) VER_AIDL2
132     std::unique_ptr<Impl2> mImpl2;
133 };
134 
135 #endif // STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_
136