From c813022b9c9e3ab6086714b17b3b5a274caca760 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Mon, 16 Aug 2010 14:29:50 -0400
Subject: [PATCH] [#3757] Dynamic allocation of AudioFile (RawFile)

---
 sflphone-common/src/managerimpl.cpp | 24 ++++++++++++++++--------
 sflphone-common/src/managerimpl.h   |  4 ++--
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index 15a34d7992..23efc4257e 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -79,7 +79,7 @@ ManagerImpl::ManagerImpl (void) :
         _hasTriedToRegister (false), _config(), _currentCallId2(),
         _currentCallMutex(), _codecBuilder (NULL), _audiodriver (NULL),
         _dtmfKey (NULL), _codecDescriptorMap(), _toneMutex(),
-        _telephoneTone (NULL), _audiofile(), _spkr_volume (0),
+        _telephoneTone (NULL), _audiofile(NULL), _spkr_volume (0),
         _mic_volume (0), _mutex(), _dbus (NULL), _waitingCall(),
         _waitingCallMutex(), _nbIncomingWaitingCall (0), _path (""),
         _exist (0), _setupLoaded (false), _callAccountMap(),
@@ -1925,7 +1925,9 @@ void ManagerImpl::stopTone ()
         _telephoneTone->setCurrentTone (Tone::TONE_NULL);
     }
 
-    _audiofile.stop();
+    if(_audiofile)
+        _audiofile.stop();
+
     _toneMutex.leaveMutex();
 }
 
@@ -2006,14 +2008,17 @@ void ManagerImpl::ringtone (const AccountID& accountID)
         }
 
         layer = audiolayer->getLayerType();
-
         samplerate = audiolayer->getSampleRate();
-
         codecForTone = _codecDescriptorMap.getFirstCodecAvailable();
 
+	
+	_audiofile = new RawFile();
+
         _toneMutex.enterMutex();
 
-        loadFile = _audiofile.loadFile (ringchoice, codecForTone, samplerate);
+	loadFile = false;
+	if(_audiofile)
+	    loadFile = _audiofile->loadFile (ringchoice, codecForTone, samplerate);
 
         _toneMutex.leaveMutex();
 
@@ -2053,10 +2058,13 @@ ManagerImpl::getTelephoneFile ()
     // _debug("ManagerImpl::getTelephoneFile()");
     ost::MutexLock m (_toneMutex);
 
-    if (_audiofile.isStarted()) {
-        return &_audiofile;
+    if (!_audiofile)
+      return NULL;
+
+    if (_audiofile->isStarted()) {
+        return _audiofile;
     } else {
-        return 0;
+        return NULL;
     }
 }
 
diff --git a/sflphone-common/src/managerimpl.h b/sflphone-common/src/managerimpl.h
index 9bea655902..41eeb62577 100644
--- a/sflphone-common/src/managerimpl.h
+++ b/sflphone-common/src/managerimpl.h
@@ -50,7 +50,7 @@
 #include "numbercleaner.h"
 
 #include "audio/sound/tonelist.h"  // for Tone::TONEID declaration
-#include "audio/sound/audiofile.h" // AudioFile class contained by value here 
+#include "audio/sound/audiofile.h"
 #include "audio/sound/dtmf.h" // DTMF class contained by value here
 #include "audio/codecs/codecDescriptor.h" // CodecDescriptor class contained by value here
 
@@ -1188,7 +1188,7 @@ class ManagerImpl
         /////////////////////
         ost::Mutex _toneMutex;
         TelephoneTone* _telephoneTone;
-        AudioFile _audiofile;
+        AudioFile *_audiofile;
 
         // To handle volume control
         short _spkr_volume;
-- 
GitLab