]> git.sesse.net Git - vlc/blob - modules/codec/ddummy.c
mediacodec: fix warning
[vlc] / modules / codec / ddummy.c
1 /*****************************************************************************
2  * ddummy.c: dummy decoder plugin for vlc.
3  *****************************************************************************
4  * Copyright (C) 2002 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_codec.h>
34 #include <vlc_fs.h>
35
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." )
40
41 static int OpenDecoder( vlc_object_t * );
42 static int OpenDecoderDump( vlc_object_t * );
43 static void CloseDecoder( vlc_object_t * );
44
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" )
54
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 ()
62
63
64 /*****************************************************************************
65  * Local prototypes
66  *****************************************************************************/
67 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
68
69 /*****************************************************************************
70  * OpenDecoder: Open the decoder
71  *****************************************************************************/
72 static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump )
73 {
74     decoder_t *p_dec = (decoder_t*)p_this;
75     char psz_file[10 + 3 * sizeof (p_dec)];
76
77     snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec );
78
79     if( !b_force_dump )
80         b_force_dump = var_InheritBool( p_dec, "dummy-save-es" );
81     if( b_force_dump )
82     {
83         FILE *stream = vlc_fopen( psz_file, "wb" );
84         if( stream == NULL )
85         {
86             msg_Err( p_dec, "cannot create `%s'", psz_file );
87             return VLC_EGENERIC;
88         }
89         msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
90         p_dec->p_sys = (void *)stream;
91     }
92     else
93         p_dec->p_sys = NULL;
94
95     /* Set callbacks */
96     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
97         DecodeBlock;
98     p_dec->pf_decode_audio = (block_t *(*)(decoder_t *, block_t **))
99         DecodeBlock;
100     p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **))
101         DecodeBlock;
102
103     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
104
105     return VLC_SUCCESS;
106 }
107
108 static int OpenDecoder( vlc_object_t *p_this )
109 {
110     return OpenDecoderCommon( p_this, false );
111 }
112
113 static int  OpenDecoderDump( vlc_object_t *p_this )
114 {
115     return OpenDecoderCommon( p_this, true );
116 }
117
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 )
124 {
125     FILE *stream = (void *)p_dec->p_sys;
126     block_t *p_block;
127
128     if( !pp_block || !*pp_block ) return NULL;
129     p_block = *pp_block;
130
131     if( stream != NULL
132      && p_block->i_buffer > 0
133      && !(p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) )
134     {
135         fwrite( p_block->p_buffer, 1, p_block->i_buffer, stream );
136         msg_Dbg( p_dec, "dumped %zu bytes", p_block->i_buffer );
137     }
138     block_Release( p_block );
139
140     return NULL;
141 }
142
143 /*****************************************************************************
144  * CloseDecoder: decoder destruction
145  *****************************************************************************/
146 static void CloseDecoder( vlc_object_t *p_this )
147 {
148     decoder_t *p_dec = (decoder_t *)p_this;
149     FILE *stream = (void *)p_dec->p_sys;
150
151     if( stream != NULL )
152         fclose( stream );
153 }