00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <vlc/vlc.h>
00028 #include <vlc/decoder.h>
00029
00030 #ifdef HAVE_UNISTD_H
00031 # include <unistd.h>
00032 #elif defined( WIN32 ) && !defined( UNDER_CE )
00033 # include <io.h>
00034 #endif
00035 #ifdef HAVE_SYS_TYPES_H
00036 # include <sys/types.h>
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>
00047 #endif
00048
00049 #include <stdio.h>
00050
00051
00052
00053
00054 struct decoder_sys_t
00055 {
00056 int i_fd;
00057 };
00058
00059
00060
00061
00062 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
00063
00064
00065
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
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
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
00116
00117
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
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 }