src/audio/SDL_sysaudio.h
author Ryan C. Gordon
Tue, 17 Oct 2006 09:09:21 +0000
branchSDL-ryan-multiple-audio-device
changeset 3846 66fb40445587
parent 3804 b12b7ec0dfcc
permissions -rw-r--r--
Removed distinction between "available" and "init" in audio backends, since
both had to be checked for success as a pair at the higher level and several
of the Available methods were just always-succeed placeholders anyhow. Now
the availability check is done in the init code, and the higher level tries
all possible drivers until one manages to initialize successfully.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@1336
     5
    This library is SDL_free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
#ifndef _SDL_sysaudio_h
slouken@0
    25
#define _SDL_sysaudio_h
slouken@0
    26
slouken@0
    27
#include "SDL_mutex.h"
slouken@0
    28
#include "SDL_thread.h"
slouken@0
    29
slouken@0
    30
/* The SDL audio driver */
slouken@0
    31
typedef struct SDL_AudioDevice SDL_AudioDevice;
icculus@3784
    32
#define _THIS	SDL_AudioDevice *_this
slouken@0
    33
icculus@3784
    34
typedef struct SDL_AudioDriverImpl
icculus@3784
    35
{
icculus@3790
    36
    int (*DetectDevices)(int iscapture);
icculus@3792
    37
    const char *(*GetDeviceName)(int index, int iscapture);
icculus@3792
    38
    int (*OpenDevice) (_THIS, const char *devname, int iscapture);
icculus@3784
    39
    void (*ThreadInit) (_THIS); /* Called by audio thread at start */
icculus@3792
    40
    void (*WaitDevice) (_THIS);
icculus@3792
    41
    void (*PlayDevice) (_THIS);
icculus@3792
    42
    Uint8 *(*GetDeviceBuf) (_THIS);
icculus@3784
    43
    void (*WaitDone) (_THIS);
icculus@3792
    44
    void (*CloseDevice) (_THIS);
icculus@3792
    45
    void (*LockDevice) (_THIS);
icculus@3792
    46
    void (*UnlockDevice) (_THIS);
icculus@3787
    47
    void (*Deinitialize) (void);
icculus@3796
    48
icculus@3796
    49
    /* Some flags to push duplicate code into the core and reduce #ifdefs. */
icculus@3796
    50
    int ProvidesOwnCallbackThread:1;
icculus@3796
    51
    int SkipMixerLock:1;
icculus@3796
    52
    int HasCaptureSupport:1;
icculus@3796
    53
    int OnlyHasDefaultOutputDevice:1;
icculus@3796
    54
    int OnlyHasDefaultInputDevice:1;
icculus@3784
    55
} SDL_AudioDriverImpl;
icculus@3784
    56
icculus@3795
    57
icculus@3784
    58
typedef struct SDL_AudioDriver
slouken@1895
    59
{
slouken@1895
    60
    /* * * */
slouken@1895
    61
    /* The name of this audio driver */
slouken@1895
    62
    const char *name;
slouken@0
    63
slouken@1895
    64
    /* * * */
slouken@1895
    65
    /* The description of this audio driver */
slouken@1895
    66
    const char *desc;
slouken@0
    67
icculus@3784
    68
    SDL_AudioDriverImpl impl;
icculus@3784
    69
} SDL_AudioDriver;
icculus@3784
    70
icculus@3784
    71
icculus@3784
    72
/* Define the SDL audio driver structure */
icculus@3784
    73
struct SDL_AudioDevice
icculus@3784
    74
{
slouken@1895
    75
    /* * * */
slouken@1895
    76
    /* Data common to all devices */
slouken@0
    77
slouken@1895
    78
    /* The current audio specification (shared with audio thread) */
slouken@1895
    79
    SDL_AudioSpec spec;
slouken@0
    80
slouken@1895
    81
    /* An audio conversion block for audio format emulation */
slouken@1895
    82
    SDL_AudioCVT convert;
slouken@0
    83
slouken@1895
    84
    /* Current state flags */
icculus@3796
    85
    int iscapture;
slouken@1895
    86
    int enabled;
slouken@1895
    87
    int paused;
slouken@1895
    88
    int opened;
slouken@0
    89
slouken@1895
    90
    /* Fake audio buffer for when the audio hardware is busy */
slouken@1895
    91
    Uint8 *fake_stream;
slouken@0
    92
slouken@1895
    93
    /* A semaphore for locking the mixing buffers */
slouken@1895
    94
    SDL_mutex *mixer_lock;
slouken@0
    95
slouken@1895
    96
    /* A thread to feed the audio device */
slouken@1895
    97
    SDL_Thread *thread;
slouken@1895
    98
    Uint32 threadid;
slouken@0
    99
slouken@1895
   100
    /* * * */
slouken@1895
   101
    /* Data private to this driver */
slouken@1895
   102
    struct SDL_PrivateAudioData *hidden;
slouken@0
   103
};
slouken@0
   104
#undef _THIS
slouken@0
   105
slouken@1895
   106
typedef struct AudioBootStrap
slouken@1895
   107
{
slouken@1895
   108
    const char *name;
slouken@1895
   109
    const char *desc;
icculus@3784
   110
    int (*init) (SDL_AudioDriverImpl *impl);
icculus@3804
   111
    int demand_only:1;  /* 1==request explicitly, or it won't be available. */
slouken@0
   112
} AudioBootStrap;
slouken@0
   113
slouken@0
   114
#endif /* _SDL_sysaudio_h */
icculus@3846
   115
slouken@1895
   116
/* vi: set ts=4 sw=4 expandtab: */