[vlc-devel] [PATCH] lib: New API to use imem for access.
Mark Lee
mark.lee at capricasoftware.co.uk
Mon Jan 13 14:48:14 CET 2014
---
include/vlc/libvlc_media_player.h | 71 +++++++++++++++++++++++++++++++++++++++
lib/libvlc.sym | 1 +
lib/media_player.c | 38 +++++++++++++++++++++
3 files changed, 110 insertions(+)
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 27f7b97..bdd0bd0 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -635,6 +635,77 @@ LIBVLC_API
void libvlc_audio_set_format( libvlc_media_player_t *mp, const char *format,
unsigned rate, unsigned channels );
+/**
+ * Callback function to get more data for the memory access method (imem).
+ *
+ * The buffer will be subsequently relinquished via the corresponding
+ * libvlc_memory_release_cb.
+ *
+ * The client buffer must remain valid until the release callback is invoked.
+ *
+ * The imem access method provides both for demux and access.
+ *
+ * When using imem for access, the data buffer is expected to contain the 'raw'
+ * data (e.g. reading from a stream). In this case the DTS and PTS callback
+ * parameters are not used and will be NULL.
+ *
+ * When using imem for demux, the data buffer is expected to contain one of
+ * audio, video or subtitle data and the LibVLC application is expected to
+ * provide correct DTS and PTS values as appropriate.
+ *
+ * \param data opaque pointer
+ * \param cookie text identifier
+ * \param dts display timestamp (for demux), otherwise NULL (for access)
+ * \param pts presentation timestamp (for demux), otherwise NULL (for access)
+ * \param flags flags
+ * \param buffer_size size of the buffer containing the data
+ * \param buffer pointer to the application buffer containing the data
+ */
+typedef int (*libvlc_memory_get_cb)(void *data, const char *cookie,
+ int64_t *dts, int64_t *pts, unsigned *flags,
+ size_t *buffer_size, void **buffer);
+
+/**
+ * Callback function to relinquish the data buffer used for the memory access
+ * method (imem).
+ *
+ * The buffer was previously acquired via the corresponding libvlc_memory_get_cb.
+ *
+ * \param data opaque pointer
+ * \param cookie text identifier
+ * \param buffer_size size of the buffer to release
+ * \param buffer pointer to the buffer to release
+ */
+typedef void (*libvlc_memory_release_cb)(void *data, const char *cookie,
+ size_t buffer_size, void *buffer);
+
+/**
+ * Setup memory access callbacks (imem).
+ *
+ * This is used to provide 'raw' media data from an in-memory buffer (e.g.
+ * reading a stream into a buffer).
+ *
+ * A LibVLC application uses the 'get' callback to provide access to the data -
+ * the buffer containing this data must remain valid until the corresponding
+ * 'release' callback is invoked.
+ *
+ * The 'data' and 'cookie' parameters can contain optional application-specific
+ * values.
+ *
+ * \param mp the media player
+ * \param get callback function to get data
+ * \param release callback function to release data
+ * \param data opaque pointer
+ * \param cookie text identifier
+ * \return zero on success, non-zero on error
+ * \version LibVLC 2.2.0 or later
+ */
+LIBVLC_API
+int libvlc_memory_set_access_callbacks( libvlc_media_player_t *mp,
+ libvlc_memory_get_cb get,
+ libvlc_memory_release_cb release,
+ void *data, const char *cookie );
+
/** \bug This might go away ... to be replaced by a broader system */
/**
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 7c99668..edf560c 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -186,6 +186,7 @@ libvlc_media_set_user_data
libvlc_media_subitems
libvlc_media_tracks_get
libvlc_media_tracks_release
+libvlc_memory_set_access_callbacks
libvlc_new
libvlc_playlist_play
libvlc_release
diff --git a/lib/media_player.c b/lib/media_player.c
index c23dd42..45e67a4 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -458,6 +458,13 @@ libvlc_media_player_new( libvlc_instance_t *instance )
var_Create (mp, "amem-rate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
var_Create (mp, "amem-channels", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+ /* Memory */
+ var_Create (mp, "imem-get", VLC_VAR_STRING);
+ var_Create (mp, "imem-release", VLC_VAR_STRING);
+ var_Create (mp, "imem-data", VLC_VAR_STRING);
+ var_Create (mp, "imem-cookie", VLC_VAR_STRING);
+ var_Create (mp, "imem-cat", VLC_VAR_INTEGER);
+
/* Video Title */
var_Create (mp, "video-title-show", VLC_VAR_BOOL);
var_Create (mp, "video-title-position", VLC_VAR_INTEGER);
@@ -981,6 +988,37 @@ void libvlc_audio_set_format( libvlc_media_player_t *mp, const char *format,
var_SetInteger( mp, "amem-channels", channels );
}
+int libvlc_memory_set_access_callbacks( libvlc_media_player_t *mp,
+ libvlc_memory_get_cb get,
+ libvlc_memory_release_cb release,
+ void *data, const char *cookie)
+{
+ char *buf;
+
+ if ( asprintf( &buf, "%p", get ) == -1 )
+ return -1;
+
+ var_SetString( mp, "imem-get", buf );
+ free( buf );
+
+ if ( asprintf( &buf, "%p", release ) == -1 )
+ return -1;
+
+ var_SetString( mp, "imem-release", buf );
+ free( buf );
+
+ if ( asprintf( &buf, "%p", data ) == -1 )
+ return -1;
+
+ var_SetString( mp, "imem-data", buf );
+ free( buf );
+
+ var_SetString( mp, "imem-cookie", cookie );
+
+ var_SetInteger( mp, "imem-cat", 4 );
+
+ return 0;
+}
/**************************************************************************
* Getters for stream information
--
1.8.1.2
More information about the vlc-devel
mailing list