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

webpdec.rs « tests « webp « video - gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cdf51ab77ca4033a5d84cd4cb93986dc4c8929e7 (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
// Copyright (C) 2021 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.

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());

    let mut expected_timestamp: gst::ClockTime = 0.into();
    let mut count = 0;
    let expected_duration: gst::ClockTime = 40_000_000.into();

    while let Some(buf) = h.try_pull() {
        assert_eq!(buf.get_pts(), expected_timestamp);
        assert_eq!(buf.get_duration(), expected_duration);

        expected_timestamp += expected_duration;
        count += 1;
    }

    assert_eq!(count, 10);

    let caps = h
        .get_sinkpad()
        .expect("harness has no sinkpad")
        .get_current_caps()
        .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()
    );
}