multicast fixes, threading fixes

git-svn-id: svn://code.dyne.org/veejay/trunk@1322 eb8d1916-c9e9-0310-b8de-cf0c9472ead5
This commit is contained in:
Niels Elburg
2009-03-22 14:52:38 +00:00
parent 9150ad89a1
commit c4c1a60f21
10 changed files with 124 additions and 225 deletions

View File

@@ -199,18 +199,6 @@ if test x"$PKG_CONFIG_PATH" = x ; then
AC_MSG_ERROR([Abort]) AC_MSG_ERROR([Abort])
fi 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) AC_MSG_CHECKING(whether to compile in debugging information)
debugCFLAGS="" debugCFLAGS=""
if test "x$enable_debug" = "xyes" ; then 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([ - Unicap Imaging : ${have_unicap} ])
AC_MSG_NOTICE([ - libsamplerate : ${have_samplerate}]) AC_MSG_NOTICE([ - libsamplerate : ${have_samplerate}])
AC_MSG_NOTICE([ Compile time switches:])
AC_MSG_NOTICE([ - Threaded playback : ${have_playthread}])

View File

@@ -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 ); packet_header_t hdr = packet_get_header( chunk );
frame_info_t inf; frame_info_t inf;
packet_get_info(&inf,chunk ); 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? 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; total_recv = n_packet * CHUNK_SIZE;
veejay_memcpy(&header, &(queued_packets->hdr), sizeof(packet_header_t)); veejay_memcpy(&header, &(queued_packets->hdr), sizeof(packet_header_t));
veejay_memcpy(&info, &(queued_packets->inf), sizeof(frame_info_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)", 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 ); __FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec, queued_packets->hdr.length, queued_packets->inf.len, n_packet );
} }
else else
{ {
//@ there are queued packets, but not the expected ones. //@ there are queued packets, but not the expected ones.
//@ destroy packet buffer //@ destroy packet buffer
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d packet with timestamp %x arrived (queued=%x, reset. grab new)", 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 ); __FUNCTION__,__LINE__, hdr.usec, queued_packets->hdr.usec );
mcast_packet_buffer_release(v->next); mcast_packet_buffer_release(v->next);
queued_packets = NULL; queued_packets = NULL;
v->next = NULL; v->next = NULL;
@@ -347,8 +353,8 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
} }
else else
{ {
// veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Queuing first packet %d/%d, data_len=%d", veejay_msg(VEEJAY_MSG_DEBUG, "%s:%d Queuing first packet %d/%d, data_len=%d",
// __FUNCTION__,__LINE__, n_packet, hdr.length, info.len ); __FUNCTION__,__LINE__, n_packet, hdr.length, info.len );
packet_len = inf.len; packet_len = inf.len;
veejay_memcpy(&header,&hdr,sizeof(packet_header_t)); veejay_memcpy(&header,&hdr,sizeof(packet_header_t));
veejay_memcpy(&info, &inf, sizeof(frame_info_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 ) if( hdr.usec < header.usec )
{ {
put_data = 0; 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 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 ); v->next = mcast_packet_buffer_new( &hdr, &inf, chunk );
// veejay_msg(VEEJAY_MSG_DEBUG,"%s:%d Stored packet with timestamp %x (processing %x)", veejay_msg(VEEJAY_MSG_DEBUG,"%s:%d Stored packet with timestamp %x (processing %x)",
// __FUNCTION__,__LINE__, hdr.usec, header.usec ); __FUNCTION__,__LINE__, hdr.usec, header.usec );
} }
else 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 // store packet if next buffer has identical timestamp
if( mcast_packet_buffer_next( v->next, &hdr ) ) 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 ); mcast_packet_buffer_store( v->next, &hdr,chunk );
put_data = 0; put_data = 0;
} }
else else
{ {
// release packet buffer and start queueing new frames only // 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 )) 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 ) 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; break;
} }
@@ -431,9 +437,6 @@ int mcast_recv_frame( mcast_receiver *v, uint8_t *linear_buf, int total_len, int
#ifdef STRICT_CHECKING #ifdef STRICT_CHECKING
assert( total_recv >= packet_len ); assert( total_recv >= packet_len );
#endif #endif
*dw = info.width;
*dh = info.height;
*dfmt = info.fmt;
return packet_len; return packet_len;
} }

