mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-10-31 14:49:24 +00:00
Add Context support for messages/queries
This commit is contained in:
parent
bf0f472014
commit
a0c6db70e0
2 changed files with 45 additions and 10 deletions
|
@ -265,7 +265,7 @@ impl Message {
|
|||
NeedContextBuilder::new(context_type)
|
||||
}
|
||||
|
||||
pub fn new_have_context(context: ()) -> HaveContextBuilder {
|
||||
pub fn new_have_context(context: ::Context) -> HaveContextBuilder {
|
||||
HaveContextBuilder::new(context)
|
||||
}
|
||||
|
||||
|
@ -933,7 +933,13 @@ impl<'a> NeedContext<'a> {
|
|||
|
||||
pub struct HaveContext<'a>(&'a MessageRef);
|
||||
impl<'a> HaveContext<'a> {
|
||||
// TODO: get_context()
|
||||
pub fn get_context(&self) -> ::Context {
|
||||
unsafe {
|
||||
let mut context = ptr::null_mut();
|
||||
ffi::gst_message_parse_have_context(self.0.as_mut_ptr(), &mut context);
|
||||
from_glib_full(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DeviceAdded<'a>(&'a MessageRef);
|
||||
|
@ -1984,24 +1990,23 @@ impl<'a> NeedContextBuilder<'a> {
|
|||
});
|
||||
}
|
||||
|
||||
// TODO Context
|
||||
pub struct HaveContextBuilder {
|
||||
src: Option<Object>,
|
||||
seqnum: Option<u32>,
|
||||
#[allow(unused)]
|
||||
context: (),
|
||||
context: Option<::Context>,
|
||||
}
|
||||
impl HaveContextBuilder {
|
||||
pub fn new(context: () /* ::Context */) -> Self {
|
||||
pub fn new(context: ::Context) -> Self {
|
||||
Self {
|
||||
src: None,
|
||||
seqnum: None,
|
||||
context: context,
|
||||
context: Some(context),
|
||||
}
|
||||
}
|
||||
|
||||
message_builder_generic_impl!(|_, src| {
|
||||
ffi::gst_message_new_have_context(src, ptr::null_mut() /*s.context.to_glib_full().0*/)
|
||||
message_builder_generic_impl!(|s: &mut Self, src| {
|
||||
let context = s.context.take().unwrap();
|
||||
ffi::gst_message_new_have_context(src, context.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use structure::*;
|
|||
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::ffi::CStr;
|
||||
use std::ops::Deref;
|
||||
|
||||
use glib;
|
||||
|
@ -93,6 +94,10 @@ impl Query {
|
|||
pub fn new_drain() -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_query_new_drain()) }
|
||||
}
|
||||
|
||||
pub fn new_context(context_type: &str) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_query_new_context(context_type.to_glib_none().0)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryRef {
|
||||
|
@ -850,15 +855,40 @@ impl<'a> Drain<&'a mut QueryRef> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
pub struct Context<T>(T);
|
||||
impl<'a> Context<&'a QueryRef> {
|
||||
pub fn get_context(&self) -> Option<&::ContextRef> {
|
||||
unsafe {
|
||||
let mut context = ptr::null_mut();
|
||||
ffi::gst_query_parse_context(self.0.as_mut_ptr(), &mut context);
|
||||
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();
|
||||
ffi::gst_query_parse_context_type(self.0.as_mut_ptr(), &mut context_type);
|
||||
CStr::from_ptr(context_type).to_str().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_query(&self) -> &QueryRef {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Context<&'a mut QueryRef> {
|
||||
pub fn set_context(&mut self, context: &::Context) {
|
||||
unsafe {
|
||||
ffi::gst_query_set_context(self.0.as_mut_ptr(), context.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut_query(&mut self) -> &mut QueryRef {
|
||||
self.0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue