vdi_osal.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 2019, Chips&Media
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef _VDI_OSAL_H_
  26. #define _VDI_OSAL_H_
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <ctype.h>
  30. #include "vputypes.h"
  31. enum
  32. {
  33. ERR=0,
  34. WARN,
  35. TRACE,
  36. INFO,
  37. MAX_LOG_LEVEL
  38. };
  39. enum
  40. {
  41. LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no] */
  42. LOG_HAS_YEAR = 2, /**< Include year digit [no] */
  43. LOG_HAS_MONTH = 4, /**< Include month [no] */
  44. LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [no] */
  45. LOG_HAS_TIME = 16, /**< Include time [yes] */
  46. LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */
  47. LOG_HAS_FILE = 64, /**< Include sender in the log [yes] */
  48. LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes] */
  49. LOG_HAS_CR = 256, /**< Include carriage return [no] */
  50. LOG_HAS_SPACE = 512, /**< Include two spaces before log [yes] */
  51. LOG_HAS_COLOR = 1024, /**< Colorize logs [yes on win32] */
  52. LOG_HAS_LEVEL_TEXT = 2048 /**< Include level text string [no] */
  53. };
  54. enum {
  55. TERM_COLOR_R = 2, /**< Red */
  56. TERM_COLOR_G = 4, /**< Green */
  57. TERM_COLOR_B = 1, /**< Blue. */
  58. TERM_COLOR_BRIGHT = 8 /**< Bright mask. */
  59. };
  60. #define MAX_PRINT_LENGTH 512
  61. #ifdef ANDROID
  62. #include <utils/Log.h>
  63. #undef LOG_NDEBUG
  64. #define LOG_NDEBUG 0
  65. #undef LOG_TAG
  66. #define LOG_TAG "VPUAPI"
  67. #endif
  68. #define VLOG LogMsg
  69. #define LOG_ENABLE_FILE SetLogDecor(GetLogDecor()|LOG_HAS_FILE);
  70. typedef void * osal_file_t;
  71. # ifndef SEEK_SET
  72. # define SEEK_SET 0
  73. # endif
  74. # ifndef SEEK_CUR
  75. # define SEEK_CUR 1
  76. # endif
  77. # ifndef SEEK_END
  78. # define SEEK_END 2
  79. # endif
  80. #if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
  81. #elif defined(linux) || defined(__linux) || defined(ANDROID)
  82. #else
  83. #ifndef stdout
  84. # define stdout (void * )1
  85. #endif
  86. #ifndef stderr
  87. # define stderr (void * )1
  88. #endif
  89. #endif
  90. typedef void* osal_thread_t;
  91. typedef void* osal_mutex_t;
  92. #if defined (__cplusplus)
  93. extern "C" {
  94. #endif
  95. int InitLog(void);
  96. void DeInitLog(void);
  97. void SetMaxLogLevel(int level);
  98. int GetMaxLogLevel(void);
  99. //log print
  100. void LogMsg(int level, const char *format, ...);
  101. //terminal
  102. void osal_init_keyboard(void);
  103. void osal_close_keyboard(void);
  104. //memory
  105. void * osal_memcpy (void *dst, const void * src, int count);
  106. void * osal_memset (void *dst, int val,int count);
  107. int osal_memcmp(const void* src, const void* dst, int size);
  108. void * osal_malloc(int size);
  109. void * osal_realloc(void* ptr, int size);
  110. void osal_free(void *p);
  111. osal_file_t osal_fopen(const char * osal_file_tname, const char * mode);
  112. size_t osal_fwrite(const void * p, int size, int count, osal_file_t fp);
  113. size_t osal_fread(void *p, int size, int count, osal_file_t fp);
  114. long osal_ftell(osal_file_t fp);
  115. int osal_fseek(osal_file_t fp, long offset, int origin);
  116. int osal_fclose(osal_file_t fp);
  117. int osal_fflush(osal_file_t fp);
  118. int osal_fprintf(osal_file_t fp, const char * _Format, ...);
  119. int osal_fscanf(osal_file_t fp, const char * _Format, ...);
  120. int osal_kbhit(void);
  121. int osal_getch(void);
  122. int osal_flush_ch(void);
  123. int osal_feof(osal_file_t fp);
  124. void osal_msleep(Uint32 millisecond);
  125. /********************************************************************************
  126. * THREAD *
  127. ********************************************************************************/
  128. osal_thread_t osal_thread_create(void(*start_routine)(void*), void*arg);
  129. /* @return 0 - success
  130. 2 - failure
  131. */
  132. Int32 osal_thread_join(osal_thread_t thread, void** retval);
  133. /* @return 0 - success
  134. 1 - timed out
  135. 2 - failure
  136. */
  137. Int32 osal_thread_timedjoin(osal_thread_t thread, void** retval, Uint32 millisecond);
  138. /********************************************************************************
  139. * MUTEX *
  140. ********************************************************************************/
  141. osal_mutex_t osal_mutex_create(void);
  142. void osal_mutex_destroy(osal_mutex_t mutex);
  143. BOOL osal_mutex_lock(osal_mutex_t mutex);
  144. BOOL osal_mutex_unlock(osal_mutex_t mutex);
  145. /********************************************************************************
  146. * SEMAPHORE *
  147. ********************************************************************************/
  148. typedef void* osal_sem_t;
  149. /* @param count The number of semaphores.
  150. */
  151. osal_sem_t osal_sem_init(Uint32 count);
  152. void osal_sem_wait(osal_sem_t sem);
  153. void osal_sem_post(osal_sem_t sem);
  154. void osal_sem_destroy(osal_sem_t sem);
  155. /********************************************************************************
  156. * SYSTEM TIME *
  157. ********************************************************************************/
  158. /* @brief It returns system time in millisecond.
  159. */
  160. Uint64 osal_gettime(void);
  161. #if defined (__cplusplus)
  162. }
  163. #endif
  164. #endif //#ifndef _VDI_OSAL_H_