+2006-07-26 Wim Taymans <wim@fluendo.com>
+
+ * gst/gstbuffer.c: (gst_buffer_get_type), (gst_buffer_new),
+ (gst_subbuffer_get_type), (gst_buffer_create_sub):
+ Avoid function call for known types by keeping the buffer and
+ subbuffer GType global.
+
+ * plugins/elements/gstfilesrc.c: (gst_file_src_create_read):
+ Random silly optimisations in read() path.
+
2006-07-26 Jan Schmidt <thaytan@mad.scientist.com>
* tools/gst-launch.c: (main):
#include "gstutils.h"
#include "gstminiobject.h"
-
static void gst_buffer_init (GTypeInstance * instance, gpointer g_class);
static void gst_buffer_class_init (gpointer g_class, gpointer class_data);
static void gst_buffer_finalize (GstBuffer * buffer);
static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
static GType gst_subbuffer_get_type (void);
+static GType _gst_subbuffer_type = 0;
+static GType _gst_buffer_type = 0;
+
void
_gst_buffer_initialize (void)
{
GType
gst_buffer_get_type (void)
{
- static GType _gst_buffer_type = 0;
-
if (G_UNLIKELY (_gst_buffer_type == 0)) {
static const GTypeInfo buffer_info = {
sizeof (GstBufferClass),
{
GstBuffer *newbuf;
- newbuf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER);
+ newbuf = (GstBuffer *) gst_mini_object_new (_gst_buffer_type);
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
typedef struct _GstSubBuffer GstSubBuffer;
typedef struct _GstSubBufferClass GstSubBufferClass;
-#define GST_TYPE_SUBBUFFER (gst_subbuffer_get_type())
-
-#define GST_IS_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_SUBBUFFER))
-#define GST_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_SUBBUFFER, GstSubBuffer))
+#define GST_IS_SUBBUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), _gst_subbuffer_type))
#define GST_SUBBUFFER_CAST(obj) ((GstSubBuffer *)(obj))
struct _GstSubBuffer
static GType
gst_subbuffer_get_type (void)
{
- static GType _gst_subbuffer_type = 0;
-
if (G_UNLIKELY (_gst_subbuffer_type == 0)) {
static const GTypeInfo subbuffer_info = {
sizeof (GstSubBufferClass),
gst_buffer_ref (parent);
/* create the new buffer */
- subbuffer = (GstSubBuffer *) gst_mini_object_new (GST_TYPE_SUBBUFFER);
+ subbuffer = (GstSubBuffer *) gst_mini_object_new (_gst_subbuffer_type);
subbuffer->parent = parent;
GST_CAT_LOG (GST_CAT_BUFFER, "new subbuffer %p (parent %p)", subbuffer,
int ret;
GstBuffer *buf;
- if (src->read_position != offset) {
+ if (G_UNLIKELY (src->read_position != offset)) {
off_t res;
res = lseek (src->fd, offset, SEEK_SET);
- if (res < 0 || res != offset)
+ if (G_UNLIKELY (res < 0 || res != offset))
goto seek_failed;
src->read_position = offset;
GST_LOG_OBJECT (src, "Reading %d bytes", length);
ret = read (src->fd, GST_BUFFER_DATA (buf), length);
- if (ret < 0)
+ if (G_UNLIKELY (ret < 0))
goto could_not_read;
/* regular files should have given us what we expected */
- if ((guint) ret < length && src->is_regular)
+ if (G_UNLIKELY ((guint) ret < length && src->is_regular))
goto unexpected_eos;
/* other files should eos if they read 0 */
- if (ret == 0) {
- GST_DEBUG ("non-regular file hits EOS");
- gst_buffer_unref (buf);
- return GST_FLOW_UNEXPECTED;
- }
+ if (G_UNLIKELY (ret == 0))
+ goto eos;
+
length = ret;
GST_BUFFER_SIZE (buf) = length;
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
+eos:
+ {
+ GST_DEBUG ("non-regular file hits EOS");
+ gst_buffer_unref (buf);
+ return GST_FLOW_UNEXPECTED;
+ }
}
static GstFlowReturn