コード例 #1
0
ファイル: mjpeg.c プロジェクト: CSRedRat/vlc
/*****************************************************************************
 * Demux: read packet and send them to decoders
 *****************************************************************************
 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
 *****************************************************************************/
static int MjpgDemux( demux_t *p_demux )
{
    demux_sys_t *p_sys = p_demux->p_sys;
    int i;

    if( p_sys->b_still && p_sys->i_still_end )
    {
        /* Still frame, wait until the pause delay is gone */
        mwait( p_sys->i_still_end );
        p_sys->i_still_end = 0;
        return 1;
    }

    if( !Peek( p_demux, true ) )
    {
        msg_Warn( p_demux, "cannot peek data" );
        return 0;
    }
    if( p_sys->i_data_peeked < 4 )
    {
        msg_Warn( p_demux, "data shortage" );
        return 0;
    }
    i = 3;
FIND_NEXT_EOI:
    while( !( 0xFF == p_sys->p_peek[i-1] && 0xD9 == p_sys->p_peek[i] ) )
    {
        if( 0xFF == p_sys->p_peek[i-1] && 0xD8 == p_sys->p_peek[i] )
        {
            p_sys->i_level++;
            msg_Dbg( p_demux, "we found another JPEG SOI at %d", i );
        }
        i++;
        if( i >= p_sys->i_data_peeked )
        {
            msg_Dbg( p_demux, "did not find JPEG EOI in %d bytes",
                     p_sys->i_data_peeked );
            if( !Peek( p_demux, false ) )
            {
                msg_Warn( p_demux, "no more data is available at the moment" );
                return 0;
            }
        }
    }
    i++;

    msg_Dbg( p_demux, "JPEG EOI detected at %d", i );
    p_sys->i_level--;

    if( p_sys->i_level > 0 )
        goto FIND_NEXT_EOI;
    return SendBlock( p_demux, i );
}
コード例 #2
0
ファイル: main.c プロジェクト: jrepan/rhombus
static uint64_t start(struct tar_file *file, char const **argv) {
	int32_t pid;

	pid = fork();

	if (pid < 0) {
		execiv(file->start, file->size, argv);
		abort();
	}

	mwait(PORT_CHILD, pid);

	return RP_CONS(pid, 1);
}
void scanRegion(int first,int last){
	//arguments are first and last encoder readings for scan
	//scans accross looking for transition in light sensor
	//sets up threshold, range and direction parameters for edge tracking


	int rval,rmin,rmax; //light sensor readings, min and max
	int i;

	int cntM,cntP;
	int dsign;
	int res;
	rmin=10000; rmax=-10000;

	dsign=last>first?1:-1;
	nstep=20;
	step=(last-first)/20;
	if(step==0) {
		step=dsign;
		nstep=abs(last-first);
	}
	res=putMlight(first);
	while(res!=0) res=putMlight(first); //position light at first

	for(i=0;i<nstep;i++){
		nMotorEncoderTarget[M_lightsensor]=step;
		motor[M_lightsensor]=dsign*15+5;
		while(nMotorRunState[M_lightsensor] != runStateIdle){};
		motor[M_lightsensor]=0;
		mwait(25);
		rval=SensorValue[S_lightsensor];
		if(rval>rmax) rmax=rval;
		if(rval<rmin) rmin=rval;
		readings[i]=rval;
	}
	threshold=(rmin+rmax)/2;
	range=rmax-rmin;

	//get averages for better threshold
	avgM=0;avgP=0;cntM=0;cntP=0;
	for(i=0;i<nstep;i++){
		rsigns[i]=readings[i]<threshold?-1:1;
		if(rsigns[i]<0) {avgM+=readings[i]; cntM++; }
		else { avgP+=readings[i]; cntP++;}
	}
	avgM/=cntM;
	avgP/=cntP;
	threshold=(int)floor(0.5+(avgM+avgP)/2);
	range=(int)(1+(int)floor(avgP-avgM));
}
コード例 #4
0
ファイル: acore.c プロジェクト: qioixiy/harvey
/*
 * Main scheduling loop done by the application core.
 * Some of functions run will not return.
 * The system call handler will reset the stack and
 * call acsched again.
 * We loop because some functions may return and we should
 * wait for another call.
 */
void
acsched(void)
{
	acmmuswitch();
	for(;;){
		acstackok();
		mwait(&machp()->icc->fn);
		if(machp()->icc->flushtlb)
			acmmuswitch();
		DBG("acsched: cpu%d: fn %#p\n", machp()->machno, machp()->icc->fn);
		machp()->icc->fn();
		DBG("acsched: cpu%d: idle\n", machp()->machno);
		mfence();
		machp()->icc->fn = nil;
	}
}
コード例 #5
0
ファイル: alsa.c プロジェクト: shanewfx/vlc-arib
/*****************************************************************************
 * ALSAThread: asynchronous thread used to DMA the data to the device
 *****************************************************************************/
