]> git.sesse.net Git - vlc/blob - modules/demux/vobsub.c
* One more fix for vobsubs with negative times
[vlc] / modules / demux / vobsub.c
1 /*****************************************************************************
2  * subtitle.c: Demux vobsub files.
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Derk-Jan Hartman <hartman at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <sys/types.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/input.h>
34 #include "vlc_video.h"
35
36 #include "ps.h"
37
38 #define MAX_LINE 8192
39
40 /*****************************************************************************
41  * Module descriptor
42  *****************************************************************************/
43 static int  Open ( vlc_object_t *p_this );
44 static void Close( vlc_object_t *p_this );
45
46 vlc_module_begin();
47     set_description( _("Vobsub subtitles demux") );
48     set_category( CAT_INPUT );
49     set_subcategory( SUBCAT_INPUT_DEMUX );
50     set_capability( "demux2", 1 );
51     
52     set_callbacks( Open, Close );
53
54     add_shortcut( "vobsub" );
55     add_shortcut( "subtitle" );
56 vlc_module_end();
57
58 /*****************************************************************************
59  * Prototypes:
60  *****************************************************************************/
61
62 typedef struct
63 {
64     int     i_line_count;
65     int     i_line;
66     char    **line;
67 } text_t;
68 static int  TextLoad( text_t *, stream_t *s );
69 static void TextUnload( text_t * );
70
71 typedef struct
72 {
73     int64_t i_start;
74     int     i_vobsub_location;
75 } subtitle_t;
76
77 typedef struct
78 {
79     es_format_t fmt;
80     es_out_id_t *p_es;
81     int         i_track_id;
82     
83     int         i_current_subtitle;
84     int         i_subtitles;
85     subtitle_t  *p_subtitles;
86
87     int64_t     i_delay;
88 } vobsub_track_t;
89
90 struct demux_sys_t
91 {
92     int64_t     i_next_demux_date;
93     int64_t     i_length;
94
95     text_t      txt;
96     FILE        *p_vobsub_file;
97     
98     /* all tracks */
99     int            i_tracks;
100     vobsub_track_t *track;
101     
102     int         i_original_frame_width;
103     int         i_original_frame_height;
104     vlc_bool_t  b_palette;
105     uint32_t    palette[16];
106 };
107
108 static int Demux( demux_t * );
109 static int Control( demux_t *, int, va_list );
110
111 static int ParseVobSubIDX( demux_t * );
112 static int DemuxVobSub( demux_t *, block_t *);
113
114 /*****************************************************************************
115  * Module initializer
116  *****************************************************************************/
117 static int Open ( vlc_object_t *p_this )
118 {
119     demux_t     *p_demux = (demux_t*)p_this;
120     demux_sys_t *p_sys;
121     char *psz_vobname, *s;
122     int i_len;
123
124     if( ( s = stream_ReadLine( p_demux->s ) ) != NULL )
125     {
126         if( !strcasestr( s, "# VobSub index file" ) )
127         {
128             msg_Dbg( p_demux, "this doesn't seem to be a vobsub file" );
129             free( s );
130             if( stream_Seek( p_demux->s, 0 ) )
131             {
132                 msg_Warn( p_demux, "failed to rewind" );
133             }
134             return VLC_EGENERIC;
135         }
136         free( s );
137
138     }
139     else
140     {
141         msg_Dbg( p_demux, "could not read vobsub IDX file" );
142         return VLC_EGENERIC;
143     }
144
145     p_demux->pf_demux = Demux;
146     p_demux->pf_control = Control;
147     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
148     p_sys->i_length = 0;
149     p_sys->p_vobsub_file = NULL;
150     p_sys->i_tracks = 0;
151     p_sys->track = (vobsub_track_t *)malloc( sizeof( vobsub_track_t ) );
152     p_sys->i_original_frame_width = -1;
153     p_sys->i_original_frame_height = -1;
154     p_sys->b_palette = VLC_FALSE;
155     memset( p_sys->palette, 0, 16 * sizeof( uint32_t ) );
156
157     /* Load the whole file */
158     TextLoad( &p_sys->txt, p_demux->s );
159
160     /* Parse it */
161     ParseVobSubIDX( p_demux );
162
163     /* Unload */
164     TextUnload( &p_sys->txt );
165
166     /* Find the total length of the vobsubs */
167     if( p_sys->i_tracks > 0 )
168     {
169         int i;
170         for( i = 0; i < p_sys->i_tracks; i++ )
171         {
172             if( p_sys->track[i].i_subtitles > 1 )
173             {
174                 if( p_sys->track[i].p_subtitles[p_sys->track[i].i_subtitles-1].i_start > p_sys->i_length )
175                     p_sys->i_length = (int64_t) p_sys->track[i].p_subtitles[p_sys->track[i].i_subtitles-1].i_start + ( 1 *1000 *1000 );
176             }
177         }
178     }
179
180     i_len = strlen( p_demux->psz_path );
181     psz_vobname = strdup( p_demux->psz_path );
182
183     strcpy( psz_vobname + i_len - 4, ".sub" );
184
185     /* open file */
186     if( !( p_sys->p_vobsub_file = fopen( psz_vobname, "rb" ) ) )
187     {
188         msg_Err( p_demux, "couldn't open .sub Vobsub file: %s",
189                  psz_vobname );
190         free( p_sys );
191         free( psz_vobname );
192         return VLC_EGENERIC;
193     }
194     free( psz_vobname );
195
196     return VLC_SUCCESS;
197 }
198
199 /*****************************************************************************
200  * Close: Close subtitle demux
201  *****************************************************************************/
202 static void Close( vlc_object_t *p_this )
203 {
204     int i;
205     demux_t *p_demux = (demux_t*)p_this;
206     demux_sys_t *p_sys = p_demux->p_sys;
207
208     /* Clean all subs from all tracks */
209     for( i = 0; i < p_sys->i_tracks; i++ )
210     {
211         if( p_sys->track[i].p_subtitles ) free( p_sys->track[i].p_subtitles );
212     }
213     if( p_sys->track ) free( p_sys->track );
214     
215     if( p_sys->p_vobsub_file )
216         fclose( p_sys->p_vobsub_file );
217
218     free( p_sys );
219 }
220
221 /*****************************************************************************
222  * Control:
223  *****************************************************************************/
224 static int Control( demux_t *p_demux, int i_query, va_list args )
225 {
226     demux_sys_t *p_sys = p_demux->p_sys;
227     int64_t *pi64, i64;
228     int i;
229     double *pf, f;
230
231     switch( i_query )
232     {
233         case DEMUX_GET_LENGTH:
234             pi64 = (int64_t*)va_arg( args, int64_t * );
235             *pi64 = (int64_t) p_sys->i_length;
236             return VLC_SUCCESS;
237
238         case DEMUX_GET_TIME:
239             pi64 = (int64_t*)va_arg( args, int64_t * );
240             for( i = 0; i < p_sys->i_tracks; i++ )
241             {
242                 vlc_bool_t b_selected;
243                 /* Check the ES is selected */
244                 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
245                                 p_sys->track[i].p_es, &b_selected );
246                 if( b_selected ) break;
247             }
248             if( i < p_sys->i_tracks && p_sys->track[i].i_current_subtitle < p_sys->track[i].i_subtitles )
249             {
250                 *pi64 = p_sys->track[i].p_subtitles[p_sys->track[i].i_current_subtitle].i_start;
251                 return VLC_SUCCESS;
252             }
253             return VLC_EGENERIC;
254
255         case DEMUX_SET_TIME:
256             i64 = (int64_t)va_arg( args, int64_t );
257             for( i = 0; i < p_sys->i_tracks; i++ )
258             {
259                 p_sys->track[i].i_current_subtitle = 0;
260                 while( p_sys->track[i].i_current_subtitle < p_sys->track[i].i_subtitles &&
261                        p_sys->track[i].p_subtitles[p_sys->track[i].i_current_subtitle].i_start < i64 )
262                 {
263                     p_sys->track[i].i_current_subtitle++;
264                 }
265
266                 if( p_sys->track[i].i_current_subtitle >= p_sys->track[i].i_subtitles )
267                     return VLC_EGENERIC;
268             }
269             return VLC_SUCCESS;
270
271         case DEMUX_GET_POSITION:
272             pf = (double*)va_arg( args, double * );
273             for( i = 0; i < p_sys->i_tracks; i++ )
274             {
275                 vlc_bool_t b_selected;
276                 /* Check the ES is selected */
277                 es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
278                                 p_sys->track[i].p_es, &b_selected );
279                 if( b_selected ) break;
280             }
281             if( p_sys->track[i].i_current_subtitle >= p_sys->track[i].i_subtitles )
282             {
283                 *pf = 1.0;
284             }
285             else if( p_sys->track[i].i_subtitles > 0 )
286             {
287                 *pf = (double)p_sys->track[i].p_subtitles[p_sys->track[i].i_current_subtitle].i_start /
288                       (double)p_sys->i_length;
289             }
290             else
291             {
292                 *pf = 0.0;
293             }
294             return VLC_SUCCESS;
295
296         case DEMUX_SET_POSITION:
297             f = (double)va_arg( args, double );
298             i64 = (int64_t) f * p_sys->i_length;
299
300             for( i = 0; i < p_sys->i_tracks; i++ )
301             {
302                 p_sys->track[i].i_current_subtitle = 0;
303                 while( p_sys->track[i].i_current_subtitle < p_sys->track[i].i_subtitles &&
304                        p_sys->track[i].p_subtitles[p_sys->track[i].i_current_subtitle].i_start < i64 )
305                 {
306                     p_sys->track[i].i_current_subtitle++;
307                 }
308                 if( p_sys->track[i].i_current_subtitle >= p_sys->track[i].i_subtitles )
309                     return VLC_EGENERIC;
310             }
311             return VLC_SUCCESS;
312
313         case DEMUX_SET_NEXT_DEMUX_TIME:
314             p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
315             return VLC_SUCCESS;
316
317         case DEMUX_GET_FPS:
318         case DEMUX_GET_META:
319         case DEMUX_GET_TITLE_INFO:
320             return VLC_EGENERIC;
321
322         default:
323             msg_Err( p_demux, "unknown query in subtitle control" );
324             return VLC_EGENERIC;
325     }
326 }
327
328 /*****************************************************************************
329  * Demux: Send subtitle to decoder
330  *****************************************************************************/
331 static int Demux( demux_t *p_demux )
332 {
333     demux_sys_t *p_sys = p_demux->p_sys;
334     int64_t i_maxdate;
335     int i;
336
337     for( i = 0; i < p_sys->i_tracks; i++ )
338     {
339 #define tk p_sys->track[i]
340         if( tk.i_current_subtitle >= tk.i_subtitles )
341             continue;
342
343         i_maxdate = (int64_t) p_sys->i_next_demux_date;
344         if( i_maxdate <= 0 && tk.i_current_subtitle < tk.i_subtitles )
345         {
346             /* Should not happen */
347             i_maxdate = (int64_t) tk.p_subtitles[tk.i_current_subtitle].i_start + 1;
348         }
349
350         while( tk.i_current_subtitle < tk.i_subtitles &&
351                tk.p_subtitles[tk.i_current_subtitle].i_start < i_maxdate )
352         {
353             int i_pos = tk.p_subtitles[tk.i_current_subtitle].i_vobsub_location;
354             block_t *p_block;
355             int i_size = 0;
356
357             /* first compute SPU size */
358             if( tk.i_current_subtitle + 1 < tk.i_subtitles )
359             {
360                 i_size = tk.p_subtitles[tk.i_current_subtitle+1].i_vobsub_location - i_pos;
361             }
362             if( i_size <= 0 ) i_size = 65535;   /* Invalid or EOF */
363
364             /* Seek at the right place */
365             if( fseek( p_sys->p_vobsub_file, i_pos, SEEK_SET ) )
366             {
367                 msg_Warn( p_demux,
368                           "cannot seek at right vobsub location %d", i_pos );
369                 tk.i_current_subtitle++;
370                 continue;
371             }
372
373             /* allocate a packet */
374             if( ( p_block = block_New( p_demux, i_size ) ) == NULL )
375             {
376                 tk.i_current_subtitle++;
377                 continue;
378             }
379
380             /* read data */
381             p_block->i_buffer = fread( p_block->p_buffer, 1, i_size,
382                                        p_sys->p_vobsub_file );
383             if( p_block->i_buffer <= 6 )
384             {
385                 block_Release( p_block );
386                 tk.i_current_subtitle++;
387                 continue;
388             }
389
390             /* pts */
391             p_block->i_pts = tk.p_subtitles[tk.i_current_subtitle].i_start;
392
393             /* demux this block */
394             DemuxVobSub( p_demux, p_block );
395
396             tk.i_current_subtitle++;
397         }
398 #undef tk
399     }
400
401     /* */
402     p_sys->i_next_demux_date = 0;
403
404     return 1;
405 }
406
407 static int TextLoad( text_t *txt, stream_t *s )
408 {
409     int   i_line_max;
410
411     /* init txt */
412     i_line_max          = 500;
413     txt->i_line_count   = 0;
414     txt->i_line         = 0;
415     txt->line           = calloc( i_line_max, sizeof( char * ) );
416
417     /* load the complete file */
418     for( ;; )
419     {
420         char *psz = stream_ReadLine( s );
421
422         if( psz == NULL )
423             break;
424
425         txt->line[txt->i_line_count++] = psz;
426         if( txt->i_line_count >= i_line_max )
427         {
428             i_line_max += 100;
429             txt->line = realloc( txt->line, i_line_max * sizeof( char*) );
430         }
431     }
432
433     if( txt->i_line_count <= 0 )
434     {
435         if( txt->line ) free( txt->line );
436         return VLC_EGENERIC;
437     }
438
439     return VLC_SUCCESS;
440 }
441 static void TextUnload( text_t *txt )
442 {
443     int i;
444
445     for( i = 0; i < txt->i_line_count; i++ )
446     {
447         if( txt->line[i] ) free( txt->line[i] );
448     }
449     if( txt->line ) free( txt->line );
450     txt->i_line       = 0;
451     txt->i_line_count = 0;
452 }
453
454 static char *TextGetLine( text_t *txt )
455 {
456     if( txt->i_line >= txt->i_line_count )
457         return( NULL );
458
459     return txt->line[txt->i_line++];
460 }
461
462 static int ParseVobSubIDX( demux_t *p_demux )
463 {
464     demux_sys_t *p_sys = p_demux->p_sys;
465     text_t      *txt = &p_sys->txt;
466     char        *line;
467     vobsub_track_t *current_tk;
468
469     for( ;; )
470     {
471         if( ( line = TextGetLine( txt ) ) == NULL )
472         {
473             return( VLC_EGENERIC );
474         }
475         
476         if( *line == 0 || *line == '\r' || *line == '\n' || *line == '#' ) 
477             continue;
478         else if( !strncmp( "size:", line, 5 ) )
479         {
480             /* Store the original size of the video */
481             if( sscanf( line, "size: %dx%d",
482                         &p_sys->i_original_frame_width, &p_sys->i_original_frame_height ) == 2 )
483             {
484                 msg_Dbg( p_demux, "original frame size: %dx%d", p_sys->i_original_frame_width, p_sys->i_original_frame_height );
485             }
486             else
487             {
488                 msg_Warn( p_demux, "reading original frame size failed" );
489             }
490         }
491         else if( !strncmp( "palette:", line, 8 ) )
492         {
493             int i;
494
495             /* Store the palette of the subs */
496             if( sscanf( line, "palette: %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x, %x",
497                         &p_sys->palette[0], &p_sys->palette[1], &p_sys->palette[2], &p_sys->palette[3], 
498                         &p_sys->palette[4], &p_sys->palette[5], &p_sys->palette[6], &p_sys->palette[7], 
499                         &p_sys->palette[8], &p_sys->palette[9], &p_sys->palette[10], &p_sys->palette[11], 
500                         &p_sys->palette[12], &p_sys->palette[13], &p_sys->palette[14], &p_sys->palette[15] ) == 16 )
501             {
502                 for( i = 0; i < 16; i++ )
503                 {
504                     uint8_t r = 0, g = 0, b = 0;
505                     uint8_t y = 0, u = 0, v = 0;
506                     r = (p_sys->palette[i] >> 16) & 0xff;
507                     g = (p_sys->palette[i] >> 8) & 0xff;
508                     b = (p_sys->palette[i] >> 0) & 0xff;
509                     /* msg_Dbg( p_demux, "palette %d: R=%x, G=%x, B=%x", i, r, g, b ); */
510                     y = (uint8_t) __MIN(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);
511                     u = (uint8_t) __MIN(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);
512                     v = (uint8_t) __MIN(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
513                     p_sys->palette[i] = 0;
514                     p_sys->palette[i] |= (y&0xff)<<16;
515                     p_sys->palette[i] |= (u&0xff);
516                     p_sys->palette[i] |= (v&0xff)<<8;
517                     /* msg_Dbg( p_demux, "palette %d: y=%x, u=%x, v=%x", i, y, u, v ); */
518
519                 }
520                 p_sys->b_palette = VLC_TRUE;
521                 msg_Dbg( p_demux, "vobsub palette read" );
522             }
523             else
524             {
525                 msg_Warn( p_demux, "reading original palette failed" );
526             }
527         }
528         else if( !strncmp( "id:", line, 3 ) )
529         {
530             char language[20];
531             int i_track_id;
532             es_format_t fmt;
533
534             /* Lets start a new track */
535             if( sscanf( line, "id: %2s, index: %d",
536                         language, &i_track_id ) == 2 )
537             {
538                 p_sys->i_tracks++;
539                 p_sys->track = (vobsub_track_t*)realloc( p_sys->track, sizeof( vobsub_track_t ) * (p_sys->i_tracks + 1 ) );
540
541                 /* Init the track */
542                 current_tk = &p_sys->track[p_sys->i_tracks - 1];
543                 memset( current_tk, 0, sizeof( vobsub_track_t ) );
544                 current_tk->i_current_subtitle = 0;
545                 current_tk->i_subtitles = 0;
546                 current_tk->p_subtitles = (subtitle_t*)malloc( sizeof( subtitle_t ) );;
547                 current_tk->i_track_id = i_track_id;
548                 current_tk->i_delay = (int64_t)0;
549                 
550                 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
551                 fmt.subs.spu.i_original_frame_width = p_sys->i_original_frame_width;
552                 fmt.subs.spu.i_original_frame_height = p_sys->i_original_frame_height;
553                 fmt.psz_language = strdup( language );
554                 if( p_sys->b_palette )
555                 {
556                     fmt.subs.spu.palette[0] = 0xBeef;
557                     memcpy( &fmt.subs.spu.palette[1], p_sys->palette, 16 * sizeof( uint32_t ) );
558                 }
559
560                 current_tk->p_es = es_out_Add( p_demux->out, &fmt );
561                 msg_Dbg( p_demux, "new vobsub track detected" );
562             }
563             else
564             {
565                 msg_Warn( p_demux, "reading new track failed" );
566             }
567         }
568         else if( !strncmp( line, "timestamp:", 10 ) )
569         {
570             /*
571              * timestamp: [sign]hh:mm:ss:mss, filepos: loc
572              * loc is the hex location of the spu in the .sub file
573              */
574             int h, m, s, ms, count, loc = 0;
575             int i_sign = 1;
576             int64_t i_start, i_location = 0;
577             
578             vobsub_track_t *current_tk = &p_sys->track[p_sys->i_tracks - 1];
579
580             if( sscanf( line, "timestamp: %d%n:%d:%d:%d, filepos: %x",
581                         &h, &count, &m, &s, &ms, &loc ) >= 5  )
582             {
583                 subtitle_t *current_sub;
584
585                 if( line[count-3] == '-' )
586                 {
587                     i_sign = -1;
588                     h = -h;
589                 }
590                 i_start = (int64_t) ( h * 3600*1000 +
591                             m * 60*1000 +
592                             s * 1000 +
593                             ms ) * 1000;
594                 i_location = loc;
595                 
596                 current_tk->i_subtitles++;
597                 current_tk->p_subtitles = (subtitle_t*)realloc( current_tk->p_subtitles, sizeof( subtitle_t ) * (current_tk->i_subtitles + 1 ) );
598                 current_sub = &current_tk->p_subtitles[current_tk->i_subtitles - 1];
599                 
600                 current_sub->i_start = (int64_t) i_start * i_sign;
601                 current_sub->i_start += current_tk->i_delay;
602                 current_sub->i_vobsub_location = i_location;
603             }
604         }
605         else if( !strncmp( line, "delay:", 6 ) )
606         {
607             /*
608              * delay: [sign]hh:mm:ss:mss
609              */
610             int h, m, s, ms, count = 0;
611             int i_sign = 1;
612             int64_t i_gap = 0;
613
614             vobsub_track_t *current_tk = &p_sys->track[p_sys->i_tracks - 1];
615
616             if( sscanf( line, "delay: %d%n:%d:%d:%d",
617                         &h, &count, &m, &s, &ms ) >= 4 )
618             {
619                 if( line[count-3] == '-' )
620                 {
621                     i_sign = -1;
622                     h = -h;
623                 }
624                 i_gap = (int64_t) ( h * 3600*1000 +
625                             m * 60*1000 +
626                             s * 1000 +
627                             ms ) * 1000;
628
629                 current_tk->i_delay = current_tk->i_delay + (i_gap * i_sign);
630                 msg_Dbg( p_demux, "sign: %+d gap: %+lld global delay: %+lld", i_sign, i_gap, current_tk->i_delay  );
631             }
632         }
633     }
634     return( 0 );
635 }
636
637 static int DemuxVobSub( demux_t *p_demux, block_t *p_bk )
638 {
639     demux_sys_t *p_sys = p_demux->p_sys;
640     uint8_t     *p = p_bk->p_buffer;
641     uint8_t     *p_end = &p_bk->p_buffer[p_bk->i_buffer];
642     int i;
643
644     while( p < p_end )
645     {
646         int i_size = ps_pkt_size( p, p_end - p );
647         block_t *p_pkt;
648         int      i_id;
649         int      i_spu;
650
651         if( i_size <= 0 )
652         {
653             break;
654         }
655         if( p[0] != 0 || p[1] != 0 || p[2] != 0x01 )
656         {
657             msg_Warn( p_demux, "invalid PES" );
658             break;
659         }
660
661         if( p[3] != 0xbd )
662         {
663             /* msg_Dbg( p_demux, "we don't need these ps packets (id=0x1%2.2x)", p[3] ); */
664             p += i_size;
665             continue;
666         }
667
668         /* Create a block */
669         p_pkt = block_New( p_demux, i_size );
670         memcpy( p_pkt->p_buffer, p, i_size);
671         p += i_size;
672
673         i_id = ps_pkt_id( p_pkt );
674         if( (i_id&0xffe0) != 0xbd20 ||
675             ps_pkt_parse_pes( p_pkt, 1 ) )
676         {
677             block_Release( p_pkt );
678             continue;
679         }
680         i_spu = i_id&0x1f;
681         /* msg_Dbg( p_demux, "SPU track %d size %d", i_spu, i_size ); */
682
683         for( i = 0; i < p_sys->i_tracks; i++ )
684         {
685 #define tk p_sys->track[i]
686             p_pkt->i_dts = p_pkt->i_pts = p_bk->i_pts;
687             p_pkt->i_length = 0;
688             
689             if( tk.p_es && tk.i_track_id == i_spu )
690             {
691                 es_out_Send( p_demux->out, tk.p_es, p_pkt );
692                 p_bk->i_pts = 0;     /*only first packet has a pts */
693                 break;
694             }
695             else if( i == p_sys->i_tracks - 1 )
696             {
697                 block_Release( p_pkt );
698             }
699 #undef tk
700         }
701     }
702
703     return VLC_SUCCESS;
704 }