httpd: Remove obsolete enum
[vlc.git] / modules / stream_filter / adf.c
blob5d3fb0a5bd5baae87d27728f70e91965b73732be
1 /*****************************************************************************
2 * adf.c ADF stream filter
3 *****************************************************************************
4 * Copyright (C) 2016 VideoLAN Authors
6 * Author: Tristan Matthews <tmatth@videolan.org>
7 * Based on record.c by: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_stream.h>
35 static int Open( vlc_object_t * );
37 vlc_module_begin()
38 set_shortname( "adf" )
39 set_category( CAT_INPUT )
40 set_subcategory( SUBCAT_INPUT_STREAM_FILTER )
41 set_capability( "stream_filter", 30 )
42 set_description( N_( "ADF stream filter" ) )
43 set_callbacks( Open, NULL )
44 vlc_module_end()
46 static int Control( stream_t *p_stream, int i_query, va_list args )
48 return vlc_stream_vaControl( p_stream->p_source, i_query, args );
51 static ssize_t Read( stream_t *s, void *buffer, size_t i_read )
53 const ssize_t i_ret = vlc_stream_Read( s->p_source, buffer, i_read );
54 if( i_ret < 1 ) return i_ret;
56 uint8_t *p_buffer = buffer;
57 static const uint8_t ADF_XOR_MASK = 34;
58 for( ssize_t i = 0; i < i_ret; ++i )
59 p_buffer[i] ^= ADF_XOR_MASK;
60 return i_ret;
63 static int Seek( stream_t *s, uint64_t offset )
65 return vlc_stream_Seek( s->p_source, offset );
68 static int Open( vlc_object_t *p_object )
70 stream_t *p_stream = (stream_t *)p_object;
72 /* Require .adf extension unless forced. */
73 if( !p_stream->obj.force )
75 if( !p_stream->psz_url )
76 return VLC_EGENERIC;
77 const char *psz_ext = strrchr( p_stream->psz_url, '.' );
78 if( !psz_ext || strncmp( psz_ext, ".adf", 4 ) )
79 return VLC_EGENERIC;
82 const uint8_t *peek;
83 if( vlc_stream_Peek( p_stream->p_source, &peek, 3 ) < 3 )
84 return VLC_EGENERIC;
86 /* Probe for XOR'd ID3 tag. */
87 if( memcmp( peek, "\x6B\x66\x11", 3 ) )
88 return VLC_EGENERIC;
90 p_stream->pf_read = Read;
91 p_stream->pf_seek = Seek;
92 p_stream->pf_control = Control;
94 return VLC_SUCCESS;