1 /*****************************************************************************
2 * ddummy.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 VLC authors and VideoLAN
7 * Authors: Samuel Hocevar <sam@zoy.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 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_codec.h>
36 #define SAVE_TEXT N_("Save raw codec data")
37 #define SAVE_LONGTEXT N_( \
38 "Save the raw codec data if you have selected/forced the dummy " \
39 "decoder in the main options." )
41 static int OpenDecoder( vlc_object_t
* );
42 static int OpenDecoderDump( vlc_object_t
* );
43 static void CloseDecoder( vlc_object_t
* );
46 set_shortname( N_("Dummy") )
47 set_description( N_("Dummy decoder") )
48 set_capability( "spu decoder", 0 )
49 set_callbacks( OpenDecoder
, CloseDecoder
)
50 set_category( CAT_INPUT
)
51 set_subcategory( SUBCAT_INPUT_SCODEC
)
52 add_bool( "dummy-save-es", false, SAVE_TEXT
, SAVE_LONGTEXT
, true )
53 add_shortcut( "dummy" )
55 add_shortcut( "dummy" )
56 set_capability( "video decoder", 0 )
57 set_callbacks( OpenDecoder
, CloseDecoder
)
59 add_shortcut( "dummy" )
60 set_capability( "audio decoder", 0 )
61 set_callbacks( OpenDecoder
, CloseDecoder
)
64 set_section( N_( "Dump decoder" ), NULL
)
65 set_description( N_("Dump decoder") )
66 set_capability( "spu decoder", -1 )
67 set_callbacks( OpenDecoderDump
, CloseDecoder
)
68 add_shortcut( "dump" )
71 set_capability( "video decoder", 0 )
72 set_callbacks( OpenDecoderDump
, CloseDecoder
)
75 set_capability( "audio decoder", 0 )
76 set_callbacks( OpenDecoderDump
, CloseDecoder
)
80 /*****************************************************************************
82 *****************************************************************************/
83 static int DecodeBlock( decoder_t
*p_dec
, block_t
*p_block
);
85 /*****************************************************************************
86 * OpenDecoder: Open the decoder
87 *****************************************************************************/
88 static int OpenDecoderCommon( vlc_object_t
*p_this
, bool b_force_dump
)
90 decoder_t
*p_dec
= (decoder_t
*)p_this
;
91 char psz_file
[10 + 3 * sizeof (p_dec
)];
93 snprintf( psz_file
, sizeof( psz_file
), "stream.%p", (void *)p_dec
);
96 b_force_dump
= var_InheritBool( p_dec
, "dummy-save-es" );
99 FILE *stream
= vlc_fopen( psz_file
, "wb" );
102 msg_Err( p_dec
, "cannot create `%s'", psz_file
);
105 msg_Dbg( p_dec
, "dumping stream to file `%s'", psz_file
);
106 p_dec
->p_sys
= (void *)stream
;
112 p_dec
->pf_decode
= DecodeBlock
;
114 es_format_Copy( &p_dec
->fmt_out
, &p_dec
->fmt_in
);
119 static int OpenDecoder( vlc_object_t
*p_this
)
121 return OpenDecoderCommon( p_this
, false );
124 static int OpenDecoderDump( vlc_object_t
*p_this
)
126 return OpenDecoderCommon( p_this
, true );
129 /****************************************************************************
130 * RunDecoder: the whole thing
131 ****************************************************************************
132 * This function must be fed with ogg packets.
133 ****************************************************************************/
134 static int DecodeBlock( decoder_t
*p_dec
, block_t
*p_block
)
136 FILE *stream
= (void *)p_dec
->p_sys
;
138 if( !p_block
) return VLCDEC_SUCCESS
;
141 && p_block
->i_buffer
> 0
142 && !(p_block
->i_flags
& (BLOCK_FLAG_CORRUPTED
)) )
144 fwrite( p_block
->p_buffer
, 1, p_block
->i_buffer
, stream
);
145 msg_Dbg( p_dec
, "dumped %zu bytes", p_block
->i_buffer
);
147 block_Release( p_block
);
149 return VLCDEC_SUCCESS
;
152 /*****************************************************************************
153 * CloseDecoder: decoder destruction
154 *****************************************************************************/
155 static void CloseDecoder( vlc_object_t
*p_this
)
157 decoder_t
*p_dec
= (decoder_t
*)p_this
;
158 FILE *stream
= (void *)p_dec
->p_sys
;