source: verona/phapi/phcall.c @ 0:bad39850d2c4

Last change on this file since 0:bad39850d2c4 was 0:bad39850d2c4, checked in by vadim@…, 3 years ago

initial commit

File size: 2.6 KB
Line 
1#include "phapi.h"
2#include "phcall.h"
3#include <eXosip/eXosip.h>
4
5phcall_t *
6ph_locate_call_by_cid(phConfig_t *cfg, int cid)
7{
8  phcall_t *ca;
9
10  for(ca = cfg->ph_calls; ca < &cfg->ph_calls[PH_MAX_CALLS];  ca++)
11    {
12      if (ca->cid == cid)
13        return ca;
14    }
15
16  return 0;
17}
18
19void phReleaseTerminatedCalls(phConfig_t *cfg)
20{
21        phcall_t *ca;
22        for(ca = cfg->ph_calls; ca < &cfg->ph_calls[PH_MAX_CALLS];  ca++)
23    {
24                if ((ca->cid != -1) && (ph_media_is_stream_stopped(ca) == 1)) {
25                        ph_release_call(cfg, ca);
26                }
27    }
28}
29
30phcall_t *
31ph_locate_call_by_rcid(phConfig_t *cfg, int cid)
32{
33  phcall_t *ca;
34
35  for(ca = cfg->ph_calls; ca < &cfg->ph_calls[PH_MAX_CALLS];  ca++)
36    {
37      if (ca->rcid == cid)
38        return ca;
39    }
40
41  return 0;
42}
43
44phcall_t *
45ph_locate_call_by_rdid(phConfig_t *cfg, int did)
46{
47  phcall_t *ca;
48
49
50  for(ca = cfg->ph_calls; ca < &cfg->ph_calls[PH_MAX_CALLS];  ca++)
51    {
52      if (ca->rdid == did)
53        return ca;
54    }
55
56  return 0;
57}
58
59
60phcall_t *
61ph_allocate_call(phConfig_t *cfg, int cid)
62{
63  phcall_t *ca = ph_locate_call_by_cid(cfg, -1);
64
65  if (!ca)
66    return 0;
67
68  ca->cid = cid;
69  ca->cfg = cfg;
70  return ca;
71}
72
73
74phcall_t *
75ph_locate_call(phConfig_t *cfg, eXosip_event_t *je, int creatit)
76{
77  phcall_t *ca, *found = 0, *newca = 0;
78
79
80  /* lookup matching call descriptor */
81  for(ca = cfg->ph_calls; ca < &cfg->ph_calls[PH_MAX_CALLS];  ca++)
82    {
83      if (ca->cid == -1 && !newca)
84        newca = ca;
85
86      if (ca->cid == je->cid)
87        {
88          found  = ca;
89          break;
90        }
91    }
92
93
94  ca = found;
95
96  if (!ca)   /* we didn't find a matching call descriptor */
97    {
98    if (creatit)   
99      {
100        /* allocate a new one */
101        if (!newca) 
102          return 0; /* !!! BUG !!! */
103        ca = newca;
104        memset(ca, 0, sizeof(*ca));
105        ca->cid = -1;
106      }
107    }
108
109 
110 
111  if (!ca)
112    return 0;
113
114
115  /* update the call information */
116
117  if (!ca->localrefer)
118    {
119      ca->cid = je->cid;
120      ca->did = je->did;
121    }
122
123  if (je->remote_sdp_audio_ip[0])
124    {
125      strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, sizeof(ca->remote_sdp_audio_ip));
126      ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
127      strncpy(ca->audio_payload_name, je->payload_name, sizeof(ca->audio_payload_name));
128      ca->audio_payload = je->payload;
129    }
130
131  if (je->remote_sdp_video_ip[0])
132    {
133      strncpy(ca->remote_sdp_video_ip, je->remote_sdp_video_ip, sizeof(ca->remote_sdp_video_ip));
134      ca->remote_sdp_video_port = je->remote_sdp_video_port;
135      strncpy(ca->video_payload_name, je->payload_name, sizeof(ca->video_payload_name));
136      ca->video_payload = je->payload;
137    }
138
139
140  return ca;
141}
142
143
144void ph_release_call(phcall_t *ca)
145{
146  if (ca->hasaudio)
147    {
148      ph_media_stop(ca);
149      ca->cid = -1;
150    }
151}
Note: See TracBrowser for help on using the repository browser.