[vlc-commits] ytdl: use custom function for input

Rémi Denis-Courmont git at videolan.org
Wed Sep 30 20:53:11 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Sep 30 21:33:26 2020 +0300| [e68f793d3dc041162506f789cfd1b5135718bae6] | committer: Rémi Denis-Courmont

ytdl: use custom function for input

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e68f793d3dc041162506f789cfd1b5135718bae6
---

 modules/demux/json/grammar.y |  4 +---
 modules/demux/json/json.h    |  3 ++-
 modules/demux/json/lexicon.l |  6 ++++++
 modules/demux/ytdl.c         | 12 ++++++++++--
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/modules/demux/json/grammar.y b/modules/demux/json/grammar.y
index d6b3b31c0d..3f8eb0a236 100644
--- a/modules/demux/json/grammar.y
+++ b/modules/demux/json/grammar.y
@@ -154,7 +154,6 @@ static void yyerror(void *log, void *scanner, struct json_object *result,
 }
 
 extern int yylex_init_extra(void *, void **);
-extern void yyset_in(FILE *, void *);
 extern int yylex(YYSTYPE *value, void *scanner);
 extern int yylex_destroy(void *);
 
@@ -214,7 +213,7 @@ value:
 
 %%
 
-int json_parse(void *opaque, FILE *in, struct json_object *result)
+int json_parse(void *opaque, struct json_object *result)
 {
 	void *scanner;
 	int ret = yylex_init_extra(opaque, &scanner);
@@ -222,7 +221,6 @@ int json_parse(void *opaque, FILE *in, struct json_object *result)
 	if (ret)
 		return ret;
 
-	yyset_in(in, scanner);
 	ret = yyparse(opaque, scanner, result);
 	yylex_destroy(scanner);
 	return ret;
diff --git a/modules/demux/json/json.h b/modules/demux/json/json.h
index e468ec871f..8274ceb652 100644
--- a/modules/demux/json/json.h
+++ b/modules/demux/json/json.h
@@ -59,10 +59,11 @@ struct json_member {
     struct json_value value;
 };
 
+size_t json_read(void *data, void *buf, size_t max);
 void json_parse_error(void *log, const char *msg);
 char *json_unescape(const char *, size_t);
 
-int json_parse(void *log, FILE *in, struct json_object *result);
+int json_parse(void *log, struct json_object *result);
 void json_free(struct json_object *);
 
 const struct json_value *json_get(const struct json_object *obj,
diff --git a/modules/demux/json/lexicon.l b/modules/demux/json/lexicon.l
index 8b8a8b8ab5..51780dad49 100644
--- a/modules/demux/json/lexicon.l
+++ b/modules/demux/json/lexicon.l
@@ -38,6 +38,12 @@
 #include "json.h"
 #include "grammar.h"
 
+#define YY_INPUT(buf,result,size) \
+{ \
+    size_t len = json_read(yyextra, buf, size); \
+    result = (len > 0) ? len : YY_NULL; \
+}
+
 %}
 
 %%
diff --git a/modules/demux/ytdl.c b/modules/demux/ytdl.c
index 243d9dc143..97f4443072 100644
--- a/modules/demux/ytdl.c
+++ b/modules/demux/ytdl.c
@@ -39,6 +39,7 @@
 
 struct ytdl_json {
     struct vlc_logger *logger;
+    FILE *input;
 };
 
 void json_parse_error(void *data, const char *msg)
@@ -48,6 +49,13 @@ void json_parse_error(void *data, const char *msg)
     vlc_error(sys->logger, "%s", msg);
 }
 
+size_t json_read(void *data, void *buf, size_t size)
+{
+    struct ytdl_json *sys = data;
+
+    return fread(buf, 1, size, sys->input);
+}
+
 static
 FILE *vlc_popen(pid_t *restrict pid, const char *argv[])
 {
@@ -355,8 +363,8 @@ static int OpenCommon(vlc_object_t *obj)
 
     free(path);
 
-    struct ytdl_json jsdata = { s->obj.logger };
-    int val = json_parse(&jsdata, input, &sys->json);
+    struct ytdl_json jsdata = { s->obj.logger, input };
+    int val = json_parse(&jsdata, &sys->json);
 
     kill(pid, SIGTERM);
     fclose(input);



More information about the vlc-commits mailing list