Add support for YUY2, UYVY and NV12 format for native DirectShow devices.

cusax-fix
Sebastien Vincent 16 years ago
parent 06fa9e6933
commit dba9eba38d

@ -5,11 +5,10 @@
CC = cl /W4 /wd4996 /EHsc /O2
JNI_HEADERS = /I%JAVA_HOME%\include /I%JAVA_HOME%\include\win32
# DX_HEADERS = /I"C:\Program Files\Microsoft DirectX SDK (February 2010)\Include" /I"C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Include"
LIBS = /link /out:jdirectshow.dll
CFLAGS = $(JNI_HEADERS)
OBJS = net_java_sip_communicator_impl_neomedia_directshow_DSManager.cpp net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice.cpp ds_manager.cpp ds_capture_device.cpp
OBJS = net_java_sip_communicator_impl_neomedia_directshow_DSManager.cpp net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice.cpp net_java_sip_communicator_impl_neomedia_directshow_DSFormat.cpp ds_manager.cpp ds_capture_device.cpp
jdirectshow.dll: clean
$(CC) $(CFLAGS) /LD $(OBJS) $(LIBS) ole32.lib oleaut32.lib user32.lib

@ -189,7 +189,6 @@ bool DSCaptureDevice::setFormat(const VideoFormat& format)
if(!FAILED(ret))
{
VIDEOINFOHEADER* videoFormat = NULL;
GUID fmt;
size_t bitCount = 0;
/* get the current format and change resolution */
@ -198,28 +197,31 @@ bool DSCaptureDevice::setFormat(const VideoFormat& format)
videoFormat->bmiHeader.biWidth = (LONG)format.width;
videoFormat->bmiHeader.biHeight = (LONG)format.height;
switch(format.format)
{
case ARGB32:
fmt = MEDIASUBTYPE_ARGB32;
bitCount = 32;
break;
case RGB32:
fmt = MEDIASUBTYPE_RGB32;
if(format.pixelFormat == MEDIASUBTYPE_ARGB32.Data1 ||
format.pixelFormat == MEDIASUBTYPE_RGB32.Data1)
{
bitCount = 32;
break;
case RGB24:
fmt = MEDIASUBTYPE_RGB24;
}
else if(format.pixelFormat == MEDIASUBTYPE_RGB24.Data1)
{
bitCount = 24;
break;
default:
/* try to set resolution with current color space */
fmt = mediaType->subtype;
}
else
{
bitCount = videoFormat->bmiHeader.biBitCount;
break;
}
mediaType->subtype = fmt;
/* find the media type */
for(std::list<VideoFormat>::iterator it = m_formats.begin() ;
it != m_formats.end() ; ++it)
{
if(format.pixelFormat == (*it).pixelFormat)
{
mediaType->subtype = (*it).mediaType;
break;
}
}
ret = streamConfig->SetFormat(mediaType);
if(FAILED(ret))
@ -229,9 +231,9 @@ bool DSCaptureDevice::setFormat(const VideoFormat& format)
}
else
{
m_width = format.width;
m_height = format.height;
m_bitPerPixel = bitCount;
m_format = format;
m_format.mediaType = mediaType->subtype;
}
DeleteMediaType(mediaType);
@ -389,31 +391,21 @@ void DSCaptureDevice::initSupportedFormats()
{
format.height = hdr->bmiHeader.biHeight;
format.width = hdr->bmiHeader.biWidth;
format.pixelFormat = mediaType->subtype.Data1;
format.mediaType = mediaType->subtype;
if(mediaType->subtype == MEDIASUBTYPE_ARGB32)
{
format.format = ARGB32;
}
else if(mediaType->subtype == MEDIASUBTYPE_RGB32)
{
format.format = RGB32;
}
else if(mediaType->subtype == MEDIASUBTYPE_RGB24)
{
format.format = RGB24;
}
m_formats.push_back(format);
if(format.pixelFormat != 0x30323449)
{
m_formats.push_back(format);
}
}
}
}
delete allocBytes;
}
}
std::list<VideoFormat> DSCaptureDevice::getSupportedFormats() const
{
return m_formats;
@ -481,14 +473,9 @@ bool DSCaptureDevice::stop()
return true;
}
size_t DSCaptureDevice::getWidth()
{
return m_width;
}
size_t DSCaptureDevice::getHeight()
VideoFormat DSCaptureDevice::getFormat() const
{
return m_height;
return m_format;
}
size_t DSCaptureDevice::getBitPerPixel()

