pipewiresrc: Fix renegotiation

Some downstream elements trigger re-negotiations when the stream is
running, e.g. due to output window resizing for the below pipeline.

gst-launch-1.0 pipewiresrc ! videoconvert ! video/x-raw ! gtk4paintablesink

This fails due to a side effect introduced by commit 77143e54 with
handle_format_change() setting `is_video` to `false` when param was
NULL. Fix this by explicitly tracking media type and not just video
using a boolean.
This commit is contained in:
Barnabás Pőcze 2025-11-03 16:52:33 +05:30 committed by Wim Taymans
parent d3368ee0d5
commit fa8b0ba018
2 changed files with 9 additions and 6 deletions

View file

@ -769,7 +769,7 @@ static GstBuffer *dequeue_buffer(GstPipeWireSrc *pwsrc)
GST_BUFFER_DTS (buf) = b->time - pwsrc->delay;
}
if (pwsrc->is_video) {
if (pwsrc->media_type == SPA_MEDIA_TYPE_video) {
if (pwsrc->video_info.fps_n) {
GST_BUFFER_DURATION (buf) = gst_util_uint64_scale (GST_SECOND,
pwsrc->video_info.fps_d, pwsrc->video_info.fps_n);
@ -912,7 +912,7 @@ on_state_changed (void *data,
* must handle the clock lost message in it's bus handler by pausing
* the pipeline and then setting it back to playing.
*/
if (current_state == GST_STATE_PLAYING && !pwsrc->is_video)
if (current_state == GST_STATE_PLAYING && pwsrc->media_type == SPA_MEDIA_TYPE_audio)
gst_element_post_message (GST_ELEMENT_CAST (pwsrc),
gst_message_new_clock_lost (GST_OBJECT_CAST (pwsrc),
GST_CLOCK_CAST (pwsrc->stream->clock)));
@ -1265,7 +1265,7 @@ handle_format_change (GstPipeWireSrc *pwsrc,
if (param == NULL) {
GST_DEBUG_OBJECT (pwsrc, "clear format");
pwsrc->negotiated = FALSE;
pwsrc->is_video = FALSE;
pwsrc->media_type = SPA_MEDIA_TYPE_unknown;
return;
}
@ -1303,7 +1303,7 @@ handle_format_change (GstPipeWireSrc *pwsrc,
structure = gst_caps_get_structure (pwsrc->caps, 0);
if (g_str_has_prefix (gst_structure_get_name (structure), "video/") ||
g_str_has_prefix (gst_structure_get_name (structure), "image/")) {
pwsrc->is_video = TRUE;
pwsrc->media_type = SPA_MEDIA_TYPE_video;
#ifdef HAVE_GSTREAMER_DMA_DRM
if (gst_video_is_dma_drm_caps (pwsrc->caps)) {
@ -1342,10 +1342,12 @@ handle_format_change (GstPipeWireSrc *pwsrc,
* application/user */
if (pwsrc->use_bufferpool != USE_BUFFERPOOL_YES)
pwsrc->use_bufferpool = USE_BUFFERPOOL_NO;
pwsrc->media_type = SPA_MEDIA_TYPE_audio;
}
} else {
pwsrc->negotiated = FALSE;
pwsrc->is_video = FALSE;
pwsrc->media_type = SPA_MEDIA_TYPE_unknown;
pwsrc->is_rawvideo = FALSE;
}

View file

@ -15,6 +15,7 @@
#include <gst/video/video.h>
#include <pipewire/pipewire.h>
#include <spa/param/format.h>
#include <gst/gstpipewirepool.h>
#include <gst/gstpipewirecore.h>
@ -63,7 +64,7 @@ struct _GstPipeWireSrc {
GstCaps *caps;
GstCaps *possible_caps;
gboolean is_video;
enum spa_media_type media_type;
gboolean is_rawvideo;
GstVideoInfo video_info;
#ifdef HAVE_GSTREAMER_DMA_DRM