Skip to content

Commit

Permalink
staging: bcm2835-codec: Add support for setting S_PARM and G_PARM
Browse files Browse the repository at this point in the history
Video encode can use the frame rate for rate control calculations,
therefore plumb it through from V4L2's [S|G]_PARM ioctl.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
  • Loading branch information
6by9 authored and popcornmix committed Jul 13, 2020
1 parent 17fa469 commit e6c4cec
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ struct bcm2835_codec_ctx {
/* Source and destination queue data */
struct bcm2835_codec_q_data q_data[2];
s32 bitrate;
unsigned int framerate_num;
unsigned int framerate_denom;

bool aborting;
int num_ip_buffers;
Expand Down Expand Up @@ -610,8 +612,8 @@ static void setup_mmal_port_format(struct bcm2835_codec_ctx *ctx,
port->es.video.height = q_data->height;
port->es.video.crop.width = q_data->crop_width;
port->es.video.crop.height = q_data->crop_height;
port->es.video.frame_rate.num = 0;
port->es.video.frame_rate.den = 1;
port->es.video.frame_rate.num = ctx->framerate_num;
port->es.video.frame_rate.den = ctx->framerate_denom;
} else {
/* Compressed format - leave resolution as 0 for decode */
if (ctx->dev->role == DECODE) {
Expand All @@ -625,9 +627,9 @@ static void setup_mmal_port_format(struct bcm2835_codec_ctx *ctx,
port->es.video.crop.width = q_data->crop_width;
port->es.video.crop.height = q_data->crop_height;
port->format.bitrate = ctx->bitrate;
port->es.video.frame_rate.num = ctx->framerate_num;
port->es.video.frame_rate.den = ctx->framerate_denom;
}
port->es.video.frame_rate.num = 0;
port->es.video.frame_rate.den = 1;
}
port->es.video.crop.x = 0;
port->es.video.crop.y = 0;
Expand Down Expand Up @@ -1361,6 +1363,41 @@ static int vidioc_s_selection(struct file *file, void *priv,
return 0;
}

static int vidioc_s_parm(struct file *file, void *priv,
struct v4l2_streamparm *parm)
{
struct bcm2835_codec_ctx *ctx = file2ctx(file);

if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
return -EINVAL;

ctx->framerate_num =
parm->parm.output.timeperframe.denominator;
ctx->framerate_denom =
parm->parm.output.timeperframe.numerator;

parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;

return 0;
}

static int vidioc_g_parm(struct file *file, void *priv,
struct v4l2_streamparm *parm)
{
struct bcm2835_codec_ctx *ctx = file2ctx(file);

if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
return -EINVAL;

parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
parm->parm.output.timeperframe.denominator =
ctx->framerate_num;
parm->parm.output.timeperframe.numerator =
ctx->framerate_denom;

return 0;
}

static int vidioc_subscribe_evt(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub)
{
Expand Down Expand Up @@ -1725,6 +1762,9 @@ static const struct v4l2_ioctl_ops bcm2835_codec_ioctl_ops = {
.vidioc_g_selection = vidioc_g_selection,
.vidioc_s_selection = vidioc_s_selection,

.vidioc_g_parm = vidioc_g_parm,
.vidioc_s_parm = vidioc_s_parm,

.vidioc_subscribe_event = vidioc_subscribe_evt,
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,

Expand Down Expand Up @@ -2546,6 +2586,8 @@ static int bcm2835_codec_create(struct platform_device *pdev,
case DECODE:
v4l2_disable_ioctl(vfd, VIDIOC_ENCODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
video_nr = decode_video_nr;
break;
case ENCODE:
Expand All @@ -2558,6 +2600,8 @@ static int bcm2835_codec_create(struct platform_device *pdev,
v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_DECODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
video_nr = isp_video_nr;
break;
default:
Expand Down

0 comments on commit e6c4cec

Please sign in to comment.