2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::structure::*;
|
|
|
|
use crate::GenericFormattedValue;
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-08-02 17:58:33 +00:00
|
|
|
use std::ffi::CStr;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::fmt;
|
|
|
|
use std::mem;
|
2018-02-15 14:05:51 +00:00
|
|
|
use std::ops::{Deref, DerefMut};
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::ptr;
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
use glib::translate::*;
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_get_type()
|
2018-09-28 15:11:46 +00:00
|
|
|
});
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
impl QueryRef {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn structure(&self) -> Option<&StructureRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let structure = ffi::gst_query_get_structure(self.as_mut_ptr());
|
2017-12-06 11:43:37 +00:00
|
|
|
if structure.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(StructureRef::from_glib_borrow(structure))
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn structure_mut(&mut self) -> &mut StructureRef {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let structure = ffi::gst_query_writable_structure(self.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
StructureRef::from_glib_borrow_mut(structure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_downstream(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_DOWNSTREAM != 0 }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_upstream(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_UPSTREAM != 0 }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_serialized(&self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_SERIALIZED != 0 }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn view(&self) -> QueryView<&Self> {
|
|
|
|
let type_ = unsafe { (*self.as_ptr()).type_ };
|
|
|
|
|
2017-09-10 11:54:43 +00:00
|
|
|
match type_ {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::GST_QUERY_POSITION => QueryView::Position(Position(self)),
|
|
|
|
ffi::GST_QUERY_DURATION => QueryView::Duration(Duration(self)),
|
|
|
|
ffi::GST_QUERY_LATENCY => QueryView::Latency(Latency(self)),
|
|
|
|
ffi::GST_QUERY_SEEKING => QueryView::Seeking(Seeking(self)),
|
|
|
|
ffi::GST_QUERY_SEGMENT => QueryView::Segment(Segment(self)),
|
|
|
|
ffi::GST_QUERY_CONVERT => QueryView::Convert(Convert(self)),
|
|
|
|
ffi::GST_QUERY_FORMATS => QueryView::Formats(Formats(self)),
|
|
|
|
ffi::GST_QUERY_BUFFERING => QueryView::Buffering(Buffering(self)),
|
|
|
|
ffi::GST_QUERY_CUSTOM => QueryView::Custom(Custom(self)),
|
|
|
|
ffi::GST_QUERY_URI => QueryView::Uri(Uri(self)),
|
|
|
|
ffi::GST_QUERY_ALLOCATION => QueryView::Allocation(Allocation(self)),
|
|
|
|
ffi::GST_QUERY_SCHEDULING => QueryView::Scheduling(Scheduling(self)),
|
|
|
|
ffi::GST_QUERY_ACCEPT_CAPS => QueryView::AcceptCaps(AcceptCaps(self)),
|
|
|
|
ffi::GST_QUERY_CAPS => QueryView::Caps(Caps(self)),
|
|
|
|
ffi::GST_QUERY_DRAIN => QueryView::Drain(Drain(self)),
|
|
|
|
ffi::GST_QUERY_CONTEXT => QueryView::Context(Context(self)),
|
|
|
|
ffi::GST_QUERY_BITRATE => QueryView::Bitrate(Bitrate(self)),
|
2017-09-10 11:54:43 +00:00
|
|
|
_ => QueryView::Other(Other(self)),
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn view_mut(&mut self) -> QueryView<&mut Self> {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { mem::transmute(self.view()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl fmt::Debug for Query {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
QueryRef::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:21:20 +00:00
|
|
|
impl fmt::Debug for QueryRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("Query")
|
2018-05-05 10:22:27 +00:00
|
|
|
.field("ptr", unsafe { &self.as_ptr() })
|
2017-12-01 17:02:53 +00:00
|
|
|
.field("type", &unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let type_ = ffi::gst_query_type_get_name((*self.as_ptr()).type_);
|
2017-12-01 09:21:20 +00:00
|
|
|
CStr::from_ptr(type_).to_str().unwrap()
|
2018-10-08 12:02:23 +00:00
|
|
|
})
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("structure", &self.structure())
|
2017-12-01 09:21:20 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
pub unsafe trait AsPtr {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_ptr(&self) -> *mut ffi::GstQuery;
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
2017-12-01 09:32:04 +00:00
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
pub unsafe trait AsMutPtr: AsPtr {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery;
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl AsPtr for Query {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_ptr(&self) -> *mut ffi::GstQuery {
|
|
|
|
QueryRef::as_ptr(self) as *mut ffi::GstQuery
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl AsMutPtr for Query {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery {
|
|
|
|
QueryRef::as_ptr(self) as *mut ffi::GstQuery
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> AsPtr for &'a QueryRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_ptr(&self) -> *mut ffi::GstQuery {
|
|
|
|
QueryRef::as_ptr(self) as *mut ffi::GstQuery
|
2017-12-01 09:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
unsafe impl<'a> AsPtr for &'a mut QueryRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_ptr(&self) -> *mut ffi::GstQuery {
|
|
|
|
QueryRef::as_ptr(self) as *mut ffi::GstQuery
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl<'a> AsMutPtr for &'a mut QueryRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery {
|
|
|
|
QueryRef::as_ptr(self) as *mut ffi::GstQuery
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2017-07-29 11:58:54 +00:00
|
|
|
pub enum QueryView<T> {
|
|
|
|
Position(Position<T>),
|
|
|
|
Duration(Duration<T>),
|
|
|
|
Latency(Latency<T>),
|
|
|
|
Seeking(Seeking<T>),
|
|
|
|
Segment(Segment<T>),
|
|
|
|
Convert(Convert<T>),
|
|
|
|
Formats(Formats<T>),
|
|
|
|
Buffering(Buffering<T>),
|
|
|
|
Custom(Custom<T>),
|
|
|
|
Uri(Uri<T>),
|
|
|
|
Allocation(Allocation<T>),
|
|
|
|
Scheduling(Scheduling<T>),
|
|
|
|
AcceptCaps(AcceptCaps<T>),
|
|
|
|
Caps(Caps<T>),
|
|
|
|
Drain(Drain<T>),
|
|
|
|
Context(Context<T>),
|
2019-04-23 16:53:10 +00:00
|
|
|
Bitrate(Bitrate<T>),
|
2017-07-29 11:58:54 +00:00
|
|
|
Other(Other<T>),
|
|
|
|
__NonExhaustive,
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
macro_rules! declare_concrete_query(
|
|
|
|
($name:ident, $param:ident) => {
|
2018-02-15 14:05:51 +00:00
|
|
|
#[derive(Debug)]
|
2018-01-29 10:31:12 +00:00
|
|
|
pub struct $name<$param>($param);
|
|
|
|
|
|
|
|
impl<'a> $name<&'a QueryRef> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn query(&self) -> &QueryRef {
|
2018-01-29 10:31:12 +00:00
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Deref for $name<&'a QueryRef> {
|
|
|
|
type Target = QueryRef;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<'a> Deref for $name<&'a mut QueryRef> {
|
|
|
|
type Target = $name<&'a QueryRef>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
unsafe {
|
2018-07-20 07:21:06 +00:00
|
|
|
&*(self as *const $name<&'a mut QueryRef> as *const $name<&'a QueryRef>)
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
impl<'a> $name<&'a mut QueryRef> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn query_mut(&mut self) -> &mut QueryRef {
|
2018-01-29 10:31:12 +00:00
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl Deref for $name<Query> {
|
|
|
|
type Target = QueryRef;
|
2018-01-29 10:31:12 +00:00
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
2018-02-15 14:05:51 +00:00
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for $name<Query> {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
self.0.get_mut().unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<$name<Query>> for Query {
|
|
|
|
fn from(concrete: $name<Query>) -> Self {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-02-15 14:05:51 +00:00
|
|
|
unsafe { from_glib_none(concrete.0.as_mut_ptr()) }
|
2018-01-29 10:31:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
declare_concrete_query!(Position, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Position<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_position(fmt.to_glib()))) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Position<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> GenericFormattedValue {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut pos = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_position(self.0.as_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init())
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_position(self.0.as_ptr(), fmt.as_mut_ptr(), ptr::null_mut());
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(fmt.assume_init())
|
2017-11-11 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Position<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set<V: Into<GenericFormattedValue>>(&mut self, pos: V) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let pos = pos.into();
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(pos.format(), self.format());
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2021-04-11 19:39:50 +00:00
|
|
|
ffi::gst_query_set_position(self.0.as_mut_ptr(), pos.format().to_glib(), pos.value());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Duration, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Duration<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_duration(fmt.to_glib()))) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Duration<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> GenericFormattedValue {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut pos = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_duration(self.0.as_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init())
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_duration(self.0.as_ptr(), fmt.as_mut_ptr(), ptr::null_mut());
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(fmt.assume_init())
|
2017-11-11 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Duration<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set<V: Into<GenericFormattedValue>>(&mut self, dur: V) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let dur = dur.into();
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(dur.format(), self.format());
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2021-04-11 19:39:50 +00:00
|
|
|
ffi::gst_query_set_duration(self.0.as_mut_ptr(), dur.format().to_glib(), dur.value());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Latency, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Latency<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_latency())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Latency<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Latency<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> (bool, crate::ClockTime, crate::ClockTime) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut live = mem::MaybeUninit::uninit();
|
|
|
|
let mut min = mem::MaybeUninit::uninit();
|
|
|
|
let mut max = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_latency(
|
2019-07-11 12:34:28 +00:00
|
|
|
self.0.as_ptr(),
|
|
|
|
live.as_mut_ptr(),
|
|
|
|
min.as_mut_ptr(),
|
|
|
|
max.as_mut_ptr(),
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
from_glib(live.assume_init()),
|
|
|
|
from_glib(min.assume_init()),
|
|
|
|
from_glib(max.assume_init()),
|
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Latency<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set(&mut self, live: bool, min: crate::ClockTime, max: crate::ClockTime) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_latency(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2017-12-05 20:43:37 +00:00
|
|
|
live.to_glib(),
|
|
|
|
min.to_glib(),
|
|
|
|
max.to_glib(),
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Seeking, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Seeking<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_seeking(fmt.to_glib()))) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Seeking<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut seekable = mem::MaybeUninit::uninit();
|
|
|
|
let mut start = mem::MaybeUninit::uninit();
|
|
|
|
let mut end = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_seeking(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
|
|
|
seekable.as_mut_ptr(),
|
|
|
|
start.as_mut_ptr(),
|
|
|
|
end.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(seekable.assume_init()),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), end.assume_init()),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_seeking(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(fmt.assume_init())
|
2017-11-11 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Seeking<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set<V: Into<GenericFormattedValue>>(&mut self, seekable: bool, start: V, end: V) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let start = start.into();
|
|
|
|
let end = end.into();
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(self.format(), start.format());
|
|
|
|
assert_eq!(start.format(), end.format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_seeking(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2021-04-11 19:39:50 +00:00
|
|
|
start.format().to_glib(),
|
2017-07-31 11:16:42 +00:00
|
|
|
seekable.to_glib(),
|
2021-04-11 19:39:50 +00:00
|
|
|
start.value(),
|
|
|
|
end.value(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Segment, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Segment<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_segment(fmt.to_glib()))) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Segment<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut rate = mem::MaybeUninit::uninit();
|
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut start = mem::MaybeUninit::uninit();
|
|
|
|
let mut stop = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_segment(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
rate.as_mut_ptr(),
|
|
|
|
fmt.as_mut_ptr(),
|
|
|
|
start.as_mut_ptr(),
|
|
|
|
stop.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2019-07-11 12:34:28 +00:00
|
|
|
rate.assume_init(),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), stop.assume_init()),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_segment(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(fmt.assume_init())
|
2017-11-11 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Segment<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set<V: Into<GenericFormattedValue>>(&mut self, rate: f64, start: V, stop: V) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(start.format(), stop.format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_segment(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
rate,
|
2021-04-11 19:39:50 +00:00
|
|
|
start.format().to_glib(),
|
|
|
|
start.value(),
|
|
|
|
stop.value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Convert, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Convert<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new<V: Into<GenericFormattedValue>>(value: V, dest_fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
let value = value.into();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_convert(
|
2021-04-11 19:39:50 +00:00
|
|
|
value.format().to_glib(),
|
|
|
|
value.value(),
|
2020-06-23 17:24:17 +00:00
|
|
|
dest_fmt.to_glib(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Convert<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> (GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut src_fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut src = mem::MaybeUninit::uninit();
|
|
|
|
let mut dest_fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut dest = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_convert(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
src_fmt.as_mut_ptr(),
|
|
|
|
src.as_mut_ptr(),
|
|
|
|
dest_fmt.as_mut_ptr(),
|
|
|
|
dest.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(from_glib(src_fmt.assume_init()), src.assume_init()),
|
|
|
|
GenericFormattedValue::new(from_glib(dest_fmt.assume_init()), dest.assume_init()),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn get(&self) -> (GenericFormattedValue, crate::Format) {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut src_fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut src = mem::MaybeUninit::uninit();
|
|
|
|
let mut dest_fmt = mem::MaybeUninit::uninit();
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_convert(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
src_fmt.as_mut_ptr(),
|
|
|
|
src.as_mut_ptr(),
|
|
|
|
dest_fmt.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
(
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(from_glib(src_fmt.assume_init()), src.assume_init()),
|
|
|
|
from_glib(dest_fmt.assume_init()),
|
2017-11-11 11:22:31 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Convert<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set<V: Into<GenericFormattedValue>>(&mut self, src: V, dest: V) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let src = src.into();
|
|
|
|
let dest = dest.into();
|
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_convert(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2021-04-11 19:39:50 +00:00
|
|
|
src.format().to_glib(),
|
|
|
|
src.value(),
|
|
|
|
dest.format().to_glib(),
|
|
|
|
dest.value(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Formats, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Formats<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_formats())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Formats<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Formats<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> Vec<crate::Format> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut n = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_n_formats(self.0.as_ptr(), n.as_mut_ptr());
|
2019-07-11 12:34:28 +00:00
|
|
|
let n = n.assume_init();
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
|
|
|
|
for i in 0..n {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_nth_format(self.0.as_ptr(), i, fmt.as_mut_ptr());
|
2019-07-11 12:34:28 +00:00
|
|
|
res.push(from_glib(fmt.assume_init()));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Formats<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set(&mut self, formats: &[crate::Format]) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let v: Vec<_> = formats.iter().map(|f| f.to_glib()).collect();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_formatsv(self.0.as_mut_ptr(), v.len() as i32, v.as_ptr() as *mut _);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Buffering, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Buffering<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(fmt: crate::Format) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_buffering(fmt.to_glib()))) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Buffering<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn format(&self) -> crate::Format {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2017-11-11 11:22:31 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(fmt.assume_init())
|
2017-11-11 11:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn percent(&self) -> (bool, i32) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut busy = mem::MaybeUninit::uninit();
|
|
|
|
let mut percent = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_buffering_percent(
|
2019-07-11 12:34:28 +00:00
|
|
|
self.0.as_ptr(),
|
|
|
|
busy.as_mut_ptr(),
|
|
|
|
percent.as_mut_ptr(),
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
(from_glib(busy.assume_init()), percent.assume_init())
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn range(&self) -> (GenericFormattedValue, GenericFormattedValue, i64) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
|
|
|
let mut start = mem::MaybeUninit::uninit();
|
|
|
|
let mut stop = mem::MaybeUninit::uninit();
|
|
|
|
let mut estimated_total = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
|
|
|
start.as_mut_ptr(),
|
|
|
|
stop.as_mut_ptr(),
|
|
|
|
estimated_total.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt.assume_init()), stop.assume_init()),
|
|
|
|
estimated_total.assume_init(),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn stats(&self) -> (crate::BufferingMode, i32, i32, i64) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut mode = mem::MaybeUninit::uninit();
|
|
|
|
let mut avg_in = mem::MaybeUninit::uninit();
|
|
|
|
let mut avg_out = mem::MaybeUninit::uninit();
|
|
|
|
let mut buffering_left = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_buffering_stats(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
mode.as_mut_ptr(),
|
|
|
|
avg_in.as_mut_ptr(),
|
|
|
|
avg_out.as_mut_ptr(),
|
|
|
|
buffering_left.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
from_glib(mode.assume_init()),
|
|
|
|
avg_in.assume_init(),
|
|
|
|
avg_out.assume_init(),
|
|
|
|
buffering_left.assume_init(),
|
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn ranges(&self) -> Vec<(GenericFormattedValue, GenericFormattedValue)> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut fmt = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
fmt.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
let fmt = from_glib(fmt.assume_init());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let n = ffi::gst_query_get_n_buffering_ranges(self.0.as_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut start = mem::MaybeUninit::uninit();
|
|
|
|
let mut stop = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
i,
|
2019-07-11 12:34:28 +00:00
|
|
|
start.as_mut_ptr(),
|
|
|
|
stop.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
));
|
2017-07-29 11:58:54 +00:00
|
|
|
if s {
|
2017-11-11 10:21:55 +00:00
|
|
|
res.push((
|
2019-07-11 12:34:28 +00:00
|
|
|
GenericFormattedValue::new(fmt, start.assume_init()),
|
|
|
|
GenericFormattedValue::new(fmt, stop.assume_init()),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Buffering<T> {
|
2017-07-29 11:58:54 +00:00
|
|
|
pub fn set_percent(&mut self, busy: bool, percent: i32) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_buffering_percent(self.0.as_mut_ptr(), busy.to_glib(), percent);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_range<V: Into<GenericFormattedValue>>(
|
|
|
|
&mut self,
|
|
|
|
start: V,
|
|
|
|
stop: V,
|
|
|
|
estimated_total: i64,
|
|
|
|
) {
|
2017-11-11 10:21:55 +00:00
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(self.format(), start.format());
|
|
|
|
assert_eq!(start.format(), stop.format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2021-04-11 19:39:50 +00:00
|
|
|
start.format().to_glib(),
|
|
|
|
start.value(),
|
|
|
|
stop.value(),
|
2017-07-31 11:16:42 +00:00
|
|
|
estimated_total,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
pub fn set_stats(
|
|
|
|
&mut self,
|
2020-11-21 13:46:48 +00:00
|
|
|
mode: crate::BufferingMode,
|
2017-07-31 11:16:42 +00:00
|
|
|
avg_in: i32,
|
|
|
|
avg_out: i32,
|
|
|
|
buffering_left: i64,
|
|
|
|
) {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_buffering_stats(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
mode.to_glib(),
|
|
|
|
avg_in,
|
|
|
|
avg_out,
|
|
|
|
buffering_left,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn add_buffering_ranges<V: Into<GenericFormattedValue> + Copy>(
|
|
|
|
&mut self,
|
|
|
|
ranges: &[(V, V)],
|
|
|
|
) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2021-04-11 19:39:50 +00:00
|
|
|
let fmt = self.format();
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
for &(start, stop) in ranges {
|
2017-11-11 10:21:55 +00:00
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(start.format(), fmt);
|
|
|
|
assert_eq!(stop.format(), fmt);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_add_buffering_range(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2021-04-11 19:39:50 +00:00
|
|
|
start.value(),
|
|
|
|
stop.value(),
|
2017-11-11 10:21:55 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Custom, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Custom<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(structure: crate::Structure) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_custom(
|
|
|
|
ffi::GST_QUERY_CUSTOM,
|
2020-06-23 17:24:17 +00:00
|
|
|
structure.into_ptr(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Uri, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Uri<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_uri())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Uri<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Uri<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn uri(&self) -> Option<String> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut uri = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_uri(self.0.as_ptr(), &mut uri);
|
2017-07-29 11:58:54 +00:00
|
|
|
from_glib_full(uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn redirection(&self) -> (Option<String>, bool) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut uri = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_uri_redirection(self.0.as_ptr(), &mut uri);
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut permanent = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_uri_redirection_permanent(self.0.as_ptr(), permanent.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
(from_glib_full(uri), from_glib(permanent.assume_init()))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Uri<T> {
|
|
|
|
pub fn set_uri<'b, U: Into<&'b str>>(&mut self, uri: U) {
|
2017-07-29 11:58:54 +00:00
|
|
|
let uri = uri.into();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_uri(self.0.as_mut_ptr(), uri.to_glib_none().0);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
pub fn set_redirection<'b, U: Into<&'b str>>(&mut self, uri: U, permanent: bool) {
|
2017-07-29 11:58:54 +00:00
|
|
|
let uri = uri.into();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_uri_redirection(self.0.as_mut_ptr(), uri.to_glib_none().0);
|
|
|
|
ffi::gst_query_set_uri_redirection_permanent(self.0.as_mut_ptr(), permanent.to_glib());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Allocation, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Allocation<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(caps: &crate::Caps, need_pool: bool) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_allocation(
|
2020-06-23 17:24:17 +00:00
|
|
|
caps.as_mut_ptr(),
|
|
|
|
need_pool.to_glib(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-01 19:56:32 +00:00
|
|
|
impl<T: AsPtr> Allocation<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn get(&self) -> (&crate::CapsRef, bool) {
|
2018-10-01 19:56:32 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut need_pool = mem::MaybeUninit::uninit();
|
2018-10-01 19:56:32 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_allocation(self.0.as_ptr(), &mut caps, need_pool.as_mut_ptr());
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::CapsRef::from_ptr(caps),
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(need_pool.assume_init()),
|
|
|
|
)
|
2018-10-01 19:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn get_owned(&self) -> (crate::Caps, bool) {
|
2019-05-23 11:28:09 +00:00
|
|
|
unsafe {
|
|
|
|
let (caps, need_pool) = self.get();
|
|
|
|
(from_glib_none(caps.as_ptr()), need_pool)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn allocation_pools(&self) -> Vec<(Option<crate::BufferPool>, u32, u32, u32)> {
|
2018-10-01 19:56:32 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr());
|
2018-10-01 19:56:32 +00:00
|
|
|
let mut pools = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
|
|
|
let mut pool = ptr::null_mut();
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut size = mem::MaybeUninit::uninit();
|
|
|
|
let mut min_buffers = mem::MaybeUninit::uninit();
|
|
|
|
let mut max_buffers = mem::MaybeUninit::uninit();
|
2018-10-01 19:56:32 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_nth_allocation_pool(
|
2018-10-01 19:56:32 +00:00
|
|
|
self.0.as_ptr(),
|
|
|
|
i,
|
|
|
|
&mut pool,
|
2019-07-11 12:34:28 +00:00
|
|
|
size.as_mut_ptr(),
|
|
|
|
min_buffers.as_mut_ptr(),
|
|
|
|
max_buffers.as_mut_ptr(),
|
2018-10-01 19:56:32 +00:00
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
pools.push((
|
|
|
|
from_glib_full(pool),
|
|
|
|
size.assume_init(),
|
|
|
|
min_buffers.assume_init(),
|
|
|
|
max_buffers.assume_init(),
|
|
|
|
));
|
2018-10-01 19:56:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pools
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn allocation_metas(&self) -> Vec<(glib::Type, Option<&crate::StructureRef>)> {
|
2018-10-01 19:56:32 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let n = ffi::gst_query_get_n_allocation_metas(self.0.as_ptr());
|
2018-10-01 19:56:32 +00:00
|
|
|
let mut metas = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
|
|
|
let mut structure = ptr::null();
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let api =
|
|
|
|
ffi::gst_query_parse_nth_allocation_meta(self.0.as_ptr(), i, &mut structure);
|
2018-10-01 19:56:32 +00:00
|
|
|
metas.push((
|
|
|
|
from_glib(api),
|
|
|
|
if structure.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
Some(crate::StructureRef::from_glib_borrow(structure))
|
2018-10-01 19:56:32 +00:00
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
metas
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn find_allocation_meta<U: crate::MetaAPI>(&self) -> Option<u32> {
|
2018-10-01 19:56:32 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut idx = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
if ffi::gst_query_find_allocation_meta(
|
2018-10-01 19:56:32 +00:00
|
|
|
self.0.as_ptr(),
|
2021-04-20 10:24:17 +00:00
|
|
|
U::meta_api().to_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
idx.as_mut_ptr(),
|
2020-11-21 13:46:48 +00:00
|
|
|
) != glib::ffi::GFALSE
|
2018-10-01 19:56:32 +00:00
|
|
|
{
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(idx.assume_init())
|
2018-10-01 19:56:32 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: AsMutPtr> Allocation<T> {
|
|
|
|
pub fn add_allocation_pool(
|
|
|
|
&mut self,
|
2020-11-21 13:46:48 +00:00
|
|
|
pool: Option<&crate::BufferPool>,
|
2018-10-01 19:56:32 +00:00
|
|
|
size: u32,
|
|
|
|
min_buffers: u32,
|
|
|
|
max_buffers: u32,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_add_allocation_pool(
|
2018-10-01 19:56:32 +00:00
|
|
|
self.0.as_mut_ptr(),
|
|
|
|
pool.to_glib_none().0,
|
|
|
|
size,
|
|
|
|
min_buffers,
|
|
|
|
max_buffers,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_nth_allocation_pool(
|
|
|
|
&mut self,
|
|
|
|
idx: u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
pool: Option<&crate::BufferPool>,
|
2018-10-01 19:56:32 +00:00
|
|
|
size: u32,
|
|
|
|
min_buffers: u32,
|
|
|
|
max_buffers: u32,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_nth_allocation_pool(
|
2018-10-01 19:56:32 +00:00
|
|
|
self.0.as_mut_ptr(),
|
|
|
|
idx,
|
|
|
|
pool.to_glib_none().0,
|
|
|
|
size,
|
|
|
|
min_buffers,
|
|
|
|
max_buffers,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_nth_allocation_pool(&mut self, idx: u32) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_remove_nth_allocation_pool(self.0.as_mut_ptr(), idx);
|
2018-10-01 19:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn add_allocation_meta<U: crate::MetaAPI>(
|
|
|
|
&mut self,
|
|
|
|
structure: Option<&crate::StructureRef>,
|
|
|
|
) {
|
2018-10-01 19:56:32 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_add_allocation_meta(
|
2018-10-01 19:56:32 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2021-04-20 10:24:17 +00:00
|
|
|
U::meta_api().to_glib(),
|
2018-10-01 19:56:32 +00:00
|
|
|
if let Some(structure) = structure {
|
|
|
|
structure.as_ptr()
|
|
|
|
} else {
|
|
|
|
ptr::null()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove_nth_allocation_meta(&mut self, idx: u32) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_remove_nth_allocation_meta(self.0.as_mut_ptr(), idx);
|
2018-10-01 19:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Scheduling, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Scheduling<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_scheduling())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Scheduling<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Scheduling<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn has_scheduling_mode(&self, mode: crate::PadMode) -> bool {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_query_has_scheduling_mode(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
mode.to_glib(),
|
|
|
|
))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
pub fn has_scheduling_mode_with_flags(
|
|
|
|
&self,
|
2020-11-21 13:46:48 +00:00
|
|
|
mode: crate::PadMode,
|
|
|
|
flags: crate::SchedulingFlags,
|
2017-07-31 11:16:42 +00:00
|
|
|
) -> bool {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_query_has_scheduling_mode_with_flags(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
mode.to_glib(),
|
|
|
|
flags.to_glib(),
|
|
|
|
))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn scheduling_modes(&self) -> Vec<crate::PadMode> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let n = ffi::gst_query_get_n_scheduling_modes(self.0.as_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
2020-11-21 13:46:48 +00:00
|
|
|
res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
i,
|
|
|
|
)));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> (crate::SchedulingFlags, i32, i32, i32) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut flags = mem::MaybeUninit::uninit();
|
|
|
|
let mut minsize = mem::MaybeUninit::uninit();
|
|
|
|
let mut maxsize = mem::MaybeUninit::uninit();
|
|
|
|
let mut align = mem::MaybeUninit::uninit();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_scheduling(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_ptr(),
|
2019-07-11 12:34:28 +00:00
|
|
|
flags.as_mut_ptr(),
|
|
|
|
minsize.as_mut_ptr(),
|
|
|
|
maxsize.as_mut_ptr(),
|
|
|
|
align.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
from_glib(flags.assume_init()),
|
|
|
|
minsize.assume_init(),
|
|
|
|
maxsize.assume_init(),
|
|
|
|
align.assume_init(),
|
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Scheduling<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn add_scheduling_modes(&mut self, modes: &[crate::PadMode]) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
for mode in modes {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_add_scheduling_mode(self.0.as_mut_ptr(), mode.to_glib());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set(&mut self, flags: crate::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_scheduling(
|
2018-02-15 14:05:51 +00:00
|
|
|
self.0.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
flags.to_glib(),
|
|
|
|
minsize,
|
|
|
|
maxsize,
|
|
|
|
align,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(AcceptCaps, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl AcceptCaps<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(caps: &crate::Caps) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_accept_caps(
|
2020-06-23 17:24:17 +00:00
|
|
|
caps.as_mut_ptr(),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> AcceptCaps<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn caps(&self) -> &crate::CapsRef {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_accept_caps(self.0.as_ptr(), &mut caps);
|
|
|
|
crate::CapsRef::from_ptr(caps)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn caps_owned(&self) -> crate::Caps {
|
|
|
|
unsafe { from_glib_none(self.caps().as_ptr()) }
|
2019-05-23 11:28:09 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> bool {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut accepted = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_accept_caps_result(self.0.as_ptr(), accepted.as_mut_ptr());
|
2019-07-11 12:34:28 +00:00
|
|
|
from_glib(accepted.assume_init())
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> AcceptCaps<T> {
|
2017-07-29 11:58:54 +00:00
|
|
|
pub fn set_result(&mut self, accepted: bool) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_accept_caps_result(self.0.as_mut_ptr(), accepted.to_glib());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Caps, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Caps<Query> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(filter: Option<&crate::Caps>) -> Self {
|
2020-06-23 17:24:17 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_caps(
|
2020-06-23 17:24:17 +00:00
|
|
|
filter.to_glib_none().0,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Caps<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn filter(&self) -> Option<&crate::CapsRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_caps(self.0.as_ptr(), &mut caps);
|
2017-12-17 09:32:01 +00:00
|
|
|
if caps.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
Some(crate::CapsRef::from_ptr(caps))
|
2017-12-17 09:32:01 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn filter_owned(&self) -> Option<crate::Caps> {
|
|
|
|
unsafe { self.filter().map(|caps| from_glib_none(caps.as_ptr())) }
|
2019-05-23 11:28:09 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result(&self) -> Option<&crate::CapsRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_caps_result(self.0.as_ptr(), &mut caps);
|
2017-12-17 09:32:01 +00:00
|
|
|
if caps.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
Some(crate::CapsRef::from_ptr(caps))
|
2017-12-17 09:32:01 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-23 11:28:09 +00:00
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn result_owned(&self) -> Option<crate::Caps> {
|
|
|
|
unsafe { self.result().map(|caps| from_glib_none(caps.as_ptr())) }
|
2019-05-23 11:28:09 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Caps<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set_result(&mut self, caps: &crate::Caps) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_caps_result(self.0.as_mut_ptr(), caps.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Drain, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Drain<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_drain())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Drain<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Context, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Context<Query> {
|
|
|
|
pub fn new(context_type: &str) -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
Self(from_glib_full(ffi::gst_query_new_context(
|
2020-06-23 17:24:17 +00:00
|
|
|
context_type.to_glib_none().0,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsPtr> Context<T> {
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn context(&self) -> Option<&crate::ContextRef> {
|
2017-08-02 17:58:33 +00:00
|
|
|
unsafe {
|
|
|
|
let mut context = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_context(self.0.as_ptr(), &mut context);
|
2017-08-02 17:58:33 +00:00
|
|
|
if context.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
Some(crate::ContextRef::from_ptr(context))
|
2017-08-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn context_owned(&self) -> Option<crate::Context> {
|
2019-05-23 11:28:09 +00:00
|
|
|
unsafe {
|
2021-04-11 19:39:50 +00:00
|
|
|
self.context()
|
2019-05-23 11:28:09 +00:00
|
|
|
.map(|context| from_glib_none(context.as_ptr()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn context_type(&self) -> &str {
|
2017-08-02 17:58:33 +00:00
|
|
|
unsafe {
|
|
|
|
let mut context_type = ptr::null();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_context_type(self.0.as_ptr(), &mut context_type);
|
2017-08-02 17:58:33 +00:00
|
|
|
CStr::from_ptr(context_type).to_str().unwrap()
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
impl<T: AsMutPtr> Context<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set_context(&mut self, context: &crate::Context) {
|
2017-08-02 17:58:33 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_context(self.0.as_mut_ptr(), context.as_mut_ptr());
|
2017-08-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 16:53:10 +00:00
|
|
|
declare_concrete_query!(Bitrate, T);
|
2020-06-23 17:24:17 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Bitrate<Query> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { Self(from_glib_full(ffi::gst_query_new_bitrate())) }
|
2020-06-23 17:24:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2020-06-23 17:24:17 +00:00
|
|
|
impl Default for Bitrate<Query> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-23 16:53:10 +00:00
|
|
|
impl<T: AsPtr> Bitrate<T> {
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn bitrate(&self) -> u32 {
|
2019-04-23 16:53:10 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut bitrate = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_parse_bitrate(self.0.as_ptr(), bitrate.as_mut_ptr());
|
2019-07-11 12:34:28 +00:00
|
|
|
bitrate.assume_init()
|
2019-04-23 16:53:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: AsMutPtr> Bitrate<T> {
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2019-04-23 16:53:10 +00:00
|
|
|
pub fn set_bitrate(&mut self, bitrate: u32) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_query_set_bitrate(self.0.as_mut_ptr(), bitrate);
|
2019-04-23 16:53:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Other, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2019-06-03 15:42:00 +00:00
|
|
|
use std::convert::TryInto;
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_writability() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
fn check_mut(query: &mut QueryRef) {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-02-15 14:05:51 +00:00
|
|
|
match query.view_mut() {
|
|
|
|
QueryView::Position(ref mut p) => {
|
2021-04-11 19:39:50 +00:00
|
|
|
let pos = p.result();
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pos.try_into(), Ok(crate::CLOCK_TIME_NONE));
|
|
|
|
p.set(3 * crate::SECOND);
|
2021-04-11 19:39:50 +00:00
|
|
|
let pos = p.result();
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pos.try_into(), Ok(3 * crate::SECOND));
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
_ => panic!("Wrong concrete Query in Query"),
|
2017-07-31 11:16:42 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-15 14:05:51 +00:00
|
|
|
fn check_ref(query: &QueryRef) {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-02-15 14:05:51 +00:00
|
|
|
match query.view() {
|
|
|
|
QueryView::Position(ref p) => {
|
2021-04-11 19:39:50 +00:00
|
|
|
let pos = p.result();
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pos.try_into(), Ok(3 * crate::SECOND));
|
2018-02-22 10:18:37 +00:00
|
|
|
unsafe {
|
|
|
|
assert!(!p.as_mut_ptr().is_null());
|
|
|
|
}
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
_ => panic!("Wrong concrete Query in Query"),
|
2017-07-31 11:16:42 +00:00
|
|
|
}
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let mut p = Position::new(crate::Format::Time);
|
2021-04-11 19:39:50 +00:00
|
|
|
let pos = p.result();
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pos.try_into(), Ok(crate::CLOCK_TIME_NONE));
|
2018-02-15 14:05:51 +00:00
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
p.structure_mut().set("check_mut", &true);
|
2018-02-15 14:05:51 +00:00
|
|
|
|
|
|
|
// deref
|
|
|
|
assert!(!p.is_serialized());
|
|
|
|
|
|
|
|
{
|
|
|
|
check_mut(&mut p);
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
let structure = p.structure();
|
2018-02-15 14:05:51 +00:00
|
|
|
structure.unwrap().has_field("check_mut");
|
|
|
|
|
|
|
|
// Expected: cannot borrow `p` as mutable because it is also borrowed as immutable
|
|
|
|
//check_mut(&mut p);
|
|
|
|
}
|
|
|
|
|
|
|
|
check_ref(&p);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_into_query() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
|
|
|
let d = Duration::new(crate::Format::Time);
|
2018-02-15 14:05:51 +00:00
|
|
|
|
|
|
|
let mut query: Query = d.into();
|
|
|
|
assert!(query.is_writable());
|
|
|
|
|
|
|
|
let query = query.make_mut();
|
2020-11-25 18:22:26 +00:00
|
|
|
if let QueryView::Duration(d) = &mut query.view_mut() {
|
|
|
|
d.set(2 * crate::SECOND);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 18:22:26 +00:00
|
|
|
if let QueryView::Duration(d) = &query.view() {
|
2021-04-11 19:39:50 +00:00
|
|
|
let duration = d.result();
|
2020-11-25 18:22:26 +00:00
|
|
|
assert_eq!(duration.try_into(), Ok(2 * crate::SECOND));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-15 14:05:51 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-03-19 07:58:20 +00:00
|
|
|
fn test_concrete_to_sys() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2018-02-15 14:05:51 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let p = Position::new(crate::Format::Time);
|
2018-02-22 10:18:37 +00:00
|
|
|
unsafe {
|
|
|
|
assert!(!p.as_mut_ptr().is_null());
|
|
|
|
}
|
2018-02-15 14:05:51 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|