mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
examples: add example of intercepting subtitles
Add an example of how to install a custom sink for receiving subtitles in playbin2.
This commit is contained in:
parent
eb7b313369
commit
c1d6745c04
3 changed files with 135 additions and 1 deletions
1
tests/icles/.gitignore
vendored
1
tests/icles/.gitignore
vendored
|
@ -4,3 +4,4 @@ test-textoverlay
|
|||
test-scale
|
||||
test-box
|
||||
test-colorkey
|
||||
playbin-text
|
||||
|
|
|
@ -42,4 +42,8 @@ test_box_SOURCES = test-box.c
|
|||
test_box_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
|
||||
test_box_LDADD = $(GST_LIBS) $(LIBM)
|
||||
|
||||
noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) stress-playbin test-scale test-box
|
||||
playbin_text_SOURCES = playbin-text.c
|
||||
playbin_text_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
|
||||
playbin_text_LDADD = $(GST_LIBS) $(LIBM)
|
||||
|
||||
noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) stress-playbin test-scale test-box playbin-text
|
||||
|
|
129
tests/icles/playbin-text.c
Normal file
129
tests/icles/playbin-text.c
Normal file
|
@ -0,0 +1,129 @@
|
|||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct _App App;
|
||||
|
||||
struct _App
|
||||
{
|
||||
GstElement *playbin;
|
||||
GstElement *textsink;
|
||||
|
||||
GMainLoop *loop;
|
||||
};
|
||||
|
||||
App s_app;
|
||||
|
||||
static gboolean
|
||||
bus_message (GstBus * bus, GstMessage * message, App * app)
|
||||
{
|
||||
GST_DEBUG ("got message %s",
|
||||
gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
|
||||
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
g_error ("received error");
|
||||
g_main_loop_quit (app->loop);
|
||||
break;
|
||||
case GST_MESSAGE_WARNING:
|
||||
g_error ("received error");
|
||||
g_main_loop_quit (app->loop);
|
||||
break;
|
||||
case GST_MESSAGE_EOS:
|
||||
g_main_loop_quit (app->loop);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
have_subtitle (GstElement * fakesink, GstBuffer * buffer,
|
||||
GstPad * pad, App * app)
|
||||
{
|
||||
guint8 *data;
|
||||
guint size;
|
||||
|
||||
g_print ("received a subtitle\n");
|
||||
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
size = GST_BUFFER_SIZE (buffer);
|
||||
|
||||
gst_util_dump_mem (data, size);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
App *app = &s_app;
|
||||
GstBus *bus;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc < 2) {
|
||||
g_print ("usage: %s <filename>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* create a mainloop to get messages */
|
||||
app->loop = g_main_loop_new (NULL, TRUE);
|
||||
|
||||
app->playbin = gst_element_factory_make ("playbin2", NULL);
|
||||
g_assert (app->playbin);
|
||||
|
||||
/* set fakesink to get the subtitles */
|
||||
app->textsink = gst_element_factory_make ("fakesink", "subtitle_sink");
|
||||
g_object_set (G_OBJECT (app->textsink), "signal-handoffs", TRUE, NULL);
|
||||
g_signal_connect (app->textsink, "handoff", G_CALLBACK (have_subtitle), app);
|
||||
g_object_set (G_OBJECT (app->playbin), "text-sink", app->textsink, NULL);
|
||||
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin));
|
||||
|
||||
/* add watch for messages */
|
||||
gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
|
||||
|
||||
/* set to read from appsrc */
|
||||
g_object_set (app->playbin, "uri", argv[1], NULL);
|
||||
|
||||
/* go to playing and wait in a mainloop. */
|
||||
gst_element_set_state (app->playbin, GST_STATE_PLAYING);
|
||||
|
||||
/* this mainloop is stopped when we receive an error or EOS */
|
||||
g_main_loop_run (app->loop);
|
||||
|
||||
GST_DEBUG ("stopping");
|
||||
|
||||
gst_element_set_state (app->playbin, GST_STATE_NULL);
|
||||
|
||||
gst_object_unref (bus);
|
||||
g_main_loop_unref (app->loop);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue