Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2022-10-10 14:55:32 +0300
committerFrançois Laignel <fengalin@free.fr>2022-10-10 20:28:13 +0300
commitbd14e476f16622d59a3a30d762b7f893c7c74614 (patch)
tree30da1afdc1308859231377629b62e9a8df0e7798
parentb1b707008f1995ea1118ab126586704c2e102233 (diff)
Fix direct access to the inner specific formatted values
This is no longer available as this could lead to building a defined value in Rust which could be interpreted as undefined in C due to the sentinel `u64::MAX` for `None`. Use the constants (e.g. `ONE`, `K`, `M`, ...) and operations to build a value and deref (`*`) to get the quantity as an integer.
-rw-r--r--generic/sodium/src/decrypter/imp.rs9
-rw-r--r--generic/sodium/src/encrypter/imp.rs9
-rw-r--r--generic/sodium/tests/decrypter.rs4
-rw-r--r--net/reqwest/tests/reqwesthttpsrc.rs34
-rw-r--r--text/json/src/jsongstparse/imp.rs6
-rw-r--r--video/cdg/src/cdgparse/imp.rs19
-rw-r--r--video/closedcaption/src/mcc_parse/imp.rs6
-rw-r--r--video/closedcaption/src/scc_parse/imp.rs6
8 files changed, 46 insertions, 47 deletions
diff --git a/generic/sodium/src/decrypter/imp.rs b/generic/sodium/src/decrypter/imp.rs
index 546b25033..b968c01d0 100644
--- a/generic/sodium/src/decrypter/imp.rs
+++ b/generic/sodium/src/decrypter/imp.rs
@@ -311,11 +311,10 @@ impl Decrypter {
return false;
}
- let size = match peer_query.result().try_into().unwrap() {
- Some(gst::format::Bytes(size)) => size,
- None => {
+ let size = match peer_query.result() {
+ gst::GenericFormattedValue::Bytes(Some(size)) => *size,
+ _ => {
gst::error!(CAT, "Failed to query upstream duration");
-
return false;
}
};
@@ -338,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(gst::format::Bytes(size));
+ q.set(size * gst::format::Bytes::ONE);
true
}
diff --git a/generic/sodium/src/encrypter/imp.rs b/generic/sodium/src/encrypter/imp.rs
index b0cc8a4c2..af7961e81 100644
--- a/generic/sodium/src/encrypter/imp.rs
+++ b/generic/sodium/src/encrypter/imp.rs
@@ -289,11 +289,10 @@ impl Encrypter {
return false;
}
- let size = match peer_query.result().try_into().unwrap() {
- Some(gst::format::Bytes(size)) => size,
- None => {
+ let size = match peer_query.result() {
+ gst::GenericFormattedValue::Bytes(Some(size)) => *size,
+ _ => {
gst::error!(CAT, "Failed to query upstream duration");
-
return false;
}
};
@@ -315,7 +314,7 @@ impl Encrypter {
let size = size + crate::HEADERS_SIZE as u64;
gst::debug!(CAT, obj: pad, "Setting duration bytes: {}", size);
- q.set(gst::format::Bytes(size));
+ q.set(size * gst::format::Bytes::ONE);
true
}
diff --git a/generic/sodium/tests/decrypter.rs b/generic/sodium/tests/decrypter.rs
index ed99ced83..6b4a4881d 100644
--- a/generic/sodium/tests/decrypter.rs
+++ b/generic/sodium/tests/decrypter.rs
@@ -190,8 +190,8 @@ fn test_pull_range() {
// get the seeking capabilities
let (seekable, start, stop) = q.result();
assert!(seekable);
- assert_eq!(start, gst::format::Bytes(0).into());
- assert_eq!(stop, gst::format::Bytes(6043).into());
+ assert_eq!(start, gst::format::Bytes::ZERO.into());
+ assert_eq!(stop, (6043 * gst::format::Bytes::ONE).into());
// do pulls
let expected_array_1 = [
diff --git a/net/reqwest/tests/reqwesthttpsrc.rs b/net/reqwest/tests/reqwesthttpsrc.rs
index ab404428d..7a445fbdc 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::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -434,7 +434,7 @@ fn test_basic_request_inverted_defaults() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -511,7 +511,7 @@ fn test_extra_headers() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -570,7 +570,7 @@ fn test_cookies_property() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -630,7 +630,7 @@ fn test_iradio_mode() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -706,7 +706,7 @@ fn test_audio_l16() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -780,7 +780,7 @@ fn test_authorization() {
if cursor.position() == 0 {
assert_eq!(
h.src.query_duration::<gst::format::Bytes>(),
- Some(gst::format::Bytes(expected_output.len() as u64))
+ Some(expected_output.len() as u64 * gst::format::Bytes::ONE)
);
}
@@ -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, gst::format::Bytes(123))
+ src.seek_simple(gst::SeekFlags::FLUSH, 123 * gst::format::Bytes::ONE)
.unwrap();
src.set_state(gst::State::Playing).unwrap();
});
let segment = h.wait_for_segment(false);
- assert_eq!(segment.start(), Some(gst::format::Bytes(123)));
+ assert_eq!(segment.start(), Some(123 * gst::format::Bytes::ONE));
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, gst::format::Bytes(123))
+ src.seek_simple(gst::SeekFlags::FLUSH, 123 * gst::format::Bytes::ONE)
.unwrap();
});
let segment = h.wait_for_segment(true);
- assert_eq!(segment.start(), Some(gst::format::Bytes(123)));
+ assert_eq!(segment.start(), Some(123 * gst::format::Bytes::ONE));
let mut expected_output = vec![0; 8192 - 123];
for (i, d) in expected_output.iter_mut().enumerate() {
@@ -1086,21 +1086,23 @@ fn test_seek_with_stop_position() {
assert_eq!(buffer.offset(), 0);
//seek to a position after a buffer is Received
- h.run(|src| {
+ let start = 123 * gst::format::Bytes::ONE;
+ let stop = 131 * gst::format::Bytes::ONE;
+ h.run(move |src| {
src.seek(
1.0,
gst::SeekFlags::FLUSH,
gst::SeekType::Set,
- gst::format::Bytes(123),
+ start,
gst::SeekType::Set,
- gst::format::Bytes(131),
+ stop,
)
.unwrap();
});
let segment = h.wait_for_segment(true);
- assert_eq!(segment.start(), Some(gst::format::Bytes(123)));
- assert_eq!(segment.stop(), Some(gst::format::Bytes(131)));
+ assert_eq!(segment.start(), Some(start));
+ assert_eq!(segment.stop(), Some(stop));
let mut expected_output = vec![0; 8];
for (i, d) in expected_output.iter_mut().enumerate() {
diff --git a/text/json/src/jsongstparse/imp.rs b/text/json/src/jsongstparse/imp.rs
index 75d8c095d..d6fb16375 100644
--- a/text/json/src/jsongstparse/imp.rs
+++ b/text/json/src/jsongstparse/imp.rs
@@ -415,9 +415,9 @@ impl JsonGstParse {
));
}
- let size = match q.result().try_into().ok().flatten() {
- Some(gst::format::Bytes(size)) => size,
- None => {
+ let size = match q.result() {
+ gst::GenericFormattedValue::Bytes(Some(size)) => *size,
+ _ => {
return Err(gst::loggable_error!(
CAT,
"Failed to query upstream duration"
diff --git a/video/cdg/src/cdgparse/imp.rs b/video/cdg/src/cdgparse/imp.rs
index 8ebf1e007..6bcd41581 100644
--- a/video/cdg/src/cdgparse/imp.rs
+++ b/video/cdg/src/cdgparse/imp.rs
@@ -92,7 +92,7 @@ impl ElementImpl for CdgParse {
}
fn bytes_to_time(bytes: Bytes) -> gst::ClockTime {
- let nb = bytes.0 / CDG_PACKET_SIZE as u64;
+ let nb = *bytes / CDG_PACKET_SIZE as u64;
gst::ClockTime::from_nseconds(
nb.mul_div_round(*gst::ClockTime::SECOND, CDG_PACKET_PERIOD)
.unwrap(),
@@ -100,14 +100,13 @@ fn bytes_to_time(bytes: Bytes) -> gst::ClockTime {
}
fn time_to_bytes(time: gst::ClockTime) -> Bytes {
- Bytes(
- time.nseconds()
- .mul_div_round(
- CDG_PACKET_PERIOD * CDG_PACKET_SIZE as u64,
- *gst::ClockTime::SECOND,
- )
- .unwrap(),
- )
+ time.nseconds()
+ .mul_div_round(
+ CDG_PACKET_PERIOD * CDG_PACKET_SIZE as u64,
+ *gst::ClockTime::SECOND,
+ )
+ .unwrap()
+ * Bytes::ONE
}
impl BaseParseImpl for CdgParse {
@@ -191,7 +190,7 @@ impl BaseParseImpl for CdgParse {
}
};
- let pts = bytes_to_time(Bytes(frame.offset()));
+ let pts = bytes_to_time(frame.offset() * Bytes::ONE);
let buffer = frame.buffer_mut().unwrap();
buffer.set_pts(pts);
diff --git a/video/closedcaption/src/mcc_parse/imp.rs b/video/closedcaption/src/mcc_parse/imp.rs
index 911ef21b4..0c2e40bbd 100644
--- a/video/closedcaption/src/mcc_parse/imp.rs
+++ b/video/closedcaption/src/mcc_parse/imp.rs
@@ -634,9 +634,9 @@ impl MccParse {
));
}
- let size = match q.result().try_into().unwrap() {
- Some(gst::format::Bytes(size)) => size,
- None => {
+ let size = match q.result() {
+ gst::GenericFormattedValue::Bytes(Some(size)) => *size,
+ _ => {
return Err(gst::loggable_error!(
CAT,
"Failed to query upstream duration"
diff --git a/video/closedcaption/src/scc_parse/imp.rs b/video/closedcaption/src/scc_parse/imp.rs
index 5581f31a6..f6c4f2206 100644
--- a/video/closedcaption/src/scc_parse/imp.rs
+++ b/video/closedcaption/src/scc_parse/imp.rs
@@ -526,9 +526,9 @@ impl SccParse {
));
}
- let size = match q.result().try_into().unwrap() {
- Some(gst::format::Bytes(size)) => size,
- None => {
+ let size = match q.result() {
+ gst::GenericFormattedValue::Bytes(Some(size)) => *size,
+ _ => {
return Err(gst::loggable_error!(
CAT,
"Failed to query upstream duration"