1.1 --- a/gmyth/src/gmyth_file_transfer.c Wed Apr 04 21:18:43 2007 +0100
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Wed Apr 04 21:36:07 2007 +0100
1.3 @@ -57,27 +57,9 @@
1.4
1.5 #define GMYTHTV_QUERY_HEADER "QUERY_FILETRANSFER "
1.6
1.7 -/* default values to the file transfer parameters */
1.8 -#define GMYTHTV_USER_READ_AHEAD TRUE
1.9 -#define GMYTHTV_RETRIES -1
1.10 -#define GMYTHTV_FILE_SIZE 0
1.11
1.12 -#define GMYTHTV_BUFFER_SIZE 64*1024
1.13 -
1.14 -#define GMYTHTV_VERSION 30
1.15 -
1.16 -#define GMYTHTV_TRANSFER_MAX_WAITS 700
1.17 -
1.18 -#ifdef GMYTHTV_ENABLE_DEBUG
1.19 -#define GMYTHTV_ENABLE_DEBUG 1
1.20 -#else
1.21 -#undef GMYTHTV_ENABLE_DEBUG
1.22 -#endif
1.23 -
1.24 -/* this NDEBUG is to maintain compatibility with GMyth library */
1.25 -#ifndef NDEBUG
1.26 -#define GMYTHTV_ENABLE_DEBUG 1
1.27 -#endif
1.28 +#define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) \
1.29 + (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
1.30
1.31 enum myth_sock_types {
1.32 GMYTH_PLAYBACK_TYPE = 0,
1.33 @@ -86,134 +68,135 @@
1.34 GMYTH_RINGBUFFER_TYPE
1.35 };
1.36
1.37 -#define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
1.38 -
1.39 struct _GMythFileTransferPrivate {
1.40 GMythRecorder *recorder;
1.41
1.42 gboolean do_next_program_chain;
1.43 gboolean disposed;
1.44 gboolean livetv_wait;
1.45 + gint64 offset;
1.46 + guint64 filesize;
1.47 +
1.48 + /* Myth URI structure */
1.49 + gchar *filename;
1.50 + GMythBackendInfo *backend_info;
1.51 +
1.52 + /* MythTV version number */
1.53 + gint mythtv_version;
1.54 +
1.55 + /* socket descriptors */
1.56 + GMythSocket *control_sock;
1.57 + GMythSocket *sock;
1.58 + GMutex *mutex;
1.59 + gint file_id;
1.60 };
1.61
1.62 static void gmyth_file_transfer_class_init (GMythFileTransferClass *klass);
1.63 static void gmyth_file_transfer_init (GMythFileTransfer *object);
1.64 -
1.65 -static void gmyth_file_transfer_dispose (GObject *object);
1.66 -static void gmyth_file_transfer_finalize (GObject *object);
1.67 -
1.68 -static void gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer,
1.69 - gint msg_code, gpointer livetv_recorder );
1.70 -
1.71 -static gboolean gmyth_connect_to_backend (GMythFileTransfer *transfer);
1.72 -
1.73 -void gmyth_file_transfer_close( GMythFileTransfer *transfer );
1.74 -
1.75 -static gboolean myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait );
1.76 -
1.77 -static gboolean myth_control_release_context( GMythFileTransfer *transfer );
1.78 +static void gmyth_file_transfer_dispose (GObject *object);
1.79 +static void gmyth_file_transfer_finalize (GObject *object);
1.80 +static void _file_transfer_program_info_changed(GMythFileTransfer *transfer,
1.81 + gint msg_code, gpointer livetv_recorder);
1.82 +static gboolean _connect_to_backend (GMythFileTransfer *transfer);
1.83 +static gboolean _control_acquire_context (GMythFileTransfer *transfer, gboolean do_wait);
1.84 +static gboolean _control_release_context (GMythFileTransfer *transfer);
1.85
1.86 G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, G_TYPE_OBJECT)
1.87
1.88 static void
1.89 gmyth_file_transfer_class_init (GMythFileTransferClass *klass)
1.90 {
1.91 - GObjectClass *gobject_class;
1.92 - GMythFileTransferClass *gtransfer_class;
1.93 + GObjectClass *gobject_class;
1.94 + GMythFileTransferClass *gtransfer_class;
1.95
1.96 - gobject_class = (GObjectClass *) klass;
1.97 - gtransfer_class = (GMythFileTransferClass *) gobject_class;
1.98 + gobject_class = (GObjectClass *) klass;
1.99 + gtransfer_class = (GMythFileTransferClass *) gobject_class;
1.100
1.101 - gobject_class->dispose = gmyth_file_transfer_dispose;
1.102 - gobject_class->finalize = gmyth_file_transfer_finalize;
1.103 + gobject_class->dispose = gmyth_file_transfer_dispose;
1.104 + gobject_class->finalize = gmyth_file_transfer_finalize;
1.105
1.106 - g_type_class_add_private (gobject_class, sizeof (GMythFileTransferPrivate));
1.107 + g_type_class_add_private (gobject_class, sizeof (GMythFileTransferPrivate));
1.108
1.109 - gtransfer_class->program_info_changed_handler = gmyth_file_transfer_program_info_changed;
1.110 + gtransfer_class->program_info_changed_handler = _file_transfer_program_info_changed;
1.111
1.112 gtransfer_class->program_info_changed_handler_signal_id =
1.113 - g_signal_new ( "program-info-changed",
1.114 - G_TYPE_FROM_CLASS (gtransfer_class),
1.115 - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1.116 - 0,
1.117 - NULL,
1.118 - NULL,
1.119 - gmyth_marshal_VOID__INT_POINTER,
1.120 - G_TYPE_NONE,
1.121 - 2,
1.122 - G_TYPE_INT,
1.123 - G_TYPE_POINTER );
1.124 + g_signal_new ("program-info-changed",
1.125 + G_TYPE_FROM_CLASS (gtransfer_class),
1.126 + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1.127 + 0,
1.128 + NULL,
1.129 + NULL,
1.130 + gmyth_marshal_VOID__INT_POINTER,
1.131 + G_TYPE_NONE,
1.132 + 2,
1.133 + G_TYPE_INT,
1.134 + G_TYPE_POINTER );
1.135
1.136 }
1.137
1.138 static void
1.139 gmyth_file_transfer_init (GMythFileTransfer *transfer)
1.140 {
1.141 - g_return_if_fail( transfer != NULL );
1.142 + GMythFileTransferPrivate *priv;
1.143 + g_return_if_fail( transfer != NULL );
1.144
1.145 - transfer->readposition = 0;
1.146 - transfer->filesize = GMYTHTV_FILE_SIZE;
1.147 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.148 + priv->mutex = g_mutex_new();
1.149
1.150 - transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.151 -
1.152 - transfer->priv->do_next_program_chain = FALSE;
1.153 - transfer->priv->recorder = NULL;
1.154 -
1.155 - transfer->control_sock = NULL;
1.156 - transfer->sock = NULL;
1.157 -
1.158 - transfer->mutex = g_mutex_new();
1.159 -
1.160 - g_signal_connect ( G_OBJECT (transfer), "program-info-changed",
1.161 - (GCallback)(GMYTH_FILE_TRANSFER_GET_CLASS(transfer)->program_info_changed_handler),
1.162 - NULL );
1.163 -
1.164 + g_signal_connect ( G_OBJECT (transfer), "program-info-changed",
1.165 + (GCallback)(GMYTH_FILE_TRANSFER_GET_CLASS(transfer)->program_info_changed_handler),
1.166 + NULL );
1.167 }
1.168
1.169 static void
1.170 gmyth_file_transfer_dispose (GObject *object)
1.171 {
1.172 + GMythFileTransferPrivate *priv;
1.173 GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (object);
1.174
1.175 - if (transfer->priv->disposed) {
1.176 + g_return_if_fail( transfer != NULL );
1.177 +
1.178 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.179 +
1.180 + if (priv->disposed) {
1.181 /* If dispose did already run, return. */
1.182 return;
1.183 }
1.184
1.185 /* Make sure dispose does not run twice. */
1.186 - transfer->priv->disposed = TRUE;
1.187 + priv->disposed = TRUE;
1.188
1.189 - if ( transfer->mutex != NULL ) {
1.190 - g_mutex_free( transfer->mutex );
1.191 - transfer->mutex = NULL;
1.192 - }
1.193 -
1.194 - if ( transfer->control_sock != NULL ) {
1.195 - g_object_unref( transfer->control_sock );
1.196 - transfer->control_sock = NULL;
1.197 - }
1.198 -
1.199 - if ( transfer->sock != NULL ) {
1.200 - g_object_unref( transfer->sock );
1.201 - transfer->sock = NULL;
1.202 - }
1.203 -
1.204 - if ( transfer->backend_info != NULL ) {
1.205 - g_object_unref( transfer->backend_info );
1.206 - transfer->backend_info = NULL;
1.207 - }
1.208 -
1.209 - if ( transfer->priv->recorder != NULL ) {
1.210 - g_object_unref( transfer->priv->recorder );
1.211 - transfer->priv->recorder = NULL;
1.212 - }
1.213 -
1.214 - if ( transfer->filename != NULL ) {
1.215 - g_free( transfer->filename );
1.216 - transfer->filename = NULL;
1.217 - }
1.218 + if (priv->mutex != NULL ) {
1.219 + g_mutex_free (priv->mutex );
1.220 + priv->mutex = NULL;
1.221 + }
1.222
1.223 - G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object);
1.224 + if (priv->control_sock != NULL ) {
1.225 + g_object_unref (priv->control_sock );
1.226 + priv->control_sock = NULL;
1.227 + }
1.228 +
1.229 + if (priv->sock != NULL ) {
1.230 + g_object_unref (priv->sock);
1.231 + priv->sock = NULL;
1.232 + }
1.233 +
1.234 + if (priv->backend_info != NULL ) {
1.235 + g_object_unref (priv->backend_info );
1.236 + priv->backend_info = NULL;
1.237 + }
1.238 +
1.239 + if (priv->recorder != NULL ) {
1.240 + g_object_unref (priv->recorder );
1.241 + priv->recorder = NULL;
1.242 + }
1.243 +
1.244 + if (priv->filename != NULL ) {
1.245 + g_free (priv->filename );
1.246 + priv->filename = NULL;
1.247 + }
1.248 +
1.249 + G_OBJECT_CLASS (gmyth_file_transfer_parent_class)->dispose (object);
1.250 }
1.251
1.252 static void
1.253 @@ -236,11 +219,19 @@
1.254 gmyth_file_transfer_new (GMythBackendInfo *backend_info)
1.255 {
1.256 GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
1.257 + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.258
1.259 - transfer->backend_info = backend_info;
1.260 - g_object_ref (transfer->backend_info);
1.261 + priv->backend_info = g_object_ref (backend_info);
1.262 + return transfer;
1.263 +}
1.264
1.265 - return transfer;
1.266 +
1.267 +gchar*
1.268 +gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer)
1.269 +{
1.270 + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.271 +
1.272 + return g_strdup (priv->filename);
1.273 }
1.274
1.275 /**
1.276 @@ -254,9 +245,9 @@
1.277 gmyth_file_transfer_new_with_uri (const gchar* uri_str)
1.278 {
1.279 GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER (g_object_new (GMYTH_FILE_TRANSFER_TYPE, NULL));
1.280 + GMythFileTransferPrivate *priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.281
1.282 - transfer->backend_info = gmyth_backend_info_new_with_uri (uri_str);
1.283 -
1.284 + priv->backend_info = gmyth_backend_info_new_with_uri (uri_str);
1.285 return transfer;
1.286 }
1.287
1.288 @@ -271,32 +262,34 @@
1.289 gboolean
1.290 gmyth_file_transfer_open (GMythFileTransfer *transfer, const gchar* filename)
1.291 {
1.292 - gboolean ret = TRUE;
1.293 + gboolean ret = TRUE;
1.294 + GMythFileTransferPrivate *priv;
1.295
1.296 - g_return_val_if_fail (transfer != NULL, FALSE);
1.297 - g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
1.298 + g_return_val_if_fail (transfer != NULL, FALSE);
1.299 + g_return_val_if_fail (filename != NULL && strlen(filename) > 0, FALSE);
1.300 +
1.301 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.302 +
1.303 + if (priv->filename != NULL)
1.304 + {
1.305 + gmyth_file_transfer_close (transfer);
1.306 + }
1.307 +
1.308 + priv->filename = g_strdup( filename );
1.309 +
1.310 + /* configure the control socket */
1.311 + if (priv->control_sock == NULL) {
1.312 + if (!_connect_to_backend (transfer)) {
1.313 + gmyth_debug ("Connection to backend failed (Control Socket).\n");
1.314 + ret = FALSE;
1.315 + }
1.316 + } else {
1.317 + gmyth_debug("Remote transfer control socket already created.\n");
1.318 + }
1.319
1.320 - if (transfer->filename != NULL)
1.321 - {
1.322 - g_free (transfer->filename);
1.323 - transfer->filename = NULL;
1.324 - }
1.325 + gmyth_debug ("Got file with size = %lld.\n", priv->filesize);
1.326
1.327 - transfer->filename = g_strdup( filename );
1.328 -
1.329 - /* configure the control socket */
1.330 - if (transfer->control_sock == NULL) {
1.331 - if (!gmyth_connect_to_backend (transfer)) {
1.332 - gmyth_debug ("Connection to backend failed (Control Socket).\n");
1.333 - ret = FALSE;
1.334 - }
1.335 - } else {
1.336 - gmyth_debug("Remote transfer control socket already created.\n");
1.337 - }
1.338 -
1.339 - gmyth_debug ("Got file with size = %lld.\n", transfer->filesize);
1.340 -
1.341 - return ret;
1.342 + return ret;
1.343 }
1.344
1.345 /**
1.346 @@ -307,103 +300,91 @@
1.347 * @return <code>true</code>, if the connection had been configured successfully.
1.348 */
1.349 static gboolean
1.350 -gmyth_connect_to_backend (GMythFileTransfer *transfer)
1.351 +_connect_to_backend (GMythFileTransfer *transfer)
1.352 {
1.353 - GString *base_str = NULL;
1.354 - GString *hostname = NULL;
1.355 - GMythStringList *strlist = NULL;
1.356 - gboolean ret = TRUE;
1.357 + GString *base_str = NULL;
1.358 + GString *hostname = NULL;
1.359 + GMythStringList *strlist = NULL;
1.360 + gboolean ret = TRUE;
1.361 + GMythFileTransferPrivate *priv;
1.362
1.363 - g_return_val_if_fail (transfer != NULL, FALSE );
1.364 + g_return_val_if_fail (transfer != NULL, FALSE );
1.365 +
1.366 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.367 + _control_acquire_context (transfer, TRUE);
1.368 +
1.369 +
1.370 + /* Creates the control socket */
1.371 +
1.372 + if (priv->control_sock != NULL) {
1.373 + g_object_unref (priv->control_sock);
1.374 + priv->control_sock = NULL;
1.375 + }
1.376 +
1.377 + base_str = g_string_new ("");
1.378
1.379 - myth_control_acquire_context( transfer, TRUE );
1.380 + priv->control_sock = gmyth_socket_new();
1.381 + // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version
1.382 + if (!gmyth_socket_connect_to_backend (priv->control_sock,
1.383 + priv->backend_info->hostname, priv->backend_info->port, TRUE)) {
1.384 +
1.385 + g_object_unref (priv->control_sock);
1.386 + priv->control_sock = NULL;
1.387 + return FALSE;
1.388 + }
1.389 +
1.390 + /* Creates the data socket */
1.391 + if (priv->sock != NULL) {
1.392 + g_object_unref (priv->sock);
1.393 + priv->sock = NULL;
1.394 + }
1.395
1.396 - base_str = g_string_new ("");
1.397 + priv->sock = gmyth_socket_new ();
1.398 + gmyth_socket_connect (priv->sock, priv->backend_info->hostname, priv->backend_info->port);
1.399 + gmyth_debug ("Connecting file transfer... (%s, %d)", priv->backend_info->hostname, priv->backend_info->port);
1.400 +
1.401 + strlist = gmyth_string_list_new();
1.402 + hostname = gmyth_socket_get_local_hostname();
1.403 + gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, priv->control_sock->mythtv_version );
1.404 + if (priv->control_sock->mythtv_version > 26 )
1.405 + g_string_printf (base_str, "ANN FileTransfer %s 1 -1", hostname->str);
1.406 + else
1.407 + g_string_printf (base_str, "ANN FileTransfer %s", hostname->str);
1.408 +
1.409 + gmyth_string_list_append_string (strlist, base_str );
1.410 + gmyth_string_list_append_char_array (strlist, priv->filename);
1.411 +
1.412 + gmyth_socket_write_stringlist (priv->sock, strlist );
1.413 + gmyth_socket_read_stringlist (priv->sock, strlist );
1.414 +
1.415 + /* file identification used in future file transfer requests to backend */
1.416 + priv->file_id = gmyth_string_list_get_int (strlist, 1);
1.417 +
1.418 + /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
1.419 + priv->filesize = gmyth_util_decode_long_long (strlist, 2);
1.420 +
1.421 + gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
1.422 + transfer->file_id, transfer->priv->filesize );
1.423 +
1.424 + if (priv->filesize < 0 ) {
1.425 + gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, priv->filesize);
1.426 + g_object_unref (priv->sock);
1.427 + priv->sock = NULL;
1.428 + ret = FALSE;
1.429 + }
1.430 +
1.431 + _control_release_context( transfer );
1.432
1.433 - /* Creates the control socket */
1.434 + if (strlist != NULL)
1.435 + g_object_unref (strlist);
1.436
1.437 - if (transfer->control_sock != NULL) {
1.438 - g_object_unref (transfer->control_sock);
1.439 - transfer->control_sock = NULL;
1.440 - }
1.441 -
1.442 - if ( NULL == transfer->control_sock )
1.443 - {
1.444 - transfer->control_sock = gmyth_socket_new();
1.445 + if (base_str != NULL)
1.446 + g_string_free (base_str, TRUE);
1.447 +
1.448 + if (hostname != NULL )
1.449 + g_string_free (hostname, TRUE);
1.450
1.451 - // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version
1.452 - if (!gmyth_socket_connect_to_backend (transfer->control_sock,
1.453 - transfer->backend_info->hostname, transfer->backend_info->port, TRUE)) {
1.454 -
1.455 - g_object_unref (transfer->control_sock);
1.456 - transfer->control_sock = NULL;
1.457 - return FALSE;
1.458 - }
1.459 -
1.460 - }
1.461 -
1.462 - /* Creates the data socket */
1.463 - if (transfer->sock != NULL) {
1.464 - g_object_unref (transfer->sock);
1.465 - transfer->sock = NULL;
1.466 - }
1.467 -
1.468 - //if ( NULL == transfer->sock ) {
1.469 - transfer->sock = gmyth_socket_new ();
1.470 - gmyth_socket_connect (transfer->sock, transfer->backend_info->hostname, transfer->backend_info->port);
1.471 - gmyth_debug("Connecting file transfer... (%s, %d)", transfer->backend_info->hostname, transfer->backend_info->port);
1.472 - //}
1.473 -
1.474 - if ( transfer->control_sock != NULL )
1.475 - {
1.476 -
1.477 - strlist = gmyth_string_list_new();
1.478 - hostname = gmyth_socket_get_local_hostname();
1.479 - gmyth_debug( "[%s] MythTV version (from backend) = %d.\n", __FUNCTION__, transfer->control_sock->mythtv_version );
1.480 - if ( transfer->control_sock->mythtv_version > 26 )
1.481 - g_string_printf( base_str, "ANN FileTransfer %s 1 -1", hostname->str);
1.482 - else
1.483 - g_string_printf( base_str, "ANN FileTransfer %s", hostname->str);
1.484 -
1.485 - gmyth_string_list_append_string (strlist, base_str );
1.486 - gmyth_string_list_append_char_array (strlist, transfer->filename);
1.487 -
1.488 - gmyth_socket_write_stringlist (transfer->sock, strlist );
1.489 - gmyth_socket_read_stringlist (transfer->sock, strlist );
1.490 -
1.491 - /* file identification used in future file transfer requests to backend */
1.492 - transfer->file_id = gmyth_string_list_get_int( strlist, 1 );
1.493 -
1.494 - /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
1.495 - transfer->filesize = gmyth_util_decode_long_long( strlist, 2 );
1.496 -
1.497 - gmyth_debug ( "[%s] ***** Received: recordernum = %d, filesize = %" G_GUINT64_FORMAT "\n", __FUNCTION__,
1.498 - transfer->file_id, transfer->filesize );
1.499 -
1.500 - if (transfer->filesize < 0 ) {
1.501 - gmyth_debug ( "[%s] Got filesize equals to %llu is lesser than 0 [invalid stream file]\n", __FUNCTION__, transfer->filesize );
1.502 - g_object_unref (transfer->sock);
1.503 - transfer->sock = NULL;
1.504 - ret = FALSE;
1.505 - goto cleanup;
1.506 - }
1.507 -
1.508 - } /* if - Control Socket is not equals to NULL? */
1.509 -
1.510 -cleanup:
1.511 -
1.512 - myth_control_release_context( transfer );
1.513 -
1.514 - if ( strlist != NULL )
1.515 - g_object_unref( strlist );
1.516 -
1.517 - if ( base_str != NULL )
1.518 - g_string_free (base_str, TRUE);
1.519 -
1.520 - if ( hostname != NULL )
1.521 - g_string_free (hostname, TRUE);
1.522 -
1.523 - return ret;
1.524 + return ret;
1.525 }
1.526
1.527 /**
1.528 @@ -418,18 +399,12 @@
1.529 gmyth_file_transfer_emit_program_info_changed_signal ( GMythFileTransfer *transfer, gint msg_code,
1.530 gpointer live_tv_recorder )
1.531 {
1.532 - /*
1.533 - g_signal_emit_by_name ( G_OBJECT(transfer),
1.534 - "program-info-changed",
1.535 - msg_code, live_tv );
1.536 - */
1.537 -
1.538 gmyth_debug( "Calling signal handler... [FILE_TRANSFER]" );
1.539
1.540 g_signal_emit ( transfer,
1.541 GMYTH_FILE_TRANSFER_GET_CLASS (transfer)->program_info_changed_handler_signal_id,
1.542 0, /* details */
1.543 - msg_code, live_tv_recorder );
1.544 + msg_code, live_tv_recorder);
1.545
1.546 }
1.547
1.548 @@ -444,29 +419,33 @@
1.549 gmyth_file_transfer_is_open (GMythFileTransfer *transfer)
1.550 {
1.551 GMythStringList *strlist;
1.552 + GMythFileTransferPrivate *priv;
1.553 GString *query;
1.554
1.555 - g_return_val_if_fail (transfer->control_sock != NULL, FALSE);
1.556 - g_return_val_if_fail (transfer->sock != NULL, FALSE);
1.557 -
1.558 - myth_control_acquire_context( transfer, TRUE );
1.559 + g_return_val_if_fail (transfer != NULL, FALSE);
1.560 +
1.561 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.562 + g_return_val_if_fail (priv->control_sock != NULL, FALSE);
1.563 + g_return_val_if_fail (priv->sock != NULL, FALSE);
1.564 +
1.565 + _control_acquire_context (transfer, TRUE);
1.566
1.567 strlist = gmyth_string_list_new();
1.568 query = g_string_new (GMYTHTV_QUERY_HEADER);
1.569 - g_string_append_printf (query, "%d", transfer->file_id );
1.570 + g_string_append_printf (query, "%d", priv->file_id );
1.571
1.572 gmyth_string_list_append_string (strlist, query );
1.573 - gmyth_string_list_append_char_array( strlist, "IS_OPEN" );
1.574 + gmyth_string_list_append_char_array (strlist, "IS_OPEN");
1.575
1.576 - gmyth_socket_write_stringlist( transfer->control_sock, strlist );
1.577 - gmyth_socket_read_stringlist( transfer->control_sock, strlist );
1.578 + gmyth_socket_write_stringlist (priv->control_sock, strlist );
1.579 + gmyth_socket_read_stringlist (priv->control_sock, strlist );
1.580
1.581 - myth_control_release_context( transfer );
1.582 + _control_release_context (transfer);
1.583
1.584 g_string_free (query, TRUE);
1.585 g_object_unref (strlist);
1.586
1.587 - return ( strlist != NULL && gmyth_string_list_get_int( strlist, 0 ) == 1 );
1.588 + return (strlist != NULL && gmyth_string_list_get_int (strlist, 0) == 1);
1.589 }
1.590
1.591 /**
1.592 @@ -475,42 +454,52 @@
1.593 * @param transfer The actual File Transfer instance.
1.594 */
1.595 void
1.596 -gmyth_file_transfer_close( GMythFileTransfer *transfer )
1.597 +gmyth_file_transfer_close (GMythFileTransfer *transfer )
1.598 {
1.599 - GMythStringList *strlist;
1.600 - GString *query;
1.601 + GMythStringList *strlist;
1.602 + GMythFileTransferPrivate *priv;
1.603 + GString *query;
1.604
1.605 - g_return_if_fail (transfer->control_sock != NULL);
1.606 -
1.607 - myth_control_acquire_context( transfer, TRUE );
1.608 + g_return_val_if_fail (transfer != NULL, FALSE);
1.609
1.610 - strlist = gmyth_string_list_new( );
1.611 - query = g_string_new (GMYTHTV_QUERY_HEADER);
1.612 - g_string_append_printf( query, "%d", transfer->file_id);
1.613 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.614
1.615 - gmyth_string_list_append_string( strlist, query );
1.616 - gmyth_string_list_append_char_array( strlist, "DONE" );
1.617 + if (priv->control_sock == NULL)
1.618 + return;
1.619
1.620 - if ( gmyth_socket_sendreceive_stringlist(transfer->control_sock, strlist) <= 0 ) {
1.621 - // fixme: time out???
1.622 - gmyth_debug ( "Remote file timeout.\n" );
1.623 - }
1.624 + _control_acquire_context (transfer, TRUE);
1.625
1.626 - g_string_free (query, TRUE);
1.627 - g_object_unref (strlist);
1.628 + strlist = gmyth_string_list_new ();
1.629 + query = g_string_new (GMYTHTV_QUERY_HEADER);
1.630 + g_string_append_printf (query, "%d", priv->file_id);
1.631
1.632 - if (transfer->sock) {
1.633 - g_object_unref( transfer->sock );
1.634 - transfer->sock = NULL;
1.635 - }
1.636 + gmyth_string_list_append_string (strlist, query);
1.637 + gmyth_string_list_append_char_array (strlist, "DONE");
1.638
1.639 - if (transfer->control_sock) {
1.640 - g_object_unref( transfer->control_sock );
1.641 - transfer->control_sock = NULL;
1.642 - }
1.643 + if (gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist) <= 0 ) {
1.644 + // fixme: time out???
1.645 + gmyth_debug ( "Remote file timeout.\n" );
1.646 + }
1.647
1.648 - myth_control_release_context( transfer );
1.649 + g_string_free (query, TRUE);
1.650 + g_object_unref (strlist);
1.651
1.652 + if (priv->sock) {
1.653 + g_object_unref (priv->sock );
1.654 + priv->sock = NULL;
1.655 + }
1.656 +
1.657 + if (priv->control_sock) {
1.658 + g_object_unref (priv->control_sock );
1.659 + priv->control_sock = NULL;
1.660 + }
1.661 +
1.662 + if (priv->filename) {
1.663 + g_free (priv->filename);
1.664 + priv->filename = NULL;
1.665 + }
1.666 +
1.667 + _control_release_context (transfer);
1.668 }
1.669
1.670 /**
1.671 @@ -523,44 +512,48 @@
1.672 * @return The actual position on the remote file (after seek has been done).
1.673 */
1.674 gint64
1.675 -gmyth_file_transfer_seek(GMythFileTransfer *transfer, guint64 pos, gint whence)
1.676 +gmyth_file_transfer_seek (GMythFileTransfer *transfer, guint64 pos, gint whence)
1.677 {
1.678 - GMythStringList *strlist = gmyth_string_list_new();
1.679 - GString *query;
1.680 + GMythStringList *strlist = gmyth_string_list_new();
1.681 + GMythFileTransferPrivate *priv;
1.682 + GString *query;
1.683
1.684 - g_return_val_if_fail (transfer->sock != NULL, -1);
1.685 - g_return_val_if_fail (transfer->control_sock != NULL, -1);
1.686 + g_return_val_if_fail (transfer != NULL, FALSE);
1.687 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.688
1.689 - strlist = gmyth_string_list_new();
1.690 - query = g_string_new (GMYTHTV_QUERY_HEADER);
1.691 - g_string_append_printf (query, "%d", transfer->file_id);
1.692 -
1.693 - /* myth_control_acquire_context( transfer, TRUE ); */
1.694 + g_return_val_if_fail (priv->sock != NULL, -1);
1.695 + g_return_val_if_fail (priv->control_sock != NULL, -1);
1.696
1.697 - gmyth_string_list_append_string( strlist, query );
1.698 - gmyth_string_list_append_char_array( strlist, "SEEK" );
1.699 - gmyth_string_list_append_uint64( strlist, pos );
1.700 -
1.701 - gmyth_string_list_append_int( strlist, whence );
1.702 + strlist = gmyth_string_list_new();
1.703 + query = g_string_new (GMYTHTV_QUERY_HEADER);
1.704 + g_string_append_printf (query, "%d", priv->file_id);
1.705
1.706 - if (pos > 0 )
1.707 - gmyth_string_list_append_uint64( strlist, pos );
1.708 - else
1.709 - gmyth_string_list_append_uint64( strlist, transfer->readposition );
1.710 -
1.711 - gmyth_socket_sendreceive_stringlist( transfer->control_sock, strlist );
1.712 + /* myth_control_acquire_context( transfer, TRUE ); */
1.713
1.714 - gint64 retval = gmyth_string_list_get_int64(strlist, 0);
1.715 - transfer->readposition = retval;
1.716 - gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n",
1.717 - __FUNCTION__, retval );
1.718 + gmyth_string_list_append_string (strlist, query);
1.719 + gmyth_string_list_append_char_array (strlist, "SEEK");
1.720 + gmyth_string_list_append_uint64 (strlist, pos);
1.721
1.722 - g_object_unref (strlist);
1.723 - g_string_free (query, TRUE);
1.724 + gmyth_string_list_append_int (strlist, whence);
1.725
1.726 - /* myth_control_release_context( transfer ); */
1.727 + if (pos > 0 )
1.728 + gmyth_string_list_append_uint64 (strlist, pos);
1.729 + else
1.730 + gmyth_string_list_append_uint64 (strlist, priv->offset);
1.731
1.732 - return retval;
1.733 + gmyth_socket_sendreceive_stringlist (priv->control_sock, strlist);
1.734 +
1.735 + gint64 retval = gmyth_string_list_get_int64 (strlist, 0);
1.736 + priv->offset = retval;
1.737 + gmyth_debug ( "[%s] got reading position pointer from the streaming = %lld\n",
1.738 + __FUNCTION__, retval );
1.739 +
1.740 + g_object_unref (strlist);
1.741 + g_string_free (query, TRUE);
1.742 +
1.743 + /* myth_control_release_context( transfer ); */
1.744 +
1.745 + return retval;
1.746 }
1.747
1.748 /**
1.749 @@ -572,31 +565,16 @@
1.750 * @return <code>true</code>, if the acquire had been got.
1.751 */
1.752 static gboolean
1.753 -myth_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait )
1.754 +_control_acquire_context( GMythFileTransfer *transfer, gboolean do_wait )
1.755 {
1.756 gboolean ret = TRUE;
1.757 - //guint max_iter = 50;
1.758 -
1.759 - g_mutex_lock( transfer->mutex );
1.760 -
1.761 - //while ( !has_io_access )
1.762 - // g_cond_wait( io_watcher_cond, mutex );
1.763 -
1.764 - //has_io_access = FALSE;
1.765 -
1.766 - //myth_control_acquire_context (FALSE);
1.767 -
1.768 - /*
1.769 - if ( do_wait ) {
1.770 - while ( --max_iter > 0 && !g_main_context_wait( io_watcher_context, io_watcher_cond, mutex ) )
1.771 - ret = FALSE;
1.772 - } else if ( !g_main_context_acquire( io_watcher_context ) )
1.773 - ret = FALSE;
1.774 - */
1.775 -
1.776 - //g_static_mutex_lock( &st_mutex );
1.777 -
1.778 - return ret;
1.779 + GMythFileTransferPrivate *priv;
1.780 +
1.781 + g_return_val_if_fail (transfer != NULL, FALSE);
1.782 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.783 +
1.784 + g_mutex_lock (priv->mutex);
1.785 + return ret;
1.786 }
1.787
1.788 /**
1.789 @@ -607,23 +585,17 @@
1.790 * @return <code>true</code>, if the socket read/write permissions had been releaseds.
1.791 */
1.792 static gboolean
1.793 -myth_control_release_context( GMythFileTransfer *transfer )
1.794 +_control_release_context( GMythFileTransfer *transfer )
1.795 {
1.796 gboolean ret = TRUE;
1.797 -
1.798 - //g_static_mutex_unlock( &st_mutex );
1.799 -
1.800 - //g_main_context_release( io_watcher_context );
1.801 -
1.802 - //g_main_context_wakeup( io_watcher_context );
1.803 -
1.804 - //has_io_access = TRUE;
1.805 + GMythFileTransferPrivate *priv;
1.806
1.807 - //g_cond_broadcast( io_watcher_cond );
1.808 -
1.809 - g_mutex_unlock( transfer->mutex );
1.810 + g_return_val_if_fail (transfer != NULL, FALSE);
1.811 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.812 +
1.813 + g_mutex_unlock (priv->mutex );
1.814
1.815 - return ret;
1.816 + return ret;
1.817 }
1.818
1.819 /**
1.820 @@ -639,70 +611,74 @@
1.821 * @return The actual block size (in bytes) returned by REQUEST_BLOCK message,
1.822 * or the error code.
1.823 */
1.824 -gint64
1.825 +GMythFileTransferReadResult
1.826 gmyth_file_transfer_read(GMythFileTransfer *transfer, GByteArray *data, gint size, gboolean read_unlimited)
1.827 {
1.828 - gint bytes_sent = 0;
1.829 - gsize bytes_read = 0;
1.830 - gint64 total_read = 0;
1.831 -
1.832 - GError *error = NULL;
1.833 -
1.834 - GIOChannel *io_channel;
1.835 - GIOChannel *io_channel_control;
1.836 + gint bytes_sent = 0;
1.837 + gsize bytes_read = 0;
1.838 + gint64 total_read = 0;
1.839 + GMythFileTransferReadResult retval = GMYTH_FILE_TRANSFER_READ_OK;
1.840 + GMythFileTransferPrivate *priv;
1.841
1.842 - GIOCondition io_cond;
1.843 - GIOCondition io_cond_control;
1.844 - GIOStatus io_status = G_IO_STATUS_NORMAL;
1.845 - GIOStatus io_status_control = G_IO_STATUS_NORMAL;
1.846 -
1.847 - gboolean ret = TRUE;
1.848 + GError *error = NULL;
1.849
1.850 - GString *query;
1.851 -
1.852 - g_return_val_if_fail ( data != NULL, -2 );
1.853 + GIOChannel *io_channel;
1.854 + GIOChannel *io_channel_control;
1.855
1.856 - io_channel = transfer->sock->sd_io_ch;
1.857 - io_channel_control = transfer->control_sock->sd_io_ch;
1.858 + GIOCondition io_cond;
1.859 + GIOCondition io_cond_control;
1.860 + GIOStatus io_status = G_IO_STATUS_NORMAL;
1.861 + GIOStatus io_status_control = G_IO_STATUS_NORMAL;
1.862
1.863 - io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
1.864 - if ( io_status == G_IO_STATUS_NORMAL )
1.865 - gmyth_debug ( "[%s] Setting encoding to binary data socket).\n", __FUNCTION__ );
1.866 + GMythStringList *strlist;
1.867 + gboolean ret = TRUE;
1.868 + GString *query;
1.869
1.870 - io_cond = g_io_channel_get_buffer_condition( io_channel );
1.871 + g_return_val_if_fail (transfer != NULL, FALSE);
1.872 + g_return_val_if_fail (data != NULL, GMYTH_FILE_TRANSFER_READ_ERROR);
1.873
1.874 - io_cond_control = g_io_channel_get_buffer_condition( io_channel );
1.875 - if ( transfer->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) {
1.876 - g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" );
1.877 - return -1;
1.878 - }
1.879 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.880
1.881 - if ( transfer->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) {
1.882 - g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" );
1.883 - return -1;
1.884 - }
1.885 + strlist = gmyth_string_list_new();
1.886
1.887 - query = g_string_new (GMYTHTV_QUERY_HEADER);
1.888 - g_string_append_printf ( query, "%d", transfer->file_id );
1.889 - gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
1.890 -
1.891 - //myth_control_acquire_context( transfer, TRUE );
1.892 -
1.893 - while (total_read != size) {
1.894 - GMythStringList *strlist = gmyth_string_list_new();
1.895 + io_channel = priv->sock->sd_io_ch;
1.896 + io_channel_control = priv->control_sock->sd_io_ch;
1.897
1.898 - gmyth_string_list_append_char_array( strlist, query->str );
1.899 - gmyth_string_list_append_char_array( strlist, "REQUEST_BLOCK" );
1.900 - gmyth_string_list_append_int( strlist, size - total_read);
1.901 + io_status = g_io_channel_set_encoding( io_channel, NULL, &error );
1.902 + if ( io_status == G_IO_STATUS_NORMAL )
1.903 + gmyth_debug ( "[%s] Setting encoding to binary data socket).\n", __FUNCTION__ );
1.904 +
1.905 + io_cond = g_io_channel_get_buffer_condition( io_channel );
1.906 +
1.907 + io_cond_control = g_io_channel_get_buffer_condition( io_channel );
1.908 + if (priv->sock == NULL || ( io_status == G_IO_STATUS_ERROR ) ) {
1.909 + g_printerr( "gmyth_file_transfer_read(): Called with no raw socket.\n" );
1.910 + return GMYTH_FILE_TRANSFER_READ_ERROR;
1.911 + }
1.912 +
1.913 + if (priv->control_sock == NULL || ( io_status_control == G_IO_STATUS_ERROR ) ) {
1.914 + g_printerr( "gmyth_file_transfer_read(): Called with no control socket.\n" );
1.915 + return GMYTH_FILE_TRANSFER_READ_ERROR;
1.916 + }
1.917 +
1.918 + query = g_string_new (GMYTHTV_QUERY_HEADER);
1.919 + g_string_append_printf ( query, "%d", priv->file_id );
1.920 + gmyth_debug ("[%s] Transfer_query = %s\n", __FUNCTION__, query->str );
1.921 +
1.922 + _control_acquire_context (transfer, TRUE );
1.923 + //Do Read
1.924 + gmyth_string_list_append_char_array (strlist, query->str );
1.925 + gmyth_string_list_append_char_array (strlist, "REQUEST_BLOCK" );
1.926 + gmyth_string_list_append_int (strlist, size - total_read);
1.927
1.928 // Request the block to the backend
1.929 - gmyth_socket_write_stringlist (transfer->control_sock, strlist);
1.930 + gmyth_socket_write_stringlist (priv->control_sock, strlist);
1.931
1.932 // Receives the backand answer
1.933 - gmyth_socket_read_stringlist (transfer->control_sock, strlist);
1.934 + gmyth_socket_read_stringlist (priv->control_sock, strlist);
1.935
1.936 if (strlist != NULL && gmyth_string_list_length (strlist) > 0) {
1.937 - bytes_sent = gmyth_string_list_get_int (strlist, 0); // -1 on backend error
1.938 + bytes_sent = gmyth_string_list_get_int (strlist, 0); // -1 on backend error
1.939 gmyth_debug ( "[%s] got SENT buffer message = %d\n", __FUNCTION__, bytes_sent );
1.940
1.941 if (bytes_sent > 0) {
1.942 @@ -716,103 +692,96 @@
1.943 if (io_status != G_IO_STATUS_NORMAL) {
1.944 gmyth_debug ("Error on io_channel");
1.945 g_free (data_buffer);
1.946 - total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
1.947 g_object_unref (strlist);
1.948 - break;
1.949 + retval = GMYTH_FILE_TRANSFER_READ_ERROR;
1.950 + goto error;
1.951 }
1.952
1.953 - total_read += bytes_read;
1.954 -
1.955 /* append new data to the increasing byte array */
1.956 data = g_byte_array_append (data, (const guint8*)data_buffer, bytes_read);
1.957 - gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", total_read);
1.958 + gmyth_debug ("Total transfer data read: %"G_GINT64_FORMAT"\n", bytes_read);
1.959 + priv->offset += bytes_read;
1.960 +
1.961 + if ((priv->filesize > 0) && (priv->offset == priv->filesize)) {
1.962 + retval = GMYTH_FILE_TRANSFER_READ_EOF;
1.963 + goto error;
1.964 + }
1.965
1.966 g_free (data_buffer);
1.967 } else if (!read_unlimited) {
1.968 - total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
1.969 g_object_unref (strlist);
1.970 strlist = NULL;
1.971 - break;
1.972 + retval = GMYTH_FILE_TRANSFER_READ_ERROR;
1.973 + goto error;
1.974 }
1.975 } else {
1.976 - /*if (!(transfer->priv != NULL && transfer->priv->recorder != NULL &&
1.977 - transfer->priv->do_next_program_chain) ) {
1.978 - */
1.979 - total_read = GMYTHTV_FILE_TRANSFER_READ_ERROR;
1.980 + retval = GMYTH_FILE_TRANSFER_READ_ERROR;
1.981 if (strlist != NULL) {
1.982 g_object_unref (strlist);
1.983 strlist = NULL;
1.984 }
1.985 - break;
1.986 }
1.987 +
1.988 if ( strlist!=NULL )
1.989 {
1.990 g_object_unref (strlist);
1.991 strlist = NULL;
1.992 }
1.993
1.994 - if ((total_read < size) && read_unlimited) {
1.995 - /* wait for more data */
1.996 - g_usleep (3 * G_USEC_PER_SEC);
1.997 - } else if (total_read < size) {
1.998 - gmyth_debug ("EOF");
1.999 - break;
1.1000 - }
1.1001 -
1.1002 - } /* while - iterates through bytes until reaches the end of stream */
1.1003 -
1.1004 - if (read_unlimited && (bytes_sent == 0)) {
1.1005 + if (read_unlimited && (bytes_sent == 0)) {
1.1006 gmyth_debug( "Trying to move to the next program chain..." );
1.1007 - transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1008 -
1.1009 - if ( transfer->priv != NULL && transfer->priv->recorder != NULL &&
1.1010 - transfer->priv->do_next_program_chain )
1.1011 + if (priv->recorder != NULL &&
1.1012 + priv->do_next_program_chain)
1.1013 {
1.1014 - total_read = GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN;
1.1015 - //g_mutex_lock( transfer->mutex );
1.1016 - //ret = gmyth_livetv_next_program_chain( transfer->priv->recorder );
1.1017 - GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info( transfer->priv->recorder );
1.1018 + retval = GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN;
1.1019 + GMythProgramInfo *prog_info = gmyth_recorder_get_current_program_info (priv->recorder);
1.1020
1.1021 - if ( prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 &&
1.1022 - g_ascii_strcasecmp( prog_info->pathname->str, transfer->filename ) != 0 )
1.1023 - ret = gmyth_file_transfer_open ( transfer, g_strrstr( prog_info->pathname->str, "/" ) );
1.1024 + if (prog_info != NULL && prog_info->pathname != NULL && strlen( prog_info->pathname->str ) > 0 &&
1.1025 + g_ascii_strcasecmp( prog_info->pathname->str, priv->filename ) != 0 )
1.1026 + ret = gmyth_file_transfer_open (transfer, g_strrstr( prog_info->pathname->str, "/" ) );
1.1027
1.1028 - if ( prog_info != NULL )
1.1029 + if (prog_info != NULL )
1.1030 g_object_unref( prog_info );
1.1031
1.1032 - //g_mutex_unlock( transfer->mutex );
1.1033 -
1.1034 if ( !ret )
1.1035 gmyth_debug( "Cannot change to the next program info!" );
1.1036 else
1.1037 gmyth_debug( "OK!!! MOVED to the next program info [%s]!",
1.1038 - transfer->filename );
1.1039 + priv->filename );
1.1040 }
1.1041
1.1042 - } /* if */
1.1043 + } /* if */
1.1044 +
1.1045 +error:
1.1046
1.1047 - //myth_control_release_context( transfer );
1.1048 - g_string_free (query, TRUE);
1.1049 + _control_release_context (transfer);
1.1050 + g_string_free (query, TRUE);
1.1051
1.1052 - if ( error != NULL ) {
1.1053 - gmyth_debug ("Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
1.1054 - error->code);
1.1055 - g_error_free (error);
1.1056 - }
1.1057 + if ( error != NULL ) {
1.1058 + gmyth_debug ("Cleaning-up ERROR: %s [msg = %s, code = %d]\n", __FUNCTION__, error->message,
1.1059 + error->code);
1.1060 + g_error_free (error);
1.1061 + }
1.1062
1.1063 - if ( total_read > 0 )
1.1064 - transfer->readposition += total_read;
1.1065 + if ( total_read > 0 )
1.1066 + priv->offset += total_read;
1.1067
1.1068 - return total_read;
1.1069 + return retval;
1.1070 }
1.1071
1.1072
1.1073 static void
1.1074 -gmyth_file_transfer_program_info_changed( GMythFileTransfer *transfer,
1.1075 - gint msg_code, gpointer livetv_recorder )
1.1076 +_file_transfer_program_info_changed( GMythFileTransfer *transfer,
1.1077 + gint msg_code, gpointer livetv_recorder )
1.1078 {
1.1079 - GMythRecorder *recorder = GMYTH_RECORDER( livetv_recorder );
1.1080 -
1.1081 + GMythRecorder *recorder;
1.1082 + GMythFileTransferPrivate *priv;
1.1083 +
1.1084 + g_return_val_if_fail (transfer != NULL, FALSE);
1.1085 +
1.1086 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.1087 +
1.1088 + recorder = GMYTH_RECORDER( livetv_recorder );
1.1089 gmyth_debug( "Program info changed! ( file transfer orig. = %p, ptr. = [%s] )", transfer,
1.1090 livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
1.1091
1.1092 @@ -821,13 +790,10 @@
1.1093 gmyth_debug( "YES, the requested program info movement on the LiveTV transfer is authentical!" );
1.1094 }
1.1095
1.1096 - transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1097 -
1.1098 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1099 g_object_ref(recorder);
1.1100 -
1.1101 - transfer->priv->recorder = recorder;
1.1102 -
1.1103 - transfer->priv->do_next_program_chain = TRUE;
1.1104 + priv->recorder = recorder;
1.1105 + priv->do_next_program_chain = TRUE;
1.1106 }
1.1107
1.1108 /**
1.1109 @@ -842,20 +808,24 @@
1.1110 gboolean
1.1111 gmyth_file_transfer_settimeout( GMythFileTransfer *transfer, gboolean fast )
1.1112 {
1.1113 -
1.1114 + GMythFileTransferPrivate *priv;
1.1115 GMythStringList *strlist = NULL;
1.1116
1.1117 - g_return_val_if_fail (transfer->sock != NULL, FALSE);
1.1118 - g_return_val_if_fail (transfer->control_sock != NULL, FALSE);
1.1119 + g_return_val_if_fail (transfer != NULL, FALSE);
1.1120 +
1.1121 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.1122 +
1.1123 + g_return_val_if_fail (priv->sock != NULL, FALSE);
1.1124 + g_return_val_if_fail (priv->control_sock != NULL, FALSE);
1.1125
1.1126 - myth_control_acquire_context( transfer, TRUE );
1.1127 + _control_acquire_context (transfer, TRUE );
1.1128
1.1129 strlist = gmyth_string_list_new();
1.1130 gmyth_string_list_append_char_array( strlist, GMYTHTV_QUERY_HEADER );
1.1131 gmyth_string_list_append_char_array( strlist, "SET_TIMEOUT" );
1.1132 gmyth_string_list_append_int( strlist, fast );
1.1133
1.1134 - gint strlist_len = gmyth_socket_sendreceive_stringlist( transfer->control_sock,
1.1135 + gint strlist_len = gmyth_socket_sendreceive_stringlist (priv->control_sock,
1.1136 strlist );
1.1137
1.1138 if ( strlist_len > 0 )
1.1139 @@ -863,7 +833,7 @@
1.1140 else
1.1141 gmyth_debug( "Timeout cannot be changed!" );
1.1142
1.1143 - myth_control_release_context( transfer );
1.1144 + _control_release_context (transfer);
1.1145
1.1146 gmyth_debug ( "%s setting timeout flag of this file transfer = %s\n",
1.1147 strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST" );
1.1148 @@ -883,6 +853,10 @@
1.1149 guint64
1.1150 gmyth_file_transfer_get_filesize (GMythFileTransfer *transfer)
1.1151 {
1.1152 + GMythFileTransferPrivate *priv;
1.1153 +
1.1154 g_return_val_if_fail (transfer != NULL, 0);
1.1155 - return transfer->filesize;
1.1156 +
1.1157 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE (transfer);
1.1158 + return priv->filesize;
1.1159 }
2.1 --- a/gmyth/src/gmyth_file_transfer.h Wed Apr 04 21:18:43 2007 +0100
2.2 +++ b/gmyth/src/gmyth_file_transfer.h Wed Apr 04 21:36:07 2007 +0100
2.3 @@ -52,13 +52,24 @@
2.4 #define IS_GMYTH_FILE_TRANSFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_FILE_TRANSFER_TYPE))
2.5 #define GMYTH_FILE_TRANSFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferClass))
2.6
2.7 -#define GMYTHTV_FILE_TRANSFER_READ_ERROR -314
2.8 -#define GMYTHTV_FILE_TRANSFER_NEXT_PROG_CHAIN -315
2.9 +typedef enum {
2.10 + GMYTH_FILE_TRANSFER_READ_OK = 0,
2.11 + GMYTH_FILE_TRANSFER_READ_NEXT_PROG_CHAIN = 1,
2.12 + GMYTH_FILE_TRANSFER_READ_ERROR = 2,
2.13 + GMYTH_FILE_TRANSFER_READ_EOF = 3
2.14 +} GMythFileTransferReadResult;
2.15 +
2.16
2.17 typedef struct _GMythFileTransfer GMythFileTransfer;
2.18 typedef struct _GMythFileTransferClass GMythFileTransferClass;
2.19 typedef struct _GMythFileTransferPrivate GMythFileTransferPrivate;
2.20
2.21 +struct _GMythFileTransfer
2.22 +{
2.23 + GObject parent;
2.24 +};
2.25 +
2.26 +
2.27 struct _GMythFileTransferClass
2.28 {
2.29 GObjectClass parent_class;
2.30 @@ -66,43 +77,21 @@
2.31 /* callbacks */
2.32 guint program_info_changed_handler_signal_id;
2.33
2.34 - /* signal default handlers */
2.35 - void (*program_info_changed_handler) ( GMythFileTransfer *transfer,
2.36 + /* signal default handlers */
2.37 + void (*program_info_changed_handler) ( GMythFileTransfer *transfer,
2.38 gint msg_code, gpointer livetv_recorder );
2.39 };
2.40
2.41 -struct _GMythFileTransfer
2.42 -{
2.43 - GObject parent;
2.44 -
2.45 - /* Myth URI structure */
2.46 - gchar *filename;
2.47 - GMythBackendInfo *backend_info;
2.48 -
2.49 - /* MythTV version number */
2.50 - gint mythtv_version;
2.51 -
2.52 - /* socket descriptors */
2.53 - GMythSocket *control_sock;
2.54 - GMythSocket *sock;
2.55 -
2.56 - GMutex *mutex;
2.57 -
2.58 - gint64 readposition;
2.59 - guint64 filesize;
2.60 - gint file_id;
2.61 -
2.62 - GMythFileTransferPrivate *priv;
2.63 -
2.64 -};
2.65
2.66 GType gmyth_file_transfer_get_type (void);
2.67 GMythFileTransfer* gmyth_file_transfer_new (GMythBackendInfo *backend_info);
2.68 +gchar* gmyth_file_transfer_get_file_name (GMythFileTransfer *transfer);
2.69 gboolean gmyth_file_transfer_open (GMythFileTransfer *transfer,
2.70 const gchar* filename);
2.71 void gmyth_file_transfer_close (GMythFileTransfer *transfer);
2.72 gboolean gmyth_file_transfer_is_open (GMythFileTransfer *transfer);
2.73 -gint64 gmyth_file_transfer_read (GMythFileTransfer *transfer,
2.74 +GMythFileTransferReadResult
2.75 + gmyth_file_transfer_read (GMythFileTransfer *transfer,
2.76 GByteArray *data,
2.77 gint size,
2.78 gboolean read_unlimited);
3.1 --- a/gmyth/src/gmyth_recorder.c Wed Apr 04 21:18:43 2007 +0100
3.2 +++ b/gmyth/src/gmyth_recorder.c Wed Apr 04 21:36:07 2007 +0100
3.3 @@ -1174,7 +1174,8 @@
3.4 * @return The framerate (double value) of the current video.
3.5 */
3.6 gdouble
3.7 -gmyth_recorder_get_framerate( GMythRecorder *recorder ) {
3.8 +gmyth_recorder_get_framerate (GMythRecorder *recorder )
3.9 +{
3.10 gdouble fr = 0.0f;
3.11 GString *query = g_string_new( GMYTHTV_RECORDER_HEADER);
3.12
3.13 @@ -1209,4 +1210,5 @@
3.14 g_string_free (query, TRUE);
3.15
3.16 return fr;
3.17 -}
3.18 \ No newline at end of file
3.19 +}
3.20 +