1 /* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2 -*- */
2 /* GStreamer MythTV Plug-in
3 * Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library Lesser General
7 * Public License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more
20 #include "gstmythtvsrc.h"
21 #include <gmyth/gmyth_file_transfer.h>
22 #include <gmyth/gmyth_livetv.h>
24 #include <gmyth/gmyth_socket.h>
25 #include <gmyth/gmyth_tvchain.h>
30 GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
31 #define GST_CAT_DEFAULT mythtvsrc_debug
33 #define GST_GMYTHTV_ID_NUM 1
35 #define GST_GMYTHTV_CHANNEL_NUM 1000
37 #define GMYTHTV_VERSION_DEFAULT 30
39 #define GMYTHTV_TRANSFER_MAX_WAITS 100
41 #define GMYTHTV_TRANSFER_MAX_BUFFER 128*1024
45 #define MAX_READ_SIZE 2*1024
48 #define GST_FLOW_ERROR_NO_DATA -101
50 /* stablish a maximum iteration value to the IS_RECORDING message */
51 static guint wait_to_transfer = 0;
53 static const GstElementDetails gst_mythtv_src_details =
54 GST_ELEMENT_DETAILS ( "MythTV client source",
56 "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
57 "Rosfran Borges <rosfran.borges@indt.org.br>" );
59 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ( "src",
62 GST_STATIC_CAPS ("video/x-nuv") );
69 #ifndef GST_DISABLE_GST_DEBUG
75 PROP_GMYTHTV_LIVE_CHAINID,
76 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
77 PROP_GMYTHTV_CHANNEL_NUM
80 static void gst_mythtv_src_finalize (GObject * gobject);
83 static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
84 guint size, GstBuffer ** outbuf);
87 //static GstFlowReturn gst_mythtv_src_chain ( GstPad* pad, GstBuffer* outbuf );
88 static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
90 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
91 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
92 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
93 //static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
95 static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
97 static GstStateChangeReturn
98 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
100 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * pspec);
102 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * pspec);
105 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
107 //static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
108 //static gboolean gst_mythtv_src_query ( GstPad * pad, GstQuery * query );
110 static gint do_read_request_response (GstMythtvSrc *src, guint64 offset,
111 guint size, GstBuffer **outbuf);
114 _urihandler_init (GType type)
116 static const GInterfaceInfo urihandler_info = {
117 gst_mythtv_src_uri_handler_init,
122 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
124 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
128 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
129 // GST_TYPE_BASE_SRC, _urihandler_init)
131 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
132 GST_TYPE_PUSH_SRC, _urihandler_init)
135 gst_mythtv_src_base_init (gpointer g_class)
137 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
139 gst_element_class_add_pad_template (element_class,
140 gst_static_pad_template_get (&srctemplate));
142 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
144 element_class->change_state = gst_mythtv_src_change_state;
149 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
151 GObjectClass *gobject_class;
152 GstPushSrcClass *gstpushsrc_class;
153 GstBaseSrcClass *gstbasesrc_class;
155 gobject_class = (GObjectClass *) klass;
156 gstbasesrc_class = (GstBaseSrcClass *) klass;
157 gstpushsrc_class = (GstPushSrcClass *) klass;
159 gobject_class->set_property = gst_mythtv_src_set_property;
160 gobject_class->get_property = gst_mythtv_src_get_property;
161 gobject_class->finalize = gst_mythtv_src_finalize;
163 g_object_class_install_property
164 (gobject_class, PROP_LOCATION,
165 g_param_spec_string ("location", "Location",
166 "The location. In the form:"
167 "\n\t\t\tmyth://a.com/file.nuv"
168 "\n\t\t\tmyth://a.com:23223/file.nuv "
169 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
170 "", G_PARAM_READWRITE));
172 g_object_class_install_property
173 (gobject_class, PROP_URI,
174 g_param_spec_string ("uri", "Uri",
175 "The location in form of a URI (deprecated; use location)",
176 "", G_PARAM_READWRITE));
178 g_object_class_install_property
179 (gobject_class, PROP_GMYTHTV_VERSION,
180 g_param_spec_int ("mythtv-version", "mythtv-version",
181 "Change MythTV version",
182 26, 30, 26, G_PARAM_READWRITE));
184 g_object_class_install_property
185 (gobject_class, PROP_GMYTHTV_LIVEID,
186 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
187 "Change MythTV version",
188 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
190 g_object_class_install_property
191 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
192 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
193 "Sets the MythTV chain ID (from TV Chain)",
194 "", G_PARAM_READWRITE));
196 g_object_class_install_property
197 (gobject_class, PROP_GMYTHTV_LIVE,
198 g_param_spec_boolean ("mythtv-live", "mythtv-live",
199 "Enable MythTV Live TV content streaming",
200 FALSE, G_PARAM_READWRITE));
202 g_object_class_install_property
203 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
204 g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
205 "Enable MythTV Live TV content size continuous updating",
206 FALSE, G_PARAM_READWRITE));
208 g_object_class_install_property
209 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
210 g_param_spec_int ("mythtv-channel", "mythtv-channel",
211 "Change MythTV channel number",
212 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
214 #ifndef GST_DISABLE_GST_DEBUG
215 g_object_class_install_property
216 (gobject_class, PROP_GMYTHTV_DBG,
217 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
218 "Enable MythTV debug messages",
219 FALSE, G_PARAM_READWRITE));
222 gstbasesrc_class->start = gst_mythtv_src_start;
223 gstbasesrc_class->stop = gst_mythtv_src_stop;
224 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
225 //gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
227 //gstbasesrc_class->create = gst_mythtv_src_create;
228 gstpushsrc_class->create = gst_mythtv_src_create;
230 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
231 "MythTV Client Source");
235 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
237 this->file_transfer = NULL;
239 this->unique_setup = FALSE;
241 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
243 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
245 this->bytes_read = 0;
247 this->prev_content_size = 0;
249 this->content_size = 0;
250 this->read_offset = 0;
252 this->content_size_last = 0;
254 this->live_tv = FALSE;
256 this->enable_timing_position = FALSE;
257 this->update_prog_chain = FALSE;
259 this->user_agent = g_strdup ("mythtvsrc");
260 this->mythtv_caps = NULL;
261 this->update_prog_chain = FALSE;
263 this->channel_num = 0;
267 this->adapter = NULL;
269 //this->th_read_ahead = NULL;
271 this->th_mutex = NULL;
273 this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
274 //gst_pad_set_chain_function ( GST_BASE_SRC_PAD( GST_BASE_SRC( this ) ),
275 // GST_DEBUG_FUNCPTR ( gst_mythtv_src_chain ) );
276 gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
278 //gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
280 gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
282 // gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
283 // gst_mythtv_src_handle_event );
288 gst_mythtv_src_finalize (GObject * gobject)
290 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
292 if ( this->th_mutex != NULL ) {
293 g_static_rec_mutex_free( this->th_mutex );
294 this->th_mutex = NULL;
297 if ( this->th_read_ahead != NULL ) {
298 gst_task_stop( this->th_read_ahead );
299 this->th_read_ahead = NULL;
302 if (this->mythtv_caps) {
303 gst_caps_unref (this->mythtv_caps);
304 this->mythtv_caps = NULL;
307 if (this->file_transfer) {
308 g_object_unref (this->file_transfer);
309 this->file_transfer = NULL;
312 if (this->spawn_livetv) {
313 g_object_unref (this->spawn_livetv);
314 this->spawn_livetv = NULL;
317 if (this->uri_name) {
318 g_free (this->uri_name);
321 if (this->user_agent) {
322 g_free (this->user_agent);
325 G_OBJECT_CLASS (parent_class)->finalize (gobject);
329 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, GstBuffer **outbuf)
332 guint sizetoread = size;
334 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
336 /* Loop sending the Myth File Transfer request:
337 * Retry whilst authentication fails and we supply it. */
339 gint8 *data_ptr = g_malloc0( size );
341 //GST_OBJECT_LOCK(src);
343 while ( sizetoread > 0 ) {
345 len = gmyth_file_transfer_read( src->file_transfer,
346 data_ptr + read, sizetoread, TRUE );
356 if ( src->live_tv == FALSE )
362 if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
363 src->update_prog_chain = TRUE;
366 if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
367 src->update_prog_chain = TRUE;
368 if ( src->enable_timing_position ) {
371 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
372 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
373 src->content_size = size_tmp;
374 else if ( size_tmp > 0 )
376 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
377 __FUNCTION__, size_tmp );
379 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
380 if ( new_offset > 0 && src->content_size <= new_offset ) {
381 src->content_size = new_offset;
383 src->update_prog_chain = TRUE;
385 src->prev_content_size = src->content_size;
393 if ( read == sizetoread )
398 src->read_offset += read;
399 src->bytes_read += read;
401 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
402 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
403 src->read_offset, src->content_size );
405 GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
406 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
407 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
408 g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
409 GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
410 GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
412 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
413 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
414 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
416 } else if ( !src->live_tv )
425 //GST_OBJECT_UNLOCK(src);
432 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
435 GstFlowReturn ret = GST_FLOW_OK;
437 gint adapter_size = -1;
439 guint max_adapter_rep = 40;
441 src = GST_MYTHTV_SRC (psrc);
443 /* The caller should know the number of bytes and not read beyond EOS. */
444 if (G_UNLIKELY (src->eos))
446 if ( G_UNLIKELY (src->update_prog_chain) )
447 goto change_progchain;
449 g_static_rec_mutex_lock( src->th_mutex );
451 while ( ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < size ) &&
452 --max_adapter_rep > 0 )
454 g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
455 GST_TASK_WAIT( src->th_read_ahead );
458 g_static_rec_mutex_unlock( src->th_mutex );
460 gint64 new_offset = -1;
461 /* just get from the adapter, no network effort... */
462 if ( offset > src->adapter_offset && size <= adapter_size )
465 GstBuffer *buf = gst_adapter_take_buffer( src->adapter, size );
466 *outbuf = gst_buffer_create_sub( buf, offset, size );
467 src->read_offset = new_offset = offset;
470 gst_adapter_flush( src->adapter, size );
473 /* no data on adapter... do all these mythtv network calls! */
475 /* verify if it needs to seek */
476 if ( src->read_offset != offset )
479 new_offset = gmyth_file_transfer_seek( src->file_transfer, offset, SEEK_SET );
481 g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
482 __FUNCTION__, src->read_offset, new_offset );
483 if ( G_UNLIKELY (new_offset < 0 ) )
486 goto change_progchain;
493 src->read_offset = offset;
495 /* Create the buffer. */
496 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
497 src->read_offset, size,
498 GST_PAD_CAPS ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)) ), outbuf);
500 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
502 goto change_progchain;
507 read = do_read_request_response ( src, src->read_offset, size, outbuf );
511 if (G_UNLIKELY (src->update_prog_chain) )
512 goto change_progchain;
514 if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
516 goto change_progchain;
522 src->read_offset += read;
523 src->bytes_read += read;
526 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
527 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
528 src->read_offset, src->content_size );
530 GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
531 //GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
532 //GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
533 //g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
534 GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
535 GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
537 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
538 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
539 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
546 const gchar *reason = gst_flow_get_name (ret);
548 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
553 const gchar *reason = gst_flow_get_name (ret);
555 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
556 return GST_FLOW_UNEXPECTED;
561 GST_ELEMENT_ERROR (src, RESOURCE, READ,
562 (NULL), ("Could not read any bytes (%i, %s)", read,
564 return GST_FLOW_ERROR;
568 GST_ELEMENT_ERROR (src, RESOURCE, READ,
569 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
572 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
573 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
574 // go to the next program chain
575 src->unique_setup = FALSE;
576 src->update_prog_chain = TRUE;
578 gst_mythtv_src_next_program_chain( src );
580 return GST_FLOW_ERROR_NO_DATA;
587 gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
590 GstFlowReturn ret = GST_FLOW_OK;
593 src = GST_MYTHTV_SRC ( psrc );
595 /* The caller should know the number of bytes and not read beyond EOS. */
596 if (G_UNLIKELY (src->eos))
598 if ( G_UNLIKELY (src->update_prog_chain) )
599 goto change_progchain;
601 //gint64 new_offset = -1;
602 /* just get from the adapter, no network effort... */
605 /* Create the buffer. */
606 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
607 GST_BUFFER_OFFSET_NONE, MAX_READ_SIZE,
608 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
610 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
612 goto change_progchain;
617 read = do_read_request_response ( src, src->read_offset, MAX_READ_SIZE, outbuf );
619 if (G_UNLIKELY (src->update_prog_chain) )
620 goto change_progchain;
622 if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
624 goto change_progchain;
633 const gchar *reason = gst_flow_get_name (ret);
635 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
640 const gchar *reason = gst_flow_get_name (ret);
642 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
643 return GST_FLOW_UNEXPECTED;
648 GST_ELEMENT_ERROR (src, RESOURCE, READ,
649 (NULL), ("Could not read any bytes (%i, %s)", read,
651 return GST_FLOW_ERROR;
655 GST_ELEMENT_ERROR (src, RESOURCE, READ,
656 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
659 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
660 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
661 // go to the next program chain
662 src->unique_setup = FALSE;
663 src->update_prog_chain = TRUE;
665 gst_mythtv_src_next_program_chain( src );
667 return GST_FLOW_ERROR_NO_DATA;
673 gst_mythtv_src_get_position ( GstMythtvSrc* src )
678 if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) <
679 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
683 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
684 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
685 src->content_size = size_tmp;
686 else if ( size_tmp > 0 && --max_tries > 0 )
688 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
689 __FUNCTION__, size_tmp );
690 /* sets the last content size amount before it can be updated */
691 src->prev_content_size = src->content_size;
694 return src->content_size;
700 gst_mythtv_src_read_ahead ( void *data ) {
702 GstMythtvSrc *src = NULL;
704 GstBuffer *buffer = NULL;
710 src = GST_MYTHTV_SRC( data );
712 GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
714 /*if ( gst_adapter_available( src->adapter ) ) && ( read < MAX_READ_SIZE )) */
716 buffer = gst_buffer_new_and_alloc( size );
718 read += do_read_request_response ( src, src->adapter_offset, size, &buffer );
720 gst_adapter_push( src->adapter, buffer );
722 //gst_buffer_unref( buffer );
723 } while ( read < MAX_READ_SIZE );
725 GST_PAD_BLOCK_SIGNAL( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
727 GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
729 gst_object_unref( src );
735 /* create a socket for connecting to remote server */
737 gst_mythtv_src_start ( GstBaseSrc * bsrc )
739 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
741 GString *chain_id_local = NULL;
745 if ( G_UNLIKELY (src->update_prog_chain) )
746 goto change_progchain;
748 if (src->unique_setup == FALSE) {
749 src->unique_setup = TRUE;
754 //GST_OBJECT_LOCK(src);
756 if ( src->live_tv ) {
757 src->spawn_livetv = gmyth_livetv_new( );
758 if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
760 //GST_OBJECT_UNLOCK( src );
764 /* set up the uri variable */
765 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
766 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
767 if ( chain_id_local != NULL ) {
768 src->live_chain_id = g_strdup( chain_id_local->str );
769 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
771 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
772 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
775 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
776 g_string_new( src->uri_name ), -1, src->mythtv_version );
778 if ( src->file_transfer == NULL ) {
779 //GST_OBJECT_UNLOCK(src);
784 /* sets the Playback monitor connection */
785 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
787 if ( src->live_tv == TRUE && ret == TRUE ) {
788 /* loop finished, set the max tries variable to zero again... */
789 wait_to_transfer = 0;
791 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
792 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE
793 /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
797 /* sets the FileTransfer instance connection (video/audio download) */
798 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
800 if ( ret == FALSE ) {
801 //GST_OBJECT_UNLOCK(src);
802 #ifndef GST_DISABLE_GST_DEBUG
803 if ( src->mythtv_msgs_dbg )
804 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
806 goto begin_req_failed;
809 src->content_size = src->file_transfer->filesize;
811 src->do_start = FALSE;
813 if ( src->live_tv ) {
814 //src->adapter = gst_adapter_new();
815 //g_static_rec_mutex_init( src->th_mutex );
816 //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
819 //GST_OBJECT_UNLOCK(src);
827 if (src->spawn_livetv != NULL )
828 g_object_unref( src->spawn_livetv );
830 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
831 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
836 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
837 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
842 GST_ELEMENT_ERROR (src, RESOURCE, READ,
843 (NULL), ("Seek failed, go to the next program info... (%s)",
846 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
847 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
849 // go to the next program chain
850 src->unique_setup = FALSE;
851 src->update_prog_chain = TRUE;
853 gst_mythtv_src_next_program_chain( src );
859 /* create a new socket for connecting to the next program chain */
861 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
863 GString *chain_id_local = NULL;
870 if (src->unique_setup == FALSE) {
871 src->unique_setup = TRUE;
876 GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
878 if (src->file_transfer) {
879 g_object_unref (src->file_transfer);
880 src->file_transfer = NULL;
884 g_free (src->uri_name);
887 if ( src->live_tv ) {
888 if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
889 g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ );
893 /* set up the uri variable */
894 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
895 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
896 if ( chain_id_local != NULL ) {
897 src->live_chain_id = g_strdup( chain_id_local->str );
898 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
900 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
901 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
904 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
905 g_string_new( src->uri_name ), -1, src->mythtv_version );
907 if ( src->file_transfer == NULL ) {
911 /* sets the Playback monitor connection */
912 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
914 if ( src->live_tv == TRUE && ret == TRUE ) {
915 /* loop finished, set the max tries variable to zero again... */
916 wait_to_transfer = 0;
920 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
921 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
925 /* sets the FileTransfer instance connection (video/audio download) */
926 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
928 if ( ret == FALSE ) {
929 #ifndef GST_DISABLE_GST_DEBUG
930 if ( src->mythtv_msgs_dbg )
931 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
933 goto begin_req_failed;
935 src->content_size_last = src->content_size;
938 if ( src->content_size < src->file_transfer->filesize ) {
939 src->content_size = src->file_transfer->filesize;
941 //gint64 pos = gst_mythtv_src_get_position(src);
942 //if ( pos > src->file_transfer->filesize )
943 // src->content_size = pos;
948 src->content_size = src->file_transfer->filesize;
949 while ( src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER*4 )
950 src->content_size = gst_mythtv_src_get_position( src );
952 src->read_offset = 0;
955 src->update_prog_chain = FALSE;
957 GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
964 if (src->spawn_livetv != NULL )
965 g_object_unref( src->spawn_livetv );
967 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
968 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
973 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
974 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
981 /* handles queries for location in the stream in the requested format */
983 gst_mythtv_src_query ( GstPad * pad, GstQuery * query )
986 GstMythtvSrc *mythtv;
990 mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
992 size = gst_mythtv_src_get_position (mythtv);
994 switch (GST_QUERY_TYPE (query)) {
996 case GST_QUERY_POSITION:
1002 /* save requested format */
1003 gst_query_parse_position (query, NULL, &cur);
1005 /* query peer for current position in time */
1006 g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
1007 ( size > cur ) ? "greater" : "lower", size, cur );
1008 gst_query_set_position (query, GST_FORMAT_BYTES, size);
1015 case GST_QUERY_DURATION:
1020 /* save requested format */
1021 gst_query_parse_position (query, NULL, &cur);
1023 /* query peer for current position in time */
1024 g_print( "[%s] Actual size is %s than current size from sink. [ %lld, %lld ]\n", __FUNCTION__,
1025 ( size * GST_SECOND > cur * GST_SECOND ) ? "greater" : "lower", size * GST_SECOND,
1027 gst_query_set_position (query, GST_FORMAT_TIME, size * GST_SECOND );
1029 if ( size * GST_SECOND < cur * GST_SECOND )
1049 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1051 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1052 gboolean ret = TRUE;
1053 g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__,
1054 abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
1056 if (src->content_size <= 0) {
1058 } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) <
1059 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1060 //g_static_mutex_lock( &update_size_mutex );
1061 //GST_OBJECT_LOCK(src);
1063 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
1064 if ( new_offset > 0 && new_offset > src->content_size ) {
1065 src->content_size = new_offset;
1066 } else if ( new_offset < src->content_size ) {
1067 src->update_prog_chain = TRUE;
1070 if ( src->enable_timing_position ) {
1071 gint64 size_tmp = 0;
1072 if (src->live_tv == TRUE) {
1075 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1076 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1077 src->content_size = size_tmp;
1078 else if ( size_tmp > 0 )
1080 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1081 __FUNCTION__, size_tmp );
1085 src->prev_content_size = src->content_size;
1087 //GST_OBJECT_UNLOCK(src);
1088 //g_static_mutex_unlock( &update_size_mutex );
1091 *size = src->content_size;
1092 g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
1098 /* close the socket and associated resources
1099 * used both to recover from errors and go to NULL state */
1101 gst_mythtv_src_stop (GstBaseSrc * bsrc)
1105 src = GST_MYTHTV_SRC (bsrc);
1107 if (src->uri_name) {
1108 g_free (src->uri_name);
1109 src->uri_name = NULL;
1112 if (src->mythtv_caps) {
1113 gst_caps_unref (src->mythtv_caps);
1114 src->mythtv_caps = NULL;
1124 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1126 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1127 gint64 cont_size = 0;
1129 switch (GST_EVENT_TYPE (event)) {
1131 case GST_EVENT_FLUSH_START:
1133 g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
1134 cont_size = gst_mythtv_src_get_position (src);
1135 if ( !src->live_tv ) {
1136 if ( cont_size > src->content_size ) {
1137 src->content_size = cont_size;
1141 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1142 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1145 if ( cont_size <= 0 ) {
1146 src->update_prog_chain = TRUE;
1148 src->unique_setup = FALSE;
1149 src->do_start = TRUE;
1153 case GST_EVENT_FLUSH_STOP:
1154 src->do_start = TRUE;
1156 gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
1157 //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
1161 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
1163 if ( src->live_tv ) {
1164 cont_size = gst_mythtv_src_get_position (src);
1165 if ( cont_size > src->content_size ) {
1166 src->content_size = cont_size;
1170 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1171 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1177 case GST_EVENT_NEWSEGMENT:
1178 g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
1181 case GST_EVENT_SEEK:
1183 g_print( "[%s] Got EVENT_SEEK!!!\n", __FUNCTION__ );
1185 //gboolean update = TRUE;
1187 GstSeekType cur_type, stop_type;
1189 gint64 cur = 0, stop = 0;
1190 gst_event_parse_seek ( event, &rate, &format,
1191 &flags, &cur_type, &cur,
1192 &stop_type, &stop );
1194 g_print( "[%s] Got EVENT_SEEK.\n", __FUNCTION__ );
1195 if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
1196 g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
1198 //gboolean ret = gst_event_parse_new_segment ( event,
1199 // &update, &rate, &format, &start, &stop,
1201 //GstFlowReturn flow_ret = gst_mythtv_src_create (GST_BASE_SRC( GST_PAD_PARENT( psrc ) ),
1202 // cur, stop - cur + 1, GstBuffer)
1206 return gst_pad_event_default (pad, event);
1209 return gst_pad_event_default (pad, event);
1215 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1222 static GstFlowReturn
1223 gst_mythtv_src_file_transfer( GstMythtvSrc *src )
1225 GstFlowReturn ret = GST_FLOW_OK;
1226 GstBuffer *buf = NULL;
1229 /* The caller should know the number of bytes and not read beyond EOS. */
1230 if ( G_UNLIKELY (src->eos) )
1232 if ( G_UNLIKELY (src->update_prog_chain) )
1233 goto change_progchain;
1237 /* Create the buffer. */
1238 buf = gst_buffer_new_and_alloc (4096);
1240 ret = gst_mythtv_src_read_bytes( src, GST_BUFFER_SIZE(buf), TRUE, &buf );
1241 if ( ret != GST_FLOW_OK )
1244 read = do_read_request_response ( src, src->read_offset, GST_BUFFER_SIZE(buf), &buf );
1246 if (G_UNLIKELY (src->update_prog_chain) )
1247 goto change_progchain;
1249 if (G_UNLIKELY (read <= 0) || buf == NULL) {
1251 goto change_progchain;
1256 if ( GST_FLOW_OK != ( ret = gst_pad_push ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), buf ) ) ) {
1264 const gchar *reason = gst_flow_get_name (ret);
1266 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
1271 const gchar *reason = gst_flow_get_name (ret);
1273 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
1274 return GST_FLOW_UNEXPECTED;
1279 GST_ELEMENT_ERROR (src, RESOURCE, READ,
1280 (NULL), ("Could not read any bytes (%i, %s)", read,
1282 return GST_FLOW_ERROR;
1286 GST_ELEMENT_ERROR (src, RESOURCE, READ,
1287 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
1289 // go to the next program chain
1290 src->unique_setup = FALSE;
1291 src->update_prog_chain = TRUE;
1292 src->mode = GST_MYTHTV_SRC_NEXT_PROGRAM_CHAIN;
1294 //GST_OBJECT_LOCK(src);
1295 //gst_mythtv_src_next_program_chain( src );
1296 //GST_OBJECT_UNLOCK(src);
1297 return GST_FLOW_OK;//GST_FLOW_ERROR_NO_DATA;
1301 static GstFlowReturn
1302 gst_mythtv_src_play (GstPad * pad)
1304 GstFlowReturn res = GST_FLOW_OK;
1305 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1307 switch ( src->state ) {
1308 case GST_MYTHTV_SRC_FILE_TRANSFER:
1309 res = gst_mythtv_src_file_transfer( src );
1310 if ((res != GST_FLOW_OK) && (res != GST_FLOW_ERROR_NO_DATA)) {
1314 case GST_MYTHTV_SRC_NEXT_PROGRAM_CHAIN:
1315 src->read_offset = 0;
1316 src->bytes_read = 0;
1317 src->unique_setup = FALSE;
1318 if ( !gst_mythtv_src_next_program_chain( src ) ) {
1321 src->state = GST_MYTHTV_SRC_FILE_TRANSFER;
1323 case GST_MYTHTV_SRC_INVALID_DATA:
1327 g_assert_not_reached ();
1330 GST_DEBUG_OBJECT (src, "state: %d res:%s", src->state,
1331 gst_flow_get_name (res));
1336 GST_LOG_OBJECT (src, "pausing task, reason %s", gst_flow_get_name (res));
1337 gst_pad_pause_task (src->srcpad);
1338 if (GST_FLOW_IS_FATAL (res)) {
1339 GST_ELEMENT_ERROR (src, STREAM, FAILED,
1340 ("Internal data stream error."),
1341 ("streaming stopped, reason %s", gst_flow_get_name (res)));
1342 gst_pad_send_event( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_eos() );
1348 static GstStateChangeReturn
1349 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1351 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;//GST_STATE_CHANGE_NO_PREROLL;
1352 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1354 switch (transition) {
1355 case GST_STATE_CHANGE_NULL_TO_READY:
1356 src->do_start = TRUE;
1357 src->unique_setup = FALSE;
1359 case GST_STATE_CHANGE_READY_TO_PAUSED:
1360 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1367 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1368 if (ret == GST_STATE_CHANGE_FAILURE)
1371 switch (transition) {
1372 case GST_STATE_CHANGE_READY_TO_NULL:
1373 g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
1375 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1376 g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1377 case GST_STATE_CHANGE_PAUSED_TO_READY:
1378 g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1379 if ( src->live_tv && src->update_prog_chain ) {
1381 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1382 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
1384 src->read_offset = 0;
1385 src->bytes_read = 0;
1386 src->unique_setup = FALSE;
1387 gst_mythtv_src_next_program_chain( src );
1398 gst_mythtv_src_set_property (GObject * object, guint prop_id,
1399 const GValue * value, GParamSpec * pspec)
1401 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1403 GST_OBJECT_LOCK (mythtvsrc);
1408 if (!g_value_get_string (value)) {
1409 GST_WARNING ("location property cannot be NULL");
1413 if (mythtvsrc->uri_name != NULL) {
1414 g_free (mythtvsrc->uri_name);
1415 mythtvsrc->uri_name = NULL;
1417 mythtvsrc->uri_name = g_value_dup_string (value);
1421 #ifndef GST_DISABLE_GST_DEBUG
1422 case PROP_GMYTHTV_DBG:
1424 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1428 case PROP_GMYTHTV_VERSION:
1430 mythtvsrc->mythtv_version = g_value_get_int (value);
1433 case PROP_GMYTHTV_LIVEID:
1435 mythtvsrc->live_tv_id = g_value_get_int (value);
1438 case PROP_GMYTHTV_LIVE:
1440 mythtvsrc->live_tv = g_value_get_boolean (value);
1443 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1445 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1448 case PROP_GMYTHTV_LIVE_CHAINID:
1450 if (!g_value_get_string (value)) {
1451 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1455 if (mythtvsrc->live_chain_id != NULL) {
1456 g_free (mythtvsrc->live_chain_id);
1457 mythtvsrc->live_chain_id = NULL;
1459 mythtvsrc->live_chain_id = g_value_dup_string (value);
1462 case PROP_GMYTHTV_CHANNEL_NUM:
1464 mythtvsrc->channel_num = g_value_get_int (value);
1468 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1471 GST_OBJECT_UNLOCK (mythtvsrc);
1477 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1478 GValue * value, GParamSpec * pspec)
1480 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1482 GST_OBJECT_LOCK (mythtvsrc);
1487 gchar *str = g_strdup( "" );
1489 if ( mythtvsrc->uri_name == NULL ) {
1490 g_free (mythtvsrc->uri_name);
1491 mythtvsrc->uri_name = NULL;
1493 str = g_strdup( mythtvsrc->uri_name );
1495 g_value_set_string ( value, str );
1498 #ifndef GST_DISABLE_GST_DEBUG
1499 case PROP_GMYTHTV_DBG:
1500 g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
1503 case PROP_GMYTHTV_VERSION:
1505 g_value_set_int ( value, mythtvsrc->mythtv_version );
1508 case PROP_GMYTHTV_LIVEID:
1510 g_value_set_int ( value, mythtvsrc->live_tv_id );
1513 case PROP_GMYTHTV_LIVE:
1514 g_value_set_boolean ( value, mythtvsrc->live_tv );
1516 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1517 g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
1519 case PROP_GMYTHTV_LIVE_CHAINID:
1521 gchar *str = g_strdup( "" );
1523 if ( mythtvsrc->live_chain_id == NULL ) {
1524 g_free (mythtvsrc->live_chain_id);
1525 mythtvsrc->live_chain_id = NULL;
1527 str = g_strdup( mythtvsrc->live_chain_id );
1529 g_value_set_string ( value, str );
1532 case PROP_GMYTHTV_CHANNEL_NUM:
1534 g_value_set_int ( value, mythtvsrc->channel_num );
1538 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1541 GST_OBJECT_UNLOCK (mythtvsrc);
1544 /* entry point to initialize the plug-in
1545 * initialize the plug-in itself
1546 * register the element factories and pad templates
1547 * register the features
1550 plugin_init (GstPlugin * plugin)
1552 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1553 GST_TYPE_MYTHTV_SRC);
1556 /* this is the structure that gst-register looks for
1557 * so keep the name plugin_desc, or you cannot get your plug-in registered */
1558 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1562 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
1565 /*** GSTURIHANDLER INTERFACE *************************************************/
1567 gst_mythtv_src_uri_get_type (void)
1573 gst_mythtv_src_uri_get_protocols (void)
1575 static gchar *protocols[] = { "myth", "myths", NULL };
1580 static const gchar *
1581 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1583 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1585 return src->uri_name;
1589 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1591 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1595 protocol = gst_uri_get_protocol (uri);
1596 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1601 g_object_set (src, "location", uri, NULL);
1607 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1609 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1611 iface->get_type = gst_mythtv_src_uri_get_type;
1612 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1613 iface->get_uri = gst_mythtv_src_uri_get_uri;
1614 iface->set_uri = gst_mythtv_src_uri_set_uri;
1618 size_header_handler (void *userdata, const char *value)
1620 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1622 //src->content_size = g_ascii_strtoull (value, NULL, 10);
1624 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);