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