1 /*****************************************************************************
2 * v4l.c : Video4Linux input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: v4l.c,v 1.1 2002/08/08 00:35:10 sam Exp $
7 * Author: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <vlc/input.h>
30 #include <sys/types.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int V4lOpen ( vlc_object_t * );
38 static void V4lClose ( vlc_object_t * );
39 static int V4lRead ( input_thread_t *, byte_t *, size_t );
41 /*****************************************************************************
43 *****************************************************************************/
45 set_description( _("Video4Linux input module") );
46 set_capability( "access", 80 );
47 set_callbacks( V4lOpen, V4lClose );
52 /*****************************************************************************
53 * V4lOpen: open device
54 *****************************************************************************/
55 static int V4lOpen( vlc_object_t *p_this )
57 input_thread_t * p_input = (input_thread_t *)p_this;
59 p_input->pf_read = V4lRead;
60 p_input->pf_seek = NULL;
61 p_input->pf_set_area = NULL;
62 p_input->pf_set_program = NULL;
64 vlc_mutex_lock( &p_input->stream.stream_lock );
65 p_input->stream.b_pace_control = 0;
66 p_input->stream.b_seekable = 0;
67 p_input->stream.p_selected_area->i_size = 0;
68 p_input->stream.p_selected_area->i_tell = 0;
69 p_input->stream.i_method = INPUT_METHOD_FILE;
70 vlc_mutex_unlock( &p_input->stream.stream_lock );
72 i_fd = open( "/dev/v4l/video0", O_RDWR );
77 /*****************************************************************************
78 * V4lClose: close device
79 *****************************************************************************/
80 static void V4lClose( vlc_object_t *p_this )
82 input_thread_t * p_input = (input_thread_t *)p_this;
83 //thread_data_t *p_data = (thread_data_t *)p_input->p_access_data;
85 //close( p_data->i_handle );
90 /*****************************************************************************
91 * V4lRead: reads from the device into PES packets.
92 *****************************************************************************
93 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
95 *****************************************************************************/
99 static int V4lRead( input_thread_t * p_input, byte_t * p_buffer,
102 struct video_capability vid_caps;
103 struct video_mbuf vid_buf;
104 struct video_mmap vid_mmap;
108 //thread_data_t * p_data;
111 if( ioctl( i_fd, VIDIOCGCAP, &vid_caps ) == -1 )
113 printf("ioctl (VIDIOCGCAP) failed\n");
117 if( ioctl( i_fd, VIDIOCGMBUF, &vid_buf ) == -1 )
119 // to do a normal read()
120 map = malloc (WIDTH * HEIGHT * 3);
121 len = read (fd_webcam, map, WIDTH * HEIGHT * 3);
131 //p_data = (thread_data_t *)p_input->p_access_data;