contrib: cargo: use cargo/vendored-openssl if needed
[vlc.git] / modules / demux / demuxdump.c
blobab47bc69b53d33f30f2a708a31ebabc28a67fb0d
1 /*****************************************************************************
2 * demuxdump.c : Pseudo demux module for vlc (dump raw stream)
3 *****************************************************************************
4 * Copyright (C) 2001-2004 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_demux.h>
30 #include <vlc_sout.h>
32 #define ACCESS_TEXT N_("Dump module")
33 #define FILE_TEXT N_("Dump filename")
34 #define FILE_LONGTEXT N_( \
35 "Name of the file to which the raw stream will be dumped." )
36 #define APPEND_TEXT N_("Append to existing file")
37 #define APPEND_LONGTEXT N_( \
38 "If the file already exists, it will not be overwritten." )
40 static int Open( vlc_object_t * );
41 static void Close ( vlc_object_t * );
43 vlc_module_begin ()
44 set_shortname("Dump")
45 set_category( CAT_INPUT )
46 set_subcategory( SUBCAT_INPUT_DEMUX )
47 set_description( N_("File dumper") )
48 set_capability( "demux", 0 )
49 add_module("demuxdump-access", "sout access", "file",
50 ACCESS_TEXT, ACCESS_TEXT)
51 add_savefile("demuxdump-file", "stream-demux.dump",
52 FILE_TEXT, FILE_LONGTEXT)
53 add_bool( "demuxdump-append", false, APPEND_TEXT, APPEND_LONGTEXT,
54 false )
55 set_callbacks( Open, Close )
56 add_shortcut( "dump" )
57 vlc_module_end ()
59 #define DUMP_BLOCKSIZE 16384
61 static int Demux( demux_t * );
62 static int Control( demux_t *, int,va_list );
64 /**
65 * Initializes the raw dump pseudo-demuxer.
67 static int Open( vlc_object_t * p_this )
69 demux_t *p_demux = (demux_t*)p_this;
71 /* Accept only if forced */
72 if( !p_demux->obj.force )
73 return VLC_EGENERIC;
75 char *access = var_InheritString( p_demux, "demuxdump-access" );
76 if( access == NULL )
77 return VLC_EGENERIC;
79 /* --sout-file-append (defaults to false) */
80 var_Create( p_demux, "sout-file-append", VLC_VAR_BOOL );
81 if( var_InheritBool( p_demux, "demuxdump-append" ) )
82 var_SetBool( p_demux, "sout-file-append", true );
83 /* --sout-file-format (always false) */
84 var_Create( p_demux, "sout-file-format", VLC_VAR_BOOL );
86 char *path = var_InheritString( p_demux, "demuxdump-file" );
87 if( path == NULL )
89 free( access );
90 msg_Err( p_demux, "no dump file name given" );
91 return VLC_EGENERIC;
94 sout_access_out_t *out = sout_AccessOutNew( p_demux, access, path );
95 free( path );
96 free( access );
97 if( out == NULL )
99 msg_Err( p_demux, "cannot create output" );
100 return VLC_EGENERIC;
103 p_demux->p_sys = (void *)out;
104 p_demux->pf_demux = Demux;
105 p_demux->pf_control = Control;
106 return VLC_SUCCESS;
110 * Destroys the pseudo-demuxer.
112 static void Close( vlc_object_t *p_this )
114 demux_t *p_demux = (demux_t*)p_this;
115 sout_access_out_t *out = (void *)p_demux->p_sys;
117 sout_AccessOutDelete( out );
121 * Copy data from input stream to dump file.
123 static int Demux( demux_t *p_demux )
125 sout_access_out_t *out = (void *)p_demux->p_sys;
127 block_t *block = block_Alloc( DUMP_BLOCKSIZE );
128 if( unlikely(block == NULL) )
129 return -1;
131 int rd = vlc_stream_Read( p_demux->s, block->p_buffer, DUMP_BLOCKSIZE );
132 if ( rd <= 0 )
134 block_Release( block );
135 return rd;
137 block->i_buffer = rd;
139 size_t wr = sout_AccessOutWrite( out, block );
140 if( wr != (size_t)rd )
142 msg_Err( p_demux, "cannot write data" );
143 return -1;
145 return 1;
148 static int Control( demux_t *p_demux, int i_query, va_list args )
150 return demux_vaControlHelper( p_demux->s, 0, -1, 0, 1, i_query, args );