21 Sep, 2011

2 commits

  • The problem tackled in this patch is how to handle volatile autoclusters
    correctly. A volatile autocluster is a cluster of related controls where one
    control is the control that toggles between manual and auto mode and the other
    controls are the values for the manual mode. For example autogain and gain,
    autoexposure and exposure, etc.

    If the hardware lets you read out the automatically calculated manual values
    while in automode, then those manual controls should be marked volatile.

    gain value as calculated by the autogain circuitry, then you would mark the
    gain control as volatile (i.e. continuously changing).

    The question in such use cases is what to do when switching from the auto
    mode to the manual mode. Should we switch to the last set manual values or
    should the volatile values be copied and used as the initial manual values.

    For example: suppose the mode is manual gain and gain is set to 5. Then
    autogain is turned on and the gain is set by the hardware to 2. Finally
    the user switches back to manual gain. What should the gain be? 2 or 5?

    After a long discussion the decisions was made to keep the last value as
    calculated by the auto mode (so 2 in the example above).

    The reason is that webcams that do such things will adapt themselves to
    the current light conditions and when you switch back to manual mode you
    expect that you keep the same picture. If you would switch back to old
    manual values, then that would give you a suddenly different picture,
    which is jarring for the user.

    Additionally, this would be difficult to implement in applications that
    store and restore the control values at application exit and start.

    If you want to keep the old manual values when you switch from auto to
    manual, then there would have to be a way for applications to get hold
    of those old values while in auto mode, but there isn't.

    So this patch will do all the heavy lifting in v4l2-ctrls.c: if you go
    from auto mode to manual mode and the manual controls are volatile, then
    g_volatile_ctrl will be called to get the current values for the manual
    controls before switching to manual mode.

    Signed-off-by: Hans Verkuil
    Acked-by: Hans de Goede
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • With the new flag there is no need anymore to have a separate is_volatile
    field. Modify all users to use the new flag.

    Signed-off-by: Hans Verkuil
    Acked-by: Hans de Goede
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     

28 Jul, 2011

9 commits

  • Thanks to Laurent Pinchart .

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • The implementation of VIDIOC_G/S/TRY_EXT_CTRLS in the control framework has
    to figure out which controls in the control list belong to the same cluster.
    Since controls belonging to the same cluster need to be handled as a unit,
    this is important information.

    It did that by going over the controls in the list and for each control that
    belonged to a multi-control cluster it would walk the remainder of the list
    to try and find controls that belong to that same cluster.

    This approach has two disadvantages:

    1) it was a potentially quadratic algorithm (although highly unlikely that
    it would ever be that bad in practice).
    2) it took place with the control handler's lock held.

    Since we want to make it possible in the future to change control values
    from interrupt context, doing a lot of work while holding a lock is not a
    good idea.

    In the new code the algorithm is no longer quadratic but linear in the
    number of controls in the list. Also, it now can be done beforehand.

    Another change that was made was to so the try and set at the same time.
    Before when S_TRY_EXT_CTRLS was called it would 'try' the controls first,
    and then it would 'set' them. The idea was that any 'try' errors would
    prevent the 'set' from happening, thus avoiding having partially set
    control lists.

    However, this caused more problems than it solved because between the 'try'
    and the 'set' changes might have happened, so it had to try a second time,
    and since actual controls with a try_ctrl op are very rare (and those that
    we have just adjust values and do not return an error), I've decided to
    drop that two-stage approach and just combine try and set.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • The driver had to decide how many events to allocate when the v4l2_fh struct
    was created. It was possible to add more events afterwards, but there was no
    way to ensure that you wouldn't miss important events if the event queue
    would fill up for that filehandle.

    In addition, once there were no more free events, any new events were simply
    dropped on the floor.

    For the control event in particular this made life very difficult since
    control status/value changes could just be missed if the number of allocated
    events and the speed at which the application read events was too low to keep
    up with the number of generated events. The application would have no idea
    what the latest state was for a control since it could have missed the latest
    control change.

    So this patch makes some major changes in how events are allocated. Instead
    of allocating events per-filehandle they are now allocated when subscribing an
    event. So for that particular event type N events (determined by the driver)
    are allocated. Those events are reserved for that particular event type.
    This ensures that you will not miss events for a particular type altogether.

    In addition, if there are N events in use and a new event is raised, then
    the oldest event is dropped and the new one is added. So the latest event
    is always available.

    This can be further improved by adding the ability to merge the state of
    two events together, ensuring that no data is lost at all. This will be
    added in the next patch.

    This also makes it possible to allow the user to determine the number of
    events that will be allocated. This is not implemented at the moment, but
    would be trivial.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • The v4l2_ctrl_fh struct connected v4l2_ctrl with v4l2_fh so the control
    would know which filehandles subscribed to it. However, it is much easier
    to use struct v4l2_subscribed_event directly for that and get rid of that
    intermediate struct.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • Whenever a control changes value or state an event is sent to anyone
    that subscribed to it.

    This functionality is useful for control panels but also for applications
    that need to wait for (usually status) controls to change value.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • When an application changes a control you want to generate an event.
    However, you want to avoid sending such an event back to the application
    (file handle) that caused the change.

    Add the filehandle to the various set control functions.

    The filehandle isn't used yet, but the control event patches will need
    this.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     
  • It is a bit tricky to handle autogain/gain type scenerios correctly. Such
    controls need to be clustered and the V4L2_CTRL_FLAG_UPDATE should be set on
    the autofoo controls. In addition, the manual controls should be marked
    inactive when the automatic mode is on, and active when the manual mode is on.
    This also requires specialized volatile handling.

    The chances of drivers doing all these things correctly are pretty remote.
    So a new v4l2_ctrl_auto_cluster function was added that takes care of these
    issues.

    Signed-off-by: Hans Verkuil
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil
     

19 Jan, 2011

2 commits


30 Dec, 2010

1 commit


09 Aug, 2010

1 commit

  • Add a new framework to handle controls which makes life for driver
    developers much easier.

    Note that this patch moves some of the control support that used to be in
    v4l2-common.c to v4l2-ctrls.c. The tables were copied unchanged. The body
    of v4l2_ctrl_query_fill() was copied to a new v4l2_ctrl_fill() function
    in v4l2-ctrls.c. This new function doesn't use the v4l2_queryctrl
    struct anymore, which makes it more general.

    The remainder of v4l2-ctrls.c is all new. Highlights include:

    - No need to implement VIDIOC_QUERYCTRL, QUERYMENU, S_CTRL, G_CTRL,
    S_EXT_CTRLS, G_EXT_CTRLS or TRY_EXT_CTRLS in either bridge drivers
    or subdevs. New wrapper functions are provided that can just be plugged in.
    Once everything has been converted these wrapper functions can be removed as well.

    - When subdevices are added their controls can be automatically merged
    with the bridge driver's controls.

    - Most drivers just need to implement s_ctrl to set the controls.
    The framework handles the locking and tries to be as 'atomic' as possible.

    - Ready for the subdev device nodes: the same mechanism applies to subdevs
    and their device nodes as well. Sub-device drivers can make controls
    local, preventing them from being merged with bridge drivers.

    - Takes care of backwards compatibility handling of VIDIOC_S_CTRL and
    VIDIOC_G_CTRL. Handling of V4L2_CID_PRIVATE_BASE is fully transparent.
    CTRL_CLASS controls are automatically added.

    Signed-off-by: Hans Verkuil
    Reviewed-by: Laurent Pinchart
    Signed-off-by: Mauro Carvalho Chehab

    Hans Verkuil