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. // 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. // The appsink will then call those handlers, as soon as data is available.
appsink.set_callbacks( appsink.set_callbacks(
gst_app::AppSinkCallbacks::new() gst_app::AppSinkCallbacks::builder()
// Add a handler to the "new-sample" signal. // Add a handler to the "new-sample" signal.
.new_sample(|appsink| { .new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer. // 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 // 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. // by creating a video info with the given format and creating caps from it for the appsrc element.
let video_info = 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)) .fps(gst::Fraction::new(2, 1))
.build() .build()
.expect("Failed to create video info"); .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 // 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, // a couple of times until all of them are filled. After this initial period,
// this handler will be called (on average) twice per second. // this handler will be called (on average) twice per second.
gst_app::AppSrcCallbacks::new() gst_app::AppSrcCallbacks::builder()
.need_data(move |appsrc, _| { .need_data(move |appsrc, _| {
// We only produce 100 frames // We only produce 100 frames
if i == 100 { if i == 100 {

View file

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

View file

@ -200,7 +200,7 @@ fn example_main() {
// of the closure of the need-data callback. // of the closure of the need-data callback.
let mut i = 0; let mut i = 0;
appsrc.set_callbacks( appsrc.set_callbacks(
gst_app::AppSrcCallbacks::new() gst_app::AppSrcCallbacks::builder()
.need_data(move |appsrc, _| { .need_data(move |appsrc, _| {
// We only produce 5 buffers. // We only produce 5 buffers.
if i == 5 { if i == 5 {
@ -228,7 +228,7 @@ fn example_main() {
// Getting data out of the appsink is done by setting callbacks on it. // 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. // The appsink will then call those handlers, as soon as data is available.
appsink.set_callbacks( appsink.set_callbacks(
gst_app::AppSinkCallbacks::new() gst_app::AppSinkCallbacks::builder()
// Add a handler to the "new-sample" signal. // Add a handler to the "new-sample" signal.
.new_sample(|appsink| { .new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer. // 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 events_proxy = events_loop.create_proxy();
let (sender, receiver) = mpsc::channel(); let (sender, receiver) = mpsc::channel();
self.appsink.set_callbacks( self.appsink.set_callbacks(
gst_app::AppSinkCallbacks::new() gst_app::AppSinkCallbacks::builder()
.new_sample(move |appsink| { .new_sample(move |appsink| {
let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?; 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 {} unsafe impl Sync for AppSinkCallbacks {}
impl AppSinkCallbacks { impl AppSinkCallbacks {
#[allow(clippy::new_ret_no_self)] pub fn builder() -> AppSinkCallbacksBuilder {
pub fn new() -> AppSinkCallbacksBuilder {
skip_assert_initialized!(); skip_assert_initialized!();
AppSinkCallbacksBuilder { AppSinkCallbacksBuilder {
eos: None, eos: None,
@ -366,7 +365,7 @@ impl AppSinkStream {
let waker_reference = Arc::new(Mutex::new(None as Option<Waker>)); let waker_reference = Arc::new(Mutex::new(None as Option<Waker>));
app_sink.set_callbacks( app_sink.set_callbacks(
AppSinkCallbacks::new() AppSinkCallbacks::builder()
.new_sample({ .new_sample({
let waker_reference = Arc::clone(&waker_reference); 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 // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() >= (1, 16, 3, 0) { if gst::version() >= (1, 16, 3, 0) {
if let Some(app_sink) = self.app_sink.upgrade() { 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 {} unsafe impl Sync for AppSrcCallbacks {}
impl AppSrcCallbacks { impl AppSrcCallbacks {
#[allow(clippy::new_ret_no_self)] pub fn builder() -> AppSrcCallbacksBuilder {
pub fn new() -> AppSrcCallbacksBuilder {
skip_assert_initialized!(); skip_assert_initialized!();
AppSrcCallbacksBuilder { AppSrcCallbacksBuilder {
@ -336,7 +335,7 @@ impl AppSrcSink {
let waker_reference = Arc::new(Mutex::new(None as Option<Waker>)); let waker_reference = Arc::new(Mutex::new(None as Option<Waker>));
app_src.set_callbacks( app_src.set_callbacks(
AppSrcCallbacks::new() AppSrcCallbacks::builder()
.need_data({ .need_data({
let waker_reference = Arc::clone(&waker_reference); 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 // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() >= (1, 16, 3, 0) { if gst::version() >= (1, 16, 3, 0) {
if let Some(app_src) = self.app_src.upgrade() { 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 sample_quantity = 5;
let samples = (0..sample_quantity) 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>>(); .collect::<Vec<gst::Sample>>();
let mut sample_stream = futures_util::stream::iter(samples).map(Ok); let mut sample_stream = futures_util::stream::iter(samples).map(Ok);

View file

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

View file

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

View file

@ -245,14 +245,17 @@ mod tests {
p[3] = 255; p[3] = 255;
} }
} }
let in_caps = ::VideoInfo::new(::VideoFormat::Rgba, 320, 240) let in_caps = ::VideoInfo::builder(::VideoFormat::Rgba, 320, 240)
.build() .build()
.unwrap() .unwrap()
.to_caps() .to_caps()
.unwrap(); .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() .build()
.unwrap() .unwrap()
.to_caps() .to_caps()

View file

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

View file

@ -15,15 +15,6 @@ use gst;
use gst::MiniObject; use gst::MiniObject;
use std::mem; 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 // FIXME: Copy from gstreamer/src/event.rs
macro_rules! event_builder_generic_impl { macro_rules! event_builder_generic_impl {
($new_fn:expr) => { ($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> { pub struct DownstreamForceKeyUnitEventBuilder<'a> {
seqnum: Option<gst::Seqnum>, seqnum: Option<gst::Seqnum>,
running_time_offset: Option<i64>, running_time_offset: Option<i64>,
@ -160,9 +147,14 @@ pub struct DownstreamForceKeyUnitEvent {
pub count: u32, pub count: u32,
} }
pub fn parse_downstream_force_key_unit_event( impl DownstreamForceKeyUnitEvent {
pub fn builder<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> {
DownstreamForceKeyUnitEventBuilder::new()
}
pub fn parse(
event: &gst::EventRef, event: &gst::EventRef,
) -> Result<DownstreamForceKeyUnitEvent, glib::error::BoolError> { ) -> Result<DownstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut timestamp = mem::MaybeUninit::uninit(); let mut timestamp = mem::MaybeUninit::uninit();
@ -193,10 +185,7 @@ pub fn parse_downstream_force_key_unit_event(
Err(glib_bool_error!("Failed to parse GstEvent")) 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> { pub struct UpstreamForceKeyUnitEventBuilder<'a> {
@ -255,9 +244,14 @@ pub struct UpstreamForceKeyUnitEvent {
pub count: u32, pub count: u32,
} }
pub fn parse_upstream_force_key_unit_event( impl UpstreamForceKeyUnitEvent {
pub fn builder<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> {
UpstreamForceKeyUnitEventBuilder::new()
}
pub fn parse(
event: &gst::EventRef, event: &gst::EventRef,
) -> Result<UpstreamForceKeyUnitEvent, glib::error::BoolError> { ) -> Result<UpstreamForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut running_time = mem::MaybeUninit::uninit(); let mut running_time = mem::MaybeUninit::uninit();
@ -282,6 +276,7 @@ pub fn parse_upstream_force_key_unit_event(
Err(glib_bool_error!("Failed to parse GstEvent")) Err(glib_bool_error!("Failed to parse GstEvent"))
} }
} }
}
} }
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]
@ -290,20 +285,24 @@ pub enum ForceKeyUnitEvent {
Upstream(UpstreamForceKeyUnitEvent), Upstream(UpstreamForceKeyUnitEvent),
} }
pub fn parse_force_key_unit_event( impl ForceKeyUnitEvent {
event: &gst::EventRef, pub fn is(event: &gst::EventRef) -> bool {
) -> Result<ForceKeyUnitEvent, glib::error::BoolError> { skip_assert_initialized!();
unsafe {
from_glib(gst_video_sys::gst_video_event_is_force_key_unit(
event.as_mut_ptr(),
))
}
}
pub fn parse(event: &gst::EventRef) -> Result<ForceKeyUnitEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if event.is_upstream() { if event.is_upstream() {
parse_upstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Upstream) UpstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Upstream)
} else { } else {
parse_downstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Downstream) DownstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Downstream)
}
} }
}
pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
assert_initialized_main_thread!();
StillFrameEventBuilder::new(in_still)
} }
pub struct StillFrameEventBuilder<'a> { pub struct StillFrameEventBuilder<'a> {
@ -334,9 +333,13 @@ pub struct StillFrameEvent {
pub in_still: bool, pub in_still: bool,
} }
pub fn parse_still_frame_event( impl StillFrameEvent {
event: &gst::EventRef, pub fn builder<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
) -> Result<StillFrameEvent, glib::error::BoolError> { assert_initialized_main_thread!();
StillFrameEventBuilder::new(in_still)
}
pub fn parse(event: &gst::EventRef) -> Result<StillFrameEvent, glib::error::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut in_still = mem::MaybeUninit::uninit(); let mut in_still = mem::MaybeUninit::uninit();
@ -353,4 +356,5 @@ pub fn parse_still_frame_event(
Err(glib_bool_error!("Invalid still-frame event")) Err(glib_bool_error!("Invalid still-frame event"))
} }
} }
}
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -47,7 +47,7 @@ struct SampleDe {
impl From<SampleDe> for Sample { impl From<SampleDe> for Sample {
fn from(buf_de: SampleDe) -> Self { fn from(buf_de: SampleDe) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
let mut builder = Sample::new(); let mut builder = Sample::builder();
if let Some(buffer) = buf_de.buffer.as_ref() { if let Some(buffer) = buf_de.buffer.as_ref() {
builder = builder.buffer(buffer); builder = builder.buffer(buffer);
@ -133,7 +133,7 @@ mod tests {
.field("f3", &123i32) .field("f3", &123i32)
.build(); .build();
Sample::new() Sample::builder()
.buffer(&buffer) .buffer(&buffer)
.caps(&caps) .caps(&caps)
.segment(&segment) .segment(&segment)
@ -196,7 +196,7 @@ mod tests {
buffer.set_offset_end(4); buffer.set_offset_end(4);
buffer.set_duration(4.into()); 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 // `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) .field("f3", &123i32)
.build(); .build();
Sample::new() Sample::builder()
.buffer(&buffer) .buffer(&buffer)
.caps(&caps) .caps(&caps)
.segment(&segment) .segment(&segment)

View file

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

View file

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

View file

@ -123,7 +123,7 @@ fn main() {
tee_app_pad.link(&queue_app_pad).unwrap(); tee_app_pad.link(&queue_app_pad).unwrap();
// configure appsrc // 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() .build()
.unwrap(); .unwrap();
let audio_caps = info.to_caps().unwrap(); let audio_caps = info.to_caps().unwrap();