summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-05-23 14:55:34 +0200
committerGitHub <noreply@github.com>2017-05-23 14:55:34 +0200
commit97229c0c2e13415d0fa1c808742c22adeb9b2f33 (patch)
tree06772df40db156723e13e40466dac2916f5d4a7b /src
parent91e3b2c11f617a126679b3d15239bdb0c1c72e4c (diff)
Vidsrc api reentrant (#256)
* vidsrc: make the API re-entrant * vidsrc: update all modules to new API
Diffstat (limited to 'src')
-rw-r--r--src/baresip.c8
-rw-r--r--src/call.c3
-rw-r--r--src/video.c8
-rw-r--r--src/vidsrc.c55
4 files changed, 38 insertions, 36 deletions
diff --git a/src/baresip.c b/src/baresip.c
index ce3f1aa..d1ebc1d 100644
--- a/src/baresip.c
+++ b/src/baresip.c
@@ -25,6 +25,7 @@ static struct baresip {
struct list auplayl;
struct list aufiltl;
struct list vidcodecl;
+ struct list vidsrcl;
} baresip;
@@ -43,6 +44,7 @@ int baresip_init(struct config *cfg, bool prefer_ipv6)
list_init(&baresip.ausrcl);
list_init(&baresip.auplayl);
list_init(&baresip.vidcodecl);
+ list_init(&baresip.vidsrcl);
/* Initialise Network */
err = net_alloc(&baresip.net, &cfg->net,
@@ -160,3 +162,9 @@ struct list *baresip_vidcodecl(void)
{
return &baresip.vidcodecl;
}
+
+
+struct list *baresip_vidsrcl(void)
+{
+ return &baresip.vidsrcl;
+}
diff --git a/src/call.c b/src/call.c
index 15c8e8c..f164ec1 100644
--- a/src/call.c
+++ b/src/call.c
@@ -599,7 +599,8 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst,
video source or video display */
use_video = (vidmode != VIDMODE_OFF)
&& (list_head(account_vidcodecl(call->acc)) != NULL)
- && (NULL != vidsrc_find(NULL) || NULL != vidisp_find(NULL));
+ && (NULL != vidsrc_find(baresip_vidsrcl(), NULL)
+ || NULL != vidisp_find(NULL));
debug("call: use_video=%d\n", use_video);
diff --git a/src/video.c b/src/video.c
index 9c1ec56..6ccfb88 100644
--- a/src/video.c
+++ b/src/video.c
@@ -880,7 +880,8 @@ static int set_vidisp(struct vrx *vrx)
static int set_encoder_format(struct vtx *vtx, const char *src,
const char *dev, struct vidsz *size)
{
- struct vidsrc *vs = (struct vidsrc *)vidsrc_find(src);
+ struct vidsrc *vs = (struct vidsrc *)vidsrc_find(baresip_vidsrcl(),
+ src);
int err;
if (!vs)
@@ -955,7 +956,7 @@ int video_start(struct video *v, const char *peer)
info("video: no video display\n");
}
- if (vidsrc_find(NULL)) {
+ if (vidsrc_find(baresip_vidsrcl(), NULL)) {
size.w = v->cfg.width;
size.h = v->cfg.height;
err = set_encoder_format(&v->vtx, v->cfg.src_mod,
@@ -1310,7 +1311,8 @@ int video_print(struct re_printf *pf, const struct video *v)
int video_set_source(struct video *v, const char *name, const char *dev)
{
- struct vidsrc *vs = (struct vidsrc *)vidsrc_find(name);
+ struct vidsrc *vs = (struct vidsrc *)vidsrc_find(baresip_vidsrcl(),
+ name);
struct vtx *vtx;
if (!v)
diff --git a/src/vidsrc.c b/src/vidsrc.c
index e0bb297..2c8f9ff 100644
--- a/src/vidsrc.c
+++ b/src/vidsrc.c
@@ -15,9 +15,6 @@ struct vidsrc_st {
};
-static struct list vidsrcl = LIST_INIT;
-
-
static void destructor(void *arg)
{
struct vidsrc *vs = arg;
@@ -30,25 +27,27 @@ static void destructor(void *arg)
* Register a Video Source
*
* @param vsp Pointer to allocated Video Source
+ * @param vidsrcl List of Video Sources
* @param name Name of Video Source
* @param alloch Allocation handler
* @param updateh Update handler
*
* @return 0 if success, otherwise errorcode
*/
-int vidsrc_register(struct vidsrc **vsp, const char *name,
+int vidsrc_register(struct vidsrc **vsp, struct list *vidsrcl,
+ const char *name,
vidsrc_alloc_h *alloch, vidsrc_update_h *updateh)
{
struct vidsrc *vs;
- if (!vsp)
+ if (!vsp || !vidsrcl)
return EINVAL;
vs = mem_zalloc(sizeof(*vs), destructor);
if (!vs)
return ENOMEM;
- list_append(&vidsrcl, &vs->le, vs);
+ list_append(vidsrcl, &vs->le, vs);
vs->name = name;
vs->alloch = alloch;
@@ -65,15 +64,16 @@ int vidsrc_register(struct vidsrc **vsp, const char *name,
/**
* Find a Video Source by name
*
- * @param name Name of the Video Source to find
+ * @param vidsrcl List of Video Sources
+ * @param name Name of the Video Source to find
*
* @return Matching Video Source if found, otherwise NULL
*/
-const struct vidsrc *vidsrc_find(const char *name)
+const struct vidsrc *vidsrc_find(const struct list *vidsrcl, const char *name)
{
struct le *le;
- for (le=vidsrcl.head; le; le=le->next) {
+ for (le=list_head(vidsrcl); le; le=le->next) {
struct vidsrc *vs = le->data;
@@ -90,25 +90,27 @@ const struct vidsrc *vidsrc_find(const char *name)
/**
* Allocate a new video source state
*
- * @param stp Pointer to allocated state
- * @param name Name of the video source
- * @param ctx Optional media context
- * @param prm Video source parameters
- * @param size Wanted video size of the source
- * @param fmt Format parameter
- * @param dev Video device
- * @param frameh Video frame handler
- * @param errorh Error handler (optional)
- * @param arg Handler argument
+ * @param stp Pointer to allocated state
+ * @param vidsrcl List of Video Sources
+ * @param name Name of the video source
+ * @param ctx Optional media context
+ * @param prm Video source parameters
+ * @param size Wanted video size of the source
+ * @param fmt Format parameter
+ * @param dev Video device
+ * @param frameh Video frame handler
+ * @param errorh Error handler (optional)
+ * @param arg Handler argument
*
* @return 0 if success, otherwise errorcode
*/
-int vidsrc_alloc(struct vidsrc_st **stp, const char *name,
+int vidsrc_alloc(struct vidsrc_st **stp, struct list *vidsrcl,
+ const char *name,
struct media_ctx **ctx, struct vidsrc_prm *prm,
const struct vidsz *size, const char *fmt, const char *dev,
vidsrc_frame_h *frameh, vidsrc_error_h *errorh, void *arg)
{
- struct vidsrc *vs = (struct vidsrc *)vidsrc_find(name);
+ struct vidsrc *vs = (struct vidsrc *)vidsrc_find(vidsrcl, name);
if (!vs)
return ENOENT;
@@ -117,17 +119,6 @@ int vidsrc_alloc(struct vidsrc_st **stp, const char *name,
}
-/**
- * Get the list of Video Sources
- *
- * @return List of Video Sources
- */
-struct list *vidsrc_list(void)
-{
- return &vidsrcl;
-}
-
-
struct vidsrc *vidsrc_get(struct vidsrc_st *st)
{
return st ? st->vs : NULL;