dynamic_ogg.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. SDL_mixer: An audio mixer library based on the SDL library
  3. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifdef OGG_MUSIC
  19. #include "SDL_loadso.h"
  20. #include "SDL_mixer.h"
  21. #include "dynamic_ogg.h"
  22. vorbis_loader vorbis = {
  23. 0, NULL
  24. };
  25. #ifdef OGG_DYNAMIC
  26. int Mix_InitOgg()
  27. {
  28. if ( vorbis.loaded == 0 ) {
  29. vorbis.handle = SDL_LoadObject(OGG_DYNAMIC);
  30. if ( vorbis.handle == NULL ) {
  31. return -1;
  32. }
  33. vorbis.ov_clear =
  34. (int (*)(OggVorbis_File *))
  35. SDL_LoadFunction(vorbis.handle, "ov_clear");
  36. if ( vorbis.ov_clear == NULL ) {
  37. SDL_UnloadObject(vorbis.handle);
  38. return -1;
  39. }
  40. vorbis.ov_info =
  41. (vorbis_info *(*)(OggVorbis_File *,int))
  42. SDL_LoadFunction(vorbis.handle, "ov_info");
  43. if ( vorbis.ov_info == NULL ) {
  44. SDL_UnloadObject(vorbis.handle);
  45. return -1;
  46. }
  47. vorbis.ov_open_callbacks =
  48. (int (*)(void *, OggVorbis_File *, const char *, long, ov_callbacks))
  49. SDL_LoadFunction(vorbis.handle, "ov_open_callbacks");
  50. if ( vorbis.ov_open_callbacks == NULL ) {
  51. SDL_UnloadObject(vorbis.handle);
  52. return -1;
  53. }
  54. vorbis.ov_pcm_total =
  55. (ogg_int64_t (*)(OggVorbis_File *,int))
  56. SDL_LoadFunction(vorbis.handle, "ov_pcm_total");
  57. if ( vorbis.ov_pcm_total == NULL ) {
  58. SDL_UnloadObject(vorbis.handle);
  59. return -1;
  60. }
  61. vorbis.ov_read =
  62. #ifdef OGG_USE_TREMOR
  63. (long (*)(OggVorbis_File *,char *,int,int *))
  64. #else
  65. (long (*)(OggVorbis_File *,char *,int,int,int,int,int *))
  66. #endif
  67. SDL_LoadFunction(vorbis.handle, "ov_read");
  68. if ( vorbis.ov_read == NULL ) {
  69. SDL_UnloadObject(vorbis.handle);
  70. return -1;
  71. }
  72. vorbis.ov_time_seek =
  73. #ifdef OGG_USE_TREMOR
  74. (long (*)(OggVorbis_File *,ogg_int64_t))
  75. #else
  76. (int (*)(OggVorbis_File *,double))
  77. #endif
  78. SDL_LoadFunction(vorbis.handle, "ov_time_seek");
  79. if ( vorbis.ov_time_seek == NULL ) {
  80. SDL_UnloadObject(vorbis.handle);
  81. return -1;
  82. }
  83. }
  84. ++vorbis.loaded;
  85. return 0;
  86. }
  87. void Mix_QuitOgg()
  88. {
  89. if ( vorbis.loaded == 0 ) {
  90. return;
  91. }
  92. if ( vorbis.loaded == 1 ) {
  93. SDL_UnloadObject(vorbis.handle);
  94. }
  95. --vorbis.loaded;
  96. }
  97. #else
  98. int Mix_InitOgg()
  99. {
  100. if ( vorbis.loaded == 0 ) {
  101. #ifdef __MACOSX__
  102. extern int ov_open_callbacks(void*, OggVorbis_File*, const char*, long, ov_callbacks) __attribute__((weak_import));
  103. if ( ov_open_callbacks == NULL )
  104. {
  105. /* Missing weakly linked framework */
  106. Mix_SetError("Missing Vorbis.framework");
  107. return -1;
  108. }
  109. #endif // __MACOSX__
  110. vorbis.ov_clear = ov_clear;
  111. vorbis.ov_info = ov_info;
  112. vorbis.ov_open_callbacks = ov_open_callbacks;
  113. vorbis.ov_pcm_total = ov_pcm_total;
  114. vorbis.ov_read = ov_read;
  115. vorbis.ov_time_seek = ov_time_seek;
  116. }
  117. ++vorbis.loaded;
  118. return 0;
  119. }
  120. void Mix_QuitOgg()
  121. {
  122. if ( vorbis.loaded == 0 ) {
  123. return;
  124. }
  125. if ( vorbis.loaded == 1 ) {
  126. }
  127. --vorbis.loaded;
  128. }
  129. #endif /* OGG_DYNAMIC */
  130. #endif /* OGG_MUSIC */