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
This commit is contained in:
François Laignel 2022-10-11 12:51:00 +02:00
parent bd14e476f1
commit bc5b51687d
5 changed files with 25 additions and 24 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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 = [

View file

@ -376,7 +376,7 @@ fn test_basic_request() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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::<gst::format::Bytes>(),
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,

View file

@ -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);