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