chromecast: lower vorbis encoding quality
[vlc.git] / modules / misc / stats.c
blob4d02a307d922dfec85b619b69aa7bb26128f62d8
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 -vv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats
34 #define kBufferSize 0x500
36 #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
37 #include <vlc_common.h>
38 #include <vlc_plugin.h>
39 #include <vlc_codec.h>
40 #include <vlc_demux.h>
42 /*** Decoder ***/
43 static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
45 picture_t * p_pic = NULL;
47 if( p_block == NULL ) /* No Drain */
48 return VLCDEC_SUCCESS;
50 if( !decoder_UpdateVideoFormat( p_dec ) )
51 p_pic = decoder_NewPicture( p_dec );
52 if( !p_pic )
53 goto error;
55 if( p_block->i_buffer == kBufferSize )
57 msg_Dbg( p_dec, "got %"PRIu64" ms",
58 *(mtime_t *)p_block->p_buffer / 1000 );
59 msg_Dbg( p_dec, "got %"PRIu64" ms offset",
60 (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
61 *(mtime_t *)(p_pic->p->p_pixels) = *(mtime_t *)p_block->p_buffer;
63 else
65 msg_Dbg( p_dec, "got a packet not from stats demuxer" );
66 *(mtime_t *)(p_pic->p->p_pixels) = mdate();
69 p_pic->date = p_block->i_pts > VLC_TS_INVALID ?
70 p_block->i_pts : p_block->i_dts;
71 p_pic->b_force = true;
73 error:
74 block_Release( p_block );
75 decoder_QueueVideo( p_dec, p_pic );
76 return VLCDEC_SUCCESS;
79 static int OpenDecoder ( vlc_object_t *p_this )
81 decoder_t *p_dec = (decoder_t*)p_this;
83 msg_Dbg( p_this, "opening stats decoder" );
85 /* Set callbacks */
86 p_dec->pf_decode = DecodeBlock;
88 /* */
89 p_dec->fmt_out.i_codec = VLC_CODEC_I420;
90 p_dec->fmt_out.video.i_width = 100;
91 p_dec->fmt_out.video.i_height = 100;
92 p_dec->fmt_out.video.i_sar_num = 1;
93 p_dec->fmt_out.video.i_sar_den = 1;
95 return VLC_SUCCESS;
98 /*** Encoder ***/
99 #ifdef ENABLE_SOUT
100 static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
102 (void)p_pict;
103 block_t * p_block = block_Alloc( kBufferSize );
105 *(mtime_t*)p_block->p_buffer = mdate();
106 p_block->i_buffer = kBufferSize;
107 p_block->i_length = kBufferSize;
108 p_block->i_dts = p_pict->date;
110 msg_Dbg( p_enc, "putting %"PRIu64"ms",
111 *(mtime_t*)p_block->p_buffer / 1000 );
112 return p_block;
115 static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_abuff )
117 (void)p_abuff;
118 (void)p_enc;
119 return NULL;
122 static int OpenEncoder ( vlc_object_t *p_this )
124 encoder_t *p_enc = (encoder_t *)p_this;
126 msg_Dbg( p_this, "opening stats encoder" );
128 p_enc->pf_encode_video = EncodeVideo;
129 p_enc->pf_encode_audio = EncodeAudio;
131 return VLC_SUCCESS;
133 #endif
135 /*** Demuxer ***/
136 struct demux_sys_t
138 es_format_t fmt;
139 es_out_id_t *p_es;
141 date_t pts;
144 static int Demux( demux_t *p_demux )
146 demux_sys_t *p_sys = p_demux->p_sys;
148 block_t * p_block = vlc_stream_Block( p_demux->s, kBufferSize );
150 if( !p_block ) return 1;
152 p_block->i_dts = p_block->i_pts =
153 date_Increment( &p_sys->pts, kBufferSize );
155 msg_Dbg( p_demux, "demux got %"PRId64" ms offset",
156 (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
158 //es_out_SetPCR( p_demux->out, p_block->i_pts );
160 es_out_Send( p_demux->out, p_sys->p_es, p_block );
162 return 1;
165 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
167 return demux_vaControlHelper( p_demux->s,
168 0, 0, 0, 1,
169 i_query, args );
172 static int OpenDemux ( vlc_object_t *p_this )
174 demux_t *p_demux = (demux_t*)p_this;
175 demux_sys_t *p_sys;
177 p_demux->p_sys = NULL;
179 /* Only when selected */
180 if( *p_demux->psz_name == '\0' )
181 return VLC_EGENERIC;
183 msg_Dbg( p_demux, "Init Stat demux" );
185 p_demux->pf_demux = Demux;
186 p_demux->pf_control = DemuxControl;
188 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
189 if( !p_demux->p_sys )
190 return VLC_ENOMEM;
192 date_Init( &p_sys->pts, 1, 1 );
193 date_Set( &p_sys->pts, 1 );
195 es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('s','t','a','t') );
196 p_sys->fmt.video.i_width = 720;
197 p_sys->fmt.video.i_height= 480;
199 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
201 return VLC_SUCCESS;
204 static void CloseDemux ( vlc_object_t *p_this )
206 demux_t *p_demux = (demux_t*)p_this;
208 msg_Dbg( p_demux, "Closing Stat demux" );
210 free( p_demux->p_sys );
213 vlc_module_begin ()
214 set_shortname( N_("Stats"))
215 #ifdef ENABLE_SOUT
216 set_description( N_("Stats encoder function") )
217 set_capability( "encoder", 0 )
218 add_shortcut( "stats" )
219 set_callbacks( OpenEncoder, NULL )
220 add_submodule ()
221 #endif
222 set_section( N_( "Stats decoder" ), NULL )
223 set_description( N_("Stats decoder function") )
224 set_capability( "video decoder", 0 )
225 add_shortcut( "stats" )
226 set_callbacks( OpenDecoder, NULL )
227 add_submodule()
228 set_section( N_( "Stats decoder" ), NULL )
229 set_description( N_("Stats decoder function") )
230 set_capability( "audio decoder", 0 )
231 add_shortcut( "stats" )
232 set_callbacks( OpenDecoder, NULL )
233 add_submodule()
234 set_section( N_( "Stats decoder" ), NULL )
235 set_description( N_("Stats decoder function") )
236 set_capability( "spu decoder", 0 )
237 add_shortcut( "stats" )
238 set_callbacks( OpenDecoder, NULL )
239 add_submodule ()
240 set_section( N_( "Stats demux" ), NULL )
241 set_description( N_("Stats demux function") )
242 set_capability( "demux", 0 )
243 add_shortcut( "stats" )
244 set_callbacks( OpenDemux, CloseDemux )
245 vlc_module_end ()