audio: Clean up some CloseDevice() interface details.

- It's now always called if device->hidden isn't NULL, even if OpenDevice()
  failed halfway through. This lets implementation code not have to clean up
  itself on every possible failure point; just return an error and SDL will
  handle it for you.

- Implementations can assume this->hidden != NULL and not check for it.

- implementations don't have to set this->hidden = NULL when done, because
  the caller is always about to free(this).

- Don't reset other fields that are in a block of memory about to be free()'d.

- Implementations all now free things like internal mix buffers last, after
  closing devices and such, to guarantee they definitely aren't in use anymore
  at the point of deallocation.
This commit is contained in:
Ryan C. Gordon
2016-08-05 01:44:41 -04:00
parent 30a9139bc3
commit 9b64772775
24 changed files with 171 additions and 373 deletions

View File

@@ -74,16 +74,11 @@ FillSound(void *device, void *stream, size_t len,
static void
HAIKUAUDIO_CloseDevice(_THIS)
{
if (_this->hidden != NULL) {
if (_this->hidden->audio_obj) {
_this->hidden->audio_obj->Stop();
delete _this->hidden->audio_obj;
_this->hidden->audio_obj = NULL;
}
delete _this->hidden;
_this->hidden = NULL;
if (_this->hidden->audio_obj) {
_this->hidden->audio_obj->Stop();
delete _this->hidden->audio_obj;
}
delete _this->hidden;
}
@@ -177,7 +172,6 @@ HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
}
if (!valid_datatype) { /* shouldn't happen, but just in case... */
HAIKUAUDIO_CloseDevice(_this);
return SDL_SetError("Unsupported audio format");
}
@@ -196,7 +190,6 @@ HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
_this->hidden->audio_obj->SetHasData(true);
} else {
HAIKUAUDIO_CloseDevice(_this);
return SDL_SetError("Unable to start Be audio");
}