summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Papp <lpapp@kde.org>2011-12-07 01:38:24 +0200
committerLaszlo Papp <ext-laszlo.papp@nokia.com>2011-12-07 01:38:24 +0200
commit28875ef07c93710878f1a70fe408ec24b240a046 (patch)
tree5378472bdc4ee9c8793f378aa7f087e119046add /src
parentd098e9d1ca7869ab643800bf59728e9d908afca3 (diff)
Use a reference counter and call the mpg123_init/exit accordingly in ctor/dtor
Diffstat (limited to 'src')
-rw-r--r--src/decoders/qalmpg123audiodecoder.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/decoders/qalmpg123audiodecoder.cpp b/src/decoders/qalmpg123audiodecoder.cpp
index 96db818..a2ec57b 100644
--- a/src/decoders/qalmpg123audiodecoder.cpp
+++ b/src/decoders/qalmpg123audiodecoder.cpp
@@ -28,17 +28,23 @@ class QALMpg123AudioDecoder::Private
{
public:
Private()
- : mpg123Handle(0)
+ : referenceCounter(0)
+ , mpg123Handle(0)
{
- int error;
- if ((error = mpg123_init()) == MPG123_OK) {
- qWarning() << Q_FUNC_INFO << "Failed to initialize the mpg123 library:" << error;
+ referenceCounter.ref();
+ if (int(referenceCounter) == 1) {
+ int error;
+ if ((error = mpg123_init()) == MPG123_OK) {
+ qWarning() << Q_FUNC_INFO << "Failed to initialize the mpg123 library:" << error;
+ }
}
}
~Private()
{
- mpg123_exit();
+ if (referenceCounter.deref() == false) {
+ mpg123_exit();
+ }
}
static sf_count_t fileLengthCallback(void *user_data);
@@ -46,6 +52,8 @@ class QALMpg123AudioDecoder::Private
static sf_count_t readCallback(void *ptr, sf_count_t count, void *user_data);
static sf_count_t tellCallback(void *user_data);
+ QAtomicInt referenceCounter;
+
QFile file;
QByteArray encodedData;