Merging gst-plugins-bad
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / ext / wayland / wlvideoformat.c
1 /* GStreamer Wayland video sink
2  *
3  * Copyright (C) 2011 Intel Corporation
4  * Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
5  * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
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 "wlvideoformat.h"
29
30 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
31 #define GST_CAT_DEFAULT gstwayland_debug
32
33 typedef struct
34 {
35   enum wl_shm_format wl_shm_format;
36   guint dma_format;
37   GstVideoFormat gst_format;
38 } wl_VideoFormat;
39
40 static const wl_VideoFormat wl_formats[] = {
41   {WL_SHM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888, GST_VIDEO_FORMAT_BGRx},
42   {WL_SHM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888, GST_VIDEO_FORMAT_BGRA},
43   {WL_SHM_FORMAT_XBGR8888, DRM_FORMAT_XBGR8888, GST_VIDEO_FORMAT_RGBx},
44   {WL_SHM_FORMAT_RGBX8888, DRM_FORMAT_RGBX8888, GST_VIDEO_FORMAT_xBGR},
45   {WL_SHM_FORMAT_BGRX8888, DRM_FORMAT_BGRX8888, GST_VIDEO_FORMAT_xRGB},
46   {WL_SHM_FORMAT_ABGR8888, DRM_FORMAT_ABGR8888, GST_VIDEO_FORMAT_RGBA},
47   {WL_SHM_FORMAT_RGBA8888, DRM_FORMAT_RGBA8888, GST_VIDEO_FORMAT_ABGR},
48   {WL_SHM_FORMAT_BGRA8888, DRM_FORMAT_BGRA8888, GST_VIDEO_FORMAT_ARGB},
49   {WL_SHM_FORMAT_RGB888, DRM_FORMAT_RGB888, GST_VIDEO_FORMAT_RGB},
50   {WL_SHM_FORMAT_BGR888, DRM_FORMAT_BGR888, GST_VIDEO_FORMAT_BGR},
51   {WL_SHM_FORMAT_RGB565, DRM_FORMAT_RGB565, GST_VIDEO_FORMAT_RGB16},
52   {WL_SHM_FORMAT_BGR565, DRM_FORMAT_BGR565, GST_VIDEO_FORMAT_BGR16},
53
54   {WL_SHM_FORMAT_YUYV, DRM_FORMAT_YUYV, GST_VIDEO_FORMAT_YUY2},
55   {WL_SHM_FORMAT_YVYU, DRM_FORMAT_YVYU, GST_VIDEO_FORMAT_YVYU},
56   {WL_SHM_FORMAT_UYVY, DRM_FORMAT_UYVY, GST_VIDEO_FORMAT_UYVY},
57   {WL_SHM_FORMAT_AYUV, DRM_FORMAT_AYUV, GST_VIDEO_FORMAT_AYUV},
58   {WL_SHM_FORMAT_NV12, DRM_FORMAT_NV12, GST_VIDEO_FORMAT_NV12},
59   {WL_SHM_FORMAT_NV21, DRM_FORMAT_NV21, GST_VIDEO_FORMAT_NV21},
60   {WL_SHM_FORMAT_NV16, DRM_FORMAT_NV16, GST_VIDEO_FORMAT_NV16},
61   {WL_SHM_FORMAT_NV61, DRM_FORMAT_NV61, GST_VIDEO_FORMAT_NV61},
62   {WL_SHM_FORMAT_YUV410, DRM_FORMAT_YUV410, GST_VIDEO_FORMAT_YUV9},
63   {WL_SHM_FORMAT_YVU410, DRM_FORMAT_YVU410, GST_VIDEO_FORMAT_YVU9},
64   {WL_SHM_FORMAT_YUV411, DRM_FORMAT_YUV411, GST_VIDEO_FORMAT_Y41B},
65   {WL_SHM_FORMAT_YUV420, DRM_FORMAT_YUV420, GST_VIDEO_FORMAT_I420},
66   {WL_SHM_FORMAT_YVU420, DRM_FORMAT_YVU420, GST_VIDEO_FORMAT_YV12},
67   {WL_SHM_FORMAT_YUV422, DRM_FORMAT_YUV422, GST_VIDEO_FORMAT_Y42B},
68   {WL_SHM_FORMAT_YUV444, DRM_FORMAT_YUV444, GST_VIDEO_FORMAT_v308},
69 };
70
71 enum wl_shm_format
72 gst_video_format_to_wl_shm_format (GstVideoFormat format)
73 {
74   guint i;
75
76   for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
77     if (wl_formats[i].gst_format == format)
78       return wl_formats[i].wl_shm_format;
79
80   GST_WARNING ("wayland shm video format not found");
81   return -1;
82 }
83
84 gint
85 gst_video_format_to_wl_dmabuf_format (GstVideoFormat format)
86 {
87   guint i;
88
89   for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
90     if (wl_formats[i].gst_format == format)
91       return wl_formats[i].dma_format;
92
93   GST_WARNING ("wayland dmabuf video format not found");
94   return -1;
95 }
96
97 GstVideoFormat
98 gst_wl_shm_format_to_video_format (enum wl_shm_format wl_format)
99 {
100   guint i;
101
102   for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
103     if (wl_formats[i].wl_shm_format == wl_format)
104       return wl_formats[i].gst_format;
105
106   return GST_VIDEO_FORMAT_UNKNOWN;
107 }
108
109 GstVideoFormat
110 gst_wl_dmabuf_format_to_video_format (guint wl_format)
111 {
112   guint i;
113
114   for (i = 0; i < G_N_ELEMENTS (wl_formats); i++)
115     if (wl_formats[i].dma_format == wl_format)
116       return wl_formats[i].gst_format;
117
118   return GST_VIDEO_FORMAT_UNKNOWN;
119 }
120
121 const gchar *
122 gst_wl_shm_format_to_string (enum wl_shm_format wl_format)
123 {
124   return gst_video_format_to_string
125       (gst_wl_shm_format_to_video_format (wl_format));
126 }
127
128 const gchar *
129 gst_wl_dmabuf_format_to_string (guint wl_format)
130 {
131   return gst_video_format_to_string
132       (gst_wl_dmabuf_format_to_video_format (wl_format));
133 }