aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLyubomir Marinov <lyubomir.marinov@jitsi.org>2010-05-16 18:38:24 +0000
committerLyubomir Marinov <lyubomir.marinov@jitsi.org>2010-05-16 18:38:24 +0000
commit2bf12e9a07991abff47f02d3d50e3197a3bc8e51 (patch)
tree294d7f59486a2e44054d8eccfe0fbe75f16ad64c
parent57a42aa9ac28bb7c60b1b7f662ac9c376ca06b16 (diff)
downloadjitsi-2bf12e9a07991abff47f02d3d50e3197a3bc8e51.zip
jitsi-2bf12e9a07991abff47f02d3d50e3197a3bc8e51.tar.gz
jitsi-2bf12e9a07991abff47f02d3d50e3197a3bc8e51.tar.bz2
Attempts to support YUYV in the Video for Linux Two API Specification CaptureDevice and to make it easier to add support for new formats.
-rw-r--r--src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.c7
-rw-r--r--src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.h37
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/codec/video/FFmpeg.java4
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/device/Video4Linux2Auto.java14
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/DataSource.java48
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2.java7
-rw-r--r--src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2Stream.java11
7 files changed, 97 insertions, 31 deletions
diff --git a/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.c b/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.c
index 1883316..96e0380 100644
--- a/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.c
+++ b/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.c
@@ -206,6 +206,13 @@ Java_net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_
}
JNIEXPORT jint JNICALL
+Java_net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_1PIX_1FMT_1YUYV
+ (JNIEnv *jniEnv, jclass clazz)
+{
+ return (jint) V4L2_PIX_FMT_YUYV;
+}
+
+JNIEXPORT jint JNICALL
Java_net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_v4l2_1pix_1format_1getHeight
(JNIEnv *jniEnv, jclass clazz, jlong v4l2_pix_format)
{
diff --git a/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.h b/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.h
index 867614a..ce23f43 100644
--- a/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.h
+++ b/src/native/linux/video4linux2/net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2.h
@@ -1,3 +1,10 @@
+/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2 */
@@ -7,28 +14,6 @@
#ifdef __cplusplus
extern "C" {
#endif
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_MAP_SHARED
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_MAP_SHARED 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_O_NONBLOCK
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_O_NONBLOCK 2048L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_O_RDWR
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_O_RDWR 2L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_PROT_READ
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_PROT_READ 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_PROT_WRITE
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_PROT_WRITE 2L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_BUF_TYPE_VIDEO_CAPTURE
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_BUF_TYPE_VIDEO_CAPTURE 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_CAP_STREAMING
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_CAP_STREAMING 67108864L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_CAP_VIDEO_CAPTURE
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_CAP_VIDEO_CAPTURE 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_FIELD_NONE
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_FIELD_NONE 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_MEMORY_MMAP
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_MEMORY_MMAP 1L
-#undef net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_MEMORY_USERPTR
-#define net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_MEMORY_USERPTR 2L
/*
* Class: net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2
* Method: close
@@ -207,6 +192,14 @@ JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_jmfext_media
/*
* Class: net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2
+ * Method: V4L2_PIX_FMT_YUYV
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2_V4L2_1PIX_1FMT_1YUYV
+ (JNIEnv *, jclass);
+
+/*
+ * Class: net_java_sip_communicator_impl_neomedia_jmfext_media_protocol_video4linux2_Video4Linux2
* Method: v4l2_pix_format_getHeight
* Signature: (J)I
*/
diff --git a/src/net/java/sip/communicator/impl/neomedia/codec/video/FFmpeg.java b/src/net/java/sip/communicator/impl/neomedia/codec/video/FFmpeg.java
index f2069c3..dc733db 100644
--- a/src/net/java/sip/communicator/impl/neomedia/codec/video/FFmpeg.java
+++ b/src/net/java/sip/communicator/impl/neomedia/codec/video/FFmpeg.java
@@ -40,6 +40,8 @@ public class FFmpeg
*/
public static final int PIX_FMT_BGR32_1;
+ public static final int PIX_FMT_NONE = -1;
+
/**
* RGB24 format handled in endian specific manner.
* It is stored as RGB on big-endian and BGR on little-endian.
@@ -62,6 +64,8 @@ public class FFmpeg
public static final int PIX_FMT_YUV420P;
+ public static final int PIX_FMT_YUYV422 = 1;
+
public static final int SWS_BICUBIC = 4;
public static final int X264_RC_ABR = 2;
diff --git a/src/net/java/sip/communicator/impl/neomedia/device/Video4Linux2Auto.java b/src/net/java/sip/communicator/impl/neomedia/device/Video4Linux2Auto.java
index c64532c..c5ca6ba 100644
--- a/src/net/java/sip/communicator/impl/neomedia/device/Video4Linux2Auto.java
+++ b/src/net/java/sip/communicator/impl/neomedia/device/Video4Linux2Auto.java
@@ -151,7 +151,8 @@ public class Video4Linux2Auto
pixelformat
= Video4Linux2.v4l2_pix_format_getPixelformat(fmtPix);
if ((Video4Linux2.V4L2_PIX_FMT_RGB24 != pixelformat)
- || (Video4Linux2.V4L2_PIX_FMT_UYVY != pixelformat))
+ || (FFmpeg.PIX_FMT_NONE
+ == DataSource.getFFmpegPixFmt(pixelformat)))
{
Video4Linux2.v4l2_pix_format_setPixelformat(
fmtPix,
@@ -179,10 +180,15 @@ public class Video4Linux2Auto
if (Video4Linux2.V4L2_PIX_FMT_RGB24 == pixelformat)
format = new RGBFormat();
- else if (Video4Linux2.V4L2_PIX_FMT_UYVY == pixelformat)
- format = new AVFrameFormat(FFmpeg.PIX_FMT_UYVY422);
else
- return false;
+ {
+ int ffmpegPixFmt = DataSource.getFFmpegPixFmt(pixelformat);
+
+ if (FFmpeg.PIX_FMT_NONE != ffmpegPixFmt)
+ format = new AVFrameFormat(ffmpegPixFmt);
+ else
+ return false;
+ }
String name = Video4Linux2.v4l2_capability_getCard(v4l2_capability);
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/DataSource.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/DataSource.java
index d46ade1..6638138 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/DataSource.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/DataSource.java
@@ -11,6 +11,7 @@ import java.io.*;
import javax.media.*;
import javax.media.control.*;
+import net.java.sip.communicator.impl.neomedia.codec.video.*;
import net.java.sip.communicator.impl.neomedia.device.*;
import net.java.sip.communicator.impl.neomedia.jmfext.media.protocol.*;
@@ -37,6 +38,19 @@ public class DataSource
public static final int DEFAULT_WIDTH = 640;
/**
+ * The map of Video for Linux Two API Specification pixel formats to FFmpeg
+ * pixel formats which allows converting between the two.
+ */
+ private static final int[] V4L2_TO_FFMPEG_PIX_FMT
+ = new int[]
+ {
+ Video4Linux2.V4L2_PIX_FMT_UYVY,
+ FFmpeg.PIX_FMT_UYVY422,
+ Video4Linux2.V4L2_PIX_FMT_YUYV,
+ FFmpeg.PIX_FMT_YUYV422
+ };
+
+ /**
* The file descriptor of the opened Video for Linux Two API Specification
* device represented by this <tt>DataSource</tt>.
*/
@@ -189,4 +203,38 @@ public class DataSource
? locator.getRemainder()
: null;
}
+
+ /**
+ * Gets the Video for Linux Two API Specification pixel format matching a
+ * specific FFmpeg pixel format.
+ *
+ * @param ffmpegPixFmt the FFmpeg pixel format to get the matching Video for
+ * Linux Two API Specification pixel format of
+ * @return the Video for Linux Two API Specification pixel format matching
+ * the specified FFmpeg format
+ */
+ public static int getFFmpegPixFmt(int v4l2PixFmt)
+ {
+ for (int i = 0; i < V4L2_TO_FFMPEG_PIX_FMT.length; i += 2)
+ if (V4L2_TO_FFMPEG_PIX_FMT[i] == v4l2PixFmt)
+ return V4L2_TO_FFMPEG_PIX_FMT[i + 1];
+ return FFmpeg.PIX_FMT_NONE;
+ }
+
+ /**
+ * Gets the FFmpeg pixel format matching a specific Video for Linux Two API
+ * Specification pixel format.
+ *
+ * @param v4l2PixFmt the Video for Linux Two API Specification pixel format
+ * to get the matching FFmpeg pixel format of
+ * @return the FFmpeg pixel format matching the specified Video for Linux
+ * Two API Specification pixel format
+ */
+ public static int getV4L2PixFmt(int ffmpegPixFmt)
+ {
+ for (int i = 0; i < V4L2_TO_FFMPEG_PIX_FMT.length; i += 2)
+ if (V4L2_TO_FFMPEG_PIX_FMT[i + 1] == ffmpegPixFmt)
+ return V4L2_TO_FFMPEG_PIX_FMT[i];
+ return Video4Linux2.V4L2_PIX_FMT_NONE;
+ }
}
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2.java
index 1011ac1..a563ad8 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2.java
@@ -36,10 +36,14 @@ public class Video4Linux2
public static final int V4L2_MEMORY_USERPTR = 2;
+ public static final int V4L2_PIX_FMT_NONE = 0;
+
public static final int V4L2_PIX_FMT_RGB24;
public static final int V4L2_PIX_FMT_UYVY;
+ public static final int V4L2_PIX_FMT_YUYV;
+
public static final int VIDIOC_DQBUF;
public static final int VIDIOC_G_FMT;
@@ -64,6 +68,7 @@ public class Video4Linux2
V4L2_PIX_FMT_RGB24 = V4L2_PIX_FMT_RGB24();
V4L2_PIX_FMT_UYVY = V4L2_PIX_FMT_UYVY();
+ V4L2_PIX_FMT_YUYV = V4L2_PIX_FMT_YUYV();
VIDIOC_DQBUF = VIDIOC_DQBUF();
VIDIOC_G_FMT = VIDIOC_G_FMT();
VIDIOC_QBUF = VIDIOC_QBUF();
@@ -131,6 +136,8 @@ public class Video4Linux2
private static native int V4L2_PIX_FMT_UYVY();
+ private static native int V4L2_PIX_FMT_YUYV();
+
public static native int v4l2_pix_format_getHeight(
long v4l2_pix_format);
diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2Stream.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2Stream.java
index 8c3ee39..025f990 100644
--- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2Stream.java
+++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/video4linux2/Video4Linux2Stream.java
@@ -199,8 +199,10 @@ public class Video4Linux2Stream
int pixelformat
= Video4Linux2.v4l2_pix_format_getPixelformat(
fmtPix);
+ int ffmpegPixFmt
+ = DataSource.getFFmpegPixFmt(pixelformat);
- if (Video4Linux2.V4L2_PIX_FMT_UYVY == pixelformat)
+ if (FFmpeg.PIX_FMT_NONE != ffmpegPixFmt)
{
int width
= Video4Linux2.v4l2_pix_format_getWidth(fmtPix);
@@ -212,7 +214,7 @@ public class Video4Linux2Stream
= new AVFrameFormat(
new Dimension(width, height),
Format.NOT_SPECIFIED,
- FFmpeg.PIX_FMT_UYVY422);
+ ffmpegPixFmt);
}
}
}
@@ -531,10 +533,9 @@ public class Video4Linux2Stream
{
int pixFmt = ((AVFrameFormat) format).getPixFmt();
- if (FFmpeg.PIX_FMT_UYVY422 == pixFmt)
- pixelformat = Video4Linux2.V4L2_PIX_FMT_UYVY;
+ pixelformat = DataSource.getV4L2PixFmt(pixFmt);
}
- if (pixelformat == 0)
+ if (Video4Linux2.V4L2_PIX_FMT_NONE == pixelformat)
throw new IOException("Unsupported format " + format);
long v4l2_format