/
gst-backend.c
129 lines (106 loc) · 3.22 KB
/
gst-backend.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (C) 2010 Sreerenj Balachandran.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gst-backend.h"
#include "globals.h"
struct Media *media;
static gboolean handler_message (GstBus *bus, GstMessage *message , gpointer data)
{
switch (GST_MESSAGE_TYPE(message)) {
case GST_MESSAGE_ERROR:
{
GError *err;
gchar *debug;
gst_message_parse_error(message,&err,&debug);
g_print("\n Message:%s\n",err->message);
g_error_free(err);
g_free(debug);
gst_message_unref (message);
gst_object_unref (bus);
}
break;
case GST_MESSAGE_EOS:
g_message("Got end of stream message..");
gst_element_set_state (media->pipeline, GST_STATE_NULL);
break;
default:
/* Unhandled message */
break;
}
return TRUE;
}
void backend_pause()
{
gst_element_set_state(media->pipeline, GST_STATE_PAUSED);
g_message("Paused....");
}
void backend_play()
{
gst_element_set_state(media->pipeline, GST_STATE_PLAYING);
g_message("Playing....");
}
void backend_seek()
{
}
GstBusSyncReply CreateWindow (GstBus *bus,GstMessage *message,gpointer data)
{
if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
return GST_BUS_PASS;
if ( !gst_structure_has_name (message->structure, "prepare-xwindow-id"))
return GST_BUS_PASS;
if (Window_Xid != 0) {
GstXOverlay *xoverlay;
xoverlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
gst_x_overlay_set_xwindow_id (xoverlay, Window_Xid);
} else {
g_warning ("Should have obtained Window_Xid by now!");
}
gst_message_unref (message);
return GST_BUS_DROP;
}
gboolean backend_start (gchar *uri)
{
media->uri = uri;
media->pipeline = gst_element_factory_make ("playbin2", "playbin2");
if (!media->pipeline)
{
g_message("Failed to create the pipeline element,playbin2...!");
return FALSE;
}
g_object_set(G_OBJECT(media->pipeline),"uri",media->uri,NULL);
media->bus = gst_pipeline_get_bus(GST_PIPELINE(media->pipeline));
gst_bus_set_sync_handler (media->bus, (GstBusSyncHandler)CreateWindow, NULL);
gst_bus_add_watch(media->bus, handler_message, NULL);
gst_object_unref (media->bus);
backend_play();
return TRUE;
}
gboolean backend_init (int *argc,char **argv[])
{
gst_init (argc, argv);
media = (struct Media*)malloc(sizeof(Media));
if (media != NULL)
return TRUE;
else
return FALSE;
}
void backend_stop ()
{
gst_element_set_state(media->pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT (media->pipeline));
gst_deinit();
}