libgnomevfs2-mythtv/modules/mythtv-method.c
branchtrunk
changeset 278 a24bacc8d752
parent 251 9f0346db9a46
child 281 08c4bc759e7a
     1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c	Wed Jan 10 17:19:50 2007 +0000
     1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c	Fri Jan 19 13:09:21 2007 +0000
     1.3 @@ -27,12 +27,16 @@
     1.4  #include <libgnomevfs/gnome-vfs-module.h>
     1.5  #include <libgnomevfs/gnome-vfs-utils.h>
     1.6  
     1.7 -#include <gmyth_file_transfer.h>
     1.8 -#include <gmyth_backendinfo.h>
     1.9 -#include <gmyth_util.h>
    1.10 +#include <gmyth/gmyth_file_transfer.h>
    1.11 +#include <gmyth/gmyth_livetv.h>
    1.12 +#include <gmyth/gmyth_uri.h>
    1.13 +#include <gmyth/gmyth_recorder.h>
    1.14 +#include <gmyth/gmyth_backendinfo.h>
    1.15 +#include <gmyth/gmyth_util.h>
    1.16  
    1.17  #define GST_MYTHTV_ID_NUM               1
    1.18  #define MYTHTV_VERSION_DEFAULT          30
    1.19 +#define MYTHTV_TRANSFER_MAX_WAITS       100
    1.20  
    1.21  #define MYTHTV_BUFFER_SIZE		1024*64
    1.22  
    1.23 @@ -45,6 +49,8 @@
    1.24  
    1.25  typedef struct {
    1.26      GMythFileTransfer *file_transfer;
    1.27 +    GMythLiveTV 			*livetv;
    1.28 +    gint 							channel_num;
    1.29      
    1.30      gint mythtv_version;
    1.31      guint64 content_size;
    1.32 @@ -65,7 +71,10 @@
    1.33  {
    1.34      MythtvHandle *myth_handle;
    1.35      GMythBackendInfo *backend_info;
    1.36 -    gboolean ret;
    1.37 +    GMythURI *gmyth_uri = NULL;
    1.38 +    gboolean ret = TRUE;
    1.39 +    gboolean is_livetv = FALSE;
    1.40 +    gint wait_to_transfer = 0;
    1.41  
    1.42      _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
    1.43      _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
    1.44 @@ -82,36 +91,83 @@
    1.45  
    1.46      /* Initialize mythtv handler*/
    1.47      myth_handle->file_transfer = NULL;
    1.48 +    myth_handle->livetv = NULL;
    1.49      myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
    1.50      myth_handle->bytes_read = 0;
    1.51      myth_handle->content_size = -1;
    1.52  
    1.53 -    /* Creates and fills out the backend info structure */
    1.54 -    backend_info = gmyth_backend_info_new_full (
    1.55 -        gnome_vfs_uri_get_host_name (uri),
    1.56 -	    NULL, NULL, NULL,
    1.57 -	    gnome_vfs_uri_get_host_port (uri));
    1.58 +    /* Creates and fills out the backend info structure */    
    1.59 +	  backend_info = gmyth_backend_info_new_with_uri ( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) );
    1.60 +	  
    1.61 +	  /* creates an instance of  */  
    1.62 +	  gmyth_uri = gmyth_uri_new_with_value( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ) );
    1.63 +	  
    1.64 +	  /* Connect to the backend */	  
    1.65 +	  if ( gmyth_uri != NULL && ( is_livetv = gmyth_uri_is_livetv( gmyth_uri ) ) == TRUE ) {
    1.66 +	    myth_handle->livetv = gmyth_livetv_new ();
    1.67  	    
    1.68 +	    myth_handle->channel_num = gmyth_uri_get_channel_num( gmyth_uri );
    1.69 +	
    1.70 +	    if ( myth_handle->channel_num != -1 ) {
    1.71 +	      if (gmyth_livetv_channel_setup (myth_handle->livetv, myth_handle->channel_num,
    1.72 +	              backend_info) == FALSE) {
    1.73 +	        g_object_unref( gmyth_uri );
    1.74 +	        ret = FALSE;
    1.75 +	      }
    1.76 +	    } else {
    1.77 +	      if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
    1.78 +	      	g_object_unref( gmyth_uri );
    1.79 +	        ret = FALSE;
    1.80 +	      }
    1.81 +	    }
    1.82 +	
    1.83 +	    myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
    1.84 +	
    1.85 +	    if (NULL == myth_handle->file_transfer) {
    1.86 +	      ret = FALSE;
    1.87 +	    }
    1.88 +	    
    1.89 +	    if ( gmyth_uri != NULL )
    1.90 +	    	g_object_unref( gmyth_uri );
    1.91 +	    	
    1.92 +	  } else {
    1.93 +	
    1.94 +	    myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
    1.95 +	    
    1.96 +	    /* Verifies if the file exists */
    1.97 +	    if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) {
    1.98 +	        g_object_unref (backend_info);
    1.99 +					return GNOME_VFS_ERROR_NOT_FOUND;
   1.100 +	    }
   1.101 +	    
   1.102 +	    /* sets the Playback monitor connection */
   1.103 +	    ret = gmyth_file_transfer_open ( myth_handle->file_transfer, gnome_vfs_uri_get_path (uri) );
   1.104 +		
   1.105 +	  } /* if - LiveTV or not? */
   1.106 +	  
   1.107 +    if (ret == FALSE) {
   1.108 +	    g_warning ("MythTV FileTransfer open error\n");
   1.109 +	    return GNOME_VFS_ERROR_NOT_OPEN;
   1.110 +	  } 
   1.111 +	
   1.112 +	  if ( is_livetv == TRUE && ret == TRUE ) {
   1.113 +	    /* loop finished, set the max tries variable to zero again... */
   1.114 +	    wait_to_transfer = 0;
   1.115 +	
   1.116 +	    while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS &&
   1.117 +	        (gmyth_livetv_is_recording (myth_handle->livetv) == FALSE))
   1.118 +	      g_usleep (500);
   1.119 +	
   1.120 +	    /* IS_RECORDING again, just like the MythTV backend does... */
   1.121 +	    gmyth_livetv_is_recording (myth_handle->livetv);
   1.122 +	
   1.123 +	    sleep (4);                  /* FIXME: this is evil (tpm) */
   1.124 +	  }
   1.125  
   1.126 -    /* Verifies if the file exists */
   1.127 -    if (!gmyth_util_file_exists (backend_info, gnome_vfs_uri_get_path (uri))) {
   1.128 -        g_object_unref (backend_info);
   1.129 -	return GNOME_VFS_ERROR_NOT_FOUND;
   1.130 -    }
   1.131 -		    
   1.132 -    /* Connect to the backend */
   1.133 -    myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
   1.134      g_object_unref (backend_info);
   1.135  
   1.136      g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
   1.137  
   1.138 -    /* sets the Playback monitor connection */
   1.139 -    ret = gmyth_file_transfer_open (myth_handle->file_transfer, gnome_vfs_uri_get_path (uri));
   1.140 -    if (ret == FALSE) {
   1.141 -        g_warning ("Mythtv FileTransfer open error\n");
   1.142 -        return GNOME_VFS_ERROR_NOT_OPEN;
   1.143 -    }
   1.144 -
   1.145      myth_handle->content_size = myth_handle->file_transfer->filesize;
   1.146      
   1.147      myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
   1.148 @@ -201,6 +257,11 @@
   1.149      	myth_handle->file_transfer = NULL;
   1.150      }
   1.151      
   1.152 +    if (myth_handle->livetv) {
   1.153 +      g_object_unref (myth_handle->livetv);
   1.154 +    	myth_handle->livetv = NULL;
   1.155 +    }
   1.156 +    
   1.157      if (myth_handle->buffer) {
   1.158  		g_byte_array_free (myth_handle->buffer, TRUE);
   1.159  		myth_handle->buffer = NULL;