vdi_osal.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. #ifdef USE_FEEDING_METHOD_BUFFER
  31. #include "wave511/vpuapi/vputypes.h"
  32. #else
  33. #include "vputypes.h"
  34. #endif
  35. enum
  36. {
  37. ERR=0,
  38. WARN,
  39. TRACE,
  40. INFO,
  41. DEBUG,
  42. MAX_LOG_LEVEL
  43. };
  44. enum
  45. {
  46. LOG_HAS_DAY_NAME = 1, /**< Include day name [default: no] */
  47. LOG_HAS_YEAR = 2, /**< Include year digit [no] */
  48. LOG_HAS_MONTH = 4, /**< Include month [no] */
  49. LOG_HAS_DAY_OF_MON = 8, /**< Include day of month [no] */
  50. LOG_HAS_TIME = 16, /**< Include time [yes] */
  51. LOG_HAS_MICRO_SEC = 32, /**< Include microseconds [yes] */
  52. LOG_HAS_FILE = 64, /**< Include sender in the log [yes] */
  53. LOG_HAS_NEWLINE = 128, /**< Terminate each call with newline [yes] */
  54. LOG_HAS_CR = 256, /**< Include carriage return [no] */
  55. LOG_HAS_SPACE = 512, /**< Include two spaces before log [yes] */
  56. LOG_HAS_COLOR = 1024, /**< Colorize logs [yes on win32] */
  57. LOG_HAS_LEVEL_TEXT = 2048 /**< Include level text string [no] */
  58. };
  59. enum {
  60. TERM_COLOR_R = 2, /**< Red */
  61. TERM_COLOR_G = 4, /**< Green */
  62. TERM_COLOR_B = 1, /**< Blue. */
  63. TERM_COLOR_BRIGHT = 8 /**< Bright mask. */
  64. };
  65. #define MAX_PRINT_LENGTH 512
  66. #ifdef ANDROID
  67. #include <utils/Log.h>
  68. #undef LOG_NDEBUG
  69. #define LOG_NDEBUG 0
  70. #undef LOG_TAG
  71. #define LOG_TAG "VPUAPI"
  72. #endif
  73. #define VLOG LogMsg
  74. #define LOG_ENABLE_FILE SetLogDecor(GetLogDecor()|LOG_HAS_FILE);
  75. typedef void * osal_file_t;
  76. # ifndef SEEK_SET
  77. # define SEEK_SET 0
  78. # endif
  79. # ifndef SEEK_CUR
  80. # define SEEK_CUR 1
  81. # endif
  82. # ifndef SEEK_END
  83. # define SEEK_END 2
  84. # endif
  85. #if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WIN32) || defined(__MINGW32__)
  86. #elif defined(linux) || defined(__linux) || defined(ANDROID)
  87. #else
  88. #ifndef stdout
  89. # define stdout (void * )1
  90. #endif
  91. #ifndef stderr
  92. # define stderr (void * )1
  93. #endif
  94. #endif
  95. typedef void* osal_thread_t;
  96. typedef void* osal_mutex_t;
  97. #if defined (__cplusplus)
  98. extern "C" {
  99. #endif
  100. int InitLog(void);
  101. void DeInitLog(void);
  102. void SetMaxLogLevel(int level);
  103. int GetMaxLogLevel(void);
  104. //log print
  105. void LogMsg(int level, const char *format, ...);
  106. //terminal
  107. void osal_init_keyboard(void);
  108. void osal_close_keyboard(void);
  109. //memory
  110. void * osal_memcpy (void *dst, const void * src, int count);
  111. void * osal_memset (void *dst, int val,int count);
  112. int osal_memcmp(const void* src, const void* dst, int size);
  113. void * osal_malloc(int size);
  114. void * osal_realloc(void* ptr, int size);
  115. void osal_free(void *p);
  116. osal_file_t osal_fopen(const char * osal_file_tname, const char * mode);
  117. size_t osal_fwrite(const void * p, int size, int count, osal_file_t fp);
  118. size_t osal_fread(void *p, int size, int count, osal_file_t fp);
  119. long osal_ftell(osal_file_t fp);
  120. int osal_fseek(osal_file_t fp, long offset, int origin);
  121. int osal_fclose(osal_file_t fp);
  122. int osal_fflush(osal_file_t fp);
  123. int osal_fprintf(osal_file_t fp, const char * _Format, ...);
  124. int osal_fscanf(osal_file_t fp, const char * _Format, ...);
  125. int osal_kbhit(void);
  126. int osal_getch(void);
  127. int osal_flush_ch(void);
  128. int osal_feof(osal_file_t fp);
  129. void osal_msleep(Uint32 millisecond);
  130. /********************************************************************************
  131. * THREAD *
  132. ********************************************************************************/
  133. osal_thread_t osal_thread_create(void(*start_routine)(void*), void*arg);
  134. /* @return 0 - success
  135. 2 - failure
  136. */
  137. Int32 osal_thread_join(osal_thread_t thread, void** retval);
  138. /* @return 0 - success
  139. 1 - timed out
  140. 2 - failure
  141. */
  142. Int32 osal_thread_timedjoin(osal_thread_t thread, void** retval, Uint32 millisecond);
  143. /********************************************************************************
  144. * MUTEX *
  145. ********************************************************************************/
  146. osal_mutex_t osal_mutex_create(void);
  147. void osal_mutex_destroy(osal_mutex_t mutex);
  148. BOOL osal_mutex_lock(osal_mutex_t mutex);
  149. BOOL osal_mutex_unlock(osal_mutex_t mutex);
  150. /********************************************************************************
  151. * SEMAPHORE *
  152. ********************************************************************************/
  153. typedef void* osal_sem_t;
  154. /* @param count The number of semaphores.
  155. */
  156. osal_sem_t osal_sem_init(Uint32 count);
  157. void osal_sem_wait(osal_sem_t sem);
  158. void osal_sem_post(osal_sem_t sem);
  159. void osal_sem_destroy(osal_sem_t sem);
  160. /********************************************************************************
  161. * SYSTEM TIME *
  162. ********************************************************************************/
  163. /* @brief It returns system time in millisecond.
  164. */
  165. Uint64 osal_gettime(void);
  166. #if defined (__cplusplus)
  167. }
  168. #endif
  169. #endif //#ifndef _VDI_OSAL_H_