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