Update to slog 2.0

This commit is contained in:
Sebastian Dröge 2017-04-12 16:44:34 +03:00
parent 0cf169aa20
commit 021de8af1f
13 changed files with 118 additions and 76 deletions

View file

@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
[dependencies] [dependencies]
url = "1.1" url = "1.1"
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
slog = "1.3" slog = "2.0"
[lib] [lib]
name = "gstrsfile" name = "gstrsfile"

View file

@ -19,7 +19,7 @@ use gst_plugin::buffer::*;
use gst_plugin::utils::*; use gst_plugin::utils::*;
use gst_plugin::log::*; use gst_plugin::log::*;
use slog::*; use slog::Logger;
#[derive(Debug)] #[derive(Debug)]
enum StreamingState { enum StreamingState {
@ -41,7 +41,7 @@ impl FileSink {
"rsfilesink", "rsfilesink",
0, 0,
"Rust file sink"), "Rust file sink"),
None), o!()),
} }
} }

View file

@ -17,7 +17,7 @@ use gst_plugin::buffer::*;
use gst_plugin::log::*; use gst_plugin::log::*;
use gst_plugin::utils::*; use gst_plugin::utils::*;
use slog::*; use slog::Logger;
#[derive(Debug)] #[derive(Debug)]
enum StreamingState { enum StreamingState {
@ -39,7 +39,7 @@ impl FileSrc {
"rsfilesrc", "rsfilesrc",
0, 0,
"Rust file source"), "Rust file source"),
None), o!()),
} }
} }

View file

@ -8,7 +8,7 @@ license = "MIT/Apache-2.0"
[dependencies] [dependencies]
url = "1.1" url = "1.1"
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
slog = "1.3" slog = "2.0"
nom = "2.0" nom = "2.0"
flavors = {git = "https://github.com/Geal/flavors.git"} flavors = {git = "https://github.com/Geal/flavors.git"}

View file

