[vlc-commits] input: more precise title events
Thomas Guillem
git at videolan.org
Wed Sep 12 16:36:11 CEST 2018
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Sep 11 17:50:09 2018 +0200| [13170b58b4cb5ff62a54a825174dd4cd7116b390] | committer: Thomas Guillem
input: more precise title events
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=13170b58b4cb5ff62a54a825174dd4cd7116b390
---
include/vlc_input.h | 19 ++++++++++++++++++-
src/input/event.h | 5 +++--
src/input/input.c | 30 +++++++++++++++++++++++-------
src/input/var.c | 4 ++--
4 files changed, 46 insertions(+), 12 deletions(-)
diff --git a/include/vlc_input.h b/include/vlc_input.h
index 30c6e4b366..afdcde8816 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -402,6 +402,23 @@ struct vlc_input_event_position
vlc_tick_t ms;
};
+struct vlc_input_event_title
+{
+ enum {
+ VLC_INPUT_TITLE_NEW_LIST,
+ VLC_INPUT_TITLE_SELECTED,
+ } action;
+ union
+ {
+ struct
+ {
+ const input_title_t **array;
+ size_t count;
+ } list;
+ size_t selected_idx;
+ };
+};
+
struct vlc_input_event_chapter
{
int title;
@@ -474,7 +491,7 @@ struct vlc_input_event
/* INPUT_EVENT_LENGTH */
vlc_tick_t length;
/* INPUT_EVENT_TITLE */
- int title;
+ struct vlc_input_event_title title;
/* INPUT_EVENT_CHAPTER */
struct vlc_input_event_chapter chapter;
/* INPUT_EVENT_PROGRAM */
diff --git a/src/input/event.h b/src/input/event.h
index 6027b3e06f..7b0b1ebcd3 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -118,11 +118,12 @@ static inline void input_SendEventRecord(input_thread_t *p_input,
});
}
-static inline void input_SendEventTitle(input_thread_t *p_input, int i_title)
+static inline void input_SendEventTitle(input_thread_t *p_input,
+ const struct vlc_input_event_title *title)
{
input_SendEvent(p_input, &(struct vlc_input_event) {
.type = INPUT_EVENT_TITLE,
- .title = i_title
+ .title = *title
});
}
diff --git a/src/input/input.c b/src/input/input.c
index 4fcfebcedd..70e55276d0 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -888,7 +888,7 @@ static int InitSout( input_thread_t * p_input )
}
#endif
-static void InitTitle( input_thread_t * p_input )
+static void InitTitle( input_thread_t * p_input, bool had_titles )
{
input_thread_private_t *priv = input_priv(p_input);
input_source_t *p_master = priv->master;
@@ -902,14 +902,22 @@ static void InitTitle( input_thread_t * p_input )
priv->title = p_master->title;
priv->i_title_offset = p_master->i_title_offset;
priv->i_seekpoint_offset = p_master->i_seekpoint_offset;
- if( priv->i_title > 0 )
- input_SendEventTitle( p_input, 0 );
/* Global flag */
priv->b_can_pace_control = p_master->b_can_pace_control;
priv->b_can_pause = p_master->b_can_pause;
priv->b_can_rate_control = p_master->b_can_rate_control;
vlc_mutex_unlock( &priv->p_item->lock );
+
+ /* Send event only if the count is valid or if titles are gone */
+ if (had_titles || p_master->i_title > 0)
+ input_SendEventTitle( p_input, &(struct vlc_input_event_title) {
+ .action = VLC_INPUT_TITLE_NEW_LIST,
+ .list = {
+ .array = p_master->title,
+ .count = p_master->i_title,
+ },
+ });
}
static void StartTitle( input_thread_t * p_input )
@@ -1338,7 +1346,7 @@ static int Init( input_thread_t * p_input )
goto error;
priv->master = master;
- InitTitle( p_input );
+ InitTitle( p_input, false );
/* Load master infos */
/* Init length */
@@ -2124,7 +2132,10 @@ static bool Control( input_thread_t *p_input,
es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
demux_Control( priv->master->p_demux,
DEMUX_SET_TITLE, i_title );
- input_SendEventTitle( p_input, i_title );
+ input_SendEventTitle( p_input, &(struct vlc_input_event_title) {
+ .action = VLC_INPUT_TITLE_SELECTED,
+ .selected_idx = i_title,
+ });
break;
}
case INPUT_CONTROL_SET_SEEKPOINT:
@@ -2352,7 +2363,10 @@ static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
/* TODO event-like */
if( demux_TestAndClearFlags( p_demux, INPUT_UPDATE_TITLE ) )
- input_SendEventTitle( p_input, demux_GetTitle( p_demux ) );
+ input_SendEventTitle( p_input, &(struct vlc_input_event_title) {
+ .action = VLC_INPUT_TITLE_SELECTED,
+ .selected_idx = demux_GetTitle( p_demux ),
+ });
if( demux_TestAndClearFlags( p_demux, INPUT_UPDATE_SEEKPOINT ) )
input_SendEventSeekpoint( p_input, demux_GetTitle( p_demux ),
@@ -2385,8 +2399,10 @@ static void UpdateTitleListfromDemux( input_thread_t *p_input )
input_source_t *in = priv->master;
/* Delete the preexisting titles */
+ bool had_titles = false;
if( in->i_title > 0 )
{
+ had_titles = true;
for( int i = 0; i < in->i_title; i++ )
vlc_input_title_Delete( in->title[i] );
TAB_CLEAN( in->i_title, in->title );
@@ -2403,7 +2419,7 @@ static void UpdateTitleListfromDemux( input_thread_t *p_input )
else
in->b_title_demux = true;
- InitTitle( p_input );
+ InitTitle( p_input, had_titles );
}
static int
diff --git a/src/input/var.c b/src/input/var.c
index 47d688262d..ee5e16f74c 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -289,10 +289,10 @@ void input_LegacyEvents( input_thread_t *p_input,
var_Change( p_input, "length", VLC_VAR_SETVALUE, val );
break;
case INPUT_EVENT_TITLE:
- val.i_int = event->title;
+ val.i_int = event->title.action == VLC_INPUT_TITLE_NEW_LIST ? 0 : event->title.selected_idx;
var_Change( p_input, "title", VLC_VAR_SETVALUE, val );
input_LegacyVarNavigation( p_input );
- input_LegacyVarTitle( p_input, event->title );
+ input_LegacyVarTitle( p_input, val.i_int );
break;
case INPUT_EVENT_CHAPTER:
/* "chapter" */
More information about the vlc-commits
mailing list