videoaggregator: ensure peek_next_sample() uses the correct caps

gst_pad_get_current_caps() may be wrong when there is a renegotiation in
progress for the pad and we have not yet received or selected the buffer
with different caps yet.

Fix by storing the caps through in a similar way to the existing code
for buffer/video-info selection machinery.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/813>
This commit is contained in:
Matthew Waters 2020-09-11 21:40:26 +10:00
parent eaedb5c2de
commit b4ea8332f5

View file

@ -68,6 +68,7 @@ enum
struct _GstVideoAggregatorPadPrivate struct _GstVideoAggregatorPadPrivate
{ {
GstBuffer *buffer; GstBuffer *buffer;
GstCaps *caps;
GstVideoFrame prepared_frame; GstVideoFrame prepared_frame;
/* properties */ /* properties */
@ -83,6 +84,7 @@ struct _GstVideoAggregatorPadPrivate
GstClockTime end_time; GstClockTime end_time;
GstVideoInfo pending_vinfo; GstVideoInfo pending_vinfo;
GstCaps *pending_caps;
}; };
@ -161,6 +163,7 @@ _flush_pad (GstAggregatorPad * aggpad, GstAggregator * aggregator)
gst_video_aggregator_reset_qos (vagg); gst_video_aggregator_reset_qos (vagg);
gst_buffer_replace (&pad->priv->buffer, NULL); gst_buffer_replace (&pad->priv->buffer, NULL);
gst_caps_replace (&pad->priv->caps, NULL);
pad->priv->start_time = -1; pad->priv->start_time = -1;
pad->priv->end_time = -1; pad->priv->end_time = -1;
@ -221,9 +224,8 @@ gst_video_aggregator_peek_next_sample (GstAggregator * agg,
GstSample *res = NULL; GstSample *res = NULL;
if (vaggpad->priv->buffer) { if (vaggpad->priv->buffer) {
GstCaps *caps = gst_pad_get_current_caps (GST_PAD (aggpad)); res = gst_sample_new (vaggpad->priv->buffer, vaggpad->priv->caps,
res = gst_sample_new (vaggpad->priv->buffer, caps, &aggpad->segment, NULL); &aggpad->segment, NULL);
gst_caps_unref (caps);
} }
return res; return res;
@ -1147,12 +1149,14 @@ gst_video_aggregator_pad_sink_setcaps (GstPad * pad, GstObject * parent,
* that this pad is getting configured; configure immediately to avoid * that this pad is getting configured; configure immediately to avoid
* problems with the initial negotiation */ * problems with the initial negotiation */
vaggpad->info = info; vaggpad->info = info;
gst_caps_replace (&vaggpad->priv->caps, caps);
gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg)); gst_pad_mark_reconfigure (GST_AGGREGATOR_SRC_PAD (vagg));
} else { } else {
/* this pad already had caps but received new ones; keep the new caps /* this pad already had caps but received new ones; keep the new caps
* pending until we pick the next buffer from the queue, otherwise we * pending until we pick the next buffer from the queue, otherwise we
* might use an old buffer with the new caps and crash */ * might use an old buffer with the new caps and crash */
vaggpad->priv->pending_vinfo = info; vaggpad->priv->pending_vinfo = info;
gst_caps_replace (&vaggpad->priv->pending_caps, caps);
GST_DEBUG_OBJECT (pad, "delaying caps change"); GST_DEBUG_OBJECT (pad, "delaying caps change");
} }
ret = TRUE; ret = TRUE;
@ -1414,6 +1418,7 @@ gst_video_aggregator_reset (GstVideoAggregator * vagg)
GstVideoAggregatorPad *p = l->data; GstVideoAggregatorPad *p = l->data;
gst_buffer_replace (&p->priv->buffer, NULL); gst_buffer_replace (&p->priv->buffer, NULL);
gst_caps_replace (&p->priv->caps, NULL);
p->priv->start_time = -1; p->priv->start_time = -1;
p->priv->end_time = -1; p->priv->end_time = -1;
@ -1490,6 +1495,8 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
"output_start_running_time. Discarding old buffer"); "output_start_running_time. Discarding old buffer");
gst_buffer_replace (&pad->priv->buffer, buf); gst_buffer_replace (&pad->priv->buffer, buf);
if (pad->priv->pending_vinfo.finfo) { if (pad->priv->pending_vinfo.finfo) {
gst_caps_replace (&pad->priv->caps, pad->priv->pending_caps);
gst_caps_replace (&pad->priv->pending_caps, NULL);
pad->info = pad->priv->pending_vinfo; pad->info = pad->priv->pending_vinfo;
need_reconfigure = TRUE; need_reconfigure = TRUE;
pad->priv->pending_vinfo.finfo = NULL; pad->priv->pending_vinfo.finfo = NULL;
@ -1504,6 +1511,8 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
buf = gst_aggregator_pad_pop_buffer (bpad); buf = gst_aggregator_pad_pop_buffer (bpad);
gst_buffer_replace (&pad->priv->buffer, buf); gst_buffer_replace (&pad->priv->buffer, buf);
if (pad->priv->pending_vinfo.finfo) { if (pad->priv->pending_vinfo.finfo) {
gst_caps_replace (&pad->priv->caps, pad->priv->pending_caps);
gst_caps_replace (&pad->priv->pending_caps, NULL);
pad->info = pad->priv->pending_vinfo; pad->info = pad->priv->pending_vinfo;
need_reconfigure = TRUE; need_reconfigure = TRUE;
pad->priv->pending_vinfo.finfo = NULL; pad->priv->pending_vinfo.finfo = NULL;
@ -1564,6 +1573,8 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
GST_TIME_ARGS (start_time)); GST_TIME_ARGS (start_time));
gst_buffer_replace (&pad->priv->buffer, buf); gst_buffer_replace (&pad->priv->buffer, buf);
if (pad->priv->pending_vinfo.finfo) { if (pad->priv->pending_vinfo.finfo) {
gst_caps_replace (&pad->priv->caps, pad->priv->pending_caps);
gst_caps_replace (&pad->priv->pending_caps, NULL);
pad->info = pad->priv->pending_vinfo; pad->info = pad->priv->pending_vinfo;
need_reconfigure = TRUE; need_reconfigure = TRUE;
pad->priv->pending_vinfo.finfo = NULL; pad->priv->pending_vinfo.finfo = NULL;
@ -1582,6 +1593,8 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
} else { } else {
gst_buffer_replace (&pad->priv->buffer, buf); gst_buffer_replace (&pad->priv->buffer, buf);
if (pad->priv->pending_vinfo.finfo) { if (pad->priv->pending_vinfo.finfo) {
gst_caps_replace (&pad->priv->caps, pad->priv->pending_caps);
gst_caps_replace (&pad->priv->pending_caps, NULL);
pad->info = pad->priv->pending_vinfo; pad->info = pad->priv->pending_vinfo;
need_reconfigure = TRUE; need_reconfigure = TRUE;
pad->priv->pending_vinfo.finfo = NULL; pad->priv->pending_vinfo.finfo = NULL;
@ -1614,6 +1627,7 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
pad->priv->max_last_buffer_repeat) { pad->priv->max_last_buffer_repeat) {
pad->priv->start_time = pad->priv->end_time = -1; pad->priv->start_time = pad->priv->end_time = -1;
gst_buffer_replace (&pad->priv->buffer, NULL); gst_buffer_replace (&pad->priv->buffer, NULL);
gst_caps_replace (&pad->priv->caps, NULL);
} }
} else { } else {
pad->priv->start_time = pad->priv->end_time = -1; pad->priv->start_time = pad->priv->end_time = -1;
@ -1621,6 +1635,7 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
need_more_data = TRUE; need_more_data = TRUE;
} else { } else {
gst_buffer_replace (&pad->priv->buffer, NULL); gst_buffer_replace (&pad->priv->buffer, NULL);
gst_caps_replace (&pad->priv->caps, NULL);
pad->priv->start_time = pad->priv->end_time = -1; pad->priv->start_time = pad->priv->end_time = -1;
} }
} else if (is_eos) { } else if (is_eos) {
@ -1628,6 +1643,7 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
} }
} else if (is_eos) { } else if (is_eos) {
gst_buffer_replace (&pad->priv->buffer, NULL); gst_buffer_replace (&pad->priv->buffer, NULL);
gst_caps_replace (&pad->priv->caps, NULL);
} else if (pad->priv->start_time != -1) { } else if (pad->priv->start_time != -1) {
/* When the current buffer didn't have a duration, but /* When the current buffer didn't have a duration, but
* max-last-buffer-repeat was set, we use start_time as * max-last-buffer-repeat was set, we use start_time as
@ -1639,6 +1655,7 @@ gst_video_aggregator_fill_queues (GstVideoAggregator * vagg,
pad->priv->max_last_buffer_repeat) { pad->priv->max_last_buffer_repeat) {
pad->priv->start_time = pad->priv->end_time = -1; pad->priv->start_time = pad->priv->end_time = -1;
gst_buffer_replace (&pad->priv->buffer, NULL); gst_buffer_replace (&pad->priv->buffer, NULL);
gst_caps_replace (&pad->priv->caps, NULL);
} }
} }
} }
@ -2290,6 +2307,8 @@ gst_video_aggregator_release_pad (GstElement * element, GstPad * pad)
gst_video_aggregator_reset (vagg); gst_video_aggregator_reset (vagg);
gst_buffer_replace (&vaggpad->priv->buffer, NULL); gst_buffer_replace (&vaggpad->priv->buffer, NULL);
gst_caps_replace (&vaggpad->priv->caps, NULL);
gst_caps_replace (&vaggpad->priv->pending_caps, NULL);
GST_ELEMENT_CLASS (gst_video_aggregator_parent_class)->release_pad GST_ELEMENT_CLASS (gst_video_aggregator_parent_class)->release_pad
(GST_ELEMENT (vagg), pad); (GST_ELEMENT (vagg), pad);