dynamic_ogg.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2013 22:30:04 -0700
changeset 627 438fb12df34f
parent 621 944412baab72
child 629 87c536d57d92
permissions -rw-r--r--
Updated iOS project to include OGG support directly
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2013 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 
    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         vorbis.ov_clear = ov_clear;
   110         vorbis.ov_info = ov_info;
   111         vorbis.ov_open_callbacks = ov_open_callbacks;
   112         vorbis.ov_pcm_total = ov_pcm_total;
   113         vorbis.ov_read = ov_read;
   114         vorbis.ov_time_seek = ov_time_seek;
   115     }
   116     ++vorbis.loaded;
   117 
   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 
   131 #endif /* OGG_MUSIC */