static GstBuffer * gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize) { GstBuffer *buf; gsize size = gst_fake_src_get_size (src); gboolean dump = src->dump; GstMapInfo info; *bufsize = size; switch (src->data) { case FAKE_SRC_DATA_ALLOCATE: buf = gst_fake_src_alloc_buffer (src, size); break; case FAKE_SRC_DATA_SUBBUFFER: /* see if we have a parent to subbuffer */ if (!src->parent) { gst_fake_src_alloc_parent (src); g_assert (src->parent); } /* see if it's large enough */ if ((src->parentsize - src->parentoffset) >= size) { buf = gst_buffer_copy_region (src->parent, GST_BUFFER_COPY_ALL, src->parentoffset, size); src->parentoffset += size; } else { /* the parent is useless now */ gst_buffer_unref (src->parent); src->parent = NULL; /* try again (this will allocate a new parent) */ return gst_fake_src_create_buffer (src, bufsize); } gst_buffer_map (buf, &info, GST_MAP_WRITE); gst_fake_src_prepare_buffer (src, info.data, info.size); gst_buffer_unmap (buf, &info); break; default: g_warning ("fakesrc: dunno how to allocate buffers !"); buf = gst_buffer_new (); break; } if (dump) { gst_buffer_map (buf, &info, GST_MAP_READ); gst_util_dump_mem (info.data, info.size); gst_buffer_unmap (buf, &info); } return buf; }
static GstBuffer * gst_fake_src_create_buffer (GstFakeSrc * src) { GstBuffer *buf; guint size; gboolean dump = src->dump; size = gst_fake_src_get_size (src); if (size == 0) return gst_buffer_new (); switch (src->data) { case FAKE_SRC_DATA_ALLOCATE: buf = gst_fake_src_alloc_buffer (src, size); break; case FAKE_SRC_DATA_SUBBUFFER: /* see if we have a parent to subbuffer */ if (!src->parent) { gst_fake_src_alloc_parent (src); g_assert (src->parent); } /* see if it's large enough */ if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) { buf = gst_buffer_create_sub (src->parent, src->parentoffset, size); src->parentoffset += size; } else { /* the parent is useless now */ gst_buffer_unref (src->parent); src->parent = NULL; /* try again (this will allocate a new parent) */ return gst_fake_src_create_buffer (src); } gst_fake_src_prepare_buffer (src, buf); break; default: g_warning ("fakesrc: dunno how to allocate buffers !"); buf = gst_buffer_new (); break; } if (dump) { gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); } return buf; }