Remove references to global heap in SDL audio

Ref #1987
This commit is contained in:
Emery Hemingway 2017-05-29 21:02:22 -05:00 committed by Christian Helmuth
parent 697f179e21
commit b814188d7a

View File

@ -19,18 +19,19 @@
#include <base/log.h>
#include <base/thread.h>
#include <audio_out_session/connection.h>
#include <util/reconstructible.h>
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_out::Connection> 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];
}