1 /*
2 video.cc
3 Copyright (C) 2016 Belledonne Communications, Grenoble, France
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or (at
8 your option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this library; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "commands/video.h"
21
22 using namespace std;
23
Video()24 Video::Video() :
25 DaemonCommand("video",
26 "video [call_id]",
27 "Toggles camera on current call."
28 "If no call is specified, the current call is taken.")
29 {
30 addExample(new DaemonCommandExample("video 1",
31 "Status: Ok\n\n"
32 "Camera activated."));
33
34 addExample(new DaemonCommandExample("video 1",
35 "Status: Ok\n\n"
36 "Camera deactivated."));
37
38 addExample(new DaemonCommandExample("video",
39 "Status: Error\n\n"
40 "Reason: No current call available."));
41
42 addExample(new DaemonCommandExample("video 2",
43 "Status: Error\n\n"
44 "Reason: No call with such id."));
45 }
46
exec(Daemon * app,const string & args)47 void Video::exec(Daemon* app, const string& args)
48 {
49 LinphoneCore *lc = app->getCore();
50 int cid;
51 LinphoneCall *call = NULL;
52 bool activate = false;
53 istringstream ist(args);
54 ist >> cid;
55 if (ist.fail()) {
56 call = linphone_core_get_current_call(lc);
57 if (call == NULL) {
58 app->sendResponse(Response("No current call available."));
59 return;
60 }
61 } else {
62 call = app->findCall(cid);
63 if (call == NULL) {
64 app->sendResponse(Response("No call with such id."));
65 return;
66 }
67 }
68
69 if (linphone_call_get_state(call) == LinphoneCallStreamsRunning) {
70 LinphoneCallParams *new_params = linphone_core_create_call_params(lc, call);
71 activate = !linphone_call_params_video_enabled(new_params);
72
73 linphone_call_params_enable_video(new_params, activate);
74 linphone_call_update(call, new_params);
75 linphone_call_params_unref(new_params);
76
77 } else {
78 app->sendResponse(Response("No streams running: can't [de]activate video"));
79 return;
80 }
81
82 app->sendResponse(Response(activate ? "Camera activated." : "Camera deactivated", Response::Ok));
83 }
84
85
VideoSource()86 VideoSource::VideoSource():
87 DaemonCommand("videosource",
88 "videosource cam|dummy [<call_id>]",
89 "Toggles camera source for specified call."
90 "If no call is specified, the current call is taken.")
91 {
92 addExample(new DaemonCommandExample("videosource cam 1",
93 "Status: Ok\n\n"
94 "Webcam source selected."));
95
96 addExample(new DaemonCommandExample("videosource dummy 1",
97 "Status: Ok\n\n"
98 "Dummy source selected."));
99
100 addExample(new DaemonCommandExample("videosource cam",
101 "Status: Error\n\n"
102 "Reason: No current call available."));
103
104 addExample(new DaemonCommandExample("videosource cam 2",
105 "Status: Error\n\n"
106 "Reason: No call with such id."));
107 }
108
exec(Daemon * app,const string & args)109 void VideoSource::exec(Daemon* app, const string& args)
110 {
111 LinphoneCore *lc = app->getCore();
112 LinphoneCall *call = NULL;
113 string subcommand;
114 int cid;
115 bool activate = false;
116
117 istringstream ist(args);
118 ist >> subcommand;
119 if (ist.fail()) {
120 app->sendResponse(Response("Missing parameter.", Response::Error));
121 return;
122 }
123 ist >> cid;
124 if (ist.fail()) {
125 call = linphone_core_get_current_call(lc);
126 if (call == NULL) {
127 app->sendResponse(Response("No current call available."));
128 return;
129 }
130 } else {
131 call = app->findCall(cid);
132 if (call == NULL) {
133 app->sendResponse(Response("No call with such id."));
134 return;
135 }
136 }
137
138 if (subcommand.compare("cam") == 0) {
139 activate = true;
140 } else if (subcommand.compare("dummy") == 0) {
141 activate = false;
142 } else {
143 app->sendResponse(Response("Invalid source.", Response::Error));
144 return;
145 }
146 linphone_call_enable_camera(call,activate);
147 app->sendResponse(Response(activate ? "Dummy source selected." : "Webcam source selected.", Response::Ok));
148 }
149
150
AutoVideo()151 AutoVideo::AutoVideo():
152 DaemonCommand("autovideo",
153 "autovideo on|off",
154 "Enables/disables automatic video setup when a call is issued.")
155 {
156 addExample(new DaemonCommandExample("autovideo on",
157 "Status: Ok\n\n"
158 "Auto video ON"));
159
160 addExample(new DaemonCommandExample("autovideo off",
161 "Status: Ok\n\n"
162 "Auto video OFF"));
163 }
164
exec(Daemon * app,const std::string & args)165 void AutoVideo::exec(Daemon* app, const std::string& args)
166 {
167
168 bool enable = (args.compare("on") == 0);
169 LinphoneCore *lc = app->getCore();
170 LinphoneVideoPolicy vpol = {TRUE, TRUE};
171
172 linphone_core_set_video_policy(lc, &vpol);
173 app->setAutoVideo(enable);
174 app->sendResponse(Response(enable?"Auto video ON": "Auto video OFF", Response::Ok));
175 }
176