4 /*****************************************************************************
5 * Copyright © 2016 Rémi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Rémi Denis-Courmont reserves the right to redistribute this file under
13 * the terms of the GNU Lesser General Public License as published by the
14 * the Free Software Foundation; either version 2.1 or the License, or
15 * (at his option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
37 #include <vlc_common.h>
38 #include <vlc_access.h>
39 #include <vlc_block.h>
40 #include <vlc_demux.h>
41 #include <vlc_es_out.h>
43 #include "../lib/libvlc_internal.h"
47 #include "demux-run.h"
52 struct es_out_id_t *ids;
57 struct es_out_id_t *next;
60 static es_out_id_t *EsOutAdd(es_out_t *out, const es_format_t *fmt)
62 struct test_es_out_t *ctx = (struct test_es_out_t *) out;
67 es_out_id_t *id = malloc(sizeof (*id));
68 if (unlikely(id == NULL))
74 debug("[%p] Added ES\n", (void *)id);
78 static void EsOutCheckId(es_out_t *out, es_out_id_t *id)
80 struct test_es_out_t *ctx = (struct test_es_out_t *) out;
82 for (es_out_id_t *ids = ctx->ids; ids != NULL; ids = ids->next)
89 static int EsOutSend(es_out_t *out, es_out_id_t *id, block_t *block)
91 //debug("[%p] Sent ES: %zu\n", (void *)idd, block->i_buffer);
92 EsOutCheckId(out, id);
97 static void EsOutDelete(es_out_t *out, es_out_id_t *id)
99 struct test_es_out_t *ctx = (struct test_es_out_t *) out;
100 es_out_id_t **pp = &ctx->ids;
109 debug("[%p] Deleted ES\n", (void *)id);
114 static int EsOutControl(es_out_t *out, int query, va_list args)
120 case ES_OUT_RESTART_ES:
122 case ES_OUT_SET_ES_DEFAULT:
123 case ES_OUT_SET_ES_STATE:
125 case ES_OUT_GET_ES_STATE:
126 EsOutCheckId(out, va_arg(args, es_out_id_t *));
127 *va_arg(args, bool *) = true;
129 case ES_OUT_SET_ES_CAT_POLICY:
131 case ES_OUT_SET_GROUP:
134 case ES_OUT_SET_GROUP_PCR:
135 case ES_OUT_RESET_PCR:
136 case ES_OUT_SET_ES_FMT:
137 case ES_OUT_SET_NEXT_DISPLAY_TIME:
138 case ES_OUT_SET_GROUP_META:
139 case ES_OUT_SET_GROUP_EPG:
140 case ES_OUT_DEL_GROUP:
141 case ES_OUT_SET_ES_SCRAMBLED_STATE:
143 case ES_OUT_GET_EMPTY:
144 *va_arg(args, bool *) = true;
146 case ES_OUT_SET_META:
148 case ES_OUT_GET_PCR_SYSTEM:
149 case ES_OUT_MODIFY_PCR_SYSTEM:
157 static void EsOutDestroy(es_out_t *out)
159 struct test_es_out_t *ctx = (struct test_es_out_t *)out;
162 while ((id = ctx->ids) != NULL)
170 static es_out_t *test_es_out_create(vlc_object_t *parent)
172 struct test_es_out_t *ctx = malloc(sizeof (*ctx));
175 fprintf(stderr, "Error: cannot create ES output.\n");
181 es_out_t *out = &ctx->out;
182 out->pf_add = EsOutAdd;
183 out->pf_send = EsOutSend;
184 out->pf_del = EsOutDelete;
185 out->pf_control = EsOutControl;
186 out->pf_destroy = EsOutDestroy;
187 out->p_sys = (void *)parent;
192 static int demux_process_stream(const struct vlc_run_args *args, stream_t *s)
194 const char *name = args->name;
201 es_out_t *out = test_es_out_create(VLC_OBJECT(s));
205 demux_t *demux = demux_New(VLC_OBJECT(s), name, "", s, out);
209 vlc_stream_Delete(s);
210 debug("Error: cannot create demultiplexer: %s\n", name);
217 while ((val = demux_Demux(demux)) == VLC_DEMUXER_SUCCESS)
223 debug("Completed with %ju iteration(s).\n", i);
225 return val == VLC_DEMUXER_EOF ? 0 : -1;
228 int vlc_demux_process_url(const struct vlc_run_args *args, const char *url)
230 libvlc_instance_t *vlc = libvlc_create(args);
234 stream_t *s = vlc_access_NewMRL(VLC_OBJECT(vlc->p_libvlc_int), url);
236 fprintf(stderr, "Error: cannot create input stream: %s\n", url);
238 int ret = demux_process_stream(args, s);
243 int vlc_demux_process_path(const struct vlc_run_args *args, const char *path)
245 char *url = vlc_path2uri(path, NULL);
248 fprintf(stderr, "Error: cannot convert path to URL: %s\n", path);
252 int ret = vlc_demux_process_url(args, url);
257 int vlc_demux_process_memory(const struct vlc_run_args *args,
258 const unsigned char *buf, size_t length)
260 libvlc_instance_t *vlc = libvlc_create(args);
264 stream_t *s = vlc_stream_MemoryNew(VLC_OBJECT(vlc->p_libvlc_int),
265 (void *)buf, length, true);
267 fprintf(stderr, "Error: cannot create input stream\n");
269 int ret = demux_process_stream(args, s);
274 #ifdef HAVE_STATIC_MODULES
275 # include <vlc_plugin.h>
277 typedef int (*vlc_plugin_cb)(int (*)(void *, void *, int, ...), void *);
278 extern vlc_plugin_cb vlc_static_modules[];
323 # define PLUGIN_TS(f) f(ts)
325 # define PLUGIN_TS(f)
328 #define DECL_PLUGIN(p) \
329 int vlc_entry__##p(int (*)(void *, void *, int, ...), void *);
331 #define FUNC_PLUGIN(p) \
336 __attribute__((visibility("default")))
337 vlc_plugin_cb vlc_static_modules[] = { PLUGINS(FUNC_PLUGIN) NULL };
338 #endif /* HAVE_STATIC_MODULES */