1 /*************************************************************************** 2 \file : ADM_coreLibva.h 3 \brief : Wrapper around libva functions 4 \author : (C) 2013 by mean fixounet@free.fr, derived from xbmc_pvr 5 ***************************************************************************/ 6 7 /*************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 #ifndef ADM_CORE_LIBVA_H 17 #define ADM_CORE_LIBVA_H 18 19 #ifdef USE_LIBVA 20 extern "C" { 21 #include "libavcodec/avcodec.h" 22 #include "libavutil/pixfmt.h" 23 #include "libavcodec/vaapi.h" 24 } 25 26 #include "ADM_windowInfo.h" 27 #include "X11/Xlib.h" 28 #include "va/va.h" 29 #include "ADM_image.h" 30 31 #define VA_INVALID VA_INVALID_ID 32 class ADM_vaSurface; 33 34 35 #define VA_10BITS_IS_ACTUALL_8BITS 1 // ??? 36 37 /** 38 \class admLibVA 39 */ 40 41 class admLibVA 42 { 43 protected: 44 static GUI_WindowInfo myWindowInfo; 45 public: 46 47 typedef enum 48 { 49 ADM_LIBVA_NONE, 50 ADM_LIBVA_DIRECT, ADM_LIBVA_INDIRECT_NV12, ADM_LIBVA_INDIRECT_YV12 51 }LIBVA_TRANSFER_MODE; 52 53 54 static bool init(GUI_WindowInfo *x); 55 static bool isOperationnal(void); 56 static bool cleanup(void); 57 static VADisplay getVADisplay(); 58 /* Setup */ 59 static bool setupConfig(void); 60 static bool setupImageFormat(void); 61 /* Encoding - setup */ 62 static bool setupEncodingConfig(void); 63 /* Surface */ 64 65 static VAContextID createDecoder(VAProfile profile,int width, int height, int nbSurface, VASurfaceID *surfaces); 66 static bool destroyDecoder(VAContextID decoder); 67 68 static VASurfaceID allocateSurface( int w, int h, int fmt=VA_RT_FORMAT_YUV420); 69 static void destroySurface( VASurfaceID surface); 70 71 static VAImage *allocateNV12Image( int w, int h); 72 static VAImage *allocateYV12Image( int w, int h); 73 static void destroyImage( VAImage *image); 74 static VAImage *allocateImage( int w, int h); 75 76 77 static bool transfer(VAContextID session, int w, int h,VASurfaceID surface, ADMImage *img,VAImage *tmp,uint8_t *yv12); 78 static bool fillContext(VAProfile profile,vaapi_context *c); 79 80 // Indirect access through image 81 static bool uploadToImage(ADMImage *src,VAImage *dest ); 82 static bool downloadFromImage(ADMImage *src,VAImage *dest ,ADMColorScalerSimple *color=NULL); 83 static bool imageToSurface(VAImage *src,ADM_vaSurface *dest); 84 static bool surfaceToImage(ADM_vaSurface *dst,VAImage *src ); 85 86 // Display 87 88 static bool putX11Surface(ADM_vaSurface *img,int widget,int displayWidth,int displayHeight); 89 90 // Direct access 91 92 static bool admImageToSurface( ADMImage *src,ADM_vaSurface *dest); 93 static bool surfaceToAdmImage(ADMImage *dest,ADM_vaSurface *src,ADMColorScalerSimple *color=NULL); 94 95 // 96 static bool supported(VAProfile profile); 97 98 //-- config for filters -- 99 static VAConfigID createFilterConfig(); 100 static bool destroyFilterConfig(VAConfigID &id); 101 102 //-- config for filters -- 103 static VAContextID createFilterContext(); 104 static bool destroyFilterContext(VAContextID &id); 105 106 107 static VADisplay getDisplay(); 108 }; 109 /** 110 * \class admLibVAEnc 111 */ 112 class ADMBitstream; 113 /** 114 * \class ADM_vaSurface 115 */ 116 class decoderFFLIBVA; 117 class ADM_vaSurface 118 { 119 public: 120 VASurfaceID surface; 121 int refCount; 122 VAImage *image; 123 int w,h; 124 ADMColorScalerSimple *color10bits; 125 ADM_vaSurface(int w, int h); 126 ~ADM_vaSurface(); 127 hasValidSurface()128 bool hasValidSurface() {return !(surface==VA_INVALID);} 129 bool toAdmImage(ADMImage *image); 130 bool fromAdmImage(ADMImage *image); 131 132 static ADM_vaSurface *allocateWithSurface(int w,int h,int fmt=VA_RT_FORMAT_YUV420); 133 134 }; 135 #endif 136 #endif 137