[svn r558] Sets the mythtv source "location" property, with the new pathname.
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 * If you want to get the LiveTV content (set channel, TV tuner, RemoteEncoder,
22 * put the following URI:
24 * myth://xxx.xxx.xxx.xxx:6543/livetv?channel=BBC
26 * This URI will say to the gmyth library to configure the Recorder instance (used to
27 * change the channel, start the TV multimedia content transmition, etc.), using
28 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
29 * server, and setting the channel name to "BBC".
31 * To get a already recorded the MythTV NUV file, put the following URI:
33 * myth://xxx.xxx.xxx.xxx:6543/filename.nuv
35 * This URI will say to the gmyth library to configure the Recorder instance (used to
36 * change the channel, start the TV multimedia content transmition, etc.), using
37 * the IP address (xxx.xxx.xxx.xxx) and port number (6543) of the MythTV backend
38 * server, and setting the channel name to "BBC".
40 * Another possible way to use the LiveTV content, and just in the case you want to
41 * use the mysql database, put the location URI in the following format:
43 * myth://mythtv:mythtv@xxx.xxx.xxx.xxx:6543/?mythconverg&channel=9
45 * Where the first field is the protocol (myth), the second and third are user
46 * name (mythtv) and password (mythtv), then backend host name and port number,
47 * and the last field is the database name (mythconverg).
54 #include "gstmythtvsrc.h"
55 #include <gmyth/gmyth_file.h>
56 #include <gmyth/gmyth_file_transfer.h>
57 #include <gmyth/gmyth_file_local.h>
58 #include <gmyth/gmyth_livetv.h>
60 #include <gmyth/gmyth_socket.h>
61 #include <gmyth/gmyth_tvchain.h>
66 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
67 #define GST_CAT_DEFAULT mythtvsrc_debug
69 #define GST_GMYTHTV_ID_NUM 1
71 #define GST_GMYTHTV_CHANNEL_DEFAULT_NUM (-1)
73 #define GMYTHTV_VERSION_DEFAULT 30
75 #define GMYTHTV_TRANSFER_MAX_WAITS 100
77 #define GMYTHTV_TRANSFER_MAX_RESENDS 2
79 #define GMYTHTV_TRANSFER_MAX_BUFFER (128*1024)
81 #define MAX_READ_SIZE (4*1024)
83 #define GST_FLOW_ERROR_NO_DATA (-101)
85 #define REQUEST_MAX_SIZE (64*1024)
87 #define INTERNAL_BUFFER_SIZE (90*1024)
89 static const GstElementDetails gst_mythtv_src_details =
90 GST_ELEMENT_DETAILS ("MythTV client source",
92 "Control and receive data as a client over the network "
93 "via raw socket connections using the MythTV protocol",
94 "Rosfran Borges <rosfran.borges@indt.org.br>");
96 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
99 GST_STATIC_CAPS ("video/x-nuv"));
105 #ifndef GST_DISABLE_GST_DEBUG
108 PROP_GMYTHTV_VERSION,
111 PROP_GMYTHTV_LIVE_CHAINID,
112 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
113 PROP_GMYTHTV_CHANNEL_NUM
116 static void gst_mythtv_src_clear (GstMythtvSrc *mythtv_src);
118 static void gst_mythtv_src_finalize (GObject * gobject);
120 static GstFlowReturn gst_mythtv_src_create (GstPushSrc * psrc,
121 GstBuffer ** outbuf);
123 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
124 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
125 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
126 static gboolean gst_mythtv_src_is_seekable (GstBaseSrc * push_src);
128 static gboolean gst_mythtv_src_do_seek (GstBaseSrc * base,
129 GstSegment * segment);
131 static GstStateChangeReturn
132 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
134 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
135 const GValue * value, GParamSpec * pspec);
136 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
137 GValue * value, GParamSpec * pspec);
139 static void gst_mythtv_src_uri_handler_init (gpointer g_iface,
140 gpointer iface_data);
142 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
144 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
146 static GMythFileReadResult do_read_request_response (GstMythtvSrc * src, guint size,
147 GByteArray * data_ptr);
150 _urihandler_init (GType type)
152 static const GInterfaceInfo urihandler_info = {
153 gst_mythtv_src_uri_handler_init,
158 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
160 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src");
163 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
164 GST_TYPE_PUSH_SRC, _urihandler_init)
166 static void gst_mythtv_src_base_init (gpointer g_class)
168 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
170 gst_element_class_add_pad_template (element_class,
171 gst_static_pad_template_get (&srctemplate));
173 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
175 element_class->change_state = gst_mythtv_src_change_state;
180 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
182 GObjectClass *gobject_class;
183 GstPushSrcClass *gstpushsrc_class;
184 GstBaseSrcClass *gstbasesrc_class;
186 gobject_class = (GObjectClass *) klass;
187 gstbasesrc_class = (GstBaseSrcClass *) klass;
188 gstpushsrc_class = (GstPushSrcClass *) klass;
190 gobject_class->set_property = gst_mythtv_src_set_property;
191 gobject_class->get_property = gst_mythtv_src_get_property;
192 gobject_class->finalize = gst_mythtv_src_finalize;
194 g_object_class_install_property
195 (gobject_class, PROP_LOCATION,
196 g_param_spec_string ("location", "Location",
197 "The location. In the form:"
198 "\n\t\t\tmyth://a.com/file.nuv"
199 "\n\t\t\tmyth://a.com:23223/file.nuv "
200 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
201 "", G_PARAM_READWRITE));
203 g_object_class_install_property
204 (gobject_class, PROP_GMYTHTV_VERSION,
205 g_param_spec_int ("mythtv-version", "mythtv-version",
206 "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE));
208 g_object_class_install_property
209 (gobject_class, PROP_GMYTHTV_LIVEID,
210 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
211 "Change MythTV version",
212 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
214 g_object_class_install_property
215 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
216 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
217 "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE));
219 g_object_class_install_property
220 (gobject_class, PROP_GMYTHTV_LIVE,
221 g_param_spec_boolean ("mythtv-live", "mythtv-live",
222 "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE));
224 g_object_class_install_property
225 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
226 g_param_spec_boolean ("mythtv-enable-timing-position",
227 "mythtv-enable-timing-position",
228 "Enable MythTV Live TV content size continuous updating", FALSE,
231 g_object_class_install_property
232 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
233 g_param_spec_string ("mythtv-channel", "mythtv-channel",
234 "Change MythTV channel number",
235 "", G_PARAM_READWRITE));
237 #ifndef GST_DISABLE_GST_DEBUG
238 g_object_class_install_property
239 (gobject_class, PROP_GMYTHTV_DBG,
240 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
241 "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE));
244 gstbasesrc_class->start = gst_mythtv_src_start;
245 gstbasesrc_class->stop = gst_mythtv_src_stop;
246 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
247 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
249 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
250 gstpushsrc_class->create = gst_mythtv_src_create;
252 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
253 "MythTV Client Source");
257 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
261 this->unique_setup = FALSE;
263 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
265 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
267 this->bytes_read = 0;
269 this->prev_content_size = 0;
271 this->content_size = 0;
272 this->read_offset = 0;
274 this->content_size_last = 0;
276 this->live_tv = FALSE;
278 this->enable_timing_position = FALSE;
279 this->update_prog_chain = FALSE;
281 this->user_agent = g_strdup ("mythtvsrc");
282 this->update_prog_chain = FALSE;
284 this->channel_name = NULL;
288 this->bytes_queue = NULL;
290 this->wait_to_transfer = 0;
292 gst_base_src_set_format (GST_BASE_SRC (this), GST_FORMAT_BYTES);
294 gst_pad_set_event_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
295 gst_mythtv_src_handle_event);
296 gst_pad_set_query_function (GST_BASE_SRC_PAD (GST_BASE_SRC (this)),
297 gst_mythtv_src_handle_query);
302 gst_mythtv_src_clear (GstMythtvSrc *mythtv_src)
305 if (mythtv_src->spawn_livetv) {
306 g_object_unref (mythtv_src->spawn_livetv);
307 mythtv_src->spawn_livetv = NULL;
310 if (mythtv_src->file) {
311 g_object_unref (mythtv_src->file);
312 mythtv_src->file = NULL;
315 if (mythtv_src->backend_info) {
316 g_object_unref (mythtv_src->backend_info);
317 mythtv_src->backend_info = NULL;
320 if (mythtv_src->uri_name) {
321 g_free (mythtv_src->uri_name);
324 if (mythtv_src->user_agent) {
325 g_free (mythtv_src->user_agent);
328 if (mythtv_src->bytes_queue) {
329 g_byte_array_free (mythtv_src->bytes_queue, TRUE);
330 mythtv_src->bytes_queue = NULL;
336 gst_mythtv_src_finalize (GObject * gobject)
338 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
340 gst_mythtv_src_clear (this);
342 G_OBJECT_CLASS (parent_class)->finalize (gobject);
345 static GMythFileReadResult
346 do_read_request_response (GstMythtvSrc * src, guint size, GByteArray *data_ptr)
349 guint sizetoread = size;
350 gint max_iters = GMYTHTV_TRANSFER_MAX_RESENDS;
351 GMythFileReadResult result;
353 GST_LOG_OBJECT (src, "Starting: Reading %d bytes...", sizetoread);
355 /* Loop sending the Myth File Transfer request:
356 * Retry whilst authentication fails and we supply it. */
358 while (sizetoread == size && --max_iters > 0) {
359 /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
360 if ( IS_GMYTH_FILE_LOCAL(src->file) )
361 result = gmyth_file_local_read ( GMYTH_FILE_LOCAL(src->file),
362 data_ptr, sizetoread, src->live_tv);
363 else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
364 result = gmyth_file_transfer_read ( GMYTH_FILE_TRANSFER(src->file),
365 data_ptr, sizetoread, src->live_tv);
367 if (data_ptr->len > 0) {
368 read += data_ptr->len;
369 sizetoread -= data_ptr->len;
370 } else if (data_ptr->len < 0) {
371 if (src->live_tv == FALSE) {
372 result = GMYTH_FILE_READ_EOF;
375 if (result == GMYTH_FILE_READ_ERROR) { /* -314 */
376 GST_INFO_OBJECT (src, "[LiveTV] FileTransfer READ_ERROR!");
378 } else if (result == GMYTH_FILE_READ_NEXT_PROG_CHAIN) { /* -315 */
379 GST_INFO_OBJECT (src,
380 "[LiveTV] FileTransfer - Go to the next program chain!");
386 } else if (data_ptr->len == 0)
389 if (read == sizetoread)
393 if ((read < 0 && !src->live_tv) || max_iters == 0){
394 result = GMYTH_FILE_READ_EOF;
408 gst_mythtv_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
411 GstFlowReturn ret = GST_FLOW_OK;
412 guint buffer_size_inter = 0;
414 src = GST_MYTHTV_SRC (psrc);
416 /* The caller should know the number of bytes and not read beyond EOS. */
417 if (G_UNLIKELY (src->eos))
419 if (G_UNLIKELY (src->update_prog_chain))
420 goto change_progchain;
422 GST_DEBUG_OBJECT (src, "offset = %" G_GUINT64_FORMAT ", size = %d...",
423 src->read_offset, MAX_READ_SIZE);
425 GST_DEBUG_OBJECT (src, "Create: buffer_remain: %d, buffer_size = %d.",
426 (gint) src->buffer_remain, src->bytes_queue->len);
428 program_chain_changed:
429 /* just get from the byte array, no network effort... */
430 if ((src->buffer_remain = src->bytes_queue->len) < MAX_READ_SIZE) {
432 GMythFileReadResult result = GMYTH_FILE_READ_OK;
435 buffer_size_inter = (INTERNAL_BUFFER_SIZE - src->buffer_remain);
437 if (buffer_size_inter > REQUEST_MAX_SIZE)
438 buffer_size_inter = REQUEST_MAX_SIZE;
440 buffer = g_byte_array_new ();
442 result = do_read_request_response (src, buffer_size_inter, buffer);
444 if (G_UNLIKELY (buffer->len < 0)) {
446 if (buffer != NULL) {
447 g_byte_array_free (buffer, TRUE);
451 if (src->live_tv || ( result == GMYTH_FILE_READ_NEXT_PROG_CHAIN ))
452 goto change_progchain;
455 } else if (G_UNLIKELY (read == 0)) {
457 if (buffer != NULL) {
458 g_byte_array_free (buffer, TRUE);
465 goto program_chain_changed;
468 if (G_UNLIKELY (src->update_prog_chain))
470 if (buffer != NULL) {
471 g_byte_array_free (buffer, TRUE);
474 goto change_progchain;
478 g_byte_array_append (src->bytes_queue, buffer->data, buffer->len);
479 if (buffer->len > buffer_size_inter)
480 GST_WARNING_OBJECT (src,
481 "INCREASED buffer size! Backend sent more than we ask him... (%d)",
482 abs (buffer->len - buffer_size_inter));
484 src->buffer_remain += buffer->len;
486 if (buffer != NULL) {
487 g_byte_array_free (buffer, TRUE);
491 GST_DEBUG_OBJECT (src,
492 "BYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "
493 "OFFSET = %llu, CONTENT SIZE = %llu.", read,
494 src->bytes_read, src->read_offset, src->content_size);
499 (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
501 *outbuf = gst_buffer_new ();
503 /* gets the first buffer_size bytes from the byte array buffer variable */
504 /* guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); */
506 GST_DEBUG_OBJECT (src, "read from network? %s!, buffer_remain = %d",
507 (buffer_size_inter ==
508 0) ? "NO, got from buffer" : "YES, go see the backend's log file",
511 GST_BUFFER_SIZE (*outbuf) = buffer_size;
512 GST_BUFFER_MALLOCDATA (*outbuf) = g_malloc0 (GST_BUFFER_SIZE (*outbuf));
513 GST_BUFFER_DATA (*outbuf) = GST_BUFFER_MALLOCDATA (*outbuf);
514 g_memmove (GST_BUFFER_DATA ((*outbuf)), src->bytes_queue->data,
515 GST_BUFFER_SIZE (*outbuf));
516 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
517 GST_BUFFER_OFFSET_END (*outbuf) =
518 src->read_offset + GST_BUFFER_SIZE (*outbuf);
520 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
522 src->read_offset += GST_BUFFER_SIZE (*outbuf);
523 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
524 GST_DEBUG_OBJECT (src, "Buffer output with size: %d",
525 GST_BUFFER_SIZE (*outbuf));
527 /* flushs the newly buffer got from byte array */
529 g_byte_array_remove_range (src->bytes_queue, 0, buffer_size);
531 GST_DEBUG_OBJECT ( src, "Got buffer: BUFFER --->SIZE = %d, OFFSET = %llu, "
532 "OFFSET_END = %llu.", GST_BUFFER_SIZE (*outbuf),
533 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
535 GST_DEBUG_OBJECT (src, "CONTENT_SIZE = %llu, BYTES_READ = %llu.",
536 src->content_size, src->bytes_read);
538 if ( G_UNLIKELY (src->eos) || ( !src->live_tv
539 && ( src->bytes_read >= src->content_size ) ) )
544 const gchar *reason = gst_flow_get_name (ret);
546 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
551 const gchar *reason = gst_flow_get_name (ret);
553 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
554 return GST_FLOW_UNEXPECTED;
559 GST_ELEMENT_ERROR (src, RESOURCE, READ,
560 (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name));
561 return GST_FLOW_ERROR;
565 GST_ELEMENT_ERROR (src, RESOURCE, READ,
566 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
570 TODO: need to send a new segment event to NUVDemux?
571 gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
572 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0));
575 goto program_chain_changed;
581 gst_mythtv_src_get_position (GstMythtvSrc * src)
587 if (src->live_tv == TRUE && (abs (src->content_size - src->bytes_read) <
588 GMYTHTV_TRANSFER_MAX_BUFFER)) {
592 size_tmp = gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
593 if (size_tmp > (src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER))
594 src->content_size = size_tmp;
595 else if (size_tmp > 0 && --max_tries > 0)
597 GST_LOG_OBJECT (src, "GET_POSITION: file_position = %lld", size_tmp);
598 /* sets the last content size amount before it can be updated */
599 src->prev_content_size = src->content_size;
602 return src->content_size;
607 gst_mythtv_src_do_seek (GstBaseSrc * base, GstSegment * segment)
609 GstMythtvSrc *src = GST_MYTHTV_SRC (base);
610 gint64 new_offset = -1;
611 gint64 actual_seek = segment->start;
614 GST_LOG_OBJECT (src, "seek, segment: %" GST_SEGMENT_FORMAT, segment);
616 if (segment->format == GST_FORMAT_TIME) {
620 "Trying to seek at the value (actual_seek = %lld, read_offset = %lld)",
621 actual_seek, src->read_offset);
622 /* verify if it needs to seek */
623 if (src->read_offset != actual_seek) {
625 /* if ( gmyth_backend_info_is_local_file(src->backend_info) ) */
626 if ( IS_GMYTH_FILE_LOCAL(src->file) )
628 gmyth_file_local_seek ( GMYTH_FILE_LOCAL(src->file), segment->start, G_SEEK_SET);
629 else if ( IS_GMYTH_FILE_TRANSFER(src->file) )
631 gmyth_file_transfer_seek ( GMYTH_FILE_TRANSFER(src->file), segment->start, SEEK_SET);
634 "Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.",
635 segment->start, src->read_offset, new_offset);
636 if (G_UNLIKELY (new_offset < 0)) {
642 src->read_offset = new_offset;
645 GST_INFO_OBJECT (src, "Failed to set the SEEK on segment!");
655 GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
661 /* create a socket for connecting to remote server */
663 gst_mythtv_src_start (GstBaseSrc * bsrc)
665 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
667 GString *chain_id_local = NULL;
668 GMythURI *gmyth_uri = NULL;
671 if (src->unique_setup == FALSE) {
672 src->unique_setup = TRUE;
677 gmyth_uri = gmyth_uri_new_with_value( src->uri_name );
679 src->backend_info = gmyth_backend_info_new_with_uri (src->uri_name);
680 src->live_tv |= gmyth_uri_is_livetv( gmyth_uri );
681 /* testing UPnP... */
682 /* gmyth_backend_info_set_hostname( src->backend_info, NULL ); */
683 if ( src->live_tv ) {
684 src->spawn_livetv = gmyth_livetv_new (src->backend_info);
686 gchar* ch = gmyth_uri_get_channel_name( gmyth_uri );
688 src->channel_name = ch;
690 if (src->channel_name != NULL) {
691 if (gmyth_livetv_channel_name_setup (src->spawn_livetv, src->channel_name) == FALSE) {
692 GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
697 if (gmyth_livetv_setup (src->spawn_livetv) == FALSE) {
698 GST_INFO_OBJECT (src, "LiveTV setup felt down on error");
704 /* testing change channel... */
705 /* gmyth_recorder_change_channel( src->spawn_livetv->recorder, CHANNEL_DIRECTION_UP ); */
707 src->file = GMYTH_FILE( gmyth_livetv_create_file_transfer (src->spawn_livetv) );
709 if (NULL == src->file) {
710 GST_INFO_OBJECT (src, "[LiveTV] FileTransfer equals to NULL");
715 /* Check if the file is local to this specific client renderer */
716 if ( gmyth_uri_is_local_file(gmyth_uri) )
717 ret = gmyth_file_local_open( GMYTH_FILE_LOCAL(src->file) );
719 ret = gmyth_file_transfer_open( GMYTH_FILE_TRANSFER(src->file), src->spawn_livetv->uri != NULL ?
720 gmyth_uri_get_path(src->spawn_livetv->uri) :
721 src->spawn_livetv->proginfo->pathname->str );
723 /* sets the mythtvsrc "location" property */
724 g_object_set (src, "location", gmyth_file_get_uri (src->file), NULL);
728 GST_INFO_OBJECT (src, "Error: couldn't open the FileTransfer from LiveTV source!" );
729 g_object_unref( src->file );
735 /* Check if the file is local to this specific client renderer, and tries to open
738 if ( gmyth_uri_is_local_file(gmyth_uri) )
740 src->file = GMYTH_FILE(gmyth_file_local_new(src->backend_info));
741 ret = gmyth_file_local_open ( GMYTH_FILE_LOCAL( src->file ) );
743 src->file = GMYTH_FILE(gmyth_file_transfer_new(src->backend_info));
744 ret = gmyth_file_transfer_open ( GMYTH_FILE_TRANSFER(src->file), src->uri_name );
747 } /* if (else) - recorded FileTransfer */
749 if (NULL == src->file) {
750 GST_INFO_OBJECT (src, "FileTransfer is NULL");
753 /*GST_INFO_OBJECT( src, "uri = %s", src->spawn_livetv->file); */
756 #ifndef GST_DISABLE_GST_DEBUG
757 if (src->mythtv_msgs_dbg)
758 GST_INFO_OBJECT (src,
759 "MythTV FileTransfer request failed when setting up socket connection!");
761 goto begin_req_failed;
764 GST_INFO_OBJECT (src,
765 "MythTV FileTransfer filesize = %lld, content_size = %lld!",
766 gmyth_file_get_filesize( src->file ), src->content_size);
768 src->content_size = gmyth_file_get_filesize (src->file);
770 src->do_start = FALSE;
772 /* this is used for the buffer cache */
773 src->bytes_queue = g_byte_array_sized_new (INTERNAL_BUFFER_SIZE);
774 src->buffer_remain = 0;
776 gst_pad_push_event (GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
777 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0,
778 src->content_size, 0));
781 /*if ( gmyth_uri != NULL )
783 g_object_unref( gmyth_uri );
787 if (chain_id_local != NULL) {
788 g_string_free (chain_id_local, TRUE);
789 chain_id_local = NULL;
797 if (src->spawn_livetv != NULL)
798 g_object_unref (src->spawn_livetv);
800 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
801 (NULL), ("Could not initialize MythTV library (%i, %s)", ret,
807 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
808 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret,
816 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
818 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
821 GST_LOG_OBJECT (src, "Differs from previous content size: %d (max.: %d)",
822 abs (src->content_size - src->prev_content_size),
823 GMYTHTV_TRANSFER_MAX_BUFFER);
827 } else if (src->live_tv && src->enable_timing_position
828 && (abs (src->content_size - src->bytes_read) <
829 GMYTHTV_TRANSFER_MAX_BUFFER)) {
832 gmyth_recorder_get_file_position (src->spawn_livetv->recorder);
833 if (new_offset > 0 && new_offset > src->content_size) {
834 src->content_size = new_offset;
835 } else if (new_offset < src->content_size) {
836 src->update_prog_chain = TRUE;
841 *size = src->content_size;
842 GST_LOG_OBJECT (src, "Content size = %lld", src->content_size);
848 /* close the socket and associated resources
849 * used both to recover from errors and go to NULL state */
851 gst_mythtv_src_stop (GstBaseSrc * bsrc)
853 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
855 gst_mythtv_src_clear (src);
857 /* src->eos = FALSE; */
863 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
865 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
866 gint64 cont_size = 0;
867 gboolean ret = FALSE;
869 switch (GST_EVENT_TYPE (event)) {
871 GST_WARNING_OBJECT (src, "Got EOS event");
874 cont_size = gst_mythtv_src_get_position (src);
875 if (cont_size > src->content_size) {
876 src->content_size = cont_size;
880 gst_element_set_state (GST_ELEMENT (src), GST_STATE_NULL);
881 gst_element_set_locked_state (GST_ELEMENT (src), FALSE);
886 ret = gst_pad_event_default (pad, event);
893 gst_mythtv_src_is_seekable (GstBaseSrc * push_src)
899 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
901 gboolean res = FALSE;
902 GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
905 switch (GST_QUERY_TYPE (query)) {
906 case GST_QUERY_POSITION:
908 gst_query_parse_position (query, &formt, NULL);
909 if (formt == GST_FORMAT_BYTES) {
910 gst_query_set_position (query, formt, myth->read_offset);
911 GST_DEBUG_OBJECT (myth, "POS %" G_GINT64_FORMAT, myth->read_offset);
913 } else if (formt == GST_FORMAT_TIME) {
914 res = gst_pad_query_default (pad, query);
918 case GST_QUERY_DURATION:
921 if (myth->duration != 0) {
925 fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
927 gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
931 gst_query_parse_duration (query, &formt, NULL);
932 if (formt == GST_FORMAT_BYTES) {
933 gst_query_set_duration (query, formt, myth->content_size);
934 GST_DEBUG_OBJECT (myth, "SIZE %" G_GINT64_FORMAT, myth->content_size);
936 } else if (formt == GST_FORMAT_TIME) {
937 res = gst_pad_query_default (pad, query);
943 res = gst_pad_query_default (pad, query);
948 gst_object_unref (myth);
953 static GstStateChangeReturn
954 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
956 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;
957 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
959 switch (transition) {
960 case GST_STATE_CHANGE_NULL_TO_READY:
962 case GST_STATE_CHANGE_READY_TO_PAUSED:
963 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
965 if (!gmyth_recorder_send_frontend_ready_command (src->spawn_livetv->
967 GST_WARNING_OBJECT (src,
968 "Couldn't send the FRONTEND_READY message to the backend!");
970 GST_DEBUG_OBJECT (src, "FRONTEND_READY was sent to the backend");
977 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
978 if (ret == GST_STATE_CHANGE_FAILURE)
981 switch (transition) {
982 case GST_STATE_CHANGE_READY_TO_NULL:
984 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
985 case GST_STATE_CHANGE_PAUSED_TO_READY:
995 gst_mythtv_src_set_property (GObject * object, guint prop_id,
996 const GValue * value, GParamSpec * pspec)
998 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1000 GST_OBJECT_LOCK (mythtvsrc);
1004 if (!g_value_get_string (value)) {
1005 GST_WARNING ("location property cannot be NULL");
1009 if (mythtvsrc->uri_name != NULL) {
1010 g_free (mythtvsrc->uri_name);
1011 mythtvsrc->uri_name = NULL;
1013 mythtvsrc->uri_name = g_value_dup_string (value);
1017 #ifndef GST_DISABLE_GST_DEBUG
1018 case PROP_GMYTHTV_DBG:
1020 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1024 case PROP_GMYTHTV_VERSION:
1026 mythtvsrc->mythtv_version = g_value_get_int (value);
1029 case PROP_GMYTHTV_LIVEID:
1031 mythtvsrc->live_tv_id = g_value_get_int (value);
1034 case PROP_GMYTHTV_LIVE:
1036 mythtvsrc->live_tv = g_value_get_boolean (value);
1039 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1041 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1044 case PROP_GMYTHTV_LIVE_CHAINID:
1046 if (!g_value_get_string (value)) {
1047 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1051 if (mythtvsrc->live_chain_id != NULL) {
1052 g_free (mythtvsrc->live_chain_id);
1053 mythtvsrc->live_chain_id = NULL;
1055 mythtvsrc->live_chain_id = g_value_dup_string (value);
1058 case PROP_GMYTHTV_CHANNEL_NUM:
1060 mythtvsrc->channel_name = g_value_dup_string (value);
1064 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1068 GST_OBJECT_UNLOCK (mythtvsrc);
1072 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1073 GValue * value, GParamSpec * pspec)
1075 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1077 GST_OBJECT_LOCK (mythtvsrc);
1081 g_value_set_string (value, mythtvsrc->uri_name);
1084 #ifndef GST_DISABLE_GST_DEBUG
1085 case PROP_GMYTHTV_DBG:
1086 g_value_set_boolean (value, mythtvsrc->mythtv_msgs_dbg);
1089 case PROP_GMYTHTV_VERSION:
1091 g_value_set_int (value, mythtvsrc->mythtv_version);
1094 case PROP_GMYTHTV_LIVEID:
1096 g_value_set_int (value, mythtvsrc->live_tv_id);
1099 case PROP_GMYTHTV_LIVE:
1100 g_value_set_boolean (value, mythtvsrc->live_tv);
1102 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1103 g_value_set_boolean (value, mythtvsrc->enable_timing_position);
1105 case PROP_GMYTHTV_LIVE_CHAINID:
1107 g_value_set_string (value, mythtvsrc->live_chain_id);
1110 case PROP_GMYTHTV_CHANNEL_NUM:
1112 g_value_set_string (value, mythtvsrc->channel_name);
1116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1119 GST_OBJECT_UNLOCK (mythtvsrc);
1123 plugin_init (GstPlugin * plugin)
1125 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1126 GST_TYPE_MYTHTV_SRC);
1129 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1133 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
1136 /*** GSTURIHANDLER INTERFACE *************************************************/
1138 gst_mythtv_src_uri_get_type (void)
1144 gst_mythtv_src_uri_get_protocols (void)
1146 static gchar *protocols[] = { "myth", "myths", NULL };
1151 static const gchar *
1152 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1154 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1156 return src->uri_name;
1160 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1162 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1166 protocol = gst_uri_get_protocol (uri);
1167 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1172 g_object_set (src, "location", uri, NULL);
1178 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1180 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1182 iface->get_type = gst_mythtv_src_uri_get_type;
1183 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1184 iface->get_uri = gst_mythtv_src_uri_get_uri;
1185 iface->set_uri = gst_mythtv_src_uri_set_uri;
1189 size_header_handler (void *userdata, const char *value)
1191 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1193 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);