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 *****************************************************************************/
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>
42 static picture_t
*DecodeBlock( decoder_t
*p_dec
, block_t
**pp_block
)
45 picture_t
* p_pic
= NULL
;
47 if( !pp_block
|| !*pp_block
) return NULL
;
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
;
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
);
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" );
82 p_dec
->pf_decode_video
= DecodeBlock
;
83 p_dec
->pf_decode_audio
= NULL
;
84 p_dec
->pf_decode_sub
= NULL
;
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;
98 static block_t
*EncodeVideo( encoder_t
*p_enc
, picture_t
*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 );
113 static block_t
*EncodeAudio( encoder_t
*p_enc
, block_t
*p_abuff
)
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
;
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
);
162 static int DemuxControl( demux_t
*p_demux
, int i_query
, va_list args
)
164 return demux_vaControlHelper( p_demux
->s
,
169 static int OpenDemux ( vlc_object_t
*p_this
)
171 demux_t
*p_demux
= (demux_t
*)p_this
;
174 p_demux
->p_sys
= NULL
;
176 /* Only when selected */
177 if( *p_demux
->psz_demux
== '\0' )
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
)
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
);
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
);
211 set_shortname( N_("Stats"))
213 set_description( N_("Stats encoder function") )
214 set_capability( "encoder", 0 )
215 add_shortcut( "stats" )
216 set_callbacks( OpenEncoder
, NULL
)
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
)
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
)