[vlc-devel] [PATCH 10/14] medialib: receive events from input thread
Romain Vimont
rom1v at videolabs.io
Thu Aug 16 16:02:07 CEST 2018
Replace listeners on the input item by input thread callbacks.
---
.../misc/medialibrary/MetadataExtractor.cpp | 48 +++++++++----------
modules/misc/medialibrary/medialibrary.h | 3 +-
2 files changed, 23 insertions(+), 28 deletions(-)
diff --git a/modules/misc/medialibrary/MetadataExtractor.cpp b/modules/misc/medialibrary/MetadataExtractor.cpp
index 3abca1c04d..e18395e014 100644
--- a/modules/misc/medialibrary/MetadataExtractor.cpp
+++ b/modules/misc/medialibrary/MetadataExtractor.cpp
@@ -32,22 +32,29 @@ MetadataExtractor::MetadataExtractor( vlc_object_t* parent )
void MetadataExtractor::onInputEvent( const vlc_input_event* ev,
ParseContext& ctx )
{
- if ( ev->type != INPUT_EVENT_DEAD && ev->type != INPUT_EVENT_STATE )
- return;
-
- if ( ev->type == INPUT_EVENT_STATE )
- {
- vlc_mutex_locker lock( &ctx.m_mutex );
- ctx.state = ev->state;
- return;
- }
-
+ switch ( ev->type )
{
- vlc_mutex_locker lock( &ctx.m_mutex );
- // We need to probe the item now, but not from the input thread
- ctx.needsProbing = true;
+ case INPUT_EVENT_PARSING:
+ if ( ev->parsing.action == vlc_input_event_parsing::VLC_INPUT_PARSING_SUBTREE_ADDED )
+ addSubtree( ctx, ev->parsing.root );
+ break;
+ case INPUT_EVENT_STATE:
+ {
+ vlc_mutex_locker lock( &ctx.m_mutex );
+ ctx.state = ev->state;
+ }
+ break;
+ case INPUT_EVENT_DEAD:
+ {
+ vlc_mutex_locker lock( &ctx.m_mutex );
+ // We need to probe the item now, but not from the input thread
+ ctx.needsProbing = true;
+ }
+ vlc_cond_signal( &ctx.m_cond );
+ break;
+ default:
+ break;
}
- vlc_cond_signal( &ctx.m_cond );
}
void MetadataExtractor::populateItem( medialibrary::parser::IItem& item, input_item_t* inputItem )
@@ -129,9 +136,8 @@ void MetadataExtractor::onInputEvent( input_thread_t*, void *data,
ctx->mde->onInputEvent( event, *ctx );
}
-void MetadataExtractor::onSubItemAdded( const vlc_event_t* event, ParseContext& ctx )
+void MetadataExtractor::addSubtree( ParseContext& ctx, input_item_node_t *root )
{
- auto root = event->u.input_item_subitem_tree_added.p_root;
for ( auto i = 0; i < root->i_children; ++i )
{
auto it = root->pp_children[i]->p_item;
@@ -140,12 +146,6 @@ void MetadataExtractor::onSubItemAdded( const vlc_event_t* event, ParseContext&
}
}
-void MetadataExtractor::onSubItemAdded( const vlc_event_t* event, void* data )
-{
- auto* ctx = static_cast<ParseContext*>( data );
- ctx->mde->onSubItemAdded( event, *ctx );
-}
-
medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem& item )
{
ParseContext ctx( this, item );
@@ -166,10 +166,6 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
if ( ctx.input == nullptr )
return medialibrary::parser::Status::Fatal;
- if( vlc_event_attach( &ctx.inputItem->event_manager, vlc_InputItemSubItemTreeAdded,
- &MetadataExtractor::onSubItemAdded, std::addressof( ctx ) ) )
- return medialibrary::parser::Status::Fatal;
-
input_Start( ctx.input.get() );
{
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 8246704f8c..70aedef2e0 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -89,12 +89,11 @@ private:
virtual void onRestarted() override;
void onInputEvent( const vlc_input_event* event, ParseContext& ctx );
- void onSubItemAdded( const vlc_event_t* event, ParseContext& ctx );
+ void addSubtree( ParseContext& ctx, input_item_node_t *root );
void populateItem( medialibrary::parser::IItem& item, input_item_t* inputItem );
static void onInputEvent( input_thread_t *input, void *user_data,
const struct vlc_input_event *event );
- static void onSubItemAdded( const vlc_event_t* event, void* data );
private:
vlc_object_t* m_obj;
--
2.18.0
More information about the vlc-devel
mailing list