static void* ALSAThread( void *data )
{
    aout_instance_t * p_aout = data;
    struct aout_sys_t * p_sys = p_aout->output.p_sys;

    /* Wait for the exact time to start playing (avoids resampling) */
    vlc_sem_wait( &p_sys->wait );
    mwait( p_sys->start_date - AOUT_PTS_TOLERANCE / 4 );

    vlc_cleanup_push( pcm_drop, p_sys->p_snd_pcm );
    for(;;)
        ALSAFill( p_aout );

    assert(0);
    vlc_cleanup_pop();
}
コード例 #6
0
ファイル: sync.c プロジェクト: jrepan/rhombus
int rp_sync(uint64_t file) {
	struct msg *msg;

	msg = aalloc(sizeof(struct msg), PAGESZ);
	if (!msg) return 1;
	msg->source = RP_CURRENT_THREAD;
	msg->target = file;
	msg->length = 0;
	msg->port   = PORT_SYNC;
	msg->arch   = ARCH_NAT;

	if (msend(msg)) return 1;
	msg = mwait(PORT_REPLY, file);

	free(msg);
	return 0;
}
コード例 #7
0
ファイル: bandwidth.c プロジェクト: FLYKingdom/vlc
static ssize_t Read (access_t *access, uint8_t *buffer, size_t len)
{
    access_t *src = access->p_source;
    access_sys_t *p_sys = access->p_sys;
    mtime_t now;

    if (len == 0)
        return 0;

retry:
    now = mdate ();
    if (now <= p_sys->last_time)
    {
        msg_Err (access, "*** ALERT *** System clock is going backward! ***");
        return 0; /* Uho, your clock is broken. */
    }

    mtime_t delta = now - p_sys->last_time;
    p_sys->last_time = now;

    delta *= p_sys->bandwidth;
    delta /= 1000000u;

    if (delta == 0)
    {
        now += 1000000u / p_sys->bandwidth;
        mwait (now);
        goto retry;
    }

    if (len > delta)
    {
        msg_Dbg (access, "reading %"PRIu64" bytes instead of %zu", delta,
                 len);
        len = (int)delta;
    }


    src->info.i_update = access->info.i_update;
    len = src->pf_read (src, buffer, len);
    access->info = src->info;

    msg_Dbg (access, "read %zu bytes", len);
    return len;
}
コード例 #8
0
ファイル: acore.c プロジェクト: qioixiy/harvey
void
testicc(int i)
{
	Mach *mp;

	if((mp = sys->machptr[i]) != nil && mp->online != 0){
		if(mp->nixtype != NIXAC){
			print("testicc: core %d is not an AC\n", i);
			return;
		}
		print("calling core %d... ", i);
		mp->icc->flushtlb = 0;
		snprint(( char *)mp->icc->data, ICCLNSZ, "<%d>", i);
		mfence();
		mp->icc->fn = testiccfn;
		mwait(&mp->icc->fn);
	}
}
コード例 #9
0
ファイル: main.c プロジェクト: UIKit0/flux
static uint64_t start(struct tar_file *file, char const **argv) {
	int32_t pid;

	pid = fork();

	setenv("NAME", "unknown");

	if (pid < 0) {
		execiv(file->start, file->size, argv);
		for(;;);
	}

	setenv("NAME", "init");

	mwait(PORT_CHILD, RP_CONS(pid, 0));

	return RP_CONS(pid, 0);
}
コード例 #10
0
ファイル: image.c プロジェクト: jomanmuk/vlc-2.2
static int Demux(demux_t *demux)
{
    demux_sys_t *sys = demux->p_sys;

    if (!sys->data)
        return 0;

    mtime_t deadline;
    const mtime_t pts_first = sys->pts_origin + date_Get(&sys->pts);
    if (sys->pts_next > VLC_TS_INVALID) {
        deadline = sys->pts_next;
    } else if (sys->is_realtime) {
        deadline = mdate();
        const mtime_t max_wait = CLOCK_FREQ / 50;
        if (deadline + max_wait < pts_first) {
            es_out_Control(demux->out, ES_OUT_SET_PCR, deadline);
            /* That's ugly, but not yet easily fixable */
            mwait(deadline + max_wait);
            return 1;
        }
    } else {
        deadline = 1 + pts_first;
    }

    for (;;) {
        const mtime_t pts = sys->pts_origin + date_Get(&sys->pts);
        if (sys->duration >= 0 && pts >= sys->pts_origin + sys->duration)
            return 0;

        if (pts >= deadline)
            return 1;

        block_t *data = block_Duplicate(sys->data);
        if (!data)
            return -1;

        data->i_dts =
        data->i_pts = VLC_TS_0 + pts;
        es_out_Control(demux->out, ES_OUT_SET_PCR, data->i_pts);
        es_out_Send(demux->out, sys->es, data);

        date_Increment(&sys->pts, 1);
    }
}
コード例 #11
0
ファイル: interrupt.c プロジェクト: 0xheart0/vlc
int vlc_mwait_i11e(mtime_t deadline)
{
    vlc_interrupt_t *ctx = vlc_interrupt_get();
    if (ctx == NULL)
        return mwait(deadline), 0;

    vlc_cond_t wait;
    vlc_cond_init(&wait);

    vlc_interrupt_prepare(ctx, vlc_mwait_i11e_wake, &wait);

    vlc_mutex_lock(&ctx->lock);
    vlc_cleanup_push(vlc_mwait_i11e_cleanup, ctx);
    while (!ctx->interrupted
        && vlc_cond_timedwait(&wait, &ctx->lock, deadline) == 0);
    vlc_cleanup_pop();
    vlc_mutex_unlock(&ctx->lock);

    int ret = vlc_interrupt_finish(ctx);
    vlc_cond_destroy(&wait);
    return ret;
}
コード例 #12
0
ファイル: munlock.c プロジェクト: mhbackes/sisop1
int main() {
	int i;
	thread_t t[N_THREADS];
	mmutex_init(&mutex);
	
	printf("munlock executado antes de iniciar escalonador retorna %d.\n",
				munlock(&mutex));
	
	printf("Main criando %d threads...\n", N_THREADS);
	for (i = 0; i < N_THREADS; i++) {
		t[i].prio = 1;
		t[i].id = mcreate(1, (void *(*)(void*)) &print_thread_mutex, &t[i]);
	}
	printf("munlock executado com mutex livre retorna %d\n", munlock(&mutex));
	printf("Main esperando as threads...\n");
	for (i = 0; i < N_THREADS; i++) {
		mwait(t[i].id);
	}
	printf("Fim da funcao main...\n");
	
	return 0;
}
コード例 #13
0
ファイル: mutex1.c プロジェクト: dmknob/INF01142
int main ()
{
	int ids[MAX_THREADS];
	int i = 0;

	puts ("Started.");

        mmutex_init(&mutex);

	for (i=0; i < MAX_THREADS; i++)
	{
		ids[i] = mcreate(2,&makeWork, NULL);
		printf("Thread using TID %d started working...\n", ids[i]);
	}

	for (i=0; i < MAX_THREADS; i++)
	{
		mwait(ids[i]);
		printf("Thread using TID %d finished.\n", ids[i]);
	}

	exit(0);
}
コード例 #14
0
ファイル: creation.c プロジェクト: carolieberhart/sisop
int main(int arg, char **argcv){

	int nT=10;
		

	int *threads = (int*)malloc(nT*sizeof(int));
	int i;
	int n=0;


	if(threads==NULL)
		return 0;
	for(i=0;i<nT;i++){
		threads[i]=mcreate(i%2, (void*)doSomething, &n);
	}
	mwait(3);





	printf("\nEnd of main...\n");
	return 0;
}
コード例 #15
0
ファイル: teste_vetor.c プロジェクト: Aleuck/mthread
int main(int argc, char *argv[]) {
    int i, pid[MAX_THR];

  
    for (i = 0; i < MAX_THR; i++) {
        pid[i] = mcreate(1, func, (void *)('A'+i));
       if ( pid[i] == -1) {
          printf("ERRO: criação de thread!\n");
          exit(-1);
       }
     }

    for (i = 0; i < MAX_THR; i++) 
         mwait(pid[i]);

    for (i = 0; i < MAX_SIZE; i++) {    
        if ( (i % 20) == 0 )
           printf("\n");
        printf("%c", (char)vetor[i]);
    }
      
    printf("\nConcluido vetor de letras...\n");
    exit(0);
}
コード例 #16
0
ファイル: acore.c プロジェクト: qioixiy/harvey
/*
 * Entered in AP core context, upon traps (system calls go through acsyscall)
 * using up->dbgreg means cores MUST be homogeneous.
 *
 * BUG: We should setup some trapenable() mechanism for the AC,
 * so that code like fpu.c could arrange for handlers specific for
 * the AC, instead of doint that by hand here.
 *
 * All interrupts are masked while in the "kernel"
 */
