[media] v4l2-ctrls: implement new volatile autocluster scheme
[pandora-kernel.git] / drivers / media / video / v4l2-ctrls.c
index 37c0648..fc8666a 100644 (file)
@@ -43,7 +43,7 @@ struct v4l2_ctrl_helper {
 };
 
 /* Small helper function to determine if the autocluster is set to manual
-   mode. In that case the is_volatile flag should be ignored. */
+   mode. */
 static bool is_cur_manual(const struct v4l2_ctrl *master)
 {
        return master->is_auto && master->cur.val == master->manual_mode_value;
@@ -203,7 +203,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
        };
        static const char * const mpeg_stream_vbi_fmt[] = {
                "No VBI",
-               "Private packet, IVTV format",
+               "Private Packet, IVTV Format",
                NULL
        };
        static const char * const camera_power_line_frequency[] = {
@@ -226,18 +226,119 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
                "Negative",
                "Emboss",
                "Sketch",
-               "Sky blue",
-               "Grass green",
-               "Skin whiten",
+               "Sky Blue",
+               "Grass Green",
+               "Skin Whiten",
                "Vivid",
                NULL
        };
        static const char * const tune_preemphasis[] = {
-               "No preemphasis",
+               "No Preemphasis",
                "50 useconds",
                "75 useconds",
                NULL,
        };
+       static const char * const header_mode[] = {
+               "Separate Buffer",
+               "Joined With 1st Frame",
+               NULL,
+       };
+       static const char * const multi_slice[] = {
+               "Single",
+               "Max Macroblocks",
+               "Max Bytes",
+               NULL,
+       };
+       static const char * const entropy_mode[] = {
+               "CAVLC",
+               "CABAC",
+               NULL,
+       };
+       static const char * const mpeg_h264_level[] = {
+               "1",
+               "1b",
+               "1.1",
+               "1.2",
+               "1.3",
+               "2",
+               "2.1",
+               "2.2",
+               "3",
+               "3.1",
+               "3.2",
+               "4",
+               "4.1",
+               "4.2",
+               "5",
+               "5.1",
+               NULL,
+       };
+       static const char * const h264_loop_filter[] = {
+               "Enabled",
+               "Disabled",
+               "Disabled at Slice Boundary",
+               NULL,
+       };
+       static const char * const h264_profile[] = {
+               "Baseline",
+               "Constrained Baseline",
+               "Main",
+               "Extended",
+               "High",
+               "High 10",
+               "High 422",
+               "High 444 Predictive",
+               "High 10 Intra",
+               "High 422 Intra",
+               "High 444 Intra",
+               "CAVLC 444 Intra",
+               "Scalable Baseline",
+               "Scalable High",
+               "Scalable High Intra",
+               "Multiview High",
+               NULL,
+       };
+       static const char * const vui_sar_idc[] = {
+               "Unspecified",
+               "1:1",
+               "12:11",
+               "10:11",
+               "16:11",
+               "40:33",
+               "24:11",
+               "20:11",
+               "32:11",
+               "80:33",
+               "18:11",
+               "15:11",
+               "64:33",
+               "160:99",
+               "4:3",
+               "3:2",
+               "2:1",
+               "Extended SAR",
+               NULL,
+       };
+       static const char * const mpeg_mpeg4_level[] = {
+               "0",
+               "0b",
+               "1",
+               "2",
+               "3",
+               "3b",
+               "4",
+               "5",
+               NULL,
+       };
+       static const char * const mpeg4_profile[] = {
+               "Simple",
+               "Adcanved Simple",
+               "Core",
+               "Simple Scalable",
+               "Advanced Coding Efficency",
+               NULL,
+       };
+
        static const char * const flash_led_mode[] = {
                "Off",
                "Flash",
@@ -293,6 +394,24 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
                return flash_led_mode;
        case V4L2_CID_FLASH_STROBE_SOURCE:
                return flash_strobe_source;
+       case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
+               return header_mode;
+       case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
+               return multi_slice;
+       case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
+               return entropy_mode;
+       case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
+               return mpeg_h264_level;
+       case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
+               return h264_loop_filter;
+       case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
+               return h264_profile;
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
+               return vui_sar_idc;
+       case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
+               return mpeg_mpeg4_level;
+       case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
+               return mpeg4_profile;
        default:
                return NULL;
        }
@@ -344,6 +463,8 @@ const char *v4l2_ctrl_get_name(u32 id)
        case V4L2_CID_CHROMA_GAIN:              return "Chroma Gain";
        case V4L2_CID_ILLUMINATORS_1:           return "Illuminator 1";
        case V4L2_CID_ILLUMINATORS_2:           return "Illuminator 2";
