gst/realmedia/rmdemux.c: Don't leak streams, strings or caps. Get rid of unnecessary getcaps() function.

Original commit message from CVS:
* gst/realmedia/rmdemux.c: (gst_rmdemux_reset),
(gst_rmdemux_change_state), (gst_rmdemux_add_stream),
(gst_rmdemux_parse_cont), (gst_rmdemux_descramble_cook_audio),
(gst_rmdemux_handle_scrambled_packet), (gst_rmdemux_parse_packet):
Don't leak streams, strings or caps. Get rid of unnecessary
getcaps() function.
This commit is contained in:
Tim-Philipp Müller 2006-07-28 13:28:19 +00:00
parent 1b4d54debc
commit 05097283d8
2 changed files with 67 additions and 49 deletions

View file

@ -1,3 +1,12 @@
2006-07-28 Tim-Philipp Müller <tim at centricular dot net>
* gst/realmedia/rmdemux.c: (gst_rmdemux_reset),
(gst_rmdemux_change_state), (gst_rmdemux_add_stream),
(gst_rmdemux_parse_cont), (gst_rmdemux_descramble_cook_audio),
(gst_rmdemux_handle_scrambled_packet), (gst_rmdemux_parse_packet):
Don't leak streams, strings or caps. Get rid of unnecessary
getcaps() function.
2006-07-27 Tim-Philipp Müller <tim at centricular dot net> 2006-07-27 Tim-Philipp Müller <tim at centricular dot net>
* gst/realmedia/rmdemux.c: (gst_rmdemux_class_init), * gst/realmedia/rmdemux.c: (gst_rmdemux_class_init),

View file

