~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/managerimpl.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
4
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
5
5
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
43
43
#include <vector>
44
44
#include <set>
45
45
#include <map>
46
 
#include <tr1/memory>
 
46
#include <memory>
 
47
#include <mutex>
47
48
 
48
 
#include <pthread.h>
49
 
#include "dbus/dbusmanager.h"
 
49
#include "client/client.h"
50
50
 
51
51
#include "config/sfl_config.h"
52
52
 
129
129
         */
130
130
        void init(const std::string &config_file);
131
131
 
 
132
        void setPath(const std::string &path);
 
133
 
 
134
#ifdef HAVE_DBUS
132
135
        /**
133
136
         * Enter Dbus mainloop
134
137
         */
135
 
        void run();
 
138
        int run();
 
139
        // Interrupt Dbus mainloop
 
140
        int interrupt();
 
141
#endif
136
142
 
137
143
        /*
138
144
         * Terminate all threads and exit DBus loop
144
150
         * it's multi-thread and use mutex internally
145
151
         * @return AudioLayer*  The audio layer object
146
152
         */
147
 
        AudioLayer* getAudioDriver() {
148
 
            return audiodriver_;
149
 
        }
 
153
        AudioLayer* getAudioDriver();
150
154
 
151
155
        void startAudioDriverStream();
152
156
 
558
562
         * Get the noise reduction engin state from
559
563
         * the current audio layer.
560
564
         */
561
 
        std::string getNoiseSuppressState() const;
 
565
        bool getNoiseSuppressState() const;
562
566
 
563
567
        /**
564
568
         * Set the noise reduction engin state in the current
565
569
         * audio layer.
566
570
         */
567
 
        void setNoiseSuppressState(const std::string &state);
568
 
 
569
 
        /**
570
 
         * Get the echo canceller engin state from
571
 
         * the current audio layer
572
 
         */
573
 
        bool getEchoCancelState() const;
574
 
 
575
 
        /**
576
 
         * Set the echo canceller engin state
577
 
         */
578
 
        void setEchoCancelState(const std::string &state);
 
571
        void setNoiseSuppressState(bool state);
 
572
 
 
573
        bool isAGCEnabled() const;
 
574
        void setAGCState(bool enabled);
579
575
 
580
576
        /**
581
577
         * Ringtone option.
606
602
         * Set recording on / off
607
603
         * Start recording
608
604
         * @param id  The call identifier
 
605
         * Returns true if the call was set to record
609
606
         */
610
 
        void setRecordingCall(const std::string& id);
 
607
        bool toggleRecordingCall(const std::string& id);
611
608
 
612
609
        /**
613
610
         * Return true if the call is currently recorded
706
703
        std::string getConfigString(const std::string& section, const std::string& name) const;
707
704
 
708
705
        /**
709
 
         * Retrieve the soundcards index in the user config file and try to open audio devices
710
 
         * with a specific alsa plugin.
711
 
         * Set the audio layer sample rate
712
 
         */
713
 
        void selectAudioDriver();
714
 
 
715
 
        /**
716
706
         * Handle audio sounds heard by a caller while they wait for their
717
707
         * connection to a called party to be completed.
718
708
         */
721
711
        /**
722
712
         * Handle played music when an incoming call occurs
723
713
         */
724
 
        void ringtone(const std::string& accountID);
 
714
        void playRingtone(const std::string& accountID);
725
715
 
726
716
        /**
727
717
         * Handle played music when a congestion occurs
754
744
         * @return true is there is one or many incoming call waiting
755
745
         * new call, not anwsered or refused
756
746
         */
757
 
        bool incomingCallWaiting() const;
 
747
        bool incomingCallsWaiting();
758
748
 
759
749
        /**
760
750
         * Return a new random callid that is not present in the list
787
777
        const AudioCodecFactory audioCodecFactory;
788
778
 
789
779
    private:
 
780
        void removeAccounts();
 
781
 
 
782
        bool parseConfiguration();
 
783
 
 
784
        // Set the ringtone or recorded call to be played
 
785
        void updateAudioFile(const std::string &file, int sampleRate);
790
786
 
791
787
        /**
792
788
         * Get the Call referred to by callID. If the Call does not exist, return NULL
794
790
        Call *getCallFromCallID(const std::string &callID);
795
791
 
796
792
        /**
797
 
         * Play the dtmf-associated sound
798
 
         * @param code  The pressed key
799
 
         */
800
 
        void playDtmf(char code);
801
 
 
802
 
        /**
803
793
         * Process remaining participant given a conference and the current call id.
804
794
         * Mainly called when a participant is detached or hagned up
805
795
         * @param current call id
810
800
        /**
811
801
         * Create config directory in home user and return configuration file path
812
802
         */
813
 
        std::string createConfigFile() const;
 
803
        std::string retrieveConfigPath() const;
814
804
 
815
805
        /*
816
806
         * Initialize zeroconf module and scanning
834
824
         */
835
825
        void playATone(Tone::TONEID toneId);
836
826
 
837
 
        DBusManager dbus_;
 
827
        Client client_;
838
828
 
839
829
        /** The configuration tree. It contains accounts parameters, general user settings ,audio settings, ... */
840
830
        Conf::ConfigTree config_;
