packetizer: hevc: add poc debug
[vlc.git] / modules / stream_filter / accesstweaks.c
bloba64c8708c8f13daa8e39cb3965d4587d64c85dae
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 /*****************************************************************************
22 * Preamble
23 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <vlc_common.h>
29 #include <vlc_plugin.h>
30 #include <vlc_stream.h>
31 #include <assert.h>
33 static int Open(vlc_object_t *);
35 vlc_module_begin ()
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)
45 change_volatile ()
46 add_bool("fastseek", true, "Expose fast-seeking capability", NULL, false)
47 change_volatile ()
48 add_bool("stream-size", true, "Expose stream size if known", NULL, false)
49 change_volatile()
50 add_shortcut("tweaks")
51 vlc_module_end ()
53 struct stream_sys_t
55 bool b_seek;
56 bool b_fastseek;
57 bool b_size;
60 /**
63 static int Control( stream_t *p_stream, int i_query, va_list args )
65 stream_sys_t *p_sys = p_stream->p_sys;
67 switch( i_query )
69 case STREAM_CAN_FASTSEEK:
70 if( !p_sys->b_fastseek || !p_sys->b_seek )
72 *va_arg( args, bool* ) = false;
73 return VLC_SUCCESS;
75 break;
76 case STREAM_CAN_SEEK:
77 if( !p_sys->b_seek )
79 *va_arg( args, bool* ) = false;
80 return VLC_SUCCESS;
82 break;
83 case STREAM_GET_SIZE:
84 if (!p_sys->b_size)
85 return VLC_EGENERIC;
86 break;
87 default:
88 break;
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))
112 return VLC_ENOMEM;
114 uint64_t size;
115 bool b;
116 bool used = false;
118 p_sys->b_seek = var_InheritBool(p_stream, "seek");
119 p_sys->b_size = var_InheritBool(p_stream, "stream-size");
121 if (!p_sys->b_seek)
123 if (vlc_stream_Control(p_stream->s, STREAM_CAN_SEEK, &b) == 0)
124 used = b;
126 p_sys->b_fastseek = false;
128 else
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,
133 &b) == 0)
134 used = b;
137 if (!p_sys->b_size && vlc_stream_GetSize(p_stream->s, &size) == 0)
138 used = true;
140 if (!used) /* Nothing to do: skip this filter */
141 return VLC_EGENERIC;
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;
148 return VLC_SUCCESS;