@ -160,16 +160,10 @@ public:
bool stop();
/**
* \brief Get current width.
* \return width
* \brief Get current format.
* \return current format
*/
size_t getWidth();
/**
* \brief Get current height.
* \return height
*/
size_t getHeight();
VideoFormat getFormat() const;
/**
* \brief Get current bit per pixel.
@ -234,14 +228,9 @@ private:
ISampleGrabber* m_sampleGrabber;
/**
* \brief Current width.
*/
size_t m_width;
/**
* \brief Current height.
* \brief Current format.
*/
size_t m_height;
VideoFormat m_format;
/**
* \brief Current bit per pixel.

@ -80,16 +80,21 @@ public:
{
BYTE* data = NULL;
size_t length = 0;
bool flipImage = true;
bool flipImage = false;
size_t width = 0;
size_t height = 0;
size_t bytesPerPixel = 0;
VideoFormat format = m_dev->getFormat();
/* get width and height */
width = m_dev->getWidth();
height = m_dev->getHeight();
width = format.width;
height = format.height;
bytesPerPixel = m_dev->getBitPerPixel() / 8;
/* flip image for RGB content */
flipImage = (format.mediaType == MEDIASUBTYPE_ARGB32 ||
format.mediaType == MEDIASUBTYPE_RGB32 ||
format.mediaType == MEDIASUBTYPE_RGB24);
sample->GetPointer(&data);
length = sample->GetActualDataLength();
@ -223,19 +228,54 @@ JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_D
{
jfieldID fieldH = env->GetFieldID(clazz, "height", "I");
jfieldID fieldW = env->GetFieldID(clazz, "width", "I");
jfieldID fieldF = env->GetFieldID(clazz, "colorSpace", "I");
jint f = env->GetIntField(format, fieldF);
jfieldID fieldF = env->GetFieldID(clazz, "pixelFormat", "J");
jlong f = env->GetLongField(format, fieldF);
jint w = env->GetIntField(format, fieldW);
jint h = env->GetIntField(format, fieldH);
fmt.width = w;
fmt.height = h;
fmt.format = (ColorSpace)f;
fmt.pixelFormat = (unsigned long)f;
dev->setFormat(fmt);
}
}
/**
* \brief Get current format.
* \param env JNI environment
* \param obj object
* \param native pointer
* \return current format
*/
JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice_getFormat
(JNIEnv* env, jobject obj, jlong ptr)
{
DSCaptureDevice* dev = reinterpret_cast<DSCaptureDevice*>(ptr);
VideoFormat fmt = dev->getFormat();
jclass clazzDSFormat = NULL;
jmethodID initDSFormat = NULL;
jobject ret = NULL;
/* get DSFormat class to instantiate some object */
clazzDSFormat = env->FindClass("net/java/sip/communicator/impl/neomedia/directshow/DSFormat");
if(clazzDSFormat == NULL)
{
return NULL;
}
initDSFormat = env->GetMethodID(clazzDSFormat, "<init>", "(IIJ)V");
if(initDSFormat == NULL)
{
return NULL;
}
ret = env->NewObject(clazzDSFormat, initDSFormat, static_cast<size_t>(fmt.width),
static_cast<size_t>(fmt.height), static_cast<jlong>(fmt.pixelFormat));
return ret;
}
/**
* \brief Get formats supported by native capture device.
* \param env JNI environment
@ -260,7 +300,7 @@ JNIEXPORT jobjectArray JNICALL Java_net_java_sip_communicator_impl_neomedia_dire
return NULL;
}
initDSFormat = env->GetMethodID(clazzDSFormat, "<init>", "(III)V");
initDSFormat = env->GetMethodID(clazzDSFormat, "<init>", "(IIJ)V");
if(initDSFormat == NULL)
{
@ -274,7 +314,7 @@ JNIEXPORT jobjectArray JNICALL Java_net_java_sip_communicator_impl_neomedia_dire
{
VideoFormat tmp = (*it);
jobject o = env->NewObject(clazzDSFormat, initDSFormat, static_cast<size_t>(tmp.width),
static_cast<size_t>(tmp.height), tmp.format);
static_cast<size_t>(tmp.height), static_cast<jlong>(tmp.pixelFormat));
if(o == NULL)
{

@ -1,10 +1,3 @@
/*
* 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_directshow_DSCaptureDevice */
@ -46,6 +39,14 @@ JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_neomedia_directsho
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice_setFormat
(JNIEnv *, jobject, jlong, jobject);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice
* Method: getFormat
* Signature: (J)Lnet/java/sip/communicator/impl/neomedia/directshow/DSFormat;
*/
JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice_getFormat
(JNIEnv *, jobject, jlong);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSCaptureDevice
* Method: getSupportedFormats

