*****************************************************************************
* Copyright © 2008-2009 Rémi Denis-Courmont
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
#include <vlc_plugin.h>
#include <vlc_stream.h>
#include <vlc_network.h>
+#include <vlc_fs.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
static void Close (vlc_object_t *);
vlc_module_begin ()
- set_description (N_("Decompression"))
set_category (CAT_INPUT)
set_subcategory (SUBCAT_INPUT_STREAM_FILTER)
set_capability ("stream_filter", 20)
+
+ set_description (N_("LZMA decompression"))
set_callbacks (OpenXZ, Close)
add_submodule ()
+ set_description (N_("Burrows-Wheeler decompression"))
set_callbacks (OpenBzip2, Close)
/* TODO: access shortnames for stream_UrlNew() */
add_submodule ()
+ set_description (N_("gzip decompression"))
set_callbacks (OpenGzip, Close)
vlc_module_end ()
struct stream_sys_t
{
- block_t *peeked;
- uint64_t offset;
+ /* Thread data */
+ int write_fd;
+
+ /* Shared data */
+ vlc_cond_t wait;
+ vlc_mutex_t lock;
+ bool paused;
+
+ /* Caller data */
vlc_thread_t thread;
pid_t pid;
- int write_fd, read_fd;
-};
-static void cloexec (int fd)
-{
- int flags = fcntl (fd, F_GETFD);
- fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
-}
+ uint64_t offset;
+ block_t *peeked;
+
+ int read_fd;
+ bool can_pace;
+ bool can_pause;
+};
extern char **environ;
vlc_cleanup_push (free, buf);
#endif
+ vlc_mutex_lock (&p_sys->lock);
+ while (p_sys->paused) /* practically always false, but... */
+ vlc_cond_wait (&p_sys->wait, &p_sys->lock);
len = stream_Read (stream->p_source, buf, bufsize);
+ vlc_mutex_unlock (&p_sys->lock);
+
vlc_restorecancel (canc);
error = len <= 0;
case STREAM_CAN_FASTSEEK:
*(va_arg (args, bool *)) = false;
break;
+ case STREAM_CAN_PAUSE:
+ *(va_arg (args, bool *)) = p_sys->can_pause;
+ break;
+ case STREAM_CAN_CONTROL_PACE:
+ *(va_arg (args, bool *)) = p_sys->can_pace;
+ break;
case STREAM_GET_POSITION:
*(va_arg (args, uint64_t *)) = p_sys->offset;
break;
case STREAM_GET_SIZE:
*(va_arg (args, uint64_t *)) = 0;
break;
+ case STREAM_SET_PAUSE_STATE:
+ {
+ bool paused = va_arg (args, unsigned);
+
+ vlc_mutex_lock (&p_sys->lock);
+ stream_Control (stream->p_source, STREAM_SET_PAUSE_STATE, paused);
+ p_sys->paused = paused;
+ vlc_cond_signal (&p_sys->wait);
+ vlc_mutex_unlock (&p_sys->lock);
+ break;
+ }
default:
return VLC_EGENERIC;
}
stream->pf_read = Read;
stream->pf_peek = Peek;
stream->pf_control = Control;
- p_sys->peeked = NULL;
- p_sys->offset = 0;
+
+ vlc_cond_init (&p_sys->wait);
+ vlc_mutex_init (&p_sys->lock);
+ p_sys->paused = false;
p_sys->pid = -1;
+ p_sys->offset = 0;
+ p_sys->peeked = NULL;
+ stream_Control (stream->p_source, STREAM_CAN_PAUSE, &p_sys->can_pause);
+ stream_Control (stream->p_source, STREAM_CAN_CONTROL_PACE,
+ &p_sys->can_pace);
/* I am not a big fan of the pyramid style, but I cannot think of anything
* better here. There are too many failure cases. */
/* We use two pipes rather than one stream socket pair, so that we can
* use vmsplice() on Linux. */
- if (pipe (comp) == 0)
+ if (vlc_pipe (comp) == 0)
{
- cloexec (comp[1]);
p_sys->write_fd = comp[1];
int uncomp[2];
- if (pipe (uncomp) == 0)
+ if (vlc_pipe (uncomp) == 0)
{
- cloexec (uncomp[0]);
p_sys->read_fd = uncomp[0];
#if (_POSIX_SPAWN >= 0)
char *const argv[] = { (char *)path, NULL };
if (!posix_spawn_file_actions_adddup2 (&actions, comp[0], 0)
- && !posix_spawn_file_actions_addclose (&actions, comp[0])
&& !posix_spawn_file_actions_adddup2 (&actions, uncomp[1], 1)
- && !posix_spawn_file_actions_addclose (&actions, uncomp[1])
&& !posix_spawnp (&p_sys->pid, path, &actions, NULL, argv,
environ))
{
break;
case 0:
dup2 (comp[0], 0);
- close (comp[0]);
dup2 (uncomp[1], 1);
- close (uncomp[1]);
execlp (path, path, (char *)NULL);
exit (1); /* if we get, execlp() failed! */
default:
}
close (comp[0]);
if (ret != VLC_SUCCESS)
- {
close (comp[1]);
- if (p_sys->pid != -1)
- while (waitpid (p_sys->pid, &(int){ 0 }, 0) == -1);
- }
}
+
+ if (ret == VLC_SUCCESS)
+ return VLC_SUCCESS;
+
+ if (p_sys->pid != -1)
+ while (waitpid (p_sys->pid, &(int){ 0 }, 0) == -1);
+ vlc_mutex_destroy (&p_sys->lock);
+ vlc_cond_destroy (&p_sys->wait);
+ free (p_sys);
return ret;
}
if (p_sys->peeked)
block_Release (p_sys->peeked);
+ vlc_mutex_destroy (&p_sys->lock);
+ vlc_cond_destroy (&p_sys->wait);
free (p_sys);
}