summaryrefslogtreecommitdiff
path: root/src/vidsrc.c
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/vidsrc.c
parent91e3b2c11f617a126679b3d15239bdb0c1c72e4c (diff)
Vidsrc api reentrant (#256)
* vidsrc: make the API re-entrant * vidsrc: update all modules to new API
Diffstat (limited to 'src/vidsrc.c')
-rw-r--r--src/vidsrc.c55
1 files changed, 23 insertions, 32 deletions
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;