1 // Copyright (c) 2020 Intel Corporation
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #pragma once
22 #include "libmfx_core_interface.h"
23 #include "feature_blocks/mfx_feature_blocks_utils.h"
24 #include <vector>
25 
26 namespace MfxEncodeHW
27 {
28 class ResPool
29     : public MfxFeatureBlocks::Storable
30 {
31 public:
32     static constexpr mfxU8 IDX_INVALID = 0xff;
33 
34     struct Resource
35     {
36         mfxU8    Idx = IDX_INVALID;
37         mfxMemId Mid = nullptr;
38     };
39 
40     ResPool(VideoCORE& core);
41 
42     ~ResPool();
43 
44     virtual mfxStatus Alloc(
45          const mfxFrameAllocRequest & req
46         , bool isCopyRequired);
47 
48     mfxStatus AllocOpaque(
49         const mfxFrameInfo & info
50         , mfxU16 type
51         , mfxFrameSurface1 **surfaces
52         , mfxU16 numSurface);
53 
GetResponse()54     mfxFrameAllocResponse GetResponse()   const { return m_response; }
GetInfo()55     mfxFrameInfo          GetInfo()       const { return m_info; }
56     Resource              Acquire();
Release(mfxU32 idx)57     void                  Release(mfxU32 idx) { Unlock(idx); }
58     void                  ClearFlag(mfxU32 idx);
59     void                  SetFlag(mfxU32 idx, mfxU32 flag);
60     mfxU32                GetFlag(mfxU32 idx);
61     void                  UnlockAll();
62     mfxU32                Lock(mfxU32 idx);
63     mfxU32                Unlock(mfxU32 idx);
64     mfxU32                Locked(mfxU32 idx) const;
65 
66     virtual void Free();
67 
IsExternal()68     bool IsExternal() { return m_bExternal; };
69 
70 protected:
71     ResPool(ResPool const &) = delete;
72     ResPool & operator =(ResPool const &) = delete;
73 
74     VideoCORE& m_core;
75 
76     std::vector<mfxFrameAllocResponse> m_responseQueue;
77     std::vector<mfxMemId>              m_mids;
78     std::vector<mfxU32>                m_locked;
79     std::vector<mfxU32>                m_flag;
80     mfxFrameInfo                       m_info           = {};
81     mfxFrameAllocResponse              m_response       = {};
82     bool                               m_bExternal      = true;
83     bool                               m_bOpaque        = false;
84     mfxU16                             m_numFrameActual = 0;
85 };
86 
87 } //namespace MfxEHW