void
actrap(Ureg *u)
{
	panic("actrap");
#if 0
	char *n;
	ACVctl *v;

	n = nil;

	_pmcupdate(m);
	if(m->proc != nil){
		m->proc->nactrap++;
		m->proc->actime1 = fastticks(nil);
	}
	if(u->type < nelem(acvctl)){
		v = acvctl[u->type];
		if(v != nil){
			DBG("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
			n = v->f(u, v->a);
			if(n != nil)
				goto Post;
			return;
		}
	}
	switch(u->type){
	case IdtDF:
		print("AC: double fault\n");
		dumpregs(u);
		ndnr();
	case IdtIPI:
		m->intr++;
		DBG("actrap: cpu%d: IPI\n", machp()->machno);
		apiceoi(IdtIPI);
		break;
	case IdtTIMER:
		apiceoi(IdtTIMER);
		panic("timer interrupt in an AC");
		break;
	case IdtPF:
		/* this case is here for debug only */
		m->pfault++;
		DBG("actrap: cpu%d: PF cr2 %#ullx\n", machp()->machno, cr2get());
		break;
	default:
		print("actrap: cpu%d: %ulld\n", machp()->machno, u->type);
	}
Post:
	m->icc->rc = ICCTRAP;
	m->cr2 = cr2get();
	memmove(m->proc->dbgreg, u, sizeof *u);
	m->icc->note = n;
	fpuprocsave(m->proc);
	_pmcupdate(m);
	mfence();
	m->icc->fn = nil;
	ready(m->proc);

	mwait(&m->icc->fn);

	if(m->icc->flushtlb)
		acmmuswitch();
	if(m->icc->fn != actrapret)
		acsched();
	DBG("actrap: ret\n");
	memmove(u, m->proc->dbgreg, sizeof *u);
	if(m->proc)
		m->proc->actime += fastticks2us(fastticks(nil) - m->proc->actime1);
#endif
}
コード例 #17
0
ファイル: dec.c プロジェクト: forthyen/SDesk
/*****************************************************************************
 * aout_DecPlay : filter & mix the decoded buffer
 *****************************************************************************/
int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
                  aout_buffer_t * p_buffer )
{
    if ( p_buffer->start_date == 0 )
    {
        msg_Warn( p_aout, "non-dated buffer received" );
        aout_BufferFree( p_buffer );
        return -1;
    }

    /* Apply the desynchronisation requested by the user */
    p_buffer->start_date += p_input->i_desync;
    p_buffer->end_date += p_input->i_desync;

    if ( p_buffer->start_date > mdate() + p_input->i_pts_delay +
         AOUT_MAX_ADVANCE_TIME )
    {
        msg_Warn( p_aout, "received buffer in the future ("I64Fd")",
                  p_buffer->start_date - mdate());
        aout_BufferFree( p_buffer );
        return -1;
    }

    p_buffer->end_date = p_buffer->start_date
                            + (mtime_t)(p_buffer->i_nb_samples * 1000000)
                                / p_input->input.i_rate;

    vlc_mutex_lock( &p_input->lock );

    if ( p_input->b_error )
    {
        vlc_mutex_unlock( &p_input->lock );
        aout_BufferFree( p_buffer );
        return -1;
    }

    if ( p_input->b_changed )
    {
        /* Maybe the allocation size has changed. Re-allocate a buffer. */
        aout_buffer_t * p_new_buffer;
        mtime_t duration = (1000000 * (mtime_t)p_buffer->i_nb_samples)
                            / p_input->input.i_rate;

        aout_BufferAlloc( &p_input->input_alloc, duration, NULL, p_new_buffer );
        p_aout->p_vlc->pf_memcpy( p_new_buffer->p_buffer, p_buffer->p_buffer,
                                  p_buffer->i_nb_bytes );
        p_new_buffer->i_nb_samples = p_buffer->i_nb_samples;
        p_new_buffer->i_nb_bytes = p_buffer->i_nb_bytes;
        p_new_buffer->start_date = p_buffer->start_date;
        p_new_buffer->end_date = p_buffer->end_date;
        aout_BufferFree( p_buffer );
        p_buffer = p_new_buffer;
        p_input->b_changed = 0;
    }

    /* If the buffer is too early, wait a while. */
    mwait( p_buffer->start_date - AOUT_MAX_PREPARE_TIME );

    if ( aout_InputPlay( p_aout, p_input, p_buffer ) == -1 )
    {
        vlc_mutex_unlock( &p_input->lock );
        return -1;
    }

    vlc_mutex_unlock( &p_input->lock );

    /* Run the mixer if it is able to run. */
    vlc_mutex_lock( &p_aout->mixer_lock );
    aout_MixerRun( p_aout );
    vlc_mutex_unlock( &p_aout->mixer_lock );

    return 0;
}
コード例 #18
0
/**
 * ProjectM update thread which do the rendering
 * @param p_this: the p_thread object
 */
static void *Thread( void *p_data )
{
    filter_t     *p_filter = (filter_t*)p_data;
    filter_sys_t *p_sys = p_filter->p_sys;
    int cancel = vlc_savecancel();
    video_format_t fmt;
    vout_opengl_t *gl;
    int i_last_width  = 0;
    int i_last_height = 0;
#ifdef HAVE_PROJECTM2
    projectM::Settings settings;
#endif

    /* Create the openGL provider */
    p_sys->p_vout =
        (vout_thread_t *)vlc_object_create( p_filter, sizeof(vout_thread_t) );
    if( !p_sys->p_vout )
        goto error;

    vlc_object_attach( p_sys->p_vout, p_filter );

    /* */
    video_format_Init( &fmt, 0 );
    video_format_Setup( &fmt, VLC_CODEC_RGB32,
                        p_sys->i_width, p_sys->i_height, 0, 1 );
    fmt.i_sar_num = 1;
    fmt.i_sar_den = 1;

    vout_display_state_t state;
    memset( &state, 0, sizeof(state) );
    state.cfg.display.sar.num = 1;
    state.cfg.display.sar.den = 1;
    state.cfg.is_display_filled = true;
    state.cfg.zoom.num = 1;
    state.cfg.zoom.den = 1;
    state.sar.num = 1;
    state.sar.den = 1;

    p_sys->p_vd = vout_NewDisplay( p_sys->p_vout, &fmt, &state, "opengl",
                                   300000, 1000000 );
    if( !p_sys->p_vd )
    {
        vlc_object_release( p_sys->p_vout );
        goto error;
    }
    var_Create( p_sys->p_vout, "fullscreen", VLC_VAR_BOOL );
    var_AddCallback( p_sys->p_vout, "fullscreen", VoutCallback, p_sys->p_vd );

    gl = vout_GetDisplayOpengl( p_sys->p_vd );
    if( !gl )
    {
        vout_DeleteDisplay( p_sys->p_vd, NULL );
        vlc_object_release( p_sys->p_vout );
        goto error;
    }

    /* Create the projectM object */
#ifndef HAVE_PROJECTM2
    p_sys->p_projectm = new projectM( p_sys->psz_config );
#else
    settings.meshX = 32;
    settings.meshY = 24;
    settings.fps = 35;
    settings.textureSize = 1024;
    settings.windowWidth = p_sys->i_width;
    settings.windowHeight = p_sys->i_height;
    settings.presetURL = p_sys->psz_preset_path;
    settings.titleFontURL =  p_sys->psz_title_font;
    settings.menuFontURL = p_sys->psz_menu_font;
    settings.smoothPresetDuration = 5;
    settings.presetDuration = 30;
    settings.beatSensitivity = 10;
    settings.aspectCorrection = 1;
    settings.easterEgg = 1;
    settings.shuffleEnabled = 1;
    p_sys->p_projectm = new projectM( settings );
#endif
    p_sys->i_buffer_size = p_sys->p_projectm->pcm()->maxsamples;
    p_sys->p_buffer = (float*)calloc( p_sys->i_buffer_size,
                                      sizeof( float ) );

    vlc_sem_post( &p_sys->ready );

    /* TODO: Give to projectm the name of the input
    p_sys->p_projectm->projectM_setTitle( "" ); */

    /* */
    for( ;; )
    {
        const mtime_t i_deadline = mdate() + CLOCK_FREQ / 50; /* 50 fps max */
        /* Manage the events */
        vout_ManageDisplay( p_sys->p_vd, true );
        if( p_sys->p_vd->cfg->display.width  != i_last_width ||
            p_sys->p_vd->cfg->display.height != i_last_height )
        {
            /* FIXME it is not perfect as we will have black bands */
            vout_display_place_t place;
            vout_display_PlacePicture( &place, &p_sys->p_vd->source, p_sys->p_vd->cfg, false );
            p_sys->p_projectm->projectM_resetGL( place.width, place.height );

            i_last_width  = p_sys->p_vd->cfg->display.width;
            i_last_height = p_sys->p_vd->cfg->display.height;
        }

        /* Render the image and swap the buffers */
        vlc_mutex_lock( &p_sys->lock );
        if( p_sys->i_nb_samples > 0 )
        {
            p_sys->p_projectm->pcm()->addPCMfloat( p_sys->p_buffer,
                                                   p_sys->i_nb_samples );
            p_sys->i_nb_samples = 0;
        }
        if( p_sys->b_quit )
        {
            vlc_mutex_unlock( &p_sys->lock );

            delete p_sys->p_projectm;
            vout_DeleteDisplay( p_sys->p_vd, NULL );
            vlc_object_release( p_sys->p_vout );
            return NULL;
        }
        vlc_mutex_unlock( &p_sys->lock );

        p_sys->p_projectm->renderFrame();

        /* */
        mwait( i_deadline );

        if( !vout_opengl_Lock(gl) )
        {
            vout_opengl_Swap( gl );
            vout_opengl_Unlock( gl );
        }
    }
    abort();

error:
    p_sys->b_error = true;
    vlc_sem_post( &p_sys->ready );
    return NULL;
}
コード例 #19
0
ファイル: main.c プロジェクト: jrepan/rhombus
int main() {
	struct tar_file *boot_image, *file;
	char const **argv;
	uint64_t temp, temp1, temp2;

	argv = malloc(sizeof(char*) * 4);

	/* Boot Image */
	boot_image = tar_parse((void*) BOOT_IMAGE);

	/* Dynamic Linker */
	file = tar_find(boot_image, "lib/dl.so");
	dl_load(file->start);

	/* Initial Root Filesystem / Device Filesystem / System Filesystem (tmpfs) */
	argv[0] = "tmpfs";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/tmpfs");
	fs_root = start(file, argv);
	fs_cons("/dev", "dir");
	fs_cons("/sys", "dir");
	
	/* Serial Driver */
	argv[0] = "serial";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/serial");
	fs_plink("/dev/serial", start(file, argv), NULL);
	ropen(1, fs_find("/dev/serial"), STAT_WRITER);
	ropen(2, fs_find("/dev/serial"), STAT_WRITER);
	stdout = fdopen(1, "w");
	stderr = fdopen(2, "w");

	fs_plink("/dev/stderr", fs_find("/dev/serial"), NULL);

	/* Keyboard Driver */
	argv[0] = "kbd";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/kbd");
	temp = start(file, argv);

	/* Graphics Driver */
	argv[0] = "svga";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/svga");
	start(file, argv);

	/* Init control file */
	fs_plink("/sys/init", RP_CONS(getpid(), 0), NULL);

	/* Initrd */
	initrd_init();
	fs_plink("/dev/initrd", RP_CONS(getpid(), 1), NULL);

	/* Root filesystem (tarfs) */
	argv[0] = "tarfs";
	argv[1] = "/dev/initrd";
	argv[2] = NULL;
	file = tar_find(boot_image, "sbin/tarfs");
	temp = start(file, argv);

	/* Link /dev and /sys and change root */
	temp1 = fs_find("/dev");
	temp2 = fs_find("/sys");
	fs_root = temp;
	fs_plink("/dev", temp1, NULL);
	fs_plink("/sys", temp2, NULL);

	/* Terminal Driver */
	argv[0] = "biterm";
	argv[1] = "/dev/kbd";
	argv[2] = "/dev/svga0";
	argv[3] = NULL;
	file = tar_find(boot_image, "sbin/biterm");
	fs_plink("/dev/tty", start(file, argv), NULL);

	/* Temporary filesystem */
	argv[0] = "tmpfs";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/tmpfs");
	fs_plink("/tmp", start(file, argv), NULL);

	/* Time Driver */
	argv[0] = "time";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/time");
	fs_plink("/dev/time", start(file, argv), NULL);

	/* Pipe Driver */
	argv[0] = "pipe";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/pipe");
	fs_plink("/sys/pipe", start(file, argv), NULL);

	setname("init");
	
	mwait(PORT_CHILD, 0);

	printf("INIT PANIC: system daemon died\n");
	for(;;);
	return 0;
}
コード例 #20
0
ファイル: glspectrum.c プロジェクト: AsamQi/vlc
/**
 * Update thread which do the rendering
 * @param p_this: the p_thread object
 */
