2019-05-01 11:09:16 +00:00
|
|
|
// Copyright (C) 2019 Guillaume Desmottes <guillaume.desmottes@collabora.com>
|
|
|
|
//
|
|
|
|
// 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.
|
2022-01-15 19:18:47 +00:00
|
|
|
//
|
2022-03-14 08:22:53 +00:00
|
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
2019-05-01 11:09:16 +00:00
|
|
|
|
2020-04-24 10:55:01 +00:00
|
|
|
use gst::prelude::*;
|
|
|
|
use std::path::PathBuf;
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
fn init() {
|
2019-07-11 13:41:42 +00:00
|
|
|
use std::sync::Once;
|
|
|
|
static INIT: Once = Once::new();
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
INIT.call_once(|| {
|
|
|
|
gst::init().unwrap();
|
2019-05-29 06:10:08 +00:00
|
|
|
gstcdg::plugin_register_static().expect("cdgdec tests");
|
2019-05-01 11:09:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_cdgdec() {
|
|
|
|
init();
|
|
|
|
|
2023-02-25 17:30:26 +00:00
|
|
|
let pipeline = gst::Pipeline::with_name("cdgdec-test");
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
let input_path = {
|
|
|
|
let mut r = PathBuf::new();
|
|
|
|
r.push(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
r.push("tests");
|
|
|
|
r.push("BrotherJohn");
|
|
|
|
r.set_extension("cdg");
|
|
|
|
r
|
|
|
|
};
|
|
|
|
|
2020-05-01 08:28:31 +00:00
|
|
|
// Ensure we are in push mode so 'blocksize' prop is used
|
2022-10-19 16:18:43 +00:00
|
|
|
let filesrc = gst::ElementFactory::make("pushfilesrc")
|
|
|
|
.property("location", input_path.to_str().unwrap())
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2020-05-01 08:28:31 +00:00
|
|
|
{
|
|
|
|
let child_proxy = filesrc.dynamic_cast_ref::<gst::ChildProxy>().unwrap();
|
2021-11-20 08:47:02 +00:00
|
|
|
child_proxy.set_child_property("real-filesrc::num-buffers", 1);
|
2020-05-01 08:28:31 +00:00
|
|
|
let blocksize: u32 = 24; // One CDG instruction
|
2021-11-20 08:47:02 +00:00
|
|
|
child_proxy.set_child_property("real-filesrc::blocksize", blocksize);
|
2020-05-01 08:28:31 +00:00
|
|
|
}
|
2019-05-01 11:09:16 +00:00
|
|
|
|
2022-10-19 16:18:43 +00:00
|
|
|
let parse = gst::ElementFactory::make("cdgparse").build().unwrap();
|
|
|
|
let dec = gst::ElementFactory::make("cdgdec").build().unwrap();
|
2022-10-22 16:06:29 +00:00
|
|
|
let sink = gst_app::AppSink::builder().build();
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
pipeline
|
2023-03-09 14:46:52 +00:00
|
|
|
.add_many([&filesrc, &parse, &dec, sink.upcast_ref()])
|
2019-05-01 11:09:16 +00:00
|
|
|
.expect("failed to add elements to the pipeline");
|
2023-03-09 14:46:52 +00:00
|
|
|
gst::Element::link_many([&filesrc, &parse, &dec, sink.upcast_ref()])
|
2022-10-22 16:06:29 +00:00
|
|
|
.expect("failed to link the elements");
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
sink.set_callbacks(
|
2020-06-25 16:49:07 +00:00
|
|
|
gst_app::AppSinkCallbacks::builder()
|
2019-05-01 11:09:16 +00:00
|
|
|
// Add a handler to the "new-sample" signal.
|
|
|
|
.new_sample(move |appsink| {
|
|
|
|
// Pull the sample in question out of the appsink's buffer.
|
2019-12-18 05:50:10 +00:00
|
|
|
let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?;
|
2021-04-12 12:49:54 +00:00
|
|
|
let buffer = sample.buffer().ok_or(gst::FlowError::Error)?;
|
2019-12-18 05:50:10 +00:00
|
|
|
let map = buffer.map_readable().map_err(|_| gst::FlowError::Error)?;
|
2019-05-01 11:09:16 +00:00
|
|
|
|
|
|
|
// First frame fully blue
|
|
|
|
map.as_slice()
|
|
|
|
.chunks_exact(4)
|
|
|
|
.for_each(|p| assert_eq!(p, [0, 0, 136, 255]));
|
|
|
|
|
|
|
|
Ok(gst::FlowSuccess::Ok)
|
|
|
|
})
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Playing)
|
|
|
|
.expect("Unable to set the pipeline to the `Playing` state");
|
|
|
|
|
2021-04-12 12:49:54 +00:00
|
|
|
let bus = pipeline.bus().unwrap();
|
2021-06-04 17:06:24 +00:00
|
|
|
for msg in bus.iter_timed(gst::ClockTime::NONE) {
|
2019-05-01 11:09:16 +00:00
|
|
|
use gst::MessageView;
|
|
|
|
match msg.view() {
|
|
|
|
MessageView::Error(err) => {
|
|
|
|
eprintln!(
|
|
|
|
"Error received from element {:?}: {}",
|
2021-04-12 12:49:54 +00:00
|
|
|
err.src().map(|s| s.path_string()),
|
|
|
|
err.error()
|
2019-05-01 11:09:16 +00:00
|
|
|
);
|
2021-04-12 12:49:54 +00:00
|
|
|
eprintln!("Debugging information: {:?}", err.debug());
|
2019-12-22 09:18:30 +00:00
|
|
|
unreachable!();
|
2019-05-01 11:09:16 +00:00
|
|
|
}
|
|
|
|
MessageView::Eos(..) => break,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline
|
|
|
|
.set_state(gst::State::Null)
|
|
|
|
.expect("Unable to set the pipeline to the `Null` state");
|
|
|
|
}
|