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 *****************************************************************************/
29 #include <vlc_demux.h>
31 #include <vlc_codecs.h>
33 /*****************************************************************************
35 *****************************************************************************/
36 static int Open ( vlc_object_t * );
37 static void Close( vlc_object_t * );
40 set_description( _("CDG demuxer") );
41 set_category( CAT_INPUT );
42 set_subcategory( SUBCAT_INPUT_DEMUX );
43 set_capability( "demux2", 3 );
44 set_callbacks( Open, Close );
45 add_shortcut( "cdg" );
46 add_shortcut( "subtitle" );
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Demux ( demux_t * );
53 static int Control( demux_t *, int i_query, va_list args );
63 #define CDG_FRAME_SIZE (96)
64 #define CDG_FRAME_RATE (75)
66 /*****************************************************************************
67 * Open: check file and initializes structures
68 *****************************************************************************/
69 static int Open( vlc_object_t * p_this )
71 demux_t *p_demux = (demux_t*)p_this;
74 /* Identify cdg file by extension, as there is no simple way to
76 if( !demux2_IsPathExtension( p_demux, ".cdg" ) && !demux2_IsForced( p_demux, "cdg" ) )
79 /* CDG file size has to be multiple of CDG_FRAME_SIZE (it works even
80 * if size is unknown ie 0) */
81 // if( (stream_Size( p_demux->s ) % CDG_FRAME_SIZE) != 0 )
83 // msg_Err( p_demux, "Reject CDG file based on its size" );
84 // return VLC_EGENERIC;
87 p_demux->pf_demux = Demux;
88 p_demux->pf_control = Control;
89 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
92 es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_FOURCC('C','D','G', ' ' ) );
93 p_sys->fmt.video.i_width = 300-2*6;
94 p_sys->fmt.video.i_height = 216-2*12 ;
96 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
98 /* There is CDG_FRAME_RATE frames per second */
99 date_Init( &p_sys->pts, CDG_FRAME_RATE, 1 );
100 date_Set( &p_sys->pts, 1 );
105 /*****************************************************************************
106 * Demux: read packet and send them to decoders
107 *****************************************************************************
108 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
109 *****************************************************************************/
110 static int Demux( demux_t *p_demux )
112 demux_sys_t *p_sys = p_demux->p_sys;
115 p_block = stream_Block( p_demux->s, CDG_FRAME_SIZE );
116 if( p_block == NULL )
118 msg_Dbg( p_demux, "cannot read data, eof" );
123 p_block->i_pts = date_Increment( &p_sys->pts, 1 );
125 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
127 es_out_Send( p_demux->out, p_sys->p_es, p_block );
131 /*****************************************************************************
132 * Close: frees unused data
133 *****************************************************************************/
134 static void Close ( vlc_object_t * p_this )
136 demux_t *p_demux = (demux_t *)p_this;
137 demux_sys_t *p_sys = p_demux->p_sys;
142 /*****************************************************************************
144 *****************************************************************************/
145 static int Control( demux_t *p_demux, int i_query, va_list args )
150 return demux2_vaControlHelper( p_demux->s, 0, -1,
151 8*CDG_FRAME_SIZE*CDG_FRAME_RATE, CDG_FRAME_SIZE, i_query, args );