/*******************************************************************************
* Preamble
- ******************************************************************************/
+ *******************************************************************************/
+#include "vlc.h"
+
+/*
#include <errno.h>
-#include <pthread.h>
-#include <sys/uio.h> /* iovec */
+#include <sys/uio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <sys/soundcard.h>
-#include <stdlib.h> /* atoi(), malloc(), free() */
+#include <stdlib.h>
#include <stdio.h>
-#include <sys/ioctl.h> /* ioctl() */
-#include <net/if.h> /* ifreq */
+#include <sys/ioctl.h>
+#include <net/if.h>
#include <netinet/in.h>
#include "common.h"
#include "config.h"
#include "mtime.h"
+#include "vlc_thread.h"
#include "intf_msg.h"
#include "debug.h"
#include "video.h"
#include "video_output.h"
#include "video_decoder.h"
+*/
/******************************************************************************
* Local prototypes
/* Create thread and set locks. */
p_input->b_die = 0;
- pthread_mutex_init( &p_input->netlist.lock, NULL );
- pthread_mutex_init( &p_input->programs_lock, NULL );
- pthread_mutex_init( &p_input->es_lock, NULL );
+ vlc_mutex_init( &p_input->netlist.lock );
+ vlc_mutex_init( &p_input->programs_lock );
+ vlc_mutex_init( &p_input->es_lock );
#ifdef NO_THREAD
input_Thread( p_input );
#else
- if( pthread_create(&p_input->thread_id, NULL, (void *) input_Thread,
+ if( vlc_thread_create(&p_input->thread_id, "input", (vlc_thread_func_t)input_Thread,
(void *) p_input) )
{
intf_ErrMsg("input error: can't spawn input thread (%s)\n",
p_input->b_die = 1; /* ask thread to kill itself */
/* Remove this as soon as the "status" flag is implemented */
- pthread_join( p_input->thread_id, NULL ); /* wait until it's done */
+ vlc_thread_join( p_input->thread_id ); /* wait until it's done */
}
#if 0
EndThread( p_input );
intf_DbgMsg("input debug: thread %p destroyed\n", p_input);
- pthread_exit( 0 );
+ vlc_thread_exit();
}
/* Remove the TS packets we have just filled from the netlist */
#ifdef INPUT_LIFO_TS_NETLIST
/* We need to take a lock here while we're calculating index positions. */
- pthread_mutex_lock( &p_input->netlist.lock );
+ vlc_mutex_lock( &p_input->netlist.lock );
i_meanwhile_released = i_base_index - p_input->netlist.i_ts_index;
if( i_meanwhile_released )
p_input->netlist.i_ts_index = i_current_index;
}
- pthread_mutex_unlock( &p_input->netlist.lock );
+ vlc_mutex_unlock( &p_input->netlist.lock );
#else /* FIFO netlist */
/* & is modulo ; that's where we make the loop. */
// i_current_pid, p_ts_packet);
/* Lock current ES state. */
- pthread_mutex_lock( &p_input->es_lock );
+ vlc_mutex_lock( &p_input->es_lock );
/* Verify that we actually want this PID. */
for( i_es_loop = 0; i_es_loop < INPUT_MAX_SELECTED_ES; i_es_loop++ )
modified from inside the input_thread (by the PSI
decoder): interface thread is only allowed to modify
the pp_selected_es table */
- pthread_mutex_unlock( &p_input->es_lock );
+ vlc_mutex_unlock( &p_input->es_lock );
/* We're interested. Pass it to the demultiplexer. */
input_DemuxTS( p_input, p_ts_packet,
break;
}
}
- pthread_mutex_unlock( &p_input->es_lock );
+ vlc_mutex_unlock( &p_input->es_lock );
}
/* We weren't interested in receiving this packet. Give it back to the
so the PES won't be usefull for any decoder. Moreover,
this should never happen so we can trash the packet and
exit roughly without regrets */
- intf_DbgMsg("PES packet is too short: trashed\n");
+ intf_DbgMsg("PES packet too short: trashed\n");
input_NetlistFreePES( p_input, p_pes );
p_pes = NULL;
/* Stats ?? */
pcr_descriptor_t * p_pcr;
p_pcr = p_input->p_pcr;
- pthread_mutex_lock( &p_pcr->lock );
- if( p_pcr->delta_clock == 0 )
+
+ p_pes->i_pts =
+ ( ((mtime_t)(p_pes->p_pes_header[9] & 0x0E) << 29) |
+ (((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) - (1 << 14)) |
+ ((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) ) * 300;
+ p_pes->i_pts /= 27;
+
+ if( p_pcr->i_synchro_state )
{
- p_pes->b_has_pts = 0;
+ switch( p_pcr->i_synchro_state )
+ {
+ case SYNCHRO_NOT_STARTED:
+ p_pes->b_has_pts = 0;
+ break;
+
+ case SYNCHRO_START:
+ p_pes->i_pts += p_pcr->delta_pcr;
+ p_pcr->delta_absolute = mdate() - p_pes->i_pts + 500000;
+ p_pes->i_pts += p_pcr->delta_absolute;
+ p_pcr->i_synchro_state = 0;
+ break;
+
+ case SYNCHRO_REINIT: /* We skip a PES */
+ p_pes->b_has_pts = 0;
+ p_pcr->i_synchro_state = SYNCHRO_START;
+ break;
+ }
}
else
{
- p_pes->i_pts = ( ((mtime_t)(p_pes->p_pes_header[9] & 0x0E) << 29) |
- (((mtime_t)U16_AT(p_pes->p_pes_header + 10) << 14) - (1 << 14)) |
- ((mtime_t)U16_AT(p_pes->p_pes_header + 12) >> 1) );
- p_pes->i_pts *= 300;
- p_pes->i_pts /= 27;
- p_pes->i_pts += p_pcr->delta_clock;
- if( p_pcr->c_pts == 0 )
- {
- p_pcr->delta_decode = mdate() - p_pes->i_pts + 500000;
- }
- p_pes->i_pts += p_pcr->delta_decode;
- p_pcr->c_pts += 1;
+ p_pes->i_pts += p_pcr->delta_pcr + p_pcr->delta_absolute;
}
- pthread_mutex_unlock( &p_pcr->lock );
}
break;
}
if( p_fifo != NULL )
{
- pthread_mutex_lock( &p_fifo->data_lock );
+ vlc_mutex_lock( &p_fifo->data_lock );
if( DECODER_FIFO_ISFULL( *p_fifo ) )
{
/* The FIFO is full !!! This should not happen. */
DECODER_FIFO_INCEND( *p_fifo );
/* Warn the decoder that it's got work to do. */
- pthread_cond_signal( &p_fifo->data_wait );
+ vlc_cond_signal( &p_fifo->data_wait );
}
- pthread_mutex_unlock( &p_fifo->data_lock );
+ vlc_mutex_unlock( &p_fifo->data_lock );
}
else
{