net.luniks.linux.jv4linfo
Class JV4LInfo

java.lang.Object
  extended bynet.luniks.linux.jv4linfo.JV4LInfo

public class JV4LInfo
extends java.lang.Object

Class providing some static methods to query and set video for linux (two) devices using the JNI. The methods work a little bit like the ioctl's of the v4l and v4l2 API's: An instance of a class representing a particular struct is given as argument to the corresponding method, which sets all fields to the values provided by the ioctl call. The classes have getters and some convenience methods, and setters for the changeable fields of the structs.
This class can also return instances of type V4LCtrl and V4L2Ctrl that hold information about a particular video device and provide some methods to control the device, such as setting the selected video norm/standard.
The methods getV4LInfo() and getV4L2Info() are in a way redundant because the returned instances are also available as members of V4LCtrl and V4L2Ctrl, respectively.
This class requires the shared library "libjv4linfo.so" to be in the LD_LIBRARY_PATH or the java.library.path system property.
PLEASE NOTE, that this API is not only incomplete but also pretty experimental, so it might not do things the way they should be done. It has currently been tested only with a Hauppauge WinTV PCI on Kernel 2.4 and 2.6.

The source can be found here: jv4linfo-0.2.1-src.jar

Example:

    // Get/set the frequency of the tuner associated with the
    // input with index '0' using the native methods of JV4LInfo 
    try {
      // Open the video device
      JV4LInfo.open("/dev/video0");

      // Get the input with index '0'
      V4L2Input input = new V4L2Input();
      input.setIndex(0);
      JV4LInfo.getV4L2Input(input);

      System.out.println("Input: " + input.getName());

      if(input.isTuner()) {
        // Get the index of the tuner associated with the input
        int tunerIndex = input.getTuner();

        // Get the frequency of the tuner
        V4L2Frequency freq = new V4L2Frequency();
        freq.setTuner(tunerIndex);
        JV4LInfo.getV4L2Frequency(freq);

        System.out.println("Current frequency is: " + freq.getFrequency());

        // Set a frequency
        freq.setFrequency(2999);
        JV4LInfo.setV4L2Frequency(freq);
      }
    }
    catch(JV4LInfoException e) {
      e.printStackTrace();
    }
    // Make sure the device will be closed in any case
    finally {
      JV4LInfo.close();
    }

    // Get/set the frequency using a convenience method of V4L2Ctrl.
    // The method will look at all inputs starting with index '0'
    // until an input of type tuner has been found. Then it gets/sets
    // the frequency of the tuner associated with that index.
    try {
      V4L2Ctrl ctrl = JV4LInfo.getV4L2Ctrl("/dev/video0");
      int frequency = ctrl.getSelectedFrequency().getFrequency();

      System.out.println("Current frequency is: " + frequency);

      ctrl.setSelectedFrequency(2999);
    }
    catch(JV4LInfoException e) {
      e.printStackTrace();
    }
 

Author:
Torsten Römer, www.luniks.net

Field Summary
private static int file
          Reference to the device file, only used from within the C code
static java.lang.String LIBRARY
          Platform independent library name
static java.lang.String V4L
          API name "v4l"
static java.lang.String V4L2
          API name "v4l2"
 
Constructor Summary
JV4LInfo()
           
 
Method Summary
static int close()
          Native method to close the device
static long getSelectedFrequency()
          Native method to get the selected v4l frequency
static int getSelectedV4L2Input()
          Native method to get the selected v4l2 input
static int getSelectedV4L2Standard()
          Native method to get the selected v4l2 standard
static void getV4L2Capability(V4L2Capability cap)
          Native method to get v4l2 capabilies
static void getV4L2Control(V4L2Control control)
          Native method to get a v4l2 control
static V4L2Ctrl getV4L2Ctrl(java.lang.String device)
          Returns an instance of the class V4L2Ctrl which allows to get information about and to control the video device specified as argument using the v4l2 API.
static void getV4L2Frequency(V4L2Frequency frequency)
          Native method to get a v4l2 frequency
static V4L2Info getV4L2Info(java.lang.String device)
          Queries the device specified as argument using the v4l2 API and returns an instance of the class V4L2Info which holds the gathered information about the device.
static void getV4L2Input(V4L2Input input)
          Native method to get a v4l2 input
static void getV4L2Standard(V4L2Standard std)
          Native method to get a v4l2 standard
static void getV4L2Tuner(V4L2Tuner tuner)
          Native method to get a v4l2 tuner
static V4LCtrl getV4LCtrl(java.lang.String device)
          Returns an instance of the class V4LCtrl which allows to get information about and to control the video device specified as argument using the v4l API.
static V4LInfo getV4LInfo(java.lang.String device)
          Queries the device specified as argument using the v4l API and returns an instance of the class V4LInfo which holds the gathered information about the device.
