summaryrefslogtreecommitdiff
path: root/modules/vidbridge/disp.c
blob: bce9cff405fd3935cebc60e9b7640783a281b0a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * @file vidbridge/disp.c Video bridge -- display
 *
 * Copyright (C) 2010 Creytiv.com
 */
#include <re.h>
#include <rem.h>
#include <baresip.h>
#include "vidbridge.h"


static void destructor(void *arg)
{
	struct vidisp_st *st = arg;

	if (st->vidsrc)
		st->vidsrc->vidisp = NULL;

	list_unlink(&st->le);
	mem_deref(st->device);
	mem_deref(st->vd);
}


int vidbridge_disp_alloc(struct vidisp_st **stp, struct vidisp *vd,
			 struct vidisp_prm *prm, const char *dev,
			 vidisp_resize_h *resizeh, void *arg)
{
	struct vidisp_st *st;
	int err = 0;
	(void)prm;
	(void)resizeh;
	(void)arg;

	if (!stp || !vd || !dev)
		return EINVAL;

	st = mem_zalloc(sizeof(*st), destructor);
	if (!st)
		return ENOMEM;

	st->vd = mem_ref(vd);

	err = str_dup(&st->device, dev);
	if (err)
		goto out;

	/* find the vidsrc with the same device-name */
	st->vidsrc = vidbridge_src_find(dev);
	if (st->vidsrc) {
		st->vidsrc->vidisp = st;
	}

	hash_append(ht_disp, hash_joaat_str(dev), &st->le, st);

 out:
	if (err)
		mem_deref(st);
	else
		*stp = st;

	return err;
}


static bool list_apply_handler(struct le *le, void *arg)
{
	struct vidisp_st *st = le->data;

	return 0 == str_cmp(st->device, arg);
}


int vidbridge_disp_display(struct vidisp_st *st, const char *title,
			   const struct vidframe *frame)
{
	int err = 0;
	(void)title;

	if (st->vidsrc)
		vidbridge_src_input(st->vidsrc, frame);
	else {
		debug("vidbridge: display: dropping frame (%u x %u)\n",
		      frame->size.w, frame->size.h);
	}

	return err;
}


struct vidisp_st *vidbridge_disp_find(const char *device)
{
	return list_ledata(hash_lookup(ht_disp, hash_joaat_str(device),
				       list_apply_handler, (void *)device));
}