From 2e4e8a00b27182a155cb10f0a00e44977bfcd5cf Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Mon, 12 Dec 2011 05:45:35 +0100 Subject: multithread preprocessing of ipecamera frames and code reorganization --- event.c | 80 ++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 30 deletions(-) (limited to 'event.c') diff --git a/event.c b/event.c index 1711400..a277e46 100644 --- a/event.c +++ b/event.c @@ -29,12 +29,10 @@ struct timespec { pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event) { int i; - pcilib_register_bank_t res; - unsigned long addr; - + pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_description_t *events = model_info->events; - + for (i = 0; events[i].name; i++) { if (!strcasecmp(events[i].name, event)) return events[i].evid; } @@ -44,8 +42,6 @@ pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event) { pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type) { int i; - pcilib_register_bank_t res; - unsigned long addr; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_data_type_description_t *data_types = model_info->data_types; @@ -193,8 +189,7 @@ static int pcilib_return_event_callback(pcilib_event_id_t event_id, pcilib_event } */ -int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, pcilib_event_info_t **info) { - int err; +int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info) { pcilib_event_api_description_t *api; // pcilib_return_event_callback_context_t user; @@ -207,7 +202,7 @@ int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_ } if (api->next_event) - return api->next_event(ctx->event_ctx, timeout, evid, info); + return api->next_event(ctx->event_ctx, timeout, evid, info_size, info); /* if (api->stream) { @@ -245,22 +240,33 @@ int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, voi void *pcilib_get_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size) { + int err; + void *res = NULL; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_api_description_t *api = model_info->event_api; if (!api) { + if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED; pcilib_error("Event API is not supported by the selected model"); return NULL; } - if (api->get_data) - return api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size, NULL); - + if (api->get_data) { + err = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size, &res); + if (err) { + if (size) *size = (size_t)err; + return NULL; + } + return res; + } + + if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED; return NULL; } int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t size, void *buf, size_t *retsize) { - void *res; + int err; + void *res = buf; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_api_description_t *api = model_info->event_api; @@ -270,8 +276,10 @@ int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pc } if (api->get_data) { - res = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, &size, buf); - if (!res) return PCILIB_ERROR_FAILED; + err = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, &size, &res); + if (err) return err; + + if (buf != res) memcpy(buf, res, size); if (retsize) *retsize = size; return 0; @@ -282,22 +290,33 @@ int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pc void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size) { + int err; + void *res = NULL; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_api_description_t *api = model_info->event_api; if (!api) { pcilib_error("Event API is not supported by the selected model"); + if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED; return NULL; } - if (api->get_data) - return api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size, NULL); + if (api->get_data) { + err = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size, &res); + if (err) { + if (size) *size = (size_t)err; + return NULL; + } + return res; + } + if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED; return NULL; } int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t size, void *buf, size_t *ret_size) { - void *res; + int err; + void *res = buf; pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_api_description_t *api = model_info->event_api; @@ -307,9 +326,11 @@ int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_dat } if (api->get_data) { - res = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, &size, buf); - if (!res) return PCILIB_ERROR_FAILED; + err = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, &size, &res); + if (err) return err; + if (buf != res) memcpy(buf, res, size); + if (ret_size) *ret_size = size; return 0; } @@ -317,7 +338,7 @@ int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_dat return PCILIB_ERROR_NOTSUPPORTED; } -int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, void *data) { +int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, void *data) { pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_event_api_description_t *api = model_info->event_api; @@ -327,7 +348,7 @@ int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, void *data) { } if (api->return_data) - return api->return_data(ctx->event_ctx, event_id, data); + return api->return_data(ctx->event_ctx, event_id, data_type, data); return 0; } @@ -352,13 +373,13 @@ static int pcilib_grab_callback(pcilib_event_t event, pcilib_event_id_t event_id data = pcilib_get_data(user->ctx, event_id, PCILIB_EVENT_DATA, &size); if (!data) { pcilib_error("Error getting event data"); - return PCILIB_ERROR_FAILED; + return -(int)size; } if (*(user->data)) { if ((user->size)&&(*(user->size) < size)) { pcilib_error("The supplied buffer does not have enough space to hold the event data. Buffer size is %z, but %z is required", user->size, size); - return PCILIB_ERROR_MEMORY; + return -PCILIB_ERROR_MEMORY; } *(user->size) = size; @@ -366,7 +387,7 @@ static int pcilib_grab_callback(pcilib_event_t event, pcilib_event_id_t event_id *(user->data) = malloc(size); if (!*(user->data)) { pcilib_error("Memory allocation (%i bytes) for event data is failed"); - return PCILIB_ERROR_MEMORY; + return -PCILIB_ERROR_MEMORY; } if (*(user->size)) *(user->size) = size; allocated = 1; @@ -374,22 +395,21 @@ static int pcilib_grab_callback(pcilib_event_t event, pcilib_event_id_t event_id memcpy(*(user->data), data, size); - err = pcilib_return_data(user->ctx, event_id, data); + err = pcilib_return_data(user->ctx, event_id, PCILIB_EVENT_DATA, data); if (err) { if (allocated) { free(*(user->data)); *(user->data) = NULL; } pcilib_error("The event data had been overwritten before it was returned, data corruption may occur"); - return err; + return -err; } - return 0; + return PCILIB_STREAMING_CONTINUE; } int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, pcilib_timeout_t timeout) { int err; - struct timespec ts; pcilib_event_id_t eid; pcilib_grab_callback_user_data_t user = {ctx, size, data}; @@ -397,7 +417,7 @@ int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **d err = pcilib_start(ctx, event_mask, PCILIB_EVENT_FLAGS_DEFAULT); if (!err) err = pcilib_trigger(ctx, event_mask, 0, NULL); if (!err) { - err = pcilib_get_next_event(ctx, timeout, &eid, NULL); + err = pcilib_get_next_event(ctx, timeout, &eid, 0, NULL); if (!err) pcilib_grab_callback(event_mask, eid, &user); } pcilib_stop(ctx, PCILIB_EVENT_FLAGS_DEFAULT); -- cgit v1.2.3