+       case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:  return "Minimum Number of Capture Buffers";
+       case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:   return "Minimum Number of Output Buffers";
 
        /* MPEG controls */
        /* Keep the order of the 'case's the same as in videodev2.h! */
@@ -380,6 +501,48 @@ const char *v4l2_ctrl_get_name(u32 id)
        case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
        case V4L2_CID_MPEG_VIDEO_MUTE:          return "Video Mute";
        case V4L2_CID_MPEG_VIDEO_MUTE_YUV:      return "Video Mute YUV";
+       case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:       return "Decoder Slice Interface";
+       case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:  return "MPEG4 Loop Filter Enable";
+       case V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB:       return "The Number of Intra Refresh MBs";
+       case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:               return "Frame Level Rate Control Enable";
+       case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:                  return "H264 MB Level Rate Control";
+       case V4L2_CID_MPEG_VIDEO_HEADER_MODE:                   return "Sequence Header Mode";
+       case V4L2_CID_MPEG_VIDEO_MAX_REF_PIC:                   return "The Max Number of Reference Picture";
+       case V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP:               return "H263 I-Frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP:               return "H263 P frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP:               return "H263 B frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H263_MIN_QP:                   return "H263 Minimum QP Value";
+       case V4L2_CID_MPEG_VIDEO_H263_MAX_QP:                   return "H263 Maximum QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP:               return "H264 I-Frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP:               return "H264 P frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP:               return "H264 B frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_MAX_QP:                   return "H264 Maximum QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_MIN_QP:                   return "H264 Minimum QP Value";
+       case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:            return "H264 8x8 Transform Enable";
+       case V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE:                 return "H264 CPB Buffer Size";
+       case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:             return "H264 Entorpy Mode";
+       case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:                 return "H264 I Period";
+       case V4L2_CID_MPEG_VIDEO_H264_LEVEL:                    return "H264 Level";
+       case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA:        return "H264 Loop Filter Alpha Offset";
+       case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA:         return "H264 Loop Filter Beta Offset";
+       case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:         return "H264 Loop Filter Mode";
+       case V4L2_CID_MPEG_VIDEO_H264_PROFILE:                  return "H264 Profile";
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT:       return "Vertical Size of SAR";
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH:        return "Horizontal Size of SAR";
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:           return "Aspect Ratio VUI Enable";
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:              return "VUI Aspect Ratio IDC";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP:              return "MPEG4 I-Frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP:              return "MPEG4 P frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP:              return "MPEG4 B frame QP Value";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP:                  return "MPEG4 Minimum QP Value";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP:                  return "MPEG4 Maximum QP Value";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:                   return "MPEG4 Level";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:                 return "MPEG4 Profile";
+       case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:                    return "Quarter Pixel Search Enable";
+       case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES:         return "The Maximum Bytes Per Slice";
+       case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB:            return "The Number of MB in a Slice";
+       case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:              return "The Slice Partitioning Method";
+       case V4L2_CID_MPEG_VIDEO_VBV_SIZE:                      return "VBV Buffer Size";
 
        /* CAMERA controls */
        /* Keep the order of the 'case's the same as in videodev2.h! */
@@ -478,6 +641,13 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
        case V4L2_CID_FLASH_STROBE_STATUS:
        case V4L2_CID_FLASH_CHARGE:
        case V4L2_CID_FLASH_READY:
+       case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER:
+       case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE:
+       case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
+       case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
+       case V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM:
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE:
+       case V4L2_CID_MPEG_VIDEO_MPEG4_QPEL:
                *type = V4L2_CTRL_TYPE_BOOLEAN;
                *min = 0;
                *max = *step = 1;
@@ -511,6 +681,15 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
        case V4L2_CID_TUNE_PREEMPHASIS:
        case V4L2_CID_FLASH_LED_MODE:
        case V4L2_CID_FLASH_STROBE_SOURCE:
+       case V4L2_CID_MPEG_VIDEO_HEADER_MODE:
+       case V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE:
+       case V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE:
+       case V4L2_CID_MPEG_VIDEO_H264_LEVEL:
+       case V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE:
+       case V4L2_CID_MPEG_VIDEO_H264_PROFILE:
+       case V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC:
+       case V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL:
+       case V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE:
                *type = V4L2_CTRL_TYPE_MENU;
                break;
        case V4L2_CID_RDS_TX_PS_NAME:
