[vlc-commits] sdp: simplify
Rémi Denis-Courmont
git at videolan.org
Sun Dec 10 15:03:53 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec 10 16:03:13 2017 +0200| [13bf37748ea9a60b9ac4ca594612910e0506988b] | committer: Rémi Denis-Courmont
sdp: simplify
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13bf37748ea9a60b9ac4ca594612910e0506988b
---
modules/access/sdp.c | 51 ++++++++++++++++++---------------------------------
1 file changed, 18 insertions(+), 33 deletions(-)
diff --git a/modules/access/sdp.c b/modules/access/sdp.c
index d781ad9330..fc7efa3fc4 100644
--- a/modules/access/sdp.c
+++ b/modules/access/sdp.c
@@ -22,6 +22,9 @@
# include "config.h"
#endif
+#include <limits.h>
+#include <string.h>
+
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_access.h>
@@ -43,62 +46,44 @@ static ssize_t Read (stream_t *, void *, size_t);
static int Seek (stream_t *, uint64_t);
static int Control (stream_t *, int, va_list);
-struct access_sys_t
-{
- size_t offset;
- size_t length;
-};
-
static int Open (vlc_object_t *obj)
{
stream_t *access = (stream_t *)obj;
- size_t len = strlen (access->psz_location);
-
- access_sys_t *sys = vlc_obj_malloc(obj, sizeof(*sys));
- if (unlikely(sys == NULL))
- return VLC_ENOMEM;
-
- sys->offset = 0;
- sys->length = len;
access->pf_read = Read;
access->pf_block = NULL;
access->pf_seek = Seek;
access->pf_control = Control;
- access->p_sys = sys;
+ access->p_sys = (char *)access->psz_location;
return VLC_SUCCESS;
}
static ssize_t Read (stream_t *access, void *buf, size_t len)
{
- access_sys_t *sys = access->p_sys;
+ char *in = access->p_sys, *out = buf;
+ size_t i;
- if (sys->offset >= sys->length)
- return 0;
+ for (i = 0; i < len && *in != '\0'; i++)
+ *(out++) = *(in++);
- if (len > sys->length - sys->offset)
- len = sys->length - sys->offset;
- memcpy(buf, access->psz_location + sys->offset, len);
- sys->offset += len;
- return len;
+ access->p_sys = in;
+ return i;
}
static int Seek (stream_t *access, uint64_t position)
{
- access_sys_t *sys = access->p_sys;
-
- if (position > sys->length)
- position = sys->length;
-
- sys->offset = position;
+#if (UINT64_MAX > SIZE_MAX)
+ if (unlikely(position > SIZE_MAX))
+ position = SIZE_MAX;
+#endif
+ access->p_sys = (char *)access->psz_location
+ + strnlen(access->psz_location, position);
return VLC_SUCCESS;
}
static int Control (stream_t *access, int query, va_list args)
{
- access_sys_t *sys = access->p_sys;
-
switch (query)
{
case STREAM_CAN_SEEK:
@@ -106,13 +91,13 @@ static int Control (stream_t *access, int query, va_list args)
case STREAM_CAN_PAUSE:
case STREAM_CAN_CONTROL_PACE:
{
- bool *b = va_arg(args, bool*);
+ bool *b = va_arg(args, bool *);
*b = true;
return VLC_SUCCESS;
}
case STREAM_GET_SIZE:
- *va_arg(args, uint64_t *) = sys->length;
+ *va_arg(args, uint64_t *) = strlen(access->psz_location);
return VLC_SUCCESS;
case STREAM_GET_PTS_DELAY:
More information about the vlc-commits
mailing list