imem.c 18.9 KB
Newer Older
1 2 3
/*****************************************************************************
 * imem.c : Memory input for VLC
 *****************************************************************************
Laurent Aimar's avatar
Laurent Aimar committed
4
 * Copyright (C) 2009-2010 Laurent Aimar
5 6 7 8
 * $Id$
 *
 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28 29 30 31 32 33 34 35
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <limits.h>
#include <math.h>

#include <vlc_common.h>
#include <vlc_plugin.h>
36
#include <vlc_access.h>
37 38 39 40 41 42
#include <vlc_demux.h>
#include <vlc_charset.h>

/*****************************************************************************
 * Module descriptior
 *****************************************************************************/
43 44 45
static int  OpenAccess (vlc_object_t *);
static void CloseAccess(vlc_object_t *);

Laurent Aimar's avatar
Laurent Aimar committed
46 47
static int  OpenDemux (vlc_object_t *);
static void CloseDemux(vlc_object_t *);
48 49 50 51 52 53 54 55 56 57 58 59 60

#define ID_TEXT N_("ID")
#define ID_LONGTEXT N_(\
    "Set the ID of the elementary stream")

#define GROUP_TEXT N_("Group")
#define GROUP_LONGTEXT N_(\
    "Set the group of the elementary stream")

#define CAT_TEXT N_("Category")
#define CAT_LONGTEXT N_(\
    "Set the category of the elementary stream")
static const int cat_values[] = {
61
    0, 1, 2, 3, 4,
62 63
};
static const char *cat_texts[] = {
64
    N_("Unknown"), N_("Audio"), N_("Video"), N_("Subtitle"), N_("Data")
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
};

#define CODEC_TEXT N_("Codec")
#define CODEC_LONGTEXT N_(\
    "Set the codec of the elementary stream")

#define LANGUAGE_TEXT N_("Language")
#define LANGUAGE_LONGTEXT N_(\
    "Language of the elementary stream as described by ISO639")

#define SAMPLERATE_TEXT N_("Sample rate")
#define SAMPLERATE_LONGTEXT N_(\
    "Sample rate of an audio elementary stream")

#define CHANNELS_TEXT N_("Channels count")
#define CHANNELS_LONGTEXT N_(\
    "Channels count of an audio elementary stream")

#define WIDTH_TEXT N_("Width")
#define WIDTH_LONGTEXT N_("Width of video or subtitle elementary streams")

#define HEIGHT_TEXT N_("Height")
#define HEIGHT_LONGTEXT N_("Height of video or subtitle elementary streams")

#define DAR_TEXT N_("Display aspect ratio")
#define DAR_LONGTEXT N_(\
    "Display aspect ratio of a video elementary stream")

#define FPS_TEXT N_("Frame rate")
#define FPS_LONGTEXT N_(\
    "Frame rate of a video elementary stream")

97 98 99 100
#define COOKIE_TEXT N_("Callback cookie string")
#define COOKIE_LONGTEXT N_(\
    "Text identifier for the callback functions")

101 102 103 104 105 106 107 108 109 110 111 112
#define DATA_TEXT N_("Callback data")
#define DATA_LONGTEXT N_(\
    "Data for the get and release functions")

#define GET_TEXT N_("Get function")
#define GET_LONGTEXT N_(\
    "Address of the get callback function")

#define RELEASE_TEXT N_("Release function")
#define RELEASE_LONGTEXT N_(\
    "Address of the release callback function")

113 114 115 116
#define SIZE_TEXT N_("Size")
#define SIZE_LONGTEXT N_(\
    "Size of stream in bytes")

117 118 119 120 121 122
vlc_module_begin()
    set_shortname(N_("Memory input"))
    set_description(N_("Memory input"))
    set_category(CAT_INPUT)
    set_subcategory(SUBCAT_INPUT_ACCESS)

123
    add_string ("imem-get", "0", GET_TEXT, GET_LONGTEXT, true)
