summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2015-06-16 21:49:43 +0200
committerAlfred E. Heggestad <aeh@db.org>2015-06-16 21:49:43 +0200
commit500a7d1de384e37d609476f84dce207cccf88dc2 (patch)
tree496ad61eb5d19117470fabcb8bdb62587a374769
parent55fe148705d206d206f61dd9aa119a6672378e07 (diff)
change ausrc/auplay base-class to pointer
- change from a memory-reference to a const pointer - this saves one mem_deref() in the destructor and also decreases the chance of introducing memory leaks - test on debian
-rw-r--r--include/baresip.h4
-rw-r--r--modules/alsa/alsa.h4
-rw-r--r--modules/alsa/alsa_play.c7
-rw-r--r--modules/alsa/alsa_src.c7
-rw-r--r--modules/aubridge/aubridge.h8
-rw-r--r--modules/aubridge/play.c5
-rw-r--r--modules/aubridge/src.c5
-rw-r--r--modules/aufile/aufile.c7
-rw-r--r--modules/gst/gst.c9
-rw-r--r--modules/oss/oss.c14
-rw-r--r--modules/portaudio/portaudio.c16
-rw-r--r--modules/rst/audio.c7
-rw-r--r--src/core.h2
13 files changed, 41 insertions, 54 deletions
diff --git a/include/baresip.h b/include/baresip.h
index ac1c6eb..fe0dbab 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -266,7 +266,7 @@ struct ausrc_prm {
typedef void (ausrc_read_h)(const int16_t *sampv, size_t sampc, void *arg);
typedef void (ausrc_error_h)(int err, const char *str, void *arg);
-typedef int (ausrc_alloc_h)(struct ausrc_st **stp, struct ausrc *ausrc,
+typedef int (ausrc_alloc_h)(struct ausrc_st **stp, const struct ausrc *ausrc,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg);
@@ -296,7 +296,7 @@ struct auplay_prm {
typedef void (auplay_write_h)(int16_t *sampv, size_t sampc, void *arg);
-typedef int (auplay_alloc_h)(struct auplay_st **stp, struct auplay *ap,
+typedef int (auplay_alloc_h)(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg);
diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h
index be345c6..a121ebb 100644
--- a/modules/alsa/alsa.h
+++ b/modules/alsa/alsa.h
@@ -9,10 +9,10 @@ extern char alsa_dev[64];
int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch,
uint32_t num_frames);
-int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as,
+int alsa_src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg);
-int alsa_play_alloc(struct auplay_st **stp, struct auplay *ap,
+int alsa_play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg);
diff --git a/modules/alsa/alsa_play.c b/modules/alsa/alsa_play.c
index ebd8146..bcc730b 100644
--- a/modules/alsa/alsa_play.c
+++ b/modules/alsa/alsa_play.c
@@ -17,7 +17,7 @@
struct auplay_st {
- struct auplay *ap; /* inheritance */
+ const struct auplay *ap; /* pointer to base-class (inheritance) */
pthread_t thread;
bool run;
snd_pcm_t *write;
@@ -44,7 +44,6 @@ static void auplay_destructor(void *arg)
snd_pcm_close(st->write);
mem_deref(st->sampv);
- mem_deref(st->ap);
mem_deref(st->device);
}
@@ -85,7 +84,7 @@ static void *write_thread(void *arg)
}
-int alsa_play_alloc(struct auplay_st **stp, struct auplay *ap,
+int alsa_play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg)
{
@@ -108,7 +107,7 @@ int alsa_play_alloc(struct auplay_st **stp, struct auplay *ap,
goto out;
st->prm = *prm;
- st->ap = mem_ref(ap);
+ st->ap = ap;
st->wh = wh;
st->arg = arg;
diff --git a/modules/alsa/alsa_src.c b/modules/alsa/alsa_src.c
index f95765c..0a5d548 100644
--- a/modules/alsa/alsa_src.c
+++ b/modules/alsa/alsa_src.c
@@ -17,7 +17,7 @@
struct ausrc_st {
- struct ausrc *as; /* inheritance */
+ const struct ausrc *as; /* pointer to base-class (inheritance) */
pthread_t thread;
bool run;
snd_pcm_t *read;
@@ -44,7 +44,6 @@ static void ausrc_destructor(void *arg)
snd_pcm_close(st->read);
mem_deref(st->sampv);
- mem_deref(st->as);
mem_deref(st->device);
}
@@ -83,7 +82,7 @@ static void *read_thread(void *arg)
}
-int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as,
+int alsa_src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -109,7 +108,7 @@ int alsa_src_alloc(struct ausrc_st **stp, struct ausrc *as,
goto out;
st->prm = *prm;
- st->as = mem_ref(as);
+ st->as = as;
st->rh = rh;
st->arg = arg;
diff --git a/modules/aubridge/aubridge.h b/modules/aubridge/aubridge.h
index 76ec53f..7e24b6c 100644
--- a/modules/aubridge/aubridge.h
+++ b/modules/aubridge/aubridge.h
@@ -8,7 +8,7 @@
struct device;
struct ausrc_st {
- struct ausrc *as; /* inheritance */
+ const struct ausrc *as; /* inheritance */
struct device *dev;
struct ausrc_prm prm;
ausrc_read_h *rh;
@@ -16,7 +16,7 @@ struct ausrc_st {
};
struct auplay_st {
- struct auplay *ap; /* inheritance */
+ const struct auplay *ap; /* inheritance */
struct device *dev;
struct auplay_prm prm;
auplay_write_h *wh;
@@ -27,10 +27,10 @@ struct auplay_st {
extern struct hash *ht_device;
-int play_alloc(struct auplay_st **stp, struct auplay *ap,
+int play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg);
-int src_alloc(struct ausrc_st **stp, struct ausrc *as,
+int src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg);
diff --git a/modules/aubridge/play.c b/modules/aubridge/play.c
index c31792c..37c04fa 100644
--- a/modules/aubridge/play.c
+++ b/modules/aubridge/play.c
@@ -15,11 +15,10 @@ static void auplay_destructor(void *arg)
device_stop(st->dev);
mem_deref(st->dev);
- mem_deref(st->ap);
}
-int play_alloc(struct auplay_st **stp, struct auplay *ap,
+int play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg)
{
@@ -33,7 +32,7 @@ int play_alloc(struct auplay_st **stp, struct auplay *ap,
if (!st)
return ENOMEM;
- st->ap = mem_ref(ap);
+ st->ap = ap;
st->prm = *prm;
st->wh = wh;
st->arg = arg;
diff --git a/modules/aubridge/src.c b/modules/aubridge/src.c
index 6439cdd..22ce13a 100644
--- a/modules/aubridge/src.c
+++ b/modules/aubridge/src.c
@@ -15,11 +15,10 @@ static void ausrc_destructor(void *arg)
device_stop(st->dev);
mem_deref(st->dev);
- mem_deref(st->as);
}
-int src_alloc(struct ausrc_st **stp, struct ausrc *as,
+int src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -36,7 +35,7 @@ int src_alloc(struct ausrc_st **stp, struct ausrc *as,
if (!st)
return ENOMEM;
- st->as = mem_ref(as);
+ st->as = as;
st->prm = *prm;
st->rh = rh;
st->arg = arg;
diff --git a/modules/aufile/aufile.c b/modules/aufile/aufile.c
index 0323758..0fc9faa 100644
--- a/modules/aufile/aufile.c
+++ b/modules/aufile/aufile.c
@@ -19,7 +19,7 @@
struct ausrc_st {
- struct ausrc *as; /* base class */
+ const struct ausrc *as; /* base class */
struct tmr tmr;
struct aufile *aufile;
struct aubuf *aubuf;
@@ -49,7 +49,6 @@ static void destructor(void *arg)
mem_deref(st->aufile);
mem_deref(st->aubuf);
- mem_deref(st->as);
}
@@ -139,7 +138,7 @@ static int read_file(struct ausrc_st *st)
}
-static int alloc_handler(struct ausrc_st **stp, struct ausrc *as,
+static int alloc_handler(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *dev,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -158,7 +157,7 @@ static int alloc_handler(struct ausrc_st **stp, struct ausrc *as,
if (!st)
return ENOMEM;
- st->as = mem_ref(as);
+ st->as = as;
st->rh = rh;
st->errh = errh;
st->arg = arg;
diff --git a/modules/gst/gst.c b/modules/gst/gst.c
index 46973a4..2817dd0 100644
--- a/modules/gst/gst.c
+++ b/modules/gst/gst.c
@@ -29,7 +29,8 @@
* </pre>
*/
struct ausrc_st {
- struct ausrc *as; /**< Inheritance */
+ const struct ausrc *as; /**< Inheritance */
+
pthread_t tid; /**< Thread ID */
bool run; /**< Running flag */
ausrc_read_h *rh; /**< Read handler */
@@ -342,12 +343,10 @@ static void gst_destructor(void *arg)
mem_deref(st->uri);
mem_deref(st->aubuf);
-
- mem_deref(st->as);
}
-static int gst_alloc(struct ausrc_st **stp, struct ausrc *as,
+static int gst_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -367,7 +366,7 @@ static int gst_alloc(struct ausrc_st **stp, struct ausrc *as,
if (!st)
return ENOMEM;
- st->as = mem_ref(as);
+ st->as = as;
st->rh = rh;
st->errh = errh;
st->arg = arg;
diff --git a/modules/oss/oss.c b/modules/oss/oss.c
index 3a3e938..3d02154 100644
--- a/modules/oss/oss.c
+++ b/modules/oss/oss.c
@@ -33,7 +33,7 @@
struct ausrc_st {
- struct ausrc *as; /* inheritance */
+ const struct ausrc *as; /* inheritance */
int fd;
int16_t *sampv;
size_t sampc;
@@ -43,7 +43,7 @@ struct ausrc_st {
};
struct auplay_st {
- struct auplay *ap; /* inheritance */
+ const struct auplay *ap; /* inheritance */
pthread_t thread;
bool run;
int fd;
@@ -153,7 +153,6 @@ static void auplay_destructor(void *arg)
}
mem_deref(st->sampv);
- mem_deref(st->ap);
}
@@ -167,7 +166,6 @@ static void ausrc_destructor(void *arg)
}
mem_deref(st->sampv);
- mem_deref(st->as);
}
@@ -205,7 +203,7 @@ static void *play_thread(void *arg)
}
-static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
+static int src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -253,7 +251,7 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
if (err)
goto out;
- st->as = mem_ref(as);
+ st->as = as;
out:
if (err)
@@ -265,7 +263,7 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
}
-static int play_alloc(struct auplay_st **stp, struct auplay *ap,
+static int play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg)
{
@@ -304,7 +302,7 @@ static int play_alloc(struct auplay_st **stp, struct auplay *ap,
if (err)
goto out;
- st->ap = mem_ref(ap);
+ st->ap = ap;
st->run = true;
err = pthread_create(&st->thread, NULL, play_thread, st);
diff --git a/modules/portaudio/portaudio.c b/modules/portaudio/portaudio.c
index 872c6af..41c8efc 100644
--- a/modules/portaudio/portaudio.c
+++ b/modules/portaudio/portaudio.c
@@ -26,7 +26,7 @@
struct ausrc_st {
- struct ausrc *as; /* inheritance */
+ const struct ausrc *as; /* inheritance */
PaStream *stream_rd;
ausrc_read_h *rh;
void *arg;
@@ -35,7 +35,7 @@ struct ausrc_st {
};
struct auplay_st {
- struct auplay *ap; /* inheritance */
+ const struct auplay *ap; /* inheritance */
PaStream *stream_wr;
auplay_write_h *wh;
void *arg;
@@ -175,8 +175,6 @@ static void ausrc_destructor(void *arg)
Pa_AbortStream(st->stream_rd);
Pa_CloseStream(st->stream_rd);
}
-
- mem_deref(st->as);
}
@@ -190,12 +188,10 @@ static void auplay_destructor(void *arg)
Pa_AbortStream(st->stream_wr);
Pa_CloseStream(st->stream_wr);
}
-
- mem_deref(st->ap);
}
-static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
+static int src_alloc(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *device,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -220,7 +216,7 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
if (!st)
return ENOMEM;
- st->as = mem_ref(as);
+ st->as = as;
st->rh = rh;
st->arg = arg;
st->ch = prm->ch;
@@ -241,7 +237,7 @@ static int src_alloc(struct ausrc_st **stp, struct ausrc *as,
}
-static int play_alloc(struct auplay_st **stp, struct auplay *ap,
+static int play_alloc(struct auplay_st **stp, const struct auplay *ap,
struct auplay_prm *prm, const char *device,
auplay_write_h *wh, void *arg)
{
@@ -263,7 +259,7 @@ static int play_alloc(struct auplay_st **stp, struct auplay *ap,
if (!st)
return ENOMEM;
- st->ap = mem_ref(ap);
+ st->ap = ap;
st->wh = wh;
st->arg = arg;
st->ch = prm->ch;
diff --git a/modules/rst/audio.c b/modules/rst/audio.c
index 9fbfe26..2eca230 100644
--- a/modules/rst/audio.c
+++ b/modules/rst/audio.c
@@ -17,7 +17,7 @@
struct ausrc_st {
- struct ausrc *as;
+ const struct ausrc *as; /* pointer to base-class (inheritance) */
pthread_t thread;
struct rst *rst;
mpg123_handle *mp3;
@@ -52,7 +52,6 @@ static void destructor(void *arg)
}
mem_deref(st->aubuf);
- mem_deref(st->as);
}
@@ -149,7 +148,7 @@ void rst_audio_feed(struct ausrc_st *st, const uint8_t *buf, size_t sz)
}
-static int alloc_handler(struct ausrc_st **stp, struct ausrc *as,
+static int alloc_handler(struct ausrc_st **stp, const struct ausrc *as,
struct media_ctx **ctx,
struct ausrc_prm *prm, const char *dev,
ausrc_read_h *rh, ausrc_error_h *errh, void *arg)
@@ -164,7 +163,7 @@ static int alloc_handler(struct ausrc_st **stp, struct ausrc *as,
if (!st)
return ENOMEM;
- st->as = mem_ref(as);
+ st->as = as;
st->rh = rh;
st->errh = errh;
st->arg = arg;
diff --git a/src/core.h b/src/core.h
index 4c1c6bb..a9a6b16 100644
--- a/src/core.h
+++ b/src/core.h
@@ -91,7 +91,7 @@ struct auplay {
*/
struct ausrc_st {
- struct ausrc *as;
+ const struct ausrc *as;
};
struct ausrc {