From f1aa474faa59265ee9fa9207663488cd34bc5a18 Mon Sep 17 00:00:00 2001 From: Jussi Saavalainen Date: Wed, 24 Apr 2013 13:24:54 +0300 Subject: [PATCH] Allow pausing of 3A thread instead of recreating it each time This partially removes some of the address space leakage associated with stack space for the threads, plus brings a tiny performance gain for stills. Change-Id: I712f86ca0f880e8bbe908d087b5ce734949a5b0d --- gst-libs/atomisphal/mfld_cam.c | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/gst-libs/atomisphal/mfld_cam.c b/gst-libs/atomisphal/mfld_cam.c index 3fc7574..3809448 100644 --- a/gst-libs/atomisphal/mfld_cam.c +++ b/gst-libs/atomisphal/mfld_cam.c @@ -102,7 +102,8 @@ struct mfld_driver_t int mmap; int first_frame; int g_3a_started; - //GThread *thread; + int thread_paused; + pthread_t thread; unsigned int width, height, fourcc; float frame_rate; @@ -134,6 +135,9 @@ static const int STILL_AF_MAX_TIME_IN_MS = 2200; * */ static struct mfld_cam_settings_t mfld_cam_settings; static struct mfld_driver_t mfld_driver; + +G_LOCK_DEFINE(3a_thread_lock); + static GstV4l2MFLDAdvCI *mfldadvci; static inline long @@ -1199,7 +1203,10 @@ libmfld_cam_init (GstV4l2MFLDAdvCI * advci) mfld_driver.first_frame = 0; mfld_driver.mmap = 1; + G_LOCK(3a_thread_lock); mfld_driver.g_3a_started = 0; + mfld_driver.thread_paused = 0; + G_UNLOCK(3a_thread_lock); mfld_driver.focus_done = 0; mfld_driver.flash_used = FALSE; @@ -1213,6 +1220,7 @@ libmfld_cam_init (GstV4l2MFLDAdvCI * advci) void libmfld_cam_dispose (void) { + G_LOCK(3a_thread_lock); if (mfld_driver.g_3a_started) { pthread_cancel (mfld_driver.thread); mfld_driver.thread = 0; @@ -1220,6 +1228,7 @@ libmfld_cam_dispose (void) mfld_driver.g_3a_started = 0; if (mfld_driver.sensor_type == SENSOR_TYPE_RAW) mfldadvci->uninit (); + G_UNLOCK(3a_thread_lock); return; } @@ -1272,7 +1281,9 @@ cam_driver_init (int fd, const char *sensor_id) mfld_driver.initflag = 1; /* We are ready to call the dz_zoom */ /* Do other driver related init here */ + G_LOCK(3a_thread_lock); mfld_driver.thread = 0; + G_UNLOCK(3a_thread_lock); mfld_driver.frame_rate = 15.0f; return CAM_ERR_NONE; @@ -1288,10 +1299,12 @@ cam_driver_deinit (int fd) /* Initialize the driver structure */ //GstCameraSrcClass *camera_class = GST_CAMERA_SRC_GET_CLASS (camerasrc); mfld_driver.initflag = 0; + G_LOCK(3a_thread_lock); if (mfld_driver.g_3a_started) { pthread_cancel (mfld_driver.thread); mfld_driver.g_3a_started = 0; } + G_UNLOCK(3a_thread_lock); /* Do other driver related deinit here */ led_flash_off(fd); return CAM_ERR_NONE; @@ -1483,12 +1496,19 @@ mfldcam_3a_process (gpointer data) for (;;) { sem_wait(&g_sem_3a); /* Read 3A statistics */ - if ((mfld_driver.ae_awb_af_enabled || mfld_driver.dis_enabled - || mfld_driver.dvs_enabled) && (mfld_driver.sensor_type == SENSOR_TYPE_RAW) ) - { + if ( (mfld_driver.ae_awb_af_enabled + || mfld_driver.dis_enabled + || mfld_driver.dvs_enabled) + && (mfld_driver.sensor_type == SENSOR_TYPE_RAW)) { + G_LOCK(3a_thread_lock); + if(mfld_driver.thread_paused) { + G_UNLOCK(3a_thread_lock); + continue; + } /* AE, AWB and AF Process */ - mfldadvci->AeAfAwb_process(TRUE,&mfld_driver.timestamp); + G_UNLOCK(3a_thread_lock); + mfldadvci->AeAfAwb_process(TRUE,&mfld_driver.timestamp); } else return NULL; @@ -1498,16 +1518,20 @@ mfldcam_3a_process (gpointer data) void mfldcam_3a_start (void) { - if (mfld_driver.sensor_type == SENSOR_TYPE_RAW){ + G_LOCK(3a_thread_lock); if (!mfld_driver.g_3a_started) { mfld_driver.g_3a_started = 1; - if (pthread_create (&mfld_driver.thread, NULL, mfldcam_3a_process, - NULL) != 0) { + mfld_driver.thread_paused = 0; + + if (pthread_create (&mfld_driver.thread, NULL, mfldcam_3a_process, NULL) != 0) { mfld_driver.g_3a_started = 0; cam_driver_dbg ("Create thread failed %s\n", __func__);; } + } else if(mfld_driver.thread_paused) { + mfld_driver.thread_paused = 0; } + G_UNLOCK(3a_thread_lock); } } @@ -1515,10 +1539,12 @@ void mfldcam_3a_stop (void) { - if (mfld_driver.sensor_type == SENSOR_TYPE_RAW){ - if (mfld_driver.g_3a_started) - pthread_cancel (mfld_driver.thread); - mfld_driver.g_3a_started = 0; + if (mfld_driver.sensor_type == SENSOR_TYPE_RAW) { + G_LOCK(3a_thread_lock); + if (mfld_driver.g_3a_started) { + mfld_driver.thread_paused = 1; + } + G_UNLOCK(3a_thread_lock); } } -- 2.7.4