Blob Blame History Raw
From 01804dcfaf77e298a3f7bdc3d4cfe0882bf681cd Mon Sep 17 00:00:00 2001
From: "Alfred E. Heggestad" <alfred.heggestad@gmail.com>
Date: Sat, 24 Apr 2021 11:41:22 +0200
Subject: [PATCH] cairo: remove deprecated module

the avformat module can be used for video test source:

    video_source    avformat,lavfi,testsrc2
---
 README.md               |   2 -
 docs/examples/config    |   1 -
 mk/modules.mk           |   1 -
 modules/cairo/cairo.c   | 347 ----------------------------------------
 modules/cairo/module.mk |  12 --
 src/config.c            |   1 -
 6 files changed, 364 deletions(-)
 delete mode 100644 modules/cairo/cairo.c
 delete mode 100644 modules/cairo/module.mk

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