From 0a831613a8adb4cb2f3de32980913493dd5accc8 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Sun, 29 Jul 2012 00:53:29 -0300 Subject: [PATCH] camerabin: update preview buffer pushing need to pass a GstSample to the utilitary preview buffer post functions as a GstBuffer doesn't have caps anymore. The GstSample has the GstCaps and it is used to inform the preview's pipeline about the format of the input, before it gets converted to the user's requested output format. --- gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c | 4 ++-- gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h | 2 +- .../gst/basecamerabinsrc/gstcamerabinpreview.c | 11 ++++++----- .../gst/basecamerabinsrc/gstcamerabinpreview.h | 2 +- gst/camerabin2/gstwrappercamerabinsrc.c | 16 ++++++++++++++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c index 199bf081dd..8a584b55b7 100644 --- a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c +++ b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.c @@ -556,10 +556,10 @@ gst_base_camera_src_init (GstBaseCameraSrc * self) } void -gst_base_camera_src_post_preview (GstBaseCameraSrc * self, GstBuffer * buf) +gst_base_camera_src_post_preview (GstBaseCameraSrc * self, GstSample * sample) { if (self->post_preview) { - gst_camerabin_preview_pipeline_post (self->preview_pipeline, buf); + gst_camerabin_preview_pipeline_post (self->preview_pipeline, sample); } else { GST_DEBUG_OBJECT (self, "Previews not enabled, not posting"); } diff --git a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h index 31e077f983..d4979f56fa 100644 --- a/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h +++ b/gst-libs/gst/basecamerabinsrc/gstbasecamerasrc.h @@ -136,7 +136,7 @@ void gst_base_camera_src_setup_preview (GstBaseCameraSrc * self, GstCaps * previ void gst_base_camera_src_finish_capture (GstBaseCameraSrc *self); -void gst_base_camera_src_post_preview (GstBaseCameraSrc *self, GstBuffer * buf); +void gst_base_camera_src_post_preview (GstBaseCameraSrc *self, GstSample * sample); // XXX add methods to get/set img capture and vid capture caps.. #endif /* __GST_BASE_CAMERA_SRC_H__ */ diff --git a/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.c b/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.c index e4b95b897a..d1c670bddb 100644 --- a/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.c +++ b/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.c @@ -249,20 +249,20 @@ gst_camerabin_destroy_preview_pipeline (GstCameraBinPreviewPipelineData * /** * gst_camerabin_preview_pipeline_post: * @preview: the #GstCameraBinPreviewPipelineData - * @buffer: the buffer to be posted as a preview + * @sample: the sample to be posted as a preview * - * Converts the @buffer to the desired format and posts the preview + * Converts the @sample to the desired format and posts the preview * message to the bus. * * Returns: %TRUE on success */ gboolean gst_camerabin_preview_pipeline_post (GstCameraBinPreviewPipelineData * preview, - GstBuffer * buffer) + GstSample * sample) { g_return_val_if_fail (preview != NULL, FALSE); g_return_val_if_fail (preview->pipeline != NULL, FALSE); - g_return_val_if_fail (buffer, FALSE); + g_return_val_if_fail (sample, FALSE); g_mutex_lock (&preview->processing_lock); g_return_val_if_fail (preview->pipeline != NULL, FALSE); @@ -277,8 +277,9 @@ gst_camerabin_preview_pipeline_post (GstCameraBinPreviewPipelineData * preview, preview->processing++; + g_object_set (preview->appsrc, "caps", gst_sample_get_caps (sample), NULL); gst_app_src_push_buffer ((GstAppSrc *) preview->appsrc, - gst_buffer_ref (buffer)); + gst_buffer_ref (gst_sample_get_buffer (sample))); g_mutex_unlock (&preview->processing_lock); diff --git a/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h b/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h index fba274cbca..6627cf66c7 100644 --- a/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h +++ b/gst-libs/gst/basecamerabinsrc/gstcamerabinpreview.h @@ -49,7 +49,7 @@ typedef struct GstCameraBinPreviewPipelineData *gst_camerabin_create_preview_pipeline (GstElement * element, GstElement * filter); void gst_camerabin_destroy_preview_pipeline (GstCameraBinPreviewPipelineData * preview); -gboolean gst_camerabin_preview_pipeline_post (GstCameraBinPreviewPipelineData * preview, GstBuffer * buffer); +gboolean gst_camerabin_preview_pipeline_post (GstCameraBinPreviewPipelineData * preview, GstSample * sample); void gst_camerabin_preview_set_caps (GstCameraBinPreviewPipelineData * preview, GstCaps * caps); gboolean gst_camerabin_preview_set_filter (GstCameraBinPreviewPipelineData * preview, GstElement * filter); diff --git a/gst/camerabin2/gstwrappercamerabinsrc.c b/gst/camerabin2/gstwrappercamerabinsrc.c index 1e3d3989a7..06d60b5891 100644 --- a/gst/camerabin2/gstwrappercamerabinsrc.c +++ b/gst/camerabin2/gstwrappercamerabinsrc.c @@ -205,6 +205,8 @@ gst_wrapper_camera_bin_src_imgsrc_probe (GstPad * pad, GstPadProbeInfo * info, g_mutex_lock (&camerasrc->capturing_mutex); if (self->image_capture_count > 0) { + GstSample *sample; + GstCaps *caps; ret = GST_PAD_PROBE_OK; self->image_capture_count--; @@ -212,7 +214,11 @@ gst_wrapper_camera_bin_src_imgsrc_probe (GstPad * pad, GstPadProbeInfo * info, /* TODO This can likely be optimized if the viewfinder caps is the same as * the preview caps, avoiding another scaling of the same buffer. */ GST_DEBUG_OBJECT (self, "Posting preview for image"); - gst_base_camera_src_post_preview (camerasrc, buffer); + caps = gst_pad_get_current_caps (pad); + sample = gst_sample_new (buffer, caps, NULL, NULL); + gst_base_camera_src_post_preview (camerasrc, sample); + gst_caps_unref (caps); + gst_sample_unref (sample); if (self->image_capture_count == 0) { gst_base_camera_src_finish_capture (camerasrc); @@ -251,6 +257,8 @@ gst_wrapper_camera_bin_src_vidsrc_probe (GstPad * pad, GstPadProbeInfo * info, } else if (self->video_rec_status == GST_VIDEO_RECORDING_STATUS_STARTING) { GstClockTime ts; GstSegment segment; + GstCaps *caps; + GstSample *sample; GST_DEBUG_OBJECT (self, "Starting video recording"); self->video_rec_status = GST_VIDEO_RECORDING_STATUS_RUNNING; @@ -264,7 +272,11 @@ gst_wrapper_camera_bin_src_vidsrc_probe (GstPad * pad, GstPadProbeInfo * info, /* post preview */ GST_DEBUG_OBJECT (self, "Posting preview for video"); - gst_base_camera_src_post_preview (camerasrc, buffer); + caps = gst_pad_get_current_caps (pad); + sample = gst_sample_new (buffer, caps, NULL, NULL); + gst_base_camera_src_post_preview (camerasrc, sample); + gst_caps_unref (caps); + gst_sample_unref (sample); ret = GST_PAD_PROBE_OK; } else if (self->video_rec_status == GST_VIDEO_RECORDING_STATUS_FINISHING) {