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:
parent
42a3f9477d
commit
8023d6bafd
@ -13,6 +13,12 @@ class MediaPlugin {
|
||||
public:
|
||||
MediaPlugin();
|
||||
virtual ~MediaPlugin();
|
||||
|
||||
private:
|
||||
// needed for plug-in reference count management
|
||||
friend class PluginManager;
|
||||
|
||||
int32 fRefCount;
|
||||
};
|
||||
|
||||
class Decoder;
|
||||
|
@ -27,10 +27,8 @@ private:
|
||||
virtual void _ReservedStreamer5();
|
||||
|
||||
MediaPlugin* fMediaPlugin;
|
||||
int32 fRefCount;
|
||||
uint32 fReserved[5];
|
||||
|
||||
// needed for plug-in reference count management
|
||||
friend class PluginManager;
|
||||
};
|
||||
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
|
||||
MediaPlugin::MediaPlugin()
|
||||
:
|
||||
fRefCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ PluginManager::CreateStreamer(Streamer** streamer, BUrl url, BDataIO** source)
|
||||
}
|
||||
|
||||
(*streamer)->fMediaPlugin = plugin;
|
||||
(*streamer)->fRefCount += 1;
|
||||
plugin->fRefCount += 1;
|
||||
|
||||
BDataIO* streamSource = NULL;
|
||||
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
|
||||
// destructor...
|
||||
MediaPlugin* plugin = streamer->fMediaPlugin;
|
||||
delete streamer;
|
||||
|
||||
// Delete the streamer only when every reference is released
|
||||
if (streamer->fRefCount == 1) {
|
||||
delete streamer;
|
||||
// Delete the plugin only when every reference is released
|
||||
if (plugin->fRefCount == 1) {
|
||||
plugin->fRefCount = 0;
|
||||
PutPlugin(plugin);
|
||||
} else
|
||||
streamer->fRefCount -= 1;
|
||||
plugin->fRefCount -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,7 @@
|
||||
|
||||
Streamer::Streamer()
|
||||
:
|
||||
fMediaPlugin(NULL),
|
||||
fRefCount(0)
|
||||
fMediaPlugin(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user