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"
|
leo_sobral@2
|
21 |
#include "myth_file_transfer.h"
|
leo_sobral@2
|
22 |
#include "myth_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 |
|
leo_sobral@2
|
33 |
#define GST_MYTHTV_ID_NUM 1
|
leo_sobral@2
|
34 |
|
leo_sobral@2
|
35 |
#define MYTHTV_VERSION_DEFAULT 30
|
leo_sobral@2
|
36 |
|
leo_sobral@2
|
37 |
#define MYTHTV_TRANSFER_MAX_WAITS 100
|
leo_sobral@2
|
38 |
|
rosfran@34
|
39 |
#define MYTHTV_TRANSFER_MAX_BUFFER 1024*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 |
|
rosfran@34
|
46 |
#define ENABLE_TIMING_POSITION 0
|
leo_sobral@2
|
47 |
|
leo_sobral@2
|
48 |
/* stablish a maximum iteration value to the IS_RECORDING message */
|
leo_sobral@2
|
49 |
static guint wait_to_transfer = 0;
|
leo_sobral@2
|
50 |
|
leo_sobral@2
|
51 |
static const GstElementDetails gst_mythtv_src_details =
|
rosfran@30
|
52 |
GST_ELEMENT_DETAILS ( "MythTV client source",
|
leo_sobral@2
|
53 |
"Source/Network",
|
leo_sobral@2
|
54 |
"Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
|
rosfran@30
|
55 |
"Rosfran Borges <rosfran.borges@indt.org.br>" );
|
leo_sobral@2
|
56 |
|
leo_sobral@2
|
57 |
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
leo_sobral@2
|
58 |
GST_PAD_SRC,
|
leo_sobral@2
|
59 |
GST_PAD_ALWAYS,
|
rosfran@30
|
60 |
GST_STATIC_CAPS ("video/x-nuv") );
|
rosfran@30
|
61 |
//GST_STATIC_CAPS_ANY);
|
rosfran@30
|
62 |
|
rosfran@30
|
63 |
static GThread *update_size_task = NULL;
|
rosfran@30
|
64 |
|
rosfran@30
|
65 |
static GStaticMutex update_size_mutex = G_STATIC_MUTEX_INIT;
|
leo_sobral@2
|
66 |
|
leo_sobral@2
|
67 |
enum
|
leo_sobral@2
|
68 |
{
|
leo_sobral@2
|
69 |
PROP_0,
|
leo_sobral@2
|
70 |
PROP_LOCATION,
|
leo_sobral@2
|
71 |
PROP_URI,
|
leo_sobral@2
|
72 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
73 |
PROP_MYTHTV_DBG,
|
leo_sobral@2
|
74 |
#endif
|
leo_sobral@2
|
75 |
PROP_MYTHTV_VERSION,
|
leo_sobral@2
|
76 |
PROP_MYTHTV_LIVE,
|
leo_sobral@2
|
77 |
PROP_MYTHTV_LIVEID,
|
leo_sobral@2
|
78 |
PROP_MYTHTV_LIVE_CHAINID
|
leo_sobral@2
|
79 |
};
|
leo_sobral@2
|
80 |
|
leo_sobral@2
|
81 |
static void gst_mythtv_src_finalize (GObject * gobject);
|
leo_sobral@2
|
82 |
|
rosfran@30
|
83 |
static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
|
rosfran@30
|
84 |
guint size, GstBuffer ** outbuf);
|
rosfran@30
|
85 |
//static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf);
|
leo_sobral@2
|
86 |
static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
|
leo_sobral@2
|
87 |
static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
|
leo_sobral@2
|
88 |
static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
|
rosfran@30
|
89 |
static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
|
rosfran@30
|
90 |
//static gboolean gst_mythtv_new_segment ( GstBaseSrc * psrc );
|
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 GstFlowReturn gst_mythtv_src_chain (GstPad * pad, GstBuffer * buf);
|
leo_sobral@2
|
98 |
|
rosfran@30
|
99 |
static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
|
rosfran@30
|
100 |
|
rosfran@31
|
101 |
static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
|
rosfran@30
|
102 |
//static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
|
rosfran@30
|
103 |
|
rosfran@30
|
104 |
static guint do_read_request_response (GstMythtvSrc *src, guint64 offset,
|
rosfran@30
|
105 |
guint size, GstBuffer **outbuf);
|
rosfran@30
|
106 |
//static gboolean gst_mythtv_src_sink_activate_pull (GstPad * srcpad, gboolean active);
|
leo_sobral@2
|
107 |
|
leo_sobral@2
|
108 |
static void
|
leo_sobral@2
|
109 |
_urihandler_init (GType type)
|
leo_sobral@2
|
110 |
{
|
leo_sobral@2
|
111 |
static const GInterfaceInfo urihandler_info = {
|
leo_sobral@2
|
112 |
gst_mythtv_src_uri_handler_init,
|
leo_sobral@2
|
113 |
NULL,
|
leo_sobral@2
|
114 |
NULL
|
leo_sobral@2
|
115 |
};
|
leo_sobral@2
|
116 |
|
leo_sobral@2
|
117 |
g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
|
leo_sobral@2
|
118 |
|
leo_sobral@2
|
119 |
GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
|
leo_sobral@2
|
120 |
"MythTV src");
|
leo_sobral@2
|
121 |
}
|
leo_sobral@2
|
122 |
|
leo_sobral@2
|
123 |
GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
|
rosfran@30
|
124 |
GST_TYPE_BASE_SRC, _urihandler_init)
|
rosfran@30
|
125 |
|
rosfran@30
|
126 |
//GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
|
rosfran@30
|
127 |
// GST_TYPE_PUSH_SRC, _urihandler_init)
|
rosfran@30
|
128 |
|
leo_sobral@2
|
129 |
static void
|
leo_sobral@2
|
130 |
gst_mythtv_src_base_init (gpointer g_class)
|
leo_sobral@2
|
131 |
{
|
leo_sobral@2
|
132 |
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
leo_sobral@2
|
133 |
|
leo_sobral@2
|
134 |
gst_element_class_add_pad_template (element_class,
|
leo_sobral@2
|
135 |
gst_static_pad_template_get (&srctemplate));
|
leo_sobral@2
|
136 |
|
leo_sobral@2
|
137 |
gst_element_class_set_details (element_class, &gst_mythtv_src_details);
|
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;
|
rosfran@30
|
149 |
//gstpushsrc_class = (GstPushSrcClass *) klass;
|
leo_sobral@2
|
150 |
|
leo_sobral@2
|
151 |
gobject_class->set_property = gst_mythtv_src_set_property;
|
leo_sobral@2
|
152 |
gobject_class->get_property = gst_mythtv_src_get_property;
|
leo_sobral@2
|
153 |
gobject_class->finalize = gst_mythtv_src_finalize;
|
leo_sobral@2
|
154 |
|
leo_sobral@2
|
155 |
g_object_class_install_property
|
leo_sobral@2
|
156 |
(gobject_class, PROP_LOCATION,
|
leo_sobral@2
|
157 |
g_param_spec_string ("location", "Location",
|
leo_sobral@2
|
158 |
"The location. In the form:"
|
leo_sobral@2
|
159 |
"\n\t\t\tmyth://a.com/file.nuv"
|
leo_sobral@2
|
160 |
"\n\t\t\tmyth://a.com:23223/file.nuv "
|
leo_sobral@2
|
161 |
"\n\t\t\ta.com/file.nuv - default scheme 'myth'",
|
leo_sobral@2
|
162 |
"", G_PARAM_READWRITE));
|
leo_sobral@2
|
163 |
|
leo_sobral@2
|
164 |
g_object_class_install_property
|
leo_sobral@2
|
165 |
(gobject_class, PROP_URI,
|
leo_sobral@2
|
166 |
g_param_spec_string ("uri", "Uri",
|
leo_sobral@2
|
167 |
"The location in form of a URI (deprecated; use location)",
|
leo_sobral@2
|
168 |
"", G_PARAM_READWRITE));
|
leo_sobral@2
|
169 |
|
leo_sobral@2
|
170 |
g_object_class_install_property
|
leo_sobral@2
|
171 |
(gobject_class, PROP_MYTHTV_VERSION,
|
leo_sobral@2
|
172 |
g_param_spec_int ("mythtv-version", "mythtv-version",
|
leo_sobral@2
|
173 |
"Change Myth TV version",
|
leo_sobral@2
|
174 |
26, 30, 26, G_PARAM_READWRITE));
|
leo_sobral@2
|
175 |
|
leo_sobral@2
|
176 |
g_object_class_install_property
|
leo_sobral@2
|
177 |
(gobject_class, PROP_MYTHTV_LIVEID,
|
leo_sobral@2
|
178 |
g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
|
leo_sobral@2
|
179 |
"Change Myth TV version",
|
leo_sobral@2
|
180 |
0, 200, GST_MYTHTV_ID_NUM, G_PARAM_READWRITE));
|
leo_sobral@2
|
181 |
|
leo_sobral@2
|
182 |
g_object_class_install_property
|
leo_sobral@2
|
183 |
(gobject_class, PROP_MYTHTV_LIVE_CHAINID,
|
leo_sobral@2
|
184 |
g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
|
leo_sobral@2
|
185 |
"Sets the Myth TV chain ID (from TV Chain)",
|
leo_sobral@2
|
186 |
"", G_PARAM_READWRITE));
|
leo_sobral@2
|
187 |
|
leo_sobral@2
|
188 |
g_object_class_install_property
|
leo_sobral@2
|
189 |
(gobject_class, PROP_MYTHTV_LIVE,
|
leo_sobral@2
|
190 |
g_param_spec_boolean ("mythtv-live", "mythtv-live",
|
leo_sobral@2
|
191 |
"Enable MythTV Live TV content streaming",
|
leo_sobral@2
|
192 |
FALSE, G_PARAM_READWRITE));
|
leo_sobral@2
|
193 |
|
leo_sobral@2
|
194 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
195 |
g_object_class_install_property
|
leo_sobral@2
|
196 |
(gobject_class, PROP_MYTHTV_DBG,
|
leo_sobral@2
|
197 |
g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
|
leo_sobral@2
|
198 |
"Enable MythTV debug messages",
|
leo_sobral@2
|
199 |
FALSE, G_PARAM_READWRITE));
|
leo_sobral@2
|
200 |
#endif
|
leo_sobral@2
|
201 |
|
leo_sobral@2
|
202 |
gstbasesrc_class->start = gst_mythtv_src_start;
|
leo_sobral@2
|
203 |
gstbasesrc_class->stop = gst_mythtv_src_stop;
|
leo_sobral@2
|
204 |
gstbasesrc_class->get_size = gst_mythtv_src_get_size;
|
leo_sobral@2
|
205 |
gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
|
rosfran@30
|
206 |
//gstpushsrc_class->newsegment = gst_mythtv_src_new_segment;
|
leo_sobral@2
|
207 |
|
leo_sobral@2
|
208 |
gstbasesrc_class->create = gst_mythtv_src_create;
|
rosfran@30
|
209 |
|
leo_sobral@2
|
210 |
GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
|
leo_sobral@2
|
211 |
"MythTV Client Source");
|
leo_sobral@2
|
212 |
}
|
leo_sobral@2
|
213 |
|
rosfran@30
|
214 |
static void
|
leo_sobral@2
|
215 |
gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
|
leo_sobral@2
|
216 |
{
|
leo_sobral@2
|
217 |
this->file_transfer = NULL;
|
leo_sobral@2
|
218 |
|
leo_sobral@2
|
219 |
this->unique_setup = FALSE;
|
leo_sobral@2
|
220 |
|
leo_sobral@2
|
221 |
this->mythtv_version = MYTHTV_VERSION_DEFAULT;
|
leo_sobral@2
|
222 |
|
leo_sobral@2
|
223 |
this->bytes_read = 0;
|
leo_sobral@2
|
224 |
|
leo_sobral@2
|
225 |
this->content_size = -1;
|
leo_sobral@2
|
226 |
this->read_offset = 0;
|
leo_sobral@2
|
227 |
|
leo_sobral@2
|
228 |
this->live_tv = FALSE;
|
leo_sobral@2
|
229 |
|
leo_sobral@2
|
230 |
this->user_agent = g_strdup ("mythtvsrc");
|
rosfran@30
|
231 |
this->mythtv_caps = NULL;
|
rosfran@30
|
232 |
|
rosfran@30
|
233 |
gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
|
leo_sobral@2
|
234 |
|
rosfran@30
|
235 |
gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
|
rosfran@30
|
236 |
|
rosfran@30
|
237 |
//gst_pad_set_chain_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
|
rosfran@30
|
238 |
// gst_mythtv_src_chain );
|
rosfran@30
|
239 |
|
rosfran@30
|
240 |
gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
|
rosfran@30
|
241 |
gst_mythtv_src_handle_event );
|
rosfran@31
|
242 |
/*
|
rosfran@30
|
243 |
gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
|
rosfran@30
|
244 |
gst_mythtv_src_query );
|
rosfran@30
|
245 |
*/
|
rosfran@30
|
246 |
//gst_pad_set_activatepull_function( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
|
rosfran@30
|
247 |
// gst_mythtv_src_sink_activate_pull );
|
rosfran@30
|
248 |
|
leo_sobral@2
|
249 |
}
|
leo_sobral@2
|
250 |
|
rosfran@30
|
251 |
static void
|
leo_sobral@2
|
252 |
gst_mythtv_src_finalize (GObject * gobject)
|
leo_sobral@2
|
253 |
{
|
leo_sobral@2
|
254 |
GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
|
leo_sobral@2
|
255 |
|
leo_sobral@2
|
256 |
g_free (this->user_agent);
|
leo_sobral@2
|
257 |
|
leo_sobral@2
|
258 |
if (this->mythtv_caps) {
|
leo_sobral@2
|
259 |
gst_caps_unref (this->mythtv_caps);
|
leo_sobral@2
|
260 |
this->mythtv_caps = NULL;
|
leo_sobral@2
|
261 |
}
|
leo_sobral@2
|
262 |
|
leo_sobral@2
|
263 |
if (this->file_transfer) {
|
leo_sobral@2
|
264 |
g_object_unref (this->file_transfer);
|
leo_sobral@2
|
265 |
this->file_transfer = NULL;
|
leo_sobral@2
|
266 |
}
|
leo_sobral@2
|
267 |
|
leo_sobral@2
|
268 |
if (this->uri_name) {
|
leo_sobral@2
|
269 |
g_free (this->uri_name);
|
leo_sobral@2
|
270 |
}
|
leo_sobral@2
|
271 |
|
leo_sobral@2
|
272 |
if (this->user_agent) {
|
leo_sobral@2
|
273 |
g_free (this->user_agent);
|
leo_sobral@2
|
274 |
}
|
leo_sobral@2
|
275 |
|
leo_sobral@2
|
276 |
G_OBJECT_CLASS (parent_class)->finalize (gobject);
|
leo_sobral@2
|
277 |
}
|
leo_sobral@2
|
278 |
|
rosfran@30
|
279 |
static guint
|
rosfran@30
|
280 |
do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
|
leo_sobral@2
|
281 |
{
|
leo_sobral@2
|
282 |
guint read = 0;
|
leo_sobral@2
|
283 |
guint sizetoread = size; //GST_BUFFER_SIZE (outbuf);
|
rosfran@31
|
284 |
//GstBuffer *buffer = gst_buffer_new_and_alloc( size );
|
leo_sobral@2
|
285 |
|
rosfran@30
|
286 |
g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
|
leo_sobral@2
|
287 |
|
rosfran@30
|
288 |
/* Loop sending the Myth File Transfer request:
|
leo_sobral@2
|
289 |
* Retry whilst authentication fails and we supply it. */
|
rosfran@30
|
290 |
guint len = 0;
|
leo_sobral@2
|
291 |
|
rosfran@34
|
292 |
//GST_OBJECT_LOCK(src);
|
leo_sobral@2
|
293 |
|
leo_sobral@2
|
294 |
while ( sizetoread > 0 ) {
|
rosfran@31
|
295 |
|
rosfran@31
|
296 |
len = myth_file_transfer_read( src->file_transfer,
|
rosfran@31
|
297 |
GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
|
leo_sobral@2
|
298 |
|
leo_sobral@2
|
299 |
if ( len > 0 ) {
|
rosfran@34
|
300 |
read += len;
|
leo_sobral@2
|
301 |
sizetoread -= len;
|
rosfran@30
|
302 |
} else if ( len <= 0 ) {
|
rosfran@30
|
303 |
|
rosfran@30
|
304 |
if ( src->live_tv == FALSE ) {
|
rosfran@30
|
305 |
goto done;
|
rosfran@34
|
306 |
} else if ( /*src->content_size >= src->read_offset &&
|
rosfran@34
|
307 |
abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
|
rosfran@34
|
308 |
( src->content_size <= ( src->read_offset + size + MYTHTV_TRANSFER_MAX_BUFFER ) ) )
|
rosfran@34
|
309 |
{
|
rosfran@34
|
310 |
#if ENABLE_TIMING_POSITION == 1
|
rosfran@34
|
311 |
guint64 size_tmp = 0;
|
rosfran@34
|
312 |
if (src->live_tv == TRUE) {
|
rosfran@34
|
313 |
get_file_pos:
|
rosfran@34
|
314 |
size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@34
|
315 |
if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
|
rosfran@34
|
316 |
src->content_size = size_tmp;
|
rosfran@34
|
317 |
else
|
rosfran@34
|
318 |
goto get_file_pos;
|
rosfran@34
|
319 |
g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
|
rosfran@34
|
320 |
__FUNCTION__, size_tmp );
|
rosfran@34
|
321 |
}
|
rosfran@34
|
322 |
#else
|
rosfran@34
|
323 |
guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@34
|
324 |
if ( src->content_size < new_offset ) {
|
rosfran@34
|
325 |
src->content_size = new_offset;
|
rosfran@34
|
326 |
}
|
rosfran@34
|
327 |
#endif
|
rosfran@34
|
328 |
goto done;
|
rosfran@34
|
329 |
}
|
rosfran@30
|
330 |
|
leo_sobral@2
|
331 |
}
|
rosfran@31
|
332 |
|
rosfran@30
|
333 |
if ( read == sizetoread )
|
leo_sobral@2
|
334 |
break;
|
leo_sobral@2
|
335 |
}
|
rosfran@30
|
336 |
|
leo_sobral@2
|
337 |
if ( read > 0 ) {
|
rosfran@34
|
338 |
src->read_offset += read;
|
leo_sobral@2
|
339 |
src->bytes_read += read;
|
rosfran@31
|
340 |
|
leo_sobral@2
|
341 |
g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
|
leo_sobral@2
|
342 |
"OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
|
leo_sobral@2
|
343 |
src->read_offset, src->content_size );
|
rosfran@31
|
344 |
|
rosfran@31
|
345 |
//GST_BUFFER_TIMESTAMP( buffer ) = GST_BUFFER_TIMESTAMP ( *outbuf );
|
rosfran@31
|
346 |
GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
|
rosfran@31
|
347 |
GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
|
rosfran@31
|
348 |
GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
|
rosfran@31
|
349 |
//*outbuf = buffer;
|
rosfran@31
|
350 |
//memcpy( GST_BUFFER_DATA( *outbuf ), GST_BUFFER_DATA( buffer ), read );
|
rosfran@30
|
351 |
|
rosfran@30
|
352 |
g_print( "Stopping: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
|
rosfran@30
|
353 |
"OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
|
rosfran@30
|
354 |
GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
|
rosfran@31
|
355 |
|
rosfran@34
|
356 |
} else if ( !src->live_tv )
|
rosfran@31
|
357 |
goto eos;
|
rosfran@31
|
358 |
|
rosfran@30
|
359 |
goto done;
|
leo_sobral@2
|
360 |
|
leo_sobral@2
|
361 |
eos:
|
rosfran@31
|
362 |
//GST_OBJECT_UNLOCK(src);
|
leo_sobral@2
|
363 |
src->eos = TRUE;
|
rosfran@30
|
364 |
|
leo_sobral@2
|
365 |
done:
|
rosfran@34
|
366 |
//GST_OBJECT_UNLOCK(src);
|
leo_sobral@2
|
367 |
|
leo_sobral@2
|
368 |
return read;
|
leo_sobral@2
|
369 |
}
|
leo_sobral@2
|
370 |
|
rosfran@30
|
371 |
static GstFlowReturn
|
rosfran@30
|
372 |
gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
|
leo_sobral@2
|
373 |
{
|
leo_sobral@2
|
374 |
GstMythtvSrc *src;
|
leo_sobral@2
|
375 |
GstFlowReturn ret = GST_FLOW_OK;
|
rosfran@30
|
376 |
guint read = 0;
|
rosfran@30
|
377 |
|
rosfran@30
|
378 |
src = GST_MYTHTV_SRC (psrc);
|
rosfran@31
|
379 |
/* The caller should know the number of bytes and not read beyond EOS. */
|
rosfran@31
|
380 |
if (G_UNLIKELY (src->eos))
|
rosfran@31
|
381 |
goto eos;
|
rosfran@30
|
382 |
|
rosfran@31
|
383 |
//GST_OBJECT_LOCK(src);
|
leo_sobral@2
|
384 |
|
rosfran@30
|
385 |
if (G_UNLIKELY (src->read_offset != offset)) {
|
rosfran@30
|
386 |
guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
|
rosfran@34
|
387 |
g_print( "[%s] SRC Offset = %llu, NEW actual backend SEEK Offset = %llu.\n",
|
rosfran@34
|
388 |
__FUNCTION__, src->read_offset, new_offset );
|
rosfran@34
|
389 |
if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
|
rosfran@34
|
390 |
{
|
rosfran@31
|
391 |
//GST_OBJECT_UNLOCK(src);
|
rosfran@30
|
392 |
goto read_error;
|
rosfran@31
|
393 |
}
|
leo_sobral@2
|
394 |
|
rosfran@30
|
395 |
src->read_offset = offset;
|
rosfran@30
|
396 |
}
|
rosfran@31
|
397 |
//GST_OBJECT_UNLOCK(src);
|
rosfran@30
|
398 |
|
rosfran@31
|
399 |
/* Create the buffer. */
|
rosfran@31
|
400 |
ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
|
rosfran@31
|
401 |
src->read_offset, size,
|
rosfran@31
|
402 |
//src->icy_caps ? src->icy_caps :
|
rosfran@31
|
403 |
GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf);
|
leo_sobral@2
|
404 |
|
rosfran@31
|
405 |
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
rosfran@31
|
406 |
goto done;
|
rosfran@30
|
407 |
|
rosfran@31
|
408 |
//g_static_mutex_lock( &update_size_mutex );
|
rosfran@31
|
409 |
read = do_read_request_response ( src, src->read_offset, size, outbuf );
|
rosfran@31
|
410 |
//g_static_mutex_unlock( &update_size_mutex );
|
leo_sobral@2
|
411 |
|
rosfran@31
|
412 |
if (G_UNLIKELY (read < 0) || *outbuf == NULL) {
|
rosfran@31
|
413 |
//if ( src->live_tv )
|
rosfran@31
|
414 |
// goto done;
|
rosfran@31
|
415 |
//else
|
leo_sobral@2
|
416 |
goto read_error;
|
rosfran@31
|
417 |
}
|
leo_sobral@2
|
418 |
|
rosfran@31
|
419 |
/*
|
leo_sobral@2
|
420 |
if (G_UNLIKELY(src->eos))
|
leo_sobral@2
|
421 |
goto eos;
|
rosfran@30
|
422 |
else
|
rosfran@30
|
423 |
goto done;
|
rosfran@31
|
424 |
*/
|
leo_sobral@2
|
425 |
|
leo_sobral@2
|
426 |
done:
|
rosfran@31
|
427 |
{
|
rosfran@31
|
428 |
const gchar *reason = gst_flow_get_name (ret);
|
rosfran@31
|
429 |
|
rosfran@31
|
430 |
GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
|
rosfran@31
|
431 |
return ret;
|
rosfran@31
|
432 |
}
|
leo_sobral@2
|
433 |
eos:
|
leo_sobral@2
|
434 |
{
|
rosfran@30
|
435 |
const gchar *reason = gst_flow_get_name (ret);
|
rosfran@30
|
436 |
|
rosfran@30
|
437 |
GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
|
leo_sobral@2
|
438 |
return GST_FLOW_UNEXPECTED;
|
leo_sobral@2
|
439 |
}
|
leo_sobral@2
|
440 |
/* ERRORS */
|
leo_sobral@2
|
441 |
read_error:
|
leo_sobral@2
|
442 |
{
|
leo_sobral@2
|
443 |
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
leo_sobral@2
|
444 |
(NULL), ("Could not read any bytes (%i, %s)", read,
|
leo_sobral@2
|
445 |
src->uri_name));
|
leo_sobral@2
|
446 |
return GST_FLOW_ERROR;
|
leo_sobral@2
|
447 |
}
|
rosfran@30
|
448 |
|
leo_sobral@2
|
449 |
}
|
leo_sobral@2
|
450 |
|
rosfran@30
|
451 |
void
|
rosfran@30
|
452 |
update_size_func( void *mythtv_data )
|
leo_sobral@2
|
453 |
{
|
rosfran@30
|
454 |
GstMythtvSrc *src;
|
leo_sobral@2
|
455 |
|
rosfran@30
|
456 |
g_return_if_fail( mythtv_data != NULL );
|
leo_sobral@2
|
457 |
|
rosfran@30
|
458 |
src = GST_MYTHTV_SRC ( mythtv_data );
|
rosfran@30
|
459 |
|
rosfran@30
|
460 |
g_static_mutex_lock( &update_size_mutex );
|
rosfran@30
|
461 |
|
rosfran@30
|
462 |
if ( src->do_start ) {
|
rosfran@30
|
463 |
#if ENABLE_TIMING_POSITION == 1
|
rosfran@30
|
464 |
guint64 size_tmp = 0;
|
rosfran@30
|
465 |
if (src->live_tv == TRUE) {
|
rosfran@30
|
466 |
get_file_pos:
|
rosfran@30
|
467 |
g_usleep( 50 );
|
rosfran@30
|
468 |
size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@30
|
469 |
if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
|
rosfran@30
|
470 |
src->content_size = size_tmp;
|
rosfran@30
|
471 |
else
|
rosfran@30
|
472 |
goto get_file_pos;
|
rosfran@30
|
473 |
g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
|
rosfran@30
|
474 |
__FUNCTION__, size_tmp );
|
rosfran@30
|
475 |
}
|
rosfran@30
|
476 |
#endif
|
leo_sobral@2
|
477 |
}
|
rosfran@30
|
478 |
g_static_mutex_unlock( &update_size_mutex );
|
leo_sobral@2
|
479 |
|
leo_sobral@2
|
480 |
}
|
leo_sobral@2
|
481 |
|
rosfran@30
|
482 |
guint64
|
rosfran@30
|
483 |
gst_mythtv_src_get_position ( GstMythtvSrc* src )
|
leo_sobral@2
|
484 |
{
|
rosfran@30
|
485 |
|
rosfran@30
|
486 |
if ( src->do_start ) {
|
rosfran@30
|
487 |
#if ENABLE_TIMING_POSITION == 1
|
rosfran@30
|
488 |
guint64 size_tmp = 0;
|
rosfran@30
|
489 |
if (src->live_tv == TRUE) {
|
rosfran@30
|
490 |
get_file_pos:
|
rosfran@30
|
491 |
g_usleep( 50 );
|
rosfran@30
|
492 |
size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@30
|
493 |
if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
|
rosfran@30
|
494 |
src->content_size = size_tmp;
|
rosfran@30
|
495 |
else
|
rosfran@30
|
496 |
goto get_file_pos;
|
rosfran@30
|
497 |
g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
|
rosfran@30
|
498 |
__FUNCTION__, size_tmp );
|
rosfran@30
|
499 |
}
|
rosfran@30
|
500 |
#endif
|
rosfran@30
|
501 |
}
|
rosfran@30
|
502 |
|
rosfran@30
|
503 |
return src->content_size;
|
rosfran@30
|
504 |
|
leo_sobral@2
|
505 |
}
|
leo_sobral@2
|
506 |
|
leo_sobral@2
|
507 |
/* create a socket for connecting to remote server */
|
rosfran@30
|
508 |
static gboolean
|
leo_sobral@2
|
509 |
gst_mythtv_src_start ( GstBaseSrc * bsrc )
|
leo_sobral@2
|
510 |
{
|
leo_sobral@2
|
511 |
GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
|
leo_sobral@2
|
512 |
|
leo_sobral@2
|
513 |
GString *chain_id_local = NULL;
|
leo_sobral@2
|
514 |
|
leo_sobral@2
|
515 |
gboolean ret = TRUE;
|
rosfran@30
|
516 |
|
leo_sobral@2
|
517 |
if (src->unique_setup == FALSE) {
|
leo_sobral@2
|
518 |
src->unique_setup = TRUE;
|
leo_sobral@2
|
519 |
} else {
|
leo_sobral@2
|
520 |
goto done;
|
leo_sobral@2
|
521 |
}
|
leo_sobral@2
|
522 |
|
leo_sobral@2
|
523 |
GST_OBJECT_LOCK(src);
|
leo_sobral@2
|
524 |
|
leo_sobral@2
|
525 |
if ( src->live_tv ) {
|
leo_sobral@2
|
526 |
src->spawn_livetv = myth_livetv_new( );
|
leo_sobral@2
|
527 |
if ( myth_livetv_setup( src->spawn_livetv ) == FALSE ) {
|
rosfran@30
|
528 |
ret = FALSE;
|
rosfran@30
|
529 |
goto init_failed;
|
leo_sobral@2
|
530 |
}
|
leo_sobral@2
|
531 |
/* set up the uri variable */
|
leo_sobral@2
|
532 |
src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
|
leo_sobral@2
|
533 |
chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
|
leo_sobral@2
|
534 |
if ( chain_id_local != NULL ) {
|
leo_sobral@2
|
535 |
src->live_chain_id = g_strdup( chain_id_local->str );
|
leo_sobral@2
|
536 |
g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
|
leo_sobral@2
|
537 |
}
|
leo_sobral@2
|
538 |
src->live_tv_id = src->spawn_livetv->remote_encoder->recorder_num;
|
leo_sobral@2
|
539 |
g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
|
leo_sobral@2
|
540 |
}
|
leo_sobral@2
|
541 |
|
leo_sobral@2
|
542 |
src->file_transfer = myth_file_transfer_new( src->live_tv_id,
|
leo_sobral@2
|
543 |
g_string_new( src->uri_name ), -1, src->mythtv_version );
|
leo_sobral@2
|
544 |
|
leo_sobral@2
|
545 |
if ( src->file_transfer == NULL ) {
|
leo_sobral@2
|
546 |
GST_OBJECT_UNLOCK(src);
|
leo_sobral@2
|
547 |
|
leo_sobral@2
|
548 |
goto init_failed;
|
leo_sobral@2
|
549 |
}
|
leo_sobral@2
|
550 |
|
leo_sobral@2
|
551 |
/* sets the Playback monitor connection */
|
leo_sobral@2
|
552 |
ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
|
leo_sobral@2
|
553 |
|
leo_sobral@2
|
554 |
if ( src->live_tv == TRUE && ret == TRUE ) {
|
leo_sobral@2
|
555 |
/* loop finished, set the max tries variable to zero again... */
|
leo_sobral@2
|
556 |
wait_to_transfer = 0;
|
leo_sobral@2
|
557 |
|
leo_sobral@2
|
558 |
while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && ( myth_file_transfer_is_recording( src->file_transfer ) == FALSE
|
leo_sobral@2
|
559 |
/*|| ( myth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
|
leo_sobral@2
|
560 |
g_usleep( 100 );
|
leo_sobral@2
|
561 |
}
|
leo_sobral@2
|
562 |
|
leo_sobral@2
|
563 |
/* sets the FileTransfer instance connection (video/audio download) */
|
leo_sobral@2
|
564 |
ret = myth_file_transfer_setup( &(src->file_transfer), src->live_tv );
|
leo_sobral@2
|
565 |
|
leo_sobral@2
|
566 |
if ( ret == FALSE ) {
|
leo_sobral@2
|
567 |
GST_OBJECT_UNLOCK(src);
|
leo_sobral@2
|
568 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
569 |
if ( src->mythtv_msgs_dbg )
|
leo_sobral@2
|
570 |
g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
|
leo_sobral@2
|
571 |
#endif
|
leo_sobral@2
|
572 |
goto begin_req_failed;
|
leo_sobral@2
|
573 |
}
|
leo_sobral@2
|
574 |
|
leo_sobral@2
|
575 |
src->content_size = src->file_transfer->filesize;
|
leo_sobral@2
|
576 |
|
leo_sobral@2
|
577 |
GST_OBJECT_UNLOCK(src);
|
rosfran@30
|
578 |
if ( src->live_tv ) {
|
rosfran@30
|
579 |
|
rosfran@30
|
580 |
//GError* error;
|
rosfran@30
|
581 |
//update_size_task = g_thread_create( (GThreadFunc)update_size_func, src, FALSE, &error );
|
rosfran@30
|
582 |
g_print( "[%s] Update Size task = %s\n", __FUNCTION__, update_size_task != NULL ? "OK !" : "ERROR!!!" );
|
rosfran@30
|
583 |
|
rosfran@30
|
584 |
}
|
rosfran@30
|
585 |
src->do_start = TRUE;
|
rosfran@30
|
586 |
|
rosfran@30
|
587 |
done:
|
rosfran@30
|
588 |
return TRUE;
|
rosfran@30
|
589 |
|
rosfran@30
|
590 |
/* ERRORS */
|
rosfran@30
|
591 |
init_failed:
|
rosfran@30
|
592 |
{
|
rosfran@30
|
593 |
if (src->spawn_livetv != NULL )
|
rosfran@30
|
594 |
g_object_unref( src->spawn_livetv );
|
rosfran@30
|
595 |
|
rosfran@30
|
596 |
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
rosfran@30
|
597 |
(NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
|
rosfran@30
|
598 |
return FALSE;
|
rosfran@30
|
599 |
}
|
rosfran@30
|
600 |
begin_req_failed:
|
rosfran@30
|
601 |
{
|
rosfran@30
|
602 |
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
rosfran@30
|
603 |
(NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
|
rosfran@30
|
604 |
return FALSE;
|
rosfran@30
|
605 |
}
|
rosfran@30
|
606 |
}
|
leo_sobral@2
|
607 |
|
leo_sobral@2
|
608 |
#if 0
|
rosfran@30
|
609 |
/* handles queries for location in the stream in the requested format */
|
rosfran@30
|
610 |
static gboolean
|
rosfran@30
|
611 |
gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
|
rosfran@30
|
612 |
{
|
rosfran@30
|
613 |
gboolean res = TRUE;
|
rosfran@30
|
614 |
GstMythtvSrc *mythtv;
|
leo_sobral@2
|
615 |
|
rosfran@30
|
616 |
guint64 size = 0;
|
rosfran@30
|
617 |
|
rosfran@30
|
618 |
mythtv = GST_MYTHTV_SRC( GST_PAD_PARENT (pad) );
|
rosfran@30
|
619 |
|
rosfran@30
|
620 |
size = gst_mythtv_src_get_position (mythtv);
|
rosfran@30
|
621 |
|
rosfran@30
|
622 |
switch (GST_QUERY_TYPE (query)) {
|
rosfran@30
|
623 |
|
rosfran@30
|
624 |
case GST_QUERY_POSITION:
|
rosfran@30
|
625 |
{
|
rosfran@30
|
626 |
|
rosfran@30
|
627 |
//GstFormat format;
|
rosfran@30
|
628 |
gint64 cur = 0;
|
rosfran@30
|
629 |
|
rosfran@30
|
630 |
/* save requested format */
|
rosfran@30
|
631 |
gst_query_parse_position (query, NULL, &cur);
|
rosfran@30
|
632 |
|
rosfran@30
|
633 |
/* query peer for current position in time */
|
rosfran@30
|
634 |
g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
|
rosfran@30
|
635 |
( size > cur ) ? "greater" : "lower", size, cur );
|
rosfran@30
|
636 |
gst_query_set_position (query, GST_FORMAT_BYTES, size);
|
rosfran@30
|
637 |
if ( size < cur )
|
rosfran@30
|
638 |
goto error;
|
rosfran@30
|
639 |
|
rosfran@30
|
640 |
break;
|
leo_sobral@2
|
641 |
}
|
rosfran@30
|
642 |
#if 0
|
rosfran@30
|
643 |
case GST_QUERY_DURATION:
|
rosfran@30
|
644 |
{
|
rosfran@30
|
645 |
//GstFormat format;
|
rosfran@30
|
646 |
gint64 cur = 0;
|
rosfran@30
|
647 |
|
rosfran@30
|
648 |
/* save requested format */
|
rosfran@30
|
649 |
gst_query_parse_position (query, NULL, &cur);
|
rosfran@30
|
650 |
|
rosfran@30
|
651 |
/* query peer for current position in time */
|
rosfran@30
|
652 |
g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
|
rosfran@30
|
653 |
( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND,
|
rosfran@30
|
654 |
cur * GST_SECOND );
|
rosfran@30
|
655 |
gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
|
rosfran@30
|
656 |
|
rosfran@30
|
657 |
if ( size * GST_SECOND < cur * GST_SECOND )
|
rosfran@30
|
658 |
goto error;
|
rosfran@30
|
659 |
|
rosfran@30
|
660 |
break;
|
rosfran@30
|
661 |
}
|
rosfran@30
|
662 |
#endif
|
rosfran@30
|
663 |
default:
|
rosfran@30
|
664 |
res = FALSE;
|
rosfran@30
|
665 |
break;
|
rosfran@30
|
666 |
}
|
rosfran@30
|
667 |
|
rosfran@30
|
668 |
return res;
|
rosfran@30
|
669 |
|
rosfran@30
|
670 |
error:
|
rosfran@30
|
671 |
|
rosfran@30
|
672 |
return FALSE;
|
rosfran@30
|
673 |
}
|
leo_sobral@2
|
674 |
#endif
|
leo_sobral@2
|
675 |
|
rosfran@30
|
676 |
static gboolean
|
leo_sobral@2
|
677 |
gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
|
leo_sobral@2
|
678 |
{
|
rosfran@31
|
679 |
GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
|
rosfran@30
|
680 |
gboolean ret = TRUE;
|
leo_sobral@2
|
681 |
|
rosfran@30
|
682 |
if (src->content_size <= 0) {
|
rosfran@30
|
683 |
ret= FALSE;
|
rosfran@34
|
684 |
} else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
|
rosfran@34
|
685 |
//g_static_mutex_lock( &update_size_mutex );
|
rosfran@30
|
686 |
|
rosfran@31
|
687 |
guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@31
|
688 |
if ( src->content_size < new_offset ) {
|
rosfran@31
|
689 |
src->content_size = new_offset;
|
rosfran@31
|
690 |
}
|
rosfran@31
|
691 |
|
leo_sobral@2
|
692 |
#if ENABLE_TIMING_POSITION == 1
|
rosfran@30
|
693 |
guint64 size_tmp = 0;
|
rosfran@30
|
694 |
if (src->live_tv == TRUE) {
|
leo_sobral@2
|
695 |
get_file_pos:
|
rosfran@31
|
696 |
g_usleep( 5 );
|
rosfran@30
|
697 |
size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
|
rosfran@30
|
698 |
if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
|
rosfran@30
|
699 |
src->content_size = size_tmp;
|
rosfran@30
|
700 |
else
|
rosfran@30
|
701 |
goto get_file_pos;
|
rosfran@30
|
702 |
g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
|
rosfran@30
|
703 |
__FUNCTION__, size_tmp );
|
rosfran@30
|
704 |
}
|
rosfran@30
|
705 |
#endif
|
rosfran@34
|
706 |
//g_static_mutex_unlock( &update_size_mutex );
|
rosfran@30
|
707 |
|
leo_sobral@2
|
708 |
}
|
leo_sobral@2
|
709 |
|
leo_sobral@2
|
710 |
*size = src->content_size;
|
rosfran@30
|
711 |
g_print( "[%s] Content size = %llu\n", __FUNCTION__, src->content_size );
|
leo_sobral@2
|
712 |
|
rosfran@30
|
713 |
return ret;
|
rosfran@30
|
714 |
|
leo_sobral@2
|
715 |
}
|
leo_sobral@2
|
716 |
|
leo_sobral@2
|
717 |
/* close the socket and associated resources
|
leo_sobral@2
|
718 |
* used both to recover from errors and go to NULL state */
|
leo_sobral@2
|
719 |
static gboolean
|
leo_sobral@2
|
720 |
gst_mythtv_src_stop (GstBaseSrc * bsrc)
|
leo_sobral@2
|
721 |
{
|
leo_sobral@2
|
722 |
GstMythtvSrc *src;
|
leo_sobral@2
|
723 |
|
leo_sobral@2
|
724 |
src = GST_MYTHTV_SRC (bsrc);
|
leo_sobral@2
|
725 |
|
leo_sobral@2
|
726 |
if (src->uri_name) {
|
leo_sobral@2
|
727 |
g_free (src->uri_name);
|
leo_sobral@2
|
728 |
src->uri_name = NULL;
|
leo_sobral@2
|
729 |
}
|
leo_sobral@2
|
730 |
|
leo_sobral@2
|
731 |
if (src->mythtv_caps) {
|
leo_sobral@2
|
732 |
gst_caps_unref (src->mythtv_caps);
|
leo_sobral@2
|
733 |
src->mythtv_caps = NULL;
|
leo_sobral@2
|
734 |
}
|
leo_sobral@2
|
735 |
|
leo_sobral@2
|
736 |
src->eos = FALSE;
|
leo_sobral@2
|
737 |
|
leo_sobral@2
|
738 |
return TRUE;
|
leo_sobral@2
|
739 |
}
|
leo_sobral@2
|
740 |
|
rosfran@30
|
741 |
static gboolean
|
leo_sobral@2
|
742 |
gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
|
leo_sobral@2
|
743 |
{
|
leo_sobral@2
|
744 |
GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
|
leo_sobral@2
|
745 |
|
leo_sobral@2
|
746 |
switch (GST_EVENT_TYPE (event)) {
|
rosfran@30
|
747 |
#if 0
|
leo_sobral@2
|
748 |
case GST_EVENT_FLUSH_START:
|
leo_sobral@2
|
749 |
src->eos = FALSE;
|
leo_sobral@2
|
750 |
break;
|
leo_sobral@2
|
751 |
//return TRUE;
|
leo_sobral@2
|
752 |
case GST_EVENT_FLUSH_STOP:
|
leo_sobral@2
|
753 |
src->do_start = TRUE;
|
leo_sobral@2
|
754 |
src->eos = FALSE;
|
leo_sobral@2
|
755 |
gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
|
rosfran@30
|
756 |
//gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
|
rosfran@30
|
757 |
break;
|
rosfran@30
|
758 |
#endif
|
rosfran@30
|
759 |
case GST_EVENT_EOS:
|
rosfran@30
|
760 |
g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
|
rosfran@31
|
761 |
guint64 cont_size = gst_mythtv_src_get_position (src);
|
rosfran@34
|
762 |
if ( !src->live_tv ) {
|
rosfran@34
|
763 |
if ( cont_size > src->content_size ) {
|
rosfran@34
|
764 |
src->content_size = cont_size;
|
rosfran@34
|
765 |
src->eos = FALSE;
|
rosfran@34
|
766 |
} else {
|
rosfran@34
|
767 |
src->eos = TRUE;
|
rosfran@34
|
768 |
gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
|
rosfran@34
|
769 |
gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
|
rosfran@34
|
770 |
}
|
rosfran@34
|
771 |
} else
|
rosfran@34
|
772 |
src->eos = TRUE;
|
rosfran@30
|
773 |
break;
|
rosfran@30
|
774 |
#if 0
|
rosfran@30
|
775 |
case GST_EVENT_NEWSEGMENT:
|
rosfran@30
|
776 |
g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
|
rosfran@30
|
777 |
src->eos = FALSE;
|
leo_sobral@2
|
778 |
break;
|
leo_sobral@2
|
779 |
case GST_EVENT_SEEK:
|
leo_sobral@2
|
780 |
{
|
rosfran@30
|
781 |
g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
|
leo_sobral@2
|
782 |
gdouble rate;
|
leo_sobral@2
|
783 |
//gboolean update = TRUE;
|
leo_sobral@2
|
784 |
GstFormat format;
|
leo_sobral@2
|
785 |
GstSeekType cur_type, stop_type;
|
leo_sobral@2
|
786 |
GstSeekFlags flags;
|
leo_sobral@2
|
787 |
gint64 cur = 0, stop = 0;
|
leo_sobral@2
|
788 |
gst_event_parse_seek ( event, &rate, &format,
|
leo_sobral@2
|
789 |
&flags, &cur_type, &cur,
|
leo_sobral@2
|
790 |
&stop_type, &stop );
|
leo_sobral@2
|
791 |
|
leo_sobral@2
|
792 |
g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
|
leo_sobral@2
|
793 |
if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
|
leo_sobral@2
|
794 |
g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
|
leo_sobral@2
|
795 |
}
|
leo_sobral@2
|
796 |
//gboolean ret = gst_event_parse_new_segment ( event,
|
leo_sobral@2
|
797 |
// &update, &rate, &format, &start, &stop,
|
leo_sobral@2
|
798 |
// &position );
|
leo_sobral@2
|
799 |
//GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ),
|
leo_sobral@2
|
800 |
// cur, stop - cur + 1, GstBuffer)
|
rosfran@30
|
801 |
}
|
rosfran@30
|
802 |
#endif
|
leo_sobral@2
|
803 |
default:
|
leo_sobral@2
|
804 |
return gst_pad_event_default (pad, event);
|
leo_sobral@2
|
805 |
}
|
leo_sobral@2
|
806 |
|
leo_sobral@2
|
807 |
return gst_pad_event_default (pad, event);
|
leo_sobral@2
|
808 |
}
|
leo_sobral@2
|
809 |
|
rosfran@30
|
810 |
static gboolean
|
rosfran@30
|
811 |
gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
|
leo_sobral@2
|
812 |
{
|
leo_sobral@2
|
813 |
return TRUE;
|
leo_sobral@2
|
814 |
}
|
leo_sobral@2
|
815 |
|
rosfran@30
|
816 |
static void
|
leo_sobral@2
|
817 |
gst_mythtv_src_set_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
818 |
const GValue * value, GParamSpec * pspec)
|
leo_sobral@2
|
819 |
{
|
leo_sobral@2
|
820 |
GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
|
leo_sobral@2
|
821 |
|
leo_sobral@2
|
822 |
GST_OBJECT_LOCK (mythtvsrc);
|
leo_sobral@2
|
823 |
switch (prop_id) {
|
leo_sobral@2
|
824 |
case PROP_URI:
|
leo_sobral@2
|
825 |
case PROP_LOCATION:
|
leo_sobral@2
|
826 |
{
|
leo_sobral@2
|
827 |
if (!g_value_get_string (value)) {
|
leo_sobral@2
|
828 |
GST_WARNING ("location property cannot be NULL");
|
leo_sobral@2
|
829 |
goto done;
|
leo_sobral@2
|
830 |
}
|
leo_sobral@2
|
831 |
|
leo_sobral@2
|
832 |
if (mythtvsrc->uri_name != NULL) {
|
leo_sobral@2
|
833 |
g_free (mythtvsrc->uri_name);
|
leo_sobral@2
|
834 |
mythtvsrc->uri_name = NULL;
|
leo_sobral@2
|
835 |
}
|
leo_sobral@2
|
836 |
mythtvsrc->uri_name = g_value_dup_string (value);
|
leo_sobral@2
|
837 |
|
leo_sobral@2
|
838 |
break;
|
leo_sobral@2
|
839 |
}
|
leo_sobral@2
|
840 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
841 |
case PROP_MYTHTV_DBG:
|
leo_sobral@2
|
842 |
{
|
leo_sobral@2
|
843 |
mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
|
leo_sobral@2
|
844 |
break;
|
leo_sobral@2
|
845 |
}
|
leo_sobral@2
|
846 |
#endif
|
leo_sobral@2
|
847 |
case PROP_MYTHTV_VERSION:
|
leo_sobral@2
|
848 |
{
|
leo_sobral@2
|
849 |
mythtvsrc->mythtv_version = g_value_get_int (value);
|
leo_sobral@2
|
850 |
break;
|
leo_sobral@2
|
851 |
}
|
leo_sobral@2
|
852 |
case PROP_MYTHTV_LIVEID:
|
leo_sobral@2
|
853 |
{
|
leo_sobral@2
|
854 |
mythtvsrc->live_tv_id = g_value_get_int (value);
|
leo_sobral@2
|
855 |
break;
|
leo_sobral@2
|
856 |
}
|
leo_sobral@2
|
857 |
case PROP_MYTHTV_LIVE:
|
leo_sobral@2
|
858 |
{
|
leo_sobral@2
|
859 |
mythtvsrc->live_tv = g_value_get_boolean (value);
|
leo_sobral@2
|
860 |
break;
|
leo_sobral@2
|
861 |
}
|
leo_sobral@2
|
862 |
case PROP_MYTHTV_LIVE_CHAINID:
|
leo_sobral@2
|
863 |
{
|
leo_sobral@2
|
864 |
if (!g_value_get_string (value)) {
|
leo_sobral@2
|
865 |
GST_WARNING ("MythTV Live chainid property cannot be NULL");
|
leo_sobral@2
|
866 |
goto done;
|
leo_sobral@2
|
867 |
}
|
leo_sobral@2
|
868 |
|
leo_sobral@2
|
869 |
if (mythtvsrc->live_chain_id != NULL) {
|
leo_sobral@2
|
870 |
g_free (mythtvsrc->live_chain_id);
|
leo_sobral@2
|
871 |
mythtvsrc->live_chain_id = NULL;
|
leo_sobral@2
|
872 |
}
|
leo_sobral@2
|
873 |
mythtvsrc->live_chain_id = g_value_dup_string (value);
|
leo_sobral@2
|
874 |
|
leo_sobral@2
|
875 |
break;
|
leo_sobral@2
|
876 |
}
|
leo_sobral@2
|
877 |
|
leo_sobral@2
|
878 |
default:
|
leo_sobral@2
|
879 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
leo_sobral@2
|
880 |
break;
|
leo_sobral@2
|
881 |
}
|
leo_sobral@2
|
882 |
GST_OBJECT_UNLOCK (mythtvsrc);
|
leo_sobral@2
|
883 |
done:
|
leo_sobral@2
|
884 |
return;
|
leo_sobral@2
|
885 |
}
|
leo_sobral@2
|
886 |
|
leo_sobral@2
|
887 |
static void
|
leo_sobral@2
|
888 |
gst_mythtv_src_get_property (GObject * object, guint prop_id,
|
leo_sobral@2
|
889 |
GValue * value, GParamSpec * pspec)
|
leo_sobral@2
|
890 |
{
|
leo_sobral@2
|
891 |
GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
|
leo_sobral@2
|
892 |
|
leo_sobral@2
|
893 |
GST_OBJECT_LOCK (mythtvsrc);
|
leo_sobral@2
|
894 |
switch (prop_id) {
|
leo_sobral@2
|
895 |
case PROP_URI:
|
leo_sobral@2
|
896 |
case PROP_LOCATION:
|
leo_sobral@2
|
897 |
{
|
leo_sobral@2
|
898 |
gchar *str = g_strdup( "" );
|
leo_sobral@2
|
899 |
|
leo_sobral@2
|
900 |
if ( mythtvsrc->uri_name == NULL ) {
|
leo_sobral@2
|
901 |
g_free (mythtvsrc->uri_name);
|
leo_sobral@2
|
902 |
mythtvsrc->uri_name = NULL;
|
leo_sobral@2
|
903 |
} else {
|
leo_sobral@2
|
904 |
str = g_strdup( mythtvsrc->uri_name );
|
leo_sobral@2
|
905 |
}
|
leo_sobral@2
|
906 |
g_value_set_string ( value, str );
|
leo_sobral@2
|
907 |
break;
|
leo_sobral@2
|
908 |
}
|
leo_sobral@2
|
909 |
#ifndef GST_DISABLE_GST_DEBUG
|
leo_sobral@2
|
910 |
case PROP_MYTHTV_DBG:
|
leo_sobral@2
|
911 |
g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
|
leo_sobral@2
|
912 |
break;
|
leo_sobral@2
|
913 |
#endif
|
leo_sobral@2
|
914 |
case PROP_MYTHTV_VERSION:
|
leo_sobral@2
|
915 |
{
|
leo_sobral@2
|
916 |
g_value_set_int ( value, mythtvsrc->mythtv_version );
|
leo_sobral@2
|
917 |
break;
|
leo_sobral@2
|
918 |
}
|
leo_sobral@2
|
919 |
case PROP_MYTHTV_LIVEID:
|
leo_sobral@2
|
920 |
{
|
leo_sobral@2
|
921 |
g_value_set_int ( value, mythtvsrc->live_tv_id );
|
leo_sobral@2
|
922 |
break;
|
leo_sobral@2
|
923 |
}
|
leo_sobral@2
|
924 |
case PROP_MYTHTV_LIVE:
|
leo_sobral@2
|
925 |
g_value_set_boolean ( value, mythtvsrc->live_tv );
|
leo_sobral@2
|
926 |
break;
|
leo_sobral@2
|
927 |
case PROP_MYTHTV_LIVE_CHAINID:
|
leo_sobral@2
|
928 |
{
|
leo_sobral@2
|
929 |
gchar *str = g_strdup( "" );
|
leo_sobral@2
|
930 |
|
leo_sobral@2
|
931 |
if ( mythtvsrc->live_chain_id == NULL ) {
|
leo_sobral@2
|
932 |
g_free (mythtvsrc->live_chain_id);
|
leo_sobral@2
|
933 |
mythtvsrc->live_chain_id = NULL;
|
leo_sobral@2
|
934 |
} else {
|
leo_sobral@2
|
935 |
str = g_strdup( mythtvsrc->live_chain_id );
|
leo_sobral@2
|
936 |
}
|
leo_sobral@2
|
937 |
g_value_set_string ( value, str );
|
leo_sobral@2
|
938 |
break;
|
leo_sobral@2
|
939 |
}
|
leo_sobral@2
|
940 |
default:
|
leo_sobral@2
|
941 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
leo_sobral@2
|
942 |
break;
|
leo_sobral@2
|
943 |
}
|
leo_sobral@2
|
944 |
GST_OBJECT_UNLOCK (mythtvsrc);
|
leo_sobral@2
|
945 |
}
|
leo_sobral@2
|
946 |
|
leo_sobral@2
|
947 |
/* entry point to initialize the plug-in
|
leo_sobral@2
|
948 |
* initialize the plug-in itself
|
leo_sobral@2
|
949 |
* register the element factories and pad templates
|
leo_sobral@2
|
950 |
* register the features
|
leo_sobral@2
|
951 |
*/
|
leo_sobral@2
|
952 |
static gboolean
|
leo_sobral@2
|
953 |
plugin_init (GstPlugin * plugin)
|
leo_sobral@2
|
954 |
{
|
leo_sobral@2
|
955 |
return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
|
leo_sobral@2
|
956 |
GST_TYPE_MYTHTV_SRC);
|
leo_sobral@2
|
957 |
}
|
leo_sobral@2
|
958 |
|
leo_sobral@2
|
959 |
/* this is the structure that gst-register looks for
|
leo_sobral@2
|
960 |
* so keep the name plugin_desc, or you cannot get your plug-in registered */
|
leo_sobral@2
|
961 |
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
leo_sobral@2
|
962 |
GST_VERSION_MINOR,
|
leo_sobral@2
|
963 |
"mythtv",
|
leo_sobral@2
|
964 |
"lib MythTV src",
|
leo_sobral@2
|
965 |
plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
|
leo_sobral@2
|
966 |
|
leo_sobral@2
|
967 |
|
leo_sobral@2
|
968 |
/*** GSTURIHANDLER INTERFACE *************************************************/
|
leo_sobral@2
|
969 |
static guint
|
leo_sobral@2
|
970 |
gst_mythtv_src_uri_get_type (void)
|
leo_sobral@2
|
971 |
{
|
leo_sobral@2
|
972 |
return GST_URI_SRC;
|
leo_sobral@2
|
973 |
}
|
leo_sobral@2
|
974 |
|
leo_sobral@2
|
975 |
static gchar **
|
leo_sobral@2
|
976 |
gst_mythtv_src_uri_get_protocols (void)
|
leo_sobral@2
|
977 |
{
|
leo_sobral@2
|
978 |
static gchar *protocols[] = { "myth", "myths", NULL };
|
leo_sobral@2
|
979 |
|
leo_sobral@2
|
980 |
return protocols;
|
leo_sobral@2
|
981 |
}
|
leo_sobral@2
|
982 |
|
leo_sobral@2
|
983 |
static const gchar *
|
leo_sobral@2
|
984 |
gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
|
leo_sobral@2
|
985 |
{
|
leo_sobral@2
|
986 |
GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
|
leo_sobral@2
|
987 |
|
leo_sobral@2
|
988 |
return src->uri_name;
|
leo_sobral@2
|
989 |
}
|
leo_sobral@2
|
990 |
|
leo_sobral@2
|
991 |
static gboolean
|
leo_sobral@2
|
992 |
gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
|
leo_sobral@2
|
993 |
{
|
leo_sobral@2
|
994 |
GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
|
leo_sobral@2
|
995 |
|
leo_sobral@2
|
996 |
gchar *protocol;
|
leo_sobral@2
|
997 |
|
leo_sobral@2
|
998 |
protocol = gst_uri_get_protocol (uri);
|
leo_sobral@2
|
999 |
if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
|
leo_sobral@2
|
1000 |
g_free (protocol);
|
leo_sobral@2
|
1001 |
return FALSE;
|
leo_sobral@2
|
1002 |
}
|
leo_sobral@2
|
1003 |
g_free (protocol);
|
leo_sobral@2
|
1004 |
g_object_set (src, "location", uri, NULL);
|
leo_sobral@2
|
1005 |
|
leo_sobral@2
|
1006 |
return TRUE;
|
leo_sobral@2
|
1007 |
}
|
leo_sobral@2
|
1008 |
|
leo_sobral@2
|
1009 |
static void
|
leo_sobral@2
|
1010 |
gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
leo_sobral@2
|
1011 |
{
|
leo_sobral@2
|
1012 |
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
leo_sobral@2
|
1013 |
|
leo_sobral@2
|
1014 |
iface->get_type = gst_mythtv_src_uri_get_type;
|
leo_sobral@2
|
1015 |
iface->get_protocols = gst_mythtv_src_uri_get_protocols;
|
leo_sobral@2
|
1016 |
iface->get_uri = gst_mythtv_src_uri_get_uri;
|
leo_sobral@2
|
1017 |
iface->set_uri = gst_mythtv_src_uri_set_uri;
|
leo_sobral@2
|
1018 |
}
|
leo_sobral@2
|
1019 |
|
leo_sobral@2
|
1020 |
void
|
leo_sobral@2
|
1021 |
size_header_handler (void *userdata, const char *value)
|
leo_sobral@2
|
1022 |
{
|
leo_sobral@2
|
1023 |
GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
|
leo_sobral@2
|
1024 |
|
leo_sobral@2
|
1025 |
//src->content_size = g_ascii_strtoull (value, NULL, 10);
|
leo_sobral@2
|
1026 |
|
leo_sobral@2
|
1027 |
GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);
|
leo_sobral@2
|
1028 |
}
|