summaryrefslogtreecommitdiff
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
parent91e3b2c11f617a126679b3d15239bdb0c1c72e4c (diff)
Vidsrc api reentrant (#256)
* vidsrc: make the API re-entrant * vidsrc: update all modules to new API
-rw-r--r--include/baresip.h9
-rw-r--r--modules/avcapture/avcapture.m3
-rw-r--r--modules/avformat/avformat.c3
-rw-r--r--modules/cairo/cairo.c3
-rw-r--r--modules/dshow/dshow.cpp3
-rw-r--r--modules/fakevideo/fakevideo.c3
-rw-r--r--modules/qtcapture/qtcapture.m3
-rw-r--r--modules/quicktime/quicktime.c3
-rw-r--r--modules/rst/video.c3
-rw-r--r--modules/v4l/v4l.c2
-rw-r--r--modules/v4l2/v4l2.c3
-rw-r--r--modules/v4l2_codec/v4l2_codec.c3
-rw-r--r--modules/vidbridge/vidbridge.c3
-rw-r--r--modules/vidloop/vidloop.c3
-rw-r--r--modules/x11grab/x11grab.c3
-rw-r--r--src/baresip.c8
-rw-r--r--src/call.c3
-rw-r--r--src/video.c8
-rw-r--r--src/vidsrc.c55
-rw-r--r--test/mock/mock_vidsrc.c2
20 files changed, 71 insertions, 55 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 4654415..8f10cb6 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -742,11 +742,11 @@ typedef int (vidsrc_alloc_h)(struct vidsrc_st **vsp, const struct vidsrc *vs,
typedef void (vidsrc_update_h)(struct vidsrc_st *st, struct vidsrc_prm *prm,
const char *dev);
-int vidsrc_register(struct vidsrc **vp, const char *name,
+int vidsrc_register(struct vidsrc **vp, struct list *vidsrcl, const char *name,
vidsrc_alloc_h *alloch, vidsrc_update_h *updateh);
-const struct vidsrc *vidsrc_find(const char *name);
-struct list *vidsrc_list(void);
-int vidsrc_alloc(struct vidsrc_st **stp, const char *name,
+const struct vidsrc *vidsrc_find(const struct list *vidsrcl, 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);
@@ -1142,6 +1142,7 @@ struct list *baresip_ausrcl(void);
struct list *baresip_auplayl(void);
struct list *baresip_aufiltl(void);
struct list *baresip_vidcodecl(void);
+struct list *baresip_vidsrcl(void);
#ifdef __cplusplus
diff --git a/modules/avcapture/avcapture.m b/modules/avcapture/avcapture.m
index e037246..f276c96 100644
--- a/modules/avcapture/avcapture.m
+++ b/modules/avcapture/avcapture.m
@@ -373,7 +373,8 @@ static int module_init(void)
debug("avcapture: found video device '%s'\n", name);
}
- err = vidsrc_register(&vidsrc, "avcapture", alloc, update);
+ err = vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "avcapture", alloc, update);
[pool drain];
diff --git a/modules/avformat/avformat.c b/modules/avformat/avformat.c
index 66bc9f1..c0338a2 100644
--- a/modules/avformat/avformat.c
+++ b/modules/avformat/avformat.c
@@ -413,7 +413,8 @@ static int module_init(void)
av_register_all();
- return vidsrc_register(&mod_avf, "avformat", alloc, NULL);
+ return vidsrc_register(&mod_avf, baresip_vidsrcl(),
+ "avformat", alloc, NULL);
}
diff --git a/modules/cairo/cairo.c b/modules/cairo/cairo.c
index 9ebb571..9f1b573 100644
--- a/modules/cairo/cairo.c
+++ b/modules/cairo/cairo.c
@@ -250,7 +250,8 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
static int module_init(void)
{
- return vidsrc_register(&vidsrc, "cairo", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "cairo", alloc, NULL);
}
diff --git a/modules/dshow/dshow.cpp b/modules/dshow/dshow.cpp
index df84ee9..d081f69 100644
--- a/modules/dshow/dshow.cpp
+++ b/modules/dshow/dshow.cpp
@@ -514,7 +514,8 @@ static int module_init(void)
if (CoInitialize(NULL) != S_OK)
return ENODATA;
- return vidsrc_register(&vsrc, "dshow", alloc, NULL);
+ return vidsrc_register(&vsrc, baresip_vidsrcl(),
+ "dshow", alloc, NULL);
}
diff --git a/modules/fakevideo/fakevideo.c b/modules/fakevideo/fakevideo.c
index c750814..4fbc9ea 100644
--- a/modules/fakevideo/fakevideo.c
+++ b/modules/fakevideo/fakevideo.c
@@ -174,7 +174,8 @@ static int display(struct vidisp_st *st, const char *title,
static int module_init(void)
{
int err = 0;
- err |= vidsrc_register(&vidsrc, "fakevideo", src_alloc, NULL);
+ err |= vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "fakevideo", src_alloc, NULL);
err |= vidisp_register(&vidisp, "fakevideo", disp_alloc, NULL,
display, NULL);
return err;
diff --git a/modules/qtcapture/qtcapture.m b/modules/qtcapture/qtcapture.m
index 08f66ab..e4fddc2 100644
--- a/modules/qtcapture/qtcapture.m
+++ b/modules/qtcapture/qtcapture.m
@@ -381,7 +381,8 @@ static void device_info(void)
static int module_init(void)
{
device_info();
- return vidsrc_register(&vidsrc, "qtcapture", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "qtcapture", alloc, NULL);
}
diff --git a/modules/quicktime/quicktime.c b/modules/quicktime/quicktime.c
index 504338c..3811add 100644
--- a/modules/quicktime/quicktime.c
+++ b/modules/quicktime/quicktime.c
@@ -303,7 +303,8 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
static int qt_init(void)
{
- return vidsrc_register(&vidsrc, "quicktime", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "quicktime", alloc, NULL);
}
diff --git a/modules/rst/video.c b/modules/rst/video.c
index b252504..bf59daf 100644
--- a/modules/rst/video.c
+++ b/modules/rst/video.c
@@ -269,7 +269,8 @@ static int alloc_handler(struct vidsrc_st **stp, const struct vidsrc *vs,
int rst_video_init(void)
{
- return vidsrc_register(&vidsrc, "rst", alloc_handler, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "rst", alloc_handler, NULL);
}
diff --git a/modules/v4l/v4l.c b/modules/v4l/v4l.c
index 46d4ca7..25b7640 100644
--- a/modules/v4l/v4l.c
+++ b/modules/v4l/v4l.c
@@ -245,7 +245,7 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
static int v4l_init(void)
{
- return vidsrc_register(&vidsrc, "v4l", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(), "v4l", alloc, NULL);
}
diff --git a/modules/v4l2/v4l2.c b/modules/v4l2/v4l2.c
index 5f7244a..e079fed 100644
--- a/modules/v4l2/v4l2.c
+++ b/modules/v4l2/v4l2.c
@@ -491,7 +491,8 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
static int v4l_init(void)
{
- return vidsrc_register(&vidsrc, "v4l2", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "v4l2", alloc, NULL);
}
diff --git a/modules/v4l2_codec/v4l2_codec.c b/modules/v4l2_codec/v4l2_codec.c
index bf77029..5570c09 100644
--- a/modules/v4l2_codec/v4l2_codec.c
+++ b/modules/v4l2_codec/v4l2_codec.c
@@ -563,7 +563,8 @@ static int module_init(void)
info("v4l2_codec inited\n");
vidcodec_register(baresip_vidcodecl(), &h264);
- return vidsrc_register(&vidsrc, "v4l2_codec", src_alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "v4l2_codec", src_alloc, NULL);
}
diff --git a/modules/vidbridge/vidbridge.c b/modules/vidbridge/vidbridge.c
index 495264e..95d0a4e 100644
--- a/modules/vidbridge/vidbridge.c
+++ b/modules/vidbridge/vidbridge.c
@@ -48,7 +48,8 @@ static int module_init(void)
if (err)
return err;
- err = vidsrc_register(&vidsrc, "vidbridge", vidbridge_src_alloc, NULL);
+ err = vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "vidbridge", vidbridge_src_alloc, NULL);
if (err)
return err;
diff --git a/modules/vidloop/vidloop.c b/modules/vidloop/vidloop.c
index 69dbb56..090c440 100644
--- a/modules/vidloop/vidloop.c
+++ b/modules/vidloop/vidloop.c
@@ -342,7 +342,8 @@ static int vsrc_reopen(struct video_loop *vl, const struct vidsz *sz)
prm.fps = vl->cfg.fps;
vl->vsrc = mem_deref(vl->vsrc);
- err = vidsrc_alloc(&vl->vsrc, vl->cfg.src_mod, NULL, &prm, sz,
+ err = vidsrc_alloc(&vl->vsrc, baresip_vidsrcl(),
+ vl->cfg.src_mod, NULL, &prm, sz,
NULL, vl->cfg.src_dev, vidsrc_frame_handler,
NULL, vl);
if (err) {
diff --git a/modules/x11grab/x11grab.c b/modules/x11grab/x11grab.c
index ecbcba5..d3aa287 100644
--- a/modules/x11grab/x11grab.c
+++ b/modules/x11grab/x11grab.c
@@ -203,7 +203,8 @@ static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
static int x11grab_init(void)
{
- return vidsrc_register(&vidsrc, "x11grab", alloc, NULL);
+ return vidsrc_register(&vidsrc, baresip_vidsrcl(),
+ "x11grab", alloc, NULL);
}
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;
diff --git a/test/mock/mock_vidsrc.c b/test/mock/mock_vidsrc.c
index 526ab16..8f92bc4 100644
--- a/test/mock/mock_vidsrc.c
+++ b/test/mock/mock_vidsrc.c
@@ -86,6 +86,6 @@ static int mock_vidsrc_alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
int mock_vidsrc_register(struct vidsrc **vidsrcp)
{
- return vidsrc_register(vidsrcp, "mock-vidsrc",
+ return vidsrc_register(vidsrcp, baresip_vidsrcl(), "mock-vidsrc",
mock_vidsrc_alloc, NULL);
}