[vlc-commits] medialib: receive events from input thread
Romain Vimont
git at videolan.org
Mon Aug 20 13:59:17 CEST 2018
vlc | branch: master | Romain Vimont <rom1v at videolabs.io> | Fri Aug 10 16:01:21 2018 +0200| [948aa63beee2f1bd92460d2e3407a59dfcac7d4b] | committer: Romain Vimont
medialib: receive events from input thread
Replace listeners on the input item by input thread callbacks.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=948aa63beee2f1bd92460d2e3407a59dfcac7d4b
---
modules/misc/medialibrary/MetadataExtractor.cpp | 47 +++++++++++--------------
modules/misc/medialibrary/medialibrary.h | 3 +-
2 files changed, 22 insertions(+), 28 deletions(-)
diff --git a/modules/misc/medialibrary/MetadataExtractor.cpp b/modules/misc/medialibrary/MetadataExtractor.cpp
index 3abca1c04d..50fbf37d7e 100644
--- a/modules/misc/medialibrary/MetadataExtractor.cpp
+++ b/modules/misc/medialibrary/MetadataExtractor.cpp
@@ -32,22 +32,28 @@ 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_SUBITEMS:
+ addSubtree( ctx, ev->subitems );
+ 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 +135,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 +145,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 +165,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 97a2891c10..f50b100803 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;
More information about the vlc-commits
mailing list