Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
791a0148
Unverified
Commit
791a0148
authored
4 years ago
by
Nicolas Werner
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #286 from trilene/voip
Adapt device monitoring for GStreamer 1.18
parents
c62db00e
e065bf22
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/WebRTCSession.cpp
+120
-22
120 additions, 22 deletions
src/WebRTCSession.cpp
src/WebRTCSession.h
+1
-2
1 addition, 2 deletions
src/WebRTCSession.h
with
121 additions
and
24 deletions
src/WebRTCSession.cpp
+
120
−
22
View file @
791a0148
...
...
@@ -21,6 +21,7 @@ WebRTCSession::WebRTCSession()
{
qRegisterMetaType
<
WebRTCSession
::
State
>
();
connect
(
this
,
&
WebRTCSession
::
stateChanged
,
this
,
&
WebRTCSession
::
setState
);
init
();
}
bool
...
...
@@ -78,7 +79,11 @@ WebRTCSession::init(std::string *errorMessage)
gst_object_unref
(
plugin
);
}
if
(
!
initialised_
)
{
if
(
initialised_
)
{
#if GST_CHECK_VERSION(1, 18, 0)
startDeviceMonitor
();
#endif
}
else
{
nhlog
::
ui
()
->
error
(
strError
);
if
(
errorMessage
)
*
errorMessage
=
strError
;
...
...
@@ -95,12 +100,65 @@ namespace {
bool
isoffering_
;
std
::
string
localsdp_
;
std
::
vector
<
mtx
::
events
::
msg
::
CallCandidates
::
Candidate
>
localcandidates_
;
std
::
vector
<
std
::
pair
<
std
::
string
,
GstDevice
*>>
audioSources_
;
void
addDevice
(
GstDevice
*
device
)
{
if
(
device
)
{
gchar
*
name
=
gst_device_get_display_name
(
device
);
nhlog
::
ui
()
->
debug
(
"WebRTC: device added: {}"
,
name
);
audioSources_
.
push_back
({
name
,
device
});
g_free
(
name
);
}
}
#if GST_CHECK_VERSION(1, 18, 0)
void
removeDevice
(
GstDevice
*
device
,
bool
changed
)
{
if
(
device
)
{
if
(
auto
it
=
std
::
find_if
(
audioSources_
.
begin
(),
audioSources_
.
end
(),
[
device
](
const
auto
&
s
)
{
return
s
.
second
==
device
;
});
it
!=
audioSources_
.
end
())
{
nhlog
::
ui
()
->
debug
(
std
::
string
(
"WebRTC: device "
)
+
(
changed
?
"changed: "
:
"removed: "
)
+
"{}"
,
it
->
first
);
gst_object_unref
(
device
);
audioSources_
.
erase
(
it
);
}
}
}
#endif
gboolean
newBusMessage
(
GstBus
*
bus
G_GNUC_UNUSED
,
GstMessage
*
msg
,
gpointer
user_data
)
{
WebRTCSession
*
session
=
static_cast
<
WebRTCSession
*>
(
user_data
);
switch
(
GST_MESSAGE_TYPE
(
msg
))
{
#if GST_CHECK_VERSION(1, 18, 0)
case
GST_MESSAGE_DEVICE_ADDED
:
{
GstDevice
*
device
;
gst_message_parse_device_added
(
msg
,
&
device
);
addDevice
(
device
);
break
;
}
case
GST_MESSAGE_DEVICE_REMOVED
:
{
GstDevice
*
device
;
gst_message_parse_device_removed
(
msg
,
&
device
);
removeDevice
(
device
,
false
);
break
;
}
case
GST_MESSAGE_DEVICE_CHANGED
:
{
GstDevice
*
device
;
GstDevice
*
oldDevice
;
gst_message_parse_device_changed
(
msg
,
&
device
,
&
oldDevice
);
removeDevice
(
oldDevice
,
true
);
addDevice
(
device
);
break
;
}
#endif
case
GST_MESSAGE_EOS
:
nhlog
::
ui
()
->
error
(
"WebRTC: end of stream"
);
session
->
end
();
...
...
@@ -504,19 +562,18 @@ WebRTCSession::startPipeline(int opusPayloadType)
bool
WebRTCSession
::
createPipeline
(
int
opusPayloadType
)
{
int
nSources
=
audioSources_
?
g_list_length
(
audioSources_
)
:
0
;
if
(
nSources
==
0
)
{
if
(
audioSources_
.
empty
())
{
nhlog
::
ui
()
->
error
(
"WebRTC: no audio sources"
);
return
false
;
}
if
(
audioSourceIndex_
<
0
||
audioSourceIndex_
>=
n
Sources
)
{
if
(
audioSourceIndex_
<
0
||
(
size_t
)
audioSourceIndex_
>=
audio
Sources
_
.
size
()
)
{
nhlog
::
ui
()
->
error
(
"WebRTC: invalid audio source index"
);
return
false
;
}
GstElement
*
source
=
gst_device_create_element
(
GST_DEVICE_CAST
(
g_list_nth_data
(
audioSources_
,
audioSourceIndex_
))
,
nullptr
);
GstElement
*
source
=
gst_device_create_element
(
audioSources_
[
audioSourceIndex_
].
second
,
nullptr
);
GstElement
*
volume
=
gst_element_factory_make
(
"volume"
,
"srclevel"
);
GstElement
*
convert
=
gst_element_factory_make
(
"audioconvert"
,
nullptr
);
GstElement
*
resample
=
gst_element_factory_make
(
"audioresample"
,
nullptr
);
...
...
@@ -609,6 +666,32 @@ WebRTCSession::end()
emit
stateChanged
(
State
::
DISCONNECTED
);
}
#if GST_CHECK_VERSION(1, 18, 0)
void
WebRTCSession
::
startDeviceMonitor
()
{
if
(
!
initialised_
)
return
;
static
GstDeviceMonitor
*
monitor
=
nullptr
;
if
(
!
monitor
)
{
monitor
=
gst_device_monitor_new
();
GstCaps
*
caps
=
gst_caps_new_empty_simple
(
"audio/x-raw"
);
gst_device_monitor_add_filter
(
monitor
,
"Audio/Source"
,
caps
);
gst_caps_unref
(
caps
);
GstBus
*
bus
=
gst_device_monitor_get_bus
(
monitor
);
gst_bus_add_watch
(
bus
,
newBusMessage
,
nullptr
);
gst_object_unref
(
bus
);
if
(
!
gst_device_monitor_start
(
monitor
))
{
nhlog
::
ui
()
->
error
(
"WebRTC: failed to start device monitor"
);
return
;
}
}
}
#else
void
WebRTCSession
::
refreshDevices
()
{
...
...
@@ -622,31 +705,42 @@ WebRTCSession::refreshDevices()
gst_device_monitor_add_filter
(
monitor
,
"Audio/Source"
,
caps
);
gst_caps_unref
(
caps
);
}
g_list_free_full
(
audioSources_
,
g_object_unref
);
audioSources_
=
gst_device_monitor_get_devices
(
monitor
);
std
::
for_each
(
audioSources_
.
begin
(),
audioSources_
.
end
(),
[](
const
auto
&
s
)
{
gst_object_unref
(
s
.
second
);
});
audioSources_
.
clear
();
GList
*
devices
=
gst_device_monitor_get_devices
(
monitor
);
if
(
devices
)
{
audioSources_
.
reserve
(
g_list_length
(
devices
));
for
(
GList
*
l
=
devices
;
l
!=
nullptr
;
l
=
l
->
next
)
addDevice
(
GST_DEVICE_CAST
(
l
->
data
));
g_list_free
(
devices
);
}
}
#endif
std
::
vector
<
std
::
string
>
WebRTCSession
::
getAudioSourceNames
(
const
std
::
string
&
defaultDevice
)
{
if
(
!
initialised_
)
return
{};
#if !GST_CHECK_VERSION(1, 18, 0)
refreshDevices
();
#endif
// move default device to top of the list
if
(
auto
it
=
std
::
find_if
(
audioSources_
.
begin
(),
audioSources_
.
end
(),
[
&
](
const
auto
&
s
)
{
return
s
.
first
==
defaultDevice
;
});
it
!=
audioSources_
.
end
())
std
::
swap
(
audioSources_
.
front
(),
*
it
);
std
::
vector
<
std
::
string
>
ret
;
ret
.
reserve
(
g_list_length
(
audioSources_
));
for
(
GList
*
l
=
audioSources_
;
l
!=
nullptr
;
l
=
l
->
next
)
{
gchar
*
name
=
gst_device_get_display_name
(
GST_DEVICE_CAST
(
l
->
data
));
ret
.
emplace_back
(
name
);
g_free
(
name
);
if
(
ret
.
back
()
==
defaultDevice
)
{
// move default device to top of the list
std
::
swap
(
audioSources_
->
data
,
l
->
data
);
std
::
swap
(
ret
.
front
(),
ret
.
back
());
}
}
ret
.
reserve
(
audioSources_
.
size
());
std
::
for_each
(
audioSources_
.
cbegin
(),
audioSources_
.
cend
(),
[
&
](
const
auto
&
s
)
{
ret
.
push_back
(
s
.
first
);
});
return
ret
;
}
#else
bool
...
...
@@ -697,6 +791,10 @@ void
WebRTCSession
::
refreshDevices
()
{}
void
WebRTCSession
::
startDeviceMonitor
()
{}
std
::
vector
<
std
::
string
>
WebRTCSession
::
getAudioSourceNames
(
const
std
::
string
&
)
{
...
...
This diff is collapsed.
Click to expand it.
src/WebRTCSession.h
+
1
−
2
View file @
791a0148
...
...
@@ -7,7 +7,6 @@
#include
"mtx/events/voip.hpp"
typedef
struct
_GList
GList
;
typedef
struct
_GstElement
GstElement
;
class
WebRTCSession
:
public
QObject
...
...
@@ -71,12 +70,12 @@ private:
unsigned
int
busWatchId_
=
0
;
std
::
string
stunServer_
;
std
::
vector
<
std
::
string
>
turnServers_
;
GList
*
audioSources_
=
nullptr
;
int
audioSourceIndex_
=
-
1
;
bool
startPipeline
(
int
opusPayloadType
);
bool
createPipeline
(
int
opusPayloadType
);
void
refreshDevices
();
void
startDeviceMonitor
();
public
:
WebRTCSession
(
WebRTCSession
const
&
)
=
delete
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment