From b814188d7a1be103dd807212c5e27b05b7e359ee Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Mon, 29 May 2017 21:02:22 -0500 Subject: [PATCH] Remove references to global heap in SDL audio Ref #1987 --- .../src/lib/sdl/audio/SDL_genodeaudio.cc | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/repos/libports/src/lib/sdl/audio/SDL_genodeaudio.cc b/repos/libports/src/lib/sdl/audio/SDL_genodeaudio.cc index f0ab854cc..6e86e774c 100644 --- a/repos/libports/src/lib/sdl/audio/SDL_genodeaudio.cc +++ b/repos/libports/src/lib/sdl/audio/SDL_genodeaudio.cc @@ -19,18 +19,19 @@ #include #include #include +#include enum { AUDIO_CHANNELS = 2, }; -using Genode::env; using Genode::Allocator_avl; using Genode::Signal_context; using Genode::Signal_receiver; using Genode::log; using Genode::Hex; +using Genode::Constructible; static const char *channel_names[] = { "front left", "front right" }; static float volume = 1.0; @@ -57,7 +58,7 @@ extern "C" { struct SDL_PrivateAudioData { Uint8 *mixbuf; Uint32 mixlen; - Audio_out::Connection *audio[AUDIO_CHANNELS]; + Constructible audio[AUDIO_CHANNELS]; Audio_out::Packet *packet[AUDIO_CHANNELS]; }; @@ -113,7 +114,7 @@ static int GENODEAUD_Available(void) static void GENODEAUD_DeleteDevice(SDL_AudioDevice *device) { for (int channel = 0; channel < AUDIO_CHANNELS; channel++) - destroy(env()->heap(), device->hidden->audio[channel]); + device->hidden->audio[channel].destruct(); SDL_free(device->hidden); SDL_free(device); @@ -152,16 +153,15 @@ static SDL_AudioDevice *GENODEAUD_CreateDevice(int devindex) /* connect to 'Audio_out' service */ for (int channel = 0; channel < AUDIO_CHANNELS; channel++) { try { - _this->hidden->audio[channel] = new (env()->heap()) - Audio_out::Connection(channel_names[channel], - false, channel == 0 ? true : false); + _this->hidden->audio[channel].construct( + channel_names[channel], false, channel == 0 ? true : false); _this->hidden->audio[channel]->start(); } catch(Genode::Service_denied) { Genode::error("could not connect to 'Audio_out' service"); while(--channel > 0) - destroy(env()->heap(), _this->hidden->audio[channel]); + _this->hidden->audio[channel].destruct(); return NULL; } @@ -181,18 +181,18 @@ AudioBootStrap GENODEAUD_bootstrap = { static void GENODEAUD_WaitAudio(_THIS) { - Audio_out::Connection *con = _this->hidden->audio[0]; - Audio_out::Packet *p = _this->hidden->packet[0]; + Audio_out::Connection &con = *_this->hidden->audio[0]; + Audio_out::Packet *p = _this->hidden->packet[0]; - unsigned const packet_pos = con->stream()->packet_position(p); - unsigned const play_pos = con->stream()->pos(); + unsigned const packet_pos = con.stream()->packet_position(p); + unsigned const play_pos = con.stream()->pos(); unsigned queued = packet_pos < play_pos ? ((Audio_out::QUEUE_SIZE + packet_pos) - play_pos) : packet_pos - play_pos; /* wait until there is only one packet left to play */ while (queued > 1) { - con->wait_for_progress(); + con.wait_for_progress(); queued--; } } @@ -203,7 +203,7 @@ static void GENODEAUD_PlayAudio(_THIS) Audio_out::Connection *c[AUDIO_CHANNELS]; Audio_out::Packet *p[AUDIO_CHANNELS]; for (int channel = 0; channel < AUDIO_CHANNELS; channel++) { - c[channel] = _this->hidden->audio[channel]; + c[channel] = &(*_this->hidden->audio[channel]); p[channel] = _this->hidden->packet[channel]; }