caps: improve caps handling

Avoid caps copy and leaks
This commit is contained in:
Wim Taymans 2012-03-27 16:41:06 +02:00
parent 8f52f8c5c8
commit e310ee8218
20 changed files with 71 additions and 71 deletions

View file

@ -1701,7 +1701,7 @@ gst_avi_mux_start_file (GstAviMux * avimux)
}
}
caps = gst_caps_copy (gst_pad_get_pad_template_caps (avimux->srcpad));
caps = gst_pad_get_pad_template_caps (avimux->srcpad);
gst_pad_set_caps (avimux->srcpad, caps);
gst_caps_unref (caps);

View file

@ -273,8 +273,6 @@ gst_image_freeze_sink_getcaps (GstImageFreeze * self, GstCaps * filter)
pad = self->sinkpad;
if (gst_pad_has_current_caps (pad)) {
ret = gst_pad_get_current_caps (pad);
gst_caps_replace (&ret, gst_caps_copy (ret));
gst_caps_unref (ret);
goto done;
}

View file

@ -403,7 +403,8 @@ gst_alaw_enc_setcaps (GstALawEnc * alawenc, GstCaps * caps)
gst_structure_get_int (structure, "channels", &alawenc->channels);
gst_structure_get_int (structure, "rate", &alawenc->rate);
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (alawenc->srcpad));
base_caps = gst_pad_get_pad_template_caps (alawenc->srcpad);
base_caps = gst_caps_make_writable (base_caps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set (structure, "rate", G_TYPE_INT, alawenc->rate, NULL);
gst_structure_set (structure, "channels", G_TYPE_INT, alawenc->channels,

View file

@ -159,7 +159,8 @@ mulawenc_setcaps (GstMuLawEnc * mulawenc, GstCaps * caps)
gst_structure_get_int (structure, "channels", &mulawenc->channels);
gst_structure_get_int (structure, "rate", &mulawenc->rate);
base_caps = gst_caps_copy (gst_pad_get_pad_template_caps (mulawenc->srcpad));
base_caps = gst_pad_get_pad_template_caps (mulawenc->srcpad);
base_caps = gst_caps_make_writable (base_caps);
structure = gst_caps_get_structure (base_caps, 0);
gst_structure_set (structure, "rate", G_TYPE_INT, mulawenc->rate, NULL);

View file

@ -3000,20 +3000,17 @@ gst_matroska_demux_check_aac (GstElement * element,
size = gst_buffer_get_size (*buf);
if (size > 2 && data[0] == 0xff && (data[1] >> 4 == 0x0f)) {
GstCaps *new_caps;
GstStructure *s;
/* tss, ADTS data, remove codec_data
* still assume it is at least parsed */
new_caps = gst_caps_copy (stream->caps);
s = gst_caps_get_structure (new_caps, 0);
stream->caps = gst_caps_make_writable (stream->caps);
s = gst_caps_get_structure (stream->caps, 0);
g_assert (s);
gst_structure_remove_field (s, "codec_data");
gst_caps_replace (&stream->caps, new_caps);
gst_pad_set_caps (stream->pad, new_caps);
gst_pad_set_caps (stream->pad, stream->caps);
GST_DEBUG_OBJECT (element, "ADTS AAC audio data; removing codec-data, "
"new caps: %" GST_PTR_FORMAT, new_caps);
gst_caps_unref (new_caps);
"new caps: %" GST_PTR_FORMAT, stream->caps);
}
/* disable subsequent checking */

View file

@ -175,8 +175,7 @@ gst_asteriskh263_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
if (!gst_pad_has_current_caps (asteriskh263->srcpad)) {
GstCaps *caps;
caps = gst_caps_copy
(gst_pad_get_pad_template_caps (asteriskh263->srcpad));
caps = gst_pad_get_pad_template_caps (asteriskh263->srcpad);
gst_pad_set_caps (asteriskh263->srcpad, caps);
gst_caps_unref (caps);
}

View file

@ -176,9 +176,9 @@ gst_rtp_L16_pay_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
GstCaps *otherpadcaps;
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *structure;
@ -187,6 +187,7 @@ gst_rtp_L16_pay_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
gint rate;
structure = gst_caps_get_structure (otherpadcaps, 0);
caps = gst_caps_make_writable (caps);
if (gst_structure_get_int (structure, "channels", &channels)) {
gst_caps_set_simple (caps, "channels", G_TYPE_INT, channels, NULL);

View file

@ -179,9 +179,9 @@ gst_rtp_bv_pay_sink_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
GstCaps *otherpadcaps;
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *structure;
@ -201,6 +201,7 @@ gst_rtp_bv_pay_sink_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
mode = -1;
if (mode == 16 || mode == 32) {
caps = gst_caps_make_writable (caps);
structure = gst_caps_get_structure (caps, 0);
gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
}

View file

@ -164,15 +164,20 @@ gst_rtp_celt_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps *caps;
const gchar *params;
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *ps = gst_caps_get_structure (otherpadcaps, 0);
GstStructure *s = gst_caps_get_structure (caps, 0);
GstStructure *ps;
GstStructure *s;
gint clock_rate = 0, frame_size = 0, channels = 1;
caps = gst_caps_make_writable (caps);
ps = gst_caps_get_structure (otherpadcaps, 0);
s = gst_caps_get_structure (caps, 0);
if (gst_structure_get_int (ps, "clock-rate", &clock_rate)) {
gst_structure_fixate_field_nearest_int (s, "rate", clock_rate);
}

View file

@ -196,10 +196,11 @@ gst_rtp_g722_pay_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
caps = gst_caps_make_writable (caps);
gst_caps_set_simple (caps, "channels", G_TYPE_INT, 1, NULL);
gst_caps_set_simple (caps, "rate", G_TYPE_INT, 16000, NULL);
}

View file

@ -235,7 +235,7 @@ gst_rtp_h263p_pay_sink_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps * filter)
{
GstRtpH263PPay *rtph263ppay;
GstCaps *caps = NULL;
GstCaps *caps = NULL, *templ;
GstCaps *peercaps = NULL;
GstCaps *intersect = NULL;
guint i;
@ -246,12 +246,12 @@ gst_rtp_h263p_pay_sink_getcaps (GstRTPBasePayload * payload, GstPad * pad,
gst_pad_peer_query_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload), filter);
if (!peercaps)
return
gst_caps_copy (gst_pad_get_pad_template_caps
(GST_RTP_BASE_PAYLOAD_SINKPAD (payload)));
gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SINKPAD (payload));
intersect = gst_caps_intersect (peercaps,
gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload)));
templ = gst_pad_get_pad_template_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload));
intersect = gst_caps_intersect (peercaps, templ);
gst_caps_unref (peercaps);
gst_caps_unref (templ);
if (gst_caps_is_empty (intersect))
return intersect;

