Debian Codegraph @

gst-libs/gst/wayland/gstwlvideoformat.c

raw symbols SCIP
1 /* GStreamer Wayland Library
2 *
3 * Copyright (C) 2011 Intel Corporation
4 * Copyright (C) 2011 Sreerenj Balachandran <[email protected]>
5 * Copyright (C) 2012 Wim Taymans <[email protected]>
6 * Copyright (C) 2014 Collabora Ltd.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "gstwlvideoformat.h"
29
30 #include <drm_fourcc.h>
31
32 #define GST_CAT_DEFAULT gst_wl_videoformat_debug
33 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
34
35 void
36 gst_wl_videoformat_init_once (void)
37 {
38 static gsize _init = 0;
39
40 if (g_once_init_enter (&_init)) {
41 GST_DEBUG_CATEGORY_INIT (gst_wl_videoformat_debug, "wl_videoformat", 0,
42 "wl_videoformat library");
43
44 g_once_init_leave (&_init, 1);
45 }
46 }
47
48 enum wl_shm_format
49 gst_video_format_to_wl_shm_format (GstVideoFormat format)
50 {
51 guint32 drm_format;
52 guint64 modifier;
53
54 drm_format = gst_video_dma_drm_format_from_gst_format (format, &modifier);
55
56 if (drm_format == DRM_FORMAT_INVALID || modifier != DRM_FORMAT_MOD_LINEAR) {
57 GST_WARNING ("wayland shm video format not found");
58 return -1;
59 }
60
61 if (drm_format == DRM_FORMAT_XRGB8888)
62 drm_format = WL_SHM_FORMAT_XRGB8888;
63 else if (drm_format == DRM_FORMAT_ARGB8888)
64 drm_format = WL_SHM_FORMAT_ARGB8888;
65
66 return drm_format;
67 }
68
69 guint32
70 gst_video_format_to_wl_dmabuf_format (GstVideoFormat format)
71 {
72 guint32 drm_format;
73 guint64 modifier;
74
75 drm_format = gst_video_dma_drm_format_from_gst_format (format, &modifier);
76
77 if (drm_format == DRM_FORMAT_INVALID || modifier != DRM_FORMAT_MOD_LINEAR) {
78 GST_WARNING ("wayland dmabuf video format not found");
79 return DRM_FORMAT_INVALID;
80 }
81
82 return drm_format;
83 }
84
85 GstVideoFormat
86 gst_wl_shm_format_to_video_format (enum wl_shm_format wl_format)
87 {
88 if (wl_format == WL_SHM_FORMAT_XRGB8888)
89 wl_format = DRM_FORMAT_XRGB8888;
90 else if (wl_format == WL_SHM_FORMAT_ARGB8888)
91 wl_format = DRM_FORMAT_ARGB8888;
92
93 return gst_wl_dmabuf_format_to_video_format (wl_format);
94 }
95
96 GstVideoFormat
97 gst_wl_dmabuf_format_to_video_format (guint wl_format)
98 {
99 return gst_video_dma_drm_format_to_gst_format (wl_format,
100 DRM_FORMAT_MOD_LINEAR);
101 }
102
103 const gchar *
104 gst_wl_shm_format_to_string (enum wl_shm_format wl_format)
105 {
106 return gst_video_format_to_string
107 (gst_wl_shm_format_to_video_format (wl_format));
108 }