camerabin2: add imagecapturebin::image-muxer property

This commit is contained in:
Teemu Katajisto 2010-12-13 16:28:58 +02:00 committed by Thiago Santos
parent 87e0cbff38
commit 89142163b1
3 changed files with 100 additions and 6 deletions

View file

@ -44,7 +44,8 @@ enum
{
PROP_0,
PROP_LOCATION,
PROP_ENCODER
PROP_ENCODER,
PROP_MUXER
};
#define DEFAULT_LOCATION "img_%d"
@ -86,6 +87,22 @@ gst_image_capture_bin_set_encoder (GstImageCaptureBin * imagebin,
imagebin->user_encoder = encoder;
}
static void
gst_image_capture_bin_set_muxer (GstImageCaptureBin * imagebin,
GstElement * muxer)
{
GST_DEBUG_OBJECT (GST_OBJECT (imagebin),
"Setting image muxer %" GST_PTR_FORMAT, muxer);
if (imagebin->user_muxer)
g_object_unref (imagebin->user_muxer);
if (muxer)
g_object_ref (muxer);
imagebin->user_muxer = muxer;
}
static void
gst_image_capture_bin_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
@ -103,6 +120,9 @@ gst_image_capture_bin_set_property (GObject * object, guint prop_id,
case PROP_ENCODER:
gst_image_capture_bin_set_encoder (imagebin, g_value_get_object (value));
break;
case PROP_MUXER:
gst_image_capture_bin_set_muxer (imagebin, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -122,6 +142,9 @@ gst_image_capture_bin_get_property (GObject * object, guint prop_id,
case PROP_ENCODER:
g_value_set_object (value, imagebin->encoder);
break;
case PROP_MUXER:
g_value_set_object (value, imagebin->muxer);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -177,6 +200,11 @@ gst_image_capture_bin_class_init (GstImageCaptureBinClass * klass)
g_param_spec_object ("image-encoder", "Image encoder",
"Image encoder GStreamer element (default is jpegenc)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_MUXER,
g_param_spec_object ("image-muxer", "Image muxer",
"Image muxer GStreamer element (default is jifmux)",
GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
static void
@ -225,10 +253,18 @@ gst_image_capture_bin_create_elements (GstImageCaptureBin * imagebin)
goto error;
}
imagebin->muxer =
gst_camerabin_create_and_add_element (GST_BIN (imagebin), DEFAULT_MUXER);
if (!imagebin->muxer)
goto error;
if (imagebin->user_muxer) {
imagebin->muxer = imagebin->user_muxer;
if (!gst_camerabin_add_element (GST_BIN (imagebin), imagebin->muxer)) {
goto error;
}
} else {
imagebin->muxer =
gst_camerabin_create_and_add_element (GST_BIN (imagebin),
DEFAULT_MUXER);
if (!imagebin->muxer)
goto error;
}
imagebin->sink =
gst_camerabin_create_and_add_element (GST_BIN (imagebin), DEFAULT_SINK);

View file

@ -39,12 +39,13 @@ struct _GstImageCaptureBin
GstPad *ghostpad;
GstElement *sink;
GstElement *muxer;
/* props */
gchar *location;
GstElement *encoder;
GstElement *user_encoder;
GstElement *muxer;
GstElement *user_muxer;
gboolean elements_created;
};

View file

@ -172,6 +172,62 @@ GST_START_TEST (test_setting_encoder)
GST_END_TEST;
GST_START_TEST (test_setting_muxer)
{
GstImageCaptureBinTestContext ctx;
GstBus *bus;
GstMessage *msg;
GstElement *encoder;
gchar *test_file_name;
gint i;
gstimagecapturebin_init_test_context (&ctx, N_BUFFERS);
bus = gst_element_get_bus (ctx.pipe);
test_file_name = make_test_file_name ();
g_object_set (ctx.icbin, "location", test_file_name, NULL);
encoder = gst_element_factory_make ("pngenc", NULL);
g_object_set (ctx.icbin, "image-encoder", encoder, NULL);
encoder = gst_element_factory_make ("identity", NULL);
g_object_set (ctx.icbin, "image-muxer", encoder, NULL);
fail_if (gst_element_set_state (ctx.pipe, GST_STATE_PLAYING) ==
GST_STATE_CHANGE_FAILURE);
msg = gst_bus_timed_pop_filtered (bus, GST_SECOND * 10,
GST_MESSAGE_EOS | GST_MESSAGE_ERROR);
fail_unless (msg != NULL);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
/* check there are N_BUFFERS files */
for (i = 0; i < N_BUFFERS; i++) {
gchar *filename;
FILE *f;
filename = g_strdup_printf (test_file_name, i);
fail_unless (g_file_test (filename, G_FILE_TEST_EXISTS));
fail_unless (g_file_test (filename, G_FILE_TEST_IS_REGULAR));
fail_if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK));
/* check the file isn't empty */
f = fopen (filename, "r");
fseek (f, 0, SEEK_END);
fail_unless (ftell (f) > 0);
fclose (f);
g_free (filename);
}
gstimagecapturebin_unset_test_context (&ctx);
gst_object_unref (bus);
g_free (test_file_name);
}
GST_END_TEST;
static Suite *
imagecapturebin_suite (void)
{
@ -181,6 +237,7 @@ imagecapturebin_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_simple_capture);
tcase_add_test (tc_chain, test_setting_encoder);
tcase_add_test (tc_chain, test_setting_muxer);
return s;
}