winscreencap: Initial port to 1.0

This commit is contained in:
Sebastian Dröge 2013-06-20 22:12:11 +02:00
parent 85c1510d6b
commit e2b83ff8a0
8 changed files with 115 additions and 210 deletions

View file

@ -347,7 +347,7 @@ GST_PLUGINS_NONPORTED=" cdxaparse \
apexsink cdaudio dc1394 directfb \
gsettings \
musepack nas sdl sndfile timidity \
directdraw direct3d9 acm wininet \
directdraw acm wininet \
xvid lv2 teletextdec sndio osx_video quicktime"
AC_SUBST(GST_PLUGINS_NONPORTED)
@ -757,36 +757,35 @@ AG_GST_CHECK_FEATURE(DIRECTDRAW, [DirectDraw plug-in], directdrawsink, [
AC_SUBST(HAVE_DIRECTDRAW)
])
dnl Direct3D9
AM_CONDITIONAL(USE_DIRECT3D9, true)
AG_GST_CHECK_FEATURE(DIRECT3D9, [Direct3D9], winscreencap, [
HAVE_DIRECT3D9="no"
dnl winscreencap
translit(dnm, m, l) AM_CONDITIONAL(USE_WINSCREENCAP, true)
AG_GST_CHECK_FEATURE(WINSCREENCAP, [winscreencap plug-in], winscreencap, [
HAVE_WINSCREENCAP="no"
save_CFLAGS="$CFLAGS"
save_LDFLAGS="$LDFLAGS"
save_LIBS="$LIBS"
CFLAGS="$CFLAGS $DIRECTX_CFLAGS"
LDFLAGS="$LDFLAGS $DIRECTX_LDFLAGS"
LIBS="$LIBS -ld3d9 -lgdi32"
AC_MSG_CHECKING(for Direct3D9 LDFLAGS)
AC_MSG_CHECKING(for Direct3D LDFLAGS)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <windows.h>
#include <d3d9.h>
]], [[
Direct3DCreate9(D3D_SDK_VERSION);
]])],
[HAVE_DIRECT3D9="yes"],
[HAVE_DIRECT3D9="no"])
AC_MSG_RESULT($HAVE_DIRECT3D9)
[HAVE_WINSCREENCAP="yes"],
[HAVE_WINSCREENCAP="no"])
AC_MSG_RESULT($HAVE_WINSCREENCAP)
CFLAGS=$save_CFLAGS
LDFLAGS=$save_LDFLAGS
LIBS=$save_LIBS
if test "x$HAVE_DIRECT3D9" = "xyes"; then
DIRECT3D9_LIBS="-ld3d9 -lgdi32"
AC_SUBST(DIRECT3D9_LIBS)
if test "x$HAVE_WINSCREENCAP" = "xyes"; then
WINSCREENCAP_LIBS="-ld3d9 -lgdi32"
AC_SUBST(WINSCREENCAP_LIBS)
fi
AC_SUBST(HAVE_DIRECT3D9)
AC_SUBST(HAVE_WINSCREENCAP)
])
dnl DirectShow

View file

@ -148,7 +148,7 @@ else
VDPAU_DIR=
endif
if USE_DIRECT3D9
if USE_WINSCREENCAP
WINSCREENCAP_DIR=winscreencap
else
WINSCREENCAP_DIR=

View file

@ -2,10 +2,10 @@ plugin_LTLIBRARIES = libgstwinscreencap.la
libgstwinscreencap_la_SOURCES = gstdx9screencapsrc.c gstgdiscreencapsrc.c gstwinscreencap.c
libgstwinscreencap_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) $(DIRECT3D9_CFLAGS) $(DIRECTX_CFLAGS)
$(GST_PLUGINS_BASE_CFLAGS) $(WINSCREENCAP_CFLAGS) $(DIRECTX_CFLAGS)
libgstwinscreencap_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \
$(DIRECT3D9_LIBS) $(DIRECTX_LDFLAGS)
$(WINSCREENCAP_LIBS) $(DIRECTX_LDFLAGS)
libgstwinscreencap_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstwinscreencap_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS= gstwinscreencap.h
noinst_HEADERS= gstwinscreencap.h gstdx9screencapsrc.h gstgdiscreencapsrc.h

View file

