[svn r96] Removed guint8 * buffer, changed to a GstAdapter.
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 6*1024
48 #define GST_FLOW_ERROR_NO_DATA -101
50 #define INTERNAL_BUFFER_SIZE 30*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, guint8 **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, guint8 **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 );
575 g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size );
577 /* just get from the adapter, no network effort... */
579 guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
581 g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__,
582 (gint) src->buffer_remain);
584 /* Create the buffer. */
585 ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
586 src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size,
587 GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf );
589 if (G_UNLIKELY (ret != GST_FLOW_OK)) {
591 goto change_progchain;
596 if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) {
598 buffer = gst_buffer_new_and_alloc( INTERNAL_BUFFER_SIZE - src->buffer_remain );
600 read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) );
602 if (G_UNLIKELY (read < 0)) {
604 goto change_progchain;
609 if ( G_UNLIKELY (src->update_prog_chain) )
610 goto change_progchain;
612 gst_adapter_push( src->adapter, buffer );
614 src->buffer_remain = src->buffer_remain + read;
616 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
617 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
618 src->read_offset, src->content_size );
622 size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE;
624 buffer = gst_adapter_take_buffer( src->adapter, size );
626 g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain );
628 GST_BUFFER_SIZE (*outbuf) = size;
629 GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) );
630 GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf );
631 g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) );
632 GST_BUFFER_OFFSET (*outbuf) = src->read_offset;
633 GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf);
635 src->buffer_remain -= GST_BUFFER_SIZE (*outbuf);
637 src->read_offset += GST_BUFFER_SIZE (*outbuf);
638 src->bytes_read += GST_BUFFER_SIZE (*outbuf);
639 g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) );
641 //gst_adapter_flush( src->adapter, size );
642 gst_buffer_unref( buffer );
644 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
645 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf),
646 GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) );
648 /* just get from the adapter, no network effort... */
655 const gchar *reason = gst_flow_get_name (ret);
657 GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason);
662 const gchar *reason = gst_flow_get_name (ret);
664 GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason);
665 return GST_FLOW_UNEXPECTED;
670 GST_ELEMENT_ERROR (src, RESOURCE, READ,
671 (NULL), ("Could not read any bytes (%i, %s)", read,
673 return GST_FLOW_ERROR;
677 GST_ELEMENT_ERROR (src, RESOURCE, READ,
678 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
681 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)),
682 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
683 // go to the next program chain
684 src->unique_setup = FALSE;
685 src->update_prog_chain = TRUE;
687 gst_mythtv_src_next_program_chain( src );
689 return GST_FLOW_ERROR_NO_DATA;
695 gst_mythtv_src_get_position ( GstMythtvSrc* src )
700 if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) <
701 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
705 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
706 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
707 src->content_size = size_tmp;
708 else if ( size_tmp > 0 && --max_tries > 0 )
710 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
711 __FUNCTION__, size_tmp );
712 /* sets the last content size amount before it can be updated */
713 src->prev_content_size = src->content_size;
716 return src->content_size;
721 gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment )
723 GstMythtvSrc *src = GST_MYTHTV_SRC( base );
724 gint64 new_offset = -1;
725 gint64 actual_seek = segment->start;
728 g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop );
730 if ( segment->format == GST_FORMAT_TIME )
733 //actual_seek = ( ( segment->start / 1000 ) * 28 ) * 4000;
735 g_print( "[%s]Trying to seek at the value (actual_seek = %lld, read_offset = %lld)\n", __FUNCTION__, actual_seek, src->read_offset );
736 /* verify if it needs to seek */
737 if ( src->read_offset != actual_seek )
740 new_offset = gmyth_file_transfer_seek( src->file_transfer, segment->start, SEEK_SET );
742 g_print( "[%s] Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
743 __FUNCTION__, segment->start, src->read_offset, new_offset );
744 if ( G_UNLIKELY (new_offset < 0 ) )
748 goto change_progchain;
753 src->read_offset = new_offset;
755 if ( ret == FALSE ) {
756 g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ );
761 g_static_rec_mutex_lock( &th_mutex );
763 GST_TASK_SIGNAL( src->th_read_ahead );
765 g_static_rec_mutex_unlock( &th_mutex );
773 GST_DEBUG_OBJECT (src, "EOS found on seeking!!!");
774 //gst_object_unref( src );
779 GST_ELEMENT_ERROR (src, RESOURCE, READ,
780 (NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
783 gst_pad_push_event ( GST_BASE_SRC_PAD (base),
784 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
785 /* go to the next program chain */
786 src->unique_setup = FALSE;
787 src->update_prog_chain = TRUE;
789 gst_mythtv_src_next_program_chain( src );
798 gst_mythtv_src_read_ahead ( void *data ) {
800 GstMythtvSrc *src = NULL;
802 GstBuffer *outbuf = NULL;
808 src = GST_MYTHTV_SRC( data );
810 //GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
813 GST_TASK_WAIT( src->th_read_ahead );
817 outbuf = gst_buffer_new_and_alloc( size );
819 read = do_read_request_response ( src, src->adapter_offset, size, &data );
822 src->read_offset += read;
823 src->bytes_read += read;
826 g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\
827 "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read,
828 src->read_offset, src->content_size );
830 GST_BUFFER_SIZE (outbuf) = read;
831 GST_BUFFER_MALLOCDATA( outbuf ) = g_malloc0( GST_BUFFER_SIZE (outbuf) );
832 GST_BUFFER_DATA( outbuf ) = GST_BUFFER_MALLOCDATA( outbuf );
833 g_memmove( GST_BUFFER_DATA( outbuf ), data, read );
834 GST_BUFFER_OFFSET (outbuf) = src->adapter_offset;
835 GST_BUFFER_OFFSET_END (outbuf) = src->adapter_offset + read;
836 g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\
837 "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (outbuf),
838 GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf) );
842 gst_adapter_push( src->adapter, outbuf );
844 GST_TASK_SIGNAL( src->th_read_ahead );
846 } while ( read < size );
848 //GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
854 /* create a socket for connecting to remote server */
856 gst_mythtv_src_start ( GstBaseSrc * bsrc )
858 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
860 GString *chain_id_local = NULL;
864 if ( G_UNLIKELY (src->update_prog_chain) )
865 goto change_progchain;
867 if (src->unique_setup == FALSE) {
868 src->unique_setup = TRUE;
873 if ( src->live_tv ) {
874 src->spawn_livetv = gmyth_livetv_new( );
875 if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
880 /* set up the uri variable */
881 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
882 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
883 if ( chain_id_local != NULL ) {
884 src->live_chain_id = g_strdup( chain_id_local->str );
885 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
887 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
888 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
891 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
892 g_string_new( src->uri_name ), -1, src->mythtv_version );
894 if ( src->file_transfer == NULL ) {
898 /* sets the Playback monitor connection */
899 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
901 if ( src->live_tv == TRUE && ret == TRUE ) {
902 /* loop finished, set the max tries variable to zero again... */
903 wait_to_transfer = 0;
905 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
906 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE
907 /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
911 /* sets the FileTransfer instance connection (video/audio download) */
912 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
914 if ( ret == FALSE ) {
915 #ifndef GST_DISABLE_GST_DEBUG
916 if ( src->mythtv_msgs_dbg )
917 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
919 goto begin_req_failed;
922 src->content_size = src->file_transfer->filesize;
924 src->do_start = FALSE;
926 //if ( src->live_tv ) {
927 src->adapter = gst_adapter_new();
928 //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src );
929 //gst_task_set_lock( src->th_read_ahead, &th_mutex );
930 //gst_task_start( src->th_read_ahead );
932 src->buffer_remain = 0;
941 if (src->spawn_livetv != NULL )
942 g_object_unref( src->spawn_livetv );
944 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
945 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
950 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
951 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
956 GST_ELEMENT_ERROR (src, RESOURCE, READ,
957 (NULL), ("Seek failed, go to the next program info... (%s)",
960 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
961 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
963 // go to the next program chain
964 src->unique_setup = FALSE;
965 src->update_prog_chain = TRUE;
967 gst_mythtv_src_next_program_chain( src );
973 /* create a new socket for connecting to the next program chain */
975 gst_mythtv_src_next_program_chain ( GstMythtvSrc *src )
977 GString *chain_id_local = NULL;
984 if (src->unique_setup == FALSE) {
985 src->unique_setup = TRUE;
990 GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
992 if (src->file_transfer) {
993 g_object_unref (src->file_transfer);
994 src->file_transfer = NULL;
998 g_free (src->uri_name);
1001 if ( src->live_tv ) {
1002 if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) {
1003 g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ );
1007 /* set up the uri variable */
1008 src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str );
1009 chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain );
1010 if ( chain_id_local != NULL ) {
1011 src->live_chain_id = g_strdup( chain_id_local->str );
1012 g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id );
1014 src->live_tv_id = src->spawn_livetv->recorder->recorder_num;
1015 g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
1018 src->file_transfer = gmyth_file_transfer_new( src->live_tv_id,
1019 g_string_new( src->uri_name ), -1, src->mythtv_version );
1021 if ( src->file_transfer == NULL ) {
1025 /* sets the Playback monitor connection */
1026 ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
1028 if ( src->live_tv == TRUE && ret == TRUE ) {
1029 /* loop finished, set the max tries variable to zero again... */
1030 wait_to_transfer = 0;
1034 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS &&
1035 ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) )
1039 /* sets the FileTransfer instance connection (video/audio download) */
1040 ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
1042 if ( ret == FALSE ) {
1043 #ifndef GST_DISABLE_GST_DEBUG
1044 if ( src->mythtv_msgs_dbg )
1045 g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" );
1047 goto begin_req_failed;
1049 src->content_size_last = src->content_size;
1052 if ( src->content_size < src->file_transfer->filesize ) {
1053 src->content_size = src->file_transfer->filesize;
1055 //gint64 pos = gst_mythtv_src_get_position(src);
1056 //if ( pos > src->file_transfer->filesize )
1057 // src->content_size = pos;
1062 src->content_size = src->file_transfer->filesize;
1063 if ( src->live_tv ) {
1064 wait_to_transfer = 0;
1065 while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER )
1066 src->content_size = gst_mythtv_src_get_position( src );
1069 src->read_offset = 0;
1072 src->update_prog_chain = FALSE;
1074 GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) );
1081 if (src->spawn_livetv != NULL )
1082 g_object_unref( src->spawn_livetv );
1084 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1085 (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name));
1090 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1091 (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name));
1098 gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1100 GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc);
1101 gboolean ret = TRUE;
1102 g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__,
1103 abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER );
1105 if (src->content_size == -1) {
1107 } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) <
1108 GMYTHTV_TRANSFER_MAX_BUFFER ) ) {
1109 //g_static_mutex_lock( &update_size_mutex );
1110 //GST_OBJECT_LOCK(src);
1112 gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
1113 if ( new_offset > 0 && new_offset > src->content_size ) {
1114 src->content_size = new_offset;
1115 } else if ( new_offset < src->content_size ) {
1116 src->update_prog_chain = TRUE;
1119 if ( src->enable_timing_position ) {
1120 gint64 size_tmp = 0;
1121 if (src->live_tv == TRUE) {
1124 size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
1125 if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
1126 src->content_size = size_tmp;
1127 else if ( size_tmp > 0 )
1129 g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
1130 __FUNCTION__, size_tmp );
1134 src->prev_content_size = src->content_size;
1136 //GST_OBJECT_UNLOCK(src);
1137 //g_static_mutex_unlock( &update_size_mutex );
1140 *size = src->content_size;
1141 g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size );
1147 /* close the socket and associated resources
1148 * used both to recover from errors and go to NULL state */
1150 gst_mythtv_src_stop (GstBaseSrc * bsrc)
1154 src = GST_MYTHTV_SRC (bsrc);
1156 if (src->uri_name) {
1157 g_free (src->uri_name);
1158 src->uri_name = NULL;
1161 if (src->mythtv_caps) {
1162 gst_caps_unref (src->mythtv_caps);
1163 src->mythtv_caps = NULL;
1172 gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event)
1174 GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad));
1175 gint64 cont_size = 0;
1176 gboolean ret = FALSE;
1178 switch (GST_EVENT_TYPE (event)) {
1180 case GST_EVENT_FLUSH_START:
1182 g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ );
1183 cont_size = gst_mythtv_src_get_position (src);
1184 if ( !src->live_tv ) {
1185 if ( cont_size > src->content_size ) {
1186 src->content_size = cont_size;
1190 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1191 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1194 if ( cont_size <= 0 ) {
1195 src->update_prog_chain = TRUE;
1197 src->unique_setup = FALSE;
1198 src->do_start = TRUE;
1202 case GST_EVENT_FLUSH_STOP:
1203 src->do_start = TRUE;
1205 gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL);
1206 //gst_element_set_locked_state (GST_ELEMENT(src), TRUE);
1210 g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ );
1212 if ( src->live_tv ) {
1213 cont_size = gst_mythtv_src_get_position (src);
1214 if ( cont_size > src->content_size ) {
1215 src->content_size = cont_size;
1219 gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL );
1220 gst_element_set_locked_state ( GST_ELEMENT (src), FALSE );
1226 case GST_EVENT_NEWSEGMENT:
1227 g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ );
1228 ret = gst_pad_event_default (pad, event);
1230 case GST_EVENT_SEEK:
1232 gst_event_ref( event );
1235 //gboolean update = TRUE;
1237 GstSeekType cur_type, stop_type;
1239 gint64 cur = 0, stop = 0;
1240 gst_event_parse_seek ( event, &rate, &format,
1241 &flags, &cur_type, &cur,
1242 &stop_type, &stop );
1244 g_print( "[%s] Got EVENT_SEEK (pos = %lld)!!!\n", __FUNCTION__, cur );
1245 if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) {
1246 g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ );
1248 if ( format == GST_FORMAT_TIME && ( ret = gst_pad_event_default (pad, event) ) == FALSE ) {
1249 gst_event_unref( event );
1256 ret = gst_pad_event_default (pad, event);
1263 gst_mythtv_src_is_seekable( GstBaseSrc *push_src )
1269 gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query)
1271 gboolean res = FALSE;
1272 GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad));
1274 switch (GST_QUERY_TYPE (query)) {
1275 case GST_QUERY_POSITION:
1276 gst_query_set_position (query, GST_FORMAT_BYTES,
1277 myth->read_offset );
1279 GST_DEBUG_OBJECT (myth, "POS %d", myth->read_offset);
1281 case GST_QUERY_DURATION:
1283 if (myth->duration != 0) {
1287 fps = nuv->h->i_fpsn / nuv->h->i_fpsd;
1288 total = gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps);
1290 //gst_query_set_duration (query, GST_FORMAT_TIME, myth->content_size);
1291 GST_DEBUG_OBJECT (myth, "DURATION %d", myth->content_size);
1299 gst_object_unref (myth);
1304 static GstStateChangeReturn
1305 gst_mythtv_src_change_state (GstElement * element, GstStateChange transition)
1307 GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;//GST_STATE_CHANGE_NO_PREROLL;
1308 GstMythtvSrc *src = GST_MYTHTV_SRC (element);
1310 switch (transition) {
1311 case GST_STATE_CHANGE_NULL_TO_READY:
1312 //src->do_start = TRUE;
1313 //src->unique_setup = FALSE;
1315 case GST_STATE_CHANGE_READY_TO_PAUSED:
1316 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1323 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1324 if (ret == GST_STATE_CHANGE_FAILURE)
1327 switch (transition) {
1328 case GST_STATE_CHANGE_READY_TO_NULL:
1329 g_print( "[%s] READY to NULL called!\n", __FUNCTION__ );
1331 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1332 g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ );
1333 case GST_STATE_CHANGE_PAUSED_TO_READY:
1334 g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ );
1335 if ( src->live_tv && src->update_prog_chain ) {
1337 gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)),
1338 gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) );
1340 src->read_offset = 0;
1341 src->bytes_read = 0;
1342 src->unique_setup = FALSE;
1343 gst_mythtv_src_next_program_chain( src );
1354 gst_mythtv_src_set_property (GObject * object, guint prop_id,
1355 const GValue * value, GParamSpec * pspec)
1357 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1359 GST_OBJECT_LOCK (mythtvsrc);
1364 if (!g_value_get_string (value)) {
1365 GST_WARNING ("location property cannot be NULL");
1369 if (mythtvsrc->uri_name != NULL) {
1370 g_free (mythtvsrc->uri_name);
1371 mythtvsrc->uri_name = NULL;
1373 mythtvsrc->uri_name = g_value_dup_string (value);
1377 #ifndef GST_DISABLE_GST_DEBUG
1378 case PROP_GMYTHTV_DBG:
1380 mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
1384 case PROP_GMYTHTV_VERSION:
1386 mythtvsrc->mythtv_version = g_value_get_int (value);
1389 case PROP_GMYTHTV_LIVEID:
1391 mythtvsrc->live_tv_id = g_value_get_int (value);
1394 case PROP_GMYTHTV_LIVE:
1396 mythtvsrc->live_tv = g_value_get_boolean (value);
1399 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1401 mythtvsrc->enable_timing_position = g_value_get_boolean (value);
1404 case PROP_GMYTHTV_LIVE_CHAINID:
1406 if (!g_value_get_string (value)) {
1407 GST_WARNING ("MythTV Live chainid property cannot be NULL");
1411 if (mythtvsrc->live_chain_id != NULL) {
1412 g_free (mythtvsrc->live_chain_id);
1413 mythtvsrc->live_chain_id = NULL;
1415 mythtvsrc->live_chain_id = g_value_dup_string (value);
1418 case PROP_GMYTHTV_CHANNEL_NUM:
1420 mythtvsrc->channel_num = g_value_get_int (value);
1424 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1427 GST_OBJECT_UNLOCK (mythtvsrc);
1433 gst_mythtv_src_get_property (GObject * object, guint prop_id,
1434 GValue * value, GParamSpec * pspec)
1436 GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object);
1438 GST_OBJECT_LOCK (mythtvsrc);
1443 gchar *str = g_strdup( "" );
1445 if ( mythtvsrc->uri_name == NULL ) {
1446 g_free (mythtvsrc->uri_name);
1447 mythtvsrc->uri_name = NULL;
1449 str = g_strdup( mythtvsrc->uri_name );
1451 g_value_set_string ( value, str );
1454 #ifndef GST_DISABLE_GST_DEBUG
1455 case PROP_GMYTHTV_DBG:
1456 g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
1459 case PROP_GMYTHTV_VERSION:
1461 g_value_set_int ( value, mythtvsrc->mythtv_version );
1464 case PROP_GMYTHTV_LIVEID:
1466 g_value_set_int ( value, mythtvsrc->live_tv_id );
1469 case PROP_GMYTHTV_LIVE:
1470 g_value_set_boolean ( value, mythtvsrc->live_tv );
1472 case PROP_GMYTHTV_ENABLE_TIMING_POSITION:
1473 g_value_set_boolean ( value, mythtvsrc->enable_timing_position );
1475 case PROP_GMYTHTV_LIVE_CHAINID:
1477 gchar *str = g_strdup( "" );
1479 if ( mythtvsrc->live_chain_id == NULL ) {
1480 g_free (mythtvsrc->live_chain_id);
1481 mythtvsrc->live_chain_id = NULL;
1483 str = g_strdup( mythtvsrc->live_chain_id );
1485 g_value_set_string ( value, str );
1488 case PROP_GMYTHTV_CHANNEL_NUM:
1490 g_value_set_int ( value, mythtvsrc->channel_num );
1494 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1497 GST_OBJECT_UNLOCK (mythtvsrc);
1500 /* entry point to initialize the plug-in
1501 * initialize the plug-in itself
1502 * register the element factories and pad templates
1503 * register the features
1506 plugin_init (GstPlugin * plugin)
1508 return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,
1509 GST_TYPE_MYTHTV_SRC);
1512 /* this is the structure that gst-register looks for
1513 * so keep the name plugin_desc, or you cannot get your plug-in registered */
1514 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1518 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
1521 /*** GSTURIHANDLER INTERFACE *************************************************/
1523 gst_mythtv_src_uri_get_type (void)
1529 gst_mythtv_src_uri_get_protocols (void)
1531 static gchar *protocols[] = { "myth", "myths", NULL };
1536 static const gchar *
1537 gst_mythtv_src_uri_get_uri (GstURIHandler * handler)
1539 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1541 return src->uri_name;
1545 gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1547 GstMythtvSrc *src = GST_MYTHTV_SRC (handler);
1551 protocol = gst_uri_get_protocol (uri);
1552 if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) {
1557 g_object_set (src, "location", uri, NULL);
1563 gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1565 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1567 iface->get_type = gst_mythtv_src_uri_get_type;
1568 iface->get_protocols = gst_mythtv_src_uri_get_protocols;
1569 iface->get_uri = gst_mythtv_src_uri_get_uri;
1570 iface->set_uri = gst_mythtv_src_uri_set_uri;
1574 size_header_handler (void *userdata, const char *value)
1576 GstMythtvSrc *src = GST_MYTHTV_SRC (userdata);
1578 //src->content_size = g_ascii_strtoull (value, NULL, 10);
1580 GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size);