@ -26,7 +26,7 @@ use gst_plugin::miniobject::*;
use gst_plugin::value::Rational32; use gst_plugin::value::Rational32;
use gst_plugin::bytes::*; use gst_plugin::bytes::*;
use slog::*; use slog::Logger;
const AUDIO_STREAM_ID: u32 = 0; const AUDIO_STREAM_ID: u32 = 0;
const VIDEO_STREAM_ID: u32 = 1; const VIDEO_STREAM_ID: u32 = 1;
@ -177,7 +177,9 @@ impl AudioFormat {
flavors::SoundFormat::PCM_ALAW => Some(Caps::new_simple("audio/x-alaw", &[])), flavors::SoundFormat::PCM_ALAW => Some(Caps::new_simple("audio/x-alaw", &[])),
flavors::SoundFormat::PCM_ULAW => Some(Caps::new_simple("audio/x-mulaw", &[])), flavors::SoundFormat::PCM_ULAW => Some(Caps::new_simple("audio/x-mulaw", &[])),
flavors::SoundFormat::AAC => { flavors::SoundFormat::AAC => {
self.aac_sequence_header.as_ref().map(|header| { self.aac_sequence_header
.as_ref()
.map(|header| {
Caps::new_simple("audio/mpeg", Caps::new_simple("audio/mpeg",
&[("mpegversion", &4.into()), &[("mpegversion", &4.into()),
("framed", &true.into()), ("framed", &true.into()),
@ -236,16 +238,19 @@ impl AudioFormat {
}; };
if self.rate != 0 { if self.rate != 0 {
caps.as_mut().map(|c| { caps.as_mut()
c.get_mut().unwrap().set_simple(&[("rate", .map(|c| {
&(self.rate as i32).into())]) c.get_mut()
.unwrap()
.set_simple(&[("rate", &(self.rate as i32).into())])
}); });
} }
if self.channels != 0 { if self.channels != 0 {
caps.as_mut().map(|c| { caps.as_mut()
c.get_mut().unwrap().set_simple(&[("channels", .map(|c| {
&(self.channels as i32) c.get_mut()
.into())]) .unwrap()
.set_simple(&[("channels", &(self.channels as i32).into())])
}); });
} }
@ -273,7 +278,9 @@ impl VideoFormat {
format: data_header.codec_id, format: data_header.codec_id,
width: metadata.as_ref().and_then(|m| m.video_width), width: metadata.as_ref().and_then(|m| m.video_width),
height: metadata.as_ref().and_then(|m| m.video_height), height: metadata.as_ref().and_then(|m| m.video_height),
pixel_aspect_ratio: metadata.as_ref().and_then(|m| m.video_pixel_aspect_ratio), pixel_aspect_ratio: metadata
.as_ref()
.and_then(|m| m.video_pixel_aspect_ratio),
framerate: metadata.as_ref().and_then(|m| m.video_framerate), framerate: metadata.as_ref().and_then(|m| m.video_framerate),
bitrate: metadata.as_ref().and_then(|m| m.video_bitrate), bitrate: metadata.as_ref().and_then(|m| m.video_bitrate),
avc_sequence_header: avc_sequence_header.clone(), avc_sequence_header: avc_sequence_header.clone(),
@ -325,7 +332,9 @@ impl VideoFormat {
flavors::CodecId::VP6A => Some(Caps::new_simple("video/x-vp6-flash-alpha", &[])), flavors::CodecId::VP6A => Some(Caps::new_simple("video/x-vp6-flash-alpha", &[])),
flavors::CodecId::SCREEN2 => Some(Caps::new_simple("video/x-flash-screen2", &[])), flavors::CodecId::SCREEN2 => Some(Caps::new_simple("video/x-flash-screen2", &[])),
flavors::CodecId::H264 => { flavors::CodecId::H264 => {
self.avc_sequence_header.as_ref().map(|header| { self.avc_sequence_header
.as_ref()
.map(|header| {
Caps::new_simple("video/x-h264", Caps::new_simple("video/x-h264",
&[("stream-format", &"avc".into()), &[("stream-format", &"avc".into()),
("codec_data", &header.as_ref().into())]) ("codec_data", &header.as_ref().into())])
@ -344,27 +353,33 @@ impl VideoFormat {
}; };
if let (Some(width), Some(height)) = (self.width, self.height) { if let (Some(width), Some(height)) = (self.width, self.height) {
caps.as_mut().map(|c| { caps.as_mut()
c.get_mut().unwrap().set_simple(&[("width", .map(|c| {
&(width as i32).into()), c.get_mut()
("height", .unwrap()
&(height as i32).into())]) .set_simple(&[("width", &(width as i32).into()),
("height", &(height as i32).into())])
}); });
} }
if let Some(par) = self.pixel_aspect_ratio { if let Some(par) = self.pixel_aspect_ratio {
if *par.numer() != 0 && par.numer() != par.denom() { if *par.numer() != 0 && par.numer() != par.denom() {
caps.as_mut().map(|c| { caps.as_mut()
c.get_mut().unwrap().set_simple(&[("pixel-aspect-ratio", .map(|c| {
&par.into())]) c.get_mut()
.unwrap()
.set_simple(&[("pixel-aspect-ratio", &par.into())])
}); });
} }
} }
if let Some(fps) = self.framerate { if let Some(fps) = self.framerate {
if *fps.numer() != 0 { if *fps.numer() != 0 {
caps.as_mut().map(|c| { caps.as_mut()
c.get_mut().unwrap().set_simple(&[("framerate", &fps.into())]) .map(|c| {
c.get_mut()
.unwrap()
.set_simple(&[("framerate", &fps.into())])
}); });
} }
} }
@ -498,7 +513,7 @@ impl FlvDemux {
"rsflvdemux", "rsflvdemux",
0, 0,
"Rust FLV demuxer"), "Rust FLV demuxer"),
None), o!()),
state: State::Stopped, state: State::Stopped,
adapter: Adapter::new(), adapter: Adapter::new(),
streaming_state: None, streaming_state: None,
@ -518,7 +533,9 @@ impl FlvDemux {
self.adapter.flush(15).unwrap(); self.adapter.flush(15).unwrap();
let buffer = self.adapter.get_buffer(tag_header.data_size as usize).unwrap(); let buffer = self.adapter
.get_buffer(tag_header.data_size as usize)
.unwrap();
let map = buffer.map_read().unwrap(); let map = buffer.map_read().unwrap();
let data = map.as_slice(); let data = map.as_slice();
@ -531,11 +548,13 @@ impl FlvDemux {
let streaming_state = self.streaming_state.as_mut().unwrap(); let streaming_state = self.streaming_state.as_mut().unwrap();
let audio_changed = streaming_state.audio let audio_changed = streaming_state
.audio
.as_mut() .as_mut()
.map(|a| a.update_with_metadata(&metadata)) .map(|a| a.update_with_metadata(&metadata))
.unwrap_or(false); .unwrap_or(false);
let video_changed = streaming_state.video let video_changed = streaming_state
.video
.as_mut() .as_mut()
.map(|v| v.update_with_metadata(&metadata)) .map(|v| v.update_with_metadata(&metadata))
.unwrap_or(false); .unwrap_or(false);
@ -630,7 +649,9 @@ impl FlvDemux {
if data_header.sound_format == flavors::SoundFormat::AAC { if data_header.sound_format == flavors::SoundFormat::AAC {
// Not big enough for the AAC packet header, ship! // Not big enough for the AAC packet header, ship!
if tag_header.data_size < 1 + 1 { if tag_header.data_size < 1 + 1 {
self.adapter.flush(15 + tag_header.data_size as usize).unwrap(); self.adapter
.flush(15 + tag_header.data_size as usize)
.unwrap();
warn!(self.logger, warn!(self.logger,
"Too small packet for AAC packet header {}", "Too small packet for AAC packet header {}",
15 + tag_header.data_size); 15 + tag_header.data_size);
@ -672,7 +693,9 @@ impl FlvDemux {
let streaming_state = self.streaming_state.as_ref().unwrap(); let streaming_state = self.streaming_state.as_ref().unwrap();
if streaming_state.audio == None { if streaming_state.audio == None {
self.adapter.flush((tag_header.data_size + 15) as usize).unwrap(); self.adapter
.flush((tag_header.data_size + 15) as usize)
.unwrap();
return Ok(HandleBufferResult::Again); return Ok(HandleBufferResult::Again);
} }
@ -689,7 +712,9 @@ impl FlvDemux {
} }
if tag_header.data_size < offset { if tag_header.data_size < offset {
self.adapter.flush((tag_header.data_size - 1) as usize).unwrap(); self.adapter
.flush((tag_header.data_size - 1) as usize)
.unwrap();
return Ok(HandleBufferResult::Again); return Ok(HandleBufferResult::Again);
} }
@ -697,8 +722,9 @@ impl FlvDemux {
self.adapter.flush(offset as usize).unwrap(); self.adapter.flush(offset as usize).unwrap();
} }
let mut buffer = let mut buffer = self.adapter
self.adapter.get_buffer((tag_header.data_size - 1 - offset) as usize).unwrap(); .get_buffer((tag_header.data_size - 1 - offset) as usize)
.unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
@ -775,7 +801,9 @@ impl FlvDemux {
if data_header.codec_id == flavors::CodecId::H264 { if data_header.codec_id == flavors::CodecId::H264 {
// Not big enough for the AVC packet header, ship! // Not big enough for the AVC packet header, ship!
if tag_header.data_size < 1 + 4 { if tag_header.data_size < 1 + 4 {
self.adapter.flush(15 + tag_header.data_size as usize).unwrap(); self.adapter
.flush(15 + tag_header.data_size as usize)
.unwrap();
warn!(self.logger, warn!(self.logger,
"Too small packet for AVC packet header {}", "Too small packet for AVC packet header {}",
15 + tag_header.data_size); 15 + tag_header.data_size);
@ -811,7 +839,9 @@ impl FlvDemux {
} }
flavors::AVCPacketType::EndOfSequence => { flavors::AVCPacketType::EndOfSequence => {
// Skip // Skip
self.adapter.flush(15 + tag_header.data_size as usize).unwrap(); self.adapter
.flush(15 + tag_header.data_size as usize)
.unwrap();
return Ok(HandleBufferResult::Again); return Ok(HandleBufferResult::Again);
} }
} }
@ -822,7 +852,9 @@ impl FlvDemux {
let streaming_state = self.streaming_state.as_ref().unwrap(); let streaming_state = self.streaming_state.as_ref().unwrap();
if streaming_state.video == None { if streaming_state.video == None {
self.adapter.flush((tag_header.data_size + 15) as usize).unwrap(); self.adapter
.flush((tag_header.data_size + 15) as usize)
.unwrap();
return Ok(HandleBufferResult::Again); return Ok(HandleBufferResult::Again);
} }
@ -843,7 +875,9 @@ impl FlvDemux {
} }
if tag_header.data_size < offset { if tag_header.data_size < offset {
self.adapter.flush((tag_header.data_size - 1) as usize).unwrap(); self.adapter
.flush((tag_header.data_size - 1) as usize)
.unwrap();
return Ok(HandleBufferResult::Again); return Ok(HandleBufferResult::Again);
} }
@ -851,8 +885,9 @@ impl FlvDemux {
self.adapter.flush(offset as usize).unwrap(); self.adapter.flush(offset as usize).unwrap();
} }
let mut buffer = let mut buffer = self.adapter
self.adapter.get_buffer((tag_header.data_size - 1 - offset) as usize).unwrap(); .get_buffer((tag_header.data_size - 1 - offset) as usize)
.unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
@ -919,7 +954,11 @@ impl FlvDemux {
Ok(HandleBufferResult::NeedMoreData) Ok(HandleBufferResult::NeedMoreData)
} }
State::Skipping { audio, video, skip_left: 0 } => { State::Skipping {
audio,
video,
skip_left: 0,
} => {
self.state = State::Streaming; self.state = State::Streaming;
self.streaming_state = Some(StreamingState::new(audio, video)); self.streaming_state = Some(StreamingState::new(audio, video));
@ -997,11 +1036,13 @@ impl FlvDemux {
let streaming_state = self.streaming_state.as_mut().unwrap(); let streaming_state = self.streaming_state.as_mut().unwrap();
if let Some(pts) = buffer.get_pts() { if let Some(pts) = buffer.get_pts() {
streaming_state.last_position = streaming_state.last_position streaming_state.last_position = streaming_state
.last_position
.map(|last| cmp::max(last, pts)) .map(|last| cmp::max(last, pts))
.or_else(|| Some(pts)); .or_else(|| Some(pts));
} else if let Some(dts) = buffer.get_dts() { } else if let Some(dts) = buffer.get_dts() {
streaming_state.last_position = streaming_state.last_position streaming_state.last_position = streaming_state
.last_position
.map(|last| cmp::max(last, dts)) .map(|last| cmp::max(last, dts))
.or_else(|| Some(dts)); .or_else(|| Some(dts));
} }

View file

@ -9,7 +9,7 @@ license = "MIT/Apache-2.0"
url = "1.1" url = "1.1"
gst-plugin = { path="../gst-plugin" } gst-plugin = { path="../gst-plugin" }
reqwest = "0.5" reqwest = "0.5"
slog = "1.3" slog = "2.0"
[lib] [lib]
name = "gstrshttp" name = "gstrshttp"

View file

@ -19,7 +19,7 @@ use gst_plugin::buffer::*;
use gst_plugin::utils::*; use gst_plugin::utils::*;
use gst_plugin::log::*; use gst_plugin::log::*;
use slog::*; use slog::Logger;
#[derive(Debug)] #[derive(Debug)]
enum StreamingState { enum StreamingState {
@ -50,7 +50,7 @@ impl HttpSrc {
"rshttpsink", "rshttpsink",
0, 0,
"Rust http sink"), "Rust http sink"),
None), o!()),
client: Client::new().unwrap(), client: Client::new().unwrap(),
} }
} }

View file

@ -10,7 +10,7 @@ license = "MIT/Apache-2.0"
libc = "0.2" libc = "0.2"
url = "1.1" url = "1.1"
bitflags = "0.8" bitflags = "0.8"
slog = { version = "1.3", features = ["max_level_trace"] } slog = { version = "2.0", features = ["max_level_trace"] }
lazy_static = "0.2" lazy_static = "0.2"
byteorder = "1.0" byteorder = "1.0"
num-rational = { version = "0.1", default-features = false, features = [] } num-rational = { version = "0.1", default-features = false, features = [] }

View file

@ -11,7 +11,7 @@ use miniobject::*;
use log::*; use log::*;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::cmp; use std::cmp;
use slog::*; use slog::Logger;
lazy_static! { lazy_static! {
static ref LOGGER: Logger = { static ref LOGGER: Logger = {
@ -19,7 +19,7 @@ lazy_static! {
"rsadapter", "rsadapter",
0, 0,
"Rust buffer adapter"), "Rust buffer adapter"),
None) o!())
}; };
} }

View file

@ -18,7 +18,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::u32; use std::u32;
use std::u64; use std::u64;
use slog::*; use slog::Logger;
use utils::*; use utils::*;
use error::*; use error::*;
@ -106,7 +106,7 @@ impl DemuxerWrapper {
"rsdemux", "rsdemux",
0, 0,
"Rust demuxer base class"), "Rust demuxer base class"),
None), o!()),
demuxer: Mutex::new(demuxer), demuxer: Mutex::new(demuxer),
panicked: AtomicBool::new(false), panicked: AtomicBool::new(false),
} }

View file

@ -8,7 +8,7 @@
use libc::c_char; use libc::c_char;
use std::ffi::CString; use std::ffi::CString;
use slog::{Drain, Record, OwnedKeyValueList, Never, Level}; use slog::{Drain, Record, OwnedKVList, Never, Level};
use std::fmt; use std::fmt;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
@ -73,9 +73,10 @@ impl Drop for GstDebugDrain {
} }
impl Drain for GstDebugDrain { impl Drain for GstDebugDrain {
type Error = Never; type Ok = ();
type Err = Never;
fn log(&self, record: &Record, _: &OwnedKeyValueList) -> Result<(), Never> { fn log(&self, record: &Record, _: &OwnedKVList) -> Result<(), Never> {
let level = match record.level() { let level = match record.level() {
Level::Critical | Level::Error => gst::GST_LEVEL_ERROR, Level::Critical | Level::Error => gst::GST_LEVEL_ERROR,
Level::Warning => gst::GST_LEVEL_WARNING, Level::Warning => gst::GST_LEVEL_WARNING,
@ -95,7 +96,7 @@ impl Drain for GstDebugDrain {
// TODO: Probably want to include module? // TODO: Probably want to include module?
let function_cstr = CString::new(record.function().as_bytes()).unwrap(); let function_cstr = CString::new(record.function().as_bytes()).unwrap();
let message_cstr = CString::new(fmt::format(record.msg()).as_bytes()).unwrap(); let message_cstr = CString::new(fmt::format(*record.msg()).as_bytes()).unwrap();
unsafe { unsafe {
let element = gobject::g_weak_ref_get(&*self.element as *const gobject::GWeakRef as let element = gobject::g_weak_ref_get(&*self.element as *const gobject::GWeakRef as

View file

@ -19,7 +19,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use url::Url; use url::Url;
use slog::*; use slog::Logger;
use utils::*; use utils::*;
use error::*; use error::*;
@ -81,7 +81,7 @@ impl SinkWrapper {
"rssink", "rssink",
0, 0,
"Rust sink base class"), "Rust sink base class"),
None), o!()),
uri: Mutex::new((None, false)), uri: Mutex::new((None, false)),
uri_validator: sink.uri_validator(), uri_validator: sink.uri_validator(),
sink: Mutex::new(sink), sink: Mutex::new(sink),

View file

@ -19,7 +19,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use url::Url; use url::Url;
use slog::*; use slog::Logger;
use plugin::Plugin; use plugin::Plugin;
use utils::*; use utils::*;
@ -84,7 +84,7 @@ impl SourceWrapper {
"rssrc", "rssrc",
0, 0,
"Rust source base class"), "Rust source base class"),
None), o!()),
uri: Mutex::new((None, false)), uri: Mutex::new((None, false)),
uri_validator: source.uri_validator(), uri_validator: source.uri_validator(),
source: Mutex::new(source), source: Mutex::new(source),