1 /* 2 * * Copyright (C) 2018 Intel Corporation. All Rights Reserved. 3 * * 4 ** Permission is hereby granted, free of charge, to any person obtaining a 5 * * copy of this software and associated documentation files (the 6 * * "Software"), to deal in the Software without restriction, including 7 * * without limitation the rights to use, copy, modify, merge, publish, 8 * * distribute, sub license, and/or sell copies of the Software, and to 9 * * permit persons to whom the Software is furnished to do so, subject to 10 * * the following conditions: 11 * * 12 * * The above copyright notice and this permission notice (including the 13 * * next paragraph) shall be included in all copies or substantial portions 14 * * of the Software. 15 * * 16 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 19 * * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 20 * * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 * * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 * * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * */ 24 25 /** 26 * @file VDecAccelVA.h 27 * @brief LibVA decode accelerator declaration 28 */ 29 30 #ifndef MV_ACCELERATOR_VAAPI_DECODE_H 31 #define MV_ACCELERATOR_VAAPI_DECODE_H 32 33 #include <stdio.h> 34 #include <stdlib.h> 35 #include <stdint.h> 36 #include <map> 37 #include <vector> 38 #include <algorithm> 39 #include <va/va.h> 40 #include "DecodeParamBuffer.h" 41 42 namespace mvaccel 43 { 44 /** 45 * @brief LibVA decode accelerator 46 */ 47 class VDecAccelVAImpl 48 { 49 public: 50 VDecAccelVAImpl(void* device); 51 VDecAccelVAImpl(); 52 virtual ~VDecAccelVAImpl(); 53 54 // VDecAccel interface 55 virtual int Open(); 56 virtual void Close(); 57 virtual uint32_t GetSurfaceID(uint32_t index); 58 bool DecodePicture(); 59 void bind_buffer(uint8_t* base); 60 61 protected: 62 // GfxSurfaceAccess interface 63 uint32_t get_width(VASurfaceID id); 64 uint32_t get_height(VASurfaceID id); 65 uint32_t get_stride(VASurfaceID id); 66 uint8_t* lock_surface(VASurfaceID id, bool write); 67 void unlock_surface(VASurfaceID id); 68 void* get_raw(VASurfaceID id); 69 void* get_device(VASurfaceID id); 70 71 typedef std::vector<VAConfigAttrib> VAConfigAttribArray; 72 typedef std::vector<VASurfaceAttrib> VASurfaceAttribArray; 73 74 // Member functions inherit by children 75 virtual bool is_config_compatible(DecodeDesc& desc); 76 virtual bool is_rt_foramt_supported(DecodeDesc& desc); 77 virtual void prepare_config_attribs( 78 DecodeDesc& desc, 79 VAConfigAttribArray& attribs); 80 virtual void prepare_surface_attribs( 81 DecodeDesc& desc, 82 VASurfaceAttribArray& attribs, 83 bool bDecodeDownsamplingHinted); 84 85 // Member fucntions NOT inherit by children 86 bool is_slice_mode_supported(DecodeDesc& desc); 87 bool is_encryption_supported(DecodeDesc& desc); 88 bool is_sfc_config_supported(DecodeDesc& desc); 89 VAStatus render_picture(VAContextID& vaContextID); 90 VAStatus query_status(); 91 VAStatus create_surface( 92 uint32_t width, 93 uint32_t height, 94 VASurfaceAttribArray& vaAttribs, 95 VASurfaceID& vaID); 96 void delete_surface(VASurfaceID& vaID); 97 void create_decode_desc(); 98 int check_process_pipeline_caps(DecodeDesc& desc); 99 int create_resources(); 100 101 protected: 102 int drm_fd = -1; 103 // VA ID & Handles 104 VADisplay m_vaDisplay; /**< @brief VA hardware device */ 105 VAProfile m_vaProfile; /**< @brief Video decoder profile */ 106 VAEntrypoint m_vaEntrypoint; /**< @brief VA entry point */ 107 VAConfigID m_vaConfigID; /**< @brief VA decode config id*/ 108 VAContextID m_vaContextID; /**< @brief Video decoder context */ 109 110 // VASurfaces id and attributes 111 std::vector<VASurfaceID> m_vaIDs; 112 VASurfaceAttribArray m_vaSurfAttribs; 113 114 uint32_t m_surfaceType; /**< @brief surface type */ 115 116 // Gfx surface access management 117 std::map<VASurfaceID, VAImage> m_images; /**< @brief buf pointer */ 118 119 enum SFC { 120 MAX_IN_W, 121 MAX_IN_H, 122 MIN_IN_W, 123 MIN_IN_H, 124 MAX_OUT_W, 125 MAX_OUT_H, 126 MIN_OUT_W, 127 MIN_OUT_H, 128 NEW_W, 129 NEW_H, 130 }; 131 132 DecodeDesc m_DecodeDesc{}; /**< @brief decode discription */ 133 VARectangle m_rectSrc{}; /**< @brief Rectangle for source input */ 134 VARectangle m_rectSFC{}; /**< @brief Rectangle for SFC output */ 135 std::vector<uint32_t> m_in4CC{}; /**< @brief input FOURCC */ 136 std::vector<uint32_t> m_out4CC{}; /**< @brief output FOURCC */ 137 std::map<SFC, uint32_t> m_sfcSize{}; /**< @brief SFC sizes */ 138 std::vector<VASurfaceID> m_sfcIDs{}; /**< @brief sfc surfaces */ 139 VAProcPipelineParameterBuffer m_vaProcBuffer{}; /**< @brief sfc pipeline buffer */ 140 }; 141 } // namespace mvaccel 142 #endif // MV_ACCELERATOR_VAAPI_DECODE_H 143