mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-03 04:52:28 +00:00
example: use appsink instead of fakesink
Use appsink instead of fakesink to get the subtitles. Make things more pretty.
This commit is contained in:
parent
c1d6745c04
commit
e8a9b98819
1 changed files with 23 additions and 13 deletions
|
@ -56,6 +56,7 @@ bus_message (GstBus * bus, GstMessage * message, App * app)
|
||||||
g_main_loop_quit (app->loop);
|
g_main_loop_quit (app->loop);
|
||||||
break;
|
break;
|
||||||
case GST_MESSAGE_EOS:
|
case GST_MESSAGE_EOS:
|
||||||
|
g_message ("received EOS");
|
||||||
g_main_loop_quit (app->loop);
|
g_main_loop_quit (app->loop);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -65,18 +66,25 @@ bus_message (GstBus * bus, GstMessage * message, App * app)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
have_subtitle (GstElement * fakesink, GstBuffer * buffer,
|
have_subtitle (GstElement * appsink, App * app)
|
||||||
GstPad * pad, App * app)
|
|
||||||
{
|
{
|
||||||
|
GstBuffer *buffer;
|
||||||
|
|
||||||
|
/* get the buffer, we can also wakeup the mainloop to get the subtitle from
|
||||||
|
* appsink in the mainloop */
|
||||||
|
g_signal_emit_by_name (appsink, "pull-buffer", &buffer);
|
||||||
|
|
||||||
|
if (buffer) {
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
guint size;
|
guint size;
|
||||||
|
|
||||||
g_print ("received a subtitle\n");
|
g_message ("received a subtitle");
|
||||||
|
|
||||||
data = GST_BUFFER_DATA (buffer);
|
data = GST_BUFFER_DATA (buffer);
|
||||||
size = GST_BUFFER_SIZE (buffer);
|
size = GST_BUFFER_SIZE (buffer);
|
||||||
|
|
||||||
gst_util_dump_mem (data, size);
|
gst_util_dump_mem (data, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -98,10 +106,12 @@ main (int argc, char *argv[])
|
||||||
app->playbin = gst_element_factory_make ("playbin2", NULL);
|
app->playbin = gst_element_factory_make ("playbin2", NULL);
|
||||||
g_assert (app->playbin);
|
g_assert (app->playbin);
|
||||||
|
|
||||||
/* set fakesink to get the subtitles */
|
/* set appsink to get the subtitles */
|
||||||
app->textsink = gst_element_factory_make ("fakesink", "subtitle_sink");
|
app->textsink = gst_element_factory_make ("appsink", "subtitle_sink");
|
||||||
g_object_set (G_OBJECT (app->textsink), "signal-handoffs", TRUE, NULL);
|
g_object_set (G_OBJECT (app->textsink), "emit-signals", TRUE, NULL);
|
||||||
g_signal_connect (app->textsink, "handoff", G_CALLBACK (have_subtitle), app);
|
g_signal_connect (app->textsink, "new-buffer", G_CALLBACK (have_subtitle),
|
||||||
|
app);
|
||||||
|
|
||||||
g_object_set (G_OBJECT (app->playbin), "text-sink", app->textsink, NULL);
|
g_object_set (G_OBJECT (app->playbin), "text-sink", app->textsink, NULL);
|
||||||
|
|
||||||
bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
|
bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
|
||||||
|
@ -118,7 +128,7 @@ main (int argc, char *argv[])
|
||||||
/* this mainloop is stopped when we receive an error or EOS */
|
/* this mainloop is stopped when we receive an error or EOS */
|
||||||
g_main_loop_run (app->loop);
|
g_main_loop_run (app->loop);
|
||||||
|
|
||||||
GST_DEBUG ("stopping");
|
g_message ("stopping");
|
||||||
|
|
||||||
gst_element_set_state (app->playbin, GST_STATE_NULL);
|
gst_element_set_state (app->playbin, GST_STATE_NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue