Skip to content

Commit

Permalink
Merge pull request #106 from deeprave:set-video-format-support
Browse files Browse the repository at this point in the history
Set video format support
  • Loading branch information
mithro committed Jan 11, 2015
2 parents 27a2d40 + 1775caf commit 0f54bcb
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ imgurbash.sh.*
/gst-plugins-good
/gst-plugins-bad
/gst-plugins-base
/gst-switch.sublime-*
/libvpx
/html
/htmlcov
Expand Down
2 changes: 1 addition & 1 deletion run-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

killall gst-switch-srv || true
sleep 2
./tools/gst-switch-srv -r &
./tools/gst-switch-srv -f debug -r &
sleep 2
./tools/gst-switch-ui &
sleep 2
Expand Down
31 changes: 16 additions & 15 deletions tests/unit/test_gstswitchopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
static void
test_strings_good (void)
{
g_assert_cmpint (parse_format ("debug"), ==, 0);
g_assert_cmpint (parse_format ("pal"), ==, 0);
g_assert_cmpint (parse_format ("720p60"), ==, 0);
g_assert_cmpint (parse_format ("1024x768@60"), ==, 0);
g_assert_cmpint (parse_format ("VGA@60"), ==, 0);
g_assert_cmpint (parse_format ("4k@60"), ==, 0);
g_assert_cmpint (parse_format ("debug", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format ("pal", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format ("720p60", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format ("1024x768@60", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format ("VGA@60", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format ("4k@60", NULL, NULL), ==, 0);
g_assert_cmpint (parse_format
("video/x-raw,height=400,width=500,framerate=25/1"), ==, 0);
("video/x-raw,height=400,width=500,framerate=25/1", NULL, NULL), ==, 0);
}

static void
test_strings_bad (void)
{
g_assert_cmpint (parse_format
("video/x-raw,height=[400,800],width=500,framerate=25/1"), ==, -1);
g_assert_cmpint (parse_format ("720p@75"), ==, -1);
g_assert_cmpint (parse_format ("bad-format-string"), ==, -1);
("video/x-raw,height=[400,800],width=500,framerate=25/1", NULL, NULL), ==,
-1);
g_assert_cmpint (parse_format ("720p@75", NULL, NULL), ==, -1);
g_assert_cmpint (parse_format ("bad-format-string", NULL, NULL), ==, -1);
g_assert_cmpint (parse_format
("video/x-raw,height=10,width=500,framerate=25/1"), ==, -1);
("video/x-raw,height=10,width=500,framerate=25/1", NULL, NULL), ==, -1);
g_assert_cmpint (parse_format
("video/x-raw,height=400,width=10,framerate=25/1"), ==, -1);
("video/x-raw,height=400,width=10,framerate=25/1", NULL, NULL), ==, -1);
g_assert_cmpint (parse_format
("video/x-raw,height=400,width=10,framerate=1001/1"), ==, -1);
// the following actually works but it shouldn't
// g_assert_cmpint (parse_format("pal@75"), ==, -1);
("video/x-raw,height=400,width=10,framerate=1001/1", NULL, NULL), ==, -1);
// @FIXME the following actually works but it shouldn't
// g_assert_cmpint (parse_format("pal@75", NULL, NULL), ==, -1);
}

int
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif

gst_switch_srv_SOURCES = gstworker.c gstswitchserver.c gstcase.c \
gstcomposite.c gstswitchcontroller.c gstrecorder.c \
gio/gsocketinputstream.c
gio/gsocketinputstream.c gstswitchopts.c
gst_switch_srv_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GCOV_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) $(AM_CFLAGS) -DLOG_PREFIX="\"gst-switch-srv\""
gst_switch_srv_LDFLAGS = $(GCOV_LFLAGS) $(GST_LIBS) $(GST_BASE_LIBS) \
Expand Down
12 changes: 6 additions & 6 deletions tools/gstcase.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,42 +505,42 @@ gst_case_class_init (GstCaseClass * klass)
g_param_spec_uint ("width", "Width",
"Output width", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
gst_composite_default_width (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_uint ("height", "Height",
"Output height", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
gst_composite_default_height (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_A_WIDTH,
g_param_spec_uint ("awidth", "A Width",
"Channel A width", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
gst_composite_default_width (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_A_HEIGHT,
g_param_spec_uint ("aheight", "A Height",
"Channel A height", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
gst_composite_default_height (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_B_WIDTH,
g_param_spec_uint ("bwidth", "B Width",
"Channel B width", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
gst_composite_default_width (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_B_HEIGHT,
g_param_spec_uint ("bheight", "B Height",
"Channel B height", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
gst_composite_default_height (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

worker_class->prepare = (GstWorkerPrepareFunc) gst_case_prepare;
Expand Down
111 changes: 97 additions & 14 deletions tools/gstcomposite.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ gst_composite_set_mode (GstComposite * composite, GstCompositeMode mode)
return;
}

composite->width = GST_SWITCH_COMPOSITE_DEFAULT_WIDTH;
composite->height = GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT;
composite->width = gst_composite_default_width ();
composite->height = gst_composite_default_height ();

switch ((composite->mode = mode)) {
case COMPOSE_MODE_NONE:
Expand Down Expand Up @@ -794,6 +794,89 @@ gst_composite_null (GstComposite * composite)
return composite->deprecated ? GST_WORKER_NR_END : GST_WORKER_NR_REPLAY;
}


/* gst_caps_get_value:
* - the missing API
* iterate the gst_structure in the given caps to return a specified field vaue
*/
static gboolean
gst_caps_get_value (GstCaps * caps, const gchar * field, GValue * value)
{
guint i;
GstStructure *structure;
for (i = 0; (structure = gst_caps_get_structure (caps, i)) != NULL; i++) {
const GValue *svalue = gst_structure_get_value (structure, field);
if (svalue != NULL) {
g_value_copy (svalue, value);
return TRUE;
}
}
return FALSE;
}

static gint
gst_composite_get_caps_int_value (const gchar * fieldname)
{
GstCaps *caps = gst_switch_server_getcaps ();
g_assert (caps != NULL && !gst_caps_is_empty (caps));
GValue value = G_VALUE_INIT;
g_value_init (&value, G_TYPE_INT);
gst_caps_get_value (caps, fieldname, &value);
return g_value_get_int (&value);
}

/* cache these so we don't need to do the above every time */
static gint cached_default_width = -1;
static gint cached_default_height = -1;

/* gst_composite_defaut_width:
*
* @return default width based on current video caps
*/
gint
gst_composite_default_width ()
{
if (cached_default_width == -1)
cached_default_width = gst_composite_get_caps_int_value ("width");
return cached_default_width;
}

/* gst_composite_defaut_height:
*
* @return default height based on current video caps
*/
gint
gst_composite_default_height ()
{
if (cached_default_height == -1)
cached_default_height = gst_composite_get_caps_int_value ("height");
return cached_default_height;
}

/* gst_composite_min_pip_width:
*
* @param pip_w desired width of PIP
* @return enforce minimum width of PIP
*/
gint
gst_check_composite_min_pip_width (gint pip_w)
{
gint min_width = gst_composite_default_width () / 4;
return pip_w < min_width ? min_width : pip_w;
}

/* gst_composite_min_pip_height:
*
* @param pip_w desired height of PIP
* @return enforce minimum height of PIP
*/
gint
gst_check_composite_min_pip_height (gint pip_h)
{
gint min_height = gst_composite_default_height () / 3;
return pip_h < min_height ? min_height : pip_h;
}

/**
* gst_composite_adjust_pip:
* @param composite The GstComposite instance
Expand Down Expand Up @@ -1060,15 +1143,15 @@ gst_composite_class_init (GstCompositeClass * klass)
g_param_spec_uint ("awidth", "A Width",
"Channel A frame width",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_composite_default_width
(), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_A_HEIGHT,
g_param_spec_uint ("aheight", "A Height",
"Channel A frame height",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_composite_default_height
(), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_B_X,
g_param_spec_uint ("bx", "B xpos",
Expand All @@ -1084,31 +1167,31 @@ gst_composite_class_init (GstCompositeClass * klass)
g_param_spec_uint ("bwidth", "B Width",
"Channel B frame width",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_composite_default_width
(), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_B_HEIGHT,
g_param_spec_uint ("bheight", "B Height",
"Channel B frame height",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_composite_default_height
(), G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_WIDTH,
g_param_spec_uint ("width",
"Composite Width",
"Output frame width", 1,
G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gst_composite_default_width
(), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_uint ("height",
"Composite Height",
"Output frame height",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gst_composite_default_height
(), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));

worker_class->alive = (GstWorkerAliveFunc) gst_composite_alive;
worker_class->null = (GstWorkerNullFunc) gst_composite_null;
Expand Down
27 changes: 16 additions & 11 deletions tools/gstcomposite.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
#define GST_IS_COMPOSITE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GST_TYPE_COMPOSITE))
#define GST_IS_COMPOSITE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), GST_TYPE_COMPOSITE))

#if ENABLE_LOW_RESOLUTION
#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH LOW_RES_W /* 640 */
#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT LOW_RES_H /* 480 */
#define GST_SWITCH_COMPOSITE_MIN_PIP_W 13
#define GST_SWITCH_COMPOSITE_MIN_PIP_H 7
#else
#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH 1280
#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT 720
#define GST_SWITCH_COMPOSITE_MIN_PIP_W 320
#define GST_SWITCH_COMPOSITE_MIN_PIP_H 240
#endif
//#if ENABLE_LOW_RESOLUTION
//#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH LOW_RES_W /* 640 */
//#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT LOW_RES_H /* 480 */
//#define GST_SWITCH_COMPOSITE_MIN_PIP_W 13
//#define GST_SWITCH_COMPOSITE_MIN_PIP_H 7
//#else
//#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH 1280
//#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT 720
//#define GST_SWITCH_COMPOSITE_MIN_PIP_W 320
//#define GST_SWITCH_COMPOSITE_MIN_PIP_H 240
//#endif

#define GST_SWITCH_FACEDETECT_FRAME_WIDTH 150
#define GST_SWITCH_FACEDETECT_FRAME_HEIGHT 100
Expand Down Expand Up @@ -154,5 +154,10 @@ struct _GstCompositeClass
GType gst_composite_get_type (void);
gboolean gst_composite_adjust_pip (GstComposite * composite,
gint x, gint y, gint w, gint h);
gint gst_composite_default_width ();
gint gst_composite_default_height ();
gint gst_check_composite_min_pip_width (gint pip_w);
gint gst_check_composite_min_pip_height (gint pip_h);


#endif //__GST_COMPOSITE_H__
7 changes: 4 additions & 3 deletions tools/gstrecorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ gst_recorder_new_filename (const gchar * filename)
static GString *
gst_recorder_get_pipeline_string (GstRecorder * rec)
{
const gchar *filename = gst_recorder_new_filename (opts.record_filename);
const gchar *filename =
gst_recorder_new_filename (gst_switch_server_get_record_filename ());
GString *desc;

//INFO ("Recording to %s and port %d", filename, rec->sink_port);
Expand Down Expand Up @@ -423,15 +424,15 @@ gst_recorder_class_init (GstRecorderClass * klass)
g_param_spec_uint ("width", "Input Width",
"Input video frame width",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_WIDTH,
gst_composite_default_width (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (object_class, PROP_HEIGHT,
g_param_spec_uint ("height",
"Input Height",
"Input video frame height",
1, G_MAXINT,
GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT,
gst_composite_default_height (),
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

worker_class->prepare = (GstWorkerPrepareFunc) gst_recorder_prepare;
Expand Down
9 changes: 9 additions & 0 deletions tools/gstswitchcapture.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
#include <stdlib.h>
#include "../logutils.h"

/* @FIXME: moved from gstcomposite which now determines these dynamically */
#if ENABLE_LOW_RESOLUTION
#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH LOW_RES_W /* 640 */
#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT LOW_RES_H /* 480 */
#else
#define GST_SWITCH_COMPOSITE_DEFAULT_WIDTH 1280
#define GST_SWITCH_COMPOSITE_DEFAULT_HEIGHT 720
#endif

#define GST_TYPE_SWITCH_CAPTURE_WORKER (gst_switch_capture_worker_get_type ())
#define GST_SWITCH_CAPTURE_WORKER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GST_TYPE_SWITCH_CAPTURE_WORKER, GstSwitchCaptureWorker))
#define GST_SWITCH_CAPTURE_WORKER_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), GST_TYPE_SWITCH_CAPTURE_WORKER, GstSwitchCaptureWorkerClass))
Expand Down

0 comments on commit 0f54bcb

Please sign in to comment.