2013-03-09 15:29:14 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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}"
|
2017-03-10 10:10:29 +01:00
|
|
|
* $ vlc -vv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats
|
2013-03-09 15:29:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define kBufferSize 0x500
|
|
|
|
|
2015-03-21 13:15:22 +01:00
|
|
|
#define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS
|
2013-03-09 15:29:14 +01:00
|
|
|
#include <vlc_common.h>
|
|
|
|
#include <vlc_plugin.h>
|
|
|
|
#include <vlc_codec.h>
|
|
|
|
#include <vlc_demux.h>
|
|
|
|
|
|
|
|
/*** Decoder ***/
|
2017-02-07 10:21:22 +01:00
|
|
|
static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
|
2013-03-09 15:29:14 +01:00
|
|
|
{
|
|
|
|
picture_t * p_pic = NULL;
|
|
|
|
|
2017-02-07 10:21:22 +01:00
|
|
|
if( p_block == NULL ) /* No Drain */
|
|
|
|
return VLCDEC_SUCCESS;
|
2013-03-09 15:29:14 +01:00
|
|
|
|
2016-09-26 16:51:35 +02:00
|
|
|
if( !decoder_UpdateVideoFormat( p_dec ) )
|
|
|
|
p_pic = decoder_NewPicture( p_dec );
|
2016-09-26 16:30:19 +02:00
|
|
|
if( !p_pic )
|
|
|
|
goto error;
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
if( p_block->i_buffer == kBufferSize )
|
|
|
|
{
|
|
|
|
msg_Dbg( p_dec, "got %"PRIu64" ms",
|
2018-06-06 12:25:34 +02:00
|
|
|
MS_FROM_VLC_TICK(*(vlc_tick_t *)p_block->p_buffer) );
|
2013-03-09 15:29:14 +01:00
|
|
|
msg_Dbg( p_dec, "got %"PRIu64" ms offset",
|
2018-06-06 12:25:34 +02:00
|
|
|
MS_FROM_VLC_TICK(vlc_tick_now() - *(vlc_tick_t *)p_block->p_buffer) );
|
2018-06-22 13:19:24 +02:00
|
|
|
*(vlc_tick_t *)(p_pic->p->p_pixels) = *(vlc_tick_t *)p_block->p_buffer;
|
2013-03-09 15:29:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg_Dbg( p_dec, "got a packet not from stats demuxer" );
|
2018-06-20 08:37:11 +02:00
|
|
|
*(vlc_tick_t *)(p_pic->p->p_pixels) = vlc_tick_now();
|
2013-03-09 15:29:14 +01:00
|
|
|
}
|
|
|
|
|
2018-07-02 15:51:29 +02:00
|
|
|
p_pic->date = p_block->i_pts != VLC_TICK_INVALID ?
|
2013-03-09 15:29:14 +01:00
|
|
|
p_block->i_pts : p_block->i_dts;
|
|
|
|
|
2016-09-26 16:30:19 +02:00
|
|
|
error:
|
2013-03-09 15:29:14 +01:00
|
|
|
block_Release( p_block );
|
2017-02-07 10:21:22 +01:00
|
|
|
decoder_QueueVideo( p_dec, p_pic );
|
|
|
|
return VLCDEC_SUCCESS;
|
2013-03-09 15:29:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2017-02-07 10:21:22 +01:00
|
|
|
p_dec->pf_decode = DecodeBlock;
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
/* */
|
2017-07-10 16:14:03 +02:00
|
|
|
p_dec->fmt_out.i_codec = VLC_CODEC_I420;
|
2013-03-09 15:29:14 +01:00
|
|
|
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 ***/
|
2013-03-09 15:30:46 +01:00
|
|
|
#ifdef ENABLE_SOUT
|
2013-03-09 15:29:14 +01:00
|
|
|
static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pict )
|
|
|
|
{
|
|
|
|
(void)p_pict;
|
|
|
|
block_t * p_block = block_Alloc( kBufferSize );
|
|
|
|
|
2018-06-20 08:37:11 +02:00
|
|
|
*(vlc_tick_t*)p_block->p_buffer = vlc_tick_now();
|
2013-03-09 15:29:14 +01:00
|
|
|
p_block->i_buffer = kBufferSize;
|
|
|
|
p_block->i_length = kBufferSize;
|
|
|
|
p_block->i_dts = p_pict->date;
|
|
|
|
|
|
|
|
msg_Dbg( p_enc, "putting %"PRIu64"ms",
|
2018-06-06 12:25:34 +02:00
|
|
|
MS_FROM_VLC_TICK(*(vlc_tick_t*)p_block->p_buffer) );
|
2013-03-09 15:29:14 +01:00
|
|
|
return p_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_abuff )
|
|
|
|
{
|
|
|
|
(void)p_abuff;
|
|
|
|
(void)p_enc;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-12-17 16:15:54 +01:00
|
|
|
static int OpenVideoEncoder ( vlc_object_t *p_this )
|
2013-03-09 15:29:14 +01:00
|
|
|
{
|
|
|
|
encoder_t *p_enc = (encoder_t *)p_this;
|
|
|
|
|
|
|
|
msg_Dbg( p_this, "opening stats encoder" );
|
|
|
|
|
2021-12-17 16:15:54 +01:00
|
|
|
static const struct vlc_encoder_operations video_ops =
|
|
|
|
{ .encode_video = EncodeVideo };
|
2013-03-09 15:29:14 +01:00
|
|
|
|
2021-12-17 16:15:54 +01:00
|
|
|
p_enc->ops = &video_ops;
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int OpenAudioEncoder ( vlc_object_t *p_this )
|
|
|
|
{
|
|
|
|
encoder_t *p_enc = (encoder_t *)p_this;
|
|
|
|
|
|
|
|
msg_Dbg( p_this, "opening stats encoder" );
|
|
|
|
|
|
|
|
static const struct vlc_encoder_operations audio_ops =
|
|
|
|
{ .encode_audio = EncodeAudio };
|
|
|
|
|
|
|
|
p_enc->ops = &audio_ops;
|
2013-03-09 15:29:14 +01:00
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
2013-03-09 15:30:46 +01:00
|
|
|
#endif
|
2013-03-09 15:29:14 +01:00
|
|
|
|
2013-03-09 15:30:46 +01:00
|
|
|
/*** Demuxer ***/
|
2018-04-27 22:10:57 +02:00
|
|
|
typedef struct
|
2013-03-09 15:29:14 +01:00
|
|
|
{
|
|
|
|
es_format_t fmt;
|
|
|
|
es_out_id_t *p_es;
|
|
|
|
|
|
|
|
date_t pts;
|
2018-04-27 22:10:57 +02:00
|
|
|
} demux_sys_t;
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
static int Demux( demux_t *p_demux )
|
|
|
|
{
|
|
|
|
demux_sys_t *p_sys = p_demux->p_sys;
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
block_t * p_block = vlc_stream_Block( p_demux->s, kBufferSize );
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
if( !p_block ) return 1;
|
|
|
|
|
2018-05-25 09:54:21 +02:00
|
|
|
p_block->i_dts = p_block->i_pts = date_Increment( &p_sys->pts, kBufferSize );
|
2013-03-09 15:29:14 +01:00
|
|
|
|
2017-07-30 20:11:31 +02:00
|
|
|
msg_Dbg( p_demux, "demux got %"PRId64" ms offset",
|
2018-06-06 12:25:34 +02:00
|
|
|
MS_FROM_VLC_TICK(vlc_tick_now() - *(vlc_tick_t *)p_block->p_buffer) );
|
2013-03-09 15:29:14 +01:00
|
|
|
|
2017-07-30 19:35:31 +02:00
|
|
|
//es_out_SetPCR( p_demux->out, p_block->i_pts );
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
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 */
|
2017-12-02 22:05:58 +01:00
|
|
|
if( *p_demux->psz_name == '\0' )
|
2013-03-09 15:29:14 +01:00
|
|
|
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 );
|
2018-07-02 15:52:19 +02:00
|
|
|
date_Set( &p_sys->pts, VLC_TICK_0 );
|
2013-03-09 15:29:14 +01:00
|
|
|
|
|
|
|
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"))
|
2013-03-09 15:30:46 +01:00
|
|
|
#ifdef ENABLE_SOUT
|
2013-03-09 15:29:14 +01:00
|
|
|
set_description( N_("Stats encoder function") )
|
2021-12-17 11:57:31 +01:00
|
|
|
set_capability( "video encoder", 0 )
|
2013-03-09 15:29:14 +01:00
|
|
|
add_shortcut( "stats" )
|
2021-12-17 16:15:54 +01:00
|
|
|
set_callback( OpenVideoEncoder )
|
2021-12-17 11:57:31 +01:00
|
|
|
|
|
|
|
add_submodule ()
|
|
|
|
set_description( N_("Stats encoder function") )
|
|
|
|
set_capability( "audio encoder", 0 )
|
|
|
|
add_shortcut( "stats" )
|
2021-12-17 16:15:54 +01:00
|
|
|
set_callback( OpenAudioEncoder )
|
2021-12-17 11:57:31 +01:00
|
|
|
|
2013-03-09 15:29:14 +01:00
|
|
|
add_submodule ()
|
2013-03-09 15:30:46 +01:00
|
|
|
#endif
|
2013-03-09 15:29:14 +01:00
|
|
|
set_section( N_( "Stats decoder" ), NULL )
|
|
|
|
set_description( N_("Stats decoder function") )
|
2017-06-19 19:50:34 +02:00
|
|
|
set_capability( "video decoder", 0 )
|
2013-03-09 15:29:14 +01:00
|
|
|
add_shortcut( "stats" )
|
2019-07-17 21:59:02 +02:00
|
|
|
set_callback( OpenDecoder )
|
2017-06-19 19:40:18 +02:00
|
|
|
add_submodule()
|
|
|
|
set_section( N_( "Stats decoder" ), NULL )
|
|
|
|
set_description( N_("Stats decoder function") )
|
|
|
|
set_capability( "audio decoder", 0 )
|
|
|
|
add_shortcut( "stats" )
|
2019-07-17 21:59:02 +02:00
|
|
|
set_callback( OpenDecoder )
|
2017-06-19 19:50:34 +02:00
|
|
|
add_submodule()
|
|
|
|
set_section( N_( "Stats decoder" ), NULL )
|
|
|
|
set_description( N_("Stats decoder function") )
|
2017-06-19 19:50:34 +02:00
|
|
|
set_capability( "spu decoder", 0 )
|
2017-06-19 19:50:34 +02:00
|
|
|
add_shortcut( "stats" )
|
2019-07-17 21:59:02 +02:00
|
|
|
set_callback( OpenDecoder )
|
2013-03-09 15:29:14 +01:00
|
|
|
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 ()
|