1 /* 2 * Copyright (c) 2017, 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 media_ddi_encode_mpeg2.h 24 //! \brief Defines class for DDI media mpeg2 encode 25 //! 26 27 #ifndef __MEDIA_LIBVA_ENCODER_MPEG2_H__ 28 #define __MEDIA_LIBVA_ENCODER_MPEG2_H__ 29 30 #include "media_ddi_encode_base.h" 31 32 static const uint8_t maxTimeCodePic = 59; 33 static const uint8_t maxTimeCodeSec = 59; 34 static const uint8_t maxTimeCodeMin = 59; 35 static const uint8_t maxTimeCodeHr = 23; 36 37 //! 38 //! \struct _DDI_ENCODE_MPEG2_FRAME_RATE 39 //! \brief Define Mpeg2 encode frame rate 40 //! 41 static struct _DDI_ENCODE_MPEG2_FRAME_RATE 42 { 43 uint32_t code; //!< Index code. 44 float value; //!< Frame rate value. 45 } frameRateTable[] = { //!< Mpeg2 encode frame rate table. 46 {1, 23.976}, 47 {2, 24.0}, 48 {3, 25.0}, 49 {4, 29.97}, 50 {5, 30}, 51 {6, 50}, 52 {7, 59.94}, 53 {8, 60}}; 54 55 //! 56 //! \class DdiEncodeMpeg2 57 //! \brief Ddi encode MPEG2 58 //! 59 class DdiEncodeMpeg2 : public DdiEncodeBase 60 { 61 public: 62 //! 63 //! \brief Constructor 64 //! DdiEncodeMpeg2()65 DdiEncodeMpeg2(){}; 66 67 //! 68 //! \brief Destructor 69 //! 70 ~DdiEncodeMpeg2(); 71 72 //! 73 //! \brief Initialize Encode Context and CodecHal Setting for Mpeg2 74 //! 75 //! \param [out] codecHalSettings 76 //! Pointer to CodechalSetting * 77 //! 78 //! \return VAStatus 79 //! VA_STATUS_SUCCESS if success, else fail reason 80 //! 81 VAStatus ContextInitialize( 82 CodechalSetting *codecHalSettings) override; 83 84 //! 85 //! \brief Parse buffer to the server. 86 //! 87 //! \param [in] ctx 88 //! Pointer to VADriverContextP 89 //! \param [in] context 90 //! VA context ID 91 //! \param [in] buffers 92 //! Pointer to VABufferID 93 //! \param [in] numBuffers 94 //! Number of buffers 95 //! 96 //! \return VAStatus 97 //! VA_STATUS_SUCCESS if success, else fail reason 98 //! 99 VAStatus RenderPicture( 100 VADriverContextP ctx, 101 VAContextID context, 102 VABufferID *buffers, 103 int32_t numBuffers) override; 104 105 protected: 106 //! 107 //! \brief Reset Encode Context At Frame Level 108 //! 109 //! \return VAStatus 110 //! VA_STATUS_SUCCESS if success, else fail reason 111 //! 112 VAStatus ResetAtFrameLevel() override; 113 114 //! 115 //! \brief Encode in CodecHal for Mpeg2 116 //! 117 //! \param [in] numSlices 118 //! Number of slice data structures 119 //! 120 //! \return VAStatus 121 //! VA_STATUS_SUCCESS if success, else fail reason 122 //! 123 VAStatus EncodeInCodecHal( 124 uint32_t numSlices) override; 125 126 //! 127 //! \brief Parse Picture Parameter buffer to Encode Context 128 //! 129 //! \param [in] mediaCtx 130 //! Pointer to DDI_MEDIA_CONTEXT 131 //! \param [in] ptr 132 //! Pointer to Picture Parameter buffer 133 //! 134 //! \return VAStatus 135 //! VA_STATUS_SUCCESS if success, else fail reason 136 //! 137 VAStatus ParsePicParams( 138 DDI_MEDIA_CONTEXT *mediaCtx, 139 void *ptr) override; 140 141 uint32_t getSliceParameterBufferSize() override; 142 143 uint32_t getSequenceParameterBufferSize() override; 144 145 uint32_t getPictureParameterBufferSize() override; 146 147 uint32_t getQMatrixBufferSize() override; 148 149 //! 150 //! \brief Parse QMatrix buffer to Encode Context 151 //! 152 //! \param [in] ptr 153 //! Pointer to QMatrix buffer 154 //! 155 //! \return VAStatus 156 //! VA_STATUS_SUCCESS if success, else fail reason 157 //! 158 VAStatus Qmatrix( 159 void *ptr); 160 161 //! 162 //! \brief Parse Sequence Parameter buffer to Encode Context 163 //! 164 //! \param [in] ptr 165 //! Pointer to Sequence Parameter buffer 166 //! 167 //! \return VAStatus 168 //! VA_STATUS_SUCCESS if success, else fail reason 169 //! 170 VAStatus ParseSeqParams( 171 void *ptr); 172 173 //! 174 //! \brief Parse Slice Parameter buffer to Encode Context 175 //! 176 //! \param [in] mediaCtx 177 //! Pointer to DDI_MEDIA_CONTEXT 178 //! \param [in] ptr 179 //! Pointer to Slice Parameter buffer 180 //! \param [in] numSlices 181 //! Number of slice 182 //! 183 //! \return VAStatus 184 //! VA_STATUS_SUCCESS if success, else fail reason 185 //! 186 VAStatus ParseSlcParams( 187 DDI_MEDIA_CONTEXT *mediaCtx, 188 void *ptr, 189 uint32_t numSlices); 190 191 //! 192 //! \brief Parse Packed Header Parameter buffer to Encode Context 193 //! 194 //! \param [in] ptr 195 //! Pointer to Packed Header Parameter buffer 196 //! 197 //! return VAStatus 198 //! VA_STATUS_SUCCESS if success, else fail reason 199 //! 200 VAStatus ParsePackedHeaderParams( 201 void *ptr); 202 203 //! 204 //! \brief Parse Packed Header Data buffer to Encode Context 205 //! 206 //! \param [in] ptr 207 //! Pointer to Packed Header Data buffer 208 //! 209 //! return VAStatus 210 //! VA_STATUS_SUCCESS if success, else fail reason 211 //! 212 VAStatus ParsePackedHeaderData( 213 void *ptr); 214 215 //! 216 //! \brief Parse Misc Parameter buffer to Encode Context 217 //! 218 //! \param [in] ptr 219 //! Pointer to Misc Parameter buffer 220 //! 221 //! \return VAStatus 222 //! VA_STATUS_SUCCESS if success, else fail reason 223 //! 224 VAStatus ParseMiscParams( 225 void *ptr); 226 227 private: 228 //! 229 //! \brief Remove Mpeg2 User Data in Encode Context 230 //! 231 //! return VAStatus 232 //! VA_STATUS_SUCCESS if success, else fail reason 233 //! 234 VAStatus RemoveUserData(); 235 236 //! 237 //! \brief Get Framerate Code from frame rate value 238 //! 239 //! \param [in] frameRate 240 //! Frame rate value 241 //! \param [in] frameRateExtD 242 //! Frame rate ExtD value 243 //! \param [in] frameRateExtN 244 //! Frame rate ExtN value 245 //! 246 //! \return uint32_t 247 //! Get Framerate Code 248 //! 249 uint32_t CalculateFramerateCode( 250 float frameRate, 251 uint8_t frameRateExtD, 252 uint8_t frameRateExtN); 253 254 //! 255 //! \brief Parse Misc Param VBV Data buffer to Encode Context 256 //! 257 //! \param [in] data 258 //! Pointer to Misc Param VBV Data buffer 259 //! 260 //! return void 261 //! 262 void ParseMiscParamVBV( 263 void *data); 264 265 //! 266 //! \brief Parse Misc Param FR Data buffer to Encode Context 267 //! 268 //! \param [in] data 269 //! Pointer to Misc Param FR Data buffer 270 //! 271 //! return void 272 //! 273 void ParseMiscParamFR( 274 void *data); 275 276 //! 277 //! \brief Parse Misc Param RC Data buffer to Encode Context 278 //! 279 //! \param [in] data 280 //! Pointer to Misc Param RC Data buffer 281 //! 282 //! return void 283 //! 284 void ParseMiscParamRC( 285 void *data); 286 287 //! 288 //! \brief Parse Misc Param Max Frame Data buffer to Encode Context 289 //! 290 //! \param [in] data 291 //! Pointer to Misc Param Max Frame Data buffer 292 //! 293 //! return void 294 //! 295 void ParseMiscParamMaxFrame( 296 void *data); 297 298 //! 299 //! \brief Parse Misc Param Type Extension Data buffer to Encode Context 300 //! 301 //! \param [in] data 302 //! Pointer to Misc Param Type Extension Data buffer 303 //! 304 //! return void 305 //! 306 void ParseMiscParamTypeExtension( 307 void *data); 308 309 //! 310 //! \brief Parse Misc Param Type encode quality buffer to Encode Context 311 //! 312 //! \param [in] data 313 //! Pointer to Misc Param Type Extension Data buffer 314 //! 315 //! return void 316 //! 317 void ParseMiscParamEncQuality( 318 void *data); 319 320 //! 321 //! \brief Parse Misc Param Type encode quality level to Encode Context 322 //! 323 //! \param [in] data 324 //! Pointer to Misc Param Type encode quality level. 325 //! 326 //! return void 327 //! 328 void ParseMiscParamEncQualityLevel( 329 void *data); 330 331 //! 332 //! \brief Parse Misc Param Skip Frame Data buffer to Encode Context 333 //! 334 //! \param [in] data 335 //! Pointer to Misc Param Skip Frame Data buffer 336 //! 337 //! return void 338 //! 339 void ParseMiscParamSkipFrame( 340 void *data); 341 342 bool m_newTimeCode = false; //!< New time code flag. 343 uint32_t m_timeCode = 0; //!< New time code. 344 void *m_userDataListHead = nullptr; //!< User data list head. 345 void *m_userDataListTail = nullptr; //!< User data list tail. 346 }; 347 #endif /* __MEDIA_LIBVA_ENCODER_MPEG2_H__ */ 348