1 /*****************************************************************************
2 * decoder.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_codec.h>
33 #include <vlc_charset.h>
36 # include <unistd.h> /* write(), close() */
37 #elif defined( WIN32 ) && !defined( UNDER_CE )
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h> /* open() */
47 #include <limits.h> /* PATH_MAX */
52 /*****************************************************************************
53 * decoder_sys_t : theora decoder descriptor
54 *****************************************************************************/
60 /*****************************************************************************
62 *****************************************************************************/
63 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
65 /*****************************************************************************
66 * OpenDecoder: Open the decoder
67 *****************************************************************************/
68 static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump )
70 decoder_t *p_dec = (decoder_t*)p_this;
72 char psz_file[ PATH_MAX ];
74 /* Allocate the memory needed to store the decoder's structure */
75 if( ( p_dec->p_sys = p_sys =
76 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
81 snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec );
86 b_force_dump = var_CreateGetBool( p_dec, "dummy-save-es" );
90 p_sys->i_fd = utf8_open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
92 if( p_sys->i_fd == -1 )
94 msg_Err( p_dec, "cannot create `%s'", psz_file );
99 msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
108 p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
110 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
112 p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **))
115 es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
120 int OpenDecoder( vlc_object_t *p_this )
122 return OpenDecoderCommon( p_this, false );
124 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 void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
136 decoder_sys_t *p_sys = p_dec->p_sys;
139 if( !pp_block || !*pp_block ) return NULL;
142 if( p_sys->i_fd >= 0 &&
143 p_block->i_buffer > 0 &&
144 (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) == 0 )
147 write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
150 msg_Dbg( p_dec, "dumped %zu bytes", p_block->i_buffer );
153 block_Release( p_block );
157 /*****************************************************************************
158 * CloseDecoder: decoder destruction
159 *****************************************************************************/
160 void CloseDecoder ( vlc_object_t *p_this )
162 decoder_t *p_dec = (decoder_t *)p_this;
163 decoder_sys_t *p_sys = p_dec->p_sys;
166 if( p_sys->i_fd >= 0 )
167 close( p_sys->i_fd );