Commit 195b05db authored by Éric Thiébaut's avatar Éric Thiébaut
Browse files

Store array time-stamp in a single object

parent 2003bcd1
......@@ -635,13 +635,14 @@ static tao_status_t on_start(
// Get image size (even though it is written in the device configuration,
// we read it again).
long width, height;
if (get_width(dev, &width) != TAO_OK || get_height(dev, &height) != TAO_OK) {
if (get_width(dev, &width) != TAO_OK ||
get_height(dev, &height) != TAO_OK) {
return TAO_ERROR;
}
// Instanciate camera acquisition buffers. Buffer data and size
// are instanciated by the on_wait_buffer method.
tao_time_t unset_time = TAO_UNKNOWN_TIME;
tao_time_t unknown_time = TAO_UNKNOWN_TIME;
for (int i = 0; i < cam->nbufs; ++i) {
cam->bufs[i].data = NULL;
cam->bufs[i].size = 0;
......@@ -651,9 +652,9 @@ static tao_status_t on_start(
cam->bufs[i].stride = stride;
cam->bufs[i].encoding = bufferencoding;
cam->bufs[i].frame_number = 0;
cam->bufs[i].frame_start = unset_time;
cam->bufs[i].frame_end = unset_time;
cam->bufs[i].buffer_ready = unset_time;
cam->bufs[i].frame_start = unknown_time;
cam->bufs[i].frame_end = unknown_time;
cam->bufs[i].buffer_ready = unknown_time;
}
// Allocate new device acquisition buffers as needed and queue them.
......
......@@ -714,8 +714,7 @@ static tao_status_t process_frame(
TAO_GET_SHARED_ARRAY_DIM(arr, 2) == height) {
andor_convert_buffer(TAO_GET_SHARED_ARRAY_DATA(arr), arrenc,
data, bufenc, width, height, stride);
arr->ts_sec = buf->frame_start.sec;
arr->ts_nsec = buf->frame_start.nsec;
arr->ts = buf->frame_start;
wrlock_shared_camera();
(void)tao_post_framegrabber_buffer(vfg);
unlock_shared_camera();
......
......@@ -21,10 +21,6 @@
#define INVALID_CAMERA_STATE -1
#define FRAMEGRABBER_TRY_LOCK 0
// Seconds and nanoseconds values when time-stamp has not been set.
#define NO_TIMESTAMP_SEC -1
#define NO_TIMESTAMP_NSEC 0
#define fatal_error(func, code) tao_push_error(func, code) // # FIXME:
#define if_likely(expr) if TAO_LIKELY(expr)
......@@ -987,8 +983,7 @@ static inline tao_shared_array_t* fetch_next_frame(
// Update information and return shared array.
arr->counter = 0; // to indicate that this buffer is not valid
arr->ts_sec = NO_TIMESTAMP_SEC;
arr->ts_nsec = NO_TIMESTAMP_NSEC;
arr->ts = TAO_UNKNOWN_TIME;
return arr;
}
......@@ -1045,13 +1040,15 @@ tao_status_t tao_post_framegrabber_buffer(
if (fg->locked != NULL) {
tao_shared_array_t* arr = fg->locked;
fg->locked = NULL;
if (arr->ts_sec == NO_TIMESTAMP_SEC &&
arr->ts_nsec == NO_TIMESTAMP_NSEC) {
if (arr->ts.sec == TAO_UNKNOWN_TIME.sec &&
arr->ts.nsec == TAO_UNKNOWN_TIME.nsec) {
// The owner did not set frame time-stamp.
tao_time_t t;
get_monotonic_time(&t);
arr->ts_sec = t.sec;
arr->ts_nsec = t.nsec;
if (tao_get_monotonic_time(&t) == TAO_OK) {
arr->ts = t;
} else {
tao_report_errors();
}
}
fg->counter += 1;
arr->counter = fg->counter;
......
......@@ -63,33 +63,31 @@ void tao_set_shared_array_counter(
void tao_get_shared_array_timestamp(
const tao_shared_array_t* arr,
int64_t* ts_sec,
int64_t* ts_nsec)
tao_time_t* ts)
{
if (arr != NULL) {
*ts_sec = arr->ts_sec;
*ts_nsec = arr->ts_nsec;
} else {
*ts_sec = -1;
*ts_nsec = 0;
if (ts != NULL) {
if (arr != NULL) {
*ts = arr->ts;
} else {
*ts = TAO_TIME(-1, 0);
}
}
}
void tao_set_shared_array_timestamp(
tao_shared_array_t* arr,
int64_t ts_sec,
int64_t ts_nsec)
const tao_time_t* ts)
{
if (arr != NULL) {
arr->ts_sec = ts_sec;
arr->ts_nsec = ts_nsec;
if (arr != NULL && ts != NULL) {
arr->ts = *ts;
}
}
tao_shared_array_t* tao_create_1d_shared_array(
const char* owner,
tao_eltype_t eltype,
long dim1, unsigned perms)
tao_eltype_t eltype,
long dim1,
unsigned perms)
{
long dims[1];
dims[0] = dim1;
......@@ -162,8 +160,7 @@ tao_shared_array_t* tao_create_shared_array(
arr->counter = 0;
tao_time_t t;
if (tao_get_monotonic_time(&t) == TAO_OK) {
arr->ts_sec = t.sec;
arr->ts_nsec = t.nsec;
arr->ts = t;
} else {
tao_report_errors();
}
......
......@@ -65,8 +65,7 @@ struct _tao_shared_array {
`ndims` are assumed to be `1`) */
tao_eltype_t eltype; /**< Type of the elements of the shared array */
volatile uint64_t counter; /**< Counter (used for posted images) */
volatile int64_t ts_sec; /**< Time stamp (seconds part) */
volatile int64_t ts_nsec; /**< Time stamp (nanoseconds part) */
volatile tao_time_t ts; /**< Time stamp. */
};
#define TAO_GET_SHARED_ARRAY_SHMID(arr) ((arr)->base.shmid)
......
......@@ -5341,10 +5341,7 @@ extern void tao_set_shared_array_counter(
*
* @param arr Pointer to a shared array attached to the address space of
* the caller and locked by the caller.
* @param ts_sec Address to store the integer part of the time-stamp in
* seconds.
* @param ts_nsec Address to store the fractional part of the time-stamp in
* nanoseconds.
* @param ts Address to store the time-stamp.
*
* @warning Since the time-stamp is variable, the caller must have locked the
* shared array for reading or for writing. For efficiency reasons,
......@@ -5354,16 +5351,14 @@ extern void tao_set_shared_array_counter(
*/
extern void tao_get_shared_array_timestamp(
const tao_shared_array_t* arr,
int64_t* ts_sec,
int64_t* ts_nsec);
tao_time_t* ts);
/**
* Set the time-stamp of a shared array counter.
*
* @param arr Pointer to a shared array attached to the address space of
* the caller and locked by the caller.
* @param ts_sec The integer part of the time-stamp in seconds.
* @param ts_nsec The fractional part of the time-stamp in nanoseconds.
* @param ts Time-stamp.
*
* @warning Since the time-stamp is variable, the caller must have locked the
* shared array for writing. For efficiency reasons, this function
......@@ -5373,8 +5368,7 @@ extern void tao_get_shared_array_timestamp(
*/
extern void tao_set_shared_array_timestamp(
tao_shared_array_t* arr,
int64_t ts_sec,
int64_t ts_nsec);
const tao_time_t* ts);
/**
* Lock a shared array for reading.
......
......@@ -669,8 +669,7 @@ static int process_frame(
}
// Copy the time stamp and publish the array.
arr->ts_sec = buf->frame_start.sec;
arr->ts_nsec = buf->frame_start.nsec;
arr->ts = buf->frame_start;
(void)tao_wrlock_shared_camera(shcam);
(void)tao_post_framegrabber_buffer(vfg);
(void)tao_unlock_shared_camera(shcam);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment