1 /*****************************************************************************
2 * rar.c: uncompressed RAR stream filter
3 *****************************************************************************
4 * Copyright (C) 2008-2010 Laurent Aimar
7 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_stream.h>
41 /*****************************************************************************
43 *****************************************************************************/
44 static int Open (vlc_object_t *);
45 static void Close(vlc_object_t *);
48 set_category(CAT_INPUT)
49 set_subcategory(SUBCAT_INPUT_STREAM_FILTER)
50 set_description(N_("Uncompressed RAR"))
51 set_capability("stream_filter", 1)
52 set_callbacks(Open, Close)
56 /****************************************************************************
57 * Local definitions/prototypes
58 ****************************************************************************/
63 static int Read(stream_t *s, void *data, unsigned size)
65 return stream_Read(s->p_sys->payload, data, size);
68 static int Peek( stream_t *s, const uint8_t **data, unsigned size)
70 return stream_Peek(s->p_sys->payload, data, size);
73 static int Control(stream_t *s, int query, va_list args)
76 case STREAM_GET_CONTENT_TYPE: {
77 char **mime = va_arg(args, char **);
78 *mime = strdup("audio/x-mpegurl");
82 return stream_vaControl(s->p_sys->payload, query, args);
86 static int Open(vlc_object_t *object)
88 stream_t *s = (stream_t*)object;
90 if (RarProbe(s->p_source))
95 const int64_t position = stream_Tell(s->p_source);
96 if (RarParse(s->p_source, &count, &files) || count <= 0) {
97 stream_Seek(s->p_source, position);
98 msg_Err(s, "Invalid or unsupported RAR archive");
103 /* TODO use xspf to have node for directories
104 * Reusing WriteXSPF from the zip access is probably a good idea
105 * (becareful about '\' and '/'.
108 if (asprintf(&mrl, "%s://%s", s->psz_access, s->psz_path)< 0)
111 char *encoded = mrl ? encode_URI_component(mrl) : NULL;
114 if (!encoded || asprintf(&base, "rar://%s", encoded) < 0)
118 char *data = strdup("#EXTM3U\n");
119 for (int i = 0; i < count; i++) {
120 rar_file_t *f = files[i];
126 data, f->name, base, f->name) >= 0) {
135 stream_t *payload = stream_MemoryNew(s, (uint8_t*)data, strlen(data), false);
143 s->pf_control = Control;
145 stream_sys_t *sys = s->p_sys = malloc(sizeof(*sys));
147 stream_Delete(payload);
150 sys->payload = payload;
153 if (asprintf(&tmp, "%s.m3u", s->psz_path) < 0) {
163 static void Close(vlc_object_t *object)
165 stream_t *s = (stream_t*)object;
166 stream_sys_t *sys = s->p_sys;
168 stream_Delete(sys->payload);