uriplaylistbin: Properly check for stream-collection/streams-selected events

There is only a new stream-collection event if the media has actually
changed, and that's also the only time in these tests when a
streams-selected event is sent as the default stream selection is always
used and never changed.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/597

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1769>
This commit is contained in:
Sebastian Dröge 2024-09-09 14:36:08 +03:00
parent 2e0f52de2c
commit 8fd2b7daa4

View file

@ -17,6 +17,12 @@ struct TestMedia {
len: gst::ClockTime, len: gst::ClockTime,
} }
impl PartialEq for TestMedia {
fn eq(&self, other: &Self) -> bool {
self.uri == other.uri
}
}
fn file_name_to_uri(name: &str) -> String { fn file_name_to_uri(name: &str) -> String {
let input_path = { let input_path = {
let mut r = PathBuf::new(); let mut r = PathBuf::new();
@ -103,8 +109,6 @@ fn test(
) -> (Vec<gst::Message>, u32, u64) { ) -> (Vec<gst::Message>, u32, u64) {
init(); init();
let playlist_len = medias.len() * (iterations as usize);
let total_len: gst::ClockTime = medias.iter().map(|t| t.len * (iterations as u64)).sum(); let total_len: gst::ClockTime = medias.iter().map(|t| t.len * (iterations as u64)).sum();
let uris: Vec<String> = medias.iter().map(|t| t.uri.clone()).collect(); let uris: Vec<String> = medias.iter().map(|t| t.uri.clone()).collect();
@ -221,11 +225,27 @@ fn test(
// check stream-collection and streams-selected message ordering // check stream-collection and streams-selected message ordering
let mut events = events.clone().into_iter(); let mut events = events.clone().into_iter();
let playlist = std::iter::repeat(medias.iter())
.take(iterations as usize)
.flatten();
let mut last_media = None;
for i in 0..playlist_len { for media in playlist {
let decodebin = assert_stream_collection(events.next().unwrap(), n_streams as usize); let mut media_changed = false;
if i == 0 {
// decodebin3 sends StreamSelected only once, which is ok as the selected stream stays the same if last_media
.as_ref()
.map_or(true, |last_media| *last_media != media)
{
last_media = Some(media);
media_changed = true;
}
// decodebin3 only sends a new stream-collection and streams-selected if it actually
// changes, which only happens here if the actual underlying media is changing.
if media_changed {
let decodebin =
assert_stream_collection(events.next().unwrap(), n_streams as usize);
assert_eq!( assert_eq!(
assert_stream_selected(events.next().unwrap(), n_streams as usize), assert_stream_selected(events.next().unwrap(), n_streams as usize),
decodebin decodebin