]> git.sesse.net Git - vlc/blob - plugins/spu_dec/spu_decoder.c
All decoders (audio, video, subtitles) are now modules.
[vlc] / plugins / spu_dec / spu_decoder.c
1 /*****************************************************************************
2  * spu_decoder.c : spu decoder thread
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  * $Id: spu_decoder.c,v 1.1 2001/11/13 12:09:18 henri Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #define MODULE_NAME spu_dec
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>                                              /* getpid() */
34 #endif
35
36 #ifdef WIN32                   /* getpid() for win32 is located in process.h */
37 #include <process.h>
38 #endif
39
40 #include <stdlib.h>                                      /* malloc(), free() */
41 #include <string.h>                                    /* memcpy(), memset() */
42
43 #include "config.h"
44 #include "common.h"
45 #include "threads.h"
46 #include "mtime.h"
47 #include "intf_msg.h"
48
49 #include "video.h"
50 #include "video_output.h"
51
52 #include "modules.h"
53 #include "modules_export.h"
54 #include "stream_control.h"
55 #include "input_ext-dec.h"
56
57 #include "spu_decoder.h"
58
59 /*****************************************************************************
60  * Local prototypes
61  *****************************************************************************/
62 static int spu_dec_Probe         ( probedata_t * );
63 static int  spu_dec_Run          ( decoder_config_t * );
64 static int  spu_dec_Init         ( spudec_thread_t * );
65 static void spu_dec_ErrorThread  ( spudec_thread_t * );
66 static void spu_dec_EndThread    ( spudec_thread_t * );
67
68 static int  SyncPacket           ( spudec_thread_t * );
69 static void ParsePacket          ( spudec_thread_t * );
70 static int  ParseControlSequences( spudec_thread_t *, subpicture_t * );
71 static int  ParseRLE             ( spudec_thread_t *, subpicture_t *, u8 * );
72
73 /*****************************************************************************
74  * Capabilities
75  *****************************************************************************/
76 void _M( spu_dec_getfunctions )( function_list_t * p_function_list )
77 {
78     p_function_list->pf_probe = spu_dec_Probe;
79     p_function_list->functions.dec.pf_RunThread = spu_dec_Run;
80 }
81
82 /*****************************************************************************
83  * Build configuration tree.
84  *****************************************************************************/
85 MODULE_CONFIG_START
86 ADD_WINDOW( "Configuration for SPU decoder module" )
87     ADD_COMMENT( "Nothing to configure" )
88 MODULE_CONFIG_STOP
89
90 MODULE_INIT_START
91     p_module->i_capabilities = MODULE_CAPABILITY_DEC;
92     p_module->psz_longname = "Subtitles decoder module";
93 MODULE_INIT_STOP
94
95 MODULE_ACTIVATE_START
96     _M( spu_dec_getfunctions )( &p_module->p_functions->dec );
97 MODULE_ACTIVATE_STOP
98
99 MODULE_DEACTIVATE_START
100 MODULE_DEACTIVATE_STOP
101
102 /*****************************************************************************
103  * spu_dec_Probe: probe the decoder and return score
104  *****************************************************************************
105  * Tries to launch a decoder and return score so that the interface is able 
106  * to chose.
107  *****************************************************************************/
108 static int spu_dec_Probe( probedata_t *p_data )
109 {
110     if( p_data->i_type == DVD_SPU_ES )
111         return( 50 );
112     else
113         return( 0 );
114 }
115
116 /*****************************************************************************
117  * spu_dec_Run: this function is called just after the thread is created
118  *****************************************************************************/
119 static int spu_dec_Run( decoder_config_t * p_config )
120 {
121     spudec_thread_t *     p_spudec;
122    
123     intf_WarnMsg( 3, "spudec: thread launched. Initializing ..." );
124
125     /* Allocate the memory needed to store the thread's structure */
126     p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) );
127
128     if ( p_spudec == NULL )
129     {
130         intf_ErrMsg( "spudec error: not enough memory "
131                      "for spudec_CreateThread() to create the new thread" );
132         return( -1 );
133     }
134     
135     /*
136      * Initialize the thread properties
137      */
138     p_spudec->p_config = p_config;
139
140     p_spudec->p_fifo = p_config->p_decoder_fifo;
141         
142     /*
143      * Initialize thread and free configuration
144      */
145     p_spudec->p_fifo->b_error = spu_dec_Init( p_spudec );
146
147     /*
148      * Main loop - it is not executed if an error occured during
149      * initialization
150      */
151     while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
152     {
153         if( !SyncPacket( p_spudec ) )
154         {
155             ParsePacket( p_spudec );
156         }
157     }
158
159     /*
160      * Error loop
161      */
162     if( p_spudec->p_fifo->b_error )
163     {
164         spu_dec_ErrorThread( p_spudec );
165     }
166
167     /* End of thread */
168     spu_dec_EndThread( p_spudec );
169
170     if( p_spudec->p_fifo->b_error )
171     {
172         return( -1 );
173     }
174    
175     return( 0 );
176
177 }
178
179 /* following functions are local */
180
181 /*****************************************************************************
182  * spu_dec_Init: initialize spu decoder thread
183  *****************************************************************************
184  * This function is called from RunThread and performs the second step of the
185  * initialization. It returns 0 on success. Note that the thread's flag are not
186  * modified inside this function.
187  *****************************************************************************/
188 static int spu_dec_Init( spudec_thread_t *p_spudec )
189 {
190     /* Spawn a video output if there is none */
191     vlc_mutex_lock( &p_vout_bank->lock );
192
193     if( p_vout_bank->i_count == 0 )
194     {
195         intf_WarnMsg( 1, "spudec: no vout present, spawning one" );
196
197         p_spudec->p_vout = vout_CreateThread( NULL, 0, 0 );
198
199         /* Everything failed */
200         if( p_spudec->p_vout == NULL )
201         {
202             intf_Msg( "spudec: can't open vout, aborting" );
203             vlc_mutex_unlock( &p_vout_bank->lock );
204             free( p_spudec );
205
206             return( -1 );
207         }
208
209         p_vout_bank->pp_vout[ p_vout_bank->i_count ] = p_spudec->p_vout;
210         p_vout_bank->i_count++;
211     }
212     else
213     {
214         /* Take the first video output FIXME: take the best one */
215         p_spudec->p_vout = p_vout_bank->pp_vout[ 0 ];
216     }
217
218     vlc_mutex_unlock( &p_vout_bank->lock );
219     p_spudec->p_config->pf_init_bit_stream(
220             &p_spudec->bit_stream,
221             p_spudec->p_config->p_decoder_fifo, NULL, NULL );
222
223     /* Mark thread as running and return */
224     return( 0 );
225 }
226
227 /*****************************************************************************
228  * spu_dec_ErrorThread: spu_dec_Run() error loop
229  *****************************************************************************
230  * This function is called when an error occured during thread main's loop. The
231  * thread can still receive feed, but must be ready to terminate as soon as
232  * possible.
233  *****************************************************************************/
234 static void spu_dec_ErrorThread( spudec_thread_t *p_spudec )
235 {
236     /* We take the lock, because we are going to read/write the start/end
237      * indexes of the decoder fifo */
238     vlc_mutex_lock( &p_spudec->p_fifo->data_lock );
239
240     /* Wait until a `die' order is sent */
241     while( !p_spudec->p_fifo->b_die )
242     {
243         /* Trash all received PES packets */
244         while( !DECODER_FIFO_ISEMPTY(*p_spudec->p_fifo) )
245         {
246             p_spudec->p_fifo->pf_delete_pes( p_spudec->p_fifo->p_packets_mgt,
247                     DECODER_FIFO_START(*p_spudec->p_fifo) );
248             DECODER_FIFO_INCSTART( *p_spudec->p_fifo );
249         }
250
251         /* Waiting for the input thread to put new PES packets in the fifo */
252         vlc_cond_wait( &p_spudec->p_fifo->data_wait,
253                        &p_spudec->p_fifo->data_lock );
254     }
255
256     /* We can release the lock before leaving */
257     vlc_mutex_unlock( &p_spudec->p_fifo->data_lock );
258 }
259
260 /*****************************************************************************
261  * spu_dec_EndThread: thread destruction
262  *****************************************************************************
263  * This function is called when the thread ends after a sucessful
264  * initialization.
265  *****************************************************************************/
266 static void spu_dec_EndThread( spudec_thread_t *p_spudec )
267 {
268     free( p_spudec->p_config );
269     free( p_spudec );
270 }
271
272 /*****************************************************************************
273  * SyncPacket: get in sync with the stream
274  *****************************************************************************
275  * This function makes a few sanity checks and returns 0 if it looks like we
276  * are at the beginning of a subpicture packet.
277  *****************************************************************************/
278 static int SyncPacket( spudec_thread_t *p_spudec )
279 {
280     /* Re-align the buffer on an 8-bit boundary */
281     RealignBits( &p_spudec->bit_stream );
282
283     /* The total SPU packet size, often bigger than a PS packet */
284     p_spudec->i_spu_size = GetBits( &p_spudec->bit_stream, 16 );
285
286     /* The RLE stuff size (remove 4 because we just read 32 bits) */
287     p_spudec->i_rle_size = ShowBits( &p_spudec->bit_stream, 16 ) - 4;
288
289     /* If the values we got are a bit strange, skip packet */
290     if( !p_spudec->i_spu_size
291          || ( p_spudec->i_rle_size >= p_spudec->i_spu_size ) )
292     {
293         return( 1 );
294     }
295
296     RemoveBits( &p_spudec->bit_stream, 16 );
297
298     return( 0 );
299 }
300
301 /*****************************************************************************
302  * ParsePacket: parse an SPU packet and send it to the video output
303  *****************************************************************************
304  * This function parses the SPU packet and, if valid, sends it to the
305  * video output.
306  *****************************************************************************/
307 static void ParsePacket( spudec_thread_t *p_spudec )
308 {
309     subpicture_t * p_spu;
310     u8           * p_src;
311     unsigned int   i_offset;
312
313     intf_WarnMsg( 3, "spudec: trying to gather a 0x%.2x long subtitle",
314                   p_spudec->i_spu_size );
315
316     /* We cannot display a subpicture with no date */
317     if( DECODER_FIFO_START(*p_spudec->p_fifo)->i_pts == 0 )
318     {
319         intf_WarnMsg( 3, "spudec error: subtitle without a date" );
320         return;
321     }
322
323     /* Allocate the subpicture internal data. */
324     p_spu = vout_CreateSubPicture( p_spudec->p_vout, DVD_SUBPICTURE,
325                                    p_spudec->i_rle_size * 4 );
326     /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
327      * expand the RLE stuff so that we won't need to read nibbles later
328      * on. This will speed things up a lot. Plus, we'll only need to do
329      * this stupid interlacing stuff once. */
330
331     if( p_spu == NULL )
332     {
333         return;
334     }
335
336     /* Get display time now. If we do it later, we may miss the PTS. */
337     p_spudec->i_pts = DECODER_FIFO_START(*p_spudec->p_fifo)->i_pts;
338
339     /* Allocate the temporary buffer we will parse */
340     p_src = malloc( p_spudec->i_rle_size );
341
342     if( p_src == NULL )
343     {
344         intf_ErrMsg( "spudec error: could not allocate p_src" );
345         vout_DestroySubPicture( p_spudec->p_vout, p_spu );
346         return;
347     }
348
349     /* Get RLE data */
350     for( i_offset = 0;
351          i_offset + SPU_CHUNK_SIZE < p_spudec->i_rle_size;
352          i_offset += SPU_CHUNK_SIZE )
353     {
354         GetChunk( &p_spudec->bit_stream, p_src + i_offset, SPU_CHUNK_SIZE );
355
356         /* Abort subtitle parsing if we were requested to stop */
357         if( p_spudec->p_fifo->b_die )
358         {
359             free( p_src );
360             vout_DestroySubPicture( p_spudec->p_vout, p_spu );
361             return;
362         }
363     }
364
365     GetChunk( &p_spudec->bit_stream, p_src + i_offset,
366               p_spudec->i_rle_size - i_offset );
367
368 #if 0
369     /* Dump the subtitle info */
370     intf_WarnHexDump( 5, p_spu->p_data, p_spudec->i_rle_size );
371 #endif
372
373     /* Getting the control part */
374     if( ParseControlSequences( p_spudec, p_spu ) )
375     {
376         /* There was a parse error, delete the subpicture */
377         free( p_src );
378         vout_DestroySubPicture( p_spudec->p_vout, p_spu );
379         return;
380     }
381
382     /* At this point, no more GetBit() command is needed, so we have all
383      * the data we need to tell whether the subtitle is valid. Thus we
384      * try to display it and we ignore b_die. */
385
386     if( ParseRLE( p_spudec, p_spu, p_src ) )
387     {
388         /* There was a parse error, delete the subpicture */
389         free( p_src );
390         vout_DestroySubPicture( p_spudec->p_vout, p_spu );
391         return;
392     }
393
394     intf_WarnMsg( 3, "spudec: total size: 0x%x, RLE offsets: 0x%x 0x%x",
395                   p_spudec->i_spu_size,
396                   p_spu->type.spu.i_offset[0], p_spu->type.spu.i_offset[1] );
397
398     /* SPU is finished - we can ask the video output to display it */
399     vout_DisplaySubPicture( p_spudec->p_vout, p_spu );
400
401     /* Clean up */
402     free( p_src );
403 }
404
405 /*****************************************************************************
406  * ParseControlSequences: parse all SPU control sequences
407  *****************************************************************************
408  * This is the most important part in SPU decoding. We get dates, palette
409  * information, coordinates, and so on. For more information on the
410  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
411  *****************************************************************************/
412 static int ParseControlSequences( spudec_thread_t *p_spudec,
413                                   subpicture_t * p_spu )
414 {
415     /* Our current index in the SPU packet */
416     int i_index = p_spudec->i_rle_size + 4;
417
418     /* The next start-of-control-sequence index and the previous one */
419     int i_next_seq, i_cur_seq;
420
421     /* Command time and date */
422     u8  i_command;
423     int i_date;
424
425     /* XXX: temporary variables */
426     boolean_t b_force_display = 0;
427
428     /* Initialize the structure */
429     p_spu->i_start = p_spu->i_stop = 0;
430     p_spu->b_ephemer = 0;
431
432     do
433     {
434         /* Get the control sequence date */
435         i_date = GetBits( &p_spudec->bit_stream, 16 );
436  
437         /* Next offset */
438         i_cur_seq = i_index;
439         i_next_seq = GetBits( &p_spudec->bit_stream, 16 );
440  
441         /* Skip what we just read */
442         i_index += 4;
443  
444         do
445         {
446             i_command = GetBits( &p_spudec->bit_stream, 8 );
447             i_index++;
448  
449             switch( i_command )
450             {
451                 case SPU_CMD_FORCE_DISPLAY:
452
453                     /* 00 (force displaying) */
454                     p_spu->i_start = p_spudec->i_pts + ( i_date * 11000 );
455                     b_force_display = 1;
456  
457                     break;
458  
459                 /* Convert the dates in seconds to PTS values */
460                 case SPU_CMD_START_DISPLAY:
461  
462                     /* 01 (start displaying) */
463                     p_spu->i_start = p_spudec->i_pts + ( i_date * 11000 );
464  
465                     break;
466  
467                 case SPU_CMD_STOP_DISPLAY:
468  
469                     /* 02 (stop displaying) */
470                     p_spu->i_stop = p_spudec->i_pts + ( i_date * 11000 );
471  
472                     break;
473  
474                 case SPU_CMD_SET_PALETTE:
475  
476                     /* 03xxxx (palette) - trashed */
477                     RemoveBits( &p_spudec->bit_stream, 16 );
478                     i_index += 2;
479  
480                     break;
481  
482                 case SPU_CMD_SET_ALPHACHANNEL:
483  
484                     /* 04xxxx (alpha channel) - trashed */
485                     RemoveBits( &p_spudec->bit_stream, 16 );
486                     i_index += 2;
487  
488                     break;
489  
490                 case SPU_CMD_SET_COORDINATES:
491  
492                     /* 05xxxyyyxxxyyy (coordinates) */
493                     p_spu->i_x = GetBits( &p_spudec->bit_stream, 12 );
494                     p_spu->i_width = GetBits( &p_spudec->bit_stream, 12 )
495                                       - p_spu->i_x + 1;
496  
497                     p_spu->i_y = GetBits( &p_spudec->bit_stream, 12 );
498                     p_spu->i_height = GetBits( &p_spudec->bit_stream, 12 )
499                                        - p_spu->i_y + 1;
500  
501                     i_index += 6;
502  
503                     break;
504  
505                 case SPU_CMD_SET_OFFSETS:
506  
507                     /* 06xxxxyyyy (byte offsets) */
508                     p_spu->type.spu.i_offset[0] =
509                         GetBits( &p_spudec->bit_stream, 16 ) - 4;
510  
511                     p_spu->type.spu.i_offset[1] =
512                         GetBits( &p_spudec->bit_stream, 16 ) - 4;
513  
514                     i_index += 4;
515  
516                     break;
517  
518                 case SPU_CMD_END:
519  
520                     /* ff (end) */
521                     break;
522  
523                 default:
524  
525                     /* xx (unknown command) */
526                     intf_ErrMsg( "spudec error: unknown command 0x%.2x",
527                                  i_command );
528                     return( 1 );
529             }
530
531             /* We need to check for quit commands here */
532             if( p_spudec->p_fifo->b_die )
533             {
534                 return( 1 );
535             }
536
537         } while( i_command != SPU_CMD_END );
538
539     } while( i_index == i_next_seq );
540
541     /* Check that the next sequence index matches the current one */
542     if( i_next_seq != i_cur_seq )
543     {
544         intf_ErrMsg( "spudec error: index mismatch (0x%.4x != 0x%.4x)",
545                      i_next_seq, i_cur_seq );
546         return( 1 );
547     }
548
549     if( i_index > p_spudec->i_spu_size )
550     {
551         intf_ErrMsg( "spudec error: uh-oh, we went too far (0x%.4x > 0x%.4x)",
552                      i_index, p_spudec->i_spu_size );
553         return( 1 );
554     }
555
556     if( !p_spu->i_start )
557     {
558         intf_ErrMsg( "spudec error: no `start display' command" );
559     }
560
561     if( !p_spu->i_stop )
562     {
563         /* This subtitle will live for 5 seconds or until the next subtitle */
564         p_spu->i_stop = p_spu->i_start + 500 * 11000;
565         p_spu->b_ephemer = 1;
566     }
567
568     /* Get rid of padding bytes */
569     switch( p_spudec->i_spu_size - i_index )
570     {
571         /* Zero or one padding byte, quite usual */
572         case 1:
573             RemoveBits( &p_spudec->bit_stream, 8 );
574             i_index++;
575         case 0:
576             break;
577
578         /* More than one padding byte - this is very strange, but
579          * we can deal with it */
580         default:
581             intf_WarnMsg( 2, "spudec warning: %i padding bytes, we usually "
582                              "get 0 or 1 of them",
583                           p_spudec->i_spu_size - i_index );
584
585             while( i_index < p_spudec->i_spu_size )
586             {
587                 RemoveBits( &p_spudec->bit_stream, 8 );
588                 i_index++;
589             }
590
591             break;
592     }
593
594     if( b_force_display )
595     {
596         intf_ErrMsg( "spudec: \"force display\" command" );
597         intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
598                      "want to help debugging this" );
599     }
600
601     /* Successfully parsed ! */
602     return( 0 );
603 }
604
605 /*****************************************************************************
606  * ParseRLE: parse the RLE part of the subtitle
607  *****************************************************************************
608  * This part parses the subtitle graphical data and stores it in a more
609  * convenient structure for later decoding. For more information on the
610  * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
611  *****************************************************************************/
612 static int ParseRLE( spudec_thread_t *p_spudec,
613                      subpicture_t * p_spu, u8 * p_src )
614 {
615     unsigned int i_code;
616
617     unsigned int i_width = p_spu->i_width;
618     unsigned int i_height = p_spu->i_height;
619     unsigned int i_x, i_y;
620
621     u16 *p_dest = (u16 *)p_spu->p_data;
622
623     /* The subtitles are interlaced, we need two offsets */
624     unsigned int  i_id = 0;                   /* Start on the even SPU layer */
625     unsigned int  pi_table[ 2 ];
626     unsigned int *pi_offset;
627
628     boolean_t b_empty_top = 1,
629               b_empty_bottom = 0;
630     unsigned int i_skipped_top = 0,
631                  i_skipped_bottom = 0;
632
633     pi_table[ 0 ] = p_spu->type.spu.i_offset[ 0 ] << 1;
634     pi_table[ 1 ] = p_spu->type.spu.i_offset[ 1 ] << 1;
635
636     for( i_y = 0 ; i_y < i_height ; i_y++ )
637     {
638         pi_offset = pi_table + i_id;
639
640         for( i_x = 0 ; i_x < i_width ; i_x += i_code >> 2 )
641         {
642             i_code = AddNibble( 0, p_src, pi_offset );
643
644             if( i_code < 0x04 )
645             {
646                 i_code = AddNibble( i_code, p_src, pi_offset );
647
648                 if( i_code < 0x10 )
649                 {
650                     i_code = AddNibble( i_code, p_src, pi_offset );
651
652                     if( i_code < 0x040 )
653                     {
654                         i_code = AddNibble( i_code, p_src, pi_offset );
655
656                         if( i_code < 0x0100 )
657                         {
658                             /* If the 14 first bits are set to 0, then it's a
659                              * new line. We emulate it. */
660                             if( i_code < 0x0004 )
661                             {
662                                 i_code |= ( i_width - i_x ) << 2;
663                             }
664                             else
665                             {
666                                 /* We have a boo boo ! */
667                                 intf_ErrMsg( "spudec error: unknown RLE code "
668                                              "0x%.4x", i_code );
669                                 return( 1 );
670                             }
671                         }
672                     }
673                 }
674             }
675
676             if( ( (i_code >> 2) + i_x + i_y * i_width ) > i_height * i_width )
677             {
678                 intf_ErrMsg( "spudec error: out of bounds, %i at (%i,%i) is "
679                              "out of %ix%i",
680                              i_code >> 2, i_x, i_y, i_width, i_height );
681                 return( 1 );
682             }
683
684             if( i_code == (i_width << 2) ) /* FIXME: we assume 0 is transp */
685             {
686                 if( b_empty_top )
687                 {
688                     /* This is a blank top line, we skip it */
689                     i_skipped_top++;
690                 }
691                 else
692                 {
693                     /* We can't be sure the current lines will be skipped,
694                      * so we store the code just in case. */
695                     *p_dest++ = i_code;
696
697                     b_empty_bottom = 1;
698                     i_skipped_bottom++;
699                 }
700             }
701             else
702             {
703                 /* We got a valid code, store it */
704                 *p_dest++ = i_code;
705
706                 /* Valid code means no blank line */
707                 b_empty_top = 0;
708                 b_empty_bottom = 0;
709                 i_skipped_bottom = 0;
710             }
711         }
712
713         /* Check that we didn't go too far */
714         if( i_x > i_width )
715         {
716             intf_ErrMsg( "spudec error: i_x overflowed, %i > %i",
717                          i_x, i_width );
718             return( 1 );
719         }
720
721         /* Byte-align the stream */
722         if( *pi_offset & 0x1 )
723         {
724             (*pi_offset)++;
725         }
726
727         /* Swap fields */
728         i_id = ~i_id & 0x1;
729     }
730
731     /* We shouldn't get any padding bytes */
732     if( i_y < i_height )
733     {
734         intf_ErrMsg( "spudec: padding bytes found in RLE sequence" );
735         intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
736                      "want to help debugging this" );
737
738         /* Skip them just in case */
739         while( i_y < i_height )
740         {
741             *p_dest++ = i_width << 2;
742             i_y++;
743         }
744
745         return( 1 );
746     }
747
748     intf_WarnMsg( 3, "spudec: valid subtitle, size: %ix%i, position: %i,%i",
749                   p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
750
751     /* Crop if necessary */
752     if( i_skipped_top || i_skipped_bottom )
753     {
754         p_spu->i_y += i_skipped_top;
755         p_spu->i_height -= i_skipped_top + i_skipped_bottom;
756
757         intf_WarnMsg( 3, "spudec: cropped to: %ix%i, position: %i,%i",
758                       p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
759     }
760
761     return( 0 );
762 }
763