static void *Thread( void *p_data )
{
    filter_t  *p_filter = (filter_t*)p_data;
    filter_sys_t *p_sys = p_filter->p_sys;

    video_format_t fmt;
    vlc_gl_t *gl;
    unsigned int i_last_width = 0;
    unsigned int i_last_height = 0;

    /* Create the openGL provider */
    p_sys->p_vout =
        (vout_thread_t *)vlc_object_create(p_filter, sizeof(vout_thread_t));
    if (!p_sys->p_vout)
        goto error;

    /* Configure the video format for the opengl provider. */
    video_format_Init(&fmt, 0);
    video_format_Setup(&fmt, VLC_CODEC_RGB32,
                       p_sys->i_width, p_sys->i_height, 0, 1 );
    fmt.i_sar_num = 1;
    fmt.i_sar_den = 1;

    /* Init vout state. */
    vout_display_state_t state;
    memset(&state, 0, sizeof(state));
    state.cfg.display.sar.num = 1;
    state.cfg.display.sar.den = 1;
    state.cfg.is_display_filled = true;
    state.cfg.zoom.num = 1;
    state.cfg.zoom.den = 1;
    state.sar.num = 1;
    state.sar.den = 1;

    p_sys->p_vd = vout_NewDisplay(p_sys->p_vout, &fmt, &state,
                                  "opengl", 1000000, 1000000);
    if (!p_sys->p_vd)
    {
        vlc_object_release(p_sys->p_vout);
        goto error;
    }

    gl = vout_GetDisplayOpengl(p_sys->p_vd);
    if (!gl)
    {
        vout_DeleteDisplay(p_sys->p_vd, NULL);
        vlc_object_release(p_sys->p_vout);
        goto error;
    }

    vlc_sem_post(&p_sys->ready);

    initOpenGLScene();

    float height[NB_BANDS] = {0};

    while (1)
    {
        block_t *block = block_FifoGet(p_sys->fifo);

        int canc = vlc_savecancel();

        /* Manage the events */
        vout_ManageDisplay(p_sys->p_vd, true);
        if (p_sys->p_vd->cfg->display.width != i_last_width ||
            p_sys->p_vd->cfg->display.height != i_last_height)
        {
            /* FIXME it is not perfect as we will have black bands */
            vout_display_place_t place;
            vout_display_PlacePicture(&place, &p_sys->p_vd->source,
                                      p_sys->p_vd->cfg, false);

            i_last_width  = p_sys->p_vd->cfg->display.width;
            i_last_height = p_sys->p_vd->cfg->display.height;
        }

        /* Horizontal scale for 20-band equalizer */
        const unsigned xscale[] = {0,1,2,3,4,5,6,7,8,11,15,20,27,
                                   36,47,62,82,107,141,184,255};

        fft_state *p_state; /* internal FFT data */

        unsigned i, j;
        float p_output[FFT_BUFFER_SIZE];           /* Raw FFT Result  */
        int16_t p_buffer1[FFT_BUFFER_SIZE];        /* Buffer on which we perform
                                                      the FFT (first channel) */
        int16_t p_dest[FFT_BUFFER_SIZE];           /* Adapted FFT result */
        float *p_buffl = (float*)block->p_buffer;  /* Original buffer */

        int16_t  *p_buffs;                         /* int16_t converted buffer */
        int16_t  *p_s16_buff;                      /* int16_t converted buffer */

        /* Allocate the buffer only if the number of samples change */
        if (block->i_nb_samples != p_sys->i_prev_nb_samples)
        {
            free(p_sys->p_prev_s16_buff);
            p_sys->p_prev_s16_buff = malloc(block->i_nb_samples *
                                            p_sys->i_channels *
                                            sizeof(int16_t));
            if (!p_sys->p_prev_s16_buff)
                goto release;
            p_sys->i_prev_nb_samples = block->i_nb_samples;
        }
        p_buffs = p_s16_buff = p_sys->p_prev_s16_buff;

        /* Convert the buffer to int16_t
           Pasted from float32tos16.c */
        for (i = block->i_nb_samples * p_sys->i_channels; i--;)
        {
            union {float f; int32_t i;} u;

            u.f = *p_buffl + 384.0;
            if (u.i > 0x43c07fff)
                *p_buffs = 32767;
            else if (u.i < 0x43bf8000)
                *p_buffs = -32768;
            else
                *p_buffs = u.i - 0x43c00000;

            p_buffl++; p_buffs++;
        }
        p_state = visual_fft_init();
        if (!p_state)
        {
            msg_Err(p_filter,"unable to initialize FFT transform");
            goto release;
        }
        p_buffs = p_s16_buff;
        for (i = 0 ; i < FFT_BUFFER_SIZE; i++)
        {
            p_output[i] = 0;
            p_buffer1[i] = *p_buffs;

            p_buffs += p_sys->i_channels;
            if (p_buffs >= &p_s16_buff[block->i_nb_samples * p_sys->i_channels])
                p_buffs = p_s16_buff;
        }
        fft_perform (p_buffer1, p_output, p_state);

        for (i = 0; i< FFT_BUFFER_SIZE; ++i)
            p_dest[i] = p_output[i] *  (2 ^ 16)
                        / ((FFT_BUFFER_SIZE / 2 * 32768) ^ 2);

        for (i = 0 ; i < NB_BANDS; i++)
        {
            /* Decrease the previous size of the bar. */
            height[i] -= BAR_DECREMENT;
            if (height[i] < 0)
                height[i] = 0;

            int y = 0;
            /* We search the maximum on one scale
               to determine the current size of the bar. */
            for (j = xscale[i]; j < xscale[i + 1]; j++)
            {
                if (p_dest[j] > y)
                     y = p_dest[j];
            }
            /* Calculate the height of the bar */
            float new_height = y != 0 ? log(y) * 0.4 : 0;
            height[i] = new_height > height[i]
                        ? new_height : height[i];
        }

        /* Determine the camera rotation angle. */
        p_sys->f_rotationAngle += p_sys->f_rotationIncrement;
        if (p_sys->f_rotationAngle <= -ROTATION_MAX)
            p_sys->f_rotationIncrement = ROTATION_INCREMENT;
        else if (p_sys->f_rotationAngle >= ROTATION_MAX)
            p_sys->f_rotationIncrement = -ROTATION_INCREMENT;

        /* Render the frame. */
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();
            glRotatef(p_sys->f_rotationAngle, 0, 1, 0);
            drawBars(height);
        glPopMatrix();

        /* Wait to swapp the frame on time. */
        mwait(block->i_pts + (block->i_length / 2));
        if (!vlc_gl_Lock(gl))
        {
            vlc_gl_Swap(gl);
            vlc_gl_Unlock(gl);
        }

release:
        block_Release(block);
        vlc_restorecancel(canc);
    }

    assert(0);

error:
    p_sys->b_error = true;
    vlc_sem_post(&p_sys->ready);
    return NULL;
}
コード例 #21
0
ファイル: lib.c プロジェクト: guillep19/frob
void primWait(ULONG c){mwait(c*100);}
コード例 #22
0
ファイル: gemevlib.c プロジェクト: ragnar76/emutos
/*
*       Do a multi-wait on the specified events.
*/
WORD ev_multi(WORD flags, MOBLK *pmo1, MOBLK *pmo2, LONG tmcount,
              LONG buparm, LONG mebuff, WORD prets[])
{
        QPB             m;
        register EVSPEC which;
        register WORD   what;
        register CQUEUE *pc;

                                                /* say nothing has      */
                                                /*   happened yet       */
        what = 0x0;
        which = 0;
                                                /* do a pre-check for a */
                                                /*   keystroke & then   */
                                                /*   clear out the forkq*/
        chkkbd();
        forker();
                                                /*   a keystroke        */
        if (flags & MU_KEYBD)
        {
                                                /* if a character is    */
                                                /*   ready then get it  */
          pc = &rlr->p_cda->c_q;
          if ( pc->c_cnt )
          {
            prets[4] = (UWORD) dq(pc);
            what |= MU_KEYBD;
          }
        }
                                                /* if we own the mouse  */
                                                /*   then do quick chks */
        if ( rlr == gl_mowner )
        {
                                                /* quick check button   */
          if (flags & MU_BUTTON)
          {
            if ( (mtrans > 1) &&
                 (downorup(pr_button, buparm)) )
            {
              what |= MU_BUTTON;
              prets[5] = pr_mclick;
            }
            else
            {
              if ( downorup(button, buparm) )
              {
                what |= MU_BUTTON;
                prets[5] = mclick;
              }
            }
          }
                                                /* quick check mouse rec*/
          if ( ( flags & MU_M1 ) &&     
               ( in_mrect(pmo1) ) )
              what |= MU_M1;
                                                /* quick check mouse rec*/
          if ( ( flags & MU_M2 ) &&
               ( in_mrect(pmo2) ) )
              what |= MU_M2;
        }
                                                /* quick check timer    */
        if (flags & MU_TIMER)
        {
          if ( tmcount == 0x0L )
            what |= MU_TIMER;
        }
                                                /* quick check message  */
        if (flags & MU_MESAG)
        {
          if ( rlr->p_qindex > 0 )
          {
            ap_rdwr(MU_MESAG, rlr, 16, mebuff);
            what |= MU_MESAG;
          }
        }
                                                /* check for quick out  */
                                                /*   if something has   */
                                                /*   already happened   */
        if (what == 0x0)
        {
                                                /* wait for a keystroke */
          if (flags & MU_KEYBD)
            iasync( MU_KEYBD, 0x0L );
                                                /* wait for a button    */
          if (flags & MU_BUTTON)
            iasync( MU_BUTTON, buparm );
                                                /* wait for mouse rect. */
          if (flags & MU_M1)
            iasync( MU_M1, ADDR(pmo1) );
                                                /* wait for mouse rect. */
          if (flags & MU_M2)
            iasync( MU_M2, ADDR(pmo2) ); 
                                                /* wait for message     */
          if (flags & MU_MESAG)
          {
            m.qpb_ppd = rlr;
            m.qpb_cnt = 16;
            m.qpb_buf = mebuff;
            iasync( MU_MESAG, ADDR(&m) );
          }
                                                /* wait for timer       */
          if (flags & MU_TIMER)
            iasync( MU_TIMER, tmcount / gl_ticktime );
                                                /* wait for events      */
          which = mwait( flags );
                                                /* cancel outstanding   */
                                                /*   events             */
          which |= acancel( flags );
        }
                                                /* get the returns      */
        ev_rets(&prets[0]);
                                                /* do aprets() if       */
                                                /*   something hasn't   */
                                                /*   already happened   */
        if (what == 0x0)
        {
          what = which;
          if (which & MU_KEYBD)
            prets[4] = apret(MU_KEYBD);
          if (which & MU_BUTTON)
            prets[5] = apret(MU_BUTTON);
          if (which & MU_M1)
            apret(MU_M1);
          if (which & MU_M2)
            apret(MU_M2);
          if (which & MU_MESAG)
            apret(MU_MESAG);
          if (which & MU_TIMER)
            apret(MU_TIMER);
        }
                                                  /* return what happened*/
        return( what );
}
コード例 #23
0
ファイル: udp.c プロジェクト: qdk0901/vlc
/*****************************************************************************
 * ThreadWrite: Write a packet on the network at the good time.
 *****************************************************************************/
