Add Context support for messages/queries

This commit is contained in:
Sebastian Dröge 2017-08-02 20:58:33 +03:00
parent bf0f472014
commit a0c6db70e0
2 changed files with 45 additions and 10 deletions

View file

@ -265,7 +265,7 @@ impl Message {
NeedContextBuilder::new(context_type) NeedContextBuilder::new(context_type)
} }
pub fn new_have_context(context: ()) -> HaveContextBuilder { pub fn new_have_context(context: ::Context) -> HaveContextBuilder {
HaveContextBuilder::new(context) HaveContextBuilder::new(context)
} }
@ -933,7 +933,13 @@ impl<'a> NeedContext<'a> {
pub struct HaveContext<'a>(&'a MessageRef); pub struct HaveContext<'a>(&'a MessageRef);
impl<'a> HaveContext<'a> { 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); pub struct DeviceAdded<'a>(&'a MessageRef);
@ -1984,24 +1990,23 @@ impl<'a> NeedContextBuilder<'a> {
}); });
} }
// TODO Context
pub struct HaveContextBuilder { pub struct HaveContextBuilder {
src: Option<Object>, src: Option<Object>,
seqnum: Option<u32>, seqnum: Option<u32>,
#[allow(unused)] context: Option<::Context>,
context: (),
} }
impl HaveContextBuilder { impl HaveContextBuilder {
pub fn new(context: () /* ::Context */) -> Self { pub fn new(context: ::Context) -> Self {
Self { Self {
src: None, src: None,
seqnum: None, seqnum: None,
context: context, context: Some(context),
} }
} }
message_builder_generic_impl!(|_, src| { message_builder_generic_impl!(|s: &mut Self, src| {
ffi::gst_message_new_have_context(src, ptr::null_mut() /*s.context.to_glib_full().0*/) let context = s.context.take().unwrap();
ffi::gst_message_new_have_context(src, context.into_ptr())
}); });
} }

View file

@ -12,6 +12,7 @@ use structure::*;
use std::ptr; use std::ptr;
use std::mem; use std::mem;
use std::ffi::CStr;
use std::ops::Deref; use std::ops::Deref;
use glib; use glib;
@ -93,6 +94,10 @@ impl Query {
pub fn new_drain() -> Self { pub fn new_drain() -> Self {
unsafe { from_glib_full(ffi::gst_query_new_drain()) } 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 { impl QueryRef {
@ -850,15 +855,40 @@ impl<'a> Drain<&'a mut QueryRef> {
} }
} }
// TODO
pub struct Context<T>(T); pub struct Context<T>(T);
impl<'a> Context<&'a QueryRef> { 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 { pub fn get_query(&self) -> &QueryRef {
self.0 self.0
} }
} }
impl<'a> Context<&'a mut QueryRef> { 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 { pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0 self.0
} }