124
        change_volatile()
125
    add_string ("imem-release", "0", RELEASE_TEXT, RELEASE_LONGTEXT, true)
126
        change_volatile()
127
    add_string ("imem-cookie", NULL, COOKIE_TEXT, COOKIE_LONGTEXT, true)
128
        change_volatile()
129
        change_safe()
130
    add_string ("imem-data", "0", DATA_TEXT, DATA_LONGTEXT, true)
131
        change_volatile()
132

133
    add_integer("imem-id", -1, ID_TEXT, ID_LONGTEXT, true)
134
        change_private()
135
        change_safe()
136
    add_integer("imem-group", 0, GROUP_TEXT, GROUP_LONGTEXT, true)
137
        change_private()
138
        change_safe()
139
    add_integer("imem-cat", 0, CAT_TEXT, CAT_LONGTEXT, true)
140
        change_integer_list(cat_values, cat_texts)
141
        change_private()
142
        change_safe()
143
    add_string ("imem-codec", NULL, CODEC_TEXT, CODEC_LONGTEXT, true)
144
        change_private()
145
        change_safe()
146
    add_string( "imem-language", NULL, LANGUAGE_TEXT, LANGUAGE_LONGTEXT, false)
147
        change_private()
148
        change_safe()
149

150
    add_integer("imem-samplerate", 0, SAMPLERATE_TEXT, SAMPLERATE_LONGTEXT, true)
151
        change_private()
152
        change_safe()
153
    add_integer("imem-channels", 0, CHANNELS_TEXT, CHANNELS_LONGTEXT, true)
154
        change_private()
155
        change_safe()
156

157
    add_integer("imem-width", 0, WIDTH_TEXT, WIDTH_LONGTEXT, true)
158
        change_private()
159
        change_safe()
160
    add_integer("imem-height", 0, HEIGHT_TEXT, HEIGHT_LONGTEXT, true)
161
        change_private()
162
        change_safe()
163
    add_string ("imem-dar", NULL, DAR_TEXT, DAR_LONGTEXT, true)
164
        change_private()
165
        change_safe()
166
    add_string ("imem-fps", NULL, FPS_TEXT, FPS_LONGTEXT, true)
167
        change_private()
168
        change_safe()
169

170
    add_integer ("imem-size", 0, SIZE_TEXT, SIZE_LONGTEXT, true)
171 172 173
        change_private()
        change_safe()

174 175
    add_shortcut("imem")
    set_capability("access_demux", 0)
Laurent Aimar's avatar
Laurent Aimar committed
176
    set_callbacks(OpenDemux, CloseDemux)
177 178 179 180 181

    add_submodule()
        add_shortcut("imem")
        set_capability("access", 0)
        set_callbacks(OpenAccess, CloseAccess)
182 183 184 185 186 187 188 189 190 191 192
vlc_module_end()

/*****************************************************************************
 * Exported API
 *****************************************************************************/

/* The clock origin for the DTS and PTS is assumed to be 0.
 * A negative value means unknown.
 *
 * TODO define flags
 */
193
typedef int  (*imem_get_t)(void *data, const char *cookie,
194 195
                           int64_t *dts, int64_t *pts, unsigned *flags,
                           size_t *, void **);
196
typedef void (*imem_release_t)(void *data, const char *cookie, size_t, void *);
197 198 199 200 201 202

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/

/* */
203 204 205
static block_t *Block(access_t *);
static int ControlAccess(access_t *, int, va_list);

206
static int Demux(demux_t *);
Laurent Aimar's avatar
Laurent Aimar committed
207
static int ControlDemux(demux_t *, int, va_list);
208 209

/* */
Laurent Aimar's avatar
Laurent Aimar committed
210
typedef struct {
211 212 213
    struct {
        imem_get_t      get;
        imem_release_t  release;
214 215
        void           *data;
        char           *cookie;
216 217 218 219 220 221 222
    } source;

    es_out_id_t  *es;

    mtime_t      dts;

    mtime_t      deadline;
Laurent Aimar's avatar
Laurent Aimar committed
223 224 225
} imem_sys_t;

static void ParseMRL(vlc_object_t *, const char *);
226

Laurent Aimar's avatar
Laurent Aimar committed
227 228 229 230 231 232 233 234
/**
 * It closes the common part of the access and access_demux
 */
static void CloseCommon(imem_sys_t *sys)
{
    free(sys->source.cookie);
    free(sys);
}
235 236

/**
Laurent Aimar's avatar
Laurent Aimar committed
237
 * It initializes the common part for imem access/access_demux.
238
 */
Laurent Aimar's avatar
Laurent Aimar committed
239
static int OpenCommon(vlc_object_t *object, imem_sys_t **sys_ptr, const char *psz_path)
240 241 242
{
    char *tmp;

243
    /* */
Laurent Aimar's avatar
Laurent Aimar committed
244
    imem_sys_t *sys = calloc(1, sizeof(*sys));
245 246
    if (!sys)
        return VLC_ENOMEM;
247 248

    /* Read the user functions */
249
    tmp = var_InheritString(object, "imem-get");
250 251 252 253
    if (tmp)
        sys->source.get = (imem_get_t)(intptr_t)strtoll(tmp, NULL, 0);
    free(tmp);

254
    tmp = var_InheritString(object, "imem-release");
255 256 257 258 259
    if (tmp)
        sys->source.release = (imem_release_t)(intptr_t)strtoll(tmp, NULL, 0);
    free(tmp);

    if (!sys->source.get || !sys->source.release) {
Laurent Aimar's avatar
Laurent Aimar committed
260
        msg_Err(object, "Invalid get/release function pointers");
261 262 263 264
        free(sys);
        return VLC_EGENERIC;
    }

265
    tmp = var_InheritString(object, "imem-data");
266
    if (tmp)
267
        sys->source.data = (void *)(uintptr_t)strtoull(tmp, NULL, 0);
268 269
    free(tmp);

270 271
    /* Now we can parse the MRL (get/release must not be parsed to avoid
     * security risks) */
Laurent Aimar's avatar
Laurent Aimar committed
272 273
    if (*psz_path)
        ParseMRL(object, psz_path);
274

Laurent Aimar's avatar
Laurent Aimar committed
275
    sys->source.cookie = var_InheritString(object, "imem-cookie");
276

Laurent Aimar's avatar
Laurent Aimar committed
277
    msg_Dbg(object, "Using get(%p), release(%p), data(%p), cookie(%s)",
278 279
            sys->source.get, sys->source.release, sys->source.data,
            sys->source.cookie ? sys->source.cookie : "(null)");
280

Laurent Aimar's avatar
Laurent Aimar committed
281 282 283 284 285 286 287 288
    /* */
    sys->dts       = 0;
    sys->deadline  = VLC_TS_INVALID;

    *sys_ptr = sys;
    return VLC_SUCCESS;
}

289 290 291 292 293 294 295 296
/**
 * It opens an imem access.
 */
static int OpenAccess(vlc_object_t *object)
{
    access_t   *access = (access_t *)object;
    imem_sys_t *sys;

297
    if (OpenCommon(object, &sys, access->psz_location))
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
        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)
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
331
    (void) access;
332 333 334 335 336 337 338 339 340 341 342 343 344 345
    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;
    }
346 347 348 349 350
    case ACCESS_GET_SIZE: {
        uint64_t *s = va_arg(args, uint64_t *);
        *s = var_InheritInteger(access, "imem-size");
        return VLC_SUCCESS;
    }
351 352
    case ACCESS_GET_PTS_DELAY: {
        int64_t *delay = va_arg(args, int64_t *);
353
        *delay = DEFAULT_PTS_DELAY; /* FIXME? */
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
        return VLC_SUCCESS;
    }
    case ACCESS_SET_PAUSE_STATE:
        return VLC_SUCCESS;

    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) {
384
        block = block_Alloc(buffer_size);
385 386 387 388 389 390 391 392 393
        if (block)
            memcpy(block->p_buffer, buffer, buffer_size);
    }

    sys->source.release(sys->source.data, sys->source.cookie,
                        buffer_size, buffer);
    return block;
}

Laurent Aimar's avatar
Laurent Aimar committed
394 395 396 397 398 399 400 401
/**
 * It opens an imem access_demux.
 */
static int OpenDemux(vlc_object_t *object)
{
    demux_t    *demux = (demux_t *)object;
    imem_sys_t *sys;

402
    if (OpenCommon(object, &sys, demux->psz_location))
Laurent Aimar's avatar
Laurent Aimar committed
403 404
        return VLC_EGENERIC;

405
    /* ES format */
406
    es_format_t fmt;
407
    es_format_Init(&fmt, UNKNOWN_ES, 0);
408

409 410
    fmt.i_id = var_InheritInteger(object, "imem-id");
    fmt.i_group = var_InheritInteger(object, "imem-group");
411

412
    char *tmp = var_InheritString(object, "imem-codec");
413 414 415 416
    if (tmp)
        fmt.i_codec = vlc_fourcc_GetCodecFromString(UNKNOWN_ES, tmp);
    free(tmp);

417 418
    const int cat = var_InheritInteger(object, "imem-cat");
    switch (cat) {
419 420
    case 1: {
        fmt.i_cat = AUDIO_ES;
421 422
        fmt.audio.i_channels = var_InheritInteger(object, "imem-channels");
        fmt.audio.i_rate = var_InheritInteger(object, "imem-samplerate");
423

Laurent Aimar's avatar
Laurent Aimar committed
424
        msg_Dbg(object, "Audio %4.4s %d channels %d Hz",
425 426 427 428 429 430
                (const char *)&fmt.i_codec,
                fmt.audio.i_channels, fmt.audio.i_rate);
        break;
    }
    case 2: {
        fmt.i_cat = VIDEO_ES;
431 432
        fmt.video.i_width  = var_InheritInteger(object, "imem-width");
        fmt.video.i_height = var_InheritInteger(object, "imem-height");
433
        unsigned num, den;
434
        if (!var_InheritURational(object, &num, &den, "imem-dar") && num > 0 && den > 0) {
435 436 437 438 439
            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;
            }
        }
440
        if (!var_InheritURational(object, &num, &den, "imem-fps") && num > 0 && den > 0) {
441 442 443 444
            fmt.video.i_frame_rate      = num;
            fmt.video.i_frame_rate_base = den;
        }

Laurent Aimar's avatar
Laurent Aimar committed
445
        msg_Dbg(object, "Video %4.4s %dx%d  SAR %d:%d frame rate %u/%u",
446 447 448 449 450 451 452 453 454
                (const char *)&fmt.i_codec,
                fmt.video.i_width, fmt.video.i_height,
                fmt.video.i_sar_num, fmt.video.i_sar_den,
                fmt.video.i_frame_rate, fmt.video.i_frame_rate_base);
        break;
    }
    case 3: {
        fmt.i_cat = SPU_ES;
        fmt.subs.spu.i_original_frame_width =
455
            var_InheritInteger(object, "imem-width");
456
        fmt.subs.spu.i_original_frame_height =
457
            var_InheritInteger(object, "imem-height");
458

Laurent Aimar's avatar
Laurent Aimar committed
459
        msg_Dbg(object, "Subtitle %4.4s",
460 461 462 463
                (const char *)&fmt.i_codec);
        break;
    }
    default:
464 465
        if (cat != 4)
            msg_Err(object, "Invalid ES category");
466
        es_format_Clean(&fmt);
Laurent Aimar's avatar
Laurent Aimar committed
467
        CloseCommon(sys);
468 469 470
        return VLC_EGENERIC;
    }

