blob: 961be220bd959f669bf44e9cd0666229501883c3 [file] [log] [blame]
xuesong.jiangae1548e2022-05-06 16:38:46 +08001/* GStreamer
2 * Copyright (C) 2022 <xuesong.jiang@amlogic.com>
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 Street, Suite 500,
17 * Boston, MA 02110-1335, USA.
18 */
19
20#ifndef __AML_V4L2_UTILS_H__
21#define __AML_V4L2_UTILS_H__
22
23#include <gst/gst.h>
24
25G_BEGIN_DECLS
26
27#define GST_AML_V4L2_ERROR_INIT \
28 { \
29 NULL, NULL \
30 }
31#define GST_AML_V4L2_ERROR(v4l2err, domain, code, msg, dbg) \
32 { \
33 if (v4l2err) \
34 { \
35 gchar *_msg = _gst_element_error_printf msg; \
36 v4l2err->error = g_error_new_literal(GST_##domain##_ERROR, \
37 GST_##domain##_ERROR_##code, _msg); \
38 g_free(_msg); \
39 v4l2err->dbg_message = _gst_element_error_printf dbg; \
40 v4l2err->file = __FILE__; \
41 v4l2err->func = GST_FUNCTION; \
42 v4l2err->line = __LINE__; \
43 } \
44 }
45
46/**
47 * GST_AML_V4L2_IS_M2M:
48 * @_dcaps: The device capabilities
49 *
50 * Checks if the device caps represent an M2M device. Note that modern M2M
51 * devices uses V4L2_CAP_VIDEO_M2M* flag, but legacy uses to set both CAPTURE
52 * and OUTPUT flags instead.
53 *
54 * Returns: %TRUE if this is a M2M device.
55 */
56#define GST_AML_V4L2_IS_M2M(_dcaps) \
57 (((_dcaps) & (V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE)) ||\
58 (((_dcaps) & \
59 (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE_MPLANE)) && \
60 ((_dcaps) & \
61 (V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_MPLANE))))
62
63typedef struct _GstAmlV4l2Iterator GstAmlV4l2Iterator;
64typedef struct _GstAmlV4l2Error GstAmlV4l2Error;
65
66struct _GstAmlV4l2Iterator
67{
68 const gchar *device_path;
69 const gchar *device_name;
70 const gchar *sys_path;
71};
72
73struct _GstAmlV4l2Error
74{
75 GError *error;
76 gchar *dbg_message;
77 const gchar *file;
78 const gchar *func;
79 gint line;
80};
81
82GstAmlV4l2Iterator *gst_aml_v4l2_iterator_new(void);
83gboolean gst_aml_v4l2_iterator_next(GstAmlV4l2Iterator *it);
84void gst_aml_v4l2_iterator_free(GstAmlV4l2Iterator *it);
85
86const gchar *gst_aml_v4l2_iterator_get_device_path(GstAmlV4l2Iterator *it);
87const gchar *gst_aml_v4l2_iterator_get_device_name(GstAmlV4l2Iterator *it);
88const gchar *gst_aml_v4l2_iterator_get_sys_path(GstAmlV4l2Iterator *it);
89
90void gst_aml_v4l2_clear_error(GstAmlV4l2Error *error);
91void gst_aml_v4l2_error(gpointer element, GstAmlV4l2Error *error);
92
93G_END_DECLS
94
95#endif /* __AML_V4L2_UTILS_H__ */