media controller -

58
2010-02-06 1 Media controller - FOSDEM 2010 Media controller Harnessing the full power of tomorrow's video devices FOSDEM 2010 Laurent Pinchart [email protected]

Upload: others

Post on 09-Feb-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

2010-02-06 1Media controller - FOSDEM 2010

Media controllerHarnessing the full power of tomorrow's video devices

FOSDEM 2010

Laurent [email protected]

2010-02-06 2Media controller - FOSDEM 2010

Topics

● Video acquisition in Linux● Embedded cameras● Tomorrow's devices● Problems● And solutions

2010-02-06 3Media controller - FOSDEM 2010

Yesterday

2010-02-06 4Media controller - FOSDEM 2010

The (recent) past

1997

V4L, L

inux 2

.2.0

First v

ideo

drive

r

1999 2002 2006

V4L2,

Linu

x 2.4

.0

V4L d

epre

cate

d

2010-02-06 5Media controller - FOSDEM 2010

V4L2 API

Userspaceapplication

V4L2 kerneldriver

/dev/videoX

V4L2 API● Controls● Video format● Memory management● Video streaming

Hardware

2010-02-06 6Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

2010-02-06 7Media controller - FOSDEM 2010

V4L2 – Open video device

struct v4l2_capability cap;

int fd;

fd = open(“/dev/video0”, O_RDWR);

ioctl(fd, VIDIOC_QUERYCAP, &cap);

printf(“Device %s opened\n”, cap.card);

2010-02-06 8Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

2010-02-06 9Media controller - FOSDEM 2010

V4L2 – Set format

struct v4l2_format format;

format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

format.fmt.pix.width = 1920;

format.fmt.pix.height = 1080;

format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;

ioctl(fd, VIDIOC_S_FMT, &format);

2010-02-06 10Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

Allocatememory

2010-02-06 11Media controller - FOSDEM 2010

V4L2 – Allocate memory

struct v4l2_requestbuffers req;

void **mem;

req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

req.count = 4;

req.memory = V4L2_MEMORY_MMAP;

ioctl(fd, VIDIOC_REQBUFS, &req);

printf(“Driver allocated %u buffers\n”, req.count);

mem = malloc(req.count, sizeof *mem);

2010-02-06 12Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

Allocatememory

Map memory

2010-02-06 13Media controller - FOSDEM 2010

V4L2 – Map memory

struct v4l2_buffer buffer;

unsigned int i;

for (i = 0; i < req.count; ++i) {

buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

buffer.memory = V4L2_MEMORY_MMAP;

buffer.index = i;

ioctl(fd, VIDIOC_QUERYBUF, &buffer);

mem[i] = mmap(0, buffer.length,

PROT_READ|PROT_WRITE,

MAP_SHARED, fd, buffer.m.offset);

}

2010-02-06 14Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

Allocatememory

Map memory

Start theVideo stream

Queuebuffers

2010-02-06 15Media controller - FOSDEM 2010

V4L2- Queue buffers and stream

struct v4l2_buffer buffer;

int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

unsigned int i;

for (i = 0; i < req.count; ++i) {

buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

buffer.memory = V4L2_MEMORY_MMAP;

buffer.index = i;

ioctl(fd, VIDIOC_QBUF, &buffer);

}

ioctl(fd, VIDIOC_STREAMON, &type);

2010-02-06 16Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

Allocatememory

Map memory

Start theVideo stream

Queuebuffers

Dequeuebuffer

Queuebuffer

2010-02-06 17Media controller - FOSDEM 2010

V4L2 – Capture video

struct v4l2_buffer buffer;

While (1) {

buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

buffer.memory = V4L2_MEMORY_MMAP;

ioctl(fd, VIDIOC_DQBUF, &buffer);

process_buffer(buffer, mem[buffer.index]);

ioctl(fd, VIDIOC_QBUF, &buffer);

}

2010-02-06 18Media controller - FOSDEM 2010

V4L2 userspace API

Openvideo device

Set format

Allocatememory

Map memory

Start theVideo stream

Queuebuffers

Dequeuebuffer

Queuebuffer

Zoom

2010-02-06 19Media controller - FOSDEM 2010

V4L2 – And zoom and more

struct v4l2_crop crop;

crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

crop.bounds.left = (2592 – 1280) / 2;

crop.bounds.top = (1968 – 720) / 2;

crop.bounds.width = 1280;

crop.bounds.height = 720;

ioctl(fd, VIDIOC_S_CROP, &crop);

