? 1
? 4th-try.patch
Index: gstgnomevfssrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gnomevfs/gstgnomevfssrc.c,v
retrieving revision 1.95
diff -r1.95 gstgnomevfssrc.c
6a7
>  *                    2006 Stefan Kost <ensonic@users.sf.net>
77d77
< 
135c135,136
<   ARG_IRADIO_TITLE
---
>   ARG_IRADIO_TITLE,
>   ARG_TIMEOUT
224a226
>   /* FIXME : should be async handle */
229a232,236
>   g_object_class_install_property (gobject_class,
>       ARG_TIMEOUT,
>       g_param_spec_double ("timeout",
>           "timeout", "Async IO Operation timeout in seconds",
>           0.0, 300.0, 10.0, G_PARAM_READWRITE));
274a282,285
>   gnomevfssrc->timeout = 10.0; /* 10 second default timeout */
>   gnomevfssrc->async_op_pending = FALSE;
>   gnomevfssrc->async_op_mutex = g_mutex_new ();
>   gnomevfssrc->async_op_cond = g_cond_new ();
334a346,347
>   g_mutex_free (src->async_op_mutex);
> 
438a452,455
>     case ARG_TIMEOUT:
>       src->timeout = g_value_get_double (value);
>       GST_INFO ("Timeout changed to %6.3lf", src->timeout);
>       break;
462a480,482
>     case ARG_TIMEOUT:
>       g_value_set_double (value, src->timeout);
>       break;
515a536,690
> /*
>  * gnome-vfs async api helpers 
>  */
> 
> static gboolean
> gst_gnome_vfs_async_wait(GstGnomeVFSSrc * src)
> {
>   gboolean res;
>   GTimeVal timeval;
> 
>   g_get_current_time (&timeval);
>   g_time_val_add (&timeval, src->timeout * 1000000);
>   /* FIXME: the mutex is not useful (btw, it should NOT be async_op_mutex, I think) */
>   if (g_cond_timed_wait (src->async_op_cond, src->async_op_mutex, &timeval) == FALSE) {
>     gnome_vfs_async_cancel (src->handle);
>     res = FALSE;
>     GST_INFO_OBJECT (src, "Timeout occured during gnomevfs async call with %f", src->timeout);
>   } else {
>     src->async_op_pending = FALSE;
>     res = TRUE;
>   }
> 
>   return res;
> }
> 
> static void
> gst_gnome_vfs_async_cancel(GstGnomeVFSSrc * src)
> {
>   /* cancel operation if there is any */
>   if (src->async_op_pending) {
>     gnome_vfs_async_cancel (src->handle);
>     src->async_op_pending = FALSE;
>     g_mutex_unlock (src->async_op_mutex);
>   }
> }
> 
> static void
> gst_gnome_vfs_src_async_read_cb (GnomeVFSAsyncHandle *handle,
>                                  GnomeVFSResult result, gpointer buffer,
>                                  GnomeVFSFileSize bytes_requested,
>                                  GnomeVFSFileSize bytes_read,
>                                  gpointer callback_data)
> {
>   GstGnomeVFSSrc * src = GST_GNOME_VFS_SRC (callback_data);
> 
>   GST_DEBUG_OBJECT (src, "Read callback : req=%"G_GUINT64_FORMAT" / read=%"G_GUINT64_FORMAT,bytes_requested,bytes_read);
>   src->bytes_read += bytes_read;
>   src->result = result;
>   src->async_op_pending = FALSE;
>   g_cond_signal (src->async_op_cond);
> }
> 
> static GnomeVFSResult
> gst_gnome_vfs_async_read (GstGnomeVFSSrc * src, guint8 *data, guint size,
> 			  GnomeVFSFileSize *bytes_read)
> {
>   GnomeVFSResult res = GNOME_VFS_OK;
>   GnomeVFSFileSize bytes_remain = size;
> 
>   src->bytes_read = 0;
> 
>   while (bytes_remain && (res == GNOME_VFS_OK)) {
>     GST_DEBUG_OBJECT (src, "Read chunk : read=%"G_GUINT64_FORMAT" / size=%d",src->bytes_read, size);
> 
>     g_mutex_lock (src->async_op_mutex);
>     src->async_op_pending = TRUE;
>     gnome_vfs_async_read (src->handle, &data[src->bytes_read], bytes_remain,
> 			  gst_gnome_vfs_src_async_read_cb, (gpointer)src);
> 
>     /* wait for callback to be called */
>     res = gst_gnome_vfs_async_wait (src) ? src->result : GNOME_VFS_ERROR_TIMEOUT;
>     g_mutex_unlock (src->async_op_mutex);
>     bytes_remain = size - src->bytes_read;
>   }
> 
>   GST_DEBUG_OBJECT (src, "read: res=%s", gnome_vfs_result_to_string (res));
> 
>   *bytes_read = src->bytes_read;
> 
>   return(res);
> }
> 
> static void
> gst_gnome_vfs_src_async_default_cb (GnomeVFSAsyncHandle *handle,
>                                     GnomeVFSResult result,
>                                     gpointer callback_data)
> {
>   GstGnomeVFSSrc * src = GST_GNOME_VFS_SRC (callback_data);
> 
>   GST_DEBUG_OBJECT (src, "Default callback : handle=%p", handle);
>   src->result = result;
>   src->async_op_pending = FALSE;
>   g_cond_signal (src->async_op_cond);
> }
> 
> static GnomeVFSResult
> gst_gnome_vfs_async_open_uri (GstGnomeVFSSrc * src)
> {
>   GnomeVFSResult res;
> 
>   g_mutex_lock (src->async_op_mutex);
>   src->async_op_pending = TRUE;
>   gnome_vfs_async_open_uri (&src->handle, src->uri, GNOME_VFS_OPEN_READ,
>                             GNOME_VFS_PRIORITY_DEFAULT,
>                             gst_gnome_vfs_src_async_default_cb,
>                             (gpointer)src);
> 
>   /* wait for callback to be called */
>   res = gst_gnome_vfs_async_wait (src) ? src->result : GNOME_VFS_ERROR_TIMEOUT;
>   g_mutex_unlock (src->async_op_mutex);
> 
>   GST_DEBUG_OBJECT (src, "open uri: handle = %p, res=%s", src->handle,
> 		    gnome_vfs_result_to_string (res));
> 
>   return(res);
> }
> 
> static void
> gst_gnome_vfs_async_close (GstGnomeVFSSrc * src)
> {
>   gst_gnome_vfs_async_cancel (src);
> 
>   GST_DEBUG_OBJECT (src, "close uri: handle = %p", src->handle);
> 
>   g_mutex_lock (src->async_op_mutex);
>   src->async_op_pending = TRUE;
>   gnome_vfs_async_close (src->handle,
>                          gst_gnome_vfs_src_async_default_cb,
>                          (gpointer)src);
> 
>   /* wait for callback to be called */
>   gst_gnome_vfs_async_wait (src);
>   g_mutex_unlock (src->async_op_mutex);
> }
> 
> static GnomeVFSResult
> gst_gnome_vfs_seek_async (GstGnomeVFSSrc *src, GnomeVFSSeekPosition whence,
>                           GnomeVFSFileOffset offset)
> {
>   GnomeVFSResult res;
> 
>   gst_gnome_vfs_async_cancel (src);
>   g_mutex_lock (src->async_op_mutex);
>   src->async_op_pending = TRUE;
>   gnome_vfs_async_seek (src->handle, whence, offset,
> 			gst_gnome_vfs_src_async_default_cb,
> 			(gpointer)src);
> 
>   /* wait for callback to be called */
>   res = gst_gnome_vfs_async_wait (src) ? src->result : GNOME_VFS_ERROR_TIMEOUT;
>   g_mutex_unlock (src->async_op_mutex);
> 
>   return(res);  
> }
> 
526c701
<   GST_DEBUG_OBJECT (src, "sending headers\n");
---
>   GST_DEBUG_OBJECT (src, "sending headers");
636c811
<   GnomeVFSFileSize readbytes;
---
>   GnomeVFSFileSize bytes_read;
643c818
<       size);
---
> 	     size);
650c825,827
<       res = gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_START, offset);
---
>       //res = gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_START, offset);
>       res = gst_gnome_vfs_seek_async (src, GNOME_VFS_SEEK_START, offset);
>       
667c844,845
<   res = gnome_vfs_read (src->handle, data, size, &readbytes);
---
>   /* read_async ??? */
>   res = gst_gnome_vfs_async_read (src, data, size, &bytes_read);
670c848
<               && readbytes == 0)))
---
>               && bytes_read == 0)))
673c851
<   GST_BUFFER_SIZE (buf) = readbytes;
---
>   GST_BUFFER_SIZE (buf) = bytes_read;
678c856
<   src->curoffset += readbytes;
---
>   src->curoffset += bytes_read;
804,805c982,984
<     res = gnome_vfs_open_uri (&src->handle, src->uri, mode);
<     if (res != GNOME_VFS_OK)
---
> /*     res = gnome_vfs_open_uri (&src->handle, src->uri, mode); */
> /*     if (res != GNOME_VFS_OK) */
>     if ((res = gst_gnome_vfs_async_open_uri (src)) != GNOME_VFS_OK)
817c996,999
<   res = gnome_vfs_get_file_info_from_handle (src->handle, info, options);
---
> /*   TODO */
> /*   res = gnome_vfs_get_file_info_from_handle (src->handle, info, options); */
>   res = gnome_vfs_get_file_info_uri (src->uri, info, options);
> 
839,840c1021,1023
<   if (gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_CURRENT, 0)
<       == GNOME_VFS_OK) {
---
>   //if (gnome_vfs_seek (src->handle, GNOME_VFS_SEEK_CURRENT, 0)
>   if (gst_gnome_vfs_seek_async (src, GNOME_VFS_SEEK_CURRENT, 0)
>     == GNOME_VFS_OK) {
841a1025
>     GST_DEBUG_OBJECT (src, "is seekable");
843a1028
>     GST_DEBUG_OBJECT (src, "is not seekable");
845a1031
>   GST_DEBUG_OBJECT (src, "open uri still okay : handle = %p", src->handle);
886c1072,1073
<     gnome_vfs_close (src->handle);
---
>     //gnome_vfs_close (src->handle);
>     gst_gnome_vfs_async_close (src);
Index: gstgnomevfssrc.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/gnomevfs/gstgnomevfssrc.h,v
retrieving revision 1.5
diff -r1.5 gstgnomevfssrc.h
61c61,62
<   GnomeVFSHandle *handle;
---
>   //GnomeVFSHandle *handle;
>   GnomeVFSAsyncHandle *handle;
64a66
>   GnomeVFSResult result;
65a68,72
>   gboolean async_op_pending;
>   GMutex *async_op_mutex;
>   GCond *async_op_cond;
>   GnomeVFSFileSize bytes_read;
>   gdouble timeout;