@ -0,0 +1,121 @@
#include "net_java_sip_communicator_impl_neomedia_directshow_DSFormat.h"
#include <windows.h>
#include <dshow.h>
#include <wmcodecdsp.h>
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getRGB24PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_RGB24.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getRGB32PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_RGB32.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getARGBPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_ARGB32.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getAYUVPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_AYUV.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYUY2PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_YUY2.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getUYVYPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_UYVY.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC1PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IMC1.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC2PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IMC2.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC3PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IMC3.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC4PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IMC4.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYV12PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_YV12.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getNV12PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_NV12.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIF09PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IF09.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIYUVPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_IYUV.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY211PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_Y211.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY411PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_Y411.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY41PPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_Y41P.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYVU9PixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_YVU9.Data1;
}
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYVYUPixelFormat
(JNIEnv *, jclass)
{
return MEDIASUBTYPE_YVYU.Data1;
}

@ -0,0 +1,165 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_sip_communicator_impl_neomedia_directshow_DSFormat */
#ifndef _Included_net_java_sip_communicator_impl_neomedia_directshow_DSFormat
#define _Included_net_java_sip_communicator_impl_neomedia_directshow_DSFormat
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getRGB24PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getRGB24PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getRGB32PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getRGB32PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getARGBPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getARGBPixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getAYUVPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getAYUVPixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getYUY2PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYUY2PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getUYVYPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getUYVYPixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIMC1PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC1PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIMC2PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC2PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIMC3PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC3PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIMC4PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIMC4PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getYV12PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYV12PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getNV12PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getNV12PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIF09PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIF09PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getIYUVPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getIYUVPixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getY211PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY211PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getY411PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY411PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getY41PPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getY41PPixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getYVU9PixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYVU9PixelFormat
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_neomedia_directshow_DSFormat
* Method: getYVYUPixelFormat
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_neomedia_directshow_DSFormat_getYVYUPixelFormat
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

@ -14,19 +14,6 @@
#ifndef VIDEO_FORMAT_H
#define VIDEO_FORMAT_H
/**
* \struct ColorSpace
* \brief Color space (RGB, YUV,...).
*/
enum ColorSpace
{
ARGB32 = 0, /**< ARGB color */
RGB32, /**< RGB on 32-bit (alpha not used) */
RGB24, /**< RGB on 24 bit */
UNKNOWN, /**< Unknown color space */
ANY = -1
};
/**
* \struct VideoFormat
* \brief Information about video format
@ -35,7 +22,8 @@ struct VideoFormat
{
size_t width; /**< Video width */
size_t height; /**< Video height */
enum ColorSpace format; /**< Format */
unsigned long pixelFormat; /**< Pixel format */
GUID mediaType; /**< Media type */
};
#endif /* VIDEO_FORMAT_H */

@ -66,6 +66,8 @@ public class FFmpeg
public static final int PIX_FMT_YUYV422 = 1;
public static final int PIX_FMT_NV12 = 25;
public static final int SWS_BICUBIC = 4;
public static final int X264_RC_ABR = 2;

