[svn r278] Added LiveTV streaming to the gnomevfs mythtv plug-in. trunk
authorrosfran
Fri Jan 19 00:51:49 2007 +0000 (2007-01-19)
branchtrunk
changeset 277890b023c759f
parent 276 ed5172cf0f1b
child 278 a24bacc8d752
[svn r278] Added LiveTV streaming to the gnomevfs mythtv plug-in.
libgnomevfs2-mythtv/README
libgnomevfs2-mythtv/modules/mythtv-method.c
     1.1 --- a/libgnomevfs2-mythtv/README	Thu Jan 18 21:03:14 2007 +0000
     1.2 +++ b/libgnomevfs2-mythtv/README	Fri Jan 19 00:51:49 2007 +0000
     1.3 @@ -1,3 +1,7 @@
     1.4  URI: myth://host:port/filename
     1.5  
     1.6 +or, when downloading LiveTV content...
     1.7 +
     1.8 +URI: myth://user:password@host:port/?dbname&channel=channel_num
     1.9 +
    1.10  sample: gnomevfs-cat myth://127.0.0.1:7654/video.nuv
     2.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c	Thu Jan 18 21:03:14 2007 +0000
     2.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c	Fri Jan 19 00:51:49 2007 +0000
     2.3 @@ -27,12 +27,16 @@
     2.4  #include <libgnomevfs/gnome-vfs-module.h>
     2.5  #include <libgnomevfs/gnome-vfs-utils.h>
     2.6  
     2.7 -#include <gmyth_file_transfer.h>
     2.8 -#include <gmyth_backendinfo.h>
     2.9 -#include <gmyth_util.h>
    2.10 +#include <gmyth/gmyth_file_transfer.h>
    2.11 +#include <gmyth/gmyth_livetv.h>
    2.12 +#include <gmyth/gmyth_uri.h>
    2.13 +#include <gmyth/gmyth_recorder.h>
    2.14 +#include <gmyth/gmyth_backendinfo.h>
    2.15 +#include <gmyth/gmyth_util.h>
    2.16  
    2.17  #define GST_MYTHTV_ID_NUM               1
    2.18  #define MYTHTV_VERSION_DEFAULT          30
    2.19 +#define MYTHTV_TRANSFER_MAX_WAITS       100
    2.20  
    2.21  #define MYTHTV_BUFFER_SIZE		1024*64
    2.22  
    2.23 @@ -45,6 +49,8 @@
    2.24  
    2.25  typedef struct {
    2.26      GMythFileTransfer *file_transfer;
    2.27 +    GMythLiveTV 			*livetv;
    2.28 +    gint 							channel_num;
    2.29      
    2.30      gint mythtv_version;
    2.31      guint64 content_size;
    2.32 @@ -65,7 +71,10 @@
    2.33  {
    2.34      MythtvHandle *myth_handle;
    2.35      GMythBackendInfo *backend_info;
    2.36 -    gboolean ret;
    2.37 +    GMythURI *gmyth_uri = NULL;
    2.38 +    gboolean ret = TRUE;
    2.39 +    gboolean is_livetv = FALSE;
    2.40 +    gint wait_to_transfer = 0;
    2.41  
    2.42      _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
    2.43      _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
    2.44 @@ -82,36 +91,83 @@
    2.45  
    2.46      /* Initialize mythtv handler*/
    2.47      myth_handle->file_transfer = NULL;
    2.48 +    myth_handle->livetv = NULL;
    2.49      myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
    2.50      myth_handle->bytes_read = 0;
    2.51      myth_handle->content_size = -1;
    2.52  
    2.53 -    /* Creates and fills out the backend info structure */
    2.54 -    backend_info = gmyth_backend_info_new_full (
    2.55 -        gnome_vfs_uri_get_host_name (uri),
    2.56 -	    NULL, NULL, NULL,
    2.57 -	    gnome_vfs_uri_get_host_port (uri));
    2.58 +    /* Creates and fills out the backend info structure */    
    2.59 +	  backend_info = gmyth_backend_info_new_with_uri ( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) );
    2.60 +	  
    2.61 +	  /* creates an instance of  */  
    2.62 +	  gmyth_uri = gmyth_uri_new_with_value( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) );
    2.63 +	  
    2.64 +	  /* Connect to the backend */	  
    2.65 +	  if ( gmyth_uri != NULL && ( is_livetv = gmyth_uri_is_livetv( gmyth_uri ) ) == TRUE ) {
    2.66 +	    myth_handle->livetv = gmyth_livetv_new ();
    2.67  	    
    2.68 +	    myth_handle->channel_num = gmyth_uri_get_channel_num( gmyth_uri );
    2.69 +	
    2.70 +	    if ( myth_handle->channel_num != -1 ) {
    2.71 +	      if (gmyth_livetv_channel_setup (myth_handle->livetv, myth_handle->channel_num,
    2.72 +	              backend_info) == FALSE) {
    2.73 +	        g_object_unref( gmyth_uri );
    2.74 +	        ret = FALSE;
    2.75 +	      }
    2.76 +	    } else {
    2.77 +	      if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
    2.78 +	      	g_object_unref( gmyth_uri );
    2.79 +	        ret = FALSE;
    2.80 +	      }
    2.81 +	    }
    2.82 +	
    2.83 +	    myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
    2.84 +	
    2.85 +	    if (NULL == myth_handle->file_transfer) {
    2.86 +	      ret = FALSE;
    2.87 +	    }
    2.88 +	    
    2.89 +	    if ( gmyth_uri != NULL )
    2.90 +	    	g_object_unref( gmyth_uri );
    2.91 +	    	
    2.92 +	  } else {
    2.93 +	
    2.94 +	    myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
    2.95 +	    
    2.96 +	    /* Verifies if the file exists */
    2.97 +	    if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) {
    2.98 +	        g_object_unref (backend_info);
    2.99 +					return GNOME_VFS_ERROR_NOT_FOUND;
   2.100 +	    }
   2.101 +	    
   2.102 +	    /* sets the Playback monitor connection */
   2.103 +	    ret = gmyth_file_transfer_open ( myth_handle->file_transfer, gnome_vfs_uri_get_path (uri) );
   2.104 +		
   2.105 +	  } /* if - LiveTV or not? */
   2.106 +	  
   2.107 +    if (ret == FALSE) {
   2.108 +	    g_warning ("MythTV FileTransfer open error\n");
   2.109 +	    return GNOME_VFS_ERROR_NOT_OPEN;
   2.110 +	  } 
   2.111 +	
   2.112 +	  if ( is_livetv == TRUE && ret == TRUE ) {
   2.113 +	    /* loop finished, set the max tries variable to zero again... */
   2.114 +	    wait_to_transfer = 0;
   2.115 +	
   2.116 +	    while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS &&
   2.117 +	        (gmyth_livetv_is_recording (myth_handle->livetv) == FALSE))
   2.118 +	      g_usleep (500);
   2.119 +	
   2.120 +	    /* IS_RECORDING again, just like the MythTV backend does... */
   2.121 +	    gmyth_livetv_is_recording (myth_handle->livetv);
   2.122 +	
   2.123 +	    sleep (4);                  /* FIXME: this is evil (tpm) */
   2.124 +	  }
   2.125  
   2.126 -    /* Verifies if the file exists */
   2.127 -    if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) {
   2.128 -        g_object_unref (backend_info);
   2.129 -	return GNOME_VFS_ERROR_NOT_FOUND;
   2.130 -    }
   2.131 -		    
   2.132 -    /* Connect to the backend */
   2.133 -    myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
   2.134      g_object_unref (backend_info);
   2.135  
   2.136      g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
   2.137  
   2.138 -    /* sets the Playback monitor connection */
   2.139 -    ret = gmyth_file_transfer_open (myth_handle->file_transfer, gnome_vfs_uri_get_path (uri));
   2.140 -    if (ret == FALSE) {
   2.141 -        g_warning ("Mythtv FileTransfer open error\n");
   2.142 -        return GNOME_VFS_ERROR_NOT_OPEN;
   2.143 -    }
   2.144 -
   2.145      myth_handle->content_size = myth_handle->file_transfer->filesize;
   2.146      
   2.147      myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
   2.148 @@ -201,6 +257,11 @@
   2.149      	myth_handle->file_transfer = NULL;
   2.150      }
   2.151      
   2.152 +    if (myth_handle->livetv) {
   2.153 +      g_object_unref (myth_handle->livetv);
   2.154 +    	myth_handle->livetv = NULL;
   2.155 +    }
   2.156 +    
   2.157      if (myth_handle->buffer) {
   2.158  		g_byte_array_free (myth_handle->buffer, TRUE);
   2.159  		myth_handle->buffer = NULL;