2010-02-06 20Media controller - FOSDEM 2010

Today

SH 7722 MIGO-RRenesas Technology

2010-02-06 21Media controller - FOSDEM 2010

The present

2006 2008

libv4

l 0.1

2010

libv4

l 0.6

.4

SoC C

amer

a

V4L2

exte

nsion

s

V4L2

subd

ev

2010-02-06 22Media controller - FOSDEM 2010

Embedded camera

Userspaceapplication

Sensordriver

/dev/videoX

Embedded SoC camera● soc_camera● v4l2_device● v4l2_subdev

Userspace library● Format conversion● Post-processing

Hardware

Bridgedriver

2010-02-06 23Media controller - FOSDEM 2010

V4L2 subdevice

● In-kernel functional abstraction layer developed by Hans Verkuil

● Designed for on-board external devices (sensors, tuners, audio codecs, …)

● Reusability, Reusability, Reusability

MT9M001sensor

EM28xxUSB

SAA7114decoder

EM28xxUSB

MT9M001sensor

PXA270SoC

SAA7114decoder

ZoranPCI

2010-02-06 24Media controller - FOSDEM 2010

V4L2 subdevice operations

struct v4l2_subdev_ops {

const struct v4l2_subdev_core_ops *core;

const struct v4l2_subdev_tuner_ops *tuner;

const struct v4l2_subdev_audio_ops *audio;

const struct v4l2_subdev_video_ops *video;

const struct v4l2_subdev_ir_ops *ir;

const struct v4l2_subdev_sensor_ops *sensor;

};

● Hardware independent● Bus type independent

2010-02-06 25Media controller - FOSDEM 2010

i2c_get_client_data

v4l2_device_register_subdev

i2c_new_device

V4L2 subdevice registration

V4L2 device V4L2 subdevice

Register hardware device device_driver::probe called

device_driver::probe called

Subdevice initialization

Retrieve subdevice pointer

Subdevice setupv4l2_subdev_call(core::s_config)

Register subdevice

v4l2_i2c_new_subdev_board

2010-02-06 26Media controller - FOSDEM 2010

SoC Camera

Host bridge Sensor

Master clock

Pixel clock

Horizontal sync

Vertical sync

Field

Data[7:0]

Host bridge Sensor

C+

C-

D+

D-

I2C

I2C

Pa

ralle

l in

terf

ace

Ser

ial i

nte

rfac

e (C

SI)

Master clock

2010-02-06 27Media controller - FOSDEM 2010

V4L2 subdevice usage

V4L2 device V4L2 subdevice

v4l2_subdev_call(video::s_fmt) Configure the sensor scaler

V4L2 call (VIDIOC_S_FMT)

return

Success ?

Configure thebridge scaler

Failure ?

● How do we decide where to perform scaling ?– On the sensor side for higher frame rates ?

– On the host side for better quality ?

2010-02-06 28Media controller - FOSDEM 2010

libv4l

● Cheap hardware rely on software image enhancement

● High resolution on low bandwidth requires compression

2010-02-06 29Media controller - FOSDEM 2010

libv4l

● Userspace library developed by Hans de Goede● http://people.fedoraproject.org/~jwrdegoede/● Format conversion

– Convert from any (known) format to BGR24 or YUV420, including compressed proprietary formats

– Transparent format emulation

● Software image processing– Rotation

– Auto-exposure

– White balance

● CPU intensive but CPU is cheap. Or is it ?

2010-02-06 30Media controller - FOSDEM 2010

Tomorrow

Camera 2.0Stanford Computer Graphics LaboratoryNokia Research Center Palo Alto Laboratory

2010-02-06 31Media controller - FOSDEM 2010

Lensdriver

Frontsensordriver

Embedded mess

Userspaceapplication

Backsensordriver

/dev/videoX

Highly complex devices● Multiple inputs● Multiple streams● Configurable pipeline

Hardware

Flashdriver

ISPdriver

Cameradriver

2010-02-06 32Media controller - FOSDEM 2010

OMAP3430 ISPDrawing is © Texas Instrument

OMAP3430 ISP● Reconfigurable pipeline● Parallel processing● Memory-to-memory

paths● Fine-grain parameters

How do we handle the zillion configuration options through a single video device ?

2010-02-06 33Media controller - FOSDEM 2010

The (past) future

2009

LPC 2

009

Med

ia Con

trolle

r

2010 20122011

2010-02-06 34Media controller - FOSDEM 2010

Frontsensordriver

Media controller – What and why

Userspaceapplication

/dev/mediaX

What ?● Just a device. Similar

to v4l2_device, but more abstract.

Why ?● To let userspace

applications have fine grain control over all the media device parameters.

Hardware

Lensdriver

Backsensordriver

Flashdriver

ISPdriver

Media kerneldriver

2010-02-06 35Media controller - FOSDEM 2010

Media controller - How

How ?● Expose the media device topology to userspace

as a graph of building blocks called entities connected through pads.

● Create/break connections from userspace.● Give access to entitites internal parameters

through read/write/ioctl calls.● Configure image streaming parameters at each

pad.

2010-02-06 36Media controller - FOSDEM 2010

Media entity

Mediaentity

struct media_entity{ u32 id; const char *name; u32 type; u32 subtype; ...};

● media_entity::type

– MEDIA_ENTITY_TYPE_NODE

– MEDIA_ENTITY_TYPE_SUBDEV

2010-02-06 37Media controller - FOSDEM 2010

Media entity - Pads

Mediaentity

0

1

2

struct media_entity{ ... u8 num_pads; struct media_entity_pad *pads; ...};

struct media_entity_pad{ u32 type; u32 index;};

● media_entity_pad::type

– MEDIA_PAD_TYPE_INPUT

– MEDIA_PAD_TYPE_OUTPUT

2010-02-06 38Media controller - FOSDEM 2010

Media entity - Links

Mediaentity

0

1

2

● media_entity_link::flags

– MEDIA_LINK_FLAG_ACTIVE

– MEDIA_LINK_FLAG_IMMUTABLE

struct media_entity{ ... u32 num_links; struct media_entity_link *links; ...};

struct media_entity_link{ struct media_entity_pad *source; struct media_entity_pad *sink; u32 flags;};

Mediaentity

0

2010-02-06 39Media controller - FOSDEM 2010

Media entity registration

media_entity_create_link

media_device_register_entity

media_entity_init

Media entity

Initialize entity

Create links

Register entity

Mediaentity

0

1

2

Mediaentity

0

1

2Mediaentity

0

2010-02-06 40Media controller - FOSDEM 2010

Media controller – Userspace API

Openmedia device

int fd;

fd = open(“/dev/media0”, O_RDWR);

2010-02-06 41Media controller - FOSDEM 2010

Media controller – Userspace API

Openmedia device

Enumerateentities, pads

and links

int fd;

fd = open(“/dev/media0”, O_RDWR);

while (1) { struct media_user_entity entity; struct media_user_links links;

ret = ioctl(fd, MEDIA_IOC_ENUM_ENTITES, &entity); if (ret < 0) break;

while (1) { ret = ioctl(fd, MEDIA_IOC_ENUM_LINKS, &links); if (ret < 0) break; }}

2010-02-06 42Media controller - FOSDEM 2010

Logitech Portable Webcam C905

2010-02-06 43Media controller - FOSDEM 2010

Nokia N900

2010-02-06 44Media controller - FOSDEM 2010

Media controller – Userspace API

Openmedia device

Enumerateentities, pads

and links

Setup links

struct media_user_link link;

link.source.entity = OMAP3_ISP_ENTITY_CCDC;link.source.index = 2;link.sink.entity = OMAP3_ISP_ENTITY_PREVIEW;link.sink.index = 0;link.flags = 0;

ioctl(fd, MEDIA_IOC_SETUP_LINK, &link);

link.source.entity = OMAP3_ISP_ENTITY_CCDC;link.source.index = 1;link.sink.entity = OMAP3_ISP_ENTITY_CCDC_OUT;link.sink.index = 0;link.flags = MEDIA_LINK_FLAG_ACTIVE;

ioctl(fd, MEDIA_IOC_SETUP_LINK, &link);

2010-02-06 45Media controller - FOSDEM 2010

OMAP3430 ISP - Controls

ISPCCDC

0

1

2

ISPPreviewEngine

0 1ISP

Resizer0 1

ET8EK8Sensor

0

● White balance ● White balance

● Faulty pixels correction

The S_CTRL API is not up to the job.

● Faulty pixels correction

2010-02-06 46Media controller - FOSDEM 2010

OMAP3430 ISP - Resizing

ISPCCDC

0

1

2

ISPPreviewEngine

0 1ISP

Resizer0 1

ET8EK8Sensor

0

● Binning ● Horizontal averaging

● Polyphase filter

2010-02-06 47Media controller - FOSDEM 2010

OMAP3430 ISP – High quality

ISPCCDC

0

1

2

ISPPreviewEngine

0 1ISP

Resizer0 1

ET8EK8Sensor

0

S_FMT(2592,1968)

S_CROP(2592,1968)

S_FMT(2592,1968)

S_CROP(2592, 1968)

S_FMT(2592,1968)

S_FMT(2592, 1968)

S_FMT(1280,720)

S_CROP(2592, 1968)

2010-02-06 48Media controller - FOSDEM 2010

OMAP3430 ISP – High speed

ISPCCDC

0

1

2

ISPPreviewEngine

0 1ISP

Resizer0 1

ET8EK8Sensor

0

S_FMT(1296, 984)

S_CROP(2592,1968)

S_FMT(1296, 984)

S_CROP(1296, 984)

S_FMT(1296, 984)

S_FMT(1296, 984)

S_FMT(1280,720)

S_CROP(1296, 984)

The S_FMT/S_CROP API is not up to the job.

2010-02-06 49Media controller - FOSDEM 2010

Lensdriver

Frontsensordriver

V4L2 subdev userspace API

Userspaceapplication

Backsensordriver

/dev/subdevX

Hardware

Flashdriver

ISP CCDCdriver

/dev/subdevY /dev/subdevZ

ISPPreviewdriver

2010-02-06 50Media controller - FOSDEM 2010

V4L2 subdevice pad operations

struct v4l2_subdev_pad_ops {

...

int (*get_fmt)(struct v4l2_subdev *sd, unsigned int pad,

struct v4l2_format *fmt,

enum v4l2_subdev_format which);

int (*set_fmt)(struct v4l2_subdev *sd, unsigned int pad,

struct v4l2_format *fmt,

enum v4l2_subdev_format which);

....

};

struct v4l2_subdev_ops {

...

const struct v4l2_subdev_pad_ops *pad;

};

2010-02-06 51Media controller - FOSDEM 2010

V4L2 plain API

Is this V4L3 ?● No, V4L2 is still alive and well● Best effort to provide V4L2-only compatibility for

existing applications (API and ABI)● Advanced features will require Media Controller

OMAP3430 ISP● Default pipeline through /dev/video0● Limited set of resolutions, limited set of controls

2010-02-06 52Media controller - FOSDEM 2010

Image quality

Host-side software algorithm

VIDIOC_S_CTRL

V4L2 events API

Retrieve statistics

Compute parameters

Set parameters

ISPH3A

ISPAF

00

ISPCCDC

0

1 2

ISPCCDC0

1

2

ISPPreviewEngine

0 1ET8EK8Sensor 0

2010-02-06 53Media controller - FOSDEM 2010

Backsensordriver

ISPdriver

libv4l

Userspaceapplication

● Image enhancement algorithms

● Hardware-specific acceleration

● Transparent for applications

Hardware

Media kerneldriver

libv4lOMAP3 plugin

2010-02-06 54Media controller - FOSDEM 2010

The future

2009

LPC 2

009

Med

ia Con

trolle

r

2010

LPC 2

010

Med

ia Con

trolle

r

20122011

libv4

l har

dwar

e

acce

lerat

ion

Med

ia bu

ffers

poo

l

V4L2

even

ts API

Global

buffe

rs p

ool

2010-02-06 55Media controller - FOSDEM 2010

The future - V2

2009 2010 2012

End o

f the

wor

ld

(acc

ordin

g to

the

May

a)

2011

LPC 2

009

Med

ia Con

trolle

r

LPC 2

010

Med

ia Con

trolle

r

libv4

l har

dwar

e

acce

lerat

ion

Med

ia bu

ffers

poo

l

V4L2

even

ts API

Global

buffe

rs p

ool

2010-02-06 56Media controller - FOSDEM 2010

The future - V3

2009 2010 2012

Year

of t

he L

inux d

eskto

p

(acc

ordin

g to

your

favo

rite

Linux

mag

azine

)

2011

LPC 2

009

Med

ia Con

trolle

r

LPC 2

010

Med

ia Con

trolle

r

libv4

l har

dwar

e

acce

lerat

ion

Med

ia bu

ffers

poo

l

V4L2

even

ts API

Global

buffe

rs p

ool

2010-02-06 57Media controller - FOSDEM 2010

Thanks

● Hans Verkuil● Sakari Ailus● Detlev Casanova

2010-02-06 58Media controller - FOSDEM 2010

Contacts

[email protected][email protected]● http://gitorious.org/omap3camera