@ -6,10 +6,14 @@
*/
package net.java.sip.communicator.impl.neomedia.device;
import java.util.*;
import javax.media.*;
import net.java.sip.communicator.impl.neomedia.codec.video.*;
import net.java.sip.communicator.impl.neomedia.directshow.*;
import net.java.sip.communicator.impl.neomedia.jmfext.media.protocol.directshow.*;
import net.java.sip.communicator.util.*;
/**
* Discovers and registers DirectShow video capture devices with JMF.
@ -18,6 +22,11 @@
*/
public class DirectShowAuto
{
/**
* The <tt>Logger</tt>.
*/
private static final Logger logger = Logger.getLogger(DirectShowAuto.class);
/**
* The protocol of the <tt>MediaLocator</tt>s identifying QuickTime/QTKit
* capture devices.
@ -47,20 +56,35 @@ public DirectShowAuto() throws Exception
for(int i = 0 ; i < devices.length ; i++)
{
DSFormat fmt = devices[i].getFormat();
long pixelFormat = fmt.getPixelFormat();
Format format = null;
int ffmpegPixFmt = (int)DataSource.getFFmpegPixFmt(pixelFormat);
if(ffmpegPixFmt != FFmpeg.PIX_FMT_NONE)
{
format = new AVFrameFormat(ffmpegPixFmt);
}
else
{
logger.warn("No support for this webcam: " +
devices[i].getName() + "(no format supported)");
continue;
}
CaptureDeviceInfo device
= new CaptureDeviceInfo(devices[i].getName(),
new MediaLocator(LOCATOR_PROTOCOL + ':' + devices[i].
getName()),
new Format[]
{
new AVFrameFormat(FFmpeg.PIX_FMT_RGB24),
new AVFrameFormat(FFmpeg.PIX_FMT_RGB32)
});
{
format,
});
CaptureDeviceManager.addDevice(device);
captureDeviceInfoIsAdded = true;
}
if (captureDeviceInfoIsAdded)
CaptureDeviceManager.commit();

@ -79,6 +79,16 @@ public void setFormat(DSFormat format)
setFormat(ptr, format);
}
/**
* Get current format.
*
* @return current format used
*/
public DSFormat getFormat()
{
return getFormat(ptr);
}
/**
* Get the supported video format this capture device supports.
*
@ -128,13 +138,21 @@ public void setDelegate(GrabberDelegate delegate)
private native String getName(long ptr);
/**
* Native method to get name of the capture device.
* Native method to set format on the capture device.
*
* @param ptr native pointer of <tt>DSCaptureDevice</tt>
* @param format format to set
*/
private native void setFormat(long ptr, DSFormat format);
/**
* Native method to get format on the capture device.
*
* @param ptr native pointer of <tt>DSCaptureDevice</tt>
* @return format current format
*/
private native DSFormat getFormat(long ptr);
/**
* Native method to get supported formats from capture device.
*

@ -13,25 +13,26 @@
*/
public class DSFormat
{
/**
* ARGB32 format type.
*/
public static final int ARGB32 = 0;
/**
* RGB32 format type (first byte is ignored).
*/
public static final int RGB32 = 1;
static
{
System.loadLibrary("jdirectshow");
/**
* RBG24 format type.
*/
public static final int RGB24 = 2;
RGB24 = getRGB24PixelFormat();
RGB32 = getRGB32PixelFormat();
ARGB32 = getARGBPixelFormat();
YUY2 = getYUY2PixelFormat();
UYVY = getUYVYPixelFormat();
NV12 = getNV12PixelFormat();
}
/**
* Unknown format type.
*/
public static final int UNKNOWN = 3;
/* supported formats */
public static final long RGB24;
public static final long RGB32;
public static final long ARGB32;
public static final long YUY2;
public static final long UYVY;
public static final long NV12;
/**
* Video width.
@ -46,20 +47,20 @@ public class DSFormat
/**
* Color space.
*/
private int colorSpace = UNKNOWN;
private long pixelFormat = -1;
/**
* Constructor.
*
* @param width video width
* @param height video height
* @param colorSpace color space
* @param pixelFormat pixel format
*/
public DSFormat(int width, int height, int colorSpace)
public DSFormat(int width, int height, long pixelFormat)
{
this.width = width;
this.height = height;
this.colorSpace = colorSpace;
this.pixelFormat = pixelFormat;
}
/**
@ -87,9 +88,32 @@ public int getHeight()
*
* @return color space
*/
public int getColorSpace()
public long getPixelFormat()
{
return colorSpace;
return pixelFormat;
}
/* RGB */
public static native long getRGB24PixelFormat();
public static native long getRGB32PixelFormat();
public static native long getARGBPixelFormat();
/* YUV */
public static native long getAYUVPixelFormat();
public static native long getYUY2PixelFormat();
public static native long getUYVYPixelFormat();
public static native long getIMC1PixelFormat();
public static native long getIMC2PixelFormat();
public static native long getIMC3PixelFormat();
public static native long getIMC4PixelFormat();
public static native long getYV12PixelFormat();
public static native long getNV12PixelFormat();
public static native long getIF09PixelFormat();
public static native long getIYUVPixelFormat();
public static native long getY211PixelFormat();
public static native long getY411PixelFormat();
public static native long getY41PPixelFormat();
public static native long getYVU9PixelFormat();
public static native long getYVYUPixelFormat();
}

@ -44,6 +44,26 @@ public class DataSource extends AbstractPushBufferCaptureDevice
*/
private DSManager manager = null;
/**
* The map of DirectShow pixel formats to FFmpeg
* pixel formats which allows converting between the two.
*/
private static final long[] DS_TO_FFMPEG_PIX_FMT
= new long[]
{
DSFormat.RGB24,
FFmpeg.PIX_FMT_RGB24,
DSFormat.RGB32,
FFmpeg.PIX_FMT_RGB32,
DSFormat.ARGB32,
FFmpeg.PIX_FMT_ARGB,
DSFormat.YUY2,
FFmpeg.PIX_FMT_YUYV422,
DSFormat.UYVY,
FFmpeg.PIX_FMT_UYVY422,
DSFormat.NV12,
FFmpeg.PIX_FMT_NV12,
};
/**
* The default width of <tt>DataSource</tt>.
*/
@ -188,26 +208,11 @@ protected Format[] getSupportedFormats(int streamIndex)
for(DSFormat fmt : fmts)
{
Dimension size = new Dimension(fmt.getWidth(), fmt.getHeight());
int colorSpace = 0;
switch(fmt.getColorSpace())
{
case DSFormat.RGB32:
colorSpace = FFmpeg.PIX_FMT_RGB32;
break;
case DSFormat.ARGB32:
colorSpace = FFmpeg.PIX_FMT_ARGB;
break;
case DSFormat.RGB24:
colorSpace = FFmpeg.PIX_FMT_RGB24;
break;
default:
/* does not support other for the moment */
continue;
}
long f = fmt.getPixelFormat();
int pixelFormat = (int)getFFmpegPixFmt(f);
formats.add(new AVFrameFormat(size, Format.NOT_SPECIFIED,
colorSpace));
pixelFormat));
}
return formats.toArray(new Format[formats.size()]);
@ -270,31 +275,18 @@ protected Format setFormat(
if(newValue instanceof AVFrameFormat)
{
AVFrameFormat f = (AVFrameFormat)newValue;
int colorSpace = DSFormat.UNKNOWN;
long pixelFormat = -1;
int pixFmt = f.getPixFmt();
if(pixFmt == FFmpeg.PIX_FMT_ARGB)
{
colorSpace = DSFormat.ARGB32;
}
else if(pixFmt == FFmpeg.PIX_FMT_RGB32)
{
colorSpace = DSFormat.RGB32;
}
else if(pixFmt == FFmpeg.PIX_FMT_RGB24)
{
colorSpace = DSFormat.RGB24;
}
else
pixelFormat = getDSPixFmt(pixFmt);
if(pixelFormat != -1)
{
/* unsupported */
DSFormat fmt = new DSFormat(newSize.width, newSize.height,
pixelFormat);
device.setFormat(fmt);
}
DSFormat fmt = new DSFormat(newSize.width, newSize.height,
colorSpace);
device.setFormat(fmt);
}
return newValue;
@ -378,5 +370,36 @@ protected void doStop() throws IOException
super.doStop();
device.close();
}
/**
* Gets the DirectShow pixel format matching a specific FFmpeg pixel
* format.
*
* @param dsPixFmt the DirectShow pixel format to get the matching
* Ffmpeg pixel format of
* @return the FFmpeg pixel format matching the specified DirectShow pixel
*/
public static long getFFmpegPixFmt(long dsPixFmt)
{
for (int i = 0; i < DS_TO_FFMPEG_PIX_FMT.length; i += 2)
if (DS_TO_FFMPEG_PIX_FMT[i] == dsPixFmt)
return DS_TO_FFMPEG_PIX_FMT[i + 1];
return FFmpeg.PIX_FMT_NONE;
}
/**
* Gets the FFmpeg pixel format matching a specific DirectShow
* Specification pixel format.
*
* @param ffmpegPixFmt FFmpeg format
* @return the DirectShow pixel format matching the specified FFmpeg format
*/
public static long getDSPixFmt(int ffmpegPixFmt)
{
for (int i = 0; i < DS_TO_FFMPEG_PIX_FMT.length; i += 2)
if (DS_TO_FFMPEG_PIX_FMT[i + 1] == ffmpegPixFmt)
return DS_TO_FFMPEG_PIX_FMT[i];
return -1;
}
}

Loading…
Cancel
Save