1 /****************************************************************************
2 * input_vcd.c: VideoCD raw reading plugin.
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
6 * Author: Johan Bilien <jobi@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 #define MODULE_NAME vcd
24 #include "modules_inner.h"
26 /*****************************************************************************
28 *****************************************************************************/
39 #include <sys/types.h>
43 #ifdef STRNCASECMP_IN_STRINGS_H
48 # include <io.h> /* read() */
50 # include <sys/uio.h> /* struct iovec */
60 # include "input_iovec.h"
63 #include "stream_control.h"
64 #include "input_ext-intf.h"
65 #include "input_ext-dec.h"
66 #include "input_ext-plugins.h"
71 #include "modules_export.h"
73 #include "../mpeg_system/input_ps.h"
74 #include "input_vcd.h"
75 #include "linux_cdrom_tools.h"
77 /* how many blocks VCDRead will read in each loop */
78 #define VCD_BLOCKS_ONCE 64
79 #define VCD_DATA_ONCE (2 * VCD_BLOCKS_ONCE)
80 #define BUFFER_SIZE VCD_DATA_SIZE
84 /*****************************************************************************
86 *****************************************************************************/
87 /* called from outside */
88 static int VCDProbe ( probedata_t *p_data );
89 static void VCDInit ( struct input_thread_s * );
90 static int VCDRead ( struct input_thread_s *, data_packet_t ** );
91 static int VCDSetArea ( struct input_thread_s *, struct input_area_s * );
92 static int VCDSetProgram ( struct input_thread_s *, pgrm_descriptor_t * );
93 static void VCDOpen ( struct input_thread_s *);
94 static void VCDClose ( struct input_thread_s *);
95 static void VCDEnd ( struct input_thread_s *);
96 static void VCDSeek ( struct input_thread_s *, off_t );
97 static int VCDRewind ( struct input_thread_s * );
98 static struct data_packet_s * NewPacket( void *, size_t );
99 static pes_packet_t * NewPES ( void * );
100 static void DeletePacket ( void *, data_packet_t * );
101 static void DeletePES ( void *, pes_packet_t *);
105 /*****************************************************************************
106 * Functions exported as capabilities. They are declared as static so that
107 * we don't pollute the namespace too much.
108 *****************************************************************************/
109 void _M( input_getfunctions )( function_list_t * p_function_list )
111 #define input p_function_list->functions.input
112 p_function_list->pf_probe = VCDProbe;
113 input.pf_init = VCDInit;
114 input.pf_open = VCDOpen;
115 input.pf_close = VCDClose;
116 input.pf_end = VCDEnd;
117 input.pf_init_bit_stream = InitBitstream;
118 input.pf_read = VCDRead;
119 input.pf_set_area = VCDSetArea;
120 input.pf_set_program = VCDSetProgram;
121 input.pf_demux = input_DemuxPS;
122 input.pf_new_packet = NewPacket;
123 input.pf_new_pes = NewPES;
124 input.pf_delete_packet = DeletePacket;
125 input.pf_delete_pes = DeletePES;
126 input.pf_rewind = VCDRewind;
127 input.pf_seek = VCDSeek;
132 * Data reading functions
135 /*****************************************************************************
136 * VCDProbe: verifies that the stream is a PS stream
137 *****************************************************************************/
138 static int VCDProbe( probedata_t *p_data )
141 input_thread_t * p_input = (input_thread_t *)p_data;
143 char * psz_name = p_input->p_source;
146 if( TestMethod( INPUT_METHOD_VAR, "vcd" ) )
151 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vcd:", 4 ) )
153 /* If the user specified "vcd:" then it's probably a VCD */
160 /*****************************************************************************
162 *****************************************************************************/
163 static void VCDOpen( struct input_thread_s *p_input )
167 vlc_mutex_lock( &p_input->stream.stream_lock );
169 /* If we are here we can control the pace... */
170 p_input->stream.b_pace_control = 1;
172 p_input->stream.b_seekable = 1;
173 p_input->stream.p_selected_area->i_size = 0;
175 p_input->stream.p_selected_area->i_tell = 0;
177 vlc_mutex_unlock( &p_input->stream.stream_lock );
180 /* XXX: put this shit in an access plugin */
181 if( strlen( p_input->p_source ) > 4
182 && !strncasecmp( p_input->p_source, "vcd:", 4 ) )
184 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
188 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
191 if( vcdhandle == -1 )
193 p_input->b_error = 1;
197 p_input->i_handle = (int) vcdhandle;
200 /*****************************************************************************
201 * VCDClose: close vcd
202 *****************************************************************************/
203 static void VCDClose( struct input_thread_s *p_input )
205 close( p_input->i_handle );
208 /*****************************************************************************
209 * VCDInit: initializes VCD structures
210 *****************************************************************************/
211 static void VCDInit( input_thread_t * p_input )
213 thread_vcd_data_t * p_vcd;
217 input_area_t * p_area;
218 es_descriptor_t * p_es;
219 packet_cache_t * p_packet_cache;
221 p_vcd = malloc( sizeof(thread_vcd_data_t) );
225 intf_ErrMsg( "vcd error: out of memory" );
226 p_input->b_error = 1;
232 p_input->p_plugin_data = (void *)p_vcd;
233 p_input->p_method_data = NULL;
235 p_vcd->vcdhandle = p_input->i_handle;
236 p_vcd->b_end_of_track = 0;
238 /* we read the Table Of Content information */
239 if ( read_toc(p_vcd) == -1 )
241 intf_ErrMsg("An error occured when reading vcd's TOC");
244 p_input->i_read_once = VCD_DATA_ONCE;
246 p_packet_cache = malloc( sizeof(packet_cache_t) );
248 if ( p_packet_cache == NULL )
250 intf_ErrMsg( "vcd error: out of memory" );
251 p_input->b_error = 1;
255 p_input->p_method_data = (void *)p_packet_cache;
256 /* Initialize packet cache mutex */
257 vlc_mutex_init( &p_packet_cache->lock );
259 /* allocates the data cache */
260 p_packet_cache->data.p_stack = malloc( DATA_CACHE_SIZE *
261 sizeof(data_packet_t*) );
262 if ( p_packet_cache->data.p_stack == NULL )
264 intf_ErrMsg( "Out of memory" );
265 p_input->b_error = 1;
268 p_packet_cache->data.l_index = 0;
270 /* allocates the PES cache */
271 p_packet_cache->pes.p_stack = malloc( PES_CACHE_SIZE *
272 sizeof(pes_packet_t*) );
273 if ( p_packet_cache->pes.p_stack == NULL )
275 intf_ErrMsg( "Out of memory" );
276 p_input->b_error = 1;
279 p_packet_cache->pes.l_index = 0;
281 /* allocates the small buffer cache */
282 p_packet_cache->smallbuffer.p_stack = malloc( SMALL_CACHE_SIZE *
283 sizeof(packet_buffer_t) );
284 if ( p_packet_cache->smallbuffer.p_stack == NULL )
286 intf_ErrMsg( "Out of memory" );
287 p_input->b_error = 1;
290 p_packet_cache->smallbuffer.l_index = 0;
292 /* allocates the large buffer cache */
293 p_packet_cache->largebuffer.p_stack = malloc( LARGE_CACHE_SIZE *
294 sizeof(packet_buffer_t) );
295 if ( p_packet_cache->largebuffer.p_stack == NULL )
297 intf_ErrMsg( "Out of memory" );
298 p_input->b_error = 1;
301 p_packet_cache->largebuffer.l_index = 0;
303 /* Set stream and area data */
304 vlc_mutex_lock( &p_input->stream.stream_lock );
306 /* Initialize ES structures */
307 input_InitStream( p_input, sizeof( stream_ps_data_t ) );
309 /* disc input method */
310 p_input->stream.i_method = INPUT_METHOD_VCD;
313 #define area p_input->stream.pp_areas
314 for( i = 1 ; i <= p_vcd->nb_tracks - 1 ; i++ )
316 input_AddArea( p_input );
318 /* Titles are Program Chains */
321 /* Absolute start offset and size */
322 area[i]->i_start = p_vcd->tracks_sector[i];
323 area[i]->i_size = p_vcd->tracks_sector[i+1] - p_vcd->tracks_sector[i];
325 /* Number of chapters */
326 area[i]->i_part_nb = 0; // will be the entry points
329 /* Number of angles */
330 area[i]->i_angle_nb = 1; // no angle support in VCDs
331 area[i]->i_angle = 1;
333 area[i]->i_plugin_data = p_vcd->tracks_sector[i];
337 /* Get requested title - if none try the first title */
338 i_title = main_GetIntVariable( INPUT_TITLE_VAR, 1 );
344 // p_vcd->current_track = i_title-1 ;
346 /* Get requested chapter - if none defaults to first one */
347 i_chapter = main_GetIntVariable( INPUT_CHAPTER_VAR, 1 );
354 p_input->stream.pp_areas[i_title]->i_part = i_chapter;
356 p_area = p_input->stream.pp_areas[i_title];
358 VCDSetArea( p_input, p_area );
360 /* Set program information. */
362 input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
363 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
365 /* No PSM to read in disc mode, we already have all information */
366 p_input->stream.p_selected_program->b_is_ok = 1;
368 p_es = input_AddES( p_input, p_input->stream.p_selected_program, 0xe0, 0 );
369 p_es->i_stream_id = 0xe0;
370 p_es->i_type = MPEG1_VIDEO_ES;
371 p_es->i_cat = VIDEO_ES;
373 if( p_main->b_video )
375 input_SelectES( p_input, p_es );
378 p_es = input_AddES( p_input,
379 p_input->stream.p_selected_program, 0xc0, 0 );
380 p_es->i_stream_id = 0xc0;
381 p_es->i_type = MPEG1_AUDIO_ES;
383 p_es->i_cat = AUDIO_ES;
385 if( p_main->b_audio )
387 input_SelectES( p_input, p_es );
390 vlc_mutex_unlock( &p_input->stream.stream_lock );
397 /*****************************************************************************
398 * VCDEnd: frees unused data
399 *****************************************************************************/
400 static void VCDEnd( input_thread_t * p_input )
402 thread_vcd_data_t * p_vcd;
404 p_vcd = (thread_vcd_data_t*)p_input->p_plugin_data;
410 /*****************************************************************************
411 * VCDSetProgram: Does nothing since a VCD is mono_program
412 *****************************************************************************/
413 static int VCDSetProgram( input_thread_t * p_input,
414 pgrm_descriptor_t * p_program)
420 /*****************************************************************************
421 * VCDSetArea: initialize input data for title x, chapter y.
422 * It should be called for each user navigation request.
423 ****************************************************************************/
424 static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
426 thread_vcd_data_t * p_vcd;
428 p_vcd = (thread_vcd_data_t*)p_input->p_plugin_data;
430 /* we can't use the interface slider until initilization is complete */
431 p_input->stream.b_seekable = 0;
433 if ( p_area != p_input->stream.p_selected_area )
435 /* Reset the Chapter position of the old title */
436 p_input->stream.p_selected_area->i_part = 0;
437 p_input->stream.p_selected_area->i_tell = 0;
439 /* Change the default area */
440 p_input->stream.p_selected_area = p_area;
442 /* Change the current track */
443 /* The first track is not a valid one */
444 p_vcd->current_track = p_area->i_id ;
445 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track] ;
447 /* warn interface that something has changed */
448 p_input->stream.b_seekable = 1;
449 p_input->stream.b_changed = 1;
456 /*****************************************************************************
457 * VCDRead: reads from the VCD into PES packets.
458 *****************************************************************************
459 * Returns -1 in case of error, 0 if everything went well, and 1 in case of
461 *****************************************************************************/
462 static int VCDRead( input_thread_t * p_input,
463 data_packet_t ** pp_packets )
465 thread_vcd_data_t * p_vcd;
466 data_packet_t * p_data;
472 boolean_t b_no_packet;
473 /* boolean_t b_eoc; No chapters yet */
475 p_vcd = (thread_vcd_data_t *)p_input->p_plugin_data;
478 p_buffer = malloc ( VCD_DATA_SIZE );
480 if ( p_buffer == NULL )
482 intf_ErrMsg("Could not malloc the read buffer");
490 while( i_packet < VCD_DATA_ONCE )
494 if ( VCD_sector_read( p_vcd, p_buffer ) == -1 )
499 while (i_index < BUFFER_SIZE - 6)
502 if( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
504 /* This is not the startcode of a packet. Read the stream
505 * until we find one. */
507 if( !U32_AT( p_buffer + i_index ) )
509 /* It is common for MPEG-1 streams to pad with zeros
510 * (although it is forbidden by the recommendation), so
511 * don't bother everybody in this case. */
512 intf_WarnMsg( 3, "Garbage at input" );
515 while( ( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
516 && ( i_index < BUFFER_SIZE - 4 ) )
521 if ( i_index == BUFFER_SIZE - 4 )
531 intf_WarnMsg(3, "No packet found on sector %d\n",
532 p_vcd->current_sector -1 );
533 break; /* go to the next sector */
537 intf_DbgMsg("packet start code : %X\n",
538 U32_AT(p_buffer + i_index));
540 /* 0x1B9 == SYSTEM_END_CODE, it is only 4 bytes long. */
541 if( U32_AT(p_buffer + i_index) != 0x1B9 )
543 /* The packet is at least 6 bytes long. */
545 if( U32_AT(p_buffer + i_index) != 0x1BA )
547 /* That's the case for all packets, except pack header. */
548 i_packet_size = U16_AT((p_buffer + ( i_index + 4 )));
553 if( ( *( p_buffer + ( i_index + 4 ) ) & 0xC0) == 0x40 )
558 else if( (*(p_buffer + ( i_index + 4 ) ) & 0xF0) == 0x20 )
565 intf_ErrMsg( "Unable to determine stream type" );
572 /* System End Code */
576 intf_DbgMsg("i_index : %d\n", i_index);
577 intf_DbgMsg("i_packet_size : %d\n", i_packet_size);
579 if ( i_index + i_packet_size > BUFFER_SIZE )
581 intf_ErrMsg( "Too long packet");
585 /* Fetch a packet of the appropriate size. */
587 p_data = NewPacket( p_input->p_method_data, i_packet_size + 6 );
591 intf_ErrMsg( "Out of memory" );
595 if( U32_AT(p_buffer) != 0x1B9 )
597 p_main->fast_memcpy( p_data->p_buffer, p_buffer + i_index,
599 i_index += ( 6 + i_packet_size );
604 /* Copy the small header. */
605 memcpy( p_data->p_buffer, p_buffer + i_index, 4 );
609 /* Give the packet to the other input stages. */
610 pp_packets[i_packet] = p_data;
614 if ( p_vcd->b_end_of_track )
620 vlc_mutex_lock( &p_input->stream.stream_lock );
622 p_input->stream.p_selected_area->i_tell =
623 p_vcd->current_sector -
624 p_input->stream.p_selected_area->i_start ;
626 /* no chapter for the moment*/
629 * We modify i_part only at end of chapter not to erase
630 * some modification from the interface *
631 p_input->stream.p_selected_area->i_part = p_vcd->i_chapter;
635 b_eof = p_vcd->b_end_of_track;
636 /*FIXME&& ( ( p_vcd->current_track ) >= p_vcd->nb_tracks - 1);*/
640 vlc_mutex_unlock( &p_input->stream.stream_lock );
644 if( p_vcd->b_end_of_track )
646 intf_WarnMsg( 4, "vcd info: new title" );
647 p_vcd->b_end_of_track = 0;
648 VCDSetArea( p_input, p_input->stream.pp_areas[
649 p_input->stream.p_selected_area->i_id + 1] );
650 vlc_mutex_unlock( &p_input->stream.stream_lock );
654 vlc_mutex_unlock( &p_input->stream.stream_lock );
660 /*****************************************************************************
661 * VCDRewind : reads a stream backward
662 *****************************************************************************/
663 static int VCDRewind( input_thread_t * p_input )
669 /****************************************************************************
671 ****************************************************************************/
672 static void VCDSeek( input_thread_t * p_input, off_t i_off )
674 thread_vcd_data_t * p_vcd;
676 p_vcd = (thread_vcd_data_t *) p_input->p_plugin_data;
678 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track]
681 p_input->stream.p_selected_area->i_tell = p_vcd->current_sector
682 - p_input->stream.p_selected_area->i_start;
690 * Packet management utilities
694 /*****************************************************************************
695 * NewPacket: allocates a data packet
696 *****************************************************************************/
697 static struct data_packet_s * NewPacket( void * p_packet_cache,
700 packet_cache_t * p_cache;
701 data_packet_t * p_data;
704 p_cache = (packet_cache_t *)p_packet_cache;
707 if ( p_cache == NULL )
709 intf_ErrMsg( "PPacket cache not initialized" );
715 if( l_size > INPUT_MAX_PACKET_SIZE )
717 intf_ErrMsg( "Packet too big (%d)", l_size );
721 vlc_mutex_lock( &p_cache->lock );
723 /* Checks whether the data cache is empty */
724 if( p_cache->data.l_index == 0 )
726 /* Allocates a new packet */
727 p_data = malloc( sizeof(data_packet_t) );
730 intf_ErrMsg( "Out of memory" );
731 vlc_mutex_unlock( &p_cache->lock );
735 intf_DbgMsg( "PS input: data packet allocated" );
740 /* Takes the packet out from the cache */
741 if( (p_data = p_cache->data.p_stack[ -- p_cache->data.l_index ])
744 intf_ErrMsg( "NULL packet in the data cache" );
745 vlc_mutex_unlock( &p_cache->lock );
750 if( l_size < MAX_SMALL_SIZE )
754 /* Checks whether the buffer cache is empty */
755 if( p_cache->smallbuffer.l_index == 0 )
757 /* Allocates a new packet */
758 p_data->p_buffer = malloc( l_size );
759 if( p_data->p_buffer == NULL )
761 intf_DbgMsg( "Out of memory" );
763 vlc_mutex_unlock( &p_cache->lock );
767 intf_DbgMsg( "PS input: small buffer allocated" );
769 p_data->l_size = l_size;
773 /* Takes the packet out from the cache */
774 l_index = -- p_cache->smallbuffer.l_index;
775 if( (p_data->p_buffer = p_cache->smallbuffer.p_stack[l_index].p_data)
778 intf_ErrMsg( "NULL packet in the small buffer cache" );
780 vlc_mutex_unlock( &p_cache->lock );
783 /* Reallocates the packet if it is too small or too large */
784 if( p_cache->smallbuffer.p_stack[l_index].l_size < l_size ||
785 p_cache->smallbuffer.p_stack[l_index].l_size > 2*l_size )
787 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
788 p_data->l_size = l_size;
792 p_data->l_size = p_cache->smallbuffer.p_stack[l_index].l_size;
800 /* Checks whether the buffer cache is empty */
801 if( p_cache->largebuffer.l_index == 0 )
803 /* Allocates a new packet */
804 p_data->p_buffer = malloc( l_size );
805 if ( p_data->p_buffer == NULL )
807 intf_ErrMsg( "Out of memory" );
809 vlc_mutex_unlock( &p_cache->lock );
813 intf_DbgMsg( "PS input: large buffer allocated" );
815 p_data->l_size = l_size;
819 /* Takes the packet out from the cache */
820 l_index = -- p_cache->largebuffer.l_index;
821 p_data->p_buffer = p_cache->largebuffer.p_stack[l_index].p_data;
822 if( p_data->p_buffer == NULL )
824 intf_ErrMsg( "NULL packet in the small buffer cache" );
826 vlc_mutex_unlock( &p_cache->lock );
829 /* Reallocates the packet if it is too small or too large */
830 if( p_cache->largebuffer.p_stack[l_index].l_size < l_size ||
831 p_cache->largebuffer.p_stack[l_index].l_size > 2*l_size )
833 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
834 p_data->l_size = l_size;
838 p_data->l_size = p_cache->largebuffer.p_stack[l_index].l_size;
843 vlc_mutex_unlock( &p_cache->lock );
845 /* Initialize data */
846 p_data->p_next = NULL;
847 p_data->b_discard_payload = 0;
848 p_data->p_payload_start = p_data->p_buffer;
849 p_data->p_payload_end = p_data->p_buffer + l_size;
856 /*****************************************************************************
857 * NewPES: allocates a pes packet
858 *****************************************************************************/
859 static pes_packet_t * NewPES( void * p_packet_cache )
861 packet_cache_t * p_cache;
862 pes_packet_t * p_pes;
864 p_cache = (packet_cache_t *)p_packet_cache;
867 if ( p_cache == NULL )
869 intf_ErrMsg( "Packet cache not initialized" );
874 vlc_mutex_lock( &p_cache->lock );
876 /* Checks whether the PES cache is empty */
877 if( p_cache->pes.l_index == 0 )
879 /* Allocates a new packet */
880 p_pes = malloc( sizeof(pes_packet_t) );
883 intf_DbgMsg( "Out of memory" );
884 vlc_mutex_unlock( &p_cache->lock );
888 intf_DbgMsg( "PS input: PES packet allocated" );
893 /* Takes the packet out from the cache */
894 p_pes = p_cache->pes.p_stack[ -- p_cache->pes.l_index ];
897 intf_ErrMsg( "NULL packet in the data cache" );
898 vlc_mutex_unlock( &p_cache->lock );
903 vlc_mutex_unlock( &p_cache->lock );
905 p_pes->b_data_alignment = p_pes->b_discontinuity =
906 p_pes->i_pts = p_pes->i_dts = 0;
907 p_pes->i_pes_size = 0;
908 p_pes->p_first = NULL;
914 /*****************************************************************************
915 * DeletePacket: deletes a data packet
916 *****************************************************************************/
917 static void DeletePacket( void * p_packet_cache,
918 data_packet_t * p_data )
920 packet_cache_t * p_cache;
922 p_cache = (packet_cache_t *)p_packet_cache;
925 if ( p_cache == NULL )
927 intf_ErrMsg( "Packet cache not initialized" );
934 vlc_mutex_lock( &p_cache->lock );
936 /* Checks whether the data cache is full */
937 if ( p_cache->data.l_index < DATA_CACHE_SIZE )
939 /* Cache not full: store the packet in it */
940 p_cache->data.p_stack[ p_cache->data.l_index ++ ] = p_data;
941 /* Small buffer or large buffer? */
942 if ( p_data->l_size < MAX_SMALL_SIZE )
944 /* Checks whether the small buffer cache is full */
945 if ( p_cache->smallbuffer.l_index < SMALL_CACHE_SIZE )
947 p_cache->smallbuffer.p_stack[
948 p_cache->smallbuffer.l_index ].l_size = p_data->l_size;
949 p_cache->smallbuffer.p_stack[
950 p_cache->smallbuffer.l_index++ ].p_data = p_data->p_buffer;
954 ASSERT( p_data->p_buffer );
955 free( p_data->p_buffer );
957 intf_DbgMsg( "PS input: small buffer freed" );
963 /* Checks whether the large buffer cache is full */
964 if ( p_cache->largebuffer.l_index < LARGE_CACHE_SIZE )
966 p_cache->largebuffer.p_stack[
967 p_cache->largebuffer.l_index ].l_size = p_data->l_size;
968 p_cache->largebuffer.p_stack[
969 p_cache->largebuffer.l_index++ ].p_data = p_data->p_buffer;
973 ASSERT( p_data->p_buffer );
974 free( p_data->p_buffer );
976 intf_DbgMsg( "PS input: large buffer freed" );
983 /* Cache full: the packet must be freed */
984 free( p_data->p_buffer );
987 intf_DbgMsg( "PS input: data packet freed" );
991 vlc_mutex_unlock( &p_cache->lock );
994 /*****************************************************************************
995 * DeletePES: deletes a PES packet and associated data packets
996 *****************************************************************************/
997 static void DeletePES( void * p_packet_cache, pes_packet_t * p_pes )
999 packet_cache_t * p_cache;
1000 data_packet_t * p_data;
1001 data_packet_t * p_next;
1003 p_cache = (packet_cache_t *)p_packet_cache;
1006 if ( p_cache == NULL )
1008 intf_ErrMsg( "Packet cache not initialized" );
1015 p_data = p_pes->p_first;
1017 while( p_data != NULL )
1019 p_next = p_data->p_next;
1020 DeletePacket( p_cache, p_data );
1024 vlc_mutex_lock( &p_cache->lock );
1026 /* Checks whether the PES cache is full */
1027 if ( p_cache->pes.l_index < PES_CACHE_SIZE )
1029 /* Cache not full: store the packet in it */
1030 p_cache->pes.p_stack[ p_cache->pes.l_index ++ ] = p_pes;
1034 /* Cache full: the packet must be freed */
1037 intf_DbgMsg( "PS input: PES packet freed" );
1041 vlc_mutex_unlock( &p_cache->lock );