From 0f10b769bf3893758da0085c3c9dab4d91f84b39 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Thu, 3 Sep 2009 17:12:26 +0200 Subject: [PATCH] dshowvideosrc: factorize dshow video format parsing --- sys/dshowsrcwrapper/gstdshow.cpp | 56 ++++++++++++++++++ sys/dshowsrcwrapper/gstdshow.h | 20 +++++++ sys/dshowsrcwrapper/gstdshowvideosrc.cpp | 73 +++++------------------- sys/dshowsrcwrapper/gstdshowvideosrc.h | 11 ---- 4 files changed, 90 insertions(+), 70 deletions(-) mode change 100644 => 100755 sys/dshowsrcwrapper/gstdshow.cpp mode change 100644 => 100755 sys/dshowsrcwrapper/gstdshow.h mode change 100644 => 100755 sys/dshowsrcwrapper/gstdshowvideosrc.cpp mode change 100644 => 100755 sys/dshowsrcwrapper/gstdshowvideosrc.h diff --git a/sys/dshowsrcwrapper/gstdshow.cpp b/sys/dshowsrcwrapper/gstdshow.cpp old mode 100644 new mode 100755 index 8b77b5857a..e3a4f4a618 --- a/sys/dshowsrcwrapper/gstdshow.cpp +++ b/sys/dshowsrcwrapper/gstdshow.cpp @@ -321,3 +321,59 @@ gst_dshow_show_propertypage (IBaseFilter *base_filter) } return ret; } + +GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar* name, + const VIDEO_STREAM_CONFIG_CAPS * vscc, const VIDEOINFOHEADER *video_info, + GstCaptureVideoDefault *video_default) +{ + GstCaps *video_caps = NULL; + GstStructure *video_structure = NULL; + + video_default->defaultWidth = video_info->bmiHeader.biWidth; + video_default->defaultHeight = video_info->bmiHeader.biHeight; + video_default->defaultFPS = (gint) (10000000 / video_info->AvgTimePerFrame); + video_default->granularityWidth = vscc->OutputGranularityX; + video_default->granularityHeight = vscc->OutputGranularityY; + + /* raw video format */ + switch (video_format) { + case GST_VIDEO_FORMAT_BGR: + video_caps = gst_caps_from_string (GST_VIDEO_CAPS_BGR); + break; + case GST_VIDEO_FORMAT_I420: + video_caps = gst_caps_from_string (GST_VIDEO_CAPS_YUV ("I420")); + default: + break; + } + + /* other video format */ + if (!video_caps){ + if (g_strcasecmp (name, "video/x-dv, systemstream=FALSE") == 0) { + video_caps = gst_caps_new_simple ("video/x-dv", + "systemstream", G_TYPE_BOOLEAN, FALSE, + "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'v', 's', 'd'), + NULL); + } else if (g_strcasecmp (name, "video/x-dv, systemstream=TRUE") == 0) { + video_caps = gst_caps_new_simple ("video/x-dv", + "systemstream", G_TYPE_BOOLEAN, TRUE, NULL); + return video_caps; + } + } + + if (!video_caps) + return NULL; + + video_structure = gst_caps_get_structure (video_caps, 0); + + gst_structure_set (video_structure, + "width", GST_TYPE_INT_RANGE, vscc->MinOutputSize.cx, vscc->MaxOutputSize.cx, + "height", GST_TYPE_INT_RANGE, vscc->MinOutputSize.cy, vscc->MaxOutputSize.cy, + "framerate", GST_TYPE_FRACTION_RANGE, + (gint) (10000000 / vscc->MaxFrameInterval), 1, + (gint) (10000000 / vscc->MinFrameInterval), 1, + NULL); + + g_print ("caps are %s\n", gst_caps_to_string (video_caps)); + + return video_caps; +} diff --git a/sys/dshowsrcwrapper/gstdshow.h b/sys/dshowsrcwrapper/gstdshow.h old mode 100644 new mode 100755 index 4491e50d66..f13d9a8d28 --- a/sys/dshowsrcwrapper/gstdshow.h +++ b/sys/dshowsrcwrapper/gstdshow.h @@ -31,6 +31,8 @@ #include #include +#include +#include typedef struct _GstCapturePinMediaType { @@ -38,6 +40,18 @@ typedef struct _GstCapturePinMediaType IPin *capture_pin; } GstCapturePinMediaType; +/* video default properties associated to a video format (YUY2, I420, RGB24 ...) */ +typedef struct _GstCaptureVideoDefault +{ + gint defaultWidth; + gint defaultHeight; + gint defaultFPS; + + gint granularityWidth; //will be removed when GST_TYPE_INT_RANGE_STEP exits + gint granularityHeight; //will be removed when GST_TYPE_INT_RANGE_STEP exits + +} GstCaptureVideoDefault; + #ifdef __cplusplus extern "C" { #endif @@ -71,6 +85,12 @@ gchar *gst_dshow_getdevice_from_devicename (const GUID *device_category, gchar * /* show the capture filter property page (generally used to setup the device). the page is modal*/ gboolean gst_dshow_show_propertypage (IBaseFilter *base_filter); + +/* transform a dshow video caps to a gstreamer video caps */ +GstCaps *gst_dshow_new_video_caps (GstVideoFormat video_format, const gchar* name, + const VIDEO_STREAM_CONFIG_CAPS * vscc, const VIDEOINFOHEADER *video_info, + GstCaptureVideoDefault *video_default); + #ifdef __cplusplus } diff --git a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp old mode 100644 new mode 100755 index 1f4ff4abc2..32c19f86ff --- a/sys/dshowsrcwrapper/gstdshowvideosrc.cpp +++ b/sys/dshowsrcwrapper/gstdshowvideosrc.cpp @@ -924,21 +924,9 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin, /* I420 */ if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_I420, FORMAT_VideoInfo)) { - video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; - video_default->defaultWidth = video_info->bmiHeader.biWidth; - video_default->defaultHeight = video_info->bmiHeader.biHeight; - video_default->defaultFPS = (int) (10000000 / video_info->AvgTimePerFrame); - video_default->granularityWidth = vscc.OutputGranularityX; - video_default->granularityHeight = vscc.OutputGranularityY; - - mediacaps = gst_caps_new_simple ("video/x-raw-yuv", - "width", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cx, vscc.MaxOutputSize.cx, - "height", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cy, vscc.MaxOutputSize.cy, - "framerate", GST_TYPE_FRACTION_RANGE, - (int) (10000000 / vscc.MaxFrameInterval), 1, - (int) (10000000 / vscc.MinFrameInterval), 1, - "format", GST_TYPE_FOURCC, MAKEFOURCC ('I', '4', '2', '0'), NULL); + mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_I420, NULL, &vscc, + (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat, video_default); if (mediacaps) { src->pins_mediatypes = @@ -955,27 +943,9 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin, /* BGR */ if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_RGB24, FORMAT_VideoInfo)) { - video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; - video_default->defaultWidth = video_info->bmiHeader.biWidth; - video_default->defaultHeight = video_info->bmiHeader.biHeight; - video_default->defaultFPS = (int) (10000000 / video_info->AvgTimePerFrame); - video_default->granularityWidth = vscc.OutputGranularityX; - video_default->granularityHeight = vscc.OutputGranularityY; - - /* ffmpegcolorspace handles RGB24 in BIG_ENDIAN */ - mediacaps = gst_caps_new_simple ("video/x-raw-rgb", - "bpp", G_TYPE_INT, 24, - "depth", G_TYPE_INT, 24, - "width", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cx, vscc.MaxOutputSize.cx, - "height", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cy, vscc.MaxOutputSize.cy, - "framerate", GST_TYPE_FRACTION_RANGE, - (int) (10000000 / vscc.MaxFrameInterval), 1, - (int) (10000000 / vscc.MinFrameInterval), 1, - "endianness", G_TYPE_INT, G_BIG_ENDIAN, - "red_mask", G_TYPE_INT, 255, - "green_mask", G_TYPE_INT, 65280, - "blue_mask", G_TYPE_INT, 16711680, NULL); + mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_BGR, NULL, &vscc, + (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat, video_default); if (mediacaps) { src->pins_mediatypes = @@ -992,22 +962,10 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin, /* DVSD */ if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_dvsd, FORMAT_VideoInfo)) { - video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; - - video_default->defaultWidth = video_info->bmiHeader.biWidth; - video_default->defaultHeight = video_info->bmiHeader.biHeight; - video_default->defaultFPS = (int) (10000000 / video_info->AvgTimePerFrame); - video_default->granularityWidth = vscc.OutputGranularityX; - video_default->granularityHeight = vscc.OutputGranularityY; - - mediacaps = gst_caps_new_simple ("video/x-dv", - "systemstream", G_TYPE_BOOLEAN, FALSE, - "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('d', 'v', 's', 'd'), - "framerate", GST_TYPE_FRACTION_RANGE, - (int) (10000000 / vscc.MaxFrameInterval), 1, - (int) (10000000 / vscc.MinFrameInterval), 1, - "width", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cx, vscc.MaxOutputSize.cx, - "height", GST_TYPE_INT_RANGE, vscc.MinOutputSize.cy, vscc.MaxOutputSize.cy, NULL); + + mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN, + "video/x-dv, systemstream=FALSE", &vscc, (VIDEOINFOHEADER *) + pin_mediatype->mediatype->pbFormat, video_default); if (mediacaps) { src->pins_mediatypes = @@ -1026,15 +984,12 @@ gst_dshowvideosrc_getcaps_from_streamcaps (GstDshowVideoSrc * src, IPin * pin, if (gst_dshow_check_mediatype (pin_mediatype->mediatype, MEDIASUBTYPE_dvsd, FORMAT_DvInfo)) { video_info = (VIDEOINFOHEADER *) pin_mediatype->mediatype->pbFormat; - //No video size in caps when stream ? I do know if the following fields exist - video_default->defaultWidth = video_info->bmiHeader.biWidth; - video_default->defaultHeight = video_info->bmiHeader.biHeight; - video_default->defaultFPS = (int) (10000000 / video_info->AvgTimePerFrame); - video_default->granularityWidth = vscc.OutputGranularityX; - video_default->granularityHeight = vscc.OutputGranularityY; - - mediacaps = gst_caps_new_simple ("video/x-dv", - "systemstream", G_TYPE_BOOLEAN, TRUE, NULL); + video_default->granularityWidth = 0; + video_default->granularityHeight = 0; + + mediacaps = gst_dshow_new_video_caps (GST_VIDEO_FORMAT_UNKNOWN, + "video/x-dv, systemstream=TRUE", &vscc, (VIDEOINFOHEADER *) + pin_mediatype->mediatype->pbFormat, video_default); if (mediacaps) { src->pins_mediatypes = diff --git a/sys/dshowsrcwrapper/gstdshowvideosrc.h b/sys/dshowsrcwrapper/gstdshowvideosrc.h old mode 100644 new mode 100755 index 415830719b..bced6bef68 --- a/sys/dshowsrcwrapper/gstdshowvideosrc.h +++ b/sys/dshowsrcwrapper/gstdshowvideosrc.h @@ -42,17 +42,6 @@ G_BEGIN_DECLS typedef struct _GstDshowVideoSrc GstDshowVideoSrc; typedef struct _GstDshowVideoSrcClass GstDshowVideoSrcClass; -/* video default properties associated to a video format (YUY2, I420, RGB24 ...) */ -typedef struct _GstCaptureVideoDefault -{ - gint defaultWidth; - gint defaultHeight; - gint defaultFPS; - - gint granularityWidth; //will be removed when GST_TYPE_INT_RANGE_STEP exits - gint granularityHeight; //will be removed when GST_TYPE_INT_RANGE_STEP exits - -} GstCaptureVideoDefault; struct _GstDshowVideoSrc {