Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GStreamer
gst-plugins-rs
Commits
8ee1f721
Commit
8ee1f721
authored
Dec 25, 2016
by
Sebastian Dröge
🍵
Browse files
Add support for logging via slog
parent
89b0220e
Changes
22
Hide whitespace changes
Inline
Side-by-side
gst-plugin-file/Cargo.toml
View file @
8ee1f721
...
...
@@ -8,6 +8,7 @@ license = "LGPL-2.1+"
[dependencies]
url
=
"1.1"
gst-plugin
=
{
path
=
"../gst-plugin"
}
slog
=
"1.3"
[lib]
name
=
"gstrsfile"
...
...
gst-plugin-file/src/filesink.rs
View file @
8ee1f721
...
...
@@ -25,6 +25,10 @@ use std::convert::From;
use
gst_plugin
::
error
::
*
;
use
gst_plugin
::
sink
::
*
;
use
gst_plugin
::
buffer
::
*
;
use
gst_plugin
::
utils
::
*
;
use
gst_plugin
::
log
::
*
;
use
slog
::
*
;
#[derive(Debug)]
enum
StreamingState
{
...
...
@@ -35,15 +39,23 @@ enum StreamingState {
#[derive(Debug)]
pub
struct
FileSink
{
streaming_state
:
StreamingState
,
logger
:
Logger
,
}
impl
FileSink
{
pub
fn
new
()
->
FileSink
{
FileSink
{
streaming_state
:
StreamingState
::
Stopped
}
pub
fn
new
(
element
:
Element
)
->
FileSink
{
FileSink
{
streaming_state
:
StreamingState
::
Stopped
,
logger
:
Logger
::
root
(
GstDebugDrain
::
new
(
Some
(
&
element
),
"rsfilesink"
,
0
,
"Rust file sink"
),
None
),
}
}
pub
fn
new_boxed
()
->
Box
<
Sink
>
{
Box
::
new
(
FileSink
::
new
())
pub
fn
new_boxed
(
element
:
Element
)
->
Box
<
Sink
>
{
Box
::
new
(
FileSink
::
new
(
element
))
}
}
...
...
gst-plugin-file/src/filesrc.rs
View file @
8ee1f721
...
...
@@ -23,6 +23,10 @@ use url::Url;
use
gst_plugin
::
error
::
*
;
use
gst_plugin
::
source
::
*
;
use
gst_plugin
::
buffer
::
*
;
use
gst_plugin
::
log
::
*
;
use
gst_plugin
::
utils
::
*
;
use
slog
::
*
;
#[derive(Debug)]
enum
StreamingState
{
...
...
@@ -33,15 +37,23 @@ enum StreamingState {
#[derive(Debug)]
pub
struct
FileSrc
{
streaming_state
:
StreamingState
,
logger
:
Logger
,
}
impl
FileSrc
{
pub
fn
new
()
->
FileSrc
{
FileSrc
{
streaming_state
:
StreamingState
::
Stopped
}
pub
fn
new
(
element
:
Element
)
->
FileSrc
{
FileSrc
{
streaming_state
:
StreamingState
::
Stopped
,
logger
:
Logger
::
root
(
GstDebugDrain
::
new
(
Some
(
&
element
),
"rsfilesrc"
,
0
,
"Rust file source"
),
None
),
}
}
pub
fn
new_boxed
()
->
Box
<
Source
>
{
Box
::
new
(
FileSrc
::
new
())
pub
fn
new_boxed
(
element
:
Element
)
->
Box
<
Source
>
{
Box
::
new
(
FileSrc
::
new
(
element
))
}
}
...
...
gst-plugin-file/src/lib.rs
View file @
8ee1f721
...
...
@@ -19,6 +19,8 @@
extern
crate
url
;
#[macro_use]
extern
crate
slog
;
#[macro_use]
extern
crate
gst_plugin
;
use
gst_plugin
::
plugin
::
*
;
...
...
gst-plugin-file/src/lib.rs.bk
deleted
100644 → 0
View file @
89b0220e
// Copyright (C) 2016 Sebastian Dröge <sebastian@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 St, Fifth Floor,
// Boston, MA 02110-1301, USA.
#![crate_type="cdylib"]
extern crate url;
#[macro_use]
extern crate gst_plugin;
use gst_plugin::plugin::*;
use gst_plugin::source::*;
use gst_plugin::sink::*;
mod filesrc;
mod filesink;
use filesrc::FileSrc;
use filesink::FileSink;
fn plugin_init(plugin: &Plugin) -> bool {
source_register(plugin,
&SourceInfo {
name: "rsfilesrc",
long_name: "File Source",
description: "Reads local files",
classification: "Source/File",
author: "Sebastian Dröge <sebastian@centricular.com>",
rank: 256 + 100,
create_instance: FileSrc::new_boxed,
protocols: "file",
push_only: false,
});
sink_register(plugin,
&SinkInfo {
name: "rsfilesink",
long_name: "File Sink",
description: "Writes to local files",
classification: "Sink/File",
author: "Luis de Bethencourt <luisbg@osg.samsung.com>",
rank: 256 + 100,
create_instance: FileSink::new_boxed,
protocols: "file",
});
true
}
plugin_define!(b"rsfile\0",
b"Rust File Plugin\0",
plugin_init,
b"1.0\0",
b"LGPL\0",
b"rsfile\0",
b"rsfile\0",
b"https://github.com/sdroege/rsplugin\0",
b"2016-12-08\0");
gst-plugin-flv/Cargo.toml
View file @
8ee1f721
...
...
@@ -8,6 +8,7 @@ license = "LGPL-2.1+"
[dependencies]
url
=
"1.1"
gst-plugin
=
{
path
=
"../gst-plugin"
}
slog
=
"1.3"
nom
=
"2.0"
flavors
=
{
git
=
"https://github.com/sdroege/flavors.git"
}
...
...
gst-plugin-flv/src/flvdemux.rs
View file @
8ee1f721
...
...
@@ -27,6 +27,10 @@ use gst_plugin::demuxer::*;
use
gst_plugin
::
buffer
::
*
;
use
gst_plugin
::
adapter
::
*
;
use
gst_plugin
::
utils
;
use
gst_plugin
::
utils
::
Element
;
use
gst_plugin
::
log
::
*
;
use
slog
::
*
;
const
AUDIO_STREAM_ID
:
u32
=
0
;
const
VIDEO_STREAM_ID
:
u32
=
1
;
...
...
@@ -383,6 +387,7 @@ impl Metadata {
#[derive(Debug)]
pub
struct
FlvDemux
{
logger
:
Logger
,
state
:
State
,
adapter
:
Adapter
,
// Only in >= State::Streaming
...
...
@@ -390,16 +395,21 @@ pub struct FlvDemux {
}
impl
FlvDemux
{
pub
fn
new
()
->
FlvDemux
{
pub
fn
new
(
element
:
Element
)
->
FlvDemux
{
FlvDemux
{
logger
:
Logger
::
root
(
GstDebugDrain
::
new
(
Some
(
&
element
),
"rsflvdemux"
,
0
,
"Rust FLV demuxer"
),
None
),
state
:
State
::
Stopped
,
adapter
:
Adapter
::
new
(),
streaming_state
:
None
,
}
}
pub
fn
new_boxed
()
->
Box
<
Demuxer
>
{
Box
::
new
(
FlvDemux
::
new
())
pub
fn
new_boxed
(
element
:
Element
)
->
Box
<
Demuxer
>
{
Box
::
new
(
FlvDemux
::
new
(
element
))
}
fn
handle_script_tag
(
&
mut
self
,
...
...
gst-plugin-flv/src/lib.rs
View file @
8ee1f721
...
...
@@ -21,6 +21,8 @@ extern crate url;
#[macro_use]
extern
crate
gst_plugin
;
#[macro_use]
extern
crate
slog
;
#[macro_use]
extern
crate
nom
;
extern
crate
flavors
;
...
...
gst-plugin-http/Cargo.toml
View file @
8ee1f721
...
...
@@ -9,6 +9,7 @@ license = "LGPL-2.1+"
url
=
"1.1"
gst-plugin
=
{
path
=
"../gst-plugin"
}
reqwest
=
"0.2"
slog
=
"1.3"
[lib]
name
=
"gstrshttp"
...
...
gst-plugin-http/src/httpsrc.rs
View file @
8ee1f721
...
...
@@ -25,6 +25,10 @@ use reqwest::header::{ContentLength, ContentRange, ContentRangeSpec, Range, Byte
use
gst_plugin
::
error
::
*
;
use
gst_plugin
::
source
::
*
;
use
gst_plugin
::
buffer
::
*
;
use
gst_plugin
::
utils
::
*
;
use
gst_plugin
::
log
::
*
;
use
slog
::
*
;
#[derive(Debug)]
enum
StreamingState
{
...
...
@@ -43,19 +47,25 @@ enum StreamingState {
#[derive(Debug)]
pub
struct
HttpSrc
{
streaming_state
:
StreamingState
,
logger
:
Logger
,
client
:
Client
,
}
impl
HttpSrc
{
pub
fn
new
()
->
HttpSrc
{
pub
fn
new
(
element
:
Element
)
->
HttpSrc
{
HttpSrc
{
streaming_state
:
StreamingState
::
Stopped
,
logger
:
Logger
::
root
(
GstDebugDrain
::
new
(
Some
(
&
element
),
"rshttpsink"
,
0
,
"Rust http sink"
),
None
),
client
:
Client
::
new
()
.unwrap
(),
}
}
pub
fn
new_boxed
()
->
Box
<
Source
>
{
Box
::
new
(
HttpSrc
::
new
())
pub
fn
new_boxed
(
element
:
Element
)
->
Box
<
Source
>
{
Box
::
new
(
HttpSrc
::
new
(
element
))
}
fn
do_request
(
&
self
,
...
...
gst-plugin-http/src/lib.rs
View file @
8ee1f721
...
...
@@ -21,6 +21,8 @@ extern crate url;
#[macro_use]
extern
crate
gst_plugin
;
extern
crate
reqwest
;
#[macro_use]
extern
crate
slog
;
use
gst_plugin
::
plugin
::
*
;
use
gst_plugin
::
source
::
*
;
...
...
gst-plugin/Cargo.toml
View file @
8ee1f721
...
...
@@ -10,6 +10,7 @@ license = "LGPL-2.1+"
libc
=
"0.2"
url
=
"1.1"
bitflags
=
"0.7"
slog
=
"1.3"
[build-dependencies]
gcc
=
"0.3"
...
...
gst-plugin/build.rs
View file @
8ee1f721
...
...
@@ -23,7 +23,7 @@ fn main() {
let
gstbase
=
pkg_config
::
probe_library
(
"gstreamer-base-1.0"
)
.unwrap
();
let
includes
=
[
gstreamer
.include_paths
,
gstbase
.include_paths
];
let
files
=
[
"src/error.c"
,
"src/buffer.c"
,
"src/source.c"
,
"src/sink.c"
,
"src/demuxer.c"
];
let
files
=
[
"src/error.c"
,
"src/buffer.c"
,
"src/log.c"
,
"src/source.c"
,
"src/sink.c"
,
"src/demuxer.c"
];
let
mut
config
=
gcc
::
Config
::
new
();
config
.include
(
"src"
);
...
...
gst-plugin/src/demuxer.rs
View file @
8ee1f721
...
...
@@ -343,9 +343,10 @@ impl DemuxerWrapper {
#[no_mangle]
pub
extern
"C"
fn
demuxer_new
(
demuxer
:
*
mut
c_void
,
create_instance
:
fn
()
->
Box
<
Demuxer
>
)
create_instance
:
fn
(
Element
)
->
Box
<
Demuxer
>
)
->
*
mut
DemuxerWrapper
{
Box
::
into_raw
(
Box
::
new
(
DemuxerWrapper
::
new
(
demuxer
,
create_instance
())))
let
instance
=
create_instance
(
unsafe
{
Element
::
new
(
demuxer
)
});
Box
::
into_raw
(
Box
::
new
(
DemuxerWrapper
::
new
(
demuxer
,
instance
)))
}
#[no_mangle]
...
...
@@ -451,7 +452,7 @@ pub struct DemuxerInfo<'a> {
pub
classification
:
&
'a
str
,
pub
author
:
&
'a
str
,
pub
rank
:
i32
,
pub
create_instance
:
fn
()
->
Box
<
Demuxer
>
,
pub
create_instance
:
fn
(
Element
)
->
Box
<
Demuxer
>
,
pub
input_formats
:
&
'a
str
,
pub
output_formats
:
&
'a
str
,
}
...
...
@@ -480,7 +481,7 @@ pub fn demuxer_register(plugin: &Plugin, demuxer_info: &DemuxerInfo) {
let
coutput_formats
=
CString
::
new
(
demuxer_info
.output_formats
)
.unwrap
();
unsafe
{
gst_rs_demuxer_register
(
plugin
.
to_raw
(),
gst_rs_demuxer_register
(
plugin
.
as_ptr
(),
cname
.as_ptr
(),
clong_name
.as_ptr
(),
cdescription
.as_ptr
(),
...
...
gst-plugin/src/error.c
View file @
8ee1f721
...
...
@@ -26,4 +26,3 @@ gst_rs_element_error (GstElement * element, GQuark error_domain,
gst_element_message_full
(
element
,
GST_MESSAGE_ERROR
,
error_domain
,
error_code
,
g_strdup
(
message
),
g_strdup
(
debug
),
file
,
function
,
line
);
}
gst-plugin/src/lib.rs
View file @
8ee1f721
...
...
@@ -20,6 +20,8 @@ extern crate libc;
extern
crate
url
;
#[macro_use]
extern
crate
bitflags
;
#[macro_use]
extern
crate
slog
;
#[macro_use]
pub
mod
utils
;
...
...
@@ -32,4 +34,4 @@ pub mod plugin;
pub
mod
source
;
pub
mod
sink
;
pub
mod
demuxer
;
pub
mod
log
;
gst-plugin/src/log.c
0 → 100644
View file @
8ee1f721
/* Copyright (C) 2016 Sebastian Dröge <sebastian@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 St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include
<gst/gst.h>
void
gst_rs_debug_log
(
GstDebugCategory
*
category
,
GstDebugLevel
level
,
const
gchar
*
file
,
const
gchar
*
function
,
gint
line
,
GObject
*
object
,
const
gchar
*
message
)
{
gst_debug_log
(
category
,
level
,
file
,
function
,
line
,
object
,
"%s"
,
message
);
}
gst-plugin/src/log.rs
0 → 100644
View file @
8ee1f721
// Copyright (C) 2016 Sebastian Dröge <sebastian@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 St, Fifth Floor,
// Boston, MA 02110-1301, USA.
use
std
::
os
::
raw
::
c_void
;
use
libc
::
c_char
;
use
std
::
ffi
::
CString
;
use
slog
::{
Drain
,
Record
,
OwnedKeyValueList
,
Never
,
Level
};
use
std
::
fmt
;
use
std
::
ptr
;
use
utils
::
Element
;
#[derive(Debug)]
pub
struct
GstDebugDrain
{
category
:
*
const
c_void
,
element
:
*
const
c_void
,
}
impl
GstDebugDrain
{
pub
fn
new
(
element
:
Option
<&
Element
>
,
name
:
&
str
,
color
:
u32
,
description
:
&
str
)
->
GstDebugDrain
{
extern
"C"
{
fn
_gst_debug_category_new
(
name
:
*
const
c_char
,
color
:
u32
,
description
:
*
const
c_char
)
->
*
const
c_void
;
}
let
name_cstr
=
CString
::
new
(
name
.as_bytes
())
.unwrap
();
let
description_cstr
=
CString
::
new
(
description
.as_bytes
())
.unwrap
();
// Gets the category if it exists already
let
category
=
unsafe
{
_gst_debug_category_new
(
name_cstr
.as_ptr
(),
color
,
description_cstr
.as_ptr
())
};
let
element
=
match
element
{
Some
(
element
)
=>
unsafe
{
element
.as_ptr
()
},
None
=>
ptr
::
null
(),
};
let
drain
=
GstDebugDrain
{
category
:
category
,
element
:
ptr
::
null
(),
};
extern
"C"
{
fn
g_weak_ref_set
(
weak_ref
:
&*
const
c_void
,
obj
:
*
const
c_void
);
}
if
!
element
.is_null
()
{
unsafe
{
g_weak_ref_set
(
&
drain
.element
,
element
);
}
}
drain
}
}
impl
Drop
for
GstDebugDrain
{
fn
drop
(
&
mut
self
)
{
extern
"C"
{
fn
g_weak_ref_clear
(
weak_ref
:
&*
const
c_void
);
}
if
!
self
.element
.is_null
()
{
unsafe
{
g_weak_ref_clear
(
&
self
.element
);
}
}
}
}
impl
Drain
for
GstDebugDrain
{
type
Error
=
Never
;
fn
log
(
&
self
,
record
:
&
Record
,
_
:
&
OwnedKeyValueList
)
->
Result
<
(),
Never
>
{
extern
"C"
{
fn
gst_rs_debug_log
(
category
:
*
const
c_void
,
level
:
u32
,
file
:
*
const
c_char
,
function
:
*
const
c_char
,
line
:
u32
,
object
:
*
const
c_void
,
message
:
*
const
c_char
);
}
let
file_cstr
=
CString
::
new
(
record
.file
()
.as_bytes
())
.unwrap
();
// TODO: Probably want to include module?
let
function_cstr
=
CString
::
new
(
record
.function
()
.as_bytes
())
.unwrap
();
let
message_cstr
=
CString
::
new
(
fmt
::
format
(
record
.msg
())
.as_bytes
())
.unwrap
();
let
level
=
match
record
.level
()
{
Level
::
Critical
|
Level
::
Error
=>
1
,
Level
::
Warning
=>
2
,
Level
::
Info
=>
4
,
Level
::
Debug
=>
5
,
Level
::
Trace
=>
7
,
};
extern
"C"
{
fn
g_weak_ref_get
(
weak_ref
:
&*
const
c_void
)
->
*
const
c_void
;
fn
gst_object_unref
(
obj
:
*
const
c_void
);
}
unsafe
{
let
element
=
if
self
.element
.is_null
()
{
ptr
::
null
()
}
else
{
g_weak_ref_get
(
&
self
.element
)
};
gst_rs_debug_log
(
self
.category
,
level
,
file_cstr
.as_ptr
(),
function_cstr
.as_ptr
(),
record
.line
(),
element
,
message_cstr
.as_ptr
());
if
!
element
.is_null
()
{
gst_object_unref
(
element
);
}
}
Ok
(())
}
}
unsafe
impl
Sync
for
GstDebugDrain
{}
unsafe
impl
Send
for
GstDebugDrain
{}
gst-plugin/src/plugin.rs
View file @
8ee1f721
...
...
@@ -25,7 +25,7 @@ impl Plugin {
Plugin
(
plugin
)
}
pub
unsafe
fn
to_raw
(
&
self
)
->
*
const
c_void
{
pub
unsafe
fn
as_ptr
(
&
self
)
->
*
const
c_void
{
self
.0
}
}
...
...
gst-plugin/src/sink.rs
View file @
8ee1f721
...
...
@@ -177,9 +177,10 @@ impl SinkWrapper {
#[no_mangle]
pub
extern
"C"
fn
sink_new
(
sink
:
*
mut
c_void
,
create_instance
:
fn
()
->
Box
<
Sink
>
)
create_instance
:
fn
(
Element
)
->
Box
<
Sink
>
)
->
*
mut
SinkWrapper
{
Box
::
into_raw
(
Box
::
new
(
SinkWrapper
::
new
(
sink
,
create_instance
())))
let
instance
=
create_instance
(
unsafe
{
Element
::
new
(
sink
)
});
Box
::
into_raw
(
Box
::
new
(
SinkWrapper
::
new
(
sink
,
instance
)))
}
#[no_mangle]
...
...
@@ -258,7 +259,7 @@ pub struct SinkInfo<'a> {
pub
classification
:
&
'a
str
,
pub
author
:
&
'a
str
,
pub
rank
:
i32
,
pub
create_instance
:
fn
()
->
Box
<
Sink
>
,
pub
create_instance
:
fn
(
Element
)
->
Box
<
Sink
>
,
pub
protocols
:
&
'a
str
,
}
...
...
@@ -284,7 +285,7 @@ pub fn sink_register(plugin: &Plugin, sink_info: &SinkInfo) {
let
cprotocols
=
CString
::
new
(
sink_info
.protocols
)
.unwrap
();
unsafe
{
gst_rs_sink_register
(
plugin
.
to_raw
(),
gst_rs_sink_register
(
plugin
.
as_ptr
(),
cname
.as_ptr
(),
clong_name
.as_ptr
(),
cdescription
.as_ptr
(),
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment