staging/bcm2835-codec: Allow a different stride alignment per role
authorDave Stevenson <dave.stevenson@raspberrypi.com>
Mon, 29 Nov 2021 19:11:29 +0000 (19:11 +0000)
committerPhil Elwell <8911409+pelwell@users.noreply.github.com>
Mon, 29 Nov 2021 20:14:30 +0000 (20:14 +0000)
Deinterlace and decode aren't affected in the same way as encode
and ISP by the alignment requirement on 3 plane YUV420.
Decode would be affected, but it always aligns the height up to
a macroblock, and uses the selection API to reflect that.

Add in the facility to set the bytesperline alignment per role.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c

index 641ee20..4cd9402 100644 (file)
@@ -88,6 +88,7 @@ enum bcm2835_codec_role {
        ENCODE,
        ISP,
        DEINTERLACE,
+       NUM_ROLES
 };
 
 static const char * const roles[] = {
@@ -145,7 +146,7 @@ static const char * const components[] = {
 struct bcm2835_codec_fmt {
        u32     fourcc;
        int     depth;
-       int     bytesperline_align;
+       u8      bytesperline_align[NUM_ROLES];
        u32     flags;
        u32     mmal_fmt;
        int     size_multiplier_x2;
@@ -157,63 +158,63 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* YUV formats */
                .fourcc                 = V4L2_PIX_FMT_YUV420,
                .depth                  = 8,
-               .bytesperline_align     = 64,
+               .bytesperline_align     = { 32, 64, 64, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_I420,
                .size_multiplier_x2     = 3,
        }, {
                .fourcc                 = V4L2_PIX_FMT_YVU420,
                .depth                  = 8,
-               .bytesperline_align     = 64,
+               .bytesperline_align     = { 32, 64, 64, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_YV12,
                .size_multiplier_x2     = 3,
        }, {
                .fourcc                 = V4L2_PIX_FMT_NV12,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_NV12,
                .size_multiplier_x2     = 3,
        }, {
                .fourcc                 = V4L2_PIX_FMT_NV21,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_NV21,
                .size_multiplier_x2     = 3,
        }, {
                .fourcc                 = V4L2_PIX_FMT_RGB565,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_RGB16,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_YUYV,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_YUYV,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_UYVY,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_UYVY,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_YVYU,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_YVYU,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_VYUY,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_VYUY,
                .size_multiplier_x2     = 2,
@@ -221,21 +222,21 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* RGB formats */
                .fourcc                 = V4L2_PIX_FMT_RGB24,
                .depth                  = 24,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_RGB24,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_BGR24,
                .depth                  = 24,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BGR24,
                .size_multiplier_x2     = 2,
        }, {
                .fourcc                 = V4L2_PIX_FMT_BGR32,
                .depth                  = 32,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BGRA,
                .size_multiplier_x2     = 2,
@@ -244,7 +245,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 8 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB8,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB8,
                .size_multiplier_x2     = 2,
@@ -252,7 +253,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR8,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR8,
                .size_multiplier_x2     = 2,
@@ -260,7 +261,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG8,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG8,
                .size_multiplier_x2     = 2,
@@ -268,7 +269,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG8,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG8,
                .size_multiplier_x2     = 2,
@@ -277,7 +278,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 10 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB10P,
                .depth                  = 10,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB10P,
                .size_multiplier_x2     = 2,
@@ -285,7 +286,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR10P,
                .depth                  = 10,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR10P,
                .size_multiplier_x2     = 2,
@@ -293,7 +294,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG10P,
                .depth                  = 10,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG10P,
                .size_multiplier_x2     = 2,
@@ -301,7 +302,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG10P,
                .depth                  = 10,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG10P,
                .size_multiplier_x2     = 2,
@@ -310,7 +311,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 12 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB12P,
                .depth                  = 12,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB12P,
                .size_multiplier_x2     = 2,
@@ -318,7 +319,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR12P,
                .depth                  = 12,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR12P,
                .size_multiplier_x2     = 2,
@@ -326,7 +327,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG12P,
                .depth                  = 12,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG12P,
                .size_multiplier_x2     = 2,
@@ -334,7 +335,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG12P,
                .depth                  = 12,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG12P,
                .size_multiplier_x2     = 2,
@@ -343,7 +344,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 14 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB14P,
                .depth                  = 14,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB14P,
                .size_multiplier_x2     = 2,
@@ -351,7 +352,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR14P,
                .depth                  = 14,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR14P,
                .size_multiplier_x2     = 2,
@@ -360,7 +361,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG14P,
                .depth                  = 14,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG14P,
                .size_multiplier_x2     = 2,
@@ -368,7 +369,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG14P,
                .depth                  = 14,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG14P,
                .size_multiplier_x2     = 2,
@@ -377,7 +378,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 16 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB16,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB16,
                .size_multiplier_x2     = 2,
@@ -385,7 +386,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR16,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR16,
                .size_multiplier_x2     = 2,
@@ -393,7 +394,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG16,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG16,
                .size_multiplier_x2     = 2,
@@ -401,7 +402,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG16,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG16,
                .size_multiplier_x2     = 2,
@@ -411,7 +412,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 10 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB10,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB10,
                .size_multiplier_x2     = 2,
@@ -419,7 +420,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR10,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR10,
                .size_multiplier_x2     = 2,
@@ -427,7 +428,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG10,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG10,
                .size_multiplier_x2     = 2,
@@ -435,7 +436,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG10,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG10,
                .size_multiplier_x2     = 2,
@@ -444,7 +445,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 12 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB12,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB12,
                .size_multiplier_x2     = 2,
@@ -452,7 +453,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR12,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR12,
                .size_multiplier_x2     = 2,
@@ -460,7 +461,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG12,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG12,
                .size_multiplier_x2     = 2,
@@ -468,7 +469,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG12,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG12,
                .size_multiplier_x2     = 2,
@@ -477,7 +478,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 14 bit */
                .fourcc                 = V4L2_PIX_FMT_SRGGB14,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SRGGB14,
                .size_multiplier_x2     = 2,
@@ -485,7 +486,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SBGGR14,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SBGGR14,
                .size_multiplier_x2     = 2,
@@ -493,7 +494,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGRBG14,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGRBG14,
                .size_multiplier_x2     = 2,
@@ -501,7 +502,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
        }, {
                .fourcc                 = V4L2_PIX_FMT_SGBRG14,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_BAYER_SGBRG14,
                .size_multiplier_x2     = 2,
@@ -511,7 +512,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 8 bit */
                .fourcc                 = V4L2_PIX_FMT_GREY,
                .depth                  = 8,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_GREY,
                .size_multiplier_x2     = 2,
@@ -519,7 +520,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 10 bit */
                .fourcc                 = V4L2_PIX_FMT_Y10P,
                .depth                  = 10,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y10P,
                .size_multiplier_x2     = 2,
@@ -527,7 +528,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 12 bit */
                .fourcc                 = V4L2_PIX_FMT_Y12P,
                .depth                  = 12,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y12P,
                .size_multiplier_x2     = 2,
@@ -535,7 +536,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 14 bit */
                .fourcc                 = V4L2_PIX_FMT_Y14P,
                .depth                  = 14,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y14P,
                .size_multiplier_x2     = 2,
@@ -543,7 +544,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 16 bit */
                .fourcc                 = V4L2_PIX_FMT_Y16,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y16,
                .size_multiplier_x2     = 2,
@@ -551,7 +552,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 10 bit as 16bpp */
                .fourcc                 = V4L2_PIX_FMT_Y10,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y10,
                .size_multiplier_x2     = 2,
@@ -559,7 +560,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 12 bit as 16bpp */
                .fourcc                 = V4L2_PIX_FMT_Y12,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y12,
                .size_multiplier_x2     = 2,
@@ -567,7 +568,7 @@ static const struct bcm2835_codec_fmt supported_formats[] = {
                /* 14 bit as 16bpp */
                .fourcc                 = V4L2_PIX_FMT_Y14,
                .depth                  = 16,
-               .bytesperline_align     = 32,
+               .bytesperline_align     = { 32, 32, 32, 32 },
                .flags                  = 0,
                .mmal_fmt               = MMAL_ENCODING_Y14,
                .size_multiplier_x2     = 2,
@@ -840,9 +841,10 @@ static inline unsigned int get_sizeimage(int bpl, int width, int height,
 }
 
 static inline unsigned int get_bytesperline(int width,
-                                           struct bcm2835_codec_fmt *fmt)
+                                           struct bcm2835_codec_fmt *fmt,
+                                           enum bcm2835_codec_role role)
 {
-       return ALIGN((width * fmt->depth) >> 3, fmt->bytesperline_align);
+       return ALIGN((width * fmt->depth) >> 3, fmt->bytesperline_align[role]);
 }
 
 static void setup_mmal_port_format(struct bcm2835_codec_ctx *ctx,
@@ -1040,7 +1042,7 @@ static void handle_fmt_changed(struct bcm2835_codec_ctx *ctx,
         */
        q_data->selection_set = true;
        q_data->bytesperline = get_bytesperline(format->es.video.width,
-                                               q_data->fmt);
+                                               q_data->fmt, ctx->dev->role);
 
        q_data->height = format->es.video.height;
        q_data->sizeimage = format->buffer_size_min;
@@ -1422,11 +1424,13 @@ static int vidioc_try_fmt(struct bcm2835_codec_ctx *ctx, struct v4l2_format *f,
                        f->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, 16);
        }
        f->fmt.pix_mp.num_planes = 1;
-       min_bytesperline = get_bytesperline(f->fmt.pix_mp.width, fmt);
+       min_bytesperline = get_bytesperline(f->fmt.pix_mp.width, fmt,
+                                           ctx->dev->role);
        if (f->fmt.pix_mp.plane_fmt[0].bytesperline < min_bytesperline)
                f->fmt.pix_mp.plane_fmt[0].bytesperline = min_bytesperline;
        f->fmt.pix_mp.plane_fmt[0].bytesperline =
-               ALIGN(f->fmt.pix_mp.plane_fmt[0].bytesperline, fmt->bytesperline_align);
+               ALIGN(f->fmt.pix_mp.plane_fmt[0].bytesperline,
+                     fmt->bytesperline_align[ctx->dev->role]);
 
        sizeimage = get_sizeimage(f->fmt.pix_mp.plane_fmt[0].bytesperline,
                                  f->fmt.pix_mp.width, f->fmt.pix_mp.height,
@@ -1581,7 +1585,8 @@ static int vidioc_s_fmt(struct bcm2835_codec_ctx *ctx, struct v4l2_format *f,
                q_data_dst->height = ALIGN(q_data->crop_height, 16);
 
                q_data_dst->bytesperline =
-                       get_bytesperline(f->fmt.pix_mp.width, q_data_dst->fmt);
+                       get_bytesperline(f->fmt.pix_mp.width, q_data_dst->fmt,
+                                        ctx->dev->role);
                q_data_dst->sizeimage = get_sizeimage(q_data_dst->bytesperline,
                                                      q_data_dst->crop_width,
                                                      q_data_dst->height,
@@ -1810,6 +1815,8 @@ static int vidioc_g_selection(struct file *file, void *priv,
                        }
                }
                break;
+       case NUM_ROLES:
+               break;
        }
 
        return 0;
@@ -1920,6 +1927,8 @@ static int vidioc_s_selection(struct file *file, void *priv,
                        }
                        break;
                }
+       case NUM_ROLES:
+               break;
        }
 
        return 0;
@@ -3095,7 +3104,8 @@ static int bcm2835_codec_open(struct file *file)
        ctx->q_data[V4L2_M2M_SRC].height = DEFAULT_HEIGHT;
        ctx->q_data[V4L2_M2M_SRC].bytesperline =
                        get_bytesperline(DEFAULT_WIDTH,
-                                        ctx->q_data[V4L2_M2M_SRC].fmt);
+                                        ctx->q_data[V4L2_M2M_SRC].fmt,
+                                        dev->role);
        ctx->q_data[V4L2_M2M_SRC].sizeimage =
                get_sizeimage(ctx->q_data[V4L2_M2M_SRC].bytesperline,
                              ctx->q_data[V4L2_M2M_SRC].crop_width,
@@ -3108,7 +3118,8 @@ static int bcm2835_codec_open(struct file *file)
        ctx->q_data[V4L2_M2M_DST].height = DEFAULT_HEIGHT;
        ctx->q_data[V4L2_M2M_DST].bytesperline =
                        get_bytesperline(DEFAULT_WIDTH,
-                                        ctx->q_data[V4L2_M2M_DST].fmt);
+                                        ctx->q_data[V4L2_M2M_DST].fmt,
+                                        dev->role);
        ctx->q_data[V4L2_M2M_DST].sizeimage =
                get_sizeimage(ctx->q_data[V4L2_M2M_DST].bytesperline,
                              ctx->q_data[V4L2_M2M_DST].crop_width,
@@ -3238,6 +3249,8 @@ static int bcm2835_codec_open(struct file *file)
                v4l2_ctrl_handler_init(hdl, 0);
        }
        break;
+       case NUM_ROLES:
+       break;
        }
 
        ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);