• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) 0"),
75   P (VP9, Profile1, "video/x-vp9", "profile = (string) 1"),
76   P (VP9, Profile2, "video/x-vp9", "profile = (string) 2"),
77   P (VP9, Profile3, "video/x-vp9", "profile = (string) 3"),
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   /* Spec A.2:
91      "Main" compliant decoders must be able to decode streams with
92      seq_profile equal to 0.
93      "High" compliant decoders must be able to decode streams with
94      seq_profile less than or equal to 1.
95      "Professional" compliant decoders must be able to decode streams
96      with seq_profile less than or equal to 2.
97 
98      The correct relationship between profile "main" "high" "professional"
99      and seq_profile "0" "1" "2" should be:
100      main <------> { 0 }
101      high <------> { main, 1 }
102      professional <------> { high, 2 }
103 
104      So far, all va decoders can support "0" when they support "1",
105      we just map "0" to "main" and "1" to "high".  */
106   P (AV1, Profile0, "video/x-av1", "profile = (string) main"),
107   P (AV1, Profile1, "video/x-av1", "profile = (string) high"),
108 #endif
109 #if VA_CHECK_VERSION(1, 8, 0)
110   P (HEVC, SccMain444_10, "video/x-h265",
111       "profile = (string) screen-extended-main-444-10"),
112 #endif
113 #undef P
114 };
115 /* *INDENT-ON* */
116 
117 static const struct ProfileMap *
get_profile_map(VAProfile profile)118 get_profile_map (VAProfile profile)
119 {
120   int i;
121 
122   for (i = 0; i < G_N_ELEMENTS (profile_map); i++) {
123     if (profile_map[i].profile == profile)
124       return &profile_map[i];
125   }
126 
127   return NULL;
128 }
129 
130 guint32
gst_va_profile_codec(VAProfile profile)131 gst_va_profile_codec (VAProfile profile)
132 {
133   const struct ProfileMap *map = get_profile_map (profile);
134   return map ? map->codec : GST_MAKE_FOURCC ('N', 'O', 'N', 'E');
135 }
136 
137 const gchar *
gst_va_profile_name(VAProfile profile)138 gst_va_profile_name (VAProfile profile)
139 {
140   const struct ProfileMap *map = get_profile_map (profile);
141   return map ? map->name : NULL;
142 }
143 
144 GstCaps *
gst_va_profile_caps(VAProfile profile)145 gst_va_profile_caps (VAProfile profile)
146 {
147   const struct ProfileMap *map = get_profile_map (profile);
148   GstCaps *caps;
149   gchar *caps_str;
150 
151   if (!map)
152     return NULL;
153 
154   if (map->caps_str)
155     caps_str = g_strdup_printf ("%s, %s", map->media_type, map->caps_str);
156   else
157     caps_str = g_strdup (map->media_type);
158 
159   caps = gst_caps_from_string (caps_str);
160   g_free (caps_str);
161 
162   return caps;
163 }
164