-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconference720p.cpp
More file actions
1434 lines (1368 loc) · 58.6 KB
/
Copy pathconference720p.cpp
File metadata and controls
1434 lines (1368 loc) · 58.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2014 Dialogic Corp.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
* Alternatively see <http://www.gnu.org/licenses/>.
* Or see the LICENSE file included within the source tree.
*
*/
/*------------------------------ Dependencies --------------------------------*/
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include "logger.h"
#include "conference720p.h"
#include "calls.h"
#include "confvideoplays.h"
#include "xmscmds.h"
/*----------------------------------------------------------------------------*/
Conference720p::Conference720p (std::string dtmf_mode)
{
nullExclusiveMediaOp ();
num_callers_ = 0;
strcpy (dtmf_mode_, dtmf_mode.c_str ());
resetConference ();
}
Conference720p::~Conference720p ()
{
if (conf_id_.empty ())
{
LOGDEBUG ("Destroying conference " << conf_id_);
destroy_conference (conf_id_);
}
}
void
Conference720p::resetConference ()
{
// initialize
is_very_first_call_ = true;
nullExclusiveMediaOp ();
conf_id_ = '\0';
layout_ = '4';
init_region_use ();
recordInProgress_ = false;
//overlay_id_ = '\0';
captionsOn_ = false;
scrolling_overlay_ = false;
slide_show_ = false;
}
int
Conference720p::file_exists (const char *filename)
{
struct stat buffer;
LOGDEBUG ("For file: " << filename << " stat returns " << stat (filename, &buffer));
return (stat (filename, &buffer) == 0);
}
void
Conference720p::notify_all_callers (const char *message)
{
// Notify all callers with message
std::vector < Call >::iterator call_iterator;
for (call_iterator = Calls::Instance ()->verification_calls_.begin ();
call_iterator != Calls::Instance ()->verification_calls_.end (); call_iterator++)
{
send_info (call_iterator->getCallId (), "text/plain", message);
}
}
const char *
Conference720p::get_next_layout ()
{
switch (layout_)
{
// Layouts rotate between 4 -> 6 -> 9 -> 4
/****** JH
case '1':
layout_ = '2';
break;
case '2':
layout_ = '4';
//return custom4PartyLayout();
return "4";
break;
*************/
case '4':
layout_ = '6';
return "6";
break;
case '6':
layout_ = '9';
return "9";
break;
case '9':
layout_ = '4';
return "4";
break;
}
return &layout_;
}
void
Conference720p::turnOnCaption (int region)
{
LOGDEBUG ("Turning conferee caption on for region " << region);
std::string showCallerId = showCallerIdOverlay (region, "XXXX for now");
update_conference (conf_id_, NULL, NULL, showCallerId.c_str ());
}
void
Conference720p::turnOffCaption (int region)
{
LOGDEBUG ("Turning conferee caption off for region " << region);
std::string delCallerId = deleteCallerIdOverlay (region);
update_conference (conf_id_, NULL, NULL, delCallerId.c_str ());
}
void
Conference720p::turnOnAllCaptions ()
{
LOGDEBUG ("Turning conferee captions on");
std::vector < Call >::iterator call_iterator;
// Need to make list public - can't get it with accessor?
int confereeNum = 1;
// Loop over all calls first
for (call_iterator = Calls::Instance ()->verification_calls_.begin ();
call_iterator != Calls::Instance ()->verification_calls_.end (); call_iterator++)
{
LOGDEBUG ("Turning conferee caption on for region " << call_iterator->getConfRegion ());
char caption[32];
sprintf (caption, "Conferee #%d", confereeNum);
std::string showCallerId = showCallerIdOverlay (call_iterator->getConfRegion (), caption);
update_conference (conf_id_, NULL, NULL, showCallerId.c_str ());
confereeNum++;
}
// Now loop over any videos playing
std::vector < ConfVideoPlay >::iterator conf_play_iterator;
for (conf_play_iterator = ConfVideoPlays::Instance ()->conf_video_plays_.begin ();
conf_play_iterator != ConfVideoPlays::Instance ()->conf_video_plays_.end (); conf_play_iterator++)
{
std::string showVidLabel = showVideoLabelOverlay (conf_play_iterator->getConfVideoPlayRegion ());
update_conference (conf_id_, NULL, NULL, showVidLabel.c_str ());
}
}
void
Conference720p::turnOffAllCaptions ()
{
LOGDEBUG ("Turning conferee captions off");
std::vector < Call >::iterator call_iterator;
int confereeNum = 1;
std::string delCallerId;
// Loop over calls first
for (call_iterator = Calls::Instance ()->verification_calls_.begin ();
call_iterator != Calls::Instance ()->verification_calls_.end (); call_iterator++)
{
delCallerId = deleteCallerIdOverlay (call_iterator->getConfRegion ());
update_conference (conf_id_, NULL, NULL, delCallerId.c_str ());
confereeNum++;
}
// And video labels next
turnOffVideoLabels ();
}
void
Conference720p::turnOffVideoLabels ()
{
//char xmlString[128];
std::vector < ConfVideoPlay >::iterator conf_play_iterator;
// Loop over any videos playing
for (conf_play_iterator = ConfVideoPlays::Instance ()->conf_video_plays_.begin ();
conf_play_iterator != ConfVideoPlays::Instance ()->conf_video_plays_.end (); conf_play_iterator++)
{
std::string deleteVidLabel = deleteVideoLabelOverlay (conf_play_iterator->getConfVideoPlayRegion ());
update_conference (conf_id_, NULL, NULL, deleteVidLabel.c_str ());
}
}
void
Conference720p::moveRegionOverlays (const int fromRegion, const int toRegion)
{
// Delete overlay in fromRegion and activate in toRegion
if (Calls::Instance ()->isAudioMuteOnForCallId (Calls::Instance ()->getCallIdByConfRegion (fromRegion)))
{
// Move the mute overlay to the new region
LOGDEBUG ("Moving mic mute overlay from region " << fromRegion << " to region " << toRegion);
std::string deleteMicMute = deleteMicMuteOverlay (fromRegion);
update_conference (conf_id_, NULL, NULL, deleteMicMute.c_str ());
std::string showMicMute = showMicMuteOverlay (toRegion);
update_conference (conf_id_, NULL, NULL, showMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (fromRegion)))
{
// Move the video hiding overlay to the new region
LOGDEBUG ("Moving video hiding overlay from region " << fromRegion << " to region " << toRegion);
std::string delBaghead = deleteBagheadOverlay (fromRegion);
update_conference (conf_id_, NULL, NULL, delBaghead.c_str ());
std::string showBaghead = showBagheadOverlay (toRegion);
update_conference (conf_id_, NULL, NULL, showBaghead.c_str ());
}
}
void
Conference720p::copyRegionOverlays (const int fromRegion, const int toRegion)
{
// Same as moveRegionOverlays, but do not remove fromRegion overlay
if (Calls::Instance ()->isAudioMuteOnForCallId (Calls::Instance ()->getCallIdByConfRegion (fromRegion)))
{
// Move the mute overlay to the new region
LOGDEBUG ("Copying mic mute overlay from region " << fromRegion << " to region " << toRegion);
std::string showMicMute = showMicMuteOverlay (toRegion);
update_conference (conf_id_, NULL, NULL, showMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (fromRegion)))
{
// Move the video hiding overlay to the new region
LOGDEBUG ("Copying video hiding overlay from region " << fromRegion << " to region " << toRegion);
std::string showBaghead = showBagheadOverlay (toRegion);
update_conference (conf_id_, NULL, NULL, showBaghead.c_str ());
}
}
int
Conference720p::get_next_region (const int region)
{
// Next region to rotate into depends on current layout
switch (layout_)
{
case '1':
return 0;
break;
case '2':
if (region == 2)
return 1;
else
return region + 1;
break;
case '4':
if (region == 4)
return 1;
else
return region + 1;
break;
case '6':
if (region == 6)
return 1;
else
return region + 1;
break;
case '9':
if (region == 9)
return 1;
else
return region + 1;
break;
}
return 0;
}
bool
Conference720p::is_region_max_for_layout (const int region)
{
switch (layout_)
{
case '1':
if (region == 1)
return true;
break;
case '2':
if (region == 2)
return true;
break;
case '4':
if (region == 4)
return true;
break;
case '6':
if (region == 6)
return true;
break;
case '9':
if (region == 9)
return true;
break;
}
return false;
}
int
Conference720p::find_clicked_region (const char *resolution, int layout, int posX, int posY)
{
int maxX;
int maxY;
if (strcmp (resolution, "cif") == 0)
{
maxX = 352;
maxY = 240;
}
else if (strcmp (resolution, "vga") == 0)
{
maxX = 640;
maxY = 480;
}
else if (strcmp (resolution, "720p") == 0)
{
maxX = 1280;
maxY = 720;
}
else
{
LOGERROR ("Unsupported resolution - " << resolution);
return NULL;
}
// 1,2,4,6,9 determine the region number returned
if (layout == 1)
{
if ((posX >= 0 && posX <= maxX) && (posY >= 0 && posY <= maxY))
{
return 1;
}
else
{
return NULL;
}
}
else if (layout == 2)
{
// Get a positive result when clicking on black bars above and below
// conferee, but maybe that's not bad. This is the only layout
// with unused real estate
if ((posX >= 0 && posX <= maxX * .50) && (posY >= 0 && posY <= maxY))
{
return 1;
}
else if ((posX >= .50 * maxX && posX <= maxX) && (posY >= 0 && posY <= maxY))
{
return 2;
}
else
{
return NULL;
}
}
else if (layout == 4)
{
if ((posX >= 0 && posX <= maxX * .50) && (posY >= 0 && posY <= maxY * .50))
{
return 1;
}
else if ((posX >= 0 && posX <= maxX * .50) && (posY >= maxY * .50 && posY <= maxY))
{
return 2;
}
else if ((posX >= .50 * maxX && posX <= maxX) && (posY >= 0 && posY <= maxY * .50))
{
return 3;
}
else if ((posX >= .50 * maxX && posX <= maxX) && (posY >= maxY * .50 && posY <= maxY))
{
return 4;
}
else
{
return NULL;
}
}
else if (layout == 6)
{
if ((posX >= 0 && posX <= maxX * .66) && (posY >= 0 && posY <= maxY * .66))
{
return 1;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= 0 && posY <= maxY * .33))
{
return 2;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= maxY * .33 && posY <= maxY * .66))
{
return 3;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= maxY * .66 && posY <= maxY))
{
return 4;
}
else if ((posX >= .33 * maxX && posX <= .66 * maxX) && (posY >= maxY * .66 && posY <= maxY))
{
return 5;
}
else if ((posX >= 0 && posX <= .33 * maxX) && (posY >= maxY * .66 && posY <= maxY))
{
return 6;
}
else
{
return NULL;
}
}
else if (layout == 9)
{
if ((posX >= 0 && posX <= maxX * .33) && (posY >= 0 && posY <= maxY * .33))
{
return 1;
}
else if ((posX >= 0 && posX <= maxX * .33) && (posY >= .33 * maxY && posY <= maxY * .66))
{
return 2;
}
else if ((posX >= 0 && posX <= maxX * .33) && (posY >= .66 * maxY && posY <= maxY))
{
return 3;
}
else if ((posX >= .33 * maxX && posX <= .66 * maxX) && (posY >= 0 && posY <= .33 * maxY))
{
return 4;
}
else if ((posX >= .33 * maxX && posX <= .66 * maxX) && (posY >= maxY * .33 && posY <= .66 * maxY))
{
return 5;
}
else if ((posX >= .33 * maxX && posX <= .66 * maxX) && (posY >= maxY * .66 && posY <= maxY))
{
return 6;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= 0 && posY <= .33 * maxY))
{
return 7;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= maxY * .33 && posY <= .66 * maxY))
{
return 8;
}
else if ((posX >= .66 * maxX && posX <= maxX) && (posY >= maxY * .66 && posY <= maxY))
{
return 9;
}
else
{
return NULL;
}
}
return 0;
}
void
Conference720p::resetDemo ()
{
// The Grand Reset
// Stop plays, destroy conference, throw everybody out
// Next call after this will start a new conference
LOGDEBUG ("720p Conference reset");
//Loop over all videos, stopping them
ConfVideoPlays::Instance ()->stopAllConfVideoPlays ();
// Destroy the conference. This will automatically remove conference parties first
destroy_conference (conf_id_);
conf_id_ = "";
// Loop over all open calls and hang them up.
std::vector < Call >::iterator call_iterator;
for (call_iterator = Calls::Instance ()->verification_calls_.begin ();
call_iterator != Calls::Instance ()->verification_calls_.end (); call_iterator++)
{
LOGDEBUG ("Hanging up call " << call_iterator->getCallId ());
hangup (call_iterator->getCallId ());
decNumCallers ();
int region = call_iterator->getConfRegion ();
LOGDEBUG ("Relinquishing conference region " << region);
clear_region (region);
}
// Nobody left; clear the list of all calls
Calls::Instance ()->clearAllCalls ();
// Resets for a new conference on next call
// Note that destroying a conference will internally kill
// all overlays associated with the conference. Saves
// the app the trouble.
resetConference ();
}
void
Conference720p::rotate_to_next_region ()
{
// Loop over all possible regions
set_all_regions_not_processed ();
const char *displacedPlayFromRegionOne = NULL;
const char *displacedCallFromRegionOne = NULL;
bool wrappedFromMaxToOne = false;
for (int curRegion = 9; curRegion >= 1; curRegion--)
{
LOGDEBUG ("Looking at region " << curRegion << " Used: " << is_region_used (curRegion) <<
" Not Processed: " << is_region_not_processed (curRegion) <<
" Wrapped from max to one: " << wrappedFromMaxToOne);
//if (is_region_used (curRegion) && is_region_not_processed (curRegion))
if (is_region_used (curRegion))
{
if (is_region_not_processed (curRegion))
{
const char *callId = Calls::Instance ()->getCallIdByConfRegion (curRegion);
LOGDEBUG ("Examine region " << curRegion << " for Call Id. Have: " << callId);
if (callId != NULL)
{
LOGDEBUG ("Call in region " << curRegion);
int nextRegion;
char nextRegionString[10];
// If this is region one and we wrapped something in here from the
// max region for the layout, take what we saved and put it in region 2
// instead of what was wrapped into here
if (curRegion == 1 && wrappedFromMaxToOne)
{
LOGDEBUG ("Displaced region one call = " << displacedCallFromRegionOne);
if (displacedCallFromRegionOne)
{
LOGDEBUG ("Restoring displaced call from region one into region two");
if (Calls::Instance ()->isAudioMuteOnForCallId (callId))
{
update_party (displacedCallFromRegionOne, "recvonly", "sendrecv", "2");
}
else
{
update_party (displacedCallFromRegionOne, "sendrecv", "sendrecv", "2");
}
set_region (2);
Calls::Instance ()->setCallRegionByCallId (displacedCallFromRegionOne, 2);
if (Calls::Instance ()->getCallIdByConfRegion (2) != NULL)
{
// Adjust overlays for region2
LOGDEBUG ("AUDIOON region 2 = " << Calls::
Instance ()->isAudioMuteOnForCallId ((Calls::Instance ()->getCallIdByConfRegion (2))));
LOGDEBUG ("VIDEOHIDDEN region 2 = " << Calls::
Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (2)));
if (Calls::Instance ()->isAudioMuteOnForCallId (Calls::Instance ()->getCallIdByConfRegion (2)))
{
std::string showMicMute = showMicMuteOverlay (2);
update_conference (conf_id_, NULL, NULL, showMicMute.c_str ());
}
else
{
std::string deleteMicMute = deleteMicMuteOverlay (2);
update_conference (conf_id_, NULL, NULL, deleteMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (2)))
{
std::string showBaghead = showBagheadOverlay (2);
update_conference (conf_id_, NULL, NULL, showBaghead.c_str ());
}
else
{
std::string delBaghead = deleteBagheadOverlay (2);
update_conference (conf_id_, NULL, NULL, delBaghead.c_str ());
}
}
if (Calls::Instance ()->getCallIdByConfRegion (1) != NULL)
{
// Adjust overlays for region 1
LOGDEBUG ("AUDIOON region 1 = " << Calls::
Instance ()->isAudioMuteOnForCallId ((Calls::Instance ()->getCallIdByConfRegion (1))));
LOGDEBUG ("VIDEOHIDDEN region 1 = " << Calls::
Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (1)));
if (Calls::Instance ()->isAudioMuteOnForCallId (Calls::Instance ()->getCallIdByConfRegion (1)))
{
std::string showMicMute = showMicMuteOverlay (1);
update_conference (conf_id_, NULL, NULL, showMicMute.c_str ());
}
else
{
std::string deleteMicMute = deleteMicMuteOverlay (1);
update_conference (conf_id_, NULL, NULL, deleteMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (1)))
{
std::string showBaghead = showBagheadOverlay (1);
update_conference (conf_id_, NULL, NULL, showBaghead.c_str ());
}
else
{
std::string delBaghead = deleteBagheadOverlay (1);
update_conference (conf_id_, NULL, NULL, delBaghead.c_str ());
}
}
}
LOGDEBUG ("Displaced region one play = " << displacedPlayFromRegionOne);
if (displacedPlayFromRegionOne)
{
LOGDEBUG ("Restoring displaced play from region one into region two");
update_play (displacedPlayFromRegionOne, NULL, "2");
set_region (2);
ConfVideoPlays::Instance ()->setConfVideoPlayRegionByPlayId (displacedPlayFromRegionOne, 2);
}
// Done with region one; exit loop
break;
}
// Special case if wrapping around from last to first region
if (is_region_max_for_layout (curRegion))
{
wrappedFromMaxToOne = true;
// If region one is occupied, save its contents
LOGDEBUG ("Saving whatever is in region one (if anyithing) as displaced");
displacedCallFromRegionOne = Calls::Instance ()->getCallIdByConfRegion (1);
displacedPlayFromRegionOne = ConfVideoPlays::Instance ()->getVideoPlayIdByConfRegion (1);
}
// Normal region processing
nextRegion = get_next_region (curRegion);
LOGDEBUG ("Video call with call ID " << callId << " in region " << curRegion << " moving to region " <<
nextRegion);
moveRegionOverlays (curRegion, nextRegion);
Calls::Instance ()->setCallRegionByCallId (callId, nextRegion);
clear_region (curRegion);
set_region (nextRegion);
set_region_processed (curRegion);
sprintf (nextRegionString, "%d", nextRegion);
// Know when we wrapped
if (is_region_max_for_layout (curRegion))
wrappedFromMaxToOne = true;
update_party (callId, NULL, NULL, nextRegionString);
}
else
{
LOGDEBUG ("Look for play in region" << curRegion);
const char *playId = ConfVideoPlays::Instance ()->getVideoPlayIdByConfRegion (curRegion);
LOGDEBUG ("Examine region " << curRegion << " for Play Id. Have: " << playId);
if (playId != NULL)
{
LOGDEBUG ("Play found in region " << curRegion);
int nextRegion;
char nextRegionString[10];
// If this is region one and we wrapped something in here from the
// max region for the layout, take what we saved and put it in region 2
// instead of what was wrapped into here
if (curRegion == 1 && wrappedFromMaxToOne)
{
LOGDEBUG ("Displaced region one call = " << displacedCallFromRegionOne);
if (displacedCallFromRegionOne)
{
LOGDEBUG ("Duct Tape 2");
LOGDEBUG ("Restoring displaced call from region one into region two");
// JH duct tape for disappearing party on restore to region 2
if (Calls::Instance ()->isAudioMuteOnForCallId (callId))
update_party (displacedCallFromRegionOne, "recvonly", "sendrecv", "2");
else
update_party (displacedCallFromRegionOne, "sendrecv", "sendrecv", "2");
set_region (2);
Calls::Instance ()->setCallRegionByCallId (displacedCallFromRegionOne, 2);
if (Calls::Instance ()->isAudioMuteOnForCallId (Calls::Instance ()->getCallIdByConfRegion (2)))
{
LOGDEBUG ("Turn on mic mute overlay in region 2");
std::string showMicMute = showMicMuteOverlay (2);
update_conference (conf_id_, NULL, NULL, showMicMute.c_str ());
}
else
{
std::string deleteMicMute = deleteMicMuteOverlay (2);
update_conference (conf_id_, NULL, NULL, deleteMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (Calls::Instance ()->getCallIdByConfRegion (2)))
{
// Move the video hiding overlay to the new region
LOGDEBUG ("Turn on video hide overlay in region 2");
std::string showBaghead = showBagheadOverlay (2);
update_conference (conf_id_, NULL, NULL, showBaghead.c_str ());
}
}
LOGDEBUG ("Displaced region one play = " << displacedPlayFromRegionOne);
if (displacedPlayFromRegionOne)
{
LOGDEBUG ("Restoring displaced play from region one into region two");
update_play (displacedPlayFromRegionOne, NULL, "2");
set_region (2);
ConfVideoPlays::Instance ()->setConfVideoPlayRegionByPlayId (displacedPlayFromRegionOne, 2);
}
// Done with region one; exit loop
break;
}
// Special case if wrapping around from last to first region
if (is_region_max_for_layout (curRegion))
{
wrappedFromMaxToOne = true;
LOGDEBUG ("Saving whatever is in region one (if anyithing) as displaced");
// If region one is occupied, save its contents
displacedCallFromRegionOne = Calls::Instance ()->getCallIdByConfRegion (1);
displacedPlayFromRegionOne = ConfVideoPlays::Instance ()->getVideoPlayIdByConfRegion (1);
}
// Normal processing
nextRegion = get_next_region (curRegion);
LOGDEBUG ("Video play with play ID " << playId << " in region " << curRegion << " moving to region "
<< nextRegion);
ConfVideoPlays::Instance ()->setConfVideoPlayRegionByPlayId (playId, nextRegion);
clear_region (curRegion);
set_region (nextRegion);
set_region_processed (curRegion);
sprintf (nextRegionString, "%d", nextRegion);
// int update_play( const char * media_id, const char * action, const char * region )
update_play (playId, NULL, nextRegionString);
}
}
}
}
}
}
void
Conference720p::onEvent (xmsEventParser * eventParser)
{
std::string eventType = eventParser->getEventType ();
LOGDEBUG ("Conference720p app handling event");
if (eventType == "incoming")
{
std::string call_id = eventParser->findValByKey ("call_id");
if (isVeryFirstCall ())
{
// On first call, create a conference, reserving no resources,
// with a max of 9 parties, 4 tiles, 720p resolution
conf_id_ = create_conference ("0", "9", "4", "720p");
LOGDEBUG ("First call - created new conference " << conf_id_);
didVeryFirstCall ();
}
incNumCallers ();
if (getNumCallers () > 6)
{
LOGDEBUG ("Exceeding six callers allowed in 720p Conference demo. Not accepting call.");
hangup (call_id);
decNumCallers ();
return;
}
// All calls go into conference
LOGDEBUG ("Answering call " << call_id);
answer (call_id, getDtmfMode ());
}
else if (eventType == "answered")
{
LOGDEBUG ("Answered event received");
// Call goes into next open conference tile/region
std::string call_id = eventParser->findValByKey ("call_id");
int region = get_next_open_region ();
char region_string[10];
sprintf (region_string, "%d", region);
// Who's where bookkeeping
Calls::Instance ()->setConfRegionById (call_id.c_str (), region);
LOGDEBUG ("Adding party to conference " << conf_id_ << " in region " << region);
add_party (call_id, conf_id_, region_string);
// JH - add error handling
if (0)
{
decNumCallers ();
hangup (call_id);
}
// Turn on this guy's caption maybe?
if (areCaptionsOn ())
turnOnCaption (region);
}
else if (eventType == "accepted")
{
LOGDEBUG ("Accepted event received. No action taken");
}
else if (eventType == "hangup")
{
LOGDEBUG ("Hangup event received");
decNumCallers ();
std::string call_id = eventParser->findValByKey ("call_id");
int region = Calls::Instance ()->getConfRegionByCallId (call_id.c_str ());
if (Calls::Instance ()->isAudioMuteOnForCallId (call_id.c_str ()))
{
// Get rid of muted microphone overlay
LOGDEBUG ("Removing mic mute overlay from region " << region);
std::string deleteMicMute = deleteMicMuteOverlay (region);
update_conference (conf_id_, NULL, NULL, deleteMicMute.c_str ());
}
if (Calls::Instance ()->isVideoHiddenForCallId (call_id.c_str ()))
{
// Get rid of video hiding overlay
LOGDEBUG ("Removing video hiding overlay from region " << region);
std::string delBaghead = deleteBagheadOverlay (region);
update_conference (conf_id_, NULL, NULL, delBaghead.c_str ());
}
LOGDEBUG ("Relinquishing conference region " << region);
clear_region (region);
LOGDEBUG ("Removing " << call_id << " from active call list");
Calls::Instance ()->delCall (call_id.c_str ());
if (areCaptionsOn ())
turnOffCaption (region);
if (getNumCallers () == 0)
{
LOGDEBUG ("Last caller leaving conference");
if (scrollingOverlayOn ())
{
LOGDEBUG ("Turning scrolling overlay off");
std::string delTicker = deleteStockTickerOverlay (0);
update_conference (conf_id_, NULL, NULL, delTicker.c_str ());
}
if (slideShowOn ())
{
LOGDEBUG ("Turning slide show off");
std::string delSlide = deleteSlideOverlay (0);
update_conference (conf_id_, NULL, NULL, delSlide.c_str ());
setSlideShowOff ();
}
if (strlen (getExclusiveMediaOp ()) != 0)
{
LOGDEBUG ("Stopping exclusive media op");
stop (conf_id_, getExclusiveMediaOp ());
}
// Destroy conference and reset so a new one is started for next caller
LOGDEBUG ("Destroy conference " << conf_id_ << " and reset for a new one");
destroy_conference (conf_id_);
conf_id_ = "";
resetConference ();
}
}
else if (eventType == "dtmf")
{
LOGDEBUG ("DTMF event received");
// JH - want to go over DTMF use, make saner. Maybe use INFO messages?
std::string digit = eventParser->findValByKey ("digits");
if (digit == "1")
{
if (strlen (getExclusiveMediaOp ()) == 0)
{
LOGDEBUG ("Recording conference for 60 seconds max");
// Notify all callers of record in progress
notify_all_callers ("720p Conference now being recorded...");
// Put a recording icon on the screen
std::string showMicOn = showMicOnOverlay (0);
update_conference (conf_id_, NULL, NULL, showMicOn.c_str ());
std::string media_id = record_conference (conf_id_,
"file://restconfdemo/conf_recording.wav",
"audio/x-wav",
"L16",
"16000",
"file://restconfdemo/conf_recording.vid",
"video/x-vid", "h264", "3.1", "720", "1280", "1536000", "30", "60s");
if (!media_id.empty ())
{
setExclusiveMediaOp (media_id.c_str ());
setRecordInProgress ();
LOGDEBUG ("Saved media ID " << getExclusiveMediaOp () << " for conference record");
}
}
else
{
LOGDEBUG ("Full screen media operation in progress...");
}
}
else if (digit == "C")
{
if (isRecordInProgress ())
{
LOGDEBUG ("Stopping conference record");
stop (conf_id_, getExclusiveMediaOp ());
setRecordNotInProgress ();
}
}
else if (digit == "2")
{
if (strlen (getExclusiveMediaOp ()) == 0)
{
if (file_exists
("/var/lib/xms/media/en-US/restconfdemo/conf_recording.wav")
&& file_exists ("/var/lib/xms/media/en-US/restconfdemo/conf_recording.vid"))
{
LOGDEBUG ("Playing conference recording into next open region");
int region = get_next_open_region ();
char region_string[10];
sprintf (region_string, "%d", region);
LOGDEBUG ("Adding video to region: " << region);
LOGDEBUG ("Replaying last conference recording");
std::string media_id = play_into_conf (conf_id_,
"conf_recording.wav",
"audio/x-wav",
"file://restconfdemo",
"conf_recording.vid",
"video/x-vid", "file://restconfdemo", region_string, "0");
ConfVideoPlay recordingPlay (conf_id_, media_id.c_str (), region);
ConfVideoPlays::Instance ()->addNewPlay (recordingPlay);
ConfVideoPlays::Instance ()->printConfVideoPlayList ();
}
else
{
LOGDEBUG ("Full screen media operation in progress...");
}
}
else
{
LOGWARN ("Please record a conference before trying to replay");
}
}
else if (digit == "3")
{
if (file_exists
("/var/lib/xms/media/en-US/restconfdemo/conf_recording.wav")
&& file_exists ("/var/lib/xms/media/en-US/restconfdemo/conf_recording.vid"))
{
if (strlen (getExclusiveMediaOp ()) == 0)
{
LOGDEBUG ("Replaying last conference recording into full screen");
std::string media_id = play_into_conf (conf_id_,
"conf_recording.wav",
"audio/x-wav",
"file://restconfdemo",
"conf_recording.vid", "video/x-vid", "file://restconfdemo", "0", "0");
setExclusiveMediaOp (media_id.c_str ());
if (areCaptionsOn ())
{
std::string showVidLabel = showVideoLabelOverlay (0);
update_conference (conf_id_, NULL, NULL, showVidLabel.c_str ());
}
}
else
{
LOGDEBUG ("Full screen media operation in progress...");
}
}
else
{
LOGWARN ("Please record a conference before trying to replay");
}
}
else if (digit == "4")
{
if (file_exists
("/var/lib/xms/media/en-US/restconfdemo/Dialogic_NetworkFuel.wav")
&& file_exists ("/var/lib/xms/media/en-US/restconfdemo/Dialogic_NetworkFuel.vid"))
{
if (strlen (getExclusiveMediaOp ()) == 0)
{
LOGDEBUG ("Playing Network Fuel video into next open region");
int region = get_next_open_region ();
char region_string[10];
sprintf (region_string, "%d", region);
LOGDEBUG ("Adding video to region: " << region);
std::string media_id = play_into_conf (conf_id_,
"Dialogic_NetworkFuel.wav",
"audio/x-wav",
"file://restconfdemo",
"Dialogic_NetworkFuel.vid", "video/x-vid",
"file://restconfdemo", region_string, "infinite");
ConfVideoPlay recordingPlay (conf_id_, media_id.c_str (), region);
ConfVideoPlays::Instance ()->addNewPlay (recordingPlay);
ConfVideoPlays::Instance ()->printConfVideoPlayList ();
if (areCaptionsOn ())
{
std::string showVidLabel = showVideoLabelOverlay (region);
update_conference (conf_id_, NULL, NULL, showVidLabel.c_str ());
}
}
else
{
LOGDEBUG ("Full screen media operation in progress...");
}
}
else
{
LOGWARN ("Dialogic_NetworkFuel media not found");
}
}
else if (digit == "5")