]> git.sesse.net Git - vlc/blob - modules/misc/stats/demux.c
89ebdc4941b57121c485a0cd93727807a4998945
[vlc] / modules / misc / stats / demux.c
1 /*****************************************************************************
2  * demux.c: stats demux plugin
3  *****************************************************************************
4  * Copyright (C) 2001-2008 the VideoLAN team
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Pierre d'Herbemont <pdherbemont@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
34 #include <vlc_access.h>
35 #include <vlc_demux.h>
36
37 #include "stats.h"
38
39
40 /*****************************************************************************
41  * Demux
42  *****************************************************************************/
43
44
45 struct demux_sys_t
46 {
47     es_format_t     fmt;
48     es_out_id_t     *p_es;
49
50     date_t          pts;
51 };
52
53 static int Demux( demux_t * );
54 static int DemuxControl( demux_t *, int, va_list );
55
56
57 /*****************************************************************************
58  * OpenDemux
59  *****************************************************************************/
60 int OpenDemux ( vlc_object_t *p_this )
61 {
62     demux_t *p_demux = (demux_t*)p_this;
63     demux_sys_t *p_sys;
64
65     p_demux->p_sys = NULL;
66
67     /* Only when selected */
68     if( *p_demux->psz_demux == '\0' )
69         return VLC_EGENERIC;
70
71     msg_Dbg( p_demux, "Init Stat demux" );
72
73     p_demux->pf_demux   = Demux;
74     p_demux->pf_control = DemuxControl;
75
76     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
77     if( !p_demux->p_sys )
78         return VLC_ENOMEM;
79
80     date_Init( &p_sys->pts, 1, 1 );
81     date_Set( &p_sys->pts, 1 );
82
83     es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('s','t','a','t') );
84     p_sys->fmt.video.i_width = 720;
85     p_sys->fmt.video.i_height= 480;
86
87     p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
88
89     return VLC_SUCCESS;
90 }
91
92 /*****************************************************************************
93  * CloseDemux
94  *****************************************************************************/
95 void CloseDemux ( vlc_object_t *p_this )
96 {
97     demux_t *p_demux = (demux_t*)p_this;
98
99     msg_Dbg( p_demux, "Closing Stat demux" );
100
101     free( p_demux->p_sys );
102 }
103
104 /*****************************************************************************
105  * Demux
106  *****************************************************************************/
107 static int Demux( demux_t *p_demux )
108 {
109     demux_sys_t *p_sys = p_demux->p_sys;
110
111     block_t * p_block = stream_Block( p_demux->s, kBufferSize );
112
113     if( !p_block ) return 1;
114
115     p_block->i_dts = p_block->i_pts =
116         date_Increment( &p_sys->pts, kBufferSize );
117
118     msg_Dbg( p_demux, "demux got %d ms offset", (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
119
120     //es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
121
122     es_out_Send( p_demux->out, p_sys->p_es, p_block );
123
124     return 1;
125 }
126
127 static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
128 {
129     return demux_vaControlHelper( p_demux->s,
130                                    0, 0, 0, 1,
131                                    i_query, args );
132 }