View File

@@ -90,6 +90,10 @@ mcast_sender *mcast_new_sender( const char *group_name )
// sizeof(int)) < 0 ) // sizeof(int)) < 0 )
// print_error(); // print_error();
char *eth = getenv("VEEJAY_MCAST_INTERFACE");
if( eth != NULL ) {
mcast_set_interface(v, eth );
}
return v; return v;
} }
@@ -132,6 +136,7 @@ int mcast_send( mcast_sender *v, const void *buf, int len, int port_num )
{ {
int n ; int n ;
v->addr.sin_port = htons( port_num ); 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 ); n = sendto( v->sock_fd, buf, len, 0, (struct sockaddr*) &(v->addr), v->addr_len );

View File

@@ -54,7 +54,7 @@ typedef struct
#define PACKET_HEADER_LENGTH ( sizeof(packet_header_t) ) #define PACKET_HEADER_LENGTH ( sizeof(packet_header_t) )
#define PACKET_APP_HEADER_LENGTH ( sizeof(frame_info_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 ) #define PACKET_PAYLOAD_SIZE (CHUNK_SIZE + PACKET_HEADER_LENGTH + PACKET_APP_HEADER_LENGTH )
void packet_dump_header( packet_header_t *h); void packet_dump_header( packet_header_t *h);

View File

@@ -153,14 +153,16 @@ 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 vj_client_connect(vj_client *v, char *host, char *group_name, int port_id )
{ {
int error = 0; 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( group_name == NULL )
{ {
if(host == NULL) if(host == NULL)
return 0; return 0;
if(port_id <= 0 || port_id > 65535)
return 0;
v->c[0]->type = VSOCK_C; v->c[0]->type = VSOCK_C;
v->c[0]->fd = alloc_sock_t(); v->c[0]->fd = alloc_sock_t();
@@ -168,24 +170,36 @@ int vj_client_connect(vj_client *v, char *host, char *group_name, int port_id )
v->c[1]->fd = alloc_sock_t(); v->c[1]->fd = alloc_sock_t();
if(!v->c[0]->fd || !v->c[1]->fd ) if(!v->c[0]->fd || !v->c[1]->fd )
{ {
veejay_msg(0, "Error opening socket");
return 0; return 0;
} }
if( sock_t_connect( v->c[0]->fd, host, port_id + VJ_CMD_PORT ) ) 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 ) ) if( sock_t_connect( v->c[1]->fd, host, port_id + VJ_STA_PORT ) )
{ {
return 1; return 1;
} else {
veejay_msg(0, "Failed to connect to status port.");
} }
} else {
veejay_msg(0, "Failed to connect to command port.");
} }
} }
else else
{ {
if(port_id <= 0 || port_id > 65535 )
return 0;
v->c[0]->type = VMCAST_C; v->c[0]->type = VMCAST_C;
v->c[0]->r = mcast_new_receiver( group_name, port_id + VJ_CMD_MCAST ); 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 ); 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[0] = port_id + VJ_CMD_MCAST;
v->ports[1] = port_id + VJ_CMD_MCAST_IN; v->ports[1] = port_id + VJ_CMD_MCAST_IN;

View File

@@ -153,8 +153,8 @@ static int _vj_server_multicast( vj_server *v, char *group_name, int port )
link[i]->n_retrieved = 0; link[i]->n_retrieved = 0;
} }
v->link = (void**) link; v->link = (void**) link;
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast frame sender ready at port %d (group '%s')", veejay_msg(VEEJAY_MSG_INFO, "UDP multicast frame sender ready at (group '%s')",
v->ports[0], group_name ); group_name );
return 1; return 1;
} }

