static GstBuffer *
gst_fake_src_alloc_buffer (GstFakeSrc * src, guint size)
{
  GstBuffer *buf;
  gpointer data;
  gboolean do_prepare = FALSE;

  buf = gst_buffer_new ();

  if (size != 0) {
    switch (src->filltype) {
      case FAKE_SRC_FILLTYPE_NOTHING:
        data = g_malloc (size);
        break;
      case FAKE_SRC_FILLTYPE_ZERO:
        data = g_malloc0 (size);
        break;
      case FAKE_SRC_FILLTYPE_RANDOM:
      case FAKE_SRC_FILLTYPE_PATTERN:
      case FAKE_SRC_FILLTYPE_PATTERN_CONT:
      default:
        data = g_malloc (size);
        do_prepare = TRUE;
        break;
    }
    if (do_prepare)
      gst_fake_src_prepare_buffer (src, data, size);

    gst_buffer_append_memory (buf,
        gst_memory_new_wrapped (0, data, size, 0, size, data, g_free));
  }

  return buf;
}
Beispiel #2
0
static GstBuffer *
gst_fake_src_alloc_buffer (GstFakeSrc * src, guint size)
{
  GstBuffer *buf;

  buf = gst_buffer_new ();
  GST_BUFFER_SIZE (buf) = size;

  if (size != 0) {
    switch (src->filltype) {
      case FAKE_SRC_FILLTYPE_NOTHING:
        GST_BUFFER_DATA (buf) = g_malloc (size);
        GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf);
        break;
      case FAKE_SRC_FILLTYPE_ZERO:
        GST_BUFFER_DATA (buf) = g_malloc0 (size);
        GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf);
        break;
      case FAKE_SRC_FILLTYPE_RANDOM:
      case FAKE_SRC_FILLTYPE_PATTERN:
      case FAKE_SRC_FILLTYPE_PATTERN_CONT:
      default:
        GST_BUFFER_DATA (buf) = g_malloc (size);
        GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf);
        gst_fake_src_prepare_buffer (src, buf);
        break;
    }
  }

  return buf;
}
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;
}
Beispiel #4
0
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;
}