]> git.sesse.net Git - vlc/blobdiff - modules/access/imem.c
live555: fix RTSP URL when it contains no path part
[vlc] / modules / access / imem.c
index e5cce1caea6ef3fc6d1683af980bf2bb865161b2..ab41aade581773f1438dfddf940d64f0327a74b2 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
+#include <vlc_access.h>
 #include <vlc_demux.h>
 #include <vlc_charset.h>
 
 /*****************************************************************************
  * Module descriptior
  *****************************************************************************/
+static int  OpenAccess (vlc_object_t *);
+static void CloseAccess(vlc_object_t *);
+
 static int  OpenDemux (vlc_object_t *);
 static void CloseDemux(vlc_object_t *);
 
@@ -59,10 +63,10 @@ static void CloseDemux(vlc_object_t *);
 #define CAT_LONGTEXT N_(\
     "Set the category of the elementary stream")
 static const int cat_values[] = {
-    0, 1, 2, 3
+    0, 1, 2, 3, 4,
 };
 static const char *cat_texts[] = {
-    N_("Unknown"), N_("Audio"), N_("Video"), N_("Subtitle")
+    N_("Unknown"), N_("Audio"), N_("Video"), N_("Subtitle"), N_("Data")
 };
 
 #define CODEC_TEXT N_("Codec")
@@ -169,6 +173,11 @@ vlc_module_begin()
     add_shortcut("imem")
     set_capability("access_demux", 0)
     set_callbacks(OpenDemux, CloseDemux)
+
+    add_submodule()
+        add_shortcut("imem")
+        set_capability("access", 0)
+        set_callbacks(OpenAccess, CloseAccess)
 vlc_module_end()
 
 /*****************************************************************************
@@ -190,6 +199,9 @@ typedef void (*imem_release_t)(void *data, const char *cookie, size_t, void *);
  *****************************************************************************/
 
 /* */
+static block_t *Block(access_t *);
+static int ControlAccess(access_t *, int, va_list);
+
 static int Demux(demux_t *);
 static int ControlDemux(demux_t *, int, va_list);
 
@@ -212,10 +224,10 @@ typedef struct {
 } imem_sys_t;
 
 static void ParseMRL(vlc_object_t *, const char *);
-#define var_CreateGetRational(a,b,c,d) var_CreateGetRational(VLC_OBJECT(a),b,c,d)
-static int (var_CreateGetRational)(vlc_object_t *,
-                                   unsigned *num, unsigned *den,
-                                   const char *var);
+#define var_InheritRational(a,b,c,d) var_InheritRational(VLC_OBJECT(a),b,c,d)
+static int (var_InheritRational)(vlc_object_t *,
+                                 unsigned *num, unsigned *den,
+                                 const char *var);
 
 /**
  * It closes the common part of the access and access_demux
@@ -233,18 +245,18 @@ static int OpenCommon(vlc_object_t *object, imem_sys_t **sys_ptr, const char *ps
 {
     char *tmp;
 
-       /* */
+    /* */
     imem_sys_t *sys = calloc(1, sizeof(*sys));
-       if (!sys)
-               return VLC_ENOMEM;
+    if (!sys)
+        return VLC_ENOMEM;
 
     /* Read the user functions */
-    tmp = var_CreateGetString(object, "imem-get");
+    tmp = var_InheritString(object, "imem-get");
     if (tmp)
         sys->source.get = (imem_get_t)(intptr_t)strtoll(tmp, NULL, 0);
     free(tmp);
 
-    tmp = var_CreateGetString(object, "imem-release");
+    tmp = var_InheritString(object, "imem-release");
     if (tmp)
         sys->source.release = (imem_release_t)(intptr_t)strtoll(tmp, NULL, 0);
     free(tmp);
@@ -255,7 +267,7 @@ static int OpenCommon(vlc_object_t *object, imem_sys_t **sys_ptr, const char *ps
         return VLC_EGENERIC;
     }
 
-    tmp = var_CreateGetString(object, "imem-data");
+    tmp = var_InheritString(object, "imem-data");
     if (tmp)
         sys->source.data = (void *)(uintptr_t)strtoull(tmp, NULL, 0);
     free(tmp);
@@ -272,7 +284,7 @@ static int OpenCommon(vlc_object_t *object, imem_sys_t **sys_ptr, const char *ps
             sys->source.cookie ? sys->source.cookie : "(null)");
 
     /* */
-    sys->pts_delay = var_CreateGetInteger(object, "imem-caching") * INT64_C(1000);
+    sys->pts_delay = var_InheritInteger(object, "imem-caching") * INT64_C(1000);
     sys->dts       = 0;
     sys->deadline  = VLC_TS_INVALID;
 
@@ -280,6 +292,114 @@ static int OpenCommon(vlc_object_t *object, imem_sys_t **sys_ptr, const char *ps
     return VLC_SUCCESS;
 }
 
+/**
+ * It opens an imem access.
+ */
+static int OpenAccess(vlc_object_t *object)
+{
+    access_t   *access = (access_t *)object;
+    imem_sys_t *sys;
+
+    if (OpenCommon(object, &sys, access->psz_path))
+        return VLC_EGENERIC;
+
+    if (var_InheritInteger(object, "imem-cat") != 4) {
+        CloseCommon(sys);
+        return VLC_EGENERIC;
+    }
+
+    /* */
+    access_InitFields(access);
+    access->pf_control = ControlAccess;
+    access->pf_read    = NULL;
+    access->pf_block   = Block;
+    access->pf_seek    = NULL;
+    access->p_sys      = (access_sys_t*)sys;
+
+    return VLC_SUCCESS;
+}
+
+/**
+ * It closes an imem access
+ */
+static void CloseAccess(vlc_object_t *object)
+{
+    access_t *access = (access_t *)object;
+
+    CloseCommon((imem_sys_t*)access->p_sys);
+}
+
+/**
+ * It controls an imem access
+ */
+static int ControlAccess(access_t *access, int i_query, va_list args)
+{
+    imem_sys_t *sys = (imem_sys_t*)access->p_sys;
+
+    switch (i_query)
+    {
+    case ACCESS_CAN_SEEK:
+    case ACCESS_CAN_FASTSEEK: {
+        bool *b = va_arg( args, bool* );
+        *b = false;
+        return VLC_SUCCESS;
+    }
+    case ACCESS_CAN_PAUSE:
+    case ACCESS_CAN_CONTROL_PACE: {
+        bool *b = va_arg( args, bool* );
+        *b = true;
+        return VLC_SUCCESS;
+    }
+    case ACCESS_GET_PTS_DELAY: {
+        int64_t *delay = va_arg(args, int64_t *);
+        *delay = sys->pts_delay;
+        return VLC_SUCCESS;
+    }
+    case ACCESS_SET_PAUSE_STATE:
+        return VLC_SUCCESS;
+
+    case ACCESS_GET_TITLE_INFO:
+    case ACCESS_SET_TITLE:
+    case ACCESS_SET_SEEKPOINT:
+    case ACCESS_SET_PRIVATE_ID_STATE:
+    case ACCESS_GET_META:
+    case ACCESS_GET_PRIVATE_ID_STATE:
+    case ACCESS_GET_CONTENT_TYPE:
+    default:
+        return VLC_EGENERIC;
+    }
+}
+
+/**
+ * It retreives data using the get() callback, copies them,
+ * and then release them using the release() callback.
+ */
+static block_t *Block(access_t *access)
+{
+    imem_sys_t *sys = (imem_sys_t*)access->p_sys;
+
+    unsigned flags;
+    size_t buffer_size;
+    void   *buffer;
+
+    if (sys->source.get(sys->source.data, sys->source.cookie,
+                        NULL, NULL, &flags, &buffer_size, &buffer)) {
+        access->info.b_eof = true;
+        return NULL;
+    }
+
+    block_t *block = NULL;
+    if (buffer_size > 0) {
+        block = block_New(access, buffer_size);
+        if (block)
+            memcpy(block->p_buffer, buffer, buffer_size);
+    }
+
+    sys->source.release(sys->source.data, sys->source.cookie,
+                        buffer_size, buffer);
+    return block;
+}
+
 /**
  * It opens an imem access_demux.
  */
@@ -288,26 +408,27 @@ static int OpenDemux(vlc_object_t *object)
     demux_t    *demux = (demux_t *)object;
     imem_sys_t *sys;
 
-    if (OpenCommon(VLC_OBJECT(demux), &sys, demux->psz_path))
+    if (OpenCommon(object, &sys, demux->psz_path))
         return VLC_EGENERIC;
 
-       /* ES format */
+    /* ES format */
     es_format_t fmt;
-       es_format_Init(&fmt, UNKNOWN_ES, 0);
+    es_format_Init(&fmt, UNKNOWN_ES, 0);
 
-    fmt.i_id = var_CreateGetInteger(object, "imem-id");
-    fmt.i_group = var_CreateGetInteger(object, "imem-group");
+    fmt.i_id = var_InheritInteger(object, "imem-id");
+    fmt.i_group = var_InheritInteger(object, "imem-group");
 
