/* vim: set sw=2: -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2; c-indent-level: 2 -*- */ /* GStreamer MythTV Plug-in * Copyright (C) <2006> Rosfran Borges * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library Lesser General * Public License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "gstmythtvsrc.h" #include #include #include #include #include #include #include GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug); #define GST_CAT_DEFAULT mythtvsrc_debug #define GST_GMYTHTV_ID_NUM 1 #define GST_GMYTHTV_CHANNEL_NUM 1000 #define GMYTHTV_VERSION_DEFAULT 30 #define GMYTHTV_TRANSFER_MAX_WAITS 100 #define GMYTHTV_TRANSFER_MAX_BUFFER 128*1024 //( 32*1024 ) /* 4*1024 ??? */ #define MAX_READ_SIZE 4*1024 //( 32*1024 ) #define GST_FLOW_ERROR_NO_DATA -101 #define INTERNAL_BUFFER_SIZE 64*1024 /* stablish a maximum iteration value to the IS_RECORDING message */ static guint wait_to_transfer = 0; static const GstElementDetails gst_mythtv_src_details = GST_ELEMENT_DETAILS ( "MythTV client source", "Source/Network", "Control and receive data as a client over the network via raw socket connections using the MythTV protocol", "Rosfran Borges " ); static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ( "src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-nuv") ); enum { PROP_0, PROP_LOCATION, PROP_URI, #ifndef GST_DISABLE_GST_DEBUG PROP_GMYTHTV_DBG, #endif PROP_GMYTHTV_VERSION, PROP_GMYTHTV_LIVE, PROP_GMYTHTV_LIVEID, PROP_GMYTHTV_LIVE_CHAINID, PROP_GMYTHTV_ENABLE_TIMING_POSITION, PROP_GMYTHTV_CHANNEL_NUM }; static void gst_mythtv_src_finalize (GObject * gobject); static GstFlowReturn gst_mythtv_src_create (GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer ** outbuf); //static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf ); static gboolean gst_mythtv_src_start (GstBaseSrc * bsrc); static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc); static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size); static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src ); //static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer, // GstClockTime * start, GstClockTime * end); //static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment ); static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src ); static GstStateChangeReturn gst_mythtv_src_change_state (GstElement * element, GstStateChange transition); static void gst_mythtv_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_mythtv_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data); static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query); static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event); static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr); GStaticRecMutex th_mutex = G_STATIC_REC_MUTEX_INIT; static void _urihandler_init (GType type) { static const GInterfaceInfo urihandler_info = { gst_mythtv_src_uri_handler_init, NULL, NULL }; g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info); GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV src"); } //GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc, // GST_TYPE_BASE_SRC, _urihandler_init) GST_BOILERPLATE_FULL (GstMythtvSrc, gst_mythtv_src, GstBaseSrc, GST_TYPE_BASE_SRC, _urihandler_init) static void gst_mythtv_src_base_init (gpointer g_class) { GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&srctemplate)); gst_element_class_set_details (element_class, &gst_mythtv_src_details); element_class->change_state = gst_mythtv_src_change_state; } static void gst_mythtv_src_class_init (GstMythtvSrcClass * klass) { GObjectClass *gobject_class; //GstPushSrcClass *gstpushsrc_class; GstBaseSrcClass *gstbasesrc_class; gobject_class = (GObjectClass *) klass; gstbasesrc_class = (GstBaseSrcClass *) klass; //gstpushsrc_class = (GstPushSrcClass *) klass; gobject_class->set_property = gst_mythtv_src_set_property; gobject_class->get_property = gst_mythtv_src_get_property; gobject_class->finalize = gst_mythtv_src_finalize; g_object_class_install_property (gobject_class, PROP_LOCATION, g_param_spec_string ("location", "Location", "The location. In the form:" "\n\t\t\tmyth://a.com/file.nuv" "\n\t\t\tmyth://a.com:23223/file.nuv " "\n\t\t\ta.com/file.nuv - default scheme 'myth'", "", G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_URI, g_param_spec_string ("uri", "Uri", "The location in form of a URI (deprecated; use location)", "", G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_VERSION, g_param_spec_int ("mythtv-version", "mythtv-version", "Change MythTV version", 26, 30, 26, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_LIVEID, g_param_spec_int ("mythtv-live-id", "mythtv-live-id", "Change MythTV version", 0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_LIVE_CHAINID, g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid", "Sets the MythTV chain ID (from TV Chain)", "", G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_LIVE, g_param_spec_boolean ("mythtv-live", "mythtv-live", "Enable MythTV Live TV content streaming", FALSE, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_ENABLE_TIMING_POSITION, g_param_spec_boolean ("mythtv-enable-timing-position", "mythtv-enable-timing-position", "Enable MythTV Live TV content size continuous updating", FALSE, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_GMYTHTV_CHANNEL_NUM, g_param_spec_int ("mythtv-channel", "mythtv-channel", "Change MythTV channel number", 0, 99999, GST_GMYTHTV_CHANNEL_NUM, G_PARAM_READWRITE)); #ifndef GST_DISABLE_GST_DEBUG g_object_class_install_property (gobject_class, PROP_GMYTHTV_DBG, g_param_spec_boolean ("mythtv-debug", "mythtv-debug", "Enable MythTV debug messages", FALSE, G_PARAM_READWRITE)); #endif gstbasesrc_class->start = gst_mythtv_src_start; gstbasesrc_class->stop = gst_mythtv_src_stop; gstbasesrc_class->get_size = gst_mythtv_src_get_size; gstbasesrc_class->is_seekable = gst_mythtv_src_is_seekable; //gstbasesrc_class->get_times = gst_mythtv_src_get_times; //gstbasesrc_class->do_seek = gst_mythtv_src_do_seek; gstbasesrc_class->create = gst_mythtv_src_create; GST_DEBUG_CATEGORY_INIT (mythtvsrc_debug, "mythtvsrc", 0, "MythTV Client Source"); } static void gst_mythtv_src_init (GstMythtvSrc * this, GstMythtvSrcClass * g_class) { this->file_transfer = NULL; this->unique_setup = FALSE; this->mythtv_version = GMYTHTV_VERSION_DEFAULT; this->state = GST_MYTHTV_SRC_FILE_TRANSFER; this->bytes_read = 0; this->prev_content_size = 0; this->content_size = 0; this->read_offset = 0; this->content_size_last = 0; this->live_tv = FALSE; this->enable_timing_position = FALSE; this->update_prog_chain = FALSE; this->user_agent = g_strdup ("mythtvsrc"); this->mythtv_caps = NULL; this->update_prog_chain = FALSE; this->channel_num = 0; this->eos = FALSE; this->bytes_queue = NULL; //this->th_read_ahead = NULL; this->th_mutex = NULL; //this->srcpad = gst_pad_new_from_static_template (&srctemplate, "src"); //gst_element_add_pad (GST_ELEMENT (this), this->srcpad); gst_base_src_set_format( GST_BASE_SRC( this ), GST_FORMAT_BYTES ); //gst_base_src_set_live ( GST_BASE_SRC( this ), TRUE ); gst_pad_set_event_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), gst_mythtv_src_handle_event ); gst_pad_set_query_function ( GST_BASE_SRC_PAD(GST_BASE_SRC(this)), gst_mythtv_src_handle_query ); } static void gst_mythtv_src_finalize (GObject * gobject) { GstMythtvSrc *this = GST_MYTHTV_SRC (gobject); if ( this->th_read_ahead != NULL ) { gst_task_stop( this->th_read_ahead ); this->th_read_ahead = NULL; } if (this->mythtv_caps) { gst_caps_unref (this->mythtv_caps); this->mythtv_caps = NULL; } if (this->file_transfer) { g_object_unref (this->file_transfer); this->file_transfer = NULL; } if (this->spawn_livetv) { g_object_unref (this->spawn_livetv); this->spawn_livetv = NULL; } if (this->uri_name) { g_free (this->uri_name); } if (this->user_agent) { g_free (this->user_agent); } G_OBJECT_CLASS (parent_class)->finalize (gobject); } static gint do_read_request_response (GstMythtvSrc * src, guint64 offset, guint size, guint8 **data_ptr) { gint read = 0; guint sizetoread = size; g_print( "Starting: [%s] Reading %d bytes...\n", __FUNCTION__, sizetoread ); /* Loop sending the Myth File Transfer request: * Retry whilst authentication fails and we supply it. */ gint len = 0; //while ( sizetoread > 0 ) { len = gmyth_file_transfer_read( src->file_transfer, *data_ptr + offset + read, sizetoread, TRUE ); if ( len > 0 ) { read += len; sizetoread -= len; } else if ( len < 0 ) { read = -1; if ( src->live_tv == FALSE ) { goto eos; } else { if ( len == GMYTHTV_FILE_TRANSFER_READ_ERROR ) { /* -314 */ src->update_prog_chain = TRUE; goto done; } /*if ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) { src->update_prog_chain = TRUE; if ( src->enable_timing_position ) { gint64 size_tmp = 0; get_file_pos: size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) src->content_size = size_tmp; else if ( size_tmp > 0 ) goto get_file_pos; g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } }*/ goto done; } } if ( read == sizetoread ) goto done; //} if ( read < 0 && !src->live_tv ) goto eos; goto done; eos: src->eos = TRUE; done: return read; } #if 0 static GstFlowReturn gst_mythtv_src_create ( GstPushSrc* psrc, GstBuffer** outbuf ) { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; gint read = -1; gint adapter_size = 0; guint max_adapter_rep = 1; src = GST_MYTHTV_SRC ( psrc ); /* The caller should know the number of bytes and not read beyond EOS. */ if (G_UNLIKELY (src->eos)) goto eos; if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; //g_static_rec_mutex_lock( &th_mutex ); g_print ( "[%s] %d - Adapter size = (%d)...\n", __FUNCTION__, max_adapter_rep, adapter_size ); /* just get from the adapter, no network effort... */ GstBuffer *buffer; guint size = (src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__, (gint) src->buffer_remain); /* Create the buffer. */ ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), src->read_offset /*GST_BUFFER_OFFSET_NONE*/, size, GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); if (G_UNLIKELY (ret != GST_FLOW_OK)) { if ( src->live_tv ) goto change_progchain; else goto done; } if ( ( src->buffer_remain = gst_adapter_available_fast( src->adapter ) ) < MAX_READ_SIZE ) { ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), src->read_offset /*GST_BUFFER_OFFSET_NONE*/, INTERNAL_BUFFER_SIZE - src->buffer_remain, GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), &buffer ); read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(GST_BUFFER_DATA(buffer)) ); if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) goto change_progchain; else goto read_error; } if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; gst_adapter_push( src->adapter, buffer ); src->buffer_remain = src->buffer_remain + read; g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, src->read_offset, src->content_size ); } if ( now == -1 ) now = gst_element_get_base_time( GST_ELEMENT( src ) ); //else // now; size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; buffer = gst_adapter_take_buffer( src->adapter, size ); g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain ); GST_BUFFER_SIZE (*outbuf) = size; GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) ); GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf ); g_memmove( GST_BUFFER_DATA( (*outbuf) ), GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(*outbuf) ); //GST_BUFFER_TIMESTAMP( *outbuf ) = now; GST_BUFFER_OFFSET (*outbuf) = src->read_offset; GST_BUFFER_OFFSET_END (*outbuf) = src->read_offset + GST_BUFFER_SIZE (*outbuf); src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); src->read_offset += GST_BUFFER_SIZE (*outbuf); src->bytes_read += GST_BUFFER_SIZE (*outbuf); g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) ); //gst_adapter_flush( src->adapter, size ); gst_buffer_unref( buffer ); g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); /* just get from the adapter, no network effort... */ return ret; done: { const gchar *reason = gst_flow_get_name (ret); GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason); return ret; } eos: { const gchar *reason = gst_flow_get_name (ret); GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason); return GST_FLOW_UNEXPECTED; } /* ERRORS */ read_error: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name)); return GST_FLOW_ERROR; } change_progchain: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, src->uri_name)); gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) ); // go to the next program chain src->unique_setup = FALSE; src->update_prog_chain = TRUE; gst_mythtv_src_next_program_chain( src ); return GST_FLOW_ERROR_NO_DATA; } } #endif static GstFlowReturn gst_mythtv_src_create ( GstBaseSrc * psrc, guint64 offset, guint size, GstBuffer **outbuf ) { GstMythtvSrc *src; GstFlowReturn ret = GST_FLOW_OK; gint read = -1; gint adapter_size = 0; guint max_adapter_rep = 1; src = GST_MYTHTV_SRC ( psrc ); /* The caller should know the number of bytes and not read beyond EOS. */ if (G_UNLIKELY (src->eos)) goto eos; if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; //g_static_rec_mutex_lock( &th_mutex ); g_print ( "[%s] %d - Adapter size = (%d), offset = %llu, size = %d...\n", __FUNCTION__, max_adapter_rep, adapter_size, offset, size ); /* just get from the adapter, no network effort... */ //GstBuffer *buffer = NULL; g_print ( "[%s]\t\tCreate: buffer_remain: %d\n", __FUNCTION__, (gint) src->buffer_remain); if ( ( src->buffer_remain = src->bytes_queue->len ) < MAX_READ_SIZE ) { guint8 *buffer = g_malloc0( INTERNAL_BUFFER_SIZE - src->buffer_remain ); read = do_read_request_response( src, 0, INTERNAL_BUFFER_SIZE - src->buffer_remain, &(buffer) ); if (G_UNLIKELY (read < 0)) { if ( src->live_tv ) goto change_progchain; else goto read_error; } if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; src->bytes_queue = g_byte_array_append( src->bytes_queue, buffer, read ); src->buffer_remain = src->buffer_remain + read; g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, src->read_offset, src->content_size ); } guint buffer_size = ( src->buffer_remain < MAX_READ_SIZE) ? src->buffer_remain : MAX_READ_SIZE; /* Create the buffer. */ ret = gst_pad_alloc_buffer ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), offset, buffer_size, GST_PAD_CAPS (GST_BASE_SRC_PAD (GST_BASE_SRC (psrc))), outbuf ); if (G_UNLIKELY (ret != GST_FLOW_OK)) { if ( src->live_tv ) goto change_progchain; else goto done; } guint8 *buf = g_memdup( src->bytes_queue->data, buffer_size ); g_print( "[%s] read = %d, buffer_remain = %d\n", __FUNCTION__, read, src->buffer_remain ); //src->read_offset = offset; GST_BUFFER_SIZE (*outbuf) = buffer_size; GST_BUFFER_MALLOCDATA( *outbuf ) = g_malloc0( GST_BUFFER_SIZE (*outbuf) ); GST_BUFFER_DATA( *outbuf ) = GST_BUFFER_MALLOCDATA( *outbuf ); g_memmove( GST_BUFFER_DATA( (*outbuf) ), buf, GST_BUFFER_SIZE(*outbuf) ); GST_BUFFER_OFFSET (*outbuf) = offset; GST_BUFFER_OFFSET_END (*outbuf) = offset + GST_BUFFER_SIZE (*outbuf); src->buffer_remain -= GST_BUFFER_SIZE (*outbuf); src->read_offset += GST_BUFFER_SIZE (*outbuf); src->bytes_read += GST_BUFFER_SIZE (*outbuf); g_print ( "[%s]\t\tBuffer output with size: %d\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf) ); src->bytes_queue = g_byte_array_remove_range( src->bytes_queue, 0, buffer_size ); g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (*outbuf), GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf) ); /* just get from the adapter, no network effort... */ return ret; done: { const gchar *reason = gst_flow_get_name (ret); GST_DEBUG_OBJECT (src, "DONE task, reason %s", reason); return ret; } eos: { const gchar *reason = gst_flow_get_name (ret); GST_DEBUG_OBJECT (src, "pausing task, reason %s", reason); return GST_FLOW_UNEXPECTED; } /* ERRORS */ read_error: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Could not read any bytes (%i, %s)", read, src->uri_name)); return GST_FLOW_ERROR; } change_progchain: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, src->uri_name)); gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (psrc)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) ); // go to the next program chain src->unique_setup = FALSE; src->update_prog_chain = TRUE; gst_mythtv_src_next_program_chain( src ); return GST_FLOW_ERROR_NO_DATA; } } gint64 gst_mythtv_src_get_position ( GstMythtvSrc* src ) { gint64 size_tmp = 0; guint max_tries = 2; if (src->live_tv == TRUE && ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) ) { get_file_pos: g_usleep( 10 ); size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) src->content_size = size_tmp; else if ( size_tmp > 0 && --max_tries > 0 ) goto get_file_pos; g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); /* sets the last content size amount before it can be updated */ src->prev_content_size = src->content_size; } return src->content_size; } #if 0 static gboolean gst_mythtv_src_do_seek( GstBaseSrc *base, GstSegment *segment ) { GstMythtvSrc *src = GST_MYTHTV_SRC( base ); gint64 new_offset = -1; gint64 actual_seek = segment->start; gboolean ret = TRUE; g_print( "[%s]DO Seek called! (start = %lld, stop = %lld)\n", __FUNCTION__, segment->start, segment->stop ); if ( segment->format == GST_FORMAT_TIME ) { goto done; //actual_seek = ( ( segment->start / 1000 ) * 28 ) * 4000; } g_print( "[%s]Trying to seek at the value (actual_seek = %lld, read_offset = %lld)\n", __FUNCTION__, actual_seek, src->read_offset ); /* verify if it needs to seek */ if ( src->read_offset != actual_seek ) { new_offset = gmyth_file_transfer_seek( src->file_transfer, segment->start, SEEK_SET ); g_print( "[%s] Segment offset start = %lld, SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n", __FUNCTION__, segment->start, src->read_offset, new_offset ); if ( G_UNLIKELY (new_offset < 0 ) ) { ret = FALSE; if ( src->live_tv ) goto change_progchain; else goto eos; } src->read_offset = new_offset; if ( ret == FALSE ) { g_print( "[%s] Failed to set the SEEK on segment!\n", __FUNCTION__ ); } } /* g_static_rec_mutex_lock( &th_mutex ); GST_TASK_SIGNAL( src->th_read_ahead ); g_static_rec_mutex_unlock( &th_mutex ); */ done: return ret; eos: { GST_DEBUG_OBJECT (src, "EOS found on seeking!!!"); //gst_object_unref( src ); return FALSE; } change_progchain: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Seek failed, go to the next program info... (%i, %s)", read, src->uri_name)); gst_pad_push_event ( GST_BASE_SRC_PAD (base), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) ); /* go to the next program chain */ src->unique_setup = FALSE; src->update_prog_chain = TRUE; gst_mythtv_src_next_program_chain( src ); return TRUE; } } #endif #if 0 static void gst_mythtv_src_read_ahead ( void *data ) { GstMythtvSrc *src = NULL; GstBuffer *outbuf = NULL; guint size = 5*2048; gint total = 0; gint read = -1; src = GST_MYTHTV_SRC( data ); //GST_PAD_STREAM_TRYLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ); do { GST_TASK_WAIT( src->th_read_ahead ); gint8 *data = NULL; outbuf = gst_buffer_new_and_alloc( size ); read = do_read_request_response ( src, src->adapter_offset, size, &data ); if ( read > 0 ) { src->read_offset += read; src->bytes_read += read; total += read; g_print( "[%s]\tBYTES READ (actual) = %d, BYTES READ (cumulative) = %llu, "\ "OFFSET = %llu, CONTENT SIZE = %llu.\n", __FUNCTION__, read, src->bytes_read, src->read_offset, src->content_size ); GST_BUFFER_SIZE (outbuf) = read; GST_BUFFER_MALLOCDATA( outbuf ) = g_malloc0( GST_BUFFER_SIZE (outbuf) ); GST_BUFFER_DATA( outbuf ) = GST_BUFFER_MALLOCDATA( outbuf ); g_memmove( GST_BUFFER_DATA( outbuf ), data, read ); GST_BUFFER_OFFSET (outbuf) = src->adapter_offset; GST_BUFFER_OFFSET_END (outbuf) = src->adapter_offset + read; g_print( "Got buffer: [%s]\t\tBUFFER --->SIZE = %d, OFFSET = %llu, "\ "OFFSET_END = %llu.\n\n", __FUNCTION__, GST_BUFFER_SIZE (outbuf), GST_BUFFER_OFFSET (outbuf), GST_BUFFER_OFFSET_END (outbuf) ); } gst_adapter_push( src->adapter, outbuf ); GST_TASK_SIGNAL( src->th_read_ahead ); } while ( read < size ); //GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ); return; } #endif /* create a socket for connecting to remote server */ static gboolean gst_mythtv_src_start ( GstBaseSrc * bsrc ) { GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); GString *chain_id_local = NULL; gboolean ret = TRUE; if ( G_UNLIKELY (src->update_prog_chain) ) goto change_progchain; if (src->unique_setup == FALSE) { src->unique_setup = TRUE; } else { goto done; } if ( src->live_tv ) { gmyth_context_initialize(); src->spawn_livetv = gmyth_livetv_new( ); if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) { ret = FALSE; goto init_failed; } /* set up the uri variable */ src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str ); chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain ); if ( chain_id_local != NULL ) { src->live_chain_id = g_strdup( chain_id_local->str ); g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id ); } src->live_tv_id = src->spawn_livetv->recorder->recorder_num; g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name ); } src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, g_string_new( src->uri_name ), -1, src->mythtv_version ); if ( src->file_transfer == NULL ) { goto init_failed; } /* sets the Playback monitor connection */ ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv ); if ( src->live_tv == TRUE && ret == TRUE ) { /* loop finished, set the max tries variable to zero again... */ wait_to_transfer = 0; while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) ) g_usleep( 100 ); } //sleep( 30 ); /* sets the FileTransfer instance connection (video/audio download) */ ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv ); if ( ret == FALSE ) { #ifndef GST_DISABLE_GST_DEBUG if ( src->mythtv_msgs_dbg ) g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" ); #endif goto begin_req_failed; } src->content_size = src->file_transfer->filesize; src->do_start = FALSE; //if ( src->live_tv ) { src->bytes_queue = g_byte_array_new(); //src->th_read_ahead = gst_task_create( (GstTaskFunction)gst_mythtv_src_read_ahead, src ); //gst_task_set_lock( src->th_read_ahead, &th_mutex ); //gst_task_start( src->th_read_ahead ); // } src->buffer_remain = 0; done: return TRUE; /* ERRORS */ init_failed: { if (src->spawn_livetv != NULL ) g_object_unref( src->spawn_livetv ); GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name)); return FALSE; } begin_req_failed: { GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name)); return FALSE; } change_progchain: { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Seek failed, go to the next program info... (%s)", src->uri_name)); gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) ); // go to the next program chain src->unique_setup = FALSE; src->update_prog_chain = TRUE; gst_mythtv_src_next_program_chain( src ); return TRUE; } } #if 0 static void gst_mythtv_src_get_times (GstBaseSrc * src, GstBuffer * buffer, GstClockTime * start, GstClockTime * end) { *start = -1; *end = -1; } #endif /* create a new socket for connecting to the next program chain */ static gboolean gst_mythtv_src_next_program_chain ( GstMythtvSrc *src ) { GString *chain_id_local = NULL; gboolean ret = TRUE; if ( !src->live_tv ) goto init_failed; if (src->unique_setup == FALSE) { src->unique_setup = TRUE; } else { goto done; } GST_PAD_STREAM_LOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ); if (src->file_transfer) { g_object_unref (src->file_transfer); src->file_transfer = NULL; } if (src->uri_name) { g_free (src->uri_name); } if ( src->live_tv ) { if ( gmyth_livetv_next_program_chain( src->spawn_livetv ) == FALSE ) { g_print( "\n\n[%s]\t\tFailed to go to the next program chain!!!\n\n", __FUNCTION__ ); ret = FALSE; goto init_failed; } /* set up the uri variable */ src->uri_name = g_strdup( src->spawn_livetv->proginfo->pathname->str ); chain_id_local = gmyth_tvchain_get_id( src->spawn_livetv->tvchain ); if ( chain_id_local != NULL ) { src->live_chain_id = g_strdup( chain_id_local->str ); g_print( "\t[%s]\tLocal chain ID = %s.\n", __FUNCTION__, src->live_chain_id ); } src->live_tv_id = src->spawn_livetv->recorder->recorder_num; g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name ); } src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, g_string_new( src->uri_name ), -1, src->mythtv_version ); if ( src->file_transfer == NULL ) { goto init_failed; } /* sets the Playback monitor connection */ ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv ); if ( src->live_tv == TRUE && ret == TRUE ) { /* loop finished, set the max tries variable to zero again... */ wait_to_transfer = 0; g_usleep( 200 ); while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE ) ) g_usleep( 1000 ); } /* sets the FileTransfer instance connection (video/audio download) */ ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv ); if ( ret == FALSE ) { #ifndef GST_DISABLE_GST_DEBUG if ( src->mythtv_msgs_dbg ) g_printerr( "MythTV FileTransfer request failed when setting up socket connection!\n" ); #endif goto begin_req_failed; } src->content_size_last = src->content_size; #if 0 if ( src->content_size < src->file_transfer->filesize ) { src->content_size = src->file_transfer->filesize; } else { //gint64 pos = gst_mythtv_src_get_position(src); //if ( pos > src->file_transfer->filesize ) // src->content_size = pos; } #endif src->content_size = src->file_transfer->filesize; if ( src->live_tv ) { wait_to_transfer = 0; while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && src->content_size < GMYTHTV_TRANSFER_MAX_BUFFER ) src->content_size = gst_mythtv_src_get_position( src ); } src->read_offset = 0; done: src->update_prog_chain = FALSE; GST_PAD_STREAM_UNLOCK( GST_BASE_SRC_PAD (GST_BASE_SRC (src)) ); return TRUE; /* ERRORS */ init_failed: { if (src->spawn_livetv != NULL ) g_object_unref( src->spawn_livetv ); GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("Could not initialize MythTV library (%i, %s)", ret, src->uri_name)); return FALSE; } begin_req_failed: { GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("Could not begin request sent to MythTV server (%i, %s)", ret, src->uri_name)); return FALSE; } } static gboolean gst_mythtv_src_get_size (GstBaseSrc * bsrc, guint64 * size) { GstMythtvSrc *src = GST_MYTHTV_SRC (bsrc); gboolean ret = TRUE; g_print( "[%s] Differs from previous content size: %d (max.: %d)\n", __FUNCTION__, abs( src->content_size - src->prev_content_size ), GMYTHTV_TRANSFER_MAX_BUFFER ); if ( src->live_tv ) //src->content_size = (guint64)-1; ret = FALSE; else if (src->content_size == -1) { //ret= FALSE; } else if ( src->live_tv && ( abs( src->content_size - src->bytes_read ) < GMYTHTV_TRANSFER_MAX_BUFFER ) ) { //g_static_mutex_lock( &update_size_mutex ); //GST_OBJECT_LOCK(src); gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer ); if ( new_offset > 0 && new_offset > src->content_size ) { src->content_size = new_offset; } else if ( new_offset < src->content_size ) { src->update_prog_chain = TRUE; } if ( src->enable_timing_position ) { gint64 size_tmp = 0; if (src->live_tv == TRUE) { get_file_pos: g_usleep( 5 ); size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer ); if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) src->content_size = size_tmp; else if ( size_tmp > 0 ) goto get_file_pos; g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n", __FUNCTION__, size_tmp ); } } src->prev_content_size = src->content_size; //GST_OBJECT_UNLOCK(src); //g_static_mutex_unlock( &update_size_mutex ); } *size = src->content_size; g_print( "[%s] Content size = %lld\n", __FUNCTION__, src->content_size ); return ret; } /* close the socket and associated resources * used both to recover from errors and go to NULL state */ static gboolean gst_mythtv_src_stop (GstBaseSrc * bsrc) { GstMythtvSrc *src; src = GST_MYTHTV_SRC (bsrc); if (src->uri_name) { g_free (src->uri_name); src->uri_name = NULL; } if (src->mythtv_caps) { gst_caps_unref (src->mythtv_caps); src->mythtv_caps = NULL; } src->eos = FALSE; return TRUE; } static gboolean gst_mythtv_src_handle_event (GstPad * pad, GstEvent * event) { GstMythtvSrc *src = GST_MYTHTV_SRC (GST_PAD_PARENT (pad)); gint64 cont_size = 0; gboolean ret = FALSE; switch (GST_EVENT_TYPE (event)) { #if 0 case GST_EVENT_FLUSH_START: //src->eos = FALSE; g_print( "\n\n\n[%s]\t\tGot FLUSH_START event!!!\n\n\n", __FUNCTION__ ); cont_size = gst_mythtv_src_get_position (src); if ( !src->live_tv ) { if ( cont_size > src->content_size ) { src->content_size = cont_size; src->eos = FALSE; } else { src->eos = TRUE; gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); } } else { if ( cont_size <= 0 ) { src->update_prog_chain = TRUE; src->eos = TRUE; src->unique_setup = FALSE; src->do_start = TRUE; } } break; case GST_EVENT_FLUSH_STOP: src->do_start = TRUE; src->eos = FALSE; gst_element_set_state (GST_ELEMENT(src), GST_STATE_NULL); //gst_element_set_locked_state (GST_ELEMENT(src), TRUE); break; #endif case GST_EVENT_EOS: g_print( "[%s] Got EOS event!!!\n", __FUNCTION__ ); if ( src->live_tv ) { cont_size = gst_mythtv_src_get_position (src); if ( cont_size > src->content_size ) { src->content_size = cont_size; src->eos = FALSE; } else { src->eos = TRUE; gst_element_set_state ( GST_ELEMENT (src), GST_STATE_NULL ); gst_element_set_locked_state ( GST_ELEMENT (src), FALSE ); } } else src->eos = TRUE; ret = TRUE; break; case GST_EVENT_NEWSEGMENT: g_print( "[%s] Got NEWSEGMENT!!!\n", __FUNCTION__ ); ret = gst_pad_event_default (pad, event); break; case GST_EVENT_SEEK: { gst_event_ref( event ); gdouble rate; //gboolean update = TRUE; GstFormat format; GstSeekType cur_type, stop_type; GstSeekFlags flags; gint64 cur = 0, stop = 0; gst_event_parse_seek ( event, &rate, &format, &flags, &cur_type, &cur, &stop_type, &stop ); g_print( "[%s] Got EVENT_SEEK (pos = %lld)!!!\n", __FUNCTION__, cur ); if ( !( flags & GST_SEEK_FLAG_FLUSH ) ) { g_print( "[%s] Could get the FLAG_FLUSH message.\n", __FUNCTION__ ); } if ( format == GST_FORMAT_TIME && ( ret = gst_pad_event_default (pad, event) ) == FALSE ) { gst_event_unref( event ); break; } break; } default: ret = gst_pad_event_default (pad, event); } return ret; } static gboolean gst_mythtv_src_is_seekable( GstBaseSrc *push_src ) { return FALSE; } static gboolean gst_mythtv_src_handle_query (GstPad * pad, GstQuery * query) { gboolean res = FALSE; GstMythtvSrc *myth = GST_MYTHTV_SRC (gst_pad_get_parent (pad)); switch (GST_QUERY_TYPE (query)) { case GST_QUERY_POSITION: gst_query_set_position (query, GST_FORMAT_BYTES, myth->read_offset ); res = TRUE; GST_DEBUG_OBJECT (myth, "POS %d", myth->read_offset); break; case GST_QUERY_DURATION: #if 0 if (myth->duration != 0) { gint64 total; gint64 fps; fps = nuv->h->i_fpsn / nuv->h->i_fpsd; total = gst_util_uint64_scale_int (GST_SECOND, nuv->h->i_video_blocks, fps); #endif //gst_query_set_duration (query, GST_FORMAT_TIME, myth->content_size); GST_DEBUG_OBJECT (myth, "DURATION %d", myth->content_size); res = FALSE; break; default: res = FALSE; break; } gst_object_unref (myth); return res; } static GstStateChangeReturn gst_mythtv_src_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;//GST_STATE_CHANGE_NO_PREROLL; GstMythtvSrc *src = GST_MYTHTV_SRC (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: //src->do_start = TRUE; //src->unique_setup = FALSE; break; case GST_STATE_CHANGE_READY_TO_PAUSED: case GST_STATE_CHANGE_PAUSED_TO_PLAYING: //src->eos = FALSE; break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); if (ret == GST_STATE_CHANGE_FAILURE) return ret; switch (transition) { case GST_STATE_CHANGE_READY_TO_NULL: g_print( "[%s] READY to NULL called!\n", __FUNCTION__ ); break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: g_print( "[%s] PLAYING to PAUSED called!\n", __FUNCTION__ ); case GST_STATE_CHANGE_PAUSED_TO_READY: g_print( "[%s] PAUSED to READY called!\n", __FUNCTION__ ); if ( src->live_tv && src->update_prog_chain ) { /* gst_pad_push_event ( GST_BASE_SRC_PAD (GST_BASE_SRC (src)), gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, 0, -1, 0 ) ); src->read_offset = 0; src->bytes_read = 0; src->unique_setup = FALSE; gst_mythtv_src_next_program_chain( src ); */ } break; default: break; } return ret; } static void gst_mythtv_src_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); GST_OBJECT_LOCK (mythtvsrc); switch (prop_id) { case PROP_URI: case PROP_LOCATION: { if (!g_value_get_string (value)) { GST_WARNING ("location property cannot be NULL"); goto done; } if (mythtvsrc->uri_name != NULL) { g_free (mythtvsrc->uri_name); mythtvsrc->uri_name = NULL; } mythtvsrc->uri_name = g_value_dup_string (value); break; } #ifndef GST_DISABLE_GST_DEBUG case PROP_GMYTHTV_DBG: { mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value); break; } #endif case PROP_GMYTHTV_VERSION: { mythtvsrc->mythtv_version = g_value_get_int (value); break; } case PROP_GMYTHTV_LIVEID: { mythtvsrc->live_tv_id = g_value_get_int (value); break; } case PROP_GMYTHTV_LIVE: { mythtvsrc->live_tv = g_value_get_boolean (value); break; } case PROP_GMYTHTV_ENABLE_TIMING_POSITION: { mythtvsrc->enable_timing_position = g_value_get_boolean (value); break; } case PROP_GMYTHTV_LIVE_CHAINID: { if (!g_value_get_string (value)) { GST_WARNING ("MythTV Live chainid property cannot be NULL"); goto done; } if (mythtvsrc->live_chain_id != NULL) { g_free (mythtvsrc->live_chain_id); mythtvsrc->live_chain_id = NULL; } mythtvsrc->live_chain_id = g_value_dup_string (value); break; } case PROP_GMYTHTV_CHANNEL_NUM: { mythtvsrc->channel_num = g_value_get_int (value); break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } GST_OBJECT_UNLOCK (mythtvsrc); done: return; } static void gst_mythtv_src_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { GstMythtvSrc *mythtvsrc = GST_MYTHTV_SRC (object); GST_OBJECT_LOCK (mythtvsrc); switch (prop_id) { case PROP_URI: case PROP_LOCATION: { gchar *str = g_strdup( "" ); if ( mythtvsrc->uri_name == NULL ) { g_free (mythtvsrc->uri_name); mythtvsrc->uri_name = NULL; } else { str = g_strdup( mythtvsrc->uri_name ); } g_value_set_string ( value, str ); break; } #ifndef GST_DISABLE_GST_DEBUG case PROP_GMYTHTV_DBG: g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg ); break; #endif case PROP_GMYTHTV_VERSION: { g_value_set_int ( value, mythtvsrc->mythtv_version ); break; } case PROP_GMYTHTV_LIVEID: { g_value_set_int ( value, mythtvsrc->live_tv_id ); break; } case PROP_GMYTHTV_LIVE: g_value_set_boolean ( value, mythtvsrc->live_tv ); break; case PROP_GMYTHTV_ENABLE_TIMING_POSITION: g_value_set_boolean ( value, mythtvsrc->enable_timing_position ); break; case PROP_GMYTHTV_LIVE_CHAINID: { gchar *str = g_strdup( "" ); if ( mythtvsrc->live_chain_id == NULL ) { g_free (mythtvsrc->live_chain_id); mythtvsrc->live_chain_id = NULL; } else { str = g_strdup( mythtvsrc->live_chain_id ); } g_value_set_string ( value, str ); break; } case PROP_GMYTHTV_CHANNEL_NUM: { g_value_set_int ( value, mythtvsrc->channel_num ); break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } GST_OBJECT_UNLOCK (mythtvsrc); } /* entry point to initialize the plug-in * initialize the plug-in itself * register the element factories and pad templates * register the features */ static gboolean plugin_init (GstPlugin * plugin) { return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE, GST_TYPE_MYTHTV_SRC); } /* this is the structure that gst-register looks for * so keep the name plugin_desc, or you cannot get your plug-in registered */ GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, "mythtv", "lib MythTV src", plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/") /*** GSTURIHANDLER INTERFACE *************************************************/ static guint gst_mythtv_src_uri_get_type (void) { return GST_URI_SRC; } static gchar ** gst_mythtv_src_uri_get_protocols (void) { static gchar *protocols[] = { "myth", "myths", NULL }; return protocols; } static const gchar * gst_mythtv_src_uri_get_uri (GstURIHandler * handler) { GstMythtvSrc *src = GST_MYTHTV_SRC (handler); return src->uri_name; } static gboolean gst_mythtv_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) { GstMythtvSrc *src = GST_MYTHTV_SRC (handler); gchar *protocol; protocol = gst_uri_get_protocol (uri); if ((strcmp (protocol, "myth") != 0) && (strcmp (protocol, "myths") != 0)) { g_free (protocol); return FALSE; } g_free (protocol); g_object_set (src, "location", uri, NULL); return TRUE; } static void gst_mythtv_src_uri_handler_init (gpointer g_iface, gpointer iface_data) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; iface->get_type = gst_mythtv_src_uri_get_type; iface->get_protocols = gst_mythtv_src_uri_get_protocols; iface->get_uri = gst_mythtv_src_uri_get_uri; iface->set_uri = gst_mythtv_src_uri_set_uri; } void size_header_handler (void *userdata, const char *value) { GstMythtvSrc *src = GST_MYTHTV_SRC (userdata); //src->content_size = g_ascii_strtoull (value, NULL, 10); GST_DEBUG_OBJECT (src, "content size = %lld bytes", src->content_size); }