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 */
62 # include "input_iovec.h"
67 #include "stream_control.h"
68 #include "input_ext-intf.h"
69 #include "input_ext-dec.h"
70 #include "input_ext-plugins.h"
75 #include "modules_export.h"
77 #include "../mpeg/input_ps.h"
78 #include "input_vcd.h"
79 #include "linux_cdrom_tools.h"
81 /* how many blocks VCDRead will read in each loop */
82 #define VCD_BLOCKS_ONCE 64
83 #define VCD_DATA_ONCE (2 * VCD_BLOCKS_ONCE)
84 #define BUFFER_SIZE VCD_DATA_SIZE
88 /*****************************************************************************
90 *****************************************************************************/
91 /* called from outside */
92 static int VCDProbe ( probedata_t *p_data );
93 static void VCDInit ( struct input_thread_s * );
94 static int VCDRead ( struct input_thread_s *, data_packet_t ** );
95 static int VCDSetArea ( struct input_thread_s *, struct input_area_s * );
96 static int VCDSetProgram ( struct input_thread_s *, pgrm_descriptor_t * );
97 static void VCDOpen ( struct input_thread_s *);
98 static void VCDClose ( struct input_thread_s *);
99 static void VCDEnd ( struct input_thread_s *);
100 static void VCDSeek ( struct input_thread_s *, off_t );
101 static int VCDRewind ( struct input_thread_s * );
102 static struct data_packet_s * NewPacket( void *, size_t );
103 static pes_packet_t * NewPES ( void * );
104 static void DeletePacket ( void *, data_packet_t * );
105 static void DeletePES ( void *, pes_packet_t *);
109 /*****************************************************************************
110 * Functions exported as capabilities. They are declared as static so that
111 * we don't pollute the namespace too much.
112 *****************************************************************************/
113 void _M( input_getfunctions )( function_list_t * p_function_list )
115 #define input p_function_list->functions.input
116 p_function_list->pf_probe = VCDProbe;
117 input.pf_init = VCDInit;
118 input.pf_open = VCDOpen;
119 input.pf_close = VCDClose;
120 input.pf_end = VCDEnd;
121 input.pf_init_bit_stream = InitBitstream;
122 input.pf_read = VCDRead;
123 input.pf_set_area = VCDSetArea;
124 input.pf_set_program = VCDSetProgram;
125 input.pf_demux = input_DemuxPS;
126 input.pf_new_packet = NewPacket;
127 input.pf_new_pes = NewPES;
128 input.pf_delete_packet = DeletePacket;
129 input.pf_delete_pes = DeletePES;
130 input.pf_rewind = VCDRewind;
131 input.pf_seek = VCDSeek;
136 * Data reading functions
139 /*****************************************************************************
140 * VCDProbe: verifies that the stream is a PS stream
141 *****************************************************************************/
142 static int VCDProbe( probedata_t *p_data )
145 input_thread_t * p_input = (input_thread_t *)p_data;
147 char * psz_name = p_input->p_source;
150 if( TestMethod( INPUT_METHOD_VAR, "vcd" ) )
155 if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vcd:", 4 ) )
157 /* If the user specified "vcd:" then it's probably a VCD */
164 /*****************************************************************************
166 *****************************************************************************/
167 static void VCDOpen( struct input_thread_s *p_input )
171 vlc_mutex_lock( &p_input->stream.stream_lock );
173 /* If we are here we can control the pace... */
174 p_input->stream.b_pace_control = 1;
176 p_input->stream.b_seekable = 1;
177 p_input->stream.p_selected_area->i_size = 0;
179 p_input->stream.p_selected_area->i_tell = 0;
181 vlc_mutex_unlock( &p_input->stream.stream_lock );
184 /* XXX: put this shit in an access plugin */
185 if( strlen( p_input->p_source ) > 4
186 && !strncasecmp( p_input->p_source, "vcd:", 4 ) )
188 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
192 vcdhandle = open( p_input->p_source + 4, O_RDONLY | O_NONBLOCK );
195 if( vcdhandle == -1 )
197 p_input->b_error = 1;
201 p_input->i_handle = (int) vcdhandle;
204 /*****************************************************************************
205 * VCDClose: close vcd
206 *****************************************************************************/
207 static void VCDClose( struct input_thread_s *p_input )
209 close( p_input->i_handle );
212 /*****************************************************************************
213 * VCDInit: initializes VCD structures
214 *****************************************************************************/
215 static void VCDInit( input_thread_t * p_input )
217 thread_vcd_data_t * p_vcd;
221 input_area_t * p_area;
222 es_descriptor_t * p_es;
223 packet_cache_t * p_packet_cache;
225 p_vcd = malloc( sizeof(thread_vcd_data_t) );
229 intf_ErrMsg( "vcd error: out of memory" );
230 p_input->b_error = 1;
236 p_input->p_plugin_data = (void *)p_vcd;
237 p_input->p_method_data = NULL;
239 p_vcd->vcdhandle = p_input->i_handle;
240 p_vcd->b_end_of_track = 0;
242 /* we read the Table Of Content information */
243 if ( read_toc(p_vcd) == -1 )
245 intf_ErrMsg("An error occured when reading vcd's TOC");
248 p_input->i_read_once = VCD_DATA_ONCE;
250 p_packet_cache = malloc( sizeof(packet_cache_t) );
252 if ( p_packet_cache == NULL )
254 intf_ErrMsg( "vcd error: out of memory" );
255 p_input->b_error = 1;
259 p_input->p_method_data = (void *)p_packet_cache;
260 /* Initialize packet cache mutex */
261 vlc_mutex_init( &p_packet_cache->lock );
263 /* allocates the data cache */
264 p_packet_cache->data.p_stack = malloc( DATA_CACHE_SIZE *
265 sizeof(data_packet_t*) );
266 if ( p_packet_cache->data.p_stack == NULL )
268 intf_ErrMsg( "Out of memory" );
269 p_input->b_error = 1;
272 p_packet_cache->data.l_index = 0;
274 /* allocates the PES cache */
275 p_packet_cache->pes.p_stack = malloc( PES_CACHE_SIZE *
276 sizeof(pes_packet_t*) );
277 if ( p_packet_cache->pes.p_stack == NULL )
279 intf_ErrMsg( "Out of memory" );
280 p_input->b_error = 1;
283 p_packet_cache->pes.l_index = 0;
285 /* allocates the small buffer cache */
286 p_packet_cache->smallbuffer.p_stack = malloc( SMALL_CACHE_SIZE *
287 sizeof(packet_buffer_t) );
288 if ( p_packet_cache->smallbuffer.p_stack == NULL )
290 intf_ErrMsg( "Out of memory" );
291 p_input->b_error = 1;
294 p_packet_cache->smallbuffer.l_index = 0;
296 /* allocates the large buffer cache */
297 p_packet_cache->largebuffer.p_stack = malloc( LARGE_CACHE_SIZE *
298 sizeof(packet_buffer_t) );
299 if ( p_packet_cache->largebuffer.p_stack == NULL )
301 intf_ErrMsg( "Out of memory" );
302 p_input->b_error = 1;
305 p_packet_cache->largebuffer.l_index = 0;
307 /* Set stream and area data */
308 vlc_mutex_lock( &p_input->stream.stream_lock );
310 /* Initialize ES structures */
311 input_InitStream( p_input, sizeof( stream_ps_data_t ) );
313 /* disc input method */
314 p_input->stream.i_method = INPUT_METHOD_VCD;
317 #define area p_input->stream.pp_areas
318 for( i = 1 ; i <= p_vcd->nb_tracks - 1 ; i++ )
320 input_AddArea( p_input );
322 /* Titles are Program Chains */
325 /* Absolute start offset and size */
326 area[i]->i_start = p_vcd->tracks_sector[i+1];
327 area[i]->i_size = p_vcd->tracks_sector[i+2] - p_vcd->tracks_sector[i+1];
329 /* Number of chapters */
330 area[i]->i_part_nb = 0; // will be the entry points
333 /* Number of angles */
334 area[i]->i_angle_nb = 1; // no angle support in VCDs
335 area[i]->i_angle = 1;
337 area[i]->i_plugin_data = p_vcd->tracks_sector[i+1];
341 /* Get requested title - if none try the first title */
342 i_title = main_GetIntVariable( INPUT_TITLE_VAR, 1 );
348 // p_vcd->current_track = i_title-1 ;
350 /* Get requested chapter - if none defaults to first one */
351 i_chapter = main_GetIntVariable( INPUT_CHAPTER_VAR, 1 );
358 p_input->stream.pp_areas[i_title]->i_part = i_chapter;
360 p_area = p_input->stream.pp_areas[i_title];
362 VCDSetArea( p_input, p_area );
364 /* Set program information. */
366 input_AddProgram( p_input, 0, sizeof( stream_ps_data_t ) );
367 p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
369 /* No PSM to read in disc mode, we already have all information */
370 p_input->stream.p_selected_program->b_is_ok = 1;
372 p_es = input_AddES( p_input, p_input->stream.p_selected_program, 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.p_selected_program, 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 * VCDSetProgram: Does nothing since a VCD is mono_program
416 *****************************************************************************/
417 static int VCDSetProgram( input_thread_t * p_input,
418 pgrm_descriptor_t * p_program)
424 /*****************************************************************************
425 * VCDSetArea: initialize input data for title x, chapter y.
426 * It should be called for each user navigation request.
427 ****************************************************************************/
428 static int VCDSetArea( input_thread_t * p_input, input_area_t * p_area )
430 thread_vcd_data_t * p_vcd;
432 p_vcd = (thread_vcd_data_t*)p_input->p_plugin_data;
434 /* we can't use the interface slider until initilization is complete */
435 p_input->stream.b_seekable = 0;
437 if ( p_area != p_input->stream.p_selected_area )
439 /* Reset the Chapter position of the old title */
440 p_input->stream.p_selected_area->i_part = 0;
442 /* Change the default area */
443 p_input->stream.p_selected_area =
444 p_input->stream.pp_areas[p_area->i_id];
446 /* Change the current track */
447 /* The first track is not a valid one */
448 p_vcd->current_track = p_area->i_id + 1 ;
449 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track] ;
451 /* warn interface that something has changed */
452 p_input->stream.b_seekable = 1;
453 p_input->stream.b_changed = 1;
460 /*****************************************************************************
461 * VCDRead: reads from the VCD into PES packets.
462 *****************************************************************************
463 * Returns -1 in case of error, 0 if everything went well, and 1 in case of
465 *****************************************************************************/
466 static int VCDRead( input_thread_t * p_input,
467 data_packet_t ** pp_packets )
469 thread_vcd_data_t * p_vcd;
470 data_packet_t * p_data;
476 boolean_t b_no_packet;
477 /* boolean_t b_eoc; No chapters yet */
479 p_vcd = (thread_vcd_data_t *)p_input->p_plugin_data;
482 p_buffer = malloc ( VCD_DATA_SIZE );
484 if ( p_buffer == NULL )
486 intf_ErrMsg("Could not malloc the read buffer");
494 while( i_packet < VCD_DATA_ONCE )
498 if ( VCD_sector_read( p_vcd, p_buffer ) == -1 )
503 while (i_index < BUFFER_SIZE - 6)
506 if( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
508 /* This is not the startcode of a packet. Read the stream
509 * until we find one. */
511 if( !U32_AT( p_buffer + i_index ) )
513 /* It is common for MPEG-1 streams to pad with zeros
514 * (although it is forbidden by the recommendation), so
515 * don't bother everybody in this case. */
516 intf_WarnMsg( 3, "Garbage at input" );
519 while( ( (U32_AT(p_buffer + i_index) & 0xFFFFFF00) != 0x100L )
520 && ( i_index < BUFFER_SIZE - 4 ) )
525 if ( i_index == BUFFER_SIZE - 4 )
535 intf_WarnMsg(3, "No packet found on sector %d\n",
536 p_vcd->current_sector -1 );
537 break; /* go to the next sector */
541 intf_DbgMsg("packet start code : %X\n",
542 U32_AT(p_buffer + i_index));
544 /* 0x1B9 == SYSTEM_END_CODE, it is only 4 bytes long. */
545 if( U32_AT(p_buffer + i_index) != 0x1B9 )
547 /* The packet is at least 6 bytes long. */
549 if( U32_AT(p_buffer + i_index) != 0x1BA )
551 /* That's the case for all packets, except pack header. */
552 i_packet_size = U16_AT((p_buffer + ( i_index + 4 )));
557 if( ( *( p_buffer + ( i_index + 4 ) ) & 0xC0) == 0x40 )
562 else if( (*(p_buffer + ( i_index + 4 ) ) & 0xF0) == 0x20 )
569 intf_ErrMsg( "Unable to determine stream type" );
576 /* System End Code */
580 intf_DbgMsg("i_index : %d\n", i_index);
581 intf_DbgMsg("i_packet_size : %d\n", i_packet_size);
583 if ( i_index + i_packet_size > BUFFER_SIZE )
585 intf_ErrMsg( "Too long packet");
589 /* Fetch a packet of the appropriate size. */
591 p_data = NewPacket( p_input->p_method_data, i_packet_size + 6 );
595 intf_ErrMsg( "Out of memory" );
599 if( U32_AT(p_buffer) != 0x1B9 )
601 pf_fast_memcpy( p_data->p_buffer, p_buffer + i_index,
603 i_index += ( 6 + i_packet_size );
608 /* Copy the small header. */
609 memcpy( p_data->p_buffer, p_buffer + i_index, 4 );
613 /* Give the packet to the other input stages. */
614 pp_packets[i_packet] = p_data;
618 if ( p_vcd->b_end_of_track )
627 vlc_mutex_lock( &p_input->stream.stream_lock );
629 p_input->stream.p_selected_area->i_tell =
630 p_vcd->current_sector -
631 p_input->stream.p_selected_area->i_start ;
633 /* no chapter for the moment*/
636 * We modify i_part only at end of chapter not to erase
637 * some modification from the interface *
638 p_input->stream.p_selected_area->i_part = p_vcd->i_chapter;
642 b_eof = p_vcd->b_end_of_track &&
643 ( ( p_vcd->current_track + 1 ) >= p_vcd->nb_tracks );
647 vlc_mutex_unlock( &p_input->stream.stream_lock );
651 if( p_vcd->b_end_of_track )
653 intf_WarnMsg( 4, "vcd info: new title" );
654 p_vcd->current_track++;
655 p_vcd->b_end_of_track = 0;
656 VCDSetArea( p_input, p_input->stream.pp_areas[p_vcd->current_track] );
657 vlc_mutex_unlock( &p_input->stream.stream_lock );
661 vlc_mutex_unlock( &p_input->stream.stream_lock );
667 /*****************************************************************************
668 * VCDRewind : reads a stream backward
669 *****************************************************************************/
670 static int VCDRewind( input_thread_t * p_input )
676 /****************************************************************************
678 ****************************************************************************/
679 static void VCDSeek( input_thread_t * p_input, off_t i_off )
681 thread_vcd_data_t * p_vcd;
683 p_vcd = (thread_vcd_data_t *) p_input->p_plugin_data;
685 p_vcd->current_sector = p_vcd->tracks_sector[p_vcd->current_track]
688 p_input->stream.p_selected_area->i_tell = p_vcd->current_sector
689 - p_input->stream.p_selected_area->i_start;
697 * Packet management utilities
701 /*****************************************************************************
702 * NewPacket: allocates a data packet
703 *****************************************************************************/
704 static struct data_packet_s * NewPacket( void * p_packet_cache,
707 packet_cache_t * p_cache;
708 data_packet_t * p_data;
711 p_cache = (packet_cache_t *)p_packet_cache;
714 if ( p_cache == NULL )
716 intf_ErrMsg( "PPacket cache not initialized" );
722 if( l_size > INPUT_MAX_PACKET_SIZE )
724 intf_ErrMsg( "Packet too big (%d)", l_size );
728 vlc_mutex_lock( &p_cache->lock );
730 /* Checks whether the data cache is empty */
731 if( p_cache->data.l_index == 0 )
733 /* Allocates a new packet */
734 p_data = malloc( sizeof(data_packet_t) );
737 intf_ErrMsg( "Out of memory" );
738 vlc_mutex_unlock( &p_cache->lock );
742 intf_DbgMsg( "PS input: data packet allocated" );
747 /* Takes the packet out from the cache */
748 if( (p_data = p_cache->data.p_stack[ -- p_cache->data.l_index ])
751 intf_ErrMsg( "NULL packet in the data cache" );
752 vlc_mutex_unlock( &p_cache->lock );
757 if( l_size < MAX_SMALL_SIZE )
761 /* Checks whether the buffer cache is empty */
762 if( p_cache->smallbuffer.l_index == 0 )
764 /* Allocates a new packet */
765 p_data->p_buffer = malloc( l_size );
766 if( p_data->p_buffer == NULL )
768 intf_DbgMsg( "Out of memory" );
770 vlc_mutex_unlock( &p_cache->lock );
774 intf_DbgMsg( "PS input: small buffer allocated" );
776 p_data->l_size = l_size;
780 /* Takes the packet out from the cache */
781 l_index = -- p_cache->smallbuffer.l_index;
782 if( (p_data->p_buffer = p_cache->smallbuffer.p_stack[l_index].p_data)
785 intf_ErrMsg( "NULL packet in the small buffer cache" );
787 vlc_mutex_unlock( &p_cache->lock );
790 /* Reallocates the packet if it is too small or too large */
791 if( p_cache->smallbuffer.p_stack[l_index].l_size < l_size ||
792 p_cache->smallbuffer.p_stack[l_index].l_size > 2*l_size )
794 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
795 p_data->l_size = l_size;
799 p_data->l_size = p_cache->smallbuffer.p_stack[l_index].l_size;
807 /* Checks whether the buffer cache is empty */
808 if( p_cache->largebuffer.l_index == 0 )
810 /* Allocates a new packet */
811 p_data->p_buffer = malloc( l_size );
812 if ( p_data->p_buffer == NULL )
814 intf_ErrMsg( "Out of memory" );
816 vlc_mutex_unlock( &p_cache->lock );
820 intf_DbgMsg( "PS input: large buffer allocated" );
822 p_data->l_size = l_size;
826 /* Takes the packet out from the cache */
827 l_index = -- p_cache->largebuffer.l_index;
828 p_data->p_buffer = p_cache->largebuffer.p_stack[l_index].p_data;
829 if( p_data->p_buffer == NULL )
831 intf_ErrMsg( "NULL packet in the small buffer cache" );
833 vlc_mutex_unlock( &p_cache->lock );
836 /* Reallocates the packet if it is too small or too large */
837 if( p_cache->largebuffer.p_stack[l_index].l_size < l_size ||
838 p_cache->largebuffer.p_stack[l_index].l_size > 2*l_size )
840 p_data->p_buffer = realloc( p_data->p_buffer, l_size );
841 p_data->l_size = l_size;
845 p_data->l_size = p_cache->largebuffer.p_stack[l_index].l_size;
850 vlc_mutex_unlock( &p_cache->lock );
852 /* Initialize data */
853 p_data->p_next = NULL;
854 p_data->b_discard_payload = 0;
855 p_data->p_payload_start = p_data->p_buffer;
856 p_data->p_payload_end = p_data->p_buffer + l_size;
863 /*****************************************************************************
864 * NewPES: allocates a pes packet
865 *****************************************************************************/
866 static pes_packet_t * NewPES( void * p_packet_cache )
868 packet_cache_t * p_cache;
869 pes_packet_t * p_pes;
871 p_cache = (packet_cache_t *)p_packet_cache;
874 if ( p_cache == NULL )
876 intf_ErrMsg( "Packet cache not initialized" );
881 vlc_mutex_lock( &p_cache->lock );
883 /* Checks whether the PES cache is empty */
884 if( p_cache->pes.l_index == 0 )
886 /* Allocates a new packet */
887 p_pes = malloc( sizeof(pes_packet_t) );
890 intf_DbgMsg( "Out of memory" );
891 vlc_mutex_unlock( &p_cache->lock );
895 intf_DbgMsg( "PS input: PES packet allocated" );
900 /* Takes the packet out from the cache */
901 p_pes = p_cache->pes.p_stack[ -- p_cache->pes.l_index ];
904 intf_ErrMsg( "NULL packet in the data cache" );
905 vlc_mutex_unlock( &p_cache->lock );
910 vlc_mutex_unlock( &p_cache->lock );
912 p_pes->b_data_alignment = p_pes->b_discontinuity =
913 p_pes->i_pts = p_pes->i_dts = 0;
914 p_pes->i_pes_size = 0;
915 p_pes->p_first = NULL;
921 /*****************************************************************************
922 * DeletePacket: deletes a data packet
923 *****************************************************************************/
924 static void DeletePacket( void * p_packet_cache,
925 data_packet_t * p_data )
927 packet_cache_t * p_cache;
929 p_cache = (packet_cache_t *)p_packet_cache;
932 if ( p_cache == NULL )
934 intf_ErrMsg( "Packet cache not initialized" );
941 vlc_mutex_lock( &p_cache->lock );
943 /* Checks whether the data cache is full */
944 if ( p_cache->data.l_index < DATA_CACHE_SIZE )
946 /* Cache not full: store the packet in it */
947 p_cache->data.p_stack[ p_cache->data.l_index ++ ] = p_data;
948 /* Small buffer or large buffer? */
949 if ( p_data->l_size < MAX_SMALL_SIZE )
951 /* Checks whether the small buffer cache is full */
952 if ( p_cache->smallbuffer.l_index < SMALL_CACHE_SIZE )
954 p_cache->smallbuffer.p_stack[
955 p_cache->smallbuffer.l_index ].l_size = p_data->l_size;
956 p_cache->smallbuffer.p_stack[
957 p_cache->smallbuffer.l_index++ ].p_data = p_data->p_buffer;
961 ASSERT( p_data->p_buffer );
962 free( p_data->p_buffer );
964 intf_DbgMsg( "PS input: small buffer freed" );
970 /* Checks whether the large buffer cache is full */
971 if ( p_cache->largebuffer.l_index < LARGE_CACHE_SIZE )
973 p_cache->largebuffer.p_stack[
974 p_cache->largebuffer.l_index ].l_size = p_data->l_size;
975 p_cache->largebuffer.p_stack[
976 p_cache->largebuffer.l_index++ ].p_data = p_data->p_buffer;
980 ASSERT( p_data->p_buffer );
981 free( p_data->p_buffer );
983 intf_DbgMsg( "PS input: large buffer freed" );
990 /* Cache full: the packet must be freed */
991 free( p_data->p_buffer );
994 intf_DbgMsg( "PS input: data packet freed" );
998 vlc_mutex_unlock( &p_cache->lock );
1001 /*****************************************************************************
1002 * DeletePES: deletes a PES packet and associated data packets
1003 *****************************************************************************/
1004 static void DeletePES( void * p_packet_cache, pes_packet_t * p_pes )
1006 packet_cache_t * p_cache;
1007 data_packet_t * p_data;
1008 data_packet_t * p_next;
1010 p_cache = (packet_cache_t *)p_packet_cache;
1013 if ( p_cache == NULL )
1015 intf_ErrMsg( "Packet cache not initialized" );
1022 p_data = p_pes->p_first;
1024 while( p_data != NULL )
1026 p_next = p_data->p_next;
1027 DeletePacket( p_cache, p_data );
1031 vlc_mutex_lock( &p_cache->lock );
1033 /* Checks whether the PES cache is full */
1034 if ( p_cache->pes.l_index < PES_CACHE_SIZE )
1036 /* Cache not full: store the packet in it */
1037 p_cache->pes.p_stack[ p_cache->pes.l_index ++ ] = p_pes;
1041 /* Cache full: the packet must be freed */
1044 intf_DbgMsg( "PS input: PES packet freed" );
1048 vlc_mutex_unlock( &p_cache->lock );