Name functions returning a builder builder(), not new()

And also make the video event API more consistent with the normal event
API.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/269
This commit is contained in:
Sebastian Dröge 2020-06-25 19:22:25 +03:00
parent ddd3bbbf84
commit 947ac8db5c
20 changed files with 162 additions and 158 deletions

View file

@ -72,7 +72,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Getting data out of the appsink is done by setting callbacks on it.
// The appsink will then call those handlers, as soon as data is available.
appsink.set_callbacks(
gst_app::AppSinkCallbacks::new()
gst_app::AppSinkCallbacks::builder()
// Add a handler to the "new-sample" signal.
.new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer.

View file

@ -57,7 +57,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Specify the format we want to provide as application into the pipeline
// by creating a video info with the given format and creating caps from it for the appsrc element.
let video_info =
gst_video::VideoInfo::new(gst_video::VideoFormat::Bgrx, WIDTH as u32, HEIGHT as u32)
gst_video::VideoInfo::builder(gst_video::VideoFormat::Bgrx, WIDTH as u32, HEIGHT as u32)
.fps(gst::Fraction::new(2, 1))
.build()
.expect("Failed to create video info");
@ -80,7 +80,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// buffers of all elements of the pipeline are still empty, this will be called
// a couple of times until all of them are filled. After this initial period,
// this handler will be called (on average) twice per second.
gst_app::AppSrcCallbacks::new()
gst_app::AppSrcCallbacks::builder()
.need_data(move |appsrc, _| {
// We only produce 100 frames
if i == 100 {

View file

@ -19,14 +19,15 @@ pub struct ExampleCustomEvent {
impl ExampleCustomEvent {
const EVENT_NAME: &'static str = "example-custom-event";
pub fn new_event(send_eos: bool) -> gst::Event {
#[allow(clippy::new_ret_no_self)]
pub fn new(send_eos: bool) -> gst::Event {
let s = gst::Structure::builder(Self::EVENT_NAME)
.field("send_eos", &send_eos)
.build();
gst::event::CustomDownstream::new(s)
}
pub fn from_event(ev: &gst::Event) -> Option<ExampleCustomEvent> {
pub fn parse(ev: &gst::EventRef) -> Option<ExampleCustomEvent> {
match ev.view() {
gst::EventView::CustomDownstream(e) => {
let s = match e.get_structure() {
@ -79,7 +80,7 @@ fn example_main() {
Some(gst::PadProbeData::Event(ref ev))
if ev.get_type() == gst::EventType::CustomDownstream =>
{
if let Some(custom_event) = ExampleCustomEvent::from_event(ev) {
if let Some(custom_event) = ExampleCustomEvent::parse(ev) {
if let Some(pipeline) = pipeline_weak.upgrade() {
if custom_event.send_eos {
/* Send EOS event to shut down the pipeline, but from an async callback, as we're
@ -121,7 +122,7 @@ fn example_main() {
"Sending custom event to the pipeline with send_eos={}",
send_eos
);
let ev = ExampleCustomEvent::new_event(*send_eos);
let ev = ExampleCustomEvent::new(*send_eos);
if !pipeline.send_event(ev) {
println!("Warning: Failed to send custom event");
}

View file

@ -200,7 +200,7 @@ fn example_main() {
// of the closure of the need-data callback.
let mut i = 0;
appsrc.set_callbacks(
gst_app::AppSrcCallbacks::new()
gst_app::AppSrcCallbacks::builder()
.need_data(move |appsrc, _| {
// We only produce 5 buffers.
if i == 5 {
@ -228,7 +228,7 @@ fn example_main() {
// Getting data out of the appsink is done by setting callbacks on it.
// The appsink will then call those handlers, as soon as data is available.
appsink.set_callbacks(
gst_app::AppSinkCallbacks::new()
gst_app::AppSinkCallbacks::builder()
// Add a handler to the "new-sample" signal.
.new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer.

View file

@ -469,7 +469,7 @@ impl App {
let events_proxy = events_loop.create_proxy();
let (sender, receiver) = mpsc::channel();
self.appsink.set_callbacks(
gst_app::AppSinkCallbacks::new()
gst_app::AppSinkCallbacks::builder()
.new_sample(move |appsink| {
let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?;

View file

@ -55,8 +55,7 @@ unsafe impl Send for AppSinkCallbacks {}
unsafe impl Sync for AppSinkCallbacks {}
impl AppSinkCallbacks {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> AppSinkCallbacksBuilder {
pub fn builder() -> AppSinkCallbacksBuilder {
skip_assert_initialized!();
AppSinkCallbacksBuilder {
eos: None,
@ -366,7 +365,7 @@ impl AppSinkStream {
let waker_reference = Arc::new(Mutex::new(None as Option<Waker>));
app_sink.set_callbacks(
AppSinkCallbacks::new()
AppSinkCallbacks::builder()
.new_sample({
let waker_reference = Arc::clone(&waker_reference);
@ -404,7 +403,7 @@ impl Drop for AppSinkStream {
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() >= (1, 16, 3, 0) {
if let Some(app_sink) = self.app_sink.upgrade() {
app_sink.set_callbacks(AppSinkCallbacks::new().build());
app_sink.set_callbacks(AppSinkCallbacks::builder().build());
}
}
}

View file

@ -37,8 +37,7 @@ unsafe impl Send for AppSrcCallbacks {}
unsafe impl Sync for AppSrcCallbacks {}
impl AppSrcCallbacks {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> AppSrcCallbacksBuilder {
pub fn builder() -> AppSrcCallbacksBuilder {
skip_assert_initialized!();
AppSrcCallbacksBuilder {
@ -336,7 +335,7 @@ impl AppSrcSink {
let waker_reference = Arc::new(Mutex::new(None as Option<Waker>));
app_src.set_callbacks(
AppSrcCallbacks::new()
AppSrcCallbacks::builder()
.need_data({
let waker_reference = Arc::clone(&waker_reference);
@ -362,7 +361,7 @@ impl Drop for AppSrcSink {
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() >= (1, 16, 3, 0) {
if let Some(app_src) = self.app_src.upgrade() {
app_src.set_callbacks(AppSrcCallbacks::new().build());
app_src.set_callbacks(AppSrcCallbacks::builder().build());
}
}
}
@ -446,7 +445,7 @@ mod tests {
let sample_quantity = 5;
let samples = (0..sample_quantity)
.map(|_| gst::Sample::new().buffer(&gst::Buffer::new()).build())
.map(|_| gst::Sample::builder().buffer(&gst::Buffer::new()).build())
.collect::<Vec<gst::Sample>>();
let mut sample_stream = futures_util::stream::iter(samples).map(Ok);

View file

@ -524,7 +524,7 @@ mod tests {
fn test_map_read() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -554,7 +554,7 @@ mod tests {
fn test_map_read_planar() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved)
.build()
.unwrap();
@ -593,7 +593,7 @@ mod tests {
fn test_map_write() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -623,7 +623,7 @@ mod tests {
fn test_map_write_planar() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved)
.build()
.unwrap();
@ -662,7 +662,7 @@ mod tests {
fn test_map_ref_read() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -683,7 +683,7 @@ mod tests {
fn test_map_ref_read_planar() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved)
.build()
.unwrap();
@ -712,7 +712,7 @@ mod tests {
fn test_map_ref_write() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.build()
.unwrap();
let mut buffer =
@ -738,7 +738,7 @@ mod tests {
fn test_map_ref_write_planar() {
gst::init().unwrap();
let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2)
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved)
.build()
.unwrap();

View file

@ -137,8 +137,7 @@ impl<'a> AudioInfoBuilder<'a> {
}
impl AudioInfo {
#[allow(clippy::new_ret_no_self)]
pub fn new<'a>(format: ::AudioFormat, rate: u32, channels: u32) -> AudioInfoBuilder<'a> {
pub fn builder<'a>(format: ::AudioFormat, rate: u32, channels: u32) -> AudioInfoBuilder<'a> {
assert_initialized_main_thread!();
AudioInfoBuilder {
@ -424,7 +423,7 @@ mod tests {
fn test_new() {
gst::init().unwrap();
let info = AudioInfo::new(::AudioFormat::S16le, 48000, 2)
let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2)
.build()
.unwrap();
assert_eq!(info.format(), ::AudioFormat::S16le);
@ -442,7 +441,7 @@ mod tests {
::AudioChannelPosition::RearLeft,
::AudioChannelPosition::RearRight,
];
let info = AudioInfo::new(::AudioFormat::S16le, 48000, 2)
let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2)
.positions(&positions)
.build()
.unwrap();

View file

@ -245,14 +245,17 @@ mod tests {
p[3] = 255;
}
}
let in_caps = ::VideoInfo::new(::VideoFormat::Rgba, 320, 240)
let in_caps = ::VideoInfo::builder(::VideoFormat::Rgba, 320, 240)
.build()
.unwrap()
.to_caps()
.unwrap();
let sample = gst::Sample::new().buffer(&in_buffer).caps(&in_caps).build();
let sample = gst::Sample::builder()
.buffer(&in_buffer)
.caps(&in_caps)
.build();
let out_caps = ::VideoInfo::new(::VideoFormat::Abgr, 320, 240)
let out_caps = ::VideoInfo::builder(::VideoFormat::Abgr, 320, 240)
.build()
.unwrap()
.to_caps()

View file

@ -64,8 +64,10 @@ pub mod video_frame;
pub use video_frame::{VideoBufferExt, VideoFrame, VideoFrameRef};
mod video_overlay;
pub use video_overlay::{is_video_overlay_prepare_window_handle_message, VideoOverlayExtManual};
mod video_event;
pub use video_event::*;
pub mod video_event;
pub use video_event::{
DownstreamForceKeyUnitEvent, ForceKeyUnitEvent, StillFrameEvent, UpstreamForceKeyUnitEvent,
};
mod functions;
pub use functions::*;
mod video_rectangle;

View file

@ -15,15 +15,6 @@ use gst;
use gst::MiniObject;
use std::mem;
pub fn is_force_key_unit_event(event: &gst::EventRef) -> bool {
skip_assert_initialized!();
unsafe {
from_glib(gst_video_sys::gst_video_event_is_force_key_unit(
event.as_mut_ptr(),
))
}
}
// FIXME: Copy from gstreamer/src/event.rs
macro_rules! event_builder_generic_impl {
($new_fn:expr) => {
@ -81,10 +72,6 @@ macro_rules! event_builder_generic_impl {
};
}
pub fn new_downstream_force_key_unit_event<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> {
DownstreamForceKeyUnitEventBuilder::new()
}
pub struct DownstreamForceKeyUnitEventBuilder<'a> {
seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>,
@ -160,45 +147,47 @@ pub struct DownstreamForceKeyUnitEvent {
pub count: u32,
}
pub fn parse_downstream_force_key_unit_event(
event: &gst::EventRef,
) -> Result<DownstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut timestamp = mem::MaybeUninit::uninit();
let mut stream_time = mem::MaybeUninit::uninit();
let mut running_time = mem::MaybeUninit::uninit();
let mut all_headers = mem::MaybeUninit::uninit();
let mut count = mem::MaybeUninit::uninit();
impl DownstreamForceKeyUnitEvent {
pub fn builder<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> {
DownstreamForceKeyUnitEventBuilder::new()
}
let res: bool = from_glib(
gst_video_sys::gst_video_event_parse_downstream_force_key_unit(
event.as_mut_ptr(),
timestamp.as_mut_ptr(),
stream_time.as_mut_ptr(),
running_time.as_mut_ptr(),
all_headers.as_mut_ptr(),
count.as_mut_ptr(),
),
);
if res {
Ok(DownstreamForceKeyUnitEvent {
timestamp: from_glib(timestamp.assume_init()),
stream_time: from_glib(stream_time.assume_init()),
running_time: from_glib(running_time.assume_init()),
all_headers: from_glib(all_headers.assume_init()),
count: count.assume_init(),
})
} else {
Err(glib_bool_error!("Failed to parse GstEvent"))
pub fn parse(
event: &gst::EventRef,
) -> Result<DownstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut timestamp = mem::MaybeUninit::uninit();
let mut stream_time = mem::MaybeUninit::uninit();
let mut running_time = mem::MaybeUninit::uninit();
let mut all_headers = mem::MaybeUninit::uninit();
let mut count = mem::MaybeUninit::uninit();
let res: bool = from_glib(
gst_video_sys::gst_video_event_parse_downstream_force_key_unit(
event.as_mut_ptr(),
timestamp.as_mut_ptr(),
stream_time.as_mut_ptr(),
running_time.as_mut_ptr(),
all_headers.as_mut_ptr(),
count.as_mut_ptr(),
),
);
if res {
Ok(DownstreamForceKeyUnitEvent {
timestamp: from_glib(timestamp.assume_init()),
stream_time: from_glib(stream_time.assume_init()),
running_time: from_glib(running_time.assume_init()),
all_headers: from_glib(all_headers.assume_init()),
count: count.assume_init(),
})
} else {
Err(glib_bool_error!("Failed to parse GstEvent"))
}
}
}
}
pub fn new_upstream_force_key_unit_event<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> {
UpstreamForceKeyUnitEventBuilder::new()
}
pub struct UpstreamForceKeyUnitEventBuilder<'a> {
seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>,
@ -255,31 +244,37 @@ pub struct UpstreamForceKeyUnitEvent {
pub count: u32,
}
pub fn parse_upstream_force_key_unit_event(
event: &gst::EventRef,
) -> Result<UpstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut running_time = mem::MaybeUninit::uninit();
let mut all_headers = mem::MaybeUninit::uninit();
let mut count = mem::MaybeUninit::uninit();
impl UpstreamForceKeyUnitEvent {
pub fn builder<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> {
UpstreamForceKeyUnitEventBuilder::new()
}
let res: bool = from_glib(
gst_video_sys::gst_video_event_parse_upstream_force_key_unit(
event.as_mut_ptr(),
running_time.as_mut_ptr(),
all_headers.as_mut_ptr(),
count.as_mut_ptr(),
),
);
if res {
Ok(UpstreamForceKeyUnitEvent {
running_time: from_glib(running_time.assume_init()),
all_headers: from_glib(all_headers.assume_init()),
count: count.assume_init(),
})
} else {
Err(glib_bool_error!("Failed to parse GstEvent"))
pub fn parse(
event: &gst::EventRef,
) -> Result<UpstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut running_time = mem::MaybeUninit::uninit();
let mut all_headers = mem::MaybeUninit::uninit();
let mut count = mem::MaybeUninit::uninit();
let res: bool = from_glib(
gst_video_sys::gst_video_event_parse_upstream_force_key_unit(
event.as_mut_ptr(),
running_time.as_mut_ptr(),
all_headers.as_mut_ptr(),
count.as_mut_ptr(),
),
);
if res {
Ok(UpstreamForceKeyUnitEvent {
running_time: from_glib(running_time.assume_init()),
all_headers: from_glib(all_headers.assume_init()),
count: count.assume_init(),
})
} else {
Err(glib_bool_error!("Failed to parse GstEvent"))
}
}
}
}
@ -290,20 +285,24 @@ pub enum ForceKeyUnitEvent {
Upstream(UpstreamForceKeyUnitEvent),
}
pub fn parse_force_key_unit_event(
event: &gst::EventRef,
) -> Result<ForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
if event.is_upstream() {
parse_upstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Upstream)
} else {
parse_downstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Downstream)
impl ForceKeyUnitEvent {
pub fn is(event: &gst::EventRef) -> bool {
skip_assert_initialized!();
unsafe {
from_glib(gst_video_sys::gst_video_event_is_force_key_unit(
event.as_mut_ptr(),
))
}
}
}
pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
assert_initialized_main_thread!();
StillFrameEventBuilder::new(in_still)
pub fn parse(event: &gst::EventRef) -> Result<ForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!();
if event.is_upstream() {
UpstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Upstream)
} else {
DownstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Downstream)
}
}
}
pub struct StillFrameEventBuilder<'a> {
@ -334,23 +333,28 @@ pub struct StillFrameEvent {
pub in_still: bool,
}
pub fn parse_still_frame_event(
event: &gst::EventRef,
) -> Result<StillFrameEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut in_still = mem::MaybeUninit::uninit();
impl StillFrameEvent {
pub fn builder<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
assert_initialized_main_thread!();
StillFrameEventBuilder::new(in_still)
}
let res: bool = from_glib(gst_video_sys::gst_video_event_parse_still_frame(
event.as_mut_ptr(),
in_still.as_mut_ptr(),
));
if res {
Ok(StillFrameEvent {
in_still: from_glib(in_still.assume_init()),
})
} else {
Err(glib_bool_error!("Invalid still-frame event"))
pub fn parse(event: &gst::EventRef) -> Result<StillFrameEvent, glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
let mut in_still = mem::MaybeUninit::uninit();
let res: bool = from_glib(gst_video_sys::gst_video_event_parse_still_frame(
event.as_mut_ptr(),
in_still.as_mut_ptr(),
));
if res {
Ok(StillFrameEvent {
in_still: from_glib(in_still.assume_init()),
})
} else {
Err(glib_bool_error!("Invalid still-frame event"))
}
}
}
}

View file

@ -847,7 +847,7 @@ mod tests {
fn test_map_read() {
gst::init().unwrap();
let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240)
let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.size()).unwrap();
@ -877,7 +877,7 @@ mod tests {
fn test_map_write() {
gst::init().unwrap();
let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240)
let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.size()).unwrap();
@ -907,7 +907,7 @@ mod tests {
fn test_map_ref_read() {
gst::init().unwrap();
let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240)
let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240)
.build()
.unwrap();
let buffer = gst::Buffer::with_size(info.size()).unwrap();
@ -923,7 +923,7 @@ mod tests {
fn test_map_ref_write() {
gst::init().unwrap();
let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240)
let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240)
.build()
.unwrap();
let mut buffer = gst::Buffer::with_size(info.size()).unwrap();

View file

@ -511,8 +511,7 @@ impl<'a> VideoInfoBuilder<'a> {
}
impl VideoInfo {
#[allow(clippy::new_ret_no_self)]
pub fn new<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> {
pub fn builder<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> {
assert_initialized_main_thread!();
#[cfg(not(any(feature = "v1_12", feature = "dox")))]
@ -950,7 +949,7 @@ mod tests {
fn test_new() {
gst::init().unwrap();
let info = VideoInfo::new(::VideoFormat::I420, 320, 240)
let info = VideoInfo::builder(::VideoFormat::I420, 320, 240)
.build()
.unwrap();
assert_eq!(info.format(), ::VideoFormat::I420);
@ -963,7 +962,7 @@ mod tests {
let offsets = [0, 640 * 240 + 16, 640 * 240 + 16 + 320 * 120 + 16];
let strides = [640, 320, 320];
let info = VideoInfo::new(::VideoFormat::I420, 320, 240)
let info = VideoInfo::builder(::VideoFormat::I420, 320, 240)
.offset(&offsets)
.stride(&strides)
.size(640 * 240 + 16 + 320 * 120 + 16 + 320 * 120 + 16)
@ -1023,7 +1022,7 @@ mod tests {
fn test_video_align() {
gst::init().unwrap();
let mut info = ::VideoInfo::new(::VideoFormat::Nv16, 1920, 1080)
let mut info = ::VideoInfo::builder(::VideoFormat::Nv16, 1920, 1080)
.build()
.expect("Failed to create VideoInfo");

View file

@ -36,7 +36,7 @@ impl VideoMeta {
return Err(glib_bool_error!("Unsupported video format {}", format));
}
let info = ::VideoInfo::new(format, width, height).build()?;
let info = ::VideoInfo::builder(format, width, height).build()?;
if !info.is_valid() {
return Err(glib_bool_error!("Invalid video info"));
@ -83,7 +83,7 @@ impl VideoMeta {
}
let n_planes = offset.len() as u32;
let info = ::VideoInfo::new(format, width, height)
let info = ::VideoInfo::builder(format, width, height)
.offset(offset)
.stride(stride)
.build()?;

View file

@ -104,8 +104,7 @@ impl<'a> SampleBuilder<'a> {
}
impl Sample {
#[allow(clippy::new_ret_no_self)]
pub fn new<'a>() -> SampleBuilder<'a> {
pub fn builder<'a>() -> SampleBuilder<'a> {
SampleBuilder {
buffer: None,
buffer_list: None,
@ -239,7 +238,7 @@ mod tests {
let info = Structure::builder("sample.info")
.field("f3", &123i32)
.build();
let sample = Sample::new().info(info).build();
let sample = Sample::builder().info(info).build();
assert!(sample.get_info().is_some());
}

View file

@ -47,7 +47,7 @@ struct SampleDe {
impl From<SampleDe> for Sample {
fn from(buf_de: SampleDe) -> Self {
skip_assert_initialized!();
let mut builder = Sample::new();
let mut builder = Sample::builder();
if let Some(buffer) = buf_de.buffer.as_ref() {
builder = builder.buffer(buffer);
@ -133,7 +133,7 @@ mod tests {
.field("f3", &123i32)
.build();
Sample::new()
Sample::builder()
.buffer(&buffer)
.caps(&caps)
.segment(&segment)
@ -196,7 +196,7 @@ mod tests {
buffer.set_offset_end(4);
buffer.set_duration(4.into());
}
Sample::new().buffer(&buffer).build()
Sample::builder().buffer(&buffer).build()
};
// `Sample`'s `Segment` is allocated in GStreamer 1.x, should be fixed in version 2.0
@ -363,7 +363,7 @@ mod tests {
.field("f3", &123i32)
.build();
Sample::new()
Sample::builder()
.buffer(&buffer)
.caps(&caps)
.segment(&segment)

View file

@ -102,8 +102,7 @@ impl StreamCollectionBuilder {
}
impl StreamCollection {
#[allow(clippy::new_ret_no_self)]
pub fn new(upstream_id: Option<&str>) -> StreamCollectionBuilder {
pub fn builder(upstream_id: Option<&str>) -> StreamCollectionBuilder {
assert_initialized_main_thread!();
let upstream_id = upstream_id.to_glib_none();
let (major, minor, _, _) = ::version();

View file

@ -366,7 +366,7 @@ mod tests {
buffer.set_offset(0);
buffer.set_offset_end(0);
}
Sample::new().buffer(&buffer).build()
Sample::builder().buffer(&buffer).build()
};
tags.add::<Image>(&sample, TagMergeMode::Append); // Sample
}
@ -588,7 +588,7 @@ mod tests {
buffer.set_offset(0);
buffer.set_offset_end(0);
}
Sample::new().buffer(&buffer).build()
Sample::builder().buffer(&buffer).build()
};
tags.add::<Image>(&sample, TagMergeMode::Append); // Sample
}

View file

@ -123,7 +123,7 @@ fn main() {
tee_app_pad.link(&queue_app_pad).unwrap();
// configure appsrc
let info = AudioInfo::new(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1)
let info = AudioInfo::builder(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1)
.build()
.unwrap();
let audio_caps = info.to_caps().unwrap();