@@ -537,6 +716,11 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
        case V4L2_CID_FLASH_FAULT:
                *type = V4L2_CTRL_TYPE_BITMASK;
                break;
+       case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
+       case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
+               *type = V4L2_CTRL_TYPE_INTEGER;
+               *flags |= V4L2_CTRL_FLAG_READ_ONLY;
+               break;
        default:
                *type = V4L2_CTRL_TYPE_INTEGER;
                break;
@@ -753,9 +937,14 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
                break;
        }
        if (update_inactive) {
-               ctrl->flags &= ~V4L2_CTRL_FLAG_INACTIVE;
-               if (!is_cur_manual(ctrl->cluster[0]))
+               /* Note: update_inactive can only be true for auto clusters. */
+               ctrl->flags &=
+                       ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE);
+               if (!is_cur_manual(ctrl->cluster[0])) {
                        ctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
+                       if (ctrl->cluster[0]->has_volatiles)
+                               ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
+               }
        }
        if (changed || update_inactive) {
                /* If a control was changed that was not one of the controls
@@ -1210,10 +1399,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
                        type, min, max,
                        is_menu ? cfg->menu_skip_mask : step,
                        def, flags, qmenu, priv);
-       if (ctrl) {
+       if (ctrl)
                ctrl->is_private = cfg->is_private;
-               ctrl->is_volatile = cfg->is_volatile;
-       }
        return ctrl;
 }
 EXPORT_SYMBOL(v4l2_ctrl_new_custom);
@@ -1307,6 +1494,7 @@ EXPORT_SYMBOL(v4l2_ctrl_add_handler);
 /* Cluster controls */
 void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
 {
+       bool has_volatiles = false;
        int i;
 
        /* The first control is the master control and it must not be NULL */
@@ -1316,8 +1504,11 @@ void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls)
                if (controls[i]) {
                        controls[i]->cluster = controls;
                        controls[i]->ncontrols = ncontrols;
+                       if (controls[i]->flags & V4L2_CTRL_FLAG_VOLATILE)
+                               has_volatiles = true;
                }
        }
+       controls[0]->has_volatiles = has_volatiles;
 }
 EXPORT_SYMBOL(v4l2_ctrl_cluster);
 
@@ -1325,22 +1516,25 @@ void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
                            u8 manual_val, bool set_volatile)
 {
        struct v4l2_ctrl *master = controls[0];
-       u32 flag;
+       u32 flag = 0;
        int i;
 
        v4l2_ctrl_cluster(ncontrols, controls);
        WARN_ON(ncontrols <= 1);
        WARN_ON(manual_val < master->minimum || manual_val > master->maximum);
+       WARN_ON(set_volatile && !has_op(master, g_volatile_ctrl));
        master->is_auto = true;
+       master->has_volatiles = set_volatile;
        master->manual_mode_value = manual_val;
        master->flags |= V4L2_CTRL_FLAG_UPDATE;
-       flag = is_cur_manual(master) ? 0 : V4L2_CTRL_FLAG_INACTIVE;
+
+       if (!is_cur_manual(master))
+               flag = V4L2_CTRL_FLAG_INACTIVE |
+                       (set_volatile ? V4L2_CTRL_FLAG_VOLATILE : 0);
 
        for (i = 1; i < ncontrols; i++)
-               if (controls[i]) {
-                       controls[i]->is_volatile = set_volatile;
+               if (controls[i])
                        controls[i]->flags |= flag;
-               }
 }
 EXPORT_SYMBOL(v4l2_ctrl_auto_cluster);
 
@@ -1395,9 +1589,6 @@ EXPORT_SYMBOL(v4l2_ctrl_grab);
 static void log_ctrl(const struct v4l2_ctrl *ctrl,
                     const char *prefix, const char *colon)
 {
-       int fl_inact = ctrl->flags & V4L2_CTRL_FLAG_INACTIVE;
-       int fl_grabbed = ctrl->flags & V4L2_CTRL_FLAG_GRABBED;
-
        if (ctrl->flags & (V4L2_CTRL_FLAG_DISABLED | V4L2_CTRL_FLAG_WRITE_ONLY))
                return;
        if (ctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS)
@@ -1428,14 +1619,17 @@ static void log_ctrl(const struct v4l2_ctrl *ctrl,
                printk(KERN_CONT "unknown type %d", ctrl->type);
                break;
        }
-       if (fl_inact && fl_grabbed)
-               printk(KERN_CONT " (inactive, grabbed)\n");
-       else if (fl_inact)
-               printk(KERN_CONT " (inactive)\n");
-       else if (fl_grabbed)
-               printk(KERN_CONT " (grabbed)\n");
-       else
-               printk(KERN_CONT "\n");
+       if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
+                          V4L2_CTRL_FLAG_GRABBED |
+                          V4L2_CTRL_FLAG_VOLATILE)) {
+               if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
+                       printk(KERN_CONT " inactive");
+               if (ctrl->flags & V4L2_CTRL_FLAG_GRABBED)
+                       printk(KERN_CONT " grabbed");
+               if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE)
+                       printk(KERN_CONT " volatile");
+       }
+       printk(KERN_CONT "\n");
 }
 
 /* Log all controls owned by the handler */
