[FFmpeg-devel] [PATCH 05/25] avcodec/v4l2_buffers: teach ff_v4l2_buffer_avframe_to_buf about contiguous planar formats

Aman Gupta ffmpeg at tmm1.net
Wed Sep 4 21:02:54 EEST 2019


On Wed, Sep 4, 2019 at 9:40 AM Alexis Ballier <aballier at gentoo.org> wrote:

> On Mon,  2 Sep 2019 18:02:10 -0700
> Aman Gupta <ffmpeg at tmm1.net> wrote:
> [...]
> > @@ -289,15 +290,59 @@ static int v4l2_bufref_to_buf(V4L2Buffer *out,
> > int plane, const uint8_t* data, i int
> > ff_v4l2_buffer_avframe_to_buf(const AVFrame *frame, V4L2Buffer *out) {
> >      int i, ret;
> > +    struct v4l2_format fmt = out->context->format;
> > +    int pixel_format = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
> > +                       fmt.fmt.pix_mp.pixelformat :
> > fmt.fmt.pix.pixelformat;
> > +    int height       = V4L2_TYPE_IS_MULTIPLANAR(fmt.type) ?
> > +                       fmt.fmt.pix_mp.height : fmt.fmt.pix.height;
> > +    int is_planar_format = 0;
> > +
> > +    switch (pixel_format) {
> > +    case V4L2_PIX_FMT_YUV420M:
> > +    case V4L2_PIX_FMT_YVU420M:
> > +    case V4L2_PIX_FMT_YUV422M:
> > +    case V4L2_PIX_FMT_YVU422M:
> > +    case V4L2_PIX_FMT_YUV444M:
> > +    case V4L2_PIX_FMT_YVU444M:
> > +    case V4L2_PIX_FMT_NV12M:
> > +    case V4L2_PIX_FMT_NV21M:
> > +    case V4L2_PIX_FMT_NV12MT_16X16:
> > +    case V4L2_PIX_FMT_NV12MT:
> > +    case V4L2_PIX_FMT_NV16M:
> > +    case V4L2_PIX_FMT_NV61M:
> > +        is_planar_format = 1;
> > +    }
>
>
> can't this be inlined as 'int is_planar_format =
> V4L2_TYPE_IS_MULTIPLANAR(fmt.type)' as done 2 lines above ?
>

Unfortunately not.

That macro differentiates between the original splane v4l2 api vs the newer
mplane api.

But even if you're using the newer api, it still support contiguous planar
formats (YUV420 vs YUV420M).

So the macro decides which fields in the struct to use (pix vs pix_mp), and
then the pixel format itself decides if the planes are contiguous in memory
or stored in separate buffers.

Aman




>
> [...]
>
>
> Alexis.
>


More information about the ffmpeg-devel mailing list