Debian Codegraph @

media_softlet/agnostic/common/codec/hal/enc/shared/bufferMgr/encode_recycle_resource.h

raw
1 /*
2 * Copyright (c) 2018-2024, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file encode_recycle_resource.h
24 //! \brief Defines the interface for recycle resource
25 //! \details The manager for the recycle resources
26 //!
27
28 #ifndef __ENCODE_RECYCLE_RESOURCE_H__
29 #define __ENCODE_RECYCLE_RESOURCE_H__
30
31 #include "media_class_trace.h"
32 #include "mos_defs.h"
33 #include "mos_os.h"
34 #include "mos_os_specific.h"
35 #include <stdint.h>
36 #include <map>
37 #include <utility>
38 #if _MEDIA_RESERVED
39 #include "encode_recycle_resource_ext.h"
40 #endif
41
42 namespace encode
43 {
44 enum RecycleResId
45 {
46 PakInfo = 0,
47 FrameStatStreamOutBuffer,
48 VdencBRCHistoryBuffer,
49 VdencBrcDebugBuffer,
50 LcuBaseAddressBuffer,
51 VdencBrcPakMmioBuffer,
52 VdencStatsBuffer,
53 StreamInBuffer,
54 HucRoiOutputBuffer,
55 HucRoiDeltaQpBuffer,
56 HucRoiMapBuffer,
57 BrcPakStatisticBuffer,
58 BrcPakStatisticBufferFull,
59 PakSliceSizeStreamOutBuffer,
60 CuRecordStreamOutBuffer,
61 CuCountBuffer,
62 PreEncRawSurface,
63 PreEncRef0,
64 PreEncRef1,
65 VdaqmBuffer0,
66 VdaqmBuffer1,
67 VdaqmBuffer2,
68 VdaqmBuffer3,
69 VdaqmBuffer4,
70 #if _MEDIA_RESERVED
71 #define RECYCLE_IDS_EXT
72 #include "encode_recycle_resource_ext.h"
73 #undef RECYCLE_IDS_EXT
74 #endif
75 };
76
77 class EncodeAllocator;
78 class RecycleQueue;
79
80 class RecycleResource
81 {
82 public:
83 //!
84 //! \brief Constructor
85 //! \param [in] allocator
86 //! Pointer to EncodeAllocator
87 //!
88 RecycleResource(EncodeAllocator *allocator);
89
90 //!
91 //! \brief Destructor
92 //!
93 virtual ~RecycleResource();
94
95 //!
96 //! \brief Register resource
97 //! \param [in] id
98 //! The ID of resource which defined in RecycleResId
99 //! \param [in] param
100 //! MOS_ALLOC_GFXRES_PARAMS
101 //! \param [in] maxLimit
102 //! The limitation of number of the resource
103 //! \return MOS_STATUS
104 //! MOS_STATUS_SUCCESS if success, else fail reason
105 //!
106 MOS_STATUS RegisterResource(RecycleResId id, MOS_ALLOC_GFXRES_PARAMS param, uint32_t maxLimit = m_maxRecycleNum);
107
108 //!
109 //! \brief Get Surface
110 //! \param [in] id
111 //! The ID of resource which defined in RecycleResId
112 //! \param [in] frameIndex
113 //! Frame index
114 //! \return MOS_SURFACE *
115 //! MOS_SURFACE * if success, else nullptr if the pool is empty
116 //!
117 MOS_SURFACE *GetSurface(RecycleResId id, uint32_t frameIndex);
118
119 //!
120 //! \brief Get Buffer
121 //! \param [in] id
122 //! The ID of resource which defined in RecycleResId
123 //! \param [in] frameIndex
124 //! Frame index
125 //! \return MOS_RESOURCE *
126 //! MOS_RESOURCE * if success, else nullptr if the pool is empty
127 //!
128 virtual MOS_RESOURCE* GetBuffer(RecycleResId id, uint32_t frameIndex);
129
130 protected:
131 //!
132 //! \brief Get resource queue
133 //! \param [in] id
134 //! The ID of resource which defined in RecycleResId
135 //! \return RecycleQueue *
136 //! RecycleQueue * if success, else nullptr
137 //!
138 RecycleQueue *GetResQueue(RecycleResId id)
139 {
140 auto it = m_resourceQueues.find(id);
141
142 if (it == m_resourceQueues.end())
143 {
144 return nullptr;
145 }
146
147 return it->second;
148 }
149
150 static const uint8_t m_maxRecycleNum = 6;
151 EncodeAllocator *m_allocator = nullptr; //!< encoder allocator
152
153 std::map<RecycleResId, RecycleQueue *> m_resourceQueues{}; //!< resource queues
154
155 MEDIA_CLASS_DEFINE_END(encode__RecycleResource)
156 };
157 } // namespace encode
158 #endif // !__ENCODE_RECYCLE_RESOURCE_H__