From 7780db0401727352a60c80eba05e5df88a8b3fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 13 Apr 2006 18:21:08 +0000 Subject: [PATCH] gst/mpegstream/gstmpegpacketize.*: g_malloc() can't fail, we don't need to handle this. Same for gst_buffer_new_and_a... Original commit message from CVS: * gst/mpegstream/gstmpegpacketize.c: (gst_mpeg_packetize_put), (read_cache): * gst/mpegstream/gstmpegpacketize.h: g_malloc() can't fail, we don't need to handle this. Same for gst_buffer_new_and_alloc(). * gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_chain): klass->send_buffer() should have the same semantics as gst_pad_push(), ie. ownership of the buffer is transfered, so we never have to unref the buffer no matter what the flow return value was. --- ChangeLog | 14 ++++++++++++++ gst/mpegstream/gstmpegpacketize.c | 8 +------- gst/mpegstream/gstmpegpacketize.h | 2 +- gst/mpegstream/gstmpegparse.c | 21 ++++++++++----------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3fbfc7c15..acfa4de204 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-04-13 Tim-Philipp Müller + + * gst/mpegstream/gstmpegpacketize.c: (gst_mpeg_packetize_put), + (read_cache): + * gst/mpegstream/gstmpegpacketize.h: + g_malloc() can't fail, we don't need to handle this. Same for + gst_buffer_new_and_alloc(). + + * gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_chain): + klass->send_buffer() should have the same semantics as + gst_pad_push(), ie. ownership of the buffer is transfered, + so we never have to unref the buffer no matter what the flow + return value was. + 2006-04-10 Thomas Vander Stichele * common/check.mak: diff --git a/gst/mpegstream/gstmpegpacketize.c b/gst/mpegstream/gstmpegpacketize.c index fcad61244a..9f985533f9 100644 --- a/gst/mpegstream/gstmpegpacketize.c +++ b/gst/mpegstream/gstmpegpacketize.c @@ -23,7 +23,6 @@ #include -/*#define GST_DEBUG_ENABLED */ #include "gstmpegpacketize.h" GstMPEGPacketize * @@ -69,7 +68,7 @@ gst_mpeg_packetize_tell (GstMPEGPacketize * packetize) return packetize->cache_byte_pos + packetize->cache_head; } -gboolean +void gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf) { int cache_len = packetize->cache_tail - packetize->cache_head; @@ -86,8 +85,6 @@ gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf) /* allocate new cache - do not realloc to avoid copying data twice */ new_cache = g_malloc (packetize->cache_size); - if (new_cache == NULL) - return FALSE; /* copy the data to the beginning of the new cache and update the cache info */ memcpy (new_cache, packetize->cache + packetize->cache_head, cache_len); @@ -114,7 +111,6 @@ gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf) packetize->cache_tail += GST_BUFFER_SIZE (buf); gst_buffer_unref (buf); - return TRUE; } static guint @@ -145,8 +141,6 @@ read_cache (GstMPEGPacketize * packetize, guint length, GstBuffer ** outbuf) return GST_FLOW_RESEND; *outbuf = gst_buffer_new_and_alloc (length); - if (*outbuf == NULL) - return GST_FLOW_ERROR; memcpy (GST_BUFFER_DATA (*outbuf), packetize->cache + packetize->cache_head, length); diff --git a/gst/mpegstream/gstmpegpacketize.h b/gst/mpegstream/gstmpegpacketize.h index 2b51911a3f..380017ec9b 100644 --- a/gst/mpegstream/gstmpegpacketize.h +++ b/gst/mpegstream/gstmpegpacketize.h @@ -71,7 +71,7 @@ GstMPEGPacketize* gst_mpeg_packetize_new (GstPad *pad, GstMPEGPacketizeType void gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize); guint64 gst_mpeg_packetize_tell (GstMPEGPacketize *packetize); -gboolean gst_mpeg_packetize_put (GstMPEGPacketize *packetize, GstBuffer * buf); +void gst_mpeg_packetize_put (GstMPEGPacketize *packetize, GstBuffer * buf); GstFlowReturn gst_mpeg_packetize_read (GstMPEGPacketize *packetize, GstBuffer ** outbuf); G_END_DECLS diff --git a/gst/mpegstream/gstmpegparse.c b/gst/mpegstream/gstmpegparse.c index 14941a4b3f..dec1fa5ccb 100644 --- a/gst/mpegstream/gstmpegparse.c +++ b/gst/mpegstream/gstmpegparse.c @@ -321,6 +321,7 @@ gst_mpeg_parse_send_buffer (GstMPEGParse * mpeg_parse, GstBuffer * buffer, GST_ELEMENT_ERROR (GST_ELEMENT (mpeg_parse), CORE, NEGOTIATION, (NULL), ("failed to set caps")); gst_caps_unref (caps); + gst_buffer_unref (buffer); return GST_FLOW_ERROR; } gst_caps_unref (caps); @@ -689,12 +690,10 @@ gst_mpeg_parse_chain (GstPad * pad, GstBuffer * buffer) GstClockTime time; guint64 size; - if (!gst_mpeg_packetize_put (mpeg_parse->packetize, buffer)) { - gst_buffer_unref (buffer); - goto done; - } + gst_mpeg_packetize_put (mpeg_parse->packetize, buffer); + buffer = NULL; - while (1) { + do { result = gst_mpeg_packetize_read (mpeg_parse->packetize, &buffer); if (result == GST_FLOW_RESEND) { /* there was not enough data in packetizer cache */ @@ -772,8 +771,13 @@ gst_mpeg_parse_chain (GstPad * pad, GstBuffer * buffer) GST_FLOW_OK); time = CLASS (mpeg_parse)->adjust_ts (mpeg_parse, MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr)); + if (CLASS (mpeg_parse)->send_buffer) result = CLASS (mpeg_parse)->send_buffer (mpeg_parse, buffer, time); + else + gst_buffer_unref (buffer); + + buffer = NULL; /* Calculate the expected next SCR. */ if (mpeg_parse->current_scr != MP_INVALID_SCR) { @@ -809,12 +813,7 @@ gst_mpeg_parse_chain (GstPad * pad, GstBuffer * buffer) ", total since SCR: %" G_GINT64_FORMAT ", br: %" G_GINT64_FORMAT ", next SCR: %" G_GINT64_FORMAT, size, bss, br, mpeg_parse->next_scr); } - - if (result != GST_FLOW_OK && result != GST_FLOW_NOT_LINKED) { - gst_buffer_unref (buffer); - goto done; - } - } + } while (!GST_FLOW_IS_FATAL (result)); done: gst_object_unref (mpeg_parse);