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 if (RarParse(s->p_source, &count, &files) || count <= 0) {
96 msg_Err(s, "Invalid or unsupported RAR archive");
101 /* TODO use xspf to have node for directories
102 * Reusing WriteXSPF from the zip access is probably a good idea
103 * (becareful about '\' and '/'.
106 char *encoded = encode_URI_component(s->psz_path);
107 if (!encoded || asprintf(&base, "rar://%s", encoded) < 0)
111 char *data = strdup("#EXTM3U\n");
112 for (int i = 0; i < count; i++) {
113 rar_file_t *f = files[i];
119 data, f->name, base, f->name) >= 0) {
128 stream_t *payload = stream_MemoryNew(s, (uint8_t*)data, strlen(data), false);
136 s->pf_control = Control;
138 stream_sys_t *sys = s->p_sys = malloc(sizeof(*sys));
140 stream_Delete(payload);
143 sys->payload = payload;
146 if (asprintf(&tmp, "%s.m3u", s->psz_path) < 0) {
156 static void Close(vlc_object_t *object)
158 stream_t *s = (stream_t*)object;
159 stream_sys_t *sys = s->p_sys;
161 stream_Delete(sys->payload);