source: verona/phcpp/phapipp.cpp @ 324:0c57fb464168

Last change on this file since 324:0c57fb464168 was 324:0c57fb464168, checked in by laurent <laurent@…>, 20 months ago

bug fix : changeVideoCodecList

File size: 14.0 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::holdCall(int cid)
128{
129        return phHoldCall(cid);
130}
131
132int phapi::resumeCall(int cid)
133{
134        return phResumeCall(cid);
135}
136
137int phapi::blindTransferCall(int cid, const char *uri)
138{
139        return phBlindTransferCall(cid, uri);
140}
141
142int phapi::sendDtmf(int cid, int dtmfChar, int mode)
143{
144        return phSendDtmf(cid, dtmfChar, mode);
145}
146
147int phapi::messageInCall(int cid, const char *mime,  const char *buff)
148{
149        return phCallSendMessage(cid, (char*) mime, (char*) buff);
150}
151
152
153int phapi::getSipCallID(int cid, char *idbuf,  int bufsize)
154{
155        return phCallGetSipCallID(cid, idbuf, bufsize);
156}
157
158int phapi::setFollowMe(int vlid, const char *uri)
159{
160        return phLineSetFollowMe(vlid, uri);
161}
162
163int phapi::setBusy(int vlid, bool busy)
164{
165        return phLineSetBusy(vlid, busy);
166}
167
168int phapi::sendMessage(int vlid, const char* to,  const char* buff, const char* mime,
169                const char* target, const char* sipcid)
170{
171        return phLineSendMessage2(vlid, target, to, buff, mime, sipcid);
172}
173
174
175
176int phapi::subscribe(int vlid, const char* to, int winfo, char* data, int use_proxy, int expire)
177{
178        return phLineSubscribe2(vlid, to, winfo, data, use_proxy, expire);
179}
180
181
182int phapi::unsubscribe(int sid, int winfo)
183{
184        return phLineUnsubscribe(sid, winfo);
185}
186
187
188int phapi::publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content,
189                int expires)
190{
191        if (expires == -1)
192                expires = 600;
193
194        return phLinePublish2(vlid, to, evt, ctt, content, expires);
195}
196
197
198
199int phapi::poll()
200{
201        return phPoll();
202}
203
204void phapi::refresh()
205{
206        phRefresh();
207}
208
209
210void phapi::setLogFile(const char* logFile)
211{
212        phSetLogFileName(logFile);
213}
214
215
216int phapi::mobility(int vlid)
217{
218        return phLineGetMobility(vlid);
219
220}
221
222int phapi::setUsername2(int vlid, const char* username)
223{
224        return phLineSetUsername2(vlid, username);
225}
226
227
228
229int phapi::getLineSipAddress(int vlid, char *buf, int size)
230{
231        return phLineGetSipAddress(vlid, buf, size);
232}
233
234void phapi::setUaString(const char *uastr)
235{
236        phSetUaString(uastr);
237}
238
239void phapi::changeAudioCodecList(const char *audio_codecs)
240{
241        ph_config_s *phcfg = ph_get_config();
242        const size_t S = sizeof(phcfg->audio_codecs);
243
244        strncpy(phcfg->audio_codecs, audio_codecs, S);
245        phcfg->audio_codecs[S-1] = 0;
246}
247
248void phapi::changeVideoCodecList(const char *video_codecs)
249{
250        ph_config_s *phcfg = ph_get_config();
251        const size_t S = sizeof(phcfg->video_codecs);
252       
253        strncpy(phcfg->video_codecs, video_codecs, S);
254        phcfg->video_codecs[S-1] = 0;
255}
256       
257#if defined(_WIN32_WCE)
258char * phapi::getLocalIpFromDescription(const char *description)
259{
260        DWORD pcbBufferSize = 0;
261        ConnMgrQueryDetailedStatus(0,&pcbBufferSize);
262        CONNMGR_CONNECTION_DETAILED_STATUS *  pStatusBuffer = (CONNMGR_CONNECTION_DETAILED_STATUS *)calloc(pcbBufferSize, 1);
263
264        if(!ConnMgrQueryDetailedStatus(pStatusBuffer,&pcbBufferSize))
265        {
266                for (CONNMGR_CONNECTION_DETAILED_STATUS * curItem = pStatusBuffer; curItem != 0; curItem = curItem->pNext)
267                {
268                        WCHAR NameBuffer[512];
269                        mbstowcs(NameBuffer,description,512);
270
271                        if (curItem->pIPAddr != NULL && (curItem->szAdapterName && !wcscmp(NameBuffer,curItem->szAdapterName) || curItem->szDescription && !wcscmp(NameBuffer,curItem->szDescription)))
272                        {
273                                WCHAR addressAsString[128];
274                                DWORD addressSize = sizeof(addressAsString);
275
276                                WSAAddressToString((LPSOCKADDR)curItem->pIPAddr->IPAddr,128,0,addressAsString,&addressSize);
277
278                                char *local_ip = new char[128];
279                                WideCharToMultiByte(CP_ACP, 0, addressAsString, -1,local_ip, 128, NULL, NULL);
280                                return local_ip;
281                        }
282                }
283        }
284        return "";
285}
286#endif
287
288void phapi::changeLocalIP(const char *local_ip)
289{
290        ph_config_s *phcfg = ph_get_config();
291        const size_t S = sizeof(phcfg->local_ip_addr);
292        strncpy(phcfg->local_ip_addr, local_ip, S);
293        phcfg->local_ip_addr[S-1] = 0;
294}
295
296std::map<char*, char*> phapi::getAudioCaptureDevices()
297{
298        ph_audio_card_desc_t* device_tab = NULL;
299        int pos = 0;
300        int i = 0;
301        std::map<char*, char*> device_map;
302
303        pos = phAudioCaptureCardList(&device_tab);
304
305        for (i = 0; i < pos; i++)
306        {
307                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].name));
308                printf("MSSndCard id:%s name:%s !!!!\n", device_tab[i].id, device_tab[i].name);
309        }
310       
311        if(device_tab)
312                delete device_tab;
313       
314        return device_map;
315}
316
317std::map<char*, char*> phapi::getVideoWebcamDevices()
318{
319        ph_video_web_cam_desc_t* device_tab = NULL;
320        int pos =0;
321        int i = 0;
322        std::map<char *, char*> device_map;
323               
324        pos = phVideoWebcamList(&device_tab);
325               
326        for (i = 0; i < pos; i++)
327        {
328                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].name));
329                printf("webcam id:%s name:%s !!!!\n", device_tab[i].id, device_tab[i].name);
330        }
331       
332        if(device_tab)
333                delete device_tab;
334       
335        return device_map;
336}
337       
338std::map<char*, char*> phapi::getAudioPlaybackDevices()
339{
340        ph_audio_card_desc_t* device_tab = NULL;
341        int pos = 0;
342        int i = 0;
343        std::map<char*, char*> device_map;
344
345        pos = phAudioPlaybackCardList(&device_tab);
346
347        for (i = 0; i < pos; i++)
348        {
349                device_map.insert(std::pair<char*, char*>(device_tab[i].id, device_tab[i].name));
350        }
351       
352        if(device_tab)
353                delete device_tab;
354       
355        return device_map;
356}
357
358void phapi::changeAudioDeviceIn(const char *devstr)
359{
360        phChangeAudioDeviceIn(devstr);
361}
362
363void phapi::changeAudioDeviceOut(const char *devstr)
364{
365        phChangeAudioDeviceOut(devstr);
366}
367       
368void phapi::changeVideoDevices(const char *devstr)
369{
370        phChangeVideoDevices(devstr);
371}
372       
373int phapi::setSoftRecvVolumeGain(int cid, float gain)
374{
375        return phAudioSoftRecvVolumeGain(cid, gain);
376}
377
378int phapi::setSoftSendVolumeGain(int cid, float gain)
379{
380        return phAudioSoftSendVolumeGain(cid, gain);
381}
382
383int phapi::setRecvVolumeLevel(int cid, int level)
384{
385        return phAudioRecvVolumeLevel(cid, level);
386}
387
388int phapi::setSendVolumeLevel(int cid, int level)
389{
390        return phAudioSendVolumeLevel(cid, level);
391}
392
393int phapi::mutePlayback(int cid, int val)
394{
395        return phAudioMutePlayback(cid, val);
396}
397
398int phapi::muteCapture(int cid, int val)
399{
400        return phAudioMuteCapture(cid, val);
401}
402
403int phapi::setSoundFileGain(phStream* phstream,float gain)
404{
405        return phSetSoundFileGain(phstream,gain);
406}
407       
408phStream * phapi::playSoundFile(const char * filename, int interval, const char* deviceid)
409{
410        return phPlaySoundFile(filename,interval,deviceid);
411}
412       
413int phapi::stopSoundFile(phStream * phstream)
414{
415        return phStopSoundFile(phstream);
416}
417
418phStream * phapi::videoStartPreview(const char* deviceid)
419{
420        phStream * stream = phVideoStartPreview(deviceid);
421        return stream;
422}
423       
424int phapi::videoStopPreview(phStream * phstream)
425{
426        return phVideoStopPreview(phstream);
427}
428
429int phapi::videoSetDefaultImage(const char* path)
430{
431        return phVideoSetDefaultImage(path);
432}
433
434void phapi::onCallProgress(int cid, const phCallStateInfo_t *info)
435{
436        if(info->event == phDTMF)
437                onDtmfProgress(cid,info->dtmfDigit);
438        else if(info->event == phCALLCLOSED || info->event == phCALLERROR) {
439#if defined(_WIN32_WCE)
440                onCallProgress2(cid,info->event,(wchar_t*)"",info->errorCode);
441#else
442                onCallProgress2(cid,info->event,(char*)"",info->errorCode);
443#endif
444        }else {
445#if defined(_WIN32_WCE)
446                int utfsize = MultiByteToWideChar(CP_ACP, 0, info->remoteUri, -1, NULL, 0);
447                wchar_t *tmp = (wchar_t *)alloca((utfsize + 1) * sizeof(*tmp));
448                       
449                MultiByteToWideChar(CP_ACP, 0, info->remoteUri, -1,tmp, utfsize);
450                onCallProgress2(cid,info->event, tmp,info->errorCode);
451#else
452                onCallProgress2(cid,info->event,(char*)info->remoteUri,info->errorCode);
453#endif
454        }
455}
456
457#if defined(_WIN32_WCE)
458void phapi::onCallProgress2(int cid, phCallStateEvent status, wchar_t * uri, int error)
459#else
460void phapi::onCallProgress2(int cid, phCallStateEvent status, char * uri, int error)
461#endif
462{
463
464}
465
466void phapi::onDtmfProgress(int cid, int)
467{
468
469}
470
471void phapi::onTransferProgress(int cid, const phTransferStateInfo_t *info)  { }
472void phapi::onConfProgress(int cfid, const phConfStateInfo_t *info)  { }
473void phapi::onRegProgress(int regid, int status)  { }
474void phapi::onMsgProgress(int mid,  const phMsgStateInfo_t *info) 
475{
476        onMsgProgress2(mid,     (char *)info->rawctt, (char *)info->content);
477}
478void phapi::onMsgProgress2(int mid, char * type, char * content) { }
479void phapi::onConnectionLost(const char* host, int port) { }
480#if defined(_WIN32_WCE)
481void phapi::onNotifyProgress (const char* event, const char* from, const char *ctt, wchar_t* content)  { }
482#else
483void phapi::onNotifyProgress (const char* event, const char* from, const char *ctt, const char* content)  { }
484#endif
485void phapi::onSubscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info)  { }
486void phapi::onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev) { }
487void phapi::onPhLogCsl(const char *msg){ }
488
489void phapi::onSoundFileStopped(void *userdata , unsigned int _id, void *arg){}
490       
491void phapi::callProgress(int cid, const phCallStateInfo_t *info)
492{
493        if (uniqueobj)
494                uniqueobj->onCallProgress(cid, info);
495}
496
497void phapi::transferProgress(int cid, const phTransferStateInfo_t *info)
498{
499        if (uniqueobj)
500                uniqueobj->onTransferProgress(cid, info);
501
502}
503
504
505void phapi::confProgress(int cfid, const phConfStateInfo_t *info)
506{
507        if (uniqueobj)
508                uniqueobj->onConfProgress(cfid, info);
509
510}
511
512void phapi::regProgress(int regid, int status)
513{
514        if (uniqueobj)
515                uniqueobj->onRegProgress(regid, status);
516
517}
518
519void phapi::msgProgress(int mid,  const phMsgStateInfo_t *info)
520{
521        if (uniqueobj)
522                uniqueobj->onMsgProgress(mid, info);
523
524}
525
526void phapi::connectionLost(const char *host, int port)
527{
528        if (uniqueobj)
529                uniqueobj->onConnectionLost(host, port);
530}
531
532void phapi::notifyProgress (const char* event, const char* from, const char *ctt, const char* content)
533{
534#if defined(_WIN32_WCE)
535        int utfsize = MultiByteToWideChar(CP_ACP, 0, content, -1, NULL, 0);
536        wchar_t *tmp = (wchar_t *)alloca((utfsize + 1) * sizeof(*tmp));
537                       
538        MultiByteToWideChar(CP_ACP, 0, content, -1,tmp, utfsize);
539
540        if (uniqueobj)
541                uniqueobj->onNotifyProgress(event, from, ctt, tmp);
542#else
543        if (uniqueobj)
544                uniqueobj->onNotifyProgress(event, from, ctt, content);
545#endif
546
547}
548
549void phapi::subscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info)
550{
551        if (uniqueobj)
552                uniqueobj->onSubscriptionProgress(sid, info);
553
554}
555
556
557void phapi::frameReady(int cid, phVideoFrameReceivedEvent_t *ev)
558{
559        if (uniqueobj)
560                uniqueobj->onFrameReady(cid, ev);
561
562}
563
564void phapi::phLogCsl(const char *msg)
565{
566        if (uniqueobj)
567                uniqueobj->onPhLogCsl(msg);
568}
569
570void phapi::soundFileStopped(void *userdata , unsigned int _id, void *arg)
571{
572        if (uniqueobj)
573                uniqueobj->onSoundFileStopped(userdata,_id,arg);
574}
575       
576phCallbacks_t phapi::callbacks = {
577                phapi::callProgress,
578                phapi::transferProgress,
579                phapi::confProgress,
580                phapi::regProgress,
581                phapi::msgProgress,
582                phapi::connectionLost,
583                phapi::notifyProgress,
584                phapi::subscriptionProgress,
585                phapi::frameReady,
586                0,
587#ifdef HAVE_CSL
588                phapi::phLogCsl,
589#endif /*!HAVE_CSL*/
590                phapi::soundFileStopped
591};
592
593
594}
595/*
596
597
598#ifdef TEST
599
600using namespace verona;
601
602stdphapi* myphapi = new stdphapi;
603
604
605void testAuth(const std::string& name, const std::string& id, const std::string& pw, const std::string& realm)
606{
607  myphapi->addAuthInfo(name, id, pw, realm);
608}
609
610
611int main(int argc, char *argv[])
612{
613
614}
615
616#endif
617 */
Note: See TracBrowser for help on using the repository browser.