-    char *tmp = var_CreateGetString(object, "imem-codec");
+    char *tmp = var_InheritString(object, "imem-codec");
     if (tmp)
         fmt.i_codec = vlc_fourcc_GetCodecFromString(UNKNOWN_ES, tmp);
     free(tmp);
 
-    switch (var_CreateGetInteger(object, "imem-cat")) {
+    const int cat = var_InheritInteger(object, "imem-cat");
+    switch (cat) {
     case 1: {
         fmt.i_cat = AUDIO_ES;
-        fmt.audio.i_channels = var_CreateGetInteger(object, "imem-channels");
-        fmt.audio.i_rate = var_CreateGetInteger(object, "imem-samplerate");
+        fmt.audio.i_channels = var_InheritInteger(object, "imem-channels");
+        fmt.audio.i_rate = var_InheritInteger(object, "imem-samplerate");
 
         msg_Dbg(object, "Audio %4.4s %d channels %d Hz",
                 (const char *)&fmt.i_codec,
@@ -316,16 +437,16 @@ static int OpenDemux(vlc_object_t *object)
     }
     case 2: {
         fmt.i_cat = VIDEO_ES;
-        fmt.video.i_width  = var_CreateGetInteger(object, "imem-width");
-        fmt.video.i_height = var_CreateGetInteger(object, "imem-height");
+        fmt.video.i_width  = var_InheritInteger(object, "imem-width");
+        fmt.video.i_height = var_InheritInteger(object, "imem-height");
         unsigned num, den;
-        if (!var_CreateGetRational(object, &num, &den, "imem-dar") && num > 0 && den > 0) {
+        if (!var_InheritRational(object, &num, &den, "imem-dar") && num > 0 && den > 0) {
             if (fmt.video.i_width > 0 && fmt.video.i_height > 0) {
                 fmt.video.i_sar_num = num * fmt.video.i_height;
                 fmt.video.i_sar_den = den * fmt.video.i_width;
             }
         }
-        if (!var_CreateGetRational(object, &num, &den, "imem-fps") && num > 0 && den > 0) {
+        if (!var_InheritRational(object, &num, &den, "imem-fps") && num > 0 && den > 0) {
             fmt.video.i_frame_rate      = num;
             fmt.video.i_frame_rate_base = den;
         }
@@ -340,24 +461,25 @@ static int OpenDemux(vlc_object_t *object)
     case 3: {
         fmt.i_cat = SPU_ES;
         fmt.subs.spu.i_original_frame_width =
-            var_CreateGetInteger(object, "imem-width");
+            var_InheritInteger(object, "imem-width");
         fmt.subs.spu.i_original_frame_height =
-            var_CreateGetInteger(object, "imem-height");
+            var_InheritInteger(object, "imem-height");
 
         msg_Dbg(object, "Subtitle %4.4s",
                 (const char *)&fmt.i_codec);
         break;
     }
     default:
-        msg_Err(object, "Invalid ES category");
+        if (cat != 4)
+            msg_Err(object, "Invalid ES category");
         es_format_Clean(&fmt);
         CloseCommon(sys);
         return VLC_EGENERIC;
     }
 
-    fmt.psz_language = var_CreateGetString(object, "imem-language");
+    fmt.psz_language = var_InheritString(object, "imem-language");
 
-       sys->es = es_out_Add(demux->out, &fmt);
+    sys->es = es_out_Add(demux->out, &fmt);
     es_format_Clean(&fmt);
 
     if (!sys->es) {
@@ -387,7 +509,7 @@ static void CloseDemux(vlc_object_t *object)
 }
 
 /**
- * It controls imem
+ * It controls an imem access_demux
  */
 static int ControlDemux(demux_t *demux, int i_query, va_list args)
 {
@@ -493,16 +615,16 @@ static int Demux(demux_t *demux)
  *
  * It returns an error if the rational number cannot be parsed (0/0 is valid).
  */
-static int (var_CreateGetRational)(vlc_object_t *object,
-                                   unsigned *num, unsigned *den,
-                                   const char *var)
+static int (var_InheritRational)(vlc_object_t *object,
+                                 unsigned *num, unsigned *den,
+                                 const char *var)
 {
     /* */
     *num = 0;
     *den = 0;
 
     /* */
-    char *tmp = var_CreateGetString(object, var);
+    char *tmp = var_InheritString(object, var);
     if (!tmp)
         goto error;