2020-03-06 17:25:32 +00:00
|
|
|
|
// Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
|
|
|
|
|
// If a copy of the MPL was not distributed with this file, You can obtain one at
|
|
|
|
|
// <https://mozilla.org/MPL/2.0/>.
|
2020-03-06 17:25:32 +00:00
|
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-06 17:25:32 +00:00
|
|
|
|
|
|
|
|
|
use gst::prelude::*;
|
2021-06-04 17:06:24 +00:00
|
|
|
|
use gst::ClockTime;
|
2020-03-06 17:25:32 +00:00
|
|
|
|
|
2020-11-22 17:21:45 +00:00
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
|
|
2020-03-06 17:25:32 +00:00
|
|
|
|
fn init() {
|
|
|
|
|
use std::sync::Once;
|
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
gstrsclosedcaption::plugin_register_static().unwrap();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_parse() {
|
|
|
|
|
init();
|
|
|
|
|
let data = include_bytes!("dn2018-1217.scc").as_ref();
|
|
|
|
|
|
|
|
|
|
let mut h = gst_check::Harness::new_parse("sccparse ! cea608tott");
|
|
|
|
|
h.set_src_caps_str("application/x-scc");
|
|
|
|
|
h.set_sink_caps_str("text/x-raw");
|
|
|
|
|
|
|
|
|
|
let buf = gst::Buffer::from_mut_slice(Vec::from(data));
|
|
|
|
|
assert_eq!(h.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
|
|
2020-03-20 21:50:26 +00:00
|
|
|
|
// Check the first 4 output buffers
|
2021-06-04 17:06:24 +00:00
|
|
|
|
let expected: [(ClockTime, ClockTime, &'static str); 4] = [
|
2020-03-06 17:25:32 +00:00
|
|
|
|
(
|
2021-06-04 17:06:24 +00:00
|
|
|
|
ClockTime::from_nseconds(15_048_366_666),
|
|
|
|
|
ClockTime::from_nseconds(3_236_566_667),
|
2020-03-06 17:25:32 +00:00
|
|
|
|
"From New York,\r\nthis is Democracy Now!",
|
|
|
|
|
),
|
|
|
|
|
(
|
2021-06-04 17:06:24 +00:00
|
|
|
|
ClockTime::from_nseconds(18_985_633_333),
|
|
|
|
|
ClockTime::from_nseconds(1_234_566_667),
|
2020-03-06 17:25:32 +00:00
|
|
|
|
"Yes, I’m supporting\r\nDonald Trump.",
|
|
|
|
|
),
|
|
|
|
|
(
|
2021-06-04 17:06:24 +00:00
|
|
|
|
ClockTime::from_nseconds(20_220_200_000),
|
|
|
|
|
ClockTime::from_nseconds(2_168_833_333),
|
2020-03-06 17:25:32 +00:00
|
|
|
|
"I’m doing so as enthusiastically\r\nas I can,",
|
|
|
|
|
),
|
|
|
|
|
(
|
2021-06-04 17:06:24 +00:00
|
|
|
|
ClockTime::from_nseconds(22_389_033_333),
|
|
|
|
|
ClockTime::from_nseconds(2_235_566_667),
|
2020-03-06 17:25:32 +00:00
|
|
|
|
"even the fact I think\r\nhe’s a terrible human being.",
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (i, e) in expected.iter().enumerate() {
|
|
|
|
|
let buf = h.try_pull().unwrap();
|
|
|
|
|
|
2021-06-04 17:06:24 +00:00
|
|
|
|
assert_eq!(
|
|
|
|
|
e.0,
|
|
|
|
|
buf.pts().unwrap(),
|
|
|
|
|
"Unexpected PTS for {}th buffer",
|
|
|
|
|
i + 1
|
|
|
|
|
);
|
2020-03-06 17:25:32 +00:00
|
|
|
|
assert_eq!(
|
|
|
|
|
e.1,
|
2021-06-04 17:06:24 +00:00
|
|
|
|
buf.duration().unwrap(),
|
2020-03-06 17:25:32 +00:00
|
|
|
|
"Unexpected duration for {}th buffer",
|
|
|
|
|
i + 1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let data = buf.map_readable().unwrap();
|
2020-03-19 10:55:29 +00:00
|
|
|
|
let s = std::str::from_utf8(&*data)
|
|
|
|
|
.unwrap_or_else(|_| panic!("Non-UTF8 data for {}th buffer", i + 1));
|
2020-03-06 17:25:32 +00:00
|
|
|
|
assert_eq!(e.2, s, "Unexpected data for {}th buffer", i + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let caps = h
|
2021-04-12 12:49:54 +00:00
|
|
|
|
.sinkpad()
|
2020-03-06 17:25:32 +00:00
|
|
|
|
.expect("harness has no sinkpad")
|
2021-04-12 12:49:54 +00:00
|
|
|
|
.current_caps()
|
2020-03-06 17:25:32 +00:00
|
|
|
|
.expect("pad has no caps");
|
|
|
|
|
assert_eq!(
|
|
|
|
|
caps,
|
|
|
|
|
gst::Caps::builder("text/x-raw")
|
2021-11-06 07:34:10 +00:00
|
|
|
|
.field("format", "utf8")
|
2020-03-06 17:25:32 +00:00
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
}
|