diff options
author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-04-12 17:45:27 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-04-12 17:45:27 +0200 |
commit | 8701b32d15dca588bccca5d8c0586826fbbcb09e (patch) | |
tree | 0eefd2a227cd5b708e31eb3b5b97418c0b64b800 | |
parent | e998dd9cf752866f09ab8eebe7e9e965cb78ccab (diff) | |
download | uca-8701b32d15dca588bccca5d8c0586826fbbcb09e.tar.gz uca-8701b32d15dca588bccca5d8c0586826fbbcb09e.tar.bz2 uca-8701b32d15dca588bccca5d8c0586826fbbcb09e.tar.xz uca-8701b32d15dca588bccca5d8c0586826fbbcb09e.zip |
Allocate memory only when size has changed
-rw-r--r-- | src/cameras/uca-pco-camera.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/cameras/uca-pco-camera.c b/src/cameras/uca-pco-camera.c index 850f3a6..fa97fb6 100644 --- a/src/cameras/uca-pco-camera.c +++ b/src/cameras/uca-pco-camera.c @@ -289,25 +289,30 @@ static void uca_pco_camera_start_recording(UcaCamera *camera, GError **error) */ guint16 roi[4] = {0}; err = pco_get_roi(priv->pco, roi); - priv->frame_width = roi[2] - roi[0] + 1; - priv->frame_height = roi[3] - roi[1] + 1; - priv->num_bytes = 2; + guint frame_width = roi[2] - roi[0] + 1; + guint frame_height = roi[3] - roi[1] + 1; - Fg_setParameter(priv->fg, FG_WIDTH, &priv->frame_width, priv->fg_port); - Fg_setParameter(priv->fg, FG_HEIGHT, &priv->frame_height, priv->fg_port); + if (priv->frame_width != frame_width || priv->frame_height != frame_height || priv->fg_mem == NULL) { + priv->frame_width = frame_width; + priv->frame_height = frame_height; + priv->num_bytes = 2; - if (priv->fg_mem) - Fg_FreeMemEx(priv->fg, priv->fg_mem); + Fg_setParameter(priv->fg, FG_WIDTH, &priv->frame_width, priv->fg_port); + Fg_setParameter(priv->fg, FG_HEIGHT, &priv->frame_height, priv->fg_port); - const guint num_buffers = 2; - priv->fg_mem = Fg_AllocMemEx(priv->fg, - num_buffers * priv->frame_width * priv->frame_height * sizeof(uint16_t), num_buffers); + if (priv->fg_mem) + Fg_FreeMemEx(priv->fg, priv->fg_mem); - if (priv->fg_mem == NULL) { - g_set_error(error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_FG_INIT, - "%s", Fg_getLastErrorDescription(priv->fg)); - g_object_unref(camera); - return; + const guint num_buffers = 2; + priv->fg_mem = Fg_AllocMemEx(priv->fg, + num_buffers * priv->frame_width * priv->frame_height * sizeof(uint16_t), num_buffers); + + if (priv->fg_mem == NULL) { + g_set_error(error, UCA_PCO_CAMERA_ERROR, UCA_PCO_CAMERA_ERROR_FG_INIT, + "%s", Fg_getLastErrorDescription(priv->fg)); + g_object_unref(camera); + return; + } } if ((priv->camera_description->camera_type == CAMERATYPE_PCO_DIMAX_STD) || |