1 /*****************************************************************************
2 * ddummy.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 VLC authors and VideoLAN
6 * Authors: Samuel Hocevar <sam@zoy.org>
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 /*****************************************************************************
25 *****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_codec.h>
35 #define SAVE_TEXT N_("Save raw codec data")
36 #define SAVE_LONGTEXT N_( \
37 "Save the raw codec data if you have selected/forced the dummy " \
38 "decoder in the main options." )
40 static int OpenDecoder( vlc_object_t
* );
41 static int OpenDecoderDump( vlc_object_t
* );
42 static void CloseDecoder( vlc_object_t
* );
45 set_shortname( N_("Dummy") )
46 set_description( N_("Dummy decoder") )
47 set_capability( "spu decoder", 0 )
48 set_callbacks( OpenDecoder
, CloseDecoder
)
49 set_category( CAT_INPUT
)
50 set_subcategory( SUBCAT_INPUT_SCODEC
)
51 add_bool( "dummy-save-es", false, SAVE_TEXT
, SAVE_LONGTEXT
, true )
52 add_shortcut( "dummy" )
54 add_shortcut( "dummy" )
55 set_capability( "video decoder", 0 )
56 set_callbacks( OpenDecoder
, CloseDecoder
)
58 add_shortcut( "dummy" )
59 set_capability( "audio decoder", 0 )
60 set_callbacks( OpenDecoder
, CloseDecoder
)
63 set_section( N_( "Dump decoder" ), NULL
)
64 set_description( N_("Dump decoder") )
65 set_capability( "spu decoder", -1 )
66 set_callbacks( OpenDecoderDump
, CloseDecoder
)
67 add_shortcut( "dump" )
70 set_capability( "video decoder", 0 )
71 set_callbacks( OpenDecoderDump
, CloseDecoder
)
74 set_capability( "audio decoder", 0 )
75 set_callbacks( OpenDecoderDump
, CloseDecoder
)
79 /*****************************************************************************
81 *****************************************************************************/
82 static int DecodeBlock( decoder_t
*p_dec
, block_t
*p_block
);
84 /*****************************************************************************
85 * OpenDecoder: Open the decoder
86 *****************************************************************************/
87 static int OpenDecoderCommon( vlc_object_t
*p_this
, bool b_force_dump
)
89 decoder_t
*p_dec
= (decoder_t
*)p_this
;
90 char psz_file
[10 + 3 * sizeof (p_dec
)];
92 snprintf( psz_file
, sizeof( psz_file
), "stream.%p", (void *)p_dec
);
95 b_force_dump
= var_InheritBool( p_dec
, "dummy-save-es" );
98 FILE *stream
= vlc_fopen( psz_file
, "wb" );
101 msg_Err( p_dec
, "cannot create `%s'", psz_file
);
104 msg_Dbg( p_dec
, "dumping stream to file `%s'", psz_file
);
105 p_dec
->p_sys
= (void *)stream
;
111 p_dec
->pf_decode
= DecodeBlock
;
113 es_format_Copy( &p_dec
->fmt_out
, &p_dec
->fmt_in
);
118 static int OpenDecoder( vlc_object_t
*p_this
)
120 return OpenDecoderCommon( p_this
, false );
123 static int OpenDecoderDump( vlc_object_t
*p_this
)
125 return OpenDecoderCommon( p_this
, true );
128 /****************************************************************************
129 * RunDecoder: the whole thing
130 ****************************************************************************
131 * This function must be fed with ogg packets.
132 ****************************************************************************/
133 static int DecodeBlock( decoder_t
*p_dec
, block_t
*p_block
)
135 FILE *stream
= (void *)p_dec
->p_sys
;
137 if( !p_block
) return VLCDEC_SUCCESS
;
140 && p_block
->i_buffer
> 0
141 && !(p_block
->i_flags
& (BLOCK_FLAG_CORRUPTED
)) )
143 fwrite( p_block
->p_buffer
, 1, p_block
->i_buffer
, stream
);
144 msg_Dbg( p_dec
, "dumped %zu bytes", p_block
->i_buffer
);
146 block_Release( p_block
);
148 return VLCDEC_SUCCESS
;
151 /*****************************************************************************
152 * CloseDecoder: decoder destruction
153 *****************************************************************************/
154 static void CloseDecoder( vlc_object_t
*p_this
)
156 decoder_t
*p_dec
= (decoder_t
*)p_this
;
157 FILE *stream
= (void *)p_dec
->p_sys
;