qt: svg support for pixmapanimator
[vlc.git] / modules / access / sdp.c
blobaea2d5ba441c0501f7497b25282c803ffb7f923e
1 /*****************************************************************************
2 * sdp.c: Fake input for sdp:// scheme
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_access.h>
29 static int Open (vlc_object_t *);
31 vlc_module_begin ()
32 set_shortname (N_("SDP"))
33 set_description (N_("Session Description Protocol"))
34 set_category (CAT_INPUT)
35 set_subcategory (SUBCAT_INPUT_ACCESS)
37 set_capability ("access", 0)
38 set_callbacks (Open, NULL)
39 add_shortcut ("sdp")
40 vlc_module_end()
42 static ssize_t Read (stream_t *, void *, size_t);
43 static int Seek (stream_t *, uint64_t);
44 static int Control (stream_t *, int, va_list);
46 struct access_sys_t
48 size_t offset;
49 size_t length;
50 char data[];
53 static int Open (vlc_object_t *obj)
55 stream_t *access = (stream_t *)obj;
56 size_t len = strlen (access->psz_location);
58 access_sys_t *sys = vlc_malloc(obj, sizeof(*sys) + len);
59 if (unlikely(sys == NULL))
60 return VLC_ENOMEM;
62 /* NOTE: This copy is not really needed. Better safe than sorry. */
63 sys->offset = 0;
64 sys->length = len;
65 memcpy (sys->data, access->psz_location, len);
67 access->pf_read = Read;
68 access->pf_block = NULL;
69 access->pf_seek = Seek;
70 access->pf_control = Control;
71 access->p_sys = sys;
73 return VLC_SUCCESS;
76 static ssize_t Read (stream_t *access, void *buf, size_t len)
78 access_sys_t *sys = access->p_sys;
80 if (sys->offset >= sys->length)
81 return 0;
83 if (len > sys->length - sys->offset)
84 len = sys->length - sys->offset;
85 memcpy (buf, sys->data + sys->offset, len);
86 return len;
89 static int Seek (stream_t *access, uint64_t position)
91 access_sys_t *sys = access->p_sys;
93 if (position > sys->length)
94 position = sys->length;
96 sys->offset = position;
97 return VLC_SUCCESS;
100 static int Control (stream_t *access, int query, va_list args)
102 access_sys_t *sys = access->p_sys;
104 switch (query)
106 case STREAM_CAN_SEEK:
107 case STREAM_CAN_FASTSEEK:
108 case STREAM_CAN_PAUSE:
109 case STREAM_CAN_CONTROL_PACE:
111 bool *b = va_arg(args, bool*);
112 *b = true;
113 return VLC_SUCCESS;
116 case STREAM_GET_SIZE:
117 *va_arg(args, uint64_t *) = sys->length;
118 return VLC_SUCCESS;
120 case STREAM_GET_PTS_DELAY:
122 int64_t *dp = va_arg(args, int64_t *);
123 *dp = DEFAULT_PTS_DELAY;
124 return VLC_SUCCESS;
127 case STREAM_SET_PAUSE_STATE:
128 return VLC_SUCCESS;
130 return VLC_EGENERIC;