2017-07-29 11:58:54 +00:00
|
|
|
// Copyright (C) 2016-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.
|
|
|
|
|
|
|
|
use ffi;
|
|
|
|
use miniobject::*;
|
|
|
|
use structure::*;
|
2017-12-09 16:20:21 +00:00
|
|
|
use GenericFormattedValue;
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
use std::ptr;
|
|
|
|
use std::mem;
|
2017-12-01 09:21:20 +00:00
|
|
|
use std::fmt;
|
2017-08-02 17:58:33 +00:00
|
|
|
use std::ffi::CStr;
|
2017-07-29 11:58:54 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
use glib;
|
2017-07-31 11:16:42 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct QueryRef(ffi::GstQuery);
|
|
|
|
|
2017-09-14 12:08:54 +00:00
|
|
|
unsafe impl Send for QueryRef {}
|
|
|
|
unsafe impl Sync for QueryRef {}
|
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
pub type Query = GstRc<QueryRef>;
|
|
|
|
|
|
|
|
unsafe impl MiniObject for QueryRef {
|
|
|
|
type GstType = ffi::GstQuery;
|
|
|
|
}
|
|
|
|
|
2017-08-30 12:12:11 +00:00
|
|
|
impl GstRc<QueryRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
pub fn new_position(fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_position(fmt.to_glib())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_duration(fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_duration(fmt.to_glib())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_latency() -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_latency()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_seeking(fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_seeking(fmt.to_glib())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_segment(fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_segment(fmt.to_glib())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn new_convert<V: Into<GenericFormattedValue>>(value: V, dest_fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-12-09 16:20:21 +00:00
|
|
|
let value = value.into();
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib_full(ffi::gst_query_new_convert(
|
2017-12-09 16:20:21 +00:00
|
|
|
value.get_format().to_glib(),
|
|
|
|
value.get_value(),
|
2017-07-31 11:16:42 +00:00
|
|
|
dest_fmt.to_glib(),
|
|
|
|
))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_formats() -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_formats()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_buffering(fmt: ::Format) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_buffering(fmt.to_glib())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_custom(structure: ::Structure) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib_full(ffi::gst_query_new_custom(
|
|
|
|
ffi::GST_QUERY_CUSTOM,
|
|
|
|
structure.into_ptr(),
|
|
|
|
))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_uri() -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_uri()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_scheduling() -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_scheduling()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_accept_caps(caps: &::Caps) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_accept_caps(caps.as_mut_ptr())) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-17 09:32:01 +00:00
|
|
|
pub fn new_caps<'a, P: Into<Option<&'a ::Caps>>>(filter: P) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-12-17 09:32:01 +00:00
|
|
|
let filter = filter.into();
|
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_caps(filter.to_glib_none().0)) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_drain() -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_drain()) }
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
2017-08-02 17:58:33 +00:00
|
|
|
|
|
|
|
pub fn new_context(context_type: &str) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-08-02 17:58:33 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_query_new_context(context_type.to_glib_none().0)) }
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl QueryRef {
|
2017-12-06 11:43:37 +00:00
|
|
|
pub fn get_structure(&self) -> Option<&StructureRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mut_structure(&mut self) -> &mut StructureRef {
|
|
|
|
unsafe {
|
|
|
|
let structure = ffi::gst_query_writable_structure(self.as_mut_ptr());
|
|
|
|
StructureRef::from_glib_borrow_mut(structure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_downstream(&self) -> bool {
|
2017-12-20 17:30:14 +00:00
|
|
|
unsafe {
|
|
|
|
((*self.as_ptr()).type_ as u32) & (ffi::GST_QUERY_TYPE_DOWNSTREAM.bits()) != 0
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_upstream(&self) -> bool {
|
2017-12-20 17:30:14 +00:00
|
|
|
unsafe {
|
|
|
|
((*self.as_ptr()).type_ as u32) & (ffi::GST_QUERY_TYPE_UPSTREAM.bits()) != 0
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_serialized(&self) -> bool {
|
2017-12-20 17:30:14 +00:00
|
|
|
unsafe {
|
|
|
|
((*self.as_ptr()).type_ as u32) & (ffi::GST_QUERY_TYPE_SERIALIZED.bits()) != 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_ {
|
|
|
|
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_JITTER => QueryView::Jitter(Jitter(self)),
|
|
|
|
ffi::GST_QUERY_RATE => QueryView::Rate(Rate(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)),
|
|
|
|
_ => 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 13:21:49 +00:00
|
|
|
impl glib::types::StaticType for QueryRef {
|
2017-07-29 11:58:54 +00:00
|
|
|
fn static_type() -> glib::types::Type {
|
|
|
|
unsafe { from_glib(ffi::gst_query_get_type()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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")
|
2017-12-01 17:02:53 +00:00
|
|
|
.field("type", &unsafe {
|
2017-12-01 09:21:20 +00:00
|
|
|
let type_ = ffi::gst_query_type_get_name((*self.as_ptr()).type_);
|
|
|
|
CStr::from_ptr(type_).to_str().unwrap()
|
|
|
|
})
|
|
|
|
.field("structure", &self.get_structure())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:32:04 +00:00
|
|
|
impl ToOwned for QueryRef {
|
|
|
|
type Owned = GstRc<QueryRef>;
|
|
|
|
|
|
|
|
fn to_owned(&self) -> GstRc<QueryRef> {
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _)
|
|
|
|
as *mut _)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
pub enum QueryView<T> {
|
|
|
|
Position(Position<T>),
|
|
|
|
Duration(Duration<T>),
|
|
|
|
Latency(Latency<T>),
|
|
|
|
Jitter(Jitter<T>),
|
|
|
|
Rate(Rate<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>),
|
|
|
|
Other(Other<T>),
|
|
|
|
__NonExhaustive,
|
|
|
|
}
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
macro_rules! declare_concrete_query(
|
|
|
|
($name:ident, $param:ident) => {
|
|
|
|
pub struct $name<$param>($param);
|
|
|
|
|
|
|
|
impl<'a> $name<&'a QueryRef> {
|
|
|
|
pub fn get_query(&self) -> &QueryRef {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Deref for $name<&'a QueryRef> {
|
|
|
|
type Target = QueryRef;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> $name<&'a mut QueryRef> {
|
|
|
|
pub fn get_mut_query(&mut self) -> &mut QueryRef {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Deref for $name<&'a mut QueryRef> {
|
|
|
|
type Target = $name<&'a QueryRef>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
unsafe {
|
|
|
|
mem::transmute(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
declare_concrete_query!(Position, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Position<&'a QueryRef> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_result(&self) -> GenericFormattedValue {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
let mut pos = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_position(self.as_mut_ptr(), &mut fmt, &mut pos);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt), pos)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_format(&self) -> ::Format {
|
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_position(self.as_mut_ptr(), &mut fmt, ptr::null_mut());
|
2017-11-11 11:22:31 +00:00
|
|
|
|
|
|
|
from_glib(fmt)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Position<&'a mut QueryRef> {
|
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();
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(pos.get_format(), self.get_format());
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-11-11 10:21:55 +00:00
|
|
|
ffi::gst_query_set_position(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
pos.get_format().to_glib(),
|
|
|
|
pos.get_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!(Duration, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Duration<&'a QueryRef> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_result(&self) -> GenericFormattedValue {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
let mut pos = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_duration(self.as_mut_ptr(), &mut fmt, &mut pos);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt), pos)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_format(&self) -> ::Format {
|
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_duration(self.as_mut_ptr(), &mut fmt, ptr::null_mut());
|
2017-11-11 11:22:31 +00:00
|
|
|
|
|
|
|
from_glib(fmt)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Duration<&'a mut QueryRef> {
|
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();
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(dur.get_format(), self.get_format());
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-11-11 10:21:55 +00:00
|
|
|
ffi::gst_query_set_duration(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
dur.get_format().to_glib(),
|
|
|
|
dur.get_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!(Latency, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Latency<&'a QueryRef> {
|
2017-12-05 20:43:37 +00:00
|
|
|
pub fn get_result(&self) -> (bool, ::ClockTime, ::ClockTime) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut live = mem::uninitialized();
|
|
|
|
let mut min = mem::uninitialized();
|
|
|
|
let mut max = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_latency(self.as_mut_ptr(), &mut live, &mut min, &mut max);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-12-05 20:43:37 +00:00
|
|
|
(from_glib(live), from_glib(min), from_glib(max))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Latency<&'a mut QueryRef> {
|
2017-12-05 20:43:37 +00:00
|
|
|
pub fn set(&mut self, live: bool, min: ::ClockTime, max: ::ClockTime) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-12-05 20:43:37 +00:00
|
|
|
ffi::gst_query_set_latency(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.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!(Jitter, T);
|
|
|
|
declare_concrete_query!(Rate, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Seeking, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Seeking<&'a QueryRef> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
let mut seekable = mem::uninitialized();
|
|
|
|
let mut start = mem::uninitialized();
|
|
|
|
let mut end = mem::uninitialized();
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_seeking(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut fmt,
|
|
|
|
&mut seekable,
|
|
|
|
&mut start,
|
|
|
|
&mut end,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
|
|
|
from_glib(seekable),
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt), start),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt), end),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_format(&self) -> ::Format {
|
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
ffi::gst_query_parse_seeking(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
&mut fmt,
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
|
|
|
|
from_glib(fmt)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Seeking<&'a mut QueryRef> {
|
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();
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(self.get_format(), start.get_format());
|
|
|
|
assert_eq!(start.get_format(), end.get_format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_set_seeking(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_format().to_glib(),
|
2017-07-31 11:16:42 +00:00
|
|
|
seekable.to_glib(),
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_value(),
|
|
|
|
end.get_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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Segment<&'a QueryRef> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut rate = mem::uninitialized();
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
let mut start = mem::uninitialized();
|
|
|
|
let mut stop = mem::uninitialized();
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_segment(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut rate,
|
|
|
|
&mut fmt,
|
|
|
|
&mut start,
|
|
|
|
&mut stop,
|
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
|
|
|
rate,
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt), start),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt), stop),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_format(&self) -> ::Format {
|
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
|
|
|
|
ffi::gst_query_parse_segment(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
ptr::null_mut(),
|
|
|
|
&mut fmt,
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
from_glib(fmt)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Segment<&'a mut QueryRef> {
|
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();
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(start.get_format(), stop.get_format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-11-11 10:21:55 +00:00
|
|
|
ffi::gst_query_set_segment(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
rate,
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_format().to_glib(),
|
|
|
|
start.get_value(),
|
|
|
|
stop.get_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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Convert<&'a QueryRef> {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_result(&self) -> (GenericFormattedValue, GenericFormattedValue) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut src_fmt = mem::uninitialized();
|
|
|
|
let mut src = mem::uninitialized();
|
|
|
|
let mut dest_fmt = mem::uninitialized();
|
|
|
|
let mut dest = mem::uninitialized();
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_convert(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut src_fmt,
|
|
|
|
&mut src,
|
|
|
|
&mut dest_fmt,
|
|
|
|
&mut dest,
|
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(src_fmt), src),
|
|
|
|
GenericFormattedValue::new(from_glib(dest_fmt), dest),
|
2017-11-11 10:21:55 +00:00
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get(&self) -> (GenericFormattedValue, ::Format) {
|
2017-11-11 11:22:31 +00:00
|
|
|
unsafe {
|
|
|
|
let mut src_fmt = mem::uninitialized();
|
|
|
|
let mut src = mem::uninitialized();
|
|
|
|
let mut dest_fmt = mem::uninitialized();
|
|
|
|
|
|
|
|
ffi::gst_query_parse_convert(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
&mut src_fmt,
|
|
|
|
&mut src,
|
|
|
|
&mut dest_fmt,
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
(
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(src_fmt), src),
|
2017-11-11 11:22:31 +00:00
|
|
|
from_glib(dest_fmt),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Convert<&'a mut QueryRef> {
|
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 {
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_set_convert(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
src.get_format().to_glib(),
|
|
|
|
src.get_value(),
|
|
|
|
dest.get_format().to_glib(),
|
|
|
|
dest.get_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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Formats<&'a QueryRef> {
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_result(&self) -> Vec<::Format> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut n = mem::uninitialized();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_n_formats(self.as_mut_ptr(), &mut n);
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
|
|
|
|
for i in 0..n {
|
|
|
|
let mut fmt = mem::uninitialized();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_nth_format(self.as_mut_ptr(), i, &mut fmt);
|
2017-07-29 11:58:54 +00:00
|
|
|
res.push(from_glib(fmt));
|
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Formats<&'a mut QueryRef> {
|
|
|
|
pub fn set(&mut self, formats: &[::Format]) {
|
|
|
|
unsafe {
|
|
|
|
let v: Vec<_> = formats.iter().map(|f| f.to_glib()).collect();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_formatsv(self.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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Buffering<&'a QueryRef> {
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_format(&self) -> ::Format {
|
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
|
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 11:22:31 +00:00
|
|
|
&mut fmt,
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
|
|
|
|
from_glib(fmt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
pub fn get_percent(&self) -> (bool, i32) {
|
|
|
|
unsafe {
|
|
|
|
let mut busy = mem::uninitialized();
|
|
|
|
let mut percent = mem::uninitialized();
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_buffering_percent(self.as_mut_ptr(), &mut busy, &mut percent);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
(from_glib(busy), percent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_range(&self) -> (GenericFormattedValue, GenericFormattedValue, i64) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
let mut start = mem::uninitialized();
|
|
|
|
let mut stop = mem::uninitialized();
|
|
|
|
let mut estimated_total = mem::uninitialized();
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut fmt,
|
|
|
|
&mut start,
|
|
|
|
&mut stop,
|
|
|
|
&mut estimated_total,
|
|
|
|
);
|
2017-11-11 10:21:55 +00:00
|
|
|
(
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(from_glib(fmt), start),
|
|
|
|
GenericFormattedValue::new(from_glib(fmt), stop),
|
2017-11-11 10:21:55 +00:00
|
|
|
estimated_total,
|
|
|
|
)
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_stats(&self) -> (::BufferingMode, i32, i32, i64) {
|
|
|
|
unsafe {
|
|
|
|
let mut mode = mem::uninitialized();
|
|
|
|
let mut avg_in = mem::uninitialized();
|
|
|
|
let mut avg_out = mem::uninitialized();
|
|
|
|
let mut buffering_left = mem::uninitialized();
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_buffering_stats(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut mode,
|
|
|
|
&mut avg_in,
|
|
|
|
&mut avg_out,
|
|
|
|
&mut buffering_left,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
(from_glib(mode), avg_in, avg_out, buffering_left)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_ranges(&self) -> Vec<(GenericFormattedValue, GenericFormattedValue)> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-11-11 10:21:55 +00:00
|
|
|
let mut fmt = mem::uninitialized();
|
|
|
|
ffi::gst_query_parse_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
&mut fmt,
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
ptr::null_mut(),
|
|
|
|
);
|
|
|
|
let fmt = from_glib(fmt);
|
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
let n = ffi::gst_query_get_n_buffering_ranges(self.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
|
|
|
let mut start = mem::uninitialized();
|
|
|
|
let mut stop = mem::uninitialized();
|
2017-07-31 11:16:42 +00:00
|
|
|
let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
i,
|
|
|
|
&mut start,
|
|
|
|
&mut stop,
|
|
|
|
));
|
2017-07-29 11:58:54 +00:00
|
|
|
if s {
|
2017-11-11 10:21:55 +00:00
|
|
|
res.push((
|
2017-12-09 16:20:21 +00:00
|
|
|
GenericFormattedValue::new(fmt, start),
|
|
|
|
GenericFormattedValue::new(fmt, stop),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Buffering<&'a mut QueryRef> {
|
|
|
|
pub fn set_percent(&mut self, busy: bool, percent: i32) {
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_buffering_percent(self.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();
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(self.get_format(), start.get_format());
|
|
|
|
assert_eq!(start.get_format(), stop.get_format());
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_set_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_format().to_glib(),
|
|
|
|
start.get_value(),
|
|
|
|
stop.get_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,
|
|
|
|
mode: ::BufferingMode,
|
|
|
|
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 {
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_set_buffering_stats(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.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 {
|
2017-11-11 11:22:31 +00:00
|
|
|
let fmt = self.get_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();
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(start.get_format(), fmt);
|
|
|
|
assert_eq!(stop.get_format(), fmt);
|
2017-11-11 10:21:55 +00:00
|
|
|
ffi::gst_query_add_buffering_range(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
start.get_value(),
|
|
|
|
stop.get_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);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Uri, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Uri<&'a QueryRef> {
|
|
|
|
pub fn get_uri(&self) -> Option<String> {
|
|
|
|
unsafe {
|
|
|
|
let mut uri = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_uri(self.as_mut_ptr(), &mut uri);
|
2017-07-29 11:58:54 +00:00
|
|
|
from_glib_full(uri)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_redirection(&self) -> (Option<String>, bool) {
|
|
|
|
unsafe {
|
|
|
|
let mut uri = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_uri_redirection(self.as_mut_ptr(), &mut uri);
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut permanent = mem::uninitialized();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_uri_redirection_permanent(self.as_mut_ptr(), &mut permanent);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
(from_glib_full(uri), from_glib(permanent))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Uri<&'a mut QueryRef> {
|
|
|
|
pub fn set_uri<'b, T: Into<&'b str>>(&mut self, uri: T) {
|
|
|
|
let uri = uri.into();
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_uri(self.as_mut_ptr(), uri.to_glib_none().0);
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_redirection<'b, T: Into<&'b str>>(&mut self, uri: T, permanent: bool) {
|
|
|
|
let uri = uri.into();
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0);
|
|
|
|
ffi::gst_query_set_uri_redirection_permanent(self.as_mut_ptr(), permanent.to_glib());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Allocation, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Scheduling, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Scheduling<&'a QueryRef> {
|
|
|
|
pub fn has_scheduling_mode(&self, mode: ::PadMode) -> bool {
|
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib(ffi::gst_query_has_scheduling_mode(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_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,
|
|
|
|
mode: ::PadMode,
|
|
|
|
flags: ::SchedulingFlags,
|
|
|
|
) -> bool {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
from_glib(ffi::gst_query_has_scheduling_mode_with_flags(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
mode.to_glib(),
|
|
|
|
flags.to_glib(),
|
|
|
|
))
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_scheduling_modes(&self) -> Vec<::PadMode> {
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
let n = ffi::gst_query_get_n_scheduling_modes(self.as_mut_ptr());
|
2017-07-29 11:58:54 +00:00
|
|
|
let mut res = Vec::with_capacity(n as usize);
|
|
|
|
for i in 0..n {
|
2017-07-31 11:16:42 +00:00
|
|
|
res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
i,
|
|
|
|
)));
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_result(&self) -> (::SchedulingFlags, i32, i32, i32) {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut flags = mem::uninitialized();
|
|
|
|
let mut minsize = mem::uninitialized();
|
|
|
|
let mut maxsize = mem::uninitialized();
|
|
|
|
let mut align = mem::uninitialized();
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_parse_scheduling(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut flags,
|
|
|
|
&mut minsize,
|
|
|
|
&mut maxsize,
|
|
|
|
&mut align,
|
|
|
|
);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
|
|
|
(from_glib(flags), minsize, maxsize, align)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Scheduling<&'a mut QueryRef> {
|
|
|
|
pub fn add_scheduling_modes(&mut self, modes: &[::PadMode]) {
|
|
|
|
unsafe {
|
|
|
|
for mode in modes {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_add_scheduling_mode(self.as_mut_ptr(), mode.to_glib());
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set(&mut self, flags: ::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) {
|
|
|
|
unsafe {
|
2017-07-31 11:16:42 +00:00
|
|
|
ffi::gst_query_set_scheduling(
|
2018-01-29 10:31:12 +00:00
|
|
|
self.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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> AcceptCaps<&'a QueryRef> {
|
2017-11-11 11:22:31 +00:00
|
|
|
pub fn get_caps(&self) -> &::CapsRef {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_accept_caps(self.as_mut_ptr(), &mut caps);
|
2017-07-29 11:58:54 +00:00
|
|
|
::CapsRef::from_ptr(caps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_result(&self) -> bool {
|
|
|
|
unsafe {
|
|
|
|
let mut accepted = mem::uninitialized();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_accept_caps_result(self.as_mut_ptr(), &mut accepted);
|
2017-07-29 11:58:54 +00:00
|
|
|
from_glib(accepted)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> AcceptCaps<&'a mut QueryRef> {
|
|
|
|
pub fn set_result(&mut self, accepted: bool) {
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_accept_caps_result(self.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);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Caps<&'a QueryRef> {
|
2017-12-17 09:32:01 +00:00
|
|
|
pub fn get_filter(&self) -> Option<&::CapsRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_caps(self.as_mut_ptr(), &mut caps);
|
2017-12-17 09:32:01 +00:00
|
|
|
if caps.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(::CapsRef::from_ptr(caps))
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 09:32:01 +00:00
|
|
|
pub fn get_result(&self) -> Option<&::CapsRef> {
|
2017-07-29 11:58:54 +00:00
|
|
|
unsafe {
|
|
|
|
let mut caps = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_caps_result(self.as_mut_ptr(), &mut caps);
|
2017-12-17 09:32:01 +00:00
|
|
|
if caps.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(::CapsRef::from_ptr(caps))
|
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Caps<&'a mut QueryRef> {
|
|
|
|
pub fn set_result(&mut self, caps: &::Caps) {
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_caps_result(self.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);
|
2017-07-29 11:58:54 +00:00
|
|
|
|
2018-01-29 10:31:12 +00:00
|
|
|
declare_concrete_query!(Context, T);
|
2017-07-29 11:58:54 +00:00
|
|
|
impl<'a> Context<&'a QueryRef> {
|
2017-08-02 17:58:33 +00:00
|
|
|
pub fn get_context(&self) -> Option<&::ContextRef> {
|
|
|
|
unsafe {
|
|
|
|
let mut context = ptr::null_mut();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_context(self.as_mut_ptr(), &mut context);
|
2017-08-02 17:58:33 +00:00
|
|
|
if context.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(::ContextRef::from_ptr(context))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_context_type(&self) -> &str {
|
|
|
|
unsafe {
|
|
|
|
let mut context_type = ptr::null();
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_parse_context_type(self.as_mut_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
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Context<&'a mut QueryRef> {
|
2017-08-02 17:58:33 +00:00
|
|
|
pub fn set_context(&mut self, context: &::Context) {
|
|
|
|
unsafe {
|
2018-01-29 10:31:12 +00:00
|
|
|
ffi::gst_query_set_context(self.as_mut_ptr(), context.as_mut_ptr());
|
2017-08-02 17:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 11:58:54 +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::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_writability() {
|
|
|
|
::init().unwrap();
|
|
|
|
|
|
|
|
let mut q = Query::new_position(::Format::Time);
|
|
|
|
|
|
|
|
match q.view() {
|
|
|
|
QueryView::Position(ref p) => {
|
2017-11-11 11:22:31 +00:00
|
|
|
let fmt = p.get_format();
|
|
|
|
assert_eq!(fmt, ::Format::Time);
|
2018-01-29 10:31:12 +00:00
|
|
|
assert!(!p.is_serialized());
|
2017-07-31 11:16:42 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
match q.get_mut().unwrap().view_mut() {
|
|
|
|
QueryView::Position(ref mut p) => {
|
2017-11-11 11:22:31 +00:00
|
|
|
let pos = p.get_result();
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(pos.try_into_time(), Ok(::CLOCK_TIME_NONE));
|
2017-11-11 10:21:55 +00:00
|
|
|
p.set(2 * ::SECOND);
|
2017-07-31 11:16:42 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
match q.view() {
|
|
|
|
QueryView::Position(ref p) => {
|
2017-11-11 11:22:31 +00:00
|
|
|
let pos = p.get_result();
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_eq!(pos.try_into_time(), Ok(2 * ::SECOND));
|
2017-07-31 11:16:42 +00:00
|
|
|
}
|
2017-07-29 11:58:54 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|