1 /* ports.h 2 3 Copyright (c) 2003-2021 HandBrake Team 4 This file is part of the HandBrake source code 5 Homepage: <http://handbrake.fr/>. 6 It may be used under the terms of the GNU General Public License v2. 7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html 8 */ 9 10 #ifndef HANDBRAKE_PORTS_H 11 #define HANDBRAKE_PORTS_H 12 13 #if ARCH_X86_64 || ARCH_X86_32 14 #define ARCH_X86 15 #endif 16 17 #if defined(_WIN32) 18 #define DIR_SEP_STR "\\" 19 #define DIR_SEP_CHAR '\\' 20 #define IS_DIR_SEP(c) (c == '\\' || c == '/') 21 #else 22 #define DIR_SEP_STR "/" 23 #define DIR_SEP_CHAR '/' 24 #define IS_DIR_SEP(c) (c == '/') 25 #endif 26 27 #include "handbrake/project.h" 28 29 #if HB_PROJECT_FEATURE_QSV 30 #include "mfx/mfxstructures.h" 31 #if defined(SYS_LINUX) || defined(SYS_FREEBSD) 32 #include <va/va_drm.h> 33 #endif 34 #endif 35 36 /************************************************************************ 37 * HW accel display 38 ***********************************************************************/ 39 #if defined(SYS_LINUX) || defined(SYS_FREEBSD) 40 extern const char* DRM_INTEL_DRIVER_NAME; 41 #endif // SYS_LINUX || SYS_FREEBSD 42 43 typedef struct 44 { 45 void * handle; 46 #if HB_PROJECT_FEATURE_QSV 47 mfxHandleType mfxType; 48 49 #if defined(SYS_LINUX) || defined(SYS_FREEBSD) 50 int vaFd; 51 VADisplay vaDisplay; 52 #endif // SYS_LINUX || SYS_FREEBSD 53 #endif 54 } hb_display_t; 55 56 hb_display_t * hb_display_init(const char * driver_name, 57 const char * const * interface_names); 58 void hb_display_close(hb_display_t ** _d); 59 60 /************************************************************************ 61 * CPU info utilities 62 ***********************************************************************/ 63 enum hb_cpu_platform 64 { 65 // list of microarchitecture codenames 66 HB_CPU_PLATFORM_UNSPECIFIED = 0, 67 HB_CPU_PLATFORM_INTEL_BNL, 68 HB_CPU_PLATFORM_INTEL_SNB, 69 HB_CPU_PLATFORM_INTEL_IVB, 70 HB_CPU_PLATFORM_INTEL_SLM, 71 HB_CPU_PLATFORM_INTEL_HSW, 72 HB_CPU_PLATFORM_INTEL_BDW, 73 HB_CPU_PLATFORM_INTEL_CHT, 74 HB_CPU_PLATFORM_INTEL_SKL, 75 HB_CPU_PLATFORM_INTEL_KBL, 76 HB_CPU_PLATFORM_INTEL_CML, 77 HB_CPU_PLATFORM_INTEL_ICL, 78 HB_CPU_PLATFORM_INTEL_TGL, 79 }; 80 int hb_get_cpu_count(void); 81 int hb_get_cpu_platform(void); 82 const char* hb_get_cpu_name(void); 83 const char* hb_get_cpu_platform_name(void); 84 85 /************************************************************************ 86 * Utils 87 ***********************************************************************/ 88 // provide time in ms 89 uint64_t hb_get_date(void); 90 // provide time in us 91 uint64_t hb_get_time_us(void); 92 93 void hb_snooze( int delay ); 94 int hb_platform_init(void); 95 96 #ifdef SYS_MINGW 97 typedef struct 98 { 99 _WDIR *wdir; 100 struct dirent entry; 101 } HB_DIR; 102 #else 103 typedef DIR HB_DIR; 104 #endif 105 106 #ifdef SYS_MINGW 107 typedef struct _stat64 hb_stat_t; 108 #else 109 typedef struct stat hb_stat_t; 110 #endif 111 112 HB_DIR* hb_opendir(const char *path); 113 int hb_closedir(HB_DIR *dir); 114 void hb_rewinddir(HB_DIR *dir); 115 struct dirent * hb_readdir(HB_DIR *dir); 116 int hb_mkdir(char * name); 117 int hb_stat(const char *path, hb_stat_t *sb); 118 FILE * hb_fopen(const char *path, const char *mode); 119 char * hb_strr_dir_sep(const char *path); 120 121 /************************************************************************ 122 * String utils 123 ***********************************************************************/ 124 char * hb_strndup(const char * src, size_t len); 125 126 /************************************************************************ 127 * File utils 128 ***********************************************************************/ 129 char * hb_get_temporary_directory(void); 130 char * hb_get_temporary_filename( char *fmt, ... ); 131 size_t hb_getline(char **lineptr, size_t *n, FILE *fp); 132 133 #ifdef __LIBHB__ 134 135 // Convert utf8 string to current code page. 136 char * hb_utf8_to_cp(const char *src); 137 138 /* Everything from now is only used internally and hidden to the UI */ 139 140 /************************************************************************ 141 * DVD utils 142 ***********************************************************************/ 143 int hb_dvd_region(char *device, int *region_mask); 144 145 #if defined( SYS_DARWIN ) 146 int macOS_get_user_config_directory( char path[512] ); 147 #endif 148 void hb_get_user_config_directory( char path[512] ); 149 void hb_get_user_config_filename( char name[1024], char *fmt, ... ); 150 /************************************************************************ 151 * Threads 152 ***********************************************************************/ 153 typedef struct hb_thread_s hb_thread_t; 154 155 #if defined( SYS_BEOS ) 156 # define HB_LOW_PRIORITY 5 157 # define HB_NORMAL_PRIORITY 10 158 #elif defined( SYS_DARWIN ) 159 # define HB_LOW_PRIORITY 31 160 # define HB_NORMAL_PRIORITY 31 161 #elif defined( SYS_CYGWIN ) 162 # define HB_LOW_PRIORITY 0 163 # define HB_NORMAL_PRIORITY 1 164 #elif defined( SYS_MINGW ) 165 # define HB_LOW_PRIORITY 0 166 # define HB_NORMAL_PRIORITY 0 167 #endif 168 169 #ifndef HB_LOW_PRIORITY 170 #define HB_LOW_PRIORITY 0 171 #endif 172 173 #ifndef HB_NORMAL_PRIORITY 174 #define HB_NORMAL_PRIORITY 0 175 #endif 176 177 typedef void (thread_func_t)(void *); 178 hb_thread_t * hb_thread_init( const char * name, thread_func_t *function, 179 void * arg, int priority ); 180 void hb_thread_close( hb_thread_t ** ); 181 int hb_thread_has_exited( hb_thread_t * ); 182 183 void hb_yield(void); 184 185 /************************************************************************ 186 * Mutexes 187 ***********************************************************************/ 188 189 hb_lock_t * hb_lock_init(); 190 void hb_lock_close( hb_lock_t ** ); 191 void hb_lock( hb_lock_t * ); 192 void hb_unlock( hb_lock_t * ); 193 194 /************************************************************************ 195 * Condition variables 196 ***********************************************************************/ 197 typedef struct hb_cond_s hb_cond_t; 198 199 hb_cond_t * hb_cond_init(); 200 void hb_cond_wait( hb_cond_t *, hb_lock_t * ); 201 void hb_cond_timedwait( hb_cond_t * c, hb_lock_t * lock, int msec ); 202 void hb_cond_signal( hb_cond_t * ); 203 void hb_cond_broadcast( hb_cond_t * c ); 204 void hb_cond_close( hb_cond_t ** ); 205 206 /************************************************************************ 207 * Network 208 ***********************************************************************/ 209 typedef struct hb_net_s hb_net_t; 210 211 hb_net_t * hb_net_open( char * address, int port ); 212 int hb_net_send( hb_net_t *, char * ); 213 int hb_net_recv( hb_net_t *, char *, int ); 214 void hb_net_close( hb_net_t ** ); 215 216 /************************************************************************ 217 * OS Sleep Allow / Prevent 218 ***********************************************************************/ 219 void* hb_system_sleep_opaque_init(); 220 void hb_system_sleep_opaque_close(void **opaque); 221 void hb_system_sleep_private_enable(void *opaque); 222 void hb_system_sleep_private_disable(void *opaque); 223 224 /************************************************************************ 225 * Loadable Libraries 226 ***********************************************************************/ 227 void * hb_dlopen(const char *name); 228 void * hb_dlsym(void *h, const char *name); 229 int hb_dlclose(void *h); 230 231 #if defined( SYS_MINGW ) 232 #define HB_SO_EXT ".dll" 233 #elif defined( SYS_DARWIN ) 234 #define HB_SO_EXT ".dylib" 235 #else 236 #define HB_SO_EXT ".so" 237 #endif 238 239 #endif /* __LIBHB__ */ 240 241 #endif // HANDBRAKE_PORTS_H 242