12 #include <linux/kernel.h>
13 #include <linux/errno.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
22 #include <linux/videodev2.h>
28 #define BULK_URB_TIMEOUT 90
30 #define print_buffer_status() { \
31 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, \
32 "%s:%d buffer stat: %d free, %d proc\n", \
34 list_size(&dev->free_buff_list), \
35 list_size(&dev->rec_buff_list)); }
55 static void hdpvr_read_bulk_callback(
struct urb *
urb)
83 static int hdpvr_free_queue(
struct list_head *
q)
90 for (p = q->
next; p != q;) {
95 urb->transfer_buffer, urb->transfer_dma);
127 "allocating %u buffers\n", count);
129 for (i = 0; i <
count; i++) {
149 "cannot allocate usb transfer buffer\n");
150 goto exit_urb_buffer;
153 usb_fill_bulk_urb(buf->
urb, dev->
udev,
154 usb_rcvbulkpipe(dev->
udev,
157 hdpvr_read_bulk_callback, buf);
159 buf->
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
188 "buffer not marked as available\n");
195 urb->actual_length = 0;
199 "usb_submit_urb in %s returned %d\n",
239 if (hdpvr_submit_buffers(dev)) {
250 "transmit worker exited\n");
254 "transmit buffers errored\n");
259 static int hdpvr_start_streaming(
struct hdpvr_device *dev)
273 "video signal: %dx%d@%dhz\n", vidinf->
width,
279 usb_sndctrlpipe(dev->
udev, 0),
280 0xb8, 0x38, 0x1, 0,
NULL, 0, 8000);
282 "encoder start control request returned %d\n", ret);
292 "streaming started\n");
298 "no video signal at input %d\n", dev->
options.video_input);
304 static int hdpvr_stop_streaming(
struct hdpvr_device *dev)
318 "for emptying the internal device buffer. "
319 "Next capture start will be slow\n");
335 while (buf && ++c < 500 &&
337 usb_rcvbulkpipe(dev->
udev,
342 "%2d: got %d bytes\n", c, actual_length);
346 "used %d urbs to empty device buffers\n", c-1);
360 static int hdpvr_open(
struct file *
file)
368 pr_err(
"open failing with with ENODEV\n");
394 static int hdpvr_release(
struct file *file)
404 hdpvr_stop_streaming(dev);
422 unsigned int ret = 0;
433 if (hdpvr_start_streaming(dev)) {
435 "start_streaming failed\n");
449 hdpvr_get_next_buffer(dev)))
453 buf = hdpvr_get_next_buffer(dev);
455 while (count > 0 && buf) {
478 rem = urb->actual_length - buf->
pos;
479 cnt = rem > count ? count : rem;
495 if (buf->
pos == urb->actual_length) {
508 buf = hdpvr_get_next_buffer(dev);
517 static unsigned int hdpvr_poll(
struct file *filp,
poll_table *
wait)
522 unsigned int mask = 0;
526 if (!video_is_registered(dev->
video_dev)) {
532 if (hdpvr_start_streaming(dev)) {
534 "start_streaming failed\n");
542 buf = hdpvr_get_next_buffer(dev);
546 buf = hdpvr_get_next_buffer(dev);
558 .release = hdpvr_release,
569 static int vidioc_querycap(
struct file *file,
void *
priv,
583 static int vidioc_s_std(
struct file *file,
void *
private_data,
596 static const char *iname[] = {
602 static int vidioc_enum_input(
struct file *file,
void *
priv,
616 i->
name[
sizeof(i->
name) - 1] =
'\0';
625 static int vidioc_s_input(
struct file *file,
void *private_data,
645 static int vidioc_g_input(
struct file *file,
void *private_data,
651 *index = dev->
options.video_input;
656 static const char *audio_iname[] = {
662 static int vidioc_enumaudio(
struct file *file,
void *priv,
674 audio->
name[
sizeof(audio->
name) - 1] =
'\0';
679 static int vidioc_s_audio(
struct file *file,
void *private_data,
699 static int vidioc_g_audio(
struct file *file,
void *private_data,
708 audio->
name[
sizeof(audio->
name) - 1] =
'\0';
712 static const s32 supported_v4l2_ctrls[] = {
764 1, V4L2_MPEG_AUDIO_ENCODING_AAC);
793 static int vidioc_queryctrl(
struct file *file,
void *private_data,
801 memset(qc, 0,
sizeof(*qc));
806 for (i = 0; i <
ARRAY_SIZE(supported_v4l2_ctrls); i++) {
808 if (qc->
id < supported_v4l2_ctrls[i])
809 qc->
id = supported_v4l2_ctrls[
i];
814 if (qc->
id == supported_v4l2_ctrls[i])
815 return fill_queryctrl(&dev->
options, qc,
819 if (qc->
id < supported_v4l2_ctrls[i])
826 static int vidioc_g_ctrl(
struct file *file,
void *private_data,
854 static int vidioc_s_ctrl(
struct file *file,
void *private_data,
928 static int vidioc_g_ext_ctrls(
struct file *file,
void *priv,
936 for (i = 0; i < ctrls->
count; i++) {
939 err = hdpvr_get_ctrl(&dev->
options, ctrl);
979 if (bitrate >= 10 && bitrate <= 135)
985 uint peak_bitrate = ctrl->
value / 100000;
986 if (peak_bitrate >= 10 && peak_bitrate <= 202)
1000 static int vidioc_try_ext_ctrls(
struct file *file,
void *priv,
1008 for (i = 0; i < ctrls->
count; i++) {
1011 err = hdpvr_try_ctrl(ctrl,
1083 if (opt->
bitrate < peak_bitrate) {
1098 static int vidioc_s_ext_ctrls(
struct file *file,
void *priv,
1106 for (i = 0; i < ctrls->
count; i++) {
1109 err = hdpvr_try_ctrl(ctrl,
1115 err = hdpvr_set_ctrl(dev, ctrl);
1128 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *private_data,
1142 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *private_data,
1161 f->
fmt.
pix.colorspace = 0;
1162 f->
fmt.
pix.bytesperline = 0;
1182 res = hdpvr_start_streaming(dev);
1185 res = hdpvr_stop_streaming(dev);
1189 "Unsupported encoder cmd %d\n", a->
cmd);
1196 static int vidioc_try_encoder_cmd(
struct file *filp,
void *priv,
1229 static void hdpvr_device_release(
struct video_device *vdev)
1241 #if defined(CONFIG_I2C) || (CONFIG_I2C_MODULE)
1251 static const struct video_device hdpvr_video_template = {
1254 .fops = &hdpvr_fops,
1255 .
release = hdpvr_device_release,
1256 .ioctl_ops = &hdpvr_ioctl_ops,
1276 *(dev->
video_dev) = hdpvr_video_template;