/* (non-Javadoc)
@see au.edu.jcu.v4l4j.FrameGrabber#startCapture()
336101
@Override
	public final void startCapture() throws V4L4JException {
		state.start();

		// make sure we have a push source
		if(pushSource == null) {
			state.rollback();
			throw new V4L4JException("setCaptureCallback() must be called with a valid "
					+ "callback object before startCapture()"); 
		}

		// start the push source and wait until it's blocked on getVideoFrame()
		pushSource.startCapture();
		state.waitForAtLeastOneUser();

		try {
			// start video capture and enqueue all buffers
			start(object);
		} catch (V4L4JException e) {
			// Error starting the capture...

			// stop the push source thread
			pushSource.stopCapture();

			// return to previous state
			state.rollback();

			// propagate exception
			throw e;
		}

		// change state to STARTED
		state.commit();

		// put all frames into the available queue and wake up push source thread
		synchronized(availableVideoFrames){
			availableVideoFrames.addAll(videoFrames);
			availableVideoFrames.notifyAll();
		}
	}
563136
function initCapture(el) {
  // read the capture instructions
  var configText = el.getAttribute('rtc-capture') || '';
  var res = el.getAttribute('rtc-resolution') || el.getAttribute('rtc-res');
  var fps = el.getAttribute('rtc-fps');

  if (res) {
    configText += ' min:' + res + ' max:' + res;
  }

  if (fps) {
    configText += ' minfps:' + fps + ' maxfps:' + fps;
  }

  // patch in a capture method to the element
  el.capture = enableCapture(el, captureConfig(configText));

  // trigger capture
  el.capture(function(stream) {
    // broadcast the stream through the session manager
    if (sessionMgr) {
      sessionMgr.broadcast(stream, { name: el.id });
    }
  });
}
981253
public void start() {

		if (!started.compareAndSet(false, true)) {
			return;
		}

		webcam.addWebcamListener(this);

		LOG.debug("Starting panel rendering and trying to open attached webcam");

		updater.start();

		starting = true;

		final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

			@Override
			protected Void doInBackground() throws Exception {

				try {
					if (!webcam.isOpen()) {
						errored = !webcam.open();
					}
				} catch (WebcamException e) {
					errored = true;
					throw e;
				} finally {
					starting = false;
					repaintPanel();
				}

				return null;
			}
		};
		worker.execute();
	}
1102916
public void setStart(final double START) {
        if (null == start) {
            _start = START;
            fireSectionEvent(UPDATE_EVENT);
        } else {
            start.set(START);
        }
    }
719595
final void release(){
		try {stopCapture();}
		catch (StateException se) {
			//capture already stopped 
		}

		state.release();		
		doRelease(object);
		state.commit();
	}
53200
@Override
	public final void setCaptureCallback(CaptureCallback callback) {
		if (callback == null)
			throw new NullPointerException("The callback object cannot be null");

		synchronized (state){
			// make sure we are in the right state.
			if (state.isStarted())
				throw new StateException("This frame grabber is already started");

			// create the push source object
			pushSource = new PushSource(this, callback, threadFactory);
		}
	}
470616
@Override
	public synchronized void start() {
		super.start();
		this.running = true;
		if (this.hasFrame) this.frame.setVisible(true);
		this.thread.start();
	}
149997
@Override
	public void start(Geometry geometry) {
		if (started) {
			return;
		}
		this.geometry = geometry;
		if (geometry == null) {
			throw new IllegalArgumentException("Null geometry not allowed.");
		}
		started = true;
		eventBus.fireEvent(new GeometryEditStartEvent(geometry));
	}
896496
@Override
    public void start(boolean deliverImmediately)
                    throws SISessionUnavailableException, SISessionDroppedException,
                    SIErrorException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConsumerSession.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConsumerSession.tc, "start",
                        new Object[] { this, Boolean.valueOf(deliverImmediately) });
        //start the LCP
        _localConsumerPoint.start(deliverImmediately);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(CoreSPIConsumerSession.tc, "start");
    }
158592
public void restart() {
		if (frames.size() == 0) {
			return;
		}
		stopped = false;
		currentFrame = 0;
		nextChange = (int) (((Frame) frames.get(0)).duration / speed);
		firstUpdate = true;
		lastUpdate = 0;
	}
1126705
public void setStart(final LocalTime START) {
        if (null == start) {
            _start = START;
        } else {
            start.set(START);
        }
    }
529579
@Override
   public void start() {
      synchronized (this) {
         try {
            while (state == ComponentStatus.INITIALIZING) {
               wait();
            }
            if (state != ComponentStatus.INSTANTIATED) {
               return;
            }

            state = ComponentStatus.INITIALIZING;
         } catch (InterruptedException e) {
            throw new CacheException("Interrupted waiting for the component registry to start");
         }
      }

      try {
         preStart();

         internalStart();

         synchronized (this) {
            state = ComponentStatus.RUNNING;
            notifyAll();
         }

         postStart();
      } catch (Throwable t) {
         synchronized (this) {
            state = ComponentStatus.FAILED;
            notifyAll();
         }

         try {
            stop();
         } catch (Throwable t1) {
            t.addSuppressed(t1);
         }

         handleLifecycleTransitionFailure(t);
      }
   }
1000265
private Thread startFramesRefresher() {
		Thread refresher = new Thread(this, String.format("frames-refresher-[%s]", id));
		refresher.setUncaughtExceptionHandler(WebcamExceptionHandler.getInstance());
		refresher.setDaemon(true);
		refresher.start();
		return refresher;
	}
293253
public void startLink(final VertexContext startVertex) {
        if (startVertex == null) {
            return;
        }

        final AbstractLayout<Object, JobGraphLink> graphLayout = _graphContext.getGraphLayout();
        final int x = (int) graphLayout.getX(startVertex.getVertex());
        final int y = (int) graphLayout.getY(startVertex.getVertex());

        logger.debug("startLink({})", startVertex);

        _startVertex = startVertex;
        _startPoint = new Point(x, y);

        transformEdgeShape(_startPoint, _startPoint);
        _graphContext.getVisualizationViewer().addPostRenderPaintable(_edgePaintable);
        transformArrowShape(_startPoint, _startPoint);
        _graphContext.getVisualizationViewer().addPostRenderPaintable(_arrowPaintable);
    }
817348
protected void startCameraTexture( TextureView view ) {
		if( verbose )
			Log.i(TAG,"startCamera(TextureView="+(view!=null)+")");
		this.mTextureView = view;
		this.mView = null;
		this.mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
	}
1121445
public void startZoom(float endZoom) {
        mStartRTC = SystemClock.elapsedRealtime();
        mEndZoom = endZoom;

        mFinished = false;
        mCurrentZoom = 1f;
    }
93922
@Override protected synchronized Object doInBackground() throws Exception {
        try {
            setProgress(INITIALIZING);

            // perform initialization of camera device
            // access FrameGrabber objects from _this_ thread *ONLY*...
            frameGrabber = cameraDevice.createFrameGrabber();
            frameGrabber.setImageMode(ImageMode.COLOR);
            if (trackingSettings.useOpenCL) {
                frameGrabber.setPixelFormat(AV_PIX_FMT_RGBA);
            }
            frameGrabber.start();
            grabberConverter = new OpenCVFrameConverter.ToIplImage();
            IplImage image = grabberConverter.convert(frameGrabber.grab());
            final IplImage initImage = image;
            final int initWidth    = initImage.width();
            final int initHeight   = initImage.height();
            final int initChannels = trackingSettings.useOpenCL ? 4 : initImage.nChannels();
            final int initDepth    = initImage.depth();

            if (initWidth != cameraDevice.imageWidth || initHeight != cameraDevice.imageHeight) {
                cameraDevice.rescale(initWidth, initHeight);
            }

            // resize and tile the monitor frames according to the size of the grabbed images
            if (monitorWindows != null) {
                final double initScale = trackingSettings.getMonitorWindowsScale();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        for (int i = 0; i < monitorWindows.length; i++) {
                            monitorWindows[i].setCanvasSize(
                                    (int)Math.round(initWidth *initScale),
                                    (int)Math.round(initHeight*initScale));
                            monitorWindows[i].setTitle(monitorWindowsTitles[i] + " (" +
                                    initWidth + " x " + initHeight + "  " +
                                    (initDepth&~IPL_DEPTH_SIGN) + " bpp  gamma = " +
                                    frameGrabber.getGamma() + ") - ProCamTracker");
                        }
                    }
                });
                CanvasFrame.tile(monitorWindows);
                CanvasFrame.global = monitorWindows[0];
            }

            // allocate memory for all images and load video
            final int minLevel = alignerSettings.getPyramidLevelMin();
            undistortedCameraImage  = IplImage.create(initWidth >> minLevel,
                    initHeight >> minLevel, initDepth, initChannels);
            distortedProjectorImage = IplImage.create(projectorDevice.imageWidth,
                    projectorDevice.imageHeight, IPL_DEPTH_8U, initChannels);
            BufferRing.BufferFactory<ProjectorBuffer> projectorBufferFactory;
            projectorBufferFactory = new BufferRing.BufferFactory<ProjectorBuffer>() {
                public ProjectorBuffer create() {
                    return new ProjectorBuffer(distortedProjectorImage, false);
                }
            };
            if (trackingSettings.useOpenCL) {
                GLContext shareWith = null;
                if (projectorFrame instanceof GLCanvasFrame) {
                    shareWith = ((GLCanvasFrame)projectorFrame).getGLCanvas().getContext();
                }
                contextCL = new JavaCVCL(shareWith);

                grabbedImageCL            = //contextCL.createCLImageFrom(initImage);
                        contextCL.getCLContext().createImage2d(initWidth, initHeight,
                                new CLImageFormat(frameGrabber.getSensorPattern() != -1L ?
                                        CLImageFormat.ChannelOrder.R :
                                        CLImageFormat.ChannelOrder.RGBA, ChannelType.UNORM_INT8));
                undistortedCameraImageCL  = //contextCL.createCLImageFrom(undistortedCameraImage);
                        contextCL.getCLContext().createImage2d(
                                undistortedCameraImage.width(), undistortedCameraImage.height(),
                                new CLImageFormat(CLImageFormat.ChannelOrder.RGBA, ChannelType.FLOAT));
                cameraDevice.setMapsPyramidLevel(minLevel);
                cameraMapxCL = contextCL.writeImage(cameraMapxCL, cameraDevice.getUndistortMap1(), false);
                cameraMapyCL = contextCL.writeImage(cameraMapyCL, cameraDevice.getUndistortMap2(), false);

                if (projectorFrame != null) {
                    projectorMapxCL = contextCL.writeImage(projectorMapxCL, projectorDevice.getDistortMap1(), false);
                    projectorMapyCL = contextCL.writeImage(projectorMapyCL, projectorDevice.getDistortMap2(), false);
                    distortedProjectorImageCL = contextCL.createCLGLImageFrom(distortedProjectorImage);
                }
                projectorBufferFactory = new BufferRing.BufferFactory<ProjectorBuffer>() {
                    public ProjectorBuffer create() {
                        return new ProjectorBuffer(distortedProjectorImage, true);
                    }
                };
            }
            projectorBufferRing = new BufferRing<ProjectorBuffer>(projectorBufferFactory,
                    trackingSettings.projectorBufferingSize);

            realityAugmentor = new RealityAugmentor(realityAugmentorSettings,
                    objectFinderSettings, markerDetectorSettings, virtualBallSettings,
                    cameraDevice, projectorDevice, initChannels);

            handMouse = new HandMouse(handMouseSettings);

            // get the three projector frames for initialization
            GNImageAligner.Settings s = alignerSettings.clone();
            // prepare settings for maximum accuracy
            s.setAlphaTikhonov(0);
            s.setDeltaMin(0);
            s.setLineSearch(new double[] { 1.0, 1.0/2, 1.0/4, 1.0/8, 1.0/16, 1.0/32, 1.0/64, 1.0/128 });
            s.setThresholdsOutlier(new double[] { 0.0 });
            s.setThresholdsZero(new double[] { 0.0 });
            reflectanceInitializer = new ReflectanceInitializer(cameraDevice, projectorDevice, initChannels, s);
            projectorInitFloatImages = reflectanceInitializer.getProjectorImages();
            projectorInitImages   = new IplImage[projectorInitFloatImages.length];
            cameraInitImages      = new IplImage[projectorInitFloatImages.length];
            cameraInitFloatImages = new IplImage[projectorInitFloatImages.length];
            for (int i = 0; i < projectorInitFloatImages.length; i++) {
                projectorInitImages[i]   = IplImage.createCompatible(distortedProjectorImage);
                cameraInitImages[i]      = IplImage.create(initWidth, initHeight, initDepth, initChannels);
                cameraInitFloatImages[i] = IplImage.create(undistortedCameraImage.width(),
                        undistortedCameraImage.height(), IPL_DEPTH_32F, initChannels);
                cvConvertScale(projectorInitFloatImages[i], projectorInitImages[i], 255, 0);
                projectorDevice.distort(projectorInitImages[i], distortedProjectorImage);
                cvCopy(distortedProjectorImage, projectorInitImages[i]);
            }
            reflectanceImage = IplImage.createCompatible(cameraInitFloatImages[0]);
            if (trackingSettings.useOpenCL) {
                reflectanceImageCL = contextCL.createCLImageFrom(reflectanceImage);
            }

            if (trackingSettings.outputVideoFile != null) {
                frameRecorder = new FFmpegFrameRecorder(trackingSettings.outputVideoFile,
                        undistortedCameraImage.width(), undistortedCameraImage.height());
                frameRecorder.start();
                recorderConverter = new OpenCVFrameConverter.ToIplImage();
            } else {
                frameRecorder = null;
                recorderConverter = null;
            }

            boolean done = false;
            while (!done) {
                done = doTracking();

                // force release of native memory
                System.gc();
                Pointer.deallocateReferences();
            }
        } catch (Throwable t) {
            if (!isCancelled()) {
                while (t.getCause() != null) { t = t.getCause(); }
                logger.log(Level.SEVERE, "Could not perform tracking.", t);
                cancel(false);
            }
        }

        try {
            if (frameGrabber != null) {
                frameGrabber.stop();
                frameGrabber.release();
            }
        } catch (Exception ex) {
            logger.log(Level.SEVERE, "Could not release FrameGrabber.", ex);
        } finally {
            frameGrabber = null;
            grabberConverter = null;
        }

        try {
            if (frameRecorder != null) {
                frameRecorder.stop();
                frameRecorder.release();
            }
        } catch (Exception ex) {
            logger.log(Level.SEVERE, "Could not release FrameRecorder.", ex);
        } finally {
            frameRecorder = null;
            recorderConverter = null;
        }

        if (trackingSettings.useOpenCL) {
            grabbedImageCL.release();
            undistortedCameraImageCL.release();
            contextCL.releaseCLGLImage(distortedProjectorImageCL);
            reflectanceImageCL.release();
            cameraMapxCL.release();
            cameraMapyCL.release();
            projectorMapxCL.release();
            projectorMapyCL.release();
            grabbedImageCL = undistortedCameraImageCL = distortedProjectorImageCL = null;
            reflectanceImageCL = null;
            cameraMapxCL = cameraMapyCL = projectorMapxCL = projectorMapyCL = null;

            contextCL.release();
            contextCL = null;
        }

        roiPts = null;
        transformer = null;
        parameters = lastParameters = tempParameters = null;
        aligner = null;
        reflectanceInitializer = null;
        handMouse = null;
        realityAugmentor = null;

        grabbedImage = undistortedCameraImage = distortedProjectorImage = null;
        projectorInitFloatImages = projectorInitImages = null;
        cameraInitImages = cameraInitFloatImages = monitorImages = null;
        reflectanceImage = null;

        projectorBufferRing.release();
        projectorBufferRing = null;

        // force release of native memory
        System.gc();
        Pointer.deallocateReferences();

        return null;
    }