From 7c4e36acfde724143b5273acbcdace274ac41c04 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 13 Apr 2023 14:19:29 +0200 Subject: [PATCH] videoflip: reset orientation if not present in a tag update Part-of: --- .../gst/videofilter/gstvideoflip.c | 23 +++++++++++++++++++ .../gst/videofilter/gstvideoflip.h | 2 ++ .../tests/check/elements/videoflip.c | 16 +++++++++++++ 3 files changed, 41 insertions(+) diff --git a/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.c b/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.c index 8cd5d67697..0005e690e0 100644 --- a/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.c +++ b/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.c @@ -1789,6 +1789,8 @@ gst_video_flip_sink_event (GstBaseTransform * trans, GstEvent * event) if (gst_video_orientation_from_tag (taglist, &method)) { if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_STREAM) { vf->got_orientation_stream_tag = TRUE; + } else if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_GLOBAL) { + vf->global_tag_method = method; } if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_GLOBAL @@ -1799,12 +1801,33 @@ gst_video_flip_sink_event (GstBaseTransform * trans, GstEvent * event) } else { gst_video_flip_set_method (vf, method, TRUE); } + } else { + // no orientation in tag + if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_STREAM) { + GST_DEBUG_OBJECT (vf, + "stream tag does not contain orientation, restore the global one: %d", + vf->global_tag_method); + vf->got_orientation_stream_tag = FALSE; + gst_video_flip_set_method (vf, vf->global_tag_method, TRUE); + } else if (gst_tag_list_get_scope (taglist) == GST_TAG_SCOPE_GLOBAL) { + vf->global_tag_method = GST_VIDEO_ORIENTATION_IDENTITY; + + if (!vf->got_orientation_stream_tag) { + GST_DEBUG_OBJECT (vf, + "global taglist withtout orientation, set to identity"); + gst_video_flip_set_method (vf, GST_VIDEO_ORIENTATION_IDENTITY, + TRUE); + } else { + // keep using the orientation from the stream tag + } + } } break; case GST_EVENT_STREAM_START: GST_DEBUG_OBJECT (vf, "new stream, reset orientation from tags"); vf->got_orientation_stream_tag = FALSE; + vf->global_tag_method = GST_VIDEO_ORIENTATION_IDENTITY; gst_video_flip_set_method (vf, GST_VIDEO_ORIENTATION_IDENTITY, TRUE); break; default: diff --git a/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.h b/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.h index d0c0fd2291..15827cad62 100644 --- a/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.h +++ b/subprojects/gst-plugins-good/gst/videofilter/gstvideoflip.h @@ -81,6 +81,8 @@ struct _GstVideoFlip { GstVideoOrientationMethod tag_method; /* TRUE if we received orientation from tag event with GST_TAG_SCOPE_STREAM */ gboolean got_orientation_stream_tag; + /* orientation received from a tag with GST_TAG_SCOPE_STREAM */ + GstVideoOrientationMethod global_tag_method; GstVideoOrientationMethod proposed_method; gboolean change_configuring_method; GstVideoOrientationMethod configuring_method; diff --git a/subprojects/gst-plugins-good/tests/check/elements/videoflip.c b/subprojects/gst-plugins-good/tests/check/elements/videoflip.c index 992b59efa6..a0bf9084b8 100644 --- a/subprojects/gst-plugins-good/tests/check/elements/videoflip.c +++ b/subprojects/gst-plugins-good/tests/check/elements/videoflip.c @@ -455,6 +455,22 @@ GST_START_TEST (test_orientation_tag_scopes) // caps is updated as the frame is now rotated caps_update (flip, &in_info, TRUE); + // sending a stream tag without orientation switch back to the global one, so no orientation change (global: 90, stream: /) + send_orientation_tag (flip, NULL, GST_TAG_SCOPE_STREAM); + caps_not_updated (flip, &in_info); + + // remove orientation from global tag, restoring identity (global: /, stream: /) + send_orientation_tag (flip, NULL, GST_TAG_SCOPE_GLOBAL); + caps_update (flip, &in_info, FALSE); + + // send rotation in stream tag (global: /, stream: 90) + send_orientation_tag (flip, "rotate-90", GST_TAG_SCOPE_STREAM); + caps_update (flip, &in_info, TRUE); + + // sending a global tag without orientation does not change the rotation (global: /, stream: 90) + send_orientation_tag (flip, NULL, GST_TAG_SCOPE_GLOBAL); + caps_not_updated (flip, &in_info); + gst_harness_teardown (flip); }