160
160
static void cx18_dualwatch(struct cx18 *cx)
162
162
struct v4l2_tuner vt;
164
163
u32 new_stereo_mode;
165
const u32 stereo_mask = 0x0300;
166
164
const u32 dual = 0x0200;
169
new_stereo_mode = cx->params.audio_properties & stereo_mask;
166
new_stereo_mode = v4l2_ctrl_g_ctrl(cx->cxhdl.audio_mode);
170
167
memset(&vt, 0, sizeof(vt));
171
168
cx18_call_all(cx, tuner, g_tuner, &vt);
172
169
if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 &&
176
173
if (new_stereo_mode == cx->dualwatch_stereo_mode)
179
new_bitmap = new_stereo_mode
180
| (cx->params.audio_properties & ~stereo_mask);
182
CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. "
183
"new audio_bitmask=0x%ux\n",
184
cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
186
h = cx18_find_handle(cx);
187
if (h == CX18_INVALID_TASK_HANDLE) {
188
CX18_DEBUG_INFO("dualwatch: can't find valid task handle\n");
193
CX18_CPU_SET_AUDIO_PARAMETERS, 2, h, new_bitmap) == 0) {
194
cx->dualwatch_stereo_mode = new_stereo_mode;
197
CX18_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
176
CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x.\n",
177
cx->dualwatch_stereo_mode, new_stereo_mode);
178
if (v4l2_ctrl_s_ctrl(cx->cxhdl.audio_mode, new_stereo_mode))
179
CX18_DEBUG_INFO("dualwatch: changing stereo flag failed\n");
603
585
ssize_t cx18_v4l2_read(struct file *filp, char __user *buf, size_t count,
606
struct cx18_open_id *id = filp->private_data;
588
struct cx18_open_id *id = file2id(filp);
607
589
struct cx18 *cx = id->cx;
608
590
struct cx18_stream *s = &cx->streams[id->type];
615
597
mutex_unlock(&cx->serialize_lock);
601
if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
602
(id->type == CX18_ENC_STREAM_TYPE_YUV)) {
603
return videobuf_read_stream(&s->vbuf_q, buf, count, pos, 0,
604
filp->f_flags & O_NONBLOCK);
618
607
return cx18_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK);
621
610
unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait)
623
struct cx18_open_id *id = filp->private_data;
612
struct cx18_open_id *id = file2id(filp);
624
613
struct cx18 *cx = id->cx;
625
614
struct cx18_stream *s = &cx->streams[id->type];
626
615
int eof = test_bit(CX18_F_S_STREAMOFF, &s->s_flags);
640
629
CX18_DEBUG_FILE("Encoder poll started capture\n");
632
if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
633
(id->type == CX18_ENC_STREAM_TYPE_YUV)) {
634
int videobuf_poll = videobuf_poll_stream(filp, &s->vbuf_q, wait);
635
if (eof && videobuf_poll == POLLERR)
638
return videobuf_poll;
643
641
/* add stream's waitq to the poll list */
644
642
CX18_DEBUG_HI_FILE("Encoder poll\n");
645
643
poll_wait(filp, &s->waitq, wait);
652
int cx18_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
654
struct cx18_open_id *id = file->private_data;
655
struct cx18 *cx = id->cx;
656
struct cx18_stream *s = &cx->streams[id->type];
657
int eof = test_bit(CX18_F_S_STREAMOFF, &s->s_flags);
659
if ((s->vb_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) &&
660
(id->type == CX18_ENC_STREAM_TYPE_YUV)) {
662
/* Start a capture if there is none */
663
if (!eof && !test_bit(CX18_F_S_STREAMING, &s->s_flags)) {
666
mutex_lock(&cx->serialize_lock);
667
rc = cx18_start_capture(id);
668
mutex_unlock(&cx->serialize_lock);
671
"Could not start capture for %s (%d)\n",
675
CX18_DEBUG_FILE("Encoder mmap started capture\n");
678
return videobuf_mmap_mapper(&s->vbuf_q, vma);
684
void cx18_vb_timeout(unsigned long data)
686
struct cx18_stream *s = (struct cx18_stream *)data;
687
struct cx18_videobuf_buffer *buf;
690
/* Return all of the buffers in error state, so the vbi/vid inode
691
* can return from blocking.
693
spin_lock_irqsave(&s->vb_lock, flags);
694
while (!list_empty(&s->vb_capture)) {
695
buf = list_entry(s->vb_capture.next,
696
struct cx18_videobuf_buffer, vb.queue);
697
list_del(&buf->vb.queue);
698
buf->vb.state = VIDEOBUF_ERROR;
699
wake_up(&buf->vb.done);
701
spin_unlock_irqrestore(&s->vb_lock, flags);
654
704
void cx18_stop_capture(struct cx18_open_id *id, int gop_end)
656
706
struct cx18 *cx = id->cx;
695
745
int cx18_v4l2_close(struct file *filp)
697
struct cx18_open_id *id = filp->private_data;
747
struct v4l2_fh *fh = filp->private_data;
748
struct cx18_open_id *id = fh2id(fh);
698
749
struct cx18 *cx = id->cx;
699
750
struct cx18_stream *s = &cx->streams[id->type];
701
752
CX18_DEBUG_IOCTL("close() of %s\n", s->name);
703
v4l2_prio_close(&cx->prio, id->prio);
705
757
/* Easy case first: this stream was never claimed by us */
706
758
if (s->id != id->open_id) {
724
776
if (atomic_read(&cx->ana_capturing) > 0) {
725
777
/* Undo video mute */
726
778
cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle,
727
cx->params.video_mute |
728
(cx->params.video_mute_yuv << 8));
779
(v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute) |
780
(v4l2_ctrl_g_ctrl(cx->cxhdl.video_mute_yuv) << 8)));
730
782
/* Done! Unmute and continue. */
732
784
cx18_release_stream(s);
734
786
cx18_stop_capture(id, 0);
787
if (id->type == CX18_ENC_STREAM_TYPE_YUV)
788
videobuf_mmap_free(&id->vbuf_q);
737
791
mutex_unlock(&cx->serialize_lock);
746
800
CX18_DEBUG_FILE("open %s\n", s->name);
748
802
/* Allocate memory */
749
item = kmalloc(sizeof(struct cx18_open_id), GFP_KERNEL);
803
item = kzalloc(sizeof(struct cx18_open_id), GFP_KERNEL);
750
804
if (NULL == item) {
751
805
CX18_DEBUG_WARN("nomem on v4l2 open\n");
808
v4l2_fh_init(&item->fh, s->video_dev);
755
811
item->type = s->type;
756
v4l2_prio_open(&cx->prio, &item->prio);
758
813
item->open_id = cx->open_id++;
759
filp->private_data = item;
814
filp->private_data = &item->fh;
761
816
if (item->type == CX18_ENC_STREAM_TYPE_RAD) {
762
817
/* Try to claim this stream */
763
818
if (cx18_claim_stream(item, item->type)) {
764
819
/* No, it's already in use */
820
v4l2_fh_exit(&item->fh);