static void getVideoAudio(VideoAudio audio)
          Native method to get a v4l audio
static void getVideoCapability(VideoCapability cap)
          Native method to get v4l capabilies
static void getVideoChannel(VideoChannel chan)
          Native method to get a v4l channel (input)
static void getVideoTuner(VideoTuner tuner)
          Native method to get a v4l tuner
static boolean isV4L2Available(java.lang.String device)
          Tries to get the capabilties of the device specified as argument using the V4L2 API, and returns true if that was successful, false otherwise.
static void main(java.lang.String[] args)
          For testing, takes the API (v4l|v4l2) as first and the device for example /dev/video0, as second argument
static void open(java.lang.String device)
          Native method to open the device
static void setSelectedFrequency(long freq)
          Native method to set the selected frequency
static void setSelectedV4L2Input(int index)
          Native method to set the selected v4l2 input
static void setSelectedV4L2Standard(long id)
          Native method to set the selected v4l2 standard
static void setV4L2Control(V4L2Control control)
          Native method to set a v4l2 control Sets the fields id and value
static void setV4L2Frequency(V4L2Frequency frequency)
          Native method to set a v4l2 frequency Sets the fields tuner and frequency
static void setV4L2Tuner(V4L2Tuner tuner)
          Native method to set a v4l2 tuner Sets the fields index and audmode
static void setVideoAudio(VideoAudio audio)
          Native method to set a v4l audio Sets the fields audio, volume, bass, treble, balance, flags and mode
static void setVideoChannel(VideoChannel chan)
          Native method to set a v4l channel Sets the fields channel and norm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

V4L

public static final java.lang.String V4L
API name "v4l"

See Also:
Constant Field Values

V4L2

public static final java.lang.String V4L2
API name "v4l2"

See Also:
Constant Field Values

LIBRARY

public static final java.lang.String LIBRARY
Platform independent library name

See Also:
Constant Field Values

file

private static final int file
Reference to the device file, only used from within the C code

See Also:
Constant Field Values
Constructor Detail

JV4LInfo

public JV4LInfo()
Method Detail

isV4L2Available

public static boolean isV4L2Available(java.lang.String device)
                               throws JV4LInfoException
Tries to get the capabilties of the device specified as argument using the V4L2 API, and returns true if that was successful, false otherwise.

Parameters:
device - the device to be used for the test
Returns:
true only if it was possible query capabilities using V4L2
Throws:
JV4LInfoException

getV4LInfo

public static V4LInfo getV4LInfo(java.lang.String device)
                          throws JV4LInfoException
Queries the device specified as argument using the v4l API and returns an instance of the class V4LInfo which holds the gathered information about the device.

Parameters:
device - the device to be queried
Returns:
instance of V4LInfo holding info about the device
Throws:
JV4LInfoException

getV4L2Info

public static V4L2Info getV4L2Info(java.lang.String device)
                            throws JV4LInfoException
Queries the device specified as argument using the v4l2 API and returns an instance of the class V4L2Info which holds the gathered information about the device.

Parameters:
device - the device to be queried
Returns:
instance of V4L2Info holding info about the device
Throws:
JV4LInfoException

getV4LCtrl

public static V4LCtrl getV4LCtrl(java.lang.String device)
                          throws JV4LInfoException
Returns an instance of the class V4LCtrl which allows to get information about and to control the video device specified as argument using the v4l API.

Parameters:
device - the device to be controlled
Returns:
instance of V4LCtrl allowing to control the device
Throws:
JV4LInfoException

getV4L2Ctrl

public static V4L2Ctrl getV4L2Ctrl(java.lang.String device)
                            throws JV4LInfoException
Returns an instance of the class V4L2Ctrl which allows to get information about and to control the video device specified as argument using the v4l2 API.

Parameters:
device - the device to be controlled
Returns:
instance of V4L2Ctrl allowing to control the device
Throws:
JV4LInfoException

open

public static void open(java.lang.String device)
                 throws JV4LInfoException
Native method to open the device

Parameters:
device - the device file to be opened
Throws:
JV4LInfoException

close

public static int close()
Native method to close the device

Returns:
0 on success, -1 on failure

getVideoCapability

public static void getVideoCapability(VideoCapability cap)
                               throws JV4LInfoException
Native method to get v4l capabilies

Parameters:
cap - the VideoCapability to be filled in
Throws:
JV4LInfoException

getVideoChannel

public static void getVideoChannel(VideoChannel chan)
                            throws JV4LInfoException
Native method to get a v4l channel (input)

Parameters:
chan - the VideoChannel to be filled in
Throws:
JV4LInfoException

getVideoTuner

public static void getVideoTuner(VideoTuner tuner)
                          throws JV4LInfoException