843
833
        std::string currentCallId_;
844
834
 
845
835
        /** Protected current call access */
846
 
        pthread_mutex_t currentCallMutex_;
 
836
        std::mutex currentCallMutex_;
847
837
 
848
838
        /** Audio layer */
849
839
        AudioLayer* audiodriver_;
850
840
 
851
841
        // Main thread
852
 
        std::tr1::shared_ptr<DTMF> dtmfKey_;
 
842
        std::unique_ptr<DTMF> dtmfKey_;
853
843
 
854
844
        /////////////////////
855
845
        // Protected by Mutex
856
846
        /////////////////////
857
 
        pthread_mutex_t toneMutex_;
858
 
        std::tr1::shared_ptr<TelephoneTone> telephoneTone_;
859
 
        std::tr1::shared_ptr<AudioFile> audiofile_;
 
847
        std::mutex toneMutex_;
 
848
        std::unique_ptr<TelephoneTone> telephoneTone_;
 
849
        std::unique_ptr<AudioFile> audiofile_;
860
850
 
861
851
        // To handle volume control
862
852
        // short speakerVolume_;
866
856
        /**
867
857
         * Mutex used to protect audio layer
868
858
         */
869
 
        pthread_mutex_t audioLayerMutex_;
 
859
        std::mutex audioLayerMutex_;
870
860
 
871
861
        /**
872
862
         * Waiting Call Vectors
873
863
         */
874
 
        CallIDSet waitingCall_;
 
864
        CallIDSet waitingCalls_;
875
865
 
876
866
        /**
877
867
         * Protect waiting call list, access by many voip/audio threads
878
868
         */
879
 
        pthread_mutex_t waitingCallMutex_;
880
 
 
881
 
        /**
882
 
         * Number of waiting call, synchronize with waitingcall callidvector
883
 
         */
884
 
        unsigned int nbIncomingWaitingCall_;
 
869
        std::mutex waitingCallsMutex_;
885
870
 
886
871
        /**
887
872
         * Add incoming callid to the waiting list
895
880
         */
896
881
        void removeWaitingCall(const std::string& id);
897
882
 
898
 
        /** Remove a CallID/std::string association
899
 
         * Protected by mutex
900
 
         * @param callID the CallID to remove
901
 
         */
902
 
        void removeCallAccount(const std::string& callID);
903
 
 
904
883
        /**
905
884
         * Path of the ConfigFile
906
885
         */
949
928
        /**
950
929
         * Return a pointer to the  instance of the mainbuffer
951
930
         */
952
 
        MainBuffer &getMainBuffer() {
953
 
            return mainBuffer_;
954
 
        }
 
931
        MainBuffer &getMainBuffer();
955
932
 
956
933
        /**
957
934
         * Tell if there is a current call processed
960
937
        bool hasCurrentCall() const;
961
938
 
962
939
        /**
963
 
         * Return the current DBusManager
964
 
         * @return A pointer to the DBusManager instance
 
940
         * Return the current Client
 
941
         * @return A pointer to the Client instance
965
942
         */
966
 
        DBusManager * getDbusManager() {
967
 
            return &dbus_;
968
 
        }
969
 
 
 
943
        Client* getClient();
970
944
#ifdef SFL_VIDEO
971
 
        VideoControls * getVideoControls() {
972
 
            return dbus_.getVideoControls();
973
 
        }
 
945
        VideoControls * getVideoControls();
974
946
#endif
975
947
 
976
948
        /**
1027
999
         */
1028
1000
        VoIPLink* getAccountLink(const std::string& accountID);
1029
1001
 
1030
 
        std::string getStunServer() const;
1031
 
        void setStunServer(const std::string &server);
1032
 
 
1033
 
        int isStunEnabled();
1034
 
        void enableStun();
1035
 
 
1036
 
        // Map containing conference pointers
1037
 
        ConferenceMap conferenceMap_;
1038
 
 
1039
1002
        /**
1040
1003
         * Send registration to all enabled accounts
1041
1004
         */
1042
1005
        void registerAccounts();
1043
1006
        void saveHistory();
1044
1007
 
 
1008
        /**
 
1009
         * Suspends SFLphone's audio processing if no calls remain, allowing
 
1010
         * other applications to resume audio.
 
1011
         * See:
 
1012
         * https://projects.savoirfairelinux.com/issues/7037
 
1013
        */
 
1014
        void
 
1015
        checkAudio();
 
1016
 
1045
1017
    private:
1046
1018
        NON_COPYABLE(ManagerImpl);
1047
1019
 
1048
1020
        /**
 
1021
         * Play the dtmf-associated sound
 
1022
         * @param code  The pressed key
 
1023
         */
 
1024
        void playDtmf(char code);
 
1025
 
 
1026
 
 
1027
        // Map containing conference pointers
 
1028
        ConferenceMap conferenceMap_;
 
1029
 
 
1030
        /**
1049
1031
         * Get a map with all the current SIP and IAX accounts
1050
1032
         */
1051
1033
        AccountMap getAllAccounts() const;
1052
1034
 
1053
 
        void
1054
 
        checkAudio();
1055
 
 
1056
1035
        /**
1057
1036
          * To handle the persistent history
1058
1037
          * TODO: move this to ConfigurationManager