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 -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>
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
);
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
;
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;
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" );
86 p_dec
->pf_decode
= DecodeBlock
;
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;
100 static block_t
*EncodeVideo( encoder_t
*p_enc
, picture_t
*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 );
115 static block_t
*EncodeAudio( encoder_t
*p_enc
, block_t
*p_abuff
)
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
;
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
);
165 static int DemuxControl( demux_t
*p_demux
, int i_query
, va_list args
)
167 return demux_vaControlHelper( p_demux
->s
,
172 static int OpenDemux ( vlc_object_t
*p_this
)
174 demux_t
*p_demux
= (demux_t
*)p_this
;
177 p_demux
->p_sys
= NULL
;
179 /* Only when selected */
180 if( *p_demux
->psz_name
== '\0' )
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
)
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
);
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
);
214 set_shortname( N_("Stats"))
216 set_description( N_("Stats encoder function") )
217 set_capability( "encoder", 0 )
218 add_shortcut( "stats" )
219 set_callbacks( OpenEncoder
, NULL
)
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
)
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
)
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
)
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
)