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:
|
public:
|
||||||
MediaPlugin();
|
MediaPlugin();
|
||||||
virtual ~MediaPlugin();
|
virtual ~MediaPlugin();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// needed for plug-in reference count management
|
||||||
|
friend class PluginManager;
|
||||||
|
|
||||||
|
int32 fRefCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Decoder;
|
class Decoder;
|
||||||
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
|
|
||||||
MediaPlugin::MediaPlugin()
|
MediaPlugin::MediaPlugin()
|
||||||
|
:
|
||||||
|
fRefCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@
|
|||||||
|
|
||||||
Streamer::Streamer()
|
Streamer::Streamer()
|
||||||
:
|
:
|
||||||
fMediaPlugin(NULL),
|
fMediaPlugin(NULL)
|
||||||
fRefCount(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user