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