vdi_osal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause
  2. //------------------------------------------------------------------------------
  3. // File: log.h
  4. //
  5. // Copyright (c) 2006, Chips & Media. All rights reserved.
  6. //------------------------------------------------------------------------------
  7. #ifndef _VDI_OSAL_H_
  8. #define _VDI_OSAL_H_
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <ctype.h>
  12. enum {NONE=0, INFO, WARN, ERR, TRACE, MAX_LOG_LEVEL};
  13. enum
  14. {
  15. LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no] */
  16. LOG_HAS_YEAR = 2, /**< Include year digit [no] */
  17. LOG_HAS_MONTH = 4, /**< Include month [no] */
  18. LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [no] */
  19. LOG_HAS_TIME = 16, /**< Include time [yes] */
  20. LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */
  21. LOG_HAS_FILE = 64, /**< Include sender in the log [yes] */
  22. LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes] */
  23. LOG_HAS_CR = 256, /**< Include carriage return [no] */
  24. LOG_HAS_SPACE = 512, /**< Include two spaces before log [yes] */
  25. LOG_HAS_COLOR = 1024, /**< Colorize logs [yes on win32] */
  26. LOG_HAS_LEVEL_TEXT = 2048 /**< Include level text string [no] */
  27. };
  28. enum {
  29. TERM_COLOR_R = 2, /**< Red */
  30. TERM_COLOR_G = 4, /**< Green */
  31. TERM_COLOR_B = 1, /**< Blue. */
  32. TERM_COLOR_BRIGHT = 8 /**< Bright mask. */
  33. };
  34. #define MAX_PRINT_LENGTH 512
  35. #ifdef ANDROID
  36. #include <utils/Log.h>
  37. #undef LOG_NDEBUG
  38. #define LOG_NDEBUG 0
  39. #undef LOG_TAG
  40. #define LOG_TAG "VPUAPI"
  41. #endif
  42. #define VLOG LogMsg
  43. #define LOG_ENABLE_FILE SetLogDecor(GetLogDecor()|LOG_HAS_FILE);
  44. typedef void * osal_file_t;
  45. # ifndef SEEK_SET
  46. # define SEEK_SET 0
  47. # endif
  48. # ifndef SEEK_CUR
  49. # define SEEK_CUR 1
  50. # endif
  51. # ifndef SEEK_END
  52. # define SEEK_END 2
  53. # endif
  54. #if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
  55. #elif defined(linux) || defined(__linux) || defined(ANDROID)
  56. #else
  57. #ifndef stdout
  58. # define stdout (void * )1
  59. #endif
  60. #ifndef stderr
  61. # define stderr (void * )1
  62. #endif
  63. #endif
  64. #if defined (__cplusplus)
  65. extern "C" {
  66. #endif
  67. int InitLog(void);
  68. void DeInitLog(void);
  69. void SetMaxLogLevel(int level);
  70. int GetMaxLogLevel(void);
  71. void SetLogColor(int level, int color);
  72. int GetLogColor(int level);
  73. void SetLogDecor(int decor);
  74. int GetLogDecor(void);
  75. //log print
  76. void LogMsg(int level, const char *format, ...);
  77. //timer
  78. void timer_start(void);
  79. void timer_stop(void);
  80. double timer_elapsed_us(void);
  81. double timer_elapsed_ms(void);
  82. int timer_is_valid(void);
  83. double timer_frequency(void);
  84. //math
  85. int math_div(int number, int denom);
  86. int math_modulo(int number, int denom);
  87. //terminal
  88. void osal_init_keyboard(void);
  89. void osal_close_keyboard(void);
  90. //memory
  91. void * osal_memcpy (void *dst, const void * src, int count);
  92. void * osal_memset (void *dst, int val,int count);
  93. int osal_memcmp(const void* src, const void* dst, int size);
  94. void * osal_malloc(int size);
  95. void * osal_realloc(void* ptr, int size);
  96. void osal_free(void *p);
  97. osal_file_t osal_fopen(const char * osal_file_tname, const char * mode);
  98. size_t osal_fwrite(const void * p, int size, int count, osal_file_t fp);
  99. size_t osal_fread(void *p, int size, int count, osal_file_t fp);
  100. long osal_ftell(osal_file_t fp);
  101. int osal_fseek(osal_file_t fp, long offset, int origin);
  102. int osal_fclose(osal_file_t fp);
  103. int osal_fflush(osal_file_t fp);
  104. int osal_fprintf(osal_file_t fp, const char * _Format, ...);
  105. int osal_fscanf(osal_file_t fp, const char * _Format, ...);
  106. int osal_kbhit(void);
  107. int osal_getch(void);
  108. int osal_flush_ch(void);
  109. int osal_feof(osal_file_t fp);
  110. void * osal_create_mutex(const char *name);
  111. void osal_close_mutex(void *handle);
  112. int osal_mutex_lock(void *handle);
  113. int osal_mutex_unlock(void *handle);
  114. #if defined (__cplusplus)
  115. }
  116. #endif
  117. #endif //#ifndef _VDI_OSAL_H_