diff options
Diffstat (limited to 'protocols/Tox/src/tox_multimedia.cpp')
-rw-r--r-- | protocols/Tox/src/tox_multimedia.cpp | 301 |
1 files changed, 164 insertions, 137 deletions
diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp index 729a75f17f..fa08e66ea5 100644 --- a/protocols/Tox/src/tox_multimedia.cpp +++ b/protocols/Tox/src/tox_multimedia.cpp @@ -1,18 +1,31 @@ #include "common.h"
-/* AUDIO RECEIVING */
+CToxCallDlgBase::CToxCallDlgBase(CToxProto *proto, int idDialog, MCONTACT hContact) :
+ CToxDlgBase(proto, idDialog, false), hContact(hContact)
+{
+}
-CToxAudioCall::CToxAudioCall(CToxProto *proto, MCONTACT hContact) :
-CToxDlgBase(proto, IDD_AUDIO, false),
-hContact(hContact), isCallStarted(false),
-ok(this, IDOK), cancel(this, IDCANCEL)
+void CToxCallDlgBase::OnInitDialog()
{
- m_autoClose = CLOSE_ON_CANCEL;
- ok.OnClick = Callback(this, &CToxAudioCall::OnOk);
- cancel.OnClick = Callback(this, &CToxAudioCall::OnCancel);
+ Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, typeid(this).name());
+}
+
+void CToxCallDlgBase::OnClose()
+{
+ //WindowList_Remove(m_proto->hAudioDialogs, m_hwnd);
+ Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, typeid(this).name());
+}
+
+INT_PTR CToxCallDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (msg == WM_CALL_END)
+ if (wParam == hContact)
+ Close();
+
+ return CToxDlgBase::DlgProc(msg, wParam, lParam);
}
-void CToxAudioCall::SetIcon(const char *name)
+void CToxCallDlgBase::SetIcon(const char *name)
{
char iconName[100];
mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, name);
@@ -20,34 +33,138 @@ void CToxAudioCall::SetIcon(const char *name) SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32));
}
-void CToxAudioCall::OnInitDialog()
+void CToxCallDlgBase::SetTitle(const TCHAR *title)
{
- Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "AudioCallWindow");
+ SetWindowText(m_hwnd, title);
}
-void CToxAudioCall::OnClose()
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+CToxIncomingCall::CToxIncomingCall(CToxProto *proto, MCONTACT hContact) :
+ CToxCallDlgBase(proto, IDD_CALL_RECEIVE, hContact),
+ from(this, IDC_FROM), date(this, IDC_DATE),
+ answer(this, IDOK), reject(this, IDCANCEL)
{
- WindowList_Remove(m_proto->hAudioDialogs, m_hwnd);
- Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "AudioCallWindow");
+ answer.OnClick = Callback(this, &CToxIncomingCall::OnAnswer);
}
-INT_PTR CToxAudioCall::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+void CToxIncomingCall::OnInitDialog()
{
- if (msg == WM_AUDIO_END)
- if (wParam == hContact)
- Close();
+ TCHAR *nick = pcli->pfnGetContactDisplayName(hContact, 0);
+ from.SetText(nick);
- return CToxDlgBase::DlgProc(msg, wParam, lParam);
+ TCHAR title[MAX_PATH];
+ mir_sntprintf(title, SIZEOF(title), TranslateT("Incoming call from %s"), nick);
+ SetTitle(title);
+ SetIcon("audio_ring");
+}
+
+void CToxIncomingCall::OnClose()
+{
+ toxav_reject(m_proto->toxAv, m_proto->calls[hContact], NULL);
+}
+
+void CToxIncomingCall::OnAnswer(CCtrlBase*)
+{
+ ToxAvCSettings *cSettings = m_proto->GetAudioCSettings();
+ if (cSettings == NULL)
+ {
+ Close();
+ return;
+ }
+
+ if (toxav_answer(m_proto->toxAv, m_proto->calls[hContact], cSettings) == TOX_ERROR)
+ {
+ m_proto->debugLogA(__FUNCTION__": failed to start call");
+ Close();
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+CToxOutgoingCall::CToxOutgoingCall(CToxProto *proto, MCONTACT hContact) :
+ CToxCallDlgBase(proto, IDD_CALL_SEND, hContact),
+ to(this, IDC_FROM), call(this, IDOK), cancel(this, IDCANCEL)
+{
+ m_autoClose = CLOSE_ON_CANCEL;
+ call.OnClick = Callback(this, &CToxOutgoingCall::OnCall);
+ cancel.OnClick = Callback(this, &CToxOutgoingCall::OnCancel);
+}
+
+void CToxOutgoingCall::OnInitDialog()
+{
+ TCHAR *nick = pcli->pfnGetContactDisplayName(hContact, 0);
+ to.SetText(nick);
+
+ TCHAR title[MAX_PATH];
+ mir_sntprintf(title, SIZEOF(title), TranslateT("Outgoing call to %s"), nick);
+ SetTitle(title);
+ SetIcon("audio_end");
}
-void CToxAudioCall::OnStartCall()
+void CToxOutgoingCall::OnCall(CCtrlBase*)
+{
+ ToxAvCSettings *cSettings = m_proto->GetAudioCSettings();
+ if (cSettings == NULL)
+ {
+ Close();
+ return;
+ }
+
+ int friendNumber = m_proto->GetToxFriendNumber(hContact);
+ if (friendNumber == UINT32_MAX)
+ {
+ Close();
+ return;
+ }
+
+ int32_t callId;
+ if (toxav_call(m_proto->toxAv, &callId, friendNumber, cSettings, 10) == TOX_ERROR)
+ {
+ m_proto->debugLogA(__FUNCTION__": failed to start outgoing call");
+ return;
+ }
+ m_proto->calls[hContact] = callId;
+
+ char *message = mir_utf8encodeT(TranslateT("Outgoing call"));
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = m_proto->m_szModuleName;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = DB_EVENT_AUDIO_CALL;
+ dbei.flags = DBEF_UTF;
+ dbei.pBlob = (PBYTE)message;
+ dbei.cbSize = mir_strlen(message);
+ db_event_add(hContact, &dbei);
+
+ call.Enable(FALSE);
+ SetIcon("audio_call");
+}
+
+void CToxOutgoingCall::OnCancel(CCtrlBase*)
+{
+ if (!call.Enabled())
+ toxav_cancel(m_proto->toxAv, m_proto->calls[hContact], 0, NULL);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+CToxCallDialog::CToxCallDialog(CToxProto *proto, MCONTACT hContact) :
+ CToxCallDlgBase(proto, IDD_CALL, hContact), end(this, IDCANCEL)
+{
+}
+
+void CToxCallDialog::OnInitDialog()
{
- ok.Enable(FALSE);
- isCallStarted = true;
SetIcon("audio_start");
}
-//
+void CToxCallDialog::OnClose()
+{
+ toxav_hangup(m_proto->toxAv, m_proto->calls[hContact]);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
ToxAvCSettings* CToxProto::GetAudioCSettings()
{
@@ -83,7 +200,7 @@ ToxAvCSettings* CToxProto::GetAudioCSettings() cSettings->audio_bitrate = 8 * 1000;
cSettings->audio_sample_rate = 48000;
}
- /*else if ((wic.dwFormats & WAVE_FORMAT_4S16) || (wic.dwFormats & WAVE_FORMAT_4M16))
+ else if ((wic.dwFormats & WAVE_FORMAT_4S16) || (wic.dwFormats & WAVE_FORMAT_4M16))
{
cSettings->audio_bitrate = 16 * 1000;
cSettings->audio_sample_rate = 24000;
@@ -112,7 +229,7 @@ ToxAvCSettings* CToxProto::GetAudioCSettings() {
cSettings->audio_bitrate = 8 * 1000;
cSettings->audio_sample_rate = 8000;
- }*/
+ }
else
{
debugLogA(__FUNCTION__": failed to parse input device caps");
@@ -123,43 +240,9 @@ ToxAvCSettings* CToxProto::GetAudioCSettings() return cSettings;
}
-// incoming call flow
-
-CToxIncomingAudioCall::CToxIncomingAudioCall(CToxProto *proto, MCONTACT hContact) :
-CToxAudioCall(proto, hContact)
-{
-}
-
-void CToxIncomingAudioCall::OnInitDialog()
-{
- SetIcon("audio_ring");
- CToxAudioCall::OnInitDialog();
-}
-
-void CToxIncomingAudioCall::OnOk(CCtrlBase*)
-{
- ToxAvCSettings *cSettings = m_proto->GetAudioCSettings();
- if (cSettings == NULL)
- {
- Close();
- return;
- }
-
- if (toxav_answer(m_proto->toxAv, m_proto->calls[hContact], cSettings) == TOX_ERROR)
- {
- m_proto->debugLogA(__FUNCTION__": failed to start call");
- Close();
- }
-}
-
-void CToxIncomingAudioCall::OnCancel(CCtrlBase*)
-{
- if (!isCallStarted)
- toxav_reject(m_proto->toxAv, m_proto->calls[hContact], NULL);
- else
- toxav_hangup(m_proto->toxAv, m_proto->calls[hContact]);
-}
+/* AUDIO RECEIVING */
+// incoming call flow
void CToxProto::OnAvInvite(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
@@ -244,9 +327,9 @@ INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam) INT_PTR CToxProto::OnAudioRing(WPARAM wParam, LPARAM lParam)
{
CLISTEVENT *cle = (CLISTEVENT*)lParam;
- CToxAudioCall *audioCall = new CToxIncomingAudioCall(this, cle->hContact);
- audioCall->Show();
- WindowList_Add(hAudioDialogs, audioCall->GetHwnd(), cle->hContact);
+ CDlgBase *incomingCallDlg = new CToxIncomingCall(this, cle->hContact);
+ incomingCallDlg->Show();
+ WindowList_Add(hAudioDialogs, incomingCallDlg->GetHwnd(), cle->hContact);
return 0;
}
@@ -286,73 +369,17 @@ void CToxProto::OnAvCancel(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, hContact, 0);
+ WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0);
}
/* AUDIO SENDING */
// outcoming audio flow
-CToxOutgoingAudioCall::CToxOutgoingAudioCall(CToxProto *proto, MCONTACT hContact) :
-CToxAudioCall(proto, hContact)
-{
-}
-
-void CToxOutgoingAudioCall::OnInitDialog()
-{
- SetIcon("audio_end");
- CToxAudioCall::OnInitDialog();
-}
-
-void CToxOutgoingAudioCall::OnOk(CCtrlBase*)
-{
- int32_t callId;
- int friendNumber = m_proto->GetToxFriendNumber(hContact);
- if (friendNumber == UINT32_MAX)
- {
- Close();
- return;
- }
-
- ToxAvCSettings *cSettings = m_proto->GetAudioCSettings();
- if (cSettings == NULL)
- {
- Close();
- return;
- }
-
- if (toxav_call(m_proto->toxAv, &callId, friendNumber, cSettings, 10) == TOX_ERROR)
- {
- m_proto->debugLogA(__FUNCTION__": failed to start outgoing call");
- return;
- }
- m_proto->calls[hContact] = callId;
- SetIcon("audio_call");
-
- char *message = mir_utf8encodeT(TranslateT("Outgoing call"));
-
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.szModule = m_proto->m_szModuleName;
- dbei.timestamp = time(NULL);
- dbei.eventType = DB_EVENT_AUDIO_CALL;
- dbei.flags = DBEF_UTF;
- dbei.pBlob = (PBYTE)message;
- dbei.cbSize = mir_strlen(message);
- db_event_add(hContact, &dbei);
-}
-
-void CToxOutgoingAudioCall::OnCancel(CCtrlBase*)
-{
- if (!isCallStarted)
- toxav_cancel(m_proto->toxAv, m_proto->calls[hContact], 0, NULL);
- else
- toxav_hangup(m_proto->toxAv, m_proto->calls[hContact]);
-}
-
INT_PTR CToxProto::OnSendAudioCall(WPARAM hContact, LPARAM)
{
- CToxAudioCall *audioCall = new CToxOutgoingAudioCall(this, hContact);
- audioCall->Show();
- WindowList_Add(hAudioDialogs, audioCall->GetHwnd(), hContact);
+ CDlgBase *outgoingCallDlg = new CToxOutgoingCall(this, hContact);
+ outgoingCallDlg->Show();
+ WindowList_Add(hAudioDialogs, outgoingCallDlg->GetHwnd(), hContact);
return 0;
}
@@ -388,7 +415,7 @@ void CToxProto::OnAvReject(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, hContact, 0);
+ WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0);
}
void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg)
@@ -422,7 +449,7 @@ void CToxProto::OnAvCallTimeout(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, hContact, 0);
+ WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0);
}
/* --- */
@@ -487,9 +514,12 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg) return;
}
- //HWND hwnd = WindowList_Find(proto->hAudioDialogs, hContact);
- //CToxAudioCall *audioCall = (CToxAudioCall*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- //audioCall->OnStartCall();
+ if (toxav_prepare_transmission(proto->toxAv, callId, false) == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to prepare audio transmition");
+ toxav_hangup(proto->toxAv, callId);
+ return;
+ }
char *message = mir_utf8encodeT(TranslateT("Call started"));
@@ -502,12 +532,9 @@ void CToxProto::OnAvStart(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- if (toxav_prepare_transmission(proto->toxAv, callId, false) == TOX_ERROR)
- {
- proto->debugLogA(__FUNCTION__": failed to prepare audio transmition");
- toxav_hangup(proto->toxAv, callId);
- return;
- }
+ CDlgBase *callDlg = new CToxCallDialog(proto, hContact);
+ callDlg->Show();
+ WindowList_Add(proto->hAudioDialogs, callDlg->GetHwnd(), hContact);
}
void CToxProto::OnAvEnd(void*, int32_t callId, void *arg)
@@ -542,7 +569,7 @@ void CToxProto::OnAvEnd(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, hContact, 0);
+ WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0);
}
void CToxProto::OnAvPeerTimeout(void*, int32_t callId, void *arg)
@@ -580,7 +607,7 @@ void CToxProto::OnAvPeerTimeout(void*, int32_t callId, void *arg) dbei.cbSize = mir_strlen(message);
db_event_add(hContact, &dbei);
- WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, hContact, 0);
+ WindowList_Broadcast(proto->hAudioDialogs, WM_CALL_END, hContact, 0);
toxav_kill_transmission(proto->toxAv, callId);
}
|