gst-plugins-mythtv/src/gstmythtvsrc.c
branchtrunk
changeset 41 686549eb5657
parent 37 324e04989738
child 44 7a654d6de88f
     1.1 --- a/gst-plugins-mythtv/src/gstmythtvsrc.c	Mon Oct 23 14:36:26 2006 +0100
     1.2 +++ b/gst-plugins-mythtv/src/gstmythtvsrc.c	Mon Oct 23 16:02:15 2006 +0100
     1.3 @@ -18,8 +18,8 @@
     1.4  #endif
     1.5  
     1.6  #include "gstmythtvsrc.h"
     1.7 -#include "myth_file_transfer.h"
     1.8 -#include "myth_livetv.h"
     1.9 +#include "gmyth_file_transfer.h"
    1.10 +#include "gmyth_livetv.h"
    1.11  
    1.12  #include <gmyth/gmyth_socket.h>
    1.13  #include <gmyth/gmyth_tvchain.h>
    1.14 @@ -30,13 +30,13 @@
    1.15  GST_DEBUG_CATEGORY_STATIC (mythtvsrc_debug);
    1.16  #define GST_CAT_DEFAULT mythtvsrc_debug
    1.17  
    1.18 -#define GST_MYTHTV_ID_NUM		1
    1.19 +#define GST_GMYTHTV_ID_NUM		1
    1.20  
    1.21 -#define MYTHTV_VERSION_DEFAULT		30
    1.22 +#define GMYTHTV_VERSION_DEFAULT		30
    1.23  
    1.24 -#define MYTHTV_TRANSFER_MAX_WAITS	100
    1.25 +#define GMYTHTV_TRANSFER_MAX_WAITS	100
    1.26  
    1.27 -#define MYTHTV_TRANSFER_MAX_BUFFER	1024*1024
    1.28 +#define GMYTHTV_TRANSFER_MAX_BUFFER	1024*1024
    1.29  //( 32*1024  )
    1.30  
    1.31  /* 4*1024 ??? */
    1.32 @@ -70,12 +70,12 @@
    1.33    PROP_LOCATION,
    1.34    PROP_URI,
    1.35  #ifndef GST_DISABLE_GST_DEBUG
    1.36 -  PROP_MYTHTV_DBG,
    1.37 +  PROP_GMYTHTV_DBG,
    1.38  #endif
    1.39 -  PROP_MYTHTV_VERSION,
    1.40 -  PROP_MYTHTV_LIVE,
    1.41 -  PROP_MYTHTV_LIVEID,
    1.42 -  PROP_MYTHTV_LIVE_CHAINID
    1.43 +  PROP_GMYTHTV_VERSION,
    1.44 +  PROP_GMYTHTV_LIVE,
    1.45 +  PROP_GMYTHTV_LIVEID,
    1.46 +  PROP_GMYTHTV_LIVE_CHAINID
    1.47  };
    1.48  
    1.49  static void gst_mythtv_src_finalize (GObject * gobject);
    1.50 @@ -168,32 +168,32 @@
    1.51         "", G_PARAM_READWRITE));
    1.52  
    1.53    g_object_class_install_property
    1.54 -    (gobject_class, PROP_MYTHTV_VERSION,
    1.55 +    (gobject_class, PROP_GMYTHTV_VERSION,
    1.56       g_param_spec_int ("mythtv-version", "mythtv-version",
    1.57         "Change Myth TV version",
    1.58         26, 30, 26, G_PARAM_READWRITE));
    1.59  
    1.60    g_object_class_install_property
    1.61 -    (gobject_class, PROP_MYTHTV_LIVEID,
    1.62 +    (gobject_class, PROP_GMYTHTV_LIVEID,
    1.63       g_param_spec_int ("mythtv-live-id", "mythtv-live-id",
    1.64         "Change Myth TV version",
    1.65 -       0, 200, GST_MYTHTV_ID_NUM, G_PARAM_READWRITE));
    1.66 +       0, 200, GST_GMYTHTV_ID_NUM, G_PARAM_READWRITE));
    1.67  
    1.68    g_object_class_install_property
    1.69 -    (gobject_class, PROP_MYTHTV_LIVE_CHAINID,
    1.70 +    (gobject_class, PROP_GMYTHTV_LIVE_CHAINID,
    1.71       g_param_spec_string ("mythtv-live-chainid", "mythtv-live-chainid",
    1.72         "Sets the Myth TV chain ID (from TV Chain)",
    1.73         "", G_PARAM_READWRITE));
    1.74  
    1.75    g_object_class_install_property
    1.76 -    (gobject_class, PROP_MYTHTV_LIVE,
    1.77 +    (gobject_class, PROP_GMYTHTV_LIVE,
    1.78       g_param_spec_boolean ("mythtv-live", "mythtv-live",
    1.79         "Enable MythTV Live TV content streaming",
    1.80         FALSE, G_PARAM_READWRITE));
    1.81  
    1.82  #ifndef GST_DISABLE_GST_DEBUG
    1.83    g_object_class_install_property
    1.84 -    (gobject_class, PROP_MYTHTV_DBG,
    1.85 +    (gobject_class, PROP_GMYTHTV_DBG,
    1.86       g_param_spec_boolean ("mythtv-debug", "mythtv-debug",
    1.87         "Enable MythTV debug messages",
    1.88         FALSE, G_PARAM_READWRITE));
    1.89 @@ -218,7 +218,7 @@
    1.90  
    1.91    this->unique_setup = FALSE;
    1.92  
    1.93 -  this->mythtv_version = MYTHTV_VERSION_DEFAULT;
    1.94 +  this->mythtv_version = GMYTHTV_VERSION_DEFAULT;
    1.95  
    1.96    this->bytes_read = 0;
    1.97  
    1.98 @@ -293,7 +293,7 @@
    1.99  
   1.100    while ( sizetoread > 0 ) {
   1.101    	
   1.102 -  	len = myth_file_transfer_read( src->file_transfer,
   1.103 +  	len = gmyth_file_transfer_read( src->file_transfer,
   1.104  			GST_BUFFER_DATA( *outbuf ) + read, sizetoread, TRUE );
   1.105  
   1.106      if ( len > 0 ) {
   1.107 @@ -305,25 +305,29 @@
   1.108  		goto done;
   1.109        } else if ( /*src->content_size >= src->read_offset && 
   1.110        			abs ( src->content_size - src->read_offset ) <= 1024 ) ||*/
   1.111 -      			( src->content_size <= ( src->read_offset + size + MYTHTV_TRANSFER_MAX_BUFFER ) ) )
   1.112 +      			( src->content_size <= ( src->read_offset + size + GMYTHTV_TRANSFER_MAX_BUFFER ) ) )
   1.113    {
   1.114  #if ENABLE_TIMING_POSITION == 1
   1.115 -    guint64 size_tmp = 0;
   1.116 +    gint64 size_tmp = 0;
   1.117      if (src->live_tv == TRUE) {
   1.118  get_file_pos:
   1.119 -      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
   1.120 -      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
   1.121 +      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.122 +      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.123  	src->content_size = size_tmp;
   1.124 -      else
   1.125 +      else if ( size_tmp > 0 )
   1.126  	goto get_file_pos;
   1.127 -      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
   1.128 +      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.129  	  __FUNCTION__, size_tmp );
   1.130      }
   1.131  #else
   1.132 -  	guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
   1.133 -  	if ( src->content_size < new_offset ) {
   1.134 -  	  src->content_size = new_offset;
   1.135 -  	}
   1.136 +  	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.137 +	if ( new_offset > 0 ) {
   1.138 +	  if ( src->content_size < new_offset ) {
   1.139 +	    src->content_size = new_offset;
   1.140 +	  }
   1.141 +	} else {
   1.142 +	  src->update_prog_chain = TRUE;
   1.143 +	}
   1.144  #endif
   1.145  	goto done;
   1.146    }
   1.147 @@ -377,17 +381,19 @@
   1.148    /* The caller should know the number of bytes and not read beyond EOS. */
   1.149    if (G_UNLIKELY (src->eos))
   1.150      goto eos;
   1.151 +  if ( G_UNLIKELY (src->update_prog_chain) )
   1.152 +    goto change_progchain;
   1.153    
   1.154    //GST_OBJECT_LOCK(src);
   1.155  
   1.156    if (G_UNLIKELY (src->read_offset != offset)) {
   1.157 -    guint64 new_offset = myth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
   1.158 -    g_print( "[%s] SRC Offset = %llu, NEW actual backend SEEK Offset = %llu.\n",
   1.159 +    gint64 new_offset = gmyth_file_transfer_seek(src->file_transfer, offset, SEEK_SET);
   1.160 +    g_print( "[%s] SRC Offset = %lld, NEW actual backend SEEK Offset = %lld.\n",
   1.161      	__FUNCTION__, src->read_offset, new_offset );
   1.162      if (G_UNLIKELY (new_offset < 0 ) )//|| new_offset != src->read_offset)) {
   1.163      {
   1.164        //GST_OBJECT_UNLOCK(src);
   1.165 -      goto seek_failed;
   1.166 +      goto change_progchain;
   1.167      }
   1.168  
   1.169      src->read_offset = offset;
   1.170 @@ -407,6 +413,9 @@
   1.171    read = do_read_request_response ( src, src->read_offset, size, outbuf );
   1.172    //g_static_mutex_unlock( &update_size_mutex );  
   1.173  
   1.174 +  if (G_UNLIKELY (src->update_prog_chain) )
   1.175 +    goto change_progchain;
   1.176 +
   1.177    if (G_UNLIKELY (read < 0) || *outbuf == NULL) {
   1.178    	//if ( src->live_tv )
   1.179      //	goto done;
   1.180 @@ -443,7 +452,7 @@
   1.181  	  src->uri_name));
   1.182      return GST_FLOW_ERROR;
   1.183    }
   1.184 -seek_failed:
   1.185 +change_progchain:
   1.186    {
   1.187      GST_ELEMENT_ERROR (src, RESOURCE, READ,
   1.188  	(NULL), ("Seek failed, go to the next program info... (%i, %s)", read,
   1.189 @@ -470,16 +479,16 @@
   1.190  
   1.191    if ( src->do_start ) {
   1.192  #if ENABLE_TIMING_POSITION == 1
   1.193 -    guint64 size_tmp = 0;
   1.194 +    gint64 size_tmp = 0;
   1.195      if (src->live_tv == TRUE) {
   1.196  get_file_pos:
   1.197        g_usleep( 50 );
   1.198 -      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
   1.199 -      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
   1.200 +      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.201 +      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.202  	src->content_size = size_tmp;
   1.203 -      else
   1.204 +      else if ( size_tmp > 0 )
   1.205  	goto get_file_pos;
   1.206 -      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
   1.207 +      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.208  	  __FUNCTION__, size_tmp );
   1.209      }
   1.210  #endif
   1.211 @@ -494,16 +503,16 @@
   1.212  
   1.213    if ( src->do_start ) {
   1.214  #if ENABLE_TIMING_POSITION == 1
   1.215 -    guint64 size_tmp = 0;
   1.216 +    gint64 size_tmp = 0;
   1.217      if (src->live_tv == TRUE) {
   1.218  get_file_pos:
   1.219        g_usleep( 50 );
   1.220 -      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
   1.221 -      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
   1.222 +      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.223 +      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.224  		src->content_size = size_tmp;
   1.225 -      else
   1.226 +      else if ( size_tmp > 0 )
   1.227  	goto get_file_pos;
   1.228 -      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
   1.229 +      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.230  	  __FUNCTION__, size_tmp );
   1.231      }
   1.232  #endif
   1.233 @@ -532,8 +541,8 @@
   1.234    GST_OBJECT_LOCK(src);
   1.235  
   1.236    if ( src->live_tv ) {
   1.237 -    src->spawn_livetv = myth_livetv_new( );
   1.238 -    if ( myth_livetv_setup( src->spawn_livetv ) == FALSE ) {
   1.239 +    src->spawn_livetv = gmyth_livetv_new( );
   1.240 +    if ( gmyth_livetv_setup( src->spawn_livetv ) == FALSE ) {
   1.241        ret = FALSE;
   1.242        goto init_failed;
   1.243      }
   1.244 @@ -548,7 +557,7 @@
   1.245      g_print ( "[%s] LiveTV id = %d, URI path = %s.\n", __FUNCTION__, src->live_tv_id, src->uri_name );
   1.246    }
   1.247  
   1.248 -  src->file_transfer = myth_file_transfer_new( src->live_tv_id, 
   1.249 +  src->file_transfer = gmyth_file_transfer_new( src->live_tv_id, 
   1.250        g_string_new( src->uri_name ), -1, src->mythtv_version );
   1.251  
   1.252    if ( src->file_transfer == NULL ) {
   1.253 @@ -558,19 +567,19 @@
   1.254    }
   1.255  
   1.256    /* sets the Playback monitor connection */
   1.257 -  ret = myth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   1.258 +  ret = gmyth_file_transfer_playback_setup( &(src->file_transfer), src->live_tv );
   1.259  
   1.260    if ( src->live_tv == TRUE && ret == TRUE ) {
   1.261      /* loop finished, set the max tries variable to zero again... */
   1.262      wait_to_transfer = 0;
   1.263  
   1.264 -    while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS && ( myth_file_transfer_is_recording( src->file_transfer ) == FALSE 
   1.265 -	  /*|| ( myth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
   1.266 +    while ( wait_to_transfer++ < GMYTHTV_TRANSFER_MAX_WAITS && ( gmyth_file_transfer_is_recording( src->file_transfer ) == FALSE 
   1.267 +	  /*|| ( gmyth_file_transfer_get_file_position( src->file_transfer ) < ( src->content_size + 327680 ) )*/ ) )
   1.268        g_usleep( 100 );
   1.269    }
   1.270  
   1.271    /* sets the FileTransfer instance connection (video/audio download) */
   1.272 -  ret = myth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   1.273 +  ret = gmyth_file_transfer_setup( &(src->file_transfer), src->live_tv );
   1.274  
   1.275    if ( ret == FALSE ) {
   1.276      GST_OBJECT_UNLOCK(src);
   1.277 @@ -624,7 +633,7 @@
   1.278  
   1.279    guint64 size = 0;
   1.280  
   1.281 -  mythtv = GST_MYTHTV_SRC( GST_PAD_PARENT (pad) );
   1.282 +  mythtv = GST_GMYTHTV_SRC( GST_PAD_PARENT (pad) );
   1.283  
   1.284    size = gst_mythtv_src_get_position (mythtv);
   1.285  
   1.286 @@ -690,26 +699,31 @@
   1.287  
   1.288    if (src->content_size <= 0) {
   1.289      ret= FALSE;
   1.290 -  } else if ( abs ( src->content_size - src->read_offset ) <= MYTHTV_TRANSFER_MAX_BUFFER ) {
   1.291 +  } else if ( abs ( src->content_size - src->read_offset ) <= GMYTHTV_TRANSFER_MAX_BUFFER ) {
   1.292      //g_static_mutex_lock( &update_size_mutex );
   1.293      GST_OBJECT_LOCK(src);
   1.294  
   1.295 -  	guint64 new_offset = myth_file_transfer_get_file_position( src->file_transfer );
   1.296 -  	if ( src->content_size < new_offset ) {
   1.297 -  	  src->content_size = new_offset;
   1.298 -  	}
   1.299 +  	gint64 new_offset = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.300 +	if ( new_offset > 0 ) {
   1.301 +	  if ( src->content_size < new_offset ) {
   1.302 +	    src->content_size = new_offset;
   1.303 +	  }
   1.304 +	} else {
   1.305 +	  src->update_prog_chain = TRUE;
   1.306 +	  src->content_size = 0;
   1.307 +	}
   1.308   
   1.309  #if ENABLE_TIMING_POSITION == 1
   1.310 -    guint64 size_tmp = 0;
   1.311 +    gint64 size_tmp = 0;
   1.312      if (src->live_tv == TRUE) {
   1.313  get_file_pos:
   1.314        g_usleep( 5 );
   1.315 -      size_tmp = myth_file_transfer_get_file_position( src->file_transfer );
   1.316 -      if ( size_tmp > ( src->content_size + MYTHTV_TRANSFER_MAX_BUFFER ) )
   1.317 +      size_tmp = gmyth_file_transfer_get_file_position( src->file_transfer );
   1.318 +      if ( size_tmp > ( src->content_size + GMYTHTV_TRANSFER_MAX_BUFFER ) )
   1.319  	src->content_size = size_tmp;
   1.320 -      else
   1.321 +      else if ( size_tmp > 0  )
   1.322  	goto get_file_pos;
   1.323 -      g_print( "\t[%s]\tGET_POSITION: file_position = %llu\n",
   1.324 +      g_print( "\t[%s]\tGET_POSITION: file_position = %lld\n",
   1.325  	  __FUNCTION__, size_tmp );
   1.326      }
   1.327  #endif
   1.328 @@ -849,28 +863,28 @@
   1.329  	break;
   1.330        }
   1.331  #ifndef GST_DISABLE_GST_DEBUG
   1.332 -    case PROP_MYTHTV_DBG:
   1.333 +    case PROP_GMYTHTV_DBG:
   1.334        {
   1.335  	mythtvsrc->mythtv_msgs_dbg = g_value_get_boolean (value);
   1.336  	break;
   1.337        }
   1.338  #endif
   1.339 -    case PROP_MYTHTV_VERSION:
   1.340 +    case PROP_GMYTHTV_VERSION:
   1.341        {
   1.342  	mythtvsrc->mythtv_version = g_value_get_int (value);
   1.343  	break;
   1.344        }
   1.345 -    case PROP_MYTHTV_LIVEID:
   1.346 +    case PROP_GMYTHTV_LIVEID:
   1.347        {
   1.348  	mythtvsrc->live_tv_id = g_value_get_int (value);
   1.349  	break;
   1.350        }
   1.351 -    case PROP_MYTHTV_LIVE:
   1.352 +    case PROP_GMYTHTV_LIVE:
   1.353        {
   1.354  	mythtvsrc->live_tv = g_value_get_boolean (value);
   1.355  	break;
   1.356        }
   1.357 -    case PROP_MYTHTV_LIVE_CHAINID:
   1.358 +    case PROP_GMYTHTV_LIVE_CHAINID:
   1.359        {
   1.360  	if (!g_value_get_string (value)) {
   1.361  	  GST_WARNING ("MythTV Live chainid property cannot be NULL");
   1.362 @@ -918,24 +932,24 @@
   1.363  	break;
   1.364        }
   1.365  #ifndef GST_DISABLE_GST_DEBUG
   1.366 -    case PROP_MYTHTV_DBG:
   1.367 +    case PROP_GMYTHTV_DBG:
   1.368        g_value_set_boolean ( value, mythtvsrc->mythtv_msgs_dbg );
   1.369        break;
   1.370  #endif
   1.371 -    case PROP_MYTHTV_VERSION:
   1.372 +    case PROP_GMYTHTV_VERSION:
   1.373        {
   1.374  	g_value_set_int ( value, mythtvsrc->mythtv_version );
   1.375  	break;
   1.376        }
   1.377 -    case PROP_MYTHTV_LIVEID:
   1.378 +    case PROP_GMYTHTV_LIVEID:
   1.379        {
   1.380  	g_value_set_int ( value, mythtvsrc->live_tv_id );
   1.381  	break;
   1.382        }
   1.383 -    case PROP_MYTHTV_LIVE:
   1.384 +    case PROP_GMYTHTV_LIVE:
   1.385        g_value_set_boolean ( value, mythtvsrc->live_tv );
   1.386        break;
   1.387 -    case PROP_MYTHTV_LIVE_CHAINID:
   1.388 +    case PROP_GMYTHTV_LIVE_CHAINID:
   1.389        {
   1.390  	gchar *str = g_strdup( "" );
   1.391  
   1.392 @@ -960,7 +974,7 @@
   1.393   * register the element factories and pad templates
   1.394   * register the features
   1.395   */
   1.396 -  static gboolean
   1.397 +static gboolean
   1.398  plugin_init (GstPlugin * plugin)
   1.399  {
   1.400    return gst_element_register (plugin, "mythtvsrc", GST_RANK_NONE,