1 // Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com> 2 // 3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or 4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license 5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your 6 // option. This file may not be copied, modified, or distributed 7 // except according to those terms. 8 9 use glib::translate::*; 10 use gst_sys; 11 use std::fmt; 12 use Caps; 13 use Stream; 14 use StreamFlags; 15 use StreamType; 16 17 impl Stream { new( stream_id: Option<&str>, caps: Option<&Caps>, type_: StreamType, flags: StreamFlags, ) -> Stream18 pub fn new( 19 stream_id: Option<&str>, 20 caps: Option<&Caps>, 21 type_: StreamType, 22 flags: StreamFlags, 23 ) -> Stream { 24 assert_initialized_main_thread!(); 25 let stream_id = stream_id.to_glib_none(); 26 let caps = caps.to_glib_none(); 27 28 let (major, minor, _, _) = ::version(); 29 if (major, minor) > (1, 12) { 30 unsafe { 31 from_glib_full(gst_sys::gst_stream_new( 32 stream_id.0, 33 caps.0, 34 type_.to_glib(), 35 flags.to_glib(), 36 )) 37 } 38 } else { 39 // Work-around for 1.14 switching from transfer-floating to transfer-full 40 unsafe { 41 from_glib_none(gst_sys::gst_stream_new( 42 stream_id.0, 43 caps.0, 44 type_.to_glib(), 45 flags.to_glib(), 46 )) 47 } 48 } 49 } 50 debug(&self) -> Debug51 pub fn debug(&self) -> Debug { 52 Debug(self) 53 } 54 } 55 56 pub struct Debug<'a>(&'a Stream); 57 58 impl<'a> fmt::Debug for Debug<'a> { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 60 f.debug_struct("Stream") 61 .field("stream_id", &self.0.get_stream_id()) 62 .field("stream_type", &self.0.get_stream_type()) 63 .field("stream_flags", &self.0.get_stream_flags()) 64 .field("caps", &self.0.get_caps()) 65 .field("tags", &self.0.get_tags()) 66 .finish() 67 } 68 } 69