rtp/gir: Manually implement RtpHeaderExtension read() and write()

The array size is now provided since [1], yet mutability and `*Ref`
makes it impossible to generate these functions properly.  Implement
them by hand.

[1]: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1190
This commit is contained in:
Marijn Suijten 2021-06-28 14:17:13 +02:00 committed by Sebastian Dröge
parent 6275b4ba70
commit ffa9697edd
3 changed files with 72 additions and 3 deletions

View file

@ -65,11 +65,11 @@ status = "manual"
[[object]]
name = "GstRtp.RTPHeaderExtension"
status = "generate"
manual_traits = ["RTPHeaderExtensionExtManual"]
[[object.function]]
pattern = "read|write"
# Until 1.19.2: `data` field lacks`array size` annotation:
# https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1190
ignore = true
# Mutability of BufferRef
manual = true
[[object.function]]
name = "get_sdp_caps_field_name"

View file

@ -28,6 +28,9 @@ pub use crate::auto::*;
pub mod rtp_buffer;
pub use crate::rtp_buffer::{compare_seqnum, RTPBuffer};
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub mod rtp_header_extension;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst_rtp::prelude::*" without getting conflicts
@ -38,4 +41,7 @@ pub mod prelude {
pub use crate::auto::traits::*;
pub use crate::rtp_buffer::RTPBufferExt;
#[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
pub use crate::rtp_header_extension::RTPHeaderExtensionExtManual;
}

View file

@ -0,0 +1,63 @@
use crate::RTPHeaderExtension;
use crate::RTPHeaderExtensionFlags;
use glib::object::IsA;
use glib::translate::*;
pub trait RTPHeaderExtensionExtManual: 'static {
#[doc(alias = "gst_rtp_header_extension_read")]
fn read(
&self,
read_flags: RTPHeaderExtensionFlags,
data: &[u8],
buffer: &mut gst::BufferRef,
) -> bool;
#[doc(alias = "gst_rtp_header_extension_write")]
fn write(
&self,
input_meta: &gst::Buffer,
write_flags: RTPHeaderExtensionFlags,
output: &mut gst::BufferRef,
data: &mut [u8],
) -> usize;
}
impl<O: IsA<RTPHeaderExtension>> RTPHeaderExtensionExtManual for O {
fn read(
&self,
read_flags: RTPHeaderExtensionFlags,
data: &[u8],
buffer: &mut gst::BufferRef,
) -> bool {
let size = data.len() as usize;
unsafe {
from_glib(ffi::gst_rtp_header_extension_read(
self.as_ref().to_glib_none().0,
read_flags.into_glib(),
data.to_glib_none().0,
size,
buffer.as_mut_ptr(),
))
}
}
fn write(
&self,
input_meta: &gst::Buffer,
write_flags: RTPHeaderExtensionFlags,
output: &mut gst::BufferRef,
data: &mut [u8],
) -> usize {
let size = data.len() as usize;
unsafe {
ffi::gst_rtp_header_extension_write(
self.as_ref().to_glib_none().0,
input_meta.to_glib_none().0,
write_flags.into_glib(),
output.as_mut_ptr(),
data.to_glib_none().0,
size,
)
}
}
}