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