[svn r329] Cleaning some non-mandatory code snippets from the GnomeVFS handler to the do_get_file_info.
1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Tue Feb 06 00:33:35 2007 +0000
1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Tue Feb 06 00:34:37 2007 +0000
1.3 @@ -38,7 +38,7 @@
1.4 #define MYTHTV_VERSION_DEFAULT 30
1.5 #define MYTHTV_TRANSFER_MAX_WAITS 100
1.6
1.7 -#define MYTHTV_BUFFER_SIZE 1024*64
1.8 +#define MYTHTV_BUFFER_SIZE 1024*64
1.9
1.10 static GnomeVFSResult do_read (GnomeVFSMethod *method,
1.11 GnomeVFSMethodHandle *method_handle,
1.12 @@ -50,7 +50,7 @@
1.13 typedef struct {
1.14 GMythFileTransfer *file_transfer;
1.15 GMythLiveTV *livetv;
1.16 - gint channel_num;
1.17 + gchar *channel_name;
1.18
1.19 gint mythtv_version;
1.20 gint64 content_size;
1.21 @@ -91,7 +91,7 @@
1.22 myth_handle->livetv = NULL;
1.23 myth_handle->mythtv_version = MYTHTV_VERSION_DEFAULT;
1.24 myth_handle->bytes_read = 0;
1.25 - myth_handle->content_size = 0;
1.26 + myth_handle->content_size = -1;
1.27
1.28 /* Creates and fills out the backend info structure */
1.29 backend_info = gmyth_backend_info_new_with_uri (
1.30 @@ -107,10 +107,12 @@
1.31 if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.32 myth_handle->livetv = gmyth_livetv_new ();
1.33
1.34 - myth_handle->channel_num = gmyth_uri_get_channel_num( gmyth_uri );
1.35 + myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.36 +
1.37 + g_print( "[%s] Channel name = %s", __FUNCTION__, myth_handle->channel_name );
1.38
1.39 - if ( myth_handle->channel_num != -1 ) {
1.40 - if (gmyth_livetv_channel_setup (myth_handle->livetv, myth_handle->channel_num,
1.41 + if ( myth_handle->channel_name != NULL ) {
1.42 + if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name,
1.43 backend_info) == FALSE) {
1.44 g_object_unref( gmyth_uri );
1.45 ret = FALSE;
1.46 @@ -148,7 +150,8 @@
1.47 }
1.48
1.49 /* sets the Playback monitor connection */
1.50 - ret = gmyth_file_transfer_open ( myth_handle->file_transfer, gmyth_uri_get_path (gmyth_uri) );
1.51 + ret = gmyth_file_transfer_open ( myth_handle->file_transfer,
1.52 + gmyth_uri_get_path (gmyth_uri) );
1.53
1.54 } /* if - LiveTV or not? */
1.55
1.56 @@ -164,9 +167,10 @@
1.57
1.58 g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
1.59
1.60 - if ( myth_handle->file_transfer->filesize < 0 && is_livetv )
1.61 + if ( myth_handle->file_transfer->filesize < 0 && is_livetv ) {
1.62 + myth_handle->content_size = (GnomeVFSFileSize) - 1;
1.63 myth_handle->content_size = gmyth_recorder_get_file_position( myth_handle->livetv->recorder );
1.64 - else
1.65 + } else
1.66 myth_handle->content_size = myth_handle->file_transfer->filesize;
1.67
1.68 myth_handle->buffer = g_byte_array_sized_new (MYTHTV_BUFFER_SIZE);
1.69 @@ -185,48 +189,48 @@
1.70 GnomeVFSFileSize *bytes_read,
1.71 GnomeVFSContext *context)
1.72 {
1.73 - MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.74 - GnomeVFSFileSize bytes_to_read;
1.75 + MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.76 + GnomeVFSFileSize bytes_to_read;
1.77
1.78 - *bytes_read = 0;
1.79 + *bytes_read = 0;
1.80
1.81 - if (myth_handle->bytes_read >= myth_handle->content_size)
1.82 - return GNOME_VFS_ERROR_EOF;
1.83 + if (myth_handle->bytes_read >= myth_handle->content_size)
1.84 + return GNOME_VFS_ERROR_EOF;
1.85
1.86 - // fixme: change this to min math function
1.87 - if (num_bytes > myth_handle->content_size - myth_handle->bytes_read)
1.88 - bytes_to_read = myth_handle->content_size - myth_handle->bytes_read;
1.89 - else
1.90 - bytes_to_read = num_bytes;
1.91 + // fixme: change this to min math function
1.92 + if (myth_handle->content_size > 0 && num_bytes > ( myth_handle->content_size - myth_handle->bytes_read ))
1.93 + bytes_to_read = myth_handle->content_size - myth_handle->bytes_read;
1.94 + else
1.95 + bytes_to_read = num_bytes;
1.96
1.97 - /* Loop sending the Myth File Transfer request:
1.98 - * Retry whilst authentication fails and we supply it. */
1.99 - //if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) {
1.100 - if ( bytes_to_read > myth_handle->buffer_remain ) {
1.101 - GByteArray *tmp_buffer = g_byte_array_new();
1.102 + /* Loop sending the Myth File Transfer request:
1.103 + * Retry whilst authentication fails and we supply it. */
1.104 + //if (myth_handle->buffer_remain < MYTHTV_BUFFER_SIZE) {
1.105 + if ( ( myth_handle->buffer_remain = myth_handle->buffer->len ) < MYTHTV_BUFFER_SIZE ) {
1.106 + GByteArray *tmp_buffer = g_byte_array_new();
1.107
1.108 - printf ("XXXXXXXXXXXXXX Pedindo %d %d\n", MYTHTV_BUFFER_SIZE, myth_handle->buffer_remain);
1.109 + printf ("XXXXXXXXXXXXXX Pedindo %d %d\n", MYTHTV_BUFFER_SIZE, myth_handle->buffer_remain);
1.110
1.111 - gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
1.112 - tmp_buffer, MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain, TRUE);
1.113 + gint len = gmyth_file_transfer_read (myth_handle->file_transfer,
1.114 + tmp_buffer, MYTHTV_BUFFER_SIZE - myth_handle->buffer_remain, TRUE);
1.115
1.116 - if (len < 0) {
1.117 - g_byte_array_free (tmp_buffer, TRUE);
1.118 - g_warning ("Fail to read bytes");
1.119 + if (len < 0) {
1.120 + g_byte_array_free (tmp_buffer, TRUE);
1.121 + g_warning ("Fail to read bytes");
1.122 return GNOME_VFS_ERROR_IO;
1.123 - } /*else if (len == 0) {
1.124 - g_byte_array_free (tmp_buffer, TRUE);
1.125 - g_warning ("End of file probably achieved");
1.126 - return GNOME_VFS_ERROR_EOF;
1.127 - }*/
1.128 + } /*else if (len == 0) {
1.129 + g_byte_array_free (tmp_buffer, TRUE);
1.130 + g_warning ("End of file probably achieved");
1.131 + return GNOME_VFS_ERROR_EOF;
1.132 + }*/
1.133 +
1.134 + myth_handle->buffer = g_byte_array_append (myth_handle->buffer,
1.135 + tmp_buffer->data, len);
1.136 +
1.137 + myth_handle->buffer_remain += len;
1.138
1.139 - myth_handle->buffer = g_byte_array_append (myth_handle->buffer,
1.140 - tmp_buffer->data, len);
1.141 -
1.142 - myth_handle->buffer_remain += len;
1.143 -
1.144 - g_byte_array_free (tmp_buffer, TRUE);
1.145 - tmp_buffer = NULL;
1.146 + g_byte_array_free (tmp_buffer, TRUE);
1.147 + tmp_buffer = NULL;
1.148 }
1.149
1.150 bytes_to_read = (bytes_to_read > myth_handle->buffer_remain) ? myth_handle->buffer_remain : bytes_to_read;
1.151 @@ -281,12 +285,13 @@
1.152 GnomeVFSContext *context)
1.153 {
1.154 GMythFileTransfer *file_transfer = NULL;
1.155 - GMythLiveTV *livetv = NULL;
1.156 + //GMythLiveTV *livetv = NULL;
1.157 GMythBackendInfo *backend_info = NULL;
1.158 GMythURI *gmyth_uri = NULL;
1.159 gboolean is_livetv = FALSE;
1.160 gboolean ret = TRUE;
1.161
1.162 + file_info->size = (GnomeVFSFileSize) - 1;
1.163 /* Creates and fills out the backend info structure */
1.164 backend_info = gmyth_backend_info_new_with_uri (
1.165 gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.166 @@ -312,8 +317,9 @@
1.167
1.168 /* Connect to the backend */
1.169 if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.170 - livetv = gmyth_livetv_new ();
1.171 -
1.172 + /*
1.173 + livetv = gmyth_livetv_new ();
1.174 +
1.175 gint channel_num = gmyth_uri_get_channel_num( gmyth_uri );
1.176
1.177 if ( channel_num != -1 ) {
1.178 @@ -329,11 +335,12 @@
1.179 }
1.180 }
1.181
1.182 - file_transfer = gmyth_livetv_create_file_transfer (livetv);
1.183 + file_transfer = gmyth_livetv_create_file_transfer (livetv);
1.184
1.185 if (NULL == file_transfer) {
1.186 ret = FALSE;
1.187 }
1.188 + */
1.189
1.190 } else {
1.191
1.192 @@ -356,16 +363,24 @@
1.193 return GNOME_VFS_ERROR_NOT_OPEN;
1.194 }
1.195 */
1.196 - if ( file_transfer->filesize < 0 && is_livetv )
1.197 - file_info->size = gmyth_recorder_get_file_position( livetv->recorder );
1.198 - else
1.199 + if ( is_livetv )
1.200 + {
1.201 + /*
1.202 + GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info ( GMythRecorder *recorder )
1.203 + if ( file_transfer->filesize < 0 )
1.204 + file_info->size = gmyth_recorder_get_file_position( livetv->recorder );
1.205 + else
1.206 + */
1.207 + file_info->size =(GnomeVFSFileSize) - 1;
1.208 + } else {
1.209 file_info->size = gmyth_file_transfer_get_filesize (file_transfer);
1.210 + }
1.211
1.212 file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
1.213 file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
1.214
1.215 g_object_unref (file_transfer);
1.216 - g_object_unref (livetv);
1.217 + //g_object_unref (livetv);
1.218 g_object_unref (backend_info);
1.219
1.220 return GNOME_VFS_OK;