[vlc-commits] qt: refcount children passed to onItemAdded in NetworkMediaModel

Pierre Lamot git at videolan.org
Thu Feb 13 11:06:34 CET 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Wed Feb  5 11:33:16 2020 +0100| [ed1d5c72178ab0081a3389a37daae06fe8947c52] | committer: Jean-Baptiste Kempf

qt: refcount children passed to onItemAdded in NetworkMediaModel

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/gui/qt/network/networkmediamodel.cpp | 23 ++++++++++++++++-------
 modules/gui/qt/network/networkmediamodel.hpp |  2 +-
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index ca1e94c51d..bbc0aa96bd 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -294,7 +294,12 @@ void NetworkMediaModel::onItemCleared( MediaSourcePtr mediaSource, input_item_no
         if (!found)
             return;
 
-        refreshMediaList( std::move( mediaSource ), res->pp_children, res->i_children, true );
+        std::vector<InputItemPtr> itemList;
+        itemList.reserve( static_cast<size_t>(res->i_children) );
+        for (int i = 0; i < res->i_children; i++)
+            itemList.emplace_back(res->pp_children[i]->p_item);
+
+        refreshMediaList( std::move( mediaSource ), std::move( itemList ), true );
     }, Qt::QueuedConnection);
 }
 
@@ -303,9 +308,14 @@ void NetworkMediaModel::onItemAdded( MediaSourcePtr mediaSource, input_item_node
                                   size_t count )
 {
     InputItemPtr p_parent { parent->p_item };
-    QMetaObject::invokeMethod(this, [this, p_parent = std::move(p_parent), mediaSource = std::move(mediaSource), children, count]() {
+    std::vector<InputItemPtr> itemList;
+    itemList.reserve( count );
+    for (size_t i = 0; i < count; i++)
+        itemList.emplace_back(children[i]->p_item);
+
+    QMetaObject::invokeMethod(this, [this, p_parent = std::move(p_parent), mediaSource = std::move(mediaSource), itemList=std::move(itemList)]() {
         if ( p_parent == m_treeItem.media )
-            refreshMediaList( std::move( mediaSource ), children, count, false );
+            refreshMediaList( std::move( mediaSource ), std::move( itemList ), false );
     }, Qt::QueuedConnection);
 }
 
@@ -364,13 +374,12 @@ void NetworkMediaModel::onItemPreparseEnded(MediaSourcePtr, input_item_node_t* n
 }
 
 void NetworkMediaModel::refreshMediaList( MediaSourcePtr mediaSource,
-                                       input_item_node_t* const children[], size_t count,
+                                       std::vector<InputItemPtr> childrens,
                                        bool clear )
 {
     std::vector<Item> items;
-    for ( auto i = 0u; i < count; ++i )
+    for ( auto it: childrens)
     {
-        auto it = children[i]->p_item;
         Item item;
         item.name = it->psz_name;
         item.protocol = "";
@@ -389,7 +398,7 @@ void NetworkMediaModel::refreshMediaList( MediaSourcePtr mediaSource,
                                     &item.indexed ) != VLC_SUCCESS )
                 item.indexed = false;
         }
-        item.tree = NetworkTreeItem( mediaSource, it );
+        item.tree = NetworkTreeItem( mediaSource, it.get() );
         items.push_back( std::move( item ) );
     }
     if ( clear == true )
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index 969d085dc4..59dae326e6 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -162,7 +162,7 @@ private:
     void onItemRemoved( MediaSourcePtr mediaSource, input_item_node_t * node, input_item_node_t *const children[], size_t count ) override;
     void onItemPreparseEnded( MediaSourcePtr mediaSource, input_item_node_t* node, enum input_item_preparse_status status ) override;
 
-    void refreshMediaList(MediaSourcePtr s, input_item_node_t* const children[], size_t count , bool clear);
+    void refreshMediaList(MediaSourcePtr s, std::vector<InputItemPtr> childrens , bool clear);
 
     static bool canBeIndexed(const QUrl& url , ItemType itemType );
 



More information about the vlc-commits mailing list