[svn r340] LiveTV is running now.
1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 08 20:57:31 2007 +0000
1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Thu Feb 08 20:57:59 2007 +0000
1.3 @@ -60,6 +60,8 @@
1.4
1.5 GByteArray *buffer;
1.6 gsize buffer_remain;
1.7 + gboolean is_livetv;
1.8 +
1.9 } MythtvHandle;
1.10
1.11 static GnomeVFSResult
1.12 @@ -73,12 +75,13 @@
1.13 GMythBackendInfo *backend_info;
1.14 GMythURI *gmyth_uri = NULL;
1.15 gboolean ret = TRUE;
1.16 - gboolean is_livetv = FALSE;
1.17
1.18 _GNOME_VFS_METHOD_PARAM_CHECK (method_handle != NULL);
1.19 _GNOME_VFS_METHOD_PARAM_CHECK (uri != NULL);
1.20
1.21 myth_handle = g_new0 (MythtvHandle, 1);
1.22 +
1.23 + myth_handle->is_livetv = FALSE;
1.24
1.25 if (mode & GNOME_VFS_OPEN_WRITE) {
1.26 return GNOME_VFS_ERROR_NOT_PERMITTED;
1.27 @@ -103,75 +106,86 @@
1.28 gmyth_uri = gmyth_uri_new_with_value(
1.29 gnome_vfs_unescape_string( gnome_vfs_uri_to_string( uri, GNOME_VFS_URI_HIDE_NONE ), "" ) );
1.30
1.31 - is_livetv = gmyth_uri_is_livetv( gmyth_uri );
1.32 + myth_handle->is_livetv = gmyth_uri_is_livetv( gmyth_uri );
1.33
1.34 /* Connect to the backend */
1.35 - if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.36 - myth_handle->livetv = gmyth_livetv_new ();
1.37 + if ( gmyth_uri != NULL && myth_handle->is_livetv == TRUE ) {
1.38 +
1.39 + if ( NULL == myth_handle->livetv )
1.40 + {
1.41 + myth_handle->livetv = gmyth_livetv_new ();
1.42
1.43 - myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.44 -
1.45 - g_print( "[%s] Channel name = %s", __FUNCTION__, myth_handle->channel_name );
1.46 + myth_handle->channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.47 +
1.48 + g_debug( "[%s] Channel name = %s\n", __FUNCTION__, myth_handle->channel_name );
1.49 +
1.50 + if ( myth_handle->channel_name != NULL ) {
1.51 + if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name,
1.52 + backend_info) == FALSE) {
1.53 + g_object_unref( gmyth_uri );
1.54 + ret = FALSE;
1.55 + }
1.56 + } else {
1.57 + if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
1.58 + g_object_unref( gmyth_uri );
1.59 + ret = FALSE;
1.60 + }
1.61 + }
1.62 + }
1.63 +
1.64 + if ( NULL == myth_handle->file_transfer ) {
1.65 + myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
1.66
1.67 - if ( myth_handle->channel_name != NULL ) {
1.68 - if (gmyth_livetv_channel_name_setup (myth_handle->livetv, myth_handle->channel_name,
1.69 - backend_info) == FALSE) {
1.70 - g_object_unref( gmyth_uri );
1.71 - ret = FALSE;
1.72 - }
1.73 - } else {
1.74 - if ( gmyth_livetv_setup (myth_handle->livetv, backend_info) == FALSE ) {
1.75 - g_object_unref( gmyth_uri );
1.76 - ret = FALSE;
1.77 - }
1.78 - }
1.79 -
1.80 - myth_handle->file_transfer = gmyth_livetv_create_file_transfer (myth_handle->livetv);
1.81 -
1.82 - if (NULL == myth_handle->file_transfer) {
1.83 - ret = FALSE;
1.84 - g_warning ("MythTV FileTransfer is NULL!\n");
1.85 - return GNOME_VFS_ERROR_NOT_OPEN;
1.86 - }
1.87 -
1.88 - if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ?
1.89 - gmyth_uri_get_path(myth_handle->livetv->uri) :
1.90 - myth_handle->livetv->proginfo->pathname->str ) )
1.91 - {
1.92 - g_object_unref( myth_handle->file_transfer );
1.93 - myth_handle->file_transfer = NULL;
1.94 - ret = FALSE;
1.95 - }
1.96 + if (NULL == myth_handle->file_transfer) {
1.97 + ret = FALSE;
1.98 + g_debug ("MythTV FileTransfer is NULL!\n");
1.99 + return GNOME_VFS_ERROR_NOT_OPEN;
1.100 + }
1.101 +
1.102 + if ( !gmyth_file_transfer_open( myth_handle->file_transfer, myth_handle->livetv->uri != NULL ?
1.103 + gmyth_uri_get_path(myth_handle->livetv->uri) :
1.104 + myth_handle->livetv->proginfo->pathname->str ) )
1.105 + {
1.106 + g_debug ("Couldn't open MythTV FileTransfer is NULL!\n");
1.107 + g_object_unref( myth_handle->file_transfer );
1.108 + myth_handle->file_transfer = NULL;
1.109 + ret = FALSE;
1.110 + }
1.111 + } /* if - FileTransfer is NULL, or not */
1.112
1.113 } else {
1.114 +
1.115 + if (NULL == myth_handle->file_transfer ) {
1.116
1.117 - myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
1.118 -
1.119 - /* Verifies if the file exists */
1.120 - if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
1.121 - g_object_unref (backend_info);
1.122 - ret = FALSE;
1.123 - }
1.124 -
1.125 - /* sets the Playback monitor connection */
1.126 - ret = gmyth_file_transfer_open ( myth_handle->file_transfer,
1.127 - gmyth_uri_get_path (gmyth_uri) );
1.128 + myth_handle->file_transfer = gmyth_file_transfer_new (backend_info);
1.129 +
1.130 + /* Verifies if the file exists */
1.131 + if (!gmyth_util_file_exists (backend_info, gmyth_uri_get_path (gmyth_uri))) {
1.132 + g_object_unref (backend_info);
1.133 + ret = FALSE;
1.134 + }
1.135 +
1.136 + /* sets the Playback monitor connection */
1.137 + ret = gmyth_file_transfer_open ( myth_handle->file_transfer,
1.138 + gmyth_uri_get_path (gmyth_uri) );
1.139 +
1.140 + }
1.141
1.142 } /* if - LiveTV or not? */
1.143
1.144 if (ret == FALSE) {
1.145 - g_warning ("MythTV FileTransfer open error.\n");
1.146 + g_debug ("MythTV FileTransfer open error.\n");
1.147 return GNOME_VFS_ERROR_NOT_OPEN;
1.148 }
1.149
1.150 - g_object_unref (backend_info);
1.151 + //g_object_unref (backend_info);
1.152
1.153 //if ( gmyth_uri != NULL )
1.154 // g_object_unref( gmyth_uri );
1.155
1.156 g_return_val_if_fail (myth_handle->file_transfer != NULL, GNOME_VFS_ERROR_NOT_OPEN);
1.157
1.158 - if ( myth_handle->file_transfer->filesize < 0 && is_livetv ) {
1.159 + if ( myth_handle->file_transfer->filesize < 0 && myth_handle->is_livetv ) {
1.160 myth_handle->content_size = (GnomeVFSFileSize) 0;
1.161 myth_handle->content_size = gmyth_recorder_get_file_position( myth_handle->livetv->recorder );
1.162 } else
1.163 @@ -261,12 +275,12 @@
1.164 MythtvHandle *myth_handle = (MythtvHandle *) method_handle;
1.165
1.166 if (myth_handle->file_transfer) {
1.167 - gmyth_file_transfer_close (myth_handle->file_transfer);
1.168 - g_object_unref (myth_handle->file_transfer);
1.169 + //gmyth_file_transfer_close (myth_handle->file_transfer);
1.170 + g_object_unref (myth_handle->file_transfer);
1.171 myth_handle->file_transfer = NULL;
1.172 }
1.173
1.174 - if (myth_handle->livetv) {
1.175 + if (myth_handle->is_livetv && myth_handle->livetv != NULL) {
1.176 g_object_unref (myth_handle->livetv);
1.177 myth_handle->livetv = NULL;
1.178 }
1.179 @@ -289,11 +303,10 @@
1.180 GnomeVFSContext *context)
1.181 {
1.182 GMythFileTransfer *file_transfer = NULL;
1.183 - GMythRecorder *recorder = NULL;
1.184 - GMythTVChain *tvchain = NULL;
1.185 + //GMythRecorder *recorder = NULL;
1.186 GMythBackendInfo *backend_info = NULL;
1.187 GMythURI *gmyth_uri = NULL;
1.188 - GMythSocket *socket = NULL;
1.189 + //GMythSocket *socket = NULL;
1.190 gboolean is_livetv = FALSE;
1.191 gboolean ret = TRUE;
1.192
1.193 @@ -325,11 +338,10 @@
1.194
1.195 /* Connect to the backend */
1.196 if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.197 -
1.198 + #if 0
1.199 gboolean res = TRUE;
1.200
1.201 - /* start to get file info from LiveTV remote encoder */
1.202 -
1.203 + /* start to get file info from LiveTV remote encoder */
1.204 socket = gmyth_socket_new ();
1.205
1.206 /* FIME: Implement this at gmyth_socket */
1.207 @@ -365,71 +377,17 @@
1.208 g_print ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
1.209 res = FALSE;
1.210 goto error;
1.211 - }
1.212 + }
1.213
1.214 - /* Creates livetv chain handler */
1.215 - tvchain = gmyth_tvchain_new();
1.216 - gmyth_tvchain_initialize ( tvchain, backend_info );
1.217 -
1.218 - if ( tvchain == NULL || tvchain->tvchain_id == NULL ) {
1.219 - g_print ("[%s] TVChain couldn't be initialized.\n", __FUNCTION__);
1.220 - res = FALSE;
1.221 - goto error;
1.222 - }
1.223 -
1.224 - // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.225 - res = gmyth_recorder_spawntv ( recorder,
1.226 - gmyth_tvchain_get_id(tvchain) );
1.227 - if (!res) {
1.228 - g_print ("[%s] Fail while spawn tv\n", __FUNCTION__);
1.229 - res = FALSE;
1.230 - goto error;
1.231 - }
1.232 -
1.233 - gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.234 -
1.235 - if ( res == TRUE ) {
1.236 - /* loop finished, set the max tries variable to zero again... */
1.237 - gint wait_to_transfer = 0;
1.238 -
1.239 - while ( wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS &&
1.240 - (gmyth_recorder_is_recording (recorder) == FALSE) )
1.241 - g_usleep (500);
1.242 -
1.243 - /* IS_RECORDING again, just like the MythTV backend does... */
1.244 - gmyth_recorder_is_recording (recorder);
1.245 -
1.246 - if ( channel_name != NULL )
1.247 - {
1.248 - /* Pauses remote encoder. */
1.249 - res = gmyth_recorder_pause_recording(recorder);
1.250 - if ( !res ) {
1.251 - g_print ("[%s] Fail while pausing remote encoder\n", __FUNCTION__);
1.252 - res = FALSE;
1.253 - goto error;
1.254 - }
1.255 -
1.256 - if ( gmyth_recorder_check_channel_name( recorder, channel_name ) )
1.257 - {
1.258 - if ( !gmyth_recorder_set_channel_name( recorder, channel_name ) )
1.259 - {
1.260 - g_warning( "Channel will not changes to: [%s].\n", channel_name );
1.261 - }
1.262 - }
1.263 -
1.264 - } /* if - changes the channel number */
1.265 -
1.266 - sleep( 1 );
1.267 -
1.268 - }
1.269 -
1.270 - /* DEBUG message */
1.271 + //gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.272 +
1.273 + /* DEBUG message */
1.274 GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( recorder );
1.275 - //gmyth_debug( "New ProgramInfo...\n" );
1.276 - gmyth_program_info_print( prog_info );
1.277
1.278 if ( prog_info != NULL )
1.279 {
1.280 + //gmyth_debug( "New ProgramInfo...\n" );
1.281 + gmyth_program_info_print( prog_info );
1.282
1.283 g_print( "path = %s", prog_info->pathname->str );
1.284
1.285 @@ -449,14 +407,15 @@
1.286 file_info->size = gmyth_recorder_get_file_position( recorder );
1.287 }
1.288
1.289 - if ( tvchain != NULL)
1.290 - g_object_unref (tvchain);
1.291 -
1.292 if ( recorder != NULL )
1.293 - gmyth_recorder_close (recorder);
1.294 + g_object_unref (recorder);
1.295
1.296 if ( prog_info != NULL )
1.297 g_object_unref( prog_info );
1.298 +
1.299 + #endif
1.300 + file_info->size = 0;
1.301 + file_info->name = g_strdup ( "LiveTV.nuv" );
1.302
1.303 } else {
1.304
1.305 @@ -472,8 +431,7 @@
1.306 /* sets the Playback monitor connection */
1.307 ret = gmyth_file_transfer_open ( file_transfer, gmyth_uri_get_path (gmyth_uri) );
1.308
1.309 - file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
1.310 -
1.311 + file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
1.312
1.313 } /* if - LiveTV or not? */
1.314
1.315 @@ -485,13 +443,13 @@
1.316 if ( ret == TRUE && file_transfer != NULL ) {
1.317 file_info->size = gmyth_file_transfer_get_filesize (file_transfer);
1.318 if ( file_transfer )
1.319 - gmyth_file_transfer_close (file_transfer);
1.320 + g_object_unref (file_transfer);
1.321 }
1.322 -
1.323 +
1.324 file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
1.325 file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
1.326
1.327 -error:
1.328 +//error:
1.329 if (backend_info)
1.330 g_object_unref (backend_info);
1.331