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 12*1024
48 #define GST_FLOW_ERROR_NO_DATA -101
50 #define INTERNAL_BUFFER_SIZE 18*1024
52 /* stablish a maximum iteration value to the IS_RECORDING message */
53 static guint wait_to_transfer = 0;
55 static const GstElementDetails gst_mythtv_src_details =
56 GST_ELEMENT_DETAILS ( "MythTV client source",
58 "Control and receive data as a client over the network via raw socket connections using the MythTV protocol",
59 "Rosfran Borges <rosfran.borges@indt.org.br>" );
61 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ( "src",
64 GST_STATIC_CAPS ("video/x-nuv") );
71 #ifndef GST_DISABLE_GST_DEBUG
77 PROP_GMYTHTV_LIVE_CHAINID,
78 PROP_GMYTHTV_ENABLE_TIMING_POSITION,
79 PROP_GMYTHTV_CHANNEL_NUM
82 static void gst_mythtv_src_finalize (GObject * gobject);
85 static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset,
86 guint size, GstBuffer ** outbuf);
89 //static GstFlowReturn gst_mythtv_src_chain ( GstPad* pad, GstBuffer* outbuf );
90 static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf );
92 static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc);
93 static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc);
94 static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size);
95 static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src );
97 static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment );
99 static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src );
101 static GstStateChangeReturn
102 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition);
104 static void gst_mythtv_src_set_property (GObject * object, guint prop_id,
105 const GValue * value, GParamSpec * pspec);
106 static void gst_mythtv_src_get_property (GObject * object, guint prop_id,
107 GValue * value, GParamSpec * pspec);
109 static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
111 static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query);
113 static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event);
115 static gint do_read_request_response (GstMythtvSrc * src, guint64 offset,
116 guint size, gint8 **data_ptr);
118 GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT;
121 _urihandler_init (GType type)
123 static const GInterfaceInfo urihandler_info = {
124 gst_mythtv_src_uri_handler_init,
129 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
131 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
135 //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc,
136 // GST_TYPE_BASE_SRC, _urihandler_init)
138 GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstPushSrc,
139 GST_TYPE_PUSH_SRC, _urihandler_init)
142 gst_mythtv_src_base_init (gpointer g_class)
144 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
146 gst_element_class_add_pad_template (element_class,
147 gst_static_pad_template_get (&srctemplate));
149 gst_element_class_set_details (element_class, &gst_mythtv_src_details);
151 element_class->change_state = gst_mythtv_src_change_state;
156 gst_mythtv_src_class_init (GstMythtvSrcClass * klass)
158 GObjectClass *gobject_class;
159 GstPushSrcClass *gstpushsrc_class;
160 GstBaseSrcClass *gstbasesrc_class;
162 gobject_class = (GObjectClass *) klass;
163 gstbasesrc_class = (GstBaseSrcClass *) klass;
164 gstpushsrc_class = (GstPushSrcClass *) klass;
166 gobject_class->set_property = gst_mythtv_src_set_property;
167 gobject_class->get_property = gst_mythtv_src_get_property;
168 gobject_class->finalize = gst_mythtv_src_finalize;
170 g_object_class_install_property
171 (gobject_class, PROP_LOCATION,
172 g_param_spec_string ("location", "Location",
173 "The location. In the form:"
174 "\n\t\t\tmyth://a.com/file.nuv"
175 "\n\t\t\tmyth://a.com:23223/file.nuv "
176 "\n\t\t\ta.com/file.nuv - default scheme 'myth'",
177 "", G_PARAM_READWRITE));
179 g_object_class_install_property
180 (gobject_class, PROP_URI,
181 g_param_spec_string ("uri", "Uri",
182 "The location in form of a URI (deprecated; use location)",
183 "", G_PARAM_READWRITE));
185 g_object_class_install_property
186 (gobject_class, PROP_GMYTHTV_VERSION,
187 g_param_spec_int ("mythtv-version", "mythtv-version",
188 "Change MythTV version",
189 26, 30, 26, G_PARAM_READWRITE));
191 g_object_class_install_property
192 (gobject_class, PROP_GMYTHTV_LIVEID,
193 g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
194 "Change MythTV version",
195 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
197 g_object_class_install_property
198 (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
199 g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
200 "Sets the MythTV chain ID (from TV Chain)",
201 "", G_PARAM_READWRITE));
203 g_object_class_install_property
204 (gobject_class, PROP_GMYTHTV_LIVE,
205 g_param_spec_boolean ("mythtv-live", "mythtv-live",
206 "Enable MythTV Live TV content streaming",
207 FALSE, G_PARAM_READWRITE));
209 g_object_class_install_property
210 (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION,
211 g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position",
212 "Enable MythTV Live TV content size continuous updating",
213 FALSE, G_PARAM_READWRITE));
215 g_object_class_install_property
216 (gobject_class, PROP_GMYTHTV_CHANNEL_NUM,
217 g_param_spec_int ("mythtv-channel", "mythtv-channel",
218 "Change MythTV channel number",
219 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE));
221 #ifndef GST_DISABLE_GST_DEBUG
222 g_object_class_install_property
223 (gobject_class, PROP_GMYTHTV_DBG,
224 g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
225 "Enable MythTV debug messages",
226 FALSE, G_PARAM_READWRITE));
229 gstbasesrc_class->start = gst_mythtv_src_start;
230 gstbasesrc_class->stop = gst_mythtv_src_stop;
231 gstbasesrc_class->get_size = gst_mythtv_src_get_size;
232 gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable;
234 gstbasesrc_class->do_seek = gst_mythtv_src_do_seek;
235 gstpushsrc_class->create = gst_mythtv_src_create;
237 GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0,
238 "MythTV Client Source");
242 gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class)
244 this->file_transfer = NULL;
246 this->unique_setup = FALSE;
248 this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
250 this->state = GST_MYTHTV_SRC_FILE_TRANSFER;
252 this->bytes_read = 0;
254 this->prev_content_size = 0;
256 this->content_size = 0;
257 this->read_offset = 0;
259 this->content_size_last = 0;
261 this->live_tv = FALSE;
263 this->enable_timing_position = FALSE;
264 this->update_prog_chain = FALSE;
266 this->user_agent = g_strdup ("mythtvsrc");
267 this->mythtv_caps = NULL;
268 this->update_prog_chain = FALSE;
270 this->channel_num = 0;
274 this->adapter = NULL;
276 //this->th_read_ahead = NULL;
278 this->th_mutex = NULL;
280 this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
281 gst_element_add_pad (GST_ELEMENT (this), this->srcpad);
283 gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES );
285 //gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE );
287 gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
288 gst_mythtv_src_handle_event );
289 gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)),
290 gst_mythtv_src_handle_query );
295 gst_mythtv_src_finalize (GObject * gobject)
297 GstMythtvSrc *this = GST_MYTHTV_SRC (gobject);
299 if ( this->th_read_ahead != NULL ) {
300 gst_task_stop( this->th_read_ahead );
301 this->th_read_ahead = NULL;
304 if (this->mythtv_caps) {
305 gst_caps_unref (this->mythtv_caps);
306 this->mythtv_caps = NULL;
309 if (this->file_transfer) {
310 g_object_unref (this->file_transfer);
311 this->file_transfer = NULL;
314 if (this->spawn_livetv) {
315 g_object_unref (this->spawn_livetv);
316 this->spawn_livetv = NULL;
319 if (this->uri_name) {
320 g_free (this->uri_name);
323 if (this->user_agent) {
324 g_free (this->user_agent);
327 G_OBJECT_CLASS (parent_class)->finalize (gobject);
331 do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, gint8 **data_ptr)
334 guint sizetoread = size;
336 g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread );
338 /* Loop sending the Myth File Transfer request:
339 * Retry whilst authentication fails and we supply it. */
341 //*data_ptr = g_malloc0( size );
343 //while ( sizetoread > 0 ) {
345 len = gmyth_file_transfer_read( src->file_transfer,
346 *data_ptr + offset + read, sizetoread, TRUE );
356 if ( src->live_tv == FALSE )
362 if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */
363 src->update_prog_chain = TRUE;
365 } else if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) {
366 src->update_prog_chain = TRUE;
367 if ( src->enable_timing_position ) {
370 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
371 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
372 src->content_size = size_tmp;
373 else if ( size_tmp > 0 )
375 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
376 __FUNCTION__, size_tmp );
384 if ( read == sizetoread )
388 if ( read < 0 && !src->live_tv )
403 gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf)
406 GstFlowReturn ret = GST_FLOW_OK;
408 gint adapter_size = -1;
410 guint max_adapter_rep = 40;
412 src = GST_MYTHTV_SRC (psrc);
414 /* The caller should know the number of bytes and not read beyond EOS. */
415 if (G_UNLIKELY (src->eos))
417 if ( G_UNLIKELY (src->update_prog_chain) )
418 goto change_progchain;
420 g_static_rec_mutex_lock( th_mutexth_mutex );
422 while ( ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < size ) &&
423 --max_adapter_rep > 0 )
425 g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
426 GST_TASK_WAIT( src->th_read_ahead );
429 g_static_rec_mutex_unlock( th_mutexth_mutex );
431 gint64 new_offset = -1;
432 /* just get from the adapter, no network effort... */
433 if ( offset > src->adapter_offset && size <= adapter_size )
436 GstBuffer *buf = gst_adapter_take_buffer( src->adapter, size );
437 *outbuf = gst_buffer_create_sub( buf, offset, size );
438 src->read_offset = new_offset = offset;
441 gst_adapter_flush( src->adapter, size );
444 /* no data on adapter... do all these mythtv network calls! */
446 /* verify if it needs to seek */
447 if ( src->read_offset != offset )
450 new_offset = gmyth_file_transfer_seek( src->file_transfer, offset, SEEK_SET );
452 g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
453 __FUNCTION__, src->read_offset, new_offset );
454 if ( G_UNLIKELY (new_offset < 0 ) )
457 goto change_progchain;
464 src->read_offset = offset;
466 /* Create the buffer. */
467 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
468 src->read_offset, size,
469 GST_PAD_CAPS ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)) ), outbuf);
471 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
473 goto change_progchain;
478 read = do_read_request_response ( src, src->read_offset, size, outbuf );
482 if (G_UNLIKELY (src->update_prog_chain) )
483 goto change_progchain;
485 if (G_UNLIKELY (read <= 0) || *outbuf == NULL) {
487 goto change_progchain;
493 src->read_offset += read;
494 src->bytes_read += read;
497 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
498 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
499 src->read_offset, src->content_size );
501 GST_BUFFER_SIZE (*outbuf) = read; //GST_BUFFER_SIZE (buffer) = read;
502 //GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
503 //GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
504 //g_memmove( GST_BUFFER_DATA( *outbuf ), data_ptr, read );
505 GST_BUFFER_OFFSET (*outbuf) = offset; //GST_BUFFER_OFFSET (buffer) = offset;
506 GST_BUFFER_OFFSET_END (*outbuf) = offset + read;//GST_BUFFER_OFFSET_END (buffer) = offset + read;
508 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
509 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
510 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
517 const gchar *reason = gst_flow_get_name (ret);
519 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
524 const gchar *reason = gst_flow_get_name (ret);
526 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
527 return GST_FLOW_UNEXPECTED;
532 GST_ELEMENT_ERROR (src, RESOURCE, READ,
533 (NULL), ("Could not read any bytes (%i, %s)", read,
535 return GST_FLOW_ERROR;
539 GST_ELEMENT_ERROR (src, RESOURCE, READ,
540 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
543 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
544 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
545 // go to the next program chain
546 src->unique_setup = FALSE;
547 src->update_prog_chain = TRUE;
549 gst_mythtv_src_next_program_chain( src );
551 return GST_FLOW_ERROR_NO_DATA;
558 gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf )
561 GstFlowReturn ret = GST_FLOW_OK;
563 gint adapter_size = 0;
564 guint max_adapter_rep = 1;
566 src = GST_MYTHTV_SRC ( psrc );
568 /* The caller should know the number of bytes and not read beyond EOS. */
569 if (G_UNLIKELY (src->eos))
571 if ( G_UNLIKELY (src->update_prog_chain) )
572 goto change_progchain;
574 //g_static_rec_mutex_lock( &th_mutex );
576 while ( src->adapter != NULL && ( ( adapter_size = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) &&
577 --max_adapter_rep > 0 )
579 g_print ( "[%s] %d - Waiting for read_ahead task...\n", __FUNCTION__, max_adapter_rep );
580 //GST_TASK_WAIT( src->th_read_ahead );
583 //gst_task_pause( src->th_read_ahead );
585 //g_static_rec_mutex_unlock( &th_mutex );
587 /* just get from the adapter, no network effort... */
588 if ( adapter_size > 0 )
590 //g_static_rec_mutex_lock( &th_mutex );
592 *outbuf = gst_adapter_take_buffer( src->adapter, adapter_size );
593 // src->read_offset += size;
596 gst_adapter_flush( src->adapter, adapter_size );
597 //g_static_rec_mutex_unlock( &th_mutex );
600 guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
602 g_print ( "[%s]\t\tCreate: buffer_offset: %d, buffer_remain: %d\n", __FUNCTION__,
603 (gint) src->buffer_offset,
604 (gint) src->buffer_remain);
606 /* Create the buffer. */
607 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
608 src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
609 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
611 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
613 goto change_progchain;
618 if (src->buffer_remain < MAX_READ_SIZE) {
619 gint8 *tmp_buffer = g_malloc0( INTERNAL_BUFFER_SIZE ); // FIXME: DON'T ALLOC EVERY TIME
621 memcpy (tmp_buffer, src->buffer + src->buffer_offset, src->buffer_remain);
623 read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &tmp_buffer );
625 if (G_UNLIKELY (read < 0)) {
627 goto change_progchain;
632 if ( G_UNLIKELY (src->update_prog_chain) )
633 goto change_progchain;
635 //len = gmyth_file_transfer_read( src->file_transfer,
636 // tmp_buffer + src->buffer_remain, INTERNAL_BUFFER_SIZE - src->buffer_remain, TRUE );
638 // fixme: can I deallocate the previous buffer here?
639 g_memmove( src->buffer + src->buffer_remain, tmp_buffer, read);
640 src->buffer_offset = 0;
641 src->buffer_remain = src->buffer_remain + read;
643 // g_free( tmp_buffer );
647 g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
649 GST_BUFFER_SIZE (*outbuf) = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
650 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
651 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
652 g_memmove( GST_BUFFER_DATA( (*outbuf) ), src->buffer + src->buffer_offset, GST_BUFFER_SIZE(*outbuf) );
653 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
654 GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
656 src->buffer_offset += GST_BUFFER_SIZE (*outbuf);
657 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
659 src->read_offset += GST_BUFFER_SIZE (*outbuf);
660 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
661 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
663 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
664 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
665 src->read_offset, src->content_size );
667 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
668 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
669 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
671 /* just get from the adapter, no network effort... */
677 //g_static_rec_mutex_lock( &th_mutex );
679 //GST_TASK_SIGNAL( src->th_read_ahead );
681 //g_static_rec_mutex_unlock( &th_mutex );
685 const gchar *reason = gst_flow_get_name (ret);
687 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
692 const gchar *reason = gst_flow_get_name (ret);
694 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
695 return GST_FLOW_UNEXPECTED;
700 GST_ELEMENT_ERROR (src, RESOURCE, READ,
701 (NULL), ("Could not read any bytes (%i, %s)", read,
703 return GST_FLOW_ERROR;
707 GST_ELEMENT_ERROR (src, RESOURCE, READ,
708 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
711 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
712 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
713 // go to the next program chain
714 src->unique_setup = FALSE;
715 src->update_prog_chain = TRUE;
717 gst_mythtv_src_next_program_chain( src );
719 return GST_FLOW_ERROR_NO_DATA;
725 gst_mythtv_src_get_position ( GstMythtvSrc* src )
730 if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) <
731 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
735 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
736 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
737 src->content_size = size_tmp;
738 else if ( size_tmp > 0 && --max_tries > 0 )
740 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
741 __FUNCTION__, size_tmp );
742 /* sets the last content size amount before it can be updated */
743 src->prev_content_size = src->content_size;
746 return src->content_size;
751 gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment )
753 GstMythtvSrc *src = GST_MYTHTV_SRC( base );
754 gint64 new_offset = -1;
755 gint64 actual_seek = segment->start;
758 g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop );
759 //g_static_rec_mutex_lock( &th_mutex );
761 //GST_TASK_WAIT( src->th_read_ahead );
763 //g_static_rec_mutex_unlock( &th_mutex );
765 if ( segment->format == GST_FORMAT_TIME )
768 //actual_seek = ( ( segment->start / 1000 ) * 28 ) * 4000;
770 g_print( "[%s]Trying to seek at the value (actual_seek = %lld, read_offset = %lld)\n", __FUNCTION__, actual_seek, src->read_offset );
771 /* verify if it needs to seek */
772 if ( src->read_offset != actual_seek )
775 new_offset = gmyth_file_transfer_seek( src->file_transfer, segment->start, SEEK_SET );
777 g_print( "[%s] Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
778 __FUNCTION__, segment->start, src->read_offset, new_offset );
779 if ( G_UNLIKELY (new_offset < 0 ) )
783 goto change_progchain;
788 src->read_offset = new_offset;
790 //gst_segment_set_seek( segment, segment->rate, GST_FORMAT_BYTES, GST_SEEK_FLAG_NONE,
791 //GST_SEEK_TYPE_CUR, src->read_offset, GST_SEEK_TYPE_CUR, segment->stop, &ret );
793 if ( ret == FALSE ) {
794 g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ );
798 //g_static_rec_mutex_lock( &th_mutex );
800 //GST_TASK_SIGNAL( src->th_read_ahead );
802 //g_static_rec_mutex_unlock( &th_mutex );
809 GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
810 //gst_object_unref( src );
815 GST_ELEMENT_ERROR (src, RESOURCE, READ,
816 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
819 gst_pad_push_event ( GST_BASE_SRC_PAD (base),
820 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
821 /* go to the next program chain */
822 src->unique_setup = FALSE;
823 src->update_prog_chain = TRUE;
825 gst_mythtv_src_next_program_chain( src );
834 gst_mythtv_src_read_ahead ( void *data ) {
836 GstMythtvSrc *src = NULL;
838 GstBuffer *outbuf = NULL;
844 src = GST_MYTHTV_SRC( data );
846 //GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
849 GST_TASK_WAIT( src->th_read_ahead );
853 outbuf = gst_buffer_new_and_alloc( size );
855 read = do_read_request_response ( src, src->adapter_offset, size, &data );
858 src->read_offset += read;
859 src->bytes_read += read;
862 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
863 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
864 src->read_offset, src->content_size );
866 GST_BUFFER_SIZE (outbuf) = read;
867 GST_BUFFER_MALLOCDATA( outbuf ) = g_malloc0( GST_BUFFER_SIZE (outbuf) );
868 GST_BUFFER_DATA( outbuf ) = GST_BUFFER_MALLOCDATA( outbuf );
869 g_memmove( GST_BUFFER_DATA( outbuf ), data, read );
870 GST_BUFFER_OFFSET (outbuf) = src->adapter_offset;
871 GST_BUFFER_OFFSET_END (outbuf) = src->adapter_offset + read;
872 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
873 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (outbuf),
874 GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf) );
878 gst_adapter_push( src->adapter, outbuf );
880 GST_TASK_SIGNAL( src->th_read_ahead );
882 } while ( read < size );
884 //GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
890 /* create a socket for connecting to remote server */
892 gst_mythtv_src_start ( GstBaseSrc * bsrc )
894 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
896 GString *chain_id_local = NULL;
900 if ( G_UNLIKELY (src->update_prog_chain) )
901 goto change_progchain;
903 if (src->unique_setup == FALSE) {
904 src->unique_setup = TRUE;
909 if ( src->live_tv ) {
910 src->spawn_livetv = gmyth_livetv_new( );
911 if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
916 /* set up the uri variable */
917 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
918 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
919 if ( chain_id_local != NULL ) {
920 src->live_chain_id = g_strdup( chain_id_local->str );
921 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
923 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
924 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
927 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
928 g_string_new( src->uri_name ), -1, src->mythtv_version );
930 if ( src->file_transfer == NULL ) {
934 /* sets the Playback monitor connection */
935 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
937 if ( src->live_tv == TRUE && ret == TRUE ) {
938 /* loop finished, set the max tries variable to zero again... */
939 wait_to_transfer = 0;
941 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
942 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE
943 /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
947 /* sets the FileTransfer instance connection (video/audio download) */
948 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
950 if ( ret == FALSE ) {
951 #ifndef GST_DISABLE_GST_DEBUG
952 if ( src->mythtv_msgs_dbg )
953 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
955 goto begin_req_failed;
958 src->content_size = src->file_transfer->filesize;
960 src->do_start = FALSE;
962 //if ( src->live_tv ) {
963 src->adapter = gst_adapter_new();
964 //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
965 //gst_task_set_lock( src->th_read_ahead, &th_mutex );
966 //gst_task_start( src->th_read_ahead );
968 //gst_pad_push_event ( GST_BASE_SRC_PAD (bsrc),
969 // gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 0, src->content_size, 0 ) );
971 src->buffer = g_malloc0 (INTERNAL_BUFFER_SIZE);
972 src->buffer_offset = 0;
973 src->buffer_remain = 0;
982 if (src->spawn_livetv != NULL )
983 g_object_unref( src->spawn_livetv );
985 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
986 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
991 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
992 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
997 GST_ELEMENT_ERROR (src, RESOURCE, READ,
998 (NULL), ("Seek failed, go to the next program info... (%s)",
1001 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1002 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
1004 // go to the next program chain
1005 src->unique_setup = FALSE;
1006 src->update_prog_chain = TRUE;
1008 gst_mythtv_src_next_program_chain( src );
1014 /* create a new socket for connecting to the next program chain */
1016 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
1018 GString *chain_id_local = NULL;
1020 gboolean ret = TRUE;
1022 if ( !src->live_tv )
1025 if (src->unique_setup == FALSE) {
1026 src->unique_setup = TRUE;
1031 GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
1033 if (src->file_transfer) {
1034 g_object_unref (src->file_transfer);
1035 src->file_transfer = NULL;
1038 if (src->uri_name) {
1039 g_free (src->uri_name);
1042 if ( src->live_tv ) {
1043 if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
1044 g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ );
1048 /* set up the uri variable */
1049 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
1050 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
1051 if ( chain_id_local != NULL ) {
1052 src->live_chain_id = g_strdup( chain_id_local->str );
1053 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
1055 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
1056 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
1059 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
1060 g_string_new( src->uri_name ), -1, src->mythtv_version );
1062 if ( src->file_transfer == NULL ) {
1066 /* sets the Playback monitor connection */
1067 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
1069 if ( src->live_tv == TRUE && ret == TRUE ) {
1070 /* loop finished, set the max tries variable to zero again... */
1071 wait_to_transfer = 0;
1075 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
1076 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
1080 /* sets the FileTransfer instance connection (video/audio download) */
1081 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
1083 if ( ret == FALSE ) {
1084 #ifndef GST_DISABLE_GST_DEBUG
1085 if ( src->mythtv_msgs_dbg )
1086 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
1088 goto begin_req_failed;
1090 src->content_size_last = src->content_size;
1093 if ( src->content_size < src->file_transfer->filesize ) {
1094 src->content_size = src->file_transfer->filesize;
1096 //gint64 pos = gst_mythtv_src_get_position(src);
1097 //if ( pos > src->file_transfer->filesize )
1098 // src->content_size = pos;
1103 src->content_size = src->file_transfer->filesize;
1104 if ( src->live_tv ) {
1105 wait_to_transfer = 0;
1106 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER )
1107 src->content_size = gst_mythtv_src_get_position( src );
1110 src->read_offset = 0;
1113 src->update_prog_chain = FALSE;
1115 GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
1122 if (src->spawn_livetv != NULL )
1123 g_object_unref( src->spawn_livetv );
1125 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1126 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
1131 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1132 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
1139 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1141 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1142 gboolean ret = TRUE;
1143 g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__,
1144 abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
1146 if (src->content_size == -1) {
1148 } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) <
1149 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1150 //g_static_mutex_lock( &update_size_mutex );
1151 //GST_OBJECT_LOCK(src);
1153 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
1154 if ( new_offset > 0 && new_offset > src->content_size ) {
1155 src->content_size = new_offset;
1156 } else if ( new_offset < src->content_size ) {
1157 src->update_prog_chain = TRUE;
1160 if ( src->enable_timing_position ) {
1161 gint64 size_tmp = 0;
1162 if (src->live_tv == TRUE) {
1165 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1166 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1167 src->content_size = size_tmp;
1168 else if ( size_tmp > 0 )
1170 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1171 __FUNCTION__, size_tmp );
1175 src->prev_content_size = src->content_size;
1177 //GST_OBJECT_UNLOCK(src);
1178 //g_static_mutex_unlock( &update_size_mutex );
1181 *size = src->content_size;
1182 g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
1188 /* close the socket and associated resources
1189 * used both to recover from errors and go to NULL state */
1191 gst_mythtv_src_stop (GstBaseSrc * bsrc)
1195 src = GST_MYTHTV_SRC (bsrc);
1197 if (src->uri_name) {
1198 g_free (src->uri_name);
1199 src->uri_name = NULL;
1202 if (src->mythtv_caps) {
1203 gst_caps_unref (src->mythtv_caps);
1204 src->mythtv_caps = NULL;
1213 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1215 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1216 gint64 cont_size = 0;
1217 gboolean ret = FALSE;
1219 switch (GST_EVENT_TYPE (event)) {
1221 case GST_EVENT_FLUSH_START:
1223 g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
1224 cont_size = gst_mythtv_src_get_position (src);
1225 if ( !src->live_tv ) {
1226 if ( cont_size > src->content_size ) {
1227 src->content_size = cont_size;
1231 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1232 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1235 if ( cont_size <= 0 ) {
1236 src->update_prog_chain = TRUE;
1238 src->unique_setup = FALSE;
1239 src->do_start = TRUE;
1243 case GST_EVENT_FLUSH_STOP:
1244 src->do_start = TRUE;
1246 gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
1247 //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
1251 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
1253 if ( src->live_tv ) {
1254 cont_size = gst_mythtv_src_get_position (src);
1255 if ( cont_size > src->content_size ) {
1256 src->content_size = cont_size;
1260 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1261 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1267 case GST_EVENT_NEWSEGMENT:
1268 g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
1269 ret = gst_pad_event_default (pad, event);
1271 case GST_EVENT_SEEK:
1273 gst_event_ref( event );
1276 //gboolean update = TRUE;
1278 GstSeekType cur_type, stop_type;
1280 gint64 cur = 0, stop = 0;
1281 gst_event_parse_seek ( event, &rate, &format,
1282 &flags, &cur_type, &cur,
1283 &stop_type, &stop );
1285 g_print( "[%s] Got EVENT_SEEK (pos = %lld)!!!\n", __FUNCTION__, cur );
1286 if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
1287 g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
1289 if ( format == GST_FORMAT_TIME && ( ret = gst_pad_event_default (pad, event) ) == FALSE ) {
1290 gst_event_unref( event );
1297 ret = gst_pad_event_default (pad, event);
1304 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1310 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
1312 gboolean res = FALSE;
1313 GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
1315 switch (GST_QUERY_TYPE (query)) {
1316 case GST_QUERY_POSITION:
1317 gst_query_set_position (query, GST_FORMAT_BYTES,
1318 myth->read_offset );
1320 GST_DEBUG_OBJECT (myth, "POS %d", myth->read_offset);
1322 case GST_QUERY_DURATION:
1324 if (myth->duration != 0) {
1328 fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
1329 total = gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
1331 //gst_query_set_duration (query, GST_FORMAT_TIME, myth->content_size);
1332 GST_DEBUG_OBJECT (myth, "DURATION %d", myth->content_size);
1340 gst_object_unref (myth);
1345 static GstStateChangeReturn
1346 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1348 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;//GST_STATE_CHANGE_NO_PREROLL;
1349 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1351 switch (transition) {
1352 case GST_STATE_CHANGE_NULL_TO_READY:
1353 //src->do_start = TRUE;
1354 //src->unique_setup = FALSE;
1356 case GST_STATE_CHANGE_READY_TO_PAUSED:
1357 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1364 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1365 if (ret == GST_STATE_CHANGE_FAILURE)
1368 switch (transition) {
1369 case GST_STATE_CHANGE_READY_TO_NULL:
1370 g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
1372 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1373 g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1374 case GST_STATE_CHANGE_PAUSED_TO_READY:
1375 g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1376 if ( src->live_tv && src->update_prog_chain ) {
1378 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1379 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
1381 src->read_offset = 0;
1382 src->bytes_read = 0;
1383 src->unique_setup = FALSE;
1384 gst_mythtv_src_next_program_chain( src );
1395 gst_mythtv_src_set_property (GObject * object, guint prop_id,
1396 const GValue * value, GParamSpec * pspec)
1398 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1400 GST_OBJECT_LOCK (mythtvsrc);
1405 if (!g_value_get_string (value)) {
1406 GST_WARNING ("location property cannot be NULL");
1410 if (mythtvsrc->uri_name != NULL) {
1411 g_free (mythtvsrc->uri_name);
1412 mythtvsrc->uri_name = NULL;
1414 mythtvsrc->uri_name = g_value_dup_string (value);
1418 #ifndef GST_DISABLE_GST_DEBUG
1419 case PROP_GMYTHTV_DBG:
1421 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1425 case PROP_GMYTHTV_VERSION:
1427 mythtvsrc->mythtv_version = g_value_get_int (value);
1430 case PROP_GMYTHTV_LIVEID:
1432 mythtvsrc->live_tv_id = g_value_get_int (value);
1435 case PROP_GMYTHTV_LIVE:
1437 mythtvsrc->live_tv = g_value_get_boolean (value);
1440 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1442 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1445 case PROP_GMYTHTV_LIVE_CHAINID:
1447 if (!g_value_get_string (value)) {
1448 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1452 if (mythtvsrc->live_chain_id != NULL) {
1453 g_free (mythtvsrc->live_chain_id);
1454 mythtvsrc->live_chain_id = NULL;
1456 mythtvsrc->live_chain_id = g_value_dup_string (value);
1459 case PROP_GMYTHTV_CHANNEL_NUM:
1461 mythtvsrc->channel_num = g_value_get_int (value);
1465 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1468 GST_OBJECT_UNLOCK (mythtvsrc);
1474 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1475 GValue * value, GParamSpec * pspec)
1477 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1479 GST_OBJECT_LOCK (mythtvsrc);
1484 gchar *str = g_strdup( "" );
1486 if ( mythtvsrc->uri_name == NULL ) {
1487 g_free (mythtvsrc->uri_name);
1488 mythtvsrc->uri_name = NULL;
1490 str = g_strdup( mythtvsrc->uri_name );
1492 g_value_set_string ( value, str );
1495 #ifndef GST_DISABLE_GST_DEBUG
1496 case PROP_GMYTHTV_DBG:
1497 g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
1500 case PROP_GMYTHTV_VERSION:
1502 g_value_set_int ( value, mythtvsrc->mythtv_version );
1505 case PROP_GMYTHTV_LIVEID:
1507 g_value_set_int ( value, mythtvsrc->live_tv_id );
1510 case PROP_GMYTHTV_LIVE:
1511 g_value_set_boolean ( value, mythtvsrc->live_tv );
1513 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1514 g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
1516 case PROP_GMYTHTV_LIVE_CHAINID:
1518 gchar *str = g_strdup( "" );
1520 if ( mythtvsrc->live_chain_id == NULL ) {
1521 g_free (mythtvsrc->live_chain_id);
1522 mythtvsrc->live_chain_id = NULL;
1524 str = g_strdup( mythtvsrc->live_chain_id );
1526 g_value_set_string ( value, str );
1529 case PROP_GMYTHTV_CHANNEL_NUM:
1531 g_value_set_int ( value, mythtvsrc->channel_num );
1535 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1538 GST_OBJECT_UNLOCK (mythtvsrc);
1541 /* entry point to initialize the plug-in
1542 * initialize the plug-in itself
1543 * register the element factories and pad templates
1544 * register the features
1547 plugin_init (GstPlugin * plugin)
1549 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1550 GST_TYPE_MYTHTV_SRC);
1553 /* this is the structure that gst-register looks for
1554 * so keep the name plugin_desc, or you cannot get your plug-in registered */
1555 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1559 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
1562 /*** GSTURIHANDLER INTERFACE *************************************************/
1564 gst_mythtv_src_uri_get_type (void)
1570 gst_mythtv_src_uri_get_protocols (void)
1572 static gchar *protocols[] = { "myth", "myths", NULL };
1577 static const gchar *
1578 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1580 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1582 return src->uri_name;
1586 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1588 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1592 protocol = gst_uri_get_protocol (uri);
1593 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1598 g_object_set (src, "location", uri, NULL);
1604 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1606 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1608 iface->get_type = gst_mythtv_src_uri_get_type;
1609 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1610 iface->get_uri = gst_mythtv_src_uri_get_uri;
1611 iface->set_uri = gst_mythtv_src_uri_set_uri;
1615 size_header_handler (void *userdata, const char *value)
1617 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1619 //src->content_size = g_ascii_strtoull (value, NULL, 10);
1621 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);