471
    fmt.psz_language = var_InheritString(object, "imem-language");
472

473
    sys->es = es_out_Add(demux->out, &fmt);
474 475 476
    es_format_Clean(&fmt);

    if (!sys->es) {
Laurent Aimar's avatar
Laurent Aimar committed
477
        CloseCommon(sys);
478 479 480 481
        return VLC_EGENERIC;
    }

    /* */
Laurent Aimar's avatar
Laurent Aimar committed
482
    demux->pf_control = ControlDemux;
483
    demux->pf_demux   = Demux;
Laurent Aimar's avatar
Laurent Aimar committed
484
    demux->p_sys      = (demux_sys_t*)sys;
485 486 487 488 489 490 491 492 493 494

    demux->info.i_update = 0;
    demux->info.i_title = 0;
    demux->info.i_seekpoint = 0;
    return VLC_SUCCESS;
}

/**
 * It closes an imem access_demux
 */
Laurent Aimar's avatar
Laurent Aimar committed
495
static void CloseDemux(vlc_object_t *object)
496
{
Laurent Aimar's avatar
Laurent Aimar committed
497
    demux_t *demux = (demux_t *)object;
498

Laurent Aimar's avatar
Laurent Aimar committed
499
    CloseCommon((imem_sys_t*)demux->p_sys);
500 501 502
}

/**
503
 * It controls an imem access_demux
504
 */
Laurent Aimar's avatar
Laurent Aimar committed
505
static int ControlDemux(demux_t *demux, int i_query, va_list args)
506
{
Laurent Aimar's avatar
Laurent Aimar committed
507
    imem_sys_t *sys = (imem_sys_t*)demux->p_sys;
508 509 510 511 512 513 514 515 516 517 518 519 520 521

    switch (i_query)
    {
    case DEMUX_CAN_PAUSE:
    case DEMUX_CAN_CONTROL_PACE: {
        bool *b = va_arg(args, bool *);
        *b = true;
        return VLC_SUCCESS;
    }
    case DEMUX_SET_PAUSE_STATE:
        return VLC_SUCCESS;

    case DEMUX_GET_PTS_DELAY: {
        int64_t *delay = va_arg(args, int64_t *);
522
        *delay = DEFAULT_PTS_DELAY; /* FIXME? */
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
        return VLC_SUCCESS;
    }
    case DEMUX_GET_POSITION: {
        double *position = va_arg(args, double *);
        *position = 0.0;
        return VLC_SUCCESS;
    }
    case DEMUX_GET_TIME: {
        int64_t *t = va_arg(args, int64_t *);
        *t = sys->dts;
        return VLC_SUCCESS;
    }
    case DEMUX_GET_LENGTH: {
        int64_t *l = va_arg(args, int64_t *);
        *l = 0;
        return VLC_SUCCESS;
    }
    case DEMUX_SET_NEXT_DEMUX_TIME:
        sys->deadline = va_arg(args, int64_t);
        return VLC_SUCCESS;

    /* */
    case DEMUX_CAN_SEEK:
    case DEMUX_SET_POSITION:
    case DEMUX_SET_TIME:
    default:
        return VLC_EGENERIC;
    }

    return VLC_EGENERIC;
}

/**
 * It retreives data using the get() callback, sends them to es_out
 * and the release it using the release() callback.
 */
