Bug 826985 - Add --enable-libv4l2 to support more video formats on Linux. r?glandium r?jesup
MozReview-Commit-ID: K8gbLAyIl4T
--- a/build/gyp.mozbuild
+++ b/build/gyp.mozbuild
@@ -9,16 +9,17 @@ gyp_vars = {
'asan': 0,
'build_with_mozilla': 1,
'build_with_chromium': 0,
'use_official_google_api_keys': 0,
'have_clock_monotonic': 1 if CONFIG['HAVE_CLOCK_MONOTONIC'] else 0,
'have_ethtool_cmd_speed_hi': 1 if CONFIG['MOZ_WEBRTC_HAVE_ETHTOOL_SPEED_HI'] else 0,
'include_alsa_audio': 1 if CONFIG['MOZ_ALSA'] else 0,
'include_pulse_audio': 1 if CONFIG['MOZ_PULSEAUDIO'] else 0,
+ 'use_libv4l2': 1 if CONFIG['MOZ_LIBV4L2'] else 0,
# basic stuff for everything
'include_internal_video_render': 0,
'clang_use_chrome_plugins': 0,
'enable_protobuf': 0,
'include_tests': 0,
'enable_android_opensl': 1,
'enable_android_opensl_output': 0,
# use_system_lib* still seems to be in use in trunk/build
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -195,16 +195,17 @@ def old_configure_options(*options):
'--enable-icf',
'--enable-install-strip',
'--enable-ion',
'--enable-ios-target',
'--enable-ipdl-tests',
'--enable-jitspew',
'--enable-libjpeg-turbo',
'--enable-libproxy',
+ '--enable-libv4l2',
'--enable-llvm-hacks',
'--enable-logrefcnt',
'--enable-maintenance-service',
'--enable-media-navigator',
'--enable-memory-sanitizer',
'--enable-mobile-optimize',
'--enable-more-deterministic',
'--enable-mozril-geoloc',
--- a/config/system-headers
+++ b/config/system-headers
@@ -627,16 +627,17 @@ libc_r.h
libelf.h
libelf/libelf.h
libgen.h
libgnome/gnome-url.h
libgnome/libgnome.h
libgnomeui/gnome-icon-lookup.h
libgnomeui/gnome-icon-theme.h
libgnomeui/gnome-ui-init.h
+libv4l2.h
limits
limits.h
link.h
#ifdef ANDROID
linux/android_alarm.h
linux/ashmem.h
#endif
linux/ioprio.h
--- a/media/webrtc/signaling/test/common.build
+++ b/media/webrtc/signaling/test/common.build
@@ -104,16 +104,19 @@ OS_LIBS += CONFIG['MOZ_WEBRTC_X11_LIBS']
OS_LIBS += CONFIG['REALTIME_LIBS']
if CONFIG['MOZ_ALSA']:
OS_LIBS += CONFIG['MOZ_ALSA_LIBS']
if CONFIG['MOZ_SYSTEM_JPEG']:
OS_LIBS += CONFIG['MOZ_JPEG_LIBS']
+if CONFIG['MOZ_LIBV4L2']:
+ OS_LIBS += CONFIG['MOZ_LIBV4L2_LIBS']
+
if CONFIG['MOZ_SYSTEM_LIBVPX']:
OS_LIBS += CONFIG['MOZ_LIBVPX_LIBS']
if not CONFIG['MOZ_TREE_PIXMAN']:
OS_LIBS += CONFIG['MOZ_PIXMAN_LIBS']
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk2':
OS_LIBS += CONFIG['XLIBS']
--- a/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc
@@ -20,20 +20,31 @@
//v4l includes
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/videoio.h>
#elif defined(__sun)
#include <sys/videodev2.h>
#else
#include <linux/videodev2.h>
#endif
+#ifdef HAVE_LIBV4L2
+#include <libv4l2.h>
+#endif
#include "webrtc/system_wrappers/interface/ref_count.h"
#include "webrtc/system_wrappers/interface/trace.h"
+#ifdef HAVE_LIBV4L2
+#define open v4l2_open
+#define close v4l2_close
+#define dup v4l2_dup
+#define ioctl v4l2_ioctl
+#define mmap v4l2_mmap
+#define munmap v4l2_munmap
+#endif
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureModule::DeviceInfo*
VideoCaptureImpl::CreateDeviceInfo(const int32_t id)
{
@@ -131,16 +142,21 @@ int32_t DeviceInfoLinux::GetDeviceName(
}
close(fd);
char cameraName[64];
memset(deviceNameUTF8, 0, deviceNameLength);
memcpy(cameraName, cap.card, sizeof(cap.card));
+ if (cameraName[0] == '\0')
+ {
+ sprintf(cameraName, "Camera at /dev/video%d", deviceNumber);
+ }
+
if (deviceNameLength >= strlen(cameraName))
{
memcpy(deviceNameUTF8, cameraName, strlen(cameraName));
}
else
{
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "buffer passed is too small");
return -1;
--- a/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc
@@ -20,24 +20,36 @@
//v4l includes
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/videoio.h>
#elif defined(__sun)
#include <sys/videodev2.h>
#else
#include <linux/videodev2.h>
#endif
+#ifdef HAVE_LIBV4L2
+#include <libv4l2.h>
+#endif
#include <new>
#include "webrtc/modules/video_capture/linux/video_capture_linux.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/ref_count.h"
#include "webrtc/system_wrappers/interface/trace.h"
+#ifdef HAVE_LIBV4L2
+#define open v4l2_open
+#define close v4l2_close
+#define dup v4l2_dup
+#define ioctl v4l2_ioctl
+#define mmap v4l2_mmap
+#define munmap v4l2_munmap
+#endif
+
namespace webrtc
{
namespace videocapturemodule
{
VideoCaptureModule* VideoCaptureImpl::Create(const int32_t id,
const char* deviceUniqueId)
{
RefCountImpl<videocapturemodule::VideoCaptureModuleV4L2>* implementation =
--- a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.gypi
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.gypi
@@ -2,16 +2,19 @@
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
{
+ 'variables': {
+ 'use_libv4l2%': 0,
+ },
'targets': [
{
# Note this library is missing an implementation for the video capture.
# Targets must link with either 'video_capture' or
# 'video_capture_module_internal_impl' depending on whether they want to
# use the internal capturer.
'target_name': 'video_capture_module',
'type': 'static_library',
@@ -70,16 +73,29 @@
'conditions': [
['include_v4l2_video_capture==1', {
'sources': [
'linux/device_info_linux.cc',
'linux/device_info_linux.h',
'linux/video_capture_linux.cc',
'linux/video_capture_linux.h',
],
+ 'conditions': [
+ ['use_libv4l2==1', {
+ 'defines': [
+ 'HAVE_LIBV4L2',
+ ],
+ 'cflags_mozilla': [
+ '$(MOZ_LIBV4L2_CFLAGS)',
+ ],
+ 'libraries': [
+ '-lv4l2',
+ ],
+ }],
+ ],
}], # linux
['OS=="mac"', {
'sources': [
'mac/qtkit/video_capture_qtkit.h',
'mac/qtkit/video_capture_qtkit.mm',
'mac/qtkit/video_capture_qtkit_info.h',
'mac/qtkit/video_capture_qtkit_info.mm',
'mac/qtkit/video_capture_qtkit_info_objc.h',
--- a/old-configure.in
+++ b/old-configure.in
@@ -3671,16 +3671,31 @@ AC_SUBST(MOZ_WEBRTC)
AC_SUBST(MOZ_WEBRTC_SIGNALING)
AC_SUBST(MOZ_PEERCONNECTION)
AC_SUBST(MOZ_WEBRTC_ASSERT_ALWAYS)
AC_SUBST(MOZ_WEBRTC_HARDWARE_AEC_NS)
AC_SUBST(MOZ_SCTP)
AC_SUBST(MOZ_SRTP)
AC_SUBST_LIST(MOZ_WEBRTC_X11_LIBS)
+dnl ========================================================
+dnl = Enable libv4l2 support
+dnl ========================================================
+MOZ_ARG_ENABLE_BOOL(libv4l2,
+[ --enable-libv4l2 Use libv4l2 to convert between webcam formats],
+ MOZ_LIBV4L2=1,
+ MOZ_LIBV4L2=)
+
+if test -n "$MOZ_LIBV4L2"; then
+ PKG_CHECK_MODULES(MOZ_LIBV4L2, libv4l2, ,
+ AC_MSG_ERROR([$MOZ_LIBV4L2_PKG_ERRORS Need libv4l2 development package. (On Ubuntu, you might try installing the package libv4l-dev.)]))
+fi
+
+AC_SUBST(MOZ_LIBV4L2)
+
dnl Use integers over floats for audio on B2G and Android
dnl (regarless of the CPU architecture, because audio
dnl backends for those platforms don't support floats. We also
dnl use integers on ARM with other OS, because it's more efficient.
if test "$OS_TARGET" = "Android" -o "$CPU_ARCH" = "arm"; then
MOZ_SAMPLE_TYPE_S16=1
AC_DEFINE(MOZ_SAMPLE_TYPE_S16)
AC_SUBST(MOZ_SAMPLE_TYPE_S16)
--- a/toolkit/library/moz.build
+++ b/toolkit/library/moz.build
@@ -221,16 +221,19 @@ if CONFIG['MOZ_SYSTEM_PNG']:
OS_LIBS += CONFIG['MOZ_PNG_LIBS']
if CONFIG['MOZ_SYSTEM_HUNSPELL']:
OS_LIBS += CONFIG['MOZ_HUNSPELL_LIBS']
if CONFIG['MOZ_SYSTEM_LIBEVENT']:
OS_LIBS += CONFIG['MOZ_LIBEVENT_LIBS']
+if CONFIG['MOZ_LIBV4L2']:
+ OS_LIBS += CONFIG['MOZ_LIBV4L2_LIBS']
+
if CONFIG['MOZ_SYSTEM_LIBVPX']:
OS_LIBS += CONFIG['MOZ_LIBVPX_LIBS']
if not CONFIG['MOZ_TREE_PIXMAN']:
OS_LIBS += CONFIG['MOZ_PIXMAN_LIBS']
if CONFIG['MOZ_ALSA']:
OS_LIBS += CONFIG['MOZ_ALSA_LIBS']