<commit_before>// Copyright (C) 2019 <NAME> <<EMAIL>>
//
// 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 Street, Suite 500,
// Boston, MA 02110-1335, USA.

extern crate glib;
use glib::prelude::*;
extern crate gio;
use gio::prelude::*;

extern crate gstreamer as gst;
use gst::prelude::*;

extern crate gstfallbackswitch;

extern crate gtk;
use gtk::prelude::*;
use std::cell::RefCell;
use std::env;

fn create_pipeline() -> (gst::Pipeline, gst::Pad, gst::Element, gtk::Widget) {
    let pipeline = gst::Pipeline::new(None);

    let video_src = gst::ElementFactory::make("videotestsrc", None).unwrap();
    video_src.set_property("is-live", &true).unwrap();
    video_src.set_property_from_str("pattern", "ball");

    let fallback_video_src = gst::ElementFactory::make("videotestsrc", None).unwrap();

    let fallbackswitch = gst::ElementFactory::make("fallbackswitch", None).unwrap();
    fallbackswitch
        .set_property("timeout", &gst::SECOND)
        .unwrap();

    let videoconvert = gst::ElementFactory::make("videoconvert", None).unwrap();

    let (video_sink, video_widget) =
        //if let Some(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) {
        //    let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap();
        //    glsinkbin.set_property("sink", &gtkglsink).unwrap();

        //    let widget = gtkglsink.get_property("widget").unwrap();
        //    (glsinkbin, widget.get::<gtk::Widget>().unwrap().unwrap())
        //} else
        {
            let sink = gst::ElementFactory::make("gtksink", None).unwrap();
            let widget = sink.get_property("widget").unwrap();
            (sink, widget.get::<gtk::Widget>().unwrap().unwrap())
        };

    pipeline
        .add_many(&[
            &video_src,
            &fallback_video_src,
            &fallbackswitch,
            &videoconvert,
            &video_sink,
        ])
        .unwrap();

    video_src
        .link_pads(Some("src"), &fallbackswitch, Some("sink"))
        .unwrap();
    fallback_video_src
        .link_pads(Some("src"), &fallbackswitch, Some("fallback_sink"))
        .unwrap();
    fallbackswitch
        .link_pads(Some("src"), &videoconvert, Some("sink"))
        .unwrap();
    videoconvert
        .link_pads(Some("src"), &video_sink, Some("sink"))<commit_msg>fallbackswitch: Allow using compressed video in the example application<commit_after>// Copyright (C) 2019 <NAME> <<EMAIL>>
//
// 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 Street, Suite 500,
// Boston, MA 02110-1335, USA.

extern crate glib;
use glib::prelude::*;
extern crate gio;
use gio::prelude::*;

extern crate gstreamer as gst;
use gst::prelude::*;

extern crate gstfallbackswitch;

extern crate gtk;
use gtk::prelude::*;
use std::cell::RefCell;
use std::env;

const MAIN_PIPELINE: &str = "videotestsrc is-live=true pattern=ball";
const FALLBACK_PIPELINE: &str = "videotestsrc is-live=true pattern=snow";

//const MAIN_PIPELINE: &str = "videotestsrc is-live=true pattern=ball ! x264enc tune=zerolatency";
//const FALLBACK_PIPELINE: &str = "videotestsrc is-live=true pattern=snow ! x264enc tune=zerolatency";

fn create_pipeline() -> (gst::Pipeline, gst::Pad, gst::Element, gtk::Widget) {
    let pipeline = gst::Pipeline::new(None);

    let video_src = gst::parse_bin_from_description(MAIN_PIPELINE, true)
        .unwrap()
        .upcast();
    let fallback_video_src = gst::parse_bin_from_description(&FALLBACK_PIPELINE, true)
        .unwrap()
        .upcast();

    let fallbackswitch = gst::ElementFactory::make("fallbackswitch", None).unwrap();
    fallbackswitch
        .set_property("timeout", &gst::SECOND)
        .unwrap();

    let decodebin = gst::ElementFactory::make("decodebin", None).unwrap();
    let videoconvert = gst::ElementFactory::make("videoconvert", None).unwrap();

    let videoconvert_clone = videoconvert.clone();
    decodebin.connect_pad_added(move |_, pad| {
        let caps = pad.get_current_caps().unwrap();
        let s = caps.get_structure(0).unwrap();

        let sinkpad = videoconvert_clone.get_static_pad("sink").unwrap();

        if s.get_name() == "video/x-raw" && !sinkpad.is_linked() {
            pad.link(&sinkpad).unwrap();
        }
    });

    let (video_sink, video_widget) =
        //if let Some(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) {
        //    let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap();
        //    glsinkbin.set_property("sink", &gtkglsink).unwrap();

        //    let widget = gtkglsink.get_property("widget").unwrap();
        //    (glsinkbin, widget.get::<gtk::Widget>().unwrap().unwrap())
        //} else
        {
            let sink = gst::ElementFactory::make("gtksink", None).unwrap();
            let widget = sink.get_property("widget").unwrap();
            (sink, widget.get::<gtk::Widget>().unwrap().unwrap())
        };

    pipeline
        .add_many(&[
            &video_src,
            &fallback_video_src,
            &fallbackswitch,
            &decodebin,
            &videoconvert,
            &video_sink,
        ])
        .unwrap();

    video_src
        .link_pads(Some("src"), &fallbackswitch, Some("sink"))
        .unwrap();
    fallback_video_src
        .link_pads(Some("src"), &fallbackswitch, Some("fallback_sink"))
        .unwrap();
    fallbackswitch
        .link_pads(Some("src"), &decodebin, Some("sink"))
        .unwrap();
    videoconvert
        .link_pads(Some("src"), &video_sink, Some("sink"))
{'fraction_non_alphanumeric': 0.1433416900162218, 'fraction_numerical': 0.006636189352602861, 'mean_word_length': 3.2229140722291407, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4551859', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2133, 'n_words': 539}