/* Pinos * Copyright (C) 2015 Wim Taymans * * 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 #include #include #include "pinos/server/utils.h" GBytes * pinos_format_filter (GBytes *format, GBytes *filter, GError **error) { GstCaps *tmp, *caps, *cfilter; gchar *str; GBytes *res; if (filter) { cfilter = gst_caps_from_string (g_bytes_get_data (filter, NULL)); if (cfilter == NULL) goto invalid_filter; } else { cfilter = NULL; } if (format) caps = gst_caps_from_string (g_bytes_get_data (format, NULL)); else caps = gst_caps_new_any (); if (caps && cfilter) { tmp = gst_caps_intersect_full (caps, cfilter, GST_CAPS_INTERSECT_FIRST); gst_caps_take (&caps, tmp); } g_clear_pointer (&cfilter, gst_caps_unref); if (caps == NULL || gst_caps_is_empty (caps)) goto no_format; str = gst_caps_to_string (caps); gst_caps_unref (caps); res = g_bytes_new_take (str, strlen (str) + 1); return res; invalid_filter: { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Invalid filter received"); return NULL; } no_format: { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "No compatible format found"); if (cfilter) gst_caps_unref (cfilter); if (caps) gst_caps_unref (caps); return NULL; } }