diff options
-rw-r--r-- | OpenAL32/alSource.c | 629 |
1 files changed, 304 insertions, 325 deletions
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 0e84ba8c..66e9b812 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -1215,134 +1215,127 @@ static ALenum GetSourcei64v(const ALsource *Source, ALCcontext *Context, SrcIntP AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources) { - ALCcontext *Context; - ALsizei cur = 0; + ALCcontext *context; + ALsizei cur = 0; + ALenum err; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(cur = 0;cur < n;cur++) { - ALenum err; - - CHECK_VALUE(Context, n >= 0); - for(cur = 0;cur < n;cur++) + ALsource *source = al_calloc(16, sizeof(ALsource)); + if(!source) { - ALsource *source = al_calloc(16, sizeof(ALsource)); - if(!source) - { - alDeleteSources(cur, sources); - al_throwerr(Context, AL_OUT_OF_MEMORY); - } - InitSourceParams(source); - - err = NewThunkEntry(&source->id); - if(err == AL_NO_ERROR) - err = InsertUIntMapEntry(&Context->SourceMap, source->id, source); - if(err != AL_NO_ERROR) - { - FreeThunkEntry(source->id); - memset(source, 0, sizeof(ALsource)); - al_free(source); + alDeleteSources(cur, sources); + SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); + } + InitSourceParams(source); - alDeleteSources(cur, sources); - al_throwerr(Context, err); - } + err = NewThunkEntry(&source->id); + if(err == AL_NO_ERROR) + err = InsertUIntMapEntry(&context->SourceMap, source->id, source); + if(err != AL_NO_ERROR) + { + FreeThunkEntry(source->id); + memset(source, 0, sizeof(ALsource)); + al_free(source); - sources[cur] = source->id; + alDeleteSources(cur, sources); + SET_ERROR_AND_GOTO(context, err, done); } + + sources[cur] = source->id; } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources) { - ALCcontext *Context; + ALCcontext *context; + ALbufferlistitem *BufferList; + ALsource *Source; + ALsizei i, j; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try - { - ALbufferlistitem *BufferList; - ALsource *Source; - ALsizei i, j; + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - CHECK_VALUE(Context, n >= 0); + /* Check that all Sources are valid */ + for(i = 0;i < n;i++) + { + if(LookupSource(context, sources[i]) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } + for(i = 0;i < n;i++) + { + ALsource **srclist, **srclistend; - /* Check that all Sources are valid */ - for(i = 0;i < n;i++) - { - if(LookupSource(Context, sources[i]) == NULL) - al_throwerr(Context, AL_INVALID_NAME); - } + if((Source=RemoveSource(context, sources[i])) == NULL) + continue; + FreeThunkEntry(Source->id); - for(i = 0;i < n;i++) + LockContext(context); + srclist = context->ActiveSources; + srclistend = srclist + context->ActiveSourceCount; + while(srclist != srclistend) { - ALsource **srclist, **srclistend; - - if((Source=RemoveSource(Context, sources[i])) == NULL) - continue; - FreeThunkEntry(Source->id); - - LockContext(Context); - srclist = Context->ActiveSources; - srclistend = srclist + Context->ActiveSourceCount; - while(srclist != srclistend) + if(*srclist == Source) { - if(*srclist == Source) - { - Context->ActiveSourceCount--; - *srclist = *(--srclistend); - break; - } - srclist++; + context->ActiveSourceCount--; + *srclist = *(--srclistend); + break; } - UnlockContext(Context); - - while(Source->queue != NULL) - { - BufferList = Source->queue; - Source->queue = BufferList->next; + srclist++; + } + UnlockContext(context); - if(BufferList->buffer != NULL) - DecrementRef(&BufferList->buffer->ref); - free(BufferList); - } + while(Source->queue != NULL) + { + BufferList = Source->queue; + Source->queue = BufferList->next; - for(j = 0;j < MAX_SENDS;++j) - { - if(Source->Send[j].Slot) - DecrementRef(&Source->Send[j].Slot->ref); - Source->Send[j].Slot = NULL; - } + if(BufferList->buffer != NULL) + DecrementRef(&BufferList->buffer->ref); + free(BufferList); + } - memset(Source, 0, sizeof(*Source)); - al_free(Source); + for(j = 0;j < MAX_SENDS;++j) + { + if(Source->Send[j].Slot) + DecrementRef(&Source->Send[j].Slot->ref); + Source->Send[j].Slot = NULL; } + + memset(Source, 0, sizeof(*Source)); + al_free(Source); } - al_endtry; - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALboolean AL_APIENTRY alIsSource(ALuint source) { - ALCcontext *Context; - ALboolean result; + ALCcontext *context; + ALboolean ret; - Context = GetContextRef(); - if(!Context) return AL_FALSE; + context = GetContextRef(); + if(!context) return AL_FALSE; - result = (LookupSource(Context, source) ? AL_TRUE : AL_FALSE); + ret = (LookupSource(context, source) ? AL_TRUE : AL_FALSE); - ALCcontext_DecRef(Context); + ALCcontext_DecRef(context); - return result; + return ret; } @@ -1896,53 +1889,51 @@ AL_API ALvoid AL_APIENTRY alSourcePlay(ALuint source) } AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCcontext *context; + ALsource *source; + ALsizei i; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(i = 0;i < n;i++) { - CHECK_VALUE(Context, n >= 0); - for(i = 0;i < n;i++) - { - if(!LookupSource(Context, sources[i])) - al_throwerr(Context, AL_INVALID_NAME); - } + if(!LookupSource(context, sources[i])) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } - LockContext(Context); - while(Context->MaxActiveSources-Context->ActiveSourceCount < n) + LockContext(context); + while(n > context->MaxActiveSources-context->ActiveSourceCount) + { + void *temp = NULL; + ALsizei newcount; + + newcount = context->MaxActiveSources << 1; + if(newcount > 0) + temp = realloc(context->ActiveSources, + sizeof(*context->ActiveSources) * newcount); + if(!temp) { - void *temp = NULL; - ALsizei newcount; - - newcount = Context->MaxActiveSources << 1; - if(newcount > 0) - temp = realloc(Context->ActiveSources, - sizeof(*Context->ActiveSources) * newcount); - if(!temp) - { - UnlockContext(Context); - al_throwerr(Context, AL_OUT_OF_MEMORY); - } - - Context->ActiveSources = temp; - Context->MaxActiveSources = newcount; + UnlockContext(context); + SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done); } - for(i = 0;i < n;i++) - { - Source = LookupSource(Context, sources[i]); - if(Context->DeferUpdates) Source->new_state = AL_PLAYING; - else SetSourceState(Source, Context, AL_PLAYING); - } - UnlockContext(Context); + context->ActiveSources = temp; + context->MaxActiveSources = newcount; } - al_endtry; - ALCcontext_DecRef(Context); + for(i = 0;i < n;i++) + { + source = LookupSource(context, sources[i]); + if(context->DeferUpdates) source->new_state = AL_PLAYING; + else SetSourceState(source, context, AL_PLAYING); + } + UnlockContext(context); + +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alSourcePause(ALuint source) @@ -1951,34 +1942,32 @@ AL_API ALvoid AL_APIENTRY alSourcePause(ALuint source) } AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCcontext *context; + ALsource *source; + ALsizei i; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(i = 0;i < n;i++) { - CHECK_VALUE(Context, n >= 0); - for(i = 0;i < n;i++) - { - if(!LookupSource(Context, sources[i])) - al_throwerr(Context, AL_INVALID_NAME); - } + if(!LookupSource(context, sources[i])) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } - LockContext(Context); - for(i = 0;i < n;i++) - { - Source = LookupSource(Context, sources[i]); - if(Context->DeferUpdates) Source->new_state = AL_PAUSED; - else SetSourceState(Source, Context, AL_PAUSED); - } - UnlockContext(Context); + LockContext(context); + for(i = 0;i < n;i++) + { + source = LookupSource(context, sources[i]); + if(context->DeferUpdates) source->new_state = AL_PAUSED; + else SetSourceState(source, context, AL_PAUSED); } - al_endtry; + UnlockContext(context); - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alSourceStop(ALuint source) @@ -1987,34 +1976,32 @@ AL_API ALvoid AL_APIENTRY alSourceStop(ALuint source) } AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCcontext *context; + ALsource *source; + ALsizei i; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(i = 0;i < n;i++) { - CHECK_VALUE(Context, n >= 0); - for(i = 0;i < n;i++) - { - if(!LookupSource(Context, sources[i])) - al_throwerr(Context, AL_INVALID_NAME); - } + if(!LookupSource(context, sources[i])) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } - LockContext(Context); - for(i = 0;i < n;i++) - { - Source = LookupSource(Context, sources[i]); - Source->new_state = AL_NONE; - SetSourceState(Source, Context, AL_STOPPED); - } - UnlockContext(Context); + LockContext(context); + for(i = 0;i < n;i++) + { + source = LookupSource(context, sources[i]); + source->new_state = AL_NONE; + SetSourceState(source, context, AL_STOPPED); } - al_endtry; + UnlockContext(context); - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } AL_API ALvoid AL_APIENTRY alSourceRewind(ALuint source) @@ -2023,159 +2010,153 @@ AL_API ALvoid AL_APIENTRY alSourceRewind(ALuint source) } AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCcontext *context; + ALsource *source; + ALsizei i; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try + if(!(n >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + for(i = 0;i < n;i++) { - CHECK_VALUE(Context, n >= 0); - for(i = 0;i < n;i++) - { - if(!LookupSource(Context, sources[i])) - al_throwerr(Context, AL_INVALID_NAME); - } + if(!LookupSource(context, sources[i])) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } - LockContext(Context); - for(i = 0;i < n;i++) - { - Source = LookupSource(Context, sources[i]); - Source->new_state = AL_NONE; - SetSourceState(Source, Context, AL_INITIAL); - } - UnlockContext(Context); + LockContext(context); + for(i = 0;i < n;i++) + { + source = LookupSource(context, sources[i]); + source->new_state = AL_NONE; + SetSourceState(source, context, AL_INITIAL); } - al_endtry; + UnlockContext(context); - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } -AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const ALuint *buffers) +AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALuint *buffers) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCdevice *device; + ALCcontext *context; + ALsource *source; + ALsizei i; ALbufferlistitem *BufferListStart = NULL; ALbufferlistitem *BufferList; - ALbuffer *BufferFmt; + ALbuffer *BufferFmt = NULL; if(nb == 0) return; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; - al_try - { - ALCdevice *device = Context->Device; + device = context->Device; - CHECK_VALUE(Context, nb >= 0); + if(!(nb >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + if((source=LookupSource(context, src)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); - if((Source=LookupSource(Context, source)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); + LockContext(context); + if(source->SourceType == AL_STATIC) + { + UnlockContext(context); + /* Can't queue on a Static Source */ + SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); + } - LockContext(Context); - if(Source->SourceType == AL_STATIC) + /* Check for a valid Buffer, for its frequency and format */ + BufferList = source->queue; + while(BufferList) + { + if(BufferList->buffer) { - UnlockContext(Context); - /* Can't queue on a Static Source */ - al_throwerr(Context, AL_INVALID_OPERATION); + BufferFmt = BufferList->buffer; + break; } + BufferList = BufferList->next; + } - BufferFmt = NULL; + for(i = 0;i < nb;i++) + { + ALbuffer *buffer = NULL; + if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == NULL) + { + UnlockContext(context); + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + } - /* Check for a valid Buffer, for its frequency and format */ - BufferList = Source->queue; - while(BufferList) + if(!BufferListStart) { - if(BufferList->buffer) - { - BufferFmt = BufferList->buffer; - break; - } + BufferListStart = malloc(sizeof(ALbufferlistitem)); + BufferListStart->buffer = buffer; + BufferListStart->next = NULL; + BufferListStart->prev = NULL; + BufferList = BufferListStart; + } + else + { + BufferList->next = malloc(sizeof(ALbufferlistitem)); + BufferList->next->buffer = buffer; + BufferList->next->next = NULL; + BufferList->next->prev = BufferList; BufferList = BufferList->next; } + if(!buffer) continue; + IncrementRef(&buffer->ref); - for(i = 0;i < nb;i++) + ReadLock(&buffer->lock); + if(BufferFmt == NULL) { - ALbuffer *buffer = NULL; - if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == NULL) - { - UnlockContext(Context); - al_throwerr(Context, AL_INVALID_NAME); - } + BufferFmt = buffer; - if(!BufferListStart) - { - BufferListStart = malloc(sizeof(ALbufferlistitem)); - BufferListStart->buffer = buffer; - BufferListStart->next = NULL; - BufferListStart->prev = NULL; - BufferList = BufferListStart; - } + source->NumChannels = ChannelsFromFmt(buffer->FmtChannels); + source->SampleSize = BytesFromFmt(buffer->FmtType); + if(buffer->FmtChannels == FmtMono) + source->Update = CalcSourceParams; else - { - BufferList->next = malloc(sizeof(ALbufferlistitem)); - BufferList->next->buffer = buffer; - BufferList->next->next = NULL; - BufferList->next->prev = BufferList; - BufferList = BufferList->next; - } - if(!buffer) continue; - IncrementRef(&buffer->ref); - - ReadLock(&buffer->lock); - if(BufferFmt == NULL) - { - BufferFmt = buffer; - - Source->NumChannels = ChannelsFromFmt(buffer->FmtChannels); - Source->SampleSize = BytesFromFmt(buffer->FmtType); - if(buffer->FmtChannels == FmtMono) - Source->Update = CalcSourceParams; - else - Source->Update = CalcNonAttnSourceParams; + source->Update = CalcNonAttnSourceParams; - Source->NeedsUpdate = AL_TRUE; - } - else if(BufferFmt->Frequency != buffer->Frequency || - BufferFmt->OriginalChannels != buffer->OriginalChannels || - BufferFmt->OriginalType != buffer->OriginalType) - { - ReadUnlock(&buffer->lock); - UnlockContext(Context); - al_throwerr(Context, AL_INVALID_OPERATION); - } + source->NeedsUpdate = AL_TRUE; + } + else if(BufferFmt->Frequency != buffer->Frequency || + BufferFmt->OriginalChannels != buffer->OriginalChannels || + BufferFmt->OriginalType != buffer->OriginalType) + { ReadUnlock(&buffer->lock); + UnlockContext(context); + SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done); } + ReadUnlock(&buffer->lock); + } - /* Source is now streaming */ - Source->SourceType = AL_STREAMING; + /* Source is now streaming */ + source->SourceType = AL_STREAMING; - if(Source->queue == NULL) - Source->queue = BufferListStart; - else - { - /* Append to the end of the queue */ - BufferList = Source->queue; - while(BufferList->next != NULL) - BufferList = BufferList->next; + if(source->queue == NULL) + source->queue = BufferListStart; + else + { + /* Append to the end of the queue */ + BufferList = source->queue; + while(BufferList->next != NULL) + BufferList = BufferList->next; - BufferListStart->prev = BufferList; - BufferList->next = BufferListStart; - } - BufferListStart = NULL; + BufferListStart->prev = BufferList; + BufferList->next = BufferListStart; + } + BufferListStart = NULL; - Source->BuffersInQueue += nb; + source->BuffersInQueue += nb; - UnlockContext(Context); - } - al_endtry; + UnlockContext(context); +done: while(BufferListStart) { BufferList = BufferListStart; @@ -2186,62 +2167,60 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint source, ALsizei nb, const free(BufferList); } - ALCcontext_DecRef(Context); + ALCcontext_DecRef(context); } -AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint source, ALsizei nb, ALuint *buffers) +AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *buffers) { - ALCcontext *Context; - ALsource *Source; - ALsizei i; + ALCcontext *context; + ALsource *source; + ALsizei i; ALbufferlistitem *BufferList; if(nb == 0) return; - Context = GetContextRef(); - if(!Context) return; + context = GetContextRef(); + if(!context) return; + + if(!(nb >= 0)) + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); - al_try + if((source=LookupSource(context, src)) == NULL) + SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done); + + LockContext(context); + if(source->Looping || source->SourceType != AL_STREAMING || + (ALuint)nb > source->BuffersPlayed) { - CHECK_VALUE(Context, nb >= 0); + UnlockContext(context); + /* Trying to unqueue pending buffers, or a buffer that wasn't queued. */ + SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done); + } - if((Source=LookupSource(Context, source)) == NULL) - al_throwerr(Context, AL_INVALID_NAME); + for(i = 0;i < nb;i++) + { + BufferList = source->queue; + source->queue = BufferList->next; + source->BuffersInQueue--; + source->BuffersPlayed--; - LockContext(Context); - if(Source->Looping || Source->SourceType != AL_STREAMING || - (ALuint)nb > Source->BuffersPlayed) + if(BufferList->buffer) { - UnlockContext(Context); - /* Trying to unqueue pending buffers, or a buffer that wasn't queued. */ - al_throwerr(Context, AL_INVALID_VALUE); + buffers[i] = BufferList->buffer->id; + DecrementRef(&BufferList->buffer->ref); } + else + buffers[i] = 0; - for(i = 0;i < nb;i++) - { - BufferList = Source->queue; - Source->queue = BufferList->next; - Source->BuffersInQueue--; - Source->BuffersPlayed--; - - if(BufferList->buffer) - { - buffers[i] = BufferList->buffer->id; - DecrementRef(&BufferList->buffer->ref); - } - else - buffers[i] = 0; - - free(BufferList); - } - if(Source->queue) - Source->queue->prev = NULL; - UnlockContext(Context); + free(BufferList); } - al_endtry; + if(source->queue) + source->queue->prev = NULL; + UnlockContext(context); - ALCcontext_DecRef(Context); +done: + ALCcontext_DecRef(context); } |