Qt: do not show open options in both normal and advanced UI
[vlc.git] / modules / codec / ddummy.c
blob42dc533f9a7f4cab485f8b27c418905917e55d36
1 /*****************************************************************************
2 * dddumy.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, 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( "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_submodule ()
56 set_section( N_( "Dump decoder" ), NULL )
57 set_description( N_("Dump decoder") )
58 set_capability( "decoder", -1 )
59 set_callbacks( OpenDecoderDump, CloseDecoder )
60 add_shortcut( "dump" )
61 vlc_module_end ()
64 /*****************************************************************************
65 * Local prototypes
66 *****************************************************************************/
67 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
69 /*****************************************************************************
70 * OpenDecoder: Open the decoder
71 *****************************************************************************/
72 static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump )
74 decoder_t *p_dec = (decoder_t*)p_this;
75 char psz_file[10 + 3 * sizeof (p_dec)];
77 snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec );
79 if( !b_force_dump )
80 b_force_dump = var_InheritBool( p_dec, "dummy-save-es" );
81 if( b_force_dump )
83 FILE *stream = vlc_fopen( psz_file, "wb" );
84 if( stream == NULL )
86 msg_Err( p_dec, "cannot create `%s'", psz_file );
87 return VLC_EGENERIC;
89 msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
90 p_dec->p_sys = (void *)stream;
92 else
93 p_dec->p_sys = NULL;
95 /* Set callbacks */
96 p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
97 DecodeBlock;
98 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
99 DecodeBlock;
100 p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **))
101 DecodeBlock;
103 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
105 return VLC_SUCCESS;
108 static int OpenDecoder( vlc_object_t *p_this )
110 return OpenDecoderCommon( p_this, false );
113 static int OpenDecoderDump( vlc_object_t *p_this )
115 return OpenDecoderCommon( p_this, true );
118 /****************************************************************************
119 * RunDecoder: the whole thing
120 ****************************************************************************
121 * This function must be fed with ogg packets.
122 ****************************************************************************/
123 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
125 FILE *stream = (void *)p_dec->p_sys;
126 block_t *p_block;
128 if( !pp_block || !*pp_block ) return NULL;
129 p_block = *pp_block;
131 if( stream != NULL
132 && p_block->i_buffer > 0
133 && !(p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) )
135 fwrite( p_block->p_buffer, 1, p_block->i_buffer, stream );
136 msg_Dbg( p_dec, "dumped %zu bytes", p_block->i_buffer );
138 block_Release( p_block );
140 return NULL;
143 /*****************************************************************************
144 * CloseDecoder: decoder destruction
145 *****************************************************************************/
146 static void CloseDecoder( vlc_object_t *p_this )
148 decoder_t *p_dec = (decoder_t *)p_this;
149 FILE *stream = (void *)p_dec->p_sys;
151 if( stream != NULL )
152 fclose( stream );