Draw text on a Wayland surface in C

Viewed 961

I am a newbie in Wayland programming. Currently, I wanna create an application which can show FPS of a playing video on a surface of a Wayland client. enter image description here

First, I use Gstreamer to read fps. I already executed 2 ways to get FPS:

[ 1 ] using timer

static char prv_time_str[25] = {0,};
static volatile int fps_counter = 0;
static char str_fps[10] = "";
static time_t timer;
static char time_str[25];
static struct tm* tm_info;
static int ignored_first = 0;
static GstElement *overlay;

static GstPadProbeReturn
cb_have_data (GstPad          *pad,
              GstPadProbeInfo *info,
              gpointer         user_data)
{
    time(&timer);
    tm_info = localtime(&timer);
    strftime(time_str, 25, "%Y:%m:%d%H:%M:%S\n", tm_info);

    fps_counter++;
    if (!strlen(prv_time_str))
        strcpy(prv_time_str, time_str);
    if (strcmp(prv_time_str, time_str)) {
        if (ignored_first) {
            sprintf(str_fps, "FPS: %d", fps_counter);
            g_object_set (G_OBJECT (overlay), "text", str_fps, NULL);
            g_print("fps: %d\n", fps_counter);
        }
        ignored_first = 1;
        fps_counter = 0;
    }
    strcpy(prv_time_str, time_str);

    return GST_PAD_PROBE_OK;
}
 ...
overlay = gst_element_factory_make ("textoverlay", "overlay");
g_object_set (G_OBJECT (overlay), "font-desc", "Sans, 72", NULL);
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback)cb_have_data, NULL, NULL);

I used a callback function to calculate FPS and tried to display on the playing video with textoverlay element, but it failed.

and

[ 2 ] using fpsdisplaysink.

fpssink = gst_element_factory_make ("fpsdisplaysink", "fpsdisplay");
  ...
g_object_set (G_OBJECT (fpssink), "text-overlay", TRUE, "video-sink", sink, NULL);
  ...
g_object_get (G_OBJECT (fpssink), "last-message", &fps_msg, NULL);
delay_show_FPS++;
if (fps_msg != NULL) {
  if ((delay_show_FPS % DELAY_VALUE) == 0) {
    g_print ("Frame info: %s\n", fps_msg);
    delay_show_FPS = 0;
  }
}

I set property of fpsdisplaysink ("text-overlay" is TRUE), but it still failed. FPS value doesn't display at all.

Second, I try to create a wayland client (run on weston background) to display the FPS on the screen (as above picture - just demonstration). But I don't know method to do that. According to my investigation on Internet, I may be use cairo lib to draw a text via function (cairo_show_text, cairo_show_glyphs).

Anyone can help me out ? Thanks.

0 Answers
Related