va: VA-API H.264 decoder and infrastructure
[platform/upstream/gstreamer.git] / sys / va / gstvaprofile.c
1 /* GStreamer
2  * Copyright (C) 2020 Igalia, S.L.
3  *     Author: Víctor Jáquez <vjaquez@igalia.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "gstvaprofile.h"
26
27 /* *INDENT-OFF* */
28 static const struct ProfileMap
29 {
30   VAProfile profile;
31   GstVaCodecs codec;
32   const gchar *name;
33   const gchar *media_type;
34   const gchar *caps_str;
35 } profile_map[] = {
36 #define P(codec, name, media_type, caps_str) {                \
37     G_PASTE (G_PASTE (VAProfile, codec), name), codec,        \
38     G_STRINGIFY (G_PASTE (G_PASTE (VAProfile, codec), name)), \
39     media_type, caps_str }
40   P (MPEG2, Simple, "video/mpeg",
41       "mpegversion = (int) 2, profile = (string) simple"),
42   P (MPEG2, Main, "video/mpeg",
43       "mpegversion = (int) 2, profile = (string) main"),
44   P (MPEG4, Simple, "video/mpeg",
45       "mpegversion = (int) 4, profile = (string) simple"),
46   P (MPEG4, AdvancedSimple, "video/mpeg",
47       "mpegversion = (int) 4, profile = (string) advanced-simple"),
48   P (MPEG4, Main, "video/mpeg",
49       "mpegversion = (int) 4, profile = (string) main, "),
50   P (H264, Main, "video/x-h264", "profile = (string) { main, baseline }"),
51   P (H264, High, "video/x-h264",
52       "profile = (string) { progressive-high, constrained-high, high }"),
53   P (VC1, Simple, "video/x-wmv",
54       "wmvversion = (int) 3, profile = (string) simple"),
55   P (VC1, Main, "video/x-wmv",
56       "wmvversion = (int) 3, profile = (string) main"),
57   P (VC1, Advanced, "video/x-wmv",
58       "wmvversion = (int) 3, format = (string) WVC1, "
59       "profile = (string) advanced"),
60   P (H263, Baseline, "video/x-h263",
61       "variant = (string) itu, h263version = (string) h263, "
62       "profile = (string) baseline"),
63   P (JPEG, Baseline, "image/jpeg", NULL),
64   P (H264, ConstrainedBaseline, "video/x-h264",
65       "profile = (string) { baseline, constrained-baseline }"),
66   P (VP8, Version0_3, "video/x-vp8", NULL),
67   /* Unsupported profiles by current GstH264Decoder */
68   /* P (H264, MultiviewHigh, "video/x-h264", */
69   /*     "profile = (string) {  multiview-high, stereo-high }"), */
70   /* P (H264, StereoHigh, "video/x-h264", */
71   /*     "profile = (string) {  multiview-high, stereo-high }"), */
72   P (HEVC, Main, "video/x-h265", "profile = (string) main"),
73   P (HEVC, Main10, "video/x-h265", "profile = (string) main-10"),
74   P (VP9, Profile0, "video/x-vp9", "profile = (string) profile0"),
75   P (VP9, Profile1, "video/x-vp9", "profile = (string) profile1"),
76   P (VP9, Profile2, "video/x-vp9", "profile = (string) profile2"),
77   P (VP9, Profile3, "video/x-vp9", "profile = (string) profile3"),
78   P (HEVC, Main12, "video/x-h265", "profile = (string) main-12"),
79   P (HEVC, Main422_10, "video/x-h265", "profile = (string) main-422-10"),
80   P (HEVC, Main422_12, "video/x-h265", "profile = (string) main-422-12"),
81   P (HEVC, Main444, "video/x-h265", "profile = (string) main-444"),
82   P (HEVC, Main444_10, "video/x-h265", "profile = (string) main-444-10"),
83   P (HEVC, Main444_12, "video/x-h265", "profile = (string) main-444-12"),
84   P (HEVC, SccMain, "video/x-h265", "profile = (string) screen-extended-main"),
85   P (HEVC, SccMain10, "video/x-h265",
86       "profile = (string) screen-extended-main-10"),
87   P (HEVC, SccMain444, "video/x-h265",
88       "profile = (string) screen-extended-main-444"),
89 #if VA_CHECK_VERSION(1,7,0)
90   P (AV1, Profile0, "video/x-av1", NULL),
91   P (AV1, Profile1, "video/x-av1", NULL),
92 #endif
93 #if VA_CHECK_VERSION(1, 8, 0)
94   P (HEVC, SccMain444_10, "video/x-h265",
95       "profile = (string) screen-extended-main-444-10"),
96 #endif
97 #undef P
98 };
99 /* *INDENT-ON* */
100
101 static const struct ProfileMap *
102 get_profile_map (VAProfile profile)
103 {
104   int i;
105
106   for (i = 0; i < G_N_ELEMENTS (profile_map); i++) {
107     if (profile_map[i].profile == profile)
108       return &profile_map[i];
109   }
110
111   return NULL;
112 }
113
114 guint32
115 gst_va_profile_codec (VAProfile profile)
116 {
117   const struct ProfileMap *map = get_profile_map (profile);
118   return map ? map->codec : GST_MAKE_FOURCC ('N', 'O', 'N', 'E');
119 }
120
121 const gchar *
122 gst_va_profile_name (VAProfile profile)
123 {
124   const struct ProfileMap *map = get_profile_map (profile);
125   return map ? map->name : NULL;
126 }
127
128 GstCaps *
129 gst_va_profile_caps (VAProfile profile)
130 {
131   const struct ProfileMap *map = get_profile_map (profile);
132   GstCaps *caps;
133   gchar *caps_str;
134
135   if (!map)
136     return NULL;
137
138   if (map->caps_str)
139     caps_str = g_strdup_printf ("%s, %s", map->media_type, map->caps_str);
140   else
141     caps_str = g_strdup (map->media_type);
142
143   caps = gst_caps_from_string (caps_str);
144   g_free (caps_str);
145
146   return caps;
147 }