access: http: only warn on deflate errors
[vlc.git] / modules / misc / stats.c
blobc98932780d3dd6f7edff38f9d3b8431609e2c116
1 /*****************************************************************************
2 * stats.c : stats plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2008 the VideoLAN team
6 * Authors: Samuel Hocevar <sam@zoy.org>
7 * Pierre d'Herbemont <pdherbemont@videolan.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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 /* Example usage:
29 * $ vlc movie.avi --sout="#transcode{aenc=dummy,venc=stats}:\
30 * std{access=http,mux=dummy,dst=0.0.0.0:8081}"
31 * $ vlc -vvv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats
34 #define kBufferSize 0x500
36 #include <vlc_common.h>
37 #include <vlc_plugin.h>
38 #include <vlc_codec.h>
39 #include <vlc_demux.h>
41 /*** Decoder ***/
42 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
44 block_t *p_block;
45 picture_t * p_pic = NULL;
47 if( !pp_block || !*pp_block ) return NULL;
48 p_block = *pp_block;
50 p_pic = decoder_NewPicture( p_dec );
52 if( p_block->i_buffer == kBufferSize )
54 msg_Dbg( p_dec, "got %"PRIu64" ms",
55 *(mtime_t *)p_block->p_buffer / 1000 );
56 msg_Dbg( p_dec, "got %"PRIu64" ms offset",
57 (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
58 *(mtime_t *)(p_pic->p->p_pixels) = *(mtime_t *)p_block->p_buffer;
60 else
62 msg_Dbg( p_dec, "got a packet not from stats demuxer" );
63 *(mtime_t *)(p_pic->p->p_pixels) = mdate();
66 p_pic->date = p_block->i_pts > VLC_TS_INVALID ?
67 p_block->i_pts : p_block->i_dts;
68 p_pic->b_force = true;
70 block_Release( p_block );
71 *pp_block = NULL;
72 return p_pic;
75 static int OpenDecoder ( vlc_object_t *p_this )
77 decoder_t *p_dec = (decoder_t*)p_this;
79 msg_Dbg( p_this, "opening stats decoder" );
81 /* Set callbacks */
82 p_dec->pf_decode_video = DecodeBlock;
83 p_dec->pf_decode_audio = NULL;
84 p_dec->pf_decode_sub = NULL;
86 /* */
87 es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_I420 );
88 p_dec->fmt_out.video.i_width = 100;
89 p_dec->fmt_out.video.i_height = 100;
90 p_dec->fmt_out.video.i_sar_num = 1;
91 p_dec->fmt_out.video.i_sar_den = 1;
93 return VLC_SUCCESS;
96 /*** Encoder ***/
97 #ifdef ENABLE_SOUT
98 static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
100 (void)p_pict;
101 block_t * p_block = block_Alloc( kBufferSize );
103 *(mtime_t*)p_block->p_buffer = mdate();
104 p_block->i_buffer = kBufferSize;
105 p_block->i_length = kBufferSize;
106 p_block->i_dts = p_pict->date;
108 msg_Dbg( p_enc, "putting %"PRIu64"ms",
109 *(mtime_t*)p_block->p_buffer / 1000 );
110 return p_block;
113 static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_abuff )
115 (void)p_abuff;
116 (void)p_enc;
117 return NULL;
120 static int OpenEncoder ( vlc_object_t *p_this )
122 encoder_t *p_enc = (encoder_t *)p_this;
124 msg_Dbg( p_this, "opening stats encoder" );
126 p_enc->pf_encode_video = EncodeVideo;
127 p_enc->pf_encode_audio = EncodeAudio;
129 return VLC_SUCCESS;
131 #endif
133 /*** Demuxer ***/
134 struct demux_sys_t
136 es_format_t fmt;
137 es_out_id_t *p_es;
139 date_t pts;
142 static int Demux( demux_t *p_demux )
144 demux_sys_t *p_sys = p_demux->p_sys;
146 block_t * p_block = stream_Block( p_demux->s, kBufferSize );
148 if( !p_block ) return 1;
150 p_block->i_dts = p_block->i_pts =
151 date_Increment( &p_sys->pts, kBufferSize );
153 msg_Dbg( p_demux, "demux got %d ms offset", (int)(mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
155 //es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
157 es_out_Send( p_demux->out, p_sys->p_es, p_block );
159 return 1;
162 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
164 return demux_vaControlHelper( p_demux->s,
165 0, 0, 0, 1,
166 i_query, args );
169 static int OpenDemux ( vlc_object_t *p_this )
171 demux_t *p_demux = (demux_t*)p_this;
172 demux_sys_t *p_sys;
174 p_demux->p_sys = NULL;
176 /* Only when selected */
177 if( *p_demux->psz_demux == '\0' )
178 return VLC_EGENERIC;
180 msg_Dbg( p_demux, "Init Stat demux" );
182 p_demux->pf_demux = Demux;
183 p_demux->pf_control = DemuxControl;
185 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
186 if( !p_demux->p_sys )
187 return VLC_ENOMEM;
189 date_Init( &p_sys->pts, 1, 1 );
190 date_Set( &p_sys->pts, 1 );
192 es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('s','t','a','t') );
193 p_sys->fmt.video.i_width = 720;
194 p_sys->fmt.video.i_height= 480;
196 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
198 return VLC_SUCCESS;
201 static void CloseDemux ( vlc_object_t *p_this )
203 demux_t *p_demux = (demux_t*)p_this;
205 msg_Dbg( p_demux, "Closing Stat demux" );
207 free( p_demux->p_sys );
210 vlc_module_begin ()
211 set_shortname( N_("Stats"))
212 #ifdef ENABLE_SOUT
213 set_description( N_("Stats encoder function") )
214 set_capability( "encoder", 0 )
215 add_shortcut( "stats" )
216 set_callbacks( OpenEncoder, NULL )
217 add_submodule ()
218 #endif
219 set_section( N_( "Stats decoder" ), NULL )
220 set_description( N_("Stats decoder function") )
221 set_capability( "decoder", 0 )
222 add_shortcut( "stats" )
223 set_callbacks( OpenDecoder, NULL )
224 add_submodule ()
225 set_section( N_( "Stats demux" ), NULL )
226 set_description( N_("Stats demux function") )
227 set_capability( "demux", 0 )
228 add_shortcut( "stats" )
229 set_callbacks( OpenDemux, CloseDemux )
230 vlc_module_end ()