1 /*****************************************************************************
2 * access.c : V4L2 compressed byte stream input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2011 the VideoLAN team
6 * Authors: Benjamin Pracht <bigben at videolan dot org>
7 * Richard Hosking <richard at hovis dot net>
8 * Antoine Cellerier <dionoea at videolan d.t org>
9 * Dennis Lou <dlou99 at yahoo dot com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
31 #include <vlc_access.h>
36 static block_t *AccessRead( access_t * );
37 static ssize_t AccessReadStream( access_t *, uint8_t *, size_t );
38 static int AccessControl( access_t *, int, va_list );
40 int AccessOpen( vlc_object_t *obj )
42 access_t *access = (access_t *)obj;
44 access_InitFields( access );
46 demux_sys_t *sys = calloc( 1, sizeof( demux_sys_t ));
47 if( unlikely(sys == NULL) )
49 access->p_sys = (access_sys_t *)sys;
51 ParseMRL( obj, access->psz_location );
52 sys->i_fd = OpenVideo( obj, sys, false );
59 if( sys->io == IO_METHOD_READ )
60 access->pf_read = AccessReadStream;
62 access->pf_block = AccessRead;
63 access->pf_seek = NULL;
64 access->pf_control = AccessControl;
68 void AccessClose( vlc_object_t *obj )
70 access_t *access = (access_t *)obj;
71 demux_sys_t *sys = (demux_sys_t *)access->p_sys;
73 ControlsDeinit( obj, sys->controls );
74 v4l2_close( sys->i_fd );
78 static block_t *AccessRead( access_t *access )
80 demux_sys_t *sys = (demux_sys_t *)access->p_sys;
84 fd.events = POLLIN|POLLPRI;
88 /* FIXME: kill timeout */
89 if( poll( &fd, 1, 500 ) <= 0 )
92 block_t *block = GrabVideo( VLC_OBJECT(access), sys );
95 block->i_pts = block->i_dts = mdate();
96 block->i_flags |= sys->i_block_flags;
101 static ssize_t AccessReadStream( access_t *access, uint8_t *buf, size_t len )
103 demux_sys_t *sys = (demux_sys_t *)access->p_sys;
110 if( access->info.b_eof )
113 /* FIXME: kill timeout and vlc_object_alive() */
116 if( !vlc_object_alive(access) )
121 while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );
126 msg_Err( access, "poll error: %m" );
130 i_ret = v4l2_read( sys->i_fd, buf, len );
132 access->info.b_eof = true;
134 access->info.i_pos += i_ret;
139 static int AccessControl( access_t *access, int query, va_list args )
144 case ACCESS_CAN_SEEK:
145 case ACCESS_CAN_FASTSEEK:
146 case ACCESS_CAN_PAUSE:
147 case ACCESS_CAN_CONTROL_PACE:
148 *va_arg( args, bool* ) = false;
152 case ACCESS_GET_PTS_DELAY:
153 *va_arg(args,int64_t *) = INT64_C(1000)
154 * var_InheritInteger( access, "live-caching" );
158 case ACCESS_SET_PAUSE_STATE:
162 case ACCESS_GET_TITLE_INFO:
163 case ACCESS_SET_TITLE:
164 case ACCESS_SET_SEEKPOINT:
165 case ACCESS_SET_PRIVATE_ID_STATE:
166 case ACCESS_GET_CONTENT_TYPE:
167 case ACCESS_GET_META:
171 msg_Warn( access, "Unimplemented query %d in control", query );