From dc3c38f6efddab3df1908cb41e854892535a2f6e Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Thu, 27 Jun 2013 13:50:30 -0400 Subject: [PATCH] * #26544: dbus: improve recording API Namely by telling the client who triggered recording whether or not recording has started. --- daemon/src/audio/audiorecord.cpp | 5 +++-- daemon/src/audio/audiorecord.h | 4 ++-- daemon/src/audio/recordable.h | 2 +- daemon/src/call.cpp | 10 ++++------ daemon/src/call.h | 2 +- daemon/src/conference.cpp | 10 ++++------ daemon/src/conference.h | 2 +- daemon/src/dbus/callmanager-introspec.xml | 17 +++++++++++++++++ daemon/src/dbus/callmanager.cpp | 8 +++++++- daemon/src/dbus/callmanager.h | 3 +++ daemon/src/managerimpl.cpp | 15 ++++++++------- daemon/src/managerimpl.h | 3 ++- gnome/src/actions.c | 11 ++++++----- gnome/src/actions.h | 2 +- gnome/src/dbus/callmanager-introspec.xml | 17 +++++++++++++++++ gnome/src/dbus/dbus.c | 8 +++++--- gnome/src/dbus/dbus.h | 2 +- gnome/src/uimanager.c | 5 ++++- 18 files changed, 87 insertions(+), 39 deletions(-) diff --git a/daemon/src/audio/audiorecord.cpp b/daemon/src/audio/audiorecord.cpp index f87d034ee4..14b30ddf1a 100644 --- a/daemon/src/audio/audiorecord.cpp +++ b/daemon/src/audio/audiorecord.cpp @@ -234,14 +234,15 @@ bool AudioRecord::isRecording() const return recordingEnabled_; } -void AudioRecord::setRecording() +bool AudioRecord::toggleRecording() { if (isOpenFile()) { recordingEnabled_ = !recordingEnabled_; } else { openFile(); - recordingEnabled_ = true; // once opend file, start recording + recordingEnabled_ = true; } + return recordingEnabled_; } void AudioRecord::stopRecording() diff --git a/daemon/src/audio/audiorecord.h b/daemon/src/audio/audiorecord.h index 59b826244b..3fb91948e8 100644 --- a/daemon/src/audio/audiorecord.h +++ b/daemon/src/audio/audiorecord.h @@ -88,9 +88,9 @@ class AudioRecord { bool isRecording() const; /** - * Set recording flag + * Toggle recording state */ - void setRecording(); + bool toggleRecording(); /** * Stop recording flag diff --git a/daemon/src/audio/recordable.h b/daemon/src/audio/recordable.h index 4df70b8083..bdc7c2b1af 100644 --- a/daemon/src/audio/recordable.h +++ b/daemon/src/audio/recordable.h @@ -51,7 +51,7 @@ class Recordable { * This method must be implemented for this interface as calls and conferences * have different behavior. */ - virtual bool setRecording() = 0; + virtual bool toggleRecording() = 0; /** * Stop recording diff --git a/daemon/src/call.cpp b/daemon/src/call.cpp index deb9ca0d6d..8c83021d1b 100644 --- a/daemon/src/call.cpp +++ b/daemon/src/call.cpp @@ -148,15 +148,13 @@ Call::getLocalVideoPort() } bool -Call::setRecording() +Call::toggleRecording() { - bool recordStatus = Recordable::recAudio_.isRecording(); - - Recordable::recAudio_.setRecording(); + const bool startRecording = Recordable::recAudio_.toggleRecording(); MainBuffer &mbuffer = Manager::instance().getMainBuffer(); std::string process_id = Recordable::recorder_.getRecorderID(); - if (!recordStatus) { + if (startRecording) { mbuffer.bindHalfDuplexOut(process_id, id_); mbuffer.bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID); @@ -168,7 +166,7 @@ Call::setRecording() Manager::instance().getMainBuffer().dumpInfo(); - return recordStatus; + return startRecording; } void Call::time_stop() diff --git a/daemon/src/call.h b/daemon/src/call.h index eee2e15db7..0ba72776b5 100644 --- a/daemon/src/call.h +++ b/daemon/src/call.h @@ -228,7 +228,7 @@ class Call : public Recordable { virtual std::map<std::string, std::string> createHistoryEntry() const; - virtual bool setRecording(); + virtual bool toggleRecording(); private: std::string getTypeStr() const; diff --git a/daemon/src/conference.cpp b/daemon/src/conference.cpp index 7203b5706f..1197d86af4 100644 --- a/daemon/src/conference.cpp +++ b/daemon/src/conference.cpp @@ -99,17 +99,15 @@ ParticipantSet Conference::getParticipantList() const return participants_; } -bool Conference::setRecording() +bool Conference::toggleRecording() { - bool recordStatus = Recordable::recAudio_.isRecording(); - - Recordable::recAudio_.setRecording(); + const bool startRecording = Recordable::recAudio_.toggleRecording(); MainBuffer &mbuffer = Manager::instance().getMainBuffer(); std::string process_id(Recordable::recorder_.getRecorderID()); // start recording - if (!recordStatus) { + if (startRecording) { for (ParticipantSet::const_iterator iter = participants_.begin(); iter != participants_.end(); ++iter) mbuffer.bindHalfDuplexOut(process_id, *iter); @@ -123,7 +121,7 @@ bool Conference::setRecording() mbuffer.unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID); } - return recordStatus; + return startRecording; } std::string Conference::getConfID() const { diff --git a/daemon/src/conference.h b/daemon/src/conference.h index 39509e28cf..1adc7aad76 100644 --- a/daemon/src/conference.h +++ b/daemon/src/conference.h @@ -89,7 +89,7 @@ class Conference : public Recordable { /** * Start/stop recording toggle */ - virtual bool setRecording(); + virtual bool toggleRecording(); private: std::string id_; ConferenceState confState_; diff --git a/daemon/src/dbus/callmanager-introspec.xml b/daemon/src/dbus/callmanager-introspec.xml index 3823492914..6551f36189 100644 --- a/daemon/src/dbus/callmanager-introspec.xml +++ b/daemon/src/dbus/callmanager-introspec.xml @@ -325,7 +325,24 @@ </arg> </method> + <method name="toggleRecording" tp:name-for-bindings="toggleRecording"> + <tp:docstring> + Toggle recording for a call. + </tp:docstring> + <arg type="s" name="callID" direction="in"> + <tp:docstring> + The ID of the call to start/stop recording. + </tp:docstring> + </arg> + <arg type="b" name="isRecording" direction="out"> + <tp:docstring> + Returns true is the call is being recorded. False otherwise. + </tp:docstring> + </arg> + </method> + <method name="setRecording" tp:name-for-bindings="setRecording"> + <annotation name="org.freedesktop.DBus.Deprecated" value="true"/> <tp:docstring> Start recording a call. </tp:docstring> diff --git a/daemon/src/dbus/callmanager.cpp b/daemon/src/dbus/callmanager.cpp index 50b6d18788..8afb4c2ae4 100644 --- a/daemon/src/dbus/callmanager.cpp +++ b/daemon/src/dbus/callmanager.cpp @@ -232,10 +232,16 @@ CallManager::stopRecordedFilePlayback(const std::string& filepath) Manager::instance().stopRecordedFilePlayback(filepath); } +bool +CallManager::toggleRecording(const std::string& callID) +{ + return Manager::instance().toggleRecordingCall(callID); +} + void CallManager::setRecording(const std::string& callID) { - Manager::instance().setRecordingCall(callID); + toggleRecording(callID); } void diff --git a/daemon/src/dbus/callmanager.h b/daemon/src/dbus/callmanager.h index a3e50c6326..e99a72b6b0 100644 --- a/daemon/src/dbus/callmanager.h +++ b/daemon/src/dbus/callmanager.h @@ -107,7 +107,10 @@ class CallManager /* General audio methods */ void setVolume(const std::string& device, const double& value); double getVolume(const std::string& device); + bool toggleRecording(const std::string& callID); + /* DEPRECATED */ void setRecording(const std::string& callID); + void recordPlaybackSeek(const double& value); bool getIsRecording(const std::string& callID); std::string getCurrentAudioCodecName(const std::string& callID); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 232775291b..96e211df48 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -388,7 +388,7 @@ bool ManagerImpl::answerCall(const std::string& call_id) // Start recording if set in preference if (audioPreference.getIsAlwaysRecording()) - setRecordingCall(call_id); + toggleRecordingCall(call_id); // update call state on client side dbus_.getCallManager()->callStateChanged(call_id, "CURRENT"); @@ -1630,7 +1630,7 @@ void ManagerImpl::peerAnsweredCall(const std::string& id) } if (audioPreference.getIsAlwaysRecording()) - setRecordingCall(id); + toggleRecordingCall(id); dbus_.getCallManager()->callStateChanged(id, "CURRENT"); } @@ -2064,16 +2064,16 @@ void ManagerImpl::setIsAlwaysRecording(bool isAlwaysRec) return audioPreference.setIsAlwaysRecording(isAlwaysRec); } -void ManagerImpl::setRecordingCall(const std::string& id) +bool ManagerImpl::toggleRecordingCall(const std::string& id) { Recordable* rec = NULL; ConferenceMap::const_iterator it(conferenceMap_.find(id)); if (it == conferenceMap_.end()) { - DEBUG("Set recording for call %s", id.c_str()); + DEBUG("toggle recording for call %s", id.c_str()); rec = getCallFromCallID(id); } else { - DEBUG("Set recording for conference %s", id.c_str()); + DEBUG("toggle recording for conference %s", id.c_str()); Conference *conf = it->second; if (conf) { @@ -2087,11 +2087,12 @@ void ManagerImpl::setRecordingCall(const std::string& id) if (rec == NULL) { ERROR("Could not find recordable instance %s", id.c_str()); - return; + return false; } - rec->setRecording(); + const bool result = rec->toggleRecording(); dbus_.getCallManager()->recordPlaybackFilepath(id, rec->getFilename()); + return result; } bool ManagerImpl::isRecording(const std::string& id) diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 1a36397fdd..dfd910c4ff 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -606,8 +606,9 @@ class ManagerImpl { * Set recording on / off * Start recording * @param id The call identifier + * Returns true if the call was set to record */ - void setRecordingCall(const std::string& id); + bool toggleRecordingCall(const std::string& id); /** * Return true if the call is currently recorded diff --git a/gnome/src/actions.c b/gnome/src/actions.c index dd7ce452cd..35cd55a39c 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -812,19 +812,19 @@ sflphone_add_main_participant(const conference_obj_t * c) dbus_add_main_participant(c->_confID); } -void + +gboolean sflphone_rec_call(SFLPhoneClient *client) { + gboolean result = FALSE; callable_obj_t * selectedCall = calltab_get_selected_call(current_calls_tab); conference_obj_t * selectedConf = calltab_get_selected_conf(current_calls_tab); if (selectedCall) { - g_debug("Set record for selected call"); - dbus_set_record(selectedCall->_callID); + result = dbus_toggle_recording(selectedCall->_callID); calltree_update_call(current_calls_tab, selectedCall, client, TRUE); } else if (selectedConf) { - g_debug("Set record for selected conf"); - dbus_set_record(selectedConf->_confID); + result = dbus_toggle_recording(selectedConf->_confID); switch (selectedConf->_state) { case CONFERENCE_STATE_ACTIVE_ATTACHED: @@ -851,6 +851,7 @@ sflphone_rec_call(SFLPhoneClient *client) } else { update_actions(client); } + return result; } void diff --git a/gnome/src/actions.h b/gnome/src/actions.h index 5e0b50d707..7d0388d869 100644 --- a/gnome/src/actions.h +++ b/gnome/src/actions.h @@ -187,7 +187,7 @@ void sflphone_fill_codec_list_per_account(account_t *); void sflphone_add_participant(); -void sflphone_rec_call(SFLPhoneClient *client); +gboolean sflphone_rec_call(SFLPhoneClient *client); void sflphone_mute_call(void); diff --git a/gnome/src/dbus/callmanager-introspec.xml b/gnome/src/dbus/callmanager-introspec.xml index 3823492914..6551f36189 100644 --- a/gnome/src/dbus/callmanager-introspec.xml +++ b/gnome/src/dbus/callmanager-introspec.xml @@ -325,7 +325,24 @@ </arg> </method> + <method name="toggleRecording" tp:name-for-bindings="toggleRecording"> + <tp:docstring> + Toggle recording for a call. + </tp:docstring> + <arg type="s" name="callID" direction="in"> + <tp:docstring> + The ID of the call to start/stop recording. + </tp:docstring> + </arg> + <arg type="b" name="isRecording" direction="out"> + <tp:docstring> + Returns true is the call is being recorded. False otherwise. + </tp:docstring> + </arg> + </method> + <method name="setRecording" tp:name-for-bindings="setRecording"> + <annotation name="org.freedesktop.DBus.Deprecated" value="true"/> <tp:docstring> Start recording a call. </tp:docstring> diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index 87fc6f4775..d7a792798c 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -1533,12 +1533,14 @@ dbus_join_conference(const gchar *sel_confID, const gchar *drag_confID) check_error(error); } -void -dbus_set_record(const gchar *id) +gboolean +dbus_toggle_recording(const gchar *id) { GError *error = NULL; - org_sflphone_SFLphone_CallManager_set_recording(call_proxy, id, &error); + gboolean isRecording; + org_sflphone_SFLphone_CallManager_toggle_recording(call_proxy, id, &isRecording, &error); check_error(error); + return isRecording; } gboolean diff --git a/gnome/src/dbus/dbus.h b/gnome/src/dbus/dbus.h index f0c74f5efb..b7263d0870 100644 --- a/gnome/src/dbus/dbus.h +++ b/gnome/src/dbus/dbus.h @@ -439,7 +439,7 @@ gchar *dbus_get_conference_id(const gchar *callID); /** * Toggle recording for this instance, may be call or conference */ -void dbus_set_record(const gchar *id); +gboolean dbus_toggle_recording(const gchar *id); /** * Set the path where the recorded audio files will be stored diff --git a/gnome/src/uimanager.c b/gnome/src/uimanager.c index f51f540e74..a7e8a5c725 100644 --- a/gnome/src/uimanager.c +++ b/gnome/src/uimanager.c @@ -748,7 +748,10 @@ static void call_record(G_GNUC_UNUSED GtkAction *action, SFLPhoneClient *client) { g_debug("Record button pressed"); - sflphone_rec_call(client); + /* Ensure that button is set to correct state, but suppress signal */ + g_signal_handler_block(recordWidget_, recordButtonConnId_); + gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(recordWidget_), sflphone_rec_call(client)); + g_signal_handler_unblock(recordWidget_, recordButtonConnId_); } static void -- GitLab