2017-07-28 17:04:15 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.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.
|
|
|
|
|
2017-12-30 10:02:33 +00:00
|
|
|
use std::fmt;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::ptr;
|
2017-07-28 17:04:15 +00:00
|
|
|
|
|
|
|
use ffi;
|
|
|
|
|
|
|
|
use glib;
|
2018-12-08 11:06:44 +00:00
|
|
|
use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr};
|
2017-07-28 17:04:15 +00:00
|
|
|
|
2018-04-25 08:10:06 +00:00
|
|
|
use miniobject::*;
|
2017-07-28 17:04:15 +00:00
|
|
|
use Buffer;
|
2017-08-03 07:15:20 +00:00
|
|
|
use BufferList;
|
2017-07-28 17:04:15 +00:00
|
|
|
use Caps;
|
2018-04-01 08:30:03 +00:00
|
|
|
use FormattedSegment;
|
2017-12-09 16:20:21 +00:00
|
|
|
use FormattedValue;
|
2017-07-28 17:04:15 +00:00
|
|
|
use Segment;
|
2018-06-11 20:21:51 +00:00
|
|
|
use Structure;
|
2017-07-28 17:04:15 +00:00
|
|
|
use StructureRef;
|
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
gst_define_mini_object_wrapper!(Sample, SampleRef, ffi::GstSample, [Debug,], || {
|
|
|
|
ffi::gst_sample_get_type()
|
|
|
|
});
|
2017-07-28 17:04:15 +00:00
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
impl Sample {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn new<F: FormattedValue>(
|
2017-11-26 21:58:02 +00:00
|
|
|
buffer: Option<&Buffer>,
|
|
|
|
caps: Option<&Caps>,
|
2017-12-09 16:20:21 +00:00
|
|
|
segment: Option<&FormattedSegment<F>>,
|
2018-06-11 20:21:51 +00:00
|
|
|
info: Option<Structure>,
|
2017-07-31 11:16:42 +00:00
|
|
|
) -> Self {
|
2017-07-28 17:04:15 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2018-06-11 20:21:51 +00:00
|
|
|
let info = info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut());
|
2017-07-28 17:04:15 +00:00
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib_full(ffi::gst_sample_new(
|
|
|
|
buffer.to_glib_none().0,
|
|
|
|
caps.to_glib_none().0,
|
2018-06-11 20:21:51 +00:00
|
|
|
segment.to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
mut_override(info),
|
|
|
|
))
|
2017-07-28 17:04:15 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-30 10:02:48 +00:00
|
|
|
|
|
|
|
pub fn with_buffer_list<F: FormattedValue>(
|
|
|
|
buffer_list: Option<&BufferList>,
|
|
|
|
caps: Option<&Caps>,
|
|
|
|
segment: Option<&FormattedSegment<F>>,
|
2018-06-11 20:21:51 +00:00
|
|
|
info: Option<Structure>,
|
2017-12-30 10:02:48 +00:00
|
|
|
) -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let sample = Self::new(None, caps, segment, info);
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_sample_set_buffer_list(sample.to_glib_none().0, buffer_list.to_glib_none().0);
|
|
|
|
}
|
|
|
|
sample
|
|
|
|
}
|
2017-07-28 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SampleRef {
|
|
|
|
pub fn get_buffer(&self) -> Option<Buffer> {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_none(ffi::gst_sample_get_buffer(self.as_mut_ptr())) }
|
2017-07-28 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 07:15:20 +00:00
|
|
|
pub fn get_buffer_list(&self) -> Option<BufferList> {
|
|
|
|
unsafe { from_glib_none(ffi::gst_sample_get_buffer_list(self.as_mut_ptr())) }
|
|
|
|
}
|
2017-07-28 17:04:15 +00:00
|
|
|
|
|
|
|
pub fn get_caps(&self) -> Option<Caps> {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_none(ffi::gst_sample_get_caps(self.as_mut_ptr())) }
|
2017-07-28 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_segment(&self) -> Option<Segment> {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_none(ffi::gst_sample_get_segment(self.as_mut_ptr())) }
|
2017-07-28 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 10:03:03 +00:00
|
|
|
pub fn get_info(&self) -> Option<&StructureRef> {
|
2017-07-28 17:04:15 +00:00
|
|
|
unsafe {
|
|
|
|
let ptr = ffi::gst_sample_get_info(self.as_mut_ptr());
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(StructureRef::from_glib_borrow(ptr))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-30 10:02:33 +00:00
|
|
|
impl fmt::Debug for SampleRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("Sample")
|
|
|
|
.field("buffer", &self.get_buffer())
|
|
|
|
.field("caps", &self.get_caps())
|
|
|
|
.field("segment", &self.get_segment())
|
|
|
|
.field("info", &self.get_info())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 20:21:51 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sample_new_with_info() {
|
|
|
|
use GenericFormattedValue;
|
|
|
|
use Sample;
|
|
|
|
use Structure;
|
|
|
|
|
|
|
|
::init().unwrap();
|
|
|
|
|
|
|
|
let info = Structure::builder("sample.info")
|
|
|
|
.field("f3", &123i32)
|
|
|
|
.build();
|
|
|
|
let sample = Sample::new::<GenericFormattedValue>(None, None, None, Some(info));
|
|
|
|
|
|
|
|
assert!(sample.get_info().is_some());
|
|
|
|
}
|
|
|
|
}
|