From 6a47f6f594740e28dcf9176fb88260114a94f8b3 Mon Sep 17 00:00:00 2001 From: Lasse Laukkanen Date: Wed, 27 May 2009 11:33:01 +0300 Subject: camerabin: preview image sending optimization * decouple image capturing from image post-processing and encoding * post image-captured message after image is captured * post preview-image message with snapshot of captured image --- gst/camerabin/camerabinimage.c | 72 +++++++----------------------------------- 1 file changed, 12 insertions(+), 60 deletions(-) (limited to 'gst/camerabin/camerabinimage.c') diff --git a/gst/camerabin/camerabinimage.c b/gst/camerabin/camerabinimage.c index 99bf20b6..338d2e3d 100644 --- a/gst/camerabin/camerabinimage.c +++ b/gst/camerabin/camerabinimage.c @@ -30,17 +30,13 @@ * * *----------------------------------------------------------------------------- - * (src0) -> queue -> - * -> [post proc] -> tee < - * (src1) -> imageenc -> metadatamuxer -> filesink + * + * -> [post proc] -> csp -> imageenc -> metadatamuxer -> filesink + * *----------------------------------------------------------------------------- * * * - * The property of elements are: - * - * queue - "max-size-buffers", 1, "leaky", 2, - * * The image bin opens file for image writing in READY to PAUSED state change. * The image bin closes the file in PAUSED to READY state change. * @@ -150,24 +146,16 @@ gst_camerabin_image_init (GstCameraBinImage * img, { img->filename = g_string_new (""); - img->pad_tee_enc = NULL; - img->pad_tee_view = NULL; - img->post = NULL; - img->tee = NULL; img->enc = NULL; img->user_enc = NULL; img->meta_mux = NULL; img->sink = NULL; - img->queue = NULL; /* Create src and sink ghost pads */ img->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK); gst_element_add_pad (GST_ELEMENT (img), img->sinkpad); - img->srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC); - gst_element_add_pad (GST_ELEMENT (img), img->srcpad); - img->elements_created = FALSE; } @@ -378,17 +366,17 @@ done: * Use gst_camerabin_image_destroy_elements to release these resources. * * Image bin: - * img->sinkpad ! [ post process !] tee name=t0 ! encoder ! metadata ! filesink - * t0. ! queue ! img->srcpad + * img->sinkpad ! [ post process !] csp ! encoder ! metadata ! filesink * * Returns: %TRUE if succeeded or FALSE if failed */ static gboolean gst_camerabin_image_create_elements (GstCameraBinImage * img) { - GstPad *sinkpad = NULL, *img_sinkpad = NULL, *img_srcpad = NULL; + GstPad *sinkpad = NULL, *img_sinkpad = NULL; gboolean ret = FALSE; GstBin *imgbin = NULL; + GstElement *csp = NULL; g_return_val_if_fail (img != NULL, FALSE); @@ -412,23 +400,18 @@ gst_camerabin_image_create_elements (GstCameraBinImage * img) img_sinkpad = gst_element_get_static_pad (img->post, "sink"); } - /* Create tee */ - if (!(img->tee = gst_camerabin_create_and_add_element (imgbin, "tee"))) { + /* Add colorspace converter */ + if (!(csp = + gst_camerabin_create_and_add_element (imgbin, "ffmpegcolorspace"))) { goto done; } /* Set up sink ghost pad for img bin */ if (!img_sinkpad) { - img_sinkpad = gst_element_get_static_pad (img->tee, "sink"); + img_sinkpad = gst_element_get_static_pad (csp, "sink"); } gst_ghost_pad_set_target (GST_GHOST_PAD (img->sinkpad), img_sinkpad); - /* Add colorspace converter */ - img->pad_tee_enc = gst_element_get_request_pad (img->tee, "src%d"); - if (!gst_camerabin_create_and_add_element (imgbin, "ffmpegcolorspace")) { - goto done; - } - /* Create image encoder */ if (img->user_enc) { img->enc = img->user_enc; @@ -461,33 +444,14 @@ gst_camerabin_image_create_elements (GstCameraBinImage * img) goto done; } - /* Create queue element leading to view finder, attaches it to the tee */ - img->pad_tee_view = gst_element_get_request_pad (img->tee, "src%d"); - if (!(img->queue = gst_camerabin_create_and_add_element (imgbin, "queue"))) { - goto done; - } - /* Set properties */ g_object_set (G_OBJECT (img->sink), "location", img->filename->str, NULL); g_object_set (G_OBJECT (img->sink), "async", FALSE, NULL); - g_object_set (G_OBJECT (img->queue), "max-size-buffers", 1, "leaky", 2, NULL); - - /* Set up src ghost pad for img bin */ - img_srcpad = gst_element_get_static_pad (img->queue, "src"); - gst_ghost_pad_set_target (GST_GHOST_PAD (img->srcpad), img_srcpad); - - /* Never let image bin eos events reach view finder */ - gst_pad_add_event_probe (img->srcpad, - G_CALLBACK (gst_camerabin_drop_eos_probe), img); - ret = TRUE; done: - if (img_srcpad) { - gst_object_unref (img_srcpad); - } if (img_sinkpad) { gst_object_unref (img_sinkpad); } @@ -511,26 +475,14 @@ static void gst_camerabin_image_destroy_elements (GstCameraBinImage * img) { GST_LOG ("destroying img elements"); - if (img->pad_tee_enc) { - gst_element_release_request_pad (img->tee, img->pad_tee_enc); - img->pad_tee_enc = NULL; - } - - if (img->pad_tee_view) { - gst_element_release_request_pad (img->tee, img->pad_tee_view); - img->pad_tee_view = NULL; - } gst_ghost_pad_set_target (GST_GHOST_PAD (img->sinkpad), NULL); - gst_ghost_pad_set_target (GST_GHOST_PAD (img->srcpad), NULL); gst_camerabin_remove_elements_from_bin (GST_BIN (img)); - img->tee = NULL; img->enc = NULL; img->meta_mux = NULL; img->sink = NULL; - img->queue = NULL; img->elements_created = FALSE; } @@ -538,7 +490,7 @@ gst_camerabin_image_destroy_elements (GstCameraBinImage * img) void gst_camerabin_image_set_encoder (GstCameraBinImage * img, GstElement * encoder) { - GST_DEBUG ("setting encoder %" GST_PTR_FORMAT, encoder); + GST_DEBUG ("setting image encoder %" GST_PTR_FORMAT, encoder); if (img->user_enc) gst_object_unref (img->user_enc); if (encoder) @@ -551,7 +503,7 @@ void gst_camerabin_image_set_postproc (GstCameraBinImage * img, GstElement * postproc) { - GST_DEBUG ("setting post processing element %" GST_PTR_FORMAT, postproc); + GST_DEBUG ("setting image postprocessing element %" GST_PTR_FORMAT, postproc); if (img->post) gst_object_unref (img->post); if (postproc) -- cgit v1.2.1