static void* ThreadWrite( void *data )
{
    sout_access_out_t *p_access = data;
    sout_access_out_sys_t *p_sys = p_access->p_sys;
    mtime_t i_date_last = -1;
    const unsigned i_group = var_GetInteger( p_access,
                                             SOUT_CFG_PREFIX "group" );
    mtime_t i_to_send = i_group;
    unsigned i_dropped_packets = 0;

    for (;;)
    {
        block_t *p_pk = block_FifoGet( p_sys->p_fifo );
        mtime_t       i_date, i_sent;

        i_date = p_sys->i_caching + p_pk->i_dts;
        if( i_date_last > 0 )
        {
            if( i_date - i_date_last > 2000000 )
            {
                if( !i_dropped_packets )
                    msg_Dbg( p_access, "mmh, hole (%"PRId64" > 2s) -> drop",
                             i_date - i_date_last );

                block_FifoPut( p_sys->p_empty_blocks, p_pk );

                i_date_last = i_date;
                i_dropped_packets++;
                continue;
            }
            else if( i_date - i_date_last < -1000 )
            {
                if( !i_dropped_packets )
                    msg_Dbg( p_access, "mmh, packets in the past (%"PRId64")",
                             i_date_last - i_date );
            }
        }

        block_cleanup_push( p_pk );
        i_to_send--;
        if( !i_to_send || (p_pk->i_flags & BLOCK_FLAG_CLOCK) )
        {
            mwait( i_date );
            i_to_send = i_group;
        }
        if ( send( p_sys->i_handle, p_pk->p_buffer, p_pk->i_buffer, 0 ) == -1 )
            msg_Warn( p_access, "send error: %s", vlc_strerror_c(errno) );
        vlc_cleanup_pop();

        if( i_dropped_packets )
        {
            msg_Dbg( p_access, "dropped %i packets", i_dropped_packets );
            i_dropped_packets = 0;
        }

#if 1
        i_sent = mdate();
        if ( i_sent > i_date + 20000 )
        {
            msg_Dbg( p_access, "packet has been sent too late (%"PRId64 ")",
                     i_sent - i_date );
        }
#endif

        block_FifoPut( p_sys->p_empty_blocks, p_pk );

        i_date_last = i_date;
    }
    return NULL;
}
コード例 #24
0
ファイル: projectm.cpp プロジェクト: 0xheart0/vlc
/**
 * ProjectM update thread which do the rendering
 * @param p_this: the p_thread object
 */
