File: mock_vidisp.c

package info (click to toggle)
baresip 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,328 kB
  • sloc: ansic: 53,606; cpp: 2,268; makefile: 332; objc: 320; python: 259; sh: 40; xml: 19
file content (106 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download
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
96
97
98
99
100
101
102
103
104
105
106
/**
 * @file mock/mock_vidisp.c Mock video display
 *
 * Copyright (C) 2010 - 2016 Alfred E. Heggestad
 */
#include <re.h>
#include <rem.h>
#include <baresip.h>
#include "../test.h"


#define MAX_WIDTH 65536
#define MAX_HEIGHT 65536


struct vidisp_st {
	unsigned n_frame;
};


static struct {
	mock_vidisp_h *disph;
	void *arg;
} mock;


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


static int mock_disp_alloc(struct vidisp_st **stp, const struct vidisp *vd,
		      struct vidisp_prm *prm, const char *dev,
		      vidisp_resize_h *resizeh, void *arg)
{
	struct vidisp_st *st;
	(void)prm;
	(void)dev;
	(void)resizeh;
	(void)arg;

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

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

	*stp = st;

	return 0;
}


static int mock_display(struct vidisp_st *st, const char *title,
			const struct vidframe *frame, uint64_t timestamp)
{
	unsigned width, height;
	(void)title;
	(void)timestamp;

	if (!st || !frame)
		return EINVAL;

	width = frame->size.w;
	height = frame->size.h;

	if (!vidframe_isvalid(frame)) {
		warning("mock_vidisp: got invalid frame\n");
		return EPROTO;
	}

	/* verify that the video frame is good */
	if (frame->fmt >= VID_FMT_N)
		return EPROTO;
	if (width == 0 || width > MAX_WIDTH)
		return EPROTO;
	if (height == 0 || height > MAX_HEIGHT)
		return EPROTO;
	if (frame->linesize[0] == 0)
		return EPROTO;

	++st->n_frame;

	if (st->n_frame >= 10) {
		info("mock_vidisp: got %u frames\n", st->n_frame);

		if (mock.disph)
			mock.disph(frame, timestamp, mock.arg);
	}

	return 0;
}


int mock_vidisp_register(struct vidisp **vidispp,
			 mock_vidisp_h *disph, void *arg)
{
	mock.disph = disph;
	mock.arg = arg;

	return vidisp_register(vidispp, baresip_vidispl(), "mock-vidisp",
			       mock_disp_alloc, NULL, mock_display, NULL);
}