demux: mp4: use struct for coreaudio layout params
[vlc.git] / modules / demux / cdg.c
blobe2aa8eaa4b3774ca0c340b1b045988b8700c3bed
1 /*****************************************************************************
2 * cdg.c : cdg file demux module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir # via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_demux.h>
36 /*****************************************************************************
37 * Module descriptor
38 *****************************************************************************/
39 static int Open ( vlc_object_t * );
41 vlc_module_begin ()
42 set_description( N_("CDG demuxer") )
43 set_category( CAT_INPUT )
44 set_subcategory( SUBCAT_INPUT_DEMUX )
45 set_capability( "demux", 3 )
46 set_callbacks( Open, NULL )
47 add_shortcut( "cdg", "subtitle" )
48 vlc_module_end ()
50 /*****************************************************************************
51 * Local prototypes
52 *****************************************************************************/
53 static int Demux ( demux_t * );
54 static int Control( demux_t *, int i_query, va_list args );
56 typedef struct
58 es_format_t fmt;
59 es_out_id_t *p_es;
61 date_t pts;
62 } demux_sys_t;
64 #define CDG_FRAME_SIZE (96)
65 #define CDG_FRAME_RATE (75)
66 #define CDG_FRAME_DELTA (CLOCK_FREQ / CDG_FRAME_RATE)
68 /*****************************************************************************
69 * Open: check file and initializes structures
70 *****************************************************************************/
71 static int Open( vlc_object_t * p_this )
73 demux_t *p_demux = (demux_t*)p_this;
75 /* Identify cdg file by extension, as there is no simple way to
76 * detect it */
77 if( !demux_IsPathExtension( p_demux, ".cdg" ) && !demux_IsForced( p_demux, "cdg" ) )
78 return VLC_EGENERIC;
80 /* CDG file size has to be multiple of CDG_FRAME_SIZE (it works even
81 * if size is unknown ie 0) */
82 // if( (stream_Size( p_demux->s ) % CDG_FRAME_SIZE) != 0 )
83 // {
84 // msg_Err( p_demux, "Reject CDG file based on its size" );
85 // return VLC_EGENERIC;
86 // }
88 demux_sys_t *p_sys = vlc_obj_malloc( p_this, sizeof (*p_sys) );
89 if( unlikely(p_sys == NULL) )
90 return VLC_ENOMEM;
92 es_format_Init( &p_sys->fmt, VIDEO_ES, VLC_CODEC_CDG );
93 p_sys->fmt.video.i_width = 300-2*6;
94 p_sys->fmt.video.i_height = 216-2*12 ;
95 p_sys->fmt.video.i_visible_width = p_sys->fmt.video.i_width;
96 p_sys->fmt.video.i_visible_height = p_sys->fmt.video.i_height;
98 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
99 if( unlikely(p_sys->p_es == NULL) )
100 return VLC_ENOMEM;
102 /* There is CDG_FRAME_RATE frames per second */
103 date_Init( &p_sys->pts, CDG_FRAME_RATE, 1 );
104 date_Set( &p_sys->pts, VLC_TICK_0 );
106 p_demux->pf_demux = Demux;
107 p_demux->pf_control = Control;
108 p_demux->p_sys = p_sys;
109 return VLC_SUCCESS;
112 static vlc_tick_t PosToDate( demux_t *p_demux )
114 return vlc_stream_Tell( p_demux->s ) / CDG_FRAME_SIZE * CDG_FRAME_DELTA;
117 /*****************************************************************************
118 * Demux: read packet and send them to decoders
119 *****************************************************************************
120 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
121 *****************************************************************************/
122 static int Demux( demux_t *p_demux )
124 demux_sys_t *p_sys = p_demux->p_sys;
125 block_t *p_block;
126 vlc_tick_t i_date;
128 p_block = vlc_stream_Block( p_demux->s, CDG_FRAME_SIZE );
129 if( p_block == NULL )
131 msg_Dbg( p_demux, "cannot read data, eof" );
132 return VLC_DEMUXER_EOF;
135 i_date = PosToDate( p_demux );
136 if( i_date >= date_Get( &p_sys->pts ) + CDG_FRAME_DELTA )
138 p_block->i_dts = p_block->i_pts = VLC_TICK_0 + i_date;
139 date_Set( &p_sys->pts, VLC_TICK_0 + i_date );
141 else
143 p_block->i_dts = VLC_TICK_0 + i_date;
144 p_block->i_pts = date_Get( &p_sys->pts );
147 es_out_SetPCR( p_demux->out, p_block->i_pts );
148 es_out_Send( p_demux->out, p_sys->p_es, p_block );
149 return VLC_DEMUXER_SUCCESS;
152 /*****************************************************************************
153 * Control:
154 *****************************************************************************/
155 static int Control( demux_t *p_demux, int i_query, va_list args )
157 demux_sys_t *p_sys = p_demux->p_sys;
158 uint64_t i_old_offset = vlc_stream_Tell( p_demux->s );
159 int i_ret = demux_vaControlHelper( p_demux->s, 0, -1,
160 8*CDG_FRAME_SIZE*CDG_FRAME_RATE, CDG_FRAME_SIZE,
161 i_query, args );
162 if( !i_ret && ( i_query == DEMUX_SET_POSITION || i_query == DEMUX_SET_TIME ) )
164 date_Set( &p_sys->pts, PosToDate( p_demux ) );
165 if ( i_old_offset > vlc_stream_Tell( p_demux->s ) )
166 i_ret = vlc_stream_Seek( p_demux->s, 0 );
167 else
168 i_ret = vlc_stream_Seek( p_demux->s, i_old_offset );
171 return i_ret;