2021-03-16 22:43:55 +00:00
|
|
|
// Copyright (C) 2021 Mathieu Duponchelle <mathieu@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/>.
|
2021-03-16 22:43:55 +00:00
|
|
|
//
|
2022-01-15 18:40:12 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2021-03-16 22:43:55 +00:00
|
|
|
|
|
|
|
use gst::prelude::*;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
|
|
|
|
fn init() {
|
|
|
|
use std::sync::Once;
|
|
|
|
static INIT: Once = Once::new();
|
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
gst::init().unwrap();
|
|
|
|
gstrswebp::plugin_register_static().expect("webpenc-rs test");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_decode() {
|
|
|
|
init();
|
|
|
|
let data = include_bytes!("animated.webp").as_ref();
|
|
|
|
let mut h = gst_check::Harness::new("webpdec-rs");
|
|
|
|
|
|
|
|
h.set_src_caps_str("image/webp");
|
|
|
|
|
|
|
|
let buf = gst::Buffer::from_slice(data);
|
|
|
|
assert_eq!(h.push(buf), Ok(gst::FlowSuccess::Ok));
|
|
|
|
h.push_event(gst::event::Eos::new());
|
|
|
|
|
2021-06-04 17:06:24 +00:00
|
|
|
let mut expected_timestamp: Option<gst::ClockTime> = Some(gst::ClockTime::ZERO);
|
2021-03-16 22:43:55 +00:00
|
|
|
let mut count = 0;
|
2021-06-04 17:06:24 +00:00
|
|
|
let expected_duration: Option<gst::ClockTime> = Some(gst::ClockTime::from_nseconds(40_000_000));
|
2021-03-16 22:43:55 +00:00
|
|
|
|
|
|
|
while let Some(buf) = h.try_pull() {
|
2021-04-12 12:49:54 +00:00
|
|
|
assert_eq!(buf.pts(), expected_timestamp);
|
|
|
|
assert_eq!(buf.duration(), expected_duration);
|
2021-03-16 22:43:55 +00:00
|
|
|
|
2021-10-09 10:17:05 +00:00
|
|
|
expected_timestamp = expected_timestamp.opt_add(expected_duration);
|
2021-03-16 22:43:55 +00:00
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(count, 10);
|
|
|
|
|
|
|
|
let caps = h
|
2021-04-12 12:49:54 +00:00
|
|
|
.sinkpad()
|
2021-03-16 22:43:55 +00:00
|
|
|
.expect("harness has no sinkpad")
|
2021-04-12 12:49:54 +00:00
|
|
|
.current_caps()
|
2021-03-16 22:43:55 +00:00
|
|
|
.expect("pad has no caps");
|
|
|
|
assert_eq!(
|
|
|
|
caps,
|
|
|
|
gst_video::VideoInfo::builder(gst_video::VideoFormat::Rgba, 400, 400)
|
|
|
|
.fps((0, 1))
|
|
|
|
.build()
|
|
|
|
.unwrap()
|
|
|
|
.to_caps()
|
|
|
|
.unwrap()
|
|
|
|
);
|
|
|
|
}
|