From 226440382bd833edcffa0ee3b0e3c968cf1ea6d1 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Tue, 2 Jul 2024 12:13:34 +0200 Subject: [PATCH] gst: src: Reset transform on stream stop When a stream is stopped, chances are high that downstream elements change or get reset, i.e. don't remember a previously send rotation event. Thus reset the transform value in order to ensure we create a new one on the next stream start. In order to not regress the case when downstream *does* remember the orientation and the buffer orientation changes from e.g. `TRANSFORMATION_90` to `TRANSFORMATION_None` between stream stop and restart, initialize the remembered transform to an invalid value and ensure we always send a rotation event, even for `TRANSFORMATION_None`. --- src/gst/gstpipewiresrc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 6e0c67e04..b4ccc55b7 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -435,6 +435,8 @@ gst_pipewire_src_init (GstPipeWireSrc * src) src->autoconnect = DEFAULT_AUTOCONNECT; src->min_latency = 0; src->max_latency = GST_CLOCK_TIME_NONE; + + src->transform_value = UINT32_MAX; } static gboolean @@ -538,7 +540,7 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc) GstPipeWirePoolData *data; struct spa_meta_header *h; struct spa_meta_region *crop; - struct spa_meta_videotransform *videotransform; + enum spa_meta_videotransform_value transform_value; struct pw_time time; guint i; @@ -613,24 +615,22 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc) } } - videotransform = data->videotransform; - if (videotransform) { - if (pwsrc->transform_value != videotransform->transform) { - GstEvent *tag_event; - const char* tag_string; + transform_value = data->videotransform ? data->videotransform->transform : + SPA_META_TRANSFORMATION_None; + if (transform_value != pwsrc->transform_value) { + GstEvent *tag_event; + const char* tag_string; - tag_string = - spa_transform_value_to_gst_image_orientation(videotransform->transform); + tag_string = spa_transform_value_to_gst_image_orientation(transform_value); - GST_LOG_OBJECT (pwsrc, "got new videotransform: %u / %s", - videotransform->transform, tag_string); + GST_LOG_OBJECT (pwsrc, "got new videotransform: %u / %s", + transform_value, tag_string); - tag_event = gst_event_new_tag(gst_tag_list_new(GST_TAG_IMAGE_ORIENTATION, - tag_string, NULL)); - gst_pad_push_event (GST_BASE_SRC_PAD (pwsrc), tag_event); + tag_event = gst_event_new_tag(gst_tag_list_new(GST_TAG_IMAGE_ORIENTATION, + tag_string, NULL)); + gst_pad_push_event (GST_BASE_SRC_PAD (pwsrc), tag_event); - pwsrc->transform_value = videotransform->transform; - } + pwsrc->transform_value = transform_value; } if (pwsrc->is_video) { @@ -1391,6 +1391,7 @@ gst_pipewire_src_stop (GstBaseSrc * basesrc) pwsrc->eos = false; gst_buffer_replace (&pwsrc->last_buffer, NULL); gst_caps_replace(&pwsrc->caps, NULL); + pwsrc->transform_value = UINT32_MAX; pw_thread_loop_unlock (pwsrc->stream->core->loop); return TRUE;