dsp_common.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2022 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef _DSP_COMMON_H_
  19. #define _DSP_COMMON_H_
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <memory.h>
  24. #define DSP_MIN(a, b) ((a) < (b) ? (a) : (b))
  25. #define DSP_MAX(a, b) ((a) > (b) ? (a) : (b))
  26. #define DSP_ALIGN_UP(num, bits) (((num) + (1 << (bits)) - 1) & ~((1 << (bits)) - 1))
  27. #define DSP_ZERO_MEMORY(data) \
  28. { \
  29. memset(data, 0, sizeof(*(data))); \
  30. }
  31. #define DSP_MEMCPY(dst, src, size) \
  32. { \
  33. memcpy(dst, src, size); \
  34. }
  35. #define DSP_SAFE_FREE(buf) \
  36. { \
  37. if (buf != NULL) \
  38. { \
  39. free(buf); \
  40. buf = NULL; \
  41. } \
  42. }
  43. #define DSP_PRINT(level, ...) \
  44. { \
  45. if (dsp_log_level >= CSI_DSP_LOG_##level) \
  46. { \
  47. struct timeval ts; \
  48. gettimeofday(&ts, 0); \
  49. printf("[%ld.%06ld] CSI_DSP[%d] %s,(%s,%d): ",ts.tv_sec, ts.tv_usec,pid, #level,__FUNCTION__,__LINE__); \
  50. printf(__VA_ARGS__); \
  51. } \
  52. }
  53. #define DSP_PRINT_RETURN(retcode, level, ...) \
  54. { \
  55. DSP_PRINT(level, __VA_ARGS__) \
  56. return retcode; \
  57. }
  58. #define DSP_CHECK_CONDITION(cond, retcode, ...) \
  59. if (cond) \
  60. { \
  61. DSP_PRINT(ERROR, __VA_ARGS__) \
  62. return retcode; \
  63. }
  64. typedef enum log_level
  65. {
  66. CSI_DSP_LOG_QUIET = 0,
  67. CSI_DSP_LOG_ERROR,
  68. CSI_DSP_LOG_WARNING,
  69. CSI_DSP_LOG_INFO,
  70. CSI_DSP_LOG_DEBUG,
  71. CSI_DSP_LOG_TRACE,
  72. CSI_DSP_LOG_MAX
  73. } csi_dsp_log_level;
  74. extern int dsp_log_level;
  75. extern int pid;
  76. void dsp_InitEnv();
  77. #endif