Commit cc7b95a6 authored by Simon Morlat's avatar Simon Morlat

fix memory leak in pulse audio player backend.

parent a23c4494
......@@ -286,11 +286,12 @@ typedef enum _StreamType {
} StreamType;
typedef struct _Stream{
ms_mutex_t mutex;
StreamType type;
pa_sample_spec sampleSpec;
pa_stream *stream;
pa_stream_state_t state;
MSQueue queue;
MSBufferizer bufferizer;
char *dev;
double init_volume;
}Stream;
......@@ -314,12 +315,13 @@ static bool_t stream_wait_for_state(Stream *ctx, pa_stream_state_t successState,
static Stream *stream_new(StreamType type) {
Stream *s = ms_new0(Stream, 1);
ms_mutex_init(&s->mutex, NULL);
s->type = type;
s->sampleSpec.format = PA_SAMPLE_S16LE;
s->sampleSpec.channels=1;
s->sampleSpec.rate=8000;
s->state = PA_STREAM_UNCONNECTED;
ms_queue_init(&s->queue);
ms_bufferizer_init(&s->bufferizer);
s->dev = NULL;
s->init_volume = -1.0;
return s;
......@@ -332,37 +334,25 @@ static void stream_free(Stream *s) {
ms_free(s->dev);
}
}
ms_queue_flush(&s->queue);
ms_bufferizer_uninit(&s->bufferizer);
ms_mutex_destroy(&s->mutex);
ms_free(s);
}
static size_t stream_play(Stream *s, size_t nbytes) {
uint8_t *data;
uint8_t *wptr;
size_t nread_glob = 0;
if(nbytes == 0) return 0;
if (ms_bufferizer_get_avail(&s->bufferizer) >= nbytes){
uint8_t *data;
data = ms_new(uint8_t, nbytes);
wptr = data;
while(!ms_queue_empty(&s->queue) && nread_glob < nbytes) {
mblk_t *m = ms_queue_peek_first(&s->queue);
size_t ntoread = nbytes - nread_glob;
size_t nread = readmsg(m, ntoread, wptr);
nread_glob += nread;
wptr += nread;
if(msgdsize(m) == 0) {
ms_queue_remove(&s->queue, m);
}
ms_mutex_lock(&s->mutex);
ms_bufferizer_read(&s->bufferizer, data, nbytes);
ms_mutex_unlock(&s->mutex);
pa_stream_write(s->stream, data, nbytes, ms_free, 0, PA_SEEK_RELATIVE);
}
if(nread_glob > 0) {
pa_stream_write(s->stream, data, nread_glob, ms_free, 0, PA_SEEK_RELATIVE);
} else {
ms_free(data);
}
return nread_glob;
return nbytes;
}
static void stream_write_request_cb(pa_stream *p, size_t nbytes, void *user_data) {
......@@ -453,7 +443,6 @@ static void stream_disconnect(Stream *s) {
}
pa_stream_unref(s->stream);
s->stream = NULL;
ms_queue_flush(&s->queue);
s->state = PA_STREAM_UNCONNECTED;
s->init_volume = -1.0;
}
......@@ -696,12 +685,9 @@ static void pulse_write_process(MSFilter *f){
size_t nwritable;
if(s->stream) {
mblk_t *im;
while((im=ms_queue_get(f->inputs[0]))) {
pa_threaded_mainloop_lock(pa_loop);
ms_queue_put(&s->queue, im);
pa_threaded_mainloop_unlock(pa_loop);
}
ms_mutex_lock(&s->mutex);
ms_bufferizer_put_from_queue(&s->bufferizer,f->inputs[0]);
ms_mutex_unlock(&s->mutex);
pa_threaded_mainloop_lock(pa_loop);
nwritable = pa_stream_writable_size(s->stream);
......
......@@ -201,8 +201,16 @@ mblk_t *ms_yuv_buf_allocator_get(MSYuvBufAllocator *obj, MSPicture *buf, int w,
}
void ms_yuv_buf_allocator_free(MSYuvBufAllocator *obj) {
mblk_t *m;
int possibly_leaked = 0;
for(m = qbegin(&obj->q); !qend(&obj->q,m); m = qnext(&obj->q, m)){
if (m->b_datap->db_ref > 1) possibly_leaked++;
}
msgb_allocator_uninit(obj);
ms_free(obj);
if (possibly_leaked > 0){
ms_warning("ms_yuv_buf_allocator_free(): leaving %i mblk_t still ref'd, possible leak.", possibly_leaked);
}
}
static void plane_horizontal_mirror(uint8_t *p, int linesize, int w, int h){
......
......@@ -789,6 +789,7 @@ void setup_media_streams(MediastreamDatas* args) {
audio_stream_set_echo_canceller_params(args->audio,args->ec_len_ms,args->ec_delay_ms,args->ec_framesize);
audio_stream_enable_echo_limiter(args->audio,args->el);
audio_stream_enable_adaptive_bitrate_control(args->audio,args->use_rc);
ms_message("Starting audio stream.\n");
audio_stream_start_full(args->audio,args->profile,args->ip,args->remoteport,args->ip,args->enable_rtcp?args->remoteport+1:-1, args->payload, args->jitter,args->infile,args->outfile,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment