[svn r566] Some fixes on the autotools.
1 /* GStreamer MythTV Plug-in
2 * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 * SECTION:element-mythtvsrc
24 * MythTVSrc allows to access a remote MythTV backend streaming Video/Audio server,
25 * and to render audio and video content through a TCP/IP connection to a specific
26 * port on this server, and based on a known MythTV protocol that is based on
27 * some message passing, such as REQUEST_BLOCK on a specified number of bytes, to get
28 * some chunk of remote file data.
29 * You should pass the information aboute the remote MythTV backend server
30 * through the <link linkend="GstMythTVSrc--location">location</link> property.
32 * <title>Examples</title>
34 * If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder,
36 * put the following URI:
39 * myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
42 * This URI will say to the gmyth library to configure the Recorder instance (used to
43 * change the channel, start the TV multimedia content transmition, etc.), using
44 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
45 * server, and setting the channel name to "BBC".
47 * To get a already recorded the MythTV NUV file, put the following URI:
50 * myth://xxx.xxx.xxx.xxx:6543/filename.nuv
53 * This URI will say to the gmyth library to configure the Recorder instance (used to
54 * change the channel, start the TV multimedia content transmition, etc.), using
55 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
56 * server, and setting the channel name to "BBC".
58 * Another possible way to use the LiveTV content, and just in the case you want to
59 * use the mysql database, put the location URI in the following format:
62 * myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
65 * Where the first field is the protocol (myth), the second and third are user
66 * name (mythtv) and password (mythtv), then backend host name and port number,
67 * and the last field is the database name (mythconverg).
75 #include "gstmythtvsrc.h"
76 #include <gmyth/gmyth_file.h>
77 #include <gmyth/gmyth_file_transfer.h>
78 #include <gmyth/gmyth_file_local.h>
79 #include <gmyth/gmyth_livetv.h>
81 #include <gmyth/gmyth_socket.h>
82 #include <gmyth/gmyth_tvchain.h>
87 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
88 #define GST_CAT_DEFAULT mythtvsrc_debug
90 #define GST_GMYTHTV_ID_NUM 1
92 #define GST_GMYTHTV_CHANNEL_DEFAULT_NUM (-1)
94 #define GMYTHTV_VERSION_DEFAULT 30
96 #define GMYTHTV_TRANSFER_MAX_WAITS 100
98 #define GMYTHTV_TRANSFER_MAX_RESENDS 2
100 #define GMYTHTV_TRANSFER_MAX_BUFFER (128*1024)
102 #define MAX_READ_SIZE (4*1024)
104 #define GST_FLOW_ERROR_NO_DATA (-101)
106 #define REQUEST_MAX_SIZE (64*1024)
108 #define INTERNAL_BUFFER_SIZE (90*1024)
110 static const GstElementDetails gst_mythtv_src_details =
111 GST_ELEMENT_DETAILS ("MythTV client source",
113 "Control and receive data as a client over the network "
114 "via raw socket connections using the MythTV protocol",
115 "Rosfran Borges <rosfran.borges@indt.org.br>");
117 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
120 GST_STATIC_CAPS ("video/x-nuv"));
126 #ifndef GST_DISABLE_GST_DEBUG
129 PROP_GMYTHTV_VERSION,
132 PROP_GMYTHTV_LIVE_CHAINID,
133 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
134 PROP_GMYTHTV_CHANNEL_NUM
137 static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
139 static void gst_mythtv_src_finalize (GObject * gobject);
141 static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
142 GstBuffer ** outbuf);
144 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
145 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
146 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
147 static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
149 static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
150 GstSegment * segment);
152 static GstStateChangeReturn
153 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
155 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
156 const GValue * value, GParamSpec * pspec);
157 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
158 GValue * value, GParamSpec * pspec);
160 static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
161 gpointer iface_data);
163 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
165 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
167 static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
168 GByteArray * data_ptr);
171 _urihandler_init (GType type)
173 static const GInterfaceInfo urihandler_info = {
174 gst_mythtv_src_uri_handler_init,
179 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
181 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
184 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
185 GST_TYPE_PUSH_SRC, _urihandler_init)
187 static void gst_mythtv_src_base_init (gpointer g_class)
189 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
191 gst_element_class_add_pad_template (element_class,
192 gst_static_pad_template_get (&srctemplate));
194 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
196 element_class->change_state = gst_mythtv_src_change_state;
201 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
203 GObjectClass *gobject_class;
204 GstPushSrcClass *gstpushsrc_class;
205 GstBaseSrcClass *gstbasesrc_class;
207 gobject_class = (GObjectClass *) klass;
208 gstbasesrc_class = (GstBaseSrcClass *) klass;
209 gstpushsrc_class = (GstPushSrcClass *) klass;
211 gobject_class->set_property = gst_mythtv_src_set_property;
212 gobject_class->get_property = gst_mythtv_src_get_property;
213 gobject_class->finalize = gst_mythtv_src_finalize;
215 g_object_class_install_property
216 (gobject_class, PROP_LOCATION,
217 g_param_spec_string ("location", "Location",
218 "The location. In the form:"
219 "\n\t\t\tmyth://a.com/file.nuv"
220 "\n\t\t\tmyth://a.com:23223/file.nuv "
221 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
222 "", G_PARAM_READWRITE));
224 g_object_class_install_property
225 (gobject_class, PROP_GMYTHTV_VERSION,
226 g_param_spec_int ("mythtv-version", "mythtv-version",
227 "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
229 g_object_class_install_property
230 (gobject_class, PROP_GMYTHTV_LIVEID,
231 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
232 "Change MythTV version",
233 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
235 g_object_class_install_property
236 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
237 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
238 "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
240 g_object_class_install_property
241 (gobject_class, PROP_GMYTHTV_LIVE,
242 g_param_spec_boolean ("mythtv-live", "mythtv-live",
243 "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
245 g_object_class_install_property
246 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
247 g_param_spec_boolean ("mythtv-enable-timing-position",
248 "mythtv-enable-timing-position",
249 "Enable MythTV Live TV content size continuous updating", FALSE,
252 g_object_class_install_property
253 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
254 g_param_spec_string ("mythtv-channel", "mythtv-channel",
255 "Change MythTV channel number",
256 "", G_PARAM_READWRITE));
258 #ifndef GST_DISABLE_GST_DEBUG
259 g_object_class_install_property
260 (gobject_class, PROP_GMYTHTV_DBG,
261 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
262 "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
265 gstbasesrc_class->start = gst_mythtv_src_start;
266 gstbasesrc_class->stop = gst_mythtv_src_stop;
267 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
268 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
270 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
271 gstpushsrc_class->create = gst_mythtv_src_create;
273 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
274 "MythTV Client Source");
278 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
282 this->unique_setup = FALSE;
284 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
286 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
288 this->bytes_read = 0;
290 this->prev_content_size = 0;
292 this->content_size = 0;
293 this->read_offset = 0;
295 this->content_size_last = 0;
297 this->live_tv = FALSE;
299 this->enable_timing_position = FALSE;
300 this->update_prog_chain = FALSE;
302 this->user_agent = g_strdup ("mythtvsrc");
303 this->update_prog_chain = FALSE;
305 this->channel_name = NULL;
309 this->bytes_queue = NULL;
311 this->wait_to_transfer = 0;
313 gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
315 gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
316 gst_mythtv_src_handle_event);
317 gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
318 gst_mythtv_src_handle_query);
323 gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
326 if (mythtv_src->spawn_livetv) {
327 g_object_unref (mythtv_src->spawn_livetv);
328 mythtv_src->spawn_livetv = NULL;
331 if (mythtv_src->file) {
332 g_object_unref (mythtv_src->file);
333 mythtv_src->file = NULL;
336 if (mythtv_src->backend_info) {
337 g_object_unref (mythtv_src->backend_info);
338 mythtv_src->backend_info = NULL;
341 if (mythtv_src->uri_name) {
342 g_free (mythtv_src->uri_name);
345 if (mythtv_src->user_agent) {
346 g_free (mythtv_src->user_agent);
349 if (mythtv_src->bytes_queue) {
350 g_byte_array_free (mythtv_src->bytes_queue, TRUE);
351 mythtv_src->bytes_queue = NULL;
357 gst_mythtv_src_finalize (GObject * gobject)
359 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
361 gst_mythtv_src_clear (this);
363 G_OBJECT_CLASS (parent_class)->finalize (gobject);
366 static GMythFileReadResult
367 do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
370 guint sizetoread = size;
371 gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
372 GMythFileReadResult result;
374 GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
376 /* Loop sending the Myth File Transfer request:
377 * Retry whilst authentication fails and we supply it. */
379 while (sizetoread == size && --max_iters > 0) {
380 /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
381 if ( IS_GMYTH_FILE_LOCAL(src->file) )
382 result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
383 data_ptr, sizetoread, src->live_tv);
384 else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
385 result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
386 data_ptr, sizetoread, src->live_tv);
388 if (data_ptr->len > 0) {
389 read += data_ptr->len;
390 sizetoread -= data_ptr->len;
391 } else if (data_ptr->len < 0) {
392 if (src->live_tv == FALSE) {
393 result = GMYTH_FILE_READ_EOF;
396 if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
397 GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
399 } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */
400 GST_INFO_OBJECT (src,
401 "[LiveTV] FileTransfer - Go to the next program chain!");
407 } else if (data_ptr->len == 0)
410 if (read == sizetoread)
414 if ((read < 0 && !src->live_tv) || max_iters == 0){
415 result = GMYTH_FILE_READ_EOF;
429 gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
432 GstFlowReturn ret = GST_FLOW_OK;
433 guint buffer_size_inter = 0;
435 src = GST_MYTHTV_SRC (psrc);
437 /* The caller should know the number of bytes and not read beyond EOS. */
438 if (G_UNLIKELY (src->eos))
440 if (G_UNLIKELY (src->update_prog_chain))
441 goto change_progchain;
443 GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
444 src->read_offset, MAX_READ_SIZE);
446 GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
447 (gint) src->buffer_remain, src->bytes_queue->len);
449 program_chain_changed:
450 /* just get from the byte array, no network effort... */
451 if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
453 GMythFileReadResult result = GMYTH_FILE_READ_OK;
456 buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
458 if (buffer_size_inter > REQUEST_MAX_SIZE)
459 buffer_size_inter = REQUEST_MAX_SIZE;
461 buffer = g_byte_array_new ();
463 result = do_read_request_response (src, buffer_size_inter, buffer);
465 if (G_UNLIKELY (buffer->len < 0)) {
467 if (buffer != NULL) {
468 g_byte_array_free (buffer, TRUE);
472 if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
473 goto change_progchain;
476 } else if (G_UNLIKELY (read == 0)) {
478 if (buffer != NULL) {
479 g_byte_array_free (buffer, TRUE);
486 goto program_chain_changed;
489 if (G_UNLIKELY (src->update_prog_chain))
491 if (buffer != NULL) {
492 g_byte_array_free (buffer, TRUE);
495 goto change_progchain;
499 g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
500 if (buffer->len > buffer_size_inter)
501 GST_WARNING_OBJECT (src,
502 "INCREASED buffer size! Backend sent more than we ask him... (%d)",
503 abs (buffer->len - buffer_size_inter));
505 src->buffer_remain += buffer->len;
507 if (buffer != NULL) {
508 g_byte_array_free (buffer, TRUE);
512 GST_DEBUG_OBJECT (src,
513 "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
514 "OFFSET = %llu, CONTENT SIZE = %llu.", read,
515 src->bytes_read, src->read_offset, src->content_size);
520 (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
522 *outbuf = gst_buffer_new ();
524 /* gets the first buffer_size bytes from the byte array buffer variable */
525 /* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
527 GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
528 (buffer_size_inter ==
529 0) ? "NO, got from buffer" : "YES, go see the backend's log file",
532 GST_BUFFER_SIZE (*outbuf) = buffer_size;
533 GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
534 GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
535 g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
536 GST_BUFFER_SIZE (*outbuf));
537 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
538 GST_BUFFER_OFFSET_END (*outbuf) =
539 src->read_offset + GST_BUFFER_SIZE (*outbuf);
541 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
543 src->read_offset += GST_BUFFER_SIZE (*outbuf);
544 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
545 GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
546 GST_BUFFER_SIZE (*outbuf));
548 /* flushs the newly buffer got from byte array */
550 g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
552 GST_DEBUG_OBJECT ( src, "Got buffer: BUFFER --->SIZE = %d, OFFSET = %llu, "
553 "OFFSET_END = %llu.", GST_BUFFER_SIZE (*outbuf),
554 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
556 GST_DEBUG_OBJECT (src, "CONTENT_SIZE = %llu, BYTES_READ = %llu.",
557 src->content_size, src->bytes_read);
559 if ( G_UNLIKELY (src->eos) || ( !src->live_tv
560 && ( src->bytes_read >= src->content_size ) ) )
565 const gchar *reason = gst_flow_get_name (ret);
567 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
572 const gchar *reason = gst_flow_get_name (ret);
574 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
575 return GST_FLOW_UNEXPECTED;
580 GST_ELEMENT_ERROR (src, RESOURCE, READ,
581 (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
582 return GST_FLOW_ERROR;
586 GST_ELEMENT_ERROR (src, RESOURCE, READ,
587 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
591 TODO: need to send a new segment event to NUVDemux?
592 gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
593 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
596 goto program_chain_changed;
602 gst_mythtv_src_get_position (GstMythtvSrc * src)
608 if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
609 GMYTHTV_TRANSFER_MAX_BUFFER)) {
613 size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
614 if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
615 src->content_size = size_tmp;
616 else if (size_tmp > 0 && --max_tries > 0)
618 GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
619 /* sets the last content size amount before it can be updated */
620 src->prev_content_size = src->content_size;
623 return src->content_size;
628 gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
630 GstMythtvSrc *src = GST_MYTHTV_SRC (base);
631 gint64 new_offset = -1;
632 gint64 actual_seek = segment->start;
635 GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
637 if (segment->format == GST_FORMAT_TIME) {
641 "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
642 actual_seek, src->read_offset);
643 /* verify if it needs to seek */
644 if (src->read_offset != actual_seek) {
646 /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
647 if ( IS_GMYTH_FILE_LOCAL(src->file) )
649 gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
650 else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
652 gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
655 "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
656 segment->start, src->read_offset, new_offset);
657 if (G_UNLIKELY (new_offset < 0)) {
663 src->read_offset = new_offset;
666 GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
676 GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
682 /* create a socket for connecting to remote server */
684 gst_mythtv_src_start (GstBaseSrc * bsrc)
686 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
688 GString *chain_id_local = NULL;
689 GMythURI *gmyth_uri = NULL;
692 if (src->unique_setup == FALSE) {
693 src->unique_setup = TRUE;
698 gmyth_uri = gmyth_uri_new_with_value( src->uri_name );
700 src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
701 src->live_tv |= gmyth_uri_is_livetv( gmyth_uri );
702 /* testing UPnP... */
703 /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
704 if ( src->live_tv ) {
705 src->spawn_livetv = gmyth_livetv_new (src->backend_info);
707 gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
709 src->channel_name = ch;
711 if (src->channel_name != NULL) {
712 if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
713 GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
718 if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
719 GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
725 /* testing change channel... */
726 /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
728 src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
730 if (NULL == src->file) {
731 GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
736 /* Check if the file is local to this specific client renderer */
737 if ( gmyth_uri_is_local_file(gmyth_uri) )
738 ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
740 ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ?
741 gmyth_uri_get_path(src->spawn_livetv->uri) :
742 src->spawn_livetv->proginfo->pathname->str );
744 /* sets the mythtvsrc "location" property */
745 g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
749 GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
750 g_object_unref( src->file );
756 /* Check if the file is local to this specific client renderer, and tries to open
759 if ( gmyth_uri_is_local_file(gmyth_uri) )
761 src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
762 ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
764 src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
765 ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
768 } /* if (else) - recorded FileTransfer */
770 if (NULL == src->file) {
771 GST_INFO_OBJECT (src, "FileTransfer is NULL");
774 /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
777 #ifndef GST_DISABLE_GST_DEBUG
778 if (src->mythtv_msgs_dbg)
779 GST_INFO_OBJECT (src,
780 "MythTV FileTransfer request failed when setting up socket connection!");
782 goto begin_req_failed;
785 GST_INFO_OBJECT (src,
786 "MythTV FileTransfer filesize = %lld, content_size = %lld!",
787 gmyth_file_get_filesize( src->file ), src->content_size);
789 src->content_size = gmyth_file_get_filesize (src->file);
791 src->do_start = FALSE;
793 /* this is used for the buffer cache */
794 src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
795 src->buffer_remain = 0;
797 gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
798 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
799 src->content_size, 0));
802 /*if ( gmyth_uri != NULL )
804 g_object_unref( gmyth_uri );
808 if (chain_id_local != NULL) {
809 g_string_free (chain_id_local, TRUE);
810 chain_id_local = NULL;
818 if (src->spawn_livetv != NULL)
819 g_object_unref (src->spawn_livetv);
821 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
822 (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
828 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
829 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
837 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
839 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
842 GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
843 abs (src->content_size - src->prev_content_size),
844 GMYTHTV_TRANSFER_MAX_BUFFER);
848 } else if (src->live_tv && src->enable_timing_position
849 && (abs (src->content_size - src->bytes_read) <
850 GMYTHTV_TRANSFER_MAX_BUFFER)) {
853 gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
854 if (new_offset > 0 && new_offset > src->content_size) {
855 src->content_size = new_offset;
856 } else if (new_offset < src->content_size) {
857 src->update_prog_chain = TRUE;
862 *size = src->content_size;
863 GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
869 /* close the socket and associated resources
870 * used both to recover from errors and go to NULL state */
872 gst_mythtv_src_stop (GstBaseSrc * bsrc)
874 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
876 gst_mythtv_src_clear (src);
878 /* src->eos = FALSE; */
884 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
886 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
887 gint64 cont_size = 0;
888 gboolean ret = FALSE;
890 switch (GST_EVENT_TYPE (event)) {
892 GST_WARNING_OBJECT (src, "Got EOS event");
895 cont_size = gst_mythtv_src_get_position (src);
896 if (cont_size > src->content_size) {
897 src->content_size = cont_size;
901 gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
902 gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
907 ret = gst_pad_event_default (pad, event);
914 gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
920 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
922 gboolean res = FALSE;
923 GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
926 switch (GST_QUERY_TYPE (query)) {
927 case GST_QUERY_POSITION:
929 gst_query_parse_position (query, &formt, NULL);
930 if (formt == GST_FORMAT_BYTES) {
931 gst_query_set_position (query, formt, myth->read_offset);
932 GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
934 } else if (formt == GST_FORMAT_TIME) {
935 res = gst_pad_query_default (pad, query);
939 case GST_QUERY_DURATION:
942 if (myth->duration != 0) {
946 fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
948 gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
952 gst_query_parse_duration (query, &formt, NULL);
953 if (formt == GST_FORMAT_BYTES) {
954 gst_query_set_duration (query, formt, myth->content_size);
955 GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, myth->content_size);
957 } else if (formt == GST_FORMAT_TIME) {
958 res = gst_pad_query_default (pad, query);
964 res = gst_pad_query_default (pad, query);
969 gst_object_unref (myth);
974 static GstStateChangeReturn
975 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
977 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
978 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
980 switch (transition) {
981 case GST_STATE_CHANGE_NULL_TO_READY:
983 case GST_STATE_CHANGE_READY_TO_PAUSED:
984 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
986 if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
988 GST_WARNING_OBJECT (src,
989 "Couldn't send the FRONTEND_READY message to the backend!");
991 GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
998 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
999 if (ret == GST_STATE_CHANGE_FAILURE)
1002 switch (transition) {
1003 case GST_STATE_CHANGE_READY_TO_NULL:
1005 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1006 case GST_STATE_CHANGE_PAUSED_TO_READY:
1016 gst_mythtv_src_set_property (GObject * object, guint prop_id,
1017 const GValue * value, GParamSpec * pspec)
1019 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1021 GST_OBJECT_LOCK (mythtvsrc);
1025 if (!g_value_get_string (value)) {
1026 GST_WARNING ("location property cannot be NULL");
1030 if (mythtvsrc->uri_name != NULL) {
1031 g_free (mythtvsrc->uri_name);
1032 mythtvsrc->uri_name = NULL;
1034 mythtvsrc->uri_name = g_value_dup_string (value);
1038 #ifndef GST_DISABLE_GST_DEBUG
1039 case PROP_GMYTHTV_DBG:
1041 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1045 case PROP_GMYTHTV_VERSION:
1047 mythtvsrc->mythtv_version = g_value_get_int (value);
1050 case PROP_GMYTHTV_LIVEID:
1052 mythtvsrc->live_tv_id = g_value_get_int (value);
1055 case PROP_GMYTHTV_LIVE:
1057 mythtvsrc->live_tv = g_value_get_boolean (value);
1060 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1062 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1065 case PROP_GMYTHTV_LIVE_CHAINID:
1067 if (!g_value_get_string (value)) {
1068 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1072 if (mythtvsrc->live_chain_id != NULL) {
1073 g_free (mythtvsrc->live_chain_id);
1074 mythtvsrc->live_chain_id = NULL;
1076 mythtvsrc->live_chain_id = g_value_dup_string (value);
1079 case PROP_GMYTHTV_CHANNEL_NUM:
1081 mythtvsrc->channel_name = g_value_dup_string (value);
1085 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1089 GST_OBJECT_UNLOCK (mythtvsrc);
1093 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1094 GValue * value, GParamSpec * pspec)
1096 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1098 GST_OBJECT_LOCK (mythtvsrc);
1102 g_value_set_string (value, mythtvsrc->uri_name);
1105 #ifndef GST_DISABLE_GST_DEBUG
1106 case PROP_GMYTHTV_DBG:
1107 g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
1110 case PROP_GMYTHTV_VERSION:
1112 g_value_set_int (value, mythtvsrc->mythtv_version);
1115 case PROP_GMYTHTV_LIVEID:
1117 g_value_set_int (value, mythtvsrc->live_tv_id);
1120 case PROP_GMYTHTV_LIVE:
1121 g_value_set_boolean (value, mythtvsrc->live_tv);
1123 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1124 g_value_set_boolean (value, mythtvsrc->enable_timing_position);
1126 case PROP_GMYTHTV_LIVE_CHAINID:
1128 g_value_set_string (value, mythtvsrc->live_chain_id);
1131 case PROP_GMYTHTV_CHANNEL_NUM:
1133 g_value_set_string (value, mythtvsrc->channel_name);
1137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1140 GST_OBJECT_UNLOCK (mythtvsrc);
1144 plugin_init (GstPlugin * plugin)
1146 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1147 GST_TYPE_MYTHTV_SRC);
1150 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1154 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
1157 /*** GSTURIHANDLER INTERFACE *************************************************/
1159 gst_mythtv_src_uri_get_type (void)
1165 gst_mythtv_src_uri_get_protocols (void)
1167 static gchar *protocols[] = { "myth", "myths", NULL };
1172 static const gchar *
1173 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1175 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1177 return src->uri_name;
1181 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1183 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1187 protocol = gst_uri_get_protocol (uri);
1188 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1193 g_object_set (src, "location", uri, NULL);
1199 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1201 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1203 iface->get_type = gst_mythtv_src_uri_get_type;
1204 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1205 iface->get_uri = gst_mythtv_src_uri_get_uri;
1206 iface->set_uri = gst_mythtv_src_uri_set_uri;
1210 size_header_handler (void *userdata, const char *value)
1212 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1214 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);