static void *Thread( void *p_data )
{
    filter_t  *p_filter = (filter_t*)p_data;
    filter_sys_t *p_sys = p_filter->p_sys;
    vlc_gl_t *gl = p_sys->gl;
    locale_t loc;
    locale_t oldloc;

    projectM *p_projectm;
#ifndef HAVE_PROJECTM2
    char *psz_config;
#else
    char *psz_preset_path;
    char *psz_title_font;
    char *psz_menu_font;
    projectM::Settings settings;
#endif

    vlc_gl_MakeCurrent( gl );

    /* Work-around the projectM locale bug */
    loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
    oldloc = uselocale (loc);

    /* Create the projectM object */
#ifndef HAVE_PROJECTM2
    psz_config = var_InheritString( p_filter, "projectm-config" );
    p_projectm = new projectM( psz_config );
    free( psz_config );
#else
    psz_preset_path = var_InheritString( p_filter, "projectm-preset-path" );
#ifdef _WIN32
    if ( psz_preset_path == NULL )
    {
        char *psz_data_path = config_GetDataDir();
        asprintf( &psz_preset_path, "%s" DIR_SEP "visualization", psz_data_path );
        free( psz_data_path );
    }
#endif

    psz_title_font                = var_InheritString( p_filter, "projectm-title-font" );
    psz_menu_font                 = var_InheritString( p_filter, "projectm-menu-font" );

    settings.meshX                = var_InheritInteger( p_filter, "projectm-meshx" );
    settings.meshY                = var_InheritInteger( p_filter, "projectm-meshy" );
    settings.fps                  = 35;
    settings.textureSize          = var_InheritInteger( p_filter, "projectm-texture-size" );
    settings.windowWidth          = var_InheritInteger( p_filter, "projectm-width" );
    settings.windowHeight         = var_CreateGetInteger( p_filter, "projectm-height" );
    settings.presetURL            = psz_preset_path;
    settings.titleFontURL         = psz_title_font;
    settings.menuFontURL          = psz_menu_font;
    settings.smoothPresetDuration = 5;
    settings.presetDuration       = 30;
    settings.beatSensitivity      = 10;
    settings.aspectCorrection     = 1;
    settings.easterEgg            = 1;
    settings.shuffleEnabled       = 1;
    settings.softCutRatingsEnabled= false;

    p_projectm = new projectM( settings );

    free( psz_menu_font );
    free( psz_title_font );
    free( psz_preset_path );
#endif /* HAVE_PROJECTM2 */

    p_sys->i_buffer_size = p_projectm->pcm()->maxsamples;
    p_sys->p_buffer = (float*)calloc( p_sys->i_buffer_size,
                                      sizeof( float ) );

    /* Choose a preset randomly or projectM will always show the first one */
    if ( p_projectm->getPlaylistSize() > 0 )
        p_projectm->selectPreset( (unsigned)vlc_mrand48() % p_projectm->getPlaylistSize() );

    /* */
    for( ;; )
    {
        const mtime_t i_deadline = mdate() + CLOCK_FREQ / 50; /* 50 fps max */

        /* Manage the events */
        unsigned width, height;
        bool quit;

        if( vlc_gl_surface_CheckSize( gl, &width, &height ) )
            p_projectm->projectM_resetGL( width, height );

        /* Render the image and swap the buffers */
        vlc_mutex_lock( &p_sys->lock );
        if( p_sys->i_nb_samples > 0 )
        {
            p_projectm->pcm()->addPCMfloat( p_sys->p_buffer,
                                            p_sys->i_nb_samples );
            p_sys->i_nb_samples = 0;
        }
        quit = p_sys->b_quit;
        vlc_mutex_unlock( &p_sys->lock );

        if( quit )
            break;

        p_projectm->renderFrame();

        /* */
        mwait( i_deadline );

        if( !vlc_gl_Lock(gl) )
        {
            vlc_gl_Swap( gl );
            vlc_gl_Unlock( gl );
        }
    }

    delete p_projectm;

    if (loc != (locale_t)0)
    {
        uselocale (oldloc);
        freelocale (loc);
    }

    vlc_gl_ReleaseCurrent( gl );
    return NULL;
}
コード例 #25
0
ファイル: gemevlib.c プロジェクト: ragnar76/emutos
/*
*       Routine to block for a certain async event and return a
*       single return code.
*/
WORD ev_block(WORD code, LONG lvalue)
{
        mwait( iasync(code, lvalue) );
        return( apret(code) );
}
コード例 #26
0
ファイル: main.c プロジェクト: UIKit0/flux
int main() {
	struct tar_file *boot_image, *file;
	char const **argv;
	uint64_t temp, temp1, temp2;

	argv = malloc(sizeof(char*) * 4);

	/* Boot Image */
	boot_image = tar_parse((void*) BOOT_IMAGE);

	/* Dynamic Linker */
	file = tar_find(boot_image, "lib/dl.so");
	dl_load(file->start);

	/* Initial Root Filesystem / Device Filesystem / System Filesystem (tmpfs) */
	argv[0] = "tmpfs";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/tmpfs");
	fs_root = start(file, argv);
	io_cons("/dev", RP_TYPE_DIR);
	io_cons("/sys", RP_TYPE_DIR);

	/* Logfile */
	io_cons("/dev/stderr", RP_TYPE_FILE);

	/* Init control file */
	io_link("/sys/init", RP_CONS(getpid(), 1));

	/* Keyboard Driver */
	argv[0] = "kbd";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/kbd");
	temp = start(file, argv);

	/* Terminal Driver */
	argv[0] = "tty";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/tty");
	temp = start(file, argv);
	io_link("/dev/tty", temp);

	/* Splash */
	stdin = stderr = stdout = fopen("/dev/tty", "w");
	printf(splash);

	/* Initrd */
	initrd_init();
	io_link("/dev/initrd", RP_CONS(getpid(), 0));

	/* Root filesystem (tarfs) */
	argv[0] = "tarfs";
	argv[1] = "/dev/initrd";
	argv[2] = NULL;
	file = tar_find(boot_image, "sbin/tarfs");
	temp = start(file, argv);

	/* Link /dev and /sys and change root */
	temp1 = io_find("/dev");
	temp2 = io_find("/sys");
	fs_root = temp;
	io_link("/dev", temp1);
	io_link("/sys", temp2);

	/* Temporary filesystem */
	argv[0] = "tmpfs";
	argv[1] = NULL;	
	file = tar_find(boot_image, "sbin/tmpfs");
	io_link("/tmp", start(file, argv));

	/* Time Driver */
	argv[0] = "time";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/time");
	io_link("/dev/time", start(file, argv));

	/* Serial Driver */
	argv[0] = "serial";
	argv[1] = NULL;
	file = tar_find(boot_image, "sbin/serial");
	io_link("/dev/serial", start(file, argv));

	/* Path */
	setenv("PATH", "/bin");

	/* Flux Init Shell */
	argv[0] = "fish";
	argv[1] = NULL;
	file = tar_find(boot_image, "bin/fish");
	if (!file) {
		printf("critical error: no init shell found\n");
		for(;;);
	}

	if (fork() < 0) {
//		setcuser(1);
		execiv(file->start, file->size, argv);
	}

	setenv("NAME", "init");
	
	mwait(PORT_CHILD, 0);

	printf("INIT PANIC: system daemon died\n");
	for(;;);
	return 0;
}
コード例 #27
0
/**
 * ProjectM update thread which do the rendering
 * @param p_this: the p_thread object
 */
