mirror of
https://github.com/game-stop/veejay.git
synced 2025-12-18 22:00:00 +01:00
multicast fixes, threading fixes
git-svn-id: svn://code.dyne.org/veejay/trunk@1322 eb8d1916-c9e9-0310-b8de-cf0c9472ead5
This commit is contained in:
@@ -199,18 +199,6 @@ if test x"$PKG_CONFIG_PATH" = x ; then
|
||||
AC_MSG_ERROR([Abort])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(whether to compile with threaded playback)
|
||||
have_playthread=true
|
||||
if test "x$with_playthread" = "xyes" ; then
|
||||
AC_DEFINE(USE_THREADS, 1, [playback threads])
|
||||
AC_MSG_RESULT([yes])
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
have_playthread=false
|
||||
fi
|
||||
|
||||
|
||||
|
||||
AC_MSG_CHECKING(whether to compile in debugging information)
|
||||
debugCFLAGS=""
|
||||
if test "x$enable_debug" = "xyes" ; then
|
||||
@@ -1071,5 +1059,3 @@ AC_MSG_NOTICE([ - Jack Audio Connection Kit : ${have_jack}])
|
||||
AC_MSG_NOTICE([ - Unicap Imaging : ${have_unicap} ])
|
||||
AC_MSG_NOTICE([ - libsamplerate : ${have_samplerate}])
|
||||
|
||||
AC_MSG_NOTICE([ Compile time switches:])
|
||||
AC_MSG_NOTICE([ - Threaded playback : ${have_playthread}])
|
||||
|
||||
@@ -315,6 +315,12 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
packet_header_t hdr = packet_get_header( chunk );
|
||||
frame_info_t inf;
|
||||
packet_get_info(&inf,chunk );
|
||||
*dw = info.width;
|
||||
*dh = info.height;
|
||||
*dfmt = info.fmt;
|
||||
|
||||
// packet_dump_header( &hdr );
|
||||
// packet_dump_info( &inf );
|
||||
|
||||
if( n_packet == 0 ) // is this the first packet we get?
|
||||
{
|
||||
@@ -327,15 +333,15 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
total_recv = n_packet * CHUNK_SIZE;
|
||||
veejay_memcpy(&header, &(queued_packets->hdr), sizeof(packet_header_t));
|
||||
veejay_memcpy(&info, &(queued_packets->inf), sizeof(frame_info_t));
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d dequeuing packet with timestamp %x in next buffer (ts=%x,length=%d,len=%d, packets=%d)",
|
||||
// __FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec, queued_packets->hdr.length, queued_packets->inf.len, n_packet );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d dequeuing packet with timestamp %x in next buffer (ts=%x,length=%d,len=%d, packets=%d)",
|
||||
__FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec, queued_packets->hdr.length, queued_packets->inf.len, n_packet );
|
||||
}
|
||||
else
|
||||
{
|
||||
//@ there are queued packets, but not the expected ones.
|
||||
//@ destroy packet buffer
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet with timestamp %x arrived (queued=%x, reset. grab new)",
|
||||
// __FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet with timestamp %x arrived (queued=%x, reset. grab new)",
|
||||
__FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec );
|
||||
mcast_packet_buffer_release(v->next);
|
||||
queued_packets = NULL;
|
||||
v->next = NULL;
|
||||
@@ -347,8 +353,8 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
}
|
||||
else
|
||||
{
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Queuing first packet %d/%d, data_len=%d",
|
||||
// __FUNCTION__,__LINE__, n_packet, hdr.length, info.len );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Queuing first packet %d/%d, data_len=%d",
|
||||
__FUNCTION__,__LINE__, n_packet, hdr.length, info.len );
|
||||
packet_len = inf.len;
|
||||
veejay_memcpy(&header,&hdr,sizeof(packet_header_t));
|
||||
veejay_memcpy(&info, &inf, sizeof(frame_info_t));
|
||||
@@ -362,7 +368,7 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
if( hdr.usec < header.usec )
|
||||
{
|
||||
put_data = 0;
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d dropped packet (too old timestamp %x)", __FUNCTION__,__LINE__,header.usec);
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d dropped packet (too old timestamp %x)", __FUNCTION__,__LINE__,header.usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -372,8 +378,8 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
{
|
||||
v->next = mcast_packet_buffer_new( &hdr, &inf, chunk );
|
||||
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG,"%s:%d Stored packet with timestamp %x (processing %x)",
|
||||
// __FUNCTION__,__LINE__, hdr.usec, header.usec );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG,"%s:%d Stored packet with timestamp %x (processing %x)",
|
||||
__FUNCTION__,__LINE__, hdr.usec, header.usec );
|
||||
|
||||
}
|
||||
else
|
||||
@@ -381,14 +387,14 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
// store packet if next buffer has identical timestamp
|
||||
if( mcast_packet_buffer_next( v->next, &hdr ) )
|
||||
{
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet buffer STORE future frame (ts=%x)", __FUNCTION__,__LINE__, hdr.usec );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet buffer STORE future frame (ts=%x)", __FUNCTION__,__LINE__, hdr.usec );
|
||||
mcast_packet_buffer_store( v->next, &hdr,chunk );
|
||||
put_data = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// release packet buffer and start queueing new frames only
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet buffer release, storing newest packets",__FUNCTION__,__LINE__ );
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet buffer release, storing newest packets",__FUNCTION__,__LINE__ );
|
||||
|
||||
if( mcast_packet_buffer_full( v->next ))
|
||||
{
|
||||
@@ -422,7 +428,7 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
|
||||
if( n_packet >= header.length )
|
||||
{
|
||||
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Have full frame",__FUNCTION__,__LINE__);
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Have full frame",__FUNCTION__,__LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -431,9 +437,6 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
|
||||
#ifdef STRICT_CHECKING
|
||||
assert( total_recv >= packet_len );
|
||||
#endif
|
||||
*dw = info.width;
|
||||
*dh = info.height;
|
||||
*dfmt = info.fmt;
|
||||
|
||||
return packet_len;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,10 @@ mcast_sender *mcast_new_sender( const char *group_name )
|
||||
// sizeof(int)) < 0 )
|
||||
// print_error();
|
||||
|
||||
char *eth = getenv("VEEJAY_MCAST_INTERFACE");
|
||||
if( eth != NULL ) {
|
||||
mcast_set_interface(v, eth );
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -132,7 +136,8 @@ int mcast_send( mcast_sender *v, const void *buf, int len, int port_num )
|
||||
{
|
||||
int n ;
|
||||
v->addr.sin_port = htons( port_num );
|
||||
|
||||
v->addr.sin_family = AF_INET;
|
||||
|
||||
n = sendto( v->sock_fd, buf, len, 0, (struct sockaddr*) &(v->addr), v->addr_len );
|
||||
|
||||
if( n == -1 )
|
||||
|
||||
@@ -54,7 +54,7 @@ typedef struct
|
||||
|
||||
#define PACKET_HEADER_LENGTH ( sizeof(packet_header_t) )
|
||||
#define PACKET_APP_HEADER_LENGTH ( sizeof(frame_info_t) )
|
||||
#define CHUNK_SIZE 2048
|
||||
#define CHUNK_SIZE ( 1500 - 28 )
|
||||
#define PACKET_PAYLOAD_SIZE (CHUNK_SIZE + PACKET_HEADER_LENGTH + PACKET_APP_HEADER_LENGTH )
|
||||
|
||||
void packet_dump_header( packet_header_t *h);
|
||||
|
||||
@@ -153,39 +153,53 @@ int vj_client_connect_dat(vj_client *v, char *host, int port_id )
|
||||
int vj_client_connect(vj_client *v, char *host, char *group_name, int port_id )
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if(port_id <= 0 || port_id > 65535)
|
||||
{
|
||||
veejay_msg(0, "Invalid port number '%d'", port_id );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( group_name == NULL )
|
||||
{
|
||||
|
||||
if(host == NULL)
|
||||
return 0;
|
||||
if(port_id <= 0 || port_id > 65535)
|
||||
return 0;
|
||||
|
||||
v->c[0]->type = VSOCK_C;
|
||||
v->c[0]->fd = alloc_sock_t();
|
||||
v->c[1]->type = VSOCK_S;
|
||||
v->c[1]->fd = alloc_sock_t();
|
||||
if(!v->c[0]->fd || !v->c[1]->fd )
|
||||
{
|
||||
{
|
||||
veejay_msg(0, "Error opening socket");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( sock_t_connect( v->c[0]->fd, host, port_id + VJ_CMD_PORT ) )
|
||||
{
|
||||
if( sock_t_connect( v->c[1]->fd, host, port_id + VJ_STA_PORT ) )
|
||||
{
|
||||
return 1;
|
||||
} else {
|
||||
veejay_msg(0, "Failed to connect to status port.");
|
||||
}
|
||||
} else {
|
||||
veejay_msg(0, "Failed to connect to command port.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(port_id <= 0 || port_id > 65535 )
|
||||
return 0;
|
||||
|
||||
v->c[0]->type = VMCAST_C;
|
||||
v->c[0]->r = mcast_new_receiver( group_name, port_id + VJ_CMD_MCAST );
|
||||
if(!v->c[0]->r ) {
|
||||
veejay_msg(0 ,"Unable to setup multicast receiver on group %s", group_name );
|
||||
return 0;
|
||||
}
|
||||
|
||||
v->c[0]->s = mcast_new_sender( group_name );
|
||||
if(!v->c[0]->s ) {
|
||||
veejay_msg(0, "Unable to setup multicast sender on group %s", group_name );
|
||||
return 0;
|
||||
}
|
||||
v->ports[0] = port_id + VJ_CMD_MCAST;
|
||||
v->ports[1] = port_id + VJ_CMD_MCAST_IN;
|
||||
|
||||
|
||||
@@ -153,8 +153,8 @@ static int _vj_server_multicast( vj_server *v, char *group_name, int port )
|
||||
link[i]->n_retrieved = 0;
|
||||
}
|
||||
v->link = (void**) link;
|
||||
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast frame sender ready at port %d (group '%s')",
|
||||
v->ports[0], group_name );
|
||||
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast frame sender ready at (group '%s')",
|
||||
group_name );
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
#include <veejay/vj-composite.h>
|
||||
#include <veejay/vj-viewport.h>
|
||||
#include <veejay/vj-OSC.h>
|
||||
|
||||
#define QUEUE_LEN 1
|
||||
#include <veejay/vims.h>
|
||||
#ifdef STRICT_CHECKING
|
||||
#include <assert.h>
|
||||
@@ -487,7 +487,6 @@ int veejay_free(veejay_t * info)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef USE_THREADS
|
||||
/******************************************************
|
||||
* veejay_busy()
|
||||
* Wait until playback is finished
|
||||
@@ -498,16 +497,11 @@ void veejay_busy(veejay_t * info)
|
||||
pthread_join( ((video_playback_setup*)(info->settings))->playback_thread, NULL );
|
||||
}
|
||||
|
||||
#endif
|
||||
void veejay_quit(veejay_t * info)
|
||||
{
|
||||
#ifdef USE_THREADS
|
||||
vj_lock(info);
|
||||
#endif
|
||||
veejay_change_state(info, LAVPLAY_STATE_STOP);
|
||||
#ifdef USE_THREADS
|
||||
vj_unlock(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -974,9 +968,7 @@ int veejay_stop(veejay_t * info)
|
||||
veejay_change_state(info, LAVPLAY_STATE_STOP);
|
||||
|
||||
/*pthread_cancel( settings->playback_thread ); */
|
||||
#ifdef USE_THREADS
|
||||
pthread_join(settings->playback_thread, NULL);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1008,7 +1000,6 @@ static int veejay_screen_update(veejay_t * info )
|
||||
int skip_update = 0;
|
||||
|
||||
video_playback_setup *settings = info->settings;
|
||||
|
||||
int check_vp = settings->composite;
|
||||
vj_perform_get_primary_frame(info,frame);
|
||||
if(check_vp)
|
||||
@@ -1202,26 +1193,12 @@ static void veejay_mjpeg_software_frame_sync(veejay_t * info,
|
||||
}
|
||||
|
||||
settings->first_frame = 0;
|
||||
#ifdef USE_THREADS
|
||||
/* We are done with writing the picture - Now update all surrounding info */
|
||||
gettimeofday(&(settings->lastframe_completion), 0);
|
||||
settings->syncinfo[settings->currently_processed_frame].timestamp =
|
||||
settings->lastframe_completion;
|
||||
#endif
|
||||
|
||||
}
|
||||
#ifndef USE_THREADS
|
||||
void veejay_sync_frame(veejay_t *info)
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
|
||||
|
||||
gettimeofday(&(settings->lastframe_completion), 0);
|
||||
settings->syncinfo[settings->currently_processed_frame].timestamp = settings->lastframe_completion;
|
||||
|
||||
}
|
||||
#endif
|
||||
void veejay_pipe_write_status(veejay_t * info, int link_id)
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
@@ -1477,7 +1454,6 @@ static void veejay_handle_callbacks(veejay_t *info) {
|
||||
/* update network */
|
||||
vj_event_update_remote( (void*)info );
|
||||
}
|
||||
#ifdef USE_THREADS
|
||||
void vj_lock(veejay_t *info)
|
||||
{
|
||||
video_playback_setup *settings = info->settings;
|
||||
@@ -1488,7 +1464,6 @@ void vj_unlock(veejay_t *info)
|
||||
video_playback_setup *settings = info->settings;
|
||||
pthread_mutex_unlock(&(settings->valid_mutex));
|
||||
}
|
||||
#endif
|
||||
static void donothing2(int sig)
|
||||
{
|
||||
veejay_msg(VEEJAY_MSG_WARNING,"Catched signal %x (ignored)",sig );
|
||||
@@ -1636,7 +1611,7 @@ static void veejay_event_handle(veejay_t *info)
|
||||
x_display_mouse_grab( info->gl, info->uc->mouse[0],info->uc->mouse[1],info->uc->mouse[2],
|
||||
info->uc->mouse[3] );
|
||||
|
||||
x_display_event( info->gl, info->current_edit_list->video_width, info->current_edit_list->video_height );
|
||||
x_display_event( info->gl, info->current_edit_list->video_width, info->current_edit_list->video_hei,,ght );
|
||||
|
||||
x_display_mouse_update( info->gl, &(info->uc->mouse[0]), &(info->uc->mouse[1]), &(info->uc->mouse[2]),
|
||||
&(info->uc->mouse[3]));
|
||||
@@ -1665,10 +1640,8 @@ static void *veejay_mjpeg_playback_thread(void *arg)
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
/* Allow easy shutting down by other processes... */
|
||||
#ifdef USE_THREADS
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||
|
||||
/* schedule FIFO */
|
||||
|
||||
veejay_schedule_fifo( info, getpid());
|
||||
@@ -1686,6 +1659,10 @@ static void *veejay_mjpeg_playback_thread(void *arg)
|
||||
while (settings->state != LAVPLAY_STATE_STOP) {
|
||||
pthread_mutex_lock(&(settings->valid_mutex));
|
||||
while (settings->valid[settings->currently_processed_frame] == 0) {
|
||||
#ifdef STRICT_CHECKING
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "Playback thread: sleeping for new frames (waiting for frame %d)",
|
||||
settings->currently_processed_frame);
|
||||
#endif
|
||||
pthread_cond_wait(&
|
||||
(settings->
|
||||
buffer_filled[settings->
|
||||
@@ -1701,7 +1678,6 @@ static void *veejay_mjpeg_playback_thread(void *arg)
|
||||
}
|
||||
pthread_mutex_unlock(&(settings->valid_mutex));
|
||||
|
||||
|
||||
if( settings->currently_processed_entry != settings->buffer_entry[settings->currently_processed_frame] &&
|
||||
!veejay_screen_update(info) )
|
||||
{
|
||||
@@ -1710,11 +1686,7 @@ static void *veejay_mjpeg_playback_thread(void *arg)
|
||||
settings->currently_processed_entry =
|
||||
settings->buffer_entry[settings->currently_processed_frame];
|
||||
|
||||
//@ here callbacks fixme was
|
||||
// pthread_mutex_lock(&(settings->valid_mutex));
|
||||
|
||||
// settings->currently_processed_entry =
|
||||
// settings->buffer_entry[settings->currently_processed_frame];
|
||||
// timestamp frame after sync
|
||||
|
||||
veejay_mjpeg_software_frame_sync(info,
|
||||
settings->valid[settings->
|
||||
@@ -1731,12 +1703,12 @@ static void *veejay_mjpeg_playback_thread(void *arg)
|
||||
buffer_done[settings->
|
||||
currently_processed_frame]));
|
||||
|
||||
// settings->previous_frame_num = settings->current_frame_num;
|
||||
|
||||
settings->currently_processed_frame =
|
||||
settings->currently_processed_frame =
|
||||
(settings->currently_processed_frame + 1) % 1;
|
||||
}
|
||||
#endif
|
||||
veejay_msg( VEEJAY_MSG_INFO, "Playback thread: was told to exit");
|
||||
pthread_exit(NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1753,21 +1725,23 @@ int veejay_open(veejay_t * info)
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
#ifdef USE_THREADS
|
||||
veejay_msg(VEEJAY_MSG_DEBUG,
|
||||
int i;
|
||||
veejay_msg(VEEJAY_MSG_DEBUG,
|
||||
"Initializing the threading system");
|
||||
|
||||
memset( &(settings->lastframe_completion), 0, sizeof(struct timeval));
|
||||
|
||||
pthread_mutex_init(&(settings->valid_mutex), NULL);
|
||||
pthread_mutex_init(&(settings->syncinfo_mutex), NULL);
|
||||
/* Invalidate all buffers, and initialize the conditions */
|
||||
for(i = 0; i < QUEUE_LEN ;i ++ ) {
|
||||
settings->valid[i] = 0;
|
||||
settings->buffer_entry[i] = 0;
|
||||
pthread_cond_init(&(settings->buffer_filled[i]), NULL);
|
||||
pthread_cond_init(&(settings->buffer_done[i]), NULL);
|
||||
|
||||
settings->valid[0] = 0;
|
||||
settings->buffer_entry[0] = 0;
|
||||
pthread_cond_init(&(settings->buffer_filled[0]), NULL);
|
||||
pthread_cond_init(&(settings->buffer_done[0]), NULL);
|
||||
|
||||
veejay_memset( &(settings->syncinfo[0]), 0, sizeof(struct mjpeg_sync));
|
||||
veejay_memset( &(settings->syncinfo[i]), 0, sizeof(struct mjpeg_sync));
|
||||
}
|
||||
|
||||
/* Now do the thread magic */
|
||||
settings->currently_processed_frame = 0;
|
||||
@@ -1784,7 +1758,6 @@ int veejay_open(veejay_t * info)
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
//@ collect geo statistics; how many times was veejay started from which geographical location
|
||||
//@ - do we do internationalization
|
||||
//@ - do we do veejay 2.0
|
||||
@@ -1834,10 +1807,10 @@ static int veejay_mjpeg_set_playback_rate(veejay_t * info,
|
||||
norm_usec_per_frame = 1001000 / 30; /* 30ish Hz */
|
||||
break;
|
||||
default:
|
||||
veejay_msg(VEEJAY_MSG_ERROR,
|
||||
veejay_msg(VEEJAY_MSG_WARNING,
|
||||
"Unknown video norm! Use PAL , SECAM or NTSC");
|
||||
return 0;
|
||||
|
||||
norm_usec_per_frame = 1000000 / (long) video_fps;
|
||||
break;
|
||||
}
|
||||
|
||||
if (video_fps != 0.0)
|
||||
@@ -1850,7 +1823,6 @@ static int veejay_mjpeg_set_playback_rate(veejay_t * info,
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef USE_THREADS
|
||||
/******************************************************
|
||||
* veejay_mjpeg_queue_buf()
|
||||
* queue a buffer
|
||||
@@ -1858,14 +1830,14 @@ static int veejay_mjpeg_set_playback_rate(veejay_t * info,
|
||||
* return value: 1 on success, 0 on error
|
||||
******************************************************/
|
||||
|
||||
static void veejay_mjpeg_queue_buf(veejay_t * info, int frame_periods)
|
||||
static void veejay_mjpeg_queue_buf(veejay_t * info,int frame, int frame_periods)
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
/* mark this buffer as playable and tell the software playback thread to wake up if it sleeps */
|
||||
pthread_mutex_lock(&(settings->valid_mutex));
|
||||
settings->valid[0] = frame_periods;
|
||||
pthread_cond_broadcast(&(settings->buffer_filled[0]));
|
||||
settings->valid[frame] = frame_periods;
|
||||
pthread_cond_broadcast(&(settings->buffer_filled[frame]));
|
||||
pthread_mutex_unlock(&(settings->valid_mutex));
|
||||
}
|
||||
|
||||
@@ -1876,13 +1848,11 @@ static void veejay_mjpeg_queue_buf(veejay_t * info, int frame_periods)
|
||||
*
|
||||
* return value: 1 on success, 0 on error
|
||||
******************************************************/
|
||||
#endif
|
||||
|
||||
static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
#ifdef USE_THREADS
|
||||
/* Wait until this buffer has been played */
|
||||
|
||||
pthread_mutex_lock(&(settings->valid_mutex));
|
||||
@@ -1893,15 +1863,13 @@ static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
|
||||
&(settings->valid_mutex));
|
||||
}
|
||||
pthread_mutex_unlock(&(settings->valid_mutex));
|
||||
#endif
|
||||
veejay_memcpy(bs, &(settings->syncinfo[settings->currently_synced_frame]),sizeof(struct mjpeg_sync));
|
||||
|
||||
settings->currently_synced_frame =
|
||||
(settings->currently_synced_frame + 1) % 1;
|
||||
(settings->currently_synced_frame + 1) % QUEUE_LEN;
|
||||
|
||||
return 1;
|
||||
}
|
||||
#ifdef USE_THREADS
|
||||
/******************************************************
|
||||
* veejay_mjpeg_close()
|
||||
* close down
|
||||
@@ -1917,7 +1885,7 @@ static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
|
||||
veejay_msg(VEEJAY_MSG_DEBUG,
|
||||
"Closing down the threading system ");
|
||||
|
||||
//pthread_cancel(settings->software_playback_thread);
|
||||
pthread_cancel(settings->software_playback_thread);
|
||||
if (pthread_join(settings->software_playback_thread, NULL)) {
|
||||
veejay_msg(VEEJAY_MSG_ERROR,
|
||||
"Failure deleting software playback thread");
|
||||
@@ -1927,7 +1895,6 @@ static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
/******************************************************
|
||||
* veejay_init()
|
||||
* check the given settings and initialize everything
|
||||
@@ -2304,6 +2271,9 @@ int veejay_init(veejay_t * info, int x, int y,char *arg, int def_tags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//@ FIXME
|
||||
//
|
||||
veejay_change_state( info, LAVPLAY_STATE_PLAYING );
|
||||
|
||||
if (!veejay_mjpeg_set_playback_rate(info, el->video_fps, el->video_norm == 'p' ? VIDEO_MODE_PAL : VIDEO_MODE_NTSC)) {
|
||||
@@ -2345,29 +2315,6 @@ static void veejay_schedule_fifo(veejay_t *info, int pid )
|
||||
* veejay_playback_cycle()
|
||||
* the playback cycle
|
||||
******************************************************/
|
||||
#ifndef USE_THREADS
|
||||
static void veejay_display_frame(veejay_t *info )
|
||||
{
|
||||
video_playback_setup *settings =
|
||||
(video_playback_setup *) info->settings;
|
||||
|
||||
//@ display
|
||||
if( settings->currently_processed_entry != settings->buffer_entry[settings->currently_processed_frame] &&
|
||||
!veejay_screen_update(info) )
|
||||
{
|
||||
veejay_msg(VEEJAY_MSG_WARNING, "Error playing frame %d", settings->current_frame_num);
|
||||
}
|
||||
settings->currently_processed_entry =
|
||||
settings->buffer_entry[settings->currently_processed_frame];
|
||||
|
||||
/* sync timestamp */
|
||||
veejay_mjpeg_software_frame_sync(info,1 );
|
||||
settings->syncinfo[settings->currently_processed_frame].frame =
|
||||
settings->currently_processed_frame;
|
||||
settings->currently_processed_frame =
|
||||
(settings->currently_processed_frame + 1) % 1;
|
||||
}
|
||||
#endif
|
||||
static void veejay_playback_cycle(veejay_t * info)
|
||||
{
|
||||
video_playback_stats stats;
|
||||
@@ -2381,29 +2328,22 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
int first_free, skipv, skipa, skipi, nvcorr,frame;
|
||||
struct mjpeg_params bp;
|
||||
long ts, te;
|
||||
long frame_number[2];
|
||||
int n;
|
||||
|
||||
veejay_set_instance( info );
|
||||
#ifndef USE_THREADS
|
||||
//@ from mjpeg_
|
||||
veejay_schedule_fifo( info, getpid());
|
||||
stats.tdiff = 0.0;
|
||||
stats.stats_changed = 0;
|
||||
stats.num_corrs_a = 0;
|
||||
stats.num_corrs_b = 0;
|
||||
stats.nsync = 0;
|
||||
stats.audio = 0;
|
||||
stats.norm = el->video_norm == 'n' ? 1 : 0;
|
||||
tdiff1 = 0.;
|
||||
tdiff2 = 0.;
|
||||
nvcorr = 0;
|
||||
|
||||
vj_get_relative_time();
|
||||
|
||||
vj_osc_set_veejay_t(info);
|
||||
vj_tag_set_veejay_t(info);
|
||||
|
||||
#ifdef HAVE_SDL
|
||||
if( info->settings->repeat_delay > 0 && info->settings->repeat_interval ) {
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if( settings->ncpu > 1 )
|
||||
{
|
||||
veejay_msg(VEEJAY_MSG_INFO, "Found %d cores.", settings->ncpu);
|
||||
}
|
||||
|
||||
if(info->current_edit_list->has_audio && info->audio == AUDIO_PLAY)
|
||||
if(info->current_edit_list->has_audio && info->audio == AUDIO_PLAY)
|
||||
{
|
||||
#ifdef HAVE_JACK
|
||||
info->audio_running = vj_perform_audio_start(info);
|
||||
@@ -2413,6 +2353,8 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
stats.audio = 0;
|
||||
}
|
||||
|
||||
veejay_set_speed(info,1);
|
||||
|
||||
switch(info->uc->playback_mode) {
|
||||
case VJ_PLAYBACK_MODE_PLAIN:
|
||||
info->current_edit_list = info->edit_list;
|
||||
@@ -2437,14 +2379,14 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
veejay_msg(VEEJAY_MSG_INFO, "Playing sample %d", info->uc->sample_id);
|
||||
break;
|
||||
}
|
||||
vj_perform_queue_audio_frame(info);
|
||||
/* vj_perform_queue_audio_frame(info);
|
||||
vj_perform_queue_video_frame(info,0);
|
||||
|
||||
if (vj_perform_queue_frame(info, 0) != 0)
|
||||
{
|
||||
veejay_msg(VEEJAY_MSG_ERROR,"Unable to queue frame");
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
bp.input = 0;
|
||||
bp.norm =
|
||||
@@ -2466,20 +2408,12 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
return ;
|
||||
}
|
||||
|
||||
stats.tdiff = 0.0;
|
||||
stats.stats_changed = 0;
|
||||
stats.num_corrs_a = 0;
|
||||
stats.num_corrs_b = 0;
|
||||
stats.nsync = 0;
|
||||
stats.audio = 0;
|
||||
stats.norm = el->video_norm == 'n' ? 1 : 0;
|
||||
tdiff1 = 0.;
|
||||
tdiff2 = 0.;
|
||||
nvcorr = 0;
|
||||
|
||||
#ifdef USE_THREADS
|
||||
veejay_mjpeg_queue_buf(info, 1 );
|
||||
#endif
|
||||
|
||||
for(n = 0; n < QUEUE_LEN ; n ++ ) {
|
||||
frame_number[n] = settings->current_frame_num;
|
||||
veejay_mjpeg_queue_buf(info, n,1 );
|
||||
}
|
||||
stats.nqueue = QUEUE_LEN;
|
||||
while (settings->state != LAVPLAY_STATE_STOP) {
|
||||
first_free = stats.nsync;
|
||||
|
||||
@@ -2499,6 +2433,13 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
goto FINISH;
|
||||
}
|
||||
frame = bs.frame;
|
||||
/* Since we queue the frames in order, we have to get them back in order */
|
||||
if (frame != stats.nsync % QUEUE_LEN)
|
||||
{
|
||||
veejay_msg(0,"**INTERNAL ERROR: Bad frame order on sync: frame = %d, nsync = %d, br.count = %ld",
|
||||
frame, stats.nsync, QUEUE_LEN);
|
||||
}
|
||||
|
||||
/* Broadcast & wake up the waiting processes */
|
||||
/* Now update the internal variables */
|
||||
|
||||
@@ -2507,10 +2448,12 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
stats.tdiff = time_now.tv_sec - bs.timestamp.tv_sec +
|
||||
(time_now.tv_usec - bs.timestamp.tv_usec)*1.e-6;
|
||||
}
|
||||
while (stats.tdiff > settings->spvf && (stats.nsync - first_free) < 0);
|
||||
#ifdef USE_THREADS
|
||||
while (stats.tdiff > settings->spvf && (stats.nsync - first_free) < (QUEUE_LEN-1));
|
||||
|
||||
if ((stats.nsync - first_free) > ( QUEUE_LEN - 3))
|
||||
veejay_msg(VEEJAY_MSG_WARNING, "Source too slow, can not keep pace!");
|
||||
|
||||
veejay_event_handle(info);
|
||||
#endif
|
||||
#ifdef HAVE_JACK
|
||||
if ( info->audio==AUDIO_PLAY && el->has_audio )
|
||||
{
|
||||
@@ -2531,7 +2474,6 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
#endif
|
||||
stats.tdiff = (tdiff1 - tdiff2);
|
||||
/* Fill and queue free buffers again */
|
||||
int n;
|
||||
for (n = first_free; n < stats.nsync;) {
|
||||
/* Audio/Video sync correction */
|
||||
skipv = 0;
|
||||
@@ -2562,7 +2504,8 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
}
|
||||
}
|
||||
|
||||
frame = 0;
|
||||
frame = n % QUEUE_LEN;
|
||||
frame_number[frame] = settings->current_frame_num;
|
||||
#ifdef HAVE_SDL
|
||||
ts= SDL_GetTicks();
|
||||
#endif
|
||||
@@ -2583,23 +2526,11 @@ static void veejay_playback_cycle(veejay_t * info)
|
||||
#endif
|
||||
if(skipv ) continue;
|
||||
|
||||
#ifdef USE_THREADS
|
||||
veejay_mjpeg_queue_buf(info, 1 );
|
||||
veejay_mjpeg_queue_buf(info,frame, 1 );
|
||||
|
||||
stats.nqueue ++;
|
||||
#endif
|
||||
n++;
|
||||
}
|
||||
#ifndef USE_THREADS
|
||||
veejay_event_handle(info);
|
||||
|
||||
|
||||
veejay_display_frame(info);
|
||||
|
||||
|
||||
veejay_sync_frame(info);
|
||||
#endif
|
||||
|
||||
/* output statistics */
|
||||
if (el->has_audio && (info->audio==AUDIO_PLAY))
|
||||
stats.audio = settings->audio_mute ? 0 : 1;
|
||||
@@ -2661,15 +2592,10 @@ static void Welcome(veejay_t *info)
|
||||
"If you want to start a new project, start veejay in an empty directory");
|
||||
}
|
||||
}
|
||||
#ifdef USE_THREADS
|
||||
static void *veejay_playback_thread(void *data)
|
||||
#else
|
||||
static void veejay_playback_thread(void *data)
|
||||
#endif
|
||||
{
|
||||
veejay_t *info = (veejay_t *) data;
|
||||
int i;
|
||||
#ifdef USE_THREADS
|
||||
sigset_t mask;
|
||||
struct sigaction act;
|
||||
sigemptyset(&mask);
|
||||
@@ -2681,12 +2607,9 @@ static void veejay_playback_thread(void *data)
|
||||
|
||||
pthread_sigmask( SIG_BLOCK, &mask, NULL );
|
||||
int mode, id;
|
||||
#endif
|
||||
Welcome(info);
|
||||
veejay_playback_cycle(info);
|
||||
#ifdef USE_THREADS
|
||||
veejay_close(info);
|
||||
#endif
|
||||
if(info->uc->is_server) {
|
||||
for(i = 0; i < 4; i ++ )
|
||||
if(info->vjs[i]) vj_server_shutdown(info->vjs[i]);
|
||||
@@ -2730,15 +2653,11 @@ static void veejay_playback_thread(void *data)
|
||||
vj_font_destroy( info->font );
|
||||
vj_font_destroy( info->osd );
|
||||
#endif
|
||||
#ifdef USE_THREADS
|
||||
veejay_msg(VEEJAY_MSG_DEBUG,"Exiting playback thread");
|
||||
#endif
|
||||
vj_perform_free(info);
|
||||
|
||||
#ifdef USE_THREADS
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2776,30 +2695,28 @@ int vj_server_setup(veejay_t * info)
|
||||
"Unable to initialize mcast sender");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast frame sender socket ready at port %d group %s",
|
||||
info->uc->port, info->settings->vims_group_name );
|
||||
}
|
||||
if(info->settings->use_mcast)
|
||||
{
|
||||
GoMultiCast( info->settings->group_name );
|
||||
}
|
||||
info->osc = (void*) vj_osc_allocate(info->uc->port+4);
|
||||
|
||||
info->osc = (void*) vj_osc_allocate(info->uc->port+6);
|
||||
|
||||
if(!info->osc)
|
||||
{
|
||||
veejay_msg(VEEJAY_MSG_ERROR,
|
||||
"Unable to start OSC server at port %d",
|
||||
info->uc->port + 4 );
|
||||
info->uc->port + 6 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( info->settings->use_mcast )
|
||||
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast OSC channel ready at port %d (group '%s')",
|
||||
info->uc->port + 4, info->settings->group_name );
|
||||
info->uc->port + 6, info->settings->group_name );
|
||||
else
|
||||
veejay_msg(VEEJAY_MSG_INFO, "UDP unicast OSC channel ready at port %d",
|
||||
info->uc->port + 4 );
|
||||
info->uc->port + 6 );
|
||||
|
||||
if(vj_osc_setup_addr_space(info->osc) == 0)
|
||||
veejay_msg(VEEJAY_MSG_INFO, "Initialized OSC (http://www.cnmat.berkeley.edu/OpenSoundControl/)");
|
||||
@@ -2970,15 +2887,6 @@ veejay_t *veejay_malloc()
|
||||
info->pixel_format = FMT_422F; //@default
|
||||
info->settings->ncpu = smp_check();
|
||||
|
||||
#ifndef USE_THREADS
|
||||
veejay_memset( &(info->settings->lastframe_completion), 0, sizeof(struct timeval));
|
||||
info->settings->valid[0] = 0;
|
||||
info->settings->buffer_entry[0] = 0;
|
||||
veejay_memset( &(info->settings->syncinfo[0]), 0, sizeof(struct mjpeg_sync));
|
||||
info->settings->currently_processed_frame = 0; //@obsolete?
|
||||
info->settings->currently_processed_entry = -1;
|
||||
#endif
|
||||
|
||||
int status = 0;
|
||||
int acj = 0;
|
||||
int tl = 0;
|
||||
@@ -3077,15 +2985,11 @@ int veejay_main(veejay_t * info)
|
||||
|
||||
/* Flush the Linux File buffers to disk */
|
||||
sync();
|
||||
#ifndef USE_THREADS
|
||||
veejay_playback_thread( (void*) info );
|
||||
#else
|
||||
if (pthread_create(&(settings->playback_thread),NULL,
|
||||
veejay_playback_thread, (void *) info)) {
|
||||
veejay_msg(VEEJAY_MSG_ERROR, "Failed to create thread");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,10 @@ veejay_t *veejay_malloc();
|
||||
void veejay_change_playback_mode(veejay_t *info, int pm, int sample);
|
||||
|
||||
int veejay_free(veejay_t *info);
|
||||
#ifdef USE_THREADS
|
||||
void vj_lock(veejay_t *info);
|
||||
|
||||
void vj_unlock(veejay_t *info);
|
||||
void veejay_busy(veejay_t * info);
|
||||
#endif
|
||||
void veejay_signal_loop(void *);
|
||||
|
||||
int veejay_init_editlist(veejay_t * info);
|
||||
|
||||
@@ -608,13 +608,9 @@ static void print_license()
|
||||
|
||||
static void donothing(int sig)
|
||||
{
|
||||
#ifdef USE_THREADS
|
||||
vj_lock(info);
|
||||
#endif
|
||||
veejay_handle_signal( info, sig );
|
||||
#ifdef USE_THREADS
|
||||
vj_unlock(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -712,7 +708,6 @@ int main(int argc, char **argv)
|
||||
veejay_msg(VEEJAY_MSG_ERROR, "Cannot start main playback cycle");
|
||||
return 1;
|
||||
}
|
||||
#ifdef USE_THREADS
|
||||
|
||||
|
||||
veejay_msg(VEEJAY_MSG_DEBUG, "Started playback");
|
||||
@@ -735,7 +730,6 @@ int main(int argc, char **argv)
|
||||
|
||||
veejay_quit(info);
|
||||
veejay_busy(info);
|
||||
#endif
|
||||
veejay_free(info);
|
||||
|
||||
veejay_msg(VEEJAY_MSG_INFO, "Thank you for using Veejay");
|
||||
|
||||
@@ -119,10 +119,6 @@ typedef struct
|
||||
|
||||
|
||||
typedef struct {
|
||||
#ifndef USE_THREADS
|
||||
pthread_t geo_stat;
|
||||
sigset_t signal_set;
|
||||
#else
|
||||
pthread_t software_playback_thread;
|
||||
pthread_t playback_thread;
|
||||
pthread_attr_t playback_attr;
|
||||
@@ -133,7 +129,6 @@ typedef struct {
|
||||
pthread_mutex_t syncinfo_mutex;
|
||||
pthread_t signal_thread;
|
||||
sigset_t signal_set;
|
||||
#endif
|
||||
struct timeval lastframe_completion; /* software sync variable */
|
||||
|
||||
long old_field_len;
|
||||
|
||||
Reference in New Issue
Block a user