[vlc-devel] [PATCH] input: Add input_item_parser_id_Interrupt

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Jun 20 14:39:07 CEST 2019


This effectively split input_item_parser_id_Release in 2 functions,
allowing an asynchronous cancellation to occur.
Otherwise, the input thread would invoke the callback synchronously
while the thread cancelling the preparser is blocked joining the input
thread. Both those thread are very likely to be called with a mutex
held, which would cause a deadlock.
---
 include/vlc_input_item.h | 14 +++++++++++++-
 src/input/item.c         |  8 +++++++-
 src/libvlccore.sym       |  1 +
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index b68c24dc49..1e94b842a2 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -421,7 +421,7 @@ typedef struct input_item_parser_cbs_t
  * Parse an item asynchronously
  *
  * @note The parsing is done asynchronously. The user can call
- * input_item_parser_id_Release() before receiving the on_ended() event in
+ * input_item_parser_id_Interrupt() before receiving the on_ended() event in
  * order to interrupt it.
  *
  * @param item the item to parse
@@ -436,6 +436,18 @@ VLC_API input_item_parser_id_t *
 input_item_Parse(input_item_t *item, vlc_object_t *parent,
                  const input_item_parser_cbs_t *cbs, void *userdata) VLC_USED;
 
+/**
+ * Interrupts & cancels the parsing
+ *
+ * @note The parser still needs to be released with input_item_parser_id_Release
+ * afterward.
+ * @note Calling this function will cause the on_ended callback to be invoked.
+ *
+ * @param the parser to interrupt
+ */
+VLC_API void
+input_item_parser_id_Interrupt(input_item_parser_id_t *parser);
+
 /**
  * Release (and interrupt if needed) a parser
  *
diff --git a/src/input/item.c b/src/input/item.c
index ac79336540..b1b92cdf9b 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1405,9 +1405,15 @@ input_item_Parse(input_item_t *item, vlc_object_t *obj,
 }
 
 void
-input_item_parser_id_Release(input_item_parser_id_t *parser)
+input_item_parser_id_Interrupt(input_item_parser_id_t *parser)
 {
     input_Stop(parser->input);
+}
+
+void
+input_item_parser_id_Release(input_item_parser_id_t *parser)
+{
+    input_item_parser_id_Interrupt(parser);
     input_Close(parser->input);
     free(parser);
 }
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 6c59e1b6fc..64a6c0123b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -204,6 +204,7 @@ input_item_slave_GetType
 input_item_slave_New
 input_item_AddSlave
 input_item_Parse
+input_item_parser_id_Interrupt
 input_item_parser_id_Release
 input_resource_New
 input_resource_Release
-- 
2.20.1



More information about the vlc-devel mailing list