...
 
Commits (3)
......@@ -157,9 +157,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
content/content.h
content/file-content.h
content/file-transfer-content.h
content/header/header.h
content/header/header-p.h
content/header/header-param.h
content/header/header.h
core/core-accessor.h
core/core-listener.h
core/core-p.h
......@@ -194,6 +194,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
event-log/events.h
hacks/hacks.h
logger/logger.h
media-device-watcher/media-device-watcher.h
nat/ice-agent.h
nat/stun-client.h
object/app-data-container.h
......@@ -365,8 +366,9 @@ elseif (WIN32)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-windows.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-windows.h)
elseif (UNIX)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-linux.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-linux.h)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-linux.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES media-device-watcher/media-device-watcher-linux.cpp)
endif ()
set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS
......@@ -383,7 +385,7 @@ foreach (header ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES})
endforeach ()
set(LINPHONE_PRIVATE_HEADER_FILES ${LINPHONE_PRIVATE_HEADER_FILES} PARENT_SCOPE)
if (ANDROID AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (ANDROID AND CMAKE_C_COMPILER_ID STREQUAL "GNU")
list(APPEND STRICT_OPTIONS_CXX "-Wno-attributes")
endif()
bc_apply_compile_flags(LINPHONE_CXX_OBJECTS_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
......
/*
* media-device-watcher-linux.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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.
*/
#ifndef _L_MEDIA_DEVICE_WATCHER_LINUX_H_
#define _L_MEDIA_DEVICE_WATCHER_LINUX_H_
#include <libudev.h>
#include "core_private.h"
#include "core/core.h"
#include "logger/logger.h"
#include "media-device-watcher.h"
#include "object/object-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class MediaDeviceWatcherPrivate : public ObjectPrivate {
public:
udev *udevContext = nullptr;
udev_monitor *udevMonitor = nullptr;
Core *core = nullptr;
belle_sip_source_t *socketWatcher = nullptr;
void clean ();
static int handleNotification (void *userData, unsigned int) {
MediaDeviceWatcherPrivate *d = static_cast<MediaDeviceWatcherPrivate *>(userData);
udev_device *udevDevice = udev_monitor_receive_device(d->udevMonitor);
const char *subsystem = udev_device_get_subsystem(udevDevice);
if (subsystem) {
if (!strcmp(subsystem, "sound")) {
// TODO:
}
if (!strcmp(subsystem, "video4linux")) {
// TODO:
}
}
udev_device_unref(udevDevice);
}
};
void MediaDeviceWatcherPrivate::clean () {
if (core)
core->getCCore()->sal->destroySocketWatcher(socketWatcher);
if (udevMonitor)
udev_monitor_unref(udevMonitor);
if (udevContext)
udev_unref(udevContext);
}
MediaDeviceWatcher::MediaDeviceWatcher (Core *core) : Object(*new MediaDeviceWatcherPrivate) {
L_D();
if (!(d->udevContext = udev_new())) {
lError() << "Unable to create udev context.";
return;
}
if (!(d->udevMonitor = udev_monitor_new_from_netlink(d->udevContext, "udev"))) {
lError() << "Unable to create udev monitor.";
d->clean();
return;
}
for (const char *subsystem : { "sound", "video4linux" })
if (udev_monitor_filter_add_match_subsystem_devtype(d->udevMonitor, subsystem, nullptr) < 0) {
lError() << "Unable to monitor: " << subsystem;
d->clean();
return;
}
int fd = udev_monitor_get_fd(d->udevMonitor);
if (fd < 0) {
d->clean();
return;
}
d->core = core;
core->getCCore()->sal->createSocketWatcher(&MediaDeviceWatcherPrivate::handleNotification, d, 0, fd, BELLE_SIP_EVENT_READ);
}
MediaDeviceWatcher::~MediaDeviceWatcher () {
L_D();
d->clean();
}
LINPHONE_END_NAMESPACE
#endif // ifndef _L_MEDIA_DEVICE_WATCHER_LINUX_H_
/*
* media-device-watcher.h
* Copyright (C) 2010-2018 Belledonne Communications SARL
*
* 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.
*/
#ifndef _L_MEDIA_DEVICE_WATCHER_H_
#define _L_MEDIA_DEVICE_WATCHER_H_
#include "object/object.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Core;
class MediaDeviceWatcherPrivate;
class MediaDeviceWatcher : public Object {
public:
MediaDeviceWatcher (Core *core);
~MediaDeviceWatcher ();
private:
L_DECLARE_PRIVATE(MediaDeviceWatcher);
L_DISABLE_COPY(MediaDeviceWatcher);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _L_MEDIA_DEVICE_WATCHER_H_
......@@ -801,6 +801,23 @@ void Sal::cancelTimer(belle_sip_source_t *timer) {
belle_sip_main_loop_remove_source(ml, timer);
}
belle_sip_source_t *Sal::createSocketWatcher (
belle_sip_source_func_t func,
void *data,
unsigned int timeoutValueMs,
belle_sip_socket_t fd,
unsigned int events
) {
belle_sip_source_t *socketWatcher = belle_sip_socket_source_new(func, data, fd, events, timeoutValueMs);
belle_sip_main_loop_add_source(belle_sip_stack_get_main_loop(mStack), socketWatcher);
return socketWatcher;
}
void Sal::destroySocketWatcher (belle_sip_source_t *socketWatcher) {
if (socketWatcher)
belle_sip_main_loop_remove_source(belle_sip_stack_get_main_loop(mStack), socketWatcher);
}
belle_sip_response_t *Sal::createResponseFromRequest (belle_sip_request_t *request, int code) {
auto response = belle_sip_response_create_from_request(request, code);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(response), BELLE_SIP_HEADER(mUserAgentHeader));
......
......@@ -240,8 +240,7 @@ public:
const std::string &getDnsUserHostsFile () const;
belle_sip_resolver_context_t *resolveA (const std::string &name, int port, int family, belle_sip_resolver_callback_t cb, void *data);
belle_sip_resolver_context_t *resolve (const std::string &service, const std::string &transport, const std::string &name, int port, int family, belle_sip_resolver_callback_t cb, void *data);
belle_sip_resolver_context_t *resolve (const std::string &service, const std::string &transport, const std::string &name, int port, int family, belle_sip_resolver_callback_t cb, void *data);
// ---------------------------------------------------------------------------
// Timers
......@@ -249,6 +248,17 @@ public:
belle_sip_source_t *createTimer (belle_sip_source_func_t func, void *data, unsigned int timeoutValueMs, const std::string &timerName);
void cancelTimer (belle_sip_source_t *timer);
// ---------------------------------------------------------------------------
// Socket watcher
// ---------------------------------------------------------------------------
belle_sip_source_t *createSocketWatcher (
belle_sip_source_func_t func,
void *data,
unsigned int timeoutValueMs,
belle_sip_socket_t fd,
unsigned int events
);
void destroySocketWatcher (belle_sip_source_t *socketWatcher);
private:
struct SalUuid {
......@@ -337,4 +347,3 @@ int toSipCode (SalReason reason);
LINPHONE_END_NAMESPACE
#endif // ifndef _L_SAL_H_