1 /*****************************************************************************
2 * cdg.c : cdg file demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir # via.ecp.fr>
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_demux.h>
36 #include <vlc_codecs.h>
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
45 set_description( N_("CDG demuxer") )
46 set_category( CAT_INPUT )
47 set_subcategory( SUBCAT_INPUT_DEMUX )
48 set_capability( "demux", 3 )
49 set_callbacks( Open, Close )
51 add_shortcut( "subtitle" )
54 /*****************************************************************************
56 *****************************************************************************/
57 static int Demux ( demux_t * );
58 static int Control( demux_t *, int i_query, va_list args );
68 #define CDG_FRAME_SIZE (96)
69 #define CDG_FRAME_RATE (75)
71 /*****************************************************************************
72 * Open: check file and initializes structures
73 *****************************************************************************/
74 static int Open( vlc_object_t * p_this )
76 demux_t *p_demux = (demux_t*)p_this;
79 /* Identify cdg file by extension, as there is no simple way to
81 if( !demux_IsPathExtension( p_demux, ".cdg" ) && !demux_IsForced( p_demux, "cdg" ) )
84 /* CDG file size has to be multiple of CDG_FRAME_SIZE (it works even
85 * if size is unknown ie 0) */
86 // if( (stream_Size( p_demux->s ) % CDG_FRAME_SIZE) != 0 )
88 // msg_Err( p_demux, "Reject CDG file based on its size" );
89 // return VLC_EGENERIC;
92 p_demux->pf_demux = Demux;
93 p_demux->pf_control = Control;
94 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
97 es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_CODEC_CDG );
98 p_sys->fmt.video.i_width = 300-2*6;
99 p_sys->fmt.video.i_height = 216-2*12 ;
101 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
103 /* There is CDG_FRAME_RATE frames per second */
104 date_Init( &p_sys->pts, CDG_FRAME_RATE, 1 );
105 date_Set( &p_sys->pts, 0 );
110 /*****************************************************************************
111 * Demux: read packet and send them to decoders
112 *****************************************************************************
113 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
114 *****************************************************************************/
115 static int Demux( demux_t *p_demux )
117 demux_sys_t *p_sys = p_demux->p_sys;
120 p_block = stream_Block( p_demux->s, CDG_FRAME_SIZE );
121 if( p_block == NULL )
123 msg_Dbg( p_demux, "cannot read data, eof" );
128 p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
130 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
132 es_out_Send( p_demux->out, p_sys->p_es, p_block );
134 date_Increment( &p_sys->pts, 1 );
139 /*****************************************************************************
140 * Close: frees unused data
141 *****************************************************************************/
142 static void Close ( vlc_object_t * p_this )
144 demux_t *p_demux = (demux_t *)p_this;
145 demux_sys_t *p_sys = p_demux->p_sys;
150 /*****************************************************************************
152 *****************************************************************************/
153 static int Control( demux_t *p_demux, int i_query, va_list args )
155 int i_ret = demux_vaControlHelper( p_demux->s, 0, -1,
156 8*CDG_FRAME_SIZE*CDG_FRAME_RATE, CDG_FRAME_SIZE,
158 if( !i_ret && ( i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME ) )
159 date_Set( &p_demux->p_sys->pts,
160 stream_Tell( p_demux->s ) / CDG_FRAME_SIZE *
161 INT64_C(1000000) / CDG_FRAME_RATE );