@ -47,7 +47,6 @@ struct _GstRMDemuxStream
guint32 format; guint32 format;
int id; int id;
GstCaps *caps;
GstPad *pad; GstPad *pad;
GstFlowReturn last_flow; GstFlowReturn last_flow;
int timescale; int timescale;
@ -150,9 +149,8 @@ static GstFlowReturn gst_rmdemux_parse_packet (GstRMDemux * rmdemux,
const void *data, guint16 version, guint16 length); const void *data, guint16 version, guint16 length);
static void gst_rmdemux_parse_indx_data (GstRMDemux * rmdemux, const void *data, static void gst_rmdemux_parse_indx_data (GstRMDemux * rmdemux, const void *data,
int length); int length);
static void gst_rmdemux_stream_clear_cached_subpackets (GstRMDemux * rmdemux,
static GstCaps *gst_rmdemux_src_getcaps (GstPad * pad); GstRMDemuxStream * stream);
static GstRMDemuxStream *gst_rmdemux_get_stream_by_id (GstRMDemux * rmdemux, static GstRMDemuxStream *gst_rmdemux_get_stream_by_id (GstRMDemux * rmdemux,
int id); int id);
@ -646,6 +644,34 @@ gst_rmdemux_src_query_types (GstPad * pad)
return query_types; return query_types;
} }
static void
gst_rmdemux_reset (GstRMDemux * rmdemux)
{
guint n;
GST_OBJECT_LOCK (rmdemux);
rmdemux->running = FALSE;
GST_OBJECT_UNLOCK (rmdemux);
for (n = 0; n < rmdemux->n_streams; ++n) {
gst_rmdemux_stream_clear_cached_subpackets (rmdemux, rmdemux->streams[n]);
gst_element_remove_pad (GST_ELEMENT (rmdemux), rmdemux->streams[n]->pad);
if (rmdemux->streams[n]->subpackets)
g_ptr_array_free (rmdemux->streams[n]->subpackets, TRUE);
g_free (rmdemux->streams[n]);
rmdemux->streams[n] = NULL;
}
rmdemux->n_streams = 0;
rmdemux->n_audio_streams = 0;
rmdemux->n_video_streams = 0;
gst_adapter_clear (rmdemux->adapter);
rmdemux->state = RMDEMUX_STATE_HEADER;
rmdemux->have_pads = FALSE;
gst_segment_init (&rmdemux->segment, GST_FORMAT_UNDEFINED);
}
static GstStateChangeReturn static GstStateChangeReturn
gst_rmdemux_change_state (GstElement * element, GstStateChange transition) gst_rmdemux_change_state (GstElement * element, GstStateChange transition)
{ {
@ -672,12 +698,10 @@ gst_rmdemux_change_state (GstElement * element, GstStateChange transition)
switch (transition) { switch (transition) {
case GST_STATE_CHANGE_PLAYING_TO_PAUSED: case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_CHANGE_PAUSED_TO_READY: case GST_STATE_CHANGE_PAUSED_TO_READY:{
gst_adapter_clear (rmdemux->adapter); gst_rmdemux_reset (rmdemux);
GST_OBJECT_LOCK (rmdemux);
rmdemux->running = FALSE;
GST_OBJECT_UNLOCK (rmdemux);
break; break;
}
case GST_STATE_CHANGE_READY_TO_NULL: case GST_STATE_CHANGE_READY_TO_NULL:
break; break;
default: default:
@ -687,24 +711,6 @@ gst_rmdemux_change_state (GstElement * element, GstStateChange transition)
return res; return res;
} }
static GstCaps *
gst_rmdemux_src_getcaps (GstPad * pad)
{
guint n;
GstRMDemux *rmdemux = GST_RMDEMUX (GST_PAD_PARENT (pad));
GST_DEBUG_OBJECT (rmdemux, "getcaps");
for (n = 0; n < rmdemux->n_streams; n++) {
if (rmdemux->streams[n] != NULL && rmdemux->streams[n]->pad == pad) {
return gst_caps_copy (rmdemux->streams[n]->caps);
}
}
/* Base case */
return gst_caps_new_empty ();
}
/* this function is called when the pad is activated and should start /* this function is called when the pad is activated and should start
* processing data. * processing data.
* *
@ -1202,6 +1208,7 @@ gst_rmdemux_send_event (GstRMDemux * rmdemux, GstEvent * event)
static void static void
gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream) gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
{ {
GstCaps *stream_caps = NULL;
const gchar *codec_tag = NULL; const gchar *codec_tag = NULL;
const gchar *codec_name = NULL; const gchar *codec_name = NULL;
int version = 0; int version = 0;
@ -1237,7 +1244,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
} }
if (version) { if (version) {
stream->caps = stream_caps =
gst_caps_new_simple ("video/x-pn-realvideo", "rmversion", G_TYPE_INT, gst_caps_new_simple ("video/x-pn-realvideo", "rmversion", G_TYPE_INT,
(int) version, (int) version,
"format", G_TYPE_INT, "format", G_TYPE_INT,
@ -1245,8 +1252,8 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
"subformat", G_TYPE_INT, (int) stream->subformat, NULL); "subformat", G_TYPE_INT, (int) stream->subformat, NULL);
} }
if (stream->caps) { if (stream_caps) {
gst_caps_set_simple (stream->caps, gst_caps_set_simple (stream_caps,
"width", G_TYPE_INT, stream->width, "width", G_TYPE_INT, stream->width,
"height", G_TYPE_INT, stream->height, "height", G_TYPE_INT, stream->height,
"framerate", GST_TYPE_FRACTION, stream->framerate_numerator, "framerate", GST_TYPE_FRACTION, stream->framerate_numerator,
@ -1279,7 +1286,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
/* DolbyNet (Dolby AC3, low bitrate) */ /* DolbyNet (Dolby AC3, low bitrate) */
case GST_RM_AUD_DNET: case GST_RM_AUD_DNET:
codec_name = "AC-3 audio"; codec_name = "AC-3 audio";
stream->caps = stream_caps =
gst_caps_new_simple ("audio/x-ac3", "rate", G_TYPE_INT, gst_caps_new_simple ("audio/x-ac3", "rate", G_TYPE_INT,
(int) stream->rate, NULL); (int) stream->rate, NULL);
stream->needs_descrambling = TRUE; stream->needs_descrambling = TRUE;
@ -1296,7 +1303,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
/* MPEG-4 based */ /* MPEG-4 based */
case GST_RM_AUD_RACP: case GST_RM_AUD_RACP:
/* FIXME: codec_name = */ /* FIXME: codec_name = */
stream->caps = stream_caps =
gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT,
(int) 4, NULL); (int) 4, NULL);
break; break;
@ -1304,7 +1311,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
/* Sony ATRAC3 */ /* Sony ATRAC3 */
case GST_RM_AUD_ATRC: case GST_RM_AUD_ATRC:
codec_name = "Sony ATRAC3"; codec_name = "Sony ATRAC3";
stream->caps = gst_caps_new_simple ("audio/x-vnd.sony.atrac3", NULL); stream_caps = gst_caps_new_simple ("audio/x-vnd.sony.atrac3", NULL);
break; break;
/* RealAudio G2 audio */ /* RealAudio G2 audio */
@ -1320,13 +1327,13 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
case GST_RM_AUD_RALF: case GST_RM_AUD_RALF:
/* FIXME: codec_name = */ /* FIXME: codec_name = */
GST_DEBUG_OBJECT (rmdemux, "RALF"); GST_DEBUG_OBJECT (rmdemux, "RALF");
stream->caps = gst_caps_new_simple ("audio/x-ralf-mpeg4-generic", NULL); stream_caps = gst_caps_new_simple ("audio/x-ralf-mpeg4-generic", NULL);
break; break;
/* Sipro/ACELP.NET Voice Codec (MIME unknown) */ /* Sipro/ACELP.NET Voice Codec (MIME unknown) */
case GST_RM_AUD_SIPR: case GST_RM_AUD_SIPR:
/* FIXME: codec_name = */ /* FIXME: codec_name = */
stream->caps = gst_caps_new_simple ("audio/x-sipro", NULL); stream_caps = gst_caps_new_simple ("audio/x-sipro", NULL);
break; break;
default: default:
@ -1337,13 +1344,13 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
} }
if (version) { if (version) {
stream->caps = stream_caps =
gst_caps_new_simple ("audio/x-pn-realaudio", "raversion", G_TYPE_INT, gst_caps_new_simple ("audio/x-pn-realaudio", "raversion", G_TYPE_INT,
(int) version, NULL); (int) version, NULL);
} }
if (stream->caps) { if (stream_caps) {
gst_caps_set_simple (stream->caps, gst_caps_set_simple (stream_caps,
"flavor", G_TYPE_INT, (int) stream->flavor, "flavor", G_TYPE_INT, (int) stream->flavor,
"rate", G_TYPE_INT, (int) stream->rate, "rate", G_TYPE_INT, (int) stream->rate,
"channels", G_TYPE_INT, (int) stream->n_channels, "channels", G_TYPE_INT, (int) stream->n_channels,
@ -1365,7 +1372,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
rmdemux->n_streams++; rmdemux->n_streams++;
GST_LOG_OBJECT (rmdemux, "n_streams is now %d", rmdemux->n_streams); GST_LOG_OBJECT (rmdemux, "n_streams is now %d", rmdemux->n_streams);
if (stream->pad && stream->caps) { if (stream->pad && stream_caps) {
GST_LOG_OBJECT (rmdemux, "%d bytes of extra data for stream %s", GST_LOG_OBJECT (rmdemux, "%d bytes of extra data for stream %s",
stream->extra_data_size, GST_PAD_NAME (stream->pad)); stream->extra_data_size, GST_PAD_NAME (stream->pad));
@ -1378,17 +1385,15 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
memcpy (GST_BUFFER_DATA (buffer), stream->extra_data, memcpy (GST_BUFFER_DATA (buffer), stream->extra_data,
stream->extra_data_size); stream->extra_data_size);
gst_caps_set_simple (stream->caps, "codec_data", GST_TYPE_BUFFER, gst_caps_set_simple (stream_caps, "codec_data", GST_TYPE_BUFFER,
buffer, NULL); buffer, NULL);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
} }
gst_pad_set_caps (stream->pad, stream->caps); gst_pad_use_fixed_caps (stream->pad);
gst_caps_unref (stream->caps);
gst_pad_set_getcaps_function (stream->pad, gst_pad_set_caps (stream->pad, stream_caps);
GST_DEBUG_FUNCPTR (gst_rmdemux_src_getcaps));
gst_pad_set_event_function (stream->pad, gst_pad_set_event_function (stream->pad,
GST_DEBUG_FUNCPTR (gst_rmdemux_src_event)); GST_DEBUG_FUNCPTR (gst_rmdemux_src_event));
gst_pad_set_query_type_function (stream->pad, gst_pad_set_query_type_function (stream->pad,
@ -1397,7 +1402,7 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
GST_DEBUG_FUNCPTR (gst_rmdemux_src_query)); GST_DEBUG_FUNCPTR (gst_rmdemux_src_query));
GST_DEBUG_OBJECT (rmdemux, "adding pad %s with caps %" GST_PTR_FORMAT GST_DEBUG_OBJECT (rmdemux, "adding pad %s with caps %" GST_PTR_FORMAT
", stream_id=%d", GST_PAD_NAME (stream->pad), stream->caps, stream->id); ", stream_id=%d", GST_PAD_NAME (stream->pad), stream_caps, stream->id);
gst_element_add_pad (GST_ELEMENT (rmdemux), stream->pad); gst_element_add_pad (GST_ELEMENT (rmdemux), stream->pad);
gst_pad_push_event (stream->pad, gst_pad_push_event (stream->pad,
@ -1414,7 +1419,9 @@ gst_rmdemux_add_stream (GstRMDemux * rmdemux, GstRMDemuxStream * stream)
} }
beach: beach:
return;
if (stream_caps)
gst_caps_unref (stream_caps);
} }
G_GNUC_UNUSED static void G_GNUC_UNUSED static void
@ -1770,6 +1777,7 @@ gst_rmdemux_parse_cont (GstRMDemux * rmdemux, const void *data, int length)
if (str != NULL && *str != '\0') { if (str != NULL && *str != '\0') {
gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, gst_tags[i], str, NULL); gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, gst_tags[i], str, NULL);
} }
g_free (str);
} }
} }
@ -1843,7 +1851,8 @@ gst_rmdemux_descramble_cook_audio (GstRMDemux * rmdemux,
leaf_size, height); leaf_size, height);
ret = gst_pad_alloc_buffer_and_set_caps (stream->pad, ret = gst_pad_alloc_buffer_and_set_caps (stream->pad,
GST_BUFFER_OFFSET_NONE, height * packet_size, stream->caps, &outbuf); GST_BUFFER_OFFSET_NONE, height * packet_size,
GST_PAD_CAPS (stream->pad), &outbuf);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto done; goto done;
@ -1903,7 +1912,7 @@ gst_rmdemux_handle_scrambled_packet (GstRMDemux * rmdemux,
GstFlowReturn ret; GstFlowReturn ret;
if (stream->subpackets == NULL) if (stream->subpackets == NULL)
stream->subpackets = g_ptr_array_new (); stream->subpackets = g_ptr_array_sized_new (stream->subpackets_needed);
GST_LOG ("Got subpacket %u/%u, len=%u, key=%d", stream->subpackets->len + 1, GST_LOG ("Got subpacket %u/%u, len=%u, key=%d", stream->subpackets->len + 1,
stream->subpackets_needed, GST_BUFFER_SIZE (buf), keyframe); stream->subpackets_needed, GST_BUFFER_SIZE (buf), keyframe);
@ -1985,7 +1994,7 @@ gst_rmdemux_parse_packet (GstRMDemux * rmdemux, const void *data,
} }
ret = gst_pad_alloc_buffer_and_set_caps (stream->pad, ret = gst_pad_alloc_buffer_and_set_caps (stream->pad,
GST_BUFFER_OFFSET_NONE, packet_size, stream->caps, &buffer); GST_BUFFER_OFFSET_NONE, packet_size, GST_PAD_CAPS (stream->pad), &buffer);
cret = gst_rmdemux_combine_flows (rmdemux, stream, ret); cret = gst_rmdemux_combine_flows (rmdemux, stream, ret);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)