Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
30a90395
Commit
30a90395
authored
Apr 27, 2018
by
DanmeiChen
Browse files
Add incall-player in linphone-daemon
parent
7604ca87
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
309 additions
and
1 deletion
+309
-1
daemon/CMakeLists.txt
daemon/CMakeLists.txt
+2
-0
daemon/commands/play.cc
daemon/commands/play.cc
+233
-0
daemon/commands/play.h
daemon/commands/play.h
+50
-0
daemon/daemon.cc
daemon/daemon.cc
+18
-0
daemon/daemon.h
daemon/daemon.h
+6
-1
No files found.
daemon/CMakeLists.txt
View file @
30a90395
...
...
@@ -79,6 +79,8 @@ set(DAEMON_SOURCE_FILES
commands/msfilter-add-fmtp.h
commands/netsim.cc
commands/netsim.h
commands/play.cc
commands/play.h
commands/play-wav.cc
commands/play-wav.h
commands/pop-event.cc
...
...
daemon/commands/play.cc
0 → 100644
View file @
30a90395
/*
play-wav.cc
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "play.h"
#include "call.h"
#include <utility>
using
namespace
std
;
#define VOIDPTR_TO_INT(p) ((int)(intptr_t)(p))
void
IncallPlayerStartCommand
::
onEof
(
LinphonePlayer
*
player
){
pair
<
int
,
Daemon
*>
*
callPlayingData
=
(
pair
<
int
,
Daemon
*>
*
)
linphone_player_get_user_data
(
player
);
Daemon
*
app
=
callPlayingData
->
second
;
int
id
=
callPlayingData
->
first
;
app
->
callPlayingComplete
(
id
);
delete
callPlayingData
;
linphone_player_set_user_data
(
player
,
NULL
);
}
IncallPlayerStartCommand
::
IncallPlayerStartCommand
()
:
DaemonCommand
(
"incall-player-start"
,
"incall-player-start <filename> [<call_id>]"
,
"Play a WAV audio file or a MKV audio/video file. The played media stream will be sent through
\n
"
"the RTP session of the given call.
\n
"
"<filename> is the file to be played.
\n
"
)
{
addExample
(
new
DaemonCommandExample
(
"incall-player-start /usr/local/share/sounds/linphone/hello8000.wav 1"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-start /usr/local/share/sounds/linphone/hello8000.wav 1"
,
"Status: Error
\n
"
"Reason: No call with such id."
));
addExample
(
new
DaemonCommandExample
(
"incall-player-start /usr/local/share/sounds/linphone/hello8000.wav"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-start /usr/local/share/sounds/linphone/hello8000.wav"
,
"Status: Error
\n
"
"Reason: No active call."
));
}
void
IncallPlayerStartCommand
::
exec
(
Daemon
*
app
,
const
string
&
args
)
{
LinphoneCall
*
call
=
NULL
;
int
cid
;
const
MSList
*
elem
;
istringstream
ist
(
args
);
string
filename
;
ist
>>
filename
;
if
(
ist
.
eof
()
&&
(
filename
.
length
()
==
0
))
{
app
->
sendResponse
(
Response
(
"Missing filename parameter."
,
Response
::
Error
));
return
;
}
if
(
ist
.
fail
())
{
app
->
sendResponse
(
Response
(
"Incorrect filename parameter."
,
Response
::
Error
));
return
;
}
ist
>>
cid
;
if
(
ist
.
fail
())
{
elem
=
linphone_core_get_calls
(
app
->
getCore
());
if
(
elem
!=
NULL
&&
elem
->
next
==
NULL
)
{
call
=
(
LinphoneCall
*
)
elem
->
data
;
}
}
else
{
call
=
app
->
findCall
(
cid
);
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No call with such id."
));
return
;
}
}
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No active call."
));
return
;
}
LinphonePlayer
*
p
=
linphone_call_get_player
(
call
);
LinphonePlayerCbs
*
cbs
=
linphone_player_get_callbacks
(
p
);
pair
<
int
,
Daemon
*>
*
callPlayingData
=
(
pair
<
int
,
Daemon
*>
*
)
linphone_player_get_user_data
(
p
);
if
(
callPlayingData
)
callPlayingData
=
new
pair
<
int
,
Daemon
*>
({
VOIDPTR_TO_INT
(
linphone_call_get_user_data
(
call
)),
app
});
linphone_player_set_user_data
(
p
,
callPlayingData
);
linphone_player_cbs_set_eof_reached
(
cbs
,
onEof
);
linphone_player_open
(
p
,
filename
.
c_str
());
linphone_player_start
(
p
);
app
->
sendResponse
(
Response
());
}
IncallPlayerStopCommand
::
IncallPlayerStopCommand
()
:
DaemonCommand
(
"incall-player-stop"
,
"incall-player-stop [<call_id>]"
,
"Close the opened file.
\n
"
)
{
addExample
(
new
DaemonCommandExample
(
"incall-player-stop 1"
,
"Status: Error
\n
"
"Reason: No call with such id."
));
addExample
(
new
DaemonCommandExample
(
"incall-player-stop 1"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-stop"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-stop"
,
"Status: Error
\n
"
"Reason: No active call."
));
}
void
IncallPlayerStopCommand
::
exec
(
Daemon
*
app
,
const
string
&
args
)
{
LinphoneCall
*
call
=
NULL
;
int
cid
;
const
MSList
*
elem
;
istringstream
ist
(
args
);
ist
>>
cid
;
if
(
ist
.
fail
())
{
elem
=
linphone_core_get_calls
(
app
->
getCore
());
if
(
elem
!=
NULL
&&
elem
->
next
==
NULL
)
{
call
=
(
LinphoneCall
*
)
elem
->
data
;
}
}
else
{
call
=
app
->
findCall
(
cid
);
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No call with such id."
));
return
;
}
}
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No active call."
));
return
;
}
LinphonePlayer
*
p
=
linphone_call_get_player
(
call
);
linphone_player_close
(
p
);
app
->
sendResponse
(
Response
());
pair
<
int
,
Daemon
*>
*
callPlayingData
=
(
pair
<
int
,
Daemon
*>
*
)
linphone_player_get_user_data
(
p
);
if
(
callPlayingData
)
delete
callPlayingData
;
}
IncallPlayerPauseCommand
::
IncallPlayerPauseCommand
()
:
DaemonCommand
(
"incall-player-pause"
,
"incall-player-pause [<call_id>]"
,
"Pause the playing of a file.
\n
"
)
{
addExample
(
new
DaemonCommandExample
(
"incall-player-pause 1"
,
"Status: Error
\n
"
"Reason: No call with such id."
));
addExample
(
new
DaemonCommandExample
(
"incall-player-pause 1"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-pause"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-pause"
,
"Status: Error
\n
"
"Reason: No active call."
));
}
void
IncallPlayerPauseCommand
::
exec
(
Daemon
*
app
,
const
string
&
args
)
{
LinphoneCall
*
call
=
NULL
;
int
cid
;
const
MSList
*
elem
;
istringstream
ist
(
args
);
ist
>>
cid
;
if
(
ist
.
fail
())
{
elem
=
linphone_core_get_calls
(
app
->
getCore
());
if
(
elem
!=
NULL
&&
elem
->
next
==
NULL
)
{
call
=
(
LinphoneCall
*
)
elem
->
data
;
}
}
else
{
call
=
app
->
findCall
(
cid
);
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No call with such id."
));
return
;
}
}
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No active call."
));
return
;
}
LinphonePlayer
*
p
=
linphone_call_get_player
(
call
);
linphone_player_pause
(
p
);
app
->
sendResponse
(
Response
());
}
IncallPlayerResumeCommand
::
IncallPlayerResumeCommand
()
:
DaemonCommand
(
"incall-player-resume"
,
"incall-player-resume [<call_id>]"
,
"Unpause the playing of a file.
\n
"
)
{
addExample
(
new
DaemonCommandExample
(
"incall-player-resume 1"
,
"Status: Error
\n
"
"Reason: No call with such id."
));
addExample
(
new
DaemonCommandExample
(
"incall-player-resume 1"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-resume"
,
"Status: Ok
\n
"
));
addExample
(
new
DaemonCommandExample
(
"incall-player-resume"
,
"Status: Error
\n
"
"Reason: No active call."
));
}
void
IncallPlayerResumeCommand
::
exec
(
Daemon
*
app
,
const
string
&
args
)
{
LinphoneCall
*
call
=
NULL
;
int
cid
;
const
MSList
*
elem
;
istringstream
ist
(
args
);
ist
>>
cid
;
if
(
ist
.
fail
())
{
elem
=
linphone_core_get_calls
(
app
->
getCore
());
if
(
elem
!=
NULL
&&
elem
->
next
==
NULL
)
{
call
=
(
LinphoneCall
*
)
elem
->
data
;
}
}
else
{
call
=
app
->
findCall
(
cid
);
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No call with such id."
));
return
;
}
}
if
(
call
==
NULL
)
{
app
->
sendResponse
(
Response
(
"No active call."
));
return
;
}
LinphonePlayer
*
p
=
linphone_call_get_player
(
call
);
linphone_player_start
(
p
);
app
->
sendResponse
(
Response
());
}
daemon/commands/play.h
0 → 100644
View file @
30a90395
/*
play-wav.h
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LINPHONE_DAEMON_COMMAND_PLAY_H_
#define LINPHONE_DAEMON_COMMAND_PLAY_H_
#include "daemon.h"
class
IncallPlayerStartCommand
:
public
DaemonCommand
{
public:
IncallPlayerStartCommand
();
virtual
void
exec
(
Daemon
*
app
,
const
std
::
string
&
args
);
private:
static
void
onEof
(
LinphonePlayer
*
player
);
};
class
IncallPlayerStopCommand
:
public
DaemonCommand
{
public:
IncallPlayerStopCommand
();
virtual
void
exec
(
Daemon
*
app
,
const
std
::
string
&
args
);
};
class
IncallPlayerPauseCommand
:
public
DaemonCommand
{
public:
IncallPlayerPauseCommand
();
virtual
void
exec
(
Daemon
*
app
,
const
std
::
string
&
args
);
};
class
IncallPlayerResumeCommand
:
public
DaemonCommand
{
public:
IncallPlayerResumeCommand
();
virtual
void
exec
(
Daemon
*
app
,
const
std
::
string
&
args
);
};
#endif // LINPHONE_DAEMON_COMMAND_PLAY_H_
daemon/daemon.cc
View file @
30a90395
...
...
@@ -79,6 +79,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "commands/netsim.h"
#include "commands/cn.h"
#include "commands/version.h"
#include "commands/play.h"
#include "private.h"
using
namespace
std
;
...
...
@@ -214,6 +215,15 @@ AudioStreamStatsResponse::AudioStreamStatsResponse(Daemon* daemon, AudioStream*
setBody
(
ostr
.
str
().
c_str
());
}
CallPlayingStatsResponse
::
CallPlayingStatsResponse
(
Daemon
*
daemon
,
int
id
)
{
ostringstream
ostr
;
ostr
<<
"Event-type: call-playing-complete
\n
"
;
ostr
<<
"Id: "
<<
id
<<
"
\n
"
;
setBody
(
ostr
.
str
().
c_str
());
}
PayloadTypeResponse
::
PayloadTypeResponse
(
LinphoneCore
*
core
,
const
PayloadType
*
payloadType
,
int
index
,
const
string
&
prefix
,
bool
enabled_status
)
{
ostringstream
ostr
;
if
(
payloadType
!=
NULL
)
{
...
...
@@ -486,6 +496,10 @@ void Daemon::initCommands() {
mCommands
.
push_back
(
new
ConfigSetCommand
());
mCommands
.
push_back
(
new
NetsimCommand
());
mCommands
.
push_back
(
new
CNCommand
());
mCommands
.
push_back
(
new
IncallPlayerStartCommand
());
mCommands
.
push_back
(
new
IncallPlayerStopCommand
());
mCommands
.
push_back
(
new
IncallPlayerPauseCommand
());
mCommands
.
push_back
(
new
IncallPlayerResumeCommand
());
mCommands
.
sort
(
compareCommands
);
}
...
...
@@ -524,6 +538,10 @@ void Daemon::callStatsUpdated(LinphoneCall *call, const LinphoneCallStats *stats
}
}
void
Daemon
::
callPlayingComplete
(
int
id
)
{
mEventQueue
.
push
(
new
CallPlayingStatsResponse
(
this
,
id
));
}
void
Daemon
::
dtmfReceived
(
LinphoneCall
*
call
,
int
dtmf
)
{
mEventQueue
.
push
(
new
DtmfResponse
(
this
,
call
,
dtmf
));
}
...
...
daemon/daemon.h
View file @
30a90395
...
...
@@ -160,6 +160,11 @@ public:
const
LinphoneCallStats
*
stats
,
bool
event
);
};
class
CallPlayingStatsResponse
:
public
Response
{
public:
CallPlayingStatsResponse
(
Daemon
*
daemon
,
int
id
);
};
class
DtmfResponse
:
public
Response
{
public:
DtmfResponse
(
Daemon
*
daemon
,
LinphoneCall
*
call
,
int
dtmf
);
...
...
@@ -230,7 +235,7 @@ public:
void
dumpCommandsHelpHtml
();
void
enableStatsEvents
(
bool
enabled
);
void
enableLSD
(
bool
enabled
);
void
callPlayingComplete
(
int
id
);
void
setAutoVideo
(
bool
enabled
){
mAutoVideo
=
enabled
;
}
inline
bool
autoVideo
(){
return
mAutoVideo
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment