1 /****************************************************************************
2 * input_vcd.c: VideoCD raw reading plugin.
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
6 * Author: Johan Bilien <jobi@via.ecp.fr>, based on Stephane Borel's DVD input
7 * and on Christophe Massiot and
8 * Cyril Deguet's PS input
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #define MODULE_NAME vcd
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
41 #include <sys/types.h>
45 #ifdef STRNCASECMP_IN_STRINGS_H
50 # include <io.h> /* read() */
52 # include <sys/uio.h> /* struct iovec */
63 # include "input_iovec.h"
70 #include "stream_control.h"
71 #include "input_ext-intf.h"
72 #include "input_ext-dec.h"
73 #include "input_ext-plugins.h"
78 #include "modules_export.h"
80 #include "../mpeg/input_ps.h"
81 #include "input_vcd.h"
82 #include "linux_cdrom_tools.h"
84 /* how many blocks VCDRead will read in each loop */
85 #define VCD_BLOCKS_ONCE 64
86 #define VCD_DATA_ONCE (2 * VCD_BLOCKS_ONCE)
87 #define BUFFER_SIZE VCD_DATA_SIZE
91 /*****************************************************************************
93 *****************************************************************************/
94 /* called from outside */
95 static int VCDProbe ( probedata_t *p_data );
96 static void VCDInit ( struct input_thread_s * );
97 static int VCDRead ( struct input_thread_s *, data_packet_t ** );
98 static int VCDSetArea ( struct input_thread_s *, struct input_area_s * );
99 static void VCDOpen ( struct input_thread_s *);
100 static void VCDClose ( struct input_thread_s *);
101 static void VCDEnd ( struct input_thread_s *);
102 static void VCDSeek ( struct input_thread_s *, off_t );
103 static int VCDRewind ( struct input_thread_s * );
104 static struct data_packet_s * NewPacket( void *, size_t );
105 static pes_packet_t * NewPES ( void * );
106 static void DeletePacket ( void *, data_packet_t * );
107 static void DeletePES ( void *, pes_packet_t *);
111 /*****************************************************************************
112 * Functions exported as capabilities. They are declared as static so that
113 * we don't pollute the namespace too much.
114 *****************************************************************************/
115 void _M( input_getfunctions )( function_list_t * p_function_list )
117 #define input p_function_list->functions.input
118 p_function_list->pf_probe = VCDProbe ;
119 input.pf_init = VCDInit ;
120 input.pf_open = VCDOpen ;
121 input.pf_close = VCDClose ;
122 input.pf_end = VCDEnd ;
123 input.pf_init_bit_stream = InitBitstream;
124 input.pf_read = VCDRead ;
125 input.pf_set_area = VCDSetArea ;
126 input.pf_demux = input_DemuxPS;
127 input.pf_new_packet = NewPacket;
128 input.pf_new_pes = NewPES;
129 input.pf_delete_packet = DeletePacket;
130 input.pf_delete_pes = DeletePES;
131 input.pf_rewind = VCDRewind ;
132 input.pf_seek = VCDSeek ;
137 * Data reading functions
140 /*****************************************************************************
141 * VCDProbe: verifies that the stream is a PS stream
142 *****************************************************************************/
143 static int VCDProbe( probedata_t *p_data )
146 input_thread_t * p_input = (input_thread_t *)p_data;
148 char * psz_name = p_input->p_source;
151 if( TestMethod( INPUT_METHOD_VAR, "vcd" ) )
156 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vcd:", 4 ) )
158 /* If the user specified "vcd:" then it's probably a VCD */
165 /*****************************************************************************
167 *****************************************************************************/
168 static void VCDOpen( struct input_thread_s *p_input )
172 vlc_mutex_lock( &p_input->stream.stream_lock );
174 /* If we are here we can control the pace... */
175 p_input->stream.b_pace_control = 1;
177 p_input->stream.b_seekable = 1;
178 p_input->stream.p_selected_area->i_size = 0;
180 p_input->stream.p_selected_area->i_tell = 0;
182 vlc_mutex_unlock( &p_input->stream.stream_lock );
185 /* XXX: put this shit in an access plugin */
186 if( strlen( p_input->p_source ) > 4
187 && !strncasecmp( p_input->p_source, "vcd:", 4 ) )
189 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
193 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
196 if( vcdhandle == -1 )
198 p_input->b_error = 1;
202 p_input->i_handle = (int) vcdhandle;
205 /*****************************************************************************
206 * VCDClose: close vcd
207 *****************************************************************************/
208 static void VCDClose( struct input_thread_s *p_input )
210 close( p_input->i_handle );
213 /*****************************************************************************
214 * VCDInit: initializes VCD structures
215 *****************************************************************************/
216 static void VCDInit( input_thread_t * p_input )
218 thread_vcd_data_t * p_vcd;
222 input_area_t * p_area;
223 es_descriptor_t * p_es;
224 packet_cache_t * p_packet_cache;
226 p_vcd = malloc( sizeof(thread_vcd_data_t) );
230 intf_ErrMsg( "vcd error: out of memory" );
231 p_input->b_error = 1;
237 p_input->p_plugin_data = (void *)p_vcd;
238 p_input->p_method_data = NULL;
240 p_vcd->vcdhandle = p_input->i_handle;
241 p_vcd->b_end_of_track = 0;
243 /* we read the Table Of Content information */
244 if ( read_toc(p_vcd) == -1 )
246 intf_ErrMsg("An error occured when reading vcd's TOC");
249 p_input->i_read_once = VCD_DATA_ONCE;
251 p_packet_cache = malloc( sizeof(packet_cache_t) );
253 if ( p_packet_cache == NULL )
255 intf_ErrMsg( "vcd error: out of memory" );
256 p_input->b_error = 1;
260 p_input->p_method_data = (void *)p_packet_cache;
261 /* Initialize packet cache mutex */
262 vlc_mutex_init( &p_packet_cache->lock );
264 /* allocates the data cache */
265 p_packet_cache->data.p_stack = malloc( DATA_CACHE_SIZE *
266 sizeof(data_packet_t*) );
267 if ( p_packet_cache->data.p_stack == NULL )
269 intf_ErrMsg( "Out of memory" );
270 p_input->b_error = 1;
273 p_packet_cache->data.l_index = 0;
275 /* allocates the PES cache */
276 p_packet_cache->pes.p_stack = malloc( PES_CACHE_SIZE *
277 sizeof(pes_packet_t*) );
278 if ( p_packet_cache->pes.p_stack == NULL )
280 intf_ErrMsg( "Out of memory" );
281 p_input->b_error = 1;
284 p_packet_cache->pes.l_index = 0;
286 /* allocates the small buffer cache */
287 p_packet_cache->smallbuffer.p_stack = malloc( SMALL_CACHE_SIZE *
288 sizeof(packet_buffer_t) );
289 if ( p_packet_cache->smallbuffer.p_stack == NULL )
291 intf_ErrMsg( "Out of memory" );
292 p_input->b_error = 1;
295 p_packet_cache->smallbuffer.l_index = 0;
297 /* allocates the large buffer cache */
298 p_packet_cache->largebuffer.p_stack = malloc( LARGE_CACHE_SIZE *
299 sizeof(packet_buffer_t) );
300 if ( p_packet_cache->largebuffer.p_stack == NULL )
302 intf_ErrMsg( "Out of memory" );
303 p_input->b_error = 1;
306 p_packet_cache->largebuffer.l_index = 0;
308 /* Set stream and area data */
309 vlc_mutex_lock( &p_input->stream.stream_lock );
311 /* Initialize ES structures */
312 input_InitStream( p_input, sizeof( stream_ps_data_t ) );
314 /* disc input method */
315 p_input->stream.i_method = INPUT_METHOD_VCD;
318 #define area p_input->stream.pp_areas
319 for( i = 1 ; i <= p_vcd->nb_tracks - 1 ; i++ )
321 input_AddArea( p_input );
323 /* Titles are Program Chains */
326 /* Absolute start offset and size */
327 area[i]->i_start = p_vcd->tracks_sector[i+1];
328 area[i]->i_size = p_vcd->tracks_sector[i+2] - p_vcd->tracks_sector[i+1];
330 /* Number of chapters */
331 area[i]->i_part_nb = 0; // will be the entry points
334 /* Number of angles */
335 area[i]->i_angle_nb = 1; // no angle support in VCDs
336 area[i]->i_angle = 1;
338 area[i]->i_plugin_data = p_vcd->tracks_sector[i+1];
342 /* Get requested title - if none try the first title */
343 i_title = main_GetIntVariable( INPUT_TITLE_VAR, 1 );
349 // p_vcd->current_track = i_title-1 ;
351 /* Get requested chapter - if none defaults to first one */
352 i_chapter = main_GetIntVariable( INPUT_CHAPTER_VAR, 1 );
359 p_input->stream.pp_areas[i_title]->i_part = i_chapter;
361 p_area = p_input->stream.pp_areas[i_title];
363 VCDSetArea( p_input, p_area );
365 /* Set program information. */
367 input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
369 /* No PSM to read in disc mode, we already have all information */
370 p_input->stream.pp_programs[0]->b_is_ok = 1;
372 p_es = input_AddES( p_input, p_input->stream.pp_programs[0], 0xe0, 0 );
373 p_es->i_stream_id = 0xe0;
374 p_es->i_type = MPEG1_VIDEO_ES;
375 p_es->i_cat = VIDEO_ES;
377 if( p_main->b_video )
379 input_SelectES( p_input, p_es );
382 p_es = input_AddES( p_input,
383 p_input->stream.pp_programs[0], 0xc0, 0 );
384 p_es->i_stream_id = 0xc0;
385 p_es->i_type = MPEG1_AUDIO_ES;
387 p_es->i_cat = AUDIO_ES;
389 if( p_main->b_audio )
391 input_SelectES( p_input, p_es );
394 vlc_mutex_unlock( &p_input->stream.stream_lock );
401 /*****************************************************************************
402 * VCDEnd: frees unused data
403 *****************************************************************************/
404 static void VCDEnd( input_thread_t * p_input )
406 thread_vcd_data_t * p_vcd;
408 p_vcd = (thread_vcd_data_t*)p_input->p_plugin_data;
414 /*****************************************************************************
415 * VCDSetArea: initialize input data for title x, chapter y.
416 * It should be called for each user navigation request.
417 ****************************************************************************/
418 static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
420 thread_vcd_data_t * p_vcd;
422 p_vcd = (thread_vcd_data_t*)p_input->p_plugin_data;
424 /* we can't use the interface slider until initilization is complete */
425 p_input->stream.b_seekable = 0;
427 if ( p_area != p_input->stream.p_selected_area )
429 /* Reset the Chapter position of the old title */
430 p_input->stream.p_selected_area->i_part = 0;
432 /* Change the default area */
433 p_input->stream.p_selected_area =
434 p_input->stream.pp_areas[p_area->i_id];
436 /* Change the current track */
437 /* The first track is not a valid one */
438 p_vcd->current_track = p_area->i_id + 1 ;
439 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track] ;
441 /* warn interface that something has changed */
442 p_input->stream.b_seekable = 1;
443 p_input->stream.b_changed = 1;
450 /*****************************************************************************
451 * VCDRead: reads from the VCD into PES packets.
452 *****************************************************************************
453 * Returns -1 in case of error, 0 if everything went well, and 1 in case of
455 *****************************************************************************/
456 static int VCDRead( input_thread_t * p_input,
457 data_packet_t ** pp_packets )
459 thread_vcd_data_t * p_vcd;
460 data_packet_t * p_data;
466 boolean_t b_no_packet;
467 /* boolean_t b_eoc; No chapters yet */
469 p_vcd = (thread_vcd_data_t *)p_input->p_plugin_data;
472 p_buffer = malloc ( VCD_DATA_SIZE );
474 if ( p_buffer == NULL )
476 intf_ErrMsg("Could not malloc the read buffer");
484 while( i_packet < VCD_DATA_ONCE )
488 if ( VCD_sector_read( p_vcd, p_buffer ) == -1 )
493 while (i_index < BUFFER_SIZE - 6)
496 if( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
498 /* This is not the startcode of a packet. Read the stream
499 * until we find one. */
501 if( !U32_AT( p_buffer + i_index ) )
503 /* It is common for MPEG-1 streams to pad with zeros
504 * (although it is forbidden by the recommendation), so
505 * don't bother everybody in this case. */
506 intf_WarnMsg( 3, "Garbage at input" );
509 while( ( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
510 && ( i_index < BUFFER_SIZE - 4 ) )
515 if ( i_index == BUFFER_SIZE - 4 )
525 intf_WarnMsg(3, "No packet found on sector %d\n",
526 p_vcd->current_sector -1 );
527 break; /* go to the next sector */
531 intf_DbgMsg("packet start code : %X\n",
532 U32_AT(p_buffer + i_index));
534 /* 0x1B9 == SYSTEM_END_CODE, it is only 4 bytes long. */
535 if( U32_AT(p_buffer + i_index) != 0x1B9 )
537 /* The packet is at least 6 bytes long. */
539 if( U32_AT(p_buffer + i_index) != 0x1BA )
541 /* That's the case for all packets, except pack header. */
542 i_packet_size = U16_AT((p_buffer + ( i_index + 4 )));
547 if( ( *( p_buffer + ( i_index + 4 ) ) & 0xC0) == 0x40 )
552 else if( (*(p_buffer + ( i_index + 4 ) ) & 0xF0) == 0x20 )
559 intf_ErrMsg( "Unable to determine stream type" );
566 /* System End Code */
570 intf_DbgMsg("i_index : %d\n", i_index);
571 intf_DbgMsg("i_packet_size : %d\n", i_packet_size);
573 if ( i_index + i_packet_size > BUFFER_SIZE )
575 intf_ErrMsg( "Too long packet");
579 /* Fetch a packet of the appropriate size. */
581 p_data = NewPacket( p_input->p_method_data, i_packet_size + 6 );
585 intf_ErrMsg( "Out of memory" );
589 if( U32_AT(p_buffer) != 0x1B9 )
591 memcpy( p_data->p_buffer, p_buffer + i_index,
593 i_index += ( 6 + i_packet_size );
598 /* Copy the small header. */
599 memcpy( p_data->p_buffer, p_buffer + i_index, 4 );
603 /* Give the packet to the other input stages. */
604 pp_packets[i_packet] = p_data;
608 if ( p_vcd->b_end_of_track )
617 vlc_mutex_lock( &p_input->stream.stream_lock );
619 p_input->stream.p_selected_area->i_tell =
620 p_vcd->current_sector -
621 p_input->stream.p_selected_area->i_start ;
623 /* no chapter for the moment*/
626 * We modify i_part only at end of chapter not to erase
627 * some modification from the interface *
628 p_input->stream.p_selected_area->i_part = p_vcd->i_chapter;
632 b_eof = p_vcd->b_end_of_track &&
633 ( ( p_vcd->current_track + 1 ) >= p_vcd->nb_tracks );
637 vlc_mutex_unlock( &p_input->stream.stream_lock );
641 if( p_vcd->b_end_of_track )
643 intf_WarnMsg( 4, "vcd info: new title" );
644 p_vcd->current_track++;
645 p_vcd->b_end_of_track = 0;
646 VCDSetArea( p_input, p_input->stream.pp_areas[p_vcd->current_track] );
647 vlc_mutex_unlock( &p_input->stream.stream_lock );
651 vlc_mutex_unlock( &p_input->stream.stream_lock );
657 /*****************************************************************************
658 * VCDRewind : reads a stream backward
659 *****************************************************************************/
660 static int VCDRewind( input_thread_t * p_input )
666 /****************************************************************************
668 ****************************************************************************/
669 static void VCDSeek( input_thread_t * p_input, off_t i_off )
671 thread_vcd_data_t * p_vcd;
673 p_vcd = (thread_vcd_data_t *) p_input->p_plugin_data;
675 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track]
678 p_input->stream.p_selected_area->i_tell = p_vcd->current_sector
679 - p_input->stream.p_selected_area->i_start;
687 * Packet management utilities
691 /*****************************************************************************
692 * NewPacket: allocates a data packet
693 *****************************************************************************/
694 static struct data_packet_s * NewPacket( void * p_packet_cache,
697 packet_cache_t * p_cache;
698 data_packet_t * p_data;
701 p_cache = (packet_cache_t *)p_packet_cache;
704 if ( p_cache == NULL )
706 intf_ErrMsg( "PPacket cache not initialized" );
712 if( l_size > INPUT_MAX_PACKET_SIZE )
714 intf_ErrMsg( "Packet too big (%d)", l_size );
718 vlc_mutex_lock( &p_cache->lock );
720 /* Checks whether the data cache is empty */
721 if( p_cache->data.l_index == 0 )
723 /* Allocates a new packet */
724 p_data = malloc( sizeof(data_packet_t) );
727 intf_ErrMsg( "Out of memory" );
728 vlc_mutex_unlock( &p_cache->lock );
732 intf_DbgMsg( "PS input: data packet allocated" );
737 /* Takes the packet out from the cache */
738 if( (p_data = p_cache->data.p_stack[ -- p_cache->data.l_index ])
741 intf_ErrMsg( "NULL packet in the data cache" );
742 vlc_mutex_unlock( &p_cache->lock );
747 if( l_size < MAX_SMALL_SIZE )
751 /* Checks whether the buffer cache is empty */
752 if( p_cache->smallbuffer.l_index == 0 )
754 /* Allocates a new packet */
755 p_data->p_buffer = malloc( l_size );
756 if( p_data->p_buffer == NULL )
758 intf_DbgMsg( "Out of memory" );
760 vlc_mutex_unlock( &p_cache->lock );
764 intf_DbgMsg( "PS input: small buffer allocated" );
766 p_data->l_size = l_size;
770 /* Takes the packet out from the cache */
771 l_index = -- p_cache->smallbuffer.l_index;
772 if( (p_data->p_buffer = p_cache->smallbuffer.p_stack[l_index].p_data)
775 intf_ErrMsg( "NULL packet in the small buffer cache" );
777 vlc_mutex_unlock( &p_cache->lock );
780 /* Reallocates the packet if it is too small or too large */
781 if( p_cache->smallbuffer.p_stack[l_index].l_size < l_size ||
782 p_cache->smallbuffer.p_stack[l_index].l_size > 2*l_size )
784 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
785 p_data->l_size = l_size;
789 p_data->l_size = p_cache->smallbuffer.p_stack[l_index].l_size;
797 /* Checks whether the buffer cache is empty */
798 if( p_cache->largebuffer.l_index == 0 )
800 /* Allocates a new packet */
801 p_data->p_buffer = malloc( l_size );
802 if ( p_data->p_buffer == NULL )
804 intf_ErrMsg( "Out of memory" );
806 vlc_mutex_unlock( &p_cache->lock );
810 intf_DbgMsg( "PS input: large buffer allocated" );
812 p_data->l_size = l_size;
816 /* Takes the packet out from the cache */
817 l_index = -- p_cache->largebuffer.l_index;
818 p_data->p_buffer = p_cache->largebuffer.p_stack[l_index].p_data;
819 if( p_data->p_buffer == NULL )
821 intf_ErrMsg( "NULL packet in the small buffer cache" );
823 vlc_mutex_unlock( &p_cache->lock );
826 /* Reallocates the packet if it is too small or too large */
827 if( p_cache->largebuffer.p_stack[l_index].l_size < l_size ||
828 p_cache->largebuffer.p_stack[l_index].l_size > 2*l_size )
830 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
831 p_data->l_size = l_size;
835 p_data->l_size = p_cache->largebuffer.p_stack[l_index].l_size;
840 vlc_mutex_unlock( &p_cache->lock );
842 /* Initialize data */
843 p_data->p_next = NULL;
844 p_data->b_discard_payload = 0;
845 p_data->p_payload_start = p_data->p_buffer;
846 p_data->p_payload_end = p_data->p_buffer + l_size;
853 /*****************************************************************************
854 * NewPES: allocates a pes packet
855 *****************************************************************************/
856 static pes_packet_t * NewPES( void * p_packet_cache )
858 packet_cache_t * p_cache;
859 pes_packet_t * p_pes;
861 p_cache = (packet_cache_t *)p_packet_cache;
864 if ( p_cache == NULL )
866 intf_ErrMsg( "Packet cache not initialized" );
871 vlc_mutex_lock( &p_cache->lock );
873 /* Checks whether the PES cache is empty */
874 if( p_cache->pes.l_index == 0 )
876 /* Allocates a new packet */
877 p_pes = malloc( sizeof(pes_packet_t) );
880 intf_DbgMsg( "Out of memory" );
881 vlc_mutex_unlock( &p_cache->lock );
885 intf_DbgMsg( "PS input: PES packet allocated" );
890 /* Takes the packet out from the cache */
891 p_pes = p_cache->pes.p_stack[ -- p_cache->pes.l_index ];
894 intf_ErrMsg( "NULL packet in the data cache" );
895 vlc_mutex_unlock( &p_cache->lock );
900 vlc_mutex_unlock( &p_cache->lock );
902 p_pes->b_data_alignment = p_pes->b_discontinuity =
903 p_pes->i_pts = p_pes->i_dts = 0;
904 p_pes->i_pes_size = 0;
905 p_pes->p_first = NULL;
911 /*****************************************************************************
912 * DeletePacket: deletes a data packet
913 *****************************************************************************/
914 static void DeletePacket( void * p_packet_cache,
915 data_packet_t * p_data )
917 packet_cache_t * p_cache;
919 p_cache = (packet_cache_t *)p_packet_cache;
922 if ( p_cache == NULL )
924 intf_ErrMsg( "Packet cache not initialized" );
931 vlc_mutex_lock( &p_cache->lock );
933 /* Checks whether the data cache is full */
934 if ( p_cache->data.l_index < DATA_CACHE_SIZE )
936 /* Cache not full: store the packet in it */
937 p_cache->data.p_stack[ p_cache->data.l_index ++ ] = p_data;
938 /* Small buffer or large buffer? */
939 if ( p_data->l_size < MAX_SMALL_SIZE )
941 /* Checks whether the small buffer cache is full */
942 if ( p_cache->smallbuffer.l_index < SMALL_CACHE_SIZE )
944 p_cache->smallbuffer.p_stack[
945 p_cache->smallbuffer.l_index ].l_size = p_data->l_size;
946 p_cache->smallbuffer.p_stack[
947 p_cache->smallbuffer.l_index++ ].p_data = p_data->p_buffer;
951 ASSERT( p_data->p_buffer );
952 free( p_data->p_buffer );
954 intf_DbgMsg( "PS input: small buffer freed" );
960 /* Checks whether the large buffer cache is full */
961 if ( p_cache->largebuffer.l_index < LARGE_CACHE_SIZE )
963 p_cache->largebuffer.p_stack[
964 p_cache->largebuffer.l_index ].l_size = p_data->l_size;
965 p_cache->largebuffer.p_stack[
966 p_cache->largebuffer.l_index++ ].p_data = p_data->p_buffer;
970 ASSERT( p_data->p_buffer );
971 free( p_data->p_buffer );
973 intf_DbgMsg( "PS input: large buffer freed" );
980 /* Cache full: the packet must be freed */
981 free( p_data->p_buffer );
984 intf_DbgMsg( "PS input: data packet freed" );
988 vlc_mutex_unlock( &p_cache->lock );
991 /*****************************************************************************
992 * DeletePES: deletes a PES packet and associated data packets
993 *****************************************************************************/
994 static void DeletePES( void * p_packet_cache, pes_packet_t * p_pes )
996 packet_cache_t * p_cache;
997 data_packet_t * p_data;
998 data_packet_t * p_next;
1000 p_cache = (packet_cache_t *)p_packet_cache;
1003 if ( p_cache == NULL )
1005 intf_ErrMsg( "Packet cache not initialized" );
1012 p_data = p_pes->p_first;
1014 while( p_data != NULL )
1016 p_next = p_data->p_next;
1017 DeletePacket( p_cache, p_data );
1021 vlc_mutex_lock( &p_cache->lock );
1023 /* Checks whether the PES cache is full */
1024 if ( p_cache->pes.l_index < PES_CACHE_SIZE )
1026 /* Cache not full: store the packet in it */
1027 p_cache->pes.p_stack[ p_cache->pes.l_index ++ ] = p_pes;
1031 /* Cache full: the packet must be freed */
1034 intf_DbgMsg( "PS input: PES packet freed" );
1038 vlc_mutex_unlock( &p_cache->lock );