srtsink: Fix header buffer filtering
Cleans up the code and fixes two issues: - If there are no streamheaders in the caps but we have `HEADER` buffers, it would run `gst_buffer_list_foreach` with `self->headers` being `NULL`. - The code forgot to unmap the buffer if it decided to ignore it. Fixes: 0a562a92d7ee38d8919d1b802add84d3c93b59eb Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9284>
This commit is contained in:
parent
e3d0a8d83e
commit
9363054e63
@ -138,7 +138,6 @@ gst_srt_sink_finalize (GObject * object)
|
||||
static void
|
||||
gst_srt_sink_init (GstSRTSink * self)
|
||||
{
|
||||
self->streamconfig_sent = FALSE;
|
||||
self->srtobject = gst_srt_object_new (GST_ELEMENT (self));
|
||||
gst_srt_object_set_uri (self->srtobject, GST_SRT_DEFAULT_URI, NULL);
|
||||
}
|
||||
@ -169,6 +168,7 @@ gst_srt_sink_stop (GstBaseSink * bsink)
|
||||
GstSRTSink *self = GST_SRT_SINK (bsink);
|
||||
|
||||
g_clear_pointer (&self->headers, gst_buffer_list_unref);
|
||||
self->headers_sent = FALSE;
|
||||
gst_srt_object_close (self->srtobject);
|
||||
|
||||
return TRUE;
|
||||
@ -184,7 +184,7 @@ static gboolean
|
||||
is_buffer_different (GstBuffer ** buffer, guint idx, gpointer data)
|
||||
{
|
||||
StreamheaderCheckContext *ctx = (StreamheaderCheckContext *) data;
|
||||
gboolean retval = FALSE;
|
||||
|
||||
g_return_val_if_fail (buffer != NULL, FALSE);
|
||||
g_return_val_if_fail (GST_IS_BUFFER (*buffer), FALSE);
|
||||
g_return_val_if_fail (ctx != NULL, FALSE);
|
||||
@ -199,9 +199,9 @@ is_buffer_different (GstBuffer ** buffer, guint idx, gpointer data)
|
||||
|
||||
if (gst_buffer_memcmp (*buffer, 0, ctx->map_info->data, ctx->map_info->size)
|
||||
!= 0)
|
||||
retval = TRUE;
|
||||
return TRUE;
|
||||
|
||||
return retval;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
@ -211,39 +211,30 @@ gst_srt_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstMapInfo info;
|
||||
GError *error = NULL;
|
||||
StreamheaderCheckContext ctx = { 0 };
|
||||
|
||||
if (g_cancellable_is_cancelled (self->srtobject->cancellable)) {
|
||||
ret = GST_FLOW_FLUSHING;
|
||||
}
|
||||
|
||||
if (!self->streamconfig_sent && GST_BUFFER_FLAG_IS_SET (buffer,
|
||||
GST_BUFFER_FLAG_HEADER)) {
|
||||
if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, READ,
|
||||
("Could not map the input stream"), (NULL));
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, READ,
|
||||
("Could not map the input stream"), (NULL));
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
ctx.map_info = &info;
|
||||
ctx.buf = buffer;
|
||||
if (!self->headers_sent && self->headers &&
|
||||
GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_HEADER)) {
|
||||
StreamheaderCheckContext ctx = {.buf = buffer,.map_info = &info };
|
||||
|
||||
if (!gst_buffer_list_foreach (self->headers, is_buffer_different, &ctx)) {
|
||||
GST_DEBUG_OBJECT (self, "Have streamheaders,"
|
||||
" ignoring header %" GST_PTR_FORMAT, buffer);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
}
|
||||
|
||||
self->streamconfig_sent = TRUE;
|
||||
|
||||
if (ctx.map_info != &info) {
|
||||
if (!gst_buffer_map (buffer, &info, GST_MAP_READ)) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, READ,
|
||||
("Could not map the input stream"), (NULL));
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
self->headers_sent = TRUE;
|
||||
|
||||
if (gst_srt_object_write (self->srtobject, self->headers, &info, &error) < 0) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, WRITE,
|
||||
@ -298,7 +289,7 @@ gst_srt_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
|
||||
GST_DEBUG_OBJECT (self, "setcaps %" GST_PTR_FORMAT, caps);
|
||||
|
||||
g_clear_pointer (&self->headers, gst_buffer_list_unref);
|
||||
self->streamconfig_sent = FALSE;
|
||||
self->headers_sent = FALSE;
|
||||
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
streamheader = gst_structure_get_value (s, "streamheader");
|
||||
|
@ -46,10 +46,9 @@ struct _GstSRTSink {
|
||||
GstBaseSink parent;
|
||||
|
||||
GstBufferList *headers;
|
||||
gboolean headers_sent;
|
||||
|
||||
GstSRTObject *srtobject;
|
||||
|
||||
gboolean streamconfig_sent;
|
||||
};
|
||||
|
||||
struct _GstSRTSinkClass {
|
||||
|
Loading…
x
Reference in New Issue
Block a user