source: verona/phcpp/phapipp.cpp @ 138:efddf6e11c3c

Last change on this file since 138:efddf6e11c3c was 138:efddf6e11c3c, checked in by laurent, 2 years ago

bug fix : media accessors

File size: 12.4 KB
Line 
1/*
2  The phapipp module implements thin C++ wrapper around phapi
3  Copyright (C) 2007  Vadim Lebedev  <vadim@mbdsys.com>
4
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20
21#include <assert.h>
22#include <stdlib.h>
23#include <string.h>
24#include <stdio.h>
25
26#include "phapipp.h"
27
28#if defined(_WIN32)
29#include <windows.h>
30# ifdef _WIN32_WCE
31#  include "connmgr_status.h"
32# endif
33#define strdup _strdup
34#endif
35
36namespace verona {
37
38static phapi *uniqueobj;
39
40phapi::phapi()
41{
42        assert(uniqueobj == 0);
43        uniqueobj = this;
44}
45
46
47phapi::~phapi()
48{
49        assert(uniqueobj == this);
50        uniqueobj = 0;
51}
52
53
54
55int phapi::init(bool asyncMode)
56{
57        return phInit(&callbacks, 0, asyncMode);
58}
59
60
61void phapi::terminate()
62{
63        phTerminate();
64}
65
66
67
68int phapi::addAuthInfo(const char* username, const char* userid,  const char* passwd,
69                const char *realm, const char* ha1)
70{
71        return phAddAuthInfo(username, userid, passwd, ha1, realm);
72}
73
74
75int phapi::addVline(const char* displayname, const char* username, const char* host,
76                const char*  proxy, int regTimeout, int mobility)
77{
78        return phAddVline3(displayname, username, host, proxy, regTimeout, mobility);
79}
80
81int phapi::delVline(int vlid)
82{
83        return phDelVline(vlid);
84}
85
86int phapi::vlRegister(int vlid)
87{
88        return phvlRegister(vlid);
89}
90
91int phapi::sendOptions(int vlid, const char *to)
92{
93        return phLineSendOptions(vlid, to);
94}
95
96int phapi::placeCall(int vlid, const char*  uri, void* userdata, int rcid, int streams,
97                const char* adev, const char* audio_addr, const char* video_addr)
98{
99        return phLinePlaceCall4(vlid, uri, userdata, rcid, streams, adev, audio_addr, video_addr);
100}
101
102
103int phapi::acceptCall(int cid, void* userData, int streams,
104                const char* audio_addr, const char* video_addr)
105{
106        return phAcceptCall4(cid, userData, streams, audio_addr, video_addr);
107}
108
109
110int phapi::rejectCall(int cid, int reason, const char *uri)
111{
112        return uri ? phRejectCall(cid, reason) : phRejectCall2(cid, uri, reason);
113}
114
115
116int phapi::ringingCall(int cid)
117{
118        return phRingingCall(cid);
119}
120
121int phapi::closeCall(int cid)
122{
123        return phCloseCall(cid);
124
125}
126
127int phapi::sendDtmf(int cid, int dtmfChar, int mode)
128{
129        return phSendDtmf(cid, dtmfChar, mode);
130}
131
132int phapi::messageInCall(int cid, const char *mime,  const char *buff)
133{
134        return phCallSendMessage(cid, (char*) mime, (char*) buff);
135}
136
137
138int phapi::getSipCallID(int cid, char *idbuf,  int bufsize)
139{
140        return phCallGetSipCallID(cid, idbuf, bufsize);
141}
142
143int phapi::setFollowMe(int vlid, const char *uri)
144{
145        return phLineSetFollowMe(vlid, uri);
146}
147
148int phapi::setBusy(int vlid, bool busy)
149{
150        return phLineSetBusy(vlid, busy);
151}
152
153int phapi::sendMessage(int vlid, const char* to,  const char* buff, const char* mime,
154                const char* target, const char* sipcid)
155{
156        return phLineSendMessage2(vlid, target, to, buff, mime, sipcid);
157}
158
159
160
161int phapi::subscribe(int vlid, const char* to, int winfo, char* data, int use_proxy, int expire)
162{
163        return phLineSubscribe2(vlid, to, winfo, data, use_proxy, expire);
164}
165
166
167int phapi::unsubscribe(int sid, int winfo)
168{
169        return phLineUnsubscribe(sid, winfo);
170}
171
172
173int phapi::publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content,
174                int expires)
175{
176        if (expires == -1)
177                expires = 600;
178
179        return phLinePublish2(vlid, to, evt, ctt, content, expires);
180}
181
182
183
184int phapi::poll()
185{
186        return phPoll();
187}
188
189void phapi::refresh()
190{
191        phRefresh();
192}
193
194
195void phapi::setLogFile(const char* logFile)
196{
197        phSetLogFileName(logFile);
198}
199
200
201int phapi::mobility(int vlid)
202{
203        return phLineGetMobility(vlid);
204
205}
206
207int phapi::getLineSipAddress(int vlid, char *buf, int size)
208{
209        return phLineGetSipAddress(vlid, buf, size);
210}
211
212void phapi::setUaString(const char *uastr)
213{
214        phSetUaString(uastr);
215}
216
217void phapi::changeAudioCodecList(const char *audio_codecs)
218{
219        ph_config_s *phcfg = ph_get_config();
220        strncpy(phcfg->audio_codecs, audio_codecs, sizeof(phcfg->audio_codecs));
221}
222
223void phapi::changeVideoCodecList(const char *video_codecs)
224{
225        ph_config_s *phcfg = ph_get_config();
226        strncpy(phcfg->video_codecs, video_codecs, sizeof(phcfg->video_codecs));
227}
228       
229#if defined(_WIN32_WCE)
230char * phapi::getLocalIpFromDescription(const char *description)
231{
232        DWORD pcbBufferSize = 0;
233        ConnMgrQueryDetailedStatus(0,&pcbBufferSize);
234        CONNMGR_CONNECTION_DETAILED_STATUS *  pStatusBuffer = (CONNMGR_CONNECTION_DETAILED_STATUS *)calloc(pcbBufferSize, 1);
235
236        if(!ConnMgrQueryDetailedStatus(pStatusBuffer,&pcbBufferSize))
237        {
238                for (CONNMGR_CONNECTION_DETAILED_STATUS * curItem = pStatusBuffer; curItem != 0; curItem = curItem->pNext)
239                {
240                        WCHAR NameBuffer[512];
241                        mbstowcs(NameBuffer,description,512);
242
243                        if (curItem->pIPAddr != NULL && (curItem->szAdapterName && !wcscmp(NameBuffer,curItem->szAdapterName) || curItem->szDescription && !wcscmp(NameBuffer,curItem->szDescription)))
244                        {
245                                WCHAR addressAsString[128];
246                                DWORD addressSize = sizeof(addressAsString);
247
248                                WSAAddressToString((LPSOCKADDR)curItem->pIPAddr->IPAddr,128,0,addressAsString,&addressSize);
249
250                                char *local_ip = new char[128];
251                                WideCharToMultiByte(CP_ACP, 0, addressAsString, -1,local_ip, 128, NULL, NULL);
252                                return local_ip;
253                        }
254                }
255        }
256        return "";
257}
258#endif
259
260void phapi::changeLocalIP(const char *local_ip)
261{
262        ph_config_s *phcfg = ph_get_config();
263        strncpy(phcfg->local_ip_addr, local_ip, sizeof(phcfg->local_ip_addr));
264}
265
266std::map<char*, char*> phapi::getAudioCaptureDevices()
267{
268        ph_audio_card_desc_t* device_tab = NULL;
269        int pos = 0;
270        int i = 0;
271        std::map<char*, char*> device_map;
272
273        pos = phAudioCaptureCardList(&device_tab);
274
275        for (i = 0; i < pos; i++)
276        {
277                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].id));
278                printf("MSSndCard id:%s name:%s !!!!\n", device_tab[i].id, device_tab[i].name);
279        }
280       
281        if(device_tab)
282                delete device_tab;
283       
284        return device_map;
285}
286
287std::map<char*, char*> phapi::getVideoWebcamDevices()
288{
289        ph_video_web_cam_desc_t* device_tab = NULL;
290        int pos =0;
291        int i = 0;
292        std::map<char *, char*> device_map;
293               
294        pos = phVideoWebcamList(&device_tab);
295               
296        for (i = 0; i < pos; i++)
297        {
298                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].name));
299                printf("webcam id:%s name:%s !!!!\n", device_tab[i].id, device_tab[i].name);
300        }
301       
302        if(device_tab)
303                delete device_tab;
304       
305        return device_map;
306}
307       
308std::map<char*, char*> phapi::getAudioPlaybackDevices()
309{
310        ph_audio_card_desc_t* device_tab = NULL;
311        int pos = 0;
312        int i = 0;
313        std::map<char*, char*> device_map;
314
315        pos = phAudioPlaybackCardList(&device_tab);
316
317        for (i = 0; i < pos; i++)
318        {
319                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].name));
320        }
321       
322        if(device_tab)
323                delete device_tab;
324       
325        return device_map;
326}
327
328void phapi::changeAudioDevices(const char *devstr)
329{
330        phChangeAudioDevices(devstr);
331}
332
333void phapi::changeVideoDevices(const char *devstr)
334{
335        phChangeVideoDevices(devstr);
336}
337       
338int phapi::setSoftRecvVolumeGain(int cid, float gain)
339{
340        return phAudioSoftRecvVolumeGain(cid, gain);
341}
342
343int phapi::setSoftSendVolumeGain(int cid, float gain)
344{
345        return phAudioSoftSendVolumeGain(cid, gain);
346}
347
348int phapi::setRecvVolumeLevel(int cid, int level)
349{
350        return phAudioRecvVolumeLevel(cid, level);
351}
352
353int phapi::setSendVolumeLevel(int cid, int level)
354{
355        return phAudioSendVolumeLevel(cid, level);
356}
357
358int phapi::mutePlayback(int cid, int val)
359{
360        return phAudioMutePlayback(cid, val);
361}
362
363int phapi::muteCapture(int cid, int val)
364{
365        return phAudioMuteCapture(cid, val);
366}
367
368void phapi::onCallProgress(int cid, const phCallStateInfo_t *info)
369{
370        if(info->event == phDTMF)
371                onDtmfProgress(cid,info->dtmfDigit);
372        else if(info->event == phCALLCLOSED || info->event == phCALLERROR) {
373#if defined(_WIN32_WCE)
374                onCallProgress2(cid,info->event,(wchar_t*)"",info->errorCode);
375#else
376                onCallProgress2(cid,info->event,(char*)"",info->errorCode);
377#endif
378        }else {
379#if defined(_WIN32_WCE)
380                int utfsize = MultiByteToWideChar(CP_ACP, 0, info->remoteUri, -1, NULL, 0);
381                wchar_t *tmp = (wchar_t *)alloca((utfsize + 1) * sizeof(*tmp));
382                       
383                MultiByteToWideChar(CP_ACP, 0, info->remoteUri, -1,tmp, utfsize);
384                onCallProgress2(cid,info->event, tmp,info->errorCode);
385#else
386                onCallProgress2(cid,info->event,(char*)info->remoteUri,info->errorCode);
387#endif
388        }
389}
390
391#if defined(_WIN32_WCE)
392void phapi::onCallProgress2(int cid, phCallStateEvent status, wchar_t * uri, int error)
393#else
394void phapi::onCallProgress2(int cid, phCallStateEvent status, char * uri, int error)
395#endif
396{
397
398}
399
400void phapi::onDtmfProgress(int cid, int)
401{
402
403}
404
405void phapi::onTransferProgress(int cid, const phTransferStateInfo_t *info)  { }
406void phapi::onConfProgress(int cfid, const phConfStateInfo_t *info)  { }
407void phapi::onRegProgress(int regid, int status)  { }
408void phapi::onMsgProgress(int mid,  const phMsgStateInfo_t *info) 
409{
410        onMsgProgress2(mid,     (char *)info->rawctt, (char *)info->content);
411}
412void phapi::onMsgProgress2(int mid, char * type, char * content) { }
413void phapi::onConnectionLost(const char* host, int port) { }
414#if defined(_WIN32_WCE)
415void phapi::onNotifyProgress (const char* event, const char* from, const char *ctt, wchar_t* content)  { }
416#else
417void phapi::onNotifyProgress (const char* event, const char* from, const char *ctt, const char* content)  { }
418#endif
419void phapi::onSubscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info)  { }
420void phapi::onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev) { }
421void phapi::onPhLogCsl(const char *msg){ }
422
423
424void phapi::callProgress(int cid, const phCallStateInfo_t *info)
425{
426        if (uniqueobj)
427                uniqueobj->onCallProgress(cid, info);
428}
429
430void phapi::transferProgress(int cid, const phTransferStateInfo_t *info)
431{
432        if (uniqueobj)
433                uniqueobj->onTransferProgress(cid, info);
434
435}
436
437
438void phapi::confProgress(int cfid, const phConfStateInfo_t *info)
439{
440        if (uniqueobj)
441                uniqueobj->onConfProgress(cfid, info);
442
443}
444
445void phapi::regProgress(int regid, int status)
446{
447        if (uniqueobj)
448                uniqueobj->onRegProgress(regid, status);
449
450}
451
452void phapi::msgProgress(int mid,  const phMsgStateInfo_t *info)
453{
454        if (uniqueobj)
455                uniqueobj->onMsgProgress(mid, info);
456
457}
458
459void phapi::connectionLost(const char *host, int port)
460{
461        if (uniqueobj)
462                uniqueobj->onConnectionLost(host, port);
463}
464
465void phapi::notifyProgress (const char* event, const char* from, const char *ctt, const char* content)
466{
467#if defined(_WIN32_WCE)
468        int utfsize = MultiByteToWideChar(CP_ACP, 0, content, -1, NULL, 0);
469        wchar_t *tmp = (wchar_t *)alloca((utfsize + 1) * sizeof(*tmp));
470                       
471        MultiByteToWideChar(CP_ACP, 0, content, -1,tmp, utfsize);
472
473        if (uniqueobj)
474                uniqueobj->onNotifyProgress(event, from, ctt, tmp);
475#else
476        if (uniqueobj)
477                uniqueobj->onNotifyProgress(event, from, ctt, content);
478#endif
479
480}
481
482void phapi::subscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info)
483{
484        if (uniqueobj)
485                uniqueobj->onSubscriptionProgress(sid, info);
486
487}
488
489
490void phapi::frameReady(int cid, phVideoFrameReceivedEvent_t *ev)
491{
492        if (uniqueobj)
493                uniqueobj->onFrameReady(cid, ev);
494
495}
496
497void phapi::phLogCsl(const char *msg)
498{
499        if (uniqueobj)
500                uniqueobj->onPhLogCsl(msg);
501}
502
503
504phCallbacks_t phapi::callbacks = {
505                phapi::callProgress,
506                phapi::transferProgress,
507                phapi::confProgress,
508                phapi::regProgress,
509                phapi::msgProgress,
510                phapi::connectionLost,
511                phapi::notifyProgress,
512                phapi::subscriptionProgress,
513                phapi::frameReady,
514                0,
515#ifdef HAVE_CSL
516                phapi::phLogCsl
517#endif /*!HAVE_CSL*/
518};
519
520
521}
522/*
523
524
525#ifdef TEST
526
527using namespace verona;
528
529stdphapi* myphapi = new stdphapi;
530
531
532void testAuth(const std::string& name, const std::string& id, const std::string& pw, const std::string& realm)
533{
534  myphapi->addAuthInfo(name, id, pw, realm);
535}
536
537
538int main(int argc, char *argv[])
539{
540
541}
542
543#endif
544 */
Note: See TracBrowser for help on using the repository browser.