Native method to get a v4l tuner

Parameters:
tuner - the VideoTuner to be filled in
Throws:
JV4LInfoException

getVideoAudio

public static void getVideoAudio(VideoAudio audio)
                          throws JV4LInfoException
Native method to get a v4l audio

Parameters:
audio - the VideoAudio to be filled in
Throws:
JV4LInfoException

setVideoChannel

public static void setVideoChannel(VideoChannel chan)
                            throws JV4LInfoException
Native method to set a v4l channel Sets the fields channel and norm

Parameters:
chan - the VideoChannel to be set
Throws:
JV4LInfoException

setVideoAudio

public static void setVideoAudio(VideoAudio audio)
                          throws JV4LInfoException
Native method to set a v4l audio Sets the fields audio, volume, bass, treble, balance, flags and mode

Parameters:
audio - the VideoAudio to be set
Throws:
JV4LInfoException

getSelectedFrequency

public static long getSelectedFrequency()
                                 throws JV4LInfoException
Native method to get the selected v4l frequency

Returns:
the current frequency
Throws:
JV4LInfoException

setSelectedFrequency

public static void setSelectedFrequency(long freq)
                                 throws JV4LInfoException
Native method to set the selected frequency

Parameters:
freq - the frequency value in 62.5 (k)Hz units
Throws:
JV4LInfoException

getV4L2Capability

public static void getV4L2Capability(V4L2Capability cap)
                              throws JV4LInfoException
Native method to get v4l2 capabilies

Parameters:
cap - the V4L2Capability to be filled in
Throws:
JV4LInfoException

getV4L2Input

public static void getV4L2Input(V4L2Input input)
                         throws JV4LInfoException
Native method to get a v4l2 input

Parameters:
input - the V4L2Input to be filled in
Throws:
JV4LInfoException

getV4L2Standard

public static void getV4L2Standard(V4L2Standard std)
                            throws JV4LInfoException
Native method to get a v4l2 standard

Parameters:
std - the V4L2Standard to be filled in
Throws:
JV4LInfoException

getV4L2Tuner

public static void getV4L2Tuner(V4L2Tuner tuner)
                         throws JV4LInfoException
Native method to get a v4l2 tuner

Parameters:
tuner - the V4L2Tuner to be filled in
Throws:
JV4LInfoException

getV4L2Frequency

public static void getV4L2Frequency(V4L2Frequency frequency)
                             throws JV4LInfoException
Native method to get a v4l2 frequency

Parameters:
frequency - the V4L2Frequency to be filled in
Throws:
JV4LInfoException

getV4L2Control

public static void getV4L2Control(V4L2Control control)
                           throws JV4LInfoException
Native method to get a v4l2 control

Parameters:
control - the V4L2Control to be filled in
Throws:
JV4LInfoException

setV4L2Tuner

public static void setV4L2Tuner(V4L2Tuner tuner)
                         throws JV4LInfoException
Native method to set a v4l2 tuner Sets the fields index and audmode

Parameters:
tuner - the V4L2Tuner to be set
Throws:
JV4LInfoException

setV4L2Frequency

public static void setV4L2Frequency(V4L2Frequency frequency)
                             throws JV4LInfoException
Native method to set a v4l2 frequency Sets the fields tuner and frequency

Parameters:
frequency - the V4L2Frequency to be set
Throws:
JV4LInfoException

setV4L2Control

public static void setV4L2Control(V4L2Control control)
                           throws JV4LInfoException
Native method to set a v4l2 control Sets the fields id and value

Parameters:
control - the V4L2Control to be set
Throws:
JV4LInfoException

getSelectedV4L2Input

public static int getSelectedV4L2Input()
                                throws JV4LInfoException
Native method to get the selected v4l2 input

Returns:
the index of the selected input or -1 on failure
Throws:
JV4LInfoException

getSelectedV4L2Standard

public static int getSelectedV4L2Standard()
                                   throws JV4LInfoException
Native method to get the selected v4l2 standard

Returns:
the id of the selected standard or -1 on failure
Throws:
JV4LInfoException

setSelectedV4L2Input

public static void setSelectedV4L2Input(int index)
                                 throws JV4LInfoException
Native method to set the selected v4l2 input

Parameters:
index - the index specifying the input to select
Throws:
JV4LInfoException

setSelectedV4L2Standard

public static void setSelectedV4L2Standard(long id)
                                    throws JV4LInfoException
Native method to set the selected v4l2 standard

Parameters:
id - the id specifying the standard to select
Throws:
JV4LInfoException

main

public static void main(java.lang.String[] args)
For testing, takes the API (v4l|v4l2) as first and the device for example /dev/video0, as second argument



Copyright © 2004 Torsten Römer, dode@luniks.net