Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

decoder.c

00001 /*****************************************************************************
00002  * decoder.c: dummy decoder plugin for vlc.
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: decoder.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <vlc/vlc.h>
00028 #include <vlc/decoder.h>
00029 
00030 #ifdef HAVE_UNISTD_H
00031 #   include <unistd.h> /* write(), close() */
00032 #elif defined( WIN32 ) && !defined( UNDER_CE )
00033 #   include <io.h>
00034 #endif
00035 #ifdef HAVE_SYS_TYPES_H
00036 #   include <sys/types.h> /* open() */
00037 #endif
00038 #ifdef HAVE_SYS_STAT_H
00039 #   include <sys/stat.h>
00040 #endif
00041 #ifdef HAVE_FCNTL_H
00042 #   include <fcntl.h>
00043 #endif
00044 
00045 #ifdef HAVE_LIMITS_H
00046 #   include <limits.h> /* PATH_MAX */
00047 #endif
00048 
00049 #include <stdio.h> /* sprintf() */
00050 
00051 /*****************************************************************************
00052  * decoder_sys_t : theora decoder descriptor
00053  *****************************************************************************/
00054 struct decoder_sys_t
00055 {
00056     int i_fd;
00057 };
00058 
00059 /*****************************************************************************
00060  * Local prototypes
00061  *****************************************************************************/
00062 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
00063 
00064 /*****************************************************************************
00065  * OpenDecoder: Open the decoder
00066  *****************************************************************************/
00067 int E_(OpenDecoder) ( vlc_object_t *p_this )
00068 {
00069     decoder_t *p_dec = (decoder_t*)p_this;
00070     decoder_sys_t *p_sys;
00071     char psz_file[ PATH_MAX ];
00072     vlc_value_t val;
00073 
00074     /* Allocate the memory needed to store the decoder's structure */
00075     if( ( p_dec->p_sys = p_sys =
00076           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
00077     {
00078         msg_Err( p_dec, "out of memory" );
00079         return VLC_EGENERIC;
00080     }
00081 
00082     sprintf( psz_file, "stream.%i", p_dec->i_object_id );
00083 
00084 #ifndef UNDER_CE
00085     var_Create( p_dec, "dummy-save-es", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
00086     var_Get( p_dec, "dummy-save-es", &val );
00087     if( val.b_bool )
00088     {
00089         p_sys->i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
00090 
00091         if( p_sys->i_fd == -1 )
00092         {
00093             msg_Err( p_dec, "cannot create `%s'", psz_file );
00094             return VLC_EGENERIC;
00095         }
00096 
00097         msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
00098     }
00099     else
00100 #endif
00101     {
00102         p_sys->i_fd = -1;
00103     }
00104 
00105     /* Set callbacks */
00106     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
00107         DecodeBlock;
00108     p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
00109         DecodeBlock;
00110 
00111     return VLC_SUCCESS;
00112 }
00113 
00114 /****************************************************************************
00115  * RunDecoder: the whole thing
00116  ****************************************************************************
00117  * This function must be fed with ogg packets.
00118  ****************************************************************************/
00119 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
00120 {
00121     decoder_sys_t *p_sys = p_dec->p_sys;
00122     block_t *p_block;
00123 
00124     if( !pp_block || !*pp_block ) return NULL;
00125     p_block = *pp_block;
00126 
00127     if( p_sys->i_fd >= 0 && p_block->i_buffer )
00128     {
00129 #ifndef UNDER_CE
00130         write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
00131 #endif
00132 
00133         msg_Dbg( p_dec, "dumped %i bytes", p_block->i_buffer );
00134     }
00135 
00136     block_Release( p_block );
00137     return NULL;
00138 }
00139 
00140 /*****************************************************************************
00141  * CloseDecoder: decoder destruction
00142  *****************************************************************************/
00143 void E_(CloseDecoder) ( vlc_object_t *p_this )
00144 {
00145     decoder_t *p_dec = (decoder_t *)p_this;
00146     decoder_sys_t *p_sys = p_dec->p_sys;
00147 
00148 #ifndef UNDER_CE
00149     if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );
00150 #endif
00151 
00152     free( p_sys );
00153 }

Generated on Tue Dec 20 10:14:48 2005 for vlc-0.8.4a by  doxygen 1.4.2