View File

@@ -89,7 +89,7 @@
#include <veejay/vj-composite.h> #include <veejay/vj-composite.h>
#include <veejay/vj-viewport.h> #include <veejay/vj-viewport.h>
#include <veejay/vj-OSC.h> #include <veejay/vj-OSC.h>
#define QUEUE_LEN 1
#include <veejay/vims.h> #include <veejay/vims.h>
#ifdef STRICT_CHECKING #ifdef STRICT_CHECKING
#include <assert.h> #include <assert.h>
@@ -487,7 +487,6 @@ int veejay_free(veejay_t * info)
return 1; return 1;
} }
#ifdef USE_THREADS
/****************************************************** /******************************************************
* veejay_busy() * veejay_busy()
* Wait until playback is finished * 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 ); pthread_join( ((video_playback_setup*)(info->settings))->playback_thread, NULL );
} }
#endif
void veejay_quit(veejay_t * info) void veejay_quit(veejay_t * info)
{ {
#ifdef USE_THREADS
vj_lock(info); vj_lock(info);
#endif
veejay_change_state(info, LAVPLAY_STATE_STOP); veejay_change_state(info, LAVPLAY_STATE_STOP);
#ifdef USE_THREADS
vj_unlock(info); vj_unlock(info);
#endif
} }
@@ -974,9 +968,7 @@ int veejay_stop(veejay_t * info)
veejay_change_state(info, LAVPLAY_STATE_STOP); veejay_change_state(info, LAVPLAY_STATE_STOP);
/*pthread_cancel( settings->playback_thread ); */ /*pthread_cancel( settings->playback_thread ); */
#ifdef USE_THREADS
pthread_join(settings->playback_thread, NULL); pthread_join(settings->playback_thread, NULL);
#endif
return 1; return 1;
} }
@@ -1008,7 +1000,6 @@ static int veejay_screen_update(veejay_t * info )
int skip_update = 0; int skip_update = 0;
video_playback_setup *settings = info->settings; video_playback_setup *settings = info->settings;
int check_vp = settings->composite; int check_vp = settings->composite;
vj_perform_get_primary_frame(info,frame); vj_perform_get_primary_frame(info,frame);
if(check_vp) if(check_vp)
@@ -1202,26 +1193,12 @@ static void veejay_mjpeg_software_frame_sync(veejay_t * info,
} }
settings->first_frame = 0; settings->first_frame = 0;
#ifdef USE_THREADS
/* We are done with writing the picture - Now update all surrounding info */ /* We are done with writing the picture - Now update all surrounding info */
gettimeofday(&(settings->lastframe_completion), 0); gettimeofday(&(settings->lastframe_completion), 0);
settings->syncinfo[settings->currently_processed_frame].timestamp = settings->syncinfo[settings->currently_processed_frame].timestamp =
settings->lastframe_completion; 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) void veejay_pipe_write_status(veejay_t * info, int link_id)
{ {
video_playback_setup *settings = video_playback_setup *settings =
@@ -1477,7 +1454,6 @@ static void veejay_handle_callbacks(veejay_t *info) {
/* update network */ /* update network */
vj_event_update_remote( (void*)info ); vj_event_update_remote( (void*)info );
} }
#ifdef USE_THREADS
void vj_lock(veejay_t *info) void vj_lock(veejay_t *info)
{ {
video_playback_setup *settings = info->settings; video_playback_setup *settings = info->settings;
@@ -1488,7 +1464,6 @@ void vj_unlock(veejay_t *info)
video_playback_setup *settings = info->settings; video_playback_setup *settings = info->settings;
pthread_mutex_unlock(&(settings->valid_mutex)); pthread_mutex_unlock(&(settings->valid_mutex));
} }
#endif
static void donothing2(int sig) static void donothing2(int sig)
{ {
veejay_msg(VEEJAY_MSG_WARNING,"Catched signal %x (ignored)",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], x_display_mouse_grab( info->gl, info->uc->mouse[0],info->uc->mouse[1],info->uc->mouse[2],
info->uc->mouse[3] ); 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]), x_display_mouse_update( info->gl, &(info->uc->mouse[0]), &(info->uc->mouse[1]), &(info->uc->mouse[2]),
&(info->uc->mouse[3])); &(info->uc->mouse[3]));
@@ -1665,10 +1640,8 @@ static void *veejay_mjpeg_playback_thread(void *arg)
video_playback_setup *settings = video_playback_setup *settings =
(video_playback_setup *) info->settings; (video_playback_setup *) info->settings;
/* Allow easy shutting down by other processes... */ /* Allow easy shutting down by other processes... */
#ifdef USE_THREADS
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/* schedule FIFO */ /* schedule FIFO */
veejay_schedule_fifo( info, getpid()); veejay_schedule_fifo( info, getpid());
@@ -1686,6 +1659,10 @@ static void *veejay_mjpeg_playback_thread(void *arg)
while (settings->state != LAVPLAY_STATE_STOP) { while (settings->state != LAVPLAY_STATE_STOP) {
pthread_mutex_lock(&(settings->valid_mutex)); pthread_mutex_lock(&(settings->valid_mutex));
while (settings->valid[settings->currently_processed_frame] == 0) { 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(& pthread_cond_wait(&
(settings-> (settings->
buffer_filled[settings-> buffer_filled[settings->
@@ -1701,7 +1678,6 @@ static void *veejay_mjpeg_playback_thread(void *arg)
} }
pthread_mutex_unlock(&(settings->valid_mutex)); pthread_mutex_unlock(&(settings->valid_mutex));
if( settings->currently_processed_entry != settings->buffer_entry[settings->currently_processed_frame] && if( settings->currently_processed_entry != settings->buffer_entry[settings->currently_processed_frame] &&
!veejay_screen_update(info) ) !veejay_screen_update(info) )
{ {
@@ -1710,11 +1686,7 @@ static void *veejay_mjpeg_playback_thread(void *arg)
settings->currently_processed_entry = settings->currently_processed_entry =
settings->buffer_entry[settings->currently_processed_frame]; settings->buffer_entry[settings->currently_processed_frame];
//@ here callbacks fixme was // timestamp frame after sync
// pthread_mutex_lock(&(settings->valid_mutex));
// settings->currently_processed_entry =
// settings->buffer_entry[settings->currently_processed_frame];
veejay_mjpeg_software_frame_sync(info, veejay_mjpeg_software_frame_sync(info,
settings->valid[settings-> settings->valid[settings->
@@ -1731,12 +1703,12 @@ static void *veejay_mjpeg_playback_thread(void *arg)
buffer_done[settings-> buffer_done[settings->
currently_processed_frame])); 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; (settings->currently_processed_frame + 1) % 1;
} }
#endif veejay_msg( VEEJAY_MSG_INFO, "Playback thread: was told to exit");
pthread_exit(NULL);
return NULL; return NULL;
} }
@@ -1753,21 +1725,23 @@ int veejay_open(veejay_t * info)
{ {
video_playback_setup *settings = video_playback_setup *settings =
(video_playback_setup *) info->settings; (video_playback_setup *) info->settings;
#ifdef USE_THREADS int i;
veejay_msg(VEEJAY_MSG_DEBUG, veejay_msg(VEEJAY_MSG_DEBUG,
"Initializing the threading system"); "Initializing the threading system");
memset( &(settings->lastframe_completion), 0, sizeof(struct timeval)); memset( &(settings->lastframe_completion), 0, sizeof(struct timeval));
pthread_mutex_init(&(settings->valid_mutex), NULL); pthread_mutex_init(&(settings->valid_mutex), NULL);
pthread_mutex_init(&(settings->syncinfo_mutex), NULL);
/* Invalidate all buffers, and initialize the conditions */ /* 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; veejay_memset( &(settings->syncinfo[i]), 0, sizeof(struct mjpeg_sync));
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));
/* Now do the thread magic */ /* Now do the thread magic */
settings->currently_processed_frame = 0; 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 //@ collect geo statistics; how many times was veejay started from which geographical location
//@ - do we do internationalization //@ - do we do internationalization
//@ - do we do veejay 2.0 //@ - 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 */ norm_usec_per_frame = 1001000 / 30; /* 30ish Hz */
break; break;
default: default:
veejay_msg(VEEJAY_MSG_ERROR, veejay_msg(VEEJAY_MSG_WARNING,
"Unknown video norm! Use PAL , SECAM or NTSC"); "Unknown video norm! Use PAL , SECAM or NTSC");
return 0; norm_usec_per_frame = 1000000 / (long) video_fps;
break;
} }
if (video_fps != 0.0) if (video_fps != 0.0)
@@ -1850,7 +1823,6 @@ static int veejay_mjpeg_set_playback_rate(veejay_t * info,
return 1; return 1;
} }
#ifdef USE_THREADS
/****************************************************** /******************************************************
* veejay_mjpeg_queue_buf() * veejay_mjpeg_queue_buf()
* queue a buffer * 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 * 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 *settings =
(video_playback_setup *) info->settings; (video_playback_setup *) info->settings;
/* mark this buffer as playable and tell the software playback thread to wake up if it sleeps */ /* mark this buffer as playable and tell the software playback thread to wake up if it sleeps */
pthread_mutex_lock(&(settings->valid_mutex)); pthread_mutex_lock(&(settings->valid_mutex));
settings->valid[0] = frame_periods; settings->valid[frame] = frame_periods;
pthread_cond_broadcast(&(settings->buffer_filled[0])); pthread_cond_broadcast(&(settings->buffer_filled[frame]));
pthread_mutex_unlock(&(settings->valid_mutex)); 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 * return value: 1 on success, 0 on error
******************************************************/ ******************************************************/
#endif
static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs) static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
{ {
video_playback_setup *settings = video_playback_setup *settings =
(video_playback_setup *) info->settings; (video_playback_setup *) info->settings;
#ifdef USE_THREADS
/* Wait until this buffer has been played */ /* Wait until this buffer has been played */
pthread_mutex_lock(&(settings->valid_mutex)); 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)); &(settings->valid_mutex));
} }
pthread_mutex_unlock(&(settings->valid_mutex)); pthread_mutex_unlock(&(settings->valid_mutex));
#endif
veejay_memcpy(bs, &(settings->syncinfo[settings->currently_synced_frame]),sizeof(struct mjpeg_sync)); veejay_memcpy(bs, &(settings->syncinfo[settings->currently_synced_frame]),sizeof(struct mjpeg_sync));
settings->currently_synced_frame = settings->currently_synced_frame =
(settings->currently_synced_frame + 1) % 1; (settings->currently_synced_frame + 1) % QUEUE_LEN;
return 1; return 1;
} }
#ifdef USE_THREADS
/****************************************************** /******************************************************
* veejay_mjpeg_close() * veejay_mjpeg_close()
* close down * close down
@@ -1917,7 +1885,7 @@ static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
veejay_msg(VEEJAY_MSG_DEBUG, veejay_msg(VEEJAY_MSG_DEBUG,
"Closing down the threading system "); "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)) { if (pthread_join(settings->software_playback_thread, NULL)) {
veejay_msg(VEEJAY_MSG_ERROR, veejay_msg(VEEJAY_MSG_ERROR,
"Failure deleting software playback thread"); "Failure deleting software playback thread");
@@ -1927,7 +1895,6 @@ static int veejay_mjpeg_sync_buf(veejay_t * info, struct mjpeg_sync *bs)
return 1; return 1;
} }
#endif
/****************************************************** /******************************************************
* veejay_init() * veejay_init()
* check the given settings and initialize everything * 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 ); 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)) { 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() * veejay_playback_cycle()
* the 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) static void veejay_playback_cycle(veejay_t * info)
{ {
video_playback_stats stats; video_playback_stats stats;
@@ -2381,29 +2328,22 @@ static void veejay_playback_cycle(veejay_t * info)
int first_free, skipv, skipa, skipi, nvcorr,frame; int first_free, skipv, skipa, skipi, nvcorr,frame;
struct mjpeg_params bp; struct mjpeg_params bp;
long ts, te; long ts, te;
long frame_number[2];
int n;
veejay_set_instance( info ); veejay_set_instance( info );
#ifndef USE_THREADS stats.tdiff = 0.0;
//@ from mjpeg_ stats.stats_changed = 0;
veejay_schedule_fifo( info, getpid()); 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(); if(info->current_edit_list->has_audio && info->audio == AUDIO_PLAY)
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)
{ {
#ifdef HAVE_JACK #ifdef HAVE_JACK
info->audio_running = vj_perform_audio_start(info); info->audio_running = vj_perform_audio_start(info);
@@ -2413,6 +2353,8 @@ static void veejay_playback_cycle(veejay_t * info)
stats.audio = 0; stats.audio = 0;
} }
veejay_set_speed(info,1);
switch(info->uc->playback_mode) { switch(info->uc->playback_mode) {
case VJ_PLAYBACK_MODE_PLAIN: case VJ_PLAYBACK_MODE_PLAIN:
info->current_edit_list = info->edit_list; 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); veejay_msg(VEEJAY_MSG_INFO, "Playing sample %d", info->uc->sample_id);
break; break;
} }
vj_perform_queue_audio_frame(info); /* vj_perform_queue_audio_frame(info);
vj_perform_queue_video_frame(info,0); vj_perform_queue_video_frame(info,0);
if (vj_perform_queue_frame(info, 0) != 0) if (vj_perform_queue_frame(info, 0) != 0)
{ {
veejay_msg(VEEJAY_MSG_ERROR,"Unable to queue frame"); veejay_msg(VEEJAY_MSG_ERROR,"Unable to queue frame");
return; return;
} }*/
bp.input = 0; bp.input = 0;
bp.norm = bp.norm =
@@ -2466,20 +2408,12 @@ static void veejay_playback_cycle(veejay_t * info)
return ; 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 for(n = 0; n < QUEUE_LEN ; n ++ ) {
veejay_mjpeg_queue_buf(info, 1 ); frame_number[n] = settings->current_frame_num;
#endif veejay_mjpeg_queue_buf(info, n,1 );
}
stats.nqueue = QUEUE_LEN;
while (settings->state != LAVPLAY_STATE_STOP) { while (settings->state != LAVPLAY_STATE_STOP) {
first_free = stats.nsync; first_free = stats.nsync;
@@ -2499,6 +2433,13 @@ static void veejay_playback_cycle(veejay_t * info)
goto FINISH; goto FINISH;
} }
frame = bs.frame; 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 */ /* Broadcast & wake up the waiting processes */
/* Now update the internal variables */ /* 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 + stats.tdiff = time_now.tv_sec - bs.timestamp.tv_sec +
(time_now.tv_usec - bs.timestamp.tv_usec)*1.e-6; (time_now.tv_usec - bs.timestamp.tv_usec)*1.e-6;
} }
while (stats.tdiff > settings->spvf && (stats.nsync - first_free) < 0); while (stats.tdiff > settings->spvf && (stats.nsync - first_free) < (QUEUE_LEN-1));
#ifdef USE_THREADS
if ((stats.nsync - first_free) > ( QUEUE_LEN - 3))
veejay_msg(VEEJAY_MSG_WARNING, "Source too slow, can not keep pace!");
veejay_event_handle(info); veejay_event_handle(info);
#endif
#ifdef HAVE_JACK #ifdef HAVE_JACK
if ( info->audio==AUDIO_PLAY && el->has_audio ) if ( info->audio==AUDIO_PLAY && el->has_audio )
{ {
@@ -2531,7 +2474,6 @@ static void veejay_playback_cycle(veejay_t * info)
#endif #endif
stats.tdiff = (tdiff1 - tdiff2); stats.tdiff = (tdiff1 - tdiff2);
/* Fill and queue free buffers again */ /* Fill and queue free buffers again */
int n;
for (n = first_free; n < stats.nsync;) { for (n = first_free; n < stats.nsync;) {
/* Audio/Video sync correction */ /* Audio/Video sync correction */
skipv = 0; 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 #ifdef HAVE_SDL
ts= SDL_GetTicks(); ts= SDL_GetTicks();
#endif #endif
@@ -2583,23 +2526,11 @@ static void veejay_playback_cycle(veejay_t * info)
#endif #endif
if(skipv ) continue; if(skipv ) continue;
#ifdef USE_THREADS veejay_mjpeg_queue_buf(info,frame, 1 );
veejay_mjpeg_queue_buf(info, 1 );
stats.nqueue ++; stats.nqueue ++;
#endif
n++; n++;
} }
#ifndef USE_THREADS
veejay_event_handle(info);
veejay_display_frame(info);
veejay_sync_frame(info);
#endif
/* output statistics */ /* output statistics */
if (el->has_audio && (info->audio==AUDIO_PLAY)) if (el->has_audio && (info->audio==AUDIO_PLAY))
stats.audio = settings->audio_mute ? 0 : 1; 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"); "If you want to start a new project, start veejay in an empty directory");
} }
} }
#ifdef USE_THREADS
static void *veejay_playback_thread(void *data) static void *veejay_playback_thread(void *data)
#else
static void veejay_playback_thread(void *data)
#endif
{ {
veejay_t *info = (veejay_t *) data; veejay_t *info = (veejay_t *) data;
int i; int i;
#ifdef USE_THREADS
sigset_t mask; sigset_t mask;
struct sigaction act; struct sigaction act;
sigemptyset(&mask); sigemptyset(&mask);
@@ -2681,12 +2607,9 @@ static void veejay_playback_thread(void *data)
pthread_sigmask( SIG_BLOCK, &mask, NULL ); pthread_sigmask( SIG_BLOCK, &mask, NULL );
int mode, id; int mode, id;
#endif
Welcome(info); Welcome(info);
veejay_playback_cycle(info); veejay_playback_cycle(info);
#ifdef USE_THREADS
veejay_close(info); veejay_close(info);
#endif
if(info->uc->is_server) { if(info->uc->is_server) {
for(i = 0; i < 4; i ++ ) for(i = 0; i < 4; i ++ )
if(info->vjs[i]) vj_server_shutdown(info->vjs[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->font );
vj_font_destroy( info->osd ); vj_font_destroy( info->osd );
#endif #endif
#ifdef USE_THREADS
veejay_msg(VEEJAY_MSG_DEBUG,"Exiting playback thread"); veejay_msg(VEEJAY_MSG_DEBUG,"Exiting playback thread");
#endif
vj_perform_free(info); vj_perform_free(info);
#ifdef USE_THREADS
pthread_exit(NULL); pthread_exit(NULL);
return NULL; return NULL;
#endif
} }
/* /*
@@ -2776,30 +2695,28 @@ int vj_server_setup(veejay_t * info)
"Unable to initialize mcast sender"); "Unable to initialize mcast sender");
return 0; 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) if(info->settings->use_mcast)
{ {
GoMultiCast( info->settings->group_name ); 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) if(!info->osc)
{ {
veejay_msg(VEEJAY_MSG_ERROR, veejay_msg(VEEJAY_MSG_ERROR,
"Unable to start OSC server at port %d", "Unable to start OSC server at port %d",
info->uc->port + 4 ); info->uc->port + 6 );
return 0; return 0;
} }
if( info->settings->use_mcast ) if( info->settings->use_mcast )
veejay_msg(VEEJAY_MSG_INFO, "UDP multicast OSC channel ready at port %d (group '%s')", 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 else
veejay_msg(VEEJAY_MSG_INFO, "UDP unicast OSC channel ready at port %d", 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) if(vj_osc_setup_addr_space(info->osc) == 0)
veejay_msg(VEEJAY_MSG_INFO, "Initialized OSC (http://www.cnmat.berkeley.edu/OpenSoundControl/)"); 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->pixel_format = FMT_422F; //@default
info->settings->ncpu = smp_check(); 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 status = 0;
int acj = 0; int acj = 0;
int tl = 0; int tl = 0;
@@ -3077,15 +2985,11 @@ int veejay_main(veejay_t * info)
/* Flush the Linux File buffers to disk */ /* Flush the Linux File buffers to disk */
sync(); sync();
#ifndef USE_THREADS
veejay_playback_thread( (void*) info );
#else
if (pthread_create(&(settings->playback_thread),NULL, if (pthread_create(&(settings->playback_thread),NULL,
veejay_playback_thread, (void *) info)) { veejay_playback_thread, (void *) info)) {
veejay_msg(VEEJAY_MSG_ERROR, "Failed to create thread"); veejay_msg(VEEJAY_MSG_ERROR, "Failed to create thread");
return -1; return -1;
} }
#endif
return 1; return 1;
} }

View File

@@ -26,12 +26,10 @@ veejay_t *veejay_malloc();
void veejay_change_playback_mode(veejay_t *info, int pm, int sample); void veejay_change_playback_mode(veejay_t *info, int pm, int sample);
int veejay_free(veejay_t *info); int veejay_free(veejay_t *info);
#ifdef USE_THREADS
void vj_lock(veejay_t *info); void vj_lock(veejay_t *info);
void vj_unlock(veejay_t *info); void vj_unlock(veejay_t *info);
void veejay_busy(veejay_t * info); void veejay_busy(veejay_t * info);
#endif
void veejay_signal_loop(void *); void veejay_signal_loop(void *);
int veejay_init_editlist(veejay_t * info); int veejay_init_editlist(veejay_t * info);

View File

@@ -608,13 +608,9 @@ static void print_license()
static void donothing(int sig) static void donothing(int sig)
{ {
#ifdef USE_THREADS
vj_lock(info); vj_lock(info);
#endif
veejay_handle_signal( info, sig ); veejay_handle_signal( info, sig );
#ifdef USE_THREADS
vj_unlock(info); vj_unlock(info);
#endif
} }
int main(int argc, char **argv) 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"); veejay_msg(VEEJAY_MSG_ERROR, "Cannot start main playback cycle");
return 1; return 1;
} }
#ifdef USE_THREADS
veejay_msg(VEEJAY_MSG_DEBUG, "Started playback"); veejay_msg(VEEJAY_MSG_DEBUG, "Started playback");
@@ -735,7 +730,6 @@ int main(int argc, char **argv)
veejay_quit(info); veejay_quit(info);
veejay_busy(info); veejay_busy(info);
#endif
veejay_free(info); veejay_free(info);
veejay_msg(VEEJAY_MSG_INFO, "Thank you for using Veejay"); veejay_msg(VEEJAY_MSG_INFO, "Thank you for using Veejay");

View File

@@ -119,10 +119,6 @@ typedef struct
typedef struct { typedef struct {
#ifndef USE_THREADS
pthread_t geo_stat;
sigset_t signal_set;
#else
pthread_t software_playback_thread; pthread_t software_playback_thread;
pthread_t playback_thread; pthread_t playback_thread;
pthread_attr_t playback_attr; pthread_attr_t playback_attr;
@@ -133,7 +129,6 @@ typedef struct {
pthread_mutex_t syncinfo_mutex; pthread_mutex_t syncinfo_mutex;
pthread_t signal_thread; pthread_t signal_thread;
sigset_t signal_set; sigset_t signal_set;
#endif
struct timeval lastframe_completion; /* software sync variable */ struct timeval lastframe_completion; /* software sync variable */
long old_field_len; long old_field_len;