From bc5b51687dacd2a1e4dadae8c4426a253a825ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Tue, 11 Oct 2022 12:51:00 +0200 Subject: [PATCH] fix formatted values constructors In restrospect, building formatted values using operations on the `ONE` constant doesn't seem idiomatic. This commit uses new panicking constructors instead. See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1122 --- generic/sodium/src/decrypter/imp.rs | 2 +- generic/sodium/src/encrypter/imp.rs | 2 +- generic/sodium/tests/decrypter.rs | 2 +- net/reqwest/tests/reqwesthttpsrc.rs | 26 +++++++++++++------------- video/cdg/src/cdgparse/imp.rs | 17 +++++++++-------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/generic/sodium/src/decrypter/imp.rs b/generic/sodium/src/decrypter/imp.rs index b968c01d..d53234ce 100644 --- a/generic/sodium/src/decrypter/imp.rs +++ b/generic/sodium/src/decrypter/imp.rs @@ -337,7 +337,7 @@ impl Decrypter { let size = size - total_chunks * box_::MACBYTES as u64; gst::debug!(CAT, obj: pad, "Setting duration bytes: {}", size); - q.set(size * gst::format::Bytes::ONE); + q.set(gst::format::Bytes::from_u64(size)); true } diff --git a/generic/sodium/src/encrypter/imp.rs b/generic/sodium/src/encrypter/imp.rs index af7961e8..9ba3a1f3 100644 --- a/generic/sodium/src/encrypter/imp.rs +++ b/generic/sodium/src/encrypter/imp.rs @@ -314,7 +314,7 @@ impl Encrypter { let size = size + crate::HEADERS_SIZE as u64; gst::debug!(CAT, obj: pad, "Setting duration bytes: {}", size); - q.set(size * gst::format::Bytes::ONE); + q.set(gst::format::Bytes::from_u64(size)); true } diff --git a/generic/sodium/tests/decrypter.rs b/generic/sodium/tests/decrypter.rs index 6b4a4881..2005ade0 100644 --- a/generic/sodium/tests/decrypter.rs +++ b/generic/sodium/tests/decrypter.rs @@ -191,7 +191,7 @@ fn test_pull_range() { let (seekable, start, stop) = q.result(); assert!(seekable); assert_eq!(start, gst::format::Bytes::ZERO.into()); - assert_eq!(stop, (6043 * gst::format::Bytes::ONE).into()); + assert_eq!(stop, gst::format::Bytes::from_u64(6043).into()); // do pulls let expected_array_1 = [ diff --git a/net/reqwest/tests/reqwesthttpsrc.rs b/net/reqwest/tests/reqwesthttpsrc.rs index 7a445fbd..5c7c2825 100644 --- a/net/reqwest/tests/reqwesthttpsrc.rs +++ b/net/reqwest/tests/reqwesthttpsrc.rs @@ -376,7 +376,7 @@ fn test_basic_request() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -434,7 +434,7 @@ fn test_basic_request_inverted_defaults() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -511,7 +511,7 @@ fn test_extra_headers() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -570,7 +570,7 @@ fn test_cookies_property() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -630,7 +630,7 @@ fn test_iradio_mode() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -706,7 +706,7 @@ fn test_audio_l16() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -780,7 +780,7 @@ fn test_authorization() { if cursor.position() == 0 { assert_eq!( h.src.query_duration::(), - Some(expected_output.len() as u64 * gst::format::Bytes::ONE) + Some(gst::format::Bytes::from_usize(expected_output.len())) ); } @@ -930,13 +930,13 @@ fn test_seek_after_ready() { assert_eq!(current_state, gst::State::Ready); h.run(|src| { - src.seek_simple(gst::SeekFlags::FLUSH, 123 * gst::format::Bytes::ONE) + src.seek_simple(gst::SeekFlags::FLUSH, gst::format::Bytes::from_u64(123)) .unwrap(); src.set_state(gst::State::Playing).unwrap(); }); let segment = h.wait_for_segment(false); - assert_eq!(segment.start(), Some(123 * gst::format::Bytes::ONE)); + assert_eq!(segment.start(), Some(gst::format::Bytes::from_u64(123))); let mut expected_output = vec![0; 8192 - 123]; for (i, d) in expected_output.iter_mut().enumerate() { @@ -1009,12 +1009,12 @@ fn test_seek_after_buffer_received() { //seek to a position after a buffer is Received h.run(|src| { - src.seek_simple(gst::SeekFlags::FLUSH, 123 * gst::format::Bytes::ONE) + src.seek_simple(gst::SeekFlags::FLUSH, gst::format::Bytes::from_u64(123)) .unwrap(); }); let segment = h.wait_for_segment(true); - assert_eq!(segment.start(), Some(123 * gst::format::Bytes::ONE)); + assert_eq!(segment.start(), Some(gst::format::Bytes::from_u64(123))); let mut expected_output = vec![0; 8192 - 123]; for (i, d) in expected_output.iter_mut().enumerate() { @@ -1086,8 +1086,8 @@ fn test_seek_with_stop_position() { assert_eq!(buffer.offset(), 0); //seek to a position after a buffer is Received - let start = 123 * gst::format::Bytes::ONE; - let stop = 131 * gst::format::Bytes::ONE; + let start = gst::format::Bytes::from_u64(123); + let stop = gst::format::Bytes::from_u64(131); h.run(move |src| { src.seek( 1.0, diff --git a/video/cdg/src/cdgparse/imp.rs b/video/cdg/src/cdgparse/imp.rs index 6bcd4158..12ea2552 100644 --- a/video/cdg/src/cdgparse/imp.rs +++ b/video/cdg/src/cdgparse/imp.rs @@ -100,13 +100,14 @@ fn bytes_to_time(bytes: Bytes) -> gst::ClockTime { } fn time_to_bytes(time: gst::ClockTime) -> Bytes { - time.nseconds() - .mul_div_round( - CDG_PACKET_PERIOD * CDG_PACKET_SIZE as u64, - *gst::ClockTime::SECOND, - ) - .unwrap() - * Bytes::ONE + Bytes::from_u64( + time.nseconds() + .mul_div_round( + CDG_PACKET_PERIOD * CDG_PACKET_SIZE as u64, + *gst::ClockTime::SECOND, + ) + .unwrap(), + ) } impl BaseParseImpl for CdgParse { @@ -190,7 +191,7 @@ impl BaseParseImpl for CdgParse { } }; - let pts = bytes_to_time(frame.offset() * Bytes::ONE); + let pts = bytes_to_time(Bytes::from_u64(frame.offset())); let buffer = frame.buffer_mut().unwrap(); buffer.set_pts(pts);