gst-plugins-rs/src/lib.rs

240 lines
8.7 KiB
Rust
Raw Normal View History

2016-05-15 15:54:09 +00:00
// Copyright (C) 2016 Sebastian Dröge <sebastian@centricular.com>
// 2016 Luis de Bethencourt <luisbg@osg.samsung.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 St, Fifth Floor,
// Boston, MA 02110-1301, USA.
2016-08-22 20:03:45 +00:00
#![crate_type="cdylib"]
2016-05-13 13:35:48 +00:00
2016-05-13 15:02:19 +00:00
extern crate libc;
2016-05-14 09:34:50 +00:00
extern crate url;
2016-11-14 18:57:54 +00:00
extern crate reqwest;
#[macro_use]
extern crate bitflags;
2016-11-24 14:29:43 +00:00
#[macro_use]
extern crate nom;
extern crate flavors;
2016-05-13 15:02:19 +00:00
#[macro_use]
pub mod utils;
#[macro_use]
pub mod error;
pub mod buffer;
pub mod adapter;
pub mod rssource;
pub mod rssink;
2016-05-13 13:35:48 +00:00
pub mod rsfilesrc;
pub mod rshttpsrc;
2016-05-13 15:07:26 +00:00
pub mod rsfilesink;
2016-11-24 14:29:43 +00:00
pub mod rsdemuxer;
pub mod flvdemux;
use utils::*;
use rsfilesrc::FileSrc;
use rshttpsrc::HttpSrc;
use rsfilesink::FileSink;
2016-11-24 14:29:43 +00:00
use flvdemux::FlvDemux;
use std::os::raw::c_void;
2016-05-15 13:15:58 +00:00
use libc::c_char;
use std::ffi::CString;
2016-08-22 20:03:06 +00:00
unsafe fn source_register(plugin: *const c_void,
name: &str,
long_name: &str,
description: &str,
classification: &str,
author: &str,
rank: i32,
create_instance: *const c_void,
protocols: &str,
push_only: bool) {
extern "C" {
fn gst_rs_source_register(plugin: *const c_void,
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: *const c_void,
protocols: *const c_char,
push_only: GBoolean)
-> GBoolean;
}
2016-08-22 20:03:06 +00:00
let cname = CString::new(name).unwrap();
let clong_name = CString::new(long_name).unwrap();
let cdescription = CString::new(description).unwrap();
let cclassification = CString::new(classification).unwrap();
let cauthor = CString::new(author).unwrap();
let cprotocols = CString::new(protocols).unwrap();
gst_rs_source_register(plugin,
cname.as_ptr(),
clong_name.as_ptr(),
cdescription.as_ptr(),
cclassification.as_ptr(),
cauthor.as_ptr(),
rank,
create_instance,
cprotocols.as_ptr(),
GBoolean::from_bool(push_only));
}
#[no_mangle]
2016-08-22 20:03:06 +00:00
pub unsafe extern "C" fn sources_register(plugin: *const c_void) -> GBoolean {
source_register(plugin,
"rsfilesrc",
"File Source",
"Reads local files",
"Source/File",
"Sebastian Dröge <sebastian@centricular.com>",
256 + 100,
FileSrc::new_boxed as *const c_void,
"file",
false);
source_register(plugin,
"rshttpsrc",
"HTTP Source",
"Read HTTP/HTTPS files",
"Source/Network/HTTP",
"Sebastian Dröge <sebastian@centricular.com>",
256 + 100,
HttpSrc::new_boxed as *const c_void,
"http:https",
true);
GBoolean::True
}
unsafe fn sink_register(plugin: *const c_void,
name: &str,
long_name: &str,
description: &str,
classification: &str,
author: &str,
rank: i32,
create_instance: *const c_void,
protocols: &str) {
extern "C" {
fn gst_rs_sink_register(plugin: *const c_void,
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: *const c_void,
protocols: *const c_char)
-> GBoolean;
}
2016-08-22 20:03:06 +00:00
let cname = CString::new(name).unwrap();
let clong_name = CString::new(long_name).unwrap();
let cdescription = CString::new(description).unwrap();
let cclassification = CString::new(classification).unwrap();
let cauthor = CString::new(author).unwrap();
let cprotocols = CString::new(protocols).unwrap();
gst_rs_sink_register(plugin,
cname.as_ptr(),
clong_name.as_ptr(),
cdescription.as_ptr(),
cclassification.as_ptr(),
cauthor.as_ptr(),
rank,
create_instance,
cprotocols.as_ptr());
}
#[no_mangle]
2016-08-22 20:03:06 +00:00
pub unsafe extern "C" fn sinks_register(plugin: *const c_void) -> GBoolean {
sink_register(plugin,
"rsfilesink",
"File Sink",
"Writes to local files",
"Sink/File",
"Luis de Bethencourt <luisbg@osg.samsung.com>",
256 + 100,
FileSink::new_boxed as *const c_void,
"file");
GBoolean::True
}
2016-11-24 14:29:43 +00:00
unsafe fn demuxer_register(plugin: *const c_void,
name: &str,
long_name: &str,
description: &str,
classification: &str,
author: &str,
rank: i32,
create_instance: *const c_void,
input_format: &str,
output_formats: &str) {
extern "C" {
fn gst_rs_demuxer_register(plugin: *const c_void,
name: *const c_char,
long_name: *const c_char,
description: *const c_char,
classification: *const c_char,
author: *const c_char,
rank: i32,
create_instance: *const c_void,
input_format: *const c_char,
output_formats: *const c_char)
-> GBoolean;
}
let cname = CString::new(name).unwrap();
let clong_name = CString::new(long_name).unwrap();
let cdescription = CString::new(description).unwrap();
let cclassification = CString::new(classification).unwrap();
let cauthor = CString::new(author).unwrap();
let cinput_format = CString::new(input_format).unwrap();
let coutput_formats = CString::new(output_formats).unwrap();
gst_rs_demuxer_register(plugin,
cname.as_ptr(),
clong_name.as_ptr(),
cdescription.as_ptr(),
cclassification.as_ptr(),
cauthor.as_ptr(),
rank,
create_instance,
cinput_format.as_ptr(),
coutput_formats.as_ptr());
}
#[no_mangle]
pub unsafe extern "C" fn demuxers_register(plugin: *const c_void) -> GBoolean {
demuxer_register(plugin,
"rsflvdemux",
"FLV Demuxer",
"Demuxes FLV Streams",
"Codec/Demuxer",
"Sebastian Dröge <sebastian@centricular.com>",
256 + 100,
FlvDemux::new_boxed as *const c_void,
"video/x-flv",
"ANY");
GBoolean::True
}