@ -48,18 +48,14 @@
GST_DEBUG_CATEGORY_STATIC (dx9screencapsrc_debug);
#define GST_VIDEO_ALPHA_MASK_15_INT 0x8000
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("video/x-raw-rgb,"
"width = " GST_VIDEO_SIZE_RANGE ","
"height = " GST_VIDEO_SIZE_RANGE "," "framerate = " GST_VIDEO_FPS_RANGE)
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("BGR"))
);
GST_BOILERPLATE (GstDX9ScreenCapSrc, gst_dx9screencapsrc,
GstPushSrc, GST_TYPE_PUSH_SRC);
#define gst_dx9screencapsrc_parent_class parent_class
G_DEFINE_TYPE (GstDX9ScreenCapSrc, gst_dx9screencapsrc, GST_TYPE_PUSH_SRC);
enum
{
@ -74,19 +70,16 @@ enum
static IDirect3D9 *g_d3d9 = NULL;
/* Fwd. decl. */
static GstCaps *gst_dx9screencapsrc_create_caps_from_format (D3DFORMAT fmt,
gint width, gint height);
static void gst_dx9screencapsrc_dispose (GObject * object);
static void gst_dx9screencapsrc_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
static void gst_dx9screencapsrc_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_dx9screencapsrc_fixate (GstPad * pad, GstCaps * caps);
static GstCaps * gst_dx9screencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps);
static gboolean gst_dx9screencapsrc_set_caps (GstBaseSrc * bsrc,
GstCaps * caps);
static GstCaps *gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc);
static GstCaps *gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter);
static gboolean gst_dx9screencapsrc_start (GstBaseSrc * bsrc);
static gboolean gst_dx9screencapsrc_stop (GstBaseSrc * bsrc);
@ -96,27 +89,16 @@ static GstFlowReturn gst_dx9screencapsrc_create (GstPushSrc * src,
GstBuffer ** buf);
/* Implementation. */
static void
gst_dx9screencapsrc_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (element_class,
"DirectX 9 screen capture source", "Source/Video", "Captures screen",
"Haakon Sporsheim <hakon.sporsheim@tandberg.com>");
}
static void
gst_dx9screencapsrc_class_init (GstDX9ScreenCapSrcClass * klass)
{
GObjectClass *go_class;
GstElementClass *e_class;
GstBaseSrcClass *bs_class;
GstPushSrcClass *ps_class;
go_class = (GObjectClass *) klass;
e_class = (GstElementClass *) klass;
bs_class = (GstBaseSrcClass *) klass;
ps_class = (GstPushSrcClass *) klass;
@ -129,6 +111,7 @@ gst_dx9screencapsrc_class_init (GstDX9ScreenCapSrcClass * klass)
bs_class->set_caps = GST_DEBUG_FUNCPTR (gst_dx9screencapsrc_set_caps);
bs_class->start = GST_DEBUG_FUNCPTR (gst_dx9screencapsrc_start);
bs_class->stop = GST_DEBUG_FUNCPTR (gst_dx9screencapsrc_stop);
bs_class->fixate = GST_DEBUG_FUNCPTR (gst_dx9screencapsrc_fixate);
ps_class->create = GST_DEBUG_FUNCPTR (gst_dx9screencapsrc_create);
@ -155,19 +138,21 @@ gst_dx9screencapsrc_class_init (GstDX9ScreenCapSrcClass * klass)
"Height of screen capture area (0 = maximum)",
0, G_MAXINT, 0, G_PARAM_READWRITE));
gst_element_class_add_pad_template (e_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (e_class,
"DirectX 9 screen capture source", "Source/Video", "Captures screen",
"Haakon Sporsheim <hakon.sporsheim@tandberg.com>");
GST_DEBUG_CATEGORY_INIT (dx9screencapsrc_debug, "dx9screencapsrc", 0,
"DirectX 9 screen capture source");
}
static void
gst_dx9screencapsrc_init (GstDX9ScreenCapSrc * src,
GstDX9ScreenCapSrcClass * klass)
gst_dx9screencapsrc_init (GstDX9ScreenCapSrc * src)
{
/* Set src element inital values... */
GstPad *src_pad = GST_BASE_SRC_PAD (src);
gst_pad_set_fixatecaps_function (src_pad, gst_dx9screencapsrc_fixate);
src->frames = 0;
src->surface = NULL;
src->d3d9_device = NULL;
@ -206,6 +191,8 @@ gst_dx9screencapsrc_dispose (GObject * object)
if (!IDirect3D9_Release (g_d3d9))
g_d3d9 = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
@ -268,16 +255,22 @@ gst_dx9screencapsrc_get_property (GObject * object, guint prop_id,
};
}
static void
gst_dx9screencapsrc_fixate (GstPad * pad, GstCaps * caps)
static GstCaps *
gst_dx9screencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps)
{
GstStructure *structure;
caps = gst_caps_make_writable (caps);
structure = gst_caps_get_structure (caps, 0);
gst_structure_fixate_field_nearest_int (structure, "width", 640);
gst_structure_fixate_field_nearest_int (structure, "height", 480);
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
return caps;
}
static gboolean
@ -312,10 +305,11 @@ gst_dx9screencapsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
}
static GstCaps *
gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc)
gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
{
GstDX9ScreenCapSrc *src = GST_DX9SCREENCAPSRC (bsrc);
RECT rect_dst;
GstCaps * caps;
if (src->monitor >= IDirect3D9_GetAdapterCount (g_d3d9) ||
FAILED (IDirect3D9_GetAdapterDisplayMode (g_d3d9, src->monitor,
@ -350,83 +344,20 @@ gst_dx9screencapsrc_get_caps (GstBaseSrc * bsrc)
* the DirectX documentation ARGB is NOT a valid display buffer format,
* but xRGB is.
*/
return gst_dx9screencapsrc_create_caps_from_format (D3DFMT_X8R8G8B8,
rect_dst.right - rect_dst.left, rect_dst.bottom - rect_dst.top);
}
caps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "BGRx",
"width", G_TYPE_INT, rect_dst.right - rect_dst.left,
"height", G_TYPE_INT, rect_dst.bottom - rect_dst.top,
"framerate", GST_TYPE_FRACTION_RANGE, 1, 1, G_MAXINT, 1,
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
static GstCaps *
gst_dx9screencapsrc_create_caps_from_format (D3DFORMAT fmt,
gint width, gint height)
{
gint bpp, depth, endianness;
gint red, green, blue, alpha;
switch (fmt) {
case D3DFMT_A8R8G8B8:
bpp = depth = 32;
endianness = G_BIG_ENDIAN;
alpha = GST_VIDEO_BYTE4_MASK_32_INT;
red = GST_VIDEO_BYTE3_MASK_32_INT;
green = GST_VIDEO_BYTE2_MASK_32_INT;
blue = GST_VIDEO_BYTE1_MASK_32_INT;
break;
case D3DFMT_X8R8G8B8:
bpp = 32;
depth = 24;
endianness = G_BIG_ENDIAN;
alpha = 0;
red = GST_VIDEO_BYTE3_MASK_32_INT;
green = GST_VIDEO_BYTE2_MASK_32_INT;
blue = GST_VIDEO_BYTE1_MASK_32_INT;
break;
case D3DFMT_R8G8B8:
endianness = G_BIG_ENDIAN;
bpp = depth = 24;
alpha = 0;
red = GST_VIDEO_BYTE1_MASK_24_INT;
green = GST_VIDEO_BYTE2_MASK_24_INT;
blue = GST_VIDEO_BYTE3_MASK_24_INT;
break;
case D3DFMT_A1R5G5B5:
bpp = 16;
depth = 15;
endianness = G_BYTE_ORDER;
alpha = GST_VIDEO_ALPHA_MASK_15_INT;
red = GST_VIDEO_COMP1_MASK_15_INT;
green = GST_VIDEO_COMP2_MASK_15_INT;
blue = GST_VIDEO_COMP3_MASK_15_INT;
break;
case D3DFMT_X1R5G5B5:
bpp = 16;
depth = 15;
endianness = G_BYTE_ORDER;
alpha = 0;
red = GST_VIDEO_COMP1_MASK_15_INT;
green = GST_VIDEO_COMP2_MASK_15_INT;
blue = GST_VIDEO_COMP3_MASK_15_INT;
break;
case D3DFMT_R5G6B5:
bpp = depth = 16;
endianness = G_BYTE_ORDER;
alpha = 0;
red = GST_VIDEO_COMP1_MASK_15_INT;
green = GST_VIDEO_COMP2_MASK_15_INT;
blue = GST_VIDEO_COMP3_MASK_15_INT;
break;
default:
return NULL;
if (filter) {
GstCaps * tmp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (caps);
caps = tmp;
}
return gst_caps_new_simple ("video/x-raw-rgb",
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height,
"framerate", GST_TYPE_FRACTION_RANGE, 1, 1, G_MAXINT, 1,
"bpp", G_TYPE_INT, bpp,
"depth", G_TYPE_INT, depth,
"endianness", G_TYPE_INT, endianness,
"alpha_mask", G_TYPE_INT, alpha,
"red_mask", G_TYPE_INT, red,
"green_mask", G_TYPE_INT, green, "blue_mask", G_TYPE_INT, blue, NULL);
return caps;
}
static gboolean
@ -498,7 +429,6 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
{
GstDX9ScreenCapSrc *src = GST_DX9SCREENCAPSRC (push_src);
GstBuffer *new_buf;
GstFlowReturn res;
gint new_buf_size, i;
gint width, height, stride;
GstClock *clock;
@ -507,6 +437,7 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
D3DLOCKED_RECT locked_rect;
LPBYTE p_dst, p_src;
HRESULT hres;
GstMapInfo map;
if (G_UNLIKELY (!src->d3d9_device)) {
GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
@ -534,22 +465,13 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
new_buf_size = width * 4 * height;
if (G_UNLIKELY (src->rate_numerator == 0 && src->frames == 1)) {
GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->frames);
return GST_FLOW_UNEXPECTED;
return GST_FLOW_EOS;
}
GST_LOG_OBJECT (src,
"creating buffer of %d bytes with %dx%d image for frame %d",
new_buf_size, width, height, (gint) src->frames);
res = gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (src),
GST_BUFFER_OFFSET_NONE, new_buf_size,
GST_PAD_CAPS (GST_BASE_SRC_PAD (push_src)), &new_buf);
if (res != GST_FLOW_OK) {
GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
gst_flow_get_name (res));
return res;
}
/* Do screen capture and put it into buffer...
* Aquire front buffer, and lock it
*/
@ -557,7 +479,7 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
IDirect3DDevice9_GetFrontBufferData (src->d3d9_device, 0, src->surface);
if (FAILED (hres)) {
GST_DEBUG_OBJECT (src, "DirectX::GetBackBuffer failed.");
return GST_FLOW_UNEXPECTED;
return GST_FLOW_ERROR;
}
hres =
@ -565,10 +487,12 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY);
if (FAILED (hres)) {
GST_DEBUG_OBJECT (src, "DirectX::LockRect failed.");
return GST_FLOW_UNEXPECTED;
return GST_FLOW_ERROR;
}
p_dst = (LPBYTE) GST_BUFFER_DATA (new_buf);
new_buf = gst_buffer_new_and_alloc (new_buf_size);
gst_buffer_map (new_buf, &map, GST_MAP_WRITE);
p_dst = (LPBYTE) map.data;
p_src = (LPBYTE) locked_rect.pBits;
stride = width * 4;
for (i = 0; i < height; ++i) {
@ -576,6 +500,7 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
p_dst += stride;
p_src += locked_rect.Pitch;
}
gst_buffer_unmap (new_buf, &map);
/* Unlock copy of front buffer */
IDirect3DSurface9_UnlockRect (src->surface);
@ -604,3 +529,4 @@ gst_dx9screencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
*buf = new_buf;
return GST_FLOW_OK;
}

View file

@ -20,9 +20,10 @@
#ifndef __GST_DX9SCREENCAPSRC_H__
#define __GST_DX9SCREENCAPSRC_H__
#include <d3d9.h>
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <d3d9.h>
#include "gstwinscreencap.h"

View file

@ -53,10 +53,10 @@ GST_DEBUG_CATEGORY_STATIC (gdiscreencapsrc_debug);
static GstStaticPadTemplate src_template =
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGR));
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("BGR")));
GST_BOILERPLATE (GstGDIScreenCapSrc, gst_gdiscreencapsrc,
GstPushSrc, GST_TYPE_PUSH_SRC);
#define gst_gdiscreencapsrc_parent_class parent_class
G_DEFINE_TYPE (GstGDIScreenCapSrc, gst_gdiscreencapsrc, GST_TYPE_PUSH_SRC);
enum
{
@ -76,10 +76,10 @@ static void gst_gdiscreencapsrc_set_property (GObject * object, guint prop_id,
static void gst_gdiscreencapsrc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static void gst_gdiscreencapsrc_fixate (GstPad * pad, GstCaps * caps);
static GstCaps * gst_gdiscreencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps);
static gboolean gst_gdiscreencapsrc_set_caps (GstBaseSrc * bsrc,
GstCaps * caps);
static GstCaps *gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc);
static GstCaps *gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter);
static gboolean gst_gdiscreencapsrc_start (GstBaseSrc * bsrc);
static gboolean gst_gdiscreencapsrc_stop (GstBaseSrc * bsrc);
@ -92,26 +92,16 @@ static gboolean gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src,
GstBuffer * buf);
/* Implementation. */
static void
gst_gdiscreencapsrc_base_init (gpointer klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (element_class,
"GDI screen capture source", "Source/Video", "Captures screen",
"Haakon Sporsheim <hakon.sporsheim@tandberg.com>");
}
static void
gst_gdiscreencapsrc_class_init (GstGDIScreenCapSrcClass * klass)
{
GObjectClass *go_class;
GstElementClass *e_class;
GstBaseSrcClass *bs_class;
GstPushSrcClass *ps_class;
go_class = (GObjectClass *) klass;
e_class = (GstElementClass *) klass;
bs_class = (GstBaseSrcClass *) klass;
ps_class = (GstPushSrcClass *) klass;
@ -124,6 +114,7 @@ gst_gdiscreencapsrc_class_init (GstGDIScreenCapSrcClass * klass)
bs_class->set_caps = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_set_caps);
bs_class->start = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_start);
bs_class->stop = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_stop);
bs_class->fixate = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_fixate);
ps_class->create = GST_DEBUG_FUNCPTR (gst_gdiscreencapsrc_create);
@ -155,17 +146,20 @@ gst_gdiscreencapsrc_class_init (GstGDIScreenCapSrcClass * klass)
"Height of screen capture area (0 = maximum)",
0, G_MAXINT, 0, G_PARAM_READWRITE));
gst_element_class_add_pad_template (e_class,
gst_static_pad_template_get (&src_template));
gst_element_class_set_static_metadata (e_class,
"GDI screen capture source", "Source/Video", "Captures screen",
"Haakon Sporsheim <hakon.sporsheim@tandberg.com>");
GST_DEBUG_CATEGORY_INIT (gdiscreencapsrc_debug,
"gdiscreencapsrc", 0, "GDI screen capture source");
}
static void
gst_gdiscreencapsrc_init (GstGDIScreenCapSrc * src,
GstGDIScreenCapSrcClass * klass)
gst_gdiscreencapsrc_init (GstGDIScreenCapSrc * src)
{
/* Set src element inital values... */
GstPad *src_pad = GST_BASE_SRC_PAD (src);
gst_pad_set_fixatecaps_function (src_pad, gst_gdiscreencapsrc_fixate);
src->frames = 0;
src->dibMem = NULL;
@ -197,6 +191,8 @@ gst_gdiscreencapsrc_dispose (GObject * object)
src->hBitmap = (HBITMAP) INVALID_HANDLE_VALUE;
src->memDC = (HDC) INVALID_HANDLE_VALUE;
src->dibMem = NULL;
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
@ -265,16 +261,22 @@ gst_gdiscreencapsrc_get_property (GObject * object, guint prop_id,
};
}
static void
gst_gdiscreencapsrc_fixate (GstPad * pad, GstCaps * caps)
static GstCaps *
gst_gdiscreencapsrc_fixate (GstBaseSrc * bsrc, GstCaps * caps)
{
GstStructure *structure;
caps = gst_caps_make_writable (caps);
structure = gst_caps_get_structure (caps, 0);
gst_structure_fixate_field_nearest_int (structure, "width", 640);
gst_structure_fixate_field_nearest_int (structure, "height", 480);
gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
return caps;
}
static gboolean
@ -285,29 +287,9 @@ gst_gdiscreencapsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
HDC device;
GstStructure *structure;
const GValue *framerate;
gint red_mask, green_mask, blue_mask;
gint bpp;
structure = gst_caps_get_structure (caps, 0);
gst_structure_get_int (structure, "red_mask", &red_mask);
gst_structure_get_int (structure, "green_mask", &green_mask);
gst_structure_get_int (structure, "blue_mask", &blue_mask);
if (blue_mask != GST_VIDEO_BYTE1_MASK_24_INT ||
green_mask != GST_VIDEO_BYTE2_MASK_24_INT ||
red_mask != GST_VIDEO_BYTE3_MASK_24_INT) {
GST_ERROR ("Wrong red_,green_,blue_ mask provided. "
"We only support RGB and BGR");
return FALSE;
}
gst_structure_get_int (structure, "bpp", &bpp);
if (bpp != 24) {
GST_ERROR ("Wrong bpp provided %d. We only support 24 bpp", bpp);
return FALSE;
}
src->src_rect = src->screen_rect;
if (src->capture_w && src->capture_h) {
src->src_rect.left += src->capture_x;
@ -359,10 +341,11 @@ gst_gdiscreencapsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps)
}
static GstCaps *
gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc)
gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
{
GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (bsrc);
RECT rect_dst;
GstCaps *caps;
src->screen_rect = rect_dst = gst_win32_get_monitor_rect (src->monitor);
@ -383,16 +366,20 @@ gst_gdiscreencapsrc_get_caps (GstBaseSrc * bsrc)
(gint) (rect_dst.right - rect_dst.left),
(gint) (rect_dst.bottom - rect_dst.top));
return gst_caps_new_simple ("video/x-raw-rgb",
"bpp", G_TYPE_INT, 24,
"depth", G_TYPE_INT, 24,
"endianness", G_TYPE_INT, G_BIG_ENDIAN,
"red_mask", G_TYPE_INT, GST_VIDEO_BYTE3_MASK_24_INT,
"green_mask", G_TYPE_INT, GST_VIDEO_BYTE2_MASK_24_INT,
"blue_mask", G_TYPE_INT, GST_VIDEO_BYTE1_MASK_24_INT,
caps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "BGR",
"width", G_TYPE_INT, rect_dst.right - rect_dst.left,
"height", G_TYPE_INT, rect_dst.bottom - rect_dst.top,
"framerate", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
"framerate", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1,
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
if (filter) {
GstCaps * tmp = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (caps);
caps = tmp;
}
return caps;
}
static gboolean
@ -437,7 +424,6 @@ gst_gdiscreencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
{
GstGDIScreenCapSrc *src = GST_GDISCREENCAPSRC (push_src);
GstBuffer *new_buf;
GstFlowReturn res;
gint new_buf_size;
GstClock *clock;
GstClockTime time = GST_CLOCK_TIME_NONE;
@ -450,7 +436,7 @@ gst_gdiscreencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
return GST_FLOW_NOT_NEGOTIATED;
} else if (G_UNLIKELY (src->rate_numerator == 0 && src->frames == 1)) {
GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->frames);
return GST_FLOW_UNEXPECTED;
return GST_FLOW_EOS;
}
new_buf_size = GST_ROUND_UP_4 (src->info.bmiHeader.biWidth * 3) *
@ -461,16 +447,7 @@ gst_gdiscreencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
new_buf_size, (gint) src->info.bmiHeader.biWidth,
(gint) (-src->info.bmiHeader.biHeight), (gint) src->frames);
res =
gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (src),
GST_BUFFER_OFFSET_NONE, new_buf_size,
GST_PAD_CAPS (GST_BASE_SRC_PAD (push_src)), &new_buf);
if (res != GST_FLOW_OK) {
GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
gst_flow_get_name (res));
return res;
}
new_buf = gst_buffer_new_and_alloc (new_buf_size);
clock = gst_element_get_clock (GST_ELEMENT (src));
if (clock) {
/* Calculate sync time. */
@ -501,13 +478,12 @@ gst_gdiscreencapsrc_create (GstPushSrc * push_src, GstBuffer ** buf)
/* NONE means forever */
GST_BUFFER_DURATION (new_buf) = GST_CLOCK_TIME_NONE;
}
gst_object_unref (clock);
GST_BUFFER_OFFSET (new_buf) = src->frames;
src->frames++;
GST_BUFFER_OFFSET_END (new_buf) = src->frames;
gst_object_unref (clock);
*buf = new_buf;
return GST_FLOW_OK;
}
@ -518,6 +494,7 @@ gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src, GstBuffer * buf)
HWND capture;
HDC winDC;
gint height, width;
GstMapInfo map;
if (G_UNLIKELY (!src->hBitmap || !src->dibMem))
return FALSE;
@ -556,7 +533,9 @@ gst_gdiscreencapsrc_screen_capture (GstGDIScreenCapSrc * src, GstBuffer * buf)
}
/* Copy DC bits to GST buffer */
memcpy (GST_BUFFER_DATA (buf), src->dibMem, GST_BUFFER_SIZE (buf));
gst_buffer_map (buf, &map, GST_MAP_WRITE);
memcpy (map.data, src->dibMem, map.size);
gst_buffer_unmap (buf, &map);
return TRUE;
}

View file

@ -22,7 +22,6 @@
#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>
#include <gst/interfaces/propertyprobe.h>
#include "gstwinscreencap.h"

View file

@ -20,8 +20,9 @@
#ifndef __GST_WINSCREENCAP_H__
#define __GST_WINSCREENCAP_H__
#include <glib.h>
#include <windows.h>
#include <glib.h>
#include <gst/gst.h>
G_BEGIN_DECLS