cx18-streams.c
来自「trident tm5600的linux驱动」· C语言 代码 · 共 625 行 · 第 1/2 页
C
625 行
/* * cx18 init/start/stop/exit stream functions * * Derived from ivtv-streams.c * * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */#include "cx18-driver.h"#include "cx18-io.h"#include "cx18-fileops.h"#include "cx18-mailbox.h"#include "cx18-i2c.h"#include "cx18-queue.h"#include "cx18-ioctl.h"#include "cx18-streams.h"#include "cx18-cards.h"#include "cx18-scb.h"#include "cx18-av-core.h"#include "cx18-dvb.h"#define CX18_DSP0_INTERRUPT_MASK 0xd0004Cstatic struct file_operations cx18_v4l2_enc_fops = { .owner = THIS_MODULE, .read = cx18_v4l2_read, .open = cx18_v4l2_open, /* FIXME change to video_ioctl2 if serialization lock can be removed */ .ioctl = cx18_v4l2_ioctl, .compat_ioctl = v4l_compat_ioctl32, .release = cx18_v4l2_close, .poll = cx18_v4l2_enc_poll,};/* offset from 0 to register ts v4l2 minors on */#define CX18_V4L2_ENC_TS_OFFSET 16/* offset from 0 to register pcm v4l2 minors on */#define CX18_V4L2_ENC_PCM_OFFSET 24/* offset from 0 to register yuv v4l2 minors on */#define CX18_V4L2_ENC_YUV_OFFSET 32static struct { const char *name; int vfl_type; int num_offset; int dma; enum v4l2_buf_type buf_type; struct file_operations *fops;} cx18_stream_info[] = { { /* CX18_ENC_STREAM_TYPE_MPG */ "encoder MPEG", VFL_TYPE_GRABBER, 0, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_TS */ "TS", VFL_TYPE_GRABBER, -1, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_YUV */ "encoder YUV", VFL_TYPE_GRABBER, CX18_V4L2_ENC_YUV_OFFSET, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_VBI */ "encoder VBI", VFL_TYPE_VBI, 0, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VBI_CAPTURE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_PCM */ "encoder PCM audio", VFL_TYPE_GRABBER, CX18_V4L2_ENC_PCM_OFFSET, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_PRIVATE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_IDX */ "encoder IDX", VFL_TYPE_GRABBER, -1, PCI_DMA_FROMDEVICE, V4L2_BUF_TYPE_VIDEO_CAPTURE, &cx18_v4l2_enc_fops }, { /* CX18_ENC_STREAM_TYPE_RAD */ "encoder radio", VFL_TYPE_RADIO, 0, PCI_DMA_NONE, V4L2_BUF_TYPE_PRIVATE, &cx18_v4l2_enc_fops },};static void cx18_stream_init(struct cx18 *cx, int type){ struct cx18_stream *s = &cx->streams[type]; struct video_device *dev = s->v4l2dev; u32 max_size = cx->options.megabytes[type] * 1024 * 1024; /* we need to keep v4l2dev, so restore it afterwards */ memset(s, 0, sizeof(*s)); s->v4l2dev = dev; /* initialize cx18_stream fields */ s->cx = cx; s->type = type; s->name = cx18_stream_info[type].name; s->handle = CX18_INVALID_TASK_HANDLE; s->dma = cx18_stream_info[type].dma; s->buf_size = cx->stream_buf_size[type]; if (s->buf_size) s->buffers = max_size / s->buf_size; if (s->buffers > 63) { /* Each stream has a maximum of 63 buffers, ensure we do not exceed that. */ s->buffers = 63; s->buf_size = (max_size / s->buffers) & ~0xfff; } spin_lock_init(&s->qlock); init_waitqueue_head(&s->waitq); s->id = -1; cx18_queue_init(&s->q_free); cx18_queue_init(&s->q_full); cx18_queue_init(&s->q_io);}static int cx18_prep_dev(struct cx18 *cx, int type){ struct cx18_stream *s = &cx->streams[type]; u32 cap = cx->v4l2_cap; int num_offset = cx18_stream_info[type].num_offset; int num = cx->num + cx18_first_minor + num_offset; /* These four fields are always initialized. If v4l2dev == NULL, then this stream is not in use. In that case no other fields but these four can be used. */ s->v4l2dev = NULL; s->cx = cx; s->type = type; s->name = cx18_stream_info[type].name; /* Check whether the radio is supported */ if (type == CX18_ENC_STREAM_TYPE_RAD && !(cap & V4L2_CAP_RADIO)) return 0; /* Check whether VBI is supported */ if (type == CX18_ENC_STREAM_TYPE_VBI && !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE))) return 0; /* User explicitly selected 0 buffers for these streams, so don't create them. */ if (cx18_stream_info[type].dma != PCI_DMA_NONE && cx->options.megabytes[type] == 0) { CX18_INFO("Disabled %s device\n", cx18_stream_info[type].name); return 0; } cx18_stream_init(cx, type); if (num_offset == -1) return 0; /* allocate and initialize the v4l2 video device structure */ s->v4l2dev = video_device_alloc(); if (s->v4l2dev == NULL) { CX18_ERR("Couldn't allocate v4l2 video_device for %s\n", s->name); return -ENOMEM; } snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d", cx->num); s->v4l2dev->num = num; s->v4l2dev->parent = &cx->dev->dev; s->v4l2dev->fops = cx18_stream_info[type].fops; s->v4l2dev->release = video_device_release; s->v4l2dev->tvnorms = V4L2_STD_ALL; cx18_set_funcs(s->v4l2dev); return 0;}/* Initialize v4l2 variables and register v4l2 devices */int cx18_streams_setup(struct cx18 *cx){ int type, ret; /* Setup V4L2 Devices */ for (type = 0; type < CX18_MAX_STREAMS; type++) { /* Prepare device */ ret = cx18_prep_dev(cx, type); if (ret < 0) break; /* Allocate Stream */ ret = cx18_stream_alloc(&cx->streams[type]); if (ret < 0) break; } if (type == CX18_MAX_STREAMS) return 0; /* One or more streams could not be initialized. Clean 'em all up. */ cx18_streams_cleanup(cx, 0); return ret;}static int cx18_reg_dev(struct cx18 *cx, int type){ struct cx18_stream *s = &cx->streams[type]; int vfl_type = cx18_stream_info[type].vfl_type; int num, ret; /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something? * We need a VFL_TYPE_TS defined. */ if (strcmp("TS", s->name) == 0) { /* just return if no DVB is supported */ if ((cx->card->hw_all & CX18_HW_DVB) == 0) return 0; ret = cx18_dvb_register(s); if (ret < 0) { CX18_ERR("DVB failed to register\n"); return ret; } } if (s->v4l2dev == NULL) return 0; num = s->v4l2dev->num; /* card number + user defined offset + device offset */ if (type != CX18_ENC_STREAM_TYPE_MPG) { struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG]; if (s_mpg->v4l2dev) num = s_mpg->v4l2dev->num + cx18_stream_info[type].num_offset; } /* Register device. First try the desired minor, then any free one. */ ret = video_register_device(s->v4l2dev, vfl_type, num); if (ret < 0) { CX18_ERR("Couldn't register v4l2 device for %s kernel number %d\n", s->name, num); video_device_release(s->v4l2dev); s->v4l2dev = NULL; return ret; } num = s->v4l2dev->num; switch (vfl_type) { case VFL_TYPE_GRABBER: CX18_INFO("Registered device video%d for %s (%d MB)\n", num, s->name, cx->options.megabytes[type]); break; case VFL_TYPE_RADIO: CX18_INFO("Registered device radio%d for %s\n", num, s->name); break; case VFL_TYPE_VBI: if (cx->options.megabytes[type]) CX18_INFO("Registered device vbi%d for %s (%d MB)\n", num, s->name, cx->options.megabytes[type]); else CX18_INFO("Registered device vbi%d for %s\n", num, s->name); break; } return 0;}/* Register v4l2 devices */int cx18_streams_register(struct cx18 *cx){ int type; int err; int ret = 0; /* Register V4L2 devices */ for (type = 0; type < CX18_MAX_STREAMS; type++) { err = cx18_reg_dev(cx, type); if (err && ret == 0) ret = err; } if (ret == 0) return 0; /* One or more streams could not be initialized. Clean 'em all up. */ cx18_streams_cleanup(cx, 1); return ret;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?