player: osd: fix zoom
[vlc.git] / modules / codec / ddummy.c
blob266e636b491563b647621c81c789325771221af1
1 /*****************************************************************************
2 * ddummy.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 VLC authors and VideoLAN
5 * $Id$
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 /*****************************************************************************
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_codec.h>
34 #include <vlc_fs.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 * );
45 vlc_module_begin ()
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" )
54 add_submodule()
55 add_shortcut( "dummy" )
56 set_capability( "video decoder", 0 )
57 set_callbacks( OpenDecoder, CloseDecoder )
58 add_submodule()
59 add_shortcut( "dummy" )
60 set_capability( "audio decoder", 0 )
61 set_callbacks( OpenDecoder, CloseDecoder )
63 add_submodule ()
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" )
69 add_submodule()
70 add_shortcut( "dump")
71 set_capability( "video decoder", 0 )
72 set_callbacks( OpenDecoderDump, CloseDecoder )
73 add_submodule()
74 add_shortcut( "dump")
75 set_capability( "audio decoder", 0 )
76 set_callbacks( OpenDecoderDump, CloseDecoder )
77 vlc_module_end ()
80 /*****************************************************************************
81 * Local prototypes
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 );
95 if( !b_force_dump )
96 b_force_dump = var_InheritBool( p_dec, "dummy-save-es" );
97 if( b_force_dump )
99 FILE *stream = vlc_fopen( psz_file, "wb" );
100 if( stream == NULL )
102 msg_Err( p_dec, "cannot create `%s'", psz_file );
103 return VLC_EGENERIC;
105 msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
106 p_dec->p_sys = (void *)stream;
108 else
109 p_dec->p_sys = NULL;
111 /* Set callbacks */
112 p_dec->pf_decode = DecodeBlock;
114 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
116 return VLC_SUCCESS;
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;
140 if( stream != NULL
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;
160 if( stream != NULL )
161 fclose( stream );