1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
/* GStreamer
* Copyright (C) <2010> Edward Hervey <edward.hervey@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "gstcapslist.h"
/*
* Caps listing convenience functions
*/
static gboolean
remove_range_foreach (const GstIdStr * fieldname, const GValue * value,
GstStructure * st)
{
GType ftype = G_VALUE_TYPE (value);
/* const gchar *fname; */
if (ftype == GST_TYPE_INT_RANGE || ftype == GST_TYPE_DOUBLE_RANGE ||
ftype == GST_TYPE_FRACTION_RANGE) {
gst_structure_remove_field (st, gst_id_str_as_str (fieldname));
return FALSE;
}
/* fname = g_quark_to_string (field_id); */
/* if (strstr (fname, "framerate") || strstr (fname, "pixel-aspect-ratio") || */
/* strstr (fname, "rate")) { */
/* gst_structure_remove_field (st, g_quark_to_string (field_id)); */
/* return FALSE; */
/* } */
return TRUE;
}
static void
clear_caps (GstCaps * caps, GstCaps * rescaps)
{
GstCaps *res;
GstStructure *st;
guint i;
res = gst_caps_make_writable (caps);
GST_DEBUG ("incoming caps %" GST_PTR_FORMAT, res);
/* Remove width/height/framerate/depth/width fields */
for (i = gst_caps_get_size (res); i; i--) {
st = gst_caps_get_structure (res, i - 1);
/* Remove range fields */
while (!gst_structure_foreach_id_str (st,
(GstStructureForeachIdStrFunc) remove_range_foreach, st));
}
GST_DEBUG ("stripped %" GST_PTR_FORMAT, res);
/* And append to list without duplicates */
while ((st = gst_caps_steal_structure (res, 0))) {
/* Skip fake codecs/containers */
if (gst_structure_has_name (st, "audio/x-raw") ||
gst_structure_has_name (st, "video/x-raw") ||
gst_structure_has_name (st, "unknown/unknown")) {
gst_structure_free (st);
continue;
}
gst_caps_append_structure (rescaps, st);
}
gst_caps_unref (res);
}
static GstCaps *
get_all_caps (GList * elements, GstPadDirection direction)
{
GstCaps *res;
GList *tmp;
res = gst_caps_new_empty ();
for (tmp = elements; tmp; tmp = tmp->next) {
GstElementFactory *factory = (GstElementFactory *) tmp->data;
const GList *templates;
GList *walk;
templates = gst_element_factory_get_static_pad_templates (factory);
for (walk = (GList *) templates; walk; walk = g_list_next (walk)) {
GstStaticPadTemplate *templ = walk->data;
if (templ->direction == direction)
clear_caps (gst_static_caps_get (&templ->static_caps), res);
}
}
res = gst_caps_normalize (res);
return res;
}
/**
* gst_caps_list_container_formats:
* @minrank: The minimum #GstRank
*
* Returns a #GstCaps corresponding to all the container formats
* one can mux to on this system.
*
* Returns: A #GstCaps. Unref with %gst_caps_unref when done with it.
*/
GstCaps *
gst_caps_list_container_formats (GstRank minrank)
{
GstCaps *res;
GList *muxers;
muxers =
gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_MUXER,
minrank);
res = get_all_caps (muxers, GST_PAD_SRC);
gst_plugin_feature_list_free (muxers);
return res;
}
static GstCaps *
gst_caps_list_encoding_formats (GstRank minrank)
{
GstCaps *res;
GList *encoders;
encoders =
gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_ENCODER,
minrank);
res = get_all_caps (encoders, GST_PAD_SRC);
gst_plugin_feature_list_free (encoders);
return res;
}
/**
* gst_caps_list_video_encoding_formats:
* @minrank: The minimum #GstRank
*
* Returns a #GstCaps corresponding to all the video or image formats one
* can encode to on this system.
*
* Returns: A #GstCaps. Unref with %gst_caps_unref when done with it.
*/
GstCaps *
gst_caps_list_video_encoding_formats (GstRank minrank)
{
GstCaps *res;
GList *encoders;
encoders =
gst_element_factory_list_get_elements
(GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER, minrank);
res = get_all_caps (encoders, GST_PAD_SRC);
gst_plugin_feature_list_free (encoders);
return res;
}
/**
* gst_caps_list_audio_encoding_formats:
* @minrank: The minimum #GstRank
*
* Returns a #GstCaps corresponding to all the audio formats one
* can encode to on this system.
*
* Returns: A #GstCaps. Unref with %gst_caps_unref when done with it.
*/
GstCaps *
gst_caps_list_audio_encoding_formats (GstRank minrank)
{
GstCaps *res;
GList *encoders;
encoders =
gst_element_factory_list_get_elements
(GST_ELEMENT_FACTORY_TYPE_AUDIO_ENCODER, minrank);
res = get_all_caps (encoders, GST_PAD_SRC);
gst_plugin_feature_list_free (encoders);
return res;
}
/**
* gst_caps_list_compatible_codecs:
* @containerformat: A #GstCaps corresponding to a container format
* @codecformats: An optional #GstCaps of codec formats
* @muxers: An optional #GList of muxer #GstElementFactory.
*
* Returns an array of #GstCaps corresponding to the audio/video/text formats
* one can encode to and that can be muxed in the provided @containerformat.
*
* If specified, only the #GstCaps contained in @codecformats will be checked
* against, else all compatible audio/video formats will be returned.
*
* If specified, only the #GstElementFactory contained in @muxers will be checked,
* else all available muxers on the system will be checked.
*
* Returns: A #GstCaps containing all compatible formats. Unref with %gst_caps_unref
* when done.
*/
GstCaps *
gst_caps_list_compatible_codecs (const GstCaps * containerformat,
GstCaps * codecformats, GList * muxers)
{
const GList *templates;
GstElementFactory *factory;
GList *walk;
GstCaps *res = NULL;
GstCaps *tmpcaps;
GList *tmp;
gboolean hadmuxers = (muxers != NULL);
gboolean hadcodecs = (codecformats != NULL);
GST_DEBUG ("containerformat: %" GST_PTR_FORMAT, containerformat);
GST_DEBUG ("codecformats: %" GST_PTR_FORMAT, codecformats);
if (!hadmuxers)
muxers =
gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_MUXER,
GST_RANK_NONE);
if (!hadcodecs)
codecformats = gst_caps_list_encoding_formats (GST_RANK_NONE);
/* Get the highest rank muxer matching containerformat */
tmp =
gst_element_factory_list_filter (muxers, containerformat, GST_PAD_SRC,
TRUE);
if (G_UNLIKELY (tmp == NULL))
goto beach;
factory = (GstElementFactory *) tmp->data;
GST_DEBUG ("Trying with factory %s",
gst_element_factory_get_metadata (factory,
GST_ELEMENT_METADATA_LONGNAME));
/* Match all muxer sink pad templates against the available codec formats */
templates = gst_element_factory_get_static_pad_templates (factory);
gst_plugin_feature_list_free (tmp);
tmpcaps = gst_caps_new_empty ();
for (walk = (GList *) templates; walk; walk = walk->next) {
GstStaticPadTemplate *templ = walk->data;
if (templ->direction == GST_PAD_SINK) {
GstCaps *templ_caps;
templ_caps = gst_static_caps_get (&templ->static_caps);
gst_caps_append (tmpcaps, gst_caps_copy (templ_caps));
}
}
res = gst_caps_intersect (tmpcaps, codecformats);
gst_caps_unref (tmpcaps);
beach:
if (!hadmuxers)
gst_plugin_feature_list_free (muxers);
if (!hadcodecs)
gst_caps_unref (codecformats);
res = gst_caps_normalize (res);
return res;
}
|