<commit_before>/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: <NAME> (Khattak) <<EMAIL>>
 *                               <<EMAIL>>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using Gst;
using Gst.PbUtils;

internal errordomain Rygel.GstError {
    MISSING_PLUGIN,
    LINK
}

internal abstract class Rygel.GstUtils {
    public static Element create_element (string factoryname,
                                          string? name)
                                          throws Error {
        Element element = ElementFactory.make (factoryname, name);
        if (element == null) {
            throw new GstError.MISSING_PLUGIN
                                        (_("Required element %s missing"),
                                         factoryname);
        }

        return element;
    }

    public static Element? create_source_for_uri (string uri) {
        try {
            dynamic Element src;

            if (uri.has_prefix ("gst-launch://")) {
                var description = uri.replace ("gst-launch://", "");
                description = Soup.URI.decode (description);

                src = Gst.parse_bin_from_description (description, true);
            } else if (uri.has_prefix ("dvd://")) {
                var tmp = new Soup.URI (uri);
                var query = Soup.Form.decode (tmp.query);
                src = ElementFactory.make ("dvdreadsrc", null);
                if (query.contains ("title")) {
                    src.title = int.parse (query.lookup ("title"));
                }
                src.device = Soup.URI.decode (tmp.path);
            } else {
                src = Element.make_from_uri (URIType.SRC, uri, null);
            }

            if (src.get_class ().find_property ("blocksize") != null) {
                // The default is usually 4KiB which is not really big enough
                // for most cases so we set this to 65KiB.
                src.blocksize = (long) 65536;
            }

            if (src.get_class ().find_property ("tcp-timeout") != null) {
   // For rtspsrc since some RTSP sources takes a while to start<commit_msg>engine-gst: Don't crash if dvdreadsrc is missing<commit_after>/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Author: <NAME>) <<EMAIL>>
 *                               <<EMAIL>>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using Gst;
using Gst.PbUtils;

internal errordomain Rygel.GstError {
    MISSING_PLUGIN,
    LINK
}

internal abstract class Rygel.GstUtils {
    public static Element create_element (string factoryname,
                                          string? name)
                                          throws Error {
        Element element = ElementFactory.make (factoryname, name);
        if (element == null) {
            throw new GstError.MISSING_PLUGIN
                                        (_("Required element %s missing"),
                                         factoryname);
        }

        return element;
    }

    public static Element? create_source_for_uri (string uri) {
        try {
            dynamic Element src;

            if (uri.has_prefix ("gst-launch://")) {
                var description = uri.replace ("gst-launch://", "");
                description = Soup.URI.decode (description);

                src = Gst.parse_bin_from_description (description, true);
            } else if (uri.has_prefix ("dvd://")) {
                src = ElementFactory.make ("dvdreadsrc", null);
                if (src == null) {
                    warning (_("GStreamer element 'dvdreadsrc' not found. DVD support does not work"));

                    return null;
                }

                var tmp = new Soup.URI (uri);
                var query = Soup.Form.decode (tmp.query);
                if (query.contains ("title")) {
                    src.title = int.parse (query.lookup ("title"));
                }
                src.device = Soup.URI.decode (tmp.path);
            } else {
                src = Element.make_from_uri (URIType.SRC, uri, null);
            }

            if (src.get_class ().find_property ("blocksize") != null) {
                // The default is usually 4KiB which is not really big enough
                // for most cases so we set this to 65KiB.
                src.blocksize = (long) 65536;
            }

            if (src.get_class ().find_property ("tcp-timeout") != null) {
   // For rtspsrc since some RTSP sources takes a while to start
{'fraction_non_alphanumeric': 0.09037162162162163, 'fraction_numerical': 0.008445945945945946, 'mean_word_length': 1.7759024847632443, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3219238', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1461, 'n_words': 566}