diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-17 05:37:25 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-17 05:37:25 +0000 |
commit | b9e3d0d154f994e77091e250a412415a2c454140 (patch) | |
tree | 1b7311ff1dfbd4d51bbae93730158eb14b61d379 | |
parent | e01f8fc1b12bef2619ade2c8a664d8d15116cfe9 (diff) |
Tox: removed unneeded event
git-svn-id: http://svn.miranda-ng.org/main/trunk@12879 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Tox/src/tox_accounts.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 54 | ||||
-rw-r--r-- | protocols/Tox/src/tox_multimedia.cpp | 191 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 1 | ||||
-rw-r--r-- | protocols/Tox/src/tox_transfer.cpp | 8 |
5 files changed, 159 insertions, 97 deletions
diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 5d1bf1886d..2e77486c37 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -35,8 +35,6 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit);
HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage);
- HookEvent(ME_DB_EVENT_ADDED, &CToxProto::OnDbEventAdded);
-
return 0;
}
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index f1e21e955a..22b7bf4afd 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -40,58 +40,4 @@ void CToxProto::InitCustomDbEvents() dbEventType.descr = Translate("Audio end");
dbEventType.eventIcon = GetIconHandle("audio_end");
CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);
-}
-
-int CToxProto::OnDbEventAdded(WPARAM hContact, LPARAM hEvent)
-{
- DWORD dwSignature;
-
- DBEVENTINFO dbei = { sizeof(dbei) };
- dbei.cbBlob = sizeof(DWORD);
- dbei.pBlob = (PBYTE)&dwSignature;
- db_event_get(hEvent, &dbei);
- if (dbei.flags & (DBEF_SENT | DBEF_READ) || dbei.eventType <= DB_EVENT_ACTION || dwSignature == 0)
- return 0;
-
- DBEVENTTYPEDESCR *dbEventType = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)MODULE, dbei.eventType);
- if (dbEventType == NULL)
- return 0;
-
- CLISTEVENT cle = { sizeof(cle) };
- cle.flags |= CLEF_TCHAR;
- cle.hContact = hContact;
- cle.hDbEvent = hEvent;
- cle.hIcon = Skin_GetIconByHandle(dbEventType->eventIcon);
-
- TCHAR szTooltip[256];
- mir_sntprintf(szTooltip, SIZEOF(szTooltip), _T("%s %s %s"), _A2T(dbEventType->descr), TranslateT("from"), pcli->pfnGetContactDisplayName(hContact, 0));
- cle.ptszTooltip = szTooltip;
-
- char szService[256];
- switch (dbei.eventType)
- {
- case DB_EVENT_AUDIO_CALL:
- mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Call", GetContactProto(hContact));
- break;
-
- case DB_EVENT_AUDIO_RING:
- mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Ring", GetContactProto(hContact));
- break;
-
- case DB_EVENT_AUDIO_START:
- mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Start", GetContactProto(hContact));
- break;
-
- case DB_EVENT_AUDIO_END:
- mir_snprintf(szService, SIZEOF(szService), "%s/Audio/End", GetContactProto(hContact));
- break;
-
- default:
- return 0;
- }
- cle.pszService = szService;
-
- CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
-
- return 0;
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_multimedia.cpp b/protocols/Tox/src/tox_multimedia.cpp index 3d6931eedc..abe371a409 100644 --- a/protocols/Tox/src/tox_multimedia.cpp +++ b/protocols/Tox/src/tox_multimedia.cpp @@ -3,8 +3,8 @@ /* AUDIO RECEIVING */
CToxAudioCall::CToxAudioCall(CToxProto *proto, int callId) :
- CToxDlgBase(proto, IDD_AUDIO, false), callId(callId),
- ok(this, IDOK), cancel(this, IDCANCEL)
+CToxDlgBase(proto, IDD_AUDIO, false), callId(callId),
+ok(this, IDOK), cancel(this, IDCANCEL)
{
m_autoClose = CLOSE_ON_CANCEL;
ok.OnClick = Callback(this, &CToxAudioCall::OnOk);
@@ -14,7 +14,7 @@ CToxAudioCall::CToxAudioCall(CToxProto *proto, int callId) : void CToxAudioCall::OnInitDialog()
{
char iconName[100];
- mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "audio_call");
+ mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "audio_start");
SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16));
SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32));
@@ -36,10 +36,7 @@ void CToxAudioCall::OnCancel(CCtrlBase*) if (ok.Enabled())
toxav_reject(m_proto->toxAv, callId, NULL);
else
- {
- int friendNumber = toxav_get_peer_id(m_proto->toxAv, callId, 0);
- toxav_cancel(m_proto->toxAv, callId, friendNumber, NULL);
- }
+ toxav_stop_call(m_proto->toxAv, callId);
}
void CToxAudioCall::OnClose()
@@ -52,7 +49,7 @@ INT_PTR CToxAudioCall::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg == WM_AUDIO_END)
Close();
-
+
return CToxDlgBase::DlgProc(msg, wParam, lParam);
}
@@ -95,8 +92,8 @@ void CToxProto::OnAvInvite(void*, int32_t callId, void *arg) PROTORECVEVENT recv = { 0 };
recv.timestamp = time(NULL);
recv.lParam = callId;
- //recv.flags = PREF_UTF;
- //recv.szMessage = mir_utf8encodeT(TranslateT("Incoming audio call"));
+ recv.flags = PREF_UTF;
+ recv.szMessage = mir_utf8encodeT(TranslateT("Incoming audio call"));
ProtoChainRecv(hContact, PSR_AUDIO, hContact, (LPARAM)&recv);
}
@@ -110,13 +107,29 @@ INT_PTR CToxProto::OnRecvAudioCall(WPARAM hContact, LPARAM lParam) DBEVENTINFO dbei = { sizeof(dbei) };
dbei.szModule = m_szModuleName;
dbei.timestamp = pre->timestamp;
- //dbei.flags = DBEF_UTF;
+ dbei.flags = DBEF_UTF;
dbei.eventType = DB_EVENT_AUDIO_RING;
+ dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
+ dbei.pBlob = (PBYTE)pre->szMessage;
+ MEVENT hEvent = db_event_add(hContact, &dbei);
+
+ CLISTEVENT cle = { sizeof(cle) };
+ cle.flags |= CLEF_TCHAR;
+ cle.hContact = hContact;
+ cle.hDbEvent = hEvent;
+ cle.hIcon = Skin_GetIconByHandle(GetIconHandle("audio_ring"));
- //dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
- //dbei.pBlob = (PBYTE)pre->szMessage;
+ TCHAR szTooltip[256];
+ mir_sntprintf(szTooltip, SIZEOF(szTooltip), _T("%s %s %s"), TranslateT("Incoming audio call"), TranslateT("from"), pcli->pfnGetContactDisplayName(hContact, 0));
+ cle.ptszTooltip = szTooltip;
- return (INT_PTR)db_event_add(hContact, &dbei);
+ char szService[256];
+ mir_snprintf(szService, SIZEOF(szService), "%s/Audio/Ring", GetContactProto(hContact));
+ cle.pszService = szService;
+
+ CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
+
+ return hEvent;
}
//
@@ -128,22 +141,138 @@ INT_PTR CToxProto::OnAudioRing(WPARAM hContact, LPARAM lParam) return 0;
}
-void CToxProto::OnAvRinging(void*, int32_t callId, void *arg) { }
-void CToxProto::OnAvStart(void*, int32_t callId, void *arg) { }
+void CToxProto::OnAvRinging(void*, int32_t callId, void *arg)
+{
+}
+
+void CToxProto::OnAvStart(void*, int32_t callId, void *arg)
+{
+ CToxProto *proto = (CToxProto*)arg;
+
+ int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ if (friendNumber == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ MCONTACT hContact = proto->GetContact(friendNumber);
+ if (hContact == NULL)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get contact");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = proto->m_szModuleName;
+ dbei.timestamp = time(NULL);
+ dbei.flags = DBEF_UTF;
+ dbei.eventType = DB_EVENT_AUDIO_START;
+ dbei.pBlob = (PBYTE)mir_utf8encodeT(TranslateT("Audio call start"));;
+ dbei.cbBlob = (DWORD)mir_strlen((char*)dbei.pBlob) + 1;
+ db_event_add(hContact, &dbei);
+
+ if (toxav_prepare_transmission(proto->toxAv, callId, false) == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to prepare transmition");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+}
void CToxProto::OnAvEnd(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
+ int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ if (friendNumber == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ MCONTACT hContact = proto->GetContact(friendNumber);
+ if (hContact == NULL)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get contact");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = proto->m_szModuleName;
+ dbei.timestamp = time(NULL);
+ dbei.flags = DBEF_UTF;
+ dbei.eventType = DB_EVENT_AUDIO_END;
+ dbei.pBlob = (PBYTE)mir_utf8encodeT(TranslateT("Audio call end"));;
+ dbei.cbBlob = (DWORD)mir_strlen((char*)dbei.pBlob) + 1;
+ db_event_add(hContact, &dbei);
+
WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, 0, 0);
}
-void CToxProto::OnAvReject(void*, int32_t callId, void *arg) { }
+void CToxProto::OnAvReject(void*, int32_t callId, void *arg)
+{
+ CToxProto *proto = (CToxProto*)arg;
+
+ int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ if (friendNumber == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ MCONTACT hContact = proto->GetContact(friendNumber);
+ if (hContact == NULL)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get contact");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = proto->m_szModuleName;
+ dbei.timestamp = time(NULL);
+ dbei.flags = DBEF_UTF;
+ dbei.eventType = DB_EVENT_AUDIO_END;
+ dbei.pBlob = (PBYTE)mir_utf8encodeT(TranslateT("Audio call end"));;
+ dbei.cbBlob = (DWORD)mir_strlen((char*)dbei.pBlob) + 1;
+ db_event_add(hContact, &dbei);
+}
void CToxProto::OnAvCancel(void*, int32_t callId, void *arg)
{
CToxProto *proto = (CToxProto*)arg;
+ int friendNumber = toxav_get_peer_id(proto->toxAv, callId, 0);
+ if (friendNumber == TOX_ERROR)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get friend number");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ MCONTACT hContact = proto->GetContact(friendNumber);
+ if (hContact == NULL)
+ {
+ proto->debugLogA(__FUNCTION__": failed to get contact");
+ toxav_stop_call(proto->toxAv, callId);
+ return;
+ }
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = proto->m_szModuleName;
+ dbei.timestamp = time(NULL);
+ dbei.flags = DBEF_UTF;
+ dbei.eventType = DB_EVENT_AUDIO_END;
+ dbei.pBlob = (PBYTE)mir_utf8encodeT(TranslateT("Audio call end"));;
+ dbei.cbBlob = (DWORD)mir_strlen((char*)dbei.pBlob) + 1;
+ db_event_add(hContact, &dbei);
+
WindowList_Broadcast(proto->hAudioDialogs, WM_AUDIO_END, 0, 0);
}
@@ -156,7 +285,8 @@ void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_ CToxProto *proto = (CToxProto*)arg;
ToxAvCSettings dest;
- if (toxav_get_peer_csettings(proto->toxAv, callId, 0, &dest) != av_ErrorNone)
+ int err = toxav_get_peer_csettings(proto->toxAv, callId, 0, &dest);
+ if (err != av_ErrorNone)
{
proto->debugLogA(__FUNCTION__": failed to get codec settings");
toxav_stop_call(proto->toxAv, callId);
@@ -173,13 +303,13 @@ void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_ WAVEFORMATEX wfx = { 0 };
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = dest.audio_channels;
- wfx.wBitsPerSample = dest.audio_bitrate;
+ wfx.wBitsPerSample = dest.audio_bitrate / 1000;
wfx.nSamplesPerSec = dest.audio_sample_rate;
wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample) / 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
- DWORD deviceId = proto->getDword("AudioOutputDeviceID", -1);
- if (deviceId != av_ErrorNone)
+ DWORD deviceId = proto->getDword("AudioOutputDeviceID", TOX_ERROR);
+ if (deviceId == TOX_ERROR)
{
proto->debugLogA(__FUNCTION__": failed to get device id");
toxav_stop_call(proto->toxAv, callId);
@@ -187,7 +317,7 @@ void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_ }
HWAVEOUT hDevice;
- MMRESULT result = waveOutOpen(&hDevice, deviceId, &wfx, 0, 0, CALLBACK_NULL | WAVE_FORMAT_DIRECT);
+ MMRESULT result = waveOutOpen(&hDevice, deviceId, &wfx, 0, 0, CALLBACK_NULL);
if (result != MMSYSERR_NOERROR)
{
proto->debugLogA(__FUNCTION__": failed to open audio device");
@@ -195,8 +325,7 @@ void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_ return;
}
- WAVEHDR header;// = { 0 };
- ZeroMemory(&header, sizeof(WAVEHDR));
+ WAVEHDR header = { 0 };
header.lpData = (LPSTR)PCM;
header.dwBufferLength = size;
@@ -216,18 +345,8 @@ void CToxProto::OnFriendAudio(void*, int32_t callId, const int16_t *PCM, uint16_ return;
}
- do
- {
- Sleep(100);
- result = waveOutUnprepareHeader(hDevice, &header, sizeof(WAVEHDR));
- } while (result == WAVERR_STILLPLAYING);
-
- if (result != MMSYSERR_NOERROR)
- {
- proto->debugLogA(__FUNCTION__": failed to unprepare audio device header");
- toxav_stop_call(proto->toxAv, callId);
- return;
- }
+ while (waveOutUnprepareHeader(hDevice, &header, sizeof(WAVEHDR)) == WAVERR_STILLPLAYING)
+ Sleep(10);
waveOutClose(hDevice);
}
\ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 6fc1dc9c9c..c6c953a8b2 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -137,7 +137,6 @@ private: int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam);
// events
- static int __cdecl OnDbEventAdded(WPARAM hContact, LPARAM hEvent);
// userinfo
static INT_PTR CALLBACK UserInfoProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
diff --git a/protocols/Tox/src/tox_transfer.cpp b/protocols/Tox/src/tox_transfer.cpp index 777671f418..8a2017affb 100644 --- a/protocols/Tox/src/tox_transfer.cpp +++ b/protocols/Tox/src/tox_transfer.cpp @@ -138,11 +138,11 @@ void CToxProto::OnFileReceiveData(Tox*, uint32_t friendNumber, uint32_t fileNumb FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
-// tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ proto->debugLogA(__FUNCTION__": failed to fing transfer (%d)", fileNumber);
return;
}
- if (length == 0 || (position == UINT64_MAX))
+ if (length == 0 || position == UINT64_MAX)
{
//receiving is finished
proto->debugLogA(__FUNCTION__": finised the transfer of file (%d)", fileNumber);
@@ -232,7 +232,7 @@ void CToxProto::OnFileSendData(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
-// tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ proto->debugLogA(__FUNCTION__": failed to fing transfer (%d)", fileNumber);
return;
}
@@ -305,7 +305,7 @@ void CToxProto::OnFileRequest(Tox*, uint32_t friendNumber, uint32_t fileNumber, FileTransferParam *transfer = proto->transfers.Get(friendNumber, fileNumber);
if (transfer == NULL)
{
- tox_file_control(proto->tox, transfer->friendNumber, transfer->fileNumber, TOX_FILE_CONTROL_CANCEL, NULL);
+ proto->debugLogA(__FUNCTION__": failed to fing transfer (%d)", fileNumber);
return;
}
|