Esempio n. 1
0
JNIEXPORT jint JNICALL Java_com_buglabs_bug_jni_camera_CameraControl_getExposureLevel
  (JNIEnv *, jobject) {
	int value = 0;
	const int ret = get_ctrl(V4L2_CID_EXPOSURE, &value);
	printf("get exposure: ret=%d, value=%d\n", ret, value);fflush(stdout);
	return (ret == 0) ? value : ret;
}
Esempio n. 2
0
//------------------------------split_thru_region------------------------------
// Split Node 'n' through merge point.
Node *PhaseIdealLoop::split_thru_region( Node *n, Node *region ) {
  uint wins = 0;
  assert( n->is_CFG(), "" );
  assert( region->is_Region(), "" );
  Node *r = new (C, region->req()) RegionNode( region->req() );
  IdealLoopTree *loop = get_loop( n );
  for( uint i = 1; i < region->req(); i++ ) {
    Node *x = n->clone();
    Node *in0 = n->in(0);
    if( in0->in(0) == region ) x->set_req( 0, in0->in(i) );
    for( uint j = 1; j < n->req(); j++ ) {
      Node *in = n->in(j);
      if( get_ctrl(in) == region )
        x->set_req( j, in->in(i) );
    }
    _igvn.register_new_node_with_optimizer(x);
    set_loop(x, loop);
    set_idom(x, x->in(0), dom_depth(x->in(0))+1);
    r->init_req(i, x);
  }

  // Record region
  r->set_req(0,region);         // Not a TRUE RegionNode
  _igvn.register_new_node_with_optimizer(r);
  set_loop(r, loop);
  if( !loop->_child )
    loop->_body.push(r);
  return r;
}
Esempio n. 3
0
JNIEXPORT jint JNICALL Java_com_buglabs_bug_jni_camera_CameraControl_getHorizontalMirror
  (JNIEnv *, jobject) {
	int value = 0;
	const int ret = get_ctrl(V4L2_CID_HFLIP, &value);
	printf("get horizontal mirror: ret=%d, value=%d\n", ret, value);fflush(stdout);
	return (ret == 0) ? value : ret;
}
Esempio n. 4
0
JNIEXPORT jint JNICALL Java_com_buglabs_bug_jni_camera_CameraControl_getVerticalFlip
  (JNIEnv *, jobject) {
	int value = 0;
	const int ret = get_ctrl(V4L2_CID_VFLIP, &value);
	printf("get vertical flip: ret=%d, value=%d\n", ret, value);fflush(stdout);
	return (ret == 0) ? value : ret;
}
Esempio n. 5
0
JNIEXPORT jint JNICALL Java_com_buglabs_bug_jni_camera_CameraControl_getColorEffects
  (JNIEnv *, jobject) {
	int value = 0;
	const int ret = get_ctrl(V4L2_CID_COLORFX, &value);
	printf("get color effects: ret=%d, value=%d\n", ret, value);fflush(stdout);
	return (ret == 0) ? value : ret;
}
Esempio n. 6
0
JNIEXPORT jint JNICALL Java_com_buglabs_bug_jni_camera_CameraControl_getTestPattern
  (JNIEnv *, jobject) {
	int value = 0;
	const int ret = get_ctrl(V4L2_CID_TEST_PATTERN, &value);
	printf("get test pattern: ret=%d, value=%d\n", ret, value);fflush(stdout);
	return (ret == 0) ? value : ret;
}
Esempio n. 7
0
static PyObject *py_get_ctrl(PyObject *self, PyObject *args,PyObject *kwds) {
    int id, ret, val;
    static char *kwlist[] = {"id", NULL};
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &id)) {
        PyErr_SetString(PyExc_Exception, "Bad arguments.");
        return NULL;
    }
    ret = get_ctrl(id, &val);
    if(ret < 0) {
        PyErr_SetString(PyExc_Exception, "Control not implemented");
        return NULL;
    }
    return PyInt_FromLong(val);
}
Esempio n. 8
0
//
// Prompts for valid directional input
//
int prompt_dir(const char * prompt, int * dx, int * dy)
{
	*dx = *dy = 0;

	wmove(dispscr, 0, 0);
	wprintw(dispscr, "%s\n", prompt);
	wrefresh(dispscr);

	switch (ctrl_by_key(get_ctrl())) {
	case CTRL_LEFT:   *dx = -1; *dy = 0; break;
	case CTRL_DOWN:   *dx =  0; *dy = 1; break;
	case CTRL_UP:     *dx =  0; *dy =-1; break;
	case CTRL_RIGHT:  *dx =  1; *dy = 0; break;
	case CTRL_ULEFT:  *dx = -1; *dy =-1; break;
	case CTRL_URIGHT: *dx =  1; *dy =-1; break;
	case CTRL_DLEFT:  *dx = -1; *dy = 1; break;
	case CTRL_DRIGHT: *dx =  1; *dy = 1; break;
	}

	wrefresh(dispscr);
	return *dx || *dy;
}
Esempio n. 9
0
//------------------------------find_use_block---------------------------------
// Find the block a USE is in.  Normally USE's are in the same block as the
// using instruction.  For Phi-USE's, the USE is in the predecessor block
// along the corresponding path.
Node *PhaseIdealLoop::find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ) {
  // CFG uses are their own block
  if( use->is_CFG() )
    return use;

  if( use->is_Phi() ) {         // Phi uses in prior block
    // Grab the first Phi use; there may be many.
    // Each will be handled as a separate iteration of
    // the "while( phi->outcnt() )" loop.
    uint j;
    for( j = 1; j < use->req(); j++ )
      if( use->in(j) == def )
        break;
    assert( j < use->req(), "def should be among use's inputs" );
    return use->in(0)->in(j);
  }
  // Normal (non-phi) use
  Node *use_blk = get_ctrl(use);
  // Some uses are directly attached to the old (and going away)
  // false and true branches.
  if( use_blk == old_false ) {
    use_blk = new_false;
    set_ctrl(use, new_false);
  }
  if( use_blk == old_true ) {
    use_blk = new_true;
    set_ctrl(use, new_true);
  }

  if (use_blk == NULL) {        // He's dead, Jim
    _igvn.hash_delete(use);
    _igvn.subsume_node(use, C->top());
  }

  return use_blk;
}
Esempio n. 10
0
/* run in a thread (SDL overlay)*/
void *main_loop(void *data)
{
    struct ALL_DATA *all_data = (struct ALL_DATA *) data;

    struct VidState *s = all_data->s;
    struct paRecordData *pdata = all_data->pdata;
    struct GLOBAL *global = all_data->global;
    struct focusData *AFdata = all_data->AFdata;
    struct vdIn *videoIn = all_data->videoIn;

    struct particle* particles = NULL; //for the particles video effect

    SDL_Event event;
    /*the main SDL surface*/
    SDL_Surface *pscreen = NULL;
    SDL_Overlay *overlay = NULL;
    SDL_Rect drect;

    int width = global->width;
    int height = global->height;
    int format = global->format;

    SAMPLE vuPeak[2];  // The maximum vuLevel seen recently
    int vuPeakFreeze[2]; // The vuPeak values will be frozen for this many frames.
    vuPeak[0] = vuPeak[1] = 0;
    vuPeakFreeze[0] = vuPeakFreeze[1] = 0;

    BYTE *p = NULL;

    Control *focus_control = NULL;
    int last_focus = 0;

    if (global->AFcontrol)
    {
        focus_control = get_ctrl_by_id(s->control_list, AFdata->id);
        get_ctrl(videoIn->fd, s->control_list, AFdata->id, all_data);
        last_focus = focus_control->value;
        /*make sure we wait for focus to settle on first check*/
        if (last_focus < 0) last_focus = AFdata->f_max;
    }

    gboolean capVid = FALSE;
    gboolean signalquit = FALSE;

    /*------------------------------ SDL init video ---------------------*/
    if(!global->no_display)
    {
        overlay = video_init(data, &(pscreen));

        if(overlay == NULL)
        {
            g_print("FATAL: Couldn't create yuv overlay - please disable hardware accelaration\n");
            signalquit = TRUE; /*exit video thread*/
        }
        else
        {
            p = (unsigned char *) overlay->pixels[0];

            drect.x = 0;
            drect.y = 0;
            drect.w = pscreen->w;
            drect.h = pscreen->h;
        }
    }

    while (!signalquit)
    {
        __LOCK_MUTEX(__VMUTEX);
            capVid = videoIn->capVid;
            signalquit = videoIn->signalquit;
        __UNLOCK_MUTEX(__VMUTEX);

        /*-------------------------- Grab Frame ----------------------------------*/
        if (uvcGrab(videoIn, format, width, height, &global->fps, &global->fps_num) < 0)
        {
            g_printerr("Error grabbing image \n");
            continue;
        }
        else
        {
            if(!videoIn->timestamp)
            {
                global->skip_n++; //skip this frame
            }

            if(capVid)
            {
                if(global->framecount < 1)
                {
					/*reset video start time to first frame capture time */
					global->Vidstarttime = videoIn->timestamp;
					/** set current time for audio ts(0) reference (MONOTONIC)
					 *  only used if we have no audio capture before video
					 */
					__LOCK_MUTEX(__AMUTEX);
						pdata->ts_ref = ns_time_monotonic();
					__UNLOCK_MUTEX(__AMUTEX);
					//printf("video ts ref: %llu audio ts_ ref: %llu\n",global->Vidstarttime, pdata->ts_ref);
					global->v_ts = 0;
                }
                else
                {
                    global->v_ts = videoIn->timestamp - global->Vidstarttime;
                    /*always use the last frame time stamp for video stop time*/
                    global->Vidstoptime = videoIn->timestamp;
                }
            }

            if (global->FpsCount && !global->no_display)
            {/* sets fps count in window title bar */
                global->frmCount++;
                if (global->DispFps>0)
                { /*set every 2 sec*/
                    g_snprintf(global->WVcaption,24,"GUVCVideo - %3.2f fps",global->DispFps);
                    SDL_WM_SetCaption(global->WVcaption, NULL);

                    global->frmCount=0;/*resets*/
                    global->DispFps=0;
                }
            }

            /*---------------- autofocus control ------------------*/

            if (global->AFcontrol && (global->autofocus || AFdata->setFocus))
            { /*AFdata = NULL if no focus control*/
                if (AFdata->focus < 0)
                {
                    /*starting autofocus*/
                    AFdata->focus = AFdata->left; /*start left*/
                    focus_control->value = AFdata->focus;
                    if (set_ctrl (videoIn->fd, s->control_list, AFdata->id) != 0)
                        g_printerr("ERROR: couldn't set focus to %d\n", AFdata->focus);
                    /*number of frames until focus is stable*/
                    /*1.4 ms focus time - every 1 step*/
                    AFdata->focus_wait = (int) abs(AFdata->focus-last_focus)*1.4/(1000/global->fps)+1;
                    last_focus = AFdata->focus;
                }
                else
                {
                    if (AFdata->focus_wait == 0)
                    {
                        AFdata->sharpness=getSharpness (videoIn->framebuffer, width, height, 5);
                        if (global->debug)
                            g_print("sharp=%d focus_sharp=%d foc=%d right=%d left=%d ind=%d flag=%d\n",
                                AFdata->sharpness,AFdata->focus_sharpness,
                                AFdata->focus, AFdata->right, AFdata->left,
                                AFdata->ind, AFdata->flag);
                        AFdata->focus=getFocusVal (AFdata);
                        if ((AFdata->focus != last_focus))
                        {
                            focus_control->value = AFdata->focus;
                            if (set_ctrl (videoIn->fd, s->control_list, AFdata->id) != 0)
                                g_printerr("ERROR: couldn't set focus to %d\n",
                                    AFdata->focus);
                            /*number of frames until focus is stable*/
                            /*1.4 ms focus time - every 1 step*/
                            AFdata->focus_wait = (int) abs(AFdata->focus-last_focus)*1.4/(1000/global->fps)+1;
                        }
                        last_focus = AFdata->focus;
                    }
                    else
                    {
                        AFdata->focus_wait--;
                        if (global->debug) g_print("Wait Frame: %d\n",AFdata->focus_wait);
                    }
                }
            }
        }
        /*------------------------- Filter Frame ---------------------------------*/
        __LOCK_MUTEX(__GMUTEX);
        if(global->Frame_Flags>0)
        {
            if((global->Frame_Flags & YUV_PARTICLES)==YUV_PARTICLES)
                particles = particles_effect(videoIn->framebuffer, width, height, 20, 4, particles);

            if((global->Frame_Flags & YUV_MIRROR)==YUV_MIRROR)
                yuyv_mirror(videoIn->framebuffer, width, height);

            if((global->Frame_Flags & YUV_UPTURN)==YUV_UPTURN)
                yuyv_upturn(videoIn->framebuffer, width, height);

            if((global->Frame_Flags & YUV_NEGATE)==YUV_NEGATE)
                yuyv_negative (videoIn->framebuffer, width, height);

            if((global->Frame_Flags & YUV_MONOCR)==YUV_MONOCR)
                yuyv_monochrome (videoIn->framebuffer, width, height);

            if((global->Frame_Flags & YUV_PIECES)==YUV_PIECES)
                pieces (videoIn->framebuffer, width, height, 16 );

        }
        __UNLOCK_MUTEX(__GMUTEX);
        /*-------------------------capture Image----------------------------------*/
        if (videoIn->capImage)
        {
            /*
             * format and resolution can change(enabled) while capturing the frame
             * but you would need to be speedy gonzalez to press two buttons
             * at almost the same time :D
             */
            int ret = 0;
            if((ret=store_picture(all_data)) < 0)
                g_printerr("saved image to:%s ...Failed \n",videoIn->ImageFName);
            else if (!ret && global->debug) g_print("saved image to:%s ...OK \n",videoIn->ImageFName);

            videoIn->capImage=FALSE;
        }
        /*---------------------------capture Video---------------------------------*/
        if (capVid && !(global->skip_n))
        {
            __LOCK_MUTEX(__VMUTEX);
                if(videoIn->VidCapStop) videoIn->VidCapStop = FALSE;
            __UNLOCK_MUTEX(__VMUTEX);
            int res=0;

			/* format and resolution don't change(disabled) while capturing video
			 * store_video_frame may sleep if needed to avoid buffer overrun
			 */
            if((res=store_video_frame(all_data))<0) g_printerr("WARNING: droped frame (%i)\n",res);

        } /*video and audio capture have stopped */
        else
        {
            __LOCK_MUTEX(__VMUTEX);
                if(!(videoIn->VidCapStop)) videoIn->VidCapStop=TRUE;
            __UNLOCK_MUTEX(__VMUTEX);
        }

        /* decrease skip frame count */
        if (global->skip_n > 0)
        {
            if (global->debug && capVid) g_print("skiping frame %d...\n", global->skip_n);
            global->skip_n--;
        }

        __LOCK_MUTEX( __AMUTEX );
            if (global->Sound_enable && capVid) pdata->skip_n = global->skip_n;
        __UNLOCK_MUTEX( __AMUTEX );

        /*------------------------- Display Frame --------------------------------*/
        if(!global->no_display)
        {
			if (global->osdFlags && pdata->audio_buff[0])
			{
				draw_vu_meter(width, height, vuPeak, vuPeakFreeze, data);
			}
            SDL_LockYUVOverlay(overlay);
            memcpy(p, videoIn->framebuffer, width * height * 2);
            SDL_UnlockYUVOverlay(overlay);
            SDL_DisplayYUVOverlay(overlay, &drect);

            /*------------------------- Read Key events ------------------------------*/
            /* Poll for events */
            while( SDL_PollEvent(&event) )
            {
                //printf("event type:%i  event key:%i\n", event.type, event.key.keysym.scancode);
                if(event.type==SDL_KEYDOWN)
                {
                    if (videoIn->PanTilt)
                    {
                        switch( event.key.keysym.sym )
                        {
                            /* Keyboard event */
                            /* Pass the event data onto PrintKeyInfo() */
                            case SDLK_DOWN:
                                /*Tilt Down*/
                                uvcPanTilt (videoIn->fd, s->control_list, 0, 1);
                                break;

                            case SDLK_UP:
                                /*Tilt UP*/
                                uvcPanTilt (videoIn->fd, s->control_list, 0, -1);
                                break;

                            case SDLK_LEFT:
                                /*Pan Left*/
                                uvcPanTilt (videoIn->fd, s->control_list, 1, 1);
                                break;

                            case SDLK_RIGHT:
                                /*Pan Right*/
                                uvcPanTilt (videoIn->fd, s->control_list, 1, -1);
                                break;
                            default:
                                break;
                        }
                    }
                    switch( event.key.keysym.scancode )
                    {
                        case 220: /*webcam button*/
                            //gdk_threads_enter();
                           	if (all_data->global->default_action == 0)
                           		g_main_context_invoke(NULL, image_capture_callback, (gpointer) all_data);
							else
                            	g_main_context_invoke(NULL, video_capture_callback, (gpointer) all_data);
                       
                            break;
                    }
                    switch( event.key.keysym.sym )
                    {
                        case SDLK_q:
                            //shutDown
                            g_timeout_add(200, shutd_timer, all_data);
                            g_print("q pressed - Quiting...\n");
                            break;
                        case SDLK_SPACE:
							{
                            if(global->AFcontrol > 0)
                                setfocus_clicked(NULL, all_data);
							}
                            break;
                        case SDLK_i:
							g_main_context_invoke(NULL, image_capture_callback, (gpointer) all_data);
							break;
						case SDLK_v:
							g_main_context_invoke(NULL, video_capture_callback, (gpointer) all_data);
							break;
                        default:
                            break;
                    }
                }
                if(event.type==SDL_VIDEORESIZE)
                {
                    pscreen =
                        SDL_SetVideoMode(event.resize.w,
                                 event.resize.h,
                                 global->bpp,
                                 SDL_VIDEO_Flags);
                    drect.w = event.resize.w;
                    drect.h = event.resize.h;
                }
                if(event.type==SDL_QUIT)
                {
                    //shutDown
                    g_timeout_add(200, shutd_timer, all_data);
                }
            }
        }
        /* if set make the thread sleep - default no sleep (full throttle)*/
        if(global->vid_sleep) sleep_ms(global->vid_sleep);

        /*------------------------------------------*/
        /*  restart video (new resolution/format)   */
        /*------------------------------------------*/
        if (global->change_res)
        {
            g_print("setting new resolution (%d x %d)\n", global->width, global->height);
            /*clean up */

            if(particles) g_free(particles);
            particles = NULL;

            if (global->debug) g_print("cleaning buffer allocations\n");
            fflush(NULL);//flush all output buffers

            if(!global->no_display)
            {
                SDL_FreeYUVOverlay(overlay);
                overlay = NULL;
            }
            /*init device*/
            restart_v4l2(videoIn, global);
            /*set new resolution for video thread*/
            width = global->width;
            height = global->height;
            format = global->format;
            /* restart SDL with new values*/
            if(!global->no_display)
            {
                overlay = video_init(data, &(pscreen));
                if(overlay == NULL)
                {
                    g_print("FATAL: Couldn't create yuv overlay - please disable hardware accelaration\n");
                    signalquit = TRUE; /*exit video thread*/
                }
                else
                {
                    if (global->debug) g_print("yuv overlay created (%ix%i).\n", overlay->w, overlay->h);
                    p = (unsigned char *) overlay->pixels[0];

                    drect.x = 0;
                    drect.y = 0;
                    drect.w = pscreen->w;
                    drect.h = pscreen->h;

                    global->change_res = FALSE;
                }
            }
            else global->change_res = FALSE;
        }

    }/*loop end*/

    __LOCK_MUTEX(__VMUTEX);
        capVid = videoIn->capVid;
    __UNLOCK_MUTEX(__VMUTEX);
    /*check if thread exited while in Video capture mode*/
    if (capVid)
    {
        /*stop capture*/
        if (global->debug) g_print("stoping Video capture\n");
        //global->Vidstoptime = ns_time_monotonic(); /*this is set in IO thread*/
        videoIn->VidCapStop=TRUE;
        capVid = FALSE;
        __LOCK_MUTEX(__VMUTEX);
            videoIn->capVid = capVid;
        __UNLOCK_MUTEX(__VMUTEX);
        __LOCK_MUTEX(__AMUTEX);
            pdata->capVid = capVid;
        __UNLOCK_MUTEX(__AMUTEX);
        /*join IO thread*/
        if (global->debug) g_print("Shuting Down IO Thread\n");
        __THREAD_JOIN( all_data->IO_thread );
        if (global->debug) g_print("IO Thread finished\n");
    }

    if (global->debug) g_print("Thread terminated...\n");
    p = NULL;
    if(particles) g_free(particles);
    particles=NULL;

    if (global->debug) g_print("cleaning Thread allocations: 100%%\n");
    fflush(NULL);//flush all output buffers

    if(!global->no_display)
    {
        if(overlay)
            SDL_FreeYUVOverlay(overlay);
        //SDL_FreeSurface(pscreen);

        SDL_Quit();
    }

    if (global->debug) g_print("Video thread completed\n");

    global = NULL;
    AFdata = NULL;
    videoIn = NULL;
    return ((void *) 0);
}
Esempio n. 11
0
void main_menu_dlg::on_init_dialog()
{
	h_screen_paradigm scr_paradigm = get_framework()->get_screen_paradigm();
	h_string suffix = get_framework()->get_screen_paradigm_suffix(scr_paradigm);

	scene_manager* scene_manager = get_ctrl()->get_scene_manager();

	int w_scr = get_framework()->get_display_settings().width;
	int h_scr = get_framework()->get_display_settings().height;
	set_size(h_vector((float)w_scr, (float)h_scr));

	h_scene_object_base_ptr background(new h_scene_object_base("background_panel"));
	add_child(background);
	background->add_sprite("/images/menu/dlg_base" + suffix, "background_panel");
	background->set_pos(scene_manager->get_scene_center() - background->get_size() / 2);

	//scene_manager* scene_manager = get_ctrl()->get_scene_manager();

	static const float height_button_t0[3] = { 43, 73, 86 };
	static const float height_button_t1[3] = { 65, 111, 130 };

	static const float width_button[3] = { 165, 280, 329 };

	h_button_ptr button_sel_tree;
	h_button_ptr button_sel_background;
	h_button_ptr button_share_social;
	h_button_ptr button_email;
	h_button_ptr button_to_img;
	h_button_ptr button_clear;


	h_vector offset_img(0, 0);
	// select tree..
	{
		/*button_sel_tree.reset(new h_button("select_tree"));
		add_child(button_sel_tree); 

		h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t0[scr_paradigm]) + offset_img;
		button_sel_tree->load_images("/images/menu/menu_buttons_0" + suffix, 
									 pos_coord_img_tl, pos_coord_img_br,
									 pos_coord_img_tl, pos_coord_img_br);
		button_sel_tree->set_action(std::tr1::bind(&scene_manager::on_change_tree, 
													get_ctrl()->get_scene_manager()));
		offset_img += h_vector(0, height_button_t0[scr_paradigm]);*/
	}
	 
	// select background..
	{

		button_sel_background.reset(new h_button("select_background"));
		background->add_child(button_sel_background); 

		h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t0[scr_paradigm]) + offset_img;
		button_sel_background->load_images("/images/menu/menu_buttons_0" + suffix, 
									 pos_coord_img_tl, pos_coord_img_br,
									 pos_coord_img_tl, pos_coord_img_br);
		button_sel_background->set_action(std::tr1::bind(&scene_manager::on_change_background, 
												   get_ctrl()->get_scene_manager()));
		offset_img += h_vector(0, height_button_t0[scr_paradigm]);
	}

	// share to social..
	{

		//button_share_social.reset(new h_button("share_social"));
		//background->add_child(button_share_social); 

		//h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		//h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t1[scr_paradigm]) + offset_img;
		//button_share_social->load_images("/images/menu/menu_buttons_0" + suffix, 
		//							 pos_coord_img_tl, pos_coord_img_br,
		//							 pos_coord_img_tl, pos_coord_img_br);
		////button_sel_tree->set_action(std::tr1::bind(&scene_manager::on_select_toys_dlg, 
		////							get_ctrl()->get_scene_manager(), dlg_balls));
		//offset_img += h_vector(0, height_button_t1[scr_paradigm]);
	}


	// export to image..
	{

		button_to_img.reset(new h_button("to_img"));
		background->add_child(button_to_img); 

		h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t1[scr_paradigm]) + offset_img;
		button_to_img->load_images("/images/menu/menu_buttons_0" + suffix, 
									 pos_coord_img_tl, pos_coord_img_br,
									 pos_coord_img_tl, pos_coord_img_br);
		button_to_img->set_action(std::tr1::bind(&scene_manager::on_export_image, 
									get_ctrl()->get_scene_manager()));
		offset_img += h_vector(0, height_button_t1[scr_paradigm]);
	}

	// send..
	{

		button_email.reset(new h_button("email"));
		background->add_child(button_email); 

		h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t0[scr_paradigm]) + offset_img;
		button_email->load_images("/images/menu/menu_buttons_0" + suffix, 
									 pos_coord_img_tl, pos_coord_img_br,
									 pos_coord_img_tl, pos_coord_img_br);
		button_email->set_action(std::tr1::bind(&scene_manager::send_email, 
									get_ctrl()->get_scene_manager()));
		offset_img += h_vector(0, height_button_t0[scr_paradigm]);
	}


	// clear..
	{
		button_clear.reset(new h_button("clear"));
		background->add_child(button_clear); 

		h_vector pos_coord_img_tl = h_vector(0, 0) + offset_img;
		h_vector pos_coord_img_br = h_vector(width_button[scr_paradigm], height_button_t0[scr_paradigm]) + offset_img;
		button_clear->load_images("/images/menu/menu_buttons_0" + suffix, 
									 pos_coord_img_tl, pos_coord_img_br,
									 pos_coord_img_tl, pos_coord_img_br);
		button_clear->set_action(std::tr1::bind(&scene_manager::on_clear, 
									get_ctrl()->get_scene_manager()));
		//offset_img += h_vector(0, height_button_t0[scr_paradigm]);
	}
	h_scene_object_ptr buttons[g_num_buttons] = { button_sel_background, 
												  button_to_img,
												  button_email,
												  button_clear };
	float height_all_buttons = 0;
	for (int i = 0; i < g_num_buttons; i++)	{
		height_all_buttons += buttons[i]->get_size().y;
		buttons[i]->get_sprites()->get_sprite(0)->set_filter(true);
	}

	float w = buttons[0]->get_size().x;

	float menu_height = background->get_size().y;
	float v = menu_height - height_all_buttons;
	float vx = background->get_size().x - w;

	float seg = v / (g_num_buttons + 1);
	float y_offset = background->get_size().y;
	for (int i = 0; i < g_num_buttons; i++)
	{
		float height = buttons[i]->get_size().y;
		y_offset += -height;//seg; 
		buttons[i]->set_pos(h_vector(vx / 2, y_offset - v / 2));
	}
	
	h_vector center = scene_manager->get_scene_center() - get_size() / 2;
	h_vector start_pos = h_vector(center.x, -get_size().y);
	h_vector end_pos(center);
	//static const float offset_from_center[3] = { 35, 70, 0 };
	//offset_pos(h_vector(0, offset_from_center[scr_paradigm]));

	h_transition_ptr trans(new h_transition_position(start_pos, end_pos, 170));
	add_transition(trans, true);
	trans->start();
}
Esempio n. 12
0
void bottom_panel::on_init()
{
	h_screen_paradigm scr_paradigm = get_framework()->get_screen_paradigm();
	h_string suffix = get_framework()->get_screen_paradigm_suffix(scr_paradigm);

	h_sprite_ptr panel = add_sprite("/images/panels/panel_bottom" + suffix, "base");

	h_rect rc = get_framework()->get_view()->get_rect();
	float width = rc.get_width();
	set_size(h_vector(width, panel->get_size().y));

	float scale_horiz_factor = get_size().x / panel->get_size().x;
	h_logger::info(h_string("[bottom_panel] scale_horiz_factor : %f", scale_horiz_factor));
	//panel->set_pos(h_vector(10, 0));
	//panel->set_scale_h(scale_horiz_factor);
	set_scale(h_vector(scale_horiz_factor, 1));
	// init bottom widgets
	// balls..
	{
		m_button_balls.reset(new h_button("button_balls_0"));
		add_child(m_button_balls); 
	
		scene_manager* scene_manager = get_ctrl()->get_scene_manager();
		static const float width[3] = { 48, 81, 95 };
		static const float height[3] = { 48, 81, 95 }; 

		h_rect rc = scene_manager->get_rect_from_atlas((int)width[scr_paradigm], 
													   (int)height[scr_paradigm], 4, 4, 0);		
		m_button_balls->load_images("/images/dlg/balls_set_0" + suffix, 
								     rc.get_top_left(), rc.get_bottom_right(),
									 rc.get_top_left(), rc.get_bottom_right());
		m_button_balls->set_action(std::tr1::bind(&scene_manager::on_select_toys_dlg, 
									get_ctrl()->get_scene_manager(), dlg_balls));
	}

	// staff..
	{
		m_button_staff.reset(new h_button("button_staff_0"));
		add_child(m_button_staff); 
	
		scene_manager* scene_manager = get_ctrl()->get_scene_manager();
		static const float width[3] = { 48, 81, 95 };
		static const float height[3] = { 48, 81, 95 }; 

		h_rect rc = scene_manager->get_rect_from_atlas((int)width[scr_paradigm], 
													   (int)height[scr_paradigm], 4, 4, 0);		
		m_button_staff->load_images("/images/dlg/staff_set_0" + suffix, 
								     rc.get_top_left(), rc.get_bottom_right(),
									 rc.get_top_left(), rc.get_bottom_right());
		m_button_staff->set_action(std::tr1::bind(&scene_manager::on_select_toys_dlg, 
									get_ctrl()->get_scene_manager(), dlg_staff));
	}

	// undo..
	{
		m_button_undo.reset(new h_button("button_undo_0"));
		add_child(m_button_undo); 
	
		scene_manager* scene_manager = get_ctrl()->get_scene_manager();
		static const float width[3] = { 48, 81, 95 };
		static const float height[3] = { 48, 81, 95 }; 
		
		m_button_undo->load_images("/images/buttons/undo" + suffix, "/images/buttons/undo" + suffix);
		m_button_undo->set_action(std::tr1::bind(&scene_manager::on_undo, get_ctrl()->get_scene_manager()));
	}


	// menu..
	{
		m_button_menu.reset(new h_button("menu"));
		add_child(m_button_menu); 
	
		scene_manager* scene_manager = get_ctrl()->get_scene_manager();
		static const float width[3] = { 60, 102, 120 };
		static const float height[3] = { 48, 81, 95 }; 
		
		m_button_menu->load_images("/images/buttons/menu" + suffix, "/images/buttons/menu" + suffix);
		m_button_menu->set_action(std::tr1::bind(&scene_manager::on_menu, get_ctrl()->get_scene_manager()));
	}

	align_buttons();
}
Esempio n. 13
0
//------------------------------split_up---------------------------------------
// Split block-local op up through the phis to empty the current block
bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) {
  if( n->is_CFG() ) {
    assert( n->in(0) != blk1, "Lousy candidate for split-if" );
    return false;
  }
  if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 )
    return false;               // Not block local
  if( n->is_Phi() ) return false; // Local PHIs are expected

  // Recursively split-up inputs
  for (uint i = 1; i < n->req(); i++) {
    if( split_up( n->in(i), blk1, blk2 ) ) {
      // Got split recursively and self went dead?
      if (n->outcnt() == 0)
        _igvn.remove_dead_node(n);
      return true;
    }
  }

  // Check for needing to clone-up a compare.  Can't do that, it forces
  // another (nested) split-if transform.  Instead, clone it "down".
  if( n->is_Cmp() ) {
    assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF");
    // Check for simple Cmp/Bool/CMove which we can clone-up.  Cmp/Bool/CMove
    // sequence can have no other users and it must all reside in the split-if
    // block.  Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below -
    // private, per-use versions of the Cmp and Bool are made.  These sink to
    // the CMove block.  If the CMove is in the split-if block, then in the
    // next iteration this will become a simple Cmp/Bool/CMove set to clone-up.
    Node *bol, *cmov;
    if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() &&
          (bol = n->unique_out()->as_Bool()) &&
          (get_ctrl(bol) == blk1 ||
           get_ctrl(bol) == blk2) &&
          bol->outcnt() == 1 &&
          bol->unique_out()->is_CMove() &&
          (cmov = bol->unique_out()->as_CMove()) &&
          (get_ctrl(cmov) == blk1 ||
           get_ctrl(cmov) == blk2) ) ) {

      // Must clone down
#ifndef PRODUCT
      if( PrintOpto && VerifyLoopOptimizations ) {
        tty->print("Cloning down: ");
        n->dump();
      }
#endif
      // Clone down any block-local BoolNode uses of this CmpNode
      for (DUIterator i = n->outs(); n->has_out(i); i++) {
        Node* bol = n->out(i);
        assert( bol->is_Bool(), "" );
        if (bol->outcnt() == 1) {
          Node* use = bol->unique_out();
          Node *use_c = use->is_If() ? use->in(0) : get_ctrl(use);
          if (use_c == blk1 || use_c == blk2) {
            continue;
          }
        }
        if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) {
          // Recursively sink any BoolNode
#ifndef PRODUCT
          if( PrintOpto && VerifyLoopOptimizations ) {
            tty->print("Cloning down: ");
            bol->dump();
          }
#endif
          for (DUIterator_Last jmin, j = bol->last_outs(jmin); j >= jmin; --j) {
            // Uses are either IfNodes or CMoves
            Node* iff = bol->last_out(j);
            assert( iff->in(1) == bol, "" );
            // Get control block of either the CMove or the If input
            Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff);
            Node *x = bol->clone();
            register_new_node(x, iff_ctrl);
            _igvn.hash_delete(iff);
            iff->set_req(1, x);
            _igvn._worklist.push(iff);
          }
          _igvn.remove_dead_node( bol );
          --i;
        }
      }
      // Clone down this CmpNode
      for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) {
        Node* bol = n->last_out(j);
        assert( bol->in(1) == n, "" );
        Node *x = n->clone();
        register_new_node(x, get_ctrl(bol));
        _igvn.hash_delete(bol);
        bol->set_req(1, x);
        _igvn._worklist.push(bol);
      }
      _igvn.remove_dead_node( n );

      return true;
    }
  }

  // See if splitting-up a Store.  Any anti-dep loads must go up as
  // well.  An anti-dep load might be in the wrong block, because in
  // this particular layout/schedule we ignored anti-deps and allow
  // memory to be alive twice.  This only works if we do the same
  // operations on anti-dep loads as we do their killing stores.
  if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) {
    // Get store's memory slice
    int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr());

    // Get memory-phi anti-dep loads will be using
    Node *memphi = n->in(MemNode::Memory);
    assert( memphi->is_Phi(), "" );
    // Hoist any anti-dep load to the splitting block;
    // it will then "split-up".
    for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) {
      Node *load = memphi->fast_out(i);
      if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) )
        set_ctrl(load,blk1);
    }
  }

  // Found some other Node; must clone it up
