1 /* GStreamer
2 * Copyright (C) <2017> Philippe Renon <philippe_renon@yahoo.fr>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "cameraevent.hpp"
21
22 #include <opencv2/opencv.hpp>
23
24 /**
25 * gst_camera_event_new_calibrated:
26 * @settings: .
27 *
28 * Creates a new calibrated event.
29 *
30 * To parse an event created by gst_camera_event_new_calibrated() use
31 * gst_camera_event_parse_calibrated().
32 *
33 * Returns: The new GstEvent
34 */
35 GstEvent *
gst_camera_event_new_calibrated(gchar * settings)36 gst_camera_event_new_calibrated (gchar * settings)
37 {
38 GstEvent *calibrated_event;
39 GstStructure *s;
40
41 s = gst_structure_new (GST_CAMERA_EVENT_CALIBRATED_NAME,
42 "undistort-settings", G_TYPE_STRING, g_strdup (settings), NULL);
43
44 calibrated_event = gst_event_new_custom (GST_EVENT_CUSTOM_BOTH, s);
45
46 return calibrated_event;
47 }
48
49 /**
50 * gst_camera_event_parse_calibrated:
51 * @event: A #GstEvent to parse
52 * @in_still: A boolean to receive the still-frame status from the event, or NULL
53 *
54 * Parse a #GstEvent, identify if it is a calibrated event, and
55 * return the s.
56 *
57 * Create a calibrated event using gst_camera_event_new_calibrated()
58 *
59 * Returns: %TRUE if the event is a valid calibrated event. %FALSE if not
60 */
61 gboolean
gst_camera_event_parse_calibrated(GstEvent * event,gchar ** settings)62 gst_camera_event_parse_calibrated (GstEvent * event, gchar ** settings)
63 {
64 const GstStructure *s;
65
66 g_return_val_if_fail (event != NULL, FALSE);
67
68 if (GST_EVENT_TYPE (event) != GST_EVENT_CUSTOM_BOTH)
69 return FALSE; /* Not a calibrated event */
70
71 s = gst_event_get_structure (event);
72 if (s == NULL
73 || !gst_structure_has_name (s, GST_CAMERA_EVENT_CALIBRATED_NAME))
74 return FALSE; /* Not a calibrated event */
75
76 const gchar *str = gst_structure_get_string (s, "undistort-settings");
77 if (!str)
78 return FALSE; /* Not calibrated frame event */
79
80 *settings = g_strdup (str);
81
82 return TRUE;
83 }
84