static void *Thread( void *p_data )
{
    filter_t  *p_filter = (filter_t*)p_data;
    filter_sys_t *p_sys = p_filter->p_sys;

    video_format_t fmt;
    vlc_gl_t *gl;
    unsigned int i_last_width  = 0;
    unsigned int i_last_height = 0;
    locale_t loc;
    locale_t oldloc;

    projectM *p_projectm;
#ifndef HAVE_PROJECTM2
    char *psz_config;
#else
    char *psz_preset_path;
    char *psz_title_font;
    char *psz_menu_font;
    projectM::Settings settings;
#endif

    vlc_savecancel();

    /* Create the openGL provider */
    p_sys->p_vout =
        (vout_thread_t *)vlc_object_create( p_filter, sizeof(vout_thread_t) );
    if( !p_sys->p_vout )
        goto error;

    /* */
    video_format_Init( &fmt, 0 );
    video_format_Setup( &fmt, VLC_CODEC_RGB32,
                        p_sys->i_width, p_sys->i_height, 0, 1 );
    fmt.i_sar_num = 1;
    fmt.i_sar_den = 1;

    vout_display_state_t state;
    memset( &state, 0, sizeof(state) );
    state.cfg.display.sar.num = 1;
    state.cfg.display.sar.den = 1;
    state.cfg.is_display_filled = true;
    state.cfg.zoom.num = 1;
    state.cfg.zoom.den = 1;
    state.sar.num = 1;
    state.sar.den = 1;

    p_sys->p_vd = vout_NewDisplay( p_sys->p_vout, &fmt, &state, "opengl",
                                   300000, 1000000 );
    if( !p_sys->p_vd )
    {
        vlc_object_release( p_sys->p_vout );
        goto error;
    }
    var_Create( p_sys->p_vout, "fullscreen", VLC_VAR_BOOL );
    var_AddCallback( p_sys->p_vout, "fullscreen", VoutCallback, p_sys->p_vd );

    gl = vout_GetDisplayOpengl( p_sys->p_vd );
    if( !gl )
    {
        vout_DeleteDisplay( p_sys->p_vd, NULL );
        vlc_object_release( p_sys->p_vout );
        goto error;
    }

    /* Work-around the projectM locale bug */
    loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
    oldloc = uselocale (loc);

    /* Create the projectM object */
#ifndef HAVE_PROJECTM2
    psz_config = var_InheritString( p_filter, "projectm-config" );
    p_projectm = new projectM( psz_config );
    free( psz_config );
#else
    psz_preset_path = var_InheritString( p_filter, "projectm-preset-path" );
#ifdef WIN32
    if ( psz_preset_path == NULL )
    {
        char *psz_data_path = config_GetDataDir( p_filter );
        asprintf( &psz_preset_path, "%s" DIR_SEP "visualization", psz_data_path );
        free( psz_data_path );
    }
#endif

    psz_title_font                = var_InheritString( p_filter, "projectm-title-font" );
    psz_menu_font                 = var_InheritString( p_filter, "projectm-menu-font" );

    settings.meshX                = var_InheritInteger( p_filter, "projectm-meshx" );
    settings.meshY                = var_InheritInteger( p_filter, "projectm-meshy" );
    settings.fps                  = 35;
    settings.textureSize          = var_InheritInteger( p_filter, "projectm-texture-size" );
    settings.windowWidth          = p_sys->i_width;
    settings.windowHeight         = p_sys->i_height;
    settings.presetURL            = psz_preset_path;
    settings.titleFontURL         = psz_title_font;
    settings.menuFontURL          = psz_menu_font;
    settings.smoothPresetDuration = 5;
    settings.presetDuration       = 30;
    settings.beatSensitivity      = 10;
    settings.aspectCorrection     = 1;
    settings.easterEgg            = 1;
    settings.shuffleEnabled       = 1;

    p_projectm = new projectM( settings );

    free( psz_menu_font );
    free( psz_title_font );
    free( psz_preset_path );
#endif /* HAVE_PROJECTM2 */

    p_sys->i_buffer_size = p_projectm->pcm()->maxsamples;
    p_sys->p_buffer = (float*)calloc( p_sys->i_buffer_size,
                                      sizeof( float ) );

    vlc_sem_post( &p_sys->ready );

    /* Choose a preset randomly or projectM will always show the first one */
    if ( p_projectm->getPlaylistSize() > 0 )
        p_projectm->selectPreset( (unsigned)vlc_mrand48() % p_projectm->getPlaylistSize() );

    /* */
    for( ;; )
    {
        const mtime_t i_deadline = mdate() + CLOCK_FREQ / 50; /* 50 fps max */
        /* Manage the events */
        vout_ManageDisplay( p_sys->p_vd, true );
        if( p_sys->p_vd->cfg->display.width  != i_last_width ||
            p_sys->p_vd->cfg->display.height != i_last_height )
        {
            /* FIXME it is not perfect as we will have black bands */
            vout_display_place_t place;
            vout_display_PlacePicture( &place, &p_sys->p_vd->source, p_sys->p_vd->cfg, false );
            p_projectm->projectM_resetGL( place.width, place.height );

            i_last_width  = p_sys->p_vd->cfg->display.width;
            i_last_height = p_sys->p_vd->cfg->display.height;
        }

        /* Render the image and swap the buffers */
        vlc_mutex_lock( &p_sys->lock );
        if( p_sys->i_nb_samples > 0 )
        {
            p_projectm->pcm()->addPCMfloat( p_sys->p_buffer,
                                            p_sys->i_nb_samples );
            p_sys->i_nb_samples = 0;
        }
        if( p_sys->b_quit )
        {
            vlc_mutex_unlock( &p_sys->lock );

            delete p_projectm;
            vout_DeleteDisplay( p_sys->p_vd, NULL );
            vlc_object_release( p_sys->p_vout );
            if (loc != (locale_t)0)
            {
                uselocale (oldloc);
                freelocale (loc);
            }
            return NULL;
        }
        vlc_mutex_unlock( &p_sys->lock );

        p_projectm->renderFrame();

        /* */
        mwait( i_deadline );

        if( !vlc_gl_Lock(gl) )
        {
            vlc_gl_Swap( gl );
            vlc_gl_Unlock( gl );
        }
    }
    abort();

error:
    p_sys->b_error = true;
    vlc_sem_post( &p_sys->ready );
    return NULL;
}
コード例 #28
0
ファイル: audioscrobbler.c プロジェクト: 0xheart0/vlc
/*****************************************************************************
 * Run : call Handshake() then submit songs
 *****************************************************************************/
