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 *****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_demux.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
* );
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", ACCESS_TEXT
,
51 add_savefile( "demuxdump-file", "stream-demux.dump", FILE_TEXT
,
52 FILE_LONGTEXT
, false )
53 add_bool( "demuxdump-append", false, APPEND_TEXT
, APPEND_LONGTEXT
,
55 set_callbacks( Open
, Close
)
56 add_shortcut( "dump" )
59 #define DUMP_BLOCKSIZE 16384
61 static int Demux( demux_t
* );
62 static int Control( demux_t
*, int,va_list );
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
->b_force
)
75 char *access
= var_InheritString( p_demux
, "demuxdump-access" );
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" );
90 msg_Err( p_demux
, "no dump file name given" );
94 sout_access_out_t
*out
= sout_AccessOutNew( p_demux
, access
, path
);
99 msg_Err( p_demux
, "cannot create output" );
103 p_demux
->p_sys
= (void *)out
;
104 p_demux
->pf_demux
= Demux
;
105 p_demux
->pf_control
= Control
;
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
) )
131 int rd
= stream_Read( p_demux
->s
, block
->p_buffer
, DUMP_BLOCKSIZE
);
134 block_Release( block
);
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" );
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
);