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

ffv1dec.rs « tests « ffv1 « video - gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47410eb90a113f2a4abd63387ce82254bc6f3c5a (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
// Copyright (C) 2019 Sebastian Dröge <sebastian@centricular.com>
// Copyright (C) 2021 Arun Raghavan <arun@asymptotic.io>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use gst::glib;
use gst::prelude::*;

use std::fs;
use std::path::PathBuf;

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

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

#[test]
fn test_decode_yuv420p() {
    init();
    test_decode("yuv420p");
}

fn test_decode(name: &str) {
    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    path.push(format!("tests/ffv1_v3_{name}.mkv"));

    let bin = gst::parse_bin_from_description(
        &format!(
            "filesrc location={path:?} ! matroskademux name=m m.video_0 ! ffv1dec name=ffv1dec"
        ),
        false,
    )
    .unwrap();

    let srcpad = bin.by_name("ffv1dec").unwrap().static_pad("src").unwrap();
    let _ = bin.add_pad(&gst::GhostPad::with_target(&srcpad).unwrap());

    let mut h = gst_check::Harness::with_element(&bin, None, Some("src"));

    h.play();

    let buf = h.pull().unwrap();
    let frame = buf.into_mapped_buffer_readable().unwrap();

    let mut refpath = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    refpath.push(format!("tests/ffv1_v3_{name}.ref"));

    let ref_frame = fs::read(refpath).unwrap();

    assert_eq!(frame.len(), ref_frame.len());
    assert_eq!(frame.as_slice(), glib::Bytes::from_owned(ref_frame));
}