• 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     C2PooledBlockPool(const std::shared_ptr<C2Allocator> &allocator, const local_id_t localId);
78 
79     virtual ~C2PooledBlockPool() override;
80 
getAllocatorId()81     virtual C2Allocator::id_t getAllocatorId() const override {
82         return mAllocator->getId();
83     }
84 
getLocalId()85     virtual local_id_t getLocalId() const override {
86         return mLocalId;
87     }
88 
89     virtual c2_status_t fetchLinearBlock(
90             uint32_t capacity,
91             C2MemoryUsage usage,
92             std::shared_ptr<C2LinearBlock> *block /* nonnull */) override;
93 
94     virtual c2_status_t fetchGraphicBlock(
95             uint32_t width,
96             uint32_t height,
97             uint32_t format,
98             C2MemoryUsage usage,
99             std::shared_ptr<C2GraphicBlock> *block) override;
100 
101     /**
102      * Retrieves the connection Id for underlying bufferpool
103      */
104     int64_t getConnectionId();
105 
106     /**
107      * Retrieves the accessor which is used by underlying bufferpool. (It can be
108      * passed to receiving process.)
109      *
110      * \param accessor          IAccessor will be written to this out parameter.
111      *
112      * \return true             IAcessor is writen successfully.
113      * \return false            IAccessor is not written.
114      */
115     bool getAccessor(android::sp<android::hardware::media::bufferpool::V2_0::IAccessor> *accessor);
116 
117 private:
118     const std::shared_ptr<C2Allocator> mAllocator;
119     const local_id_t mLocalId;
120 
121     class Impl;
122     std::unique_ptr<Impl> mImpl;
123 };
124 
125 #endif // STAGEFRIGHT_CODEC2_BUFFER_PRIV_H_
126