leo_sobral@2
|
1 |
/* GStreamer MythTV Plug-in
|
leo_sobral@2
|
2 |
* Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
|
leo_sobral@2
|
3 |
*
|
leo_sobral@2
|
4 |
* This library is free software; you can redistribute it and/or
|
rosfran@289
|
5 |
* modify it under the terms of the GNU Library General Public
|
rosfran@289
|
6 |
* License as published by the Free Software Foundation; either
|
leo_sobral@2
|
7 |
* version 2 of the License, or (at your option) any later version.
|
leo_sobral@2
|
8 |
*
|
leo_sobral@2
|
9 |
* This library is distributed in the hope that it will be useful,
|
leo_sobral@2
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
leo_sobral@2
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
rosfran@289
|
12 |
* Library General Public License for more details.
|
rosfran@289
|
13 |
*
|
rosfran@289
|
14 |
* You should have received a copy of the GNU Library General Public
|
rosfran@289
|
15 |
* License along with this library; if not, write to the
|
rosfran@289
|
16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
rosfran@289
|
17 |
* Boston, MA 02111-1307, USA.
|
leo_sobral@2
|
18 |
*/
|
rosfran@289
|
19 |
/**
|
rosfran@371
|
20 |
* If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder,
|
rosfran@371
|
21 |
* Recorder),
|
rosfran@371
|
22 |
* put the following URI:
|
rosfran@289
|
23 |
*
|
rosfran@371
|
24 |
* myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
|
rosfran@371
|
25 |
*
|
rosfran@371
|
26 |
* This URI will say to the gmyth library to configure the Recorder instance (used to
|
rosfran@371
|
27 |
* change the channel, start the TV multimedia content transmition, etc.), using
|
rosfran@371
|
28 |
* the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
|
rosfran@371
|
29 |
* server, and setting the channel name to "BBC".
|
rosfran@371
|
30 |
*
|
rosfran@371
|
31 |
* To get a already recorded the MythTV NUV file, put the following URI:
|
rosfran@371
|
32 |
*
|
rosfran@371
|
33 |
* myth://xxx.xxx.xxx.xxx:6543/filename.nuv
|
rosfran@371
|
34 |
*
|
rosfran@371
|
35 |
* This URI will say to the gmyth library to configure the Recorder instance (used to
|
rosfran@371
|
36 |
* change the channel, start the TV multimedia content transmition, etc.), using
|
rosfran@371
|
37 |
* the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
|
rosfran@371
|
38 |
* server, and setting the channel name to "BBC".
|
rosfran@371
|
39 |
*
|
rosfran@371
|
40 |
* Another possible way to use the LiveTV content, and just in the case you want to
|
rosfran@371
|
41 |
* use the mysql database, put the location URI in the following format:
|
rosfran@371
|
42 |
*
|
rosfran@375
|
43 |
* myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
|
rosfran@289
|
44 |
*
|
rosfran@289
|
45 |
* Where the first field is the protocol (myth), the second and third are user
|
rosfran@289
|
46 |
* name (mythtv) and password (mythtv), then backend host name and port number,
|
rosfran@289
|
47 |
* and the last field is the database name (mythconverg).
|
rosfran@289
|
48 |
*/
|
leo_sobral@2
|
49 |
|
leo_sobral@2
|
50 |
#ifdef HAVE_CONFIG_H
|
leo_sobral@2
|
51 |
#include "config.h"
|
leo_sobral@2
|
52 |
#endif
|
leo_sobral@2
|
53 |
|
leo_sobral@2
|
54 |
#include "gstmythtvsrc.h"
|
rosfran@528
|
55 |
#include <gmyth/gmyth_file.h>
|
rosfran@52
|
56 |
#include <gmyth/gmyth_file_transfer.h>
|
rosfran@528
|
57 |
#include <gmyth/gmyth_file_local.h>
|
rosfran@52
|
58 |
#include <gmyth/gmyth_livetv.h>
|
leo_sobral@2
|
59 |
|
leo_sobral@2
|
60 |
#include <gmyth/gmyth_socket.h>
|
leo_sobral@2
|
61 |
#include <gmyth/gmyth_tvchain.h>
|
leo_sobral@2
|
62 |
|
leo_sobral@2
|
63 |
#include <string.h>
|
leo_sobral@2
|
64 |
#include <unistd.h>
|
leo_sobral@2
|
65 |
|
leo_sobral@2
|
66 |
GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
|
leo_sobral@2
|
67 |
#define GST_CAT_DEFAULT mythtvsrc_debug
|
leo_sobral@2
|
68 |
|
rosfran@289
|
69 |
#define GST_GMYTHTV_ID_NUM 1
|
rosfran@70
|
70 |
|
rosfran@289
|
71 |
#define GST_GMYTHTV_CHANNEL_DEFAULT_NUM (-1)
|
leo_sobral@2
|
72 |
|
rosfran@289
|
73 |
#define GMYTHTV_VERSION_DEFAULT 30
|
leo_sobral@2
|
74 |
|
rosfran@289
|
75 |
#define GMYTHTV_TRANSFER_MAX_WAITS 100
|
rosfran@102
|
76 |
|
rosfran@289
|
77 |
#define GMYTHTV_TRANSFER_MAX_RESENDS 2
|
leo_sobral@2
|
78 |
|
rosfran@289
|
79 |
#define GMYTHTV_TRANSFER_MAX_BUFFER (128*1024)
|
leo_sobral@2
|
80 |
|
rosfran@289
|
81 |
#define MAX_READ_SIZE (4*1024)
|
rosfran@70
|
82 |
|
rosfran@289
|
83 |
#define GST_FLOW_ERROR_NO_DATA (-101)
|
rosfran@124
|
84 |
|
rosfran@289
|
85 |
#define REQUEST_MAX_SIZE (64*1024)
|
rosfran@90
|
86 |
|
rosfran@289
|
87 |
#define INTERNAL_BUFFER_SIZE (90*1024)
|
leo_sobral@2
|
88 |
|
leo_sobral@2
|
89 |
static const GstElementDetails gst_mythtv_src_details =
|
rosfran@289
|
90 |
GST_ELEMENT_DETAILS ("MythTV client source",
|
leo_sobral@2
|
91 |
"Source/Network",
|
rosfran@289
|
92 |
"Control and receive data as a client over the network "
|
rosfran@289
|
93 |
"via raw socket connections using the MythTV protocol",
|
rosfran@289
|
94 |
"Rosfran Borges <rosfran.borges@indt.org.br>");
|
leo_sobral@2
|
95 |
|
rosfran@289
|
96 |
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
leo_sobral@2
|
97 |
GST_PAD_SRC,
|
leo_sobral@2
|
98 |
GST_PAD_ALWAYS,
|
rosfran@289
|
99 |
GST_STATIC_CAPS ("video/x-nuv"));
|
rosfran@289
|
100 |
|
leo_sobral@2
|
101 |
enum
|
leo_sobral@2
|
102 |
{
|
leo_sobral@2
|
103 |
PROP_0,
|
leo_sobral@2
|
104 |
PROP_LOCATION,
|
leo_sobral@2
|
105 |
#ifndef GST_DISABLE_GST_DEBUG
|
rosfran@40
|
106 |
PROP_GMYTHTV_DBG,
|
leo_sobral@2
|
107 |
#endif
|
rosfran@40
|
108 |
PROP_GMYTHTV_VERSION,
|
rosfran@40
|
109 |
PROP_GMYTHTV_LIVE,
|
rosfran@40
|
110 |
PROP_GMYTHTV_LIVEID,
|
rosfran@52
|
111 |
PROP_GMYTHTV_LIVE_CHAINID,
|
rosfran@70
|
112 |
PROP_GMYTHTV_ENABLE_TIMING_POSITION,
|
rosfran@70
|
113 |
PROP_GMYTHTV_CHANNEL_NUM
|
leo_sobral@2
|
114 |
};
|
leo_sobral@2
|
115 |
|
rosfran@548
|
116 |
static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
|
rosfran@548
|
117 |
|
leo_sobral@2
|
118 |
static void gst_mythtv_src_finalize (GObject * gobject);
|
leo_sobral@2
|
119 |
|
rosfran@289
|
120 |
static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
|
rosfran@289
|
121 |
GstBuffer ** outbuf);
|
rosfran@52
|
122 |
|
leo_sobral@2
|
123 |
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
|
leo_sobral@2
|
124 |
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
|
leo_sobral@2
|
125 |
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
|
rosfran@289
|
126 |
static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
|
rosfran@87
|
127 |
|
rosfran@289
|
128 |
static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
|
rosfran@289
|
129 |
GstSegment * segment);
|
rosfran@98
|
130 |
|
rosfran@52
|
131 |
static GstStateChangeReturn
|
rosfran@52
|
132 |
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
|
leo_sobral@2
|
133 |
|
leo_sobral@2
|
134 |
static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
135 |
const GValue * value, GParamSpec * pspec);
|
leo_sobral@2
|
136 |
static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
137 |
GValue * value, GParamSpec * pspec);
|
leo_sobral@2
|
138 |
|
rosfran@289
|
139 |
static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
|
rosfran@289
|
140 |
gpointer iface_data);
|
rosfran@30
|
141 |
|
rosfran@87
|
142 |
static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
|
rosfran@87
|
143 |
|
rosfran@90
|
144 |
static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
|
rosfran@30
|
145 |
|
rosfran@528
|
146 |
static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
|
rosfran@289
|
147 |
GByteArray * data_ptr);
|
leo_sobral@2
|
148 |
|
rosfran@52
|
149 |
static void
|
leo_sobral@2
|
150 |
_urihandler_init (GType type)
|
leo_sobral@2
|
151 |
{
|
leo_sobral@2
|
152 |
static const GInterfaceInfo urihandler_info = {
|
leo_sobral@2
|
153 |
gst_mythtv_src_uri_handler_init,
|
leo_sobral@2
|
154 |
NULL,
|
leo_sobral@2
|
155 |
NULL
|
leo_sobral@2
|
156 |
};
|
leo_sobral@2
|
157 |
|
leo_sobral@2
|
158 |
g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
|
leo_sobral@2
|
159 |
|
rosfran@289
|
160 |
GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
|
leo_sobral@2
|
161 |
}
|
leo_sobral@2
|
162 |
|
rosfran@100
|
163 |
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
|
rosfran@100
|
164 |
GST_TYPE_PUSH_SRC, _urihandler_init)
|
rosfran@289
|
165 |
|
rosfran@289
|
166 |
static void gst_mythtv_src_base_init (gpointer g_class)
|
leo_sobral@2
|
167 |
{
|
leo_sobral@2
|
168 |
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
leo_sobral@2
|
169 |
|
leo_sobral@2
|
170 |
gst_element_class_add_pad_template (element_class,
|
leo_sobral@2
|
171 |
gst_static_pad_template_get (&srctemplate));
|
rosfran@289
|
172 |
|
leo_sobral@2
|
173 |
gst_element_class_set_details (element_class, &gst_mythtv_src_details);
|
rosfran@289
|
174 |
|
rosfran@52
|
175 |
element_class->change_state = gst_mythtv_src_change_state;
|
rosfran@289
|
176 |
|
leo_sobral@2
|
177 |
}
|
leo_sobral@2
|
178 |
|
rosfran@30
|
179 |
static void
|
leo_sobral@2
|
180 |
gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
|
leo_sobral@2
|
181 |
{
|
rosfran@289
|
182 |
GObjectClass *gobject_class;
|
rosfran@100
|
183 |
GstPushSrcClass *gstpushsrc_class;
|
leo_sobral@2
|
184 |
GstBaseSrcClass *gstbasesrc_class;
|
leo_sobral@2
|
185 |
|
leo_sobral@2
|
186 |
gobject_class = (GObjectClass *) klass;
|
leo_sobral@2
|
187 |
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
rosfran@100
|
188 |
gstpushsrc_class = (GstPushSrcClass *) klass;
|
leo_sobral@2
|
189 |
|
leo_sobral@2
|
190 |
gobject_class->set_property = gst_mythtv_src_set_property;
|
leo_sobral@2
|
191 |
gobject_class->get_property = gst_mythtv_src_get_property;
|
leo_sobral@2
|
192 |
gobject_class->finalize = gst_mythtv_src_finalize;
|
leo_sobral@2
|
193 |
|
leo_sobral@2
|
194 |
g_object_class_install_property
|
rosfran@289
|
195 |
(gobject_class, PROP_LOCATION,
|
rosfran@289
|
196 |
g_param_spec_string ("location", "Location",
|
rosfran@289
|
197 |
"The location. In the form:"
|
rosfran@289
|
198 |
"\n\t\t\tmyth://a.com/file.nuv"
|
rosfran@289
|
199 |
"\n\t\t\tmyth://a.com:23223/file.nuv "
|
rosfran@289
|
200 |
"\n\t\t\ta.com/file.nuv - default scheme 'myth'",
|
rosfran@289
|
201 |
"", G_PARAM_READWRITE));
|
leo_sobral@2
|
202 |
|
leo_sobral@2
|
203 |
g_object_class_install_property
|
rosfran@289
|
204 |
(gobject_class, PROP_GMYTHTV_VERSION,
|
rosfran@289
|
205 |
g_param_spec_int ("mythtv-version", "mythtv-version",
|
rosfran@289
|
206 |
"Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
|
leo_sobral@2
|
207 |
|
leo_sobral@2
|
208 |
g_object_class_install_property
|
rosfran@289
|
209 |
(gobject_class, PROP_GMYTHTV_LIVEID,
|
rosfran@289
|
210 |
g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
|
rosfran@289
|
211 |
"Change MythTV version",
|
rosfran@289
|
212 |
0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
|
leo_sobral@2
|
213 |
|
leo_sobral@2
|
214 |
g_object_class_install_property
|
rosfran@289
|
215 |
(gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
|
rosfran@289
|
216 |
g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
|
rosfran@289
|
217 |
"Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
|
leo_sobral@2
|
218 |
|
leo_sobral@2
|
219 |
g_object_class_install_property
|
rosfran@289
|
220 |
(gobject_class, PROP_GMYTHTV_LIVE,
|
rosfran@289
|
221 |
g_param_spec_boolean ("mythtv-live", "mythtv-live",
|
rosfran@289
|
222 |
"Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
|
leo_sobral@2
|
223 |
|
leo_sobral@2
|
224 |
g_object_class_install_property
|
rosfran@289
|
225 |
(gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
|
rosfran@289
|
226 |
g_param_spec_boolean ("mythtv-enable-timing-position",
|
rosfran@289
|
227 |
"mythtv-enable-timing-position",
|
rosfran@289
|
228 |
"Enable MythTV Live TV content size continuous updating", FALSE,
|
rosfran@289
|
229 |
G_PARAM_READWRITE));
|
leo_sobral@2
|
230 |
|
rosfran@52
|
231 |
g_object_class_install_property
|
rosfran@289
|
232 |
(gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
|
rosfran@308
|
233 |
g_param_spec_string ("mythtv-channel", "mythtv-channel",
|
rosfran@289
|
234 |
"Change MythTV channel number",
|
rosfran@308
|
235 |
"", G_PARAM_READWRITE));
|
rosfran@52
|
236 |
|
leo_sobral@2
|
237 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
238 |
g_object_class_install_property
|
rosfran@289
|
239 |
(gobject_class, PROP_GMYTHTV_DBG,
|
rosfran@289
|
240 |
g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
|
rosfran@289
|
241 |
"Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
|
leo_sobral@2
|
242 |
#endif
|
leo_sobral@2
|
243 |
|
leo_sobral@2
|
244 |
gstbasesrc_class->start = gst_mythtv_src_start;
|
leo_sobral@2
|
245 |
gstbasesrc_class->stop = gst_mythtv_src_stop;
|
leo_sobral@2
|
246 |
gstbasesrc_class->get_size = gst_mythtv_src_get_size;
|
rosfran@87
|
247 |
gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
|
rosfran@289
|
248 |
|
rosfran@100
|
249 |
gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
|
rosfran@100
|
250 |
gstpushsrc_class->create = gst_mythtv_src_create;
|
rosfran@289
|
251 |
|
leo_sobral@2
|
252 |
GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
|
leo_sobral@2
|
253 |
"MythTV Client Source");
|
leo_sobral@2
|
254 |
}
|
leo_sobral@2
|
255 |
|
rosfran@30
|
256 |
static void
|
leo_sobral@2
|
257 |
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
|
leo_sobral@2
|
258 |
{
|
rosfran@546
|
259 |
this->file = NULL;
|
leo_sobral@2
|
260 |
|
leo_sobral@2
|
261 |
this->unique_setup = FALSE;
|
leo_sobral@2
|
262 |
|
rosfran@40
|
263 |
this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
|
rosfran@289
|
264 |
|
rosfran@70
|
265 |
this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
|
leo_sobral@2
|
266 |
|
leo_sobral@2
|
267 |
this->bytes_read = 0;
|
rosfran@289
|
268 |
|
rosfran@63
|
269 |
this->prev_content_size = 0;
|
leo_sobral@2
|
270 |
|
rosfran@52
|
271 |
this->content_size = 0;
|
leo_sobral@2
|
272 |
this->read_offset = 0;
|
leo_sobral@2
|
273 |
|
rosfran@61
|
274 |
this->content_size_last = 0;
|
rosfran@61
|
275 |
|
leo_sobral@2
|
276 |
this->live_tv = FALSE;
|
rosfran@289
|
277 |
|
rosfran@52
|
278 |
this->enable_timing_position = FALSE;
|
rosfran@289
|
279 |
this->update_prog_chain = FALSE;
|
leo_sobral@2
|
280 |
|
leo_sobral@2
|
281 |
this->user_agent = g_strdup ("mythtvsrc");
|
rosfran@52
|
282 |
this->update_prog_chain = FALSE;
|
rosfran@289
|
283 |
|
rosfran@308
|
284 |
this->channel_name = NULL;
|
rosfran@289
|
285 |
|
rosfran@52
|
286 |
this->eos = FALSE;
|
rosfran@289
|
287 |
|
rosfran@98
|
288 |
this->bytes_queue = NULL;
|
leo_sobral@2
|
289 |
|
rosfran@289
|
290 |
this->wait_to_transfer = 0;
|
rosfran@289
|
291 |
|
rosfran@289
|
292 |
gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
|
rosfran@289
|
293 |
|
rosfran@289
|
294 |
gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
|
rosfran@289
|
295 |
gst_mythtv_src_handle_event);
|
rosfran@289
|
296 |
gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
|
rosfran@289
|
297 |
gst_mythtv_src_handle_query);
|
rosfran@30
|
298 |
|
leo_sobral@2
|
299 |
}
|
leo_sobral@2
|
300 |
|
rosfran@30
|
301 |
static void
|
rosfran@548
|
302 |
gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
|
rosfran@548
|
303 |
{
|
rosfran@548
|
304 |
|
rosfran@548
|
305 |
if (mythtv_src->spawn_livetv) {
|
rosfran@548
|
306 |
g_object_unref (mythtv_src->spawn_livetv);
|
rosfran@548
|
307 |
mythtv_src->spawn_livetv = NULL;
|
rosfran@548
|
308 |
}
|
rosfran@548
|
309 |
|
rosfran@548
|
310 |
if (mythtv_src->file) {
|
rosfran@548
|
311 |
g_object_unref (mythtv_src->file);
|
rosfran@548
|
312 |
mythtv_src->file = NULL;
|
rosfran@548
|
313 |
}
|
rosfran@548
|
314 |
|
rosfran@548
|
315 |
if (mythtv_src->backend_info) {
|
rosfran@548
|
316 |
g_object_unref (mythtv_src->backend_info);
|
rosfran@548
|
317 |
mythtv_src->backend_info = NULL;
|
rosfran@548
|
318 |
}
|
rosfran@548
|
319 |
|
rosfran@548
|
320 |
if (mythtv_src->uri_name) {
|
rosfran@548
|
321 |
g_free (mythtv_src->uri_name);
|
rosfran@548
|
322 |
}
|
rosfran@548
|
323 |
|
rosfran@548
|
324 |
if (mythtv_src->user_agent) {
|
rosfran@548
|
325 |
g_free (mythtv_src->user_agent);
|
rosfran@548
|
326 |
}
|
rosfran@548
|
327 |
|
rosfran@548
|
328 |
if (mythtv_src->bytes_queue) {
|
rosfran@548
|
329 |
g_byte_array_free (mythtv_src->bytes_queue, TRUE);
|
rosfran@548
|
330 |
mythtv_src->bytes_queue = NULL;
|
rosfran@548
|
331 |
}
|
rosfran@548
|
332 |
|
rosfran@548
|
333 |
}
|
rosfran@548
|
334 |
|
rosfran@548
|
335 |
static void
|
leo_sobral@2
|
336 |
gst_mythtv_src_finalize (GObject * gobject)
|
leo_sobral@2
|
337 |
{
|
leo_sobral@2
|
338 |
GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
|
rosfran@114
|
339 |
|
rosfran@548
|
340 |
gst_mythtv_src_clear (this);
|
leo_sobral@2
|
341 |
|
leo_sobral@2
|
342 |
G_OBJECT_CLASS (parent_class)->finalize (gobject);
|
leo_sobral@2
|
343 |
}
|
leo_sobral@2
|
344 |
|
rosfran@528
|
345 |
static GMythFileReadResult
|
renatofilho@506
|
346 |
do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
|
leo_sobral@2
|
347 |
{
|
rosfran@37
|
348 |
gint read = 0;
|
rosfran@52
|
349 |
guint sizetoread = size;
|
rosfran@142
|
350 |
gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
|
rosfran@528
|
351 |
GMythFileReadResult result;
|
rosfran@289
|
352 |
|
rosfran@289
|
353 |
GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
|
leo_sobral@2
|
354 |
|
rosfran@30
|
355 |
/* Loop sending the Myth File Transfer request:
|
leo_sobral@2
|
356 |
* Retry whilst authentication fails and we supply it. */
|
rosfran@61
|
357 |
|
rosfran@289
|
358 |
while (sizetoread == size && --max_iters > 0) {
|
rosfran@546
|
359 |
/* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
|
rosfran@546
|
360 |
if ( IS_GMYTH_FILE_LOCAL(src->file) )
|
rosfran@546
|
361 |
result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
|
rosfran@528
|
362 |
data_ptr, sizetoread, src->live_tv);
|
rosfran@546
|
363 |
else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
|
rosfran@546
|
364 |
result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
|
rosfran@528
|
365 |
data_ptr, sizetoread, src->live_tv);
|
rosfran@289
|
366 |
|
renatofilho@506
|
367 |
if (data_ptr->len > 0) {
|
renatofilho@503
|
368 |
read += data_ptr->len;
|
renatofilho@503
|
369 |
sizetoread -= data_ptr->len;
|
renatofilho@506
|
370 |
} else if (data_ptr->len < 0) {
|
rosfran@289
|
371 |
if (src->live_tv == FALSE) {
|
rosfran@528
|
372 |
result = GMYTH_FILE_READ_EOF;
|
rosfran@289
|
373 |
goto eos;
|
rosfran@289
|
374 |
} else {
|
rosfran@528
|
375 |
if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
|
rosfran@289
|
376 |
GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
|
rosfran@289
|
377 |
goto done;
|
rosfran@528
|
378 |
} else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */
|
rosfran@289
|
379 |
GST_INFO_OBJECT (src,
|
rosfran@289
|
380 |
"[LiveTV] FileTransfer - Go to the next program chain!");
|
rosfran@289
|
381 |
continue;
|
rosfran@289
|
382 |
}
|
rosfran@289
|
383 |
goto done;
|
rosfran@90
|
384 |
}
|
rosfran@30
|
385 |
|
renatofilho@503
|
386 |
} else if (data_ptr->len == 0)
|
rosfran@289
|
387 |
goto done;
|
rosfran@61
|
388 |
|
rosfran@289
|
389 |
if (read == sizetoread)
|
rosfran@90
|
390 |
goto done;
|
rosfran@100
|
391 |
}
|
rosfran@61
|
392 |
|
renatofilho@506
|
393 |
if ((read < 0 && !src->live_tv) || max_iters == 0){
|
rosfran@528
|
394 |
result = GMYTH_FILE_READ_EOF;
|
rosfran@61
|
395 |
goto eos;
|
renatofilho@506
|
396 |
}
|
rosfran@61
|
397 |
|
rosfran@30
|
398 |
goto done;
|
leo_sobral@2
|
399 |
|
leo_sobral@2
|
400 |
eos:
|
leo_sobral@2
|
401 |
src->eos = TRUE;
|
rosfran@61
|
402 |
|
leo_sobral@2
|
403 |
done:
|
renatofilho@506
|
404 |
return result;
|
leo_sobral@2
|
405 |
}
|
leo_sobral@2
|
406 |
|
rosfran@30
|
407 |
static GstFlowReturn
|
rosfran@289
|
408 |
gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
rosfran@81
|
409 |
{
|
rosfran@81
|
410 |
GstMythtvSrc *src;
|
rosfran@81
|
411 |
GstFlowReturn ret = GST_FLOW_OK;
|
rosfran@528
|
412 |
guint buffer_size_inter = 0;
|
rosfran@90
|
413 |
|
rosfran@289
|
414 |
src = GST_MYTHTV_SRC (psrc);
|
rosfran@90
|
415 |
|
rosfran@81
|
416 |
/* The caller should know the number of bytes and not read beyond EOS. */
|
rosfran@289
|
417 |
if (G_UNLIKELY (src->eos))
|
rosfran@81
|
418 |
goto eos;
|
rosfran@289
|
419 |
if (G_UNLIKELY (src->update_prog_chain))
|
rosfran@81
|
420 |
goto change_progchain;
|
rosfran@95
|
421 |
|
rosfran@289
|
422 |
GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
|
rosfran@289
|
423 |
src->read_offset, MAX_READ_SIZE);
|
rosfran@95
|
424 |
|
rosfran@289
|
425 |
GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
|
rosfran@289
|
426 |
(gint) src->buffer_remain, src->bytes_queue->len);
|
rosfran@95
|
427 |
|
rosfran@429
|
428 |
program_chain_changed:
|
rosfran@100
|
429 |
/* just get from the byte array, no network effort... */
|
rosfran@289
|
430 |
if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
|
rosfran@364
|
431 |
GByteArray *buffer;
|
rosfran@528
|
432 |
GMythFileReadResult result = GMYTH_FILE_READ_OK;
|
rosfran@359
|
433 |
|
rosfran@364
|
434 |
buffer = NULL;
|
rosfran@528
|
435 |
buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
|
rosfran@95
|
436 |
|
rosfran@289
|
437 |
if (buffer_size_inter > REQUEST_MAX_SIZE)
|
rosfran@289
|
438 |
buffer_size_inter = REQUEST_MAX_SIZE;
|
rosfran@289
|
439 |
|
rosfran@289
|
440 |
buffer = g_byte_array_new ();
|
rosfran@289
|
441 |
|
renatofilho@503
|
442 |
result = do_read_request_response (src, buffer_size_inter, buffer);
|
rosfran@142
|
443 |
|
renatofilho@503
|
444 |
if (G_UNLIKELY (buffer->len < 0)) {
|
rosfran@359
|
445 |
|
rosfran@359
|
446 |
if (buffer != NULL) {
|
rosfran@359
|
447 |
g_byte_array_free (buffer, TRUE);
|
rosfran@359
|
448 |
buffer = NULL;
|
rosfran@359
|
449 |
}
|
rosfran@359
|
450 |
|
rosfran@528
|
451 |
if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
|
rosfran@289
|
452 |
goto change_progchain;
|
rosfran@142
|
453 |
else
|
rosfran@289
|
454 |
goto read_error;
|
rosfran@289
|
455 |
} else if (G_UNLIKELY (read == 0)) {
|
rosfran@359
|
456 |
|
rosfran@359
|
457 |
if (buffer != NULL) {
|
rosfran@359
|
458 |
g_byte_array_free (buffer, TRUE);
|
rosfran@359
|
459 |
buffer = NULL;
|
rosfran@359
|
460 |
}
|
rosfran@359
|
461 |
|
rosfran@289
|
462 |
if (!src->live_tv)
|
rosfran@303
|
463 |
goto done;
|
rosfran@289
|
464 |
else
|
rosfran@429
|
465 |
goto program_chain_changed;
|
rosfran@174
|
466 |
}
|
rosfran@142
|
467 |
|
rosfran@289
|
468 |
if (G_UNLIKELY (src->update_prog_chain))
|
rosfran@359
|
469 |
{
|
rosfran@359
|
470 |
if (buffer != NULL) {
|
rosfran@359
|
471 |
g_byte_array_free (buffer, TRUE);
|
rosfran@359
|
472 |
buffer = NULL;
|
rosfran@359
|
473 |
}
|
rosfran@359
|
474 |
goto change_progchain;
|
rosfran@359
|
475 |
}
|
rosfran@289
|
476 |
|
rosfran@289
|
477 |
src->bytes_queue =
|
renatofilho@503
|
478 |
g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
|
renatofilho@503
|
479 |
if (buffer->len > buffer_size_inter)
|
rosfran@289
|
480 |
GST_WARNING_OBJECT (src,
|
rosfran@289
|
481 |
"INCREASED buffer size! Backend sent more than we ask him... (%d)",
|
rosfran@528
|
482 |
abs (buffer->len - buffer_size_inter));
|
rosfran@142
|
483 |
|
renatofilho@503
|
484 |
src->buffer_remain += buffer->len;
|
rosfran@142
|
485 |
|
rosfran@289
|
486 |
if (buffer != NULL) {
|
rosfran@289
|
487 |
g_byte_array_free (buffer, TRUE);
|
rosfran@289
|
488 |
buffer = NULL;
|
rosfran@142
|
489 |
}
|
rosfran@289
|
490 |
|
rosfran@289
|
491 |
GST_DEBUG_OBJECT (src,
|
rosfran@289
|
492 |
"BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
|
rosfran@289
|
493 |
"OFFSET = %llu, CONTENT SIZE = %llu.", read,
|
rosfran@289
|
494 |
src->bytes_read, src->read_offset, src->content_size);
|
rosfran@289
|
495 |
|
rosfran@81
|
496 |
}
|
rosfran@289
|
497 |
|
rosfran@289
|
498 |
guint buffer_size =
|
rosfran@289
|
499 |
(src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
|
rosfran@289
|
500 |
|
rosfran@289
|
501 |
*outbuf = gst_buffer_new ();
|
rosfran@289
|
502 |
|
rosfran@289
|
503 |
/* gets the first buffer_size bytes from the byte array buffer variable */
|
rosfran@235
|
504 |
/* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
|
rosfran@95
|
505 |
|
rosfran@289
|
506 |
GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
|
rosfran@528
|
507 |
(buffer_size_inter ==
|
rosfran@528
|
508 |
0) ? "NO, got from buffer" : "YES, go see the backend's log file",
|
rosfran@289
|
509 |
src->buffer_remain);
|
rosfran@95
|
510 |
|
rosfran@100
|
511 |
GST_BUFFER_SIZE (*outbuf) = buffer_size;
|
rosfran@289
|
512 |
GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
|
rosfran@289
|
513 |
GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
|
rosfran@289
|
514 |
g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
|
rosfran@289
|
515 |
GST_BUFFER_SIZE (*outbuf));
|
rosfran@95
|
516 |
GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
|
rosfran@289
|
517 |
GST_BUFFER_OFFSET_END (*outbuf) =
|
rosfran@289
|
518 |
src->read_offset + GST_BUFFER_SIZE (*outbuf);
|
rosfran@95
|
519 |
|
rosfran@95
|
520 |
src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
|
rosfran@95
|
521 |
|
rosfran@95
|
522 |
src->read_offset += GST_BUFFER_SIZE (*outbuf);
|
rosfran@95
|
523 |
src->bytes_read += GST_BUFFER_SIZE (*outbuf);
|
rosfran@289
|
524 |
GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
|
rosfran@289
|
525 |
GST_BUFFER_SIZE (*outbuf));
|
rosfran@289
|
526 |
|
rosfran@100
|
527 |
/* flushs the newly buffer got from byte array */
|
rosfran@289
|
528 |
src->bytes_queue =
|
rosfran@289
|
529 |
g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
|
rosfran@95
|
530 |
|
rosfran@359
|
531 |
GST_DEBUG_OBJECT ( src, "Got buffer: BUFFER --->SIZE = %d, OFFSET = %llu, "
|
rosfran@289
|
532 |
"OFFSET_END = %llu.", GST_BUFFER_SIZE (*outbuf),
|
rosfran@359
|
533 |
GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
|
rosfran@95
|
534 |
|
rosfran@289
|
535 |
GST_DEBUG_OBJECT (src, "CONTENT_SIZE = %llu, BYTES_READ = %llu.",
|
rosfran@289
|
536 |
src->content_size, src->bytes_read);
|
rosfran@289
|
537 |
|
rosfran@359
|
538 |
if ( G_UNLIKELY (src->eos) || ( !src->live_tv
|
rosfran@359
|
539 |
&& ( src->bytes_read >= src->content_size ) ) )
|
rosfran@289
|
540 |
goto eos;
|
rosfran@90
|
541 |
|
rosfran@81
|
542 |
done:
|
rosfran@90
|
543 |
{
|
rosfran@81
|
544 |
const gchar *reason = gst_flow_get_name (ret);
|
rosfran@81
|
545 |
|
rosfran@81
|
546 |
GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
|
rosfran@90
|
547 |
return ret;
|
rosfran@90
|
548 |
}
|
rosfran@81
|
549 |
eos:
|
rosfran@81
|
550 |
{
|
rosfran@81
|
551 |
const gchar *reason = gst_flow_get_name (ret);
|
rosfran@81
|
552 |
|
rosfran@81
|
553 |
GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
|
rosfran@81
|
554 |
return GST_FLOW_UNEXPECTED;
|
rosfran@81
|
555 |
}
|
rosfran@81
|
556 |
/* ERRORS */
|
rosfran@81
|
557 |
read_error:
|
rosfran@81
|
558 |
{
|
rosfran@81
|
559 |
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
rosfran@289
|
560 |
(NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
|
rosfran@81
|
561 |
return GST_FLOW_ERROR;
|
rosfran@81
|
562 |
}
|
rosfran@81
|
563 |
change_progchain:
|
rosfran@81
|
564 |
{
|
rosfran@81
|
565 |
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
rosfran@289
|
566 |
(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
|
rosfran@289
|
567 |
src->uri_name));
|
rosfran@90
|
568 |
|
rosfran@375
|
569 |
/*
|
rosfran@429
|
570 |
TODO: need to send a new segment event to NUVDemux?
|
rosfran@289
|
571 |
gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
|
rosfran@289
|
572 |
gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
|
rosfran@375
|
573 |
*/
|
rosfran@303
|
574 |
|
rosfran@359
|
575 |
goto program_chain_changed;
|
rosfran@37
|
576 |
}
|
rosfran@30
|
577 |
|
leo_sobral@2
|
578 |
}
|
rosfran@98
|
579 |
|
rosfran@52
|
580 |
gint64
|
rosfran@289
|
581 |
gst_mythtv_src_get_position (GstMythtvSrc * src)
|
leo_sobral@2
|
582 |
{
|
rosfran@30
|
583 |
|
rosfran@52
|
584 |
gint64 size_tmp = 0;
|
rosfran@71
|
585 |
guint max_tries = 2;
|
rosfran@71
|
586 |
|
rosfran@289
|
587 |
if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
|
rosfran@289
|
588 |
GMYTHTV_TRANSFER_MAX_BUFFER)) {
|
rosfran@289
|
589 |
|
rosfran@289
|
590 |
get_file_pos:
|
rosfran@289
|
591 |
g_usleep (10);
|
rosfran@289
|
592 |
size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
|
rosfran@289
|
593 |
if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
|
rosfran@61
|
594 |
src->content_size = size_tmp;
|
rosfran@289
|
595 |
else if (size_tmp > 0 && --max_tries > 0)
|
rosfran@61
|
596 |
goto get_file_pos;
|
rosfran@289
|
597 |
GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
|
rosfran@71
|
598 |
/* sets the last content size amount before it can be updated */
|
rosfran@71
|
599 |
src->prev_content_size = src->content_size;
|
rosfran@30
|
600 |
}
|
rosfran@52
|
601 |
|
rosfran@289
|
602 |
return src->content_size;
|
rosfran@30
|
603 |
|
leo_sobral@2
|
604 |
}
|
leo_sobral@2
|
605 |
|
rosfran@87
|
606 |
static gboolean
|
rosfran@289
|
607 |
gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
|
rosfran@87
|
608 |
{
|
rosfran@289
|
609 |
GstMythtvSrc *src = GST_MYTHTV_SRC (base);
|
rosfran@90
|
610 |
gint64 new_offset = -1;
|
rosfran@90
|
611 |
gint64 actual_seek = segment->start;
|
rosfran@87
|
612 |
gboolean ret = TRUE;
|
rosfran@87
|
613 |
|
rosfran@289
|
614 |
GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
|
rosfran@90
|
615 |
|
rosfran@289
|
616 |
if (segment->format == GST_FORMAT_TIME) {
|
rosfran@289
|
617 |
goto done;
|
rosfran@90
|
618 |
}
|
rosfran@289
|
619 |
GST_LOG_OBJECT (src,
|
rosfran@289
|
620 |
"Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
|
rosfran@289
|
621 |
actual_seek, src->read_offset);
|
rosfran@87
|
622 |
/* verify if it needs to seek */
|
rosfran@289
|
623 |
if (src->read_offset != actual_seek) {
|
rosfran@528
|
624 |
|
rosfran@546
|
625 |
/* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
|
rosfran@546
|
626 |
if ( IS_GMYTH_FILE_LOCAL(src->file) )
|
rosfran@528
|
627 |
new_offset =
|
rosfran@546
|
628 |
gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
|
rosfran@546
|
629 |
else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
|
rosfran@528
|
630 |
new_offset =
|
rosfran@546
|
631 |
gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
|
rosfran@87
|
632 |
|
rosfran@289
|
633 |
GST_LOG_OBJECT (src,
|
rosfran@289
|
634 |
"Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
|
rosfran@289
|
635 |
segment->start, src->read_offset, new_offset);
|
rosfran@289
|
636 |
if (G_UNLIKELY (new_offset < 0)) {
|
rosfran@87
|
637 |
ret = FALSE;
|
rosfran@371
|
638 |
if (!src->live_tv)
|
rosfran@289
|
639 |
goto eos;
|
rosfran@87
|
640 |
}
|
rosfran@87
|
641 |
|
rosfran@87
|
642 |
src->read_offset = new_offset;
|
rosfran@87
|
643 |
|
rosfran@289
|
644 |
if (ret == FALSE) {
|
rosfran@289
|
645 |
GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
|
rosfran@90
|
646 |
}
|
rosfran@90
|
647 |
|
rosfran@87
|
648 |
}
|
rosfran@90
|
649 |
|
rosfran@90
|
650 |
done:
|
rosfran@289
|
651 |
return ret;
|
rosfran@87
|
652 |
|
rosfran@87
|
653 |
eos:
|
rosfran@87
|
654 |
{
|
rosfran@87
|
655 |
GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
|
rosfran@87
|
656 |
return FALSE;
|
rosfran@87
|
657 |
}
|
rosfran@87
|
658 |
|
rosfran@87
|
659 |
}
|
rosfran@87
|
660 |
|
leo_sobral@2
|
661 |
/* create a socket for connecting to remote server */
|
rosfran@30
|
662 |
static gboolean
|
rosfran@289
|
663 |
gst_mythtv_src_start (GstBaseSrc * bsrc)
|
leo_sobral@2
|
664 |
{
|
leo_sobral@2
|
665 |
GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
|
leo_sobral@2
|
666 |
|
rosfran@293
|
667 |
GString *chain_id_local = NULL;
|
rosfran@293
|
668 |
GMythURI *gmyth_uri = NULL;
|
leo_sobral@2
|
669 |
gboolean ret = TRUE;
|
rosfran@90
|
670 |
|
leo_sobral@2
|
671 |
if (src->unique_setup == FALSE) {
|
leo_sobral@2
|
672 |
src->unique_setup = TRUE;
|
leo_sobral@2
|
673 |
} else {
|
leo_sobral@2
|
674 |
goto done;
|
leo_sobral@2
|
675 |
}
|
rosfran@174
|
676 |
|
rosfran@293
|
677 |
gmyth_uri = gmyth_uri_new_with_value( src->uri_name );
|
rosfran@289
|
678 |
|
rosfran@289
|
679 |
src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
|
rosfran@304
|
680 |
src->live_tv |= gmyth_uri_is_livetv( gmyth_uri );
|
rosfran@289
|
681 |
/* testing UPnP... */
|
rosfran@289
|
682 |
/* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
|
rosfran@304
|
683 |
if ( src->live_tv ) {
|
rosfran@448
|
684 |
src->spawn_livetv = gmyth_livetv_new (src->backend_info);
|
rosfran@236
|
685 |
|
rosfran@308
|
686 |
gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
|
rosfran@308
|
687 |
if ( ch != NULL )
|
rosfran@308
|
688 |
src->channel_name = ch;
|
rosfran@289
|
689 |
|
rosfran@308
|
690 |
if (src->channel_name != NULL) {
|
rosfran@448
|
691 |
if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
|
rosfran@289
|
692 |
GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
|
rosfran@289
|
693 |
ret = FALSE;
|
rosfran@289
|
694 |
goto init_failed;
|
rosfran@289
|
695 |
}
|
rosfran@236
|
696 |
} else {
|
rosfran@448
|
697 |
if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
|
rosfran@289
|
698 |
GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
|
rosfran@289
|
699 |
ret = FALSE;
|
rosfran@289
|
700 |
goto init_failed;
|
rosfran@289
|
701 |
}
|
rosfran@236
|
702 |
}
|
rosfran@546
|
703 |
|
rosfran@311
|
704 |
/* testing change channel... */
|
rosfran@311
|
705 |
/* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
|
rosfran@52
|
706 |
|
rosfran@546
|
707 |
src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
|
rosfran@289
|
708 |
|
rosfran@546
|
709 |
if (NULL == src->file) {
|
rosfran@289
|
710 |
GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
|
rosfran@289
|
711 |
ret = FALSE;
|
rosfran@289
|
712 |
goto init_failed;
|
leo_sobral@2
|
713 |
}
|
rosfran@325
|
714 |
|
rosfran@546
|
715 |
if ( !gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ?
|
rosfran@325
|
716 |
gmyth_uri_get_path(src->spawn_livetv->uri) :
|
rosfran@325
|
717 |
src->spawn_livetv->proginfo->pathname->str ) )
|
rosfran@325
|
718 |
{
|
rosfran@325
|
719 |
GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
|
rosfran@546
|
720 |
g_object_unref( src->file );
|
rosfran@546
|
721 |
src->file = NULL;
|
rosfran@325
|
722 |
goto init_failed;
|
rosfran@325
|
723 |
}
|
rosfran@217
|
724 |
} else {
|
rosfran@217
|
725 |
|
rosfran@546
|
726 |
if ( gmyth_uri_is_local_file(gmyth_uri) )
|
rosfran@528
|
727 |
{
|
rosfran@546
|
728 |
src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
|
rosfran@546
|
729 |
ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
|
rosfran@546
|
730 |
} else {
|
rosfran@546
|
731 |
src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
|
rosfran@546
|
732 |
ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name);
|
rosfran@546
|
733 |
}
|
leo_sobral@2
|
734 |
|
rosfran@528
|
735 |
} /* if (else) - recorded FileTransfer */
|
leo_sobral@2
|
736 |
|
rosfran@546
|
737 |
if (NULL == src->file) {
|
rosfran@289
|
738 |
GST_INFO_OBJECT (src, "FileTransfer is NULL");
|
rosfran@289
|
739 |
goto init_failed;
|
rosfran@289
|
740 |
}
|
rosfran@546
|
741 |
/*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
|
rosfran@289
|
742 |
|
rosfran@289
|
743 |
if (ret == FALSE) {
|
rosfran@289
|
744 |
#ifndef GST_DISABLE_GST_DEBUG
|
rosfran@289
|
745 |
if (src->mythtv_msgs_dbg)
|
rosfran@289
|
746 |
GST_INFO_OBJECT (src,
|
rosfran@289
|
747 |
"MythTV FileTransfer request failed when setting up socket connection!");
|
leo_sobral@2
|
748 |
#endif
|
leo_sobral@2
|
749 |
goto begin_req_failed;
|
leo_sobral@2
|
750 |
}
|
rosfran@289
|
751 |
|
rosfran@289
|
752 |
GST_INFO_OBJECT (src,
|
rosfran@289
|
753 |
"MythTV FileTransfer filesize = %lld, content_size = %lld!",
|
rosfran@546
|
754 |
gmyth_file_get_filesize( src->file ), src->content_size);
|
leo_sobral@2
|
755 |
|
rosfran@546
|
756 |
src->content_size = gmyth_file_get_filesize (src->file);
|
leo_sobral@2
|
757 |
|
rosfran@71
|
758 |
src->do_start = FALSE;
|
rosfran@289
|
759 |
|
rosfran@114
|
760 |
/* this is used for the buffer cache */
|
rosfran@289
|
761 |
src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
|
rosfran@90
|
762 |
src->buffer_remain = 0;
|
rosfran@114
|
763 |
|
rosfran@289
|
764 |
gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
|
rosfran@289
|
765 |
gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
|
rosfran@289
|
766 |
src->content_size, 0));
|
rosfran@90
|
767 |
|
rosfran@30
|
768 |
done:
|
rosfran@293
|
769 |
/*if ( gmyth_uri != NULL )
|
rosfran@289
|
770 |
{
|
rosfran@289
|
771 |
g_object_unref( gmyth_uri );
|
rosfran@289
|
772 |
gmyth_uri = NULL;
|
rosfran@293
|
773 |
}*/
|
rosfran@210
|
774 |
|
rosfran@289
|
775 |
if (chain_id_local != NULL) {
|
rosfran@289
|
776 |
g_string_free (chain_id_local, TRUE);
|
rosfran@289
|
777 |
chain_id_local = NULL;
|
rosfran@289
|
778 |
}
|
rosfran@289
|
779 |
|
rosfran@30
|
780 |
return TRUE;
|
rosfran@30
|
781 |
|
rosfran@30
|
782 |
/* ERRORS */
|
rosfran@30
|
783 |
init_failed:
|
rosfran@30
|
784 |
{
|
rosfran@289
|
785 |
if (src->spawn_livetv != NULL)
|
rosfran@289
|
786 |
g_object_unref (src->spawn_livetv);
|
rosfran@30
|
787 |
|
rosfran@30
|
788 |
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
rosfran@289
|
789 |
(NULL), ("Could not initialize MythTV library (%i, %s)", ret,
|
rosfran@289
|
790 |
src->uri_name));
|
rosfran@30
|
791 |
return FALSE;
|
rosfran@30
|
792 |
}
|
rosfran@30
|
793 |
begin_req_failed:
|
rosfran@30
|
794 |
{
|
rosfran@30
|
795 |
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
rosfran@289
|
796 |
(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
|
rosfran@289
|
797 |
src->uri_name));
|
rosfran@30
|
798 |
return FALSE;
|
rosfran@30
|
799 |
}
|
rosfran@61
|
800 |
|
rosfran@52
|
801 |
}
|
rosfran@52
|
802 |
|
rosfran@30
|
803 |
static gboolean
|
leo_sobral@2
|
804 |
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
|
leo_sobral@2
|
805 |
{
|
rosfran@31
|
806 |
GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
|
rosfran@30
|
807 |
gboolean ret = TRUE;
|
rosfran@289
|
808 |
|
rosfran@289
|
809 |
GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
|
rosfran@289
|
810 |
abs (src->content_size - src->prev_content_size),
|
rosfran@289
|
811 |
GMYTHTV_TRANSFER_MAX_BUFFER);
|
rosfran@289
|
812 |
|
rosfran@289
|
813 |
if (src->live_tv) {
|
rosfran@289
|
814 |
ret = FALSE;
|
rosfran@289
|
815 |
} else if (src->live_tv && src->enable_timing_position
|
rosfran@289
|
816 |
&& (abs (src->content_size - src->bytes_read) <
|
rosfran@289
|
817 |
GMYTHTV_TRANSFER_MAX_BUFFER)) {
|
rosfran@289
|
818 |
|
rosfran@289
|
819 |
gint64 new_offset =
|
rosfran@289
|
820 |
gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
|
rosfran@289
|
821 |
if (new_offset > 0 && new_offset > src->content_size) {
|
rosfran@289
|
822 |
src->content_size = new_offset;
|
rosfran@289
|
823 |
} else if (new_offset < src->content_size) {
|
rosfran@289
|
824 |
src->update_prog_chain = TRUE;
|
rosfran@289
|
825 |
}
|
rosfran@61
|
826 |
|
leo_sobral@2
|
827 |
}
|
leo_sobral@2
|
828 |
|
leo_sobral@2
|
829 |
*size = src->content_size;
|
rosfran@289
|
830 |
GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
|
rosfran@289
|
831 |
|
rosfran@30
|
832 |
return ret;
|
rosfran@30
|
833 |
|
leo_sobral@2
|
834 |
}
|
leo_sobral@2
|
835 |
|
leo_sobral@2
|
836 |
/* close the socket and associated resources
|
leo_sobral@2
|
837 |
* used both to recover from errors and go to NULL state */
|
rosfran@52
|
838 |
static gboolean
|
leo_sobral@2
|
839 |
gst_mythtv_src_stop (GstBaseSrc * bsrc)
|
leo_sobral@2
|
840 |
{
|
rosfran@548
|
841 |
GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
|
rosfran@548
|
842 |
|
rosfran@548
|
843 |
gst_mythtv_src_clear (src);
|
leo_sobral@2
|
844 |
|
rosfran@548
|
845 |
/* src->eos = FALSE; */
|
leo_sobral@2
|
846 |
|
leo_sobral@2
|
847 |
return TRUE;
|
leo_sobral@2
|
848 |
}
|
leo_sobral@2
|
849 |
|
rosfran@30
|
850 |
static gboolean
|
leo_sobral@2
|
851 |
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
|
leo_sobral@2
|
852 |
{
|
leo_sobral@2
|
853 |
GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
|
rosfran@52
|
854 |
gint64 cont_size = 0;
|
rosfran@90
|
855 |
gboolean ret = FALSE;
|
leo_sobral@2
|
856 |
|
leo_sobral@2
|
857 |
switch (GST_EVENT_TYPE (event)) {
|
rosfran@30
|
858 |
case GST_EVENT_EOS:
|
rosfran@289
|
859 |
GST_WARNING_OBJECT (src, "Got EOS event");
|
rosfran@61
|
860 |
|
rosfran@289
|
861 |
if (src->live_tv) {
|
rosfran@289
|
862 |
cont_size = gst_mythtv_src_get_position (src);
|
rosfran@289
|
863 |
if (cont_size > src->content_size) {
|
rosfran@289
|
864 |
src->content_size = cont_size;
|
rosfran@289
|
865 |
src->eos = FALSE;
|
rosfran@289
|
866 |
} else {
|
rosfran@289
|
867 |
src->eos = TRUE;
|
rosfran@289
|
868 |
gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
|
rosfran@289
|
869 |
gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
|
rosfran@289
|
870 |
}
|
rosfran@114
|
871 |
}
|
rosfran@30
|
872 |
break;
|
leo_sobral@2
|
873 |
default:
|
rosfran@90
|
874 |
ret = gst_pad_event_default (pad, event);
|
leo_sobral@2
|
875 |
}
|
leo_sobral@2
|
876 |
|
rosfran@90
|
877 |
return ret;
|
leo_sobral@2
|
878 |
}
|
leo_sobral@2
|
879 |
|
rosfran@30
|
880 |
static gboolean
|
rosfran@289
|
881 |
gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
|
leo_sobral@2
|
882 |
{
|
rosfran@100
|
883 |
return TRUE;
|
leo_sobral@2
|
884 |
}
|
rosfran@87
|
885 |
|
rosfran@87
|
886 |
static gboolean
|
rosfran@87
|
887 |
gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
|
rosfran@87
|
888 |
{
|
rosfran@87
|
889 |
gboolean res = FALSE;
|
rosfran@87
|
890 |
GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
|
rosfran@114
|
891 |
GstFormat formt;
|
rosfran@87
|
892 |
|
rosfran@87
|
893 |
switch (GST_QUERY_TYPE (query)) {
|
rosfran@87
|
894 |
case GST_QUERY_POSITION:
|
rosfran@114
|
895 |
{
|
rosfran@289
|
896 |
gst_query_parse_position (query, &formt, NULL);
|
rosfran@289
|
897 |
if (formt == GST_FORMAT_BYTES) {
|
rosfran@289
|
898 |
gst_query_set_position (query, formt, myth->read_offset);
|
rosfran@289
|
899 |
GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
|
rosfran@289
|
900 |
res = TRUE;
|
rosfran@289
|
901 |
} else if (formt == GST_FORMAT_TIME) {
|
rosfran@289
|
902 |
res = gst_pad_query_default (pad, query);
|
rosfran@124
|
903 |
}
|
rosfran@87
|
904 |
break;
|
rosfran@114
|
905 |
}
|
rosfran@87
|
906 |
case GST_QUERY_DURATION:
|
rosfran@114
|
907 |
{
|
rosfran@87
|
908 |
#if 0
|
rosfran@87
|
909 |
if (myth->duration != 0) {
|
rosfran@289
|
910 |
gint64 total;
|
rosfran@289
|
911 |
gint64 fps;
|
rosfran@87
|
912 |
|
rosfran@289
|
913 |
fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
|
rosfran@289
|
914 |
total =
|
rosfran@289
|
915 |
gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
|
rosfran@114
|
916 |
}
|
rosfran@81
|
917 |
#endif
|
rosfran@289
|
918 |
|
rosfran@289
|
919 |
gst_query_parse_duration (query, &formt, NULL);
|
rosfran@289
|
920 |
if (formt == GST_FORMAT_BYTES) {
|
rosfran@289
|
921 |
gst_query_set_duration (query, formt, myth->content_size);
|
rosfran@289
|
922 |
GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, myth->content_size);
|
rosfran@289
|
923 |
res = TRUE;
|
rosfran@289
|
924 |
} else if (formt == GST_FORMAT_TIME) {
|
rosfran@289
|
925 |
res = gst_pad_query_default (pad, query);
|
rosfran@289
|
926 |
}
|
rosfran@70
|
927 |
break;
|
rosfran@114
|
928 |
}
|
rosfran@70
|
929 |
default:
|
rosfran@114
|
930 |
{
|
rosfran@289
|
931 |
res = gst_pad_query_default (pad, query);
|
rosfran@87
|
932 |
break;
|
rosfran@114
|
933 |
}
|
rosfran@70
|
934 |
}
|
rosfran@61
|
935 |
|
rosfran@87
|
936 |
gst_object_unref (myth);
|
rosfran@61
|
937 |
|
rosfran@70
|
938 |
return res;
|
rosfran@61
|
939 |
}
|
rosfran@61
|
940 |
|
rosfran@52
|
941 |
static GstStateChangeReturn
|
rosfran@52
|
942 |
gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
|
rosfran@52
|
943 |
{
|
rosfran@289
|
944 |
GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
|
rosfran@52
|
945 |
GstMythtvSrc *src = GST_MYTHTV_SRC (element);
|
rosfran@52
|
946 |
|
rosfran@52
|
947 |
switch (transition) {
|
rosfran@52
|
948 |
case GST_STATE_CHANGE_NULL_TO_READY:
|
rosfran@52
|
949 |
break;
|
rosfran@52
|
950 |
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
rosfran@52
|
951 |
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
rosfran@289
|
952 |
if (src->live_tv) {
|
rosfran@289
|
953 |
if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
|
rosfran@289
|
954 |
recorder))
|
rosfran@289
|
955 |
GST_WARNING_OBJECT (src,
|
rosfran@289
|
956 |
"Couldn't send the FRONTEND_READY message to the backend!");
|
rosfran@289
|
957 |
else
|
rosfran@289
|
958 |
GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
|
rosfran@124
|
959 |
}
|
rosfran@52
|
960 |
break;
|
rosfran@52
|
961 |
default:
|
rosfran@52
|
962 |
break;
|
rosfran@52
|
963 |
}
|
rosfran@61
|
964 |
|
rosfran@61
|
965 |
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
rosfran@52
|
966 |
if (ret == GST_STATE_CHANGE_FAILURE)
|
rosfran@52
|
967 |
return ret;
|
rosfran@52
|
968 |
|
rosfran@52
|
969 |
switch (transition) {
|
rosfran@52
|
970 |
case GST_STATE_CHANGE_READY_TO_NULL:
|
rosfran@52
|
971 |
break;
|
rosfran@61
|
972 |
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
rosfran@52
|
973 |
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
rosfran@61
|
974 |
break;
|
rosfran@52
|
975 |
default:
|
rosfran@52
|
976 |
break;
|
rosfran@52
|
977 |
}
|
rosfran@52
|
978 |
|
rosfran@52
|
979 |
return ret;
|
rosfran@52
|
980 |
}
|
rosfran@52
|
981 |
|
rosfran@30
|
982 |
static void
|
leo_sobral@2
|
983 |
gst_mythtv_src_set_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
984 |
const GValue * value, GParamSpec * pspec)
|
leo_sobral@2
|
985 |
{
|
leo_sobral@2
|
986 |
GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
|
leo_sobral@2
|
987 |
|
leo_sobral@2
|
988 |
GST_OBJECT_LOCK (mythtvsrc);
|
leo_sobral@2
|
989 |
switch (prop_id) {
|
leo_sobral@2
|
990 |
case PROP_LOCATION:
|
rosfran@289
|
991 |
{
|
rosfran@289
|
992 |
if (!g_value_get_string (value)) {
|
rosfran@289
|
993 |
GST_WARNING ("location property cannot be NULL");
|
leo_sobral@2
|
994 |
break;
|
leo_sobral@2
|
995 |
}
|
rosfran@289
|
996 |
|
rosfran@289
|
997 |
if (mythtvsrc->uri_name != NULL) {
|
rosfran@289
|
998 |
g_free (mythtvsrc->uri_name);
|
rosfran@289
|
999 |
mythtvsrc->uri_name = NULL;
|
rosfran@289
|
1000 |
}
|
rosfran@289
|
1001 |
mythtvsrc->uri_name = g_value_dup_string (value);
|
rosfran@289
|
1002 |
|
rosfran@289
|
1003 |
break;
|
rosfran@289
|
1004 |
}
|
leo_sobral@2
|
1005 |
#ifndef GST_DISABLE_GST_DEBUG
|
rosfran@40
|
1006 |
case PROP_GMYTHTV_DBG:
|
rosfran@289
|
1007 |
{
|
rosfran@289
|
1008 |
mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
|
rosfran@289
|
1009 |
break;
|
rosfran@289
|
1010 |
}
|
rosfran@289
|
1011 |
#endif
|
rosfran@289
|
1012 |
case PROP_GMYTHTV_VERSION:
|
rosfran@289
|
1013 |
{
|
rosfran@289
|
1014 |
mythtvsrc->mythtv_version = g_value_get_int (value);
|
rosfran@289
|
1015 |
break;
|
rosfran@289
|
1016 |
}
|
rosfran@289
|
1017 |
case PROP_GMYTHTV_LIVEID:
|
rosfran@289
|
1018 |
{
|
rosfran@289
|
1019 |
mythtvsrc->live_tv_id = g_value_get_int (value);
|
rosfran@289
|
1020 |
break;
|
rosfran@289
|
1021 |
}
|
rosfran@289
|
1022 |
case PROP_GMYTHTV_LIVE:
|
rosfran@289
|
1023 |
{
|
rosfran@289
|
1024 |
mythtvsrc->live_tv = g_value_get_boolean (value);
|
rosfran@289
|
1025 |
break;
|
rosfran@289
|
1026 |
}
|
rosfran@289
|
1027 |
case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
|
rosfran@289
|
1028 |
{
|
rosfran@289
|
1029 |
mythtvsrc->enable_timing_position = g_value_get_boolean (value);
|
rosfran@289
|
1030 |
break;
|
rosfran@289
|
1031 |
}
|
rosfran@289
|
1032 |
case PROP_GMYTHTV_LIVE_CHAINID:
|
rosfran@289
|
1033 |
{
|
rosfran@289
|
1034 |
if (!g_value_get_string (value)) {
|
rosfran@289
|
1035 |
GST_WARNING ("MythTV Live chainid property cannot be NULL");
|
leo_sobral@2
|
1036 |
break;
|
leo_sobral@2
|
1037 |
}
|
rosfran@289
|
1038 |
|
rosfran@289
|
1039 |
if (mythtvsrc->live_chain_id != NULL) {
|
rosfran@289
|
1040 |
g_free (mythtvsrc->live_chain_id);
|
rosfran@289
|
1041 |
mythtvsrc->live_chain_id = NULL;
|
leo_sobral@2
|
1042 |
}
|
rosfran@289
|
1043 |
mythtvsrc->live_chain_id = g_value_dup_string (value);
|
rosfran@289
|
1044 |
break;
|
rosfran@289
|
1045 |
}
|
rosfran@70
|
1046 |
case PROP_GMYTHTV_CHANNEL_NUM:
|
rosfran@289
|
1047 |
{
|
rosfran@308
|
1048 |
mythtvsrc->channel_name = g_value_dup_string (value);
|
rosfran@289
|
1049 |
break;
|
rosfran@289
|
1050 |
}
|
leo_sobral@2
|
1051 |
default:
|
leo_sobral@2
|
1052 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
leo_sobral@2
|
1053 |
break;
|
leo_sobral@2
|
1054 |
}
|
rosfran@289
|
1055 |
|
leo_sobral@2
|
1056 |
GST_OBJECT_UNLOCK (mythtvsrc);
|
leo_sobral@2
|
1057 |
}
|
leo_sobral@2
|
1058 |
|
rosfran@100
|
1059 |
static void
|
leo_sobral@2
|
1060 |
gst_mythtv_src_get_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
1061 |
GValue * value, GParamSpec * pspec)
|
leo_sobral@2
|
1062 |
{
|
leo_sobral@2
|
1063 |
GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
|
leo_sobral@2
|
1064 |
|
leo_sobral@2
|
1065 |
GST_OBJECT_LOCK (mythtvsrc);
|
leo_sobral@2
|
1066 |
switch (prop_id) {
|
leo_sobral@2
|
1067 |
case PROP_LOCATION:
|
rosfran@289
|
1068 |
{
|
rosfran@528
|
1069 |
g_value_set_string (value, mythtvsrc->uri_name);
|
rosfran@289
|
1070 |
break;
|
rosfran@289
|
1071 |
}
|
leo_sobral@2
|
1072 |
#ifndef GST_DISABLE_GST_DEBUG
|
rosfran@40
|
1073 |
case PROP_GMYTHTV_DBG:
|
rosfran@289
|
1074 |
g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
|
leo_sobral@2
|
1075 |
break;
|
leo_sobral@2
|
1076 |
#endif
|
rosfran@40
|
1077 |
case PROP_GMYTHTV_VERSION:
|
rosfran@289
|
1078 |
{
|
rosfran@289
|
1079 |
g_value_set_int (value, mythtvsrc->mythtv_version);
|
rosfran@289
|
1080 |
break;
|
rosfran@289
|
1081 |
}
|
rosfran@40
|
1082 |
case PROP_GMYTHTV_LIVEID:
|
rosfran@289
|
1083 |
{
|
rosfran@289
|
1084 |
g_value_set_int (value, mythtvsrc->live_tv_id);
|
rosfran@289
|
1085 |
break;
|
rosfran@289
|
1086 |
}
|
rosfran@40
|
1087 |
case PROP_GMYTHTV_LIVE:
|
rosfran@289
|
1088 |
g_value_set_boolean (value, mythtvsrc->live_tv);
|
leo_sobral@2
|
1089 |
break;
|
rosfran@52
|
1090 |
case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
|
rosfran@289
|
1091 |
g_value_set_boolean (value, mythtvsrc->enable_timing_position);
|
rosfran@52
|
1092 |
break;
|
rosfran@40
|
1093 |
case PROP_GMYTHTV_LIVE_CHAINID:
|
rosfran@289
|
1094 |
{
|
rosfran@528
|
1095 |
g_value_set_string (value, mythtvsrc->live_chain_id);
|
rosfran@289
|
1096 |
break;
|
rosfran@289
|
1097 |
}
|
rosfran@70
|
1098 |
case PROP_GMYTHTV_CHANNEL_NUM:
|
rosfran@289
|
1099 |
{
|
rosfran@308
|
1100 |
g_value_set_string (value, mythtvsrc->channel_name);
|
rosfran@289
|
1101 |
break;
|
rosfran@289
|
1102 |
}
|
leo_sobral@2
|
1103 |
default:
|
leo_sobral@2
|
1104 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
leo_sobral@2
|
1105 |
break;
|
leo_sobral@2
|
1106 |
}
|
leo_sobral@2
|
1107 |
GST_OBJECT_UNLOCK (mythtvsrc);
|
leo_sobral@2
|
1108 |
}
|
leo_sobral@2
|
1109 |
|
rosfran@40
|
1110 |
static gboolean
|
leo_sobral@2
|
1111 |
plugin_init (GstPlugin * plugin)
|
leo_sobral@2
|
1112 |
{
|
leo_sobral@2
|
1113 |
return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
|
leo_sobral@2
|
1114 |
GST_TYPE_MYTHTV_SRC);
|
leo_sobral@2
|
1115 |
}
|
leo_sobral@2
|
1116 |
|
leo_sobral@2
|
1117 |
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
leo_sobral@2
|
1118 |
GST_VERSION_MINOR,
|
leo_sobral@2
|
1119 |
"mythtv",
|
leo_sobral@2
|
1120 |
"lib MythTV src",
|
rosfran@312
|
1121 |
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|
leo_sobral@2
|
1122 |
|
leo_sobral@2
|
1123 |
|
leo_sobral@2
|
1124 |
/*** GSTURIHANDLER INTERFACE *************************************************/
|
rosfran@289
|
1125 |
static guint
|
leo_sobral@2
|
1126 |
gst_mythtv_src_uri_get_type (void)
|
leo_sobral@2
|
1127 |
{
|
leo_sobral@2
|
1128 |
return GST_URI_SRC;
|
leo_sobral@2
|
1129 |
}
|
leo_sobral@2
|
1130 |
|
rosfran@289
|
1131 |
static gchar **
|
leo_sobral@2
|
1132 |
gst_mythtv_src_uri_get_protocols (void)
|
leo_sobral@2
|
1133 |
{
|
leo_sobral@2
|
1134 |
static gchar *protocols[] = { "myth", "myths", NULL };
|
leo_sobral@2
|
1135 |
|
leo_sobral@2
|
1136 |
return protocols;
|
leo_sobral@2
|
1137 |
}
|
leo_sobral@2
|
1138 |
|
rosfran@289
|
1139 |
static const gchar *
|
leo_sobral@2
|
1140 |
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
|
leo_sobral@2
|
1141 |
{
|
leo_sobral@2
|
1142 |
GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
|
leo_sobral@2
|
1143 |
|
leo_sobral@2
|
1144 |
return src->uri_name;
|
leo_sobral@2
|
1145 |
}
|
leo_sobral@2
|
1146 |
|
rosfran@289
|
1147 |
static gboolean
|
leo_sobral@2
|
1148 |
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
|
leo_sobral@2
|
1149 |
{
|
leo_sobral@2
|
1150 |
GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
|
leo_sobral@2
|
1151 |
|
leo_sobral@2
|
1152 |
gchar *protocol;
|
leo_sobral@2
|
1153 |
|
leo_sobral@2
|
1154 |
protocol = gst_uri_get_protocol (uri);
|
leo_sobral@2
|
1155 |
if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
|
leo_sobral@2
|
1156 |
g_free (protocol);
|
leo_sobral@2
|
1157 |
return FALSE;
|
leo_sobral@2
|
1158 |
}
|
leo_sobral@2
|
1159 |
g_free (protocol);
|
leo_sobral@2
|
1160 |
g_object_set (src, "location", uri, NULL);
|
leo_sobral@2
|
1161 |
|
leo_sobral@2
|
1162 |
return TRUE;
|
leo_sobral@2
|
1163 |
}
|
leo_sobral@2
|
1164 |
|
rosfran@289
|
1165 |
static void
|
leo_sobral@2
|
1166 |
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
leo_sobral@2
|
1167 |
{
|
leo_sobral@2
|
1168 |
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
leo_sobral@2
|
1169 |
|
leo_sobral@2
|
1170 |
iface->get_type = gst_mythtv_src_uri_get_type;
|
leo_sobral@2
|
1171 |
iface->get_protocols = gst_mythtv_src_uri_get_protocols;
|
leo_sobral@2
|
1172 |
iface->get_uri = gst_mythtv_src_uri_get_uri;
|
leo_sobral@2
|
1173 |
iface->set_uri = gst_mythtv_src_uri_set_uri;
|
leo_sobral@2
|
1174 |
}
|
leo_sobral@2
|
1175 |
|
rosfran@289
|
1176 |
void
|
leo_sobral@2
|
1177 |
size_header_handler (void *userdata, const char *value)
|
leo_sobral@2
|
1178 |
{
|
leo_sobral@2
|
1179 |
GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
|
leo_sobral@2
|
1180 |
|
leo_sobral@2
|
1181 |
GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
|
leo_sobral@2
|
1182 |
}
|