static int Demux(demux_t *demux)
{
Laurent Aimar's avatar
Laurent Aimar committed
561
    imem_sys_t *sys = (imem_sys_t*)demux->p_sys;
562 563 564 565 566 567 568 569 570 571 572 573 574 575

    if (sys->deadline == VLC_TS_INVALID)
        sys->deadline = sys->dts + 1;

    for (;;) {
        if (sys->deadline <= sys->dts)
            break;

        /* */
        int64_t dts, pts;
        unsigned flags;
        size_t buffer_size;
        void   *buffer;

576 577
        if (sys->source.get(sys->source.data, sys->source.cookie,
                            &dts, &pts, &flags, &buffer_size, &buffer))
578 579 580 581 582 583
            return 0;

        if (dts < 0)
            dts = pts;

        if (buffer_size > 0) {
584
            block_t *block = block_Alloc(buffer_size);
585 586 587 588 589 590 591 592 593 594 595 596
            if (block) {
                block->i_dts = dts >= 0 ? (1 + dts) : VLC_TS_INVALID;
                block->i_pts = pts >= 0 ? (1 + pts) : VLC_TS_INVALID;
                memcpy(block->p_buffer, buffer, buffer_size);

                es_out_Control(demux->out, ES_OUT_SET_PCR, block->i_dts);
                es_out_Send(demux->out, sys->es, block);
            }
        }

        sys->dts = dts;

597 598
        sys->source.release(sys->source.data, sys->source.cookie,
                            buffer_size, buffer);
599 600 601 602 603 604 605 606 607 608 609 610
    }
    sys->deadline = VLC_TS_INVALID;
    return 1;
}

/**
 * Parse the MRL and extract configuration from it.
 *
 * Syntax: option1=value1[:option2=value2[...]]
 *
 * XXX get and release are not supported on purpose.
 */
Laurent Aimar's avatar
Laurent Aimar committed
611
static void ParseMRL(vlc_object_t *object, const char *psz_path)
612 613 614 615 616 617 618 619 620 621 622 623
{
    static const struct {
        const char *name;
        int        type;
    } options[] = {
        { "id",         VLC_VAR_INTEGER },
        { "group",      VLC_VAR_INTEGER },
        { "cat",        VLC_VAR_INTEGER },
        { "samplerate", VLC_VAR_INTEGER },
        { "channels",   VLC_VAR_INTEGER },
        { "width",      VLC_VAR_INTEGER },
        { "height",     VLC_VAR_INTEGER },
624
        { "cookie",     VLC_VAR_STRING },
625 626 627 628 629 630 631
        { "codec",      VLC_VAR_STRING },
        { "language",   VLC_VAR_STRING },
        { "dar",        VLC_VAR_STRING },
        { "fps",        VLC_VAR_STRING },
        { NULL, -1 }
    };

Laurent Aimar's avatar
Laurent Aimar committed
632
    char *dup = strdup(psz_path);
633 634 635 636 637 638 639 640 641 642 643 644 645
    if (!dup)
        return;
    char *current = dup;

    while (current) {
        char *next = strchr(current, ':');
        if (next)
            *next++ = '\0';

        char *option = current;
        char *value = strchr(current, '=');
        if (value) {
            *value++ = '\0';
Laurent Aimar's avatar
Laurent Aimar committed
646
            msg_Dbg(object, "option '%s' value '%s'", option, value);
647
        } else {
Laurent Aimar's avatar
Laurent Aimar committed
648
            msg_Dbg(object, "option '%s' without value (unsupported)", option);
649 650 651 652 653 654 655 656 657
        }

        char *name;
        if (asprintf(&name, "imem-%s", option) < 0)
            name = NULL;
        for (unsigned i = 0; name && options[i].name; i++) {
            if (strcmp(options[i].name, option))
                continue;
            /* */
Laurent Aimar's avatar
Laurent Aimar committed
658
            var_Create(object, name, options[i].type | VLC_VAR_DOINHERIT);
659
            if (options[i].type == VLC_VAR_INTEGER && value) {
Laurent Aimar's avatar
Laurent Aimar committed
660
                var_SetInteger(object, name, strtol(value, NULL, 0));
661
            } else if (options[i].type == VLC_VAR_STRING && value) {
Laurent Aimar's avatar
Laurent Aimar committed
662
                var_SetString(object, name, value);
663 664 665 666 667 668 669 670 671 672
            }
            break;
        }
        free(name);

        /* */
        current = next;
    }
    free(dup);
}