///
/// @return Returns the value of m_inited after initialization, e.g. returns TRUE if the camera is successfully initialized
///
bool SimpleDirectShowAcq::Open()
{
	struct SimpleCapParams	params;
	bool					success = false;


	if (m_width == 0 || m_height == 0)	// these get set in Init()
	{
		m_logMsg = "Unable to Open camera:  width and height are not set.";
	}
	else
	{
		m_numCameras = setupESCAPI();

		if (m_numCameras == 0)
		{
			m_logMsg.Format("%s: no cameras found.\n", __FUNCTION__);
		}
		else
		{
			params.mWidth     = m_width;
			params.mHeight    = m_height;
			params.mTargetBuf = (int *)m_buf;	// m_buf gets set in Init()
			m_cameraIndex     = 0;
			
			if (initCapture(m_cameraIndex, &params))
			{
				m_inited = true;	// assigning it here avoids an annoying compiler warning
			}
		}
	}

	return m_inited;
}
예제 #2
0
void Libdc1394SequenceGrabber::start()
{
	msg(osg::INFO) << "start" << std::endl;

	dc1394error_t err;
	initCapture();
	if (!_camera) return;
	err=dc1394_video_set_transmission(_camera, DC1394_ON);
    checkSuccess(err, "dc1394_video_set_transmission failed");
	
	setRunning(true);
}
예제 #3
0
AudioCaptureNode::AudioCaptureNode(const char *device, int desiredNbFrame)
{
    this->device = device;
    this->nbFrames = (uint)desiredNbFrame;
    this->fs = 44100;

    this->buffer = NULL;
    this->captureHandle = NULL;
    this->hwParams = NULL;

    if(initCapture() == 0)
	this->errorInit = 1;
    else this->errorInit = 0;

    this->_current_index = 0;
}
예제 #4
0
void EkosManager::setFilter(ISD::GDInterface *filterDevice)
{

    if (useFilterFromCCD == false)
    {
       filter = filterDevice;
       appendLogText(i18n("%1 is online.", filter->getDeviceName()));
    }
    else
        filter = ccd;

    initCapture();

    connect(filter, SIGNAL(numberUpdated(INumberVectorProperty *)), this, SLOT(processNewNumber(INumberVectorProperty*)));

    captureProcess->addFilter(filter);
}
예제 #5
0
void EkosManager::setCCD(ISD::GDInterface *ccdDevice)
{
    initCapture();

    captureProcess->addCCD(ccdDevice);

    initFocus();

    focusProcess->addCCD(ccdDevice);

    // If we have a guider and it's the same as the CCD driver, then let's establish it separately.
    //if (useGuiderFromCCD == false && guider_di && (!strcmp(guider_di->getBaseDevice()->getDeviceName(), ccdDevice->getDeviceName())))
    if (useGuiderFromCCD == false && guiderName == QString(ccdDevice->getDeviceName()))
    {
        guider = ccdDevice;
        appendLogText(i18n("%1 is online.", ccdDevice->getDeviceName()));

        initGuide();
        guideProcess->setCCD(guider);

        if (scope && scope->isConnected())
            guideProcess->setTelescope(scope);
    }
    else
    {
        ccd = ccdDevice;

        if (ccdStarted == false)
            appendLogText(i18n("%1 is online.", ccdDevice->getDeviceName()));

        ccdStarted = true;

        // If guider is the same driver as the CCD
        if (useGuiderFromCCD == true)
        {
            guider = ccd;
            initGuide();
            guideProcess->setCCD(guider);

            if (scope && scope->isConnected())
                guideProcess->setTelescope(scope);
        }
    }

}
예제 #6
0
void EkosManager::processNewProperty(INDI::Property* prop)
{
    if (!strcmp(prop->getName(), "CCD_INFO") || !strcmp(prop->getName(), "GUIDE_INFO"))
    {
        if (guideProcess)
            guideProcess->syncCCDInfo();
    }

    if (!strcmp(prop->getName(), "TELESCOPE_INFO"))
    {
        if (guideProcess)
        {
           guideProcess->setTelescope(scope);
           guideProcess->syncTelescopeInfo();
        }

    }

    if (!strcmp(prop->getName(), "GUIDER_EXPOSURE"))
    {
        initCapture();

        if (ccd && !strcmp(ccd->getDeviceName(), prop->getDeviceName()))
            captureProcess->addGuideHead(ccd);
        else if (guider)
            captureProcess->addGuideHead(guider);


        if (guideProcess)
            guideProcess->addGuideHead();
    }

    if (!strcmp(prop->getName(), "CCD_FRAME_TYPE"))
    {
        if (captureProcess)
        {
            if (ccd && !strcmp(ccd->getDeviceName(), prop->getDeviceName()))
                captureProcess->syncFrameType(ccd);
            else if (guider)
                captureProcess->syncFrameType(guider);
        }
    }

}
  //---------------------------------------------------------------
  void
  Device1394::init(Miro::Server& _server, FilterParameters const * _params)
  {
    MIRO_DBG(VIDEO, LL_DEBUG, "Device1394::init()");

    if (_params)
        params_ = *(dynamic_cast<Device1394Parameters const *>(_params));

    initDevice();
    initSettings();
	
    setImageFormat();
    initCapture();

    control_ = new ControlImpl(this);
    Video::Control_var control = control_->_this();
    _server.addToNameService(control.in(), "VideoControl");

    Super::init(_server, _params);
  }
