demux: mp4: avoid audio cuts on seek
[vlc.git] / modules / stream_filter / accesstweaks.c
blob8341cee864add19aee00872b497a9334c37fcfda
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 *);
34 static void Close(vlc_object_t *);
36 vlc_module_begin ()
37 set_shortname("accesstweaks")
38 set_category (CAT_INPUT)
39 set_subcategory (SUBCAT_INPUT_STREAM_FILTER)
40 set_capability ("stream_filter", 0)
41 /* Developers only module, no translation please */
42 set_description ("Access controls tweaking")
43 set_callbacks (Open, Close)
45 add_bool ("seek", true, "forces result of the CAN_SEEK control", NULL, false)
46 change_volatile ()
47 add_bool ("fastseek", true, "forces result of the CAN_FASTSEEK control", NULL, false)
48 change_volatile ()
49 add_shortcut("tweaks")
50 vlc_module_end ()
52 struct stream_sys_t
54 bool b_seek;
55 bool b_fastseek;
58 /**
61 static int Control( stream_t *p_stream, int i_query, va_list args )
63 stream_sys_t *p_sys = p_stream->p_sys;
65 switch( i_query )
67 case STREAM_CAN_FASTSEEK:
68 if( !p_sys->b_fastseek || !p_sys->b_seek )
70 *va_arg( args, bool* ) = false;
71 return VLC_SUCCESS;
73 break;
74 case STREAM_CAN_SEEK:
75 if( !p_sys->b_seek )
77 *va_arg( args, bool* ) = false;
78 return VLC_SUCCESS;
80 break;
82 default:
83 break;
86 return vlc_stream_vaControl( p_stream->p_source, i_query, args );
89 static ssize_t Read( stream_t *s, void *buffer, size_t i_read )
91 return vlc_stream_Read( s->p_source, buffer, i_read );
94 static int Seek( stream_t *s, uint64_t offset )
96 stream_sys_t *p_sys = s->p_sys;
98 assert( p_sys->b_seek );
99 return vlc_stream_Seek( s->p_source, offset );
102 static int Open( vlc_object_t *p_object )
104 stream_t *p_stream = (stream_t *) p_object;
106 stream_sys_t *p_sys = p_stream->p_sys = malloc( sizeof(*p_sys) );
107 if (unlikely(p_sys == NULL))
108 return VLC_ENOMEM;
110 p_sys->b_seek = var_InheritBool( p_stream, "seek" );
111 p_sys->b_fastseek = var_InheritBool( p_stream, "fastseek" );
113 p_stream->pf_read = Read;
114 p_stream->pf_seek = p_sys->b_seek ? Seek : NULL;
115 p_stream->pf_control = Control;
117 return VLC_SUCCESS;
120 static void Close ( vlc_object_t *p_object )
122 stream_t *p_stream = (stream_t *)p_object;
123 free( p_stream->p_sys );