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.
This commit is contained in:
Tim-Philipp Müller 2006-04-13 18:21:08 +00:00
parent c538a643c3
commit 7780db0401
4 changed files with 26 additions and 19 deletions

View file

@ -1,3 +1,17 @@
2006-04-13 Tim-Philipp Müller <tim at centricular dot net>
* 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 <thomas at apestaart dot org> 2006-04-10 Thomas Vander Stichele <thomas at apestaart dot org>
* common/check.mak: * common/check.mak:

View file

@ -23,7 +23,6 @@
#include <string.h> #include <string.h>
/*#define GST_DEBUG_ENABLED */
#include "gstmpegpacketize.h" #include "gstmpegpacketize.h"
GstMPEGPacketize * GstMPEGPacketize *
@ -69,7 +68,7 @@ gst_mpeg_packetize_tell (GstMPEGPacketize * packetize)
return packetize->cache_byte_pos + packetize->cache_head; return packetize->cache_byte_pos + packetize->cache_head;
} }
gboolean void
gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf) gst_mpeg_packetize_put (GstMPEGPacketize * packetize, GstBuffer * buf)
{ {
int cache_len = packetize->cache_tail - packetize->cache_head; 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 */ /* allocate new cache - do not realloc to avoid copying data twice */
new_cache = g_malloc (packetize->cache_size); 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 */ /* 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); 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); packetize->cache_tail += GST_BUFFER_SIZE (buf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return TRUE;
} }
static guint static guint
@ -145,8 +141,6 @@ read_cache (GstMPEGPacketize * packetize, guint length, GstBuffer ** outbuf)
return GST_FLOW_RESEND; return GST_FLOW_RESEND;
*outbuf = gst_buffer_new_and_alloc (length); *outbuf = gst_buffer_new_and_alloc (length);
if (*outbuf == NULL)
return GST_FLOW_ERROR;
memcpy (GST_BUFFER_DATA (*outbuf), packetize->cache + packetize->cache_head, memcpy (GST_BUFFER_DATA (*outbuf), packetize->cache + packetize->cache_head,
length); length);

View file

@ -71,7 +71,7 @@ GstMPEGPacketize* gst_mpeg_packetize_new (GstPad *pad, GstMPEGPacketizeType
void gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize); void gst_mpeg_packetize_destroy (GstMPEGPacketize *packetize);
guint64 gst_mpeg_packetize_tell (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); GstFlowReturn gst_mpeg_packetize_read (GstMPEGPacketize *packetize, GstBuffer ** outbuf);
G_END_DECLS G_END_DECLS

View file

@ -321,6 +321,7 @@ gst_mpeg_parse_send_buffer (GstMPEGParse * mpeg_parse, GstBuffer * buffer,
GST_ELEMENT_ERROR (GST_ELEMENT (mpeg_parse), GST_ELEMENT_ERROR (GST_ELEMENT (mpeg_parse),
CORE, NEGOTIATION, (NULL), ("failed to set caps")); CORE, NEGOTIATION, (NULL), ("failed to set caps"));
gst_caps_unref (caps); gst_caps_unref (caps);
gst_buffer_unref (buffer);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
gst_caps_unref (caps); gst_caps_unref (caps);
@ -689,12 +690,10 @@ gst_mpeg_parse_chain (GstPad * pad, GstBuffer * buffer)
GstClockTime time; GstClockTime time;
guint64 size; guint64 size;
if (!gst_mpeg_packetize_put (mpeg_parse->packetize, buffer)) { gst_mpeg_packetize_put (mpeg_parse->packetize, buffer);
gst_buffer_unref (buffer); buffer = NULL;
goto done;
}
while (1) { do {
result = gst_mpeg_packetize_read (mpeg_parse->packetize, &buffer); result = gst_mpeg_packetize_read (mpeg_parse->packetize, &buffer);
if (result == GST_FLOW_RESEND) { if (result == GST_FLOW_RESEND) {
/* there was not enough data in packetizer cache */ /* there was not enough data in packetizer cache */
@ -772,8 +771,13 @@ gst_mpeg_parse_chain (GstPad * pad, GstBuffer * buffer)
GST_FLOW_OK); GST_FLOW_OK);
time = CLASS (mpeg_parse)->adjust_ts (mpeg_parse, time = CLASS (mpeg_parse)->adjust_ts (mpeg_parse,
MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr)); MPEGTIME_TO_GSTTIME (mpeg_parse->current_scr));
if (CLASS (mpeg_parse)->send_buffer) if (CLASS (mpeg_parse)->send_buffer)
result = CLASS (mpeg_parse)->send_buffer (mpeg_parse, buffer, time); result = CLASS (mpeg_parse)->send_buffer (mpeg_parse, buffer, time);
else
gst_buffer_unref (buffer);
buffer = NULL;
/* Calculate the expected next SCR. */ /* Calculate the expected next SCR. */
if (mpeg_parse->current_scr != MP_INVALID_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 ", total since SCR: %" G_GINT64_FORMAT ", br: %" G_GINT64_FORMAT
", next SCR: %" G_GINT64_FORMAT, size, bss, br, mpeg_parse->next_scr); ", next SCR: %" G_GINT64_FORMAT, size, bss, br, mpeg_parse->next_scr);
} }
} while (!GST_FLOW_IS_FATAL (result));
if (result != GST_FLOW_OK && result != GST_FLOW_NOT_LINKED) {
gst_buffer_unref (buffer);
goto done;
}
}
done: done:
gst_object_unref (mpeg_parse); gst_object_unref (mpeg_parse);