Welcome to mirror list, hosted at ThFree Co, Russian Federation.

inputselector.rs « tests « threadshare « generic - gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4dd3427ad807fe53a5bca907c7d464544ff46d35 (plain)
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
// Copyright (C) 2020 Mathieu Duponchelle <mathieu@centricular.com>
//
// 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.
//
// SPDX-License-Identifier: LGPL-2.1-or-later

use gst::prelude::*;

fn init() {
    use std::sync::Once;
    static INIT: Once = Once::new();

    INIT.call_once(|| {
        gst::init().unwrap();
        gstthreadshare::plugin_register_static().expect("gstthreadshare inputselector test");
    });
}

#[test]
fn test_active_pad() {
    init();

    let is = gst::ElementFactory::make("ts-input-selector", None).unwrap();

    let mut h1 = gst_check::Harness::with_element(&is, Some("sink_%u"), Some("src"));
    let mut h2 = gst_check::Harness::with_element(&is, Some("sink_%u"), None);

    let active_pad = is.property::<Option<gst::Pad>>("active-pad");
    assert_eq!(active_pad, h1.srcpad().unwrap().peer());

    is.set_property("active-pad", h2.srcpad().unwrap().peer());
    let active_pad = is.property::<Option<gst::Pad>>("active-pad");
    assert_eq!(active_pad, h2.srcpad().unwrap().peer());

    h1.set_src_caps_str("foo/bar");
    h2.set_src_caps_str("foo/bar");

    h1.play();

    /* Push buffer on inactive pad, we should not receive anything */
    let buf = gst::Buffer::new();
    assert_eq!(h1.push(buf), Ok(gst::FlowSuccess::Ok));
    assert_eq!(h1.buffers_received(), 0);

    /* Buffers pushed on the active pad should be received */
    let buf = gst::Buffer::new();
    assert_eq!(h2.push(buf), Ok(gst::FlowSuccess::Ok));
    assert_eq!(h1.buffers_received(), 1);

    assert_eq!(h1.events_received(), 3);

    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::StreamStart);
    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::Caps);
    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::Segment);

    /* Push another buffer on the active pad, there should be no new events */
    let buf = gst::Buffer::new();
    assert_eq!(h2.push(buf), Ok(gst::FlowSuccess::Ok));
    assert_eq!(h1.buffers_received(), 2);
    assert_eq!(h1.events_received(), 3);

    /* Switch the active pad and push a buffer, we should receive stream-start, segment and caps
     * again */
    let buf = gst::Buffer::new();
    is.set_property("active-pad", h1.srcpad().unwrap().peer());
    assert_eq!(h1.push(buf), Ok(gst::FlowSuccess::Ok));
    assert_eq!(h1.buffers_received(), 3);
    assert_eq!(h1.events_received(), 6);
    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::StreamStart);
    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::Caps);
    let event = h1.pull_event().unwrap();
    assert_eq!(event.type_(), gst::EventType::Segment);

    let _ = is.set_state(gst::State::Null);
}