ijksdl_misc.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*****************************************************************************
  2. * ijksdl_misc.h
  3. *****************************************************************************
  4. *
  5. * Copyright (c) 2013 Bilibili
  6. * copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
  7. *
  8. * This file is part of ijkPlayer.
  9. *
  10. * ijkPlayer is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * ijkPlayer is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with ijkPlayer; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #ifndef IJKSDL__IJKSDL_MISC_H
  25. #define IJKSDL__IJKSDL_MISC_H
  26. #include <stdlib.h>
  27. #include <memory.h>
  28. #ifndef IJKMAX
  29. #define IJKMAX(a, b) ((a) > (b) ? (a) : (b))
  30. #endif
  31. #ifndef IJKMIN
  32. #define IJKMIN(a, b) ((a) < (b) ? (a) : (b))
  33. #endif
  34. #ifndef IJKALIGN
  35. #define IJKALIGN(x, align) ((( x ) + (align) - 1) / (align) * (align))
  36. #endif
  37. #define IJK_CHECK_RET(condition__, retval__, ...) \
  38. if (!(condition__)) { \
  39. ALOGE(__VA_ARGS__); \
  40. return (retval__); \
  41. }
  42. #ifndef NELEM
  43. #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
  44. #endif
  45. inline static void *mallocz(size_t size)
  46. {
  47. void *mem = malloc(size);
  48. if (!mem)
  49. return mem;
  50. memset(mem, 0, size);
  51. return mem;
  52. }
  53. inline static void freep(void **mem)
  54. {
  55. if (mem && *mem) {
  56. free(*mem);
  57. *mem = NULL;
  58. }
  59. }
  60. #endif