2007-03-11 00:48:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/app/gstappsrc.h>
|
|
|
|
#include <gst/app/gstappsink.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-07-18 07:35:32 +00:00
|
|
|
#include <stdlib.h>
|
2007-03-11 00:48:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct _App App;
|
|
|
|
struct _App
|
|
|
|
{
|
|
|
|
GstElement *pipe;
|
|
|
|
GstElement *src;
|
|
|
|
GstElement *id;
|
|
|
|
GstElement *sink;
|
|
|
|
};
|
|
|
|
|
|
|
|
App s_app;
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
App *app = &s_app;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
|
|
|
app->pipe = gst_pipeline_new (NULL);
|
|
|
|
g_assert (app->pipe);
|
|
|
|
|
|
|
|
app->src = gst_element_factory_make ("appsrc", NULL);
|
|
|
|
g_assert (app->src);
|
|
|
|
gst_bin_add (GST_BIN (app->pipe), app->src);
|
|
|
|
|
|
|
|
app->id = gst_element_factory_make ("identity", NULL);
|
|
|
|
g_assert (app->id);
|
|
|
|
gst_bin_add (GST_BIN (app->pipe), app->id);
|
|
|
|
|
|
|
|
app->sink = gst_element_factory_make ("appsink", NULL);
|
|
|
|
g_assert (app->sink);
|
|
|
|
gst_bin_add (GST_BIN (app->pipe), app->sink);
|
|
|
|
|
|
|
|
gst_element_link (app->src, app->id);
|
|
|
|
gst_element_link (app->id, app->sink);
|
|
|
|
|
|
|
|
gst_element_set_state (app->pipe, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
GstBuffer *buf;
|
|
|
|
void *data;
|
|
|
|
|
2011-02-24 11:19:27 +00:00
|
|
|
buf = gst_buffer_new_and_alloc (100);
|
2011-03-28 12:12:24 +00:00
|
|
|
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
2007-03-11 00:48:26 +00:00
|
|
|
memset (data, i, 100);
|
2011-03-28 12:12:24 +00:00
|
|
|
gst_buffer_unmap (buf, data, 100);
|
2007-03-11 00:48:26 +00:00
|
|
|
|
2011-02-24 11:19:27 +00:00
|
|
|
printf ("%d: pushing buffer for pointer %p, %p\n", i, data, buf);
|
2007-03-11 00:48:26 +00:00
|
|
|
gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
|
|
|
|
}
|
|
|
|
|
2009-01-06 10:50:37 +00:00
|
|
|
/* push EOS */
|
2007-03-11 00:48:26 +00:00
|
|
|
gst_app_src_end_of_stream (GST_APP_SRC (app->src));
|
|
|
|
|
2009-01-06 10:50:37 +00:00
|
|
|
/* _is_eos() does not block and returns TRUE if there is not currently an EOS
|
|
|
|
* to be retrieved */
|
2007-09-20 17:38:10 +00:00
|
|
|
while (!gst_app_sink_is_eos (GST_APP_SINK (app->sink))) {
|
2011-12-01 15:48:49 +00:00
|
|
|
GstSample *sample;
|
2007-03-11 00:48:26 +00:00
|
|
|
|
2009-01-06 10:50:37 +00:00
|
|
|
/* pull the next item, this can return NULL when there is no more data and
|
|
|
|
* EOS has been received */
|
2011-12-01 15:48:49 +00:00
|
|
|
sample = gst_app_sink_pull_sample (GST_APP_SINK (app->sink));
|
|
|
|
printf ("retrieved sample %p\n", sample);
|
|
|
|
if (sample)
|
|
|
|
gst_sample_unref (sample);
|
2007-03-11 00:48:26 +00:00
|
|
|
}
|
examples/app/: Added an example on how to use appsrc in playbin in streaming mode from an mmapped file.
Original commit message from CVS:
* examples/app/.cvsignore:
* examples/app/Makefile.am:
* examples/app/appsrc-stream.c: (read_data), (start_feed),
(stop_feed), (found_source), (bus_message), (main):
Added an example on how to use appsrc in playbin in streaming mode from
an mmapped file.
* examples/app/appsrc_ex.c: (main):
Set pipeline to NULL to free queued buffers.
* gst-libs/gst/app/gstapp-marshal.list:
* gst-libs/gst/app/gstappsrc.c: (stream_type_get_type), (_do_init),
(gst_app_src_class_init), (gst_app_src_init),
(gst_app_src_flush_queued), (gst_app_src_dispose),
(gst_app_src_set_property), (gst_app_src_get_property),
(gst_app_src_unlock), (gst_app_src_unlock_stop),
(gst_app_src_start), (gst_app_src_stop), (gst_app_src_is_seekable),
(gst_app_src_check_get_range), (gst_app_src_do_seek),
(gst_app_src_create), (gst_app_src_set_stream_type),
(gst_app_src_get_stream_type), (gst_app_src_set_max_bytes),
(gst_app_src_get_max_bytes), (gst_app_src_push_buffer),
(gst_app_src_end_of_stream), (gst_app_src_uri_get_type),
(gst_app_src_uri_get_protocols), (gst_app_src_uri_get_uri),
(gst_app_src_uri_set_uri), (gst_app_src_uri_handler_init):
* gst-libs/gst/app/gstappsrc.h:
Measure max queue size in bytes instead.
Add support for 3 modes of operation, streaming, seekable and
random-access, making basesrc handle the scheduling modes for each.
Add appsrc:// uri handler so that automatic plugging can be done from
playbin2 or uridecodebin, for example.
Added support for custom segment formats.
Add support for push and pull based operations from the application.
Expand the methods so that errors can be detected.
Flush the queued buffers on seeks and when shutting down.
Add signals to inform the app that a seek must happen.
2008-06-05 16:38:50 +00:00
|
|
|
gst_element_set_state (app->pipe, GST_STATE_NULL);
|
2007-03-11 00:48:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|