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

Number of buffers is always named `nbufs`

parent c453395f
......@@ -493,8 +493,8 @@ static tao_status on_set_config(
dst->pixeltype = src->pixeltype;
changes = true;
}
if (src->buffers != dst->buffers) {
dst->buffers = src->buffers;
if (src->nbufs != dst->nbufs) {
dst->nbufs = src->nbufs;
changes = true;
}
if (src->bufferencoding != dst->bufferencoding) {
......@@ -1249,5 +1249,11 @@ static tao_status check_configuration(
tao_store_error(func, TAO_BAD_ENCODING);
return TAO_ERROR;
}
// Check number of number of acquisition buffers.
if (cfg->nbufs < 2) {
tao_store_error(func, TAO_BAD_SIZE);
return TAO_ERROR;
}
return TAO_OK;
}
......@@ -140,14 +140,13 @@ static void* run_worker(void* arg);
// Set commands.
static tao_send_callback on_get_accesspoint;
static tao_send_callback on_get_bufferencoding;
static tao_send_callback on_get_buffers;
static tao_send_callback on_get_serial;
static tao_send_callback on_get_debuglevel;
static tao_send_callback on_get_drop;
static tao_send_callback on_get_exposuretime;
static tao_send_callback on_get_framerate;
static tao_send_callback on_get_height;
static tao_send_callback on_get_lastshmid;
static tao_send_callback on_get_nbufs;
static tao_send_callback on_get_nextshmid;
static tao_send_callback on_get_ping;
static tao_send_callback on_get_pixeltype;
......@@ -155,6 +154,7 @@ static tao_send_callback on_get_roi;
static tao_send_callback on_get_sensorencoding;
static tao_send_callback on_get_sensorheight;
static tao_send_callback on_get_sensorwidth;
static tao_send_callback on_get_serial;
static tao_send_callback on_get_shmid;
static tao_send_callback on_get_state;
static tao_send_callback on_get_suspended;
......@@ -167,14 +167,13 @@ static tao_send_callback on_get_yoff;
static tao_server_command get_commands[] = {
{"accesspoint", on_get_accesspoint, NULL, NULL, NULL},
{"bufferencoding", on_get_bufferencoding, NULL, NULL, NULL},
{"buffers", on_get_buffers, NULL, NULL, NULL},
{"serial", on_get_serial, NULL, NULL, NULL},
{"debuglevel", on_get_debuglevel, NULL, NULL, NULL},
{"drop", on_get_drop, NULL, NULL, NULL},
{"exposuretime", on_get_exposuretime, NULL, NULL, NULL},
{"framerate", on_get_framerate, NULL, NULL, NULL},
{"height", on_get_height, NULL, NULL, NULL},
{"lastshmid", on_get_lastshmid, NULL, NULL, NULL},
{"nbufs", on_get_nbufs, NULL, NULL, NULL},
{"nextshmid", on_get_nextshmid, NULL, NULL, NULL},
{"ping", on_get_ping, NULL, NULL, NULL},
{"pixeltype", on_get_pixeltype, NULL, NULL, NULL},
......@@ -182,6 +181,7 @@ static tao_server_command get_commands[] = {
{"sensorencoding", on_get_sensorencoding, NULL, NULL, NULL},
{"sensorheight", on_get_sensorheight, NULL, NULL, NULL},
{"sensorwidth", on_get_sensorwidth, NULL, NULL, NULL},
{"serial", on_get_serial, NULL, NULL, NULL},
{"shmid", on_get_shmid, NULL, NULL, NULL},
{"state", on_get_state, NULL, NULL, NULL},
{"suspended", on_get_suspended, NULL, NULL, NULL},
......@@ -912,7 +912,7 @@ GETTER(long, "%ld", lastshmid, lastframe)
GETTER(long, "%ld", nextshmid, nextframe)
GETTER(long, "%ld", sensorwidth, info.sensorwidth)
GETTER(long, "%ld", sensorheight, info.sensorheight)
GETTER(int, "%d", buffers, info.config.buffers)
GETTER(long, "%ld", nbufs, info.config.nbufs)
GETTER(long, "%ld", xbin, info.config.roi.xbin)
GETTER(long, "%ld", ybin, info.config.roi.ybin)
GETTER(long, "%ld", xoff, info.config.roi.xoff)
......@@ -1494,9 +1494,9 @@ static tao_status on_set_config(
GETOPT("bufferencoding", bufferencoding,
(req.bufferencoding = tao_parse_encoding(val)) !=
TAO_ENCODING_UNKNOWN);
GETOPT("buffers", buffers,
tao_parse_long(val, &req.buffers, 10) == TAO_OK
&& req.buffers >= 2);
GETOPT("nbufs", nbufs,
tao_parse_long(val, &req.nbufs, 10) == TAO_OK
&& req.nbufs >= 2);
} else if (c == 'e') {
GETOPT("exposuretime", exposuretime,
tao_parse_double(val, &req.exposuretime) == TAO_OK
......@@ -1603,7 +1603,7 @@ static tao_status on_set_config(
if (status == TAO_OK) {
bool change = false;
SETOPT(bufferencoding);
SETOPT(buffers);
SETOPT(nbufs);
SETOPT(framerate);
SETOPT(exposuretime);
SETOPT(pixeltype);
......
......@@ -85,7 +85,7 @@ int main(
//cfg.roi.height = 480;
cfg.framerate = 40.0;
cfg.exposuretime = 0.005;
cfg.buffers = 4;
cfg.nbufs = 4;
//cfg.pixelencoding = ANDOR_ENCODING_MONO12PACKED;
if (tao_camera_set_configuration(cam, &cfg) != TAO_OK) {
tao_report_error();
......
......@@ -140,7 +140,7 @@ void tao_camera_info_initialize(
info->config.pixeltype = TAO_FLOAT;
info->config.sensorencoding = TAO_ENCODING_UNKNOWN;
info->config.bufferencoding = TAO_ENCODING_UNKNOWN;
info->config.buffers = 4;
info->config.nbufs = 4;
info->config.framerate = 25.0; // 25 Hz
info->config.exposuretime = 0.001; // 1 ms
info->config.preprocessing = TAO_PREPROCESSING_NONE;
......@@ -400,11 +400,11 @@ tao_status tao_camera_start_acquisition(
// pending buffers to be overwritten by the frame-grabber), clear
// events and manage to have next acquisition buffer information at
// index 0.
if (cam->info.config.buffers < 1) {
if (cam->info.config.nbufs < 1) {
tao_store_error(__func__, TAO_BAD_BUFFERS);
return TAO_ERROR;
}
if (manage_buffers(cam, cam->info.config.buffers + 1) != TAO_OK) {
if (manage_buffers(cam, cam->info.config.nbufs + 1) != TAO_OK) {
return TAO_ERROR;
}
for (int i = 0; i < cam->nbufs; ++i) {
......@@ -745,7 +745,7 @@ tao_status tao_camera_config_print(
strcpy(buf, "IllegalEncoding");
}
if (fprintf(out, "Buffer encoding: %s\n", buf) < 0 ||
fprintf(out, "Number of acquisition buffers: %ld\n", cfg->buffers) < 0 ||
fprintf(out, "Number of acquisition buffers: %ld\n", cfg->nbufs) < 0 ||
fprintf(out, "Frame rate: %g Hz\n", cfg->framerate) < 0 ||
fprintf(out, "Exposure time: %.3f ms\n", 1E3*cfg->exposuretime) < 0) {
goto fprintf_error;
......
......@@ -68,81 +68,81 @@ TAO_BEGIN_DECLS
* operations on the camera yield @ref TAO_NOT_READY error code.
*/
struct tao_camera_ops_ {
const char* name; /**< Camera model/family name */
const char* name; ///< Camera model/family name.
tao_status (*initialize)(
tao_camera* cam);
/**< Initialize the members of this structure (including the
configuration). This method is only called once during the lifetime
of the camera instance. It shall return @ref TAO_OK on success or @ref
TAO_ERROR on failure. It is assumed that any allocated specific
resources are destroyed in case of failure (the `finalize` method is
not called if initialization fails). */
///< Initialize the members of this structure (including the
/// configuration). This method is only called once during the lifetime
/// of the camera instance. It shall return @ref TAO_OK on success or @ref
/// TAO_ERROR on failure. It is assumed that any allocated specific
/// resources are destroyed in case of failure (the `finalize` method is
/// not called if initialization fails).
void (*finalize)(
tao_camera* cam);
/**< Free device resources. This method is only called once at the end of
the lifetime of the camera instance. This method is not called by the
generic constructor tao_camera_create() in case of errors during the
construction. */
///< Free device resources. This method is only called once at the end of
/// the lifetime of the camera instance. This method is not called by the
/// generic constructor tao_camera_create() in case of errors during the
/// construction.
tao_status (*reset)(
tao_camera* cam);
/**< Reset camera to run-level 1 (sleeping) in case of recoverable error.
This method shall only be called when the camera run-level is 3. On
success, the method shall set the run-level to 1 and return @ref
TAO_OK; otherwise it shall return @ref TAO_ERROR to indicate a
failure. */
///< Reset camera to run-level 1 (sleeping) in case of recoverable error.
/// This method shall only be called when the camera run-level is 3. On
/// success, the method shall set the run-level to 1 and return @ref
/// TAO_OK; otherwise it shall return @ref TAO_ERROR to indicate a
/// failure.
tao_status (*update_config)(
tao_camera* cam);
/**< Retrieve camera current device settings, never called while
acquisition is running. It shall return @ref TAO_OK on success or
@ref TAO_ERROR on failure. */
///< Retrieve camera current device settings, never called while
/// acquisition is running. It shall return @ref TAO_OK on success or
/// @ref TAO_ERROR on failure.
tao_status (*check_config)(
tao_camera* cam,
const tao_camera_config* cfg);
/**< Check camera settings. Caller's last error may be used to report
which parameters are invalid. It shall return @ref TAO_OK on success
or @ref TAO_ERROR on failure. */
///< Check camera settings. Caller's last error may be used to report
/// which parameters are invalid. It shall return @ref TAO_OK on success
/// or @ref TAO_ERROR on failure.
tao_status (*set_config)(
tao_camera* cam,
const tao_camera_config* cfg);
/**< Set camera settings. This method is called to set the camera
configuration. It is never called while acquitring. It shall return
@ref TAO_OK on success or @ref TAO_ERROR on failure. */
///< Set camera settings. This method is called to set the camera
/// configuration. It is never called while acquiring. It shall return
/// @ref TAO_OK on success or @ref TAO_ERROR on failure.
tao_status (*start)(
tao_camera* cam);
/**< Start acquisition. This method is only called after initialization
and if the camera is not acquiring. It shall return @ref TAO_OK on
success or @ref TAO_ERROR on failure. */
///< Start acquisition. This method is only called after initialization
/// and if the camera is not acquiring. It shall return @ref TAO_OK on
/// success or @ref TAO_ERROR on failure.
tao_status (*stop)(
tao_camera* cam);
/**< Stop acquisition. This method shall stop acquisition immediately,
without waiting for the current frame. This method is only called when
the camera is acquiring. It shall return @ref TAO_OK on success or
@ref TAO_ERROR on failure. */
///< Stop acquisition. This method shall stop acquisition immediately,
/// without waiting for the current frame. This method is only called when
/// the camera is acquiring. It shall return @ref TAO_OK on success or
/// @ref TAO_ERROR on failure.
tao_status (*wait_buffer)(
tao_camera* cam,
double secs);
/**< Wait for the next frame. This method is only called when the camera
is acquiring. It shall not wait more than `secs` seconds. It shall
return @ref TAO_OK on success, @ref TAO_TIMEOUT on timeout or @ref
TAO_ERROR on failure. This method may assume that arguments have been
checked for correctness. This method shall update `cam->last` and
`cam->pending`. */
///< Wait for the next frame. This method is only called when the camera
/// is acquiring. It shall not wait more than `secs` seconds. It shall
/// return @ref TAO_OK on success, @ref TAO_TIMEOUT on timeout or @ref
/// TAO_ERROR on failure. This method may assume that arguments have been
/// checked for correctness. This method shall update `cam->last` and
/// `cam->pending`.
tao_status (*release_buffer)(
tao_camera* cam);
/**< Release the first pending acquisition buffer. This method is only
called when the camera is acquiring. It shall return @ref TAO_OK on
success or @ref TAO_ERROR on failure. This method shall update
`cam->last` and `cam->pending`. */
///< Release the first pending acquisition buffer. This method is only
/// called when the camera is acquiring. It shall return @ref TAO_OK on
/// success or @ref TAO_ERROR on failure. This method shall update
/// `cam->last` and `cam->pending`.
};
/**
......@@ -153,13 +153,9 @@ struct tao_camera_ops_ {
* belongs to the same process so the mutex and condition variable associated
* to a camera are not sharable between processes.
*
* The number `nbufs` of acquisition buffers is set to `info.config.buffers`
* plus one so that `info.config.buffers` can safely be the maximum number of
* pending acquisition buffers. Indeed, thanks to this extra buffer, it is
* possible to ensure that none of the pending buffers be overwritten by the
* frame-grabber. FIXME: In the code, the maximum number of pending buffers is
* enforced to be `nbufs - 1`. Whatever the value of `info.config.buffers`,
* the minimum number of acquisition buffers is `nbufs=2`.
* The number `nbufs` of acquisition buffers is set to `info.config.nbufs` at
* the latest when acquisition is started. The the minimum number of
* acquisition buffers should be 2.
*
* @note The `runlevel` member may be related to the enumeration @ref tao_state
* but has fewer possible values because @ref tao_state can also
......
......@@ -161,7 +161,7 @@ typedef struct tao_camera_config_ {
/// the sensor.
tao_encoding bufferencoding;///< Pixel encoding for acquisition
/// buffers.
long buffers;///< Number of acquisition buffers.
long nbufs;///< Number of acquisition buffers.
double framerate;///< Acquisition rate in frames per second.
double exposuretime;///< Exposure time in seconds.
tao_preprocessing preprocessing;///< Level of image pre-processing.
......@@ -265,7 +265,7 @@ typedef struct tao_acquisition_buffer_ {
long offset;///< Offset (in bytes) of first pixel in ROI.
long width;///< Number of pixel per line in ROI.
long height;///< Number of lines in ROI.
long stride;///< Bytes per line in buffer.
long stride;///< Bytes per line in buffer (including padding).
tao_encoding encoding;///< Pixel encoding in buffer.
tao_serial serial;///< Serial number of frame.
tao_time frame_start;///< Start time of frame.
......@@ -295,8 +295,8 @@ typedef struct tao_camera_ops_ tao_camera_ops;
* be allocated to store the @ref tao_camera structure. See the code of
* phnx_create_camera() for an example.
*
* @warning In case of error, the `finalize` method in @b ops is not called by
* the constructor tao_camera_create().
* @warning In case of failure of tao_camera_create(), the `finalize` method in
* @b ops is not called.
*
* @param ops Virtual operations table.
* @param ctx Address of contextual data.
......@@ -346,9 +346,9 @@ extern void tao_camera_lock(
/**
* Try to lock a camera.
*
* This function attempts to lock the mutex of the camera @b cam. If the call
* is successful, the caller is responsible of eventually calling
* tao_camera_unlock().
* This function attempts to lock the mutex of the camera @b cam without
* blocking. If the call is successful, the caller is responsible of
* eventually calling tao_camera_unlock().
*
* @param cam Address of camera instance (must be non-`NULL`).
*
......@@ -377,7 +377,7 @@ extern void tao_camera_unlock(
* variable of the camera @b cam. Nothing happens, if no threads are waiting
* on the condition variable of @b cam. The caller is assumed to have locked
* the camera before calling this function and to unlock the camera soon after
* calling this function.
* calling this function to effectively trigger the notification to others.
*
* @param cam Address of camera instance (must be non-`NULL`).
*
......@@ -496,15 +496,15 @@ extern tao_status tao_camera_reflect_configuration(
* ~~~~~{.c}
* long timouts = 0, frames = 0, number = 100;
* int drop = 0; // keep all images
* tao_status status;
* double secs = 30.0; // max. number of seconds to wait for each buffer
* tao_camera_lock(cam);
* status = tao_camera_start_acquisition(cam);
* tao_status status = tao_camera_start_acquisition(cam);
* while (status == TAO_OK && frames < number) {
* const tao_acquisition_buffer* buf;
* status = tao_camera_wait_acquisition_buffer(cam, &buf, secs, drop);
* if (status == TAO_OK) {
* // Process acquisition buffer (unlock during processing,
* // relock and release buffer).
* // Process acquisition buffer and release buffer (unlock camera
* // during processing).
* tao_camera_unlock(cam);
* process(buf->data, buf->size, ...); // do the processing
* tao_camera_lock(cam);
......@@ -512,7 +512,7 @@ extern tao_status tao_camera_reflect_configuration(
* ++frames;
* } else if (status == TAO_TIMEOUT) {
* // Timeout occurred.
* if (++timeouts > 40) {
* if (++timeouts > 4) {
* fprintf(stderr, "Too many timouts, aborting acquisition...\");
* } else {
* status = TAO_OK;
......@@ -528,8 +528,8 @@ extern tao_status tao_camera_reflect_configuration(
*
* @note The caller must own the lock on the camera when calling
* tao_camera_wait_acquisition_buffer(). Unlocking the camera during the
* processing of the acquisition buffer is only recommended if this
* operation is time consuming.
* processing of the acquisition buffer, as in the above example, is only
* recommended if this operation is time consuming.
*
* @note Do not forget to call tao_camera_release_acquisition_buffer() after the
* processing otherwise the same acquisition buffer will be immediately
......
......@@ -171,7 +171,6 @@ static void* run_worker(void* arg);
static tao_send_callback on_get_accesspoint;
static tao_send_callback on_get_bias;
static tao_send_callback on_get_bufferencoding;
static tao_send_callback on_get_buffers;
static tao_send_callback on_get_connection;
static tao_send_callback on_get_debuglevel;
static tao_send_callback on_get_drop;
......@@ -182,6 +181,7 @@ static tao_send_callback on_get_gain;
static tao_send_callback on_get_height;
static tao_send_callback on_get_lostframes;
static tao_send_callback on_get_lostsyncs;
static tao_send_callback on_get_nbufs;
static tao_send_callback on_get_origin;
static tao_send_callback on_get_overflows;
static tao_send_callback on_get_overruns;
......@@ -205,7 +205,6 @@ static tao_server_command get_commands[] = {
{"accesspoint", on_get_accesspoint, NULL, NULL, NULL},
{"bias", on_get_bias, NULL, NULL, NULL},
{"bufferencoding", on_get_bufferencoding, NULL, NULL, NULL},
{"buffers", on_get_buffers, NULL, NULL, NULL},
{"connection", on_get_connection, NULL, NULL, NULL},
{"debuglevel", on_get_debuglevel, NULL, NULL, NULL},
{"drop", on_get_drop, NULL, NULL, NULL},
......@@ -216,6 +215,7 @@ static tao_server_command get_commands[] = {
{"height", on_get_height, NULL, NULL, NULL},
{"lostframes", on_get_lostframes, NULL, NULL, NULL},
{"lostsyncs", on_get_lostsyncs, NULL, NULL, NULL},
{"nbufs", on_get_nbufs, NULL, NULL, NULL},
{"origin", on_get_origin, NULL, NULL, NULL},
{"overflows", on_get_overflows, NULL, NULL, NULL},
{"overruns", on_get_overruns, NULL, NULL, NULL},
......@@ -1204,7 +1204,7 @@ static tao_status on_get_origin(
}
GETTER(long, "%ld", sensorwidth, sensorwidth)
GETTER(long, "%ld", sensorheight, sensorheight)
GETTER(int, "%d", buffers, config.buffers)
GETTER(long, "%ld", nbufs, config.nbufs)
GETTER(long, "%ld", xbin, config.roi.xbin)
GETTER(long, "%ld", ybin, config.roi.ybin)
GETTER(long, "%ld", xoff, config.roi.xoff)
......@@ -1761,9 +1761,9 @@ static tao_status on_set_config(
GETOPT("bufferencoding", base.bufferencoding,
(req.base.bufferencoding = tao_parse_encoding(val)) !=
TAO_ENCODING_UNKNOWN);
GETOPT("buffers", base.buffers,
tao_parse_long(val, &req.base.buffers, 10) == TAO_OK
&& req.base.buffers >= 2);
GETOPT("nbufs", base.nbufs,
tao_parse_long(val, &req.base.nbufs, 10) == TAO_OK
&& req.base.nbufs >= 2);
} else if (c == 'e') {
GETOPT("exposuretime", base.exposuretime,
tao_parse_double(val, &req.base.exposuretime) == TAO_OK
......@@ -1834,7 +1834,7 @@ static tao_status on_set_config(
bool change = false;
SETOPT(extra.bias);
SETOPT(base.bufferencoding);
SETOPT(base.buffers);
SETOPT(base.nbufs);
SETOPT(base.framerate);
SETOPT(extra.gain);
SETOPT(base.exposuretime);
......
......@@ -403,11 +403,11 @@ static tao_status on_set_config(
// Set encoding and number of acquisition buffers.
cam->info.config.bufferencoding = cfg->bufferencoding;
if (cfg->buffers < 2) {
if (cfg->nbufs < 2) {
tao_store_error(__func__, TAO_BAD_BUFFERS);
return TAO_ERROR;
}
cam->info.config.buffers = cfg->buffers;
cam->info.config.nbufs = cfg->nbufs;
// Call virtual method with specific settings identical to the current
// ones.
......@@ -624,9 +624,9 @@ static tao_status on_wait_buffer(
assert(cam->runlevel == 2);
// Compute absolute time-out time.
tao_time t;
tao_time abstime;
bool forever;
switch (tao_get_absolute_timeout(&t, secs)) {
switch (tao_get_absolute_timeout(&abstime, secs)) {
case TAO_TIMEOUT_PAST:
++cam->info.timeouts;
......@@ -649,14 +649,14 @@ static tao_status on_wait_buffer(
// error to occur. This is done in a `while` loop to cope with spurious
// signaled conditions. Index `cam->last` (and other members) is updated
// by the acquisition callback.
while (cam->pending < 1) {
while (cam->pending < 1) { // FIXME: check all expected events
if (forever) {
if (tao_condition_wait(&cam->notify, &cam->mutex) != TAO_OK) {
return TAO_ERROR;
}
} else {
tao_status status =
tao_condition_abstimed_wait(&cam->notify, &cam->mutex, &t);
tao_status status = tao_condition_abstimed_wait(
&cam->notify, &cam->mutex, &abstime);
if (status != TAO_OK) {
if (status == TAO_TIMEOUT) {
++cam->info.timeouts;
......@@ -778,7 +778,7 @@ static tao_status update_buffer_address(
// pending: p -= 1
// recycled: r += 1
//
// The safer is to make sure that the frame grabber can always write to a
// The safer is to make sure that the frame-grabber can always write to a
// recyclable buffer. So when a buffer ready event arrives, there should be at
// least 2 recyclable buffers. If there is one buffer being processed, there
// must be at least 3 acquisition buffers in total.
......
......@@ -128,7 +128,7 @@ extern bool phnx_parse_nbufs_option(
#define PHNX_OPTION_ACQUISITION_BUFFERS(cfg) \
{2, "nbufs", 1, "NUMBER", "Number of acquisition buffers", \
&(cfg).base.buffers, tao_show_int_option, phnx_parse_nbufs_option}
&(cfg).base.nbufs, tao_show_int_option, phnx_parse_nbufs_option}
#define PHNX_OPTION_DROP(lval) \
TAO_OPTION_YESNO(2, "drop", \
......
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