9e2a230
From 01804dcfaf77e298a3f7bdc3d4cfe0882bf681cd Mon Sep 17 00:00:00 2001
9e2a230
From: "Alfred E. Heggestad" <alfred.heggestad@gmail.com>
9e2a230
Date: Sat, 24 Apr 2021 11:41:22 +0200
9e2a230
Subject: [PATCH] cairo: remove deprecated module
9e2a230
9e2a230
the avformat module can be used for video test source:
9e2a230
9e2a230
    video_source    avformat,lavfi,testsrc2
9e2a230
---
9e2a230
 README.md               |   2 -
9e2a230
 docs/examples/config    |   1 -
9e2a230
 mk/modules.mk           |   1 -
9e2a230
 modules/cairo/cairo.c   | 347 ----------------------------------------
9e2a230
 modules/cairo/module.mk |  12 --
9e2a230
 src/config.c            |   1 -
9e2a230
 6 files changed, 364 deletions(-)
9e2a230
 delete mode 100644 modules/cairo/cairo.c
9e2a230
 delete mode 100644 modules/cairo/module.mk
9e2a230
9e2a230
diff --git a/README.md b/README.md
9e2a230
index 1ad82c9bd..d87a76564 100644
9e2a230
--- a/README.md
9e2a230
+++ b/README.md
9e2a230
@@ -110,7 +110,6 @@ Distributed under BSD license
9e2a230
 * Video-drivers:
9e2a230
   - iOS avcapture video-source
9e2a230
   - FFmpeg/libav libavformat/avdevice input
9e2a230
-  - Cairo video-source test module
9e2a230
   - Direct Show video-source
9e2a230
   - MacOSX AVCapture video-source
9e2a230
   - RST media player
9e2a230
@@ -229,7 +228,6 @@ avcapture     Video source using iOS AVFoundation video capture
9e2a230
 avcodec       Video codec using FFmpeg/libav libavcodec
9e2a230
 avformat      Video source using FFmpeg/libav libavformat
9e2a230
 b2bua         Back-to-Back User-Agent (B2BUA) module
9e2a230
-cairo         Cairo video source
9e2a230
 codec2        Codec2 low bit rate speech codec
9e2a230
 cons          UDP/TCP console UI driver
9e2a230
 contact       Contacts module
9e2a230
diff --git a/docs/examples/config b/docs/examples/config
9e2a230
index e0921b0fb..5e7a29b9a 100644
9e2a230
--- a/docs/examples/config
9e2a230
+++ b/docs/examples/config
9e2a230
@@ -122,7 +122,6 @@ module			alsa.so
9e2a230
 #module			v4l2.so
9e2a230
 #module			v4l2_codec.so
9e2a230
 #module			x11grab.so
9e2a230
-#module			cairo.so
9e2a230
 #module			vidbridge.so
9e2a230
 
9e2a230
 # Video display modules
9e2a230
diff --git a/mk/modules.mk b/mk/modules.mk
9e2a230
index ce7fd1313..d4e53a337 100644
9e2a230
--- a/mk/modules.mk
9e2a230
+++ b/mk/modules.mk
9e2a230
@@ -333,7 +333,6 @@ ifneq ($(USE_AVFILTER),)
9e2a230
 MODULES   += avfilter
9e2a230
 endif
9e2a230
 ifneq ($(USE_CAIRO),)
9e2a230
-MODULES   += cairo
9e2a230
 ifneq ($(USE_MPG123),)
9e2a230
 MODULES   += rst
9e2a230
 endif