/** Codel startAcquire of activity Acquire.
 *
 * Triggered by bass_start.
 * Yields to bass_exec, bass_ether.
 * Throws bass_e_nomem, bass_e_device, bass_e_hwparams,
 *        bass_e_swparams.
 */
genom_event
startAcquire(const char *device, uint32_t sampleRate,
             uint32_t nFramesPerChunk, uint32_t nChunksOnPort,
             bass_ids *ids, const bass_Audio *Audio,
             genom_context self)
{
    int err;

    /* Prepare the Port */
    if ((err = initPort(Audio, sampleRate, nFramesPerChunk, nChunksOnPort,
                        self)) < 0)
        return_bass_exception(err);

    /* Start the capture */
    initCapture(&(ids->cap), device, sampleRate, nFramesPerChunk);
    if ((err = createCapture(ids->cap)) < 0) {
        endCapture(&(ids->cap));
        return_bass_exception(err);
    }

    return bass_exec;
}
예제 #9
0
int initAll()
{
	initConfiguration();

//	cout << "Use webcam? (Y/N)" <<endl;
//
//	char cc = fgetc(stdin);
	if( !initCapture(true,cam_id)) //!initCapture(cc == 'Y' || cc == 'y',cam_id) ) 
		return 0;

	if( !initFaceDet((OPENCV_ROOT + "/data/haarcascades/haarcascade_frontalface_default.xml").c_str()))
	{
		cerr << "failed initFaceDet with" << OPENCV_ROOT << "/data/haarcascades/haarcascade_frontalface_default.xml" << endl;
		return 0;
	}
	// Startup message tells user how to begin and how to exit
	printf( "\n********************************************\n"
	        "To exit, click inside the video display,\n"
	        "then press the ESC key\n\n"
			"Press <ENTER> to begin"
			"\n********************************************\n" );
	fgetc(stdin);

	// Create the display window
	cvNamedWindow( DISPLAY_WINDOW, 1 );

	// Initialize tracker
	captureVideoFrame();
	if( !createTracker(pfd_pVideoFrameCopy) ) return 0;

	// Set Camshift parameters
	setVmin(60);
	setSmin(50);

	FdInit();

	return 1;
}
예제 #10
0
Video::Video(int w, int h){
	this->width = w, this->height = h;

	initCapture();
	initMemory();
}
예제 #11
0
void initProgram()
{
	//------------------------
	// start initializing crap
	//------------------------
	defaultExceptionHandler(); // set up the exception handler

    powerON(POWER_ALL_2D); // turn on everything

	#ifndef DEBUG_MODE
	fb_init(); // initialize top screen video
	#else
	debugInit();
	#endif
	bg_init(); // initialize bottom screen video

	setNewOrientation(ORIENTATION_0);

	// set up extra vram banks to be scratch memory
	vramSetBankE(VRAM_E_LCD);
	vramSetBankF(VRAM_F_LCD);
	vramSetBankG(VRAM_G_LCD);
	vramSetBankH(VRAM_H_LCD);
	vramSetBankI(VRAM_I_LCD);

	fb_setBGColor(30653);
	bg_setBGColor(0);
	drawStartSplash();

	lcdMainOnTop(); // set fb to top screen
	fb_swapBuffers();
	bg_swapBuffers();

	// out of order for competition
	irqInit(); // initialize irqs

    irqSet(IRQ_VBLANK, startvBlank);
	irqEnable(IRQ_VBLANK);

	setMode(INITFAT);
	setSoundInterrupt(); // initialize fifo irq

	setGenericSound(11025, 127, 64, 1);
	waitForInit(); // wait until arm7 has loaded and gone to sleep
	initComplexSound(); // initialize sound variables
	initWifi();
	fixGautami();

	setCursorProperties(0, 2, 0, 0);
	initCapture();
	initClipboard();

	// set defaults to english in case we can't load the langauge file for
	// some reason also takes care of partial translations.
	initLanguage();
	initRandomList();
	fixAndTags();

	resetKeyboard();
	setDate();

	if(!DRAGON_InitFiles())
	{
		// oops, no cf card!
		setMode(DISPLAYCOW);

		setFont(font_arial_11);
		setColor(0xFFFF);

		bg_dispSprite(96, 5, errmsg, 0);
		bg_setClipping(5,25,250,181);
		bg_dispString(0,0,l_nofat);
		bg_swapBuffers();

		while(1)
		{
			// wee, la la la!
		  // More or less, we aren't going to do nothing here
		}
	}

	//--------------------------------------------------------------------
	//finished init, now check to make sure the DSOrganize dir is there...
	//--------------------------------------------------------------------

	findDataDirectory();
	makeDirectories();

	if(DRAGON_FileExists("DSOrganize") != FE_DIR)
	{
		setMode(DISPLAYCOW);

		// oops, not there, we must create!
		DRAGON_mkdir("DSOrganize");
		DRAGON_chdir("DSOrganize");
		DRAGON_mkdir("DAY");
		DRAGON_mkdir("HELP");
		DRAGON_mkdir("LANG");
		DRAGON_mkdir("RESOURCES");
		DRAGON_mkdir("REMINDER");
		DRAGON_mkdir("SCRIBBLE");
		DRAGON_mkdir("TODO");
		DRAGON_mkdir("VCARD");
		DRAGON_mkdir("ICONS");
		DRAGON_mkdir("CACHE");
		DRAGON_mkdir("COOKIES");
		DRAGON_mkdir("HOME");
		DRAGON_chdir("/");

		makeDefaultSettings();

		setFont(font_arial_11);
		setColor(0xFFFF);

		bg_dispSprite(96, 5, errmsg, 0);
		bg_setClipping(5,25,250,181);
		bg_dispString(0,0, l_createdir);
		bg_swapBuffers();

		while(!keysDown())
		{
			scanKeys();
		}
	}

	setMode(INITPLUGIN);

	//-------------------------------------------------------------------
	//finished creating dirs, now check to make sure if they extracted it
	//did their extracting program actually get all the dirs?
	//-------------------------------------------------------------------

	DRAGON_chdir(d_base);

	if(DRAGON_FileExists("Day") != FE_DIR)
	{
		DRAGON_mkdir("DAY");
	}
	if(DRAGON_FileExists("Help") != FE_DIR)
	{
		DRAGON_mkdir("HELP");
	}
	if(DRAGON_FileExists("Lang") != FE_DIR)
	{
		DRAGON_mkdir("LANG");
	}
	if(DRAGON_FileExists("Reminder") != FE_DIR)
	{
		DRAGON_mkdir("REMINDER");
	}
	if(DRAGON_FileExists("Scribble") != FE_DIR)
	{
		DRAGON_mkdir("SCRIBBLE");
	}
	if(DRAGON_FileExists("Todo") != FE_DIR)
	{
		DRAGON_mkdir("TODO");
	}
	if(DRAGON_FileExists("VCard") != FE_DIR)
	{
		DRAGON_mkdir("VCARD");
	}
	if(DRAGON_FileExists("Icons") != FE_DIR)
	{
		DRAGON_mkdir("ICONS");
	}
	if(DRAGON_FileExists("Cache") != FE_DIR)
	{
		DRAGON_mkdir("CACHE");
	}
	if(DRAGON_FileExists("Cookies") != FE_DIR)
	{
		DRAGON_mkdir("COOKIES");
	}
	if(DRAGON_FileExists("Home") != FE_DIR)
	{
		DRAGON_mkdir("HOME");
	}

	DRAGON_chdir("/");

	//-------------------------------------------
	//how about we load the settings for them eh?
	//-------------------------------------------
	loadSettings();

	DRAGON_chdir(d_base);

	if(DRAGON_FileExists("startup.wav") == FE_FILE)
	{
		char tStr[256];

		sprintf(tStr, "%sstartup.wav", d_base);
		loadWavToMemory();
		loadSound(tStr);
	}

	DRAGON_chdir("/");
	initStartScreen();

    irqSet(IRQ_VBLANK, vBlank);
	fb_setBGColor(genericFillColor);
	bg_setBGColor(genericFillColor);
}
/*=====================app_main===========================*/
int app_main()
{
	int i = 0;
	void *capturebuffer0;
	void *displaybuffer;
	int counter = 0;
	int ret = 0;
	struct v4l2_format capture_fmt;
	struct v4l2_format display_fmt;
	int capture_chroma_offset, display_chroma_offset;
	int capture_size;
	int capture_fd, display_fd;
	char outputname[15];
	char stdname[15];
	int capture_numbuffers = MAX_BUFFER, display_numbuffers = MAX_BUFFER;

	for (i = 0; i < MAX_BUFFER; i++) {
		capture_buff_info[i].start = NULL;
		display_buff_info[i].start = NULL;
	}

	/* STEP1:
	 * Initialization section
	 * Initialize capture and display devices. 
	 * Here one capture channel is opened 
	 * Display channel is opened with the same standard that is detected at
	 * capture channel. same output name as input
	 * */

	/* open capture channel 0 */
	ret = initCapture(&capture_fd, &capture_numbuffers, &capture_fmt);
	if (ret < 0) {
		printf("Error in opening capture device for channel 0\n");
		return ret;
	}

	printf(" Capture initialized\n");
	/* open display channel */
	if (display_enable) {
		ret = initDisplay(&display_fd, &display_numbuffers, &display_fmt);
		if (ret < 0) {
			printf("Error in opening display device\n");
			return ret;
		}
		printf(" Display initialized\n");
		/* run section
		 * STEP2:
		 * Here display and capture channels are started for streaming. After 
		 * this capture device will start capture frames into enqueued 
		 * buffers and display device will start displaying buffers from 
		 * the qneueued buffers */

		/* start display */
		ret = startDisplay(&display_fd);
		if (ret < 0) {
			printf("Error in starting display\n");
			return ret;
		}
		printf(" display started \n");
	}
	/* start capturing for channel 0 */
	ret = startCapture(&capture_fd);
	if (ret < 0) {
		printf("Error in starting capturing for channel 0\n");
		return ret;
	}

	printf(" capture started \n");

	/* calculate the offset from where chroma data will be stored for 
	 * both capture and display */
	capture_chroma_offset = kernel_buf_size/2;
	//display_chroma_offset = display_fmt.fmt.pix.sizeimage / 2;
	display_chroma_offset = kernel_buf_size/2;
	capture_size = capture_fmt.fmt.pix.width * capture_fmt.fmt.pix.height;

	/* One buffer is dequeued from display and capture channels.
	 * Capture buffer will be copied to display buffer.
	 * All two buffers are put back to respective channels.
	 * This sequence is repeated in loop.
	 * After completion of this loop, channels are stopped.
	 * */
	printf("Going into loopback\n");

#if 0
	sleep(10);
#else
	while (1) {
		/* get capturing buffer for channel 0 */
		capturebuffer0 = getCaptureBuffer(&capture_fd);
		if (NULL == capturebuffer0) {
			printf("Error in get capture buffer for channel 0\n");
			return ret;
		}

		/* get display buffer */
		if (display_enable) {
			displaybuffer = getDisplayBuffer(&display_fd);
			if (NULL == displaybuffer) {
				printf("Error in get display buffer\n");
				return ret;
			}

			/* Copy Luma data from capture buffer to display buffer */
			memcpy(displaybuffer, capturebuffer0, capture_size);
			/* Copy chroma data from capture buffer to display buffer
			 * from the appropriate offsets in capture buffer and 
			 * display buffer */
			memcpy(displaybuffer + display_chroma_offset,
				capturebuffer0 + capture_chroma_offset,
				capture_size);

			/* put output buffer into display queue */
			ret = putDisplayBuffer(&display_fd, display_numbuffers,
					       displaybuffer);
			if (ret < 0) {
				printf("Error in put display buffer\n");
				return ret;
			}
		}
		if (save_frame && counter == 100) {
			fwrite(capturebuffer0, 1, capture_size,
				file_fp);
			fwrite(capturebuffer0 + capture_chroma_offset,
				1, capture_size,
				file_fp); 
			fclose(file_fp);
		}

		/* put buffers in capture channels */
		ret = putCaptureBuffer(&capture_fd, capture_numbuffers,
				       capturebuffer0);
		if (ret < 0) {
			printf("Error in put capture buffer for channel 0\n");
			return ret;
		}
		counter++;


		if (print_fn)
			printf("time:%lu    frame:%u\n", (unsigned long)time(NULL), counter);

		if (stress_test && counter >= MAXLOOPCOUNT)
			break;
	}
#endif

	printf("After sleep, stop capture/display\n");
	/* stop display */
	if (display_enable) {
		ret = stopDisplay(&display_fd);
		if (ret < 0) {
			printf("Error in stopping display\n");
			return ret;
		}
	}
	/* stop capturing for channel 0 */
	ret = stopCapture(&capture_fd);
	if (ret < 0) {
		printf("Error in stopping capturing for channel 0\n");
		return ret;
	}

	/* close capture channel 0 */
	ret = releaseCapture(&capture_fd, capture_numbuffers);
	if (ret < 0) {
		printf("Error in closing capture device\n");
		return ret;
	}
	/* Free section
	 * Here channels for capture and display are close.
	 * */
	/* open display channel */
	if (display_enable) {
		ret = releaseDisplay(&display_fd, display_numbuffers);
		if (ret < 0) {
			printf("Error in closing display device\n");
			return ret;
		}
	}
	return ret;
}
예제 #13
0
void LUA_START_CALLBACK(SLuaCallBack* p)
{ // the callback function of the new Lua command
	int result=-1; // error
	int returnResolution[2]={0,0};

	if (p->inputArgCount>2)
	{ // Ok, we have at least 3 input argument
		if ( (p->inputArgTypeAndSize[0*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[1*2+0]==sim_lua_arg_int)&&(p->inputArgTypeAndSize[2*2+0]==sim_lua_arg_int) )
		{ // Ok, we have (at least) 3 ints as argument
			if ( (countCaptureDevices()>p->inputInt[0])&&(p->inputInt[0]>=0)&&(p->inputInt[0]<4) )
			{
				if (!openCaptureDevices[p->inputInt[0]])
				{ // We can set the new resolution
					bool goOn=true;
					if (startCountOverall==0)
					{ // Launch the thread!
						_camThreadLaunched=false;
						CreateThread(NULL,0,_camThread,NULL,THREAD_PRIORITY_NORMAL,NULL);
						while (!_camThreadLaunched)
							Sleep(2);
						if (deviceCount<1)
						{
							simSetLastError(LUA_START,"ESCAPI initialization failure or no devices found."); // output an error
							killThread();
							goOn=false;
						}
					}

					if (goOn)
					{
						captureInfo[p->inputInt[0]].mWidth=p->inputInt[1];
						captureInfo[p->inputInt[0]].mHeight=p->inputInt[2];
						captureInfo[p->inputInt[0]].mTargetBuf=new int[p->inputInt[1]*p->inputInt[2]];
						if (initCapture(p->inputInt[0],&captureInfo[p->inputInt[0]])!=0)
						{
							doCapture(p->inputInt[0]);
							openCaptureDevices[p->inputInt[0]]=true;
							returnResolution[0]=p->inputInt[1];
							returnResolution[1]=p->inputInt[2];
							result=1; // success!
							startCountOverall++;
							startCountPerDevice[p->inputInt[0]]++;
						}
						else
						{
							delete[] captureInfo[p->inputInt[0]].mTargetBuf;
							simSetLastError(LUA_START,"Device may already be in use."); // output an error
						}
					}
				}
				else
				{ // We have to retrieve the current resolution
					returnResolution[0]=captureInfo[p->inputInt[0]].mWidth;
					returnResolution[1]=captureInfo[p->inputInt[0]].mHeight;
					result=0;
					startCountOverall++;
					startCountPerDevice[p->inputInt[0]]++;
				}
			}
			else
				simSetLastError(LUA_START,"Invalid device index."); // output an error
		}
		else
			simSetLastError(LUA_START,"Wrong argument type/size."); // output an error
	}
	else
		simSetLastError(LUA_START,"Not enough arguments."); // output an error

	// Now we prepare the return value:
	if (result>-1)
	{
		p->outputArgCount=3; // 3 return values
		p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer
		p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int;	// The return value is an int
		p->outputArgTypeAndSize[2*0+1]=1;				// Not used (table size if the return value was a table)
		p->outputArgTypeAndSize[2*1+0]=sim_lua_arg_int;	// The return value is an int
		p->outputArgTypeAndSize[2*1+1]=1;				// Not used (table size if the return value was a table)
		p->outputArgTypeAndSize[2*2+0]=sim_lua_arg_int;	// The return value is an int
		p->outputArgTypeAndSize[2*2+1]=1;				// Not used (table size if the return value was a table)
		p->outputInt=(simInt*)simCreateBuffer(3*sizeof(result)); // 1 int return value
		p->outputInt[0]=result; // This is the int value we want to return
		p->outputInt[1]=returnResolution[0]; // This is the int value we want to return
		p->outputInt[2]=returnResolution[1]; // This is the int value we want to return
	}
	else
	{
		p->outputArgCount=1; // 1 return value
		p->outputArgTypeAndSize=(simInt*)simCreateBuffer(p->outputArgCount*2*sizeof(simInt)); // x return values takes x*2 simInt for the type and size buffer
		p->outputArgTypeAndSize[2*0+0]=sim_lua_arg_int;	// The return value is an int
		p->outputArgTypeAndSize[2*0+1]=1;				// Not used (table size if the return value was a table)
		p->outputInt=(simInt*)simCreateBuffer(1*sizeof(result)); // 1 int return value
		p->outputInt[0]=result; // This is the int value we want to return
	}
}