if (entity == NULL)
return NULL;
- for (++end; isspace(*end); ++end);
+ ++end;
} else {
- entity_id = strtoul(p, &end, 10) - 1;
- if (entity_id >= media->entities_count)
+ entity_id = strtoul(p, &end, 10);
+ entity = media_get_entity_by_id(media, entity_id);
+ if (entity == NULL)
return NULL;
-
- entity = &media->entities[entity_id];
}
+ for (; isspace(*end); ++end);
if (*end != ':')
return NULL;
return 0;
}
+static int parse_crop(struct v4l2_rect *crop, const char *p, char **endp)
+{
+ char *end;
+
+ for (; isspace(*p); ++p);
+
+ crop->left = strtoul(p, &end, 10);
+ if (*end != ',')
+ return -EINVAL;
+
+ p = end + 1;
+ crop->top = strtoul(p, &end, 10);
+ if (*end != '/')
+ return -EINVAL;
+
+ p = end + 1;
+ crop->width = strtoul(p, &end, 10);
+ if (*end != 'x')
+ return -EINVAL;
+
+ p = end + 1;
+ crop->height = strtoul(p, &end, 10);
+ *endp = end;
+
+ return 0;
+}
+
+static int parse_frame_interval(struct v4l2_fract *interval, const char *p, char **endp)
+{
+ char *end;
+
+ for (; isspace(*p); ++p);
+
+ interval->numerator = strtoul(p, &end, 10);
+
+ for (p = end; isspace(*p); ++p);
+ if (*p++ != '/')
+ return -EINVAL;
+
+ for (; isspace(*p); ++p);
+ interval->denominator = strtoul(p, &end, 10);
+
+ *endp = end;
+ return 0;
+}
+
static struct media_entity_pad *parse_pad_format(struct media_device *media,
- struct v4l2_mbus_framefmt *format, const char *p, char **endp)
+ struct v4l2_mbus_framefmt *format, struct v4l2_rect *crop,
+ struct v4l2_fract *interval, const char *p, char **endp)
{
struct media_entity_pad *pad;
char *end;
return NULL;
for (p = end; isspace(*p); p++);
- if (*p++ != ']')
+ if (isdigit(*p)) {
+ ret = parse_crop(crop, p, &end);
+ if (ret < 0)
+ return NULL;
+
+ for (p = end; isspace(*p); p++);
+ }
+
+ if (*p == '@') {
+ ret = parse_frame_interval(interval, ++p, &end);
+ if (ret < 0)
+ return NULL;
+
+ for (p = end; isspace(*p); p++);
+ }
+
+ if (*p != ']')
return NULL;
- *endp = (char *)p;
+ *endp = (char *)p + 1;
return pad;
}
return 0;
}
+static int set_crop(struct media_entity_pad *pad, struct v4l2_rect *crop)
+{
+ int ret;
+
+ if (crop->left == -1 || crop->top == -1)
+ return 0;
+
+ printf("Setting up crop rectangle %u,%u/%ux%u on pad %s/%u\n",
+ crop->left, crop->top, crop->width, crop->height,
+ pad->entity->info.name, pad->index);
+
+ ret = v4l2_subdev_set_crop(pad->entity, crop, pad->index,
+ V4L2_SUBDEV_FORMAT_ACTIVE);
+ if (ret < 0) {
+ printf("Unable to set crop rectangle: %s (%d)", strerror(-ret), ret);
+ return ret;
+ }
+
+ printf("Crop rectangle set: %u,%u/%ux%u\n",
+ crop->left, crop->top, crop->width, crop->height);
+
+ return 0;
+}
+
+static int set_frame_interval(struct media_entity *entity, struct v4l2_fract *interval)
+{
+ int ret;
+
+ printf("Setting up frame interval %u/%u on entity %s\n",
+ interval->numerator, interval->denominator, entity->info.name);
+
+ ret = v4l2_subdev_set_frame_interval(entity, interval);
+ if (ret < 0) {
+ printf("Unable to set frame interval: %s (%d)", strerror(-ret), ret);
+ return ret;
+ }
+
+ printf("Frame interval set: %u/%u\n",
+ interval->numerator, interval->denominator);
+
+ return 0;
+}
+
+
static int setup_format(struct media_device *media, const char *p, char **endp)
{
struct v4l2_mbus_framefmt format;
struct media_entity_pad *pad;
+ struct v4l2_rect crop = { -1, -1, -1, -1 };
+ struct v4l2_fract interval = { 0, 0 };
unsigned int i;
char *end;
int ret;
- pad = parse_pad_format(media, &format, p, &end);
+ pad = parse_pad_format(media, &format, &crop, &interval, p, &end);
if (pad == NULL) {
printf("Unable to parse format\n");
return -EINVAL;
}
+ if (pad->type == MEDIA_PAD_TYPE_OUTPUT) {
+ ret = set_crop(pad, &crop);
+ if (ret < 0)
+ return ret;
+ }
+
ret = set_format(pad, &format);
if (ret < 0)
return ret;
+ if (pad->type == MEDIA_PAD_TYPE_INPUT) {
+ ret = set_crop(pad, &crop);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (interval.numerator != 0) {
+ ret = set_frame_interval(pad->entity, &interval);
+ if (ret < 0) {
+ printf("Unable to set frame interval\n");
+ return ret;
+ }
+ }
+
/* If the pad is an output pad, automatically set the same format on
* the remote subdev input pads, if any.
*/
do {
ret = setup_format(media, p, &end);
- if (ret < 0) {
- printf("Unable to parse format\n");
+ if (ret < 0)
return ret;
- }
p = end + 1;
} while (*end == ',');