static inline GstBuffer * gst_y4m_encode_get_stream_header (GstY4mEncode * filter) { gpointer header; GstBuffer *buf; gchar interlaced; interlaced = 'p'; if (filter->interlaced && filter->top_field_first) interlaced = 't'; else if (filter->interlaced) interlaced = 'b'; header = g_strdup_printf ("YUV4MPEG2 C%s W%d H%d I%c F%d:%d A%d:%d\n", filter->colorspace, filter->width, filter->height, interlaced, filter->fps_num, filter->fps_den, filter->par_num, filter->par_den); buf = gst_buffer_new (); gst_buffer_set_data (buf, header, strlen (header)); /* so it gets free'd when needed */ GST_BUFFER_MALLOCDATA (buf) = header; return buf; }
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; }
GstFlowReturn gst_ebml_read_buffer (GstEbmlRead * ebml, guint32 * id, GstBuffer ** buf) { guint64 length; GstFlowReturn ret; ret = gst_ebml_read_element_id (ebml, id, NULL); if (ret != GST_FLOW_OK) return ret; ret = gst_ebml_read_element_length (ebml, &length, NULL); if (ret != GST_FLOW_OK) return ret; if (length == 0) { *buf = gst_buffer_new (); return GST_FLOW_OK; } *buf = NULL; ret = gst_ebml_read_pull_bytes (ebml, (guint) length, buf, NULL); return ret; }
/* This method is called by the need-data signal callback, we feed data into the * appsrc. */ static void feed_data (GstElement * appsrc, guint size, App * app) { GstBuffer *buffer; guint len; GstFlowReturn ret; buffer = gst_buffer_new (); if (app->offset >= app->length) { /* we are EOS, send end-of-stream */ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); return; } /* read the next chunk */ len = CHUNK_SIZE; if (app->offset + len > app->length) len = app->length - app->offset; GST_BUFFER_DATA (buffer) = app->data + app->offset; GST_BUFFER_SIZE (buffer) = len; GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, len); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); app->offset += len; return; }
static void * run_test (void *user_data) { gint threadid = GPOINTER_TO_INT (user_data); guint64 nb; GstBuffer *buf; GstClockTime start, end; g_mutex_lock (&mutex); g_mutex_unlock (&mutex); start = gst_util_get_timestamp (); g_assert (nbbuffers > 0); for (nb = nbbuffers; nb; nb--) { buf = gst_buffer_new (); gst_buffer_unref (buf); } end = gst_util_get_timestamp (); g_print ("total %" GST_TIME_FORMAT " - average %" GST_TIME_FORMAT " - Thread %d\n", GST_TIME_ARGS (end - start), GST_TIME_ARGS ((end - start) / nbbuffers), threadid); g_thread_exit (NULL); return NULL; }
static GstFlowReturn buffer_alloc(GstBaseSink *base, guint64 offset, guint size, GstCaps *caps, GstBuffer **buf) { struct gst_omapfb_sink *self = (struct gst_omapfb_sink *)base; GstBuffer *buffer; struct page *page; if (!self->enabled && !setup(self, caps)) goto missing; page = get_page(self); if (!page) goto missing; buffer = gst_buffer_new(); GST_BUFFER_DATA(buffer) = page->buf; GST_BUFFER_SIZE(buffer) = size; gst_buffer_set_caps(buffer, caps); *buf = buffer; if (page == self->old_page) ioctl(self->overlay_fd, OMAPFB_WAITFORVSYNC); return GST_FLOW_OK; missing: *buf = NULL; return GST_FLOW_OK; }
gboolean airplayRendererFeedData(GstElement *appsrc, guint size, gpointer *object) { AirplayRenderer *self = AIRPLAY_RENDERER(object); AirplayRendererPrivate *priv = AIRPLAY_RENDERER_GET_PRIVATE(self); g_print("AirplayMediaPlayer: feed data %d\n", priv->seq); AudioPkg *pkg = g_async_queue_try_pop(priv->bufferList); while(pkg == NULL) { if(!priv->isRunning) return FALSE; pkg = g_hash_table_lookup(priv->resendTable, &priv->seq); g_print("Look up: %d %d\n", priv->seq, pkg == NULL); if(pkg) { priv->seq = (priv->seq + 1) % 65536; break; } usleep(50000); sched_yield(); pkg = g_async_queue_try_pop(priv->bufferList); g_print("Sleep: %d\n", priv->seq); } GstBuffer *buffer = gst_buffer_new(); gst_buffer_set_data(buffer, pkg->data, pkg->length); GST_BUFFER_SIZE(buffer) = pkg->length; GST_BUFFER_MALLOCDATA(buffer) = pkg->data; GST_BUFFER_DATA(buffer) = GST_BUFFER_MALLOCDATA(buffer); gst_app_src_push_buffer((GstAppSrc *)appsrc, buffer); g_free(pkg); // gst_buffer_unref(buffer); return TRUE; }
static GstCaps * typefind_test_file (const gchar * filename) { GstBuffer *buf; GError *err = NULL; GstCaps *caps = NULL; gchar *path, *data = NULL; gsize data_len; path = g_build_filename (GST_TEST_FILES_PATH, filename, NULL); GST_LOG ("reading file '%s'", path); if (!g_file_get_contents (path, &data, &data_len, &err)) { g_error ("error loading test file: %s", err->message); } buf = gst_buffer_new (); gst_buffer_append_memory (buf, gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, (gpointer) data, data_len, 0, data_len, NULL, NULL)); GST_BUFFER_OFFSET (buf) = 0; caps = gst_type_find_helper_for_buffer (NULL, buf, NULL); fail_unless (caps != NULL); GST_LOG ("Found type: %" GST_PTR_FORMAT, caps); gst_buffer_unref (buf); g_free (data); g_free (path); return caps; }
static GstFlowReturn gst_wayland_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, GstBufferPoolAcquireParams * params) { GstWaylandBufferPool *self = GST_WAYLAND_BUFFER_POOL_CAST (pool); gint width, height, stride; gsize size; enum wl_shm_format format; gint offset; void *data; GstWlMeta *meta; width = GST_VIDEO_INFO_WIDTH (&self->info); height = GST_VIDEO_INFO_HEIGHT (&self->info); stride = GST_VIDEO_INFO_PLANE_STRIDE (&self->info, 0); size = GST_VIDEO_INFO_SIZE (&self->info); format = gst_video_format_to_wayland_format (GST_VIDEO_INFO_FORMAT (&self->info)); GST_DEBUG_OBJECT (self, "Allocating buffer of size %" G_GSSIZE_FORMAT " (%d x %d, stride %d), format %s", size, width, height, stride, gst_wayland_format_to_string (format)); /* try to reserve another memory block from the shm pool */ if (self->used + size > self->size) goto no_buffer; offset = self->used; self->used += size; data = ((gchar *) self->data) + offset; /* create buffer and its metadata object */ *buffer = gst_buffer_new (); meta = (GstWlMeta *) gst_buffer_add_meta (*buffer, GST_WL_META_INFO, NULL); meta->pool = self; meta->wbuffer = wl_shm_pool_create_buffer (self->wl_pool, offset, width, height, stride, format); meta->used_by_compositor = FALSE; /* configure listening to wl_buffer.release */ g_mutex_lock (&self->buffers_map_mutex); g_hash_table_insert (self->buffers_map, meta->wbuffer, *buffer); g_mutex_unlock (&self->buffers_map_mutex); wl_buffer_add_listener (meta->wbuffer, &buffer_listener, self); /* add the allocated memory on the GstBuffer */ gst_buffer_append_memory (*buffer, gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data, size, 0, size, NULL, NULL)); return GST_FLOW_OK; /* ERROR */ no_buffer: { GST_WARNING_OBJECT (pool, "can't create buffer"); return GST_FLOW_ERROR; } }
/** * gst_buffer_try_new_and_alloc: * @size: the size of the new buffer's data. * * Tries to create a newly allocated buffer with data of the given size. If * the requested amount of memory can't be allocated, NULL will be returned. * The buffer memory is not cleared. * * Note that when @size == 0, the buffer data pointer will be NULL. * * MT safe. * * Returns: a new #GstBuffer, or NULL if the memory couldn't be allocated. * * Since: 0.10.13 */ GstBuffer * gst_buffer_try_new_and_alloc (guint size) { GstBuffer *newbuf; guint8 *malloc_data; malloc_data = g_try_malloc (size); if (G_UNLIKELY (malloc_data == NULL && size != 0)) { GST_CAT_WARNING (GST_CAT_BUFFER, "failed to allocate %d bytes", size); return NULL; } /* FIXME: there's no g_type_try_create_instance() in GObject yet, so this * will still abort if a new GstBuffer structure can't be allocated */ newbuf = gst_buffer_new (); GST_BUFFER_MALLOCDATA (newbuf) = malloc_data; GST_BUFFER_DATA (newbuf) = malloc_data; GST_BUFFER_SIZE (newbuf) = size; GST_CAT_LOG (GST_CAT_BUFFER, "new %p of size %d", newbuf, size); return newbuf; }
static void lose_and_recover_test (GstHarness * h, guint16 lost_seq, gconstpointer recbuf, gsize recbuf_size) { guint64 duration = 222222; guint64 timestamp = 111111; GstBuffer *bufout; push_lost_event (h, lost_seq, timestamp, duration, FALSE); bufout = gst_harness_pull (h); fail_unless_equals_int (gst_buffer_get_size (bufout), recbuf_size); fail_unless_equals_int (GST_BUFFER_PTS (bufout), timestamp); fail_unless (gst_buffer_memcmp (bufout, 0, recbuf, recbuf_size) == 0); fail_unless (!GST_BUFFER_FLAG_IS_SET (bufout, GST_RTP_BUFFER_FLAG_REDUNDANT)); gst_buffer_unref (bufout); /* Pushing the next buffer with discont flag set */ bufout = gst_buffer_new (); GST_BUFFER_FLAG_SET (bufout, GST_BUFFER_FLAG_DISCONT); bufout = gst_harness_push_and_pull (h, bufout); /* Checking the flag was unset */ fail_unless (!GST_BUFFER_IS_DISCONT (bufout)); gst_buffer_unref (bufout); }
/** * gst_buffer_new_and_alloc: * @size: the size of the new buffer's data. * * Creates a newly allocated buffer with data of the given size. * The buffer memory is not cleared. If the requested amount of * memory can't be allocated, the program will abort. Use * gst_buffer_try_new_and_alloc() if you want to handle this case * gracefully or have gotten the size to allocate from an untrusted * source such as a media stream. * * * Note that when @size == 0, the buffer data pointer will be NULL. * * MT safe. * Returns: the new #GstBuffer. */ GstBuffer * gst_buffer_new_and_alloc (guint size) { GstBuffer *newbuf; newbuf = gst_buffer_new (); #ifdef HAVE_POSIX_MEMALIGN { gpointer memptr = NULL; if (G_LIKELY (size)) { if (G_UNLIKELY (!aligned_malloc (&memptr, size))) { /* terminate on error like g_memdup() would */ g_error ("%s: failed to allocate %u bytes", G_STRLOC, size); } } newbuf->malloc_data = (guint8 *) memptr; GST_BUFFER_FREE_FUNC (newbuf) = free; } #else newbuf->malloc_data = g_malloc (size); #endif GST_BUFFER_DATA (newbuf) = newbuf->malloc_data; GST_BUFFER_SIZE (newbuf) = size; GST_CAT_LOG (GST_CAT_BUFFER, "new %p of size %d", newbuf, size); return newbuf; }
static inline void extract_and_queue_tags (GstJpegParse * parse, guint size, guint8 * data, GstTagList * (*tag_func) (const GstBuffer * buff)) { GstTagList *tags; GstBuffer *buf; buf = gst_buffer_new (); GST_BUFFER_DATA (buf) = data; GST_BUFFER_SIZE (buf) = size; tags = tag_func (buf); gst_buffer_unref (buf); if (tags) { GstTagList *taglist = parse->priv->tags; if (taglist) { gst_tag_list_insert (taglist, tags, GST_TAG_MERGE_REPLACE); gst_tag_list_free (tags); } else { parse->priv->tags = tags; } GST_DEBUG_OBJECT (parse, "collected tags: %" GST_PTR_FORMAT, parse->priv->tags); } }
static inline GstBuffer * gst_y4m_encode_get_stream_header (GstY4mEncode * filter, gboolean tff) { gpointer header; GstBuffer *buf; gchar interlaced; gsize len; if (GST_VIDEO_INFO_IS_INTERLACED (&filter->info)) { if (tff) interlaced = 't'; else interlaced = 'b'; } else { interlaced = 'p'; } header = g_strdup_printf ("YUV4MPEG2 C%s W%d H%d I%c F%d:%d A%d:%d\n", filter->colorspace, GST_VIDEO_INFO_WIDTH (&filter->info), GST_VIDEO_INFO_HEIGHT (&filter->info), interlaced, GST_VIDEO_INFO_FPS_N (&filter->info), GST_VIDEO_INFO_FPS_D (&filter->info), GST_VIDEO_INFO_PAR_N (&filter->info), GST_VIDEO_INFO_PAR_D (&filter->info)); len = strlen (header); buf = gst_buffer_new (); gst_buffer_append_memory (buf, gst_memory_new_wrapped (0, header, len, 0, len, header, g_free)); return buf; }
/* This method is called by the need-data signal callback, we feed data into the * appsrc with the requested size. */ static void feed_data (GstElement * appsrc, guint size, App * app) { GstBuffer *buffer; GstFlowReturn ret; if (app->offset >= app->length) { /* we are EOS, send end-of-stream */ g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); return; } /* read the amount of data, we are allowed to return less if we are EOS */ buffer = gst_buffer_new (); if (app->offset + size > app->length) size = app->length - app->offset; gst_buffer_append_memory (buffer, gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, app->data, app->length, app->offset, size, NULL, NULL)); /* we need to set an offset for random access */ GST_BUFFER_OFFSET (buffer) = app->offset; GST_BUFFER_OFFSET_END (buffer) = app->offset + size; GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, app->offset, size); g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); gst_buffer_unref (buffer); app->offset += size; return; }
/* FIXME */ static GstBuffer * gst_sdlvideosink_buffer_new (GstBufferPool * pool, gint64 location, guint size, gpointer user_data) { GstSDLVideoSink *sdlvideosink = GST_SDLVIDEOSINK (user_data); GstBuffer *buffer; if (!sdlvideosink->overlay) return NULL; if (!gst_sdlvideosink_lock (sdlvideosink)) { return NULL; } /* this protects the buffer from being written over multiple times */ g_mutex_lock (sdlvideosink->lock); buffer = gst_buffer_new (); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_DONTFREE); GST_BUFFER_DATA (buffer) = sdlvideosink->overlay->pixels[0]; if (sdlvideosink->format == SDL_YV12_OVERLAY || sdlvideosink->format == SDL_IYUV_OVERLAY) { GST_BUFFER_SIZE (buffer) = sdlvideosink->width * sdlvideosink->height * 3 / 2; } else { GST_BUFFER_SIZE (buffer) = sdlvideosink->width * sdlvideosink->height * 2; } GST_BUFFER_MAXSIZE (buffer) = GST_BUFFER_SIZE (buffer); return buffer; }
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; }
static GstFlowReturn wayland_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, GstBufferPoolAcquireParams * params) { GstWaylandBufferPool *w_pool = GST_WAYLAND_BUFFER_POOL_CAST (pool); GstBuffer *w_buffer; GstWlMeta *meta; w_buffer = gst_buffer_new (); meta = gst_buffer_add_wayland_meta (w_buffer, w_pool); if (meta == NULL) { gst_buffer_unref (w_buffer); goto no_buffer; } *buffer = w_buffer; return GST_FLOW_OK; /* ERROR */ no_buffer: { GST_WARNING_OBJECT (pool, "can't create buffer"); return GST_FLOW_ERROR; } }
static void gst_gme_play (GstPad * pad) { GstGmeDec *gme = GST_GME_DEC (gst_pad_get_parent (pad)); GstFlowReturn flow_return; GstBuffer *out; gboolean seeking = gme->seeking; gme_err_t gme_err = NULL; const int NUM_SAMPLES = 1600; /* 4 bytes (stereo 16-bit) per sample */ if (!seeking) { GstMapInfo map; out = gst_buffer_new_and_alloc (NUM_SAMPLES * 4); GST_BUFFER_TIMESTAMP (out) = gme_tell (gme->player) * GST_MSECOND; gst_buffer_map (out, &map, GST_MAP_WRITE); gme_err = gme_play (gme->player, NUM_SAMPLES * 2, (short *) map.data); gst_buffer_unmap (out, &map); if (gme_err) { GST_ELEMENT_ERROR (gme, STREAM, DEMUX, (NULL), ("%s", gme_err)); gst_pad_pause_task (pad); gst_pad_push_event (pad, gst_event_new_eos ()); gst_object_unref (gme); return; } } else { gme_seek (gme->player, gme->seekpoint); gme->seeking = FALSE; out = gst_buffer_new (); } if ((flow_return = gst_pad_push (gme->srcpad, out)) != GST_FLOW_OK) { GST_DEBUG_OBJECT (gme, "pausing task, reason %s", gst_flow_get_name (flow_return)); gst_pad_pause_task (pad); if (flow_return == GST_FLOW_EOS) { gst_pad_push_event (pad, gst_event_new_eos ()); } else if (flow_return < GST_FLOW_EOS || flow_return == GST_FLOW_NOT_LINKED) { GST_ELEMENT_ERROR (gme, STREAM, FAILED, ("Internal data stream error."), ("stream stopped, reason %s", gst_flow_get_name (flow_return))); gst_pad_push_event (pad, gst_event_new_eos ()); } } if (gme_tell (gme->player) * GST_MSECOND > gme->total_duration) { gst_pad_pause_task (pad); gst_pad_push_event (pad, gst_event_new_eos ()); } gst_object_unref (gme); return; }
/** * gst_adapter_take_buffer: * @adapter: a #GstAdapter * @nbytes: the number of bytes to take * * Returns a #GstBuffer containing the first @nbytes bytes of the * @adapter. The returned bytes will be flushed from the adapter. * This function is potentially more performant than gst_adapter_take() * since it can reuse the memory in pushed buffers by subbuffering * or merging. * * Caller owns returned value. gst_buffer_unref() after usage. * * Since: 0.10.6 * * Returns: a #GstBuffer containing the first @nbytes of the adapter, * or #NULL if @nbytes bytes are not available */ GstBuffer * gst_adapter_take_buffer (GstAdapter * adapter, guint nbytes) { GstBuffer *buffer; GstBuffer *cur; guint hsize, skip; guint8 *data; g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL); g_return_val_if_fail (nbytes > 0, NULL); GST_LOG_OBJECT (adapter, "taking buffer of %u bytes", nbytes); /* we don't have enough data, return NULL. This is unlikely * as one usually does an _available() first instead of grabbing a * random size. */ if (G_UNLIKELY (nbytes > adapter->size)) return NULL; cur = adapter->buflist->data; skip = adapter->skip; hsize = GST_BUFFER_SIZE (cur); /* our head buffer has enough data left, return it */ if (skip == 0 && hsize == nbytes) { GST_LOG_OBJECT (adapter, "providing buffer of %d bytes as head buffer", nbytes); buffer = gst_buffer_ref (cur); goto done; } else if (hsize >= nbytes + skip) { GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", nbytes); buffer = gst_buffer_create_sub (cur, skip, nbytes); goto done; } if (gst_adapter_try_to_merge_up (adapter, nbytes)) { /* Merged something, let's try again for sub-buffering */ cur = adapter->buflist->data; if (GST_BUFFER_SIZE (cur) >= nbytes + skip) { GST_LOG_OBJECT (adapter, "providing buffer of %d bytes via sub-buffer", nbytes); buffer = gst_buffer_create_sub (cur, skip, nbytes); goto done; } } data = gst_adapter_take_internal (adapter, nbytes); buffer = gst_buffer_new (); GST_BUFFER_SIZE (buffer) = nbytes; GST_BUFFER_DATA (buffer) = data; GST_BUFFER_MALLOCDATA (buffer) = data; done: gst_adapter_flush_unchecked (adapter, nbytes); return buffer; }
/* * Runs the RTP pipeline. * @param p Pointer to the RTP pipeline. */ static void rtp_pipeline_run (rtp_pipeline * p) { GstFlowReturn flow_ret; GMainLoop *mainloop = NULL; GstBus *bus; gint i, j; /* Check parameters. */ if (p == NULL) { return; } /* Create mainloop. */ mainloop = g_main_loop_new (NULL, FALSE); if (!mainloop) { return; } /* Add bus callback. */ bus = gst_pipeline_get_bus (GST_PIPELINE (p->pipeline)); gst_bus_add_watch (bus, rtp_bus_callback, (gpointer) mainloop); gst_object_unref (bus); /* Set pipeline to PLAYING. */ gst_element_set_state (p->pipeline, GST_STATE_PLAYING); /* Push data into the pipeline */ for (i = 0; i < LOOP_COUNT; i++) { const guint8 *data = p->frame_data; for (j = 0; j < p->frame_count; j++) { GstBuffer *buf; buf = gst_buffer_new (); GST_BUFFER_DATA (buf) = (guint8 *) data; GST_BUFFER_SIZE (buf) = p->frame_data_size; GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); g_signal_emit_by_name (p->appsrc, "push-buffer", buf, &flow_ret); fail_unless_equals_int (flow_ret, GST_FLOW_OK); data += p->frame_data_size; gst_buffer_unref (buf); } } g_signal_emit_by_name (p->appsrc, "end-of-stream", &flow_ret); /* Run mainloop. */ g_main_loop_run (mainloop); /* Set pipeline to NULL. */ gst_element_set_state (p->pipeline, GST_STATE_NULL); /* Release mainloop. */ g_main_loop_unref (mainloop); }
static gpointer thread_push_buffer (gpointer data) { GstPad *pad = data; gst_pad_push (pad, gst_buffer_new ()); return NULL; }
static GstBuffer * create_timestamp_buffer (GstClockTime timestamp) { GstBuffer * buf = gst_buffer_new (); GST_BUFFER_PTS (buf) = timestamp; GST_BUFFER_DTS (buf) = timestamp; return buf; }
static void gst_tarkinenc_setup (TarkinEnc * tarkinenc) { gint i; GstBuffer *outbuf; ogg_stream_init (&tarkinenc->os, 1); tarkin_info_init (&tarkinenc->ti); tarkinenc->ti.inter.numerator = 1; tarkinenc->ti.inter.denominator = 1; tarkin_comment_init (&tarkinenc->tc); tarkin_comment_add_tag (&tarkinenc->tc, "TITLE", "GStreamer produced file"); tarkin_comment_add_tag (&tarkinenc->tc, "ARTIST", "C coders ;)"); tarkinenc->tarkin_stream = tarkin_stream_new (); tarkin_analysis_init (tarkinenc->tarkin_stream, &tarkinenc->ti, free_frame, packet_out, (void *) tarkinenc); tarkin_analysis_add_layer (tarkinenc->tarkin_stream, &tarkinenc->layer[0]); tarkin_analysis_headerout (tarkinenc->tarkin_stream, &tarkinenc->tc, tarkinenc->op, &tarkinenc->op[1], &tarkinenc->op[2]); for (i = 0; i < 3; i++) { ogg_stream_packetin (&tarkinenc->os, &tarkinenc->op[i]); } ogg_stream_flush (&tarkinenc->os, &tarkinenc->og); tarkinenc->frame_num = 0; outbuf = gst_buffer_new (); GST_BUFFER_DATA (outbuf) = tarkinenc->og.header; GST_BUFFER_SIZE (outbuf) = tarkinenc->og.header_len; GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_DONTFREE); gst_pad_push (tarkinenc->srcpad, GST_DATA (outbuf)); outbuf = gst_buffer_new (); GST_BUFFER_DATA (outbuf) = tarkinenc->og.body; GST_BUFFER_SIZE (outbuf) = tarkinenc->og.body_len; GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_DONTFREE); gst_pad_push (tarkinenc->srcpad, GST_DATA (outbuf)); tarkinenc->setup = TRUE; }
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; }
/* This function handles GstBuffer creation */ static GstFlowReturn gst_gl_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer, GstBufferPoolAcquireParams * params) { GstGLMemoryAllocator *alloc; GstGLBufferPool *glpool = GST_GL_BUFFER_POOL_CAST (pool); GstGLBufferPoolPrivate *priv = glpool->priv; GstBuffer *buf; if (!(buf = gst_buffer_new ())) { goto no_buffer; } #if GST_GL_HAVE_PLATFORM_EGL if (priv->want_eglimage) { /* alloc and append memories, also add video_meta and * texture_upload_meta */ if (!gst_egl_image_memory_setup_buffer (glpool->context, priv->gl_params->v_info, buf)) goto egl_image_mem_create_failed; *buffer = buf; return GST_FLOW_OK; } #endif alloc = GST_GL_MEMORY_ALLOCATOR (priv->allocator); if (!gst_gl_memory_setup_buffer (alloc, buf, priv->gl_params)) goto mem_create_failed; if (priv->add_glsyncmeta) gst_buffer_add_gl_sync_meta (glpool->context, buf); *buffer = buf; return GST_FLOW_OK; /* ERROR */ no_buffer: { GST_WARNING_OBJECT (pool, "can't create image"); return GST_FLOW_ERROR; } mem_create_failed: { GST_WARNING_OBJECT (pool, "Could not create GL Memory"); return GST_FLOW_ERROR; } #if GST_GL_HAVE_PLATFORM_EGL egl_image_mem_create_failed: { GST_WARNING_OBJECT (pool, "Could not create EGLImage Memory"); return GST_FLOW_ERROR; } #endif }
GstBuffer * gst_core_media_buffer_new (CMSampleBufferRef sample_buf, gboolean use_video_meta, GstVideoTextureCache * cache) { CVImageBufferRef image_buf; CMBlockBufferRef block_buf; GstBuffer *buf; image_buf = CMSampleBufferGetImageBuffer (sample_buf); block_buf = CMSampleBufferGetDataBuffer (sample_buf); buf = gst_buffer_new (); gst_core_media_meta_add (buf, sample_buf, image_buf, block_buf); if (image_buf != NULL && CFGetTypeID (image_buf) == CVPixelBufferGetTypeID () && cache) { GstVideoInfo info; gboolean has_padding = FALSE; CVPixelBufferRef pixel_buf = (CVPixelBufferRef) image_buf; if (!gst_video_info_init_from_pixel_buffer (&info, pixel_buf)) { goto error; } gst_core_video_wrap_pixel_buffer (buf, &info, pixel_buf, cache, &has_padding); /* If the video meta API is not supported, remove padding by * copying the core media buffer to a system memory buffer */ if (has_padding && !use_video_meta) { GstBuffer *copy_buf; copy_buf = gst_core_media_buffer_new_from_buffer (buf, &info); if (!copy_buf) { goto error; } gst_buffer_unref (buf); buf = copy_buf; } } else if (block_buf != NULL) { if (!gst_core_media_buffer_wrap_block_buffer (buf, block_buf)) { goto error; } } else { goto error; } return buf; error: if (buf) { gst_buffer_unref (buf); } return NULL; }
static void write_metadata (GstWavEnc * wavenc) { GString *info_str; GList *props; int total = 4; gboolean need_to_write = FALSE; info_str = g_string_new ("LIST INFO"); for (props = wavenc->metadata->properties->properties; props; props = props->next) { GstPropsEntry *entry = props->data; const char *name; guint32 id; name = gst_props_entry_get_name (entry); id = get_id_from_name (name); if (id != 0) { const char *text; char *tmp; int len, req, i; need_to_write = TRUE; /* We've got at least one entry */ gst_props_entry_get_string (entry, &text); len = strlen (text) + 1; /* The length in the file includes the \0 */ tmp = g_strdup_printf ("%" GST_FOURCC_FORMAT "%d%s", GST_FOURCC_ARGS (id), GUINT32_TO_LE (len), text); g_string_append (info_str, tmp); g_free (tmp); /* Check that we end on an even boundary */ req = ((len + 8) + 1) & ~1; for (i = 0; i < req - len; i++) { g_string_append_printf (info_str, "%c", 0); } total += req; } } if (need_to_write) { GstBuffer *buf; /* Now we've got all the strings together, we can write our length in */ info_str->str[4] = GUINT32_TO_LE (total); buf = gst_buffer_new (); gst_buffer_set_data (buf, info_str->str, info_str->len); gst_pad_push (wavenc->srcpad, GST_DATA (buf)); g_string_free (info_str, FALSE); } }
static void gst_rfc2250_enc_new_buffer (GstRFC2250Enc * enc) { if (enc->packet) { gst_pad_push (enc->srcpad, GST_DATA (enc->packet)); } enc->packet = gst_buffer_new (); enc->flags = 0; enc->remaining = enc->MTU; }
static GstFlowReturn oob_source_create (GstPushSrc * src, GstBuffer ** p_buf) { *p_buf = gst_buffer_new (); gst_pad_push_event (GST_BASE_SRC_PAD (src), gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, NULL)); return GST_FLOW_OK; }