2020-03-17 15:19:01 +00:00
|
|
|
// Copyright (C) 2020 Mathieu Duponchelle <mathieu@centricular.com>
|
2020-01-03 17:46:32 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2022-01-15 19:18:47 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2020-01-03 17:46:32 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-06-11 10:45:15 +00:00
|
|
|
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);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
let active_pad = is.property::<Option<gst::Pad>>("active-pad");
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(active_pad, h1.srcpad().unwrap().peer());
|
2020-01-03 17:46:32 +00:00
|
|
|
|
2021-11-08 09:55:40 +00:00
|
|
|
is.set_property("active-pad", h2.srcpad().unwrap().peer());
|
|
|
|
let active_pad = is.property::<Option<gst::Pad>>("active-pad");
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(active_pad, h2.srcpad().unwrap().peer());
|
2020-01-03 17:46:32 +00:00
|
|
|
|
|
|
|
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();
|
2020-02-27 14:34:44 +00:00
|
|
|
assert_eq!(h1.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
assert_eq!(h1.buffers_received(), 0);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
|
|
|
/* Buffers pushed on the active pad should be received */
|
|
|
|
let buf = gst::Buffer::new();
|
2020-02-27 14:34:44 +00:00
|
|
|
assert_eq!(h2.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
assert_eq!(h1.buffers_received(), 1);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
2020-03-17 15:19:01 +00:00
|
|
|
assert_eq!(h1.events_received(), 3);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::StreamStart);
|
2020-01-03 17:46:32 +00:00
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::Caps);
|
2020-01-03 17:46:32 +00:00
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::Segment);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
|
|
|
/* Push another buffer on the active pad, there should be no new events */
|
|
|
|
let buf = gst::Buffer::new();
|
2020-02-27 14:34:44 +00:00
|
|
|
assert_eq!(h2.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
assert_eq!(h1.buffers_received(), 2);
|
2020-03-17 15:19:01 +00:00
|
|
|
assert_eq!(h1.events_received(), 3);
|
2020-01-03 17:46:32 +00:00
|
|
|
|
2020-02-27 14:34:44 +00:00
|
|
|
/* Switch the active pad and push a buffer, we should receive stream-start, segment and caps
|
|
|
|
* again */
|
2020-01-03 17:46:32 +00:00
|
|
|
let buf = gst::Buffer::new();
|
2021-11-08 09:55:40 +00:00
|
|
|
is.set_property("active-pad", h1.srcpad().unwrap().peer());
|
2020-02-27 14:34:44 +00:00
|
|
|
assert_eq!(h1.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
assert_eq!(h1.buffers_received(), 3);
|
2020-03-17 15:19:01 +00:00
|
|
|
assert_eq!(h1.events_received(), 6);
|
2020-01-03 17:46:32 +00:00
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::StreamStart);
|
2020-01-03 17:46:32 +00:00
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::Caps);
|
2020-02-27 14:34:44 +00:00
|
|
|
let event = h1.pull_event().unwrap();
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(event.type_(), gst::EventType::Segment);
|
2020-01-29 19:18:15 +00:00
|
|
|
|
|
|
|
let _ = is.set_state(gst::State::Null);
|
2020-01-03 17:46:32 +00:00
|
|
|
}
|