From 6cd00b758c2ac4166b107f36df447034524a5f1b Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Tue, 24 Apr 2018 17:12:29 +0200 Subject: [PATCH] Move log function to a dedicated file and rename it along the way Signed-off-by: Paul Kocialkowski --- src/buffer.c | 1 + src/config.c | 1 + src/media.c | 10 +++++----- src/picture.c | 3 ++- src/sunxi_cedrus.c | 14 ++------------ src/sunxi_cedrus.h | 2 -- src/surface.c | 5 +++-- src/utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/utils.h | 31 +++++++++++++++++++++++++++++++ src/v4l2.c | 8 ++++---- 10 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 src/utils.c create mode 100644 src/utils.h diff --git a/src/buffer.c b/src/buffer.c index 7059e85..3949f01 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -36,6 +36,7 @@ #include +#include "utils.h" #include "v4l2.h" VAStatus SunxiCedrusCreateBuffer(VADriverContextP context, diff --git a/src/config.c b/src/config.c index ce13c1a..8057406 100644 --- a/src/config.c +++ b/src/config.c @@ -34,6 +34,7 @@ #include #include "v4l2.h" +#include "utils.h" VAStatus SunxiCedrusCreateConfig(VADriverContextP context, VAProfile profile, VAEntrypoint entrypoint, VAConfigAttrib *attributes, diff --git a/src/media.c b/src/media.c index bfe4af7..a77b582 100644 --- a/src/media.c +++ b/src/media.c @@ -36,7 +36,7 @@ int media_request_alloc(int media_fd) rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &request_alloc); if (rc < 0) { - sunxi_cedrus_msg("Unable to allocate media request: %s\n", strerror(errno)); + sunxi_cedrus_log("Unable to allocate media request: %s\n", strerror(errno)); return -1; } @@ -49,7 +49,7 @@ int media_request_reinit(int request_fd) rc = ioctl(request_fd, MEDIA_REQUEST_IOC_REINIT, NULL); if (rc < 0) { - sunxi_cedrus_msg("Unable to reinit media request: %s\n", strerror(errno)); + sunxi_cedrus_log("Unable to reinit media request: %s\n", strerror(errno)); return -1; } @@ -62,7 +62,7 @@ int media_request_queue(int request_fd) rc = ioctl(request_fd, MEDIA_REQUEST_IOC_QUEUE, NULL); if (rc < 0) { - sunxi_cedrus_msg("Unable to queue media request: %s\n", strerror(errno)); + sunxi_cedrus_log("Unable to queue media request: %s\n", strerror(errno)); return -1; } @@ -79,10 +79,10 @@ int media_request_wait_completion(int request_fd) rc = select(request_fd + 1, NULL, NULL, &except_fds, &tv); if (rc == 0) { - sunxi_cedrus_msg("Timeout when waiting for media request\n"); + sunxi_cedrus_log("Timeout when waiting for media request\n"); return -1; } else if (rc < 0) { - sunxi_cedrus_msg("Unable to select media request: %s\n", strerror(errno)); + sunxi_cedrus_log("Unable to select media request: %s\n", strerror(errno)); return -1; } diff --git a/src/picture.c b/src/picture.c index 0a1e1f4..3b3d9da 100644 --- a/src/picture.c +++ b/src/picture.c @@ -42,6 +42,7 @@ #include #include "v4l2.h" +#include "utils.h" VAStatus SunxiCedrusBeginPicture(VADriverContextP context, VAContextID context_id, VASurfaceID surface_id) @@ -119,7 +120,7 @@ VAStatus SunxiCedrusRenderPicture(VADriverContextP context, if (rc < 0) return VA_STATUS_ERROR_OPERATION_FAILED; } else { - sunxi_cedrus_msg("Unsupported buffer type: %d\n", buffer_object->type); + sunxi_cedrus_log("Unsupported buffer type: %d\n", buffer_object->type); } break; diff --git a/src/sunxi_cedrus.c b/src/sunxi_cedrus.c index c45b163..89e2df3 100644 --- a/src/sunxi_cedrus.c +++ b/src/sunxi_cedrus.c @@ -36,6 +36,7 @@ #include #include "sunxi_cedrus.h" +#include "utils.h" #include #include @@ -49,17 +50,6 @@ #include -void sunxi_cedrus_msg(const char *msg, ...) -{ - va_list args; - - /* We need to use stderr if we want to be heard */ - fprintf(stderr, "sunxi_cedrus_drv_video: "); - va_start(args, msg); - vfprintf(stderr, msg, args); - va_end(args); -} - /* Set default visibility for the init function only. */ VAStatus __attribute__((visibility("default"))) VA_DRIVER_INIT_FUNC(VADriverContextP context); @@ -153,7 +143,7 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context) rc = ioctl(driver_data->video_fd, VIDIOC_QUERYCAP, &capability); if (rc < 0 || !(capability.capabilities & V4L2_CAP_VIDEO_M2M_MPLANE)) { - sunxi_cedrus_msg("%s does not support m2m mplanes\n", path); + sunxi_cedrus_log("%s does not support m2m mplanes\n", path); return VA_STATUS_ERROR_OPERATION_FAILED; } diff --git a/src/sunxi_cedrus.h b/src/sunxi_cedrus.h index d31f74a..0ddb484 100644 --- a/src/sunxi_cedrus.h +++ b/src/sunxi_cedrus.h @@ -56,8 +56,6 @@ struct sunxi_cedrus_driver_data { int slice_offset[INPUT_BUFFERS_NB]; }; -void sunxi_cedrus_msg(const char *msg, ...); - VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context); VAStatus SunxiCedrusTerminate(VADriverContextP context); diff --git a/src/surface.c b/src/surface.c index 8e10111..ed86c22 100644 --- a/src/surface.c +++ b/src/surface.c @@ -39,6 +39,7 @@ #include #include "v4l2.h" +#include "utils.h" VAStatus SunxiCedrusCreateSurfaces(VADriverContextP context, int width, int height, int format, int surfaces_count, VASurfaceID *surfaces) @@ -204,11 +205,11 @@ VAStatus SunxiCedrusPutSurface(VADriverContextP context, VASurfaceID surface_id, display = XOpenDisplay(getenv("DISPLAY")); if (display == NULL) { - sunxi_cedrus_msg("Cannot connect to X server\n"); + sunxi_cedrus_log("Cannot connect to X server\n"); exit(1); } - sunxi_cedrus_msg("warning: using vaPutSurface with sunxi-cedrus is not recommended\n"); + sunxi_cedrus_log("warning: using vaPutSurface with sunxi-cedrus is not recommended\n"); screen = DefaultScreen(display); gc = XCreateGC(display, RootWindow(display, screen), 0, NULL); XSync(display, False); diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..1678c71 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 Florent Revest + * Copyright (C) 2018 Paul Kocialkowski + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include + +#include "sunxi_cedrus.h" +#include "utils.h" + +void sunxi_cedrus_log(const char *format, ...) +{ + va_list arguments; + + fprintf(stderr, "%s: ", SUNXI_CEDRUS_STR_VENDOR); + + va_start(arguments, format); + vfprintf(stderr, format, arguments); + va_end(arguments); +} diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..c44284f --- /dev/null +++ b/src/utils.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 Florent Revest + * Copyright (C) 2018 Paul Kocialkowski + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _UTILS_H_ +#define _UTILS_H_ + +void sunxi_cedrus_log(const char *format, ...); + +#endif diff --git a/src/v4l2.c b/src/v4l2.c index 3cf6d73..523f516 100644 --- a/src/v4l2.c +++ b/src/v4l2.c @@ -69,7 +69,7 @@ int v4l2_set_format(int video_fd, unsigned int type, unsigned int pixelformat, rc = ioctl(video_fd, VIDIOC_S_FMT, &format); if (rc < 0) { - sunxi_cedrus_msg("Unable to set format for type %d: %s\n", type, strerror(errno)); + sunxi_cedrus_log("Unable to set format for type %d: %s\n", type, strerror(errno)); return -1; } @@ -89,13 +89,13 @@ int v4l2_create_buffers(int video_fd, unsigned int type, rc = ioctl(video_fd, VIDIOC_G_FMT, &buffers.format); if (rc < 0) { - sunxi_cedrus_msg("Unable to get format for type %d: %s\n", type, strerror(errno)); + sunxi_cedrus_log("Unable to get format for type %d: %s\n", type, strerror(errno)); return -1; } rc = ioctl(video_fd, VIDIOC_CREATE_BUFS, &buffers); if (rc < 0) { - sunxi_cedrus_msg("Unable to create buffer for type %d: %s\n", type, strerror(errno)); + sunxi_cedrus_log("Unable to create buffer for type %d: %s\n", type, strerror(errno)); return -1; } @@ -241,7 +241,7 @@ int v4l2_set_stream(int video_fd, unsigned int type, bool enable) rc = ioctl(video_fd, enable ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &buf_type); if (rc < 0) { - sunxi_cedrus_msg("Unable to %sable stream: %s\n", enable ? "en" : "dis", strerror(errno)); + sunxi_cedrus_log("Unable to %sable stream: %s\n", enable ? "en" : "dis", strerror(errno)); return -1; }