1 /*****************************************************************************
2 * decoder.c: dummy decoder plugin for vlc.
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN (Centrale Réseaux) and its contributors
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <vlc/decoder.h>
31 # include <unistd.h> /* write(), close() */
32 #elif defined( WIN32 ) && !defined( UNDER_CE )
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h> /* open() */
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
46 # include <limits.h> /* PATH_MAX */
49 #include <stdio.h> /* sprintf() */
51 /*****************************************************************************
52 * decoder_sys_t : theora decoder descriptor
53 *****************************************************************************/
59 /*****************************************************************************
61 *****************************************************************************/
62 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
64 /*****************************************************************************
65 * OpenDecoder: Open the decoder
66 *****************************************************************************/
67 int E_(OpenDecoder) ( vlc_object_t *p_this )
69 decoder_t *p_dec = (decoder_t*)p_this;
71 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 )
78 msg_Err( p_dec, "out of memory" );
82 sprintf( psz_file, "stream.%i", p_dec->i_object_id );
85 var_Create( p_dec, "dummy-save-es", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
86 var_Get( p_dec, "dummy-save-es", &val );
89 p_sys->i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
91 if( p_sys->i_fd == -1 )
93 msg_Err( p_dec, "cannot create `%s'", psz_file );
97 msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
106 p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
108 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
114 /****************************************************************************
115 * RunDecoder: the whole thing
116 ****************************************************************************
117 * This function must be fed with ogg packets.
118 ****************************************************************************/
119 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
121 decoder_sys_t *p_sys = p_dec->p_sys;
124 if( !pp_block || !*pp_block ) return NULL;
127 if( p_sys->i_fd >= 0 && p_block->i_buffer )
130 write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
133 msg_Dbg( p_dec, "dumped %i bytes", p_block->i_buffer );
136 block_Release( p_block );
140 /*****************************************************************************
141 * CloseDecoder: decoder destruction
142 *****************************************************************************/
143 void E_(CloseDecoder) ( vlc_object_t *p_this )
145 decoder_t *p_dec = (decoder_t *)p_this;
146 decoder_sys_t *p_sys = p_dec->p_sys;
149 if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );