Commit 09250193 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB: ivtv: support the new events API

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 1bcaf4bd
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-fh.h>
#include <media/tuner.h> #include <media/tuner.h>
#include <media/cx2341x.h> #include <media/cx2341x.h>
#include <media/ir-kbd-i2c.h> #include <media/ir-kbd-i2c.h>
...@@ -375,6 +376,7 @@ struct ivtv_stream { ...@@ -375,6 +376,7 @@ struct ivtv_stream {
}; };
struct ivtv_open_id { struct ivtv_open_id {
struct v4l2_fh fh;
u32 open_id; /* unique ID for this file descriptor */ u32 open_id; /* unique ID for this file descriptor */
int type; /* stream type */ int type; /* stream type */
int yuv_frames; /* 1: started OUT_UDMA_YUV output mode */ int yuv_frames; /* 1: started OUT_UDMA_YUV output mode */
...@@ -382,6 +384,11 @@ struct ivtv_open_id { ...@@ -382,6 +384,11 @@ struct ivtv_open_id {
struct ivtv *itv; struct ivtv *itv;
}; };
static inline struct ivtv_open_id *fh2id(struct v4l2_fh *fh)
{
return container_of(fh, struct ivtv_open_id, fh);
}
struct yuv_frame_info struct yuv_frame_info
{ {
u32 update; u32 update;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "ivtv-yuv.h" #include "ivtv-yuv.h"
#include "ivtv-ioctl.h" #include "ivtv-ioctl.h"
#include "ivtv-cards.h" #include "ivtv-cards.h"
#include <media/v4l2-event.h>
#include <media/saa7115.h> #include <media/saa7115.h>
/* This function tries to claim the stream for a specific file descriptor. /* This function tries to claim the stream for a specific file descriptor.
...@@ -506,7 +507,7 @@ int ivtv_start_capture(struct ivtv_open_id *id) ...@@ -506,7 +507,7 @@ int ivtv_start_capture(struct ivtv_open_id *id)
ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos) ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos)
{ {
struct ivtv_open_id *id = filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
int rc; int rc;
...@@ -541,7 +542,7 @@ int ivtv_start_decoding(struct ivtv_open_id *id, int speed) ...@@ -541,7 +542,7 @@ int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos) ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos)
{ {
struct ivtv_open_id *id = filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
struct yuv_playback_info *yi = &itv->yuv_info; struct yuv_playback_info *yi = &itv->yuv_info;
...@@ -711,19 +712,31 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c ...@@ -711,19 +712,31 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait) unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
{ {
struct ivtv_open_id *id = filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
int res = 0; int res = 0;
/* add stream's waitq to the poll list */ /* add stream's waitq to the poll list */
IVTV_DEBUG_HI_FILE("Decoder poll\n"); IVTV_DEBUG_HI_FILE("Decoder poll\n");
poll_wait(filp, &s->waitq, wait);
/* If there are subscribed events, then only use the new event
API instead of the old video.h based API. */
if (!list_empty(&id->fh.events->subscribed)) {
poll_wait(filp, &id->fh.events->wait, wait);
/* Turn off the old-style vsync events */
clear_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
if (v4l2_event_pending(&id->fh))
res = POLLPRI;
} else {
/* This is the old-style API which is here only for backwards
compatibility. */
poll_wait(filp, &s->waitq, wait);
set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) || if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) ||
test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags)) test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
res = POLLPRI; res = POLLPRI;
}
/* Allow write if buffers are available for writing */ /* Allow write if buffers are available for writing */
if (s->q_free.buffers) if (s->q_free.buffers)
...@@ -733,7 +746,7 @@ unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait) ...@@ -733,7 +746,7 @@ unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait) unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
{ {
struct ivtv_open_id *id = filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags); int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
...@@ -833,13 +846,16 @@ static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts) ...@@ -833,13 +846,16 @@ static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
int ivtv_v4l2_close(struct file *filp) int ivtv_v4l2_close(struct file *filp)
{ {
struct ivtv_open_id *id = filp->private_data; struct v4l2_fh *fh = filp->private_data;
struct ivtv_open_id *id = fh2id(fh);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
IVTV_DEBUG_FILE("close %s\n", s->name); IVTV_DEBUG_FILE("close %s\n", s->name);
v4l2_prio_close(&itv->prio, &id->prio); v4l2_prio_close(&itv->prio, &id->prio);
v4l2_fh_del(fh);
v4l2_fh_exit(fh);
/* Easy case first: this stream was never claimed by us */ /* Easy case first: this stream was never claimed by us */
if (s->id != id->open_id) { if (s->id != id->open_id) {
...@@ -895,6 +911,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp) ...@@ -895,6 +911,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
{ {
struct ivtv *itv = s->itv; struct ivtv *itv = s->itv;
struct ivtv_open_id *item; struct ivtv_open_id *item;
int res = 0;
IVTV_DEBUG_FILE("open %s\n", s->name); IVTV_DEBUG_FILE("open %s\n", s->name);
...@@ -915,17 +932,27 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp) ...@@ -915,17 +932,27 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
} }
/* Allocate memory */ /* Allocate memory */
item = kmalloc(sizeof(struct ivtv_open_id), GFP_KERNEL); item = kzalloc(sizeof(struct ivtv_open_id), GFP_KERNEL);
if (NULL == item) { if (NULL == item) {
IVTV_DEBUG_WARN("nomem on v4l2 open\n"); IVTV_DEBUG_WARN("nomem on v4l2 open\n");
return -ENOMEM; return -ENOMEM;
} }
v4l2_fh_init(&item->fh, s->vdev);
if (s->type == IVTV_DEC_STREAM_TYPE_YUV ||
s->type == IVTV_DEC_STREAM_TYPE_MPG) {
res = v4l2_event_alloc(&item->fh, 60);
}
if (res < 0) {
v4l2_fh_exit(&item->fh);
kfree(item);
return res;
}
item->itv = itv; item->itv = itv;
item->type = s->type; item->type = s->type;
v4l2_prio_open(&itv->prio, &item->prio); v4l2_prio_open(&itv->prio, &item->prio);
item->open_id = itv->open_id++; item->open_id = itv->open_id++;
filp->private_data = item; filp->private_data = &item->fh;
if (item->type == IVTV_ENC_STREAM_TYPE_RAD) { if (item->type == IVTV_ENC_STREAM_TYPE_RAD) {
/* Try to claim this stream */ /* Try to claim this stream */
...@@ -940,6 +967,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp) ...@@ -940,6 +967,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
/* switching to radio while capture is /* switching to radio while capture is
in progress is not polite */ in progress is not polite */
ivtv_release_stream(s); ivtv_release_stream(s);
v4l2_fh_exit(&item->fh);
kfree(item); kfree(item);
return -EBUSY; return -EBUSY;
} }
...@@ -970,6 +998,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp) ...@@ -970,6 +998,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31); 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
itv->yuv_info.stream_size = 0; itv->yuv_info.stream_size = 0;
} }
v4l2_fh_add(&item->fh);
return 0; return 0;
} }
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <media/saa7127.h> #include <media/saa7127.h>
#include <media/tveeprom.h> #include <media/tveeprom.h>
#include <media/v4l2-chip-ident.h> #include <media/v4l2-chip-ident.h>
#include <media/v4l2-event.h>
#include <linux/dvb/audio.h> #include <linux/dvb/audio.h>
#include <linux/i2c-id.h> #include <linux/i2c-id.h>
...@@ -1452,6 +1453,18 @@ static int ivtv_overlay(struct file *file, void *fh, unsigned int on) ...@@ -1452,6 +1453,18 @@ static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
return 0; return 0;
} }
static int ivtv_subscribe_event(struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
{
switch (sub->type) {
case V4L2_EVENT_VSYNC:
case V4L2_EVENT_EOS:
break;
default:
return -EINVAL;
}
return v4l2_event_subscribe(fh, sub);
}
static int ivtv_log_status(struct file *file, void *fh) static int ivtv_log_status(struct file *file, void *fh)
{ {
struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
...@@ -1560,7 +1573,7 @@ static int ivtv_log_status(struct file *file, void *fh) ...@@ -1560,7 +1573,7 @@ static int ivtv_log_status(struct file *file, void *fh)
static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg) static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
{ {
struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
int nonblocking = filp->f_flags & O_NONBLOCK; int nonblocking = filp->f_flags & O_NONBLOCK;
struct ivtv_stream *s = &itv->streams[id->type]; struct ivtv_stream *s = &itv->streams[id->type];
...@@ -1820,7 +1833,7 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp, ...@@ -1820,7 +1833,7 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
unsigned int cmd, unsigned long arg) unsigned int cmd, unsigned long arg)
{ {
struct video_device *vfd = video_devdata(filp); struct video_device *vfd = video_devdata(filp);
struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
long ret; long ret;
/* check priority */ /* check priority */
...@@ -1852,10 +1865,13 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp, ...@@ -1852,10 +1865,13 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{ {
struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data; struct ivtv_open_id *id = fh2id(filp->private_data);
struct ivtv *itv = id->itv; struct ivtv *itv = id->itv;
long res; long res;
/* DQEVENT can block, so this should not run with the serialize lock */
if (cmd == VIDIOC_DQEVENT)
return ivtv_serialized_ioctl(itv, filp, cmd, arg);
mutex_lock(&itv->serialize_lock); mutex_lock(&itv->serialize_lock);
res = ivtv_serialized_ioctl(itv, filp, cmd, arg); res = ivtv_serialized_ioctl(itv, filp, cmd, arg);
mutex_unlock(&itv->serialize_lock); mutex_unlock(&itv->serialize_lock);
...@@ -1926,6 +1942,8 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = { ...@@ -1926,6 +1942,8 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
.vidioc_g_ext_ctrls = ivtv_g_ext_ctrls, .vidioc_g_ext_ctrls = ivtv_g_ext_ctrls,
.vidioc_s_ext_ctrls = ivtv_s_ext_ctrls, .vidioc_s_ext_ctrls = ivtv_s_ext_ctrls,
.vidioc_try_ext_ctrls = ivtv_try_ext_ctrls, .vidioc_try_ext_ctrls = ivtv_try_ext_ctrls,
.vidioc_subscribe_event = ivtv_subscribe_event,
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
}; };
void ivtv_set_funcs(struct video_device *vdev) void ivtv_set_funcs(struct video_device *vdev)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ivtv-mailbox.h" #include "ivtv-mailbox.h"
#include "ivtv-vbi.h" #include "ivtv-vbi.h"
#include "ivtv-yuv.h" #include "ivtv-yuv.h"
#include <media/v4l2-event.h>
#define DMA_MAGIC_COOKIE 0x000001fe #define DMA_MAGIC_COOKIE 0x000001fe
...@@ -778,6 +779,14 @@ static void ivtv_irq_vsync(struct ivtv *itv) ...@@ -778,6 +779,14 @@ static void ivtv_irq_vsync(struct ivtv *itv)
} }
} }
if (frame != (itv->last_vsync_field & 1)) { if (frame != (itv->last_vsync_field & 1)) {
static const struct v4l2_event evtop = {
.type = V4L2_EVENT_VSYNC,
.u.vsync.field = V4L2_FIELD_TOP,
};
static const struct v4l2_event evbottom = {
.type = V4L2_EVENT_VSYNC,
.u.vsync.field = V4L2_FIELD_BOTTOM,
};
struct ivtv_stream *s = ivtv_get_output_stream(itv); struct ivtv_stream *s = ivtv_get_output_stream(itv);
itv->last_vsync_field += 1; itv->last_vsync_field += 1;
...@@ -791,10 +800,12 @@ static void ivtv_irq_vsync(struct ivtv *itv) ...@@ -791,10 +800,12 @@ static void ivtv_irq_vsync(struct ivtv *itv)
if (test_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags)) { if (test_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags)) {
set_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags); set_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags);
wake_up(&itv->event_waitq); wake_up(&itv->event_waitq);
}
wake_up(&itv->vsync_waitq);
if (s) if (s)
wake_up(&s->waitq); wake_up(&s->waitq);
}
if (s && s->vdev)
v4l2_event_queue(s->vdev, frame ? &evtop : &evbottom);
wake_up(&itv->vsync_waitq);
/* Send VBI to saa7127 */ /* Send VBI to saa7127 */
if (frame && (itv->output_mode == OUT_PASSTHROUGH || if (frame && (itv->output_mode == OUT_PASSTHROUGH ||
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "ivtv-yuv.h" #include "ivtv-yuv.h"
#include "ivtv-cards.h" #include "ivtv-cards.h"
#include "ivtv-streams.h" #include "ivtv-streams.h"
#include <media/v4l2-event.h>
static const struct v4l2_file_operations ivtv_v4l2_enc_fops = { static const struct v4l2_file_operations ivtv_v4l2_enc_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -840,6 +841,9 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end) ...@@ -840,6 +841,9 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts) int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
{ {
static const struct v4l2_event ev = {
.type = V4L2_EVENT_EOS,
};
struct ivtv *itv = s->itv; struct ivtv *itv = s->itv;
if (s->vdev == NULL) if (s->vdev == NULL)
...@@ -891,6 +895,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts) ...@@ -891,6 +895,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
set_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags); set_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags);
wake_up(&itv->event_waitq); wake_up(&itv->event_waitq);
v4l2_event_queue(s->vdev, &ev);
/* wake up wait queues */ /* wake up wait queues */
wake_up(&s->waitq); wake_up(&s->waitq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment