Skip to content

Commit 6b45624

Browse files
pinchartlHans Verkuil
authored andcommitted
media: v4l2-subdev: Store frame interval in subdev state
Subdev states store all standard pad configuration data, except for frame intervals. Fix it by adding interval fields in the v4l2_subdev_pad_config and v4l2_subdev_stream_config structures, with corresponding accessor functions and a helper function to implement the .get_frame_interval() operation. Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 805d431 commit 6b45624

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

drivers/media/v4l2-core/v4l2-subdev.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,42 @@ __v4l2_subdev_state_get_compose(struct v4l2_subdev_state *state,
16521652
}
16531653
EXPORT_SYMBOL_GPL(__v4l2_subdev_state_get_compose);
16541654

1655+
struct v4l2_fract *
1656+
__v4l2_subdev_state_get_interval(struct v4l2_subdev_state *state,
1657+
unsigned int pad, u32 stream)
1658+
{
1659+
struct v4l2_subdev_stream_configs *stream_configs;
1660+
unsigned int i;
1661+
1662+
if (WARN_ON(!state))
1663+
return NULL;
1664+
1665+
lockdep_assert_held(state->lock);
1666+
1667+
if (state->pads) {
1668+
if (stream)
1669+
return NULL;
1670+
1671+
if (pad >= state->sd->entity.num_pads)
1672+
return NULL;
1673+
1674+
return &state->pads[pad].interval;
1675+
}
1676+
1677+
lockdep_assert_held(state->lock);
1678+
1679+
stream_configs = &state->stream_configs;
1680+
1681+
for (i = 0; i < stream_configs->num_configs; ++i) {
1682+
if (stream_configs->configs[i].pad == pad &&
1683+
stream_configs->configs[i].stream == stream)
1684+
return &stream_configs->configs[i].interval;
1685+
}
1686+
1687+
return NULL;
1688+
}
1689+
EXPORT_SYMBOL_GPL(__v4l2_subdev_state_get_interval);
1690+
16551691
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
16561692

16571693
static int
@@ -1718,6 +1754,22 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
17181754
}
17191755
EXPORT_SYMBOL_GPL(v4l2_subdev_get_fmt);
17201756

1757+
int v4l2_subdev_get_frame_interval(struct v4l2_subdev *sd,
1758+
struct v4l2_subdev_state *state,
1759+
struct v4l2_subdev_frame_interval *fi)
1760+
{
1761+
struct v4l2_fract *interval;
1762+
1763+
interval = v4l2_subdev_state_get_interval(state, fi->pad, fi->stream);
1764+
if (!interval)
1765+
return -EINVAL;
1766+
1767+
fi->interval = *interval;
1768+
1769+
return 0;
1770+
}
1771+
EXPORT_SYMBOL_GPL(v4l2_subdev_get_frame_interval);
1772+
17211773
int v4l2_subdev_set_routing(struct v4l2_subdev *sd,
17221774
struct v4l2_subdev_state *state,
17231775
const struct v4l2_subdev_krouting *routing)

include/media/v4l2-subdev.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,13 @@ struct v4l2_subdev_ir_ops {
681681
* @format: &struct v4l2_mbus_framefmt
682682
* @crop: &struct v4l2_rect to be used for crop
683683
* @compose: &struct v4l2_rect to be used for compose
684+
* @interval: frame interval
684685
*/
685686
struct v4l2_subdev_pad_config {
686687
struct v4l2_mbus_framefmt format;
687688
struct v4l2_rect crop;
688689
struct v4l2_rect compose;
690+
struct v4l2_fract interval;
689691
};
690692

691693
/**
@@ -697,6 +699,7 @@ struct v4l2_subdev_pad_config {
697699
* @fmt: &struct v4l2_mbus_framefmt
698700
* @crop: &struct v4l2_rect to be used for crop
699701
* @compose: &struct v4l2_rect to be used for compose
702+
* @interval: frame interval
700703
*
701704
* This structure stores configuration for a stream.
702705
*/
@@ -708,6 +711,7 @@ struct v4l2_subdev_stream_config {
708711
struct v4l2_mbus_framefmt fmt;
709712
struct v4l2_rect crop;
710713
struct v4l2_rect compose;
714+
struct v4l2_fract interval;
711715
};
712716

713717
/**
@@ -1392,6 +1396,27 @@ struct v4l2_rect *
13921396
__v4l2_subdev_state_get_compose(struct v4l2_subdev_state *state,
13931397
unsigned int pad, u32 stream);
13941398

1399+
/**
1400+
* v4l2_subdev_state_get_interval() - Get pointer to a stream frame interval
1401+
* @state: subdevice state
1402+
* @pad: pad id
1403+
* @...: stream id (optional argument)
1404+
*
1405+
* This returns a pointer to the frame interval for the given pad + stream in
1406+
* the subdev state.
1407+
*
1408+
* For stream-unaware drivers the frame interval for the corresponding pad is
1409+
* returned. If the pad does not exist, NULL is returned.
1410+
*/
1411+
#define v4l2_subdev_state_get_interval(state, pad, ...) \
1412+
__v4l2_subdev_state_gen_call(interval, ##__VA_ARGS__, , _pad) \
1413+
(state, pad, ##__VA_ARGS__)
1414+
#define __v4l2_subdev_state_get_interval_pad(state, pad) \
1415+
__v4l2_subdev_state_get_interval(state, pad, 0)
1416+
struct v4l2_fract *
1417+
__v4l2_subdev_state_get_interval(struct v4l2_subdev_state *state,
1418+
unsigned int pad, u32 stream);
1419+
13951420
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
13961421

13971422
/**
@@ -1411,6 +1436,24 @@ __v4l2_subdev_state_get_compose(struct v4l2_subdev_state *state,
14111436
int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state,
14121437
struct v4l2_subdev_format *format);
14131438

1439+
/**
1440+
* v4l2_subdev_get_frame_interval() - Fill frame interval based on state
1441+
* @sd: subdevice
1442+
* @state: subdevice state
1443+
* @fi: pointer to &struct v4l2_subdev_frame_interval
1444+
*
1445+
* Fill @fi->interval field based on the information in the @fi struct.
1446+
*
1447+
* This function can be used by the subdev drivers which support active state to
1448+
* implement v4l2_subdev_pad_ops.get_frame_interval if the subdev driver does
1449+
* not need to do anything special in their get_frame_interval op.
1450+
*
1451+
* Returns 0 on success, error value otherwise.
1452+
*/
1453+
int v4l2_subdev_get_frame_interval(struct v4l2_subdev *sd,
1454+
struct v4l2_subdev_state *state,
1455+
struct v4l2_subdev_frame_interval *fi);
1456+
14141457
/**
14151458
* v4l2_subdev_set_routing() - Set given routing to subdev state
14161459
* @sd: The subdevice

0 commit comments

Comments
 (0)