src/audio/SDL_sysaudio.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 16 Dec 2009 04:48:11 +0000
changeset 3578 0d1b16ee0bca
parent 2859 99210400e8b9
child 3697 f7b03b6838cb
permissions -rw-r--r--
Fixed bug #741

The thread ID is an unsigned long so it can hold pthread_t so people can do naughty things with it.

I'm going to be adding additional useful thread API functions, but this should prevent crashes in people's existing code on 64-bit architectures.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 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@2049
    32
#define _THIS	SDL_AudioDevice *_this
slouken@0
    33
icculus@2049
    34
typedef struct SDL_AudioDriverImpl
icculus@2049
    35
{
slouken@2060
    36
    int (*DetectDevices) (int iscapture);
slouken@2060
    37
    const char *(*GetDeviceName) (int index, int iscapture);
icculus@2049
    38
    int (*OpenDevice) (_THIS, const char *devname, int iscapture);
icculus@2049
    39
    void (*ThreadInit) (_THIS); /* Called by audio thread at start */
icculus@2049
    40
    void (*WaitDevice) (_THIS);
icculus@2049
    41
    void (*PlayDevice) (_THIS);
icculus@2049
    42
    Uint8 *(*GetDeviceBuf) (_THIS);
icculus@2049
    43
    void (*WaitDone) (_THIS);
icculus@2049
    44
    void (*CloseDevice) (_THIS);
icculus@2049
    45
    void (*LockDevice) (_THIS);
icculus@2049
    46
    void (*UnlockDevice) (_THIS);
icculus@2049
    47
    void (*Deinitialize) (void);
icculus@2049
    48
icculus@2049
    49
    /* Some flags to push duplicate code into the core and reduce #ifdefs. */
icculus@2049
    50
    int ProvidesOwnCallbackThread:1;
icculus@2049
    51
    int SkipMixerLock:1;
icculus@2049
    52
    int HasCaptureSupport:1;
icculus@2049
    53
    int OnlyHasDefaultOutputDevice:1;
icculus@2049
    54
    int OnlyHasDefaultInputDevice:1;
icculus@2049
    55
} SDL_AudioDriverImpl;
icculus@2049
    56
icculus@2049
    57
icculus@2049
    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@2049
    68
    SDL_AudioDriverImpl impl;
icculus@2049
    69
} SDL_AudioDriver;
slouken@0
    70
slouken@322
    71
slouken@2716
    72
/* Streamer */
slouken@2716
    73
typedef struct
slouken@2716
    74
{
slouken@2716
    75
    Uint8 *buffer;
slouken@2716
    76
    int max_len;                /* the maximum length in bytes */
slouken@2716
    77
    int read_pos, write_pos;    /* the position of the write and read heads in bytes */
slouken@2716
    78
} SDL_AudioStreamer;
slouken@2716
    79
slouken@2716
    80
icculus@2049
    81
/* Define the SDL audio driver structure */
icculus@2049
    82
struct SDL_AudioDevice
icculus@2049
    83
{
slouken@1895
    84
    /* * * */
slouken@1895
    85
    /* Data common to all devices */
slouken@0
    86
slouken@1895
    87
    /* The current audio specification (shared with audio thread) */
slouken@1895
    88
    SDL_AudioSpec spec;
slouken@0
    89
slouken@1895
    90
    /* An audio conversion block for audio format emulation */
slouken@1895
    91
    SDL_AudioCVT convert;
slouken@0
    92
slouken@2716
    93
    /* The streamer, if sample rate conversion necessitates it */
slouken@2716
    94
    int use_streamer;
slouken@2716
    95
    SDL_AudioStreamer streamer;
slouken@2716
    96
slouken@1895
    97
    /* Current state flags */
icculus@2049
    98
    int iscapture;
slouken@1895
    99
    int enabled;
slouken@1895
   100
    int paused;
slouken@1895
   101
    int opened;
slouken@0
   102
slouken@1895
   103
    /* Fake audio buffer for when the audio hardware is busy */
slouken@1895
   104
    Uint8 *fake_stream;
slouken@0
   105
slouken@1895
   106
    /* A semaphore for locking the mixing buffers */
slouken@1895
   107
    SDL_mutex *mixer_lock;
slouken@0
   108
slouken@1895
   109
    /* A thread to feed the audio device */
slouken@1895
   110
    SDL_Thread *thread;
slouken@3578
   111
    SDL_threadID threadid;
slouken@0
   112
slouken@1895
   113
    /* * * */
slouken@1895
   114
    /* Data private to this driver */
slouken@1895
   115
    struct SDL_PrivateAudioData *hidden;
slouken@0
   116
};
slouken@0
   117
#undef _THIS
slouken@0
   118
slouken@1895
   119
typedef struct AudioBootStrap
slouken@1895
   120
{
slouken@1895
   121
    const char *name;
slouken@1895
   122
    const char *desc;
slouken@2060
   123
    int (*init) (SDL_AudioDriverImpl * impl);
slouken@2060
   124
    int demand_only:1;          /* 1==request explicitly, or it won't be available. */
slouken@0
   125
} AudioBootStrap;
slouken@0
   126
icculus@2049
   127
#endif /* _SDL_sysaudio_h */
slouken@0
   128
slouken@1895
   129
/* vi: set ts=4 sw=4 expandtab: */