[vlc-devel] [RFC PATCH 1/2] libvlc: media: remove usage of ssize_t
Thomas Guillem
thomas at gllm.fr
Fri Jul 22 14:26:52 CEST 2016
It's in POSIX but not in C standard.
---
include/vlc/libvlc_media.h | 10 +++++-----
modules/access/imem-access.c | 13 ++++++-------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index 15933c5..d7b7aab 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -318,18 +318,18 @@ typedef int (*libvlc_media_open_cb)(void *opaque, void **datap,
* \param opaque private pointer as set by the @ref libvlc_media_open_cb
* callback
* \param buf start address of the buffer to read data into
- * \param len bytes length of the buffer
+ * \param len bytes length of the buffer. The callback should set the number of
+ * bytes that is actually read (0 on end-of-stream) [IN/OUT]
*
- * \return strictly positive number of bytes read, 0 on end-of-stream,
- * or -1 on non-recoverable error
+ * \return 0 on success, -1 on error.
*
* \note If no data is immediately available, then the callback should sleep.
* \warning The application is responsible for avoiding deadlock situations.
* In particular, the callback should return an error if playback is stopped;
* if it does not return, then libvlc_media_player_stop() will never return.
*/
-typedef ssize_t (*libvlc_media_read_cb)(void *opaque, unsigned char *buf,
- size_t len);
+typedef int (*libvlc_media_read_cb)(void *opaque, unsigned char *buf,
+ size_t *len);
/**
* Callback prototype to seek a custom bitstream input media.
diff --git a/modules/access/imem-access.c b/modules/access/imem-access.c
index d7a80bb..5921a7e 100644
--- a/modules/access/imem-access.c
+++ b/modules/access/imem-access.c
@@ -31,7 +31,7 @@
struct access_sys_t
{
void *opaque;
- ssize_t (*read_cb)(void *, unsigned char *, size_t);
+ int (*read_cb)(void *, unsigned char *, size_t *);
int (*seek_cb)(void *, uint64_t);
void (*close_cb)(void *);
uint64_t size;
@@ -41,14 +41,13 @@ static ssize_t Read(access_t *access, void *buf, size_t len)
{
access_sys_t *sys = access->p_sys;
- ssize_t val = sys->read_cb(sys->opaque, buf, len);
-
- if (val < 0) {
+ if (sys->read_cb(sys->opaque, buf, &len) < 0)
+ {
msg_Err(access, "read error");
- val = 0;
+ return 0;
}
-
- return val;
+ else
+ return len;
}
static int Seek(access_t *access, uint64_t offset)
--
2.8.1
More information about the vlc-devel
mailing list