@@ -1775,7 +1969,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
                v4l2_ctrl_lock(master);
 
                /* g_volatile_ctrl will update the new control values */
-               if (has_op(master, g_volatile_ctrl) && !is_cur_manual(master)) {
+               if ((master->flags & V4L2_CTRL_FLAG_VOLATILE) ||
+                       (master->has_volatiles && !is_cur_manual(master))) {
                        for (j = 0; j < master->ncontrols; j++)
                                cur_to_new(master->cluster[j]);
                        ret = call_op(master, g_volatile_ctrl);
@@ -1820,7 +2015,7 @@ static int get_ctrl(struct v4l2_ctrl *ctrl, s32 *val)
 
        v4l2_ctrl_lock(master);
        /* g_volatile_ctrl will update the current control values */
-       if (ctrl->is_volatile && !is_cur_manual(master)) {
+       if (ctrl->flags & V4L2_CTRL_FLAG_VOLATILE) {
                for (i = 0; i < master->ncontrols; i++)
                        cur_to_new(master->cluster[i]);
                ret = call_op(master, g_volatile_ctrl);
@@ -1936,6 +2131,20 @@ static int validate_ctrls(struct v4l2_ext_controls *cs,
        return 0;
 }
 
+/* Obtain the current volatile values of an autocluster and mark them
+   as new. */
+static void update_from_auto_cluster(struct v4l2_ctrl *master)
+{
+       int i;
+
+       for (i = 0; i < master->ncontrols; i++)
+               cur_to_new(master->cluster[i]);
+       if (!call_op(master, g_volatile_ctrl))
+               for (i = 1; i < master->ncontrols; i++)
+                       if (master->cluster[i])
+                               master->cluster[i]->is_new = 1;
+}
+
 /* Try or try-and-set controls */
 static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
                             struct v4l2_ext_controls *cs,
@@ -1981,6 +2190,31 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
                        if (master->cluster[j])
                                master->cluster[j]->is_new = 0;
 
+               /* For volatile autoclusters that are currently in auto mode
+                  we need to discover if it will be set to manual mode.
+                  If so, then we have to copy the current volatile values
+                  first since those will become the new manual values (which
+                  may be overwritten by explicit new values from this set
+                  of controls). */
+               if (master->is_auto && master->has_volatiles &&
+                                               !is_cur_manual(master)) {
+                       /* Pick an initial non-manual value */
+                       s32 new_auto_val = master->manual_mode_value + 1;
+                       u32 tmp_idx = idx;
+
+                       do {
+                               /* Check if the auto control is part of the
+                                  list, and remember the new value. */
+                               if (helpers[tmp_idx].ctrl == master)
+                                       new_auto_val = cs->controls[tmp_idx].value;
+                               tmp_idx = helpers[tmp_idx].next;
+                       } while (tmp_idx);
+                       /* If the new value == the manual value, then copy
+                          the current volatile values. */
+                       if (new_auto_val == master->manual_mode_value)
+                               update_from_auto_cluster(master);
+               }
+
                /* Copy the new caller-supplied control values.
                   user_to_new() sets 'is_new' to 1. */
                do {
@@ -2051,6 +2285,12 @@ static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, s32 *val)
                if (master->cluster[i])
                        master->cluster[i]->is_new = 0;
 
+       /* For autoclusters with volatiles that are switched from auto to
+          manual mode we have to update the current volatile values since
+          those will become the initial manual values after such a switch. */
+       if (master->is_auto && master->has_volatiles && ctrl == master &&
+           !is_cur_manual(master) && *val == master->manual_mode_value)
+               update_from_auto_cluster(master);
        ctrl->val = *val;
        ctrl->is_new = 1;
        ret = try_or_set_cluster(fh, master, true);