gstpipewiresrc: Handle stream being disconnected

When PW source is used with something like Camera and the camera is
disconnected, all buffers are removed and stream will be paused.

When using PW sink with source, the sink side pipeline can go to EOS.
This again results in all the buffers being removed and stream being
paused on the source side. PW source side pipeline can also crash if
the sink was in the middle of frame copying a buffer to render which
got removed.

Handle this scenario by sending a flush-start event at the start of
buffer removal and flush-stop at the end followed by an end of stream
or pipeline error depending on user selection.
This commit is contained in:
Sanchayan Maity 2025-03-24 15:50:22 +05:30 committed by Wim Taymans
parent e9a2406314
commit bb1bb07f6c
2 changed files with 147 additions and 8 deletions

View file

@ -24,6 +24,22 @@ G_BEGIN_DECLS
#define GST_PIPEWIRE_SRC_CAST(obj) ((GstPipeWireSrc *) (obj))
G_DECLARE_FINAL_TYPE (GstPipeWireSrc, gst_pipewire_src, GST, PIPEWIRE_SRC, GstPushSrc)
/**
* GstPipeWireSrcOnDisconnect:
* @GST_PIPEWIRE_SRC_ON_DISCONNECT_EOS: send EoS downstream
* @GST_PIPEWIRE_SRC_ON_DISCONNECT_ERROR: raise pipeline error
* @GST_PIPEWIRE_SRC_ON_DISCONNECT_NONE: no action
*
* Different actions on disconnect.
*/
typedef enum
{
GST_PIPEWIRE_SRC_ON_DISCONNECT_NONE,
GST_PIPEWIRE_SRC_ON_DISCONNECT_EOS,
GST_PIPEWIRE_SRC_ON_DISCONNECT_ERROR,
} GstPipeWireSrcOnDisconnect;
#define GST_TYPE_PIPEWIRE_SRC_ON_DISCONNECT (gst_pipewire_src_on_disconnect_get_type ())
/**
* GstPipeWireSrc:
@ -36,6 +52,7 @@ struct _GstPipeWireSrc {
GstPipeWireStream *stream;
/*< private >*/
gint n_buffers;
gint use_bufferpool;
gint min_buffers;
gint max_buffers;
@ -56,6 +73,7 @@ struct _GstPipeWireSrc {
gboolean flushing;
gboolean started;
gboolean eos;
gboolean flushing_on_remove_buffer;
gboolean is_live;
int64_t delay;
@ -65,8 +83,12 @@ struct _GstPipeWireSrc {
GstBuffer *last_buffer;
enum spa_meta_videotransform_value transform_value;
GstPipeWireSrcOnDisconnect on_disconnect;
};
GType gst_pipewire_src_on_stream_disconnect_get_type (void);
G_END_DECLS
#endif /* __GST_PIPEWIRE_SRC_H__ */