1 /*****************************************************************************
2 * accesstweaks.c Access controls tweaking stream filter
3 *****************************************************************************
4 * Copyright (C) 2015 VideoLAN Authors
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 /*****************************************************************************
23 *****************************************************************************/
28 #include <vlc_common.h>
29 #include <vlc_plugin.h>
30 #include <vlc_stream.h>
33 static int Open(vlc_object_t
*);
36 set_shortname("accesstweaks")
37 set_category (CAT_INPUT
)
38 set_subcategory (SUBCAT_INPUT_STREAM_FILTER
)
39 set_capability ("stream_filter", 1)
40 /* Developers only module, no translation please */
41 set_description ("Access controls tweaking")
42 set_callbacks(Open
, NULL
)
44 add_bool("seek", true, "Expose seeking capability", NULL
, false)
46 add_bool("fastseek", true, "Expose fast-seeking capability", NULL
, false)
48 add_bool("stream-size", true, "Expose stream size if known", NULL
, false)
50 add_shortcut("tweaks")
63 static int Control( stream_t
*p_stream
, int i_query
, va_list args
)
65 stream_sys_t
*p_sys
= p_stream
->p_sys
;
69 case STREAM_CAN_FASTSEEK
:
70 if( !p_sys
->b_fastseek
|| !p_sys
->b_seek
)
72 *va_arg( args
, bool* ) = false;
79 *va_arg( args
, bool* ) = false;
91 return vlc_stream_vaControl( p_stream
->s
, i_query
, args
);
94 static ssize_t
Read( stream_t
*s
, void *buffer
, size_t i_read
)
96 return vlc_stream_Read( s
->s
, buffer
, i_read
);
99 static int Seek( stream_t
*s
, uint64_t offset
)
101 stream_sys_t
*p_sys
= s
->p_sys
;
103 assert( p_sys
->b_seek
);
104 return vlc_stream_Seek( s
->s
, offset
);
107 static int Open( vlc_object_t
*p_object
)
109 stream_t
*p_stream
= (stream_t
*) p_object
;
110 stream_sys_t
*p_sys
= vlc_obj_malloc(p_object
, sizeof (*p_sys
));
111 if (unlikely(p_sys
== NULL
))
118 p_sys
->b_seek
= var_InheritBool(p_stream
, "seek");
119 p_sys
->b_size
= var_InheritBool(p_stream
, "stream-size");
123 if (vlc_stream_Control(p_stream
->s
, STREAM_CAN_SEEK
, &b
) == 0)
126 p_sys
->b_fastseek
= false;
130 p_sys
->b_fastseek
= var_InheritBool(p_stream
, "fastseek");
131 if (!p_sys
->b_fastseek
132 && vlc_stream_Control(p_stream
->s
, STREAM_CAN_FASTSEEK
,
137 if (!p_sys
->b_size
&& vlc_stream_GetSize(p_stream
->s
, &size
) == 0)
140 if (!used
) /* Nothing to do: skip this filter */
143 p_stream
->p_sys
= p_sys
;
144 p_stream
->pf_read
= Read
;
145 p_stream
->pf_seek
= p_sys
->b_seek
? Seek
: NULL
;
146 p_stream
->pf_control
= Control
;