#ifndef PRODUCT
  if( PrintOpto && VerifyLoopOptimizations ) {
    tty->print("Cloning up: ");
    n->dump();
  }
#endif

  // Now actually split-up this guy.  One copy per control path merging.
  Node *phi = PhiNode::make_blank(blk1, n);
  for( uint j = 1; j < blk1->req(); j++ ) {
    Node *x = n->clone();
    if( n->in(0) && n->in(0) == blk1 )
      x->set_req( 0, blk1->in(j) );
    for( uint i = 1; i < n->req(); i++ ) {
      Node *m = n->in(i);
      if( get_ctrl(m) == blk1 ) {
        assert( m->in(0) == blk1, "" );
        x->set_req( i, m->in(j) );
      }
    }
    register_new_node( x, blk1->in(j) );
    phi->init_req( j, x );
  }
  // Announce phi to optimizer
  register_new_node(phi, blk1);

  // Remove cloned-up value from optimizer; use phi instead
  _igvn.hash_delete(n);
  _igvn.subsume_node( n, phi );

  // (There used to be a self-recursive call to split_up() here,
  // but it is not needed.  All necessary forward walking is done
  // by do_split_if() below.)

  return true;
}
Esempio n. 14
0
File: uac.c Progetto: grpascal/GEO
/* Initialize the audio path */
int mxuvc_audio_init(const char *backend, const char *options)
{
	RECORD("\"%s\", \"%s\"", backend, options);
	struct libusb_device *dev = NULL;
	int ret=0, i, config;
	uint16_t vendor_id=0xdead, product_id=0xbeef;
	char *str=NULL, *opt, *value;
	int audio_sampling_rate;

	TRACE("Initializing the audio\n");

	/* Check that the correct video backend was requested*/
	if(strncmp(backend, "libusb-uac", 10)) {
		ERROR(-1, "The audio backend requested (%s) does not match "
			"the implemented one (libusb-uac)", backend);
	}

	/* Set init parameters to their default values */
	packets_per_transfer = PACKETS_PER_TRANSFER_DEFAULT;
	num_transfers        = NUM_TRANSFERS_DEFAULT;
	audio_duration_ms    = AUDIO_DURATION_MS_DEFAULT;
	audio_sampling_rate  = AUDIO_SAMPLING_RATE_DEFAULT;

	/* Copy the options string to a new buffer since next_opt() needs
	 * non const strings and options could be a const string */
	if(options != NULL) {
		str = (char*)malloc(strlen(options)+1);
		strncpy(str, options, strlen(options));
		*(str + strlen(options)) = '\0';
	}

	/* Get backend option from the option string */
	ret = next_opt(str, &opt, &value);
	while(ret == 0) {
		if(strncmp(opt, "vid", 3) == 0) {
			vendor_id = (uint16_t) strtoul(value, NULL, 16);
		} else if(strncmp(opt, "pid", 3) == 0) {
			product_id = (uint16_t) strtoul(value, NULL, 16);
		} else if(strncmp(opt, "packets_per_transfer", 19) == 0) {
			packets_per_transfer = (unsigned int) strtoul(value, NULL, 10);
		} else if(strncmp(opt, "num_transfers", 12) == 0) {
			num_transfers = (unsigned int) strtoul(value, NULL, 10);
		} else if(strncmp(opt, "audio_duration_ms", 17) == 0) {
			audio_duration_ms = (unsigned int) strtoul(value, NULL, 10);
		}
		else if (strncmp (opt, "audio_sampling_rate", 19) == 0) {
			audio_sampling_rate =
				(unsigned int) strtoul (value, NULL, 10);
		} else {
			WARNING("Unrecognized option: '%s'", opt);
		}
		ret = next_opt(NULL, &opt, &value);
	}

	/* Display the values we are going to use */
	TRACE("Using vid = 0x%x\n",                vendor_id);
	TRACE("Using pid = 0x%x\n",                product_id);
	TRACE("Using packets_per_transfer = %i\n", packets_per_transfer);
	TRACE("Using num_transfers = %i\n",        num_transfers);
	TRACE("Using audio_duration_ms = %i\n",    audio_duration_ms);
	TRACE("Using audio_sampling_rate = %i\n",  audio_sampling_rate);

	/* Free the memory allocated to parse 'options' */
	if(str)
		free(str);

	/* Initialize the backend */
	aud_started = 0;
	audio_disconnected = 0;
	ret = init_libusb(&audio_ctx);
	if(ret < 0)
		return -1;

	audio_hdl = libusb_open_device_with_vid_pid(audio_ctx, vendor_id,
							product_id);
	CHECK_ERROR(audio_hdl == NULL, -1, "Could not open USB device "
			"%x:%x", vendor_id, product_id);

	dev = libusb_get_device(audio_hdl);
	if(dev == NULL) {
		printf("Unexpected error: libusb_get_device returned a NULL "
				"pointer.");
		mxuvc_audio_deinit();
		return -1;
	}

	/* Get active USB configuration */
	libusb_get_configuration(audio_hdl, &config);

	/* Parse USB decriptors from active USB configuration
	 * to get all the UVC/UAC info needed */
	ret = aparse_usb_config(dev, config);
	if(ret < 0){
		mxuvc_audio_deinit();
		return -1;
	}

	/* Initialize audio */

	/* Claim audio control interface */
	/* Check if a kernel driver is active on the audio control interface */
	ret = libusb_kernel_driver_active(audio_hdl, aud_cfg.ctrlif);
	if(ret < 0)
		printf("Error: libusb_kernel_driver_active failed %d\n", ret);

	if(ret == 1) {
		TRACE("Detach the kernel driver...\n");
		/* If kernel driver is active, detach it so that we can claim
		 * the interface */
		ret = libusb_detach_kernel_driver(audio_hdl, aud_cfg.ctrlif);
		if(ret < 0)
			printf("Error: libusb_detach_kernel_driver failed "
					"%d\n", ret);
	}

	/* Claim audio control interface */
	ret = libusb_claim_interface(audio_hdl, aud_cfg.ctrlif);
	if(ret < 0) {
		printf("Error: libusb_claim_interface failed %d\n", ret);
	}

	/* Claim audio streaming interface */
	/* Check if a kernel driver is active on the audio interface */
	ret = libusb_kernel_driver_active(audio_hdl, aud_cfg.interface);
	if(ret < 0)
		printf("Error: libusb_kernel_driver_active failed %d\n", ret);

	if(ret == 1) {
		TRACE("Detach the kernel driver...\n");
		/* If kernel driver is active, detach it so that we can claim
		 * the interface */
		ret = libusb_detach_kernel_driver(audio_hdl, aud_cfg.interface);
		if(ret < 0)
			printf("Error: libusb_detach_kernel_driver failed "
					"%d\n",ret);
	}

	/* Claim audio streaming interface */
	ret = libusb_claim_interface(audio_hdl, aud_cfg.interface);
	if(ret < 0) {
		printf("Error: libusb_claim_interface failed %d\n",ret);
	}

	/* Select sampling rate */
	for(i=0;i<MAX_AUD_FMTS;i++) {
		if(aud_cfg.format[i].samFr == audio_sampling_rate){
			aud_cfg.fmt_idx = i;
			break;
		}
		CHECK_ERROR(i == MAX_AUD_FMTS-1, -1,
			"Unable to set the sampling rate to %i",
			audio_sampling_rate);
	}

	/* Map default UAC format to Audio format */
	cur_aud_format = AUD_FORMAT_PCM_RAW;

	/* Get min, max and real unit id for ctrl */
	AUDIO_CTRL *ctrl = uac_controls;
	int16_t min = 0, max = 0;
	uint16_t res = 0;
	while(ctrl->id != CTRL_NONE) {
		switch(ctrl->unit) {
			TRACE(">>>>>id:%d  unit:%d\n", ctrl->id,ctrl->unit);
			case FEATURE:
				ctrl->unit = aud_cfg.ctrl_feature;
				break;
			default:
				ERROR(-1, "Unsupported control unit (%i) for "
						"audio control %i",
						ctrl->unit, ctrl->id);
		}

		if (ctrl->id == CTRL_MUTE) {
			ctrl++;
			continue;
		}

		ret = get_ctrl(ctrl->id, GET_MIN, (void*) &min);
		CHECK_ERROR(ret < 0, -1,
				"Unable to get min (GET_MIN) for audio "
				"control: id=%i, cs=%i, cn=%i.",
				ctrl->id, ctrl->cs, ctrl->cn);
		ctrl->min = min;
		ret = get_ctrl(ctrl->id, GET_MAX, (void*) &max);
		CHECK_ERROR(ret < 0, -1,
				"Unable to get max (GET_MAX) for audio "
				"control: id=%i, cs=%i, cn=%i.",
				ctrl->id, ctrl->cs, ctrl->cn);
		ctrl->max = max;
		ret = get_ctrl(ctrl->id, GET_RES, (void*) &res);
		CHECK_ERROR(ret < 0, -1,
				"Unable to get res (GET_RES) for audio "
				"control: id=%i, cs=%i, cn=%i.",
				ctrl->id, ctrl->cs, ctrl->cn);
		ctrl->res = res;

		ctrl++;
	}

	/* Register removal USB event*/
	register_libusb_removal_cb((libusb_pollfd_removed_cb) audio_removed,
			audio_hdl);

	/* Start event thread/loop */
	ret = start_libusb_events();
	if(ret < 0)
		return -1;

	audio_initialized = 1;

	return 0;
}
Esempio n. 15
0
h_touch_response scene_tree::on_touch_tap(const h_vector& pos)
{

	get_ctrl()->get_scene_manager()->on_touch_tree(pos);
	return touch_processed;
}