mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-05 10:12:20 +00:00
camerabin2: Rename variables
Use better name for the variables, making the code clearer. Also keep a ref for some internal elements to avoid fetching them by name when needed later.
This commit is contained in:
parent
201e9ac221
commit
adc3cdc6aa
2 changed files with 99 additions and 86 deletions
|
@ -28,14 +28,14 @@
|
||||||
/*
|
/*
|
||||||
* Detail Topics:
|
* Detail Topics:
|
||||||
*
|
*
|
||||||
* videorecordingbin state management (for now on vidbin)
|
* videorecordingbin state management (for now on videobin)
|
||||||
* - The problem: keeping vidbin state in sync with camerabin will make it
|
* - The problem: keeping videobin state in sync with camerabin will make it
|
||||||
* go to playing when it might not be used, causing its internal
|
* go to playing when it might not be used, causing its internal
|
||||||
* filesink to open a file that might be left blank.
|
* filesink to open a file that might be left blank.
|
||||||
* - The solution: vidbin state is set to locked upon its creation and camerabin
|
* - The solution: videobin state is set to locked upon its creation and camerabin
|
||||||
* registers itself on the notify::ready-for-capture of the src.
|
* registers itself on the notify::ready-for-capture of the src.
|
||||||
* Whenever the src readyness goes to FALSE it means a new
|
* Whenever the src readyness goes to FALSE it means a new
|
||||||
* capture is starting. If we are on video mode, the vidbin's
|
* capture is starting. If we are on video mode, the videobin's
|
||||||
* state is set to NULL and then PLAYING (in between this we
|
* state is set to NULL and then PLAYING (in between this we
|
||||||
* have room to set the destination filename).
|
* have room to set the destination filename).
|
||||||
* There is no problem to leave it on playing after an EOS, so
|
* There is no problem to leave it on playing after an EOS, so
|
||||||
|
@ -176,16 +176,17 @@ gst_camera_bin_src_notify_readyforcapture (GObject * obj, GParamSpec * pspec,
|
||||||
|
|
||||||
/* a video recording is about to start, we reset the videobin to clear eos/flushing state
|
/* a video recording is about to start, we reset the videobin to clear eos/flushing state
|
||||||
* also need to clean the queue ! capsfilter before it */
|
* also need to clean the queue ! capsfilter before it */
|
||||||
gst_element_set_state (camera->vidbin, GST_STATE_NULL);
|
gst_element_set_state (camera->videobin, GST_STATE_NULL);
|
||||||
gst_element_set_state (camera->vid_queue, GST_STATE_NULL);
|
gst_element_set_state (camera->videobin_queue, GST_STATE_NULL);
|
||||||
gst_element_set_state (camera->vid_capsfilter, GST_STATE_NULL);
|
gst_element_set_state (camera->videobin_capsfilter, GST_STATE_NULL);
|
||||||
location = g_strdup_printf (camera->vid_location, camera->vid_index++);
|
location =
|
||||||
GST_DEBUG_OBJECT (camera, "Switching vidbin location to %s", location);
|
g_strdup_printf (camera->video_location, camera->video_index++);
|
||||||
g_object_set (camera->vidbin, "location", location, NULL);
|
GST_DEBUG_OBJECT (camera, "Switching videobin location to %s", location);
|
||||||
|
g_object_set (camera->videobin, "location", location, NULL);
|
||||||
g_free (location);
|
g_free (location);
|
||||||
gst_element_set_state (camera->vidbin, GST_STATE_PLAYING);
|
gst_element_set_state (camera->videobin, GST_STATE_PLAYING);
|
||||||
gst_element_set_state (camera->vid_capsfilter, GST_STATE_PLAYING);
|
gst_element_set_state (camera->videobin_capsfilter, GST_STATE_PLAYING);
|
||||||
gst_element_set_state (camera->vid_queue, GST_STATE_PLAYING);
|
gst_element_set_state (camera->videobin_queue, GST_STATE_PLAYING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,11 +196,9 @@ gst_camera_bin_dispose (GObject * object)
|
||||||
{
|
{
|
||||||
GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
|
GstCameraBin *camerabin = GST_CAMERA_BIN_CAST (object);
|
||||||
|
|
||||||
if (camerabin->vf_bin)
|
|
||||||
gst_object_unref (camerabin->vf_bin);
|
|
||||||
|
|
||||||
g_free (camerabin->img_location);
|
g_free (camerabin->image_location);
|
||||||
g_free (camerabin->vid_location);
|
g_free (camerabin->video_location);
|
||||||
|
|
||||||
if (camerabin->src_capture_notify_id)
|
if (camerabin->src_capture_notify_id)
|
||||||
g_signal_handler_disconnect (camerabin->src,
|
g_signal_handler_disconnect (camerabin->src,
|
||||||
|
@ -207,15 +206,27 @@ gst_camera_bin_dispose (GObject * object)
|
||||||
if (camerabin->src)
|
if (camerabin->src)
|
||||||
gst_object_unref (camerabin->src);
|
gst_object_unref (camerabin->src);
|
||||||
|
|
||||||
if (camerabin->vidbin)
|
if (camerabin->viewfinderbin)
|
||||||
gst_object_unref (camerabin->vidbin);
|
gst_object_unref (camerabin->viewfinderbin);
|
||||||
if (camerabin->vid_queue)
|
if (camerabin->viewfinderbin_queue)
|
||||||
gst_object_unref (camerabin->vid_queue);
|
gst_object_unref (camerabin->viewfinderbin_queue);
|
||||||
if (camerabin->vid_capsfilter)
|
if (camerabin->viewfinderbin_capsfilter)
|
||||||
gst_object_unref (camerabin->vid_capsfilter);
|
gst_object_unref (camerabin->viewfinderbin_capsfilter);
|
||||||
|
|
||||||
if (camerabin->imgbin)
|
|
||||||
gst_object_unref (camerabin->imgbin);
|
if (camerabin->videobin)
|
||||||
|
gst_object_unref (camerabin->videobin);
|
||||||
|
if (camerabin->videobin_queue)
|
||||||
|
gst_object_unref (camerabin->videobin_queue);
|
||||||
|
if (camerabin->videobin_capsfilter)
|
||||||
|
gst_object_unref (camerabin->videobin_capsfilter);
|
||||||
|
|
||||||
|
if (camerabin->imagebin)
|
||||||
|
gst_object_unref (camerabin->imagebin);
|
||||||
|
if (camerabin->imagebin_queue)
|
||||||
|
gst_object_unref (camerabin->imagebin_queue);
|
||||||
|
if (camerabin->imagebin_capsfilter)
|
||||||
|
gst_object_unref (camerabin->imagebin_capsfilter);
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
@ -318,11 +329,12 @@ static void
|
||||||
gst_camera_bin_init (GstCameraBin * camerabin)
|
gst_camera_bin_init (GstCameraBin * camerabin)
|
||||||
{
|
{
|
||||||
camerabin->mode = DEFAULT_MODE;
|
camerabin->mode = DEFAULT_MODE;
|
||||||
camerabin->vid_location = g_strdup (DEFAULT_VID_LOCATION);
|
camerabin->video_location = g_strdup (DEFAULT_VID_LOCATION);
|
||||||
camerabin->img_location = g_strdup (DEFAULT_IMG_LOCATION);
|
camerabin->image_location = g_strdup (DEFAULT_IMG_LOCATION);
|
||||||
camerabin->vf_bin = gst_element_factory_make ("viewfinderbin", "vf-bin");
|
camerabin->viewfinderbin = gst_element_factory_make ("viewfinderbin",
|
||||||
|
"vf-bin");
|
||||||
|
|
||||||
gst_bin_add (GST_BIN (camerabin), gst_object_ref (camerabin->vf_bin));
|
gst_bin_add (GST_BIN (camerabin), gst_object_ref (camerabin->viewfinderbin));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -340,49 +352,45 @@ gst_camera_bin_init (GstCameraBin * camerabin)
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_camera_bin_create_elements (GstCameraBin * camera)
|
gst_camera_bin_create_elements (GstCameraBin * camera)
|
||||||
{
|
{
|
||||||
GstElement *src;
|
|
||||||
GstElement *vid;
|
|
||||||
GstElement *img;
|
|
||||||
GstElement *vid_queue;
|
|
||||||
GstElement *img_queue;
|
|
||||||
GstElement *vf_queue;
|
|
||||||
GstElement *vid_capsfilter;
|
|
||||||
GstElement *img_capsfilter;
|
|
||||||
GstElement *vf_capsfilter;
|
|
||||||
|
|
||||||
if (camera->elements_created)
|
if (camera->elements_created)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
src = gst_element_factory_make ("v4l2camerasrc", "camerasrc");
|
camera->src = gst_element_factory_make ("v4l2camerasrc", "camerasrc");
|
||||||
vid = gst_element_factory_make ("videorecordingbin", "video-rec-bin");
|
camera->videobin = gst_element_factory_make ("videorecordingbin", "videobin");
|
||||||
img = gst_element_factory_make ("imagecapturebin", "image-cap-bin");
|
camera->imagebin = gst_element_factory_make ("imagecapturebin", "imagebin");
|
||||||
|
|
||||||
camera->src = gst_object_ref (src);
|
camera->videobin_queue = gst_element_factory_make ("queue", "videobin-queue");
|
||||||
camera->vidbin = gst_object_ref (vid);
|
camera->imagebin_queue = gst_element_factory_make ("queue", "imagebin-queue");
|
||||||
camera->imgbin = gst_object_ref (img);
|
camera->viewfinderbin_queue = gst_element_factory_make ("queue",
|
||||||
|
"viewfinderbin-queue");
|
||||||
|
|
||||||
vid_queue = gst_element_factory_make ("queue", "video-queue");
|
camera->videobin_capsfilter = gst_element_factory_make ("capsfilter",
|
||||||
img_queue = gst_element_factory_make ("queue", "image-queue");
|
"videobin-capsfilter");
|
||||||
vf_queue = gst_element_factory_make ("queue", "vf-queue");
|
camera->imagebin_capsfilter = gst_element_factory_make ("capsfilter",
|
||||||
|
"imagebin-capsfilter");
|
||||||
|
camera->viewfinderbin_capsfilter = gst_element_factory_make ("capsfilter",
|
||||||
|
"viewfinderbin-capsfilter");
|
||||||
|
|
||||||
vid_capsfilter = gst_element_factory_make ("capsfilter", "video-capsfilter");
|
gst_bin_add_many (GST_BIN_CAST (camera), gst_object_ref (camera->src),
|
||||||
img_capsfilter = gst_element_factory_make ("capsfilter", "image-capsfilter");
|
gst_object_ref (camera->videobin), gst_object_ref (camera->imagebin),
|
||||||
vf_capsfilter = gst_element_factory_make ("capsfilter", "vf-capsfilter");
|
gst_object_ref (camera->videobin_queue),
|
||||||
|
gst_object_ref (camera->imagebin_queue),
|
||||||
gst_bin_add_many (GST_BIN_CAST (camera), src, vid, img,
|
gst_object_ref (camera->viewfinderbin_queue),
|
||||||
vid_queue, img_queue, vf_queue, vid_capsfilter, img_capsfilter,
|
gst_object_ref (camera->videobin_capsfilter),
|
||||||
vf_capsfilter, NULL);
|
gst_object_ref (camera->imagebin_capsfilter),
|
||||||
|
gst_object_ref (camera->viewfinderbin_capsfilter), NULL);
|
||||||
|
|
||||||
/* Linking can be optimized TODO */
|
/* Linking can be optimized TODO */
|
||||||
gst_element_link_many (vid_queue, vid_capsfilter, vid, NULL);
|
gst_element_link_many (camera->videobin_queue, camera->videobin_capsfilter,
|
||||||
gst_element_link_many (img_queue, img_capsfilter, img, NULL);
|
camera->videobin, NULL);
|
||||||
gst_element_link_many (vf_queue, vf_capsfilter, camera->vf_bin, NULL);
|
gst_element_link_many (camera->imagebin_queue, camera->imagebin_capsfilter,
|
||||||
gst_element_link_pads (src, "vfsrc", vf_queue, "sink");
|
camera->imagebin, NULL);
|
||||||
gst_element_link_pads (src, "imgsrc", img_queue, "sink");
|
gst_element_link_many (camera->viewfinderbin_queue,
|
||||||
gst_element_link_pads (src, "vidsrc", vid_queue, "sink");
|
camera->viewfinderbin_capsfilter, camera->viewfinderbin, NULL);
|
||||||
|
gst_element_link_pads (camera->src, "vfsrc", camera->viewfinderbin_queue,
|
||||||
camera->vid_queue = gst_object_ref (vid_queue);
|
"sink");
|
||||||
camera->vid_capsfilter = gst_object_ref (vid_capsfilter);
|
gst_element_link_pads (camera->src, "imgsrc", camera->imagebin_queue, "sink");
|
||||||
|
gst_element_link_pads (camera->src, "vidsrc", camera->videobin_queue, "sink");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Video can't get into playing as its internal filesink will open
|
* Video can't get into playing as its internal filesink will open
|
||||||
|
@ -393,14 +401,14 @@ gst_camera_bin_create_elements (GstCameraBin * camera)
|
||||||
* the source's ready-for-capture goes to FALSE it means it is
|
* the source's ready-for-capture goes to FALSE it means it is
|
||||||
* starting recording, so we should prepare the video bin.
|
* starting recording, so we should prepare the video bin.
|
||||||
*/
|
*/
|
||||||
gst_element_set_locked_state (vid, TRUE);
|
gst_element_set_locked_state (camera->videobin, TRUE);
|
||||||
camera->src_capture_notify_id = g_signal_connect (G_OBJECT (src),
|
camera->src_capture_notify_id = g_signal_connect (G_OBJECT (camera->src),
|
||||||
"notify::ready-for-capture",
|
"notify::ready-for-capture",
|
||||||
G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
|
G_CALLBACK (gst_camera_bin_src_notify_readyforcapture), camera);
|
||||||
|
|
||||||
g_object_set (src, "mode", camera->mode, NULL);
|
g_object_set (camera->src, "mode", camera->mode, NULL);
|
||||||
g_object_set (vid, "location", camera->vid_location, NULL);
|
g_object_set (camera->videobin, "location", camera->video_location, NULL);
|
||||||
g_object_set (img, "location", camera->img_location, NULL);
|
g_object_set (camera->imagebin, "location", camera->image_location, NULL);
|
||||||
|
|
||||||
camera->elements_created = TRUE;
|
camera->elements_created = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -426,7 +434,7 @@ gst_camera_bin_change_state (GstElement * element, GstStateChange trans)
|
||||||
|
|
||||||
switch (trans) {
|
switch (trans) {
|
||||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||||
gst_element_set_state (camera->vidbin, GST_STATE_NULL);
|
gst_element_set_state (camera->videobin, GST_STATE_NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -441,13 +449,13 @@ gst_camera_bin_set_location (GstCameraBin * camera, const gchar * location)
|
||||||
GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
|
GST_DEBUG_OBJECT (camera, "Setting mode %d location to %s", camera->mode,
|
||||||
location);
|
location);
|
||||||
if (camera->mode == MODE_IMAGE) {
|
if (camera->mode == MODE_IMAGE) {
|
||||||
if (camera->imgbin)
|
if (camera->imagebin)
|
||||||
g_object_set (camera->imgbin, "location", location, NULL);
|
g_object_set (camera->imagebin, "location", location, NULL);
|
||||||
g_free (camera->img_location);
|
g_free (camera->image_location);
|
||||||
camera->img_location = g_strdup (location);
|
camera->image_location = g_strdup (location);
|
||||||
} else {
|
} else {
|
||||||
g_free (camera->vid_location);
|
g_free (camera->video_location);
|
||||||
camera->vid_location = g_strdup (location);
|
camera->video_location = g_strdup (location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,9 +490,9 @@ gst_camera_bin_get_property (GObject * object, guint prop_id,
|
||||||
break;
|
break;
|
||||||
case PROP_LOCATION:
|
case PROP_LOCATION:
|
||||||
if (camera->mode == MODE_VIDEO) {
|
if (camera->mode == MODE_VIDEO) {
|
||||||
g_value_set_string (value, camera->vid_location);
|
g_value_set_string (value, camera->video_location);
|
||||||
} else {
|
} else {
|
||||||
g_value_set_string (value, camera->img_location);
|
g_value_set_string (value, camera->image_location);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PROP_VIDEO_CAPTURE_SUPPORTED_CAPS:
|
case PROP_VIDEO_CAPTURE_SUPPORTED_CAPS:
|
||||||
|
|
|
@ -40,20 +40,25 @@ struct _GstCameraBin
|
||||||
GstElement *src;
|
GstElement *src;
|
||||||
gulong src_capture_notify_id;
|
gulong src_capture_notify_id;
|
||||||
|
|
||||||
GstElement *vidbin;
|
GstElement *videobin;
|
||||||
GstElement *vid_queue;
|
GstElement *videobin_queue;
|
||||||
GstElement *vid_capsfilter;
|
GstElement *videobin_capsfilter;
|
||||||
|
|
||||||
GstElement *vf_bin;
|
GstElement *viewfinderbin;
|
||||||
|
GstElement *viewfinderbin_queue;
|
||||||
|
GstElement *viewfinderbin_capsfilter;
|
||||||
|
|
||||||
GstElement *imgbin;
|
GstElement *imagebin;
|
||||||
|
GstElement *imagebin_queue;
|
||||||
|
GstElement *imagebin_capsfilter;
|
||||||
|
|
||||||
gint vid_index;
|
/* Index of the auto incrementing file index for video recordings */
|
||||||
|
gint video_index;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
gint mode;
|
gint mode;
|
||||||
gchar *vid_location;
|
gchar *video_location;
|
||||||
gchar *img_location;
|
gchar *image_location;
|
||||||
|
|
||||||
gboolean elements_created;
|
gboolean elements_created;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue