1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/*****************************************************************************
* stats.c : stats plugin for vlc
*****************************************************************************
* Copyright (C) 2000-2008 the VideoLAN team
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Pierre d'Herbemont <pdherbemont@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
/* Example usage:
* $ vlc movie.avi --sout="#transcode{aenc=dummy,venc=stats}:\
* std{access=http,mux=dummy,dst=0.0.0.0:8081}"
* $ vlc -vv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats
*/
#define kBufferSize 0x500
#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_demux.h>
/*** Decoder ***/
static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
{
picture_t * p_pic = NULL;
if( p_block == NULL ) /* No Drain */
return VLCDEC_SUCCESS;
if( !decoder_UpdateVideoFormat( p_dec ) )
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
goto error;
if( p_block->i_buffer == kBufferSize )
{
msg_Dbg( p_dec, "got %"PRIu64" ms",
*(vlc_tick_t *)p_block->p_buffer / 1000 );
msg_Dbg( p_dec, "got %"PRIu64" ms offset",
(mdate() - *(vlc_tick_t *)p_block->p_buffer) / 1000 );
*(vlc_tick_t *)(p_pic->p->p_pixels) = *(vlc_tick_t *)p_block->p_buffer;
}
else
{
msg_Dbg( p_dec, "got a packet not from stats demuxer" );
*(vlc_tick_t *)(p_pic->p->p_pixels) = mdate();
}
p_pic->date = p_block->i_pts > VLC_TICK_INVALID ?
p_block->i_pts : p_block->i_dts;
p_pic->b_force = true;
error:
block_Release( p_block );
if ( p_pic )
decoder_QueueVideo( p_dec, p_pic );
return VLCDEC_SUCCESS;
}
static int OpenDecoder ( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t*)p_this;
msg_Dbg( p_this, "opening stats decoder" );
/* Set callbacks */
p_dec->pf_decode = DecodeBlock;
/* */
p_dec->fmt_out.i_codec = VLC_CODEC_I420;
p_dec->fmt_out.video.i_width = 100;
p_dec->fmt_out.video.i_height = 100;
p_dec->fmt_out.video.i_sar_num = 1;
p_dec->fmt_out.video.i_sar_den = 1;
return VLC_SUCCESS;
}
/*** Encoder ***/
#ifdef ENABLE_SOUT
static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
{
(void)p_pict;
block_t * p_block = block_Alloc( kBufferSize );
*(vlc_tick_t*)p_block->p_buffer = mdate();
p_block->i_buffer = kBufferSize;
p_block->i_length = kBufferSize;
p_block->i_dts = p_pict->date;
msg_Dbg( p_enc, "putting %"PRIu64"ms",
*(vlc_tick_t*)p_block->p_buffer / 1000 );
return p_block;
}
static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_abuff )
{
(void)p_abuff;
(void)p_enc;
return NULL;
}
static int OpenEncoder ( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
msg_Dbg( p_this, "opening stats encoder" );
p_enc->pf_encode_video = EncodeVideo;
p_enc->pf_encode_audio = EncodeAudio;
return VLC_SUCCESS;
}
#endif
/*** Demuxer ***/
struct demux_sys_t
{
es_format_t fmt;
es_out_id_t *p_es;
date_t pts;
};
static int Demux( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
block_t * p_block = vlc_stream_Block( p_demux->s, kBufferSize );
if( !p_block ) return 1;
p_block->i_dts = p_block->i_pts =
date_Increment( &p_sys->pts, kBufferSize );
msg_Dbg( p_demux, "demux got %"PRId64" ms offset",
(mdate() - *(vlc_tick_t *)p_block->p_buffer) / 1000 );
//es_out_SetPCR( p_demux->out, p_block->i_pts );
es_out_Send( p_demux->out, p_sys->p_es, p_block );
return 1;
}
static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
{
return demux_vaControlHelper( p_demux->s,
0, 0, 0, 1,
i_query, args );
}
static int OpenDemux ( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t*)p_this;
demux_sys_t *p_sys;
p_demux->p_sys = NULL;
/* Only when selected */
if( *p_demux->psz_demux == '\0' )
return VLC_EGENERIC;
msg_Dbg( p_demux, "Init Stat demux" );
p_demux->pf_demux = Demux;
p_demux->pf_control = DemuxControl;
p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
if( !p_demux->p_sys )
return VLC_ENOMEM;
date_Init( &p_sys->pts, 1, 1 );
date_Set( &p_sys->pts, 1 );
es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('s','t','a','t') );
p_sys->fmt.video.i_width = 720;
p_sys->fmt.video.i_height= 480;
p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
return VLC_SUCCESS;
}
static void CloseDemux ( vlc_object_t *p_this )
{
demux_t *p_demux = (demux_t*)p_this;
msg_Dbg( p_demux, "Closing Stat demux" );
free( p_demux->p_sys );
}
vlc_module_begin ()
set_shortname( N_("Stats"))
#ifdef ENABLE_SOUT
set_description( N_("Stats encoder function") )
set_capability( "encoder", 0 )
add_shortcut( "stats" )
set_callbacks( OpenEncoder, NULL )
add_submodule ()
#endif
set_section( N_( "Stats decoder" ), NULL )
set_description( N_("Stats decoder function") )
set_capability( "video decoder", 0 )
add_shortcut( "stats" )
set_callbacks( OpenDecoder, NULL )
add_submodule()
set_section( N_( "Stats decoder" ), NULL )
set_description( N_("Stats decoder function") )
set_capability( "audio decoder", 0 )
add_shortcut( "stats" )
set_callbacks( OpenDecoder, NULL )
add_submodule()
set_section( N_( "Stats decoder" ), NULL )
set_description( N_("Stats decoder function") )
set_capability( "spu decoder", 0 )
add_shortcut( "stats" )
set_callbacks( OpenDecoder, NULL )
add_submodule ()
set_section( N_( "Stats demux" ), NULL )
set_description( N_("Stats demux function") )
set_capability( "demux", 0 )
add_shortcut( "stats" )
set_callbacks( OpenDemux, CloseDemux )
vlc_module_end ()
|