• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2018, 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 #ifndef __TEST_DATA_ENCODE_H__
23 #define __TEST_DATA_ENCODE_H__
24 
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <string.h>
29 #include "driver_loader.h"
30 
31 #define ENC_FRAME_NUM 3
32 
33 const FeatureID TEST_Intel_Encode_HEVC  = { VAProfileHEVCMain    , VAEntrypointEncSlice  , };
34 const FeatureID TEST_Intel_Encode_AVC   = { VAProfileH264Main    , VAEntrypointEncSlice  , };
35 const FeatureID TEST_Intel_Encode_MPEG2 = { VAProfileMPEG2Main   , VAEntrypointEncSlice  , };
36 const FeatureID TEST_Intel_Encode_JPEG  = { VAProfileJPEGBaseline, VAEntrypointEncPicture, };
37 
38 class HevcEncBufs
39 {
40 public:
41 
42     HevcEncBufs();
43 
GetSpsSize()44     uint32_t GetSpsSize() { return sizeof(VAEncSequenceParameterBufferHEVC); }
45 
GetPpsSize()46     uint32_t GetPpsSize() { return sizeof(VAEncPictureParameterBufferHEVC); }
47 
GetSlcSize()48     uint32_t GetSlcSize() { return sizeof(VAEncSliceParameterBufferHEVC); }
49 
GetSpsBuf()50     VAEncSequenceParameterBufferHEVC *GetSpsBuf() { return m_sps.get(); }
51 
GetPpsBuf()52     VAEncPictureParameterBufferHEVC *GetPpsBuf() { return m_pps.get(); }
53 
GetSlcBuf()54     VAEncSliceParameterBufferHEVC *GetSlcBuf() { return m_slc.get(); }
55 
56 private:
57 
58     std::shared_ptr<VAEncSequenceParameterBufferHEVC> m_sps;
59     std::shared_ptr<VAEncPictureParameterBufferHEVC>  m_pps;
60     std::shared_ptr<VAEncSliceParameterBufferHEVC>    m_slc;
61 };
62 
63 class AvcEncBufs
64 {
65 public:
66 
67     AvcEncBufs();
68 
GetSpsSize()69     uint32_t GetSpsSize() { return sizeof(VAEncSequenceParameterBufferH264); }
70 
GetPpsSize()71     uint32_t GetPpsSize() { return sizeof(VAEncPictureParameterBufferH264); }
72 
GetSlcSize()73     uint32_t GetSlcSize() { return sizeof(VAEncSliceParameterBufferH264); }
74 
GetSpsBuf()75     VAEncSequenceParameterBufferH264 *GetSpsBuf() { return m_sps.get(); }
76 
GetPpsBuf()77     VAEncPictureParameterBufferH264 *GetPpsBuf() { return m_pps.get(); }
78 
GetSlcBuf()79     VAEncSliceParameterBufferH264 *GetSlcBuf() { return m_slc.get(); }
80 
81 private:
82 
83     std::shared_ptr<VAEncSequenceParameterBufferH264> m_sps;
84     std::shared_ptr<VAEncPictureParameterBufferH264>  m_pps;
85     std::shared_ptr<VAEncSliceParameterBufferH264>    m_slc;
86 };
87 
88 class EncTestData
89 {
90 public:
91 
~EncTestData()92     virtual ~EncTestData() { }
93 
GetFeatureID()94     FeatureID GetFeatureID() { return m_featureId; }
95 
GetWidth()96     uint32_t GetWidth() { return m_picWidth; }
97 
GetHeight()98     uint32_t GetHeight() { return m_picHeight; }
99 
GetCompBuffers()100     std::vector<std::vector<CompBufConif>> &GetCompBuffers() { return m_compBufs; }
101 
GetResources()102     std::vector<VASurfaceID> &GetResources() { return m_resources; }
103 
GetConfAttrib()104     std::vector<VAConfigAttrib> &GetConfAttrib() { return m_confAttrib; }
105 
GetSurfAttrib()106     std::vector<VASurfaceAttrib> &GetSurfAttrib() { return m_surfAttrib; }
107 
UpdateCompBuffers(int frameId)108     virtual void UpdateCompBuffers(int frameId) { }
109 
110 public:
111 
112     int                                    m_num_frames;
113 
114 protected:
115 
116     FeatureID                              m_featureId;
117     uint32_t                               m_picWidth;
118     uint32_t                               m_picHeight;
119     uint32_t                               m_surfacesNum;
120     std::vector<std::vector<CompBufConif>> m_compBufs;
121     std::vector<VASurfaceID>               m_resources;
122     std::vector<VAConfigAttrib>            m_confAttrib;
123     std::vector<VASurfaceAttrib>           m_surfAttrib;
124 };
125 
126 class EncTestDataHEVC : public EncTestData
127 {
128 public:
129 
130     EncTestDataHEVC(FeatureID testFeatureID);
131 
132     void UpdateCompBuffers(int frameId) override;
133 
134     struct EncFrameDataHEVC
135     {
136         std::vector<uint8_t> spsData;
137         std::vector<uint8_t> ppsData;
138         std::vector<uint8_t> sliceData;
139     };
140 
141 public:
142 
143     const std::vector<uint8_t> m_headerData = { 0x00, 0x00, 0x00, 0x01 };
144 
145 protected:
146 
147     void InitCompBuffers();
148 
149 protected:
150 
151     std::vector<EncFrameDataHEVC>    m_frameArray;
152     VAEncPackedHeaderParameterBuffer m_packedsps;
153     VAEncPackedHeaderParameterBuffer m_packedpps;
154     VAEncPackedHeaderParameterBuffer m_packedsh;
155     std::shared_ptr<HevcEncBufs>     m_pBufs = nullptr;
156 };
157 
158 class EncTestDataAVC: public EncTestData
159 {
160 public:
161 
162     EncTestDataAVC(FeatureID testFeatureID);
163 
164     void UpdateCompBuffers(int frameId) override;
165 
166     struct EncFrameDataAVC
167     {
168         std::vector<uint8_t> spsData;
169         std::vector<uint8_t> ppsData;
170         std::vector<uint8_t> sliceData;
171     };
172 
173 public:
174 
175     const std::vector<uint8_t> m_headerData = { 0x00, 0x00, 0x00, 0x01 };
176 
177 protected:
178 
179     void InitCompBuffers();
180 
181 protected:
182 
183     std::vector<EncFrameDataAVC>     m_frameArray;
184     VAEncPackedHeaderParameterBuffer m_packedsps;
185     VAEncPackedHeaderParameterBuffer m_packedpps;
186     VAEncPackedHeaderParameterBuffer m_packedsh;
187     std::shared_ptr<AvcEncBufs>      m_pBufs = nullptr;
188 };
189 
190 class EncTestDataFactory
191 {
192 public:
193 
GetEncTestData(const std::string & description)194     static EncTestData *GetEncTestData(const std::string &description)
195     {
196         if (description == "HEVC-DualPipe")
197         {
198             return new EncTestDataHEVC(TEST_Intel_Encode_HEVC);
199         }
200         if (description == "AVC-DualPipe")
201         {
202             return new EncTestDataAVC(TEST_Intel_Encode_AVC);
203         }
204 
205         return nullptr;
206     }
207 };
208 
209 #endif // __TEST_DATA_ENCODE_H__
210