[svn r334] Put all the gmyth recorder and tvchain inseide get_file_info; removed reference to LiveTV.
1.1 --- a/libgnomevfs2-mythtv/modules/mythtv-method.c Wed Feb 07 18:30:15 2007 +0000
1.2 +++ b/libgnomevfs2-mythtv/modules/mythtv-method.c Wed Feb 07 19:15:48 2007 +0000
1.3 @@ -33,6 +33,8 @@
1.4 #include <gmyth/gmyth_recorder.h>
1.5 #include <gmyth/gmyth_backendinfo.h>
1.6 #include <gmyth/gmyth_util.h>
1.7 +#include <gmyth/gmyth_remote_util.h>
1.8 +#include <gmyth/gmyth_tvchain.h>
1.9
1.10 #define GST_MYTHTV_ID_NUM 1
1.11 #define MYTHTV_VERSION_DEFAULT 30
1.12 @@ -285,9 +287,11 @@
1.13 GnomeVFSContext *context)
1.14 {
1.15 GMythFileTransfer *file_transfer = NULL;
1.16 - GMythLiveTV *livetv = NULL;
1.17 + GMythRecorder *recorder = NULL;
1.18 + GMythTVChain *tvchain = NULL;
1.19 GMythBackendInfo *backend_info = NULL;
1.20 GMythURI *gmyth_uri = NULL;
1.21 + GMythSocket *socket = NULL;
1.22 gboolean is_livetv = FALSE;
1.23 gboolean ret = TRUE;
1.24
1.25 @@ -313,42 +317,142 @@
1.26 GNOME_VFS_PERM_OTHER_READ |
1.27 GNOME_VFS_PERM_GROUP_READ;
1.28
1.29 - g_print( "gnome_vfs_uri == %s | gmyth_uri == %s.",
1.30 + g_print( "gnome_vfs_uri == %s | gmyth_uri == %s.\n",
1.31 gnome_vfs_uri_get_path (uri),
1.32 gmyth_uri_get_path (gmyth_uri) );
1.33
1.34 /* Connect to the backend */
1.35 if ( gmyth_uri != NULL && is_livetv == TRUE ) {
1.36 - livetv = gmyth_livetv_new ();
1.37 -
1.38 - gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.39 -
1.40 - if ( channel_name != NULL ) {
1.41 - if (gmyth_livetv_channel_name_setup (livetv, channel_name,
1.42 - backend_info) == FALSE) {
1.43 - g_object_unref( gmyth_uri );
1.44 - ret = FALSE;
1.45 - }
1.46 - } else {
1.47 - if ( gmyth_livetv_setup (livetv, backend_info) == FALSE ) {
1.48 - g_object_unref( gmyth_uri );
1.49 - ret = FALSE;
1.50 - }
1.51 - }
1.52 -
1.53 - g_print( "path = %s", gmyth_uri_get_path (livetv->uri) );
1.54 -
1.55 - file_transfer = gmyth_livetv_create_file_transfer (livetv);
1.56 -
1.57 - if (NULL == file_transfer) {
1.58 - ret = FALSE;
1.59 - }
1.60 - g_print( "path = %s", gmyth_uri_get_path (livetv->uri) );
1.61 -
1.62 - file_info->name = g_strdup ( gmyth_uri_get_path (livetv->uri) );
1.63 +
1.64 + gboolean res = TRUE;
1.65 +
1.66 + /* start to get file info from LiveTV remote encoder */
1.67 +
1.68 + socket = gmyth_socket_new ();
1.69 +
1.70 + /* FIME: Implement this at gmyth_socket */
1.71 + res = gmyth_socket_connect_to_backend (socket, backend_info->hostname,
1.72 + backend_info->port, TRUE);
1.73 + if (!res) {
1.74 + g_warning ("[%s] LiveTV can not connect to backend", __FUNCTION__);
1.75 + res = FALSE;
1.76 + goto error;
1.77 + }
1.78 +
1.79 + if ( gmyth_remote_util_get_free_recorder_count (socket) <= 0 ) {
1.80 + g_warning ("No free remote encoder available.");
1.81 + res = FALSE;
1.82 + goto error;
1.83 + }
1.84 +
1.85 + /* Gets the recorder num */
1.86 + recorder = remote_request_next_free_recorder (socket, -1);
1.87 + gmyth_socket_close_connection (socket);
1.88 +
1.89 + if ( recorder == NULL ) {
1.90 + g_warning ("[%s] None remote encoder available", __FUNCTION__);
1.91 + res = FALSE;
1.92 + goto error;
1.93 + }
1.94 +
1.95 + /* Init remote encoder. Opens its control socket. */
1.96 + res = gmyth_recorder_setup(recorder);
1.97 + if ( !res ) {
1.98 + g_warning ("[%s] Fail while setting remote encoder\n", __FUNCTION__);
1.99 + res = FALSE;
1.100 + goto error;
1.101 + }
1.102 +
1.103 + /* Creates livetv chain handler */
1.104 + tvchain = gmyth_tvchain_new();
1.105 + gmyth_tvchain_initialize ( tvchain, backend_info );
1.106 +
1.107 + if ( tvchain == NULL || tvchain->tvchain_id == NULL ) {
1.108 + res = FALSE;
1.109 + goto error;
1.110 + }
1.111 +
1.112 + // Spawn live tv. Uses the socket to send mythprotocol data to start livetv in the backend (remotelly)
1.113 + res = gmyth_recorder_spawntv ( recorder,
1.114 + gmyth_tvchain_get_id(tvchain) );
1.115 + if (!res) {
1.116 + g_warning ("[%s] Fail while spawn tv\n", __FUNCTION__);
1.117 + res = FALSE;
1.118 + goto error;
1.119 + }
1.120 +
1.121 + gchar* channel_name = gmyth_uri_get_channel_name( gmyth_uri );
1.122 +
1.123 + if ( res == TRUE ) {
1.124 + /* loop finished, set the max tries variable to zero again... */
1.125 + gint wait_to_transfer = 0;
1.126 +
1.127 + while (wait_to_transfer++ < MYTHTV_TRANSFER_MAX_WAITS &&
1.128 + (gmyth_recorder_is_recording (recorder) == FALSE))
1.129 + g_usleep (500);
1.130 +
1.131 + /* IS_RECORDING again, just like the MythTV backend does... */
1.132 + gmyth_recorder_is_recording (recorder);
1.133 +
1.134 + if ( channel_name != NULL )
1.135 + {
1.136 + /* Pauses remote encoder. */
1.137 + res = gmyth_recorder_pause_recording(recorder);
1.138 + if ( !res ) {
1.139 + g_warning ("[%s] Fail while pausing remote encoder\n", __FUNCTION__);
1.140 + res = FALSE;
1.141 + goto error;
1.142 + }
1.143 +
1.144 + if ( gmyth_recorder_check_channel_name( recorder, channel_name ) )
1.145 + {
1.146 + if ( gmyth_recorder_set_channel_name( recorder, channel_name ) )
1.147 + {
1.148 + g_warning( "Channel changed!!! [%s].\n", channel_name );
1.149 + }
1.150 + }
1.151 +
1.152 + } /* if - changes the channel number */
1.153 +
1.154 + sleep( 5 );
1.155 +
1.156 + }
1.157 +
1.158 + /* DEBUG message */
1.159 + GMythProgramInfo* prog_info = gmyth_recorder_get_current_program_info( recorder );
1.160 +
1.161 + if ( prog_info != NULL )
1.162 + {
1.163 +
1.164 + g_print( "path = %s", prog_info->pathname->str );
1.165 +
1.166 + file_info->name = g_strdup ( g_strrstr( prog_info->pathname->str, "/" ) );
1.167 +
1.168 + gint64 size = 0;
1.169 + size = gmyth_recorder_get_file_position( recorder );
1.170 + if( size < 0 )
1.171 + {
1.172 + //GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info ( recorder );
1.173 + file_info->size = prog_info->filesize;
1.174 + }
1.175 + else
1.176 + file_info->size = size;
1.177 +
1.178 + } else {
1.179 + file_info->size = gmyth_recorder_get_file_position( recorder );
1.180 + }
1.181 +
1.182 + if ( tvchain != NULL)
1.183 + g_object_unref (tvchain);
1.184 +
1.185 + if ( recorder != NULL )
1.186 + g_object_unref (recorder);
1.187 +
1.188 + g_object_unref( prog_info );
1.189
1.190 } else {
1.191 -
1.192 +
1.193 + /* start to get file info from remote file encoder */
1.194 file_transfer = gmyth_file_transfer_new (backend_info);
1.195
1.196 /* Verifies if the file exists */
1.197 @@ -360,7 +464,8 @@
1.198 /* sets the Playback monitor connection */
1.199 ret = gmyth_file_transfer_open ( file_transfer, gmyth_uri_get_path (gmyth_uri) );
1.200
1.201 - file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
1.202 + file_info->name = g_strdup ( gnome_vfs_uri_get_path (uri) );
1.203 +
1.204
1.205 } /* if - LiveTV or not? */
1.206
1.207 @@ -370,38 +475,7 @@
1.208 return GNOME_VFS_ERROR_NOT_OPEN;
1.209 }
1.210 */
1.211 - if ( is_livetv )
1.212 - {
1.213 - gint64 size = 0;
1.214 - if ( file_transfer->filesize < 0 )
1.215 - {
1.216 - size = gmyth_recorder_get_file_position( livetv->recorder );
1.217 - if( size < 0 ) {
1.218 - GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info ( livetv->recorder );
1.219 - size = prog_info->filesize;
1.220 -
1.221 - if ( prog_info )
1.222 - g_object_unref( prog_info );
1.223 - }
1.224 - }
1.225 - else if ( file_transfer != NULL )
1.226 - size = gmyth_file_transfer_get_filesize (file_transfer);
1.227 -
1.228 - if ( size < 0 )
1.229 - file_info->size =(GnomeVFSFileSize) - 1;
1.230 - else
1.231 - file_info->size = size;
1.232 -
1.233 - /*if ( file_transfer != NULL)
1.234 - g_object_unref (file_transfer);*/
1.235 -
1.236 - if ( livetv != NULL )
1.237 - g_object_unref (livetv);
1.238 -
1.239 - /*if ( file_transfer != NULL)
1.240 - g_object_unref (file_transfer);*/
1.241 -
1.242 - } else if ( ret == TRUE && file_transfer != NULL ) {
1.243 + if ( ret == TRUE && file_transfer != NULL ) {
1.244 file_info->size = gmyth_file_transfer_get_filesize (file_transfer);
1.245 if ( file_transfer )
1.246 g_object_unref (file_transfer);
1.247 @@ -409,7 +483,8 @@
1.248
1.249 file_info->block_count = GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
1.250 file_info->io_block_size = GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
1.251 -
1.252 +
1.253 +error:
1.254 if (backend_info)
1.255 g_object_unref (backend_info);
1.256