1 /*****************************************************************************
2 * dddumy.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
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 /*****************************************************************************
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( "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" )
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" )
64 /*****************************************************************************
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
);
80 b_force_dump
= var_InheritBool( p_dec
, "dummy-save-es" );
83 FILE *stream
= vlc_fopen( psz_file
, "wb" );
86 msg_Err( p_dec
, "cannot create `%s'", psz_file
);
89 msg_Dbg( p_dec
, "dumping stream to file `%s'", psz_file
);
90 p_dec
->p_sys
= (void *)stream
;
96 p_dec
->pf_decode_video
= (picture_t
*(*)(decoder_t
*, block_t
**))
98 p_dec
->pf_decode_audio
= (aout_buffer_t
*(*)(decoder_t
*, block_t
**))
100 p_dec
->pf_decode_sub
= (subpicture_t
*(*)(decoder_t
*, block_t
**))
103 es_format_Copy( &p_dec
->fmt_out
, &p_dec
->fmt_in
);
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
;
128 if( !pp_block
|| !*pp_block
) return 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
);
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
;