9e2a230
diff --git a/modules/cairo/cairo.c b/modules/cairo/cairo.c
9e2a230
deleted file mode 100644
9e2a230
index 85cef8031..000000000
9e2a230
--- a/modules/cairo/cairo.c
9e2a230
+++ /dev/null
9e2a230
@@ -1,347 +0,0 @@
9e2a230
-/**
9e2a230
- * @file cairo.c  Cairo module
9e2a230
- *
9e2a230
- * Copyright (C) 2010 Alfred E. Heggestad
9e2a230
- */
9e2a230
-#define _DEFAULT_SOURCE 1
9e2a230
-#define _BSD_SOURCE 1
9e2a230
-#include <unistd.h>
9e2a230
-#include <pthread.h>
9e2a230
-#include <math.h>
9e2a230
-#include <re.h>
9e2a230
-#include <rem.h>
9e2a230
-#include <baresip.h>
9e2a230
-#include <cairo/cairo.h>
9e2a230
-
9e2a230
-
9e2a230
-#if !defined (M_PI)
9e2a230
-#define M_PI 3.14159265358979323846264338327
9e2a230
-#endif
9e2a230
-
9e2a230
-
9e2a230
-/**
9e2a230
- * @defgroup cairo cairo
9e2a230
- *
9e2a230
- * Cairo video-source module is a video generator for testing
9e2a230
- * and demo purposes.
9e2a230
- *
9e2a230
- * Note: This module is very experimental!
9e2a230
- *
9e2a230
- * Use Cairo library to draw graphics into a frame buffer
9e2a230
- */
9e2a230
-
9e2a230
-
9e2a230
-enum {
9e2a230
-	FONT_SIZE = 18
9e2a230
-};
9e2a230
-
9e2a230
-struct vidsrc_st {
9e2a230
-	struct vidsrc_prm prm;
9e2a230
-	struct vidsz size;
9e2a230
-	cairo_surface_t *surface;
9e2a230
-	cairo_t *cr;
9e2a230
-	cairo_surface_t *surface_logo;
9e2a230
-	cairo_t *cr_logo;
9e2a230
-	double logo_width;
9e2a230
-	double logo_height;
9e2a230
-	double step;
9e2a230
-	bool run;
9e2a230
-	pthread_t thread;
9e2a230
-	vidsrc_frame_h *frameh;
9e2a230
-	void *arg;
9e2a230
-};
9e2a230
-
9e2a230
-
9e2a230
-static struct vidsrc *vidsrc;
9e2a230
-
9e2a230
-
9e2a230
-static void destructor(void *arg)
9e2a230
-{
9e2a230
-	struct vidsrc_st *st = arg;
9e2a230
-
9e2a230
-	if (st->run) {
9e2a230
-		st->run = false;
9e2a230
-		pthread_join(st->thread, NULL);
9e2a230
-	}
9e2a230
-
9e2a230
-	if (st->cr)
9e2a230
-		cairo_destroy(st->cr);
9e2a230
-	if (st->surface)
9e2a230
-		cairo_surface_destroy(st->surface);
9e2a230
-
9e2a230
-	if (st->cr_logo)
9e2a230
-		cairo_destroy(st->cr_logo);
9e2a230
-	if (st->surface_logo)
9e2a230
-		cairo_surface_destroy(st->surface_logo);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static void draw_background(cairo_t *cr, double color_step,
9e2a230
-			    int width, int height)
9e2a230
-{
9e2a230
-	cairo_pattern_t *pat;
9e2a230
-	double grey, r, g, b;
9e2a230
-
9e2a230
-	grey = 0.1 + fabs(sin(3 * color_step));
9e2a230
-	r = grey;
9e2a230
-	g = grey;
9e2a230
-	b = grey;
9e2a230
-
9e2a230
-	pat = cairo_pattern_create_linear (0.0, 0.0,  0.0, height);
9e2a230
-	cairo_pattern_add_color_stop_rgba (pat, 1, r, g, b, 1);
9e2a230
-	cairo_pattern_add_color_stop_rgba (pat, 0, 0, 0, 0, 1);
9e2a230
-	cairo_rectangle (cr, 0, 0, width, height);
9e2a230
-	cairo_set_source (cr, pat);
9e2a230
-	cairo_fill (cr);
9e2a230
-	cairo_pattern_destroy (pat);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static void draw_text(struct vidsrc_st *st, int x, int y,
9e2a230
-		      const char *fmt, ...)
9e2a230
-{
9e2a230
-	char buf[4096] = "";
9e2a230
-	va_list ap;
9e2a230
-
9e2a230
-	va_start(ap, fmt);
9e2a230
-	(void)re_vsnprintf(buf, sizeof(buf), fmt, ap);
9e2a230
-	va_end(ap);
9e2a230
-
9e2a230
-	cairo_set_source_rgb(st->cr, 1.0, 1.0, 1.0);  /* white */
9e2a230
-
9e2a230
-	cairo_set_font_size(st->cr, FONT_SIZE);
9e2a230
-	cairo_move_to(st->cr, x, y);
9e2a230
-	cairo_show_text(st->cr, buf);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static void draw_logo(struct vidsrc_st *st)
9e2a230
-{
9e2a230
-	double x, y;
9e2a230
-
9e2a230
-	x = (st->size.w - st->logo_width) * (sin(10 * st->step) + 1)/2;
9e2a230
-	y = (st->size.h - st->logo_height)* (1 - fabs(sin(30 * st->step)));
9e2a230
-
9e2a230
-	cairo_set_source_surface(st->cr, st->surface_logo, x, y);
9e2a230
-	cairo_paint(st->cr);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static void process(struct vidsrc_st *st, uint64_t timestamp)
9e2a230
-{
9e2a230
-	struct vidframe f;
9e2a230
-	unsigned xoffs = 2, yoffs = 24;
9e2a230
-
9e2a230
-	draw_background(st->cr, st->step, st->size.w, st->size.h);
9e2a230
-
9e2a230
-	draw_text(st, xoffs, yoffs + FONT_SIZE, "%H", fmt_gmtime, NULL);
9e2a230
-
9e2a230
-	draw_text(st, xoffs, yoffs + FONT_SIZE*2, "%u x %u @ %.2f fps",
9e2a230
-		  st->size.w, st->size.h, st->prm.fps);
9e2a230
-
9e2a230
-	draw_text(st, xoffs, yoffs + FONT_SIZE*3, "Time: %.3f sec",
9e2a230
-		  timestamp / (double)VIDEO_TIMEBASE);
9e2a230
-
9e2a230
-	draw_logo(st);
9e2a230
-
9e2a230
-	st->step += 0.02 / st->prm.fps;
9e2a230
-
9e2a230
-	vidframe_init_buf(&f, VID_FMT_RGB32, &st->size,
9e2a230
-			  cairo_image_surface_get_data(st->surface));
9e2a230
-
9e2a230
-	st->frameh(&f, timestamp, st->arg);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static void *read_thread(void *arg)
9e2a230
-{
9e2a230
-	struct vidsrc_st *st = arg;
9e2a230
-	uint64_t ts = 0, ts_start = 0;
9e2a230
-
9e2a230
-	while (st->run) {
9e2a230
-
9e2a230
-		uint64_t now;
9e2a230
-		uint64_t timestamp;
9e2a230
-
9e2a230
-		sys_msleep(2);
9e2a230
-
9e2a230
-		now = tmr_jiffies();
9e2a230
-		if (!ts) {
9e2a230
-			ts = ts_start = now;
9e2a230
-		}
9e2a230
-
9e2a230
-		if (ts > now)
9e2a230
-			continue;
9e2a230
-
9e2a230
-		timestamp = (ts - ts_start) * VIDEO_TIMEBASE / 1000;
9e2a230
-
9e2a230
-		process(st, timestamp);
9e2a230
-
9e2a230
-		ts += 1000/st->prm.fps;
9e2a230
-	}
9e2a230
-
9e2a230
-	return NULL;
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static int load_logo(struct vidsrc_st *st, const char *filename)
9e2a230
-{
9e2a230
-	cairo_surface_t *logo;
9e2a230
-	double lw;
9e2a230
-	double scale;
9e2a230
-	int err = 0;
9e2a230
-
9e2a230
-	logo = cairo_image_surface_create_from_png(filename);
9e2a230
-	if (!logo) {
9e2a230
-		warning("cairo: failed to load PNG logo\n");
9e2a230
-		err = ENOENT;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	if (!cairo_image_surface_get_width(logo) ||
9e2a230
-	    !cairo_image_surface_get_height(logo)) {
9e2a230
-		warning("cairo: invalid logo (%s)\n", filename);
9e2a230
-		err = ENOENT;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	st->logo_width = st->size.w / 2;
9e2a230
-	lw = cairo_image_surface_get_width(logo);
9e2a230
-	scale = (double)st->logo_width / (double)lw;
9e2a230
-
9e2a230
-	st->logo_height = cairo_image_surface_get_height(logo) * scale;
9e2a230
-
9e2a230
-	/* create a scaled-down logo with same aspect ratio */
9e2a230
-
9e2a230
-	st->surface_logo = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
9e2a230
-						      st->logo_width,
9e2a230
-						      st->logo_height);
9e2a230
-	if (!st->surface_logo) {
9e2a230
-		err = ENOMEM;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	st->cr_logo = cairo_create(st->surface_logo);
9e2a230
-	if (!st->cr_logo) {
9e2a230
-		err = ENOMEM;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	cairo_scale(st->cr_logo, scale, scale);
9e2a230
-
9e2a230
-	cairo_set_source_surface(st->cr_logo, logo, 0, 0);
9e2a230
-	cairo_paint(st->cr_logo);
9e2a230
-
9e2a230
-	info("cairo: scaling logo '%s' from %d x %d to %.1f x %.1f\n",
9e2a230
-	     filename,
9e2a230
-	     cairo_image_surface_get_width(logo),
9e2a230
-	     cairo_image_surface_get_height(logo),
9e2a230
-	     st->logo_width,
9e2a230
-	     st->logo_height);
9e2a230
-
9e2a230
- out:
9e2a230
-	if (logo)
9e2a230
-		cairo_surface_destroy(logo);
9e2a230
-	return err;
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static int alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
9e2a230
-		 struct media_ctx **ctx, struct vidsrc_prm *prm,
9e2a230
-		 const struct vidsz *size, const char *fmt,
9e2a230
-		 const char *dev, vidsrc_frame_h *frameh,
9e2a230
-		 vidsrc_error_h *errorh, void *arg)
9e2a230
-{
9e2a230
-	struct config *cfg;
9e2a230
-	struct vidsrc_st *st;
9e2a230
-	char logo[256];
9e2a230
-	int err = 0;
9e2a230
-
9e2a230
-	(void)ctx;
9e2a230
-	(void)fmt;
9e2a230
-	(void)dev;
9e2a230
-	(void)errorh;
9e2a230
-	(void)vs;
9e2a230
-
9e2a230
-	if (!stp || !prm || !size || !frameh)
9e2a230
-		return EINVAL;
9e2a230
-
9e2a230
-	cfg = conf_config();
9e2a230
-	if (!cfg)
9e2a230
-		return EINVAL;
9e2a230
-
9e2a230
-	st = mem_zalloc(sizeof(*st), destructor);
9e2a230
-	if (!st)
9e2a230
-		return ENOMEM;
9e2a230
-
9e2a230
-	st->frameh = frameh;
9e2a230
-	st->arg    = arg;
9e2a230
-	st->prm    = *prm;
9e2a230
-	st->size   = *size;
9e2a230
-
9e2a230
-	st->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
9e2a230
-						 size->w, size->h);
9e2a230
-	if (!st->surface) {
9e2a230
-		err = ENOMEM;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	st->cr = cairo_create(st->surface);
9e2a230
-	if (!st->cr) {
9e2a230
-		err = ENOMEM;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
-	cairo_select_font_face(st->cr, "Sans",
9e2a230
-				CAIRO_FONT_SLANT_NORMAL,
9e2a230
-				CAIRO_FONT_WEIGHT_BOLD);
9e2a230
-
9e2a230
-	info("cairo: surface with resolution %d x %d\n",
9e2a230
-	     cairo_image_surface_get_width(st->surface),
9e2a230
-	     cairo_image_surface_get_height(st->surface));
9e2a230
-
9e2a230
-	st->step = rand_u16() / 1000.0;
9e2a230
-
9e2a230
-	re_snprintf(logo, sizeof(logo), "%s/logo.png", cfg->audio.audio_path);
9e2a230
-
9e2a230
-	err = load_logo(st, logo);
9e2a230
-	if (err)
9e2a230
-		goto out;
9e2a230
-
9e2a230
-	st->run = true;
9e2a230
-	err = pthread_create(&st->thread, NULL, read_thread, st);
9e2a230
-	if (err) {
9e2a230
-		st->run = false;
9e2a230
-		goto out;
9e2a230
-	}
9e2a230
-
9e2a230
- out:
9e2a230
-	if (err)
9e2a230
-		mem_deref(st);
9e2a230
-	else
9e2a230
-		*stp = st;
9e2a230
-
9e2a230
-	return err;
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static int module_init(void)
9e2a230
-{
9e2a230
-	return vidsrc_register(&vidsrc, baresip_vidsrcl(),
9e2a230
-			       "cairo", alloc, NULL);
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-static int module_close(void)
9e2a230
-{
9e2a230
-	vidsrc = mem_deref(vidsrc);
9e2a230
-	return 0;
9e2a230
-}
9e2a230
-
9e2a230
-
9e2a230
-EXPORT_SYM const struct mod_export DECL_EXPORTS(cairo) = {
9e2a230
-	"cairo",
9e2a230
-	"vidsrc",
9e2a230
-	module_init,
9e2a230
-	module_close
9e2a230
-};
9e2a230
diff --git a/modules/cairo/module.mk b/modules/cairo/module.mk
9e2a230
deleted file mode 100644
9e2a230
index 01e3dc7cc..000000000
9e2a230
--- a/modules/cairo/module.mk
9e2a230
+++ /dev/null
9e2a230
@@ -1,12 +0,0 @@
9e2a230
-#
9e2a230
-# module.mk
9e2a230
-#
9e2a230
-# Copyright (C) 2010 Alfred E. Heggestad
9e2a230
-#
9e2a230
-
9e2a230
-MOD		:= cairo
9e2a230
-$(MOD)_SRCS	+= cairo.c
9e2a230
-$(MOD)_LFLAGS	+= $(shell pkg-config --libs cairo)
9e2a230
-$(MOD)_CFLAGS	+= $(shell pkg-config --cflags cairo)
9e2a230
-
9e2a230
-include mk/mod.mk
9e2a230
diff --git a/src/config.c b/src/config.c
9e2a230
index f12dc5a31..483d374c1 100644
9e2a230
--- a/src/config.c
9e2a230
+++ b/src/config.c
9e2a230
@@ -911,7 +911,6 @@ int config_write_template(const char *file, const struct config *cfg)
9e2a230
 	(void)re_fprintf(f, "#module\t\t\t" "v4l2_codec" MOD_EXT "\n");
9e2a230
 #endif
9e2a230
 	(void)re_fprintf(f, "#module\t\t\t" "x11grab" MOD_EXT "\n");
9e2a230
-	(void)re_fprintf(f, "#module\t\t\t" "cairo" MOD_EXT "\n");
9e2a230
 	(void)re_fprintf(f, "#module\t\t\t" "vidbridge" MOD_EXT "\n");
9e2a230
 
9e2a230
 	(void)re_fprintf(f, "\n# Video display modules\n");