View file

@ -183,7 +183,7 @@ gst_rtp_ilbc_pay_sink_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (rtppayload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
@ -198,6 +198,7 @@ gst_rtp_ilbc_pay_sink_getcaps (GstRTPBasePayload * rtppayload, GstPad * pad,
if (mode_str) {
mode = strtol (mode_str, NULL, 10);
if (mode == 20 || mode == 30) {
caps = gst_caps_make_writable (caps);
structure = gst_caps_get_structure (caps, 0);
gst_structure_set (structure, "mode", G_TYPE_INT, mode, NULL);
}

View file

@ -114,14 +114,18 @@ gst_rtp_speex_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps *caps;
otherpadcaps = gst_pad_get_allowed_caps (payload->srcpad);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
caps = gst_pad_get_pad_template_caps (pad);
if (otherpadcaps) {
if (!gst_caps_is_empty (otherpadcaps)) {
GstStructure *ps = gst_caps_get_structure (otherpadcaps, 0);
GstStructure *s = gst_caps_get_structure (caps, 0);
GstStructure *ps;
GstStructure *s;
gint clock_rate;
ps = gst_caps_get_structure (otherpadcaps, 0);
caps = gst_caps_make_writable (caps);
s = gst_caps_get_structure (caps, 0);
if (gst_structure_get_int (ps, "clock-rate", &clock_rate)) {
gst_structure_fixate_field_nearest_int (s, "rate", clock_rate);
}

View file

@ -327,17 +327,19 @@ static GstCaps *
gst_shape_wipe_video_sink_getcaps (GstPad * pad, GstCaps * filter)
{
GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
GstCaps *ret, *tmp;
GstCaps *templ, *ret, *tmp;
if (gst_pad_has_current_caps (pad))
return gst_pad_get_current_caps (pad);
templ = gst_pad_get_pad_template_caps (pad);
tmp = gst_pad_peer_query_caps (self->srcpad, NULL);
if (tmp) {
ret = gst_caps_intersect (tmp, gst_pad_get_pad_template_caps (pad));
ret = gst_caps_intersect (tmp, templ);
gst_caps_unref (templ);
gst_caps_unref (tmp);
} else {
ret = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
ret = templ;
}
GST_LOG_OBJECT (pad, "srcpad accepted caps: %" GST_PTR_FORMAT, ret);
@ -365,6 +367,7 @@ gst_shape_wipe_video_sink_getcaps (GstPad * pad, GstCaps * filter)
if (self->vinfo.height && self->vinfo.width) {
guint i, n;
ret = gst_caps_make_writable (ret);
n = gst_caps_get_size (ret);
for (i = 0; i < n; i++) {
GstStructure *s = gst_caps_get_structure (ret, i);
@ -381,15 +384,13 @@ gst_shape_wipe_video_sink_getcaps (GstPad * pad, GstCaps * filter)
GstCaps *intersection, *tmp2;
guint i, n;
tmp = gst_caps_make_writable (tmp);
tmp2 = gst_caps_copy (gst_pad_get_pad_template_caps (self->mask_sinkpad));
tmp2 = gst_pad_get_pad_template_caps (self->mask_sinkpad);
intersection = gst_caps_intersect (tmp, tmp2);
gst_caps_unref (tmp);
gst_caps_unref (tmp2);
tmp = intersection;
tmp = gst_caps_make_writable (tmp);
n = gst_caps_get_size (tmp);
for (i = 0; i < n; i++) {
@ -463,7 +464,7 @@ gst_shape_wipe_mask_sink_getcaps (GstPad * pad, GstCaps * filter)
gst_pad_get_pad_template_caps (self->video_sinkpad));
gst_caps_unref (tmp);
} else {
ret = gst_caps_copy (gst_pad_get_pad_template_caps (self->video_sinkpad));
ret = gst_pad_get_pad_template_caps (self->video_sinkpad);
}
GST_LOG_OBJECT (pad, "video sink accepted caps: %" GST_PTR_FORMAT, ret);
@ -536,21 +537,21 @@ static GstCaps *
gst_shape_wipe_src_getcaps (GstPad * pad, GstCaps * filter)
{
GstShapeWipe *self = GST_SHAPE_WIPE (gst_pad_get_parent (pad));
GstCaps *ret, *tmp;
GstCaps *templ, *ret, *tmp;
if (gst_pad_has_current_caps (pad))
return gst_pad_get_current_caps (pad);
else if (gst_pad_has_current_caps (self->video_sinkpad))
return gst_pad_get_current_caps (self->video_sinkpad);
templ = gst_pad_get_pad_template_caps (self->video_sinkpad);
tmp = gst_pad_peer_query_caps (self->video_sinkpad, NULL);
if (tmp) {
ret =
gst_caps_intersect (tmp,
gst_pad_get_pad_template_caps (self->video_sinkpad));
ret = gst_caps_intersect (tmp, templ);
gst_caps_unref (templ);
gst_caps_unref (tmp);
} else {
ret = gst_caps_copy (gst_pad_get_pad_template_caps (self->video_sinkpad));
ret = templ;
}
GST_LOG_OBJECT (pad, "video sink accepted caps: %" GST_PTR_FORMAT, ret);
@ -577,6 +578,7 @@ gst_shape_wipe_src_getcaps (GstPad * pad, GstCaps * filter)
if (self->vinfo.height && self->vinfo.width) {
guint i, n;
ret = gst_caps_make_writable (ret);
n = gst_caps_get_size (ret);
for (i = 0; i < n; i++) {
GstStructure *s = gst_caps_get_structure (ret, i);
@ -592,14 +594,12 @@ gst_shape_wipe_src_getcaps (GstPad * pad, GstCaps * filter)
GstCaps *intersection, *tmp2;
guint i, n;
tmp = gst_caps_make_writable (tmp);
tmp2 = gst_caps_copy (gst_pad_get_pad_template_caps (self->mask_sinkpad));
tmp2 = gst_pad_get_pad_template_caps (self->mask_sinkpad);
intersection = gst_caps_intersect (tmp, tmp2);
gst_caps_unref (tmp);
gst_caps_unref (tmp2);
tmp = intersection;
tmp = gst_caps_make_writable (intersection);
n = gst_caps_get_size (tmp);
for (i = 0; i < n; i++) {

View file

@ -545,13 +545,14 @@ gst_smpte_collected (GstCollectPads2 * pads, GstSMPTE * smpte)
GstSegment segment;
caps =
gst_caps_copy (gst_static_caps_get
gst_caps_make_writable (gst_static_caps_get
(&gst_smpte_src_template.static_caps));
gst_caps_set_simple (caps, "width", G_TYPE_INT, smpte->width, "height",
G_TYPE_INT, smpte->height, "framerate", GST_TYPE_FRACTION,
smpte->fps_num, smpte->fps_denom, NULL);
gst_pad_set_caps (smpte->srcpad, caps);
gst_caps_unref (caps);
gst_segment_init (&segment, GST_FORMAT_TIME);
gst_pad_push_event (smpte->srcpad, gst_event_new_segment (&segment));

View file

@ -294,14 +294,13 @@ gst_oss_sink_getcaps (GstBaseSink * bsink)
osssink = GST_OSSSINK (bsink);
if (osssink->fd == -1) {
caps = gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
(bsink)));
caps = gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (bsink));
} else if (osssink->probed_caps) {
caps = gst_caps_copy (osssink->probed_caps);
caps = gst_caps_ref (osssink->probed_caps);
} else {
caps = gst_oss_helper_probe_caps (osssink->fd);
if (caps && !gst_caps_is_empty (caps)) {
osssink->probed_caps = gst_caps_copy (caps);
osssink->probed_caps = gst_caps_ref (caps);
}
}

View file

@ -513,9 +513,7 @@ gst_v4l2sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
if (!GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
/* FIXME: copy? */
GST_DEBUG_OBJECT (v4l2sink, "device is not open");
return
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD
(v4l2sink)));
return gst_pad_get_pad_template_caps (GST_BASE_SINK_PAD (v4l2sink));
}
if (v4l2sink->probed_caps == NULL) {

View file

@ -442,10 +442,7 @@ gst_v4l2src_get_caps (GstBaseSrc * src, GstCaps * filter)
obj = v4l2src->v4l2object;
if (!GST_V4L2_IS_OPEN (obj)) {
/* FIXME: copy? */
return
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
(v4l2src)));
return gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (v4l2src));
}
if (v4l2src->probed_caps)

View file

@ -1022,14 +1022,10 @@ gst_ximage_src_get_caps (GstBaseSrc * bs, GstCaps * filter)
GstVideoFormat format;
if ((!s->xcontext) && (!gst_ximage_src_open_display (s, s->display_name)))
return
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC
(s)->srcpad));
return gst_pad_get_pad_template_caps (GST_BASE_SRC (s)->srcpad);
if (!gst_ximage_src_recalc (s))
return
gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC
(s)->srcpad));
return gst_pad_get_pad_template_caps (GST_BASE_SRC (s)->srcpad);
xcontext = s->xcontext;
width = s->xcontext->width;

View file

@ -208,7 +208,7 @@ check_qtmux_pad (GstStaticPadTemplate * srctemplate, const gchar * sinkname,
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
inbuffer = gst_buffer_new_and_alloc (1);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
caps = gst_pad_get_pad_template_caps (mysrcpad);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -296,7 +296,7 @@ check_qtmux_pad_fragmented (GstStaticPadTemplate * srctemplate,
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
inbuffer = gst_buffer_new_and_alloc (1);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
caps = gst_pad_get_pad_template_caps (mysrcpad);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -526,7 +526,7 @@ GST_START_TEST (test_reuse)
inbuffer = gst_buffer_new_and_alloc (1);
fail_unless (inbuffer != NULL);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
caps = gst_pad_get_pad_template_caps (mysrcpad);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -817,7 +817,7 @@ test_average_bitrate_custom (const gchar * elementname,
for (i = 0; i < 3; i++) {
inbuffer = gst_buffer_new_and_alloc (bytes[i]);
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
caps = gst_pad_get_pad_template_caps (mysrcpad);
gst_pad_set_caps (mysrcpad, caps);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = total_duration;