PluginManager: Move reference counting in the MediaPlugin

* Ideally we should support this feature by default to allow
future improvements to the plugins management.
* Fixes the major memory corruption that lead to various
crashes on exit in MediaPlayer.
This commit is contained in:
Dario Casalinuovo 2016-10-31 23:34:48 +01:00
parent 42a3f9477d
commit 8023d6bafd
5 changed files with 15 additions and 9 deletions

View File

@ -13,6 +13,12 @@ class MediaPlugin {
public: public:
MediaPlugin(); MediaPlugin();
virtual ~MediaPlugin(); virtual ~MediaPlugin();
private:
// needed for plug-in reference count management
friend class PluginManager;
int32 fRefCount;
}; };
class Decoder; class Decoder;

View File

@ -27,10 +27,8 @@ private:
virtual void _ReservedStreamer5(); virtual void _ReservedStreamer5();
MediaPlugin* fMediaPlugin; MediaPlugin* fMediaPlugin;
int32 fRefCount;
uint32 fReserved[5]; uint32 fReserved[5];
// needed for plug-in reference count management
friend class PluginManager; friend class PluginManager;
}; };

View File

@ -8,6 +8,8 @@
MediaPlugin::MediaPlugin() MediaPlugin::MediaPlugin()
:
fRefCount(0)
{ {
} }

View File

@ -635,7 +635,7 @@ PluginManager::CreateStreamer(Streamer** streamer, BUrl url, BDataIO** source)
} }
(*streamer)->fMediaPlugin = plugin; (*streamer)->fMediaPlugin = plugin;
(*streamer)->fRefCount += 1; plugin->fRefCount += 1;
BDataIO* streamSource = NULL; BDataIO* streamSource = NULL;
if ((*streamer)->Sniff(url, &streamSource) == B_OK) { if ((*streamer)->Sniff(url, &streamSource) == B_OK) {
@ -666,13 +666,14 @@ PluginManager::DestroyStreamer(Streamer* streamer)
// since otherwise we may actually unload the code for the // since otherwise we may actually unload the code for the
// destructor... // destructor...
MediaPlugin* plugin = streamer->fMediaPlugin; MediaPlugin* plugin = streamer->fMediaPlugin;
delete streamer;
// Delete the streamer only when every reference is released // Delete the plugin only when every reference is released
if (streamer->fRefCount == 1) { if (plugin->fRefCount == 1) {
delete streamer; plugin->fRefCount = 0;
PutPlugin(plugin); PutPlugin(plugin);
} else } else
streamer->fRefCount -= 1; plugin->fRefCount -= 1;
} }
} }

View File

@ -8,8 +8,7 @@
Streamer::Streamer() Streamer::Streamer()
: :
fMediaPlugin(NULL), fMediaPlugin(NULL)
fRefCount(0)
{ {
} }