Blame tests/examples/app/appsrc_ex.c

Packit 971217
/* GStreamer
Packit 971217
 *
Packit 971217
 * appsrc_ex.c: example for using appsrc and appsink linked.
Packit 971217
 *
Packit 971217
 * Copyright (C) 2007 David Schleef <ds@schleef.org>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gst/app/gstappsrc.h>
Packit 971217
#include <gst/app/gstappsink.h>
Packit 971217
Packit 971217
#include <stdio.h>
Packit 971217
#include <string.h>
Packit 971217
#include <stdlib.h>
Packit 971217
Packit 971217
Packit 971217
typedef struct _App App;
Packit 971217
struct _App
Packit 971217
{
Packit 971217
  GstElement *pipe;
Packit 971217
  GstElement *src;
Packit 971217
  GstElement *id;
Packit 971217
  GstElement *sink;
Packit 971217
};
Packit 971217
Packit 971217
App s_app;
Packit 971217
Packit 971217
int
Packit 971217
main (int argc, char *argv[])
Packit 971217
{
Packit 971217
  App *app = &s_app;
Packit 971217
  int i;
Packit 971217
Packit 971217
  gst_init (&argc, &argv);
Packit 971217
Packit 971217
  app->pipe = gst_pipeline_new (NULL);
Packit 971217
  g_assert (app->pipe);
Packit 971217
Packit 971217
  app->src = gst_element_factory_make ("appsrc", NULL);
Packit 971217
  g_assert (app->src);
Packit 971217
  gst_bin_add (GST_BIN (app->pipe), app->src);
Packit 971217
Packit 971217
  app->id = gst_element_factory_make ("identity", NULL);
Packit 971217
  g_assert (app->id);
Packit 971217
  gst_bin_add (GST_BIN (app->pipe), app->id);
Packit 971217
Packit 971217
  app->sink = gst_element_factory_make ("appsink", NULL);
Packit 971217
  g_assert (app->sink);
Packit 971217
  gst_bin_add (GST_BIN (app->pipe), app->sink);
Packit 971217
Packit 971217
  gst_element_link (app->src, app->id);
Packit 971217
  gst_element_link (app->id, app->sink);
Packit 971217
Packit 971217
  gst_element_set_state (app->pipe, GST_STATE_PLAYING);
Packit 971217
Packit 971217
  for (i = 0; i < 10; i++) {
Packit 971217
    GstBuffer *buf;
Packit 971217
    GstMapInfo map;
Packit 971217
Packit 971217
    buf = gst_buffer_new_and_alloc (100);
Packit 971217
    gst_buffer_map (buf, &map, GST_MAP_WRITE);
Packit 971217
    memset (map.data, i, 100);
Packit 971217
    gst_buffer_unmap (buf, &map);
Packit 971217
Packit 971217
    printf ("%d: pushing buffer for pointer %p, %p\n", i, map.data, buf);
Packit 971217
    gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
Packit 971217
  }
Packit 971217
Packit 971217
  /* push EOS */
Packit 971217
  gst_app_src_end_of_stream (GST_APP_SRC (app->src));
Packit 971217
Packit 971217
  /* _is_eos() does not block and returns TRUE if there is not currently an EOS
Packit 971217
   * to be retrieved */
Packit 971217
  while (!gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
Packit 971217
    GstSample *sample;
Packit 971217
Packit 971217
    /* pull the next item, this can return NULL when there is no more data and
Packit 971217
     * EOS has been received */
Packit 971217
    sample = gst_app_sink_pull_sample (GST_APP_SINK (app->sink));
Packit 971217
    printf ("retrieved sample %p\n", sample);
Packit 971217
    if (sample)
Packit 971217
      gst_sample_unref (sample);
Packit 971217
  }
Packit 971217
  gst_element_set_state (app->pipe, GST_STATE_NULL);
Packit 971217
Packit 971217
  return 0;
Packit 971217
}