Package org.openni

Class VideoStream

java.lang.Object
org.openni.VideoStream

public class VideoStream extends Object
The VideoStream object encapsulates a single video stream from a device. Once created, it is used to start data flow from the device, and to read individual frames of data. This is the central class used to obtain data in OpenNI. It provides the ability to manually read data in a polling loop, as well as providing events and a Listener class that can be used to implement event-driven data acquisition. Aside from the video data frames themselves, the class offers a number of functions used for obtaining information about a VideoStream. Field of view, available video modes, and minimum and maximum valid pixel values can all be obtained. In addition to obtaining data, the VideoStream object is used to set all configuration properties that apply to a specific stream (rather than to an entire device). In particular, it is used to control cropping, mirroring, and video modes. A valid, initialized device that provides the desired stream type is required to create a stream. Several video streams can be created to stream data from the same sensor. This is useful if several components of an application need to read frames separately. While some device might allow different streams from the same sensor to have different configurations, most devices will have a single configuration for the sensor, shared by all streams.
  • Method Details

    • create

      public static VideoStream create(Device device, SensorType sensorType)
      Creates a stream of frames from a specific sensor type of a specific device. You must supply a reference to a Device that supplies the sensor type requested. You can use Device.hasSensor(SensorType) to check whether a given sensor is available on your target device before calling create().
      Parameters:
      device - A reference to the Device you want to create the stream on.
      sensorType - The type of sensor the stream should produce data from.
    • destroy

      public void destroy()
      Destroy this stream. This function is currently called automatically by the destructor, but it is considered a best practice for applications to manually call this function on any VideoStream that they call create() for.
    • getSensorInfo

      public final SensorInfo getSensorInfo()
      Provides the SensorInfo object associated with the sensor that is producing this VideoStream. SensorInfo is useful primarily as a means of learning which video modes are valid for this VideoStream.
      Returns:
      SensorInfo object associated with the sensor providing this stream.
    • start

      public void start()
      Starts data generation from this video stream.
    • stop

      public void stop()
      Stops data generation from this video stream.
    • readFrame

      public VideoFrameRef readFrame()
      Read the next frame from this video stream, delivered as a VideoFrameRef. This is the primary method for manually obtaining frames of video data. If no new frame is available, the call will block until one is available. To avoid blocking, use VideoStream.NewFrameListener to implement an event driven architecture. Another alternative is to use OpenNI.waitForAnyStream(java.util.List, int) to wait for new frames from several streams
      Returns:
      VideoFrameRef object which hold the data of the new frame.
    • addNewFrameListener

      public void addNewFrameListener(VideoStream.NewFrameListener streamListener)
      Adds a new Listener to receive this VideoStream onNewFrame event. See VideoStream.NewFrameListener for more information on implementing an event driven frame reading architecture.
      Parameters:
      streamListener - Object which implements VideoStream.NewFrameListener that will respond to this event.
    • removeNewFrameListener

      public void removeNewFrameListener(VideoStream.NewFrameListener streamListener)
      Removes a Listener from this video stream list. The listener removed will no longer receive new frame events from this stream.
      Parameters:
      streamListener - Object of the listener to be removed.
    • getHandle

      public long getHandle()
      This function return stream handle.
      Returns:
      OpenNI stream handle.
    • getCameraSettings

      public VideoStream.CameraSettings getCameraSettings()
      Gets an object through which several camera settings can be configured.
      Returns:
      null if the stream doesn't support camera settings.
    • getVideoMode

      public final VideoMode getVideoMode()
      Get the current video mode information for this video stream. This includes its resolution, fps and stream format.
      Returns:
      Current video mode information for this video stream.
    • setVideoMode

      public void setVideoMode(VideoMode videoMode)
      Changes the current video mode of this stream. Recommended practice is to use Device.getSensorInfo(SensorType), and then SensorInfo.getSupportedVideoModes() to obtain a list of valid video mode settings for this stream. Then, pass a valid VideoMode to setVideoMode(VideoMode) to ensure correct operation.
      Parameters:
      videoMode - Desired new video mode for this stream. returns Status code indicating success or failure of this operation.
    • getMaxPixelValue

      public int getMaxPixelValue()
      Provides the maximum possible value for pixels obtained by this stream. This is most useful for getting the maximum possible value of depth streams.
      Returns:
      Maximum possible pixel value.
    • getMinPixelValue

      public int getMinPixelValue()
      Provides the smallest possible value for pixels obtains by this VideoStream. This is most useful for getting the minimum possible value that will be reported by a depth stream.
      Returns:
      Minimum possible pixel value that can come from this stream.
    • isCroppingSupported

      public boolean isCroppingSupported()
      Checks whether this stream supports cropping.
      Returns:
      true if the stream supports cropping, false if it does not.
    • getCropping

      public CropArea getCropping()
      Obtains the current cropping settings for this stream.
      Returns:
      CropArea CropArea object which encapsulated cropping info.
    • setCropping

      public void setCropping(CropArea cropping)
      Changes the cropping settings for this stream. You can use the isCroppingSupported() function to make sure cropping is supported before calling this function.
      Parameters:
      cropping - CropArea object which set corresponding cropping information.
    • resetCropping

      public void resetCropping()
      Disables cropping.
    • getMirroringEnabled

      public boolean getMirroringEnabled()
      Check whether mirroring is currently turned on for this stream.
      Returns:
      true if mirroring is currently enabled, false otherwise.
    • setMirroringEnabled

      public void setMirroringEnabled(boolean isEnabled)
      Enable or disable mirroring for this stream.
      Parameters:
      isEnabled - true to enable mirroring, false to disable it.
    • getHorizontalFieldOfView

      public float getHorizontalFieldOfView()
      Gets the horizontal field of view of frames received from this stream.
      Returns:
      Horizontal field of view, in radians.
    • getVerticalFieldOfView

      public float getVerticalFieldOfView()
      Gets the vertical field of view of frames received from this stream.
      Returns:
      Vertical field of view, in radians.
    • getSensorType

      public SensorType getSensorType()
      Gets the sensor type for this stream.
      Returns:
      sensor type.