static void *Run(void *data)
{
    intf_thread_t          *p_intf = data;
    uint8_t                 p_buffer[1024];
    int                     canc = vlc_savecancel();
    bool                    b_handshaked = false;
    bool                    b_nowp_submission_ongoing = false;

    /* data about audioscrobbler session */
    mtime_t                 next_exchange = 0; /**< when can we send data  */
    unsigned int            i_interval = 0;     /**< waiting interval (secs)*/

    intf_sys_t *p_sys = p_intf->p_sys;

    /* main loop */
    for (;;)
    {
        vlc_restorecancel(canc);
        mwait(next_exchange);

        vlc_mutex_lock(&p_sys->lock);
        mutex_cleanup_push(&p_sys->lock);

        while (p_sys->i_songs == 0 && p_sys->b_submit_nowp == false)
            vlc_cond_wait(&p_sys->wait, &p_sys->lock);

        vlc_cleanup_pop();
        vlc_mutex_unlock(&p_sys->lock);
        canc = vlc_savecancel();

        /* handshake if needed */
        if (!b_handshaked)
        {
            msg_Dbg(p_intf, "Handshaking with last.fm ...");

            switch(Handshake(p_intf))
            {
                case VLC_ENOMEM:
                    goto out;

                case VLC_ENOVAR:
                    /* username not set */
                    vlc_dialog_display_error(p_intf,
                        _("Last.fm username not set"),
                        "%s", _("Please set a username or disable the "
                        "audioscrobbler plugin, and restart VLC.\n"
                        "Visit http://www.last.fm/join/ to get an account."));
                    goto out;

                case VLC_SUCCESS:
                    msg_Dbg(p_intf, "Handshake successful :)");
                    b_handshaked = true;
                    i_interval = 0;
                    next_exchange = 0;
                    break;

                case VLC_AUDIOSCROBBLER_EFATAL:
                    msg_Warn(p_intf, "Exiting...");
                    goto out;

                case VLC_EGENERIC:
                default:
                    /* protocol error : we'll try later */
                    HandleInterval(&next_exchange, &i_interval);
                    break;
            }
            /* if handshake failed let's restart the loop */
            if (!b_handshaked)
                continue;
        }

        msg_Dbg(p_intf, "Going to submit some data...");
        char *psz_submit;
        vlc_url_t *url;
        char *psz_submit_song, *psz_submit_tmp;

        if (asprintf(&psz_submit, "s=%s", p_sys->psz_auth_token) == -1)
            break;

        /* forge the HTTP POST request */
        vlc_mutex_lock(&p_sys->lock);

        if (p_sys->b_submit_nowp)
        {
            b_nowp_submission_ongoing = true;
            url = &p_sys->p_nowp_url;
            if (asprintf(&psz_submit_song,
                "&a=%s"
                "&t=%s"
                "&b=%s"
                "&l=%d"
                "&n=%s"
                "&m=%s",
                p_sys->p_current_song.psz_a,
                p_sys->p_current_song.psz_t,
                p_sys->p_current_song.psz_b ? p_sys->p_current_song.psz_b : "",
                p_sys->p_current_song.i_l,
                p_sys->p_current_song.psz_n ? p_sys->p_current_song.psz_n : "",
                p_sys->p_current_song.psz_m ? p_sys->p_current_song.psz_m : ""
                ) == -1)
            {   /* Out of memory */
                vlc_mutex_unlock(&p_sys->lock);
                goto out;
            }

        }
        else
        {
            url = &p_sys->p_submit_url;
            audioscrobbler_song_t *p_song;
            for (int i_song = 0 ; i_song < p_sys->i_songs ; i_song++)
            {
                p_song = &p_sys->p_queue[i_song];
                if (asprintf(&psz_submit_song,
                        "&a%%5B%d%%5D=%s"
                        "&t%%5B%d%%5D=%s"
                        "&i%%5B%d%%5D=%u"
                        "&o%%5B%d%%5D=P"
                        "&r%%5B%d%%5D="
                        "&l%%5B%d%%5D=%d"
                        "&b%%5B%d%%5D=%s"
                        "&n%%5B%d%%5D=%s"
                        "&m%%5B%d%%5D=%s",
                        i_song, p_song->psz_a,
                        i_song, p_song->psz_t,
                        i_song, (unsigned)p_song->date, /* HACK: %ju (uintmax_t) unsupported on Windows */
                        i_song,
                        i_song,
                        i_song, p_song->i_l,
                        i_song, p_song->psz_b ? p_song->psz_b : "",
                        i_song, p_song->psz_n ? p_song->psz_n : "",
                        i_song, p_song->psz_m ? p_song->psz_m : ""
                       ) == -1)
                {   /* Out of memory */
                        vlc_mutex_unlock(&p_sys->lock);
                        goto out;
                }
            }
        }

        psz_submit_tmp = psz_submit;
        int print_ret = asprintf(&psz_submit, "%s%s",
                                 psz_submit_tmp, psz_submit_song);
        free(psz_submit_tmp);
        free(psz_submit_song);
        vlc_mutex_unlock(&p_sys->lock);

        if (print_ret == -1)
        {   /* Out of memory */
            goto out;
        }

        int i_post_socket = net_ConnectTCP(p_intf, url->psz_host,
                                        url->i_port);

        if (i_post_socket == -1)
        {
            /* If connection fails, we assume we must handshake again */
            HandleInterval(&next_exchange, &i_interval);
            b_handshaked = false;
            free(psz_submit);
            continue;
        }

        /* we transmit the data */
        int i_net_ret = net_Printf(p_intf, i_post_socket,
            "POST %s HTTP/1.1\r\n"
            "Host: %s\r\n"
            "User-Agent: "PACKAGE_NAME"/"PACKAGE_VERSION"\r\n"
            "Connection: close\r\n"
            "Accept-Encoding: identity\r\n"
            "Content-Type: application/x-www-form-urlencoded\r\n"
            "Content-Length: %zu\r\n"
            "\r\n"
            "%s\r\n"
            "\r\n",
            url->psz_path, url->psz_host, strlen(psz_submit), psz_submit);

        free(psz_submit);
        if (i_net_ret == -1)
        {
            /* If connection fails, we assume we must handshake again */
            HandleInterval(&next_exchange, &i_interval);
            b_handshaked = false;
            net_Close(i_post_socket);
            continue;
        }

        /* FIXME: this might wait forever */
        struct pollfd ufd = { .fd = i_post_socket, .events = POLLIN };
        while( poll( &ufd, 1, -1 ) == -1 );

        /* FIXME: With TCP, you should never assume that a single read will
         * return the entire response... */
        i_net_ret = recv(i_post_socket, p_buffer, sizeof(p_buffer) - 1, 0);
        if (i_net_ret <= 0)
        {
            /* if we get no answer, something went wrong : try again */
            net_Close(i_post_socket);
            continue;
        }

        net_Close(i_post_socket);
        p_buffer[i_net_ret] = '\0';

        char *failed = strstr((char *) p_buffer, "FAILED");
        if (failed)
        {
            msg_Warn(p_intf, "%s", failed);
            HandleInterval(&next_exchange, &i_interval);
            continue;
        }

        if (strstr((char *) p_buffer, "BADSESSION"))
        {
            msg_Err(p_intf, "Authentication failed (BADSESSION), are you connected to last.fm with another program ?");
            b_handshaked = false;
            HandleInterval(&next_exchange, &i_interval);
            continue;
        }

        if (strstr((char *) p_buffer, "OK"))
        {
            if (b_nowp_submission_ongoing)
            {
                b_nowp_submission_ongoing = false;
                p_sys->b_submit_nowp = false;
            }
            else
            {
                for (int i = 0; i < p_sys->i_songs; i++)
                    DeleteSong(&p_sys->p_queue[i]);
                p_sys->i_songs = 0;
            }

            i_interval = 0;
            next_exchange = 0;
            msg_Dbg(p_intf, "Submission successful!");
        }
        else
        {
            msg_Err(p_intf, "Authentication failed, handshaking again (%s)",
                             p_buffer);
            b_handshaked = false;
            HandleInterval(&next_exchange, &i_interval);
        }
    }
out:
    vlc_restorecancel(canc);
    return NULL;
}
コード例 #29
0
ファイル: thread.c プロジェクト: 12307/VLC-for-VS2010
void msleep (mtime_t delay)
{
    mwait (mdate () + delay);
}
コード例 #30
0
ファイル: test_mwait.c プロジェクト: anastop/htsynch
int main(int argc, char **argv)
{
    monitor(&c, 0, 0);
    mwait(0,0); 
}